From nobody Thu Dec 18 10:37:39 2025 Received: from fra-out-013.esa.eu-central-1.outbound.mail-perimeter.amazon.com (fra-out-013.esa.eu-central-1.outbound.mail-perimeter.amazon.com [63.178.132.221]) (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 13E143358A7; Fri, 5 Dec 2025 16:59:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=63.178.132.221 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764953973; cv=none; b=q1XZZALvmtGGABlDZabZYOd+tP84MyD9r6oLUw5gLx4Ux7Sb68JMYQd0Ae7EpyRt188ACv84z5/33Qimf2ccyilqetE2HWjrpye9FMVT4h3k/KN1S7nkdFkFsI+iWiIYM8TrneRR/ztFquW+ZonoaCHDlfa5bSTlZ6DI1lAtmwA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764953973; c=relaxed/simple; bh=Ll4+gFY6xgocJ4sAVlTLpUB/YiZ64ywS7lKYvFBu4Ts=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=jSSw4W9prjlLqViQj2TCPuMo11Kgtp+y5UJoU4SANJr7Q8F0njv/a/qpX4dz5kB8gCpvhxToQYKD8lx1psWbYFmsYbw1nOkVMKE/Jh/zdtyuGoEjZ4eKaJh6NkSBWsC/84AH2K5qo5kV7Ng4EnvbdIhIua6y1ro3JCEC3cFD7uE= 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=KLFJbW22; arc=none smtp.client-ip=63.178.132.221 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="KLFJbW22" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.co.uk; i=@amazon.co.uk; q=dns/txt; s=amazoncorp2; t=1764953958; x=1796489958; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=W7GJfZU7LO05jHXKZKMobVu/d9jql0a0jk/2tfUdHpg=; b=KLFJbW22vyfwNVbyIQN4+0IxkgGvNkOaEFh20/znrD3A4aAqfRYAqTMs AqmNsvaT7NA1LN9+ufJNdBPyDcF3brZQB22teOlveVtA7nh8TcwMqlQAj eY/5nU19BJutLC97dr+6UQjiGv3VaFW6pBikaKESgpVlC2rgcIBzxP+3x b7VZ/AbyAip6VKNy6gnMF7oodo6iKqR4aQyUVMBDaBfZOHpfjkGCOV7jW 47bkh3xczOAepRg4O0SuY5PCGTxbBswdg5eZ2zzDC2dU23IdXd4P7kH34 VqLALsBm4oxdF9ZuIgMg4aHwCUx3xYYKx8ORkeL0N2MEF1jH9QHasEoNN A==; X-CSE-ConnectionGUID: UrLe81L+QuOcbGqQwPNB0A== X-CSE-MsgGUID: 9doc33xfT2uUuc+3NSn9iA== X-IronPort-AV: E=Sophos;i="6.20,252,1758585600"; d="scan'208";a="6196628" Received: from ip-10-6-11-83.eu-central-1.compute.internal (HELO smtpout.naws.eu-central-1.prod.farcaster.email.amazon.dev) ([10.6.11.83]) by internal-fra-out-013.esa.eu-central-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Dec 2025 16:59:07 +0000 Received: from EX19MTAEUB001.ant.amazon.com [54.240.197.234:25054] by smtpin.naws.eu-central-1.prod.farcaster.email.amazon.dev [10.0.45.40:2525] with esmtp (Farcaster) id 207ea9c1-766b-47ab-853b-ca8cb9de4fa5; Fri, 5 Dec 2025 16:59:07 +0000 (UTC) X-Farcaster-Flow-ID: 207ea9c1-766b-47ab-853b-ca8cb9de4fa5 Received: from EX19D005EUB002.ant.amazon.com (10.252.51.103) by EX19MTAEUB001.ant.amazon.com (10.252.51.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.29; Fri, 5 Dec 2025 16:59:07 +0000 Received: from EX19D005EUB003.ant.amazon.com (10.252.51.31) by EX19D005EUB002.ant.amazon.com (10.252.51.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.29; Fri, 5 Dec 2025 16:59:06 +0000 Received: from EX19D005EUB003.ant.amazon.com ([fe80::b825:becb:4b38:da0c]) by EX19D005EUB003.ant.amazon.com ([fe80::b825:becb:4b38:da0c%3]) with mapi id 15.02.2562.029; Fri, 5 Dec 2025 16:59:06 +0000 From: "Kalyazin, Nikita" To: "kvm@vger.kernel.org" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "kvmarm@lists.linux.dev" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" , "bpf@vger.kernel.org" , "linux-kselftest@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@linutronix.de" , "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" , "Liam.Howlett@oracle.com" , "vbabka@suse.cz" , "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" , "shuah@kernel.org" , "riel@surriel.com" , "baohua@kernel.org" , "ryan.roberts@arm.com" , "jgross@suse.com" , "yu-cheng.yu@intel.com" , "kas@kernel.org" , "coxu@redhat.com" , "kevin.brodsky@arm.com" , "ackerleytng@google.com" , "maobibo@loongson.cn" , "prsampat@amd.com" , "mlevitsk@redhat.com" , "isaku.yamahata@intel.com" , "jmattson@google.com" , "jthoughton@google.com" , "linux-arm-kernel@lists.infradead.org" , "vannapurve@google.com" , "jackmanb@google.com" , "aneesh.kumar@kernel.org" , "patrick.roy@linux.dev" , "Thomson, Jack" , "Itazuri, Takahiro" , "Manwaring, Derek" , "Cali, Marco" , "Kalyazin, Nikita" Subject: [PATCH v8 07/13] KVM: arm64: define kvm_arch_gmem_supports_no_direct_map() Thread-Topic: [PATCH v8 07/13] KVM: arm64: define kvm_arch_gmem_supports_no_direct_map() Thread-Index: AQHcZgh3WLdsPS6cE06bWor8xc18DA== Date: Fri, 5 Dec 2025 16:59:06 +0000 Message-ID: <20251205165743.9341-8-kalyazin@amazon.com> References: <20251205165743.9341-1-kalyazin@amazon.com> In-Reply-To: <20251205165743.9341-1-kalyazin@amazon.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Patrick Roy Support for GUEST_MEMFD_FLAG_NO_DIRECT_MAP on arm64 depends on 1) direct map manipulations at 4k granularity being possible, and 2) FEAT_S2FWB. 1) is met whenever the direct map is set up at 4k granularity (e.g. not with huge/gigantic pages) at boottime, as due to ARM's break-before-make semantics, breaking huge mappings into 4k mappings in the direct map is not possible (BBM would require temporary invalidation of the entire huge mapping, even if only a 4k subrange should be zapped, which will probably crash the kernel). However, current defconfigs select for example CONFIG_RO_DATA_FULL_DEFAULT_ENABLED, which forces a 4k direct map. 2) is required to allow KVM to elide cache coherency operations when installing stage 2 page tables, which require the direct map to be entry for the newly mapped memory to be present (which it will not be, as guest_memfd would have removed direct map entries in kvm_gmem_get_pfn()). Cc: Will Deacon Signed-off-by: Patrick Roy Signed-off-by: Nikita Kalyazin --- arch/arm64/include/asm/kvm_host.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm= _host.h index ac7f970c7883..d431ca7d4fc9 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -1654,5 +1655,17 @@ static __always_inline enum fgt_group_id __fgt_reg_t= o_group_id(enum vcpu_sysreg \ p; \ }) +#ifdef CONFIG_KVM_GUEST_MEMFD +static inline bool kvm_arch_gmem_supports_no_direct_map(void) +{ + /* + * Without FWB, direct map access is needed in kvm_pgtable_stage2_map(), + * as it calls dcache_clean_inval_poc(). + */ + return can_set_direct_map() && cpus_have_final_cap(ARM64_HAS_STAGE2_FWB); +} +#define kvm_arch_gmem_supports_no_direct_map kvm_arch_gmem_supports_no_dir= ect_map +#endif /* CONFIG_KVM_GUEST_MEMFD */ + =20 #endif /* __ARM64_KVM_HOST_H__ */ --=20 2.50.1