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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42132C6FD19 for ; Fri, 10 Mar 2023 21:45:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231359AbjCJVpK (ORCPT ); Fri, 10 Mar 2023 16:45:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231877AbjCJVoP (ORCPT ); Fri, 10 Mar 2023 16:44:15 -0500 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E96A6A2DA for ; Fri, 10 Mar 2023 13:43:24 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id q1-20020a170902dac100b0019f1e3ea83dso416565plx.4 for ; Fri, 10 Mar 2023 13:43:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678484588; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=ksXX7w7DOgMSUfWcc6++N7pFfPEmS+/uh5KW2SxRWLg=; b=CdkmpywEjUR3b6EjxKkPa4YvZWHbCoXcmVBs3Hrb87A0RA1IF7R1chC4RjF2JU1UOO T/cPDMvG5as5m9qH6MplauVwoTRVSihJS3LAgYhtKzJX8Z1kYl4K5wiFEuEgOVRLSnGw moRsmkKH4UmV0BGwbRQbwpF+m76vXrmtiVO2m644ebUcqa/l6EUx13O5BGJaHJ+3NFZR T3Zkce7rO2JaWHF2Bk617TTUV2pO00zgP6GgppW8x5bVerYKtHy32JCdD7FgQieizCTs eiPnzyTcqjOSubxVy0dYUkClK8MpTWRqAu9J4BBo4EwRRL8Aw7W1OqcsW5dgcZu+QSuI 2Z+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678484588; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ksXX7w7DOgMSUfWcc6++N7pFfPEmS+/uh5KW2SxRWLg=; b=G13p/S8la+PKYUdfLCcS5S0Wve4S3KNuIcZU2BUcL7ZJH/JQQoESOKTHUJtklNykeC nQATn8lBpdlqy6edua8QprTZYpmB7dSoCeK9wnmxrW6hKvxTqnyyX6piOMaNomcWGvg6 UBso0i7w9u+kvrPH8/BHcW7Lz/qGMDgxjP1G/X0uN+UY/F+5BF6Z2lXbj3Kh4pQ2EEZZ bnyVGc5zR+KNy+Ffm+sLUvejXP1SHHVCOGUy+RCswdwPaa8naEnEwH/EdrWdpiXLv/WX LEw1LhSP/S2oaKfEv3DNTFomVq6nyUlVj2JNgABb63rAnxo6fg2Ld0DI01bVO+VcryBc LA7A== X-Gm-Message-State: AO0yUKXIJeS7oBu5gigdPT4aSuaDTPPJ3Lr5+5t80Xu9HXTzVnZu5B/m 5f+exqu1Y2HmQvrYcaLNiASYuWMzoqA= X-Google-Smtp-Source: AK7set+XsHBE74XVTrryN54b8Gg3t9oEH4NnaUYXf+7w5reulKwgA27aofO8Yoo5+U0IPiFzcXypJh/zuqc= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:f90b:b0:19f:1ee9:a14 with SMTP id kw11-20020a170902f90b00b0019f1ee90a14mr331047plb.4.1678484588314; Fri, 10 Mar 2023 13:43:08 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 10 Mar 2023 13:42:30 -0800 In-Reply-To: <20230310214232.806108-1-seanjc@google.com> Mime-Version: 1.0 References: <20230310214232.806108-1-seanjc@google.com> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog Message-ID: <20230310214232.806108-17-seanjc@google.com> Subject: [PATCH v2 16/18] x86/virt: KVM: Move "disable SVM" helper into KVM SVM From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Sean Christopherson , Paolo Bonzini Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Andrew Cooper , Kai Huang , Chao Gao Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move cpu_svm_disable() into KVM proper now that all hardware virtualization management is routed through KVM. Remove the now-empty virtext.h. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/include/asm/virtext.h | 50 ---------------------------------- arch/x86/kvm/svm/svm.c | 28 +++++++++++++++++-- 2 files changed, 25 insertions(+), 53 deletions(-) delete mode 100644 arch/x86/include/asm/virtext.h diff --git a/arch/x86/include/asm/virtext.h b/arch/x86/include/asm/virtext.h deleted file mode 100644 index 632575e257d8..000000000000 --- a/arch/x86/include/asm/virtext.h +++ /dev/null @@ -1,50 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* CPU virtualization extensions handling - * - * This should carry the code for handling CPU virtualization extensions - * that needs to live in the kernel core. - * - * Author: Eduardo Habkost - * - * Copyright (C) 2008, Red Hat Inc. - * - * Contains code from KVM, Copyright (C) 2006 Qumranet, Inc. - */ -#ifndef _ASM_X86_VIRTEX_H -#define _ASM_X86_VIRTEX_H - -#include - -#include -#include -#include - -/* - * SVM functions: - */ -/** Disable SVM on the current CPU - */ -static inline void cpu_svm_disable(void) -{ - uint64_t efer; - - wrmsrl(MSR_VM_HSAVE_PA, 0); - rdmsrl(MSR_EFER, efer); - if (efer & EFER_SVME) { - /* - * Force GIF=1 prior to disabling SVM to ensure INIT and NMI - * aren't blocked, e.g. if a fatal error occurred between CLGI - * and STGI. Note, STGI may #UD if SVM is disabled from NMI - * context between reading EFER and executing STGI. In that - * case, GIF must already be set, otherwise the NMI would have - * been blocked, so just eat the fault. - */ - asm_volatile_goto("1: stgi\n\t" - _ASM_EXTABLE(1b, %l[fault]) - ::: "memory" : fault); -fault: - wrmsrl(MSR_EFER, efer & ~EFER_SVME); - } -} - -#endif /* _ASM_X86_VIRTEX_H */ diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index f04b61c3d9d8..2db03991dcdf 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -41,7 +41,6 @@ #include #include -#include #include "trace.h" #include "svm.h" @@ -584,9 +583,32 @@ void __svm_write_tsc_multiplier(u64 multiplier) preempt_enable(); } +static inline void kvm_cpu_svm_disable(void) +{ + uint64_t efer; + + wrmsrl(MSR_VM_HSAVE_PA, 0); + rdmsrl(MSR_EFER, efer); + if (efer & EFER_SVME) { + /* + * Force GIF=1 prior to disabling SVM to ensure INIT and NMI + * aren't blocked, e.g. if a fatal error occurred between CLGI + * and STGI. Note, STGI may #UD if SVM is disabled from NMI + * context between reading EFER and executing STGI. In that + * case, GIF must already be set, otherwise the NMI would have + * been blocked, so just eat the fault. + */ + asm_volatile_goto("1: stgi\n\t" + _ASM_EXTABLE(1b, %l[fault]) + ::: "memory" : fault); +fault: + wrmsrl(MSR_EFER, efer & ~EFER_SVME); + } +} + static void svm_emergency_disable(void) { - cpu_svm_disable(); + kvm_cpu_svm_disable(); } static void svm_hardware_disable(void) @@ -595,7 +617,7 @@ static void svm_hardware_disable(void) if (tsc_scaling) __svm_write_tsc_multiplier(SVM_TSC_RATIO_DEFAULT); - cpu_svm_disable(); + kvm_cpu_svm_disable(); amd_pmu_disable_virt(); } -- 2.40.0.rc1.284.g88254d51c5-goog