* [PATCH] x86/hyperv: Use atomic_try_cmpxchg() to micro-optimize hv_nmi_unknown() @ 2023-11-14 16:59 Uros Bizjak 2023-11-15 17:19 ` Michael Kelley 0 siblings, 1 reply; 7+ messages in thread From: Uros Bizjak @ 2023-11-14 16:59 UTC (permalink / raw) To: linux-hyperv, x86, linux-kernel Cc: Uros Bizjak, K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin Use atomic_try_cmpxchg() instead of atomic_cmpxchg(*ptr, old, new) == old in hv_nmi_unknown(). On x86 the CMPXCHG instruction returns success in the ZF flag, so this change saves a compare after CMPXCHG. The generated asm code improves from: 3e: 65 8b 15 00 00 00 00 mov %gs:0x0(%rip),%edx 45: b8 ff ff ff ff mov $0xffffffff,%eax 4a: f0 0f b1 15 00 00 00 lock cmpxchg %edx,0x0(%rip) 51: 00 52: 83 f8 ff cmp $0xffffffff,%eax 55: 0f 95 c0 setne %al to: 3e: 65 8b 15 00 00 00 00 mov %gs:0x0(%rip),%edx 45: b8 ff ff ff ff mov $0xffffffff,%eax 4a: f0 0f b1 15 00 00 00 lock cmpxchg %edx,0x0(%rip) 51: 00 52: 0f 95 c0 setne %al No functional change intended. Cc: "K. Y. Srinivasan" <kys@microsoft.com> Cc: Haiyang Zhang <haiyangz@microsoft.com> Cc: Wei Liu <wei.liu@kernel.org> Cc: Dexuan Cui <decui@microsoft.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Signed-off-by: Uros Bizjak <ubizjak@gmail.com> --- arch/x86/kernel/cpu/mshyperv.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index e6bba12c759c..01fa06dd06b6 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -262,11 +262,14 @@ static uint32_t __init ms_hyperv_platform(void) static int hv_nmi_unknown(unsigned int val, struct pt_regs *regs) { static atomic_t nmi_cpu = ATOMIC_INIT(-1); + unsigned int old_cpu, this_cpu; if (!unknown_nmi_panic) return NMI_DONE; - if (atomic_cmpxchg(&nmi_cpu, -1, raw_smp_processor_id()) != -1) + old_cpu = -1; + this_cpu = raw_smp_processor_id(); + if (!atomic_try_cmpxchg(&nmi_cpu, &old_cpu, this_cpu)) return NMI_HANDLED; return NMI_DONE; -- 2.41.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* RE: [PATCH] x86/hyperv: Use atomic_try_cmpxchg() to micro-optimize hv_nmi_unknown() 2023-11-14 16:59 [PATCH] x86/hyperv: Use atomic_try_cmpxchg() to micro-optimize hv_nmi_unknown() Uros Bizjak @ 2023-11-15 17:19 ` Michael Kelley 2023-11-15 20:58 ` Uros Bizjak 0 siblings, 1 reply; 7+ messages in thread From: Michael Kelley @ 2023-11-15 17:19 UTC (permalink / raw) To: Uros Bizjak, linux-hyperv@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org Cc: K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin From: Uros Bizjak <ubizjak@gmail.com> Sent: Tuesday, November 14, 2023 8:59 AM > > Use atomic_try_cmpxchg() instead of atomic_cmpxchg(*ptr, old, new) == old > in hv_nmi_unknown(). On x86 the CMPXCHG instruction returns success in > the ZF flag, so this change saves a compare after CMPXCHG. The generated > asm code improves from: > > 3e: 65 8b 15 00 00 00 00 mov %gs:0x0(%rip),%edx > 45: b8 ff ff ff ff mov $0xffffffff,%eax > 4a: f0 0f b1 15 00 00 00 lock cmpxchg %edx,0x0(%rip) > 51: 00 > 52: 83 f8 ff cmp $0xffffffff,%eax > 55: 0f 95 c0 setne %al > > to: > > 3e: 65 8b 15 00 00 00 00 mov %gs:0x0(%rip),%edx > 45: b8 ff ff ff ff mov $0xffffffff,%eax > 4a: f0 0f b1 15 00 00 00 lock cmpxchg %edx,0x0(%rip) > 51: 00 > 52: 0f 95 c0 setne %al > > No functional change intended. > > Cc: "K. Y. Srinivasan" <kys@microsoft.com> > Cc: Haiyang Zhang <haiyangz@microsoft.com> > Cc: Wei Liu <wei.liu@kernel.org> > Cc: Dexuan Cui <decui@microsoft.com> > Cc: Thomas Gleixner <tglx@linutronix.de> > Cc: Ingo Molnar <mingo@kernel.org> > Cc: Borislav Petkov <bp@alien8.de> > Cc: Dave Hansen <dave.hansen@linux.intel.com> > Cc: "H. Peter Anvin" <hpa@zytor.com> > Signed-off-by: Uros Bizjak <ubizjak@gmail.com> > --- > arch/x86/kernel/cpu/mshyperv.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kernel/cpu/mshyperv.c > b/arch/x86/kernel/cpu/mshyperv.c index e6bba12c759c..01fa06dd06b6 > 100644 > --- a/arch/x86/kernel/cpu/mshyperv.c > +++ b/arch/x86/kernel/cpu/mshyperv.c > @@ -262,11 +262,14 @@ static uint32_t __init ms_hyperv_platform(void) > static int hv_nmi_unknown(unsigned int val, struct pt_regs *regs) { > static atomic_t nmi_cpu = ATOMIC_INIT(-1); > + unsigned int old_cpu, this_cpu; > > if (!unknown_nmi_panic) > return NMI_DONE; > > - if (atomic_cmpxchg(&nmi_cpu, -1, raw_smp_processor_id()) != -1) > + old_cpu = -1; > + this_cpu = raw_smp_processor_id(); > + if (!atomic_try_cmpxchg(&nmi_cpu, &old_cpu, this_cpu)) > return NMI_HANDLED; > > return NMI_DONE; > -- > 2.41.0 The change looks correct to me. But is there any motivation other than saving 3 bytes of generated code? This is not a performance sensitive path. And the change adds 3 lines of source code. So I wonder if the change is worth the churn. In any case, Reviewed-by: Michael Kelley <mhklinux@outlook.com> ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] x86/hyperv: Use atomic_try_cmpxchg() to micro-optimize hv_nmi_unknown() 2023-11-15 17:19 ` Michael Kelley @ 2023-11-15 20:58 ` Uros Bizjak 2023-11-22 3:51 ` Wei Liu 2023-11-22 16:52 ` Konstantin Ryabitsev 0 siblings, 2 replies; 7+ messages in thread From: Uros Bizjak @ 2023-11-15 20:58 UTC (permalink / raw) To: Michael Kelley Cc: linux-hyperv@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin On Wed, Nov 15, 2023 at 6:19 PM Michael Kelley <mhklinux@outlook.com> wrote: > > From: Uros Bizjak <ubizjak@gmail.com> Sent: Tuesday, November 14, 2023 8:59 AM > > > > Use atomic_try_cmpxchg() instead of atomic_cmpxchg(*ptr, old, new) == old > > in hv_nmi_unknown(). On x86 the CMPXCHG instruction returns success in > > the ZF flag, so this change saves a compare after CMPXCHG. The generated > > asm code improves from: > > > > 3e: 65 8b 15 00 00 00 00 mov %gs:0x0(%rip),%edx > > 45: b8 ff ff ff ff mov $0xffffffff,%eax > > 4a: f0 0f b1 15 00 00 00 lock cmpxchg %edx,0x0(%rip) > > 51: 00 > > 52: 83 f8 ff cmp $0xffffffff,%eax > > 55: 0f 95 c0 setne %al > > > > to: > > > > 3e: 65 8b 15 00 00 00 00 mov %gs:0x0(%rip),%edx > > 45: b8 ff ff ff ff mov $0xffffffff,%eax > > 4a: f0 0f b1 15 00 00 00 lock cmpxchg %edx,0x0(%rip) > > 51: 00 > > 52: 0f 95 c0 setne %al > > > > No functional change intended. > > > > Cc: "K. Y. Srinivasan" <kys@microsoft.com> > > Cc: Haiyang Zhang <haiyangz@microsoft.com> > > Cc: Wei Liu <wei.liu@kernel.org> > > Cc: Dexuan Cui <decui@microsoft.com> > > Cc: Thomas Gleixner <tglx@linutronix.de> > > Cc: Ingo Molnar <mingo@kernel.org> > > Cc: Borislav Petkov <bp@alien8.de> > > Cc: Dave Hansen <dave.hansen@linux.intel.com> > > Cc: "H. Peter Anvin" <hpa@zytor.com> > > Signed-off-by: Uros Bizjak <ubizjak@gmail.com> > > --- > > arch/x86/kernel/cpu/mshyperv.c | 5 ++++- > > 1 file changed, 4 insertions(+), 1 deletion(-) > > > > diff --git a/arch/x86/kernel/cpu/mshyperv.c > > b/arch/x86/kernel/cpu/mshyperv.c index e6bba12c759c..01fa06dd06b6 > > 100644 > > --- a/arch/x86/kernel/cpu/mshyperv.c > > +++ b/arch/x86/kernel/cpu/mshyperv.c > > @@ -262,11 +262,14 @@ static uint32_t __init ms_hyperv_platform(void) > > static int hv_nmi_unknown(unsigned int val, struct pt_regs *regs) { > > static atomic_t nmi_cpu = ATOMIC_INIT(-1); > > + unsigned int old_cpu, this_cpu; > > > > if (!unknown_nmi_panic) > > return NMI_DONE; > > > > - if (atomic_cmpxchg(&nmi_cpu, -1, raw_smp_processor_id()) != -1) > > + old_cpu = -1; > > + this_cpu = raw_smp_processor_id(); > > + if (!atomic_try_cmpxchg(&nmi_cpu, &old_cpu, this_cpu)) > > return NMI_HANDLED; > > > > return NMI_DONE; > > -- > > 2.41.0 > > The change looks correct to me. But is there any motivation other > than saving 3 bytes of generated code? This is not a performance > sensitive path. And the change adds 3 lines of source code. So > I wonder if the change is worth the churn. Yes, I was trying to make the function more easy to understand and similar to nmi_panic() from kernel/panic.c. I had also the idea of using CPU_INVALID #define instead of -1, but IMO, the above works as well. > In any case, > > Reviewed-by: Michael Kelley <mhklinux@outlook.com> Thanks, Uros. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] x86/hyperv: Use atomic_try_cmpxchg() to micro-optimize hv_nmi_unknown() 2023-11-15 20:58 ` Uros Bizjak @ 2023-11-22 3:51 ` Wei Liu 2023-11-22 12:31 ` Uros Bizjak 2023-11-22 16:52 ` Konstantin Ryabitsev 1 sibling, 1 reply; 7+ messages in thread From: Wei Liu @ 2023-11-22 3:51 UTC (permalink / raw) To: Uros Bizjak Cc: Michael Kelley, linux-hyperv@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin On Wed, Nov 15, 2023 at 09:58:29PM +0100, Uros Bizjak wrote: > On Wed, Nov 15, 2023 at 6:19 PM Michael Kelley <mhklinux@outlook.com> wrote: > > > > From: Uros Bizjak <ubizjak@gmail.com> Sent: Tuesday, November 14, 2023 8:59 AM > > > > > > Use atomic_try_cmpxchg() instead of atomic_cmpxchg(*ptr, old, new) == old > > > in hv_nmi_unknown(). On x86 the CMPXCHG instruction returns success in > > > the ZF flag, so this change saves a compare after CMPXCHG. The generated > > > asm code improves from: > > > > > > 3e: 65 8b 15 00 00 00 00 mov %gs:0x0(%rip),%edx > > > 45: b8 ff ff ff ff mov $0xffffffff,%eax > > > 4a: f0 0f b1 15 00 00 00 lock cmpxchg %edx,0x0(%rip) > > > 51: 00 > > > 52: 83 f8 ff cmp $0xffffffff,%eax > > > 55: 0f 95 c0 setne %al > > > > > > to: > > > > > > 3e: 65 8b 15 00 00 00 00 mov %gs:0x0(%rip),%edx > > > 45: b8 ff ff ff ff mov $0xffffffff,%eax > > > 4a: f0 0f b1 15 00 00 00 lock cmpxchg %edx,0x0(%rip) > > > 51: 00 > > > 52: 0f 95 c0 setne %al > > > > > > No functional change intended. > > > > > > Cc: "K. Y. Srinivasan" <kys@microsoft.com> > > > Cc: Haiyang Zhang <haiyangz@microsoft.com> > > > Cc: Wei Liu <wei.liu@kernel.org> > > > Cc: Dexuan Cui <decui@microsoft.com> > > > Cc: Thomas Gleixner <tglx@linutronix.de> > > > Cc: Ingo Molnar <mingo@kernel.org> > > > Cc: Borislav Petkov <bp@alien8.de> > > > Cc: Dave Hansen <dave.hansen@linux.intel.com> > > > Cc: "H. Peter Anvin" <hpa@zytor.com> > > > Signed-off-by: Uros Bizjak <ubizjak@gmail.com> > > > --- > > > arch/x86/kernel/cpu/mshyperv.c | 5 ++++- > > > 1 file changed, 4 insertions(+), 1 deletion(-) > > > > > > diff --git a/arch/x86/kernel/cpu/mshyperv.c > > > b/arch/x86/kernel/cpu/mshyperv.c index e6bba12c759c..01fa06dd06b6 > > > 100644 > > > --- a/arch/x86/kernel/cpu/mshyperv.c > > > +++ b/arch/x86/kernel/cpu/mshyperv.c > > > @@ -262,11 +262,14 @@ static uint32_t __init ms_hyperv_platform(void) > > > static int hv_nmi_unknown(unsigned int val, struct pt_regs *regs) { > > > static atomic_t nmi_cpu = ATOMIC_INIT(-1); > > > + unsigned int old_cpu, this_cpu; > > > > > > if (!unknown_nmi_panic) > > > return NMI_DONE; > > > > > > - if (atomic_cmpxchg(&nmi_cpu, -1, raw_smp_processor_id()) != -1) > > > + old_cpu = -1; > > > + this_cpu = raw_smp_processor_id(); > > > + if (!atomic_try_cmpxchg(&nmi_cpu, &old_cpu, this_cpu)) > > > return NMI_HANDLED; > > > > > > return NMI_DONE; > > > -- > > > 2.41.0 > > > > The change looks correct to me. But is there any motivation other > > than saving 3 bytes of generated code? This is not a performance > > sensitive path. And the change adds 3 lines of source code. So > > I wonder if the change is worth the churn. > > Yes, I was trying to make the function more easy to understand and > similar to nmi_panic() from kernel/panic.c. I had also the idea of > using CPU_INVALID #define instead of -1, but IMO, the above works as > well. > > > In any case, > > > > Reviewed-by: Michael Kelley <mhklinux@outlook.com> Applied to hyperv-fixes. Uros, just so you know, DKIM verification failed when I used b4 to apply this patch. You may want to check your email setup. For such a simple patch I'm not worried about spoofing authorship, and I also checked the same email address had sent similar patches before. Thanks, Wei. > > Thanks, > Uros. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] x86/hyperv: Use atomic_try_cmpxchg() to micro-optimize hv_nmi_unknown() 2023-11-22 3:51 ` Wei Liu @ 2023-11-22 12:31 ` Uros Bizjak 2023-11-22 12:38 ` Uros Bizjak 0 siblings, 1 reply; 7+ messages in thread From: Uros Bizjak @ 2023-11-22 12:31 UTC (permalink / raw) To: Wei Liu Cc: Michael Kelley, linux-hyperv@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, K. Y. Srinivasan, Haiyang Zhang, Dexuan Cui, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin On Wed, Nov 22, 2023 at 4:52 AM Wei Liu <wei.liu@kernel.org> wrote: > > On Wed, Nov 15, 2023 at 09:58:29PM +0100, Uros Bizjak wrote: > > On Wed, Nov 15, 2023 at 6:19 PM Michael Kelley <mhklinux@outlook.com> wrote: > > > > > > From: Uros Bizjak <ubizjak@gmail.com> Sent: Tuesday, November 14, 2023 8:59 AM > > > > > > > > Use atomic_try_cmpxchg() instead of atomic_cmpxchg(*ptr, old, new) == old > > > > in hv_nmi_unknown(). On x86 the CMPXCHG instruction returns success in > > > > the ZF flag, so this change saves a compare after CMPXCHG. The generated > > > > asm code improves from: > > > > > > > > 3e: 65 8b 15 00 00 00 00 mov %gs:0x0(%rip),%edx > > > > 45: b8 ff ff ff ff mov $0xffffffff,%eax > > > > 4a: f0 0f b1 15 00 00 00 lock cmpxchg %edx,0x0(%rip) > > > > 51: 00 > > > > 52: 83 f8 ff cmp $0xffffffff,%eax > > > > 55: 0f 95 c0 setne %al > > > > > > > > to: > > > > > > > > 3e: 65 8b 15 00 00 00 00 mov %gs:0x0(%rip),%edx > > > > 45: b8 ff ff ff ff mov $0xffffffff,%eax > > > > 4a: f0 0f b1 15 00 00 00 lock cmpxchg %edx,0x0(%rip) > > > > 51: 00 > > > > 52: 0f 95 c0 setne %al > > > > > > > > No functional change intended. > > > > > > > > Cc: "K. Y. Srinivasan" <kys@microsoft.com> > > > > Cc: Haiyang Zhang <haiyangz@microsoft.com> > > > > Cc: Wei Liu <wei.liu@kernel.org> > > > > Cc: Dexuan Cui <decui@microsoft.com> > > > > Cc: Thomas Gleixner <tglx@linutronix.de> > > > > Cc: Ingo Molnar <mingo@kernel.org> > > > > Cc: Borislav Petkov <bp@alien8.de> > > > > Cc: Dave Hansen <dave.hansen@linux.intel.com> > > > > Cc: "H. Peter Anvin" <hpa@zytor.com> > > > > Signed-off-by: Uros Bizjak <ubizjak@gmail.com> > > > > --- > > > > arch/x86/kernel/cpu/mshyperv.c | 5 ++++- > > > > 1 file changed, 4 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/arch/x86/kernel/cpu/mshyperv.c > > > > b/arch/x86/kernel/cpu/mshyperv.c index e6bba12c759c..01fa06dd06b6 > > > > 100644 > > > > --- a/arch/x86/kernel/cpu/mshyperv.c > > > > +++ b/arch/x86/kernel/cpu/mshyperv.c > > > > @@ -262,11 +262,14 @@ static uint32_t __init ms_hyperv_platform(void) > > > > static int hv_nmi_unknown(unsigned int val, struct pt_regs *regs) { > > > > static atomic_t nmi_cpu = ATOMIC_INIT(-1); > > > > + unsigned int old_cpu, this_cpu; > > > > > > > > if (!unknown_nmi_panic) > > > > return NMI_DONE; > > > > > > > > - if (atomic_cmpxchg(&nmi_cpu, -1, raw_smp_processor_id()) != -1) > > > > + old_cpu = -1; > > > > + this_cpu = raw_smp_processor_id(); > > > > + if (!atomic_try_cmpxchg(&nmi_cpu, &old_cpu, this_cpu)) > > > > return NMI_HANDLED; > > > > > > > > return NMI_DONE; > > > > -- > > > > 2.41.0 > > > > > > The change looks correct to me. But is there any motivation other > > > than saving 3 bytes of generated code? This is not a performance > > > sensitive path. And the change adds 3 lines of source code. So > > > I wonder if the change is worth the churn. > > > > Yes, I was trying to make the function more easy to understand and > > similar to nmi_panic() from kernel/panic.c. I had also the idea of > > using CPU_INVALID #define instead of -1, but IMO, the above works as > > well. > > > > > In any case, > > > > > > Reviewed-by: Michael Kelley <mhklinux@outlook.com> > > Applied to hyperv-fixes. > > Uros, just so you know, DKIM verification failed when I used b4 to apply > this patch. You may want to check your email setup. Strange, because I didn't touch the mailer and git config for months... and recently I have sent many patches this way without problems. Thanks, Uros. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] x86/hyperv: Use atomic_try_cmpxchg() to micro-optimize hv_nmi_unknown() 2023-11-22 12:31 ` Uros Bizjak @ 2023-11-22 12:38 ` Uros Bizjak 0 siblings, 0 replies; 7+ messages in thread From: Uros Bizjak @ 2023-11-22 12:38 UTC (permalink / raw) To: Wei Liu Cc: Michael Kelley, linux-hyperv@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, K. Y. Srinivasan, Haiyang Zhang, Dexuan Cui, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin On Wed, Nov 22, 2023 at 1:31 PM Uros Bizjak <ubizjak@gmail.com> wrote: > > On Wed, Nov 22, 2023 at 4:52 AM Wei Liu <wei.liu@kernel.org> wrote: > > > > On Wed, Nov 15, 2023 at 09:58:29PM +0100, Uros Bizjak wrote: > > > On Wed, Nov 15, 2023 at 6:19 PM Michael Kelley <mhklinux@outlook.com> wrote: > > > > > > > > From: Uros Bizjak <ubizjak@gmail.com> Sent: Tuesday, November 14, 2023 8:59 AM > > > > > > > > > > Use atomic_try_cmpxchg() instead of atomic_cmpxchg(*ptr, old, new) == old > > > > > in hv_nmi_unknown(). On x86 the CMPXCHG instruction returns success in > > > > > the ZF flag, so this change saves a compare after CMPXCHG. The generated > > > > > asm code improves from: > > > > > > > > > > 3e: 65 8b 15 00 00 00 00 mov %gs:0x0(%rip),%edx > > > > > 45: b8 ff ff ff ff mov $0xffffffff,%eax > > > > > 4a: f0 0f b1 15 00 00 00 lock cmpxchg %edx,0x0(%rip) > > > > > 51: 00 > > > > > 52: 83 f8 ff cmp $0xffffffff,%eax > > > > > 55: 0f 95 c0 setne %al > > > > > > > > > > to: > > > > > > > > > > 3e: 65 8b 15 00 00 00 00 mov %gs:0x0(%rip),%edx > > > > > 45: b8 ff ff ff ff mov $0xffffffff,%eax > > > > > 4a: f0 0f b1 15 00 00 00 lock cmpxchg %edx,0x0(%rip) > > > > > 51: 00 > > > > > 52: 0f 95 c0 setne %al > > > > > > > > > > No functional change intended. > > > > > > > > > > Cc: "K. Y. Srinivasan" <kys@microsoft.com> > > > > > Cc: Haiyang Zhang <haiyangz@microsoft.com> > > > > > Cc: Wei Liu <wei.liu@kernel.org> > > > > > Cc: Dexuan Cui <decui@microsoft.com> > > > > > Cc: Thomas Gleixner <tglx@linutronix.de> > > > > > Cc: Ingo Molnar <mingo@kernel.org> > > > > > Cc: Borislav Petkov <bp@alien8.de> > > > > > Cc: Dave Hansen <dave.hansen@linux.intel.com> > > > > > Cc: "H. Peter Anvin" <hpa@zytor.com> > > > > > Signed-off-by: Uros Bizjak <ubizjak@gmail.com> > > > > > --- > > > > > arch/x86/kernel/cpu/mshyperv.c | 5 ++++- > > > > > 1 file changed, 4 insertions(+), 1 deletion(-) > > > > > > > > > > diff --git a/arch/x86/kernel/cpu/mshyperv.c > > > > > b/arch/x86/kernel/cpu/mshyperv.c index e6bba12c759c..01fa06dd06b6 > > > > > 100644 > > > > > --- a/arch/x86/kernel/cpu/mshyperv.c > > > > > +++ b/arch/x86/kernel/cpu/mshyperv.c > > > > > @@ -262,11 +262,14 @@ static uint32_t __init ms_hyperv_platform(void) > > > > > static int hv_nmi_unknown(unsigned int val, struct pt_regs *regs) { > > > > > static atomic_t nmi_cpu = ATOMIC_INIT(-1); > > > > > + unsigned int old_cpu, this_cpu; > > > > > > > > > > if (!unknown_nmi_panic) > > > > > return NMI_DONE; > > > > > > > > > > - if (atomic_cmpxchg(&nmi_cpu, -1, raw_smp_processor_id()) != -1) > > > > > + old_cpu = -1; > > > > > + this_cpu = raw_smp_processor_id(); > > > > > + if (!atomic_try_cmpxchg(&nmi_cpu, &old_cpu, this_cpu)) > > > > > return NMI_HANDLED; > > > > > > > > > > return NMI_DONE; > > > > > -- > > > > > 2.41.0 > > > > > > > > The change looks correct to me. But is there any motivation other > > > > than saving 3 bytes of generated code? This is not a performance > > > > sensitive path. And the change adds 3 lines of source code. So > > > > I wonder if the change is worth the churn. > > > > > > Yes, I was trying to make the function more easy to understand and > > > similar to nmi_panic() from kernel/panic.c. I had also the idea of > > > using CPU_INVALID #define instead of -1, but IMO, the above works as > > > well. > > > > > > > In any case, > > > > > > > > Reviewed-by: Michael Kelley <mhklinux@outlook.com> > > > > Applied to hyperv-fixes. > > > > Uros, just so you know, DKIM verification failed when I used b4 to apply > > this patch. You may want to check your email setup. > > Strange, because I didn't touch the mailer and git config for > months... and recently I have sent many patches this way without > problems. This one [1] checks OK, so it looks like some transient issue with gmail. [1] https://lore.kernel.org/lkml/20231120153419.3045-1-ubizjak@gmail.com/ Thanks, Uros. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] x86/hyperv: Use atomic_try_cmpxchg() to micro-optimize hv_nmi_unknown() 2023-11-15 20:58 ` Uros Bizjak 2023-11-22 3:51 ` Wei Liu @ 2023-11-22 16:52 ` Konstantin Ryabitsev 1 sibling, 0 replies; 7+ messages in thread From: Konstantin Ryabitsev @ 2023-11-22 16:52 UTC (permalink / raw) To: Wei Liu, Uros Bizjak; +Cc: linux-hyperv, linux-kernel, tools November 21, 2023 at 10:51 PM, "Wei Liu" <wei.liu@kernel.org> wrote: > Uros, just so you know, DKIM verification failed when I used b4 to apply > this patch. You may want to check your email setup. This is not actually Uros's fault. Recently, Gmail started adding a forced expiration field to their DKIM signatures, via the x= field: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699981249; x=1700586049; darn=vger.kernel.org; ^^^^^^^^^^^^^ This gives the signature an enforced validity of only 7 days. Since the original message was sent on November 14 and you're retrieving it on November 21, this causes the DKIM check to fail. I need to figure out how to make b4 ignore the x= field, because it's not relevant for our purposes, but the library we're using for DKIM doesn't currently have any mechanism to do so. I will open an RFE with them in the hopes that we can get this implemented. Regards, -K ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-11-22 16:59 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-11-14 16:59 [PATCH] x86/hyperv: Use atomic_try_cmpxchg() to micro-optimize hv_nmi_unknown() Uros Bizjak 2023-11-15 17:19 ` Michael Kelley 2023-11-15 20:58 ` Uros Bizjak 2023-11-22 3:51 ` Wei Liu 2023-11-22 12:31 ` Uros Bizjak 2023-11-22 12:38 ` Uros Bizjak 2023-11-22 16:52 ` Konstantin Ryabitsev
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).