All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] parisc: Fix locking in pdc_iodc_print() firmware call
@ 2022-11-26 21:36 Helge Deller
  2022-11-26 21:36 ` [PATCH 2/4] parisc: Merge hpmc_iodc_buf and iodc_dbuf buffers Helge Deller
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Helge Deller @ 2022-11-26 21:36 UTC (permalink / raw)
  To: linux-parisc

Utilize pdc_lock spinlock to protect parallel modifications of the
iodc_dbuf[] buffer, check length to prevent buffer overflow of
iodc_dbuf[], drop the iodc_retbuf[] buffer and fix some wrong
indentings.

Signed-off-by: Helge Deller <deller@gmx.de>
---
 arch/parisc/kernel/firmware.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/arch/parisc/kernel/firmware.c b/arch/parisc/kernel/firmware.c
index 6a7e315bcc2e..c19506fc4e4e 100644
--- a/arch/parisc/kernel/firmware.c
+++ b/arch/parisc/kernel/firmware.c
@@ -1288,9 +1288,8 @@ void pdc_io_reset_devices(void)

 #endif /* defined(BOOTLOADER) */

-/* locked by pdc_console_lock */
-static int __attribute__((aligned(8)))   iodc_retbuf[32];
-static char __attribute__((aligned(64))) iodc_dbuf[4096];
+/* locked by pdc_lock */
+char iodc_dbuf[2*4096] __page_aligned_bss;

 /**
  * pdc_iodc_print - Console print using IODC.
@@ -1307,6 +1306,9 @@ int pdc_iodc_print(const unsigned char *str, unsigned count)
 	unsigned int i;
 	unsigned long flags;

+	count = min(count, sizeof(iodc_dbuf));
+
+	spin_lock_irqsave(&pdc_lock, flags);
 	for (i = 0; i < count;) {
 		switch(str[i]) {
 		case '\n':
@@ -1322,12 +1324,11 @@ int pdc_iodc_print(const unsigned char *str, unsigned count)
 	}

 print:
-        spin_lock_irqsave(&pdc_lock, flags);
-        real32_call(PAGE0->mem_cons.iodc_io,
-                    (unsigned long)PAGE0->mem_cons.hpa, ENTRY_IO_COUT,
-                    PAGE0->mem_cons.spa, __pa(PAGE0->mem_cons.dp.layers),
-                    __pa(iodc_retbuf), 0, __pa(iodc_dbuf), i, 0);
-        spin_unlock_irqrestore(&pdc_lock, flags);
+	real32_call(PAGE0->mem_cons.iodc_io,
+		(unsigned long)PAGE0->mem_cons.hpa, ENTRY_IO_COUT,
+		PAGE0->mem_cons.spa, __pa(PAGE0->mem_cons.dp.layers),
+		__pa(pdc_result), 0, __pa(iodc_dbuf), i, 0);
+	spin_unlock_irqrestore(&pdc_lock, flags);

 	return i;
 }
@@ -1354,10 +1355,10 @@ int pdc_iodc_getc(void)
 	real32_call(PAGE0->mem_kbd.iodc_io,
 		    (unsigned long)PAGE0->mem_kbd.hpa, ENTRY_IO_CIN,
 		    PAGE0->mem_kbd.spa, __pa(PAGE0->mem_kbd.dp.layers),
-		    __pa(iodc_retbuf), 0, __pa(iodc_dbuf), 1, 0);
+		    __pa(pdc_result), 0, __pa(iodc_dbuf), 1, 0);

 	ch = *iodc_dbuf;
-	status = *iodc_retbuf;
+	status = *pdc_result;
 	spin_unlock_irqrestore(&pdc_lock, flags);

 	if (status == 0)
--
2.38.1


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

* [PATCH 2/4] parisc: Merge hpmc_iodc_buf and iodc_dbuf buffers
  2022-11-26 21:36 [PATCH 1/4] parisc: Fix locking in pdc_iodc_print() firmware call Helge Deller
@ 2022-11-26 21:36 ` Helge Deller
  2022-11-26 21:36 ` [PATCH 3/4] parisc: Drop duplicate kgdb_pdc console in pdc_cons.c Helge Deller
  2022-11-26 21:36 ` [PATCH 4/4] parisc: Fix kgdb_pdc console read/write funtions Helge Deller
  2 siblings, 0 replies; 4+ messages in thread
