kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] KVM: s390: fix LPSWEY handling
@ 2024-06-28 16:35 Christian Borntraeger
  2024-07-01  6:08 ` Sven Schnelle
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Christian Borntraeger @ 2024-06-28 16:35 UTC (permalink / raw)
  To: KVM
  Cc: Christian Borntraeger, Janosch Frank, David Hildenbrand,
	linux-s390, Thomas Huth, Claudio Imbrenda, Heiko Carstens,
	Vasily Gorbik, Alexander Gordeev, Marc Hartmayer, Sven Schnelle

in rare cases, e.g. for injecting a machine check we do intercept all
load PSW instructions via ICTL_LPSW. With facility 193 a new variant
LPSWEY was added. KVM needs to handle that as well.

Fixes: a3efa8429266 ("KVM: s390: gen_facilities: allow facilities 165, 193, 194 and 196")
Reported-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
---
 arch/s390/include/asm/kvm_host.h |  1 +
 arch/s390/kvm/kvm-s390.c         |  1 +
 arch/s390/kvm/kvm-s390.h         | 15 +++++++++++++++
 arch/s390/kvm/priv.c             | 32 ++++++++++++++++++++++++++++++++
 4 files changed, 49 insertions(+)

diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index 95990461888f..9281063636a7 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -427,6 +427,7 @@ struct kvm_vcpu_stat {
 	u64 instruction_io_other;
 	u64 instruction_lpsw;
 	u64 instruction_lpswe;
+	u64 instruction_lpswey;
 	u64 instruction_pfmf;
 	u64 instruction_ptff;
 	u64 instruction_sck;
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 50b77b759042..8e04c7f0c90c 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -132,6 +132,7 @@ const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = {
 	STATS_DESC_COUNTER(VCPU, instruction_io_other),
 	STATS_DESC_COUNTER(VCPU, instruction_lpsw),
 	STATS_DESC_COUNTER(VCPU, instruction_lpswe),
+	STATS_DESC_COUNTER(VCPU, instruction_lpswey),
 	STATS_DESC_COUNTER(VCPU, instruction_pfmf),
 	STATS_DESC_COUNTER(VCPU, instruction_ptff),
 	STATS_DESC_COUNTER(VCPU, instruction_sck),
diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h
index 111eb5c74784..1b326f3c3383 100644
--- a/arch/s390/kvm/kvm-s390.h
+++ b/arch/s390/kvm/kvm-s390.h
@@ -138,6 +138,21 @@ static inline u64 kvm_s390_get_base_disp_s(struct kvm_vcpu *vcpu, u8 *ar)
 	return (base2 ? vcpu->run->s.regs.gprs[base2] : 0) + disp2;
 }
 
+static inline u64 kvm_s390_get_base_disp_siy(struct kvm_vcpu *vcpu, u8 *ar)
+{
+	u32 base1 = vcpu->arch.sie_block->ipb >> 28;
+	s64 disp1;
+       
+	/* The displacement is a 20bit _SIGNED_ value */
+	disp1 = sign_extend64(((vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16) +
+			      ((vcpu->arch.sie_block->ipb & 0xff00) << 4), 19);
+
+	if (ar)
+		*ar = base1;
+
+	return (base1 ? vcpu->run->s.regs.gprs[base1] : 0) + disp1;
+}
+
 static inline void kvm_s390_get_base_disp_sse(struct kvm_vcpu *vcpu,
 					      u64 *address1, u64 *address2,
 					      u8 *ar_b1, u8 *ar_b2)
diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
index 1be19cc9d73c..1a49b89706f8 100644
--- a/arch/s390/kvm/priv.c
+++ b/arch/s390/kvm/priv.c
@@ -797,6 +797,36 @@ static int handle_lpswe(struct kvm_vcpu *vcpu)
 	return 0;
 }
 
+static int handle_lpswey(struct kvm_vcpu *vcpu)
+{
+	psw_t new_psw;
+	u64 addr;
+	int rc;
+	u8 ar;
+
+	vcpu->stat.instruction_lpswey++;
+
+	if (!test_kvm_facility(vcpu->kvm, 193))
+		return kvm_s390_inject_program_int(vcpu, PGM_OPERATION);
+
+	if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
+		return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
+
+	addr = kvm_s390_get_base_disp_siy(vcpu, &ar);
+	if (addr & 7)
+		return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
+
+	rc = read_guest(vcpu, addr, ar, &new_psw, sizeof(new_psw));
+	if (rc)
+		return kvm_s390_inject_prog_cond(vcpu, rc);
+
+	vcpu->arch.sie_block->gpsw = new_psw;
+	if (!is_valid_psw(&vcpu->arch.sie_block->gpsw))
+		return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
+
+	return 0;
+}
+
 static int handle_stidp(struct kvm_vcpu *vcpu)
 {
 	u64 stidp_data = vcpu->kvm->arch.model.cpuid;
@@ -1462,6 +1492,8 @@ int kvm_s390_handle_eb(struct kvm_vcpu *vcpu)
 	case 0x61:
 	case 0x62:
 		return handle_ri(vcpu);
+	case 0x71:
+		return handle_lpswey(vcpu);
 	default:
 		return -EOPNOTSUPP;
 	}
-- 
2.45.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] KVM: s390: fix LPSWEY handling
  2024-06-28 16:35 [PATCH v2] KVM: s390: fix LPSWEY handling Christian Borntraeger
@ 2024-07-01  6:08 ` Sven Schnelle
  2024-07-01  7:21   ` Christian Borntraeger
  2024-07-01  8:11 ` Sven Schnelle
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Sven Schnelle @ 2024-07-01  6:08 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: KVM, Janosch Frank, David Hildenbrand, linux-s390, Thomas Huth,
	Claudio Imbrenda, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Marc Hartmayer

