From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) (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 A2E353C8C5E for ; Thu, 13 Aug 2026 22:08:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.198 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786658934; cv=none; b=fLAstz/ERxcDOw1MtwgXuS9rV6wpnBdiAMIx40Q82j9Wdi/m3SCNPo9MriiI6R/8RcFcbc4ngf0fGgSnAhZ4YNHuGFGuVcqh8JrotmCmvE4q1Sq5Kik21K9Rvr0ruNVYW1uHZVURIg5igST8NlqL5LoLBVX4P3hLjnAL1eHu21Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786658934; c=relaxed/simple; bh=KiztK1JbpO5JZhhPbKHjeFsloeqjBsAvtQBBDIoVGKs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=EpwPZ8MAqbHYJyWvLKUAOPzBssqAo0uFM4FRiYUsBUXguP08oAwPwLZ9Voc44NlXoI/lxx4L/H/d6/m0Vu4WqmZv/1WYKQVIKiUQKrX7StscZid4S0HZC2BYk0OszXfml1YIpHK3ggOKRfZ3wzDNAbXLVV8LPzll+a/beMf/h7k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=O77IikC1; arc=none smtp.client-ip=209.85.215.198 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--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="O77IikC1" Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-cbedfa3898aso185958a12.3 for ; Thu, 13 Aug 2026 15:08:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786658930; x=1787263730; 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=N/3XZWjnKAuEX+EJn/U2x2ZdOkAMPrJlBbo8McfTGik=; b=O77IikC1sR3xbQiMdywHmVt9JDOGw8IV08kS1LlwG8tzdQFj+o2dEb5UtJfGTjdWMh pgDMHr1drHwz1I8R/nduFxDD3mpZjyZ++TGcDlZyZcxBYFUDrjwowv1eTOikIInNxZK2 C+BVoq7Rs9oMQv2z+nf3MxU/4RS2i6u6Pxm9pG6jOBNP7zkUxOTEtpiMBbclB7Exjwtk eLzyLlr0iUpPg+Uj/+ovfahhebV2/xui++RgIUBhZHyjnJ5MUZcEkEyf4t1dIX/Vg0C+ Pyjk4KGvxS80cFbaFhV6oQ01WJyWy0A5Tvo9HpI6vkZFozu109yY7U7GGivUD5HBvXEP IHdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786658930; x=1787263730; 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=N/3XZWjnKAuEX+EJn/U2x2ZdOkAMPrJlBbo8McfTGik=; b=mCwGhGlyJzDEvm64xxj/iuIiGHIdQs31KO3cDochbVkMmkJqtP/QhZ3/EjoNe9nOwP kxn7ewbMQnCwrVUaLwVSwSPGW+WrMf2qUcPd8MnkbSH+bORpP9QKJx2cBEvJGgVskz/d e1UfO9uCLb3eW3JXNuDYRX9hu/vhv033KD6buwKiogukehX9QQh2C0/jdvorc+CaZ5SF zlA3jG2u51X8PQj5yXUguHd1bjg1h+A/LOW1+O997zFb8Ir+2j0cMccQAhM0L2iVIwv8 XjfJnvXSNnT3YBn8LmW1vnTUztVMDVCN08GHMrr87pO7xb/iX6je12hQHXSGHdgflTco a0dQ== X-Forwarded-Encrypted: i=1; AHgh+RoB952+qcz/lQd93Bqj0yy2OK14Do/+gQvTkOj8x9I5clkrTNU7jbNyh9FWdD3DAySmvmCpd0HCJ10cb80=@vger.kernel.org X-Gm-Message-State: AOJu0YwXNXWUuYXmLg8DI97NbWiF+X2j/8mcgP+nG8KByNlmj4Y3elyn QDeab8BKoUv4dMAJ3O7A3/dfX+t3R7XcCe28kPMCjNzraGJ+AiZV2SGEvC4jvR2ZhYjuPr+fGVj uijZitg== X-Received: from pgcd20.prod.google.com ([2002:a05:6a02:4c54:b0:c9e:41e5:2eec]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:6a21:b0:3b5:489c:7bb5 with SMTP id adf61e73a8af0-3cc71d1e1c7mr839682637.28.1786658929498; Thu, 13 Aug 2026 15:08:49 -0700 (PDT) Date: Thu, 13 Aug 2026 15:08:48 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260807-gmem-inplace-conversion-v10-0-2fc18ee6d3ba@google.com> <20260807-gmem-inplace-conversion-v10-12-2fc18ee6d3ba@google.com> <1ec08cd8-3072-4753-ad5e-cd34956647f8@linux.intel.com> Message-ID: Subject: Re: [PATCH v10 12/41] KVM: guest_memfd: Call arch make_shared callback for to-shared conversion From: Sean Christopherson To: Ackerley Tng Cc: Binbin Wu , aik@amd.com, andrew.jones@linux.dev, 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, 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, liam@infradead.org, Paolo Bonzini , 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, 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, Fuad Tabba Content-Type: text/plain; charset="us-ascii" On Thu, Aug 13, 2026, Ackerley Tng wrote: > Sean Christopherson writes: > > > On Thu, Aug 13, 2026, Binbin Wu wrote: > >> On 8/8/2026 5:52 AM, Ackerley Tng via B4 Relay wrote: > >> > +#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_CONVERT > >> > +static void kvm_gmem_make_shared(struct inode *inode, pgoff_t start, pgoff_t end) > >> > +{ > >> > + struct folio_batch fbatch; > >> > + pgoff_t next = start; > >> > + int i; > >> > + > >> > + folio_batch_init(&fbatch); > >> > + while (filemap_get_folios(inode->i_mapping, &next, end - 1, &fbatch)) { > >> > + for (i = 0; i < folio_batch_count(&fbatch); ++i) { > >> > + struct folio *folio = fbatch.folios[i]; > >> > + pgoff_t start_index, end_index; > >> > + kvm_pfn_t start_pfn; > >> > + kvm_pfn_t nr_pages; > >> > + > >> > + start_index = max(start, folio->index); > >> > + end_index = min(end, folio_next_index(folio)); > >> > + /* > >> > + * end_index is either in folio or points to > >> > + * the first page of the next folio. Hence, > >> > + * all pages in range [start_index, end_index) > >> > + * are contiguous. > >> > + */ > >> > + start_pfn = folio_file_pfn(folio, start_index); > >> > + nr_pages = end_index - start_index; > >> > + > >> > + kvm_arch_gmem_make_shared(start_pfn, nr_pages); > >> > + } > >> > + > >> > + folio_batch_release(&fbatch); > >> > + cond_resched(); > >> > + } > >> > +} > >> > +#else > >> > +static void kvm_gmem_make_shared(struct inode *inode, pgoff_t start, pgoff_t end) {} > >> > +#endif > >> > + > >> > static int __kvm_gmem_set_attributes(struct inode *inode, pgoff_t start, > >> > size_t nr_pages, uint64_t attrs, > >> > pgoff_t *err_index) > >> > @@ -599,7 +636,12 @@ static int __kvm_gmem_set_attributes(struct inode *inode, pgoff_t start, > >> > > >> > filter = to_private ? KVM_FILTER_SHARED : KVM_FILTER_PRIVATE; > >> > kvm_gmem_invalidate_start(inode, start, end, filter); > >> > + > >> > + if (!to_private) > > Should I make this condition > > if (!to_private && kvm_x86_ops.gmem_make_shared) > > instead? > > Will that help? No, because that's bleeding x86 details into common code, which defeats the purpose of arch hooks. That's why I think it's worth analyzing the cost: if it's in the noise, leave it alone. If it's meaningful, figure out a not-too-gross way to skip the entire thing if kvm_arch_gmem_make_shared() is a glorified nop in the end.