From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) (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 B38F33BBFDB for ; Wed, 26 Aug 2026 09:19:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.197 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787735952; cv=none; b=J211MxIyjzSZAqIbIU1KILZu74KmVfmUKEfctBLp0//7SCjmOGVcc4JG1IUQ4BweVjxP2UJ2722+Jky5dN4zIbq70nJyYk3qR3u7X7Nt4qYlPhxyCT9V+GxGMbEo0KeL/lV/IQe4LzRgZz4i2/si/A+uLjjAQ5GVuMDxozlDDq8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787735952; c=relaxed/simple; bh=7hWrOiBCNLWR4WmaZsIQ/WiJTqMaoqs3GPpOPxdsIrA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=i58QSw/vi6d5TvPAUi7HtKs01HhsJb4RaFrs5HrXHkssrSVR5P/qB4RT8ndSeoJ4N+tCK1pzBJn97D/4+BumB+wIStnkHfk7Xxno2wnpQvC7oIUnVyQ93MdP1kh5n6CCwASqPaeVM3gU+6W/HyQRxnzNNKZIuocQnWlZdvRSVBI= 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=k9cRaxz6; arc=none smtp.client-ip=209.85.214.197 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="k9cRaxz6" Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-2d6df0a1e18so9989665ad.1 for ; Wed, 26 Aug 2026 02:19:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1787735946; x=1788340746; darn=lists.linux.dev; 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=QanNPXruSQXVrF67aaQcoGfZbE9UbCtKaKkFHYTWC+U=; b=k9cRaxz64CTexY/SiGC7IvpBlH2TRjk/moH7OmOEdvQVh9H6aH6tZP7y+kFWRibWLQ +cisWBrBoGrKdg/CsluSEDcszHatW/acE0vRELzqwraLIPdXggwSpUx/GWkrv4LVVWuG mBUFPMMySPIbUcoDqj7XPQ3oogTCDHodi8ZVRZgRdcrz8XiAWs9OKW+9ObyOqcMfG3ET 8IS7ppwSUMAbZvSMjQ0ezHKotcxN5eKpFhmDN+75+RC0iIkY0mYnDuPm+0MBJJqv3TCJ IZP8Zng5jMVZ817aieB+CITy/CrHd0bJGeTwf/ScLIP89l1rwtLYpQy0SltrRbbNhsPA RoXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787735946; x=1788340746; 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=QanNPXruSQXVrF67aaQcoGfZbE9UbCtKaKkFHYTWC+U=; b=r5f9OVMIB63F0qm12+TseaZCpv+1X6J07sTmk1rUxLNpuhybon2vFwpjnJ6uGHc0ik B6nKn+d/vk9YQDJoVUnqbtyJST5/xwxG2ok7ktZlIEOrGQEJJDg617e0mqSTRQ9QbmRC LyMMw36PE01Mo3kgRJGYE6KaQmyPYb91i052PF5xm8Ul3Wo5HI7X1cTZ+CfNDXr8SqCE RqM9wEIIXA4IqJDNxEopFpFcK3Pfmmd0lxr/eZOfqniuoKHwxzHHgOS2npmuCamkjQDN xLUuzVZnRw08ZK+xHCowsCmT6mBUjizHaOtDNNef3GfeCpjavs3gvWcxcM2ESthhOOi0 Mprg== X-Forwarded-Encrypted: i=1; AHgh+RqC1QtY/DaH5CLjZwjDr0Ik+HTibGeiJ/9psTgz2gDHo847M8jZDqVM5e+0TJ9lKUDHyya8QHWeYm/k@lists.linux.dev X-Gm-Message-State: AFuF++n9dB3yTYsT/iaZzB4DODG2JyhzXVIJ1+rf7VDH9U6g36+hhzTu AXATu2HQ8yn+udXNqa77zQVmsmr9aGaZxYTy04URxRIjz9UF+Fh8RFSxeXbBhO1axAvrzgQKl0D d9t5SQHva6LGOWN/ZWFCojYgabA== X-Received: from plyw15.prod.google.com ([2002:a17:902:d70f:b0:2cc:6206:58ad]) (user=ackerleytng job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:f541:b0:2d3:716e:e2ae with SMTP id d9443c01a7336-2d707ab1407mr81866255ad.6.1787735945585; Wed, 26 Aug 2026 02:19:05 -0700 (PDT) Date: Wed, 26 Aug 2026 09:18:32 +0000 In-Reply-To: <20260826-gmem-inplace-conversion-v11-0-0a15d8a799aa@google.com> Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev 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=2317; i=ackerleytng@google.com; s=20260225; h=from:subject:message-id; bh=7hWrOiBCNLWR4WmaZsIQ/WiJTqMaoqs3GPpOPxdsIrA=; b=H4rkK1YLN75/OUClRsyrNGZ+v8Y0cZ9iPfybDQNGwCS1Lp8udQXVRcUWRxH/i7jKh5B1xjwbI /6yH7SDOMn/C3e0QrzREPxPxypHEsDepGeNaD2wcV8oKFQzOKNmrTyz X-Mailer: b4 0.16.0 Message-ID: <20260826-gmem-inplace-conversion-v11-34-0a15d8a799aa@google.com> Subject: [PATCH v11 34/46] KVM: selftests: Convert with allocated folios in different layouts 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 a guest_memfd selftest to verify that memory conversions work correctly with allocated folios in different layouts. By iterating through which pages are initially faulted, the test covers various layouts of contiguous allocated and unallocated regions, exercising conversion with different range layouts. Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Reviewed-by: Fuad Tabba Tested-by: Shivank Garg Signed-off-by: Ackerley Tng --- .../kvm/x86/guest_memfd_conversions_test.c | 30 ++++++++++++++++++++++ 1 file changed, 30 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 f46f1530a94b9..acdff2d154046 100644 --- a/tools/testing/selftests/kvm/x86/guest_memfd_conversions_test.c +++ b/tools/testing/selftests/kvm/x86/guest_memfd_conversions_test.c @@ -282,6 +282,36 @@ GMEM_CONVERSION_TEST_INIT_PRIVATE(before_allocation_private) test_convert_to_shared(t, 0, 0, 'A', 'B'); } +/* + * Test that when some of the folios in the conversion range are allocated, + * conversion requests are handled correctly in guest_memfd. Vary the ranges + * allocated before conversion, using test_page, to cover various layouts of + * contiguous allocated and unallocated regions. + */ +GMEM_CONVERSION_MULTIPAGE_TEST_INIT_SHARED(unallocated_folios, 8) +{ + const int second_page_to_fault = 4; + int i; + + /* + * Fault 2 of the pages to test filemap range operations except when + * test_page == second_page_to_fault. + */ + host_do_rmw(t->mem, test_page, 0, 'A'); + if (test_page != second_page_to_fault) + host_do_rmw(t->mem, second_page_to_fault, 0, 'A'); + + gmem_set_private(t->gmem_fd, 0, nr_pages * page_size); + for (i = 0; i < nr_pages; ++i) { + char expected = (i == test_page || i == second_page_to_fault) ? 'A' : 0; + + test_private(t, i, expected, 'B'); + } + + for (i = 0; i < nr_pages; ++i) + test_convert_to_shared(t, i, 'B', 'C', 'D'); +} + 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