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: <26822c313754e03b2c393e6fdefe495f117bbfff.1695327124.git.isaku.yamahata@intel.com>
Date:   Thu, 21 Sep 2023 13:14:36 -0700
From:   isaku.yamahata@...el.com
To:     kvm@...r.kernel.org, linux-kernel@...r.kernel.org
Cc:     isaku.yamahata@...el.com, isaku.yamahata@...il.com,
        Michael Roth <michael.roth@....com>,
        Paolo Bonzini <pbonzini@...hat.com>,
        Sean Christopherson <seanjc@...gle.com>, erdemaktas@...gle.com,
        Sagi Shahar <sagis@...gle.com>,
        David Matlack <dmatlack@...gle.com>,
        Kai Huang <kai.huang@...el.com>,
        Zhi Wang <zhi.wang.linux@...il.com>, chen.bo@...el.com,
        linux-coco@...ts.linux.dev,
        Chao Peng <chao.p.peng@...ux.intel.com>,
        Ackerley Tng <ackerleytng@...gle.com>,
        Vishal Annapurve <vannapurve@...gle.com>,
        Yuan Yao <yuan.yao@...ux.intel.com>,
        Jarkko Sakkinen <jarkko@...nel.org>,
        Xu Yilun <yilun.xu@...el.com>,
        Quentin Perret <qperret@...gle.com>, wei.w.wang@...el.com,
        Fuad Tabba <tabba@...gle.com>
Subject: [RFC PATCH v2 3/6] KVM: selftests: Add tests for punch hole on guest_memfd

From: Isaku Yamahata <isaku.yamahata@...el.com>

Punch hole implies the region is zeroed out. Add tests if the punched
region has zero.
Oppertunistically Remove unused member, pattern, in guest_run_test().

Signed-off-by: Isaku Yamahata <isaku.yamahata@...el.com>
---
 .../kvm/x86_64/private_mem_conversions_test.c | 26 ++++++++++++++-----
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c b/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c
index 50541246d6fd..c05c725645af 100644
--- a/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c
+++ b/tools/testing/selftests/kvm/x86_64/private_mem_conversions_test.c
@@ -85,9 +85,10 @@ static void guest_sync_private(uint64_t gpa, uint64_t size, uint8_t pattern)
 /* Arbitrary values, KVM doesn't care about the attribute flags. */
 #define MAP_GPA_SHARED		BIT(0)
 #define MAP_GPA_DO_FALLOCATE	BIT(1)
+#define MAP_GPA_FALLOCATE_ONLY	BIT(2)
 
 static void guest_map_mem(uint64_t gpa, uint64_t size, bool map_shared,
-			  bool do_fallocate)
+			  bool do_fallocate, bool fallocate_only)
 {
 	uint64_t flags = 0;
 
@@ -95,17 +96,24 @@ static void guest_map_mem(uint64_t gpa, uint64_t size, bool map_shared,
 		flags |= MAP_GPA_SHARED;
 	if (do_fallocate)
 		flags |= MAP_GPA_DO_FALLOCATE;
+	if (fallocate_only)
+		flags |= MAP_GPA_FALLOCATE_ONLY;
 	kvm_hypercall_map_gpa_range(gpa, size, flags);
 }
 
 static void guest_map_shared(uint64_t gpa, uint64_t size, bool do_fallocate)
 {
-	guest_map_mem(gpa, size, true, do_fallocate);
+	guest_map_mem(gpa, size, true, do_fallocate, false);
 }
 
 static void guest_map_private(uint64_t gpa, uint64_t size, bool do_fallocate)
 {
-	guest_map_mem(gpa, size, false, do_fallocate);
+	guest_map_mem(gpa, size, false, do_fallocate, false);
+}
+
+static void guest_punch_hole_private(uint64_t gpa, uint64_t size)
+{
+	guest_map_mem(gpa, size, true, true, true);
 }
 
 static void guest_run_test(uint64_t base_gpa, bool do_fallocate)
@@ -113,7 +121,6 @@ static void guest_run_test(uint64_t base_gpa, bool do_fallocate)
 	struct {
 		uint64_t offset;
 		uint64_t size;
-		uint8_t pattern;
 	} stages[] = {
 		GUEST_STAGE(0, PAGE_SIZE),
 		GUEST_STAGE(0, SZ_2M),
@@ -156,6 +163,10 @@ static void guest_run_test(uint64_t base_gpa, bool do_fallocate)
 
 		if (size > PAGE_SIZE) {
 			memset((void *)gpa, p2, PAGE_SIZE);
+
+			/* Test if punch hole results in zeroing page. */
+			guest_punch_hole_private(gpa, PAGE_SIZE);
+			memcmp_g(gpa, 0, PAGE_SIZE);
 			goto skip;
 		}
 
@@ -229,6 +240,7 @@ static void handle_exit_hypercall(struct kvm_vcpu *vcpu)
 	uint64_t size = run->hypercall.args[1] * PAGE_SIZE;
 	bool map_shared = run->hypercall.args[2] & MAP_GPA_SHARED;
 	bool do_fallocate = run->hypercall.args[2] & MAP_GPA_DO_FALLOCATE;
+	bool fallocate_only = run->hypercall.args[2] & MAP_GPA_FALLOCATE_ONLY;
 	struct kvm_vm *vm = vcpu->vm;
 
 	TEST_ASSERT(run->hypercall.nr == KVM_HC_MAP_GPA_RANGE,
@@ -238,8 +250,10 @@ static void handle_exit_hypercall(struct kvm_vcpu *vcpu)
 	if (do_fallocate)
 		vm_guest_mem_fallocate(vm, gpa, size, map_shared);
 
-	vm_set_memory_attributes(vm, gpa, size,
-				 map_shared ? 0 : KVM_MEMORY_ATTRIBUTE_PRIVATE);
+	if (!fallocate_only)
+		vm_set_memory_attributes(vm, gpa, size,
+					 map_shared ?
+					 0 : KVM_MEMORY_ATTRIBUTE_PRIVATE);
 	run->hypercall.ret = 0;
 }
 
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