Christian Borntraeger <borntraeger@linux.ibm.com> writes:

> in rare cases, e.g. for injecting a machine check we do intercept all
> load PSW instructions via ICTL_LPSW. With facility 193 a new variant
> LPSWEY was added. KVM needs to handle that as well.
>
> Fixes: a3efa8429266 ("KVM: s390: gen_facilities: allow facilities 165, 193, 194 and 196")
> Reported-by: Marc Hartmayer <mhartmay@linux.ibm.com>
> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
> ---
>  arch/s390/include/asm/kvm_host.h |  1 +
>  arch/s390/kvm/kvm-s390.c         |  1 +
>  arch/s390/kvm/kvm-s390.h         | 15 +++++++++++++++
>  arch/s390/kvm/priv.c             | 32 ++++++++++++++++++++++++++++++++
>  4 files changed, 49 insertions(+)
>
> diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
> index 1be19cc9d73c..1a49b89706f8 100644
> --- a/arch/s390/kvm/priv.c
> +++ b/arch/s390/kvm/priv.c
> @@ -797,6 +797,36 @@ static int handle_lpswe(struct kvm_vcpu *vcpu)
>  	return 0;
>  }
>  
> +static int handle_lpswey(struct kvm_vcpu *vcpu)
> +{
> +	psw_t new_psw;
> +	u64 addr;
> +	int rc;
> +	u8 ar;
> +
> +	vcpu->stat.instruction_lpswey++;
> +
> +	if (!test_kvm_facility(vcpu->kvm, 193))
> +		return kvm_s390_inject_program_int(vcpu, PGM_OPERATION);
> +
> +	if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
> +		return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
> +
> +	addr = kvm_s390_get_base_disp_siy(vcpu, &ar);
> +	if (addr & 7)
> +		return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
> +
> +	rc = read_guest(vcpu, addr, ar, &new_psw, sizeof(new_psw));
> +	if (rc)
> +		return kvm_s390_inject_prog_cond(vcpu, rc);
> +
> +	vcpu->arch.sie_block->gpsw = new_psw;
> +	if (!is_valid_psw(&vcpu->arch.sie_block->gpsw))
> +		return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);

Shouldn't the gpsw get updated with new_psw after the check? POP says "The operation
is suppressed on all addressing and protection exceptions."

