From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B139FC47096 for ; Thu, 3 Jun 2021 17:38:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 85374613F1 for ; Thu, 3 Jun 2021 17:38:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230258AbhFCRkU (ORCPT ); Thu, 3 Jun 2021 13:40:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:38230 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229710AbhFCRkT (ORCPT ); Thu, 3 Jun 2021 13:40:19 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1CF2961359; Thu, 3 Jun 2021 17:38:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622741914; bh=mbA/RbQu9W1QdRb3EfA6YF6E9+vaRvVXQpsVRjvSbG8=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=LsjAGp3wAJiRQCvZRhbwnJPpwoP9mtl7zm2JsxIy0VL9C3KOH87jHO2b4NgIdo0wW ElxNf8QYQ5k+7x/jd9isS3g/NZXxdo1Qn0JOG9JwVfE1cfrcVWbNgC+l1HJtannDd3 V6vFoPlpqobZJMWHRSyYmTwGQM2SEfVC2mRW8uBGk7XyNshi/crcEyBREz+MDtMqgY L9/YNT4zBcoi0n3TFNjHBhvFtFwO5E3sR+EBu+1duQ+UCmrGpJp7CvkRIiHsVsxRB5 aN8gLnhAIpK4+FeCLEnNvc85njGsvViMb98t9bAv/bE2jnLB3FykZdeWEgG0ECf0k4 Ye0p4MBA0d7Aw== Subject: Re: [RFC PATCH 4/4] x86/entry/nmi: unmask NMIs on userspace NMI when entry debugging To: Lai Jiangshan , linux-kernel@vger.kernel.org Cc: Steven Rostedt , Lai Jiangshan , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" References: <20210601065217.23540-1-jiangshanlai@gmail.com> <20210601065217.23540-5-jiangshanlai@gmail.com> From: Andy Lutomirski Message-ID: Date: Thu, 3 Jun 2021 10:38:33 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <20210601065217.23540-5-jiangshanlai@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/31/21 11:52 PM, Lai Jiangshan wrote: > From: Lai Jiangshan Why? > > Signed-off-by: Lai Jiangshan > --- > arch/x86/entry/entry_64.S | 36 ++++++++++++++++++++---------------- > 1 file changed, 20 insertions(+), 16 deletions(-) > > diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S > index f54e06139d4b..309e63f4f391 100644 > --- a/arch/x86/entry/entry_64.S > +++ b/arch/x86/entry/entry_64.S > @@ -1055,6 +1055,24 @@ SYM_CODE_START_LOCAL(error_return) > jmp swapgs_restore_regs_and_return_to_usermode > SYM_CODE_END(error_return) > > +.macro debug_entry_unmask_NMIs > +#ifdef CONFIG_DEBUG_ENTRY > + /* > + * For ease of testing, unmask NMIs right away. Disabled by > + * default because IRET is very expensive. > + */ > + pushq $0 /* SS */ > + pushq %rsp /* RSP (minus 8 because of the previous push) */ > + addq $8, (%rsp) /* Fix up RSP */ > + pushfq /* RFLAGS */ > + pushq $__KERNEL_CS /* CS */ > + pushq $1f /* RIP */ > + iretq /* continues with NMI unmasked */ > + UNWIND_HINT_IRET_REGS > +1: > +#endif > +.endm > + > /* > * Runs on exception stack. Xen PV does not go through this path at all, > * so we can use real assembly here. > @@ -1145,6 +1163,7 @@ SYM_CODE_START(asm_exc_nmi) > * At this point we no longer need to worry about stack damage > * due to nesting -- we're done with the NMI stack. > */ > + debug_entry_unmask_NMIs > pushq $-1 /* pt_regs->orig_ax */ > idtentry_body exc_nmi has_error_code=0 > > @@ -1286,22 +1305,7 @@ first_nmi: > UNWIND_HINT_IRET_REGS > > /* Everything up to here is safe from nested NMIs */ > - > -#ifdef CONFIG_DEBUG_ENTRY > - /* > - * For ease of testing, unmask NMIs right away. Disabled by > - * default because IRET is very expensive. > - */ > - pushq $0 /* SS */ > - pushq %rsp /* RSP (minus 8 because of the previous push) */ > - addq $8, (%rsp) /* Fix up RSP */ > - pushfq /* RFLAGS */ > - pushq $__KERNEL_CS /* CS */ > - pushq $1f /* RIP */ > - iretq /* continues at repeat_nmi below */ > - UNWIND_HINT_IRET_REGS > -1: > -#endif > + debug_entry_unmask_NMIs > > repeat_nmi: > /* >