From patchwork Mon Aug 14 09:22:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 135293 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp2631473vqi; Mon, 14 Aug 2023 02:52:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH9SGIGJlY6knzZT3AH1vIxm1UGyli7Mo6Uo6kw6R7jMEuNZ3ipIima+VB8uceXwSzir+O8 X-Received: by 2002:a17:903:120c:b0:1bc:7c69:925a with SMTP id l12-20020a170903120c00b001bc7c69925amr12550109plh.33.1692006747982; Mon, 14 Aug 2023 02:52:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692006747; cv=none; d=google.com; s=arc-20160816; b=foFeXvMUT8m0B6LY+fF8kpljYTcy2nB4uc+kjkHTw4eSpFQT7F6OT4qtOLrJrf02lk vm2m8sMxVFyzfgdqdA7BlQesrJZ89y7YyXcir3w1XCSEocAShIyQBLq5d0/kR+AMEp7f 8iKWslQyGIzpWu5FC6V8YxHPvKJ85Hd5O8dWLRk1JvbuFghz8nZqETsFNZmcR9FuFcYT mBOdRcye+/9PVlfJytaFFuOQC/uoTIfQrrPfVAEmxCRWQOhulb3S/8rJrQqbQDXYvjw4 npf2ycXoaZ5r8vXWT6I3voYOplgrY2bFm9kDA3JZW3zuwWW5GvjqOjVU/zx3bG+pss5n HSGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=jNZyioyg0CuqfNRFAIhBnybBfkifZC/RQ8HztUyD7MM=; fh=Ozd30i0im7hP1p8Dg8bdK6DpKCOZr4N95qGOF6KmRUY=; b=wuaKBVpJx8/3/oAbZXTdSyfJDhOSPHyr0i75NEgpKSFbhtJBnSD++sgboeeOuyXPGl d8lIY1vCsvxekMEOWa+dduBpAKkzCB1l479FmVsNrBwVNBeem4mpyaSVN2ZruYEU5XWt M8GaqxcRkljQ15AOwLu06wFwhNFlagXvnuiBNwrlPveXbmX1gFaD2uyg+R3zFjJzczSo tiT5f+FAHzoxaAwO3d28M9ZGr6jyg4cWqGf+0hTE1+jCiwdqeMALuGanqVXB8jMaTqMt njvnoO7txArbGkdUHpGjNcoZazzC8AdqGCQHVjZvc8H8Tqofx7yF2LAeHotrzxDNGFK7 zAVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=gnqMSJp5; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j7-20020a170903024700b001b89b77ce99si7977615plh.458.2023.08.14.02.52.14; Mon, 14 Aug 2023 02:52:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@linutronix.de header.s=2020 header.b=gnqMSJp5; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234969AbjHNJWs (ORCPT + 99 others); Mon, 14 Aug 2023 05:22:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235158AbjHNJWa (ORCPT ); Mon, 14 Aug 2023 05:22:30 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CBDD130; Mon, 14 Aug 2023 02:22:29 -0700 (PDT) Date: Mon, 14 Aug 2023 09:22:21 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1692004942; h=from:from:sender:sender:reply-to: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; bh=jNZyioyg0CuqfNRFAIhBnybBfkifZC/RQ8HztUyD7MM=; b=gnqMSJp5O+I8IoMI3BZcJy0VbD3jNkJS+kSfB57wPIBUI2B6Zbdit4AM83LzSDpM/Bu8Ly b57OR02ZPMghb6gISCjsJYZv8SvvzU4AnsWDSPdOUOsraoIPZokoqfTyLm2A5ErvTSILRo bM4WNbFHzUKhCdvljsSGaVzbrp0+Ny/NK1Xt1wZLzfCs4IcsLKn3VdCMZ84Y7aIxWAD9PL hnglyzJgKv1cOqsyNE1h1lCQ5nnfXaLBOJKMK7U56evw9kOyvtdzQVvIEYX8hfJbn9QB2X rkGEQuEwPzLBaBNazPhOJOC3jZmytSTEuJ+b/yNX6fyeAHMzPgGAYDLKDuuLVA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1692004942; h=from:from:sender:sender:reply-to: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; bh=jNZyioyg0CuqfNRFAIhBnybBfkifZC/RQ8HztUyD7MM=; b=R4bzImJcenZM1APzAvN3rocGHHb7B7iYKtoQjnd1tNJoMekLfKNsQMYqghJwmTZxnf2X32 IoAi9ZGQBtsD6VAA== From: "tip-bot2 for Borislav Petkov (AMD)" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] x86/CPU/AMD: Fix the DIV(0) initial fix attempt Cc: "Borislav Petkov (AMD)" , , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230811213824.10025-1-bp@alien8.de> References: <20230811213824.10025-1-bp@alien8.de> MIME-Version: 1.0 Message-ID: <169200494163.27769.3355062803892299575.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773970917105472787 X-GMAIL-MSGID: 1774197667624689451 The following commit has been merged into the x86/urgent branch of tip: Commit-ID: f58d6fbcb7c848b7f2469be339bc571f2e9d245b Gitweb: https://git.kernel.org/tip/f58d6fbcb7c848b7f2469be339bc571f2e9d245b Author: Borislav Petkov (AMD) AuthorDate: Fri, 11 Aug 2023 23:38:24 +02:00 Committer: Borislav Petkov (AMD) CommitterDate: Mon, 14 Aug 2023 11:02:50 +02:00 x86/CPU/AMD: Fix the DIV(0) initial fix attempt Initially, it was thought that doing an innocuous division in the #DE handler would take care to prevent any leaking of old data from the divider but by the time the fault is raised, the speculation has already advanced too far and such data could already have been used by younger operations. Therefore, do the innocuous division on every exit to userspace so that userspace doesn't see any potentially old data from integer divisions in kernel space. Do the same before VMRUN too, to protect host data from leaking into the guest too. Fixes: 77245f1c3c64 ("x86/CPU/AMD: Do not leak quotient data after a division by 0") Signed-off-by: Borislav Petkov (AMD) Cc: Link: https://lore.kernel.org/r/20230811213824.10025-1-bp@alien8.de --- arch/x86/include/asm/entry-common.h | 1 + arch/x86/kernel/cpu/amd.c | 1 + arch/x86/kernel/traps.c | 2 -- arch/x86/kvm/svm/svm.c | 2 ++ 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/entry-common.h b/arch/x86/include/asm/entry-common.h index 1179038..ce8f501 100644 --- a/arch/x86/include/asm/entry-common.h +++ b/arch/x86/include/asm/entry-common.h @@ -92,6 +92,7 @@ static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs, static __always_inline void arch_exit_to_user_mode(void) { mds_user_clear_cpu_buffers(); + amd_clear_divider(); } #define arch_exit_to_user_mode arch_exit_to_user_mode diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index 70f9d56..7eca6a8 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -1329,3 +1329,4 @@ void noinstr amd_clear_divider(void) asm volatile(ALTERNATIVE("", "div %2\n\t", X86_BUG_DIV0) :: "a" (0), "d" (0), "r" (1)); } +EXPORT_SYMBOL_GPL(amd_clear_divider); diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index 1885326..4a817d2 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -206,8 +206,6 @@ DEFINE_IDTENTRY(exc_divide_error) { do_error_trap(regs, 0, "divide error", X86_TRAP_DE, SIGFPE, FPE_INTDIV, error_get_trap_addr(regs)); - - amd_clear_divider(); } DEFINE_IDTENTRY(exc_overflow) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 03e852d..d4bfdc6 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4006,6 +4006,8 @@ static noinstr void svm_vcpu_enter_exit(struct kvm_vcpu *vcpu, bool spec_ctrl_in guest_state_enter_irqoff(); + amd_clear_divider(); + if (sev_es_guest(vcpu->kvm)) __svm_sev_es_vcpu_run(svm, spec_ctrl_intercepted); else