From patchwork Wed Jan 22 15:27:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13947435 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F23AC02182 for ; Wed, 22 Jan 2025 15:28:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 958646B009C; Wed, 22 Jan 2025 10:27:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E21B280002; Wed, 22 Jan 2025 10:27:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 75E9F280001; Wed, 22 Jan 2025 10:27:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 561626B009C for ; Wed, 22 Jan 2025 10:27:59 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 1E7DCA0342 for ; Wed, 22 Jan 2025 15:27:59 +0000 (UTC) X-FDA: 83035468278.23.E636E85 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf20.hostedemail.com (Postfix) with ESMTP id 459561C0018 for ; Wed, 22 Jan 2025 15:27:57 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=2ge24xzW; spf=pass (imf20.hostedemail.com: domain of 3ew6RZwUKCCAP6776CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--tabba.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=3ew6RZwUKCCAP6776CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737559677; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=5uY+HDVZ7Dp1D+/uAf3D/YK52BSVzxXpdvAU1b299wE=; b=FLSDIcRiSLJx0NjJ5pdwzXSuKVugmiCrVuBSZ81UtYl8Wl+vuKazXWKK7LFr94KTT8N0sx SB8Jnk92oJFjo3+oJn8hPQbgNyfypJFQfJtkKLS2WGL0IjM4y6enf6Enfbzbo+k0j+5ezH KiBDM4Mo+0sa9n+BCI1dbtx65na28Rg= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=2ge24xzW; spf=pass (imf20.hostedemail.com: domain of 3ew6RZwUKCCAP6776CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--tabba.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=3ew6RZwUKCCAP6776CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737559677; a=rsa-sha256; cv=none; b=wDer446tgwZGz2SYGb+JqOKOsMN2A0q0r27aP6L+e3WtnB8cRDwl2duP4qq60Tnp5O+yfp +rIauO4q1h7jFbedX1Tb8818mWx8yvp+5BbuPIGMXsWYwjmjlkSvSz1ZYMFb3YmrTxHuP5 P1C+ZIHqM7MBWZ3UOqRT6/w1NLWsOy4= Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-4362153dcd6so36915475e9.2 for ; Wed, 22 Jan 2025 07:27:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737559676; x=1738164476; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=5uY+HDVZ7Dp1D+/uAf3D/YK52BSVzxXpdvAU1b299wE=; b=2ge24xzW+ityfS9uZ+cNTeaDyZVRrdYdMfDuPWEeUNVACbrCajpO3FnyTQVbENfp5Q 9g5N1NHeairXZc9vkmUSEJv2vkvi4XZQwIyWPLG2HXCpgPNgTDUbO6EcH21NxSL/xosy TWu4/y45D3HRGzB5nSgYRmGPPeEEQZYNp8o8YyusqBh73DseaeSmuJzIEXn31fJ63rNC pM81bETmiwbpgoE7xEIF1WQL5NCKdZXgqwBw99HgSaLyLvxbwjCpWMzX5bBxsT+zez/W ql284hiGJsWX5vU5lUUNsTtYrwVRs3Yltlw+mkhvz6oCCJyQttrm2eSjlbazaS/8ZLnO w9Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737559676; x=1738164476; h=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; bh=5uY+HDVZ7Dp1D+/uAf3D/YK52BSVzxXpdvAU1b299wE=; b=ZJbT1IxJ1nXhBmaQceOVR7+LHkV2bZgzleL2qdY3nlWZzAYC54m3aDwjw449gJwaEC z+x7Z23ewGm2Lv/AA212CzAILZIO/NyNDV22KvD1CmFz6/4cuA1hBP8Q0ick5Q2legSx 37FvGRmmTTFOgbyEtA58WyOhEInBItsQgjPjLnlLLDttRUrsSR8KylsiUtgPer8ytnnY W/yueuSIzGMnrNPfAI8Ol6xxi4Lh4iUKDdiPN1cQ5MdFQMYQ+moPlqHQVs/JwnW1gQf3 VU3C/vXUytiBJbPn477H/DnnBiOrfuf0aEpLHvPl1yA6sBIzkCsc0ISJ1cS2QI/zVoFs o3XQ== X-Forwarded-Encrypted: i=1; AJvYcCWNnCLM5K/vflVc3I/Ty2OJwwytKxxCG0vEnXFp08/aJZCvdYBMHTyE/M4SK33wzd8LKuj+y1h8rg==@kvack.org X-Gm-Message-State: AOJu0YwnqIY1OuIGLVtvdEKgSP6G712cBGfrXZJE8SkUY4eyMpJvV4Wm hQZogqLjZngjmpt6UiWm6B09XQAHZEmA2dDqjJHo+ENeQxVz9Cuk3RX/9whIqBsUVTpMnAWjvw= = X-Google-Smtp-Source: AGHT+IF2hKFLXA7PBCoJ+LiMdi1Un48iNomJH581YLTvT7wM4Qq5KK+uhWlMUrwC1rIHE2BbM0N2m173nA== X-Received: from wmom15.prod.google.com ([2002:a05:600c:460f:b0:436:1a60:654e]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4894:b0:434:a7e7:a1ca with SMTP id 5b1f17b1804b1-43891427762mr182016925e9.20.1737559675909; Wed, 22 Jan 2025 07:27:55 -0800 (PST) Date: Wed, 22 Jan 2025 15:27:36 +0000 In-Reply-To: <20250122152738.1173160-1-tabba@google.com> Mime-Version: 1.0 References: <20250122152738.1173160-1-tabba@google.com> X-Mailer: git-send-email 2.48.0.rc2.279.g1de40edade-goog Message-ID: <20250122152738.1173160-8-tabba@google.com> Subject: [RFC PATCH v1 7/9] KVM: arm64: Introduce KVM_VM_TYPE_ARM_SW_PROTECTED machine type From: Fuad Tabba To: kvm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mm@kvack.org Cc: pbonzini@redhat.com, chenhuacai@kernel.org, mpe@ellerman.id.au, anup@brainfault.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, viro@zeniv.linux.org.uk, brauner@kernel.org, willy@infradead.org, akpm@linux-foundation.org, xiaoyao.li@intel.com, yilun.xu@intel.com, chao.p.peng@linux.intel.com, jarkko@kernel.org, amoorthy@google.com, dmatlack@google.com, yu.c.zhang@linux.intel.com, isaku.yamahata@intel.com, mic@digikod.net, vbabka@suse.cz, vannapurve@google.com, ackerleytng@google.com, mail@maciej.szmigiero.name, david@redhat.com, michael.roth@amd.com, wei.w.wang@intel.com, liam.merwick@oracle.com, isaku.yamahata@gmail.com, kirill.shutemov@linux.intel.com, suzuki.poulose@arm.com, steven.price@arm.com, quic_eberman@quicinc.com, quic_mnalajal@quicinc.com, quic_tsoni@quicinc.com, quic_svaddagi@quicinc.com, quic_cvanscha@quicinc.com, quic_pderrin@quicinc.com, quic_pheragu@quicinc.com, catalin.marinas@arm.com, james.morse@arm.com, yuzenghui@huawei.com, oliver.upton@linux.dev, maz@kernel.org, will@kernel.org, qperret@google.com, keirf@google.com, roypat@amazon.co.uk, shuah@kernel.org, hch@infradead.org, jgg@nvidia.com, rientjes@google.com, jhubbard@nvidia.com, fvdl@google.com, hughd@google.com, jthoughton@google.com, tabba@google.com X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 459561C0018 X-Stat-Signature: hrjzqjxpkj6eohhb79nna1i3b6mefxr1 X-Rspam-User: X-HE-Tag: 1737559677-888155 X-HE-Meta: U2FsdGVkX18UIdi09RgG6VOnXn4JjHsRUzSWiJtQMXWeUxZeQ2B+dP271hv2vIQZr5aUsa6fMAYDQS3+XUHMEiE2NgGSx993wjPdj2QK6Wan2hoGzgQvM6+aOnC88AZdAP5x8jmpmllqF5PgoR5pDSfcQ3KPazsPMkGzdiHQYejBSyBaV9tqYtVdCiqhukaf6SRqaHmETelpZVD5v67/kz2ET5s5FOzu8wpOMsxy59srDutissb2VvIUTue8ErmdqiTYiDxaaArQRHsl6NVUQZJVBjxZ39cP+pAzEjduIV0uQqiq9S/xZ6hiJUB8XChmR5rRKvalYsmXgUHBLKAuGLfX+TJ2c3/m+Zl9MhAj+Km6K58jS9FfXyysJCRxsIgvK3NCbIRDK2d6dAbVfdLwEMuGKoajcVUJVfiEoq8zSFtYBGx5XtrGBsWmkk3msSY+dGXPWE71vYeVy7NPbHZ91TVb6UK3fWp5Hcuv4RG814Tmw797tf7Z7yXjJLJ0kkm5qb8xH1h1YDctymFLi1VrVB+hsqG7BCbLM/7OFiI92CPRN0cfHg91B4QAn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iXuRihBkPYWg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Introduce a new virtual machine type, KVM_VM_TYPE_ARM_SW_PROTECTED, to serve as a development and testing vehicle for Confidential (CoCo) VMs, similar to the x86 KVM_X86_SW_PROTECTED_VM type. Initially, this is used to test guest_memfd without needing any underlying protection. Similar to the x86 type, this is currently only for development and testing. Do not use KVM_VM_TYPE_ARM_SW_PROTECTED for "real" VMs, and especially not in production. The behavior and effective ABI for software-protected VMs is unstable. Signed-off-by: Fuad Tabba --- Documentation/virt/kvm/api.rst | 5 +++++ arch/arm64/include/asm/kvm_host.h | 10 ++++++++++ arch/arm64/kvm/arm.c | 5 +++++ arch/arm64/kvm/mmu.c | 3 --- include/uapi/linux/kvm.h | 6 ++++++ 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index f15b61317aad..7953b07c8c2b 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -214,6 +214,11 @@ exposed by the guest CPUs in ID_AA64MMFR0_EL1[PARange]. It only affects size of the address translated by the stage2 level (guest physical to host physical address translations). +KVM_VM_TYPE_ARM_SW_PROTECTED is currently only for development and testing of +confidential VMs without having underlying support. Do not use +KVM_VM_TYPE_ARM_SW_PROTECTED for "real" VMs, and especially not in production. +The behavior and effective ABI for software-protected VMs is unstable. + 4.3 KVM_GET_MSR_INDEX_LIST, KVM_GET_MSR_FEATURE_INDEX_LIST ---------------------------------------------------------- diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index e18e9244d17a..2fdc7e24ae8e 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -380,6 +380,8 @@ struct kvm_arch { * the associated pKVM instance in the hypervisor. */ struct kvm_protected_vm pkvm; + + unsigned long vm_type; }; struct kvm_vcpu_fault_info { @@ -1529,4 +1531,12 @@ void kvm_set_vm_id_reg(struct kvm *kvm, u32 reg, u64 val); #define kvm_has_s1poe(k) \ (kvm_has_feat((k), ID_AA64MMFR3_EL1, S1POE, IMP)) +#define kvm_arch_has_private_mem(kvm) \ + (IS_ENABLED(CONFIG_KVM_PRIVATE_MEM) && \ + ((kvm)->arch.vm_type & KVM_VM_TYPE_ARM_SW_PROTECTED)) + +#define kvm_arch_private_mem_inplace(kvm) \ + (IS_ENABLED(CONFIG_KVM_GMEM_MAPPABLE) && \ + ((kvm)->arch.vm_type & KVM_VM_TYPE_ARM_SW_PROTECTED)) + #endif /* __ARM64_KVM_HOST_H__ */ diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index a102c3aebdbc..ecdb8db619d8 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -171,6 +171,9 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) { int ret; + if (type & ~KVM_VM_TYPE_MASK) + return -EINVAL; + mutex_init(&kvm->arch.config_lock); #ifdef CONFIG_LOCKDEP @@ -212,6 +215,8 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) bitmap_zero(kvm->arch.vcpu_features, KVM_VCPU_MAX_FEATURES); + kvm->arch.vm_type = type; + return 0; err_free_cpumask: diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index adf23618e2a0..b6cbe11dea48 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -869,9 +869,6 @@ static int kvm_init_ipa_range(struct kvm_s2_mmu *mmu, unsigned long type) u64 mmfr0, mmfr1; u32 phys_shift; - if (type & ~KVM_VM_TYPE_ARM_IPA_SIZE_MASK) - return -EINVAL; - phys_shift = KVM_VM_TYPE_ARM_IPA_SIZE(type); if (is_protected_kvm_enabled()) { phys_shift = kvm_ipa_limit; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 021f8ef9979b..5e10a5903a58 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -656,6 +656,12 @@ struct kvm_enable_cap { #define KVM_VM_TYPE_ARM_IPA_SIZE_MASK 0xffULL #define KVM_VM_TYPE_ARM_IPA_SIZE(x) \ ((x) & KVM_VM_TYPE_ARM_IPA_SIZE_MASK) + +#define KVM_VM_TYPE_ARM_SW_PROTECTED (1UL << 9) + +#define KVM_VM_TYPE_MASK (KVM_VM_TYPE_ARM_IPA_SIZE_MASK | \ + KVM_VM_TYPE_ARM_SW_PROTECTED) + /* * ioctls for /dev/kvm fds: */