From: Helge Deller @ 2022-11-26 21:36 UTC (permalink / raw)
  To: linux-parisc

The HPMC handler can share the IODC buffer with the various firmware
calls.

Signed-off-by: Helge Deller <deller@gmx.de>
---
 arch/parisc/kernel/hpmc.S | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/arch/parisc/kernel/hpmc.S b/arch/parisc/kernel/hpmc.S
index eb2e4bd67035..1dc85e963a17 100644
--- a/arch/parisc/kernel/hpmc.S
+++ b/arch/parisc/kernel/hpmc.S
@@ -44,15 +44,11 @@
 	 */

 	.import toc_stack,data
+	.import iodc_dbuf,data
 #define hpmc_stack	toc_stack	/* re-use the TOC stack */
-
+#define hpmc_iodc_buf	iodc_dbuf	/* re-use IODC buffer from firmware.c */
 #define HPMC_IODC_BUF_SIZE 0x8000

-	__PAGE_ALIGNED_BSS
-	.align 4096
-hpmc_iodc_buf:
-	.block HPMC_IODC_BUF_SIZE
-
 	.section .bss
 	.align 8
 hpmc_raddr:
--
2.38.1


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

* [PATCH 3/4] parisc: Drop duplicate kgdb_pdc console in pdc_cons.c
  2022-11-26 21:36 [PATCH 1/4] parisc: Fix locking in pdc_iodc_print() firmware call Helge Deller
  2022-11-26 21:36 ` [PATCH 2/4] parisc: Merge hpmc_iodc_buf and iodc_dbuf buffers Helge Deller
@ 2022-11-26 21:36 ` Helge Deller
  2022-11-26 21:36 ` [PATCH 4/4] parisc: Fix kgdb_pdc console read/write funtions Helge Deller
  2 siblings, 0 replies; 4+ messages in thread
From: Helge Deller @ 2022-11-26 21:36 UTC (permalink / raw)
  To: linux-parisc

The kgdb console is already registered in kgdb.c, so the duplicate code
can be dropped.

Signed-off-by: Helge Deller <deller@gmx.de>
---
 arch/parisc/kernel/pdc_cons.c | 36 -----------------------------------
 1 file changed, 36 deletions(-)

diff --git a/arch/parisc/kernel/pdc_cons.c b/arch/parisc/kernel/pdc_cons.c
index 7d0989f523d0..eebfc3e3d94c 100644
--- a/arch/parisc/kernel/pdc_cons.c
+++ b/arch/parisc/kernel/pdc_cons.c
@@ -8,50 +8,18 @@
 #include <linux/console.h>
 #include <linux/init.h>
 #include <linux/serial_core.h>
-#include <linux/kgdb.h>
 #include <asm/page.h>		/* for PAGE0 */
 #include <asm/pdc.h>		/* for iodc_call() proto and friends */

-static DEFINE_SPINLOCK(pdc_console_lock);
-
 static void pdc_console_write(struct console *co, const char *s, unsigned count)
 {
 	int i = 0;
-	unsigned long flags;

-	spin_lock_irqsave(&pdc_console_lock, flags);
 	do {
 		i += pdc_iodc_print(s + i, count - i);
 	} while (i < count);
-	spin_unlock_irqrestore(&pdc_console_lock, flags);
-}
-
-#ifdef CONFIG_KGDB
-static int kgdb_pdc_read_char(void)
-{
-	int c;
-	unsigned long flags;
-
-	spin_lock_irqsave(&pdc_console_lock, flags);
-	c = pdc_iodc_getc();
-	spin_unlock_irqrestore(&pdc_console_lock, flags);
-
-	return (c <= 0) ? NO_POLL_CHAR : c;
 }

-static void kgdb_pdc_write_char(u8 chr)
-{
-	if (PAGE0->mem_cons.cl_class != CL_DUPLEX)
-		pdc_console_write(NULL, &chr, 1);
-}
-
-static struct kgdb_io kgdb_pdc_io_ops = {
-	.name = "kgdb_pdc",
-	.read_char = kgdb_pdc_read_char,
-	.write_char = kgdb_pdc_write_char,
-};
-#endif
-
 static int __init pdc_earlycon_setup(struct earlycon_device *device,
 				     const char *opt)
 {
@@ -65,10 +33,6 @@ static int __init pdc_earlycon_setup(struct earlycon_device *device,
 	earlycon_console->write = pdc_console_write;
 	device->port.iotype = UPIO_MEM32BE;

-#ifdef CONFIG_KGDB
-	kgdb_register_io_module(&kgdb_pdc_io_ops);
-#endif
-
 	return 0;
 }

--
2.38.1


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

* [PATCH 4/4] parisc: Fix kgdb_pdc console read/write funtions
  2022-11-26 21:36 [PATCH 1/4] parisc: Fix locking in pdc_iodc_print() firmware call Helge Deller
  2022-11-26 21:36 ` [PATCH 2/4] parisc: Merge hpmc_iodc_buf and iodc_dbuf buffers Helge Deller
  2022-11-26 21:36 ` [PATCH 3/4] parisc: Drop duplicate kgdb_pdc console in pdc_cons.c Helge Deller
@ 2022-11-26 21:36 ` Helge Deller
  2 siblings, 0 replies; 4+ messages in thread
