Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1564283pxb; Tue, 26 Oct 2021 11:19:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQElo488xnIIOokKEXq2CamhkIX8GTUdXf2oasP0Af2eyzzlaWkl40zAy74fgx+DcEzgy8 X-Received: by 2002:a63:5714:: with SMTP id l20mr20121185pgb.121.1635272396419; Tue, 26 Oct 2021 11:19:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635272396; cv=none; d=google.com; s=arc-20160816; b=Zfhaj/9V0oaA3rUO3z4l6tNWCHfVpfstZQxegyi6V0TPh8ymytcdx/m5KzGlgpKqk4 OZQzCunZLCBfWsdHccFSfMTgFzfYJIpyYY6KwuPYaRIk8cpw7LNAz8yC1+u1UJt+5vqU dosqJYmcRM1EeBcNJvtiaXwbLCTgD6vRTGdS5vt1vUKUy6MzOlWb3bMakZ1u0yRIZTZ1 HjAwyQJpp74kJsDm9/vbgUAwVLSYHUMso9rVgkXW9gGi184WktenuQRP7re96LdofPZL iMCm9MNL9W+XhX3yd0yTN8sMsl1a6ENVKC9bYLVGsgJ3awMtFkhs4BZfHwJ77eAfgtPa y3rQ== 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=2lhQrUUxc7kLVqNyEu//dKP6He8ZHxMSI107NCUgfsQ=; b=d7ltraK0ZWfnmrKBmqJGFCPV5re0h8EcwAnaTc6siQYXRYvmk736cxdVIH7/JSKNoq 1T7snCtBCD5o93WYQqIpUkuT/C7mln1eUuwF8xbu8WG6tBOtHxz6zNyEYCBQPaBlPPj/ Y9e7vwaLZ1rn6Y6L5zpsAPpFWWb/EODaJIJq74EU17JZ/Aah6AlZonCDHWjWnG3nW8I2 ZmU+HO95mHvx1lI1j5/fNFafRy4eH17kUh37bROzG1FEqSfgpuvtMgVaiyL4DKLebbzw /zTi/MslMo48HqOW55Fn+R36ebKf9lz2YCHAX9Mg+LbSrUqYZfyoeeL2usbAfoBnHosN eipA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=XXqyFh9T; 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 o15si22612562plg.408.2021.10.26.11.19.41; Tue, 26 Oct 2021 11:19:56 -0700 (PDT) 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=XXqyFh9T; 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 S236696AbhJZOho (ORCPT + 99 others); Tue, 26 Oct 2021 10:37:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236710AbhJZOhl (ORCPT ); Tue, 26 Oct 2021 10:37:41 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BB97C061348 for ; Tue, 26 Oct 2021 07:35:18 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id n12so5792286plc.2 for ; Tue, 26 Oct 2021 07:35:18 -0700 (PDT) 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=2lhQrUUxc7kLVqNyEu//dKP6He8ZHxMSI107NCUgfsQ=; b=XXqyFh9TsXGyVqBT+cjiPNuZf1BOPdrErU27osHoEj3Ey8yZCk/h766YDo4xHli/V2 lPhjd+dWILy6bnvpbwQMsKcTxYqpaTZSAFq1zVluvlo8TeP06C0Smfo0/Is+rdN7Tzeh gYS7kSHme/AZpRFY2+u2kuc568uWa/5Uh6p93Hw+fDbr382HlCyKWZnEBfdAgac+iiYu hcralk6HtPTK/5THbbjVQX9Igr0amtExuaPwIlblY3YQO/dvEyq+7jz/jnwL+mmlFNNr jRQKmBsVgQUkDBpaot0GgX1EPj5f6o+0r5qCSEVnv3MGrUm/3TIUI1stH4AGAzMs1vYF bKIw== 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=2lhQrUUxc7kLVqNyEu//dKP6He8ZHxMSI107NCUgfsQ=; b=3wJuVrWmQrADOZ++f/Qnac/s6AyWJoBwBFFPZiSApwLNuJBiEGCFQkyxnAk4nMCQKL wKbaFzYwkc/kxM3f3oCXc78HOzu7wpSzmyZKKV6fneMvVCjheQmk5JMTY3UPiOL19Toq izR25r/vD/NAxRBm/EnUoV6sGowPBGLCrpuOSLbASGhjhRQxWlY1NReMxw+S3W6ZZ901 1pnPLVKq37cgQwY0NR61e9ZvxhfSRLEcsF9vR6TtUeHcKX7LCwTT/U2DpgB7v0YL6ELf UIAfWOBd5pSqKDlLflOaHVJulLIM0d2RZvdv/0dcTYGEwv0oKZEHdXtjeyay0PHCA9Mv h/3A== X-Gm-Message-State: AOAM533uWUQdqyDu38sQOUWzoVbjPqRiaUNZuQVY4bnj5+JI08KRGq6l eKmS2kB+IiSu3XxGODPMC+ma2IAELOc= X-Received: by 2002:a17:90b:ec9:: with SMTP id gz9mr3211937pjb.218.1635258917280; Tue, 26 Oct 2021 07:35:17 -0700 (PDT) Received: from localhost ([47.88.5.130]) by smtp.gmail.com with ESMTPSA id j16sm3457583pfj.16.2021.10.26.07.35.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Oct 2021 07:35:17 -0700 (PDT) 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 V4 29/50] x86/entry: Call paranoid_exit() in asm_exc_nmi() Date: Tue, 26 Oct 2021 22:34:15 +0800 Message-Id: <20211026143436.19071-4-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20211026141420.17138-1-jiangshanlai@gmail.com> References: <20211026141420.17138-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 8790bf41edd4..8d873b778681 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -959,8 +959,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