From patchwork Tue Jan 26 13:20:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1431681 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DQ6n01Zlwz9sW8; Wed, 27 Jan 2021 00:20:51 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1l4OH1-0008ED-RF; Tue, 26 Jan 2021 13:20:47 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1l4OGz-0008DF-6l for kernel-team@lists.ubuntu.com; Tue, 26 Jan 2021 13:20:45 +0000 Received: from mail-qv1-f70.google.com ([209.85.219.70]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1l4OGy-0005DT-Rv for kernel-team@lists.ubuntu.com; Tue, 26 Jan 2021 13:20:44 +0000 Received: by mail-qv1-f70.google.com with SMTP id b1so558969qvk.17 for ; Tue, 26 Jan 2021 05:20:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5lBruM8nkgMArKc+Rx5olhpzkOZ9jKtB3bKCgYvt/MQ=; b=U0RHpumqVo1U2Vjs0rMjzf3FRowgafgf+3WGsL51s1/StXC7+1HORssjSYW3tM5s1A a6urxZqWrBhRI/MwAMeiRgmMogutiVyUacbFtPdNFPb4VXYPNx20GMiJ9yo0oYntQGDk Nod/IlOR4Phm63VwnbozapLqLgWlKkg8gHECCMWlnOkwwlHk7HOsWkvNLIbI096aaFL5 7kHyqB8ijoPRlgr0KpQm2TXkC14wfn0xVBnc5/15v9aM0QkPkK4USM2uqWOye+L7WRYm 7d8YuNSyW0mcmzyL24I3TmeiBOFIuCXkOkyDbtXj7otPJAHJN5/mf88cqSAFXwlBit8L ud7Q== X-Gm-Message-State: AOAM531q93cyp0VVtCvJ//DjPESlqWAoYHKTRY6skIzECZ70NGCtXch6 qiq9b2ZjyU6jy65JC/GlM7IgFMeNsbAJaK3FsunLRY8oeI0ewsYL65fpZQdyeRvwiSb0CI4oeYZ hVN1IVD+Ws5IRPHYg761q2oD+NlsKJ/+gU8E0/kXX X-Received: by 2002:ac8:6902:: with SMTP id e2mr4873879qtr.162.1611667243649; Tue, 26 Jan 2021 05:20:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJze8OwM20ebLcEfPWQCY0N3kehdIy/ayKhxO7h6KVrEhRDV6qVuPmZQDYJsurOx5jIyNIJkWw== X-Received: by 2002:ac8:6902:: with SMTP id e2mr4873853qtr.162.1611667243392; Tue, 26 Jan 2021 05:20:43 -0800 (PST) Received: from localhost.localdomain ([2804:431:cfed:edc:c86c:ab75:eda1:1e6c]) by smtp.gmail.com with ESMTPSA id 18sm7068007qkl.20.2021.01.26.05.20.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 05:20:42 -0800 (PST) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [bionic:linux-azure-4.15][PATCH 2/3] x86/process/64: Make save_fsgs_for_kvm() ready for FSGSBASE Date: Tue, 26 Jan 2021 10:20:23 -0300 Message-Id: <20210126132024.1764493-3-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210126132024.1764493-1-marcelo.cerri@canonical.com> References: <20210126131712.1744754-1-marcelo.cerri@canonical.com> <20210126132024.1764493-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Thomas Gleixner BugLink: https://bugs.launchpad.net/bugs/1913294 save_fsgs_for_kvm() is invoked via vcpu_enter_guest() kvm_x86_ops.prepare_guest_switch(vcpu) vmx_prepare_switch_to_guest() save_fsgs_for_kvm() with preemption disabled, but interrupts enabled. The upcoming FSGSBASE based GS safe needs interrupts to be disabled. This could be done in the helper function, but that function is also called from switch_to() which has interrupts disabled already. Disable interrupts inside save_fsgs_for_kvm() and rename the function to current_save_fsgs() so it can be invoked from other places. Signed-off-by: Thomas Gleixner Signed-off-by: Sasha Levin Signed-off-by: Thomas Gleixner Link: https://lkml.kernel.org/r/20200528201402.1708239-7-sashal@kernel.org (backported from commit 6758034e4d6a7f0e26b748789ab1f83f3116d1b9) Signed-off-by: Marcelo Henrique Cerri --- arch/x86/include/asm/processor.h | 4 +--- arch/x86/kernel/process_64.c | 15 +++++++++------ arch/x86/kvm/vmx.c | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h index 286bc96c67c8..c3a2392fa7ec 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -409,10 +409,8 @@ DECLARE_PER_CPU(char *, irq_stack_ptr); DECLARE_PER_CPU(unsigned int, irq_count); extern asmlinkage void ignore_sysret(void); -#if IS_ENABLED(CONFIG_KVM) /* Save actual FS/GS selectors and bases to current->thread */ -void save_fsgs_for_kvm(void); -#endif +void current_save_fsgs(void); #else /* X86_64 */ #ifdef CONFIG_CC_STACKPROTECTOR /* diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index e976b6c1c26e..381c478184b1 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -218,18 +218,21 @@ static __always_inline void save_fsgs(struct task_struct *task) } } -#if IS_ENABLED(CONFIG_KVM) /* * While a process is running,current->thread.fsbase and current->thread.gsbase - * may not match the corresponding CPU registers (see save_base_legacy()). KVM - * wants an efficient way to save and restore FSBASE and GSBASE. - * When FSGSBASE extensions are enabled, this will have to use RD{FS,GS}BASE. + * may not match the corresponding CPU registers (see save_base_legacy()). */ -void save_fsgs_for_kvm(void) +void current_save_fsgs(void) { + unsigned long flags; + + /* Interrupts need to be off for FSGSBASE */ + local_irq_save(flags); save_fsgs(current); + local_irq_restore(flags); } -EXPORT_SYMBOL_GPL(save_fsgs_for_kvm); +#if IS_ENABLED(CONFIG_KVM) +EXPORT_SYMBOL_GPL(current_save_fsgs); #endif static __always_inline void loadseg(enum which_selector which, diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index ca29acc1721f..79893adbcdac 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -2324,7 +2324,7 @@ static void vmx_save_host_state(struct kvm_vcpu *vcpu) vmx->host_state.gs_ldt_reload_needed = vmx->host_state.ldt_sel; #ifdef CONFIG_X86_64 - save_fsgs_for_kvm(); + current_save_fsgs(); vmx->host_state.fs_sel = current->thread.fsindex; vmx->host_state.gs_sel = current->thread.gsindex; #else