2021-07-06 12:14:53

by Janis Schoetterl-Glausch

[permalink] [raw]
Subject: [PATCH] KVM: s390: Enable specification exception interpretation

When this feature is enabled the hardware is free to interpret
specification exceptions generated by the guest, instead of causing
program interruption interceptions.

This benefits (test) programs that generate a lot of specification
exceptions (roughly 4x increase in exceptions/sec).

Interceptions will occur as before if ICTL_PINT is set,
i.e. if guest debug is enabled.

Signed-off-by: Janis Schoetterl-Glausch <[email protected]>
---
I'll additionally send kvm-unit-tests for testing this feature.

arch/s390/include/asm/kvm_host.h | 1 +
arch/s390/kvm/kvm-s390.c | 2 ++
arch/s390/kvm/vsie.c | 2 ++
3 files changed, 5 insertions(+)

diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index 9b4473f76e56..3a5b5084cdbe 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -244,6 +244,7 @@ struct kvm_s390_sie_block {
__u8 fpf; /* 0x0060 */
#define ECB_GS 0x40
#define ECB_TE 0x10
+#define ECB_SPECI 0x08
#define ECB_SRSI 0x04
#define ECB_HOSTPROTINT 0x02
__u8 ecb; /* 0x0061 */
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index b655a7d82bf0..aadd589a3755 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -3200,6 +3200,8 @@ static int kvm_s390_vcpu_setup(struct kvm_vcpu *vcpu)
vcpu->arch.sie_block->ecb |= ECB_SRSI;
if (test_kvm_facility(vcpu->kvm, 73))
vcpu->arch.sie_block->ecb |= ECB_TE;
+ if (!kvm_is_ucontrol(vcpu->kvm))
+ vcpu->arch.sie_block->ecb |= ECB_SPECI;

if (test_kvm_facility(vcpu->kvm, 8) && vcpu->kvm->arch.use_pfmfi)
vcpu->arch.sie_block->ecb2 |= ECB2_PFMFI;
diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c
index 4002a24bc43a..acda4b6fc851 100644
--- a/arch/s390/kvm/vsie.c
+++ b/arch/s390/kvm/vsie.c
@@ -510,6 +510,8 @@ static int shadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
prefix_unmapped(vsie_page);
scb_s->ecb |= ECB_TE;
}
+ /* specification exception interpretation */
+ scb_s->ecb |= scb_o->ecb & ECB_SPECI;
/* branch prediction */
if (test_kvm_facility(vcpu->kvm, 82))
scb_s->fpf |= scb_o->fpf & FPF_BPBC;
--
2.25.1


2021-07-06 12:15:20

by David Hildenbrand

[permalink] [raw]
Subject: Re: [PATCH] KVM: s390: Enable specification exception interpretation

On 06.07.21 13:47, Janis Schoetterl-Glausch wrote:
> When this feature is enabled the hardware is free to interpret
> specification exceptions generated by the guest, instead of causing
> program interruption interceptions.
>
> This benefits (test) programs that generate a lot of specification
> exceptions (roughly 4x increase in exceptions/sec).
>
> Interceptions will occur as before if ICTL_PINT is set,
> i.e. if guest debug is enabled.
>
> Signed-off-by: Janis Schoetterl-Glausch <[email protected]>
> ---
> I'll additionally send kvm-unit-tests for testing this feature.
>
> arch/s390/include/asm/kvm_host.h | 1 +
> arch/s390/kvm/kvm-s390.c | 2 ++
> arch/s390/kvm/vsie.c | 2 ++
> 3 files changed, 5 insertions(+)
>
> diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
> index 9b4473f76e56..3a5b5084cdbe 100644
> --- a/arch/s390/include/asm/kvm_host.h
> +++ b/arch/s390/include/asm/kvm_host.h
> @@ -244,6 +244,7 @@ struct kvm_s390_sie_block {
> __u8 fpf; /* 0x0060 */
> #define ECB_GS 0x40
> #define ECB_TE 0x10
> +#define ECB_SPECI 0x08
> #define ECB_SRSI 0x04
> #define ECB_HOSTPROTINT 0x02
> __u8 ecb; /* 0x0061 */
> diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
> index b655a7d82bf0..aadd589a3755 100644
> --- a/arch/s390/kvm/kvm-s390.c
> +++ b/arch/s390/kvm/kvm-s390.c
> @@ -3200,6 +3200,8 @@ static int kvm_s390_vcpu_setup(struct kvm_vcpu *vcpu)
> vcpu->arch.sie_block->ecb |= ECB_SRSI;
> if (test_kvm_facility(vcpu->kvm, 73))
> vcpu->arch.sie_block->ecb |= ECB_TE;
> + if (!kvm_is_ucontrol(vcpu->kvm))
> + vcpu->arch.sie_block->ecb |= ECB_SPECI;
>
> if (test_kvm_facility(vcpu->kvm, 8) && vcpu->kvm->arch.use_pfmfi)
> vcpu->arch.sie_block->ecb2 |= ECB2_PFMFI;
> diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c
> index 4002a24bc43a..acda4b6fc851 100644
> --- a/arch/s390/kvm/vsie.c
> +++ b/arch/s390/kvm/vsie.c
> @@ -510,6 +510,8 @@ static int shadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
> prefix_unmapped(vsie_page);
> scb_s->ecb |= ECB_TE;
> }
> + /* specification exception interpretation */
> + scb_s->ecb |= scb_o->ecb & ECB_SPECI;
> /* branch prediction */
> if (test_kvm_facility(vcpu->kvm, 82))
> scb_s->fpf |= scb_o->fpf & FPF_BPBC;
>

