From: Janosch Frank <frankja@linux.ibm.com>
To: kvm@vger.kernel.org
Cc: thuth@redhat.com, imbrenda@linux.ibm.com, nrb@linux.ibm.com
Subject: [kvm-unit-tests PATCH v2 8/9] s390x: uv-host: Properly handle config creation errors
Date: Fri, 24 Mar 2023 12:17:23 +0000 [thread overview]
Message-ID: <20230324121724.1627-9-frankja@linux.ibm.com> (raw)
In-Reply-To: <20230324121724.1627-1-frankja@linux.ibm.com>
If the first bit is set on a error rc, the hypervisor will need to
destroy the config before trying again. Let's properly handle those
cases so we're not usign stale data.
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
lib/s390x/asm/uv.h | 1 +
s390x/uv-host.c | 66 +++++++++++++++++++++++++++++++++++++++-------
2 files changed, 58 insertions(+), 9 deletions(-)
diff --git a/lib/s390x/asm/uv.h b/lib/s390x/asm/uv.h
index 38920461..e9fb19af 100644
--- a/lib/s390x/asm/uv.h
+++ b/lib/s390x/asm/uv.h
@@ -24,6 +24,7 @@
#define UVC_RC_NO_RESUME 0x0007
#define UVC_RC_INV_GHANDLE 0x0020
#define UVC_RC_INV_CHANDLE 0x0021
+#define UVC_RC_DSTR_NEEDED_FLG 0x8000
#define UVC_CMD_QUI 0x0001
#define UVC_CMD_INIT_UV 0x000f
diff --git a/s390x/uv-host.c b/s390x/uv-host.c
index 8d1d441f..5ad1a116 100644
--- a/s390x/uv-host.c
+++ b/s390x/uv-host.c
@@ -370,6 +370,42 @@ static void test_cpu_create(void)
report_prefix_pop();
}
+/*
+ * If the first bit of the rc is set we need to destroy the
+ * configuration before testing other create config errors.
+ */
+static void cgc_destroy_if_needed(struct uv_cb_cgc *uvcb)
+{
+ uint16_t rc, rrc;
+
+ if (uvcb->header.rc != UVC_RC_EXECUTED &&
+ !(uvcb->header.rc & UVC_RC_DSTR_NEEDED_FLG))
+ return;
+
+ assert(uvcb->guest_handle);
+ assert(!uv_cmd_nodata(uvcb->guest_handle, UVC_CMD_DESTROY_SEC_CONF,
+ &rc, &rrc));
+
+ /* We need to zero it for the next test */
+ uvcb->guest_handle = 0;
+}
+
+static bool cgc_check_data(struct uv_cb_cgc *uvcb, uint16_t rc_expected)
+{
+ /* This function purely checks for error rcs */
+ if (uvcb->header.rc == UVC_RC_EXECUTED)
+ return false;
+
+ /*
+ * We should only receive a handle when the rc is 1 or the
+ * first bit is set.
+ */
+ if (!(uvcb->header.rc & UVC_RC_DSTR_NEEDED_FLG) && uvcb->guest_handle)
+ report_abort("Received a handle when we didn't expect one");
+
+ return (uvcb->header.rc & ~UVC_RC_DSTR_NEEDED_FLG) == rc_expected;
+}
+
static void test_config_create(void)
{
int rc;
@@ -394,44 +430,51 @@ static void test_config_create(void)
rc = uv_call(0, (uint64_t)&uvcb_cgc);
report(uvcb_cgc.header.rc == UVC_RC_INV_LEN && rc == 1 &&
!uvcb_cgc.guest_handle, "hdr invalid length");
+ cgc_destroy_if_needed(&uvcb_cgc);
uvcb_cgc.header.len += 8;
uvcb_cgc.guest_stor_origin = uvcb_qui.max_guest_stor_addr + (1UL << 20) * 2 + 1;
rc = uv_call(0, (uint64_t)&uvcb_cgc);
- report(uvcb_cgc.header.rc == 0x101 && rc == 1,
+ report(cgc_check_data(&uvcb_cgc, 0x101) && rc == 1,
"MSO > max guest addr");
+ cgc_destroy_if_needed(&uvcb_cgc);
uvcb_cgc.guest_stor_origin = 0;
uvcb_cgc.guest_stor_origin = uvcb_qui.max_guest_stor_addr - (1UL << 20);
rc = uv_call(0, (uint64_t)&uvcb_cgc);
- report(uvcb_cgc.header.rc == 0x102 && rc == 1,
+ report(cgc_check_data(&uvcb_cgc, 0x102) && rc == 1,
"MSO + MSL > max guest addr");
+ cgc_destroy_if_needed(&uvcb_cgc);
uvcb_cgc.guest_stor_origin = 0;
uvcb_cgc.guest_asce &= ~ASCE_P;
rc = uv_call(0, (uint64_t)&uvcb_cgc);
- report(uvcb_cgc.header.rc == 0x105 && rc == 1,
+ report(cgc_check_data(&uvcb_cgc, 0x105) && rc == 1,
"ASCE private bit missing");
+ cgc_destroy_if_needed(&uvcb_cgc);
uvcb_cgc.guest_asce |= ASCE_P;
uvcb_cgc.guest_asce |= 0x20;
rc = uv_call(0, (uint64_t)&uvcb_cgc);
- report(uvcb_cgc.header.rc == 0x105 && rc == 1,
+ report(cgc_check_data(&uvcb_cgc, 0x105) && rc == 1,
"ASCE bit 58 set");
+ cgc_destroy_if_needed(&uvcb_cgc);
uvcb_cgc.guest_asce &= ~0x20;
tmp = uvcb_cgc.conf_base_stor_origin;
uvcb_cgc.conf_base_stor_origin = get_max_ram_size() + 8;
rc = uv_call(0, (uint64_t)&uvcb_cgc);
- report(uvcb_cgc.header.rc == 0x108 && rc == 1,
+ report(cgc_check_data(&uvcb_cgc, 0x108) && rc == 1,
"base storage origin > available memory");
+ cgc_destroy_if_needed(&uvcb_cgc);
uvcb_cgc.conf_base_stor_origin = tmp;
tmp = uvcb_cgc.conf_base_stor_origin;
uvcb_cgc.conf_base_stor_origin = 0x1000;
rc = uv_call(0, (uint64_t)&uvcb_cgc);
- report(uvcb_cgc.header.rc == 0x109 && rc == 1,
- "base storage origin contains lowcore");
+ report(cgc_check_data(&uvcb_cgc, 0x109) && rc == 1,
+ "base storage origin contains lowcore %x", uvcb_cgc.header.rc);
+ cgc_destroy_if_needed(&uvcb_cgc);
uvcb_cgc.conf_base_stor_origin = tmp;
/*
@@ -444,21 +487,24 @@ static void test_config_create(void)
rc = uv_call(0, (uint64_t)&uvcb_cgc);
report(uvcb_cgc.header.rc == 0x10b && rc == 1 &&
!uvcb_cgc.guest_handle, "variable storage area contains lowcore");
+ cgc_destroy_if_needed(&uvcb_cgc);
smp_sigp(1, SIGP_SET_PREFIX, 0x0, NULL);
}
tmp = uvcb_cgc.guest_sca;
uvcb_cgc.guest_sca = 0;
rc = uv_call(0, (uint64_t)&uvcb_cgc);
- report(uvcb_cgc.header.rc == 0x10c && rc == 1,
+ report(cgc_check_data(&uvcb_cgc, 0x10c) && rc == 1,
"sca == 0");
+ cgc_destroy_if_needed(&uvcb_cgc);
uvcb_cgc.guest_sca = tmp;
tmp = uvcb_cgc.guest_sca;
uvcb_cgc.guest_sca = get_max_ram_size() + PAGE_SIZE * 4;
rc = uv_call(0, (uint64_t)&uvcb_cgc);
- report(uvcb_cgc.header.rc == 0x10d && rc == 1,
+ report(cgc_check_data(&uvcb_cgc, 0x10d) && rc == 1,
"sca inaccessible");
+ cgc_destroy_if_needed(&uvcb_cgc);
uvcb_cgc.guest_sca = tmp;
rc = uv_call(0, (uint64_t)&uvcb_cgc);
@@ -477,6 +523,7 @@ static void test_config_create(void)
uvcb_cgc.guest_handle = 0;
rc = uv_call(0, (uint64_t)&uvcb_cgc);
report(uvcb_cgc.header.rc >= 0x100 && rc == 1, "reuse uvcb");
+ cgc_destroy_if_needed(&uvcb_cgc);
uvcb_cgc.guest_handle = tmp;
/* Copy over most data from uvcb_cgc, so we have the ASCE that was used. */
@@ -494,6 +541,7 @@ static void test_config_create(void)
rc = uv_call(0, (uint64_t)&uvcb);
report(uvcb.header.rc >= 0x104 && rc == 1 && !uvcb.guest_handle,
"reuse ASCE");
+ cgc_destroy_if_needed(&uvcb);
free((void *)uvcb.conf_base_stor_origin);
free((void *)uvcb.conf_var_stor_origin);
--
2.34.1
next prev parent reply other threads:[~2023-03-24 12:18 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-24 12:17 [kvm-unit-tests PATCH v2 0/9] s390x: uv-host: Fixups and extensions part 1 Janosch Frank
2023-03-24 12:17 ` [kvm-unit-tests PATCH v2 1/9] s390x: uv-host: Fix UV init test memory allocation Janosch Frank
2023-03-24 12:39 ` Nico Boehr
2023-03-24 12:17 ` [kvm-unit-tests PATCH v2 2/9] s390x: uv-host: Check for sufficient amount of memory Janosch Frank
2023-03-24 12:17 ` [kvm-unit-tests PATCH v2 3/9] s390x: Add PV tests to unittests.cfg Janosch Frank
2023-03-24 12:40 ` Nico Boehr
2023-03-24 12:17 ` [kvm-unit-tests PATCH v2 4/9] s390x: uv-host: Beautify code Janosch Frank
2023-03-24 12:17 ` [kvm-unit-tests PATCH v2 5/9] s390x: uv-host: Add cpu number check Janosch Frank
2023-03-24 12:17 ` [kvm-unit-tests PATCH v2 6/9] s390x: uv-host: Fix create guest variable storage prefix check Janosch Frank
2023-03-24 12:17 ` [kvm-unit-tests PATCH v2 7/9] s390x: uv-host: Switch to smp_sigp Janosch Frank
2023-03-24 12:40 ` Nico Boehr
2023-03-24 12:17 ` Janosch Frank [this message]
2023-03-24 12:42 ` [kvm-unit-tests PATCH v2 8/9] s390x: uv-host: Properly handle config creation errors Nico Boehr
2023-03-24 12:17 ` [kvm-unit-tests PATCH v2 9/9] s390x: uv-host: Fence access checks when UV debug is enabled 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=20230324121724.1627-9-frankja@linux.ibm.com \
--to=frankja@linux.ibm.com \
--cc=imbrenda@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=nrb@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