From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.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 9EAC6371897 for ; Thu, 6 Aug 2026 13:20:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.197 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786022428; cv=none; b=br6i4c6SkVJuhSQk7K/06JEDrAmsYe+thKc9qyc/q5uKYhwDEmJVrzhcb1S4IrCsUhtX3yXZ/2UqYA9xuVzCZI7HHDLpRS06lPy+vupVFv1nDj+BcEi5MsxVBFOgBnWjO5m6ZkgPteA1QPzQt6yTMGznfHbA9bpZViLeWtApvCw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786022428; c=relaxed/simple; bh=/Jh5oYlubsywuVmQ5YDdqkn0evsJEQYRz4nFdjoYIFk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qBvl4g7Eg/FD6IKyQwefGyOjRiuvjI3iK7FNya4yCNfCGW3j0kl/luS7EymWIZwBhbGqr3h7eQHTGD1d9zs0fxCXYyt7hh6wOnBuFcfk3aBwuMbzDAL9w5iRDA7lstys1v7o37+f4MSxvZMLvIMFAB68Mb0Sc57hZwJE+tvOaPk= 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=D1byBUH7; arc=none smtp.client-ip=209.85.210.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--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="D1byBUH7" Received: by mail-pf1-f197.google.com with SMTP id d2e1a72fcca58-8487eb67173so3592562b3a.2 for ; Thu, 06 Aug 2026 06:20:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786022417; x=1786627217; 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=quMxwgvzS8F8CxQzPIpHc+hBSqfVyEO+f6ARjKTQRm8=; b=D1byBUH7rhMNbdLarcIo2F/MsOXYOEPyXeY+6+x/GiEXIJoBjTRlBaVdK+7cwRD1jd RpiQZKlSrwUHSx6vEl6JrUiPikI9JuQSWm5atoi9VR52Vi2ReT090mwH2GuDPXUqKvxY 8/aXK8AK6ziAu1ZOTEpfvxHeohVtHGjDUIWsKRTbTy0kslhg3t248Uu88Q9XZbEONLYU Zsre/Wn0z/1QV1rxgRtZzOq7igMLsgeNTsuNDU33xuDpuRHPIM4rY7tG3qdISx4F5T3n ZAiDSdbMMM3GP2lDxo3/V+Jq/Wj54gEYJ6sGAkQRyTqGxv3o1XZdgmZpgmbvjK+bphia x49w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786022417; x=1786627217; 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=quMxwgvzS8F8CxQzPIpHc+hBSqfVyEO+f6ARjKTQRm8=; b=YGCIgKtlXHVgEVj2QM+JSmiaLODnDBPGIe8UENd2/QJB9UJOgu+jReoo98dSCe/Uod jESl4VzNjBnHkvlYDchFGkvPHK3T8PDa5CIfXsjifi1VJ066EbOYGgv5iof6XpZF/Ega wCAvXaL6YGG0DJhfanL2+Wfw0jnD2d7xBuoF3NNN5FzHbBntKQFG96NXh4n9SBi+JWCZ gx8VsfxhjSn/bN5Kkaw2OGdHM0jrzoQe3+obvhqd8LvEbbuuVq+NgtAWi5ylBJlYfH75 54NSo1yOeafmjB5DzKqYUBijvgEiu8cdkWH8l2xUhORFiSs9MpzDrBJjXO1h0X3Nmaqm qelw== X-Forwarded-Encrypted: i=1; AHgh+Rr4sgyqIH9CrDCQsfgCktvsEKGKEesNmlbWh2Yclb+ye55H6ELH4FAl32BrbECPkbAANHDvchSDEG7vcQw=@vger.kernel.org X-Gm-Message-State: AOJu0YzdtICwEFU2kSdY0EFamxT8j+NNu1Xy9EwG007CrYd5qe+Vj+S9 ZgThM4EmX/hlFCe7fbatlgYb2oCEDsFuieBSuIVNZJplCBMZeHXO8/hgW22CYsn5ZWdn+BFoUQB eaoA0iQ== X-Received: from pfbcj19.prod.google.com ([2002:a05:6a00:2993:b0:84c:3651:a4b1]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:3ccd:b0:845:c7f1:29fa with SMTP id d2e1a72fcca58-84f2e04a63bmr16001363b3a.30.1786022416699; Thu, 06 Aug 2026 06:20:16 -0700 (PDT) Date: Thu, 6 Aug 2026 06:19:45 -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: <20260728-gmem-inplace-conversion-v9-0-35f9aec2aed2@google.com> <20260728-gmem-inplace-conversion-v9-3-35f9aec2aed2@google.com> <7dafaa90-f3d4-4be4-a5cc-472163f18040@intel.com> Message-ID: Subject: Re: [PATCH v9 03/41] KVM: Enumerate support for PRIVATE memory iff kvm_arch_has_private_mem is defined From: Sean Christopherson To: Xiaoyao Li Cc: Ackerley Tng , 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, 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 , 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="us-ascii" On Thu, Aug 06, 2026, Xiaoyao Li wrote: > On 8/6/2026 8:43 AM, Sean Christopherson wrote: > > On Wed, Aug 05, 2026, Xiaoyao Li wrote: > > > On 7/31/2026 4:34 AM, Ackerley Tng wrote: > > > > I think another way to phrase this is that if we don't make this change, > > > > say, on the foo architecture where there's no CoCo and no private mem > > > > support, kvm_supported_mem_attributes() would return true for the !kvm > > > > case, which is over-reporting. > > > > > > Under the condition that the foo architecture enables > > > CONFIG_KVM_VM_MEMORY_ATTRIBUTES. > > > > > > > How about this, replacing the entire changelog paragraph above: > > > > > > > > Explicitly guard reporting support for KVM_MEMORY_ATTRIBUTE_PRIVATE > > > > based on kvm_arch_has_private_mem being #defined. This improves > > > > reporting accuracy by not reporting support for > > > > KVM_MEMORY_ATTRIBUTE_PRIVATE when kvm_supported_mem_attributes() is > > > > called with kvm == NULL. > > > > > > It doesn't help for the case where kvm == NULL, but help for the case where > > > CONFIG_KVM_VM_MEMORY_ATTRIBUTES is defined but kvm_arch_has_private_mem not. > > > > > > sorry for being picky. I think we can say > > > > > > This improves the reporting accuracy by avoiding the case where > > > KVM_MEMORY_ATTRIBUTE_PRIVATE is reported when kvm == null even without > > > kvm_arch_has_private_mem being #defined. > > > > How about this? > > > > Explicitly guard reporting support for KVM_MEMORY_ATTRIBUTE_PRIVATE based > > on kvm_arch_has_private_mem being #defined in anticipation of tracking > > PRIVATE vs. SHARED state per-guest_memfd, not per-VM (to allow in-place > > conversion). > > Sorry, maybe I'm stupid. I still don't understand how to connect it to > tracking PRIVATE vs. SHARED state per-guest_memfd. > > There are two diffs in this patch, and we are talking about the second diff, > right? Yes, the second diff is what provides the desired change in behavior. > If the kvm_supported_mem_attributes() will be used by gmem, I can buy the > justification. But it won't. At least, it won't after this series. It's not about gmem using that API, it's about non-gmem using the API when reporting KVM_CAP_MEMORY_ATTRIBUTES. Without the change, if KVM supports any memory attributes, i.e. if KVM_GENERIC_MEMORY_ATTRIBUTES=y, then the below will *incorrctly* include PRIVATE in the set of memory attributes, because KVM_CAP_MEMORY_ATTRIBUTES reports what memory attributes are supported via the VM-scoped KVM_SET_MEMORY_ATTRIBUTES. #ifdef CONFIG_KVM_GENERIC_MEMORY_ATTRIBUTES case KVM_CAP_MEMORY_ATTRIBUTES: return kvm_supported_mem_attributes(kvm); #endif > > > guest_memfd support for memory attributes is expected to be unconditional > > to avoid yet more macros (all architectures that support guest_memfd are > > expected to use per-gmem attributes at some point), at which point > > enumerating support KVM_MEMORY_ATTRIBUTE_PRIVATE based solely on memory > > attributes being supported by KVM at-large would result in a system-scope > > s/memory attributes/CONFIG_KVM_VM_MEMORY_ATTRIBUTES/ ? No. I mean "memory attributes" as in KVM as a whole entity, i.e. everything linked into kvm.ko (and kvm-{amd,intel}.ko, supports memory attributes. > > check (NULL @kvm) over-reporting support on arm64. > > I think arm64 won't define CONFIG_KVM_VM_MEMORY_ATTRIBUTES? Precisely *because* of this patch. More at the bottom. > So it seems to have nothing to do with arm64. > > It matters for x86. After patch 20, CONFIG_KVM_VM_MEMORY_ATTRIBUTES is > user-configurable. At that time, people can disable > CONFIG_KVM_SW_PROTECTED_VM, CONFIG_KVM_INTEL_TDX and CONFIG_KVM_AMD_SEV, but > enable CONFIG_KVM_VM_MEMORY_ATTRIBUTES on x86. No, they can't. KVM_VM_MEMORY_ATTRIBUTES depends on one of those three being enabled. What am I missing? config KVM_VM_MEMORY_ATTRIBUTES bool "Enable per-VM PRIVATE vs. SHARED attributes (for CoCo VMs)" depends on KVM_SW_PROTECTED_VM || KVM_INTEL_TDX || KVM_AMD_SEV <====== > In this case, kvm_supported_mem_attributes() reports > KVM_MEMORY_ATTRIBUTE_PRIVATE for system-scope query which is totally wrong. I > think this is the case we want to prevent not something won't happen for > arm64? Well, yeah, because of patches like this one. That's the whole point. Without this change, kvm_supports_private_mem() would be reachable if and only if KVM_VM_MEMORY_ATTRIBUTES=y, which would prevent burying that Kconfig in x86 and would prevent arm64 from enabling the PRIVATE memory attribute in guest_memfd.