I assume this is a new CPU feature, right? If so

a) How can we check whether we can actually safely enable it. (which
facility do we have to check)
b) Do we have to handle vSIE? Do we have to indicate a CPU feature that
unlocks this feature?

--
Thanks,

David / dhildenb

2021-07-07 08:31:50

by Christian Borntraeger

[permalink] [raw]
Subject: Re: [PATCH] KVM: s390: Enable specification exception interpretation



On 06.07.21 13:47, Janis Schoetterl-Glausch wrote:
> When this feature is enabled the hardware is free to interpret
> specification exceptions generated by the guest, instead of causing
> program interruption interceptions.
>
> This benefits (test) programs that generate a lot of specification
> exceptions (roughly 4x increase in exceptions/sec).
>
> Interceptions will occur as before if ICTL_PINT is set,
> i.e. if guest debug is enabled.

I think I will add

There is no indication if this feature is available or not and the hardware
is free to interpret or not. So we can simply set this bit and if the
hardware ignores it we fall back to intercept 8 handling.


With that

Reviewed-by: Christian Borntraeger <[email protected]>
>
> Signed-off-by: Janis Schoetterl-Glausch <[email protected]>
> ---
> I'll additionally send kvm-unit-tests for testing this feature.
>
> arch/s390/include/asm/kvm_host.h | 1 +
> arch/s390/kvm/kvm-s390.c | 2 ++
> arch/s390/kvm/vsie.c | 2 ++
> 3 files changed, 5 insertions(+)
>
> diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
> index 9b4473f76e56..3a5b5084cdbe 100644
> --- a/arch/s390/include/asm/kvm_host.h
> +++ b/arch/s390/include/asm/kvm_host.h
> @@ -244,6 +244,7 @@ struct kvm_s390_sie_block {
> __u8 fpf; /* 0x0060 */
> #define ECB_GS 0x40
> #define ECB_TE 0x10
> +#define ECB_SPECI 0x08
> #define ECB_SRSI 0x04
> #define ECB_HOSTPROTINT 0x02
> __u8 ecb; /* 0x0061 */
> diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
> index b655a7d82bf0..aadd589a3755 100644
> --- a/arch/s390/kvm/kvm-s390.c
> +++ b/arch/s390/kvm/kvm-s390.c
> @@ -3200,6 +3200,8 @@ static int kvm_s390_vcpu_setup(struct kvm_vcpu *vcpu)
> vcpu->arch.sie_block->ecb |= ECB_SRSI;
> if (test_kvm_facility(vcpu->kvm, 73))
> vcpu->arch.sie_block->ecb |= ECB_TE;
> + if (!kvm_is_ucontrol(vcpu->kvm))
> + vcpu->arch.sie_block->ecb |= ECB_SPECI;
>
> if (test_kvm_facility(vcpu->kvm, 8) && vcpu->kvm->arch.use_pfmfi)
> vcpu->arch.sie_block->ecb2 |= ECB2_PFMFI;
> diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c
> index 4002a24bc43a..acda4b6fc851 100644
> --- a/arch/s390/kvm/vsie.c
> +++ b/arch/s390/kvm/vsie.c
> @@ -510,6 +510,8 @@ static int shadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
> prefix_unmapped(vsie_page);
> scb_s->ecb |= ECB_TE;
> }
> + /* specification exception interpretation */
> + scb_s->ecb |= scb_o->ecb & ECB_SPECI;
> /* branch prediction */
> if (test_kvm_facility(vcpu->kvm, 82))
> scb_s->fpf |= scb_o->fpf & FPF_BPBC;
>

