From nobody Thu Apr 2 12:33:05 2026 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (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 AAA8E3BC683 for ; Thu, 26 Mar 2026 22:25:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774563924; cv=none; b=IxqP2qUAqcGmWRvHNuiq6XBAHD1psUE8C4KTCBfBHlE7sQtsnC+5aReEi64Sujt7RX83jjF1KylLuZ4uC2h0IMTctTG/DC04jA+1ugiB3KN1VVtExkPqDkZvNafoMZAA1rUkAnKacIVaqrFamQgmCn/hqfzfm40AojEkoyPtADE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774563924; c=relaxed/simple; bh=6GHfy5Gjl/zAQ6e2mdyS+8IkN1+t3F2076IrLeNAKh4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=FryzQ+CsowWyMPQYUm8d5l88ZHjTbxzMyGiA5DbD+olM6XqCeOOd2oasw9+uIdixiacjL8yoUsxlgTtr1lSfa5eHezc6vfarxHJku5J90kutx9gpXrg30vqbb77r70TmhENUREoSUNhkgUxk+Vq+gtdUI+igB3vDLJIq0Lp6TWg= 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=v1MffO8R; arc=none smtp.client-ip=209.85.210.202 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="v1MffO8R" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-82c38b85c25so2734985b3a.3 for ; Thu, 26 Mar 2026 15:25:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774563922; x=1775168722; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=OMzauqzu1N0T+RdZOJts60YeEjJTRcPELOzUqUrSMzA=; b=v1MffO8RiaH90mFYckLFZ5gdhTd7BAqhQkOdkqcqxHjPr7jMIIkx+hKeZgPCd2PJlQ 8SsA79u9Orau9gbFa5xPteH5pIbl+Y/cKWJquegq0hPtQnBYn6mrOpDxMGz8OqduPrNx SZw+RfbTkp2NbBxQIDwjjHD0TrBUlB3mJfS4HcbrUZcV0eIpYwmQHVnnC0twVvNtpSDJ E1P2ShJpNrPcUSqG8C9RbSM+nSHghXTer+GZndTp4z6lY7iKoNLeE4+g3OsMpRQFz8oG xtJghtG7iiAIK5YMuHhuK0uMR0eNmiipdnkcuvoNPpcrGwznhjsp8Lnh/FoYH87aBJ2a 00gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774563922; x=1775168722; h=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; bh=OMzauqzu1N0T+RdZOJts60YeEjJTRcPELOzUqUrSMzA=; b=Cyw+EZO4nZ2sNRuZl8E9duU0ZeBN3AZ0KQ6JI4vm6c3Vmo0L0USN0RI3pWg6HsqyRQ DmSuVi/lFxE2j4kLM+nFye/ioj+5QGQglrb1vixOkVS+WF67q8Ht5JGr9qWUrQ7GgjsU b0gHVwOPTtp40WoJQqsW9UL1EkuN8EUpeDMWcC3/+WRWQLEW7uWojbON6KI/aM8b/79Q yi9voxL36v9mqwbhXVrOLE7XJFOSa5DpzTutG//nMl+M6MYPCFjcsyoarYmWMobIyuyY a8/N3lU3PYiLgRMLQASGrH9vcvKazgUa4VWsEsaIzIUO5y2rkch3i0vOoGN9Ek4OeD51 /qwA== X-Forwarded-Encrypted: i=1; AJvYcCU32d8PhOoBlX0YfvLanBfhUZTpj2wPjDKTHAD5VgVPcm8blk4vfMs1vgudD9cmOnDBuu8eiz8WRB4+jp8=@vger.kernel.org X-Gm-Message-State: AOJu0YwDUKo7e+P2K0w7qPVZ8L9jzqu6xczmlmxVcBn7gYFz+cVC0ovS s10fG2rhT8FFNi/gPZpiJQdliNL3BOS06cOsT68PFOhq04YZ1ydDtThtWouoHW4MkS4fdl2H+L+ L0FqHBBgTm8EO0SV59UJts5AqrA== X-Received: from pfjf18.prod.google.com ([2002:a05:6a00:22d2:b0:82c:8530:819b]) (user=ackerleytng job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:23c8:b0:82a:805a:7cc with SMTP id d2e1a72fcca58-82c959d4be3mr154865b3a.4.1774563921606; Thu, 26 Mar 2026 15:25:21 -0700 (PDT) Date: Thu, 26 Mar 2026 15:24:37 -0700 In-Reply-To: <20260326-gmem-inplace-conversion-v4-0-e202fe950ffd@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260326-gmem-inplace-conversion-v4-0-e202fe950ffd@google.com> X-Developer-Key: i=ackerleytng@google.com; a=ed25519; pk=sAZDYXdm6Iz8FHitpHeFlCMXwabodTm7p8/3/8xUxuU= X-Developer-Signature: v=1; a=ed25519-sha256; t=1774563861; l=1702; i=ackerleytng@google.com; s=20260225; h=from:subject:message-id; bh=6GHfy5Gjl/zAQ6e2mdyS+8IkN1+t3F2076IrLeNAKh4=; b=c0+/tVHHCj0rRhXtP95bZmzyVS99cg5m742QeRGaOCMuqdCrbTR5SGdXnoc6pcKSp6OoBARjg dKSpjzbhP3OC/hursTJC8G2V8dCdYgi2xvh0GxAAJepAlmCgB5i/jZU X-Mailer: b4 0.14.3 Message-ID: <20260326-gmem-inplace-conversion-v4-28-e202fe950ffd@google.com> Subject: [PATCH RFC v4 28/44] KVM: selftests: Test conversion before allocation 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, ira.weiny@intel.com, jmattson@google.com, jroedel@suse.de, 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, tabba@google.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, 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 , Baoquan He , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Jason Gunthorpe , 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, Ackerley Tng Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Add two test cases to the guest_memfd conversions selftest to cover the scenario where a conversion is requested before any memory has been allocated in the guest_memfd region. The KVM_SET_MEMORY_ATTRIBUTES2 ioctl can be called on a memory region at any time. If the guest had not yet faulted in any pages for that region, the kernel must record the conversion request and apply the requested state when the pages are eventually allocated. The new tests cover both conversion directions. Signed-off-by: Ackerley Tng Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/guest_memfd_conversions_test.c | 14 ++++++++++= ++++ 1 file changed, 14 insertions(+) diff --git a/tools/testing/selftests/kvm/guest_memfd_conversions_test.c b/t= ools/testing/selftests/kvm/guest_memfd_conversions_test.c index 3388f06bc51db..1198c9c914318 100644 --- a/tools/testing/selftests/kvm/guest_memfd_conversions_test.c +++ b/tools/testing/selftests/kvm/guest_memfd_conversions_test.c @@ -275,6 +275,20 @@ GMEM_CONVERSION_MULTIPAGE_TEST_INIT_SHARED(indexing, 4) #undef f } =20 +/* + * Test that even if there are no folios yet, conversion requests are reco= rded + * in guest_memfd. + */ +GMEM_CONVERSION_TEST_INIT_SHARED(before_allocation_shared) +{ + test_convert_to_private(t, 0, 0, 'A'); +} + +GMEM_CONVERSION_TEST_INIT_PRIVATE(before_allocation_private) +{ + test_convert_to_shared(t, 0, 0, 'A', 'B'); +} + int main(int argc, char *argv[]) { TEST_REQUIRE(kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_SW_PROTECTED_V= M)); --=20 2.53.0.1018.g2bb0e51243-goog