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

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