2021-07-07 08:55:43

by Cornelia Huck

[permalink] [raw]
Subject: Re: [PATCH] KVM: s390: Enable specification exception interpretation

On Wed, Jul 07 2021, Christian Borntraeger <[email protected]> wrote:

> On 06.07.21 13:47, Janis Schoetterl-Glausch wrote:
>> When this feature is enabled the hardware is free to interpret
>> specification exceptions generated by the guest, instead of causing
>> program interruption interceptions.
>>
>> This benefits (test) programs that generate a lot of specification
>> exceptions (roughly 4x increase in exceptions/sec).
>>
>> Interceptions will occur as before if ICTL_PINT is set,
>> i.e. if guest debug is enabled.
>
> I think I will add
>
> There is no indication if this feature is available or not and the hardware
> is free to interpret or not. So we can simply set this bit and if the
> hardware ignores it we fall back to intercept 8 handling.

Sounds good.

>
>
> With that
>
> Reviewed-by: Christian Borntraeger <[email protected]>
>>
>> Signed-off-by: Janis Schoetterl-Glausch <[email protected]>
>> ---
>> I'll additionally send kvm-unit-tests for testing this feature.
>>
>> arch/s390/include/asm/kvm_host.h | 1 +
>> arch/s390/kvm/kvm-s390.c | 2 ++
>> arch/s390/kvm/vsie.c | 2 ++
>> 3 files changed, 5 insertions(+)

(...)

>> diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
>> index b655a7d82bf0..aadd589a3755 100644
>> --- a/arch/s390/kvm/kvm-s390.c
>> +++ b/arch/s390/kvm/kvm-s390.c
>> @@ -3200,6 +3200,8 @@ static int kvm_s390_vcpu_setup(struct kvm_vcpu *vcpu)
>> vcpu->arch.sie_block->ecb |= ECB_SRSI;
>> if (test_kvm_facility(vcpu->kvm, 73))
>> vcpu->arch.sie_block->ecb |= ECB_TE;

Maybe add

/* no facility bit, but safe as the hardware may ignore it */

or something like that, so that we don't stumble over that in the future?

>> + if (!kvm_is_ucontrol(vcpu->kvm))
>> + vcpu->arch.sie_block->ecb |= ECB_SPECI;
>>
>> if (test_kvm_facility(vcpu->kvm, 8) && vcpu->kvm->arch.use_pfmfi)
>> vcpu->arch.sie_block->ecb2 |= ECB2_PFMFI;

Reviewed-by: Cornelia Huck <[email protected]>

2021-07-07 08:58:19

by Janis Schoetterl-Glausch

[permalink] [raw]
Subject: Re: [PATCH] KVM: s390: Enable specification exception interpretation

On 7/7/21 10:30 AM, Christian Borntraeger wrote:
>
>
> On 06.07.21 13:47, Janis Schoetterl-Glausch wrote:
>> When this feature is enabled the hardware is free to interpret
>> specification exceptions generated by the guest, instead of causing
>> program interruption interceptions.
>>
>> This benefits (test) programs that generate a lot of specification
>> exceptions (roughly 4x increase in exceptions/sec).
>>
>> Interceptions will occur as before if ICTL_PINT is set,
>> i.e. if guest debug is enabled.
>
> I think I will add
>
> There is no indication if this feature is available or not and the hardware
> is free to interpret or not. So we can simply set this bit and if the
> hardware ignores it we fall back to intercept 8 handling.

Might also mention vSIE and/or incorporate into first paragraph:

When this feature is enabled the hardware is free to interpret
specification exceptions generated by the guest, instead of causing
program interruption interceptions, but it is not required to.
There is no indication if this feature is available or not,
so we can simply set this bit and if the hardware ignores it
we fall back to intercept 8 handling.
The same applies to vSIE, we forward the guest hypervisor's bit
and fall back to injection if interpretation does not occur.
>
>
> With that
>
> Reviewed-by: Christian Borntraeger <[email protected]>

[...]

2021-07-07 09:02:06

by Christian Borntraeger

[permalink] [raw]
Subject: Re: [PATCH] KVM: s390: Enable specification exception interpretation



