public inbox for linux-s390@vger.kernel.org
 help / color / mirror / Atom feed
From: Claudio Imbrenda <imbrenda@linux.ibm.com>
To: kvm@vger.kernel.org
Cc: linux-s390@vger.kernel.org, frankja@linux.ibm.com,
	scgl@linux.ibm.com, pmorel@linux.ibm.com, nrb@linux.ibm.com,
	thuth@redhat.com
Subject: [kvm-unit-tests PATCH v1 2/2] lib: s390x: better smp interrupt checks
Date: Fri,  3 Jun 2022 17:40:37 +0200	[thread overview]
Message-ID: <20220603154037.103733-3-imbrenda@linux.ibm.com> (raw)
In-Reply-To: <20220603154037.103733-1-imbrenda@linux.ibm.com>

Use per-CPU flags and callbacks for Program, Extern, and I/O interrupts
instead of global variables.

This allows for more accurate error handling; a CPU waiting for an
interrupt will not have it "stolen" by a different CPU that was not
supposed to wait for one, and now two CPUs can wait for interrupts at
the same time.

Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
 lib/s390x/asm/arch_def.h |  7 ++++++-
 lib/s390x/interrupt.c    | 38 ++++++++++++++++----------------------
 2 files changed, 22 insertions(+), 23 deletions(-)

