Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp2041009rdf; Mon, 6 Nov 2023 03:04:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IG7urv+WGWaOowifv09ZCwUV4hj40wnRRtHAkfbiBWkHbrIOQXWhy0yeVe+0/n0Bi2/ICA0 X-Received: by 2002:a05:6871:8785:b0:1ea:206e:cb10 with SMTP id td5-20020a056871878500b001ea206ecb10mr34229554oab.22.1699268683280; Mon, 06 Nov 2023 03:04:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699268683; cv=none; d=google.com; s=arc-20160816; b=kKDIkfaaB5Gw7cyAXsAX5dqRSvoQPAFj9SF0d7kS1LtPQsDcS0vLMnxdwfTahHC6St GXejFtbGgGJdwyVzr0JO+zNIT+0rTH8L6dhcti/ZR1+H++K8jp6TMYQdF/vhpw1URN5j vyG0v2MwvHQXKQnLYsPV+vGaPayBMdCEIYt0WDNfLRo3spu1D7sEUqWFbcRhPWPC1oFV 6ZWTDWej7E0g+gK7lgmuoBcgNA1ij+UV3V8q/bQDH9uanm5tgLo8yFP95gEbmCku0LAd 8ikEzG1X+gCatjfnFp1xl9LYdlkkimS9pX35ol1rriAg7BWtLYMxNZsDcVH1jjG4Lhzt UW6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:autocrypt :from:references:cc:to:content-language:subject:user-agent :mime-version:date:message-id:dkim-signature; bh=PMg5NrY+vjxLbRnS3SqlrSoMXrcxCGHK0jMnZO5VxDw=; fh=7rJgxVvJ7KQFSAPG5doi0t0kzHx79nCAzg3btSxMdFs=; b=qFxOKxyfHlzLXHRQC0gR1fLwelBeqpvfkGhCNS+3VZhZJ3uFFr/9Ga6pQeE2ngJUUk hku8lrHXZmULie2jg7ecXGewqc2ESBbovVEvciswe4pa5HjDhawSFryBIvQeIZrK8tmq v38skVmSLbj9lswwbAEoi9JAvjdubHVfYMGzMBF4+fnnPf2ukxuurq0mbp4vIWOiBMCm I7+o7ELRHYf97O05afhWkkUXkj7RqhFULEHpvyL+2yu0Ys4l74Fs3OCpxcTYbai0hipk a7mg8LuYuuNyRG9NXKDOhSHdl0v5bxOXej2tyFbaO8tn3jHSvPEnPPQV/D0lZghSgE6b HDXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=A0tpgkDd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id z130-20020a633388000000b005898e10f9b9si7583983pgz.213.2023.11.06.03.04.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 03:04:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=A0tpgkDd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 0D22880A3675; Mon, 6 Nov 2023 03:04:39 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231462AbjKFLEC (ORCPT + 99 others); Mon, 6 Nov 2023 06:04:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231445AbjKFLD6 (ORCPT ); Mon, 6 Nov 2023 06:03:58 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5FD6BE for ; Mon, 6 Nov 2023 03:03:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699268590; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=PMg5NrY+vjxLbRnS3SqlrSoMXrcxCGHK0jMnZO5VxDw=; b=A0tpgkDdNjWp2OJ81ND5V9TrZ7Rq+xmIeiTk7R9nCcfkqnO4mHOz/ykHq1v6wqZythiGdp rQolAErFxUuQ9U032O9M9w7hszfL6swy90daGu9goYb5NFhGyA6rUYZLBM9K+tdiSp5UOe XCdI4WhBwo8PCUdIL7nN4lkHKsuaEBE= Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-479-l88mMXmVPyqD_b8xkYDgTA-1; Mon, 06 Nov 2023 06:03:08 -0500 X-MC-Unique: l88mMXmVPyqD_b8xkYDgTA-1 Received: by mail-lf1-f71.google.com with SMTP id 2adb3069b0e04-507a3426041so4783128e87.0 for ; Mon, 06 Nov 2023 03:03:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699268587; x=1699873387; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PMg5NrY+vjxLbRnS3SqlrSoMXrcxCGHK0jMnZO5VxDw=; b=s2LXa2GdIEEfNFT/BCQP4Y2j5S4VSs2axjm81GEkb7swW0e68XG2lsaz2LG31hJEB3 22uNFU64j/o0693VuAK+SLYXjJItVtYJfu6J19oM+o6nUr+BtUyiBukxZBCryvdUZZpF FTqRHI6knZTc15mhU7gkUnaDu6Tk0bzCdutg9rZmH7AdzCS7Q9BOYv+X12KgcVmb/acO i/i7117W65hhSSwmS0m59yER/7V0k67dxVHhnmZfr5+Kssauo87pvxrrtA+W3Rw6CbgL aosEHmla/B5oztcJL3Yjruj31n33OUzlx9qJ5weDhxyRcY1++OHNiwQoHWGXVLjd7aM2 Z94g== X-Gm-Message-State: AOJu0Yzs4Lc6MtvccTbvxykv5fqhA4i3ryPVVjsWQuoeotyq3VI5hZ3c HuX6VWtS2IkOFM0mWRS6Zlbnqni1hZygoIjSbOz2MZQmo/3m1fhuPbQs6YKPNtw2k+yHecyUckE dWfB4pDdDc5kt/PWTFkmzttjw X-Received: by 2002:a05:6512:39c8:b0:507:ae8b:a573 with SMTP id k8-20020a05651239c800b00507ae8ba573mr28020849lfu.51.1699268587094; Mon, 06 Nov 2023 03:03:07 -0800 (PST) X-Received: by 2002:a05:6512:39c8:b0:507:ae8b:a573 with SMTP id k8-20020a05651239c800b00507ae8ba573mr28020798lfu.51.1699268586630; Mon, 06 Nov 2023 03:03:06 -0800 (PST) Received: from ?IPV6:2001:b07:6468:f312:63a7:c72e:ea0e:6045? ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.googlemail.com with ESMTPSA id o7-20020a5d6847000000b0032f7e832cabsm9104646wrw.90.2023.11.06.03.03.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 06 Nov 2023 03:03:06 -0800 (PST) Message-ID: <5562bf2d-e039-425d-875e-e7ced85dc51a@redhat.com> Date: Mon, 6 Nov 2023 12:03:03 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v13 23/35] KVM: x86: Add support for "protected VMs" that can utilize private memory Content-Language: en-US To: Fuad Tabba , Sean Christopherson Cc: Marc Zyngier , Oliver Upton , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexander Viro , Christian Brauner , "Matthew Wilcox (Oracle)" , Andrew Morton , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Xiaoyao Li , Xu Yilun , Chao Peng , Jarkko Sakkinen , Anish Moorthy , David Matlack , Yu Zhang , Isaku Yamahata , =?UTF-8?B?TWlja2HDq2wgU2FsYcO8?= =?UTF-8?Q?n?= , Vlastimil Babka , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" References: <20231027182217.3615211-1-seanjc@google.com> <20231027182217.3615211-24-seanjc@google.com> From: Paolo Bonzini Autocrypt: addr=pbonzini@redhat.com; keydata= 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 In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 06 Nov 2023 03:04:39 -0800 (PST) On 11/6/23 12:00, Fuad Tabba wrote: > Hi, > > > On Fri, Oct 27, 2023 at 7:23 PM Sean Christopherson wrote: >> >> Add a new x86 VM type, KVM_X86_SW_PROTECTED_VM, to serve as a development >> and testing vehicle for Confidential (CoCo) VMs, and potentially to even >> become a "real" product in the distant future, e.g. a la pKVM. >> >> The private memory support in KVM x86 is aimed at AMD's SEV-SNP and >> Intel's TDX, but those technologies are extremely complex (understatement), >> difficult to debug, don't support running as nested guests, and require >> hardware that's isn't universally accessible. I.e. relying SEV-SNP or TDX > > nit: "that isn't" > > Reviewed-by: Fuad Tabba > Tested-by: Fuad Tabba Hi Fuad, thanks for your reviews and tests of the gmem patches! Can you please continue replying to v14? Thanks, Paolo > Cheers, > /fuad > >> for maintaining guest private memory isn't a realistic option. >> >> At the very least, KVM_X86_SW_PROTECTED_VM will enable a variety of >> selftests for guest_memfd and private memory support without requiring >> unique hardware. >> >> Signed-off-by: Sean Christopherson >> --- >> Documentation/virt/kvm/api.rst | 32 ++++++++++++++++++++++++++++++++ >> arch/x86/include/asm/kvm_host.h | 15 +++++++++------ >> arch/x86/include/uapi/asm/kvm.h | 3 +++ >> arch/x86/kvm/Kconfig | 12 ++++++++++++ >> arch/x86/kvm/mmu/mmu_internal.h | 1 + >> arch/x86/kvm/x86.c | 16 +++++++++++++++- >> include/uapi/linux/kvm.h | 1 + >> virt/kvm/Kconfig | 5 +++++ >> 8 files changed, 78 insertions(+), 7 deletions(-) >> >> diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst >> index 38dc1fda4f45..00029436ac5b 100644 >> --- a/Documentation/virt/kvm/api.rst >> +++ b/Documentation/virt/kvm/api.rst >> @@ -147,10 +147,29 @@ described as 'basic' will be available. >> The new VM has no virtual cpus and no memory. >> You probably want to use 0 as machine type. >> >> +X86: >> +^^^^ >> + >> +Supported X86 VM types can be queried via KVM_CAP_VM_TYPES. >> + >> +S390: >> +^^^^^ >> + >> In order to create user controlled virtual machines on S390, check >> KVM_CAP_S390_UCONTROL and use the flag KVM_VM_S390_UCONTROL as >> privileged user (CAP_SYS_ADMIN). >> >> +MIPS: >> +^^^^^ >> + >> +To use hardware assisted virtualization on MIPS (VZ ASE) rather than >> +the default trap & emulate implementation (which changes the virtual >> +memory layout to fit in user mode), check KVM_CAP_MIPS_VZ and use the >> +flag KVM_VM_MIPS_VZ. >> + >> +ARM64: >> +^^^^^^ >> + >> On arm64, the physical address size for a VM (IPA Size limit) is limited >> to 40bits by default. The limit can be configured if the host supports the >> extension KVM_CAP_ARM_VM_IPA_SIZE. When supported, use >> @@ -8650,6 +8669,19 @@ block sizes is exposed in KVM_CAP_ARM_SUPPORTED_BLOCK_SIZES as a >> 64-bit bitmap (each bit describing a block size). The default value is >> 0, to disable the eager page splitting. >> >> +8.41 KVM_CAP_VM_TYPES >> +--------------------- >> + >> +:Capability: KVM_CAP_MEMORY_ATTRIBUTES >> +:Architectures: x86 >> +:Type: system ioctl >> + >> +This capability returns a bitmap of support VM types. The 1-setting of bit @n >> +means the VM type with value @n is supported. Possible values of @n are:: >> + >> + #define KVM_X86_DEFAULT_VM 0 >> + #define KVM_X86_SW_PROTECTED_VM 1 >> + >> 9. Known KVM API problems >> ========================= >> >> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h >> index f9e8d5642069..dff10051e9b6 100644 >> --- a/arch/x86/include/asm/kvm_host.h >> +++ b/arch/x86/include/asm/kvm_host.h >> @@ -1244,6 +1244,7 @@ enum kvm_apicv_inhibit { >> }; >> >> struct kvm_arch { >> + unsigned long vm_type; >> unsigned long n_used_mmu_pages; >> unsigned long n_requested_mmu_pages; >> unsigned long n_max_mmu_pages; >> @@ -2077,6 +2078,12 @@ void kvm_mmu_new_pgd(struct kvm_vcpu *vcpu, gpa_t new_pgd); >> void kvm_configure_mmu(bool enable_tdp, int tdp_forced_root_level, >> int tdp_max_root_level, int tdp_huge_page_level); >> >> +#ifdef CONFIG_KVM_PRIVATE_MEM >> +#define kvm_arch_has_private_mem(kvm) ((kvm)->arch.vm_type != KVM_X86_DEFAULT_VM) >> +#else >> +#define kvm_arch_has_private_mem(kvm) false >> +#endif >> + >> static inline u16 kvm_read_ldt(void) >> { >> u16 ldt; >> @@ -2125,14 +2132,10 @@ enum { >> #define HF_SMM_INSIDE_NMI_MASK (1 << 2) >> >> # define KVM_MAX_NR_ADDRESS_SPACES 2 >> +/* SMM is currently unsupported for guests with private memory. */ >> +# define kvm_arch_nr_memslot_as_ids(kvm) (kvm_arch_has_private_mem(kvm) ? 1 : 2) >> # define kvm_arch_vcpu_memslots_id(vcpu) ((vcpu)->arch.hflags & HF_SMM_MASK ? 1 : 0) >> # define kvm_memslots_for_spte_role(kvm, role) __kvm_memslots(kvm, (role).smm) >> - >> -static inline int kvm_arch_nr_memslot_as_ids(struct kvm *kvm) >> -{ >> - return KVM_MAX_NR_ADDRESS_SPACES; >> -} >> - >> #else >> # define kvm_memslots_for_spte_role(kvm, role) __kvm_memslots(kvm, 0) >> #endif >> diff --git a/arch/x86/include/uapi/asm/kvm.h b/arch/x86/include/uapi/asm/kvm.h >> index 1a6a1f987949..a448d0964fc0 100644 >> --- a/arch/x86/include/uapi/asm/kvm.h >> +++ b/arch/x86/include/uapi/asm/kvm.h >> @@ -562,4 +562,7 @@ struct kvm_pmu_event_filter { >> /* x86-specific KVM_EXIT_HYPERCALL flags. */ >> #define KVM_EXIT_HYPERCALL_LONG_MODE BIT(0) >> >> +#define KVM_X86_DEFAULT_VM 0 >> +#define KVM_X86_SW_PROTECTED_VM 1 >> + >> #endif /* _ASM_X86_KVM_H */ >> diff --git a/arch/x86/kvm/Kconfig b/arch/x86/kvm/Kconfig >> index 091b74599c22..8452ed0228cb 100644 >> --- a/arch/x86/kvm/Kconfig >> +++ b/arch/x86/kvm/Kconfig >> @@ -77,6 +77,18 @@ config KVM_WERROR >> >> If in doubt, say "N". >> >> +config KVM_SW_PROTECTED_VM >> + bool "Enable support for KVM software-protected VMs" >> + depends on EXPERT >> + depends on X86_64 >> + select KVM_GENERIC_PRIVATE_MEM >> + help >> + Enable support for KVM software-protected VMs. Currently "protected" >> + means the VM can be backed with memory provided by >> + KVM_CREATE_GUEST_MEMFD. >> + >> + If unsure, say "N". >> + >> config KVM_INTEL >> tristate "KVM for Intel (and compatible) processors support" >> depends on KVM && IA32_FEAT_CTL >> diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h >> index 86c7cb692786..b66a7d47e0e4 100644 >> --- a/arch/x86/kvm/mmu/mmu_internal.h >> +++ b/arch/x86/kvm/mmu/mmu_internal.h >> @@ -297,6 +297,7 @@ static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, >> .max_level = KVM_MAX_HUGEPAGE_LEVEL, >> .req_level = PG_LEVEL_4K, >> .goal_level = PG_LEVEL_4K, >> + .is_private = kvm_mem_is_private(vcpu->kvm, cr2_or_gpa >> PAGE_SHIFT), >> }; >> int r; >> >> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c >> index c4d17727b199..e3eb608b6692 100644 >> --- a/arch/x86/kvm/x86.c >> +++ b/arch/x86/kvm/x86.c >> @@ -4441,6 +4441,13 @@ static int kvm_ioctl_get_supported_hv_cpuid(struct kvm_vcpu *vcpu, >> return 0; >> } >> >> +static bool kvm_is_vm_type_supported(unsigned long type) >> +{ >> + return type == KVM_X86_DEFAULT_VM || >> + (type == KVM_X86_SW_PROTECTED_VM && >> + IS_ENABLED(CONFIG_KVM_SW_PROTECTED_VM) && tdp_enabled); >> +} >> + >> int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) >> { >> int r = 0; >> @@ -4632,6 +4639,11 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) >> case KVM_CAP_X86_NOTIFY_VMEXIT: >> r = kvm_caps.has_notify_vmexit; >> break; >> + case KVM_CAP_VM_TYPES: >> + r = BIT(KVM_X86_DEFAULT_VM); >> + if (kvm_is_vm_type_supported(KVM_X86_SW_PROTECTED_VM)) >> + r |= BIT(KVM_X86_SW_PROTECTED_VM); >> + break; >> default: >> break; >> } >> @@ -12314,9 +12326,11 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) >> int ret; >> unsigned long flags; >> >> - if (type) >> + if (!kvm_is_vm_type_supported(type)) >> return -EINVAL; >> >> + kvm->arch.vm_type = type; >> + >> ret = kvm_page_track_init(kvm); >> if (ret) >> goto out; >> diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h >> index 29e9eb51dec9..5b5820d19e71 100644 >> --- a/include/uapi/linux/kvm.h >> +++ b/include/uapi/linux/kvm.h >> @@ -1218,6 +1218,7 @@ struct kvm_ppc_resize_hpt { >> #define KVM_CAP_MEMORY_FAULT_INFO 231 >> #define KVM_CAP_MEMORY_ATTRIBUTES 232 >> #define KVM_CAP_GUEST_MEMFD 233 >> +#define KVM_CAP_VM_TYPES 234 >> >> #ifdef KVM_CAP_IRQ_ROUTING >> >> diff --git a/virt/kvm/Kconfig b/virt/kvm/Kconfig >> index 08afef022db9..2c964586aa14 100644 >> --- a/virt/kvm/Kconfig >> +++ b/virt/kvm/Kconfig >> @@ -104,3 +104,8 @@ config KVM_GENERIC_MEMORY_ATTRIBUTES >> config KVM_PRIVATE_MEM >> select XARRAY_MULTI >> bool >> + >> +config KVM_GENERIC_PRIVATE_MEM >> + select KVM_GENERIC_MEMORY_ATTRIBUTES >> + select KVM_PRIVATE_MEM >> + bool >> -- >> 2.42.0.820.g83a721a137-goog >> >