mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] x86/boot: Add error_putdec() helper
@ 2024-02-02  3:51 NOMURA JUNICHI(野村 淳一)
  2024-02-02  3:51 ` [PATCH 2/2] x86/boot: Add a message about ignored early NMIs NOMURA JUNICHI(野村 淳一)
  2024-02-06 10:01 ` [tip: x86/boot] x86/boot: Add error_putdec() helper tip-bot2 for H. Peter Anvin
  0 siblings, 2 replies; 3+ messages in thread
From: NOMURA JUNICHI(野村 淳一) @ 2024-02-02  3:51 UTC (permalink / raw)
  To: x86, mingo, tglx, bp, dave.hansen
  Cc: hpa, ardb, david, debarbos, dzickus, jlelli,
	NOMURA JUNICHI(野村 淳一),
	kirill.shutemov, lgoncalv, linux-kernel, nikunj, thomas.lendacky

From: "H. Peter Anvin" <hpa@zytor.com>

Add a helper to print decimal numbers to early console.

Suggested-by: Borislav Petkov (AMD) <bp@alien8.de>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Signed-off-by: Jun'ichi Nomura <junichi.nomura@nec.com>
Link: https://lore.kernel.org/lkml/20240123112624.GBZa-iYP1l9SSYtr-V@fat_crate.local/

diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
--- 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
--- 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
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] x86/boot: Add a message about ignored early NMIs
  2024-02-02  3:51 [PATCH 1/2] x86/boot: Add error_putdec() helper NOMURA JUNICHI(野村 淳一)
@ 2024-02-02  3:51 ` NOMURA JUNICHI(野村 淳一)
  2024-02-06 10:01 ` [tip: x86/boot] x86/boot: Add error_putdec() helper tip-bot2 for H. Peter Anvin
  1 sibling, 0 replies; 3+ messages in thread
From: NOMURA JUNICHI(野村 淳一) @ 2024-02-02  3:51 UTC (permalink / raw)
  To: x86, mingo, tglx, bp, dave.hansen
  Cc: hpa, ardb, david, debarbos, dzickus, jlelli,
	NOMURA JUNICHI(野村 淳一),
	kirill.shutemov, lgoncalv, linux-kernel, nikunj, thomas.lendacky

Commit

  78a509fba9c9 ("x86/boot: Ignore NMIs during very early boot")

added an empty handler in early boot stage to avoid boot failure due to
spurious NMIs.

Add a diagnostic message to show when early NMIs have occurred and/or
what happened to them.

  [ bp: Touchups. ]

Suggested-by: Borislav Petkov <bp@alien8.de>
Suggested-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Jun'ichi Nomura <junichi.nomura@nec.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Link: https://lore.kernel.org/lkml/20231130103339.GCZWhlA196uRklTMNF@fat_crate.local

--
v2
  * Moved variable declaration and definition to the right place
    based on comments from Kirill.
    No functional changes.
v3
  * Removed comment and updated message in the NMI handler.
  * Use error_putdec() helper.

diff --git a/arch/x86/boot/compressed/ident_map_64.c b/arch/x86/boot/compressed/ident_map_64.c
--- a/arch/x86/boot/compressed/ident_map_64.c
+++ b/arch/x86/boot/compressed/ident_map_64.c
@@ -389,5 +389,5 @@ void do_boot_page_fault(struct pt_regs *regs, unsigned long error_code)
 
 void do_boot_nmi_trap(struct pt_regs *regs, unsigned long error_code)
 {
-	/* Empty handler to ignore NMI during early boot */
+	spurious_nmi_count++;
 }
diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
--- a/arch/x86/boot/compressed/misc.c
+++ b/arch/x86/boot/compressed/misc.c
@@ -52,6 +52,7 @@ struct port_io_ops pio_ops;
 
 memptr free_mem_ptr;
 memptr free_mem_end_ptr;
+int spurious_nmi_count;
 
 static char *vidmem;
 static int vidport;
@@ -493,6 +494,12 @@ asmlinkage __visible void *extract_kernel(void *rmode, unsigned char *output)
 	/* Disable exception handling before booting the kernel */
 	cleanup_exception_handling();
 
+	if (spurious_nmi_count) {
+		error_putstr("Spurious early NMIs ignored: ");
+		error_putdec(spurious_nmi_count);
+		error_putstr("\n");
+	}
+
 	return output + entry_offset;
 }
 
diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h
--- a/arch/x86/boot/compressed/misc.h
+++ b/arch/x86/boot/compressed/misc.h
@@ -59,6 +59,7 @@ extern char _head[], _end[];
 /* misc.c */
 extern memptr free_mem_ptr;
 extern memptr free_mem_end_ptr;
+extern int spurious_nmi_count;
 void *malloc(int size);
 void free(void *where);
 void __putstr(const char *s);

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip: x86/boot] x86/boot: Add error_putdec() helper
  2024-02-02  3:51 [PATCH 1/2] x86/boot: Add error_putdec() helper NOMURA JUNICHI(野村 淳一)
  2024-02-02  3:51 ` [PATCH 2/2] x86/boot: Add a message about ignored early NMIs NOMURA JUNICHI(野村 淳一)
@ 2024-02-06 10:01 ` tip-bot2 for H. Peter Anvin
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for H. Peter Anvin @ 2024-02-06 10:01 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Borislav Petkov (AMD), H. Peter Anvin (Intel),
	Jun'ichi Nomura, x86, linux-kernel

The following commit has been merged into the x86/boot branch of tip:

Commit-ID:     9ba8ec8ee67a00eb5631364e4b716f35559724d4
Gitweb:        https://git.kernel.org/tip/9ba8ec8ee67a00eb5631364e4b716f35559724d4
Author:        H. Peter Anvin <hpa@zytor.com>
AuthorDate:    Fri, 02 Feb 2024 03:51:43 
Committer:     Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Tue, 06 Feb 2024 10:50:21 +01:00

x86/boot: Add error_putdec() helper

Add a helper to print decimal numbers to early console.

Suggested-by: Borislav Petkov (AMD) <bp@alien8.de>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Signed-off-by: Jun'ichi Nomura <junichi.nomura@nec.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/lkml/20240123112624.GBZa-iYP1l9SSYtr-V@fat_crate.local/
Link: https://lore.kernel.org/r/20240202035052.17963-1-junichi.nomura@nec.com
---
 arch/x86/boot/compressed/misc.c | 33 ++++++++++++++++++++++----------
 arch/x86/boot/compressed/misc.h |  2 ++-
 2 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
index b99e08e..bf2aac4 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 bc2f0f1..6502bc6 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
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-06 10:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-02  3:51 [PATCH 1/2] x86/boot: Add error_putdec() helper NOMURA JUNICHI(野村 淳一)
2024-02-02  3:51 ` [PATCH 2/2] x86/boot: Add a message about ignored early NMIs NOMURA JUNICHI(野村 淳一)
2024-02-06 10:01 ` [tip: x86/boot] x86/boot: Add error_putdec() helper tip-bot2 for H. Peter Anvin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®