Blame SOURCES/0004-ppc64-dynamically-allocate-h-w-interrupt-stack.patch

56ae9b
From 6a89173a25450b679e4a713793b2ed36b077fe56 Mon Sep 17 00:00:00 2001
56ae9b
From: Hari Bathini <hbathini@linux.ibm.com>
56ae9b
Date: Mon, 4 Jul 2022 10:55:42 +0530
56ae9b
Subject: [PATCH 04/28] ppc64: dynamically allocate h/w interrupt stack
56ae9b
56ae9b
Only older kernel (v2.4) used h/w interrupt stack to store frames when
56ae9b
CPU received IPI. Memory used for this in 'struct machine_specific' is
56ae9b
useless for later kernels. For the sake of backward compatibility keep
56ae9b
h/w interrupt stack but dynamically allocate memory for it and save
56ae9b
some bytes from being wasted.
56ae9b
56ae9b
Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
56ae9b
Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
56ae9b
---
56ae9b
 defs.h  |  2 +-
56ae9b
 ppc64.c | 51 +++++++++++++++++++++------------------------------
56ae9b
 2 files changed, 22 insertions(+), 31 deletions(-)
56ae9b
56ae9b
diff --git a/defs.h b/defs.h
56ae9b
index c524a05d8105..d8fbeb89e335 100644
56ae9b
--- a/defs.h
56ae9b
+++ b/defs.h
56ae9b
@@ -6311,7 +6311,7 @@ struct ppc64_vmemmap {
56ae9b
  * Used to store the HW interrupt stack. It is only for 2.4.
56ae9b
  */
56ae9b
 struct machine_specific {
56ae9b
-        ulong hwintrstack[NR_CPUS];
56ae9b
+	ulong *hwintrstack;
56ae9b
         char *hwstackbuf;
56ae9b
         uint hwstacksize;
56ae9b
 
56ae9b
diff --git a/ppc64.c b/ppc64.c
56ae9b
index 0e1d8678eef5..272eb207074a 100644
56ae9b
--- a/ppc64.c
56ae9b
+++ b/ppc64.c
56ae9b
@@ -256,7 +256,7 @@ static int set_ppc64_max_physmem_bits(void)
56ae9b
 }
56ae9b
 
56ae9b
 struct machine_specific ppc64_machine_specific = { 
56ae9b
-	.hwintrstack = { 0 }, 
56ae9b
+	.hwintrstack = NULL,
56ae9b
 	.hwstackbuf = 0,
56ae9b
 	.hwstacksize = 0,
56ae9b
 	.pte_rpn_shift = PTE_RPN_SHIFT_DEFAULT,
56ae9b
@@ -275,7 +275,7 @@ struct machine_specific ppc64_machine_specific = {
56ae9b
 };
56ae9b
 
56ae9b
 struct machine_specific book3e_machine_specific = {
56ae9b
-	.hwintrstack = { 0 },
56ae9b
+	.hwintrstack = NULL,
56ae9b
 	.hwstackbuf = 0,
56ae9b
 	.hwstacksize = 0,
56ae9b
 	.pte_rpn_shift = PTE_RPN_SHIFT_L4_BOOK3E_64K,
56ae9b
@@ -676,6 +676,9 @@ ppc64_init(int when)
56ae9b
 			 */
56ae9b
 			offset = MEMBER_OFFSET("paca_struct", "xHrdIntStack");
56ae9b
 			paca_sym  = symbol_value("paca");
56ae9b
+			if (!(machdep->machspec->hwintrstack =
56ae9b
+			      (ulong *)calloc(NR_CPUS, sizeof(ulong))))
56ae9b
+				error(FATAL, "cannot malloc hwintrstack space.");
56ae9b
 			for (cpu = 0; cpu < kt->cpus; cpu++)  {
56ae9b
 				readmem(paca_sym + (paca_size * cpu) + offset,
56ae9b
 					KVADDR, 
56ae9b
@@ -686,14 +689,9 @@ ppc64_init(int when)
56ae9b
 			machdep->machspec->hwstacksize = 8 * machdep->pagesize;
56ae9b
 			if ((machdep->machspec->hwstackbuf = (char *)
56ae9b
 				malloc(machdep->machspec->hwstacksize)) == NULL)
56ae9b
-				error(FATAL, "cannot malloc hwirqstack space.");
56ae9b
-		} else
56ae9b
-			/*
56ae9b
-			 * 'xHrdIntStack' member in "paca_struct" is not 
56ae9b
-			 * available for 2.6 kernel. 
56ae9b
-			 */
56ae9b
-			BZERO(&machdep->machspec->hwintrstack,
56ae9b
-				NR_CPUS*sizeof(ulong));
56ae9b
+				error(FATAL, "cannot malloc hwirqstack buffer space.");
56ae9b
+		}
56ae9b
+
56ae9b
 		if (!machdep->hz) {
56ae9b
 			machdep->hz = HZ;
56ae9b
 			if (THIS_KERNEL_VERSION >= LINUX(2,6,0))
56ae9b
@@ -846,23 +844,15 @@ ppc64_dump_machdep_table(ulong arg)
56ae9b
 	fprintf(fp, "            is_vmaddr: %s\n", 
56ae9b
 		machdep->machspec->is_vmaddr == book3e_is_vmaddr ? 
56ae9b
 		"book3e_is_vmaddr()" : "ppc64_is_vmaddr()");
56ae9b
-	fprintf(fp, "    hwintrstack[%d]: ", NR_CPUS);
56ae9b
-       	for (c = 0; c < NR_CPUS; c++) {
56ae9b
-		for (others = 0, i = c; i < NR_CPUS; i++) {
56ae9b
-			if (machdep->machspec->hwintrstack[i])
56ae9b
-				others++;
56ae9b
+	if (machdep->machspec->hwintrstack) {
56ae9b
+		fprintf(fp, "    hwintrstack[%d]: ", NR_CPUS);
56ae9b
+		for (c = 0; c < NR_CPUS; c++) {
56ae9b
+			fprintf(fp, "%s%016lx ",
56ae9b
+				((c % 4) == 0) ? "\n  " : "",
56ae9b
+				machdep->machspec->hwintrstack[c]);
56ae9b
 		}
56ae9b
-		if (!others) {
56ae9b
-			fprintf(fp, "%s%s", 
56ae9b
-			        c && ((c % 4) == 0) ? "\n  " : "",
56ae9b
-				c ? "(remainder unused)" : "(unused)");
56ae9b
-			break;
56ae9b
-		}
56ae9b
-
56ae9b
-		fprintf(fp, "%s%016lx ", 
56ae9b
-			((c % 4) == 0) ? "\n  " : "",
56ae9b
-			machdep->machspec->hwintrstack[c]);
56ae9b
-	}
56ae9b
+	} else
56ae9b
+		fprintf(fp, "          hwintrstack: (unused)");
56ae9b
 	fprintf(fp, "\n");
56ae9b
 	fprintf(fp, "           hwstackbuf: %lx\n", (ulong)machdep->machspec->hwstackbuf);
56ae9b
 	fprintf(fp, "          hwstacksize: %d\n", machdep->machspec->hwstacksize);
56ae9b
@@ -1683,9 +1673,10 @@ ppc64_check_sp_in_HWintrstack(ulong sp, struct bt_info *bt)
56ae9b
 	 * 
56ae9b
 	 * Note: HW Interrupt stack is used only in 2.4 kernel.
56ae9b
 	 */
56ae9b
-	if (is_task_active(bt->task) && (tt->panic_task != bt->task) &&
56ae9b
-		machdep->machspec->hwintrstack[bt->tc->processor]) {
56ae9b
+	if (machdep->machspec->hwintrstack && is_task_active(bt->task) &&
56ae9b
+	    (bt->task != tt->panic_task)) {
56ae9b
 		ulong newsp;
56ae9b
+
56ae9b
 		readmem(machdep->machspec->hwintrstack[bt->tc->processor],
56ae9b
 			KVADDR, &newsp, sizeof(ulong),
56ae9b
 			"stack pointer", FAULT_ON_ERROR);
56ae9b
@@ -1958,7 +1949,7 @@ ppc64_back_trace(struct gnu_request *req, struct bt_info *bt)
56ae9b
 			bt->stackbase = irqstack;
56ae9b
 			bt->stacktop = bt->stackbase + STACKSIZE();
56ae9b
 			alter_stackbuf(bt);
56ae9b
-		} else if (ms->hwintrstack[bt->tc->processor]) {
56ae9b
+		} else if (ms->hwintrstack) {
56ae9b
 			bt->stacktop = ms->hwintrstack[bt->tc->processor] +
56ae9b
 				sizeof(ulong);
56ae9b
 			bt->stackbase = ms->hwintrstack[bt->tc->processor] - 
56ae9b
@@ -2555,7 +2546,7 @@ retry:
56ae9b
 		goto retry;
56ae9b
 	} 
56ae9b
 
56ae9b
-	if (check_intrstack && ms->hwintrstack[bt->tc->processor]) {
56ae9b
+	if (check_intrstack && ms->hwintrstack) {
56ae9b
 		bt->stacktop = ms->hwintrstack[bt->tc->processor] +
56ae9b
 			sizeof(ulong);
56ae9b
 		bt->stackbase = ms->hwintrstack[bt->tc->processor] -
56ae9b
-- 
56ae9b
2.37.1
56ae9b