The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Lai Jiangshan <jiangshanlai@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: x86@kernel.org, Lai Jiangshan <laijs@linux.alibaba.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"H. Peter Anvin" <hpa@zytor.com>, Joerg Roedel <jroedel@suse.de>,
	Brijesh Singh <brijesh.singh@amd.com>
Subject: [PATCH 4/4] x86/nmi: Convert nmi_cr2/nmi_dr7 to be func-local variable
Date: Mon, 13 Dec 2021 23:03:40 +0800	[thread overview]
Message-ID: <20211213150340.9419-5-jiangshanlai@gmail.com> (raw)
In-Reply-To: <20211213150340.9419-1-jiangshanlai@gmail.com>

From: Lai Jiangshan <laijs@linux.alibaba.com>

nmi_cr2 and nmi_dr7 are used inside a function (the outmost exc_nmi()),
they don't need to be percpu data.

Signed-off-by: Lai Jiangshan <laijs@linux.alibaba.com>
---
 arch/x86/kernel/nmi.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
index 44c3adb68282..673eee5831db 100644
--- a/arch/x86/kernel/nmi.c
+++ b/arch/x86/kernel/nmi.c
@@ -470,12 +470,12 @@ enum nmi_states {
 	NMI_LATCHED,
 };
 static DEFINE_PER_CPU(enum nmi_states, nmi_state);
-static DEFINE_PER_CPU(unsigned long, nmi_cr2);
-static DEFINE_PER_CPU(unsigned long, nmi_dr7);
 
 DEFINE_IDTENTRY_NMI(exc_nmi)
 {
 	irqentry_state_t irq_state;
+	unsigned long nmi_cr2;
+	unsigned long nmi_dr7;
 
 	/*
 	 * Re-enable NMIs right here when running as an SEV-ES guest. This might
@@ -491,7 +491,7 @@ DEFINE_IDTENTRY_NMI(exc_nmi)
 		return;
 	}
 	this_cpu_write(nmi_state, NMI_EXECUTING);
-	this_cpu_write(nmi_cr2, read_cr2());
+	nmi_cr2 = read_cr2();
 nmi_restart:
 
 	/*
@@ -500,7 +500,7 @@ DEFINE_IDTENTRY_NMI(exc_nmi)
 	 */
 	sev_es_ist_enter(regs);
 
-	this_cpu_write(nmi_dr7, local_db_save());
+	nmi_dr7 = local_db_save();
 
 	irq_state = irqentry_nmi_enter(regs);
 
@@ -511,12 +511,12 @@ DEFINE_IDTENTRY_NMI(exc_nmi)
 
 	irqentry_nmi_exit(regs, irq_state);
 
-	local_db_restore(this_cpu_read(nmi_dr7));
+	local_db_restore(nmi_dr7);
 
 	sev_es_ist_exit();
 
-	if (unlikely(this_cpu_read(nmi_cr2) != read_cr2()))
-		write_cr2(this_cpu_read(nmi_cr2));
+	if (unlikely(nmi_cr2 != read_cr2()))
+		write_cr2(nmi_cr2);
 	if (this_cpu_dec_return(nmi_state))
 		goto nmi_restart;
 
-- 
2.19.1.6.gb485710b


      parent reply	other threads:[~2021-12-13 15:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-13 15:03 [PATCH 0/4] x86/nmi: NMI cleanups Lai Jiangshan
2021-12-13 15:03 ` [PATCH 1/4] x86/entry: Make paranoid_exit() callable Lai Jiangshan
2021-12-20 18:56   ` Borislav Petkov
2021-12-21  2:22     ` Lai Jiangshan
2021-12-21 10:49       ` Borislav Petkov
2021-12-13 15:03 ` [PATCH 2/4] x86/entry: Call paranoid_exit() in asm_exc_nmi() Lai Jiangshan
2021-12-13 15:03 ` [PATCH 3/4] x86/nmi: Use DEFINE_IDTENTRY_NMI for NMI handler Lai Jiangshan
2021-12-13 15:03 ` Lai Jiangshan [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211213150340.9419-5-jiangshanlai@gmail.com \
    --to=jiangshanlai@gmail.com \
    --cc=bp@alien8.de \
    --cc=brijesh.singh@amd.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=jroedel@suse.de \
    --cc=laijs@linux.alibaba.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox