diff mbox series

[kvm-unit-tests,v2,3/5] s390x: css: implementing Set CHannel Monitor

Message ID 1612963214-30397-4-git-send-email-pmorel@linux.ibm.com (mailing list archive)
State New, archived
Headers show
Series CSS Mesurement Block | expand

Commit Message

Pierre Morel Feb. 10, 2021, 1:20 p.m. UTC
We implement the call of the Set CHannel Monitor instruction,
starting the monitoring of the all Channel Sub System, and
initializing channel subsystem monitoring.

An initial test reports the presence of the extended measurement
block feature.

Several tests on SCHM verify the error reporting of the hypervisor.

Signed-off-by: Pierre Morel <pmorel@linux.ibm.com>
---
 lib/s390x/css.h     | 19 +++++++++++-
 lib/s390x/css_lib.c | 74 +++++++++++++++++++++++++++++++++++++++++++++
 s390x/css.c         | 36 ++++++++++++++++++++++
 3 files changed, 128 insertions(+), 1 deletion(-)

Comments

Cornelia Huck Feb. 12, 2021, 10:53 a.m. UTC | #1
On Wed, 10 Feb 2021 14:20:12 +0100
Pierre Morel <pmorel@linux.ibm.com> wrote:

> We implement the call of the Set CHannel Monitor instruction,
> starting the monitoring of the all Channel Sub System, and
> initializing channel subsystem monitoring.
> 
> An initial test reports the presence of the extended measurement
> block feature.
> 
> Several tests on SCHM verify the error reporting of the hypervisor.

Combine these two into one sentence?

"Initial tests report the presence of the extended measurement block
feature, and verify the error reporting of the hypervisor for SCHM."

Also, you add the infrastructure for enabling measurements at the
subchannel -- either mention this in the patch description or move it
to a separate patch or the first user?

> 
> Signed-off-by: Pierre Morel <pmorel@linux.ibm.com>
> ---
>  lib/s390x/css.h     | 19 +++++++++++-
>  lib/s390x/css_lib.c | 74 +++++++++++++++++++++++++++++++++++++++++++++
>  s390x/css.c         | 36 ++++++++++++++++++++++
>  3 files changed, 128 insertions(+), 1 deletion(-)
> 

(...)

> diff --git a/lib/s390x/css_lib.c b/lib/s390x/css_lib.c
> index 5426a6b..355881d 100644
> --- a/lib/s390x/css_lib.c
> +++ b/lib/s390x/css_lib.c
> @@ -267,6 +267,80 @@ retry:
>  	return -1;
>  }
>  
> +static bool schib_update(int schid, uint64_t mb, uint16_t mbi, uint16_t flags,
> +		  bool format1)

Maybe schib_update_mb()?

> +{
> +	struct pmcw *pmcw = &schib.pmcw;
> +	int cc;
> +
> +	/* Read the SCHIB for this subchannel */
> +	cc = stsch(schid, &schib);
> +	if (cc) {
> +		report_info("stsch: sch %08x failed with cc=%d", schid, cc);
> +		return false;
> +	}
> +
> +	/* Update the SCHIB to enable the measurement block */
> +	pmcw->flags |= flags;

Do we also want to be able to disable it again?

> +
> +	if (format1)
> +		pmcw->flags2 |= PMCW_MBF1;
> +	else
> +		pmcw->flags2 &= ~PMCW_MBF1;
> +
> +	pmcw->mbi = mbi;
> +	schib.mbo = mb;
> +
> +	/* Tell the CSS we want to modify the subchannel */
> +	cc = msch(schid, &schib);
> +	if (cc) {
> +		/*
> +		 * If the subchannel is status pending or
> +		 * if a function is in progress,
> +		 * we consider both cases as errors.
> +		 */
> +		report_info("msch: sch %08x failed with cc=%d", schid, cc);
> +		return false;
> +	}
> +
> +	/*
> +	 * Read the SCHIB again to verify the measurement block origin
> +	 */
> +	cc = stsch(schid, &schib);
> +	if (cc) {
> +		report_info("stsch: updating sch %08x failed with cc=%d",
> +			    schid, cc);
> +		return false;
> +	}

Hm, you only do the stsch, but do not check the result (that is done by
the caller) -- remove the misleading comment or replace it with "Read
the SCHIB again"?

> +
> +	return true;
> +}
> +

(...)

Otherwise, LGTM.
Pierre Morel Feb. 12, 2021, 3:51 p.m. UTC | #2
On 2/12/21 11:53 AM, Cornelia Huck wrote:
> On Wed, 10 Feb 2021 14:20:12 +0100
> Pierre Morel <pmorel@linux.ibm.com> wrote:
> 
>> We implement the call of the Set CHannel Monitor instruction,
>> starting the monitoring of the all Channel Sub System, and
>> initializing channel subsystem monitoring.
>>
>> An initial test reports the presence of the extended measurement
>> block feature.
>>
>> Several tests on SCHM verify the error reporting of the hypervisor.
> 
> Combine these two into one sentence?
> 
> "Initial tests report the presence of the extended measurement block
> feature, and verify the error reporting of the hypervisor for SCHM."
> 
> Also, you add the infrastructure for enabling measurements at the
> subchannel -- either mention this in the patch description or move it
> to a separate patch or the first user?

yes, I change for one of these solutions, thanks.

> 
>>
>> Signed-off-by: Pierre Morel <pmorel@linux.ibm.com>
>> ---
>>   lib/s390x/css.h     | 19 +++++++++++-
>>   lib/s390x/css_lib.c | 74 +++++++++++++++++++++++++++++++++++++++++++++
>>   s390x/css.c         | 36 ++++++++++++++++++++++
>>   3 files changed, 128 insertions(+), 1 deletion(-)
>>
> 
> (...)
> 
>> diff --git a/lib/s390x/css_lib.c b/lib/s390x/css_lib.c
>> index 5426a6b..355881d 100644
>> --- a/lib/s390x/css_lib.c
>> +++ b/lib/s390x/css_lib.c
>> @@ -267,6 +267,80 @@ retry:
>>   	return -1;
>>   }
>>   
>> +static bool schib_update(int schid, uint64_t mb, uint16_t mbi, uint16_t flags,
>> +		  bool format1)
> 
> Maybe schib_update_mb()?

yes, it is dedicated.

> 
>> +{
>> +	struct pmcw *pmcw = &schib.pmcw;
>> +	int cc;
>> +
>> +	/* Read the SCHIB for this subchannel */
>> +	cc = stsch(schid, &schib);
>> +	if (cc) {
>> +		report_info("stsch: sch %08x failed with cc=%d", schid, cc);
>> +		return false;
>> +	}
>> +
>> +	/* Update the SCHIB to enable the measurement block */
>> +	pmcw->flags |= flags;
> 
> Do we also want to be able to disable it again?

Yes, I can add the disabling of the measurement on a channel.
In the test I disable it for the system but we may need this later.


> 
>> +
>> +	if (format1)
>> +		pmcw->flags2 |= PMCW_MBF1;
>> +	else
>> +		pmcw->flags2 &= ~PMCW_MBF1;
>> +
>> +	pmcw->mbi = mbi;
>> +	schib.mbo = mb;
>> +
>> +	/* Tell the CSS we want to modify the subchannel */
>> +	cc = msch(schid, &schib);
>> +	if (cc) {
>> +		/*
>> +		 * If the subchannel is status pending or
>> +		 * if a function is in progress,
>> +		 * we consider both cases as errors.
>> +		 */
>> +		report_info("msch: sch %08x failed with cc=%d", schid, cc);
>> +		return false;
>> +	}
>> +
>> +	/*
>> +	 * Read the SCHIB again to verify the measurement block origin
>> +	 */
>> +	cc = stsch(schid, &schib);
>> +	if (cc) {
>> +		report_info("stsch: updating sch %08x failed with cc=%d",
>> +			    schid, cc);
>> +		return false;
>> +	}
> 
> Hm, you only do the stsch, but do not check the result (that is done by
> the caller) -- remove the misleading comment or replace it with "Read
> the SCHIB again"?

right, "Read the SCHIB again"

> 
>> +
>> +	return true;
>> +}
>> +
> 
> (...)
> 
> Otherwise, LGTM.
> 

