Received: by 2002:a05:6a10:8395:0:0:0:0 with SMTP id n21csp424796pxh; Wed, 10 Nov 2021 04:03:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJylbQDMGQ4d3iSaVNDiighXfW6/8iVe7SXEPJeimY/hwH2r0Xj1tGZmAqip86W5t3Z2LHRW X-Received: by 2002:a17:907:3e96:: with SMTP id hs22mr20410895ejc.139.1636545826915; Wed, 10 Nov 2021 04:03:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636545826; cv=none; d=google.com; s=arc-20160816; b=DNBYFNqCEttdsv+AP5OJ7QSfl7BdxZIEpc056H6YBcS0uXw97OX5aRk9/rkJ0MfUQ4 YmdEAAiTRyG46G7Xi01uh11qKgdLYW/JzTTT1sKwIl6uKtYejJ/E/KcXvjNQb6N5pQGq NuykJC0V3RzC59uOkM/fopYMagr5N8hQg7YpwMsgwYd2ZzfbIFDotnavwXEF9Wt+1MHW zuiyZRykFPIdk9hKEPbgdW0Qt97fnpM64XnPgnUEeQAmtti2ZZY5VPyOKhbRlVm8vSzg atIEtv/FpuukKUDy2fT/0JpuyqL9fMh1ovRc2HQi2O4cLsFwvQxNujuXQHDPkuqt1Vle mDyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=w9NEeDtCVo+FiatRNBp9c/z7itcHiF3dSTibOob4YLE=; b=T6PsSV/rR9Tx/Zp0o+AD3+jPoZt/+iOaDqS3j/F6ChOevhjTB3FwlknEUdllgmiQeq LTg88dOeLpNnQ7941XjJxxggyQQSUAkOZP8ws1JNg1hfFtPvtMIgbeggOXVwv14xJwEV SyHcvd7/RE2Jxv+qh+7hiKzO7z3jZ38ee+s6D23knQuIamL0eDVoyF769PsDst3WIrz4 GJKikDNZoChXc88mFLmSaBaiL/vjdDnw7Nr+tyE1whiAXpKfU8vakJTU8iV4UUjKcCIr iTlCEdxyfR599ZgNyGvQCP8KBnrMl6OpEe6I986EERkv9WsI0lanuggeu1ISVxMXeTTL viMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=CfEv4Gvi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e16si37153906edr.581.2021.11.10.04.03.22; Wed, 10 Nov 2021 04:03:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=CfEv4Gvi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231517AbhKJMDd (ORCPT + 99 others); Wed, 10 Nov 2021 07:03:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231566AbhKJMDT (ORCPT ); Wed, 10 Nov 2021 07:03:19 -0500 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC98BC06120F for ; Wed, 10 Nov 2021 04:00:31 -0800 (PST) Received: by mail-pf1-x42c.google.com with SMTP id o4so2420295pfp.13 for ; Wed, 10 Nov 2021 04:00:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=w9NEeDtCVo+FiatRNBp9c/z7itcHiF3dSTibOob4YLE=; b=CfEv4GvioEcU+HMc1pv06hCbu+3F6q2jd08TV83uSBd5aMGFbsbGUOcL+8Zk9tNmv1 8LdZZRZwObh2uzBYolmFYgagmA53FKm8UA9f+eL55sF1fwIoxBLIMm2KsWs1uHERJm3Z ppfxu+ZWFArUPFKtDCdXgKLeHKjpnOHLLAeN3JURZG04mGaT6cZ7aNvv6OMEXJL7gPiz fcY4W6rxTG+KUR9M7I7w13u+S7lmD3FLy1gn1kwRXlyHZgQ8PehsHStBrvJHKojy6SMC w5ZXBPhlSRJ87IkV0qZJQlCmBJOQ3mLNaqoAo1HcztVDXejxniQAIKjlDwRsPpPuucKa ZESQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=w9NEeDtCVo+FiatRNBp9c/z7itcHiF3dSTibOob4YLE=; b=0ibelN7vSLOpKG6enpZ78nuyO2ZDXIpegZDOsslNKJGGIMrnJ8JuK7V6ZxKRkPtXaL YEU4pPt6E2ohOxZVkA3S4PFLgJ8YAIVRJVHJKcJwawKzH/l8K9Cen3wNwT3hjPfE3+71 mDHsH8iSwSkrFT3yFHrrLrHMAztp7StQZqf66TExD7y9JQByeDrZgA2ZMPqLAfHrHFve Jwt9zOieAMB3rrDKCxYqVmk2Gyx2lTnkeShuTnvhpMXtamIjRpiDtzfHpRq9GbDPF6Kd IAaOq6mkSrsyX/0FXyMaAmSipa5jsFOuK9j3nDsQo7cGQsl0EHIMyFRvcUaYThy1sQYQ yyjA== X-Gm-Message-State: AOAM531+SwUPANiSHwkk4d6/QUq+KLoTeaJLlUHbiOaiOKy/Mu3vClq7 aMGaDF0VJdFDD+4jDxniU4Drac45e2k= X-Received: by 2002:a05:6a00:16d2:b029:300:200b:6572 with SMTP id l18-20020a056a0016d2b0290300200b6572mr15694419pfc.62.1636545631018; Wed, 10 Nov 2021 04:00:31 -0800 (PST) Received: from localhost ([198.11.178.15]) by smtp.gmail.com with ESMTPSA id b21sm18686368pff.179.2021.11.10.04.00.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Nov 2021 04:00:30 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, Lai Jiangshan , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH V5 29/50] x86/entry: Call paranoid_exit() in asm_exc_nmi() Date: Wed, 10 Nov 2021 19:57:15 +0800 Message-Id: <20211110115736.3776-30-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211110115736.3776-1-jiangshanlai@gmail.com> References: <20211110115736.3776-1-jiangshanlai@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lai Jiangshan The code between "call exc_nmi" and nmi_restore is as the same as paranoid_exit(), so we can just use paranoid_exit() instead of the open duplicated code. No functional change intended. Signed-off-by: Lai Jiangshan --- arch/x86/entry/entry_64.S | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index e6e655a1764a..3a434b179963 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -960,8 +960,7 @@ SYM_CODE_END(paranoid_entry) /* * "Paranoid" exit path from exception stack. This is invoked - * only on return from non-NMI IST interrupts that came - * from kernel space. + * only on return from IST interrupts that came from kernel space. * * We may be returning to very strange contexts (e.g. very early * in syscall entry), so checking for preemption here would @@ -1309,11 +1308,7 @@ end_repeat_nmi: pushq $-1 /* ORIG_RAX: no syscall to restart */ /* - * Use paranoid_entry to handle SWAPGS, but no need to use paranoid_exit - * as we should not be calling schedule in NMI context. - * Even with normal interrupts enabled. An NMI should not be - * setting NEED_RESCHED or anything that normal interrupts and - * exceptions might do. + * Use paranoid_entry to handle SWAPGS and CR3. */ call paranoid_entry UNWIND_HINT_REGS @@ -1322,31 +1317,12 @@ end_repeat_nmi: movq $-1, %rsi call exc_nmi - /* Always restore stashed CR3 value (see paranoid_entry) */ - RESTORE_CR3 scratch_reg=%r15 save_reg=%r14 - /* - * The above invocation of paranoid_entry stored the GSBASE - * related information in R/EBX depending on the availability - * of FSGSBASE. - * - * If FSGSBASE is enabled, restore the saved GSBASE value - * unconditionally, otherwise take the conditional SWAPGS path. + * Use paranoid_exit to handle SWAPGS and CR3, but no need to use + * restore_regs_and_return_to_kernel as we must handle nested NMI. */ - ALTERNATIVE "jmp nmi_no_fsgsbase", "", X86_FEATURE_FSGSBASE - - wrgsbase %rbx - jmp nmi_restore - -nmi_no_fsgsbase: - /* EBX == 0 -> invoke SWAPGS */ - testl %ebx, %ebx - jnz nmi_restore - -nmi_swapgs: - swapgs + call paranoid_exit -nmi_restore: POP_REGS /* -- 2.19.1.6.gb485710b