diff --git a/lib/s390x/asm/arch_def.h b/lib/s390x/asm/arch_def.h
index 72553819..3a0d9c43 100644
--- a/lib/s390x/asm/arch_def.h
+++ b/lib/s390x/asm/arch_def.h
@@ -124,7 +124,12 @@ struct lowcore {
 	uint8_t		pad_0x0280[0x0308 - 0x0280];	/* 0x0280 */
 	uint64_t	sw_int_crs[16];			/* 0x0308 */
 	struct psw	sw_int_psw;			/* 0x0388 */
-	uint8_t		pad_0x0310[0x11b0 - 0x0398];	/* 0x0398 */
+	uint32_t	pgm_int_expected;		/* 0x0398 */
+	uint32_t	ext_int_expected;		/* 0x039c */
+	void		(*pgm_cleanup_func)(void);	/* 0x03a0 */
+	void		(*ext_cleanup_func)(void);	/* 0x03a8 */
+	void		(*io_int_func)(void);		/* 0x03b0 */
+	uint8_t		pad_0x03b8[0x11b0 - 0x03b8];	/* 0x03b8 */
 	uint64_t	mcck_ext_sa_addr;		/* 0x11b0 */
 	uint8_t		pad_0x11b8[0x1200 - 0x11b8];	/* 0x11b8 */
 	uint64_t	fprs_sa[16];			/* 0x1200 */
diff --git a/lib/s390x/interrupt.c b/lib/s390x/interrupt.c
index 27d3b767..e57946f0 100644
--- a/lib/s390x/interrupt.c
+++ b/lib/s390x/interrupt.c
@@ -15,14 +15,11 @@
 #include <fault.h>
 #include <asm/page.h>
 
-static bool pgm_int_expected;
-static bool ext_int_expected;
-static void (*pgm_cleanup_func)(void);
 static struct lowcore *lc;
 
 void expect_pgm_int(void)
 {
-	pgm_int_expected = true;
+	lc->pgm_int_expected = 1;
 	lc->pgm_int_code = 0;
 	lc->trans_exc_id = 0;
 	mb();
@@ -30,7 +27,7 @@ void expect_pgm_int(void)
 
 void expect_ext_int(void)
 {
-	ext_int_expected = true;
+	lc->ext_int_expected = 1;
 	lc->ext_int_code = 0;
 	mb();
 }
@@ -43,7 +40,7 @@ uint16_t clear_pgm_int(void)
 	code = lc->pgm_int_code;
 	lc->pgm_int_code = 0;
 	lc->trans_exc_id = 0;
-	pgm_int_expected = false;
+	lc->pgm_int_expected = 0;
 	return code;
 }
 
@@ -57,7 +54,7 @@ void check_pgm_int_code(uint16_t code)
 
 void register_pgm_cleanup_func(void (*f)(void))
 {
-	pgm_cleanup_func = f;
+	lc->pgm_cleanup_func = f;
 }
 
 static void fixup_pgm_int(struct stack_frame_int *stack)
@@ -184,24 +181,23 @@ static void print_pgm_info(struct stack_frame_int *stack)
 
 void handle_pgm_int(struct stack_frame_int *stack)
 {
-	if (!pgm_int_expected) {
+	if (!lc->pgm_int_expected) {
 		/* Force sclp_busy to false, otherwise we will loop forever */
 		sclp_handle_ext();
 		print_pgm_info(stack);
 	}
 
-	pgm_int_expected = false;
+	lc->pgm_int_expected = 0;
 
-	if (pgm_cleanup_func)
-		(*pgm_cleanup_func)();
+	if (lc->pgm_cleanup_func)
+		(*lc->pgm_cleanup_func)();
 	else
 		fixup_pgm_int(stack);
 }
 
 void handle_ext_int(struct stack_frame_int *stack)
 {
-	if (!ext_int_expected &&
-	    lc->ext_int_code != EXT_IRQ_SERVICE_SIG) {
+	if (!lc->ext_int_expected && lc->ext_int_code != EXT_IRQ_SERVICE_SIG) {
 		report_abort("Unexpected external call interrupt (code %#x): on cpu %d at %#lx",
 			     lc->ext_int_code, stap(), lc->ext_old_psw.addr);
 		return;
@@ -211,7 +207,7 @@ void handle_ext_int(struct stack_frame_int *stack)
 		stack->crs[0] &= ~(1UL << 9);
 		sclp_handle_ext();
 	} else {
-		ext_int_expected = false;
+		lc->ext_int_expected = 0;
 	}
 
 	if (!(stack->crs[0] & CR0_EXTM_MASK))
@@ -224,12 +220,10 @@ void handle_mcck_int(void)
 		     stap(), lc->mcck_old_psw.addr);
 }
 
-static void (*io_int_func)(void);
-
 void handle_io_int(void)
 {
-	if (io_int_func)
-		return io_int_func();
+	if (lc->io_int_func)
+		return lc->io_int_func();
 
 	report_abort("Unexpected io interrupt: on cpu %d at %#lx",
 		     stap(), lc->io_old_psw.addr);
@@ -237,17 +231,17 @@ void handle_io_int(void)
 
 int register_io_int_func(void (*f)(void))
 {
-	if (io_int_func)
+	if (lc->io_int_func)
 		return -1;
-	io_int_func = f;
+	lc->io_int_func = f;
 	return 0;
 }
 
 int unregister_io_int_func(void (*f)(void))
 {
-	if (io_int_func != f)
+	if (lc->io_int_func != f)
 		return -1;
-	io_int_func = NULL;
+	lc->io_int_func = NULL;
 	return 0;
 }
 
-- 
2.36.1


  parent reply	other threads:[~2022-06-03 15:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-03 15:40 [kvm-unit-tests PATCH v1 0/2] better smp interrupt checks Claudio Imbrenda
2022-06-03 15:40 ` [kvm-unit-tests PATCH v1 1/2] s390x: skey.c: rework the interrupt handler Claudio Imbrenda
2022-06-07 13:29   ` Nico Boehr
2022-06-03 15:40 ` Claudio Imbrenda [this message]
2022-06-07 10:01   ` [kvm-unit-tests PATCH v1 2/2] lib: s390x: better smp interrupt checks Janis Schoetterl-Glausch
2022-06-07 11:08     ` Claudio Imbrenda
2022-06-07 14:23   ` Nico Boehr
2022-06-07 14:41     ` Claudio Imbrenda
2022-06-07 14:48       ` Nico Boehr
2022-06-07 16:43         ` Claudio Imbrenda
2022-06-10  9:43   ` Janosch Frank

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220603154037.103733-3-imbrenda@linux.ibm.com \
    --to=imbrenda@linux.ibm.com \
    --cc=frankja@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=nrb@linux.ibm.com \
    --cc=pmorel@linux.ibm.com \
    --cc=scgl@linux.ibm.com \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox