x86/traps: Drop dummy_nmi_callback()

The unconditional nmi_callback() call in do_nmi() calls dummy_nmi_callback()
in all cases other than for a few specific and rare tasks (alternative
patching, microcode loading, etc).

Indirect calls are expensive under retpoline, so rearrange the logic to use
NULL as the default, and skip the call entirely in the common case.

While rearranging the code, fold the exit paths.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
This commit is contained in:
Andrew Cooper committed 2021-11-29 13:53:05 +00:00
1 parent d9f60a924c
commit 04c48ccd75
1 file changed
+7 -12
+7 -12
View File
@@ -1869,29 +1869,23 @@ static void unknown_nmi_error(const struct cpu_user_regs *regs,
}
}
static int dummy_nmi_callback(const struct cpu_user_regs *regs, int cpu)
{
return 0;
}
static nmi_callback_t *nmi_callback = dummy_nmi_callback;
static nmi_callback_t *__read_mostly nmi_callback;
DEFINE_PER_CPU(unsigned int, nmi_count);
void do_nmi(const struct cpu_user_regs *regs)
{
unsigned int cpu = smp_processor_id();
nmi_callback_t *callback;
unsigned char reason = 0;
bool handle_unknown = false;
this_cpu(nmi_count)++;
nmi_enter();
if ( nmi_callback(regs, cpu) )
{
nmi_exit();
return;
}
callback = ACCESS_ONCE(nmi_callback);
if ( unlikely(callback) && callback(regs, cpu) )
goto out;
/*
* Accessing port 0x61 may trap to SMM which has been actually
@@ -1918,6 +1912,7 @@ void do_nmi(const struct cpu_user_regs *regs)
unknown_nmi_error(regs, reason);
}
out:
nmi_exit();
}
@@ -1932,7 +1927,7 @@ nmi_callback_t *set_nmi_callback(nmi_callback_t *callback)
void unset_nmi_callback(void)
{
nmi_callback = dummy_nmi_callback;
nmi_callback = NULL;
}
bool nmi_check_continuation(void)
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.