On 07.07.21 10:56, Janis Schoetterl-Glausch wrote:
> On 7/7/21 10:30 AM, Christian Borntraeger wrote:
>>
>>
>> On 06.07.21 13:47, Janis Schoetterl-Glausch wrote:
>>> When this feature is enabled the hardware is free to interpret
>>> specification exceptions generated by the guest, instead of causing
>>> program interruption interceptions.
>>>
>>> This benefits (test) programs that generate a lot of specification
>>> exceptions (roughly 4x increase in exceptions/sec).
>>>
>>> Interceptions will occur as before if ICTL_PINT is set,
>>> i.e. if guest debug is enabled.
>>
>> I think I will add
>>
>> There is no indication if this feature is available or not and the hardware
>> is free to interpret or not. So we can simply set this bit and if the
>> hardware ignores it we fall back to intercept 8 handling.
>
> Might also mention vSIE and/or incorporate into first paragraph:
>
> When this feature is enabled the hardware is free to interpret
> specification exceptions generated by the guest, instead of causing
> program interruption interceptions, but it is not required to.
> There is no indication if this feature is available or not,
> so we can simply set this bit and if the hardware ignores it
> we fall back to intercept 8 handling.
> The same applies to vSIE, we forward the guest hypervisor's bit
> and fall back to injection if interpretation does not occur.

Can you maybe resend a v2 with all comments (and RBs) added?

2021-07-07 09:57:17

by Janis Schoetterl-Glausch

[permalink] [raw]
Subject: Re: [PATCH] KVM: s390: Enable specification exception interpretation

On 7/7/21 10:54 AM, Cornelia Huck wrote:

[...]

>
>>> diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
>>> index b655a7d82bf0..aadd589a3755 100644
>>> --- a/arch/s390/kvm/kvm-s390.c
>>> +++ b/arch/s390/kvm/kvm-s390.c
>>> @@ -3200,6 +3200,8 @@ static int kvm_s390_vcpu_setup(struct kvm_vcpu *vcpu)
>>> vcpu->arch.sie_block->ecb |= ECB_SRSI;
>>> if (test_kvm_facility(vcpu->kvm, 73))
>>> vcpu->arch.sie_block->ecb |= ECB_TE;
>
> Maybe add
>
> /* no facility bit, but safe as the hardware may ignore it */
>
> or something like that, so that we don't stumble over that in the future?

Well, the hardware being allowed to ignore the bit makes its introduction
without an indication forward compatible because it does not require vSIE to be adapted.
The reserved bits are implicitly set to 0 which means new features are disabled
by default and one observes all the interception one expects.

Maybe this:

/* no facility bit, can opt in because we do not need
to observe specification exception intercepts */

?

>
>>> + if (!kvm_is_ucontrol(vcpu->kvm))
>>> + vcpu->arch.sie_block->ecb |= ECB_SPECI;
>>>
>>> if (test_kvm_facility(vcpu->kvm, 8) && vcpu->kvm->arch.use_pfmfi)
>>> vcpu->arch.sie_block->ecb2 |= ECB2_PFMFI;
>
> Reviewed-by: Cornelia Huck <[email protected]>
>

2021-07-07 11:44:18

by Cornelia Huck

[permalink] [raw]
Subject: Re: [PATCH] KVM: s390: Enable specification exception interpretation

On Wed, Jul 07 2021, Janis Schoetterl-Glausch <[email protected]> wrote:

> On 7/7/21 10:54 AM, Cornelia Huck wrote:
>
> [...]
>
>>
>>>> diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
>>>> index b655a7d82bf0..aadd589a3755 100644
>>>> --- a/arch/s390/kvm/kvm-s390.c
>>>> +++ b/arch/s390/kvm/kvm-s390.c
>>>> @@ -3200,6 +3200,8 @@ static int kvm_s390_vcpu_setup(struct kvm_vcpu *vcpu)
>>>> vcpu->arch.sie_block->ecb |= ECB_SRSI;
>>>> if (test_kvm_facility(vcpu->kvm, 73))
>>>> vcpu->arch.sie_block->ecb |= ECB_TE;
>>
>> Maybe add
>>
>> /* no facility bit, but safe as the hardware may ignore it */
>>
>> or something like that, so that we don't stumble over that in the future?
>
> Well, the hardware being allowed to ignore the bit makes its introduction
> without an indication forward compatible because it does not require vSIE to be adapted.
> The reserved bits are implicitly set to 0 which means new features are disabled
> by default and one observes all the interception one expects.
>
> Maybe this:
>
> /* no facility bit, can opt in because we do not need
> to observe specification exception intercepts */
>
> ?

Works for me as well.

>
>>
>>>> + if (!kvm_is_ucontrol(vcpu->kvm))
>>>> + vcpu->arch.sie_block->ecb |= ECB_SPECI;
>>>>
>>>> if (test_kvm_facility(vcpu->kvm, 8) && vcpu->kvm->arch.use_pfmfi)
>>>> vcpu->arch.sie_block->ecb2 |= ECB2_PFMFI;
>>
>> Reviewed-by: Cornelia Huck <[email protected]>
>>