From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (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 5FB743BD644 for ; Thu, 26 Mar 2026 22:25:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774563925; cv=none; b=uIJvvPxQctfG7XnqnZLtwDyEcxkhzDwxaI9bhvDZ2XCKX82Koi75/N/MCchmzv40TFUWi5MRqjqvB1ZQ11Wr+QpoBHBSCxK59wynoVkWxKqaclJ34zMMw0kWo6xriSbLCN/IqYKqJCEvyGHed48kfMC7kuZYdsS8oBQoTGAQbfc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774563925; c=relaxed/simple; bh=oHklOacZgiD0w5i2dlS6G3/6wCT4tptcmpz8kawfH5k=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=HrSMdm+hwXBxonTCn/3Rc9wQZhS/y55aiVDr0UuoegSUAwhBMpG2OLP2Zuu/MqYmRbEDAEHU60bJGUrxMVBKA4u0G5CsOkhnbJGAW9x21m+PfIJJXyhxf4cENK2yZzwR1EQw5cdXPPL7f9hC7CjQ9mm07P+KlU5jfpgFY6uajsU= 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=dfcgBgh3; arc=none smtp.client-ip=209.85.210.201 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="dfcgBgh3" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-82c38b85c25so2735009b3a.3 for ; Thu, 26 Mar 2026 15:25:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774563924; x=1775168724; 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=E1xYMD/ygmI2J6L6yZT+C265xiVpI/P15LX3jXqm3Xk=; b=dfcgBgh3QsUyTetXaxxZILIH4NOqD2AjY/TzHEz05JFk4PU8q/RwhBwi0wmEbqlYJB 9tuGeDdUZgL8eHkL2KgwGcjpXe8S5xZPO4Wg0QlDD3/vmbHFveSztKIB0CLtull6fPtI ijonnS9FnRa/HMfshoSUXbhTaDmlz7HrNYAD/lK0iPp4RKcHuL+5BOKQFS/936vTQsr/ F2VBd+U6tZtsE3O5QF94qntZwQepEZPZ2DyPFwh0IlBF4FVcjwJeH8tU317ZWtPADqOk 9iQslmkSOM8R4XqWNPgFd5TuvXkRzreTy8K/4rXX3ytCNSq3VB7GCiarTMPj8bv3lIyD QKMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774563924; x=1775168724; 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=E1xYMD/ygmI2J6L6yZT+C265xiVpI/P15LX3jXqm3Xk=; b=P7ZhyUgTu2/DboevuMAlw1y2rVvE+9MOzw9JY6Bt2jh6xnn1h2whGgfIdVylvWgs9D A3/kLbklriIimO21NVGiDFFfK8BPdpmMjzZiz682fsmt8eIeUBIdd3Gr49N7l6VOOlM+ rBKtSdGXMQjVpl7Dw+sUf+58bzpW7/OOwcpk6vUDMUq8Anawr4UwRXBWM8SBxHLF0OF9 WE4Bd26L1NyTSvJSB6Ovb6rL4IBKKQtet1fJ2SXZYgh+llKb7RGJjLUYYCKgKkk36IUi sTFNBrN+VbnmVVbDI1yCcchck3MJDvF1ptwK+LpDcb+0QKC4KBMwZNM1RGo2kgFv2vbN 5rXw== X-Forwarded-Encrypted: i=1; AJvYcCVZZWMm3dhWo33eFoYgpk8J/ecSWe6d+z9LZLtTzBnpYksoAUTwv2O3i9poomPbsTXB+VhkmDxGQrg=@vger.kernel.org X-Gm-Message-State: AOJu0YxQ+JLkCSkdlsV+GOx5Zz0f5fFzCJ7yrg6XmmEEjPou0OBQ4wzp 2fUSx94ihxkm5Dqmlfo3HiVsR8StWja9bWunjxKkebXO3BXLIF+N2YavCc7ab4Mq0yqPQAqUJ/5 HmvvXz4zKwg1ChhIC6D0sdAFLNg== X-Received: from pfbfo22.prod.google.com ([2002:a05:6a00:6016:b0:82c:6863:427a]) (user=ackerleytng job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:348b:b0:829:6f37:158a with SMTP id d2e1a72fcca58-82c95c036cdmr167633b3a.18.1774563923362; Thu, 26 Mar 2026 15:25:23 -0700 (PDT) Date: Thu, 26 Mar 2026 15:24:38 -0700 In-Reply-To: <20260326-gmem-inplace-conversion-v4-0-e202fe950ffd@google.com> Precedence: bulk X-Mailing-List: linux-doc@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=2257; i=ackerleytng@google.com; s=20260225; h=from:subject:message-id; bh=oHklOacZgiD0w5i2dlS6G3/6wCT4tptcmpz8kawfH5k=; b=t7NZE6MbqQDRWbQsWbc0txg2U4p4153wpJM1gp3EaoANwnq92WnqbVCOltBJBXIrWcw+W5+GI jF48qJjsPNLBWBTO1mypfrEwWyywX8S14Vetlu9iUQQtlDVpnf415F4 X-Mailer: b4 0.14.3 Message-ID: <20260326-gmem-inplace-conversion-v4-29-e202fe950ffd@google.com> Subject: [PATCH RFC v4 29/44] 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, 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" 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. Signed-off-by: Ackerley Tng Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson --- .../selftests/kvm/guest_memfd_conversions_test.c | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tools/testing/selftests/kvm/guest_memfd_conversions_test.c b/tools/testing/selftests/kvm/guest_memfd_conversions_test.c index 1198c9c914318..8f09671505b32 100644 --- a/tools/testing/selftests/kvm/guest_memfd_conversions_test.c +++ b/tools/testing/selftests/kvm/guest_memfd_conversions_test.c @@ -289,6 +289,37 @@ 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, + KVM_SET_MEMORY_ATTRIBUTES2_PRESERVE); + 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.53.0.1018.g2bb0e51243-goog