Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp866248rwj; Fri, 23 Dec 2022 09:03:33 -0800 (PST) X-Google-Smtp-Source: AMrXdXu4WM4MssU4/RM2M5SjUqVLllLSynbQlNXUXnDP5+JA85Fm8Y4T0zNw43o2Ca4pXYjpbsVJ X-Received: by 2002:a17:902:7207:b0:189:6457:4e14 with SMTP id ba7-20020a170902720700b0018964574e14mr10210899plb.8.1671815013664; Fri, 23 Dec 2022 09:03:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671815013; cv=none; d=google.com; s=arc-20160816; b=EgDWv1UTudbI40uM6H+x8UjyMcqDPAKpGKb1Zmx8MqSKOuEznZRMwA0n+cyONpBXoL d0yitlRKcXsp4yCNi3lWZ8iwhnqS/i6T45AcwpXam3yD3D8YrqAD+zbrjuTOQAdV1mdM Pz/Y3V4oDWk9BQQHyxgjE0W1MfM4GDQsGhPISOaqiwt78mw/kms9+NF8ySwiNdr6Szf4 g2MdiaDvXk92Szv8NGgyG9uwEYvJ7nKKCchG6tzhGfhpR73R3qztPtz9zhYb3jnZECae ONTlaeqZRnjshT5+Hr958qL8bzpXUHHT0PFl7TsIa2d3gdhwJB5iW7SXsvgBr3KcL8HL bFpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=eIrwyfehmxU3S8OfAsjHXXxAvKGYqWtRXnlHsmPvMIs=; b=OVi0oak8ofiHPLmKn8S85g9FDKZWBsJFx4xfmHdNoqNOBpOfWYO3voHIEsJbE+9AxS 1gXUPGUsIPcn6IxWvjnT0eVH1CS+pdeE5qOf3MOZOJHsvgyQPftcKzfKmyO16qw9MH5c HLxX5vHuSf9Sir6TwP0F+NXPJNE9qmFYKVqjEaciMswFBMC6a7M5O1fS2QA2JdJZhluZ cfnqszzs6BA3SFtSzXbPfRPm3ydemrd9WcQPSXBV3Cey3eivHNLPKq/5SzgJmDbszx6m 27ptckhsoXBO3orFIZvOMG3u34jrSRJt78TIQxBLLBkB1iMoA6Z2RlWiglkVIh7ZzHtj FR5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=sQpLqtBZ; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m12-20020a170902db0c00b0018956e3ff71si3966844plx.473.2022.12.23.09.03.13; Fri, 23 Dec 2022 09:03:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=sQpLqtBZ; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231523AbiLWQ5D (ORCPT + 99 others); Fri, 23 Dec 2022 11:57:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230527AbiLWQ5B (ORCPT ); Fri, 23 Dec 2022 11:57:01 -0500 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEE271D3; Fri, 23 Dec 2022 08:56:58 -0800 (PST) Received: from zn.tnic (p5de8e9fe.dip0.t-ipconnect.de [93.232.233.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 62AA51EC0724; Fri, 23 Dec 2022 17:56:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1671814616; 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:in-reply-to:in-reply-to: references:references; bh=eIrwyfehmxU3S8OfAsjHXXxAvKGYqWtRXnlHsmPvMIs=; b=sQpLqtBZNyzt9lCkh02Tv1TArmXNvAYkccThgPqKToX+E4uRVMeRWpB6DQOtn0UgGq7QfH xnfQYy4dQI8JTVvBFgPDRc1+UI8QVqekXcGosVLwwJkrENFYZi9w4fEUexsMn6EYHGTJQO Vhfz7bb9sk0ICgmVHhqqvOh8tEjrjhY= Date: Fri, 23 Dec 2022 17:56:50 +0100 From: Borislav Petkov To: Michael Roth Cc: kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-crypto@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, jroedel@suse.de, thomas.lendacky@amd.com, hpa@zytor.com, ardb@kernel.org, pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, luto@kernel.org, dave.hansen@linux.intel.com, slp@redhat.com, pgonda@google.com, peterz@infradead.org, srinivas.pandruvada@linux.intel.com, rientjes@google.com, dovmurik@linux.ibm.com, tobin@ibm.com, vbabka@suse.cz, kirill@shutemov.name, ak@linux.intel.com, tony.luck@intel.com, marcorr@google.com, sathyanarayanan.kuppuswamy@linux.intel.com, alpergun@google.com, dgilbert@redhat.com, jarkko@kernel.org, ashish.kalra@amd.com, harald@profian.com, Nikunj A Dadhania Subject: Re: [PATCH RFC v7 03/64] KVM: SVM: Advertise private memory support to KVM Message-ID: References: <20221214194056.161492-1-michael.roth@amd.com> <20221214194056.161492-4-michael.roth@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20221214194056.161492-4-michael.roth@amd.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Wed, Dec 14, 2022 at 01:39:55PM -0600, Michael Roth wrote: > + bool (*private_mem_enabled)(struct kvm *kvm); This looks like a function returning boolean to me. IOW, you can simplify this to: diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-x86-ops.h index 82ba4a564e58..4449aeff0dff 100644 --- a/arch/x86/include/asm/kvm-x86-ops.h +++ b/arch/x86/include/asm/kvm-x86-ops.h @@ -129,6 +129,7 @@ KVM_X86_OP(msr_filter_changed) KVM_X86_OP(complete_emulated_msr) KVM_X86_OP(vcpu_deliver_sipi_vector) KVM_X86_OP_OPTIONAL_RET0(vcpu_get_apicv_inhibit_reasons); +KVM_X86_OP_OPTIONAL_RET0(private_mem_enabled); #undef KVM_X86_OP #undef KVM_X86_OP_OPTIONAL diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 1da0474edb2d..1b4b89ddeb55 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1574,6 +1574,7 @@ struct kvm_x86_ops { void (*load_mmu_pgd)(struct kvm_vcpu *vcpu, hpa_t root_hpa, int root_level); + bool (*private_mem_enabled)(struct kvm *kvm); bool (*has_wbinvd_exit)(void); diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index ce362e88a567..73b780fa4653 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4680,6 +4680,14 @@ static int svm_vm_init(struct kvm *kvm) return 0; } +static bool svm_private_mem_enabled(struct kvm *kvm) +{ + if (sev_guest(kvm)) + return kvm->arch.upm_mode; + + return IS_ENABLED(CONFIG_HAVE_KVM_PRIVATE_MEM_TESTING); +} + static struct kvm_x86_ops svm_x86_ops __initdata = { .name = "kvm_amd", @@ -4760,6 +4768,8 @@ static struct kvm_x86_ops svm_x86_ops __initdata = { .vcpu_after_set_cpuid = svm_vcpu_after_set_cpuid, + .private_mem_enabled = svm_private_mem_enabled, + .has_wbinvd_exit = svm_has_wbinvd_exit, .get_l2_tsc_offset = svm_get_l2_tsc_offset, diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 823646d601db..9a1ca59d36a4 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -12556,6 +12556,11 @@ void __user * __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa, } EXPORT_SYMBOL_GPL(__x86_set_memory_region); +bool kvm_arch_has_private_mem(struct kvm *kvm) +{ + return static_call(kvm_x86_private_mem_enabled)(kvm); +} + void kvm_arch_pre_destroy_vm(struct kvm *kvm) { kvm_mmu_pre_destroy_vm(kvm); -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette