From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) (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 644B7372661 for ; Thu, 25 Jun 2026 08:05:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.160.182 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782374756; cv=pass; b=OFRHBVeTbgPox24kcwoZ62Z2Tsa6FI1W/tgdPDkle0iw/MZvLyVQnWMWQSQzSHKfzf9fYuz4UiQsnHI38MvZ72TMrR1TUrr2J74PmWdrrqEgRiInjnW5UwOE3DMzbZnQC5TQuWGBW/utXcueHaGR2kjTkZMq0Q/mYWuV8YhdCkQ= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782374756; c=relaxed/simple; bh=gUH5CYeDQBwLfZeJDBALuowu5eygG91h78hLIiPuwTE=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=WUou6h6hUVGabJOPjYaov/iGD+wvqgSxmmppf3fJHREzTTVi+OSy1kLB8CvP1o4yfuk5pAy/YeFzK//n6wYvVRhBwhPe2zSF6XsW91DQo7fF4P0m+YCtcDvNbRGQEQTCn4yPQ0slP5UKPnO9+InlJ3XxfAfTyWQ5MIrduAM0pIU= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=YFbONY8w; arc=pass smtp.client-ip=209.85.160.182 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=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YFbONY8w" Received: by mail-qt1-f182.google.com with SMTP id d75a77b69052e-51765331535so141381cf.1 for ; Thu, 25 Jun 2026 01:05:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1782374753; cv=none; d=google.com; s=arc-20260327; b=bMrHNjmVKmmfdBrPAKzbLNUDvSXScMIpTxQ9x8go4A413hI9e/iILLmuJqHmFDkA4N EM0aBQhU/wg5t+bkgtIaOj1yOKZ4zIgYql9CqjImnKyi76YZM7ZdF9+FngdM6PJPNlK8 GAeEY4jdhcO7paPTSNXplqZsqviaU3YihhL6zhzsG6pvxSFSKWT4X2XKfwRYVM5BQdKS /OhL25PMVMqRQ8UW+VjJUCYu9Z162IXoba6E7Pw18Kj54xY5PBgpsc+ngCnrI18m8s1X F0lGZBq5v3hhmTRFswJMYfuytdinsl7rDjJLhaqgq9Dszi6RxMv/Wx9EGiFygvqbljkt pPVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=9LjtIzZk3vxrXZVAwqdL1YMS08SLuDbLYjQh10VCn/I=; fh=vwbOGopH/wtXDNBg1FZLRtG+kv8PlCLcc1WROt4E4Rc=; b=cQ/RiU883Aqis9KhMX1YuyOXQcz089shDMRsWv0Dhuus1z++3EAdzNAJuqvmbF6PcN utqpud0bhfwKhrz2KykLiyImWVh1dcgqLIFma7hYZOjHM8RhXu+Nu60v7uMTZxqunab1 ZjcNd0zFe4EGPHRUry80mScDp3G/quhzUGC6nD1BZBk8ShE0NQhnO5iCj1OEAX19OYId UrUIYHms+widwGKReGB0D9hnF+ZsP5A+9K21MXAzJ48a4M9uTdSYLkuvjXe9va2jyrCf vGncz48qEU3X7qsVO/E8ybiSgwFvad3BnGuBqvrWaioE8lp0BZDHVrf3g8DepVCT3zge u+Ug==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1782374753; x=1782979553; darn=vger.kernel.org; h=content-type:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:from:to:cc:subject:date:message-id:reply-to :content-type; bh=9LjtIzZk3vxrXZVAwqdL1YMS08SLuDbLYjQh10VCn/I=; b=YFbONY8woyRitxOoL3EOCijfwZmjVqxkXb3tlHefMKLJHWvlWwefwjsAkTp7x/HB3h +nM1BkP1tcuZ5cFWSybI4kh4vQDezciG4UgXYpqDxDft0FznJY7bwusIvni7jB0/PaZa r30LNzjVwejPNokpTMm4iRLvJittgnmhgX/+Z1kxiCGWCAPeDfZ034qyYBZJ8JSic4QQ ZvwyUeTdhQzc0Yzo6z3jFmr+82Jm5wrxkwiSd8Ao30OxgX4s5BFQry8fem7J0DnxhGeU WBS6IlacsOxKFAWrg7Yx07O1XU7wcSJV5D0LGAS6yT5qhnGx4iw36hcmx5zut+E5gy4B 1x8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782374753; x=1782979553; h=content-type:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=9LjtIzZk3vxrXZVAwqdL1YMS08SLuDbLYjQh10VCn/I=; b=ivCVG05A63m2OQHi+vhbkbDG8v+NW62DUcaRlIiLfzwgZWRfJoiXv4M9G38Ml8fHNs 2YtDKeB9jsnOWTMm2c+BCwjp+SoKZM4MSQtLp8JKl9QO9DLIzm4WwrjbtadzFqgF1jzM YXiut9LbvIcbLRWdI+nT2PuJGji2GbNGLbfGb+2TVkBq9/u5A9pWUBEM7j3lFBFAz3Ub WhTP8ilj8s+8Vf4HJg3zDmf50NtNblyW1HeJ3QcTPvDtvijBCla69SW0uuZ/W57/aN3m g/OEQ2AEE8pYDos3/1drrVMUuMup/mGDUc1JSYxce3rmS83uGiYKb70JW70JN7f5rg9q kGjg== X-Forwarded-Encrypted: i=1; AFNElJ8kBEMS62wwtHLkmzXSsqCKMrpV7rB/flSjA2vlnh83d38BuSabTfX+MVYazyd0bEFRxMbDIzv6ULIKhIg=@vger.kernel.org X-Gm-Message-State: AOJu0YwJEWqLrynY4ej/nkgwbCYqzODKzBzZwI8hcs+frAINBBYc6o08 Krc2weoIm9iz4rlT2EYucO4hKanflEk8dDnotoH5d7u+r6R5uSwqHEJYZ1aCvLWiYaaRXonJI0T mGq/+5SNG5GJuHGqIm1vFAoZUaqbhhrXZ2v6qIS8G X-Gm-Gg: AfdE7cmQrK4ciK3ky1HTNuWCtbIpUd0R4ifkyibAispagLaTMLAwtpnP1DkRz3sLXcC AiOtJLzHimyGwKMQ/a97kaSion4fZDv711RwhyGlrUSySpwbSckbLSMfBMlMNV+e8AYRNYknEEQ a9aXNl99ywXGfPmegvamjMlpPXGFJHHx+IsFRcUdHFiJlsJqTkmDTVFST/gXyQOz8yUmq8vJz6l OTXvWqq4mkwHrXLtpJDto/3foA0jA+zLXq0PchXbgJVH9VR1fyRhGywe4neXyQoOmJFMvkaHg== X-Received: by 2002:a05:622a:4d99:b0:516:4f62:85ec with SMTP id d75a77b69052e-51a7097cdf7mr5787961cf.17.1782374752598; Thu, 25 Jun 2026 01:05:52 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20260618-gmem-inplace-conversion-v8-0-9d2959357853@google.com> <20260618-gmem-inplace-conversion-v8-39-9d2959357853@google.com> In-Reply-To: <20260618-gmem-inplace-conversion-v8-39-9d2959357853@google.com> From: Fuad Tabba Date: Thu, 25 Jun 2026 09:04:00 +0100 X-Gm-Features: AVVi8CcBY4t5giF0-A9bP1HPllgz1zAJhj3Ny1-iABTQtlbD2BJIIQOiCS34wl4 Message-ID: Subject: Re: [PATCH v8 39/46] KVM: selftests: Test conversion with elevated page refcount To: ackerleytng@google.com Cc: 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 , Vlastimil Babka , 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 Content-Type: text/plain; charset="UTF-8" On Fri, 19 Jun 2026 at 01:32, Ackerley Tng via B4 Relay wrote: > > From: Ackerley Tng > > Add a selftest to verify that converting a shared guest_memfd page to a > private page fails if the page has an elevated reference count. > > When KVM converts a shared page to a private one, it expects the page to > have a reference count equal to the reference counts taken by the > filemap. If another kernel subsystem holds a reference to the page, the > conversion must be aborted. > > The test asserts that both bulk and single-page conversion attempts > correctly fail with EAGAIN for the pinned page. After the page is unpinned, > the test verifies that subsequent conversions succeed. > > Signed-off-by: Ackerley Tng > Co-developed-by: Sean Christopherson > Signed-off-by: Sean Christopherson Not sure Sashiko's concern is worth it. Reviewed-by: Fuad Tabba Cheers, /fuad > --- > .../kvm/x86/guest_memfd_conversions_test.c | 56 ++++++++++++++++++++++ > 1 file changed, 56 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 99b0023609670..4ebbd29029526 100644 > --- a/tools/testing/selftests/kvm/x86/guest_memfd_conversions_test.c > +++ b/tools/testing/selftests/kvm/x86/guest_memfd_conversions_test.c > @@ -441,6 +441,62 @@ GMEM_CONVERSION_TEST_INIT_SHARED(forked_accesses) > #undef TEST_STATE_AWAIT > } > > +static void test_convert_to_private_fails(test_data_t *t, u64 pgoff, > + size_t nr_pages, > + u64 expected_error_offset) > +{ > + /* +1 to make it anything but expected_error_offset. */ > + u64 error_offset = expected_error_offset + 1; > + u64 offset = pgoff * page_size; > + int ret; > + > + do { > + ret = __gmem_set_private(t->gmem_fd, offset, > + nr_pages * page_size, &error_offset); > + } while (ret == -1 && errno == EINTR); > + TEST_ASSERT(ret == -1 && errno == EAGAIN, > + "Wanted EAGAIN on page %lu, got %d (ret = %d)", pgoff, > + errno, ret); > + TEST_ASSERT_EQ(error_offset, expected_error_offset); > +} > + > +GMEM_CONVERSION_MULTIPAGE_TEST_INIT_SHARED(elevated_refcount, 4) > +{ > + int i; > + > + pin_pages(t->mem + test_page * page_size, page_size); > + > + for (i = 0; i < nr_pages; i++) > + test_shared(t, i, 0, 'A', 'B'); > + > + /* > + * Converting in bulk should fail as long any page in the range has > + * unexpected refcounts. > + */ > + test_convert_to_private_fails(t, 0, nr_pages, test_page * page_size); > + > + for (i = 0; i < nr_pages; i++) { > + /* > + * Converting page-wise should also fail as long any page in the > + * range has unexpected refcounts. > + */ > + if (i == test_page) > + test_convert_to_private_fails(t, i, 1, test_page * page_size); > + else > + test_convert_to_private(t, i, 'B', 'C'); > + } > + > + unpin_pages(); > + > + gmem_set_private(t->gmem_fd, 0, nr_pages * page_size); > + > + for (i = 0; i < nr_pages; i++) { > + char expected = i == test_page ? 'B' : 'C'; > + > + test_private(t, i, expected, '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.rc0.738.g0c8ab3ebcc-goog > >