From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 609BC40098A for ; Wed, 26 Aug 2026 09:19:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787735962; cv=none; b=Hcraas0Up5VRWGNI/E9do6LY0kFpJOOv+adJA8ZzvlbCew3402fwqX+Ff8qHGcLn98B94CVyo1GTE7uq0wdm7kzxFgb4ObV1x9VTjklZa/GEiRhIOJ0WW6SDokG+AtwjI2nJSsWl0gLGApmhXu6z3Xnw83qLIiecxzHa67ZCeSQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787735962; c=relaxed/simple; bh=Z2tr8qvCMQ6vCwWclEIKVEn4lsWDwgpi8MEvWzFtaCI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qergRvjpStgDqgRpCbSCpMUuWn2pyja+b8e8KOEfa4vg/3AK3yyNxgkTLBAnjbHKBZp2S6rWmuI6EYtGkqa2GZLjoqk8MlxFHblhH78AM0NfQVhCcIBk0HYG6PRlBUQEHKw8oUPq8krB9pQ2or0nzXEuLTGcF4ZtRSPH1tHjOKQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ackerleytng.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=r11z5JKA; arc=none smtp.client-ip=209.85.215.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ackerleytng.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="r11z5JKA" Received: by mail-pg1-f199.google.com with SMTP id 41be03b00d2f7-cc1a439db36so897060a12.2 for ; Wed, 26 Aug 2026 02:19:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1787735955; x=1788340755; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=bLTz+QoAp4yNZ1r8wY9Xq6qZeJQ57AOaVsGWHTn9ANY=; b=r11z5JKAqRwK5SgW3du5wfI9Q8/jzJB0UWeBchf9XMDxcxNt08IbW9E5zf899fF62R DzjO3uqyIpPXoKCLbybYH7u1PkrFA20Y/wYg8sfprnqU8pc91Qyc54xmOhFDTtxyzrVH seH3E1Aq7bUPQY/fyaO+6sj/PKxUDdx0WgA3UrEklXsImF570s0NgRwuTyTfiozKoxWJ sD8ge0hTjbc6mtCMusU66k3sMn8JQwFLn5jWOwgVr69NREg5us3GxB19w1/j8G9Tm2Wc wBphtcHLwpZYud2UegLK/QYCUA/Bm7IbHpIndsIB7hAc1+35RuMqM2tLY5JXtzyvS77+ vpNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787735955; x=1788340755; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=bLTz+QoAp4yNZ1r8wY9Xq6qZeJQ57AOaVsGWHTn9ANY=; b=S+er05M5VaahIJ3TNwLgXhdb5M+Bz28NTpezue63ylNphrwUNP5NFw87dJL7C45GxZ /rflf9pxCJwmeSJ8Z4PDtZCZbbFAumSCWmE5HtEA7kbc6e9oYHDiNTmA0OO7wwE/vD0/ kgtBTFlp20B6ZQD1Ks4fqW4+6/VvUhjOjET2vhjgTUOc+/KQYc+xxbv2EK2MmOTJU8jl WleQNWr/4LTGq/641ZbPyQsikKRl75gRnNkbrh0lugNK0IIni3ONn1RTnGfofEIRY5sP Y6v3GvC1wdflT68F8m6ryt4YKUFGGUmh8yJvMfhKH3rR5lnDcfe1ndKcMS+oih430I0y 07UQ== X-Forwarded-Encrypted: i=1; AHgh+RpGVs8vaqhe0akNWMC2zCNCKPxX5t/QeMpl9ba+INAjvrUbIcrkNxl16H8Nj8/0b7P2O61Aj8ELndSqY28=@vger.kernel.org X-Gm-Message-State: AFuF++kYG/KxpPha8xcQXVhCu4MvAfC0stC8rKiPvpTOct7V3ivP4j4P f/NKve+577U+dkOZ7z1Y17mvHtsyiUqMseml1aghlzqHjjCcindiaoDkn6ZE5VikyNMJ09G8UlA DQWY67KU4FW8m+dOJCEHueuv7Tw== X-Received: from pgcq30.prod.google.com ([2002:a63:751e:0:b0:c9b:2759:d240]) (user=ackerleytng job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6300:6681:b0:3cc:9288:99aa with SMTP id adf61e73a8af0-3cf6673e199mr11680996637.0.1787735954249; Wed, 26 Aug 2026 02:19:14 -0700 (PDT) Date: Wed, 26 Aug 2026 09:18:37 +0000 In-Reply-To: <20260826-gmem-inplace-conversion-v11-0-0a15d8a799aa@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260826-gmem-inplace-conversion-v11-0-0a15d8a799aa@google.com> X-Developer-Key: i=ackerleytng@google.com; a=ed25519; pk=sAZDYXdm6Iz8FHitpHeFlCMXwabodTm7p8/3/8xUxuU= X-Developer-Signature: v=1; a=ed25519-sha256; t=1787735885; l=2579; i=ackerleytng@google.com; s=20260225; h=from:subject:message-id; bh=Z2tr8qvCMQ6vCwWclEIKVEn4lsWDwgpi8MEvWzFtaCI=; b=uYPyckNcYtbmNIce6USQWE2ZQN3yzQ5s9PRlHn/kQiqauAVRj01fYWLdGSn4JUn4Y8ICRU4i5 SrOFy7IMtVFANbmMI9ps1KJiTpkrRcJ6bBbcMXjogb2zUhXxCkElfSO X-Mailer: b4 0.16.0 Message-ID: <20260826-gmem-inplace-conversion-v11-39-0a15d8a799aa@google.com> Subject: [PATCH v11 39/46] KVM: selftests: Reset shared memory after hole-punching From: Ackerley Tng To: aik@amd.com, andrew.jones@linux.dev, binbin.wu@linux.intel.com, brauner@kernel.org, chao.p.peng@linux.intel.com, david@kernel.org, jmattson@google.com, jthoughton@google.com, michael.roth@amd.com, oupton@kernel.org, pankaj.gupta@amd.com, qperret@google.com, rick.p.edgecombe@intel.com, rientjes@google.com, shivankg@amd.com, steven.price@arm.com, willy@infradead.org, wyihan@google.com, yan.y.zhao@intel.com, forkloop@google.com, pratyush@kernel.org, suzuki.poulose@arm.com, aneesh.kumar@kernel.org, liam@infradead.org, Paolo Bonzini , Sean Christopherson , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jonathan Corbet , Shuah Khan , Shuah Khan , Vishal Annapurve , Andrew Morton , Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Youngjun Park , Qi Zheng , Shakeel Butt , Kiryl Shutsemau , Baoquan He , Jason Gunthorpe , John Hubbard , Peter Xu , tarunsahu@google.com, Fuad Tabba , Vlastimil Babka Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-coco@lists.linux.dev, Ackerley Tng Content-Type: text/plain; charset="utf-8" private_mem_conversions_test used to reset the shared memory that was used for the test to an initial pattern at the end of each test iteration. Then, it would punch out the pages, which would zero memory. Without in-place conversion, the resetting would write shared memory, and hole-punching will zero private memory, hence resetting the test to the state at the beginning of the for loop. With in-place conversion, resetting writes memory as shared, and hole-punching zeroes the same physical memory, hence undoing the reset done before the hole punch. Move the resetting after the hole-punching, and reset the entire PER_CPU_DATA_SIZE instead of just the tested range. With in-place conversion, this zeroes and then resets the same physical memory. Without in-place conversion, the private memory is zeroed, and the shared memory is reset to init_p. This is sufficient since at each test stage, the memory is assumed to start as shared, and private memory is always assumed to start zeroed. Conversion zeroes memory, so the future test stages will work as expected. Fixes: 43f623f350ce1 ("KVM: selftests: Add x86-only selftest for private memory conversions") Reviewed-by: Fuad Tabba Tested-by: Shivank Garg Signed-off-by: Ackerley Tng --- tools/testing/selftests/kvm/x86/private_mem_conversions_test.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/x86/private_mem_conversions_test.c b/tools/testing/selftests/kvm/x86/private_mem_conversions_test.c index f3de2a4ab0551..cf50e9a332c5b 100644 --- a/tools/testing/selftests/kvm/x86/private_mem_conversions_test.c +++ b/tools/testing/selftests/kvm/x86/private_mem_conversions_test.c @@ -202,15 +202,18 @@ static void guest_test_explicit_conversion(u64 base_gpa, bool do_fallocate) guest_sync_shared(gpa, size, p3, p4); memcmp_g(gpa, p4, size); - /* Reset the shared memory back to the initial pattern. */ - memset((void *)gpa, init_p, size); - /* * Free (via PUNCH_HOLE) *all* private memory so that the next * iteration starts from a clean slate, e.g. with respect to * whether or not there are pages/folios in guest_mem. */ guest_map_shared(base_gpa, PER_CPU_DATA_SIZE, true); + + /* + * Hole-punching above zeroed private memory. Reset shared + * memory in preparation for the next GUEST_STAGE. + */ + memset((void *)base_gpa, init_p, PER_CPU_DATA_SIZE); } } -- 2.55.0.887.g758fc8c411-goog