Skip to content

Commit bb5a93a

Browse files
committed
x86/ldt: use "pr_info_once()" instead of open-coding it badly
Using a mutex for "print this warning only once" is so overdesigned as to be actively offensive to my sensitive stomach. Just use "pr_info_once()" that already does this, although in a (harmlessly) racy manner that can in theory cause the message to be printed twice if more than one CPU races on that "is this the first time" test. [ If somebody really cares about that harmless data race (which sounds very unlikely indeed), that person can trivially fix printk_once() by using a simple atomic access, preferably with an optimistic non-atomic test first before even bothering to treat the pointless "make sure it is _really_ just once" case. A mutex is most definitely never the right primitive to use for something like this. ] Yes, this is a small and meaningless detail in a code path that hardly matters. But let's keep some code quality standards here, and not accept outrageously bad code. Link: https://lore.kernel.org/lkml/CAHk-=wgV9toS7GU3KmNpj8hCS9SeF+A0voHS8F275_mgLhL4Lw@mail.gmail.com/ Cc: Andy Lutomirski <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 72674d4 commit bb5a93a

File tree

1 file changed

+1
-10
lines changed

1 file changed

+1
-10
lines changed

arch/x86/kernel/ldt.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -559,16 +559,7 @@ static bool allow_16bit_segments(void)
559559
* is worthwhile, disallow 16-bit segments under Xen PV.
560560
*/
561561
if (xen_pv_domain()) {
562-
static DEFINE_MUTEX(xen_warning);
563-
static bool warned;
564-
565-
mutex_lock(&xen_warning);
566-
if (!warned) {
567-
pr_info("Warning: 16-bit segments do not work correctly in a Xen PV guest\n");
568-
warned = true;
569-
}
570-
mutex_unlock(&xen_warning);
571-
562+
pr_info_once("Warning: 16-bit segments do not work correctly in a Xen PV guest\n");
572563
return false;
573564
}
574565
#endif

0 commit comments

Comments
 (0)