From: Helge Deller @ 2022-11-26 21:36 UTC (permalink / raw)
  To: linux-parisc

Allow the kgdb debugger to read chars from PDC firmware console
(keyboard or serial port), and fix output to only show up on monitors
since the output to serial ports is already happens in the kgdb serial
driver.

Signed-off-by: Helge Deller <deller@gmx.de>
---
 arch/parisc/kernel/kgdb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/arch/parisc/kernel/kgdb.c b/arch/parisc/kernel/kgdb.c
index ab7620f695be..586046d52712 100644
--- a/arch/parisc/kernel/kgdb.c
+++ b/arch/parisc/kernel/kgdb.c
@@ -13,6 +13,7 @@
 #include <linux/notifier.h>
 #include <linux/kdebug.h>
 #include <linux/uaccess.h>
+#include <linux/serial_core.h>
 #include <asm/ptrace.h>
 #include <asm/traps.h>
 #include <asm/processor.h>
@@ -211,14 +212,22 @@ int kgdb_arch_handle_exception(int trap, int signo,

 /* KGDB console driver which uses PDC to read chars from keyboard */

+static int kgdb_pdc_read_char(void)
+{
+        int c = pdc_iodc_getc();
+
+        return (c <= 0) ? NO_POLL_CHAR : c;
+}
+
 static void kgdb_pdc_write_char(u8 chr)
 {
-	/* no need to print char. kgdb will do it. */
+	if (PAGE0->mem_cons.cl_class != CL_DUPLEX)
+		pdc_iodc_print(&chr, 1);
 }

 static struct kgdb_io kgdb_pdc_io_ops = {
 	.name		= "kgdb_pdc",
-	.read_char	= pdc_iodc_getc,
+	.read_char	= kgdb_pdc_read_char,
 	.write_char	= kgdb_pdc_write_char,
 };

--
2.38.1


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

end of thread, other threads:[~2022-11-26 21:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-26 21:36 [PATCH 1/4] parisc: Fix locking in pdc_iodc_print() firmware call Helge Deller
2022-11-26 21:36 ` [PATCH 2/4] parisc: Merge hpmc_iodc_buf and iodc_dbuf buffers Helge Deller
2022-11-26 21:36 ` [PATCH 3/4] parisc: Drop duplicate kgdb_pdc console in pdc_cons.c Helge Deller
2022-11-26 21:36 ` [PATCH 4/4] parisc: Fix kgdb_pdc console read/write funtions Helge Deller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.