lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <fbd6ebaf-c722-41d2-9587-45b12bc74ce5@linux.intel.com>
Date: Fri, 1 Mar 2024 14:55:29 +0800
From: Binbin Wu <binbin.wu@...ux.intel.com>
To: Sagi Shahar <sagis@...gle.com>
Cc: linux-kselftest@...r.kernel.org, Ackerley Tng <ackerleytng@...gle.com>,
 Ryan Afranji <afranji@...gle.com>, Erdem Aktas <erdemaktas@...gle.com>,
 Isaku Yamahata <isaku.yamahata@...el.com>,
 Sean Christopherson <seanjc@...gle.com>, Paolo Bonzini
 <pbonzini@...hat.com>, Shuah Khan <shuah@...nel.org>,
 Peter Gonda <pgonda@...gle.com>, Haibo Xu <haibo1.xu@...el.com>,
 Chao Peng <chao.p.peng@...ux.intel.com>,
 Vishal Annapurve <vannapurve@...gle.com>, Roger Wang <runanwang@...gle.com>,
 Vipin Sharma <vipinsh@...gle.com>, jmattson@...gle.com, dmatlack@...gle.com,
 linux-kernel@...r.kernel.org, kvm@...r.kernel.org, linux-mm@...ck.org
Subject: Re: [RFC PATCH v5 13/29] KVM: selftests: TDX: Add TDX IO writes test



On 12/13/2023 4:46 AM, Sagi Shahar wrote:
> The test verifies IO writes of various sizes from the guest to the host.
>
> Signed-off-by: Sagi Shahar <sagis@...gle.com>
> Signed-off-by: Ackerley Tng <ackerleytng@...gle.com>
> Signed-off-by: Ryan Afranji <afranji@...gle.com>
> ---
>   .../selftests/kvm/include/x86_64/tdx/tdcall.h |  3 +
>   .../selftests/kvm/x86_64/tdx_vm_tests.c       | 91 +++++++++++++++++++
>   2 files changed, 94 insertions(+)

Reviewed-by: Binbin Wu <binbin.wu@...ux.intel.com>