> +
> +	return 0;
> +}

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] KVM: s390: fix LPSWEY handling
  2024-07-01  6:08 ` Sven Schnelle
@ 2024-07-01  7:21   ` Christian Borntraeger
  2024-07-01  7:25     ` Sven Schnelle
  0 siblings, 1 reply; 8+ messages in thread
From: Christian Borntraeger @ 2024-07-01  7:21 UTC (permalink / raw)
  To: Sven Schnelle
  Cc: KVM, Janosch Frank, David Hildenbrand, linux-s390, Thomas Huth,
	Claudio Imbrenda, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Marc Hartmayer



Am 01.07.24 um 08:08 schrieb Sven Schnelle:
> Christian Borntraeger <borntraeger@linux.ibm.com> writes:
> 
>> in rare cases, e.g. for injecting a machine check we do intercept all
>> load PSW instructions via ICTL_LPSW. With facility 193 a new variant
>> LPSWEY was added. KVM needs to handle that as well.
>>
>> Fixes: a3efa8429266 ("KVM: s390: gen_facilities: allow facilities 165, 193, 194 and 196")
>> Reported-by: Marc Hartmayer <mhartmay@linux.ibm.com>
>> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
>> ---
>>   arch/s390/include/asm/kvm_host.h |  1 +
>>   arch/s390/kvm/kvm-s390.c         |  1 +
>>   arch/s390/kvm/kvm-s390.h         | 15 +++++++++++++++
>>   arch/s390/kvm/priv.c             | 32 ++++++++++++++++++++++++++++++++
>>   4 files changed, 49 insertions(+)
>>
>> diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
>> index 1be19cc9d73c..1a49b89706f8 100644
>> --- a/arch/s390/kvm/priv.c
>> +++ b/arch/s390/kvm/priv.c
>> @@ -797,6 +797,36 @@ static int handle_lpswe(struct kvm_vcpu *vcpu)
>>   	return 0;
>>   }
>>   
>> +static int handle_lpswey(struct kvm_vcpu *vcpu)
>> +{
>> +	psw_t new_psw;
>> +	u64 addr;
>> +	int rc;
>> +	u8 ar;
>> +
>> +	vcpu->stat.instruction_lpswey++;
>> +
>> +	if (!test_kvm_facility(vcpu->kvm, 193))
>> +		return kvm_s390_inject_program_int(vcpu, PGM_OPERATION);
>> +
>> +	if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
>> +		return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
>> +
>> +	addr = kvm_s390_get_base_disp_siy(vcpu, &ar);
>> +	if (addr & 7)
>> +		return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
>> +
>> +	rc = read_guest(vcpu, addr, ar, &new_psw, sizeof(new_psw));
>> +	if (rc)
>> +		return kvm_s390_inject_prog_cond(vcpu, rc);
>> +
>> +	vcpu->arch.sie_block->gpsw = new_psw;
>> +	if (!is_valid_psw(&vcpu->arch.sie_block->gpsw))
>> +		return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
> 
> Shouldn't the gpsw get updated with new_psw after the check? POP says "The operation
> is suppressed on all addressing and protection exceptions."

Only for exception of the instruction but not for the target PSW.
POP says:

The other PSW fields which are to be loaded by the
instruction are not checked for validity before they are
loaded. However, immediately after loading, a speci-
fication exception is recognized, and a program inter-
ruption occurs, when any of the following is true for
the newly loaded PSW

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] KVM: s390: fix LPSWEY handling
  2024-07-01  7:21   ` Christian Borntraeger
@ 2024-07-01  7:25     ` Sven Schnelle
  2024-07-01  7:27       ` Christian Borntraeger
  0 siblings, 1 reply; 8+ messages in thread
From: Sven Schnelle @ 2024-07-01  7:25 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: KVM, Janosch Frank, David Hildenbrand, linux-s390, Thomas Huth,
	Claudio Imbrenda, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Marc Hartmayer

Christian Borntraeger <borntraeger@linux.ibm.com> writes:

> Am 01.07.24 um 08:08 schrieb Sven Schnelle:
>> Christian Borntraeger <borntraeger@linux.ibm.com> writes:
>> 
>>> diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
>>> index 1be19cc9d73c..1a49b89706f8 100644
>>> --- a/arch/s390/kvm/priv.c
>>> +++ b/arch/s390/kvm/priv.c
>>> @@ -797,6 +797,36 @@ static int handle_lpswe(struct kvm_vcpu *vcpu)
>>>   	return 0;
>>>   }
>>>   +static int handle_lpswey(struct kvm_vcpu *vcpu)
>>> +{
>>> +	psw_t new_psw;
>>> +	u64 addr;
>>> +	int rc;
>>> +	u8 ar;
>>> +
>>> +	vcpu->stat.instruction_lpswey++;
>>> +
>>> +	if (!test_kvm_facility(vcpu->kvm, 193))
>>> +		return kvm_s390_inject_program_int(vcpu, PGM_OPERATION);
>>> +
>>> +	if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
>>> +		return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
>>> +
>>> +	addr = kvm_s390_get_base_disp_siy(vcpu, &ar);
>>> +	if (addr & 7)
>>> +		return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
>>> +
>>> +	rc = read_guest(vcpu, addr, ar, &new_psw, sizeof(new_psw));
>>> +	if (rc)
>>> +		return kvm_s390_inject_prog_cond(vcpu, rc);
>>> +
>>> +	vcpu->arch.sie_block->gpsw = new_psw;
>>> +	if (!is_valid_psw(&vcpu->arch.sie_block->gpsw))
>>> +		return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
>> Shouldn't the gpsw get updated with new_psw after the check? POP
>> says "The operation
>> is suppressed on all addressing and protection exceptions."
>
> Only for exception of the instruction but not for the target PSW.
> POP says:
>
> The other PSW fields which are to be loaded by the
> instruction are not checked for validity before they are
> loaded. However, immediately after loading, a speci-
> fication exception is recognized, and a program inter-
> ruption occurs, when any of the following is true for
> the newly loaded PSW

Ok, sorry for the noise.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] KVM: s390: fix LPSWEY handling
  2024-07-01  7:25     ` Sven Schnelle
@ 2024-07-01  7:27       ` Christian Borntraeger
  0 siblings, 0 replies; 8+ messages in thread
From: Christian Borntraeger @ 2024-07-01  7:27 UTC (permalink / raw)
  To: Sven Schnelle
  Cc: KVM, Janosch Frank, David Hildenbrand, linux-s390, Thomas Huth,
	Claudio Imbrenda, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Marc Hartmayer


Am 01.07.24 um 09:25 schrieb Sven Schnelle:
>>>> +	vcpu->arch.sie_block->gpsw = new_psw;
>>>> +	if (!is_valid_psw(&vcpu->arch.sie_block->gpsw))
>>>> +		return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
>>> Shouldn't the gpsw get updated with new_psw after the check? POP
>>> says "The operation
>>> is suppressed on all addressing and protection exceptions."
>>
>> Only for exception of the instruction but not for the target PSW.
>> POP says:
>>
>> The other PSW fields which are to be loaded by the
>> instruction are not checked for validity before they are
>> loaded. However, immediately after loading, a speci-
>> fication exception is recognized, and a program inter-
>> ruption occurs, when any of the following is true for
>> the newly loaded PSW
> 
> Ok, sorry for the noise.

You can repend by doing a review and send an RB or other feedback :-)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] KVM: s390: fix LPSWEY handling
  2024-06-28 16:35 [PATCH v2] KVM: s390: fix LPSWEY handling Christian Borntraeger
  2024-07-01  6:08 ` Sven Schnelle
@ 2024-07-01  8:11 ` Sven Schnelle
  2024-07-01 10:28 ` Claudio Imbrenda
  2024-07-01 10:39 ` Christian Borntraeger
  3 siblings, 0 replies; 8+ messages in thread
From: Sven Schnelle @ 2024-07-01  8:11 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: KVM, Janosch Frank, David Hildenbrand, linux-s390, Thomas Huth,
	Claudio Imbrenda, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Marc Hartmayer

Christian Borntraeger <borntraeger@linux.ibm.com> writes:

> in rare cases, e.g. for injecting a machine check we do intercept all
> load PSW instructions via ICTL_LPSW. With facility 193 a new variant
> LPSWEY was added. KVM needs to handle that as well.
>
> Fixes: a3efa8429266 ("KVM: s390: gen_facilities: allow facilities 165, 193, 194 and 196")
> Reported-by: Marc Hartmayer <mhartmay@linux.ibm.com>
> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>
> ---
>  arch/s390/include/asm/kvm_host.h |  1 +
>  arch/s390/kvm/kvm-s390.c         |  1 +
>  arch/s390/kvm/kvm-s390.h         | 15 +++++++++++++++
>  arch/s390/kvm/priv.c             | 32 ++++++++++++++++++++++++++++++++
>  4 files changed, 49 insertions(+)
>
> diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h
> index 111eb5c74784..1b326f3c3383 100644
> --- a/arch/s390/kvm/kvm-s390.h
> +++ b/arch/s390/kvm/kvm-s390.h
> @@ -138,6 +138,21 @@ static inline u64 kvm_s390_get_base_disp_s(struct kvm_vcpu *vcpu, u8 *ar)
>  	return (base2 ? vcpu->run->s.regs.gprs[base2] : 0) + disp2;
>  }
>  
> +static inline u64 kvm_s390_get_base_disp_siy(struct kvm_vcpu *vcpu, u8 *ar)
> +{
> +	u32 base1 = vcpu->arch.sie_block->ipb >> 28;
> +	s64 disp1;
> +       

Whitespace error. With that removed:

Reviewed-by: Sven Schnelle <svens@linux.ibm.com>

> +	/* The displacement is a 20bit _SIGNED_ value */
> +	disp1 = sign_extend64(((vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16) +
> +			      ((vcpu->arch.sie_block->ipb & 0xff00) << 4), 19);
> +
> +	if (ar)
> +		*ar = base1;
> +
> +	return (base1 ? vcpu->run->s.regs.gprs[base1] : 0) + disp1;
> +}

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] KVM: s390: fix LPSWEY handling
  2024-06-28 16:35 [PATCH v2] KVM: s390: fix LPSWEY handling Christian Borntraeger
  2024-07-01  6:08 ` Sven Schnelle
  2024-07-01  8:11 ` Sven Schnelle