Thanks,
Pierre
diff mbox series

Patch

diff --git a/lib/s390x/css.h b/lib/s390x/css.h
index fa8775f..0e3254a 100644
--- a/lib/s390x/css.h
+++ b/lib/s390x/css.h
@@ -82,6 +82,7 @@  struct pmcw {
 	uint32_t intparm;
 #define PMCW_DNV	0x0001
 #define PMCW_ENABLE	0x0080
+#define PMCW_MBUE	0x0010
 #define PMCW_ISC_MASK	0x3800
 #define PMCW_ISC_SHIFT	11
 	uint16_t flags;
@@ -94,6 +95,7 @@  struct pmcw {
 	uint8_t  pom;
 	uint8_t  pam;
 	uint8_t  chpid[8];
+#define PMCW_MBF1	0x0004
 	uint32_t flags2;
 };
 #define PMCW_CHANNEL_TYPE(pmcw) (pmcw->flags2 >> 21)
@@ -101,7 +103,8 @@  struct pmcw {
 struct schib {
 	struct pmcw pmcw;
 	struct scsw scsw;
-	uint8_t  md[12];
+	uint64_t mbo;
+	uint8_t  md[4];
 } __attribute__ ((aligned(4)));
 
 struct irb {
@@ -306,6 +309,7 @@  struct chsc_scsc {
 	u32 res_04[2];
 	struct chsc_header res;
 	u32 res_fmt;
+#define CSSC_EXTENDED_MEASUREMENT_BLOCK 48
 	u64 general_char[255];
 	u64 chsc_char[254];
 };
@@ -358,4 +362,17 @@  int chsc(void *p, uint16_t code, uint16_t len);
 #define css_general_feature(bit) test_bit_inv(bit, chsc_scsc->general_char)
 #define css_chsc_feature(bit) test_bit_inv(bit, chsc_scsc->chsc_char)
 
+#define SCHM_DCTM	1 /* activate Device Connection TiMe */
+#define SCHM_MBU	2 /* activate Measurement Block Update */
+
+static inline void schm(void *mbo, unsigned int flags)
+{
+	register void *__gpr2 asm("2") = mbo;
+	register long __gpr1 asm("1") = flags;
+
+	asm("schm" : : "d" (__gpr2), "d" (__gpr1));
+}
+
+bool css_enable_mb(int sid, uint64_t mb, uint16_t mbi, uint16_t flg, bool fmt1);
+
 #endif
diff --git a/lib/s390x/css_lib.c b/lib/s390x/css_lib.c
index 5426a6b..355881d 100644
--- a/lib/s390x/css_lib.c
+++ b/lib/s390x/css_lib.c
@@ -267,6 +267,80 @@  retry:
 	return -1;
 }
 
+static bool schib_update(int schid, uint64_t mb, uint16_t mbi, uint16_t flags,
+		  bool format1)
+{
+	struct pmcw *pmcw = &schib.pmcw;
+	int cc;
+
+	/* Read the SCHIB for this subchannel */
+	cc = stsch(schid, &schib);
+	if (cc) {
+		report_info("stsch: sch %08x failed with cc=%d", schid, cc);
+		return false;
+	}
+
+	/* Update the SCHIB to enable the measurement block */
+	pmcw->flags |= flags;
+
+	if (format1)
+		pmcw->flags2 |= PMCW_MBF1;
+	else
+		pmcw->flags2 &= ~PMCW_MBF1;
+
+	pmcw->mbi = mbi;
+	schib.mbo = mb;
+
+	/* Tell the CSS we want to modify the subchannel */
+	cc = msch(schid, &schib);
+	if (cc) {
+		/*
+		 * If the subchannel is status pending or
+		 * if a function is in progress,
+		 * we consider both cases as errors.
+		 */
+		report_info("msch: sch %08x failed with cc=%d", schid, cc);
+		return false;
+	}
+
+	/*
+	 * Read the SCHIB again to verify the measurement block origin
+	 */
+	cc = stsch(schid, &schib);
+	if (cc) {
+		report_info("stsch: updating sch %08x failed with cc=%d",
+			    schid, cc);
+		return false;
+	}
+
+	return true;
+}
+
+/*
+ * css_enable_mb: enable the subchannel Mesurement Block
+ * @schid: Subchannel Identifier
+ * @mb   : 64bit address of the measurement block
+ * @format1: set if format 1 is to be used
+ * @mbi : the measurement block offset
+ * @flags : PMCW_MBUE to enable measurement block update
+ *	    PMCW_DCTME to enable device connect time
+ * Return value:
+ *   On success: 0
+ *   On error the CC of the faulty instruction
+ *      or -1 if the retry count is exceeded.
+ */
+bool css_enable_mb(int schid, uint64_t mb, uint16_t mbi, uint16_t flags,
+		   bool format1)
+{
+	int retry_count = MAX_ENABLE_RETRIES;
+	struct pmcw *pmcw = &schib.pmcw;
+
+	while (retry_count-- && !schib_update(schid, mb, mbi, flags, format1))
+		mdelay(10); /* the hardware was not ready, give it some time */
+
+	return schib.mbo == mb && pmcw->mbi == mbi;
+}
+
 static struct irb irb;
 
 void css_irq_io(void)
diff --git a/s390x/css.c b/s390x/css.c
index d4b3cc8..a382235 100644
--- a/s390x/css.c
+++ b/s390x/css.c
@@ -157,6 +157,41 @@  static void css_init(void)
 	report(1, "CSS initialized");
 }
 
+static void test_schm(void)
+{
+	if (css_general_feature(CSSC_EXTENDED_MEASUREMENT_BLOCK))
+		report_info("Extended measurement block available");
+
+	/* bits 59-63 of MB address must be 0  if MBU is defined */
+	report_prefix_push("Unaligned operand");
+	expect_pgm_int();
+	schm((void *)0x01, SCHM_MBU);
+	check_pgm_int_code(PGM_INT_CODE_OPERAND);
+	report_prefix_pop();
+
+	/* bits 36-61 flags must be 0 */
+	report_prefix_push("Bad flags");
+	expect_pgm_int();
+	schm(NULL, 0x04);
+	check_pgm_int_code(PGM_INT_CODE_OPERAND);
+	report_prefix_pop();
+
+	/* bits 36-61 flags must be 0 */
+	report_prefix_push("Privilege");
+	enter_pstate();
+	expect_pgm_int();
+	schm(NULL, SCHM_MBU);
+	check_pgm_int_code(PGM_INT_CODE_PRIVILEGED_OPERATION);
+	report_prefix_pop();
+
+	/* Normal operation */
+	report_prefix_push("Normal operation");
+	schm(NULL, SCHM_MBU);
+	report(1,"SCHM call without address");
+	report_prefix_pop();
+
+}
+
 static struct {
 	const char *name;
 	void (*func)(void);
@@ -166,6 +201,7 @@  static struct {
 	{ "enumerate (stsch)", test_enumerate },
 	{ "enable (msch)", test_enable },
 	{ "sense (ssch/tsch)", test_sense },
+	{ "measurement block (schm)", test_schm },
 	{ NULL, NULL }
 };