From patchwork Thu Jan 14 00:36:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12018149 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9606EC433E9 for ; Thu, 14 Jan 2021 01:48:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 621422343B for ; Thu, 14 Jan 2021 01:48:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728372AbhANBsV (ORCPT ); Wed, 13 Jan 2021 20:48:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727222AbhANAjv (ORCPT ); Wed, 13 Jan 2021 19:39:51 -0500 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAA31C0617A5 for ; Wed, 13 Jan 2021 16:37:42 -0800 (PST) Received: by mail-qt1-x84a.google.com with SMTP id b8so2961936qtr.18 for ; Wed, 13 Jan 2021 16:37:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=Yn6K+Al6keU4qwvbVZAct8COFyc60/5tuafg8uWsv9s=; b=GS6+9cj6bVKPfRttuQ0OZ/gu/AsdxWthI6birI03VxeJb329XZwukIQq4bqq7K4gJS j91y+ixUlBa+XlE8v7BJbEh3opw0dlXyeMZ1gAX0edJAlFapMSehK/ME8xkZrOE1bxEc 4LHRU4RdoHMq7krywcO/0tV5tsJIBWHXX+J/TSWdRUf6KwSb3QCz2L4EKvZ5r19Vvmlg 7cJxtmSqa/q2cFomiqcWZzaNpDI/BOzwCdqrtJEMx4QT6iA5ODADGquyUKIe1R+NVmq0 kMVppEH/pbzbWNzt7gTer5fwzh9t2qzV5HiXMaEO1s/zpPQBfoyf/nH4520yX7ychR6A vF3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=Yn6K+Al6keU4qwvbVZAct8COFyc60/5tuafg8uWsv9s=; b=l0jfibOHEWUEk31wuEPZMci5o7gEDtzcALjn4qJFiGodbkn75BfNl/8zruIaXiB+EZ fUOKurg3RvMy2Epxjkk7FvKYO5BthbjEL9MnRU+bdykvp3iuN6iMM8fNvPMKdWuQmnnS C5NJAlQ6HaDyY/0oUhjAADIHzFWDyTjjEnxqkFR2cF28lOP7FoRGRZ/nUQ1VmYOM5gFE pvadlv4tI0dwiO7DKZDdZ8Ujt6eaLGIkMp0QEAUsM7ODFwXl80ANNjbPuPx8r3Lc9ZDw Ei31DwnYC7y+JpPqvpVYMU7ldxwNzRAa5dzM7+TWd3Kf7CToTQEnlOy77JUCQPcL5/Kr qLsg== X-Gm-Message-State: AOAM530KjBB63Vd/TuB5U9a1lwyL/j5bi1b8q8eXvst1ydeIzYkSf//j PsZ5TP+BddUYHF2qaFNecB3IQWgVef0= X-Google-Smtp-Source: ABdhPJwET5/FgHxggwO9NJkiIa/7tDnom5JB75FWqiMIu+CYa8J3rxhBsOEsUoDXlnwDytx02ooiXilB3kI= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:1ea0:b8ff:fe73:50f5]) (user=seanjc job=sendgmr) by 2002:a0c:8445:: with SMTP id l63mr4984501qva.60.1610584662011; Wed, 13 Jan 2021 16:37:42 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 13 Jan 2021 16:36:57 -0800 In-Reply-To: <20210114003708.3798992-1-seanjc@google.com> Message-Id: <20210114003708.3798992-4-seanjc@google.com> Mime-Version: 1.0 References: <20210114003708.3798992-1-seanjc@google.com> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog Subject: [PATCH v2 03/14] KVM: SVM: Move SEV module params/variables to sev.c From: Sean Christopherson To: Paolo Bonzini , Dave Hansen , Andy Lutomirski , Peter Zijlstra Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Borislav Petkov , Tom Lendacky , Brijesh Singh Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Unconditionally invoke sev_hardware_setup() when configuring SVM and handle clearing the module params/variable 'sev' and 'sev_es' in sev_hardware_setup(). This allows making said variables static within sev.c and reduces the odds of a collision with guest code, e.g. the guest side of things has already laid claim to 'sev_enabled'. Signed-off-by: Sean Christopherson Reviewed-by: Tom Lendacky Reviewed-by: Brijesh Singh --- arch/x86/kvm/svm/sev.c | 11 +++++++++++ arch/x86/kvm/svm/svm.c | 15 +-------------- arch/x86/kvm/svm/svm.h | 2 -- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 0eeb6e1b803d..8ba93b8fa435 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -27,6 +27,14 @@ #define __ex(x) __kvm_handle_fault_on_reboot(x) +/* enable/disable SEV support */ +static int sev = IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT); +module_param(sev, int, 0444); + +/* enable/disable SEV-ES support */ +static int sev_es = IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT); +module_param(sev_es, int, 0444); + static u8 sev_enc_bit; static int sev_flush_asids(void); static DECLARE_RWSEM(sev_deactivate_lock); @@ -1249,6 +1257,9 @@ void __init sev_hardware_setup(void) bool sev_es_supported = false; bool sev_supported = false; + if (!IS_ENABLED(CONFIG_KVM_AMD_SEV) || !sev) + goto out; + /* Does the CPU support SEV? */ if (!boot_cpu_has(X86_FEATURE_SEV)) goto out; diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index ccf52c5531fb..f89f702b2a58 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -189,14 +189,6 @@ module_param(vls, int, 0444); static int vgif = true; module_param(vgif, int, 0444); -/* enable/disable SEV support */ -int sev = IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT); -module_param(sev, int, 0444); - -/* enable/disable SEV-ES support */ -int sev_es = IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT); -module_param(sev_es, int, 0444); - bool __read_mostly dump_invalid_vmcb; module_param(dump_invalid_vmcb, bool, 0644); @@ -976,12 +968,7 @@ static __init int svm_hardware_setup(void) kvm_enable_efer_bits(EFER_SVME | EFER_LMSLE); } - if (IS_ENABLED(CONFIG_KVM_AMD_SEV) && sev) { - sev_hardware_setup(); - } else { - sev = false; - sev_es = false; - } + sev_hardware_setup(); svm_adjust_mmio_mask(); diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 0fe874ae5498..8e169835f52a 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -408,8 +408,6 @@ static inline bool gif_set(struct vcpu_svm *svm) #define MSR_CR3_LONG_MBZ_MASK 0xfff0000000000000U #define MSR_INVALID 0xffffffffU -extern int sev; -extern int sev_es; extern bool dump_invalid_vmcb; u32 svm_msrpm_offset(u32 msr);