2020-04-02 18:51:02

by David Hildenbrand

[permalink] [raw]
Subject: [PATCH v1 0/5] KVM: s390: vsie: fixes and cleanups.

Some vsie/gmap fixes and two cleanups/improvements.

Patch #1 fixes an issue reported by Janosch. It was never observed so far,
because KVM usually doesn't use a region 1 table for it's guest (unless
memory would be exceeding something like 16 EB, which isn't even supported
by the HW). Older QEMU+KVM or other hypervisors can trigger this.

Patch #2 fixes a code path that probably was never taken and will most
probably not be taken very often in the future - unless somebody really
messes up the page tables for a guest (or writes a test for it). At some
point, a test case for this would be nice.

Patch #3 fixes a rare possible race. Don't think this is stable material.

Gave it some testing with my limited access to somewhat-fast s390x
machines. Booted a Linux kernel, supplying all possible number of
page table hiearchies.

David Hildenbrand (5):
KVM: s390: vsie: Fix region 1 ASCE sanity shadow address checks
KVM: s390: vsie: Fix delivery of addressing exceptions
KVM: s390: vsie: Fix possible race when shadowing region 3 tables
KVM: s390: vsie: Move conditional reschedule
KVM: s390: vsie: gmap_table_walk() simplifications

arch/s390/kvm/vsie.c | 4 ++--
arch/s390/mm/gmap.c | 14 ++++++++++----
2 files changed, 12 insertions(+), 6 deletions(-)

--
2.25.1


2020-04-02 19:33:34

by David Hildenbrand

[permalink] [raw]
Subject: [PATCH v1 2/5] KVM: s390: vsie: Fix delivery of addressing exceptions

Whenever we get an -EFAULT, we failed to read in guest 2 physical
address space. Such addressing exceptions are reported via a program
intercept to the nested hypervisor.

We faked the intercept, we have to return to guest 2. Instead, right
now we would be returning -EFAULT from the intercept handler, eventually
crashing the VM.

Addressing exceptions can only happen if the g2->g3 page tables
reference invalid g2 addresses (say, either a table or the final page is
not accessible - so something that basically never happens in sane
environments.

Identified by manual code inspection.

Fixes: a3508fbe9dc6 ("KVM: s390: vsie: initial support for nested virtualization")
Cc: <[email protected]> # v4.8+
Signed-off-by: David Hildenbrand <[email protected]>
---
arch/s390/kvm/vsie.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c
index 076090f9e666..4f6c22d72072 100644
--- a/arch/s390/kvm/vsie.c
+++ b/arch/s390/kvm/vsie.c
@@ -1202,6 +1202,7 @@ static int vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
scb_s->iprcc = PGM_ADDRESSING;
scb_s->pgmilc = 4;
scb_s->gpsw.addr = __rewind_psw(scb_s->gpsw, 4);
+ rc = 1;
}
return rc;
}
--
2.25.1

2020-04-06 13:18:42

by Christian Borntraeger

[permalink] [raw]
Subject: Re: [PATCH v1 2/5] KVM: s390: vsie: Fix delivery of addressing exceptions