>
> diff --git a/tools/testing/selftests/kvm/include/x86_64/tdx/tdcall.h b/tools/testing/selftests/kvm/include/x86_64/tdx/tdcall.h
> index 78001bfec9c8..b5e94b7c48fa 100644
> --- a/tools/testing/selftests/kvm/include/x86_64/tdx/tdcall.h
> +++ b/tools/testing/selftests/kvm/include/x86_64/tdx/tdcall.h
> @@ -10,6 +10,9 @@
>   #define TDG_VP_VMCALL_INSTRUCTION_IO_READ 0
>   #define TDG_VP_VMCALL_INSTRUCTION_IO_WRITE 1
>   
> +#define TDG_VP_VMCALL_SUCCESS 0x0000000000000000
> +#define TDG_VP_VMCALL_INVALID_OPERAND 0x8000000000000000
> +
>   #define TDX_HCALL_HAS_OUTPUT BIT(0)
>   
>   #define TDX_HYPERCALL_STANDARD 0
> diff --git a/tools/testing/selftests/kvm/x86_64/tdx_vm_tests.c b/tools/testing/selftests/kvm/x86_64/tdx_vm_tests.c
> index 569c8fb0a59f..a2b3e1aef151 100644
> --- a/tools/testing/selftests/kvm/x86_64/tdx_vm_tests.c
> +++ b/tools/testing/selftests/kvm/x86_64/tdx_vm_tests.c
> @@ -339,6 +339,96 @@ void verify_get_td_vmcall_info(void)
>   	printf("\t ... PASSED\n");
>   }
>   
> +#define TDX_IO_WRITES_TEST_PORT 0x51
> +
> +/*
> + * Verifies IO functionality by writing values of different sizes
> + * to the host.
> + */
> +void guest_io_writes(void)
> +{
> +	uint64_t byte_1 = 0xAB;
> +	uint64_t byte_2 = 0xABCD;
> +	uint64_t byte_4 = 0xFFABCDEF;
> +	uint64_t ret;
> +
> +	ret = tdg_vp_vmcall_instruction_io(TDX_IO_WRITES_TEST_PORT, 1,
> +					TDG_VP_VMCALL_INSTRUCTION_IO_WRITE,
> +					&byte_1);
> +	if (ret)
> +		tdx_test_fatal(ret);
> +
> +	ret = tdg_vp_vmcall_instruction_io(TDX_IO_WRITES_TEST_PORT, 2,
> +					TDG_VP_VMCALL_INSTRUCTION_IO_WRITE,
> +					&byte_2);
> +	if (ret)
> +		tdx_test_fatal(ret);
> +
> +	ret = tdg_vp_vmcall_instruction_io(TDX_IO_WRITES_TEST_PORT, 4,
> +					TDG_VP_VMCALL_INSTRUCTION_IO_WRITE,
> +					&byte_4);
> +	if (ret)
> +		tdx_test_fatal(ret);
> +
> +	// Write an invalid number of bytes.
> +	ret = tdg_vp_vmcall_instruction_io(TDX_IO_WRITES_TEST_PORT, 5,
> +					TDG_VP_VMCALL_INSTRUCTION_IO_WRITE,
> +					&byte_4);
> +	if (ret)
> +		tdx_test_fatal(ret);
> +
> +	tdx_test_success();
> +}
> +
> +void verify_guest_writes(void)
> +{
> +	struct kvm_vm *vm;
> +	struct kvm_vcpu *vcpu;
> +
> +	uint8_t byte_1;
> +	uint16_t byte_2;
> +	uint32_t byte_4;
> +
> +	vm = td_create();
> +	td_initialize(vm, VM_MEM_SRC_ANONYMOUS, 0);
> +	vcpu = td_vcpu_add(vm, 0, guest_io_writes);
> +	td_finalize(vm);
> +
> +	printf("Verifying guest writes:\n");
> +
> +	td_vcpu_run(vcpu);
> +	TDX_TEST_CHECK_GUEST_FAILURE(vcpu);
> +	TDX_TEST_ASSERT_IO(vcpu, TDX_IO_WRITES_TEST_PORT, 1,
> +			TDG_VP_VMCALL_INSTRUCTION_IO_WRITE);
> +	byte_1 = *(uint8_t *)((void *)vcpu->run + vcpu->run->io.data_offset);
> +
> +	td_vcpu_run(vcpu);
> +	TDX_TEST_CHECK_GUEST_FAILURE(vcpu);
> +	TDX_TEST_ASSERT_IO(vcpu, TDX_IO_WRITES_TEST_PORT, 2,
> +			TDG_VP_VMCALL_INSTRUCTION_IO_WRITE);
> +	byte_2 = *(uint16_t *)((void *)vcpu->run + vcpu->run->io.data_offset);
> +
> +	td_vcpu_run(vcpu);
> +	TDX_TEST_CHECK_GUEST_FAILURE(vcpu);
> +	TDX_TEST_ASSERT_IO(vcpu, TDX_IO_WRITES_TEST_PORT, 4,
> +			TDG_VP_VMCALL_INSTRUCTION_IO_WRITE);
> +	byte_4 = *(uint32_t *)((void *)vcpu->run + vcpu->run->io.data_offset);
> +
> +	TEST_ASSERT_EQ(byte_1, 0xAB);
> +	TEST_ASSERT_EQ(byte_2, 0xABCD);
> +	TEST_ASSERT_EQ(byte_4, 0xFFABCDEF);
> +
> +	td_vcpu_run(vcpu);
> +	TEST_ASSERT_EQ(vcpu->run->exit_reason, KVM_EXIT_SYSTEM_EVENT);
> +	TEST_ASSERT_EQ(vcpu->run->system_event.data[1], TDG_VP_VMCALL_INVALID_OPERAND);
> +
> +	td_vcpu_run(vcpu);
> +	TDX_TEST_ASSERT_SUCCESS(vcpu);
> +
> +	kvm_vm_free(vm);
> +	printf("\t ... PASSED\n");
> +}
> +
>   int main(int argc, char **argv)
>   {
>   	setbuf(stdout, NULL);
> @@ -353,6 +443,7 @@ int main(int argc, char **argv)
>   	run_in_new_process(&verify_td_ioexit);
>   	run_in_new_process(&verify_td_cpuid);
>   	run_in_new_process(&verify_get_td_vmcall_info);
> +	run_in_new_process(&verify_guest_writes);
>   
>   	return 0;
>   }


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