@ 2024-07-01 10:28 ` Claudio Imbrenda
  2024-07-01 10:39 ` Christian Borntraeger
  3 siblings, 0 replies; 8+ messages in thread
From: Claudio Imbrenda @ 2024-07-01 10:28 UTC (permalink / raw)
  To: Christian Borntraeger
  Cc: KVM, Janosch Frank, David Hildenbrand, linux-s390, Thomas Huth,
	Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Marc Hartmayer,
	Sven Schnelle

On Fri, 28 Jun 2024 18:35:47 +0200
Christian Borntraeger <borntraeger@linux.ibm.com> wrote:

> in rare cases, e.g. for injecting a machine check we do intercept all
> load PSW instructions via ICTL_LPSW. With facility 193 a new variant
> LPSWEY was added. KVM needs to handle that as well.
> 
> Fixes: a3efa8429266 ("KVM: s390: gen_facilities: allow facilities 165, 193, 194 and 196")
> Reported-by: Marc Hartmayer <mhartmay@linux.ibm.com>
> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>

With the whitespace error reported by Sven fixed:

Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>

> ---
>  arch/s390/include/asm/kvm_host.h |  1 +
>  arch/s390/kvm/kvm-s390.c         |  1 +
>  arch/s390/kvm/kvm-s390.h         | 15 +++++++++++++++
>  arch/s390/kvm/priv.c             | 32 ++++++++++++++++++++++++++++++++
>  4 files changed, 49 insertions(+)
> 
> diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
> index 95990461888f..9281063636a7 100644
> --- a/arch/s390/include/asm/kvm_host.h
> +++ b/arch/s390/include/asm/kvm_host.h
> @@ -427,6 +427,7 @@ struct kvm_vcpu_stat {
>  	u64 instruction_io_other;
>  	u64 instruction_lpsw;
>  	u64 instruction_lpswe;
> +	u64 instruction_lpswey;
>  	u64 instruction_pfmf;
>  	u64 instruction_ptff;
>  	u64 instruction_sck;
> diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
> index 50b77b759042..8e04c7f0c90c 100644
> --- a/arch/s390/kvm/kvm-s390.c
> +++ b/arch/s390/kvm/kvm-s390.c
> @@ -132,6 +132,7 @@ const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = {
>  	STATS_DESC_COUNTER(VCPU, instruction_io_other),
>  	STATS_DESC_COUNTER(VCPU, instruction_lpsw),
>  	STATS_DESC_COUNTER(VCPU, instruction_lpswe),
> +	STATS_DESC_COUNTER(VCPU, instruction_lpswey),
>  	STATS_DESC_COUNTER(VCPU, instruction_pfmf),
>  	STATS_DESC_COUNTER(VCPU, instruction_ptff),
>  	STATS_DESC_COUNTER(VCPU, instruction_sck),
> diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h
> index 111eb5c74784..1b326f3c3383 100644
> --- a/arch/s390/kvm/kvm-s390.h
> +++ b/arch/s390/kvm/kvm-s390.h
> @@ -138,6 +138,21 @@ static inline u64 kvm_s390_get_base_disp_s(struct kvm_vcpu *vcpu, u8 *ar)
>  	return (base2 ? vcpu->run->s.regs.gprs[base2] : 0) + disp2;
>  }
>  
> +static inline u64 kvm_s390_get_base_disp_siy(struct kvm_vcpu *vcpu, u8 *ar)
> +{
> +	u32 base1 = vcpu->arch.sie_block->ipb >> 28;
> +	s64 disp1;
> +       
> +	/* The displacement is a 20bit _SIGNED_ value */
> +	disp1 = sign_extend64(((vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16) +
> +			      ((vcpu->arch.sie_block->ipb & 0xff00) << 4), 19);
> +
> +	if (ar)
> +		*ar = base1;
> +
> +	return (base1 ? vcpu->run->s.regs.gprs[base1] : 0) + disp1;
> +}
> +
>  static inline void kvm_s390_get_base_disp_sse(struct kvm_vcpu *vcpu,
>  					      u64 *address1, u64 *address2,
>  					      u8 *ar_b1, u8 *ar_b2)
> diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
> index 1be19cc9d73c..1a49b89706f8 100644
> --- a/arch/s390/kvm/priv.c
> +++ b/arch/s390/kvm/priv.c
> @@ -797,6 +797,36 @@ static int handle_lpswe(struct kvm_vcpu *vcpu)
>  	return 0;
>  }
>  
> +static int handle_lpswey(struct kvm_vcpu *vcpu)
> +{
> +	psw_t new_psw;
> +	u64 addr;
> +	int rc;
> +	u8 ar;
> +
> +	vcpu->stat.instruction_lpswey++;
> +
> +	if (!test_kvm_facility(vcpu->kvm, 193))
> +		return kvm_s390_inject_program_int(vcpu, PGM_OPERATION);
> +
> +	if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
> +		return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
> +
> +	addr = kvm_s390_get_base_disp_siy(vcpu, &ar);
> +	if (addr & 7)
> +		return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
> +
> +	rc = read_guest(vcpu, addr, ar, &new_psw, sizeof(new_psw));
> +	if (rc)
> +		return kvm_s390_inject_prog_cond(vcpu, rc);
> +
> +	vcpu->arch.sie_block->gpsw = new_psw;
> +	if (!is_valid_psw(&vcpu->arch.sie_block->gpsw))
> +		return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
> +
> +	return 0;
> +}
> +
>  static int handle_stidp(struct kvm_vcpu *vcpu)
>  {
>  	u64 stidp_data = vcpu->kvm->arch.model.cpuid;
> @@ -1462,6 +1492,8 @@ int kvm_s390_handle_eb(struct kvm_vcpu *vcpu)
>  	case 0x61:
>  	case 0x62:
>  		return handle_ri(vcpu);
> +	case 0x71:
> +		return handle_lpswey(vcpu);
>  	default:
>  		return -EOPNOTSUPP;
>  	}


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] KVM: s390: fix LPSWEY handling
  2024-06-28 16:35 [PATCH v2] KVM: s390: fix LPSWEY handling Christian Borntraeger
                   ` (2 preceding siblings ...)
  2024-07-01 10:28 ` Claudio Imbrenda