On 02.04.20 20:48, David Hildenbrand wrote:
> Whenever we get an -EFAULT, we failed to read in guest 2 physical
> address space. Such addressing exceptions are reported via a program
> intercept to the nested hypervisor.
>
> We faked the intercept, we have to return to guest 2. Instead, right
> now we would be returning -EFAULT from the intercept handler, eventually
> crashing the VM.
>
> Addressing exceptions can only happen if the g2->g3 page tables
> reference invalid g2 addresses (say, either a table or the final page is
> not accessible - so something that basically never happens in sane
> environments.
>
> Identified by manual code inspection.
>
> Fixes: a3508fbe9dc6 ("KVM: s390: vsie: initial support for nested virtualization")
> Cc: <[email protected]> # v4.8+
> Signed-off-by: David Hildenbrand <[email protected]>
> ---
> arch/s390/kvm/vsie.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c
> index 076090f9e666..4f6c22d72072 100644
> --- a/arch/s390/kvm/vsie.c
> +++ b/arch/s390/kvm/vsie.c
> @@ -1202,6 +1202,7 @@ static int vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
> scb_s->iprcc = PGM_ADDRESSING;
> scb_s->pgmilc = 4;
> scb_s->gpsw.addr = __rewind_psw(scb_s->gpsw, 4);
> + rc = 1;


kvm_s390_handle_vsie has

return rc < 0 ? rc : 0;


so rc = 0 would result in the same behaviour, correct?
Since we DO handle everything as we should, why rc = 1 ?

2020-04-06 13:24:32

by David Hildenbrand

[permalink] [raw]
Subject: Re: [PATCH v1 2/5] KVM: s390: vsie: Fix delivery of addressing exceptions

On 06.04.20 15:17, Christian Borntraeger wrote:
>
>
> On 02.04.20 20:48, David Hildenbrand wrote:
>> Whenever we get an -EFAULT, we failed to read in guest 2 physical
>> address space. Such addressing exceptions are reported via a program
>> intercept to the nested hypervisor.
>>
>> We faked the intercept, we have to return to guest 2. Instead, right
>> now we would be returning -EFAULT from the intercept handler, eventually
>> crashing the VM.
>>
>> Addressing exceptions can only happen if the g2->g3 page tables
>> reference invalid g2 addresses (say, either a table or the final page is
>> not accessible - so something that basically never happens in sane
>> environments.
>>
>> Identified by manual code inspection.
>>
>> Fixes: a3508fbe9dc6 ("KVM: s390: vsie: initial support for nested virtualization")
>> Cc: <[email protected]> # v4.8+
>> Signed-off-by: David Hildenbrand <[email protected]>
>> ---
>> arch/s390/kvm/vsie.c | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c
>> index 076090f9e666..4f6c22d72072 100644
>> --- a/arch/s390/kvm/vsie.c
>> +++ b/arch/s390/kvm/vsie.c
>> @@ -1202,6 +1202,7 @@ static int vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
>> scb_s->iprcc = PGM_ADDRESSING;
>> scb_s->pgmilc = 4;
>> scb_s->gpsw.addr = __rewind_psw(scb_s->gpsw, 4);
>> + rc = 1;
>
>
> kvm_s390_handle_vsie has
>
> return rc < 0 ? rc : 0;
>
>
> so rc = 0 would result in the same behaviour, correct?

yes

> Since we DO handle everything as we should, why rc = 1 ?

rc == 1 is the internal representation of "we have to go back into g2".
rc == 0, in contrast, means "we can go back into g2 (via a NULL
intercept) or continue executing g3". Returning rc == 1 instead of rc ==
0 at this point is just consistency.

--
Thanks,

David / dhildenb

2020-04-06 13:26:50

by Christian Borntraeger

[permalink] [raw]
Subject: Re: [PATCH v1 2/5] KVM: s390: vsie: Fix delivery of addressing exceptions



On 06.04.20 15:22, David Hildenbrand wrote:
> On 06.04.20 15:17, Christian Borntraeger wrote:
>>
>>
>> On 02.04.20 20:48, David Hildenbrand wrote:
>>> Whenever we get an -EFAULT, we failed to read in guest 2 physical
>>> address space. Such addressing exceptions are reported via a program
>>> intercept to the nested hypervisor.
>>>
>>> We faked the intercept, we have to return to guest 2. Instead, right
>>> now we would be returning -EFAULT from the intercept handler, eventually
>>> crashing the VM.
>>>
>>> Addressing exceptions can only happen if the g2->g3 page tables
>>> reference invalid g2 addresses (say, either a table or the final page is
>>> not accessible - so something that basically never happens in sane
>>> environments.
>>>
>>> Identified by manual code inspection.
>>>
>>> Fixes: a3508fbe9dc6 ("KVM: s390: vsie: initial support for nested virtualization")
>>> Cc: <[email protected]> # v4.8+
>>> Signed-off-by: David Hildenbrand <[email protected]>
>>> ---
>>> arch/s390/kvm/vsie.c | 1 +
>>> 1 file changed, 1 insertion(+)
>>>
>>> diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c
>>> index 076090f9e666..4f6c22d72072 100644
>>> --- a/arch/s390/kvm/vsie.c
>>> +++ b/arch/s390/kvm/vsie.c
>>> @@ -1202,6 +1202,7 @@ static int vsie_run(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
>>> scb_s->iprcc = PGM_ADDRESSING;
>>> scb_s->pgmilc = 4;
>>> scb_s->gpsw.addr = __rewind_psw(scb_s->gpsw, 4);
>>> + rc = 1;
>>
>>
>> kvm_s390_handle_vsie has
>>
>> return rc < 0 ? rc : 0;
>>
>>
>> so rc = 0 would result in the same behaviour, correct?
>
> yes
>
>> Since we DO handle everything as we should, why rc = 1 ?
>
> rc == 1 is the internal representation of "we have to go back into g2".
> rc == 0, in contrast, means "we can go back into g2 (via a NULL
> intercept) or continue executing g3". Returning rc == 1 instead of rc ==
> 0 at this point is just consistency.

Ok, I will add something to the patch description.
Reviewed-by: Christian Borntraeger <[email protected]>