Re: [PATCH v2] x86/boot: Add a message about ignored early NMIs

From: H. Peter Anvin
Date: Wed Jan 24 2024 - 21:01:49 EST




On 1/24/24 03:44, NOMURA JUNICHI(野村 淳一) wrote:
From: Borislav Petkov <bp@xxxxxxxxx>
On Mon, Jan 15, 2024 at 08:57:45AM +0000, NOMURA JUNICHI(野村 淳一) wrote:
+ if (spurious_nmi_count) {
+ error_putstr("Spurious early NMI ignored. Number of NMIs: 0x");
+ error_puthex(spurious_nmi_count);
+ error_putstr("\n");

Uff, that's just silly:

Spurious early NMIs ignored: 0x0000000000000017

Would you like to add a error_putnum() or so in a prepatch which would
make this output

Spurious early NMIs ignored: 23.

?

So that it is human readable and doesn't make me wonder what that hex
value is supposed to mean?

Yes, it would be nicer to print that way. I used the existing error_puthex() just
to keep the patch minimal. I will try to add error_putnum().

Btw, please use this version when sending next time:


Here is a *completely* untested patch for you...

-hpa
diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
index b99e08e6815b..bf2aac4f195e 100644
--- a/arch/x86/boot/compressed/misc.c
+++ b/arch/x86/boot/compressed/misc.c
@@ -164,21 +164,34 @@ void __putstr(const char *s)
outb(0xff & (pos >> 1), vidport+1);
}

-void __puthex(unsigned long value)
+static noinline void __putnum(unsigned long value, unsigned int base,
+ int mindig)
{
- char alpha[2] = "0";
- int bits;
+ char buf[8*sizeof(value)+1];
+ char *p;

- for (bits = sizeof(value) * 8 - 4; bits >= 0; bits -= 4) {
- unsigned long digit = (value >> bits) & 0xf;
+ p = buf + sizeof(buf);
+ *--p = '\0';

- if (digit < 0xA)
- alpha[0] = '0' + digit;
- else
- alpha[0] = 'a' + (digit - 0xA);
+ while (mindig-- > 0 || value) {
+ unsigned char digit = value % base;
+ digit += (digit >= 10) ? ('a'-10) : '0';
+ *--p = digit;

- __putstr(alpha);
+ value /= base;
}
+
+ __putstr(p);
+}
+
+void __puthex(unsigned long value)
+{
+ __putnum(value, 16, sizeof(value)*2);
+}
+
+void __putdec(unsigned long value)
+{
+ __putnum(value, 10, 1);
}

#ifdef CONFIG_X86_NEED_RELOCS
diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h
index bc2f0f17fb90..6502bc69d1b8 100644
--- a/arch/x86/boot/compressed/misc.h
+++ b/arch/x86/boot/compressed/misc.h
@@ -63,8 +63,10 @@ void *malloc(int size);
void free(void *where);
void __putstr(const char *s);
void __puthex(unsigned long value);
+void __putdec(unsigned long value);
#define error_putstr(__x) __putstr(__x)
#define error_puthex(__x) __puthex(__x)
+#define error_putdec(__x) __putdec(__x)

#ifdef CONFIG_X86_VERBOSE_BOOTUP