@ 2024-07-01 10:39 ` Christian Borntraeger
  3 siblings, 0 replies; 8+ messages in thread
From: Christian Borntraeger @ 2024-07-01 10:39 UTC (permalink / raw)
  To: KVM
  Cc: Janosch Frank, David Hildenbrand, linux-s390, Thomas Huth,
	Claudio Imbrenda, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Marc Hartmayer, Sven Schnelle

Am 28.06.24 um 18:35 schrieb Christian Borntraeger:
> in rare cases, e.g. for injecting a machine check we do intercept all
> load PSW instructions via ICTL_LPSW. With facility 193 a new variant
> LPSWEY was added. KVM needs to handle that as well.
> 
> Fixes: a3efa8429266 ("KVM: s390: gen_facilities: allow facilities 165, 193, 194 and 196")
> Reported-by: Marc Hartmayer <mhartmay@linux.ibm.com>
> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com>

applied.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-07-01 10:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-28 16:35 [PATCH v2] KVM: s390: fix LPSWEY handling Christian Borntraeger
2024-07-01  6:08 ` Sven Schnelle
2024-07-01  7:21   ` Christian Borntraeger
2024-07-01  7:25     ` Sven Schnelle
2024-07-01  7:27       ` Christian Borntraeger
2024-07-01  8:11 ` Sven Schnelle
2024-07-01 10:28 ` Claudio Imbrenda
2024-07-01 10:39 ` Christian Borntraeger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).