From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from iad-out-015.esa.us-east-1.outbound.mail-perimeter.amazon.com (iad-out-015.esa.us-east-1.outbound.mail-perimeter.amazon.com [44.210.169.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E230A3E121D; Fri, 10 Apr 2026 15:19:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=44.210.169.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775834357; cv=none; b=s1s99wg8SSXJGLKhIQZe3QtDR+mNteqASjEklx7cIy15rdNlgKqLO1eXRGUXTnq6OX2Y0csXlON2wWGuRSfxsYPkNR/zl/IR8pxRFclvnGiE8M+RblPK6vBziT8IszdS6dXXbahW7eebUmkereE/ul+vSUdJI7j802jpxTuiAl0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775834357; c=relaxed/simple; bh=g42t1AuoQjNP+Na/yg6PoUGXChwwAdv2XYqnEELG11E=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=K2x4CH+KVfC2xu9BV8je5ebwQmZpRt8vnUQ9/IWkFP+/WfFbqk1kouTCHO9xA+8QHzkl1SSlsAOcU0pjcZZ++rJPw+9ciTzletCDME7LDb5EUrp/HTAIrMl3Mx/G9tY6Ih3oKBGsMEzA0MALHFEJNwUl4WVzcHdRpjTu+KMRclw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.co.uk; spf=pass smtp.mailfrom=amazon.co.uk; dkim=pass (2048-bit key) header.d=amazon.co.uk header.i=@amazon.co.uk header.b=ecu73tiR; arc=none smtp.client-ip=44.210.169.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.co.uk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.co.uk header.i=@amazon.co.uk header.b="ecu73tiR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.co.uk; i=@amazon.co.uk; q=dns/txt; s=amazoncorp2; t=1775834356; x=1807370356; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=ALg3p/ltsqIoaqb5A/f57OhF7/SQhKPMf9Yd0huEWqI=; b=ecu73tiRmauTv6PbmBm9tKKAbekJXwT+VzqLDYEHdYpYyfigooGVW7bU rpkK5IbZphPLGe31YIDysAaStkIAWH/kEln0chR2o0iOQi0plQ9KLvS3y nBITydLA6jKNr0G2S9Ba7pICqogEauG3t35nEROiYIrBY06qRY8M1LVOc GBP6fHXT+GjjW7Y9huAST7hJg09Bt8ECG+0g7f9Trqsc7NzCyN9LmYS4p j/vrIQj14WRmW3NZNwsQSuu5Q/1+lxLk/VK5uX7S8EO72BGPRe1svxRIU lIpbL1IF49lEVpW5nZu29Bd+ooUR7R/7VyOEX4GT6+uHQQAVE9yG4EVcL Q==; X-CSE-ConnectionGUID: Guv9fjVNT/aSrGQUraKCmg== X-CSE-MsgGUID: tuX3xo+YRyC+BGiBmsyZ+w== X-IronPort-AV: E=Sophos;i="6.23,171,1770595200"; d="scan'208";a="15419479" Received: from ip-10-4-3-150.ec2.internal (HELO smtpout.naws.us-east-1.prod.farcaster.email.amazon.dev) ([10.4.3.150]) by internal-iad-out-015.esa.us-east-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2026 15:19:14 +0000 Received: from EX19MTAUEC001.ant.amazon.com [52.94.133.142:28111] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.29.254:2525] with esmtp (Farcaster) id ff476389-81e7-44f5-b885-cbfab252140c; Fri, 10 Apr 2026 15:19:14 +0000 (UTC) X-Farcaster-Flow-ID: ff476389-81e7-44f5-b885-cbfab252140c Received: from EX19D027UEC002.ant.amazon.com (10.252.137.166) by EX19MTAUEC001.ant.amazon.com (10.252.135.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.37; Fri, 10 Apr 2026 15:19:14 +0000 Received: from EX19D027UEC003.ant.amazon.com (10.252.137.250) by EX19D027UEC002.ant.amazon.com (10.252.137.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.37; Fri, 10 Apr 2026 15:19:13 +0000 Received: from EX19D027UEC003.ant.amazon.com ([fe80::887f:519b:ba73:21d]) by EX19D027UEC003.ant.amazon.com ([fe80::887f:519b:ba73:21d%3]) with mapi id 15.02.2562.037; Fri, 10 Apr 2026 15:19:13 +0000 From: "Kalyazin, Nikita" To: "kvm@vger.kernel.org" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "kvmarm@lists.linux.dev" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" , "bpf@vger.kernel.org" , "linux-kselftest@vger.kernel.org" , "kernel@xen0n.name" , "linux-riscv@lists.infradead.org" , "linux-s390@vger.kernel.org" , "loongarch@lists.linux.dev" , "linux-pm@vger.kernel.org" CC: "pbonzini@redhat.com" , "corbet@lwn.net" , "maz@kernel.org" , "oupton@kernel.org" , "joey.gouly@arm.com" , "suzuki.poulose@arm.com" , "yuzenghui@huawei.com" , "catalin.marinas@arm.com" , "will@kernel.org" , "seanjc@google.com" , "tglx@kernel.org" , "mingo@redhat.com" , "bp@alien8.de" , "dave.hansen@linux.intel.com" , "x86@kernel.org" , "hpa@zytor.com" , "luto@kernel.org" , "peterz@infradead.org" , "willy@infradead.org" , "akpm@linux-foundation.org" , "david@kernel.org" , "lorenzo.stoakes@oracle.com" , "vbabka@kernel.org" , "rppt@kernel.org" , "surenb@google.com" , "mhocko@suse.com" , "ast@kernel.org" , "daniel@iogearbox.net" , "andrii@kernel.org" , "martin.lau@linux.dev" , "eddyz87@gmail.com" , "song@kernel.org" , "yonghong.song@linux.dev" , "john.fastabend@gmail.com" , "kpsingh@kernel.org" , "sdf@fomichev.me" , "haoluo@google.com" , "jolsa@kernel.org" , "jgg@ziepe.ca" , "jhubbard@nvidia.com" , "peterx@redhat.com" , "jannh@google.com" , "pfalcato@suse.de" , "skhan@linuxfoundation.org" , "riel@surriel.com" , "ryan.roberts@arm.com" , "jgross@suse.com" , "yu-cheng.yu@intel.com" , "kas@kernel.org" , "coxu@redhat.com" , "ackerleytng@google.com" , "yosry@kernel.org" , "ajones@ventanamicro.com" , "maobibo@loongson.cn" , "tabba@google.com" , "prsampat@amd.com" , "wu.fei9@sanechips.com.cn" , "mlevitsk@redhat.com" , "jmattson@google.com" , "jthoughton@google.com" , "agordeev@linux.ibm.com" , "alex@ghiti.fr" , "aou@eecs.berkeley.edu" , "borntraeger@linux.ibm.com" , "chenhuacai@kernel.org" , "baolu.lu@linux.intel.com" , "dev.jain@arm.com" , "gor@linux.ibm.com" , "hca@linux.ibm.com" , "palmer@dabbelt.com" , "pjw@kernel.org" , "shijie@os.amperecomputing.com" , "svens@linux.ibm.com" , "thuth@redhat.com" , "yang@os.amperecomputing.com" , "Liam.Howlett@oracle.com" , "urezki@gmail.com" , "zhengqi.arch@bytedance.com" , "gerald.schaefer@linux.ibm.com" , "jiayuan.chen@shopee.com" , "lenb@kernel.org" , "pavel@kernel.org" , "rafael@kernel.org" , "yangyicong@hisilicon.com" , "vannapurve@google.com" , "jackmanb@google.com" , "patrick.roy@linux.dev" , "Thomson, Jack" , "Itazuri, Takahiro" , "Manwaring, Derek" , "Kalyazin, Nikita" , Nikita Kalyazin Subject: [PATCH v12 08/16] KVM: x86: define kvm_arch_gmem_supports_no_direct_map() Thread-Topic: [PATCH v12 08/16] KVM: x86: define kvm_arch_gmem_supports_no_direct_map() Thread-Index: AQHcyP1jSNvh4qnnak2U1huEC4ubjw== Date: Fri, 10 Apr 2026 15:19:13 +0000 Message-ID: <20260410151746.61150-9-kalyazin@amazon.com> References: <20260410151746.61150-1-kalyazin@amazon.com> In-Reply-To: <20260410151746.61150-1-kalyazin@amazon.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Patrick Roy =0A= =0A= x86 supports GUEST_MEMFD_FLAG_NO_DIRECT_MAP whenever direct map=0A= modifications are possible. Exclude TDX and SEV-SNP as they access=0A= pages via direct map in certain operations, such as population.=0A= =0A= Signed-off-by: Patrick Roy =0A= Reviewed-by: Ackerley Tng =0A= Reviewed-by: David Hildenbrand (Arm) =0A= Co-developed-by: Nikita Kalyazin =0A= Signed-off-by: Nikita Kalyazin =0A= ---=0A= arch/x86/include/asm/kvm_host.h | 6 ++++++=0A= arch/x86/kvm/x86.c | 7 +++++++=0A= include/linux/kvm_host.h | 9 +++++++++=0A= 3 files changed, 22 insertions(+)=0A= =0A= diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.h=0A= index 6e4e3ef9b8c7..171ce8b84137 100644=0A= --- a/arch/x86/include/asm/kvm_host.h=0A= +++ b/arch/x86/include/asm/kvm_host.h=0A= @@ -28,6 +28,7 @@=0A= #include =0A= #include =0A= #include =0A= +#include =0A= =0A= #include =0A= #include =0A= @@ -2504,4 +2505,9 @@ static inline bool kvm_arch_has_irq_bypass(void)=0A= return enable_device_posted_irqs;=0A= }=0A= =0A= +#ifdef CONFIG_KVM_GUEST_MEMFD=0A= +bool kvm_arch_gmem_supports_no_direct_map(struct kvm *kvm);=0A= +#define kvm_arch_gmem_supports_no_direct_map kvm_arch_gmem_supports_no_dir= ect_map=0A= +#endif /* CONFIG_KVM_GUEST_MEMFD */=0A= +=0A= #endif /* _ASM_X86_KVM_HOST_H */=0A= diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c=0A= index fd1c4a36b593..32da7820823c 100644=0A= --- a/arch/x86/kvm/x86.c=0A= +++ b/arch/x86/kvm/x86.c=0A= @@ -14079,6 +14079,13 @@ void kvm_arch_gmem_invalidate(kvm_pfn_t start, kvm= _pfn_t end)=0A= kvm_x86_call(gmem_invalidate)(start, end);=0A= }=0A= #endif=0A= +=0A= +bool kvm_arch_gmem_supports_no_direct_map(struct kvm *kvm)=0A= +{=0A= + return can_set_direct_map() &&=0A= + kvm->arch.vm_type !=3D KVM_X86_TDX_VM &&=0A= + kvm->arch.vm_type !=3D KVM_X86_SNP_VM;=0A= +}=0A= #endif=0A= =0A= int kvm_spec_ctrl_test_value(u64 value)=0A= diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h=0A= index e8aa3d676c31..ce8c5fdf2752 100644=0A= --- a/include/linux/kvm_host.h=0A= +++ b/include/linux/kvm_host.h=0A= @@ -742,6 +742,15 @@ static inline u64 kvm_gmem_get_supported_flags(struct = kvm *kvm)=0A= }=0A= #endif=0A= =0A= +#ifdef CONFIG_KVM_GUEST_MEMFD=0A= +#ifndef kvm_arch_gmem_supports_no_direct_map=0A= +static inline bool kvm_arch_gmem_supports_no_direct_map(struct kvm *kvm)= =0A= +{=0A= + return false;=0A= +}=0A= +#endif=0A= +#endif /* CONFIG_KVM_GUEST_MEMFD */=0A= +=0A= #ifndef kvm_arch_has_readonly_mem=0A= static inline bool kvm_arch_has_readonly_mem(struct kvm *kvm)=0A= {=0A= -- =0A= 2.50.1=0A= =0A=