From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.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 6DDD73C13E0 for ; Wed, 26 Aug 2026 09:19:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787735951; cv=none; b=q1UfNaNMSQMpcusussCq4KmFX32DC0+cxxGIdVTuyduRGoIpYusdcru16iSJF+dlHyU0O8oStycMYg4G46EPnYZunT3Rm7WUi+B67WJIssqL/xJ3fwT5+YmaQaR+cm+iQkyD3Xf4vm9raQxv4rYOFb1Y2zxJWTz1RsgMII1ot1w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787735951; c=relaxed/simple; bh=Z2UFei2SRBY3/wzto9IlHBrYtnnFhcb6Xe3JALubj7U=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=CR679cf1+nzxXew5/jNk5wieiEO6wvcTyyHWtWDP6LKs+s3lAj57m2Nwg7U/J+pJg1V/78Eq6KQ24RQcVzL73ie6ypASr2WrHmCKQD88ki4pCGHLscm8lRVn685lrWe5SR20I1v61ShO/Co/GOKz0ibrDOh9hUay6wi3X4ho+1I= 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=pKSvIGw4; arc=none smtp.client-ip=209.85.214.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="pKSvIGw4" Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-2ccb6823efcso9254805ad.0 for ; Wed, 26 Aug 2026 02:19:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1787735944; x=1788340744; 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=U+QIStebluGuNMlcnL56N5FeU5gomqFB4kLU+1RXvFs=; b=pKSvIGw4gHzl277z2O9++u8ArJO7/iN+6GosdgORq6KqRqN3i8IQiNP+ayOReQ7A2b U2PBUNQO6GMcv0ZnyL7+wTEhOCmrjufb3sSvf/aM7+8hvNI0NzKaP8gaxqz3nlMOSenY yt6EYNUw1XCVP+RPGeYxakgo3h2OX/MJusHgSXY0GMLANeWsEd9Kmt//D2Bg8LyeNSjQ qlWsAJ2xTAFr9m2DtJccGyaDwauOI2CNEzN0UbI6jbGqG/GuR+fEIYks0k2xY1Y90zgo c7qads9jyIem1l+LaBns1sturFDi1YGCdH/okxckmVhd19e0vwEM7xs0a2J6SlhUvIvk R3QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787735944; x=1788340744; 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=U+QIStebluGuNMlcnL56N5FeU5gomqFB4kLU+1RXvFs=; b=ch4mvEO2o4kzlNlkwS9jngYlZkyF1HJK18lhTsZBg32pgbiqzc4mJimKaZkd+FRzmf LVOkI+xUVQlmcHPr08jacX7cg4TxlfXzo3DtDOhaC09YmnztLBjsz3fRDpbRhwme/TjI 10IRRM5GIv6UBfE6GrPiW/iO/VxvNvA7cRgP+aimCevQwsueDtiT1M+F5nJn/PzT1UZj 67dKty215jjE/CDjKMpmQU9ZqSIxde5E3pY/lFrgdj/2qVa3/VDdv6EFN3saRk6Pb3pF qdf/L0g6X2eUCiSt/Nlo9tfRnLCikXSFEmL1ouwMjwjoMOPJIS4ZqL8lG9A/8gRL2tfE Mecw== X-Forwarded-Encrypted: i=1; AHgh+Rq5Zjy8ETpOzbfroI8m88nV/2fbrn0tTCNq/atFbJsQScLH0tum6YU8JiW2zpRO6vWBw6BXtExHJ14=@vger.kernel.org X-Gm-Message-State: AFuF++mnngMoyBIUO0mCA/iIn+r6MKmUCWjeMQpXdDC9TU8FzZiCUe4h XWym9lUpf4hWFI7TY6a0bDz9UkhAc4M1NYG5GJsKWBpurhZM838ZPIdAZBBEUnP9WnDMfYM8w08 sMbXuX4unjLBS+KlJdGCXni41pQ== X-Received: from plblb3.prod.google.com ([2002:a17:902:fa43:b0:2cf:75c1:ab87]) (user=ackerleytng job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:2283:b0:2d6:7409:7145 with SMTP id d9443c01a7336-2d707a2edd0mr90992585ad.1.1787735943792; Wed, 26 Aug 2026 02:19:03 -0700 (PDT) Date: Wed, 26 Aug 2026 09:18:31 +0000 In-Reply-To: <20260826-gmem-inplace-conversion-v11-0-0a15d8a799aa@google.com> Precedence: bulk X-Mailing-List: linux-doc@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=1811; i=ackerleytng@google.com; s=20260225; h=from:subject:message-id; bh=Z2UFei2SRBY3/wzto9IlHBrYtnnFhcb6Xe3JALubj7U=; b=iF9oclctKMAmtq8/BXAmeziLVob0gwQiMxab9AP4cOna1dViC2KVb0DXsHietLlhMm4MmiLFx NG5IyiRqrCFAgls8o8R4aRa0shTBIbhH28LRiR+I6Ogpy3OSwNF8ZVo X-Mailer: b4 0.16.0 Message-ID: <20260826-gmem-inplace-conversion-v11-33-0a15d8a799aa@google.com> Subject: [PATCH v11 33/46] 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, 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" 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. Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Reviewed-by: Fuad Tabba Tested-by: Shivank Garg Signed-off-by: Ackerley Tng --- .../selftests/kvm/x86/guest_memfd_conversions_test.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tools/testing/selftests/kvm/x86/guest_memfd_conversions_test.c b/tools/testing/selftests/kvm/x86/guest_memfd_conversions_test.c index a8d89df53e46d..f46f1530a94b9 100644 --- a/tools/testing/selftests/kvm/x86/guest_memfd_conversions_test.c +++ b/tools/testing/selftests/kvm/x86/guest_memfd_conversions_test.c @@ -268,6 +268,20 @@ GMEM_CONVERSION_MULTIPAGE_TEST_INIT_SHARED(indexing, 4) #undef combine } +/* + * Test that even if there are no folios yet, conversion requests are recorded + * 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_VM)); -- 2.55.0.887.g758fc8c411-goog