KVM: s390: Add support for protected VMs
Subsystems (11)
v2 cover KVM: s390: Add support for protected VMs
mm people: This series contains a "pretty small" common code memory management change that will allow paging, guest backing with files etc almost just like normal VMs. It should be a no-op for all architectures not opting in. And it should be usable for others that also try to get notified on "the pages are in the process of being used for things like I/O". At the end of the series are two sample patches as these hooks seem to be useful for other with error handling/call information. I would suggest to keep the patch as is and add the additional things when intel/arm know exactly what they need.
mm-related patches CCed on linux-mm, the complete list can be found on the KVM and linux-s390 list.
Andrew, any chance to either take " mm:gup/writeback: add callbacks for inaccessible pages" or ACK so that I can take it?
Overview
--------
Protected VMs (PVM) are KVM VMs, where KVM can't access the VM's state like guest memory and guest registers anymore. Instead the PVMs are mostly managed by a new entity called Ultravisor (UV), which provides an API, so KVM and the PV can request management actions.
PVMs are encrypted at rest and protected from hypervisor access while running. They switch from a normal operation into protected mode, so we can still use the standard boot process to load a encrypted blob and then move it into protected mode.
Rebooting is only possible by passing through the unprotected/normal mode and switching to protected again.
All patches are in the protvirtv4 branch of the korg s390 kvm git
https://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git/log/?h=protvirtv4
Claudio presented the technology at his presentation at KVM Forum 2019.
https://static.sched.com/hosted_files/kvmforum2019/3b/ibm_protected_vms_s390x.pdf
v-> v2
- rebase on top of kvm/master
- pipe through rc and rrc. This might have created some churn here and there
- turn off sclp masking when rebooting into "unsecure"
- memory management simplification
- prefix page handling now via intercept 112
- io interrupt intervention request fix (do not use GISA)
- api.txt conversion to rst
- sample patches on top of mm/gup/writeback
- tons of review feedback
- kvm_uv debug feature fixes and unifications
- ultravisor information for /sys/firmware
-
RFCv2 -> v1 (you can diff the protvirtv2 and the protvirtv3 branch)
- tons of review feedback integrated (see mail thread)
- memory management now complete and working
- Documentation patches merged
- interrupt patches merged
- CONFIG_KVM_S390_PROTECTED_VIRTUALIZATION_HOST removed
- SIDA interface integrated into memop
- for merged patches I removed reviews that were not in all patches
Christian Borntraeger (5):
KVM: s390/mm: Make pages accessible before destroying the guest
KVM: s390: protvirt: Add SCLP interrupt handling
KVM: s390: protvirt: do not inject interrupts after start s390/uv: Fix handling of length extensions (already in s390 tree)
KVM: s390: rstify new ioctls in api.rst
Claudio Imbrenda (6):
mm:gup/writeback: add callbacks for inaccessible pages s390/mm: provide memory management functions for protected KVM guests
KVM: s390/mm: handle guest unpin events
example for future extension: mm:gup/writeback: add callbacks for
inaccessible pages: error cases
example for future extension: mm:gup/writeback: add callbacks for
inaccessible pages: source indication
potential fixup for "s390/mm: provide memory management functions for
protected KVM guests"
Janosch Frank (25):
KVM: s390: protvirt: Add UV debug trace
KVM: s390: add new variants of UV CALL
KVM: s390: protvirt: Add initial vm and cpu lifecycle handling
KVM: s390: protvirt: Add KVM api documentation
KVM: s390: protvirt: Secure memory is not mergeable
KVM: s390: protvirt: Handle SE notification interceptions
KVM: s390: protvirt: Instruction emulation
KVM: s390: protvirt: Handle spec exception loops
KVM: s390: protvirt: Add new gprs location handling
KVM: S390: protvirt: Introduce instruction data area bounce buffer
KVM: s390: protvirt: handle secure guest prefix pages
KVM: s390: protvirt: Write sthyi data to instruction data area
KVM: s390: protvirt: STSI handling
KVM: s390: protvirt: disallow one_reg
KVM: s390: protvirt: Do only reset registers that are accessible
KVM: s390: protvirt: Only sync fmt4 registers
KVM: s390: protvirt: Add program exception injection
KVM: s390: protvirt: Add diag 308 subcode 8 - 10 handling
KVM: s390: protvirt: UV calls in support of diag308 0, 1
KVM: s390: protvirt: Report CPU state to Ultravisor
KVM: s390: protvirt: Support cmd 5 operation state
KVM: s390: protvirt: Mask PSW interrupt bits for interception 104 and
112
KVM: s390: protvirt: Add UV cpu reset calls
DOCUMENTATION: Protected virtual machine introduction and IPL
s390: protvirt: Add sysfs firmware interface for Ultravisor
information
Michael Mueller (2):
KVM: s390: protvirt: Add interruption injection controls
KVM: s390: protvirt: Implement interruption injection
Ulrich Weigand (1):
KVM: s390/interrupt: do not pin adapter interrupt pages
Vasily Gorbik (3):
s390/protvirt: introduce host side setup s390/protvirt: add ultravisor initialization s390/mm: add (non)secure page access exceptions handlers
.../admin-guide/kernel-parameters.txt | 5 + Documentation/virt/kvm/api.rst | 108 +++- Documentation/virt/kvm/devices/s390_flic.rst | 11 +- Documentation/virt/kvm/index.rst | 2 + Documentation/virt/kvm/s390-pv-boot.rst | 83 +++ Documentation/virt/kvm/s390-pv.rst | 116 +++++ MAINTAINERS | 1 + arch/s390/boot/Makefile | 2 +- arch/s390/boot/uv.c | 23 +- arch/s390/include/asm/gmap.h | 6 + arch/s390/include/asm/kvm_host.h | 113 ++++- arch/s390/include/asm/mmu.h | 2 + arch/s390/include/asm/mmu_context.h | 1 + arch/s390/include/asm/page.h | 5 + arch/s390/include/asm/pgtable.h | 35 +- arch/s390/include/asm/uv.h | 251 ++++++++- arch/s390/kernel/Makefile | 1 + arch/s390/kernel/pgm_check.S | 4 +- arch/s390/kernel/setup.c | 9 +- arch/s390/kernel/uv.c | 412 +++++++++++++++ arch/s390/kvm/Makefile | 2 +- arch/s390/kvm/intercept.c | 111 +++- arch/s390/kvm/interrupt.c | 391 ++++++++------ arch/s390/kvm/kvm-s390.c | 479 ++++++++++++++++-- arch/s390/kvm/kvm-s390.h | 40 ++ arch/s390/kvm/priv.c | 11 +- arch/s390/kvm/pv.c | 295 +++++++++++ arch/s390/mm/fault.c | 78 +++ arch/s390/mm/gmap.c | 65 ++- include/linux/gfp.h | 12 + include/uapi/linux/kvm.h | 44 +- mm/gup.c | 15 +- mm/page-writeback.c | 5 + 33 files changed, 2438 insertions(+), 300 deletions(-) create mode 100644 Documentation/virt/kvm/s390-pv-boot.rst create mode 100644 Documentation/virt/kvm/s390-pv.rst create mode 100644 arch/s390/kernel/uv.c create mode 100644 arch/s390/kvm/pv.c
Signature · 1 line
2.25.0
PATCH v2 1/42 mm:gup/writeback: add callbacks for inaccessible pages
From: Claudio Imbrenda <[email protected]>
With the introduction of protected KVM guests on s390 there is now a concept of inaccessible pages. These pages need to be made accessible before the host can access them.
While cpu accesses will trigger a fault that can be resolved, I/O accesses will just fail. We need to add a callback into architecture code for places that will do I/O, namely when writeback is started or when a page reference is taken.
This is not only to enable paging, file backing etc, it is also necessary to protect the host against a malicious user space. For example a bad QEMU could simply start direct I/O on such protected memory. We do not want userspace to be able to trigger I/O errors and thus we the logic is "whenever somebody accesses that page (gup) or doing I/O, make sure that this page can be accessed. When the guest tries to access that page we will wait in the page fault handler for writeback to have finished and for the page_ref to be the expected value.
If wanted by others, the callbacks can be extended with error handlin and a parameter from where this is called.
--- include/linux/gfp.h | 6 ++++++ mm/gup.c | 2 ++ mm/page-writeback.c | 1 + 3 files changed, 9 insertions(+)
include/linux/gfp.h +6 -0
@@ -485,6 +485,12 @@ static inline void arch_free_page(struct page *page, int order) { }#ifndef HAVE_ARCH_ALLOC_PAGE static inline void arch_alloc_page (struct page *page,int order) { }#endif +#ifndef HAVE_ARCH_MAKE_PAGE_ACCESSIBLE +static inline int arch_make_page_accessible (struct page *page) +{ +return 0 ; +} +#endif struct page * __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order, int preferred_nid,
mm/gup.c +2 -0
@@ -276,6 +276,7 @@ static struct page *follow_page_pte(struct vm_area_struct *vma, page =ERR_PTR (-ENOMEM ); goto out; } +arch_make_page_accessible (page); }if (flags &FOLL_TOUCH ) { if ((flags & FOLL_WRITE) &&
@@ -1919,6 +1920,7 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end,VM_BUG_ON_PAGE (compound_head (page) != head, page); +arch_make_page_accessible (page);SetPageReferenced (page); pages[*nr] = page; (*nr)++;
mm/page-writeback.c +1 -0
@@ -2807,6 +2807,7 @@ int __test_set_page_writeback(struct page *page, bool keep_write)inc_zone_page_state (page,NR_ZONE_WRITE_PENDING ); }unlock_page_memcg (page); +arch_make_page_accessible (page);return ret; }
Signature · 1 line
2.25.0
Re: [PATCH v2 01/42] mm:gup/writeback: add callbacks for inaccessible pages
Quoted 21 lines · Christian Borntraeger
From: Claudio Imbrenda <[email protected]>
With the introduction of protected KVM guests on s390 there is now a concept of inaccessible pages. These pages need to be made accessible before the host can access them.
While cpu accesses will trigger a fault that can be resolved, I/O accesses will just fail. We need to add a callback into architecture code for places that will do I/O, namely when writeback is started or when a page reference is taken.
This is not only to enable paging, file backing etc, it is also necessary to protect the host against a malicious user space. For example a bad QEMU could simply start direct I/O on such protected memory. We do not want userspace to be able to trigger I/O errors and thus we the logic is "whenever somebody accesses that page (gup) or doing I/O, make sure that this page can be accessed. When the guest tries to access that page we will wait in the page fault handler for writeback to have finished and for the
page_refto be the expected value.
Quoted 2 lines
If wanted by others, the callbacks can be extended with error handlin and a parameter from where this is called.
s/handlin/handling/
One last question from my side:
Why is it OK to ignore errors here. IOW, why not squash "[PATCH v2 39/42] example for future extension: mm:gup/writeback: add callbacks for inaccessible pages: error cases" into this patch.
I can see in patch "[PATCH v2 05/42] s390/mm: provide memory management functions for protected KVM guests", that the call can fail for various reasons. That puzzles me a bit - what would happen if any of that fails? Or will it actually never fail for s390x (and all that error handling in arch_make_page_accessible() is essentially dead code in real life?)
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v2 01/42] mm:gup/writeback: add callbacks for inaccessible pages
Quoted 22 lines · David Hildenbrand
Quoted 21 lines · Christian Borntraeger
From: Claudio Imbrenda <[email protected]>
With the introduction of protected KVM guests on s390 there is now a concept of inaccessible pages. These pages need to be made accessible before the host can access them.
While cpu accesses will trigger a fault that can be resolved, I/O accesses will just fail. We need to add a callback into architecture code for places that will do I/O, namely when writeback is started or when a page reference is taken.
This is not only to enable paging, file backing etc, it is also necessary to protect the host against a malicious user space. For example a bad QEMU could simply start direct I/O on such protected memory. We do not want userspace to be able to trigger I/O errors and thus we the logic is "whenever somebody accesses that page (gup) or doing I/O, make sure that this page can be accessed. When the guest tries to access that page we will wait in the page fault handler for writeback to have finished and for the
page_refto be the expected value.
Quoted 4 lines
Quoted 2 lines
If wanted by others, the callbacks can be extended with error handlin and a parameter from where this is called.
s/handlin/handling/
ack.
Quoted 6 lines
One last question from my side:
Why is it OK to ignore errors here. IOW, why not squash "[PATCH v2 39/42] example for future extension: mm:gup/writeback: add callbacks for inaccessible pages: error cases" into this patch.
I can certainly squash this in. But I have never heard feedback from the memory management people if they would prefer the patch as-is (no overhead at all for !s390) or already with the error handling.
Quoted 4 lines
I can see in patch "[PATCH v2 05/42] s390/mm: provide memory management functions for protected KVM guests", that the call can fail for various reasons. That puzzles me a bit - what would happen if any of that fails?
The convert _to_ secure has error handling. uv_convert_from_secure (the one that is used for arch_make_page_accessible can only fail if we mess up, e.g. an "export" on memory that we have donated to the ultravisor.
Quoted 2 lines
Or will it actually never fail for s390x (and all that error handling in
arch_make_page_accessible()is essentially dead code in real life?)
So yes, if everything is setup properly this should not fail in real life and only we have a kernel (or firmware) bug.
Re: [PATCH v2 01/42] mm:gup/writeback: add callbacks for inaccessible pages
Quoted 42 lines · Christian Borntraeger
Quoted 22 lines · David Hildenbrand
Quoted 21 lines · Christian Borntraeger
From: Claudio Imbrenda <[email protected]>
With the introduction of protected KVM guests on s390 there is now a concept of inaccessible pages. These pages need to be made accessible before the host can access them.
While cpu accesses will trigger a fault that can be resolved, I/O accesses will just fail. We need to add a callback into architecture code for places that will do I/O, namely when writeback is started or when a page reference is taken.
This is not only to enable paging, file backing etc, it is also necessary to protect the host against a malicious user space. For example a bad QEMU could simply start direct I/O on such protected memory. We do not want userspace to be able to trigger I/O errors and thus we the logic is "whenever somebody accesses that page (gup) or doing I/O, make sure that this page can be accessed. When the guest tries to access that page we will wait in the page fault handler for writeback to have finished and for the
page_refto be the expected value.Quoted 4 lines
Quoted 2 lines
If wanted by others, the callbacks can be extended with error handlin and a parameter from where this is called.
s/handlin/handling/
ack.
Quoted 6 lines
One last question from my side:
Why is it OK to ignore errors here. IOW, why not squash "[PATCH v2 39/42] example for future extension: mm:gup/writeback: add callbacks for inaccessible pages: error cases" into this patch.
I can certainly squash this in. But I have never heard feedback from the memory management people if they would prefer the patch as-is (no overhead at all for !s390) or already with the error handling.
Quoted 1 line
Quoted 7 lines
Quoted 3 lines
I can see in patch "[PATCH v2 05/42] s390/mm: provide memory management functions for protected KVM guests", that the call can fail for various reasons. That puzzles me a bit - what would happen if any of that fails?
The convert _to_ secure has error handling.
uv_convert_from_secure(the one that is used forarch_make_page_accessiblecan only fail if we mess up, e.g. an "export" on memory that we have donated to the ultravisor.
Okay, so more like a BUG_ON() in case it really fails.
Quoted 8 lines
Quoted 4 lines
Or will it actually never fail for s390x (and all that error handling in
arch_make_page_accessible()is essentially dead code in real life?)So yes, if everything is setup properly this should not fail in real life and only we have a kernel (or firmware) bug.
Then, without feedback from other possible users, this should be a void function. So either introduce error handling or convert it to a void for now (and add e.g., BUG_ON and a comment inside the s390x implementation).
As discussed in the other patch, I'd prefer a CONFIG_HAVE_ARCH_MAKE_PAGE_ACCESSIBLE and handle it via kconfig, but not sure what other people here prefer.
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v2 01/42] mm:gup/writeback: add callbacks for inaccessible pages
Quoted 8 lines · David Hildenbrand
Quoted 3 lines · Christian Borntraeger
So yes, if everything is setup properly this should not fail in real life and only we have a kernel (or firmware) bug.
Then, without feedback from other possible users, this should be a void function. So either introduce error handling or convert it to a void for now (and add e.g.,
BUG_ONand a comment inside the s390x implementation).
My preference would also be for a void function (versus ignoring an int return).
Re: [PATCH v2 01/42] mm:gup/writeback: add callbacks for inaccessible pages
Quoted 6 lines · Sean Christopherson
Quoted 5 lines · David Hildenbrand
Quoted 3 lines · Christian Borntraeger
So yes, if everything is setup properly this should not fail in real life and only we have a kernel (or firmware) bug.
Quoted 6 lines
Quoted 3 lines
Then, without feedback from other possible users, this should be a void function. So either introduce error handling or convert it to a void for now (and add e.g.,
BUG_ONand a comment inside the s390x implementation).My preference would also be for a void function (versus ignoring an int return).
The gup code could certainly handle the error value, although the writeback is a lot less clear (so a BUG_ON() would seem to be sufficient for now).
Will
Re: [PATCH v2 01/42] mm:gup/writeback: add callbacks for inaccessible pages
Quoted 11 lines · Will Deacon
Quoted 10 lines · Sean Christopherson
Quoted 8 lines · David Hildenbrand
Quoted 3 lines · Christian Borntraeger
So yes, if everything is setup properly this should not fail in real life and only we have a kernel (or firmware) bug.
Then, without feedback from other possible users, this should be a void function. So either introduce error handling or convert it to a void for now (and add e.g.,
BUG_ONand a comment inside the s390x implementation).
Quoted 5 lines
Quoted 2 lines
My preference would also be for a void function (versus ignoring an int return).
The gup code could certainly handle the error value, although the writeback is a lot less clear (so a
BUG_ON()would seem to be sufficient for now).
Sean, David. Can we agree on merging patch 39?
Re: [PATCH v2 01/42] mm:gup/writeback: add callbacks for inaccessible pages
Quoted 14 lines · Christian Borntraeger
Quoted 11 lines · Will Deacon
Quoted 10 lines · Sean Christopherson
Quoted 8 lines · David Hildenbrand
Quoted 3 lines · Christian Borntraeger
So yes, if everything is setup properly this should not fail in real life and only we have a kernel (or firmware) bug.
Then, without feedback from other possible users, this should be a void function. So either introduce error handling or convert it to a void for now (and add e.g.,
BUG_ONand a comment inside the s390x implementation).
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
My preference would also be for a void function (versus ignoring an int return).
The gup code could certainly handle the error value, although the writeback is a lot less clear (so a
BUG_ON()would seem to be sufficient for now).Sean, David. Can we agree on merging patch 39?
I'm a-ok with adding error checking, ignoring the return value is the only option I don't like :-)
Re: [PATCH v2 01/42] mm:gup/writeback: add callbacks for inaccessible pages
Quoted 18 lines · Sean Christopherson
Quoted 17 lines · Christian Borntraeger
Quoted 14 lines · Will Deacon
Quoted 12 lines · Sean Christopherson
Quoted 8 lines · David Hildenbrand
Quoted 3 lines · Christian Borntraeger
So yes, if everything is setup properly this should not fail in real life and only we have a kernel (or firmware) bug.
Then, without feedback from other possible users, this should be a void function. So either introduce error handling or convert it to a void for now (and add e.g.,
BUG_ONand a comment inside the s390x implementation).My preference would also be for a void function (versus ignoring an int return).
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
The gup code could certainly handle the error value, although the writeback is a lot less clear (so a
BUG_ON()would seem to be sufficient for now).Sean, David. Can we agree on merging patch 39?
I'm a-ok with adding error checking, ignoring the return value is the only option I don't like :-)
Same over here :)
Signature · 3 lines
Thanks, David / dhildenb
PATCH v2 2/42 KVM: s390/interrupt: do not pin adapter interrupt pages
In reply to Christian BorntraegerFrom: Ulrich Weigand <[email protected]>
The adapter interrupt page containing the indicator bits is currently pinned. That means that a guest with many devices can pin a lot of memory pages in the host. This also complicates the reference tracking which is needed for memory management handling of protected virtual machines. It might also have some strange side effects for madvise MADV_DONTNEED and other things.
We can simply try to get the userspace page set the bits and free the page. By storing the userspace address in the irq routing entry instead of the guest address we can actually avoid many lookups and list walks so that this variant is very likely not slower.
If userspace messes around with the memory slots the worst thing that can happen is that we write to some other memory within that process. As we get the the page with FOLL_WRITE this can also not be used to write to shared read-only pages.
--- Documentation/virt/kvm/devices/s390_flic.rst | 11 +- arch/s390/include/asm/kvm_host.h | 3 - arch/s390/kvm/interrupt.c | 170 ++++++------------- 3 files changed, 53 insertions(+), 131 deletions(-)
Documentation/virt/kvm/devices/s390_flic.rst +2 -9
@@ -108,16 +108,9 @@ Groups: mask or unmask the adapter, as specified in mask KVM_S390_IO_ADAPTER_MAP - perform a gmap translation for the guest address provided in addr, - pin a userspace page for the translated address and add it to the - list of mappings - - .. note:: A new mapping will be created unconditionally; therefore, - the calling code should avoid making duplicate mappings. - + This is now a no-op. The mapping is purely done by the irq route. KVM_S390_IO_ADAPTER_UNMAP - release a userspace page for the translated address specified in addr - from the list of mappings + This is now a no-op. The mapping is purely done by the irq route. KVM_DEV_FLIC_AISM modify the adapter-interruption-suppression mode for a given isc if the
arch/s390/include/asm/kvm_host.h +0 -3
@@ -701,9 +701,6 @@ struct s390_io_adapter {bool masked;bool swap;bool suppressible; -struct rw_semaphore maps_lock; -struct list_head maps; -atomic_t nr_maps; };#define MAX_S390_IO_ADAPTERS ((MAX_ISC + 1) * 8)
arch/s390/kvm/interrupt.c +51 -119
240 lines not on this page · raw message
Signature · 1 line
2.25.0
Re: [PATCH v2 02/42] KVM: s390/interrupt: do not pin adapter interrupt pages
Quoted 39 lines · Christian Borntraeger
From: Ulrich Weigand <[email protected]>
The adapter interrupt page containing the indicator bits is currently pinned. That means that a guest with many devices can pin a lot of memory pages in the host. This also complicates the reference tracking which is needed for memory management handling of protected virtual machines. It might also have some strange side effects for madvise
MADV_DONTNEEDand other things.We can simply try to get the userspace page set the bits and free the page. By storing the userspace address in the irq routing entry instead of the guest address we can actually avoid many lookups and list walks so that this variant is very likely not slower.
If userspace messes around with the memory slots the worst thing that can happen is that we write to some other memory within that process. As we get the the page with
FOLL_WRITEthis can also not be used to write to shared read-only pages.Signed-off-by Ulrich Weigand <[email protected]>[[email protected]: patch simplification]Signed-off-by Christian Borntraeger <[email protected]>--- Documentation/virt/kvm/devices/s390_flic.rst | 11 +- arch/s390/include/asm/kvm_host.h | 3 - arch/s390/kvm/interrupt.c | 170 ++++++------------- 3 files changed, 53 insertions(+), 131 deletions(-)Documentation/virt/kvm/devices/s390_flic.rst +0
-3@@ -108,16 +108,9 @@ Groups: mask or unmask the adapter, as specified in mask KVM_S390_IO_ADAPTER_MAP - perform a gmap translation for the guest address provided in addr, - pin a userspace page for the translated address and add it to the - list of mappings
Documentation/virt/kvm/devices/s390_flic.rst Groups: · line 114
Quoted 10 lines
Documentation/virt/kvm/devices/s390_flic.rst +2
-6- - .. note:: A new mapping will be created unconditionally; therefore, - the calling code should avoid making duplicate mappings. - + This is now a no-op. The mapping is purely done by the irq route. KVM_S390_IO_ADAPTER_UNMAP - release a userspace page for the translated address specified in addr - from the list of mappings + This is now a no-op. The mapping is purely done by the irq route.
The interface should have accepted a hva from the very start and not guest addresses ...
[...]
Documentation/virt/kvm/devices/s390_flic.rst static int modify_io_adapter(struct kvm_device *dev, · line 2383
Quoted 9 lines
Documentation/virt/kvm/devices/s390_flic.rst +3
-0static int modify_io_adapter(struct kvm_device *dev,@@ -2456,12 +2378,13 @@ static int modify_io_adapter(struct kvm_device *dev, if (ret > 0) ret = 0; break; + /* + * We resolve the gpa to hva when setting the IRQ routing. the set_irq + * code uses get_user_pages_remote to do the actual write.
nit: "get_user_pages_remote()"
Quoted 16 lines
Documentation/virt/kvm/devices/s390_flic.rst +2
-5+ */ case KVM_S390_IO_ADAPTER_MAP: - ret = kvm_s390_adapter_map(dev->kvm, req.id, req.addr); - break; case KVM_S390_IO_ADAPTER_UNMAP: - ret = kvm_s390_adapter_unmap(dev->kvm, req.id, req.addr); - break; + return 0; default: ret = -EINVAL; }@@ -2699,19 +2622,21 @@ static unsigned long get_ind_bit(__u64 addr, unsigned long bit_nr, bool swap) return swap ? (bit ^ (BITS_PER_LONG - 1)) : bit; } -static struct s390_map_info *get_map_info(struct s390_io_adapter *adapter,
Documentation/virt/kvm/devices/s390_flic.rst static unsigned long get_ind_bit(__u64 addr, unsigned long bit_nr, bool swap) · line 2632
Quoted 10 lines
Documentation/virt/kvm/devices/s390_flic.rst +4
-2- u64 addr) +static struct page *get_map_page(struct kvm *kvm, + struct s390_io_adapter *adapter, + u64 uaddr) { - struct s390_map_info *map; + struct page *page = NULL; if (!adapter) return NULL;
AFAIKs, this check is not necessary.
Documentation/virt/kvm/devices/s390_flic.rst static unsigned long get_ind_bit(__u64 addr, unsigned long bit_nr, bool swap) · line 2634
Quoted 8 lines
Documentation/virt/kvm/devices/s390_flic.rst +2
-6- - list_for_each_entry(map, &adapter->maps, list) { - if (map->guest_addr == addr) - return map; - } - return NULL; + if (!uaddr) + return NULL;
I do wonder if that check is necessary. I don't think so but might be missing something.
Quoted 81 lines
Documentation/virt/kvm/devices/s390_flic.rst +29
-20+ down_read(&kvm->mm->mmap_sem); + get_user_pages_remote(NULL, kvm->mm, uaddr, 1, FOLL_WRITE, + &page, NULL, NULL); + up_read(&kvm->mm->mmap_sem); + return page; } static int adapter_indicators_set(struct kvm *kvm,@@ -2720,30 +2645,35 @@ static int adapter_indicators_set(struct kvm *kvm, { unsigned long bit; int summary_set, idx; - struct s390_map_info *info; + struct page *ind_page, *summary_page; void *map; - info = get_map_info(adapter, adapter_int->ind_addr); - if (!info) + ind_page = get_map_page(kvm, adapter, adapter_int->ind_addr); + if (!ind_page) return -1; - map = page_address(info->page); - bit = get_ind_bit(info->addr, adapter_int->ind_offset, adapter->swap); - set_bit(bit, map); - idx = srcu_read_lock(&kvm->srcu); - mark_page_dirty(kvm, info->guest_addr >> PAGE_SHIFT); - set_page_dirty_lock(info->page); - info = get_map_info(adapter, adapter_int->summary_addr); - if (!info) { - srcu_read_unlock(&kvm->srcu, idx); + summary_page = get_map_page(kvm, adapter, adapter_int->summary_addr); + if (!summary_page) { + put_page(ind_page); return -1; } - map = page_address(info->page); - bit = get_ind_bit(info->addr, adapter_int->summary_offset, - adapter->swap); + + idx = srcu_read_lock(&kvm->srcu); + map = page_address(ind_page); + bit = get_ind_bit(adapter_int->ind_addr, + adapter_int->ind_offset, adapter->swap); + set_bit(bit, map); + mark_page_dirty(kvm, adapter_int->ind_addr >> PAGE_SHIFT); + set_page_dirty_lock(ind_page); + map = page_address(summary_page); + bit = get_ind_bit(adapter_int->summary_addr, + adapter_int->summary_offset, adapter->swap); summary_set = test_and_set_bit(bit, map); - mark_page_dirty(kvm, info->guest_addr >> PAGE_SHIFT); - set_page_dirty_lock(info->page); + mark_page_dirty(kvm, adapter_int->summary_addr >> PAGE_SHIFT); + set_page_dirty_lock(summary_page); srcu_read_unlock(&kvm->srcu, idx); + + put_page(ind_page); + put_page(summary_page); return summary_set ? 0 : 1; }@@ -2765,9 +2695,7 @@ static int set_adapter_int(struct kvm_kernel_irq_routing_entry *e, adapter = get_io_adapter(kvm, e->adapter.adapter_id); if (!adapter) return -1; - down_read(&adapter->maps_lock); ret = adapter_indicators_set(kvm, adapter, &e->adapter); - up_read(&adapter->maps_lock); if ((ret > 0) && !adapter->masked) { ret = kvm_s390_inject_airq(kvm, adapter); if (ret == 0)@@ -2818,23 +2746,27 @@ int kvm_set_routing_entry(struct kvm *kvm, struct kvm_kernel_irq_routing_entry *e, const struct kvm_irq_routing_entry *ue) { - int ret; + u64 uaddr; switch (ue->type) { + /* we store the userspace addresses instead of the guest addresses */ case KVM_IRQ_ROUTING_S390_ADAPTER:
Documentation/virt/kvm/devices/s390_flic.rst int kvm_set_routing_entry(struct kvm *kvm, · line 2761
Quoted 10 lines
Documentation/virt/kvm/devices/s390_flic.rst +7
-2e->set = set_adapter_int; - e->adapter.summary_addr = ue->u.adapter.summary_addr; - e->adapter.ind_addr = ue->u.adapter.ind_addr; + uaddr = gmap_translate(kvm->arch.gmap, ue->u.adapter.summary_addr); + if (uaddr == -EFAULT) + return -EFAULT; + e->adapter.summary_addr = uaddr; + uaddr = gmap_translate(kvm->arch.gmap, ue->u.adapter.ind_addr); + if (uaddr == -EFAULT) + return -EFAULT;
AFAIK, leaving e->adapter.summary_addr set is not an issue.
Interesting, in kvm_s390_adapter_map(), we didn't synchronize again slot updates when doing the gmap_translate(), which looks wrong to me ...
It seems to be the same thing here. I do wonder if it is safe to do a gmap_translate() here, looks like this can race with kvm_arch_commit_memory_region().
I would have assumed we need e.g., the slots_lock while doing the gmap_translate() - or a srcu_read_lock(&vcpu->kvm->srcu) or similar ...
Apart from that, looks good to me.
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v2 02/42] KVM: s390/interrupt: do not pin adapter interrupt pages
Quoted 210 lines · David Hildenbrand
Quoted 39 lines · Christian Borntraeger
From: Ulrich Weigand <[email protected]>
The adapter interrupt page containing the indicator bits is currently pinned. That means that a guest with many devices can pin a lot of memory pages in the host. This also complicates the reference tracking which is needed for memory management handling of protected virtual machines. It might also have some strange side effects for madvise
MADV_DONTNEEDand other things.We can simply try to get the userspace page set the bits and free the page. By storing the userspace address in the irq routing entry instead of the guest address we can actually avoid many lookups and list walks so that this variant is very likely not slower.
If userspace messes around with the memory slots the worst thing that can happen is that we write to some other memory within that process. As we get the the page with
FOLL_WRITEthis can also not be used to write to shared read-only pages.Signed-off-by Ulrich Weigand <[email protected]>[[email protected]: patch simplification]Signed-off-by Christian Borntraeger <[email protected]>--- Documentation/virt/kvm/devices/s390_flic.rst | 11 +- arch/s390/include/asm/kvm_host.h | 3 - arch/s390/kvm/interrupt.c | 170 ++++++------------- 3 files changed, 53 insertions(+), 131 deletions(-)Documentation/virt/kvm/devices/s390_flic.rst +0
-3@@ -108,16 +108,9 @@ Groups: mask or unmask the adapter, as specified in mask KVM_S390_IO_ADAPTER_MAP - perform a gmap translation for the guest address provided in addr, - pin a userspace page for the translated address and add it to the - list of mappingsDocumentation/virt/kvm/devices/s390_flic.rst Groups: · line 114
Quoted 10 lines
Documentation/virt/kvm/devices/s390_flic.rst +2
-6- - .. note:: A new mapping will be created unconditionally; therefore, - the calling code should avoid making duplicate mappings. - + This is now a no-op. The mapping is purely done by the irq route. KVM_S390_IO_ADAPTER_UNMAP - release a userspace page for the translated address specified in addr - from the list of mappings + This is now a no-op. The mapping is purely done by the irq route.The interface should have accepted a hva from the very start and not guest addresses ...
[...]
Documentation/virt/kvm/devices/s390_flic.rst static int modify_io_adapter(struct kvm_device *dev, · line 2383
Quoted 9 lines
Documentation/virt/kvm/devices/s390_flic.rst +3
-0static int modify_io_adapter(struct kvm_device *dev,@@ -2456,12 +2378,13 @@ static int modify_io_adapter(struct kvm_device *dev, if (ret > 0) ret = 0; break; + /* + * We resolve the gpa to hva when setting the IRQ routing. the set_irq + * code uses get_user_pages_remote to do the actual write.nit: "
get_user_pages_remote()"Quoted 16 lines
Documentation/virt/kvm/devices/s390_flic.rst +2
-5+ */ case KVM_S390_IO_ADAPTER_MAP: - ret = kvm_s390_adapter_map(dev->kvm, req.id, req.addr); - break; case KVM_S390_IO_ADAPTER_UNMAP: - ret = kvm_s390_adapter_unmap(dev->kvm, req.id, req.addr); - break; + return 0; default: ret = -EINVAL; }@@ -2699,19 +2622,21 @@ static unsigned long get_ind_bit(__u64 addr, unsigned long bit_nr, bool swap) return swap ? (bit ^ (BITS_PER_LONG - 1)) : bit; } -static struct s390_map_info *get_map_info(struct s390_io_adapter *adapter,Documentation/virt/kvm/devices/s390_flic.rst static unsigned long get_ind_bit(__u64 addr, unsigned long bit_nr, bool swap) · line 2632
Quoted 10 lines
Documentation/virt/kvm/devices/s390_flic.rst +4
-2- u64 addr) +static struct page *get_map_page(struct kvm *kvm, + struct s390_io_adapter *adapter, + u64 uaddr) { - struct s390_map_info *map; + struct page *page = NULL; if (!adapter) return NULL;AFAIKs, this check is not necessary.
Documentation/virt/kvm/devices/s390_flic.rst static unsigned long get_ind_bit(__u64 addr, unsigned long bit_nr, bool swap) · line 2634
Quoted 8 lines
Documentation/virt/kvm/devices/s390_flic.rst +2
-6- - list_for_each_entry(map, &adapter->maps, list) { - if (map->guest_addr == addr) - return map; - } - return NULL; + if (!uaddr) + return NULL;I do wonder if that check is necessary. I don't think so but might be missing something.
Quoted 81 lines
Documentation/virt/kvm/devices/s390_flic.rst +29
-20+ down_read(&kvm->mm->mmap_sem); + get_user_pages_remote(NULL, kvm->mm, uaddr, 1, FOLL_WRITE, + &page, NULL, NULL); + up_read(&kvm->mm->mmap_sem); + return page; } static int adapter_indicators_set(struct kvm *kvm,@@ -2720,30 +2645,35 @@ static int adapter_indicators_set(struct kvm *kvm, { unsigned long bit; int summary_set, idx; - struct s390_map_info *info; + struct page *ind_page, *summary_page; void *map; - info = get_map_info(adapter, adapter_int->ind_addr); - if (!info) + ind_page = get_map_page(kvm, adapter, adapter_int->ind_addr); + if (!ind_page) return -1; - map = page_address(info->page); - bit = get_ind_bit(info->addr, adapter_int->ind_offset, adapter->swap); - set_bit(bit, map); - idx = srcu_read_lock(&kvm->srcu); - mark_page_dirty(kvm, info->guest_addr >> PAGE_SHIFT); - set_page_dirty_lock(info->page); - info = get_map_info(adapter, adapter_int->summary_addr); - if (!info) { - srcu_read_unlock(&kvm->srcu, idx); + summary_page = get_map_page(kvm, adapter, adapter_int->summary_addr); + if (!summary_page) { + put_page(ind_page); return -1; } - map = page_address(info->page); - bit = get_ind_bit(info->addr, adapter_int->summary_offset, - adapter->swap); + + idx = srcu_read_lock(&kvm->srcu); + map = page_address(ind_page); + bit = get_ind_bit(adapter_int->ind_addr, + adapter_int->ind_offset, adapter->swap); + set_bit(bit, map); + mark_page_dirty(kvm, adapter_int->ind_addr >> PAGE_SHIFT); + set_page_dirty_lock(ind_page); + map = page_address(summary_page); + bit = get_ind_bit(adapter_int->summary_addr, + adapter_int->summary_offset, adapter->swap); summary_set = test_and_set_bit(bit, map); - mark_page_dirty(kvm, info->guest_addr >> PAGE_SHIFT); - set_page_dirty_lock(info->page); + mark_page_dirty(kvm, adapter_int->summary_addr >> PAGE_SHIFT); + set_page_dirty_lock(summary_page); srcu_read_unlock(&kvm->srcu, idx); + + put_page(ind_page); + put_page(summary_page); return summary_set ? 0 : 1; }@@ -2765,9 +2695,7 @@ static int set_adapter_int(struct kvm_kernel_irq_routing_entry *e, adapter = get_io_adapter(kvm, e->adapter.adapter_id); if (!adapter) return -1; - down_read(&adapter->maps_lock); ret = adapter_indicators_set(kvm, adapter, &e->adapter); - up_read(&adapter->maps_lock); if ((ret > 0) && !adapter->masked) { ret = kvm_s390_inject_airq(kvm, adapter); if (ret == 0)@@ -2818,23 +2746,27 @@ int kvm_set_routing_entry(struct kvm *kvm, struct kvm_kernel_irq_routing_entry *e, const struct kvm_irq_routing_entry *ue) { - int ret; + u64 uaddr; switch (ue->type) { + /* we store the userspace addresses instead of the guest addresses */ case KVM_IRQ_ROUTING_S390_ADAPTER:Documentation/virt/kvm/devices/s390_flic.rst int kvm_set_routing_entry(struct kvm *kvm, · line 2761
Quoted 10 lines
Documentation/virt/kvm/devices/s390_flic.rst +7
-2e->set = set_adapter_int; - e->adapter.summary_addr = ue->u.adapter.summary_addr; - e->adapter.ind_addr = ue->u.adapter.ind_addr; + uaddr = gmap_translate(kvm->arch.gmap, ue->u.adapter.summary_addr); + if (uaddr == -EFAULT) + return -EFAULT; + e->adapter.summary_addr = uaddr; + uaddr = gmap_translate(kvm->arch.gmap, ue->u.adapter.ind_addr); + if (uaddr == -EFAULT) + return -EFAULT;AFAIK, leaving
e->adapter.summary_addrset is not an issue.Interesting, in
kvm_s390_adapter_map(), we didn't synchronize again slot updates when doing thegmap_translate(), which looks wrong to me ...It seems to be the same thing here. I do wonder if it is safe to do a
gmap_translate()here, looks like this can race withkvm_arch_commit_memory_region().
Quoted 6 lines
I would have assumed we need e.g., the
slots_lockwhile doing thegmap_translate()- or asrcu_read_lock(&vcpu->kvm->srcu)or similar ...Apart from that, looks good to me.
I think you missed this mail.
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v2 02/42] KVM: s390/interrupt: do not pin adapter interrupt pages
In reply to David HildenbrandQuoted 45 lines · David Hildenbrand
Quoted 44 lines · Christian Borntraeger
From: Ulrich Weigand <[email protected]>
The adapter interrupt page containing the indicator bits is currently pinned. That means that a guest with many devices can pin a lot of memory pages in the host. This also complicates the reference tracking which is needed for memory management handling of protected virtual machines. It might also have some strange side effects for madvise
MADV_DONTNEEDand other things.We can simply try to get the userspace page set the bits and free the page. By storing the userspace address in the irq routing entry instead of the guest address we can actually avoid many lookups and list walks so that this variant is very likely not slower.
If userspace messes around with the memory slots the worst thing that can happen is that we write to some other memory within that process. As we get the the page with
FOLL_WRITEthis can also not be used to write to shared read-only pages.Signed-off-by Ulrich Weigand <[email protected]>[[email protected]: patch simplification]Signed-off-by Christian Borntraeger <[email protected]>--- Documentation/virt/kvm/devices/s390_flic.rst | 11 +- arch/s390/include/asm/kvm_host.h | 3 - arch/s390/kvm/interrupt.c | 170 ++++++------------- 3 files changed, 53 insertions(+), 131 deletions(-)Documentation/virt/kvm/devices/s390_flic.rst +1
-7@@ -108,16 +108,9 @@ Groups: mask or unmask the adapter, as specified in mask KVM_S390_IO_ADAPTER_MAP - perform a gmap translation for the guest address provided in addr, - pin a userspace page for the translated address and add it to the - list of mappings - - .. note:: A new mapping will be created unconditionally; therefore, - the calling code should avoid making duplicate mappings. - + This is now a no-op. The mapping is purely done by the irq route.
Quoted 8 lines
Documentation/virt/kvm/devices/s390_flic.rst Groups: · line 114
Quoted 5 lines
Documentation/virt/kvm/devices/s390_flic.rst +1
-2KVM_S390_IO_ADAPTER_UNMAP - release a userspace page for the translated address specified in addr - from the list of mappings + This is now a no-op. The mapping is purely done by the irq route.The interface should have accepted a hva from the very start and not guest addresses ...
right, but that is history.
Quoted 8 lines
[...]
Documentation/virt/kvm/devices/s390_flic.rst
Quoted 3 lines
Documentation/virt/kvm/devices/s390_flic.rst +3
-0+ /* + * We resolve the gpa to hva when setting the IRQ routing. the set_irq + * code uses get_user_pages_remote to do the actual write.nit: "
get_user_pages_remote()"
ack.
Quoted 25 lines
Quoted 25 lines
Documentation/virt/kvm/devices/s390_flic.rst +6
-7+ */ case KVM_S390_IO_ADAPTER_MAP: - ret = kvm_s390_adapter_map(dev->kvm, req.id, req.addr); - break; case KVM_S390_IO_ADAPTER_UNMAP: - ret = kvm_s390_adapter_unmap(dev->kvm, req.id, req.addr); - break; + return 0; default: ret = -EINVAL; }@@ -2699,19 +2622,21 @@ static unsigned long get_ind_bit(__u64 addr, unsigned long bit_nr, bool swap) return swap ? (bit ^ (BITS_PER_LONG - 1)) : bit; } -static struct s390_map_info *get_map_info(struct s390_io_adapter *adapter, - u64 addr) +static struct page *get_map_page(struct kvm *kvm, + struct s390_io_adapter *adapter, + u64 uaddr) { - struct s390_map_info *map; + struct page *page = NULL;
Quoted 4 lines
Documentation/virt/kvm/devices/s390_flic.rst static unsigned long get_ind_bit(__u64 addr, unsigned long bit_nr, bool swap) · line 2632
Quoted 2 lines
Documentation/virt/kvm/devices/s390_flic.rst +0
-0if (!adapter) return NULL;AFAIKs, this check is not necessary.
Right otherwise we would crash earlier.
Quoted 12 lines
Documentation/virt/kvm/devices/s390_flic.rst static unsigned long get_ind_bit(__u64 addr, unsigned long bit_nr, bool swap) · line 2634
Quoted 9 lines
Documentation/virt/kvm/devices/s390_flic.rst +2
-6- - list_for_each_entry(map, &adapter->maps, list) { - if (map->guest_addr == addr) - return map; - } - return NULL; + if (!uaddr) + return NULL;I do wonder if that check is necessary. I don't think so but might be missing something.
Nothing should break when we remove this check. get_user_pages_remote will also return NULL (as newer kernels usually forbid mapping things at 0).
Will remove.
[...]
Quoted 26 lines
Quoted 10 lines
Documentation/virt/kvm/devices/s390_flic.rst +2
-1@@ -2818,23 +2746,27 @@ int kvm_set_routing_entry(struct kvm *kvm, struct kvm_kernel_irq_routing_entry *e, const struct kvm_irq_routing_entry *ue) { - int ret; + u64 uaddr; switch (ue->type) { + /* we store the userspace addresses instead of the guest addresses */ case KVM_IRQ_ROUTING_S390_ADAPTER:Documentation/virt/kvm/devices/s390_flic.rst int kvm_set_routing_entry(struct kvm *kvm, · line 2761
Quoted 10 lines
Documentation/virt/kvm/devices/s390_flic.rst +7
-2e->set = set_adapter_int; - e->adapter.summary_addr = ue->u.adapter.summary_addr; - e->adapter.ind_addr = ue->u.adapter.ind_addr; + uaddr = gmap_translate(kvm->arch.gmap, ue->u.adapter.summary_addr); + if (uaddr == -EFAULT) + return -EFAULT; + e->adapter.summary_addr = uaddr; + uaddr = gmap_translate(kvm->arch.gmap, ue->u.adapter.ind_addr); + if (uaddr == -EFAULT) + return -EFAULT;AFAIK, leaving
e->adapter.summary_addrset is not an issue.Interesting, in
kvm_s390_adapter_map(), we didn't synchronize again slot updates when doing thegmap_translate(), which looks wrong to me ...
Quoted 6 lines
It seems to be the same thing here. I do wonder if it is safe to do a
gmap_translate()here, looks like this can race withkvm_arch_commit_memory_region().I would have assumed we need e.g., the
slots_lockwhile doing thegmap_translate()- or asrcu_read_lock(&vcpu->kvm->srcu)or similar ...
gmap_translate does this via the gmap and it holds the mm sem. gmap_unmap_segment takes the same lock. So I think we are ok here.
Quoted 3 lines
Apart from that, looks good to me.
Re: [PATCH v2 02/42] KVM: s390/interrupt: do not pin adapter interrupt pages
Quoted 9 lines
Quoted 9 lines
AFAIK, leaving
e->adapter.summary_addrset is not an issue.Interesting, in
kvm_s390_adapter_map(), we didn't synchronize again slot updates when doing thegmap_translate(), which looks wrong to me ...It seems to be the same thing here. I do wonder if it is safe to do a
gmap_translate()here, looks like this can race withkvm_arch_commit_memory_region().
Quoted 5 lines
Quoted 2 lines
I would have assumed we need e.g., the
slots_lockwhile doing thegmap_translate()- or asrcu_read_lock(&vcpu->kvm->srcu)or similar ...
gmap_translatedoes this via the gmap and it holds the mm sem.gmap_unmap_segmenttakes the same lock. So I think we are ok here.
Ahh, I was looking at __gmap_translate(). Makes sense.
Signature · 3 lines
Thanks, David / dhildenb
PATCH v2 3/42 s390/protvirt: introduce host side setup
In reply to Christian BorntraegerFrom: Vasily Gorbik <[email protected]>
Add "prot_virt" command line option which controls if the kernel protected VMs support is enabled at early boot time. This has to be done early, because it needs large amounts of memory and will disable some features like STP time sync for the lpar.
Extend ultravisor info definitions and expose it via uv_info struct filled in during startup.
--- .../admin-guide/kernel-parameters.txt | 5 ++ arch/s390/boot/Makefile | 2 +- arch/s390/boot/uv.c | 21 +++++++- arch/s390/include/asm/uv.h | 45 +++++++++++++++- arch/s390/kernel/Makefile | 1 + arch/s390/kernel/setup.c | 4 -- arch/s390/kernel/uv.c | 52 +++++++++++++++++++ 7 files changed, 122 insertions(+), 8 deletions(-) create mode 100644 arch/s390/kernel/uv.c
Documentation/admin-guide/kernel-parameters.txt +5 -0
@@ -3795,6 +3795,11 @@ before loading. See Documentation/admin-guide/blockdev/ramdisk.rst. + prot_virt= [S390] enable hosting protected virtual machines + isolated from the hypervisor (if hardware supports + that). + Format: <bool> + psi= [KNL] Enable or disable pressure stall information tracking. Format: <bool>
arch/s390/boot/Makefile +1 -1
@@ -37,7 +37,7 @@ CFLAGS_sclp_early_core.o += -I$(srctree)/drivers/s390/char obj-y := head.o als.o startup.o mem_detect.o ipl_parm.o ipl_report.o obj-y += string.o ebcdic.o sclp_early_core.o mem.o ipl_vmparm.o cmdline.o obj-y += version.o pgm_check_info.o ctype.o text_dma.o -obj-$(CONFIG_PROTECTED_VIRTUALIZATION_GUEST) += uv.o +obj-$(findstring y, $(CONFIG_PROTECTED_VIRTUALIZATION_GUEST) $(CONFIG_PGSTE)) += uv.o obj-$(CONFIG_RELOCATABLE) += machine_kexec_reloc.o obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o targets := bzImage startup.a section_cmp.boot.data section_cmp.boot.preserved.data $(obj-y)
arch/s390/boot/uv.c +20 -1
@@ -3,7 +3,13 @@#include <asm/facility.h> #include <asm/sections.h> +/* will be used in arch/s390/kernel/uv.c */ +#ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST int __bootdata_preserved (prot_virt_guest ); +#endif +#if IS_ENABLED (CONFIG_KVM ) +struct uv_info __bootdata_preserved (uv_info ); +#endif void uv_query_info (void ) {
@@ -18,7 +24,20 @@ void uv_query_info(void)if (uv_call (0 , (uint64_t )&uvcb))return ; -if (test_bit_inv (BIT_UVC_CMD_SET_SHARED_ACCESS , (unsigned long *)uvcb.inst_calls_list) && +if (IS_ENABLED (CONFIG_KVM )) { +memcpy (uv_info.inst_calls_list, uvcb.inst_calls_list,sizeof (uv_info.inst_calls_list)); + uv_info.uv_base_stor_len = uvcb.uv_base_stor_len; + uv_info.guest_base_stor_len = uvcb.conf_base_phys_stor_len; + uv_info.guest_virt_base_stor_len = uvcb.conf_base_virt_stor_len; + uv_info.guest_virt_var_stor_len = uvcb.conf_virt_var_stor_len; + uv_info.guest_cpu_stor_len = uvcb.cpu_stor_len; + uv_info.max_sec_stor_addr =ALIGN (uvcb.max_guest_stor_addr,PAGE_SIZE ); + uv_info.max_num_sec_conf = uvcb.max_num_sec_conf; + uv_info.max_guest_cpus = uvcb.max_guest_cpus; + } + +if (IS_ENABLED (CONFIG_PROTECTED_VIRTUALIZATION_GUEST ) && +test_bit_inv (BIT_UVC_CMD_SET_SHARED_ACCESS , (unsigned long *)uvcb.inst_calls_list) &&test_bit_inv (BIT_UVC_CMD_REMOVE_SHARED_ACCESS , (unsigned long *)uvcb.inst_calls_list)) prot_virt_guest =1 ; }
arch/s390/include/asm/uv.h +43 -2
67 lines not on this page · raw message
arch/s390/kernel/Makefile +1 -0
@@ -78,6 +78,7 @@ obj-$(CONFIG_PERF_EVENTS) += perf_cpum_cf_events.o perf_regs.o obj-$(CONFIG_PERF_EVENTS) += perf_cpum_cf_diag.o obj-$(CONFIG_TRACEPOINTS) += trace.o +obj-$(findstring y, $(CONFIG_PROTECTED_VIRTUALIZATION_GUEST) $(CONFIG_PGSTE)) += uv.o # vdso obj-y += vdso64/
arch/s390/kernel/setup.c +0 -4
@@ -92,10 +92,6 @@ char elf_platform[ELF_PLATFORM_SIZE];unsigned long int_hwcap =0 ; -#ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST -int __bootdata_preserved (prot_virt_guest ); -#endif -int __bootdata (noexec_disabled );int __bootdata (memory_end_set );unsigned long __bootdata (memory_end );
arch/s390/kernel/uv.c new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
2.25.0
Re: [PATCH v2 03/42] s390/protvirt: introduce host side setup
Quoted 215 lines · Christian Borntraeger
From: Vasily Gorbik <[email protected]>
Add "
prot_virt" command line option which controls if the kernel protected VMs support is enabled at early boot time. This has to be done early, because it needs large amounts of memory and will disable some features like STP time sync for the lpar.Extend ultravisor info definitions and expose it via
uv_infostruct filled in during startup.Signed-off-by Vasily Gorbik <[email protected]>Reviewed-by Thomas Huth <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- .../admin-guide/kernel-parameters.txt | 5 ++ arch/s390/boot/Makefile | 2 +- arch/s390/boot/uv.c | 21 +++++++- arch/s390/include/asm/uv.h | 45 +++++++++++++++- arch/s390/kernel/Makefile | 1 + arch/s390/kernel/setup.c | 4 -- arch/s390/kernel/uv.c | 52 +++++++++++++++++++ 7 files changed, 122 insertions(+), 8 deletions(-) create mode 100644 arch/s390/kernel/uv.cDocumentation/admin-guide/kernel-parameters.txt +5
-0@@ -3795,6 +3795,11 @@ before loading. See Documentation/admin-guide/blockdev/ramdisk.rst. + prot_virt= [S390] enable hosting protected virtual machines + isolated from the hypervisor (if hardware supports + that). + Format: <bool> + psi= [KNL] Enable or disable pressure stall information tracking. Format: <bool>arch/s390/boot/Makefile +1
-1@@ -37,7 +37,7 @@ CFLAGS_sclp_early_core.o += -I$(srctree)/drivers/s390/char obj-y := head.o als.o startup.o mem_detect.o ipl_parm.o ipl_report.o obj-y += string.o ebcdic.o sclp_early_core.o mem.o ipl_vmparm.o cmdline.o obj-y += version.o pgm_check_info.o ctype.o text_dma.o -obj-$(CONFIG_PROTECTED_VIRTUALIZATION_GUEST) += uv.o +obj-$(findstring y, $(CONFIG_PROTECTED_VIRTUALIZATION_GUEST) $(CONFIG_PGSTE)) += uv.o obj-$(CONFIG_RELOCATABLE) += machine_kexec_reloc.o obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o targets := bzImage startup.a section_cmp.boot.data section_cmp.boot.preserved.data $(obj-y)arch/s390/boot/uv.c +20
-1@@ -3,7 +3,13 @@#include <asm/facility.h> #include <asm/sections.h> +/* will be used in arch/s390/kernel/uv.c */ +#ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST int __bootdata_preserved (prot_virt_guest ); +#endif +#if IS_ENABLED (CONFIG_KVM ) +struct uv_info __bootdata_preserved (uv_info ); +#endif void uv_query_info (void ) {@@ -18,7 +24,20 @@ void uv_query_info(void)if (uv_call (0 , (uint64_t )&uvcb))return ; -if (test_bit_inv (BIT_UVC_CMD_SET_SHARED_ACCESS , (unsigned long *)uvcb.inst_calls_list) && +if (IS_ENABLED (CONFIG_KVM )) { +memcpy (uv_info.inst_calls_list, uvcb.inst_calls_list,sizeof (uv_info.inst_calls_list)); + uv_info.uv_base_stor_len = uvcb.uv_base_stor_len; + uv_info.guest_base_stor_len = uvcb.conf_base_phys_stor_len; + uv_info.guest_virt_base_stor_len = uvcb.conf_base_virt_stor_len; + uv_info.guest_virt_var_stor_len = uvcb.conf_virt_var_stor_len; + uv_info.guest_cpu_stor_len = uvcb.cpu_stor_len; + uv_info.max_sec_stor_addr =ALIGN (uvcb.max_guest_stor_addr,PAGE_SIZE ); + uv_info.max_num_sec_conf = uvcb.max_num_sec_conf; + uv_info.max_guest_cpus = uvcb.max_guest_cpus; + } + +if (IS_ENABLED (CONFIG_PROTECTED_VIRTUALIZATION_GUEST ) && +test_bit_inv (BIT_UVC_CMD_SET_SHARED_ACCESS , (unsigned long *)uvcb.inst_calls_list) &&test_bit_inv (BIT_UVC_CMD_REMOVE_SHARED_ACCESS , (unsigned long *)uvcb.inst_calls_list)) prot_virt_guest =1 ; }arch/s390/include/asm/uv.h +43
-2@@ -44,7 +44,19 @@ struct uv_cb_qui {struct uv_cb_header header;u64 reserved08;u64 inst_calls_list[4 ]; -u64 reserved30[15 ]; +u64 reserved30[2 ]; +u64 uv_base_stor_len; +u64 reserved48; +u64 conf_base_phys_stor_len; +u64 conf_base_virt_stor_len; +u64 conf_virt_var_stor_len; +u64 cpu_stor_len; +u32 reserved70[3 ]; +u32 max_num_sec_conf; +u64 max_guest_stor_addr; +u8 reserved88[158 -136 ]; +u16 max_guest_cpus; +u64 reserveda0; } __packed__aligned(8) ;struct uv_cb_share {@@ -69,6 +81,19 @@ static inline int uv_call(unsigned long r1, unsigned long r2)return cc; } +struct uv_info { +unsigned long inst_calls_list[4 ]; +unsigned long uv_base_stor_len; +unsigned long guest_base_stor_len; +unsigned long guest_virt_base_stor_len; +unsigned long guest_virt_var_stor_len; +unsigned long guest_cpu_stor_len; +unsigned long max_sec_stor_addr; +unsigned int max_num_sec_conf; +unsigned short max_guest_cpus; +}; +extern struct uv_info uv_info; +#ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST extern int prot_virt_guest;@@ -121,11 +146,27 @@ static inline int uv_remove_shared(unsigned long addr) return share(addr, UVC_CMD_REMOVE_SHARED_ACCESS); } -void uv_query_info (void );#else #define is_prot_virt_guest () 0static inline int uv_set_shared (unsigned long addr) {return 0 ; }static inline int uv_remove_shared (unsigned long addr) {return 0 ; } +#endif + +#if IS_ENABLED (CONFIG_KVM ) +extern int prot_virt_host; + +static inline int is_prot_virt_host (void ) +{ +return prot_virt_host; +} +#else +#define is_prot_virt_host () 0 +#endif + +#if defined(CONFIG_PROTECTED_VIRTUALIZATION_GUEST ) || \ +IS_ENABLED (CONFIG_KVM ) +void uv_query_info (void ); +#else static inline void uv_query_info (void ) {}#endif arch/s390/kernel/Makefile +1
-0@@ -78,6 +78,7 @@ obj-$(CONFIG_PERF_EVENTS) += perf_cpum_cf_events.o perf_regs.o obj-$(CONFIG_PERF_EVENTS) += perf_cpum_cf_diag.o obj-$(CONFIG_TRACEPOINTS) += trace.o +obj-$(findstring y, $(CONFIG_PROTECTED_VIRTUALIZATION_GUEST) $(CONFIG_PGSTE)) += uv.o # vdso obj-y += vdso64/arch/s390/kernel/setup.c +0
-4@@ -92,10 +92,6 @@ char elf_platform[ELF_PLATFORM_SIZE];unsigned long int_hwcap =0 ; -#ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST -int __bootdata_preserved (prot_virt_guest ); -#endif -int __bootdata (noexec_disabled );int __bootdata (memory_end_set );unsigned long __bootdata (memory_end );arch/s390/kernel/uv.c new file +14
-0@@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Common Ultravisor functions and initialization +* +* Copyright IBM Corp. 2019, 2020 +*/ +#define KMSG_COMPONENT "prot_virt" +#define pr_fmt (fmt) KMSG_COMPONENT ": " fmt + +#include <linux/kernel.h> +#include <linux/types.h> +#include <linux/sizes.h> +#include <linux/bitmap.h> +#include <linux/memblock.h>
arch/s390/kernel/uv.c line 24
Quoted 10 lines
arch/s390/kernel/uv.c new file +10
-0+#include <asm/facility.h> +#include <asm/sections.h> +#include <asm/uv.h> + +/* the bootdata_preserved fields come from ones in arch/s390/boot/uv.c */ +#ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST +int __bootdata_preserved (prot_virt_guest ); +#endif + +#if IS_ENABLED (CONFIG_KVM )
Why is that glued to CONFIG_KVM? Can't we glue all that stuff to CONFIG_PROTECTED_VIRTUALIZATION_GUEST and make in kconfig CONFIG_PROTECTED_VIRTUALIZATION_GUEST depend on CONFIG_KVM?
IOW, I'd prefer to only have CONFIG_PROTECTED_VIRTUALIZATION_GUEST in !KVM code and enforce it via kconfig instead.
Anyhow, I remember Conny also having a comment about that previously, so
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v2 03/42] s390/protvirt: introduce host side setup
Quoted 223 lines · David Hildenbrand
Quoted 222 lines · Christian Borntraeger
From: Vasily Gorbik <[email protected]>
Add "
prot_virt" command line option which controls if the kernel protected VMs support is enabled at early boot time. This has to be done early, because it needs large amounts of memory and will disable some features like STP time sync for the lpar.Extend ultravisor info definitions and expose it via
uv_infostruct filled in during startup.Signed-off-by Vasily Gorbik <[email protected]>Reviewed-by Thomas Huth <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- .../admin-guide/kernel-parameters.txt | 5 ++ arch/s390/boot/Makefile | 2 +- arch/s390/boot/uv.c | 21 +++++++- arch/s390/include/asm/uv.h | 45 +++++++++++++++- arch/s390/kernel/Makefile | 1 + arch/s390/kernel/setup.c | 4 -- arch/s390/kernel/uv.c | 52 +++++++++++++++++++ 7 files changed, 122 insertions(+), 8 deletions(-) create mode 100644 arch/s390/kernel/uv.cDocumentation/admin-guide/kernel-parameters.txt +5
-0@@ -3795,6 +3795,11 @@ before loading. See Documentation/admin-guide/blockdev/ramdisk.rst. + prot_virt= [S390] enable hosting protected virtual machines + isolated from the hypervisor (if hardware supports + that). + Format: <bool> + psi= [KNL] Enable or disable pressure stall information tracking. Format: <bool>arch/s390/boot/Makefile +1
-1@@ -37,7 +37,7 @@ CFLAGS_sclp_early_core.o += -I$(srctree)/drivers/s390/char obj-y := head.o als.o startup.o mem_detect.o ipl_parm.o ipl_report.o obj-y += string.o ebcdic.o sclp_early_core.o mem.o ipl_vmparm.o cmdline.o obj-y += version.o pgm_check_info.o ctype.o text_dma.o -obj-$(CONFIG_PROTECTED_VIRTUALIZATION_GUEST) += uv.o +obj-$(findstring y, $(CONFIG_PROTECTED_VIRTUALIZATION_GUEST) $(CONFIG_PGSTE)) += uv.o obj-$(CONFIG_RELOCATABLE) += machine_kexec_reloc.o obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o targets := bzImage startup.a section_cmp.boot.data section_cmp.boot.preserved.data $(obj-y)arch/s390/boot/uv.c +20
-1@@ -3,7 +3,13 @@#include <asm/facility.h> #include <asm/sections.h> +/* will be used in arch/s390/kernel/uv.c */ +#ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST int __bootdata_preserved (prot_virt_guest ); +#endif +#if IS_ENABLED (CONFIG_KVM ) +struct uv_info __bootdata_preserved (uv_info ); +#endif void uv_query_info (void ) {@@ -18,7 +24,20 @@ void uv_query_info(void)if (uv_call (0 , (uint64_t )&uvcb))return ; -if (test_bit_inv (BIT_UVC_CMD_SET_SHARED_ACCESS , (unsigned long *)uvcb.inst_calls_list) && +if (IS_ENABLED (CONFIG_KVM )) { +memcpy (uv_info.inst_calls_list, uvcb.inst_calls_list,sizeof (uv_info.inst_calls_list)); + uv_info.uv_base_stor_len = uvcb.uv_base_stor_len; + uv_info.guest_base_stor_len = uvcb.conf_base_phys_stor_len; + uv_info.guest_virt_base_stor_len = uvcb.conf_base_virt_stor_len; + uv_info.guest_virt_var_stor_len = uvcb.conf_virt_var_stor_len; + uv_info.guest_cpu_stor_len = uvcb.cpu_stor_len; + uv_info.max_sec_stor_addr =ALIGN (uvcb.max_guest_stor_addr,PAGE_SIZE ); + uv_info.max_num_sec_conf = uvcb.max_num_sec_conf; + uv_info.max_guest_cpus = uvcb.max_guest_cpus; + } + +if (IS_ENABLED (CONFIG_PROTECTED_VIRTUALIZATION_GUEST ) && +test_bit_inv (BIT_UVC_CMD_SET_SHARED_ACCESS , (unsigned long *)uvcb.inst_calls_list) &&test_bit_inv (BIT_UVC_CMD_REMOVE_SHARED_ACCESS , (unsigned long *)uvcb.inst_calls_list)) prot_virt_guest =1 ; }arch/s390/include/asm/uv.h +43
-2@@ -44,7 +44,19 @@ struct uv_cb_qui {struct uv_cb_header header;u64 reserved08;u64 inst_calls_list[4 ]; -u64 reserved30[15 ]; +u64 reserved30[2 ]; +u64 uv_base_stor_len; +u64 reserved48; +u64 conf_base_phys_stor_len; +u64 conf_base_virt_stor_len; +u64 conf_virt_var_stor_len; +u64 cpu_stor_len; +u32 reserved70[3 ]; +u32 max_num_sec_conf; +u64 max_guest_stor_addr; +u8 reserved88[158 -136 ]; +u16 max_guest_cpus; +u64 reserveda0; } __packed__aligned(8) ;struct uv_cb_share {@@ -69,6 +81,19 @@ static inline int uv_call(unsigned long r1, unsigned long r2)return cc; } +struct uv_info { +unsigned long inst_calls_list[4 ]; +unsigned long uv_base_stor_len; +unsigned long guest_base_stor_len; +unsigned long guest_virt_base_stor_len; +unsigned long guest_virt_var_stor_len; +unsigned long guest_cpu_stor_len; +unsigned long max_sec_stor_addr; +unsigned int max_num_sec_conf; +unsigned short max_guest_cpus; +}; +extern struct uv_info uv_info; +#ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST extern int prot_virt_guest;@@ -121,11 +146,27 @@ static inline int uv_remove_shared(unsigned long addr) return share(addr, UVC_CMD_REMOVE_SHARED_ACCESS); } -void uv_query_info (void );#else #define is_prot_virt_guest () 0static inline int uv_set_shared (unsigned long addr) {return 0 ; }static inline int uv_remove_shared (unsigned long addr) {return 0 ; } +#endif + +#if IS_ENABLED (CONFIG_KVM ) +extern int prot_virt_host; + +static inline int is_prot_virt_host (void ) +{ +return prot_virt_host; +} +#else +#define is_prot_virt_host () 0 +#endif + +#if defined(CONFIG_PROTECTED_VIRTUALIZATION_GUEST ) || \ +IS_ENABLED (CONFIG_KVM ) +void uv_query_info (void ); +#else static inline void uv_query_info (void ) {}#endif arch/s390/kernel/Makefile +1
-0@@ -78,6 +78,7 @@ obj-$(CONFIG_PERF_EVENTS) += perf_cpum_cf_events.o perf_regs.o obj-$(CONFIG_PERF_EVENTS) += perf_cpum_cf_diag.o obj-$(CONFIG_TRACEPOINTS) += trace.o +obj-$(findstring y, $(CONFIG_PROTECTED_VIRTUALIZATION_GUEST) $(CONFIG_PGSTE)) += uv.o # vdso obj-y += vdso64/arch/s390/kernel/setup.c +0
-4@@ -92,10 +92,6 @@ char elf_platform[ELF_PLATFORM_SIZE];unsigned long int_hwcap =0 ; -#ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST -int __bootdata_preserved (prot_virt_guest ); -#endif -int __bootdata (noexec_disabled );int __bootdata (memory_end_set );unsigned long __bootdata (memory_end );arch/s390/kernel/uv.c new file +21
-0@@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Common Ultravisor functions and initialization +* +* Copyright IBM Corp. 2019, 2020 +*/ +#define KMSG_COMPONENT "prot_virt" +#define pr_fmt (fmt) KMSG_COMPONENT ": " fmt + +#include <linux/kernel.h> +#include <linux/types.h> +#include <linux/sizes.h> +#include <linux/bitmap.h> +#include <linux/memblock.h> +#include <asm/facility.h> +#include <asm/sections.h> +#include <asm/uv.h> + +/* the bootdata_preserved fields come from ones in arch/s390/boot/uv.c */ +#ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST +int __bootdata_preserved (prot_virt_guest );
Quoted 8 lines
arch/s390/kernel/uv.c line 24
Quoted 3 lines
arch/s390/kernel/uv.c new file +3
-0+#endif + +#if IS_ENABLED (CONFIG_KVM )Why is that glued to
CONFIG_KVM? Can't we glue all that stuff toCONFIG_PROTECTED_VIRTUALIZATION_GUESTand make in kconfigCONFIG_PROTECTED_VIRTUALIZATION_GUESTdepend onCONFIG_KVM?
CONFIG_PROTECTED_VIRTUALIZATION_GUEST is for the GUEST part (the virtio-ccw changes inside the guest). The other thing is for the host and here we bind it to CONFIG_KVM (or PGSTE for mm code).
Quoted 10 lines
IOW, I'd prefer to only have
CONFIG_PROTECTED_VIRTUALIZATION_GUESTin !KVM code and enforce it via kconfig instead.Anyhow, I remember Conny also having a comment about that previously, so
Re: [PATCH v2 03/42] s390/protvirt: introduce host side setup
Quoted 236 lines · Christian Borntraeger
Quoted 223 lines · David Hildenbrand
Quoted 222 lines · Christian Borntraeger
From: Vasily Gorbik <[email protected]>
Add "
prot_virt" command line option which controls if the kernel protected VMs support is enabled at early boot time. This has to be done early, because it needs large amounts of memory and will disable some features like STP time sync for the lpar.Extend ultravisor info definitions and expose it via
uv_infostruct filled in during startup.Signed-off-by Vasily Gorbik <[email protected]>Reviewed-by Thomas Huth <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- .../admin-guide/kernel-parameters.txt | 5 ++ arch/s390/boot/Makefile | 2 +- arch/s390/boot/uv.c | 21 +++++++- arch/s390/include/asm/uv.h | 45 +++++++++++++++- arch/s390/kernel/Makefile | 1 + arch/s390/kernel/setup.c | 4 -- arch/s390/kernel/uv.c | 52 +++++++++++++++++++ 7 files changed, 122 insertions(+), 8 deletions(-) create mode 100644 arch/s390/kernel/uv.cDocumentation/admin-guide/kernel-parameters.txt +5
-0@@ -3795,6 +3795,11 @@ before loading. See Documentation/admin-guide/blockdev/ramdisk.rst. + prot_virt= [S390] enable hosting protected virtual machines + isolated from the hypervisor (if hardware supports + that). + Format: <bool> + psi= [KNL] Enable or disable pressure stall information tracking. Format: <bool>arch/s390/boot/Makefile +1
-1@@ -37,7 +37,7 @@ CFLAGS_sclp_early_core.o += -I$(srctree)/drivers/s390/char obj-y := head.o als.o startup.o mem_detect.o ipl_parm.o ipl_report.o obj-y += string.o ebcdic.o sclp_early_core.o mem.o ipl_vmparm.o cmdline.o obj-y += version.o pgm_check_info.o ctype.o text_dma.o -obj-$(CONFIG_PROTECTED_VIRTUALIZATION_GUEST) += uv.o +obj-$(findstring y, $(CONFIG_PROTECTED_VIRTUALIZATION_GUEST) $(CONFIG_PGSTE)) += uv.o obj-$(CONFIG_RELOCATABLE) += machine_kexec_reloc.o obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o targets := bzImage startup.a section_cmp.boot.data section_cmp.boot.preserved.data $(obj-y)arch/s390/boot/uv.c +20
-1@@ -3,7 +3,13 @@#include <asm/facility.h> #include <asm/sections.h> +/* will be used in arch/s390/kernel/uv.c */ +#ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST int __bootdata_preserved (prot_virt_guest ); +#endif +#if IS_ENABLED (CONFIG_KVM ) +struct uv_info __bootdata_preserved (uv_info ); +#endif void uv_query_info (void ) {@@ -18,7 +24,20 @@ void uv_query_info(void)if (uv_call (0 , (uint64_t )&uvcb))return ; -if (test_bit_inv (BIT_UVC_CMD_SET_SHARED_ACCESS , (unsigned long *)uvcb.inst_calls_list) && +if (IS_ENABLED (CONFIG_KVM )) { +memcpy (uv_info.inst_calls_list, uvcb.inst_calls_list,sizeof (uv_info.inst_calls_list)); + uv_info.uv_base_stor_len = uvcb.uv_base_stor_len; + uv_info.guest_base_stor_len = uvcb.conf_base_phys_stor_len; + uv_info.guest_virt_base_stor_len = uvcb.conf_base_virt_stor_len; + uv_info.guest_virt_var_stor_len = uvcb.conf_virt_var_stor_len; + uv_info.guest_cpu_stor_len = uvcb.cpu_stor_len; + uv_info.max_sec_stor_addr =ALIGN (uvcb.max_guest_stor_addr,PAGE_SIZE ); + uv_info.max_num_sec_conf = uvcb.max_num_sec_conf; + uv_info.max_guest_cpus = uvcb.max_guest_cpus; + } + +if (IS_ENABLED (CONFIG_PROTECTED_VIRTUALIZATION_GUEST ) && +test_bit_inv (BIT_UVC_CMD_SET_SHARED_ACCESS , (unsigned long *)uvcb.inst_calls_list) &&test_bit_inv (BIT_UVC_CMD_REMOVE_SHARED_ACCESS , (unsigned long *)uvcb.inst_calls_list)) prot_virt_guest =1 ; }arch/s390/include/asm/uv.h +43
-2@@ -44,7 +44,19 @@ struct uv_cb_qui {struct uv_cb_header header;u64 reserved08;u64 inst_calls_list[4 ]; -u64 reserved30[15 ]; +u64 reserved30[2 ]; +u64 uv_base_stor_len; +u64 reserved48; +u64 conf_base_phys_stor_len; +u64 conf_base_virt_stor_len; +u64 conf_virt_var_stor_len; +u64 cpu_stor_len; +u32 reserved70[3 ]; +u32 max_num_sec_conf; +u64 max_guest_stor_addr; +u8 reserved88[158 -136 ]; +u16 max_guest_cpus; +u64 reserveda0; } __packed__aligned(8) ;struct uv_cb_share {@@ -69,6 +81,19 @@ static inline int uv_call(unsigned long r1, unsigned long r2)return cc; } +struct uv_info { +unsigned long inst_calls_list[4 ]; +unsigned long uv_base_stor_len; +unsigned long guest_base_stor_len; +unsigned long guest_virt_base_stor_len; +unsigned long guest_virt_var_stor_len; +unsigned long guest_cpu_stor_len; +unsigned long max_sec_stor_addr; +unsigned int max_num_sec_conf; +unsigned short max_guest_cpus; +}; +extern struct uv_info uv_info; +#ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST extern int prot_virt_guest;@@ -121,11 +146,27 @@ static inline int uv_remove_shared(unsigned long addr) return share(addr, UVC_CMD_REMOVE_SHARED_ACCESS); } -void uv_query_info (void );#else #define is_prot_virt_guest () 0static inline int uv_set_shared (unsigned long addr) {return 0 ; }static inline int uv_remove_shared (unsigned long addr) {return 0 ; } +#endif + +#if IS_ENABLED (CONFIG_KVM ) +extern int prot_virt_host; + +static inline int is_prot_virt_host (void ) +{ +return prot_virt_host; +} +#else +#define is_prot_virt_host () 0 +#endif + +#if defined(CONFIG_PROTECTED_VIRTUALIZATION_GUEST ) || \ +IS_ENABLED (CONFIG_KVM ) +void uv_query_info (void ); +#else static inline void uv_query_info (void ) {}#endif arch/s390/kernel/Makefile +1
-0@@ -78,6 +78,7 @@ obj-$(CONFIG_PERF_EVENTS) += perf_cpum_cf_events.o perf_regs.o obj-$(CONFIG_PERF_EVENTS) += perf_cpum_cf_diag.o obj-$(CONFIG_TRACEPOINTS) += trace.o +obj-$(findstring y, $(CONFIG_PROTECTED_VIRTUALIZATION_GUEST) $(CONFIG_PGSTE)) += uv.o # vdso obj-y += vdso64/arch/s390/kernel/setup.c +0
-4@@ -92,10 +92,6 @@ char elf_platform[ELF_PLATFORM_SIZE];unsigned long int_hwcap =0 ; -#ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST -int __bootdata_preserved (prot_virt_guest ); -#endif -int __bootdata (noexec_disabled );int __bootdata (memory_end_set );unsigned long __bootdata (memory_end );arch/s390/kernel/uv.c new file +21
-0@@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Common Ultravisor functions and initialization +* +* Copyright IBM Corp. 2019, 2020 +*/ +#define KMSG_COMPONENT "prot_virt" +#define pr_fmt (fmt) KMSG_COMPONENT ": " fmt + +#include <linux/kernel.h> +#include <linux/types.h> +#include <linux/sizes.h> +#include <linux/bitmap.h> +#include <linux/memblock.h> +#include <asm/facility.h> +#include <asm/sections.h> +#include <asm/uv.h> + +/* the bootdata_preserved fields come from ones in arch/s390/boot/uv.c */ +#ifdef CONFIG_PROTECTED_VIRTUALIZATION_GUEST +int __bootdata_preserved (prot_virt_guest );Quoted 8 lines
arch/s390/kernel/uv.c line 24
Quoted 3 lines
arch/s390/kernel/uv.c new file +3
-0+#endif + +#if IS_ENABLED (CONFIG_KVM )Why is that glued to
CONFIG_KVM? Can't we glue all that stuff toCONFIG_PROTECTED_VIRTUALIZATION_GUESTand make in kconfigCONFIG_PROTECTED_VIRTUALIZATION_GUESTdepend onCONFIG_KVM?
Quoted 3 lines
CONFIG_PROTECTED_VIRTUALIZATION_GUESTis for the GUEST part (the virtio-ccw changes inside the guest). The other thing is for the host and here we bind it toCONFIG_KVM(or PGSTE for mm code).
Ahh, sorry messed that up. Think I had another (in previous versions?) config option in mind.
Makes sense
Signature · 3 lines
Thanks, David / dhildenb
PATCH v2 4/42 s390/protvirt: add ultravisor initialization
In reply to Christian BorntraegerFrom: Vasily Gorbik <[email protected]>
Before being able to host protected virtual machines, donate some of the memory to the ultravisor. Besides that the ultravisor might impose addressing limitations for memory used to back protected VM storage. Treat that limit as protected virtualization host's virtual memory limit.
--- arch/s390/include/asm/uv.h | 15 +++++++++++ arch/s390/kernel/setup.c | 5 ++++ arch/s390/kernel/uv.c | 51 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+)
arch/s390/include/asm/uv.h +15 -0
@@ -23,12 +23,14 @@#define UVC_RC_NO_RESUME 0x0007#define UVC_CMD_QUI 0x0001 +#define UVC_CMD_INIT_UV 0x000f#define UVC_CMD_SET_SHARED_ACCESS 0x1000#define UVC_CMD_REMOVE_SHARED_ACCESS 0x1001/* Bits in installed uv calls */ enum uv_cmds_inst {BIT_UVC_CMD_QUI =0 , +BIT_UVC_CMD_INIT_UV =1 ,BIT_UVC_CMD_SET_SHARED_ACCESS =8 ,BIT_UVC_CMD_REMOVE_SHARED_ACCESS =9 , };
@@ -59,6 +61,14 @@ struct uv_cb_qui {u64 reserveda0; } __packed__aligned(8) ; +struct uv_cb_init { +struct uv_cb_header header; +u64 reserved08[2 ]; +u64 stor_origin; +u64 stor_len; +u64 reserved28[4 ]; +} __packed__aligned(8) ; +struct uv_cb_share {struct uv_cb_header header;u64 reserved08[3 ];
@@ -159,8 +169,13 @@ static inline int is_prot_virt_host(void) {return prot_virt_host; } + +void setup_uv (void ); +void adjust_to_uv_max (unsigned long *vmax);#else #define is_prot_virt_host () 0 +static inline void setup_uv (void ) {} +static inline void adjust_to_uv_max (unsigned long *vmax) {}#endif #if defined(CONFIG_PROTECTED_VIRTUALIZATION_GUEST) || \
arch/s390/kernel/setup.c +5 -0
@@ -560,6 +560,9 @@ static void __init setup_memory_end(void) vmax = _REGION1_SIZE;/* 4-level kernel page table */ } +if (prot_virt_host) +adjust_to_uv_max (&vmax); +/* module area is at the end of the kernel address space. */ MODULES_END = vmax;MODULES_VADDR =MODULES_END -MODULES_LEN ;
@@ -1134,6 +1137,8 @@ void __init setup_arch(char **cmdline_p)*/ memblock_trim_memory (1UL << (MAX_ORDER -1 +PAGE_SHIFT )); +if (prot_virt_host) +setup_uv ();setup_memory_end ();setup_memory ();dma_contiguous_reserve (memory_end);
arch/s390/kernel/uv.c +51 -0
55 lines not on this page · raw message
Signature · 1 line
2.25.0
Re: [PATCH v2 04/42] s390/protvirt: add ultravisor initialization
Quoted 112 lines · Christian Borntraeger
From: Vasily Gorbik <[email protected]>
Before being able to host protected virtual machines, donate some of the memory to the ultravisor. Besides that the ultravisor might impose addressing limitations for memory used to back protected VM storage. Treat that limit as protected virtualization host's virtual memory limit.
Signed-off-by Vasily Gorbik <[email protected]>Reviewed-by Christian Borntraeger <[email protected]>Reviewed-by Cornelia Huck <[email protected]>Reviewed-by Thomas Huth <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/include/asm/uv.h | 15 +++++++++++ arch/s390/kernel/setup.c | 5 ++++ arch/s390/kernel/uv.c | 51 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+)arch/s390/include/asm/uv.h +15
-0@@ -23,12 +23,14 @@#define UVC_RC_NO_RESUME 0x0007#define UVC_CMD_QUI 0x0001 +#define UVC_CMD_INIT_UV 0x000f#define UVC_CMD_SET_SHARED_ACCESS 0x1000#define UVC_CMD_REMOVE_SHARED_ACCESS 0x1001/* Bits in installed uv calls */ enum uv_cmds_inst {BIT_UVC_CMD_QUI =0 , +BIT_UVC_CMD_INIT_UV =1 ,BIT_UVC_CMD_SET_SHARED_ACCESS =8 ,BIT_UVC_CMD_REMOVE_SHARED_ACCESS =9 , };@@ -59,6 +61,14 @@ struct uv_cb_qui {u64 reserveda0; } __packed__aligned(8) ; +struct uv_cb_init { +struct uv_cb_header header; +u64 reserved08[2 ]; +u64 stor_origin; +u64 stor_len; +u64 reserved28[4 ]; +} __packed__aligned(8) ; +struct uv_cb_share {struct uv_cb_header header;u64 reserved08[3 ];@@ -159,8 +169,13 @@ static inline int is_prot_virt_host(void) {return prot_virt_host; } + +void setup_uv (void ); +void adjust_to_uv_max (unsigned long *vmax);#else #define is_prot_virt_host () 0 +static inline void setup_uv (void ) {} +static inline void adjust_to_uv_max (unsigned long *vmax) {}#endif #if defined(CONFIG_PROTECTED_VIRTUALIZATION_GUEST) || \arch/s390/kernel/setup.c +5
-0@@ -560,6 +560,9 @@ static void __init setup_memory_end(void) vmax = _REGION1_SIZE;/* 4-level kernel page table */ } +if (prot_virt_host) +adjust_to_uv_max (&vmax); +/* module area is at the end of the kernel address space. */ MODULES_END = vmax;MODULES_VADDR =MODULES_END -MODULES_LEN ;@@ -1134,6 +1137,8 @@ void __init setup_arch(char **cmdline_p)*/ memblock_trim_memory (1UL << (MAX_ORDER -1 +PAGE_SHIFT )); +if (prot_virt_host) +setup_uv ();setup_memory_end ();setup_memory ();dma_contiguous_reserve (memory_end);arch/s390/kernel/uv.c +14
-0@@ -49,4 +49,55 @@ static int __init prot_virt_setup(char *val)return rc; }early_param ("prot_virt" , prot_virt_setup); + +static int __init uv_init (unsigned long stor_base,unsigned long stor_len) +{ +struct uv_cb_init uvcb = { + .header.cmd =UVC_CMD_INIT_UV , + .header.len =sizeof (uvcb), + .stor_origin = stor_base, + .stor_len = stor_len, + }; + +if (uv_call (0 , (uint64_t )&uvcb)) { +pr_err ("Ultravisor init failed with rc: 0x%x rrc: 0%x\n" , + uvcb.header.rc, uvcb.header.rrc); +return -1 ;
arch/s390/kernel/uv.c static int __init prot_virt_setup(char *val) · line 75
Quoted 10 lines
arch/s390/kernel/uv.c +10
-0+ } +return 0 ; +} + +void __init setup_uv (void ) +{ +unsigned long uv_stor_base; + +if (!prot_virt_host) +return ;
That can go.
arch/s390/kernel/uv.c static int __init prot_virt_setup(char *val) · line 79
Quoted 4 lines
arch/s390/kernel/uv.c +4
-0+ + uv_stor_base = (unsigned long )memblock_alloc_try_nid ( + uv_info.uv_base_stor_len,SZ_1M ,SZ_2G , +MEMBLOCK_ALLOC_ACCESSIBLE ,NUMA_NO_NODE );
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v2 04/42] s390/protvirt: add ultravisor initialization
On 17.02.20 10:57, David Hildenbrand wrote:
t setup_uv(void)
Quoted 7 lines
arch/s390/kernel/uv.c static int __init prot_virt_setup(char *val) · line 75
Quoted 5 lines
arch/s390/kernel/uv.c +5
-0+{ +unsigned long uv_stor_base; + +if (!prot_virt_host) +return ;That can go.
ack.
Quoted 8 lines
arch/s390/kernel/uv.c static int __init prot_virt_setup(char *val) · line 79
Quoted 5 lines
arch/s390/kernel/uv.c +4
-0+ + uv_stor_base = (unsigned long )memblock_alloc_try_nid ( + uv_info.uv_base_stor_len,SZ_1M ,SZ_2G , +MEMBLOCK_ALLOC_ACCESSIBLE ,NUMA_NO_NODE );Reviewed-by David Hildenbrand <[email protected]>
PATCH v2 5/42 s390/mm: provide memory management functions for protected KVM guests
In reply to Christian BorntraegerFrom: Claudio Imbrenda <[email protected]>
This provides the basic ultravisor calls and page table handling to cope with secure guests:
- provide arch_make_page_accessible
- make pages accessible after unmapping of secure guests
- provide the ultravisor commands convert to/from secure
- provide the ultravisor commands pin/unpin shared
- provide callbacks to make pages secure (inacccessible)
- we check for the expected pin count to only make pages secure if the host is not accessing them
- we fence hugetlbfs for secure pages
--- arch/s390/include/asm/gmap.h | 4 + arch/s390/include/asm/mmu.h | 2 + arch/s390/include/asm/mmu_context.h | 1 + arch/s390/include/asm/page.h | 5 + arch/s390/include/asm/pgtable.h | 35 ++++- arch/s390/include/asm/uv.h | 31 ++++ arch/s390/kernel/uv.c | 223 ++++++++++++++++++++++++++++ 7 files changed, 296 insertions(+), 5 deletions(-)
arch/s390/include/asm/gmap.h +4 -0
@@ -9,6 +9,7 @@#ifndef _ASM_S390_GMAP_H#define _ASM_S390_GMAP_H +#include <linux/radix-tree.h> #include <linux/refcount.h> /* Generic bits for GMAP notification on DAT table entry changes. */
@@ -31,6 +32,7 @@* @table: pointer to the page directory * @asce: address space control element for gmap page table * @pfault_enabled: defines if pfaults are applicable for the guest +* @guest_handle: protected virtual machine handle for the ultravisor * @host_to_rmap: radix tree with gmap_rmap lists * @children: list of shadow gmap structures * @pt_list: list of all page tables used in the shadow guest address space
@@ -54,6 +56,8 @@ struct gmap {unsigned long asce_end;void *private;bool pfault_enabled; +/* only set for protected virtual machines */ +unsigned long guest_handle;/* Additional data for shadow guest address spaces */ struct radix_tree_root host_to_rmap;struct list_head children;
arch/s390/include/asm/mmu.h +2 -0
@@ -16,6 +16,8 @@ typedef struct {unsigned long asce;unsigned long asce_limit;unsigned long vdso_base; +/* The mmu context belongs to a secure guest. */ +atomic_t is_protected;/* * The following bitfields need a down_write on the mm * semaphore when they are written to. As they are only
arch/s390/include/asm/mmu_context.h +1 -0
@@ -23,6 +23,7 @@ static inline int init_new_context(struct task_struct *tsk,INIT_LIST_HEAD (&mm->context.gmap_list);cpumask_clear (&mm->context.cpu_attach_mask);atomic_set (&mm->context.flush_count,0 ); +atomic_set (&mm->context.is_protected,0 ); mm->context.gmap_asce =0 ; mm->context.flush_mm =0 ; mm->context.compat_mm =test_thread_flag (TIF_31BIT );
arch/s390/include/asm/page.h +5 -0
@@ -153,6 +153,11 @@ static inline int devmem_is_allowed(unsigned long pfn)#define HAVE_ARCH_FREE_PAGE #define HAVE_ARCH_ALLOC_PAGE +#if IS_ENABLED (CONFIG_PGSTE ) +int arch_make_page_accessible (struct page *page); +#define HAVE_ARCH_MAKE_PAGE_ACCESSIBLE +#endif +#endif /* !__ASSEMBLY__ */ #define __PAGE_OFFSET 0x0UL
arch/s390/include/asm/pgtable.h +30 -5
@@ -19,6 +19,7 @@#include <linux/atomic.h> #include <asm/bug.h> #include <asm/page.h> +#include <asm/uv.h> extern pgd_t swapper_pg_dir[];extern void paging_init (void );
@@ -520,6 +521,15 @@ static inline int mm_has_pgste(struct mm_struct *mm)return 0 ; } +static inline int mm_is_protected (struct mm_struct *mm) +{ +#ifdef CONFIG_PGSTE +if (unlikely (atomic_read (&mm->context.is_protected))) +return 1 ; +#endif +return 0 ; +} +static inline int mm_alloc_pgste (struct mm_struct *mm) {#ifdef CONFIG_PGSTE
@@ -1061,7 +1071,12 @@ static inline int ptep_clear_flush_young(struct vm_area_struct *vma,static inline pte_t ptep_get_and_clear (struct mm_struct *mm,unsigned long addr,pte_t *ptep) { -return ptep_xchg_lazy (mm, addr, ptep,__pte (_PAGE_INVALID)); +pte_t res; + + res =ptep_xchg_lazy (mm, addr, ptep,__pte (_PAGE_INVALID)); +if (mm_is_protected (mm) &&pte_present (res)) +uv_convert_from_secure (pte_val (res) &PAGE_MASK ); +return res; }#define __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION
@@ -1073,7 +1088,12 @@ void ptep_modify_prot_commit(struct vm_area_struct *, unsigned long,static inline pte_t ptep_clear_flush (struct vm_area_struct *vma,unsigned long addr,pte_t *ptep) { -return ptep_xchg_direct (vma->vm_mm, addr, ptep,__pte (_PAGE_INVALID)); +pte_t res; + + res =ptep_xchg_direct (vma->vm_mm, addr, ptep,__pte (_PAGE_INVALID)); +if (mm_is_protected (vma->vm_mm) &&pte_present (res)) +uv_convert_from_secure (pte_val (res) &PAGE_MASK ); +return res; }/*
@@ -1088,12 +1108,17 @@ static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm,unsigned long addr, pte_t *ptep, int full) { + pte_t res; +if (full) { - pte_t pte = *ptep; + res = *ptep; *ptep =__pte (_PAGE_INVALID); -return pte; + }else { + res =ptep_xchg_lazy (mm, addr, ptep,__pte (_PAGE_INVALID)); } -return ptep_xchg_lazy (mm, addr, ptep,__pte (_PAGE_INVALID)); +if (mm_is_protected (mm) &&pte_present (res)) +uv_convert_from_secure (pte_val (res) &PAGE_MASK ); +return res; }#define __HAVE_ARCH_PTEP_SET_WRPROTECT
arch/s390/include/asm/uv.h +31 -0
@@ -15,6 +15,7 @@#include <linux/errno.h> #include <linux/bug.h> #include <asm/page.h> +#include <asm/gmap.h> #define UVC_RC_EXECUTED 0x0001#define UVC_RC_INV_CMD 0x0002
@@ -24,6 +25,10 @@#define UVC_CMD_QUI 0x0001#define UVC_CMD_INIT_UV 0x000f +#define UVC_CMD_CONV_TO_SEC_STOR 0x0200 +#define UVC_CMD_CONV_FROM_SEC_STOR 0x0201 +#define UVC_CMD_PIN_PAGE_SHARED 0x0341 +#define UVC_CMD_UNPIN_PAGE_SHARED 0x0342#define UVC_CMD_SET_SHARED_ACCESS 0x1000#define UVC_CMD_REMOVE_SHARED_ACCESS 0x1001
@@ -31,8 +36,12 @@enum uv_cmds_inst {BIT_UVC_CMD_QUI =0 ,BIT_UVC_CMD_INIT_UV =1 , +BIT_UVC_CMD_CONV_TO_SEC_STOR =6 , +BIT_UVC_CMD_CONV_FROM_SEC_STOR =7 ,BIT_UVC_CMD_SET_SHARED_ACCESS =8 ,BIT_UVC_CMD_REMOVE_SHARED_ACCESS =9 , +BIT_UVC_CMD_PIN_PAGE_SHARED =21 , +BIT_UVC_CMD_UNPIN_PAGE_SHARED =22 , };struct uv_cb_header {
@@ -69,6 +78,19 @@ struct uv_cb_init {u64 reserved28[4 ]; } __packed__aligned(8) ; +struct uv_cb_cts { +struct uv_cb_header header; +u64 reserved08[2 ]; +u64 guest_handle; +u64 gaddr; +} __packed__aligned(8) ; + +struct uv_cb_cfs { +struct uv_cb_header header; +u64 reserved08[2 ]; +u64 paddr; +} __packed__aligned(8) ; +struct uv_cb_share {struct uv_cb_header header;u64 reserved08[3 ];
@@ -170,12 +192,21 @@ static inline int is_prot_virt_host(void)return prot_virt_host; } +int gmap_make_secure (struct gmap *gmap,unsigned long gaddr,void *uvcb); +int uv_convert_from_secure (unsigned long paddr); +int gmap_convert_to_secure (struct gmap *gmap,unsigned long gaddr); +void setup_uv (void );void adjust_to_uv_max (unsigned long *vmax);#else #define is_prot_virt_host () 0static inline void setup_uv (void ) {}static inline void adjust_to_uv_max (unsigned long *vmax) {} + +static inline int uv_convert_from_secure (unsigned long paddr) +{ +return 0 ; +}#endif #if defined(CONFIG_PROTECTED_VIRTUALIZATION_GUEST) || \
arch/s390/kernel/uv.c +223 -0
233 lines not on this page · raw message
Signature · 1 line
2.25.0
Re: [PATCH v2 05/42] s390/mm: provide memory management functions for protected KVM guests
arch/s390/include/asm/page.h static inline int devmem_is_allowed(unsigned long pfn) · line 160
Quoted 13 lines
arch/s390/include/asm/page.h +5
-0@@ -153,6 +153,11 @@ static inline int devmem_is_allowed(unsigned long pfn)#define HAVE_ARCH_FREE_PAGE #define HAVE_ARCH_ALLOC_PAGE +#if IS_ENABLED (CONFIG_PGSTE ) +int arch_make_page_accessible (struct page *page); +#define HAVE_ARCH_MAKE_PAGE_ACCESSIBLE +#endif +
Feels like this should have been one of the (CONFIG_)ARCH_HAVE_XXX thingies defined via kconfig instead.
E.g., like (CONFIG_)HAVE_ARCH_TRANSPARENT_HUGEPAGE
[...]
Quoted 15 lines
arch/s390/include/asm/page.h +15
-0+ +/* +* Requests the Ultravisor to encrypt a guest page and make it +* accessible to the host for paging (export). +* +* @paddr: Absolute host address of page to be exported +*/ +int uv_convert_from_secure (unsigned long paddr) +{ +struct uv_cb_cfs uvcb = { + .header.cmd =UVC_CMD_CONV_FROM_SEC_STOR , + .header.len =sizeof (uvcb), + .paddr = paddr + }; +
arch/s390/include/asm/page.h static inline int devmem_is_allowed(unsigned long pfn)
Quoted 10 lines
arch/s390/include/asm/page.h +10
-0+if (uv_call (0 , (u64)&uvcb)) +return -EINVAL ; +return 0 ; +} + +/* +* Calculate the expected ref_count for a page that would otherwise have no +* further pins. This was cribbed from similar functions in other places in +* the kernel, but with some slight modifications. We know that a secure +* page can not be a huge page for example.
s/ca not cannot/
Quoted 47 lines
+ */
arch/s390/include/asm/page.h +46
-0+static int expected_page_refs (struct page *page) +{ +int res; + + res =page_mapcount (page); +if (PageSwapCache (page)) { + res++; + }else if (page_mapping (page)) { + res++; +if (page_has_private (page)) + res++; + } +return res; +} + +static int make_secure_pte (pte_t *ptep,unsigned long addr, +struct page *exp_page,struct uv_cb_header *uvcb) +{ +pte_t entry =READ_ONCE (*ptep); +struct page *page; +int expected, rc =0 ; + +if (!pte_present (entry)) +return -ENXIO ; +if (pte_val (entry) & _PAGE_INVALID) +return -ENXIO ; + + page =pte_page (entry); +if (page != exp_page) +return -ENXIO ; +if (PageWriteback (page)) +return -EAGAIN ; + expected =expected_page_refs (page); +if (!page_ref_freeze (page, expected)) +return -EBUSY ; +set_bit (PG_arch_1, &page->flags); + rc =uv_call (0 , (u64 )uvcb); +page_ref_unfreeze (page, expected); +/* Return -ENXIO if the page was not mapped, -EINVAL otherwise */ +if (rc) + rc = uvcb->rc ==0x10a ? -ENXIO : -EINVAL ; +return rc; +} + +/* +* Requests the Ultravisor to make a page accessible to a guest.
arch/s390/include/asm/page.h
Quoted 10 lines
arch/s390/include/asm/page.h +10
-0+* If it's brought in the first time, it will be cleared. If +* it has been exported before, it will be decrypted and integrity +* checked. +*/ +int gmap_make_secure (struct gmap *gmap,unsigned long gaddr,void *uvcb) +{ +struct vm_area_struct *vma; +unsigned long uaddr; +struct page *page; +int rc, local_drain =0 ;
local_drain could have been a bool.
Quoted 9 lines
arch/s390/include/asm/page.h +9
-0+spinlock_t *ptelock; +pte_t *ptep; + +again: + rc = -EFAULT ; +down_read (&gmap->mm->mmap_sem); + + uaddr =__gmap_translate (gmap, gaddr); +if (IS_ERR_VALUE (uaddr))
arch/s390/include/asm/page.h
Quoted 10 lines
arch/s390/include/asm/page.h +10
-0+ goto out; + vma =find_vma (gmap->mm, uaddr); +if (!vma) + goto out; +/* +* Secure pages cannot be huge and userspace should not combine both. +* In case userspace does it anyway this will result in an -EFAULT for +* the unpack. The guest is thus never reaching secure mode. If +* userspace is playing dirty tricky with mapping huge pages later +* on this will result in a segmenation fault.
s/segmenation/segmentation/
Quoted 18 lines
arch/s390/include/asm/page.h +18
-0+*/ +if (is_vm_hugetlb_page (vma)) + goto out; + + rc = -ENXIO ; + page =follow_page (vma, uaddr,FOLL_WRITE ); +if (IS_ERR_OR_NULL (page)) + goto out; + +lock_page (page); + ptep =get_locked_pte (gmap->mm, uaddr, &ptelock); + rc =make_secure_pte (ptep, uaddr, page, uvcb); +pte_unmap_unlock (ptep, ptelock); +unlock_page (page); +out: +up_read (&gmap->mm->mmap_sem); + +if (rc == -EAGAIN ) {
arch/s390/include/asm/page.h
Quoted 10 lines
arch/s390/include/asm/page.h +10
-0+wait_on_page_writeback (page); + }else if (rc == -EBUSY ) { +/* +* If we have tried a local drain and the page refcount +* still does not match our expected safe value, try with a +* system wide drain. This is needed if the pagevecs holding +* the page are on a different CPU. +*/ +if (local_drain) { +lru_add_drain_all ();
I do wonder if that is valid to be called with all the locks at this point.
arch/s390/include/asm/page.h
Quoted 11 lines
arch/s390/include/asm/page.h +11
-0+/* We give up here, and let the caller try again */ +return -EAGAIN ; + } +/* +* We are here if the page refcount does not match the +* expected safe value. The main culprits are usually +* pagevecs. With lru_add_drain() we drain the pagevecs +* on the local CPU so that hopefully the refcount will +* reach the expected safe value. +*/ +lru_add_drain ();
dito ...
Quoted 17 lines
arch/s390/include/asm/page.h +17
-0+ local_drain =1 ; +/* And now we try again immediately after draining */ + goto again; + }else if (rc == -ENXIO ) { +if (gmap_fault (gmap, gaddr,FAULT_FLAG_WRITE )) +return -EFAULT ; +return -EAGAIN ; + } +return rc; +} +EXPORT_SYMBOL_GPL (gmap_make_secure); + +int gmap_convert_to_secure (struct gmap *gmap,unsigned long gaddr) +{ +struct uv_cb_cts uvcb = { + .header.cmd =UVC_CMD_CONV_TO_SEC_STOR , + .header.len = sizeof(uvcb),
arch/s390/include/asm/page.h
Quoted 10 lines
arch/s390/include/asm/page.h +10
-0+ .guest_handle = gmap->guest_handle, + .gaddr = gaddr, + }; + +return gmap_make_secure (gmap, gaddr, &uvcb); +} +EXPORT_SYMBOL_GPL (gmap_convert_to_secure); + +/** +* To be called with the page locked or with an extra reference!
Can we have races here? (IOW, two callers concurrently for the same page)
Quoted 16 lines
+ */
arch/s390/include/asm/page.h +15
-0+int arch_make_page_accessible (struct page *page) +{ +int rc =0 ; + +/* Hugepage cannot be protected, so nothing to do */ +if (PageHuge (page)) +return 0 ; + +/* +* PG_arch_1 is used in 3 places: +* 1. for kernel page tables during early boot +* 2. for storage keys of huge pages and KVM +* 3. As an indication that this page might be secure. This can +* overindicate, e.g. we set the bit before calling +* convert_to_secure.
arch/s390/include/asm/page.h
Quoted 10 lines
arch/s390/include/asm/page.h +10
-0+* As secure pages are never huge, all 3 variants can co-exists. +*/ +if (!test_bit (PG_arch_1, &page->flags)) +return 0 ; + + rc =uv_pin_shared (page_to_phys (page)); +if (!rc) { +clear_bit (PG_arch_1, &page->flags); +return 0 ; + }
Overall, looks sane to me. (I am mostly concerned about possible races, e.g., when two gmaps would be created for a single VM and nasty stuff be done with them). But yeah, I guess you guys thought about this ;)
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v2 05/42] s390/mm: provide memory management functions for protected KVM guests
Quoted 17 lines · David Hildenbrand
arch/s390/include/asm/page.h static inline int devmem_is_allowed(unsigned long pfn) · line 160
Quoted 13 lines
arch/s390/include/asm/page.h +5
-0@@ -153,6 +153,11 @@ static inline int devmem_is_allowed(unsigned long pfn)#define HAVE_ARCH_FREE_PAGE #define HAVE_ARCH_ALLOC_PAGE +#if IS_ENABLED (CONFIG_PGSTE ) +int arch_make_page_accessible (struct page *page); +#define HAVE_ARCH_MAKE_PAGE_ACCESSIBLE +#endif +Feels like this should have been one of the (CONFIG_)ARCH_HAVE_XXX thingies defined via kconfig instead.
Quoted 3 lines
E.g., like (CONFIG_)HAVE_ARCH_TRANSPARENT_HUGEPAGE
[...]
This looks more or less like HAVE_ARCH_ALLOC_PAGE. You will find both variants.
I think I will leave it that way for now until we need it to be a config or the mm maintainers have a preference.
Quoted 20 lines
Quoted 20 lines
arch/s390/include/asm/page.h +19
-0+ +/* +* Requests the Ultravisor to encrypt a guest page and make it +* accessible to the host for paging (export). +* +* @paddr: Absolute host address of page to be exported +*/ +int uv_convert_from_secure (unsigned long paddr) +{ +struct uv_cb_cfs uvcb = { + .header.cmd =UVC_CMD_CONV_FROM_SEC_STOR , + .header.len =sizeof (uvcb), + .paddr = paddr + }; + +if (uv_call (0 , (u64)&uvcb)) +return -EINVAL ; +return 0 ; +}
Quoted 8 lines
arch/s390/include/asm/page.h
Quoted 6 lines
arch/s390/include/asm/page.h +6
-0+ +/* +* Calculate the expected ref_count for a page that would otherwise have no +* further pins. This was cribbed from similar functions in other places in +* the kernel, but with some slight modifications. We know that a secure +* page can not be a huge page for example. s/ca not cannot/
ack.
Quoted 52 lines
Quoted 52 lines
+ */
arch/s390/include/asm/page.h +50
-0+static int expected_page_refs (struct page *page) +{ +int res; + + res =page_mapcount (page); +if (PageSwapCache (page)) { + res++; + }else if (page_mapping (page)) { + res++; +if (page_has_private (page)) + res++; + } +return res; +} + +static int make_secure_pte (pte_t *ptep,unsigned long addr, +struct page *exp_page,struct uv_cb_header *uvcb) +{ +pte_t entry =READ_ONCE (*ptep); +struct page *page; +int expected, rc =0 ; + +if (!pte_present (entry)) +return -ENXIO ; +if (pte_val (entry) & _PAGE_INVALID) +return -ENXIO ; + + page =pte_page (entry); +if (page != exp_page) +return -ENXIO ; +if (PageWriteback (page)) +return -EAGAIN ; + expected =expected_page_refs (page); +if (!page_ref_freeze (page, expected)) +return -EBUSY ; +set_bit (PG_arch_1, &page->flags); + rc =uv_call (0 , (u64 )uvcb); +page_ref_unfreeze (page, expected); +/* Return -ENXIO if the page was not mapped, -EINVAL otherwise */ +if (rc) + rc = uvcb->rc ==0x10a ? -ENXIO : -EINVAL ; +return rc; +} + +/* +* Requests the Ultravisor to make a page accessible to a guest. +* If it's brought in the first time, it will be cleared. If +* it has been exported before, it will be decrypted and integrity +* checked. +*/
Quoted 8 lines
arch/s390/include/asm/page.h
Quoted 6 lines
arch/s390/include/asm/page.h +6
-0+int gmap_make_secure (struct gmap *gmap,unsigned long gaddr,void *uvcb) +{ +struct vm_area_struct *vma; +unsigned long uaddr; +struct page *page; +int rc, local_drain =0 ;
local_draincould have been a bool.
ack
Quoted 14 lines
Quoted 14 lines
arch/s390/include/asm/page.h +13
-0+spinlock_t *ptelock; +pte_t *ptep; + +again: + rc = -EFAULT ; +down_read (&gmap->mm->mmap_sem); + + uaddr =__gmap_translate (gmap, gaddr); +if (IS_ERR_VALUE (uaddr)) + goto out; + vma =find_vma (gmap->mm, uaddr); +if (!vma) + goto out;
Quoted 8 lines
arch/s390/include/asm/page.h
Quoted 6 lines
arch/s390/include/asm/page.h +6
-0+/* +* Secure pages cannot be huge and userspace should not combine both. +* In case userspace does it anyway this will result in an -EFAULT for +* the unpack. The guest is thus never reaching secure mode. If +* userspace is playing dirty tricky with mapping huge pages later +* on this will result in a segmenation fault. s/segmenation/segmentation/
ack.
Quoted 23 lines
Quoted 23 lines
arch/s390/include/asm/page.h +22
-0+*/ +if (is_vm_hugetlb_page (vma)) + goto out; + + rc = -ENXIO ; + page =follow_page (vma, uaddr,FOLL_WRITE ); +if (IS_ERR_OR_NULL (page)) + goto out; + +lock_page (page); + ptep =get_locked_pte (gmap->mm, uaddr, &ptelock); + rc =make_secure_pte (ptep, uaddr, page, uvcb); +pte_unmap_unlock (ptep, ptelock); +unlock_page (page); +out: +up_read (&gmap->mm->mmap_sem); + +if (rc == -EAGAIN ) { +wait_on_page_writeback (page); + }else if (rc == -EBUSY ) { +/* +* If we have tried a local drain and the page refcount
Quoted 8 lines
arch/s390/include/asm/page.h
Quoted 6 lines
arch/s390/include/asm/page.h +6
-0+* still does not match our expected safe value, try with a +* system wide drain. This is needed if the pagevecs holding +* the page are on a different CPU. +*/ +if (local_drain) { +lru_add_drain_all ();I do wonder if that is valid to be called with all the locks at this point.
This function uses per cpu workers and needs no other locks. Also verified with lockdep.
Quoted 14 lines
arch/s390/include/asm/page.h
Quoted 12 lines
arch/s390/include/asm/page.h +11
-0+/* We give up here, and let the caller try again */ +return -EAGAIN ; + } +/* +* We are here if the page refcount does not match the +* expected safe value. The main culprits are usually +* pagevecs. With lru_add_drain() we drain the pagevecs +* on the local CPU so that hopefully the refcount will +* reach the expected safe value. +*/ +lru_add_drain ();dito ...
dito.
Quoted 22 lines
Quoted 22 lines
arch/s390/include/asm/page.h +21
-0+ local_drain =1 ; +/* And now we try again immediately after draining */ + goto again; + }else if (rc == -ENXIO ) { +if (gmap_fault (gmap, gaddr,FAULT_FLAG_WRITE )) +return -EFAULT ; +return -EAGAIN ; + } +return rc; +} +EXPORT_SYMBOL_GPL (gmap_make_secure); + +int gmap_convert_to_secure (struct gmap *gmap,unsigned long gaddr) +{ +struct uv_cb_cts uvcb = { + .header.cmd =UVC_CMD_CONV_TO_SEC_STOR , + .header.len =sizeof (uvcb), + .guest_handle = gmap->guest_handle, + .gaddr = gaddr, + }; +
Quoted 8 lines
arch/s390/include/asm/page.h
Quoted 6 lines
arch/s390/include/asm/page.h +6
-0+return gmap_make_secure (gmap, gaddr, &uvcb); +} +EXPORT_SYMBOL_GPL (gmap_convert_to_secure); + +/** +* To be called with the page locked or with an extra reference! Can we have races here? (IOW, two callers concurrently for the same page)
That would be fine and is part of the design. The ultravisor calls will either make the page accessible or will be a (mostly) no-op. In fact, we allow for slight over-indication of "needs to be exported"
What about:
/*
* To be called with the page locked or with an extra reference! This will
* prevent gmap_make_secure from touching the page concurrently. Having 2
* parallel make_page_accessible is fine, as the UV calls will become a
* no-op if the page is already exported.
*/
Quoted 31 lines
Quoted 17 lines
+ */
arch/s390/include/asm/page.h +15
-0+int arch_make_page_accessible (struct page *page) +{ +int rc =0 ; + +/* Hugepage cannot be protected, so nothing to do */ +if (PageHuge (page)) +return 0 ; + +/* +* PG_arch_1 is used in 3 places: +* 1. for kernel page tables during early boot +* 2. for storage keys of huge pages and KVM +* 3. As an indication that this page might be secure. This can +* overindicate, e.g. we set the bit before calling +* convert_to_secure. arch/s390/include/asm/page.h
Quoted 10 lines
arch/s390/include/asm/page.h +10
-0+* As secure pages are never huge, all 3 variants can co-exists. +*/ +if (!test_bit (PG_arch_1, &page->flags)) +return 0 ; + + rc =uv_pin_shared (page_to_phys (page)); +if (!rc) { +clear_bit (PG_arch_1, &page->flags); +return 0 ; + }Overall, looks sane to me. (I am mostly concerned about possible races, e.g., when two gmaps would be created for a single VM and nasty stuff be done with them). But yeah, I guess you guys thought about this ;)
Re: [PATCH v2 05/42] s390/mm: provide memory management functions for protected KVM guests
Quoted 8 lines
Quoted 5 lines
arch/s390/kernel/uv.c void adjust_to_uv_max(unsigned long *vmax) · line 250
Quoted 3 lines
arch/s390/kernel/uv.c +2
-0+if (local_drain) { +lru_add_drain_all ();I do wonder if that is valid to be called with all the locks at this point.
This function uses per cpu workers and needs no other locks. Also verified with lockdep.
Okay, perfect.
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
+/**
+ * To be called with the page locked or with an extra reference!Can we have races here? (IOW, two callers concurrently for the same page)
That would be fine and is part of the design. The ultravisor calls will either make the page accessible or will be a (mostly) no-op. In fact, we allow for slight over-indication of "needs to be exported"
Quoted 8 lines
What about:
/*
* To be called with the page locked or with an extra reference! This will
* preventgmap_make_securefrom touching the page concurrently. Having 2
* parallelmake_page_accessibleis fine, as the UV calls will become a
* no-op if the page is already exported.
*/
Yes, much clearer, thanks!
Signature · 3 lines
Thanks, David / dhildenb
PATCH v2 6/42 s390/mm: add (non)secure page access exceptions handlers
In reply to Christian BorntraegerFrom: Vasily Gorbik <[email protected]>
Add exceptions handlers performing transparent transition of non-secure pages to secure (import) upon guest access and secure pages to non-secure (export) upon hypervisor access.
--- arch/s390/kernel/pgm_check.S | 4 +- arch/s390/mm/fault.c | 78 ++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 2 deletions(-)
arch/s390/kernel/pgm_check.S +2 -2
@@ -78,8 +78,8 @@ PGM_CHECK(do_dat_exception) /* 39 */ PGM_CHECK(do_dat_exception) /* 3a */ PGM_CHECK(do_dat_exception) /* 3b */ PGM_CHECK_DEFAULT /* 3c */ -PGM_CHECK_DEFAULT /* 3d */ -PGM_CHECK_DEFAULT /* 3e */ +PGM_CHECK(do_secure_storage_access) /* 3d */ +PGM_CHECK(do_non_secure_storage_access) /* 3e */ PGM_CHECK_DEFAULT /* 3f */ PGM_CHECK(monitor_event_exception) /* 40 */ PGM_CHECK_DEFAULT /* 41 */
arch/s390/mm/fault.c +78 -0
87 lines not on this page · raw message
Signature · 1 line
2.25.0
PATCH v2 7/42 KVM: s390: protvirt: Add UV debug trace
In reply to Christian BorntraegerFrom: Janosch Frank <[email protected]>
Let's have some debug traces which stay around for longer than the guest.
--- arch/s390/kvm/kvm-s390.c | 9 ++++++++- arch/s390/kvm/kvm-s390.h | 11 +++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-)
arch/s390/kvm/kvm-s390.c +8 -1
@@ -220,6 +220,7 @@ static struct kvm_s390_vm_cpu_subfunc kvm_s390_available_subfunc;static struct gmap_notifier gmap_notifier;static struct gmap_notifier vsie_gmap_notifier;debug_info_t *kvm_s390_dbf; +debug_info_t *kvm_s390_dbf_uv;/* Section: not file related */ int kvm_arch_hardware_enable (void )
@@ -460,7 +461,12 @@ int kvm_arch_init(void *opaque)if (!kvm_s390_dbf)return -ENOMEM ; -if (debug_register_view (kvm_s390_dbf, &debug_sprintf_view)) + kvm_s390_dbf_uv =debug_register ("kvm-uv" ,32 ,1 ,7 *sizeof (long )); +if (!kvm_s390_dbf_uv) + goto out; + +if (debug_register_view (kvm_s390_dbf, &debug_sprintf_view) || +debug_register_view (kvm_s390_dbf_uv, &debug_sprintf_view)) goto out;kvm_s390_cpu_feat_init ();
@@ -487,6 +493,7 @@ void kvm_arch_exit(void) {kvm_s390_gib_destroy ();debug_unregister (kvm_s390_dbf); +debug_unregister (kvm_s390_dbf_uv); }/* Section: device related */
arch/s390/kvm/kvm-s390.h +11 -0
@@ -25,6 +25,17 @@#define IS_ITDB_VALID (vcpu) ((*(char *)vcpu->arch.sie_block->itdba == TDB_FORMAT1))extern debug_info_t *kvm_s390_dbf; +extern debug_info_t *kvm_s390_dbf_uv; + +#define KVM_UV_EVENT(d_kvm, d_loglevel, d_string, d_args...)\ +do { \ + debug_sprintf_event((d_kvm)->arch.dbf, d_loglevel, d_string "\n", \ + d_args); \ + debug_sprintf_event(kvm_s390_dbf_uv, d_loglevel, \ + "%d: " d_string "\n", (d_kvm)->userspace_pid, \ + d_args); \ +} while (0) + #define KVM_EVENT(d_loglevel, d_string, d_args...)\ do { \ debug_sprintf_event(kvm_s390_dbf, d_loglevel, d_string "\n", \
Signature · 1 line
2.25.0
Re: [PATCH v2 07/42] KVM: s390: protvirt: Add UV debug trace
Quoted 27 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
Let's have some debug traces which stay around for longer than the guest.
Signed-off-by Janosch Frank <[email protected]>Reviewed-by Cornelia Huck <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/kvm/kvm-s390.c | 9 ++++++++- arch/s390/kvm/kvm-s390.h | 11 +++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-)arch/s390/kvm/kvm-s390.c +1
-0@@ -220,6 +220,7 @@ static struct kvm_s390_vm_cpu_subfunc kvm_s390_available_subfunc;static struct gmap_notifier gmap_notifier;static struct gmap_notifier vsie_gmap_notifier;debug_info_t *kvm_s390_dbf; +debug_info_t *kvm_s390_dbf_uv;/* Section: not file related */ int kvm_arch_hardware_enable (void )
arch/s390/kvm/kvm-s390.c int kvm_arch_init(void *opaque) · line 466
Quoted 7 lines
arch/s390/kvm/kvm-s390.c +3
-1@@ -460,7 +461,12 @@ int kvm_arch_init(void *opaque)if (!kvm_s390_dbf)return -ENOMEM ; -if (debug_register_view (kvm_s390_dbf, &debug_sprintf_view)) + kvm_s390_dbf_uv =debug_register ("kvm-uv" ,32 ,1 ,7 *sizeof (long )); +if (!kvm_s390_dbf_uv) + goto out;
Signature · 3 lines
Thanks, David / dhildenb
PATCH v2 8/42 KVM: s390: add new variants of UV CALL
In reply to Christian BorntraegerFrom: Janosch Frank <[email protected]>
This adds two new helper functions for doing UV CALLs.
The first variant handles UV CALLs that might have longer busy conditions or just need longer when doing partial completion. We should schedule when necessary.
The second variant handles UV CALLs that only need the handle but have no payload (e.g. destroying a VM). We can provide a simple wrapper for those.
--- arch/s390/include/asm/uv.h | 65 +++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 5 deletions(-)
arch/s390/include/asm/uv.h +60 -5
@@ -14,6 +14,7 @@#include <linux/types.h> #include <linux/errno.h> #include <linux/bug.h> +#include <linux/sched.h> #include <asm/page.h> #include <asm/gmap.h>
@@ -91,6 +92,19 @@ struct uv_cb_cfs {u64 paddr; } __packed__aligned(8) ; +/* +* A common UV call struct for calls that take no payload +* Examples: +* Destroy cpu/config +* Verify +*/ +struct uv_cb_nodata { +struct uv_cb_header header; +u64 reserved08[2 ]; +u64 handle; +u64 reserved20[4 ]; +} __packed__aligned(8) ; +struct uv_cb_share {struct uv_cb_header header;u64 reserved08[3 ];
@@ -98,21 +112,62 @@ struct uv_cb_share {u64 reserved28; } __packed__aligned(8) ; -static inline int uv_call (unsigned long r1,unsigned long r2) +static inline int __uv_call (unsigned long r1,unsigned long r2) {int cc; asmvolatile ( -"0: .insn rrf,0xB9A40000,%[r1],%[r2],0,0\n" -" brc 3,0b\n" -" ipm %[cc]\n" -" srl %[cc],28\n" +" .insn rrf,0xB9A40000,%[r1],%[r2],0,0\n" +" ipm %[cc]\n" +" srl %[cc],28\n" : [cc]"=d" (cc) : [r1]"a" (r1), [r2]"a" (r2) :"memory" ,"cc" );return cc; } +static inline int uv_call (unsigned long r1,unsigned long r2) +{ +int cc; + +do { + cc =__uv_call (r1, r2); + }while (cc >1 ); +return cc; +} + +/* Low level uv_call that avoids stalls for long running busy conditions */ +static inline int uv_call_sched (unsigned long r1,unsigned long r2) +{ +int cc; + +do { + cc =__uv_call (r1, r2); +cond_resched (); + }while (cc >1 ); +return cc; +} + +/* +* special variant of uv_call that only transports the cpu or guest +* handle and the command, like destroy or verify. +*/ +static inline int uv_cmd_nodata (u64 handle,u16 cmd,u16 *rc,u16 *rrc) +{ +struct uv_cb_nodata uvcb = { + .header.cmd = cmd, + .header.len =sizeof (uvcb), + .handle = handle, + }; +int cc; + +WARN (!handle,"No handle provided to Ultravisor call cmd %x\n" , cmd); + cc =uv_call_sched (0 , (u64)&uvcb); + *rc = uvcb.header.rc; + *rrc = uvcb.header.rrc; +return cc ? -EINVAL :0 ; +} +struct uv_info {unsigned long inst_calls_list[4 ];unsigned long uv_base_stor_len;
Signature · 1 line
2.25.0
Re: [PATCH v2 08/42] KVM: s390: add new variants of UV CALL
Quoted 112 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
This adds two new helper functions for doing UV CALLs.
The first variant handles UV CALLs that might have longer busy conditions or just need longer when doing partial completion. We should schedule when necessary.
The second variant handles UV CALLs that only need the handle but have no payload (e.g. destroying a VM). We can provide a simple wrapper for those.
Signed-off-by Janosch Frank <[email protected]>Reviewed-by Thomas Huth <[email protected]>Reviewed-by Cornelia Huck <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/include/asm/uv.h | 65 +++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 5 deletions(-)arch/s390/include/asm/uv.h +53
-5@@ -14,6 +14,7 @@#include <linux/types.h> #include <linux/errno.h> #include <linux/bug.h> +#include <linux/sched.h> #include <asm/page.h> #include <asm/gmap.h> @@ -91,6 +92,19 @@ struct uv_cb_cfs {u64 paddr; } __packed__aligned(8) ; +/* +* A common UV call struct for calls that take no payload +* Examples: +* Destroy cpu/config +* Verify +*/ +struct uv_cb_nodata { +struct uv_cb_header header; +u64 reserved08[2 ]; +u64 handle; +u64 reserved20[4 ]; +} __packed__aligned(8) ; +struct uv_cb_share {struct uv_cb_header header;u64 reserved08[3 ];@@ -98,21 +112,62 @@ struct uv_cb_share {u64 reserved28; } __packed__aligned(8) ; -static inline int uv_call (unsigned long r1,unsigned long r2) +static inline int __uv_call (unsigned long r1,unsigned long r2) {int cc; asmvolatile ( -"0: .insn rrf,0xB9A40000,%[r1],%[r2],0,0\n" -" brc 3,0b\n" -" ipm %[cc]\n" -" srl %[cc],28\n" +" .insn rrf,0xB9A40000,%[r1],%[r2],0,0\n" +" ipm %[cc]\n" +" srl %[cc],28\n" : [cc]"=d" (cc) : [r1]"a" (r1), [r2]"a" (r2) :"memory" ,"cc" );return cc; } +static inline int uv_call (unsigned long r1,unsigned long r2) +{ +int cc; + +do { + cc =__uv_call (r1, r2); + }while (cc >1 ); +return cc; +} + +/* Low level uv_call that avoids stalls for long running busy conditions */ +static inline int uv_call_sched (unsigned long r1,unsigned long r2) +{ +int cc; + +do { + cc =__uv_call (r1, r2); +cond_resched (); + }while (cc >1 ); +return cc; +} + +/* +* special variant of uv_call that only transports the cpu or guest +* handle and the command, like destroy or verify. +*/ +static inline int uv_cmd_nodata (u64 handle,u16 cmd,u16 *rc,u16 *rrc) +{ +struct uv_cb_nodata uvcb = { + .header.cmd = cmd, + .header.len =sizeof (uvcb), + .handle = handle, + }; +int cc; +
arch/s390/include/asm/uv.h struct uv_cb_share { · line 173
Quoted 10 lines
arch/s390/include/asm/uv.h +7
-0+WARN (!handle,"No handle provided to Ultravisor call cmd %x\n" , cmd); + cc =uv_call_sched (0 , (u64)&uvcb); + *rc = uvcb.header.rc; + *rrc = uvcb.header.rrc; +return cc ? -EINVAL :0 ; +} +struct uv_info {unsigned long inst_calls_list[4 ];unsigned long uv_base_stor_len;
Signature · 3 lines
Thanks, David / dhildenb
PATCH v2 9/42 KVM: s390: protvirt: Add initial vm and cpu lifecycle handling
In reply to Christian BorntraegerFrom: Janosch Frank <[email protected]>
This contains 3 main changes:
1. changes in SIE control block handling for secure guests
2. helper functions for create/destroy/unpack secure guests
3. KVM_S390_PV_COMMAND ioctl to allow userspace dealing with secure machines
--- arch/s390/include/asm/kvm_host.h | 24 ++- arch/s390/include/asm/uv.h | 69 ++++++++ arch/s390/kvm/Makefile | 2 +- arch/s390/kvm/kvm-s390.c | 202 +++++++++++++++++++++++- arch/s390/kvm/kvm-s390.h | 27 ++++ arch/s390/kvm/pv.c | 262 +++++++++++++++++++++++++++++++ include/uapi/linux/kvm.h | 35 +++++ 7 files changed, 617 insertions(+), 4 deletions(-) create mode 100644 arch/s390/kvm/pv.c
arch/s390/include/asm/kvm_host.h +22 -2
@@ -160,7 +160,13 @@ struct kvm_s390_sie_block {__u8 reserved08[4 ];/* 0x0008 */ #define PROG_IN_SIE (1<<0)__u32 prog0c;/* 0x000c */ -__u8 reserved10[16 ];/* 0x0010 */ +union { +__u8 reserved10[16 ];/* 0x0010 */ +struct { +__u64 pv_handle_cpu; +__u64 pv_handle_config; + }; + };#define PROG_BLOCK_SIE (1<<0)#define PROG_REQUEST (1<<1)atomic_t prog20;/* 0x0020 */
@@ -233,7 +239,7 @@ struct kvm_s390_sie_block {#define ECB3_RI 0x01__u8 ecb3;/* 0x0063 */ __u32 scaol;/* 0x0064 */ -__u8 reserved68;/* 0x0068 */ +__u8 sdf;/* 0x0068 */ __u8 epdx;/* 0x0069 */ __u8 reserved6a[2 ];/* 0x006a */ __u32 todpr;/* 0x006c */
@@ -645,6 +651,11 @@ struct kvm_guestdbg_info_arch {unsigned long last_bp; }; +struct kvm_s390_pv_vcpu { +u64 handle; +unsigned long stor_base; +}; +struct kvm_vcpu_arch {struct kvm_s390_sie_block *sie_block;/* if vsie is active, currently executed shadow sie control block */
@@ -673,6 +684,7 @@ struct kvm_vcpu_arch {__u64 cputm_start;bool gs_enabled;bool skey_enabled; +struct kvm_s390_pv_vcpu pv; };struct kvm_vm_stat {
@@ -843,6 +855,13 @@ struct kvm_s390_gisa_interrupt {DECLARE_BITMAP (kicked_mask,KVM_MAX_VCPUS ); }; +struct kvm_s390_pv { +u64 handle; +u64 guest_len; +unsigned long stor_base; +void *stor_var; +}; +struct kvm_arch {void *sca;int use_esca;
@@ -878,6 +897,7 @@ struct kvm_arch{DECLARE_BITMAP (cpu_feat,KVM_S390_VM_CPU_FEAT_NR_BITS );DECLARE_BITMAP (idle_mask,KVM_MAX_VCPUS );struct kvm_s390_gisa_interrupt gisa_int; +struct kvm_s390_pv pv; };#define KVM_HVA_ERR_BAD (-1UL)
arch/s390/include/asm/uv.h +69 -0
126 lines not on this page · raw message
arch/s390/kvm/Makefile +1 -1
@@ -9,6 +9,6 @@ common-objs = $(KVM)/kvm_main.o $(KVM)/eventfd.o $(KVM)/async_pf.o $(KVM)/irqch ccflags-y := -Ivirt/kvm -Iarch/s390/kvm kvm-objs := $(common-objs) kvm-s390.o intercept.o interrupt.o priv.o sigp.o -kvm-objs += diag.o gaccess.o guestdbg.o vsie.o +kvm-objs += diag.o gaccess.o guestdbg.o vsie.o pv.o obj-$(CONFIG_KVM) += kvm.o
arch/s390/kvm/kvm-s390.c +201 -1
285 lines not on this page · raw message
arch/s390/kvm/kvm-s390.h +27 -0
@@ -207,6 +207,33 @@ static inline int kvm_s390_user_cpu_state_ctrl(struct kvm *kvm)return kvm->arch.user_cpu_state_ctrl !=0 ; } +/* implemented in pv.c */ +void kvm_s390_pv_dealloc_vm (struct kvm *kvm); +int kvm_s390_pv_alloc_vm (struct kvm *kvm); +int kvm_s390_pv_create_vm (struct kvm *kvm,u16 *rc,u16 *rrc); +int kvm_s390_pv_create_cpu (struct kvm_vcpu *vcpu,u16 *rc,u16 *rrc); +int kvm_s390_pv_destroy_vm (struct kvm *kvm,u16 *rc,u16 *rrc); +int kvm_s390_pv_destroy_cpu (struct kvm_vcpu *vcpu,u16 *rc,u16 *rrc); +int kvm_s390_pv_set_sec_parms (struct kvm *kvm,void *hdr,u64 length,u16 *rc, +u16 *rrc); +int kvm_s390_pv_unpack (struct kvm *kvm,unsigned long addr,unsigned long size, +unsigned long tweak,u16 *rc,u16 *rrc); + +static inline bool kvm_s390_pv_is_protected (struct kvm *kvm) +{ +return !!kvm->arch.pv.handle; +} + +static inline u64 kvm_s390_pv_handle (struct kvm *kvm) +{ +return kvm->arch.pv.handle; +} + +static inline u64 kvm_s390_pv_handle_cpu (struct kvm_vcpu *vcpu) +{ +return vcpu->arch.pv.handle; +} +/* implemented in interrupt.c */ int kvm_s390_handle_wait (struct kvm_vcpu *vcpu);void kvm_s390_vcpu_wakeup (struct kvm_vcpu *vcpu);
arch/s390/kvm/pv.c new file +262 -0
262 lines not on this page · raw message
include/uapi/linux/kvm.h +35 -0
@@ -1010,6 +1010,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_ARM_NISV_TO_USER 177#define KVM_CAP_ARM_INJECT_EXT_DABT 178#define KVM_CAP_S390_VCPU_RESETS 179 +#define KVM_CAP_S390_PROTECTED 181#ifdef KVM_CAP_IRQ_ROUTING
@@ -1478,6 +1479,40 @@ struct kvm_enc_region {#define KVM_S390_NORMAL_RESET _IO(KVMIO, 0xc3)#define KVM_S390_CLEAR_RESET _IO(KVMIO, 0xc4) +struct kvm_s390_pv_sec_parm { +__u64 origin; +__u64 length; +}; + +struct kvm_s390_pv_unp { +__u64 addr; +__u64 size; +__u64 tweak; +}; + +enum pv_cmd_id { +KVM_PV_VM_CREATE , +KVM_PV_VM_DESTROY , +KVM_PV_VM_SET_SEC_PARMS , +KVM_PV_VM_UNPACK , +KVM_PV_VM_VERIFY , +KVM_PV_VCPU_CREATE , +KVM_PV_VCPU_DESTROY , +}; + +struct kvm_pv_cmd { +__u32 cmd;/* Command to be executed */ +__u16 rc;/* Ultravisor return code */ +__u16 rrc;/* Ultravisor return reason code */ +__u64 data;/* Data or address */ +__u32 flags;/* flags for future extensions. Must be 0 for now */ +__u32 reserved[3 ]; +}; + +/* Available with KVM_CAP_S390_PROTECTED */ +#define KVM_S390_PV_COMMAND _IOWR(KVMIO, 0xc5, struct kvm_pv_cmd) +#define KVM_S390_PV_COMMAND_VCPU _IOWR(KVMIO, 0xc6, struct kvm_pv_cmd) +/* Secure Encrypted Virtualization command */ enum sev_cmd_id {/* Guest initialization commands */
Signature · 1 line
2.25.0
Re: [PATCH v2 09/42] KVM: s390: protvirt: Add initial vm and cpu lifecycle handling
[...]
arch/s390/kvm/kvm-s390.c static int kvm_s390_set_cmma_bits(struct kvm *kvm, · line 2183
Quoted 11 lines
arch/s390/kvm/kvm-s390.c +10
-0+static int kvm_s390_handle_pv (struct kvm *kvm,struct kvm_pv_cmd *cmd) +{ +int r =0 ; +void __user *argp = (void __user *)cmd->data; + +switch (cmd->cmd) { +case KVM_PV_VM_CREATE : { + r = -EINVAL ; +if (kvm_s390_pv_is_protected (kvm)) +break ;
Isn't this racy? I think there has to be a way to make sure the PV state can't change. Is there any and I am missing something obvious? (is suspect we need the kvm->lock)
Quoted 15 lines
arch/s390/kvm/kvm-s390.c +15
-0+ + r =kvm_s390_pv_alloc_vm (kvm); +if (r) +break ; + +mutex_lock (&kvm->lock); +kvm_s390_vcpu_block_all (kvm); +/* FMT 4 SIE needs esca */ + r =sca_switch_to_extended (kvm); +if (r) { +kvm_s390_pv_dealloc_vm (kvm); +kvm_s390_vcpu_unblock_all (kvm); +mutex_unlock (&kvm->lock); +break ; + }
arch/s390/kvm/kvm-s390.c static int kvm_s390_set_cmma_bits(struct kvm *kvm, · line 2208
Quoted 10 lines
arch/s390/kvm/kvm-s390.c +10
-0+ r =kvm_s390_pv_create_vm (kvm, &cmd->rc, &cmd->rrc); +kvm_s390_vcpu_unblock_all (kvm); +mutex_unlock (&kvm->lock); +break ; + } +case KVM_PV_VM_DESTROY : { + r = -EINVAL ; +if (!kvm_s390_pv_is_protected (kvm)) +break ; +
dito
arch/s390/kvm/kvm-s390.c static int kvm_s390_set_cmma_bits(struct kvm *kvm, · line 2219
Quoted 11 lines
arch/s390/kvm/kvm-s390.c +11
-0+/* All VCPUs have to be destroyed before this call. */ +mutex_lock (&kvm->lock); +kvm_s390_vcpu_block_all (kvm); + r =kvm_s390_pv_destroy_vm (kvm, &cmd->rc, &cmd->rrc); +if (!r) +kvm_s390_pv_dealloc_vm (kvm); +kvm_s390_vcpu_unblock_all (kvm); +mutex_unlock (&kvm->lock); +break ; + } +case KVM_PV_VM_SET_SEC_PARMS : {
I'd name this "KVM_PV_VM_SET_PARMS" instead.
arch/s390/kvm/kvm-s390.c static int kvm_s390_set_cmma_bits(struct kvm *kvm, · line 2226
Quoted 7 lines
arch/s390/kvm/kvm-s390.c +7
-0+struct kvm_s390_pv_sec_parm parms = {}; +void *hdr; + + r = -EINVAL ; +if (!kvm_s390_pv_is_protected (kvm)) +break ; +
dito
Quoted 20 lines
arch/s390/kvm/kvm-s390.c +20
-0+ r = -EFAULT ; +if (copy_from_user (&parms, argp,sizeof (parms))) +break ; + +/* Currently restricted to 8KB */ + r = -EINVAL ; +if (parms.length >PAGE_SIZE *2 ) +break ; + + r = -ENOMEM ; + hdr =vmalloc (parms.length); +if (!hdr) +break ; + + r = -EFAULT ; +if (!copy_from_user (hdr, (void __user *)parms.origin, + parms.length)) + r =kvm_s390_pv_set_sec_parms (kvm, hdr, parms.length, + &cmd->rc, &cmd->rrc); +
arch/s390/kvm/kvm-s390.c static int kvm_s390_set_cmma_bits(struct kvm *kvm, · line 2256
Quoted 10 lines
arch/s390/kvm/kvm-s390.c +10
-0+vfree (hdr); +break ; + } +case KVM_PV_VM_UNPACK : { +struct kvm_s390_pv_unp unp = {}; + + r = -EINVAL ; +if (!kvm_s390_pv_is_protected (kvm)) +break ; +
dito
arch/s390/kvm/kvm-s390.c static int kvm_s390_set_cmma_bits(struct kvm *kvm,
Quoted 11 lines
arch/s390/kvm/kvm-s390.c +11
-0+ r = -EFAULT ; +if (copy_from_user (&unp, argp,sizeof (unp))) +break ; + + r =kvm_s390_pv_unpack (kvm, unp.addr, unp.size, unp.tweak, + &cmd->rc, &cmd->rrc); +break ; + } +case KVM_PV_VM_VERIFY : { + r = -EINVAL ; + if (!kvm_s390_pv_is_protected(kvm))> + break;
dito
Quoted 96 lines
arch/s390/kvm/kvm-s390.c +46
-1+ + r =uv_cmd_nodata (kvm_s390_pv_handle (kvm), +UVC_CMD_VERIFY_IMG , &cmd->rc, &cmd->rrc); +KVM_UV_EVENT (kvm,3 ,"PROTVIRT VERIFY: rc %x rrc %x" , cmd->rc, + cmd->rrc); +break ; + } +default : +return -ENOTTY ; + } +return r; +} +long kvm_arch_vm_ioctl (struct file *filp,unsigned int ioctl,unsigned long arg) {@@ -2262,6 +2376,25 @@ long kvm_arch_vm_ioctl(struct file *filp,mutex_unlock (&kvm->slots_lock);break ; } +case KVM_S390_PV_COMMAND : { +struct kvm_pv_cmd args; + + r =0 ; +if (!is_prot_virt_host ()) { + r = -EINVAL ; +break ; + } +if (copy_from_user (&args, argp,sizeof (args))) { + r = -EFAULT ; +break ; + } + r =kvm_s390_handle_pv (kvm, &args); +if (copy_to_user (argp, &args,sizeof (args))) { + r = -EFAULT ; +break ; + } +break ; + }default : r = -ENOTTY ; }@@ -2525,6 +2658,8 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)void kvm_arch_vcpu_destroy (struct kvm_vcpu *vcpu) { +u16 rc, rrc; +VCPU_EVENT (vcpu,3 ,"%s" ,"free cpu" );trace_kvm_s390_destroy_vcpu (vcpu->vcpu_id);kvm_s390_clear_local_irqs (vcpu);@@ -2537,6 +2672,8 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)if (vcpu->kvm->arch.use_cmma)kvm_s390_vcpu_unsetup_cmma (vcpu); +if (kvm_s390_pv_handle_cpu (vcpu)) +kvm_s390_pv_destroy_cpu (vcpu, &rc, &rrc);free_page ((unsigned long )(vcpu->arch.sie_block)); }@@ -2558,10 +2695,15 @@ static void kvm_free_vcpus(struct kvm *kvm)void kvm_arch_destroy_vm (struct kvm *kvm) { +u16 rc, rrc;kvm_free_vcpus (kvm);sca_dispose (kvm); -debug_unregister (kvm->arch.dbf);kvm_s390_gisa_destroy (kvm); +if (kvm_s390_pv_is_protected (kvm)) { +kvm_s390_pv_destroy_vm (kvm, &rc, &rrc); +kvm_s390_pv_dealloc_vm (kvm); + } +debug_unregister (kvm->arch.dbf);free_page ((unsigned long )kvm->arch.sie_page2);if (!kvm_is_ucontrol (kvm))gmap_remove (kvm->arch.gmap);@@ -2657,6 +2799,9 @@ static int sca_switch_to_extended(struct kvm *kvm)unsigned int vcpu_idx;u32 scaol, scaoh; +if (kvm->arch.use_esca) +return 0 ; + new_sca =alloc_pages_exact (sizeof (*new_sca),GFP_KERNEL |__GFP_ZERO);if (!new_sca)return -ENOMEM ;@@ -2908,6 +3053,7 @@ static void kvm_s390_vcpu_setup_model(struct kvm_vcpu *vcpu)static int kvm_s390_vcpu_setup (struct kvm_vcpu *vcpu) {int rc =0 ; +u16 uvrc, uvrrc; atomic_set(&vcpu->arch.sie_block->cpuflags, CPUSTAT_ZARCH | CPUSTAT_SM |
arch/s390/kvm/kvm-s390.c static int kvm_s390_vcpu_setup(struct kvm_vcpu *vcpu) · line 3125
Quoted 5 lines
arch/s390/kvm/kvm-s390.c +2
-0@@ -2975,6 +3121,9 @@ static int kvm_s390_vcpu_setup(struct kvm_vcpu *vcpu)kvm_s390_vcpu_crypto_setup (vcpu); +if (kvm_s390_pv_is_protected (vcpu->kvm)) + rc =kvm_s390_pv_create_cpu (vcpu, &uvrc, &uvrrc);
With an explicit KVM_PV_VCPU_CREATE, this does not belong here. When hotplugging CPUs, user space has to do that manually. But as I said already, this user space API could be improved. (below)
Quoted 58 lines
arch/s390/kvm/kvm-s390.c +44
-0+return rc; }@@ -4352,6 +4501,38 @@ long kvm_arch_vcpu_async_ioctl(struct file *filp,return -ENOIOCTLCMD ; } +static int kvm_s390_handle_pv_vcpu (struct kvm_vcpu *vcpu, +struct kvm_pv_cmd *cmd) +{ +int r =0 ; + +if (!kvm_s390_pv_is_protected (vcpu->kvm)) +return -EINVAL ; + +if (cmd->flags) +return -EINVAL ; + +switch (cmd->cmd) { +case KVM_PV_VCPU_CREATE : { +if (kvm_s390_pv_handle_cpu (vcpu)) +return -EINVAL ; + + r =kvm_s390_pv_create_cpu (vcpu, &cmd->rc, &cmd->rrc); +break ; + } +case KVM_PV_VCPU_DESTROY : { +if (!kvm_s390_pv_handle_cpu (vcpu)) +return -EINVAL ; + + r =kvm_s390_pv_destroy_cpu (vcpu, &cmd->rc, &cmd->rrc); +break ; + } +default : + r = -ENOTTY ; + } +return r; +} +long kvm_arch_vcpu_ioctl (struct file *filp,unsigned int ioctl,unsigned long arg) {@@ -4493,6 +4674,25 @@ long kvm_arch_vcpu_ioctl(struct file *filp, irq_state.len);break ; } +case KVM_S390_PV_COMMAND_VCPU : { +struct kvm_pv_cmd args; + + r =0 ; +if (!is_prot_virt_host ()) { + r = -EINVAL ; +break ; + } +if (copy_from_user (&args, argp,sizeof (args))) { + r = -EFAULT ; +break ;
arch/s390/kvm/kvm-s390.c long kvm_arch_vcpu_ioctl(struct file *filp, · line 4697
Quoted 10 lines
arch/s390/kvm/kvm-s390.c +8
-0+ } + r =kvm_s390_handle_pv_vcpu (vcpu, &args); +if (copy_to_user (argp, &args,sizeof (args))) { + r = -EFAULT ; +break ; + } +break ; + }default : r = -ENOTTY ;
Can we please discuss why we can't
- Get rid of KVM_S390_PV_COMMAND_VCPU
- Do the allocation in KVM_PV_VM_CREATE
- Rename KVM_PV_VM_CREATE -> KVM_PV_ENABLE
- Rename KVM_PV_VM_DESTROY -> KVM_PV_DISABLE
This user space API is unnecessary complicated and confusing.
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v2 09/42] KVM: s390: protvirt: Add initial vm and cpu lifecycle handling
Quoted 16 lines · David Hildenbrand
[...]
Review
Quoted 11 lines
(quoted diff) +10
-0+static int kvm_s390_handle_pv(struct kvm *kvm, struct kvm_pv_cmd *cmd) +{ + int r = 0; + void __user *argp = (void __user *)cmd->data; + + switch (cmd->cmd) { + case KVM_PV_VM_CREATE: { + r = -EINVAL; + if (kvm_s390_pv_is_protected(kvm)) + break;Isn't this racy? I think there has to be a way to make sure the PV state can't change. Is there any and I am missing something obvious? (is suspect we need the
kvm->lock)
Yes, kvm->lock around kvm_s390_handle_pv is safer.
Something like
arch/s390/kvm/kvm-s390.c +2 -0
@@ -2422,7 +2422,9 @@ long kvm_arch_vm_ioctl(struct file *filp, r = -EFAULT ;break ; } +mutex_lock (&kvm->lock); r =kvm_s390_handle_pv (kvm, &args); +mutex_unlock (&kvm->lock);if (copy_to_user (argp, &args,sizeof (args))) { r = -EFAULT ;break ;
[...]
Quoted 3 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ case KVM_PV_VM_SET_SEC_PARMS: {I'd name this "
KVM_PV_VM_SET_PARMS" instead.
[...]
Quoted 10 lines
Review static int kvm_s390_vcpu_setup(struct kvm_vcpu *vcpu) · line 3125
Quoted 6 lines
(quoted diff) +2
-0@@ -2975,6 +3121,9 @@ static int kvm_s390_vcpu_setup(struct kvm_vcpu *vcpu) kvm_s390_vcpu_crypto_setup(vcpu); + if (kvm_s390_pv_is_protected(vcpu->kvm)) + rc = kvm_s390_pv_create_cpu(vcpu, &uvrc, &uvrrc);With an explicit
KVM_PV_VCPU_CREATE, this does not belong here. When hotplugging CPUs, user space has to do that manually. But as I said already, this user space API could be improved. (below)
With your proposed API this would stay.
[...]
Quoted 29 lines
Quoted 15 lines
(quoted diff) +11
-0@@ -4493,6 +4674,25 @@ long kvm_arch_vcpu_ioctl(struct file *filp, irq_state.len); break; } + case KVM_S390_PV_COMMAND_VCPU: { + struct kvm_pv_cmd args; + + r = 0; + if (!is_prot_virt_host()) { + r = -EINVAL; + break; + } + if (copy_from_user(&args, argp, sizeof(args))) { + r = -EFAULT; + break;Review long kvm_arch_vcpu_ioctl(struct file *filp, · line 4697
Quoted 10 lines
(quoted diff) +8
-0+ } + r = kvm_s390_handle_pv_vcpu(vcpu, &args); + if (copy_to_user(argp, &args, sizeof(args))) { + r = -EFAULT; + break; + } + break; + } default: r = -ENOTTY;Can we please discuss why we can't
Quoted 6 lines
- Get rid of
KVM_S390_PV_COMMAND_VCPU
- Do the allocation inKVM_PV_VM_CREATE
- RenameKVM_PV_VM_CREATE->KVM_PV_ENABLE
- RenameKVM_PV_VM_DESTROY->KVM_PV_DISABLEThis user space API is unnecessary complicated and confusing.
I will have a look if this is feasible.
Re: [PATCH v2 09/42] KVM: s390: protvirt: Add initial vm and cpu lifecycle handling
Quoted 21 lines · Christian Borntraeger
Quoted 16 lines · David Hildenbrand
[...]
Review
Quoted 11 lines
(quoted diff) +10
-0+static int kvm_s390_handle_pv(struct kvm *kvm, struct kvm_pv_cmd *cmd) +{ + int r = 0; + void __user *argp = (void __user *)cmd->data; + + switch (cmd->cmd) { + case KVM_PV_VM_CREATE: { + r = -EINVAL; + if (kvm_s390_pv_is_protected(kvm)) + break;Isn't this racy? I think there has to be a way to make sure the PV state can't change. Is there any and I am missing something obvious? (is suspect we need the
kvm->lock)
Quoted 3 lines
Yes,
kvm->lockaroundkvm_s390_handle_pvis safer.Something like
Yes. Probably a lockdep_assert_held() inside kvm_s390_pv_is_protected() would make sense to catch other races.
[...]
Quoted 6 lines
Quoted 4 lines
With an explicit
KVM_PV_VCPU_CREATE, this does not belong here. When hotplugging CPUs, user space has to do that manually. But as I said already, this user space API could be improved. (below)With your proposed API this would stay.
Yes
[...]
Quoted 4 lines
Quoted 4 lines
Can we please discuss why we can't
Quoted 9 lines
Quoted 6 lines
- Get rid of
KVM_S390_PV_COMMAND_VCPU
- Do the allocation inKVM_PV_VM_CREATE
- RenameKVM_PV_VM_CREATE->KVM_PV_ENABLE
- RenameKVM_PV_VM_DESTROY->KVM_PV_DISABLEThis user space API is unnecessary complicated and confusing.
I will have a look if this is feasible.
Okay, thanks!
Signature · 3 lines
Thanks, David / dhildenb
cover example changes
I also need to rename the ioctls and do more testing, but this is probably what you want?
Christian Borntraeger (2):
lock changes
merge vm/cpu create
arch/s390/kvm/intercept.c | 6 +-- arch/s390/kvm/interrupt.c | 35 ++++++++++------- arch/s390/kvm/kvm-s390.c | 83 +++++++++++++++++++++++++-------------- arch/s390/kvm/kvm-s390.h | 18 ++++++--- arch/s390/kvm/priv.c | 4 +- 5 files changed, 92 insertions(+), 54 deletions(-)
Signature · 1 line
2.25.0
PATCH 1/2 lock changes
--- arch/s390/kvm/intercept.c | 6 +++--- arch/s390/kvm/interrupt.c | 35 +++++++++++++++++++++-------------- arch/s390/kvm/kvm-s390.c | 28 +++++++++++++--------------- arch/s390/kvm/kvm-s390.h | 18 +++++++++++++----- arch/s390/kvm/priv.c | 4 ++-- 5 files changed, 52 insertions(+), 39 deletions(-)
arch/s390/kvm/intercept.c +3 -3
@@ -236,7 +236,7 @@ static int handle_prog(struct kvm_vcpu *vcpu)* Intercept 8 indicates a loop of specification exceptions * for protected guests. */ -if (kvm_s390_pv_is_protected (vcpu->kvm)) +if (kvm_s390_pv_cpu_is_protected (vcpu))return -EOPNOTSUPP ;if (guestdbg_enabled (vcpu) &&per_event (vcpu)) {
@@ -392,7 +392,7 @@ int handle_sthyi(struct kvm_vcpu *vcpu) goto out; } -if (!kvm_s390_pv_is_protected (vcpu->kvm) && (addr & ~PAGE_MASK )) +if (!kvm_s390_pv_cpu_is_protected (vcpu) && (addr & ~PAGE_MASK ))return kvm_s390_inject_program_int (vcpu,PGM_SPECIFICATION ); sctns = (void *)get_zeroed_page (GFP_KERNEL );
@@ -403,7 +403,7 @@ int handle_sthyi(struct kvm_vcpu *vcpu) out:if (!cc) { -if (kvm_s390_pv_is_protected (vcpu->kvm)) { +if (kvm_s390_pv_cpu_is_protected (vcpu)) {memcpy ((void *)(sida_origin (vcpu->arch.sie_block)), sctns,PAGE_SIZE ); }else {
arch/s390/kvm/interrupt.c +21 -14
@@ -393,7 +393,7 @@ static unsigned long deliverable_irqs(struct kvm_vcpu *vcpu)if (psw_mchk_disabled (vcpu)) active_mask &= ~IRQ_PEND_MCHK_MASK ;/* PV guest cpus can have a single interruption injected at a time. */ -if (kvm_s390_pv_is_protected (vcpu->kvm) && +if (kvm_s390_pv_cpu_is_protected (vcpu) && vcpu->arch.sie_block->iictl !=IICTL_CODE_NONE ) active_mask &= ~(IRQ_PEND_EXT_II_MASK | IRQ_PEND_IO_MASK |
@@ -495,7 +495,7 @@ static int __must_check __deliver_cpu_timer(struct kvm_vcpu *vcpu) vcpu->stat.deliver_cputm++;trace_kvm_s390_deliver_interrupt (vcpu->vcpu_id,KVM_S390_INT_CPU_TIMER ,0 ,0 ); -if (kvm_s390_pv_is_protected (vcpu->kvm)) { +if (kvm_s390_pv_cpu_is_protected (vcpu)) { vcpu->arch.sie_block->iictl =IICTL_CODE_EXT ; vcpu->arch.sie_block->eic =EXT_IRQ_CPU_TIMER ; }else {
@@ -519,7 +519,7 @@ static int __must_check __deliver_ckc(struct kvm_vcpu *vcpu) vcpu->stat.deliver_ckc++;trace_kvm_s390_deliver_interrupt (vcpu->vcpu_id,KVM_S390_INT_CLOCK_COMP ,0 ,0 ); -if (kvm_s390_pv_is_protected (vcpu->kvm)) { +if (kvm_s390_pv_cpu_is_protected (vcpu)) { vcpu->arch.sie_block->iictl =IICTL_CODE_EXT ; vcpu->arch.sie_block->eic =EXT_IRQ_CLK_COMP ; }else {
@@ -578,7 +578,7 @@ static int __write_machine_check(struct kvm_vcpu *vcpu,* the hypervisor does not not have the needed information for * protected guests. */ -if (kvm_s390_pv_is_protected (vcpu->kvm)) { +if (kvm_s390_pv_cpu_is_protected (vcpu)) { vcpu->arch.sie_block->iictl =IICTL_CODE_MCHK ; vcpu->arch.sie_block->mcic = mchk->mcic; vcpu->arch.sie_block->faddr = mchk->failing_storage_address;
@@ -735,7 +735,7 @@ static int __must_check __deliver_restart(struct kvm_vcpu *vcpu) vcpu->stat.deliver_restart_signal++;trace_kvm_s390_deliver_interrupt (vcpu->vcpu_id,KVM_S390_RESTART ,0 ,0 ); -if (kvm_s390_pv_is_protected (vcpu->kvm)) { +if (kvm_s390_pv_cpu_is_protected (vcpu)) { vcpu->arch.sie_block->iictl =IICTL_CODE_RESTART ; }else { rc = write_guest_lc(vcpu,
@@ -785,7 +785,7 @@ static int __must_check __deliver_emergency_signal(struct kvm_vcpu *vcpu) vcpu->stat.deliver_emergency_signal++;trace_kvm_s390_deliver_interrupt (vcpu->vcpu_id,KVM_S390_INT_EMERGENCY , cpu_addr,0 ); -if (kvm_s390_pv_is_protected (vcpu->kvm)) { +if (kvm_s390_pv_cpu_is_protected (vcpu)) { vcpu->arch.sie_block->iictl =IICTL_CODE_EXT ; vcpu->arch.sie_block->eic =EXT_IRQ_EMERGENCY_SIG ; vcpu->arch.sie_block->extcpuaddr = cpu_addr;
@@ -819,7 +819,7 @@ static int __must_check __deliver_external_call(struct kvm_vcpu *vcpu)trace_kvm_s390_deliver_interrupt (vcpu->vcpu_id,KVM_S390_INT_EXTERNAL_CALL , extcall.code,0 ); -if (kvm_s390_pv_is_protected (vcpu->kvm)) { +if (kvm_s390_pv_cpu_is_protected (vcpu)) { vcpu->arch.sie_block->iictl =IICTL_CODE_EXT ; vcpu->arch.sie_block->eic =EXT_IRQ_EXTERNAL_CALL ; vcpu->arch.sie_block->extcpuaddr = extcall.code;
@@ -871,7 +871,7 @@ static int __must_check __deliver_prog(struct kvm_vcpu *vcpu)trace_kvm_s390_deliver_interrupt (vcpu->vcpu_id,KVM_S390_PROGRAM_INT , pgm_info.code,0 ); -if (kvm_s390_pv_is_protected (vcpu->kvm)) +if (kvm_s390_pv_cpu_is_protected (vcpu))return __deliver_prog_pv (vcpu, pgm_info.code & ~PGM_PER );switch (pgm_info.code & ~PGM_PER ) {
@@ -1010,7 +1010,7 @@ static int __must_check __deliver_service(struct kvm_vcpu *vcpu)memset (&fi->srv_signal,0 ,sizeof (ext));clear_bit (IRQ_PEND_EXT_SERVICE , &fi->pending_irqs);clear_bit (IRQ_PEND_EXT_SERVICE_EV , &fi->pending_irqs); -if (kvm_s390_pv_is_protected (vcpu->kvm)) +if (kvm_s390_pv_cpu_is_protected (vcpu))set_bit (IRQ_PEND_EXT_SERVICE , &fi->masked_irqs);spin_unlock (&fi->lock);
@@ -1139,7 +1139,7 @@ static int __do_deliver_io(struct kvm_vcpu *vcpu, struct kvm_s390_io_info *io) {int rc; -if (kvm_s390_pv_is_protected (vcpu->kvm)) { +if (kvm_s390_pv_cpu_is_protected (vcpu)) { vcpu->arch.sie_block->iictl =IICTL_CODE_IO ; vcpu->arch.sie_block->subchannel_id = io->subchannel_id; vcpu->arch.sie_block->subchannel_nr = io->subchannel_nr;
@@ -1898,8 +1898,13 @@ static int __inject_io(struct kvm *kvm, struct kvm_s390_interrupt_info *inti) kvm->stat.inject_io++; isc =int_word_to_isc (inti->io.io_int_word); -/* do not make use of gisa in protected mode */ -if (!kvm_s390_pv_is_protected (kvm) && +/* +* Do not make use of gisa in protected mode. We do not use the lock +* checking variant as this is just a performance optimization and we +* do not hold the lock here. This is ok as the code will pick +* interrupts from both "lists" for delivery. +*/ +if (!kvm_s390_pv_handle (kvm) && gi->origin && inti->type &KVM_S390_INT_IO_AI_MASK ) {VM_EVENT (kvm,4 ,"%s isc %1u" ,"inject: I/O (AI/gisa)" , isc);gisa_set_ipm_gisc (gi->origin, isc);
@@ -2208,10 +2213,12 @@ void kvm_s390_clear_float_irqs(struct kvm *kvm)struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int;int i; -spin_lock (&fi->lock); - fi->pending_irqs =0 ; +mutex_lock (&kvm->lock);if (!kvm_s390_pv_is_protected (kvm)) fi->masked_irqs =0 ; +mutex_unlock (&kvm->lock); +spin_lock (&fi->lock); + fi->pending_irqs =0 ;memset (&fi->srv_signal,0 ,sizeof (fi->srv_signal));memset (&fi->mchk,0 ,sizeof (fi->mchk));for (i =0 ; i <FIRQ_LIST_COUNT ; i++)
arch/s390/kvm/kvm-s390.c +13 -15
@@ -2194,7 +2194,6 @@ static int kvm_s390_handle_pv(struct kvm *kvm, struct kvm_pv_cmd *cmd)break ; } -mutex_lock (&kvm->lock);kvm_s390_vcpu_block_all (kvm);/* FMT 4 SIE needs esca */ r =sca_switch_to_extended (kvm);
@@ -2208,7 +2207,6 @@ static int kvm_s390_handle_pv(struct kvm *kvm, struct kvm_pv_cmd *cmd)kvm_s390_vcpu_unblock_all (kvm);/* we need to block service interrupts from now on */ set_bit (IRQ_PEND_EXT_SERVICE , &kvm->arch.float_int.masked_irqs); -mutex_unlock (&kvm->lock);break ; }case KVM_PV_VM_DESTROY : {
@@ -2216,8 +2214,6 @@ static int kvm_s390_handle_pv(struct kvm *kvm, struct kvm_pv_cmd *cmd)if (!kvm_s390_pv_is_protected (kvm))break ; -/* All VCPUs have to be destroyed before this call. */ -mutex_lock (&kvm->lock);kvm_s390_vcpu_block_all (kvm); r =kvm_s390_pv_destroy_vm (kvm, &cmd->rc, &cmd->rrc);if (!r)
@@ -2225,7 +2221,6 @@ static int kvm_s390_handle_pv(struct kvm *kvm, struct kvm_pv_cmd *cmd)kvm_s390_vcpu_unblock_all (kvm);/* no need to block service interrupts any more */ clear_bit (IRQ_PEND_EXT_SERVICE , &kvm->arch.float_int.masked_irqs); -mutex_unlock (&kvm->lock);break ; }case KVM_PV_VM_SET_SEC_PARMS : {
@@ -2740,7 +2735,8 @@ void kvm_arch_destroy_vm(struct kvm *kvm)kvm_free_vcpus (kvm);sca_dispose (kvm);kvm_s390_gisa_destroy (kvm); -if (kvm_s390_pv_is_protected (kvm)) { +/* do not use the lock checking variant at tear-down */ +if (kvm_s390_pv_handle (kvm)) {kvm_s390_pv_destroy_vm (kvm, &rc, &rrc);kvm_s390_pv_dealloc_vm (kvm); }
@@ -3162,8 +3158,10 @@ static int kvm_s390_vcpu_setup(struct kvm_vcpu *vcpu)kvm_s390_vcpu_crypto_setup (vcpu); +mutex_lock (&vcpu->kvm->lock);if (kvm_s390_pv_is_protected (vcpu->kvm)) rc =kvm_s390_pv_create_cpu (vcpu, &uvrc, &uvrrc); +mutex_unlock (&vcpu->kvm->lock);return rc; }
@@ -4053,14 +4051,14 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)guest_enter_irqoff ();__disable_cpu_timer_accounting (vcpu);local_irq_enable (); -if (kvm_s390_pv_is_protected (vcpu->kvm)) { +if (kvm_s390_pv_cpu_is_protected (vcpu)) {memcpy (sie_page->pv_grregs, vcpu->run->s.regs.gprs,sizeof (sie_page->pv_grregs)); } exit_reason =sie64a (vcpu->arch.sie_block, vcpu->run->s.regs.gprs); -if (kvm_s390_pv_is_protected (vcpu->kvm)) { +if (kvm_s390_pv_cpu_is_protected (vcpu)) {memcpy (vcpu->run->s.regs.gprs, sie_page->pv_grregs,sizeof (sie_page->pv_grregs));
@@ -4184,7 +4182,7 @@ static void sync_regs(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) current->thread.fpu.fpc =0 ;/* Sync fmt2 only data */ -if (likely (!kvm_s390_pv_is_protected (vcpu->kvm))) { +if (likely (!kvm_s390_pv_cpu_is_protected (vcpu))) {sync_regs_fmt2 (vcpu, kvm_run); }else {/*
@@ -4244,7 +4242,7 @@ static void store_regs(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)/* Restore will be done lazily at return */ current->thread.fpu.fpc = vcpu->arch.host_fpregs.fpc; current->thread.fpu.regs = vcpu->arch.host_fpregs.regs; -if (likely (!kvm_s390_pv_is_protected (vcpu->kvm))) +if (likely (!kvm_s390_pv_cpu_is_protected (vcpu)))store_regs_fmt2 (vcpu, kvm_run); }
@@ -4443,7 +4441,7 @@ void kvm_s390_vcpu_start(struct kvm_vcpu *vcpu)* ultravisor. We block all interrupts and let the next sie exit * refresh our view. */ -if (kvm_s390_pv_is_protected (vcpu->kvm)) +if (kvm_s390_pv_cpu_is_protected (vcpu)) vcpu->arch.sie_block->gpsw.mask &= ~PSW_INT_MASK ;/* * Another VCPU might have used IBS while we were offline.
@@ -4573,7 +4571,7 @@ static long kvm_s390_guest_mem_op(struct kvm_vcpu *vcpu,switch (mop->op) {case KVM_S390_MEMOP_LOGICAL_READ : -if (kvm_s390_pv_is_protected (vcpu->kvm)) { +if (kvm_s390_pv_cpu_is_protected (vcpu)) { r = -EINVAL ;break ; }
@@ -4589,7 +4587,7 @@ static long kvm_s390_guest_mem_op(struct kvm_vcpu *vcpu, }break ;case KVM_S390_MEMOP_LOGICAL_WRITE : -if (kvm_s390_pv_is_protected (vcpu->kvm)) { +if (kvm_s390_pv_cpu_is_protected (vcpu)) { r = -EINVAL ;break ; }
@@ -4655,7 +4653,7 @@ static int kvm_s390_handle_pv_vcpu(struct kvm_vcpu *vcpu, {int r =0 ; -if (!kvm_s390_pv_is_protected (vcpu->kvm)) +if (!kvm_s390_pv_cpu_is_protected (vcpu))return -EINVAL ;if (cmd->flags)
@@ -4751,7 +4749,7 @@ long kvm_arch_vcpu_ioctl(struct file *filp,case KVM_GET_ONE_REG : {struct kvm_one_reg reg; r = -EINVAL ; -if (kvm_s390_pv_is_protected (vcpu->kvm)) +if (kvm_s390_pv_cpu_is_protected (vcpu))break ; r = -EFAULT ;if (copy_from_user (®, argp,sizeof (reg)))
arch/s390/kvm/kvm-s390.h +13 -5
@@ -15,6 +15,7 @@#include <linux/hrtimer.h> #include <linux/kvm.h> #include <linux/kvm_host.h> +#include <linux/lockdep.h> #include <asm/facility.h> #include <asm/processor.h> #include <asm/sclp.h>
@@ -221,11 +222,6 @@ int kvm_s390_pv_unpack(struct kvm *kvm, unsigned long addr, unsigned long size,int kvm_s390_pv_set_cpu_state (struct kvm_vcpu *vcpu,u8 state,u16 *rc,u16 *rrc); -static inline bool kvm_s390_pv_is_protected (struct kvm *kvm) -{ -return !!kvm->arch.pv.handle; -} -static inline u64 kvm_s390_pv_handle (struct kvm *kvm) {return kvm->arch.pv.handle;
@@ -236,6 +232,18 @@ static inline u64 kvm_s390_pv_handle_cpu(struct kvm_vcpu *vcpu)return vcpu->arch.pv.handle; } +static inline bool kvm_s390_pv_is_protected (struct kvm *kvm) +{ +lockdep_assert_held (&kvm->lock); +return !!kvm_s390_pv_handle (kvm); +} + +static inline bool kvm_s390_pv_cpu_is_protected (struct kvm_vcpu *vcpu) +{ +lockdep_assert_held (&vcpu->mutex); +return !!kvm_s390_pv_handle_cpu (vcpu); +} +/* implemented in interrupt.c */ int kvm_s390_handle_wait (struct kvm_vcpu *vcpu);void kvm_s390_vcpu_wakeup (struct kvm_vcpu *vcpu);
arch/s390/kvm/priv.c +2 -2
@@ -872,7 +872,7 @@ static int handle_stsi(struct kvm_vcpu *vcpu) operand2 =kvm_s390_get_base_disp_s (vcpu, &ar); -if (!kvm_s390_pv_is_protected (vcpu->kvm) && (operand2 &0xfff )) +if (!kvm_s390_pv_cpu_is_protected (vcpu) && (operand2 &0xfff ))return kvm_s390_inject_program_int (vcpu,PGM_SPECIFICATION );switch (fc) {
@@ -893,7 +893,7 @@ static int handle_stsi(struct kvm_vcpu *vcpu)handle_stsi_3_2_2 (vcpu, (void *) mem);break ; } -if (kvm_s390_pv_is_protected (vcpu->kvm)) { +if (kvm_s390_pv_cpu_is_protected (vcpu)) {memcpy ((void *)sida_origin (vcpu->arch.sie_block), (void *)mem,PAGE_SIZE ); rc =0 ;
Signature · 1 line
2.25.0
PATCH 2/2 merge vm/cpu create
In reply to Christian Borntraeger--- arch/s390/kvm/kvm-s390.c | 55 +++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 15 deletions(-)
arch/s390/kvm/kvm-s390.c +40 -15
@@ -2171,9 +2171,41 @@ static int kvm_s390_set_cmma_bits(struct kvm *kvm,return r; } +static int kvm_s390_switch_from_pv (struct kvm *kvm,u16 *rc,u16 *rrc) +{ +int i, r =0 ; + +struct kvm_vcpu *vcpu; + +kvm_for_each_vcpu (i, vcpu, kvm) { + r =kvm_s390_pv_destroy_cpu (vcpu, rc, rrc); +if (r) +break ; + } +return r; +} + +static int kvm_s390_switch_to_pv (struct kvm *kvm,u16 *rc,u16 *rrc) +{ +int i, r =0 ; +u16 dummy; + +struct kvm_vcpu *vcpu; + +kvm_for_each_vcpu (i, vcpu, kvm) { + r =kvm_s390_pv_create_cpu (vcpu, rc, rrc); +if (r) +break ; + } +if (r) +kvm_s390_switch_from_pv (kvm,&dummy, &dummy); +return r; +} +static int kvm_s390_handle_pv (struct kvm *kvm,struct kvm_pv_cmd *cmd) {int r =0 ; +u16 dummy;void __user *argp = (void __user *)cmd->data;switch (cmd->cmd) {
@@ -2204,6 +2236,11 @@ static int kvm_s390_handle_pv(struct kvm *kvm, struct kvm_pv_cmd *cmd)break ; } r =kvm_s390_pv_create_vm (kvm, &cmd->rc, &cmd->rrc); +if (!r) + r =kvm_s390_switch_to_pv (kvm, &cmd->rc, &cmd->rrc); +if (r) +kvm_s390_pv_destroy_vm (kvm, &dummy, &dummy); +kvm_s390_vcpu_unblock_all (kvm);/* we need to block service interrupts from now on */ set_bit (IRQ_PEND_EXT_SERVICE , &kvm->arch.float_int.masked_irqs);
@@ -2215,7 +2252,9 @@ static int kvm_s390_handle_pv(struct kvm *kvm, struct kvm_pv_cmd *cmd)break ;kvm_s390_vcpu_block_all (kvm); - r =kvm_s390_pv_destroy_vm (kvm, &cmd->rc, &cmd->rrc); + r =kvm_s390_switch_from_pv (kvm, &cmd->rc, &cmd->rrc); +if (!r) + r =kvm_s390_pv_destroy_vm (kvm, &cmd->rc, &cmd->rrc);if (!r)kvm_s390_pv_dealloc_vm (kvm);kvm_s390_vcpu_unblock_all (kvm);
@@ -4660,20 +4699,6 @@ static int kvm_s390_handle_pv_vcpu(struct kvm_vcpu *vcpu,return -EINVAL ;switch (cmd->cmd) { -case KVM_PV_VCPU_CREATE : { -if (kvm_s390_pv_handle_cpu (vcpu)) -return -EINVAL ; - - r =kvm_s390_pv_create_cpu (vcpu, &cmd->rc, &cmd->rrc); -break ; - } -case KVM_PV_VCPU_DESTROY : { -if (!kvm_s390_pv_handle_cpu (vcpu)) -return -EINVAL ; - - r =kvm_s390_pv_destroy_cpu (vcpu, &cmd->rc, &cmd->rrc); -break ; - }case KVM_PV_VCPU_SET_IPL_PSW : {if (!kvm_s390_pv_handle_cpu (vcpu))return -EINVAL ;
Signature · 1 line
2.25.0
Janosch Frank
maintainerRe: [PATCH 2/2] merge vm/cpu create
Quoted 33 lines · Christian Borntraeger
Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/kvm/kvm-s390.c | 55 +++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 15 deletions(-)arch/s390/kvm/kvm-s390.c +20
-0@@ -2171,9 +2171,41 @@ static int kvm_s390_set_cmma_bits(struct kvm *kvm,return r; } +static int kvm_s390_switch_from_pv (struct kvm *kvm,u16 *rc,u16 *rrc) +{ +int i, r =0 ; + +struct kvm_vcpu *vcpu; + +kvm_for_each_vcpu (i, vcpu, kvm) { + r =kvm_s390_pv_destroy_cpu (vcpu, rc, rrc); +if (r) +break ; + } +return r; +} + +static int kvm_s390_switch_to_pv (struct kvm *kvm,u16 *rc,u16 *rrc) +{ +int i, r =0 ; +u16 dummy; + +struct kvm_vcpu *vcpu;
arch/s390/kvm/kvm-s390.c static int kvm_s390_set_cmma_bits(struct kvm *kvm, · line 2203
Quoted 10 lines
arch/s390/kvm/kvm-s390.c +10
-0+ +kvm_for_each_vcpu (i, vcpu, kvm) { + r =kvm_s390_pv_create_cpu (vcpu, rc, rrc); +if (r) +break ; + } +if (r) +kvm_s390_switch_from_pv (kvm,&dummy, &dummy); +return r; +}
Why does that only affect the cpus?
If we have a switch function it should do VM and VCPUs, no?
Quoted 53 lines
arch/s390/kvm/kvm-s390.c +10
-15+static int kvm_s390_handle_pv (struct kvm *kvm,struct kvm_pv_cmd *cmd) {int r =0 ; +u16 dummy;void __user *argp = (void __user *)cmd->data;switch (cmd->cmd) {@@ -2204,6 +2236,11 @@ static int kvm_s390_handle_pv(struct kvm *kvm, struct kvm_pv_cmd *cmd)break ; } r =kvm_s390_pv_create_vm (kvm, &cmd->rc, &cmd->rrc); +if (!r) + r =kvm_s390_switch_to_pv (kvm, &cmd->rc, &cmd->rrc); +if (r) +kvm_s390_pv_destroy_vm (kvm, &dummy, &dummy); +kvm_s390_vcpu_unblock_all (kvm);/* we need to block service interrupts from now on */ set_bit (IRQ_PEND_EXT_SERVICE , &kvm->arch.float_int.masked_irqs);@@ -2215,7 +2252,9 @@ static int kvm_s390_handle_pv(struct kvm *kvm, struct kvm_pv_cmd *cmd)break ;kvm_s390_vcpu_block_all (kvm); - r =kvm_s390_pv_destroy_vm (kvm, &cmd->rc, &cmd->rrc); + r =kvm_s390_switch_from_pv (kvm, &cmd->rc, &cmd->rrc); +if (!r) + r =kvm_s390_pv_destroy_vm (kvm, &cmd->rc, &cmd->rrc);if (!r)kvm_s390_pv_dealloc_vm (kvm);kvm_s390_vcpu_unblock_all (kvm);@@ -4660,20 +4699,6 @@ static int kvm_s390_handle_pv_vcpu(struct kvm_vcpu *vcpu,return -EINVAL ;switch (cmd->cmd) { -case KVM_PV_VCPU_CREATE : { -if (kvm_s390_pv_handle_cpu (vcpu)) -return -EINVAL ; - - r =kvm_s390_pv_create_cpu (vcpu, &cmd->rc, &cmd->rrc); -break ; - } -case KVM_PV_VCPU_DESTROY : { -if (!kvm_s390_pv_handle_cpu (vcpu)) -return -EINVAL ; - - r =kvm_s390_pv_destroy_cpu (vcpu, &cmd->rc, &cmd->rrc); -break ; - }case KVM_PV_VCPU_SET_IPL_PSW : {if (!kvm_s390_pv_handle_cpu (vcpu))return -EINVAL ;
Re: [PATCH 2/2] merge vm/cpu create
Quoted 39 lines · Janosch Frank
Quoted 38 lines · Christian Borntraeger
Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/kvm/kvm-s390.c | 55 +++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 15 deletions(-)arch/s390/kvm/kvm-s390.c +25
-0@@ -2171,9 +2171,41 @@ static int kvm_s390_set_cmma_bits(struct kvm *kvm,return r; } +static int kvm_s390_switch_from_pv (struct kvm *kvm,u16 *rc,u16 *rrc) +{ +int i, r =0 ; + +struct kvm_vcpu *vcpu; + +kvm_for_each_vcpu (i, vcpu, kvm) { + r =kvm_s390_pv_destroy_cpu (vcpu, rc, rrc); +if (r) +break ; + } +return r; +} + +static int kvm_s390_switch_to_pv (struct kvm *kvm,u16 *rc,u16 *rrc) +{ +int i, r =0 ; +u16 dummy; + +struct kvm_vcpu *vcpu; + +kvm_for_each_vcpu (i, vcpu, kvm) { + r =kvm_s390_pv_create_cpu (vcpu, rc, rrc); +if (r) +break ;
Quoted 8 lines
arch/s390/kvm/kvm-s390.c static int kvm_s390_set_cmma_bits(struct kvm *kvm, · line 2203
Quoted 5 lines
arch/s390/kvm/kvm-s390.c +5
-0+ } +if (r) +kvm_s390_switch_from_pv (kvm,&dummy, &dummy); +return r; +}Why does that only affect the cpus?
If we have a switch function it should do VM and VCPUs, no?
It is a helper function for the function below.
FWIW, it also needs to take the cpu->mutex for each cpu.
Re: [PATCH 2/2] merge vm/cpu create
In reply to Janosch FrankQuoted 25 lines · Janosch Frank
Quoted 25 lines
arch/s390/kvm/kvm-s390.c +25
-0+static int kvm_s390_switch_from_pv (struct kvm *kvm,u16 *rc,u16 *rrc) +{ +int i, r =0 ; + +struct kvm_vcpu *vcpu; + +kvm_for_each_vcpu (i, vcpu, kvm) { + r =kvm_s390_pv_destroy_cpu (vcpu, rc, rrc); +if (r) +break ; + } +return r; +} + +static int kvm_s390_switch_to_pv (struct kvm *kvm,u16 *rc,u16 *rrc) +{ +int i, r =0 ; +u16 dummy; + +struct kvm_vcpu *vcpu; + +kvm_for_each_vcpu (i, vcpu, kvm) { + r =kvm_s390_pv_create_cpu (vcpu, rc, rrc); +if (r) +break ;
Quoted 8 lines
arch/s390/kvm/kvm-s390.c static int kvm_s390_set_cmma_bits(struct kvm *kvm, · line 2203
Quoted 5 lines
arch/s390/kvm/kvm-s390.c +5
-0+ } +if (r) +kvm_s390_switch_from_pv (kvm,&dummy, &dummy); +return r; +}Why does that only affect the cpus?
If we have a switch function it should do VM and VCPUs, no?
I will rename that to kvm_s390_switch_cpus_to/from.
Re: [PATCH 0/2] example changes
In reply to Christian BorntraegerQuoted 2 lines · Christian Borntraeger
I also need to rename the ioctls and do more testing, but this is probably what you want?
Yes, looks like that should be it! Will have a look at the remaining patches tomorrow.
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v2 09/42] KVM: s390: protvirt: Add initial vm and cpu lifecycle handling
In reply to David HildenbrandQuoted 4 lines · David Hildenbrand
Review
Quoted 2 lines
(quoted diff) +2
-0+ } + case KVM_PV_VM_SET_SEC_PARMS: {I'd name this "
KVM_PV_VM_SET_PARMS" instead.
I would stick with the SEC name as this is more similar to the UV call name.
PATCH 1/1 KVM: s390: protvirt: Add initial vm and cpu lifecycle handling
In reply to Christian BorntraegerFrom: Janosch Frank <[email protected]>
This contains 3 main changes:
1. changes in SIE control block handling for secure guests
2. helper functions for create/destroy/unpack secure guests
3. KVM_S390_PV_COMMAND ioctl to allow userspace dealing with secure machines
---
2->2.1 - combine CREATE/DESTROY CPU/VM into ENABLE DISABLE
- rework locking and check locks with lockdep
- I still have the PV_COMMAND_CPU in here for later use in the SET_IPL_PSW ioctl. If wanted I can move
- change CAP number
arch/s390/include/asm/kvm_host.h | 24 ++- arch/s390/include/asm/uv.h | 69 ++++++++ arch/s390/kvm/Makefile | 2 +- arch/s390/kvm/kvm-s390.c | 231 ++++++++++++++++++++++++++- arch/s390/kvm/kvm-s390.h | 35 +++++ arch/s390/kvm/pv.c | 262 +++++++++++++++++++++++++++++++ include/uapi/linux/kvm.h | 35 +++++ 7 files changed, 654 insertions(+), 4 deletions(-) create mode 100644 arch/s390/kvm/pv.c
arch/s390/include/asm/kvm_host.h +22 -2
@@ -160,7 +160,13 @@ struct kvm_s390_sie_block {__u8 reserved08[4 ];/* 0x0008 */ #define PROG_IN_SIE (1<<0)__u32 prog0c;/* 0x000c */ -__u8 reserved10[16 ];/* 0x0010 */ +union { +__u8 reserved10[16 ];/* 0x0010 */ +struct { +__u64 pv_handle_cpu; +__u64 pv_handle_config; + }; + };#define PROG_BLOCK_SIE (1<<0)#define PROG_REQUEST (1<<1)atomic_t prog20;/* 0x0020 */
@@ -233,7 +239,7 @@ struct kvm_s390_sie_block {#define ECB3_RI 0x01__u8 ecb3;/* 0x0063 */ __u32 scaol;/* 0x0064 */ -__u8 reserved68;/* 0x0068 */ +__u8 sdf;/* 0x0068 */ __u8 epdx;/* 0x0069 */ __u8 reserved6a[2 ];/* 0x006a */ __u32 todpr;/* 0x006c */
@@ -645,6 +651,11 @@ struct kvm_guestdbg_info_arch {unsigned long last_bp; }; +struct kvm_s390_pv_vcpu { +u64 handle; +unsigned long stor_base; +}; +struct kvm_vcpu_arch {struct kvm_s390_sie_block *sie_block;/* if vsie is active, currently executed shadow sie control block */
@@ -673,6 +684,7 @@ struct kvm_vcpu_arch {__u64 cputm_start;bool gs_enabled;bool skey_enabled; +struct kvm_s390_pv_vcpu pv; };struct kvm_vm_stat {
@@ -843,6 +855,13 @@ struct kvm_s390_gisa_interrupt {DECLARE_BITMAP (kicked_mask,KVM_MAX_VCPUS ); }; +struct kvm_s390_pv { +u64 handle; +u64 guest_len; +unsigned long stor_base; +void *stor_var; +}; +struct kvm_arch {void *sca;int use_esca;
@@ -878,6 +897,7 @@ struct kvm_arch{DECLARE_BITMAP (cpu_feat,KVM_S390_VM_CPU_FEAT_NR_BITS );DECLARE_BITMAP (idle_mask,KVM_MAX_VCPUS );struct kvm_s390_gisa_interrupt gisa_int; +struct kvm_s390_pv pv; };#define KVM_HVA_ERR_BAD (-1UL)
arch/s390/include/asm/uv.h +69 -0
126 lines not on this page · raw message
arch/s390/kvm/Makefile +1 -1
@@ -9,6 +9,6 @@ common-objs = $(KVM)/kvm_main.o $(KVM)/eventfd.o $(KVM)/async_pf.o $(KVM)/irqch ccflags-y := -Ivirt/kvm -Iarch/s390/kvm kvm-objs := $(common-objs) kvm-s390.o intercept.o interrupt.o priv.o sigp.o -kvm-objs += diag.o gaccess.o guestdbg.o vsie.o +kvm-objs += diag.o gaccess.o guestdbg.o vsie.o pv.o obj-$(CONFIG_KVM) += kvm.o
arch/s390/kvm/kvm-s390.c +230 -1
314 lines not on this page · raw message
arch/s390/kvm/kvm-s390.h +35 -0
@@ -15,6 +15,7 @@#include <linux/hrtimer.h> #include <linux/kvm.h> #include <linux/kvm_host.h> +#include <linux/lockdep.h> #include <asm/facility.h> #include <asm/processor.h> #include <asm/sclp.h>
@@ -207,6 +208,40 @@ static inline int kvm_s390_user_cpu_state_ctrl(struct kvm *kvm)return kvm->arch.user_cpu_state_ctrl !=0 ; } +/* implemented in pv.c */ +void kvm_s390_pv_dealloc_vm (struct kvm *kvm); +int kvm_s390_pv_alloc_vm (struct kvm *kvm); +int kvm_s390_pv_create_vm (struct kvm *kvm,u16 *rc,u16 *rrc); +int kvm_s390_pv_create_cpu (struct kvm_vcpu *vcpu,u16 *rc,u16 *rrc); +int kvm_s390_pv_destroy_vm (struct kvm *kvm,u16 *rc,u16 *rrc); +int kvm_s390_pv_destroy_cpu (struct kvm_vcpu *vcpu,u16 *rc,u16 *rrc); +int kvm_s390_pv_set_sec_parms (struct kvm *kvm,void *hdr,u64 length,u16 *rc, +u16 *rrc); +int kvm_s390_pv_unpack (struct kvm *kvm,unsigned long addr,unsigned long size, +unsigned long tweak,u16 *rc,u16 *rrc); + +static inline u64 kvm_s390_pv_handle (struct kvm *kvm) +{ +return kvm->arch.pv.handle; +} + +static inline u64 kvm_s390_pv_handle_cpu (struct kvm_vcpu *vcpu) +{ +return vcpu->arch.pv.handle; +} + +static inline bool kvm_s390_pv_is_protected (struct kvm *kvm) +{ +lockdep_assert_held (&kvm->lock); +return !!kvm_s390_pv_handle (kvm); +} + +static inline bool kvm_s390_pv_cpu_is_protected (struct kvm_vcpu *vcpu) +{ +lockdep_assert_held (&vcpu->mutex); +return !!kvm_s390_pv_handle_cpu (vcpu); +} +/* implemented in interrupt.c */ int kvm_s390_handle_wait (struct kvm_vcpu *vcpu);void kvm_s390_vcpu_wakeup (struct kvm_vcpu *vcpu);
arch/s390/kvm/pv.c new file +262 -0
262 lines not on this page · raw message
include/uapi/linux/kvm.h +35 -0
@@ -1010,6 +1010,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_ARM_NISV_TO_USER 177#define KVM_CAP_ARM_INJECT_EXT_DABT 178#define KVM_CAP_S390_VCPU_RESETS 179 +#define KVM_CAP_S390_PROTECTED 180#ifdef KVM_CAP_IRQ_ROUTING
@@ -1478,6 +1479,40 @@ struct kvm_enc_region {#define KVM_S390_NORMAL_RESET _IO(KVMIO, 0xc3)#define KVM_S390_CLEAR_RESET _IO(KVMIO, 0xc4) +struct kvm_s390_pv_sec_parm { +__u64 origin; +__u64 length; +}; + +struct kvm_s390_pv_unp { +__u64 addr; +__u64 size; +__u64 tweak; +}; + +enum pv_cmd_id { +KVM_PV_ENABLE , +KVM_PV_DISABLE , +KVM_PV_VM_SET_SEC_PARMS , +KVM_PV_VM_UNPACK , +KVM_PV_VM_VERIFY , +KVM_PV_VCPU_CREATE , +KVM_PV_VCPU_DESTROY , +}; + +struct kvm_pv_cmd { +__u32 cmd;/* Command to be executed */ +__u16 rc;/* Ultravisor return code */ +__u16 rrc;/* Ultravisor return reason code */ +__u64 data;/* Data or address */ +__u32 flags;/* flags for future extensions. Must be 0 for now */ +__u32 reserved[3 ]; +}; + +/* Available with KVM_CAP_S390_PROTECTED */ +#define KVM_S390_PV_COMMAND _IOWR(KVMIO, 0xc5, struct kvm_pv_cmd) +#define KVM_S390_PV_COMMAND_VCPU _IOWR(KVMIO, 0xc6, struct kvm_pv_cmd) +/* Secure Encrypted Virtualization command */ enum sev_cmd_id {/* Guest initialization commands */
Signature · 1 line
2.25.0
Re: [PATCH v2.1] KVM: s390: protvirt: Add initial vm and cpu lifecycle handling
Quoted 8 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
This contains 3 main changes:
1. changes in SIE control block handling for secure guests
2. helper functions for create/destroy/unpack secure guests
3.KVM_S390_PV_COMMANDioctl to allow userspace dealing with secure machines
Quoted 8 lines
Signed-off-by Janosch Frank <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>---
2->2.1 - combine CREATE/DESTROY CPU/VM into ENABLE DISABLE
- rework locking and check locks with lockdep
- I still have thePV_COMMAND_CPUin here for later use in theSET_IPL_PSWioctl. If wanted I can move
I'd prefer to move, and eventually just turn this into a clean, separate ioctl without subcommands (e.g., if we'll only need a single subcommand in the near future). And it makes this patch a alittle easier to review ... :)
[...]
Quoted 35 lines
obj-$(CONFIG_KVM) += kvm.o
arch/s390/kvm/kvm-s390.c +6
-0@@ -44,6 +44,7 @@#include <asm/cpacf.h> #include <asm/timex.h> #include <asm/ap.h> +#include <asm/uv.h> #include "kvm-s390.h" #include "gaccess.h" @@ -234,8 +235,10 @@ int kvm_arch_check_processor_compat(void)return 0 ; } +/* forward declarations */ static void kvm_gmap_notifier (struct gmap *gmap,unsigned long start,unsigned long end); +static int sca_switch_to_extended (struct kvm *kvm);static void kvm_clock_sync_scb (struct kvm_s390_sie_block *scb,u64 delta) {@@ -571,6 +574,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)case KVM_CAP_S390_BPB : r =test_facility (82 );break ; +case KVM_CAP_S390_PROTECTED : + r =is_prot_virt_host (); +break ;default : r =0 ; }
arch/s390/kvm/kvm-s390.c static int kvm_s390_set_cmma_bits(struct kvm *kvm, · line 2179
Quoted 9 lines
arch/s390/kvm/kvm-s390.c +6
-0@@ -2165,6 +2171,152 @@ static int kvm_s390_set_cmma_bits(struct kvm *kvm,return r; } +static int kvm_s390_switch_from_pv (struct kvm *kvm,u16 *rc,u16 *rrc) +{ +int i, r =0 ; + +struct kvm_vcpu *vcpu; +
Once we lock the VCPU, it cannot be running, right?
arch/s390/kvm/kvm-s390.c static int kvm_s390_set_cmma_bits(struct kvm *kvm, · line 2186
Quoted 7 lines
arch/s390/kvm/kvm-s390.c +7
-0+kvm_for_each_vcpu (i, vcpu, kvm) { +mutex_lock (&vcpu->mutex); + r =kvm_s390_pv_destroy_cpu (vcpu, rc, rrc); +mutex_unlock (&vcpu->mutex); +if (r) +break ; + }
Can this actually ever fail? If so, you would leave half-initialized state around. Warn and continue?
Especially, kvm_arch_vcpu_destroy() ignores any error from kvm_s390_pv_destroy_cpu() as well ...
IMHO, we should make kvm_s390_switch_from_pv() and kvm_s390_pv_destroy_cpu() never fail.
Quoted 23 lines
arch/s390/kvm/kvm-s390.c +23
-0+return r; +} + +static int kvm_s390_switch_to_pv (struct kvm *kvm,u16 *rc,u16 *rrc) +{ +int i, r =0 ; +u16 dummy; + +struct kvm_vcpu *vcpu; + +kvm_for_each_vcpu (i, vcpu, kvm) { +mutex_lock (&vcpu->mutex); + r =kvm_s390_pv_create_cpu (vcpu, rc, rrc); +mutex_unlock (&vcpu->mutex); +if (r) +break ; + } +if (r) +kvm_s390_switch_from_pv (kvm,&dummy, &dummy); +return r; +} + +static int kvm_s390_handle_pv (struct kvm *kvm,struct kvm_pv_cmd *cmd)
arch/s390/kvm/kvm-s390.c static int kvm_s390_set_cmma_bits(struct kvm *kvm, · line 2219
Quoted 10 lines
arch/s390/kvm/kvm-s390.c +10
-0+{ +int r =0 ; +u16 dummy; +void __user *argp = (void __user *)cmd->data; + +switch (cmd->cmd) { +case KVM_PV_ENABLE : { + r = -EINVAL ; +if (kvm_s390_pv_is_protected (kvm)) +break ;
Why not factor out this check, it's common for all sucommands.
arch/s390/kvm/kvm-s390.c static int kvm_s390_set_cmma_bits(struct kvm *kvm, · line 2225
Quoted 6 lines
arch/s390/kvm/kvm-s390.c +6
-0+ + r =kvm_s390_pv_alloc_vm (kvm); +if (r) +break ; + +kvm_s390_vcpu_block_all (kvm);
As kvm_s390_vcpu_block_all() does not support nesting, this will not work as expected - sca_switch_to_extended() already blocks. Are the vcpu->locks not enough?
Quoted 13 lines
arch/s390/kvm/kvm-s390.c +13
-0+/* FMT 4 SIE needs esca */ + r =sca_switch_to_extended (kvm); +if (r) { +kvm_s390_pv_dealloc_vm (kvm); +kvm_s390_vcpu_unblock_all (kvm); +mutex_unlock (&kvm->lock); +break ; + } + r =kvm_s390_pv_create_vm (kvm, &cmd->rc, &cmd->rrc); +if (!r) + r =kvm_s390_switch_to_pv (kvm, &cmd->rc, &cmd->rrc); +if (r) +kvm_s390_pv_destroy_vm (kvm, &dummy, &dummy);
arch/s390/kvm/kvm-s390.c static int kvm_s390_set_cmma_bits(struct kvm *kvm, · line 2248
Quoted 10 lines
arch/s390/kvm/kvm-s390.c +10
-0+ +kvm_s390_vcpu_unblock_all (kvm); +break ; + } +case KVM_PV_DISABLE : { + r = -EINVAL ; +if (!kvm_s390_pv_is_protected (kvm)) +break ; + +kvm_s390_vcpu_block_all (kvm);
Won't taking the vcpu lock achieve a similar goal (VCPU can't be running).
Quoted 8 lines
arch/s390/kvm/kvm-s390.c +8
-0+ r =kvm_s390_switch_from_pv (kvm, &cmd->rc, &cmd->rrc); +if (!r) + r =kvm_s390_pv_destroy_vm (kvm, &cmd->rc, &cmd->rrc); +if (!r) +kvm_s390_pv_dealloc_vm (kvm); +kvm_s390_vcpu_unblock_all (kvm); +break ; + }
[...]
arch/s390/kvm/kvm-s390.c static void kvm_free_vcpus(struct kvm *kvm) · line 2743
Quoted 11 lines
arch/s390/kvm/kvm-s390.c +3
-1@@ -2558,10 +2735,16 @@ static void kvm_free_vcpus(struct kvm *kvm)void kvm_arch_destroy_vm (struct kvm *kvm) { +u16 rc, rrc;kvm_free_vcpus (kvm);sca_dispose (kvm); -debug_unregister (kvm->arch.dbf);kvm_s390_gisa_destroy (kvm); +/* do not use the lock checking variant at tear-down */ +if (kvm_s390_pv_handle (kvm)) {
kvm_s390_pv_is_protected ? I dislike using kvm_s390_pv_handle() when we're not interested in the handle.
Quoted 7 lines
arch/s390/kvm/kvm-s390.c +4
-0+kvm_s390_pv_destroy_vm (kvm, &rc, &rrc); +kvm_s390_pv_dealloc_vm (kvm); + } +debug_unregister (kvm->arch.dbf);free_page ((unsigned long )kvm->arch.sie_page2);if (!kvm_is_ucontrol (kvm))gmap_remove (kvm->arch.gmap);
[...]
Quoted 6 lines
arch/s390/kvm/kvm-s390.c +6
-0+/* implemented in pv.c */ +void kvm_s390_pv_dealloc_vm (struct kvm *kvm); +int kvm_s390_pv_alloc_vm (struct kvm *kvm); +int kvm_s390_pv_create_vm (struct kvm *kvm,u16 *rc,u16 *rrc); +int kvm_s390_pv_create_cpu (struct kvm_vcpu *vcpu,u16 *rc,u16 *rrc); +int kvm_s390_pv_destroy_vm (struct kvm *kvm,u16 *rc,u16 *rrc);
arch/s390/kvm/kvm-s390.c
Quoted 10 lines
arch/s390/kvm/kvm-s390.c +10
-0+int kvm_s390_pv_destroy_cpu (struct kvm_vcpu *vcpu,u16 *rc,u16 *rrc); +int kvm_s390_pv_set_sec_parms (struct kvm *kvm,void *hdr,u64 length,u16 *rc, +u16 *rrc); +int kvm_s390_pv_unpack (struct kvm *kvm,unsigned long addr,unsigned long size, +unsigned long tweak,u16 *rc,u16 *rrc); + +static inline u64 kvm_s390_pv_handle (struct kvm *kvm) +{ +return kvm->arch.pv.handle; +}
Can we rename this to
kvm_s390_pv_get_handle()
arch/s390/kvm/kvm-s390.c
Quoted 5 lines
arch/s390/kvm/kvm-s390.c +5
-0+ +static inline u64 kvm_s390_pv_handle_cpu (struct kvm_vcpu *vcpu) +{ +return vcpu->arch.pv.handle; +}
Can we rename this to kvm_s390_pv_cpu_get_handle() ? (so it doesn't look like the function will handle something)
Quoted 60 lines
arch/s390/kvm/kvm-s390.c +13
-0+ +static inline bool kvm_s390_pv_is_protected (struct kvm *kvm) +{ +lockdep_assert_held (&kvm->lock); +return !!kvm_s390_pv_handle (kvm); +} + +static inline bool kvm_s390_pv_cpu_is_protected (struct kvm_vcpu *vcpu) +{ +lockdep_assert_held (&vcpu->mutex); +return !!kvm_s390_pv_handle_cpu (vcpu); +} +/* implemented in interrupt.c */ int kvm_s390_handle_wait (struct kvm_vcpu *vcpu);void kvm_s390_vcpu_wakeup (struct kvm_vcpu *vcpu);arch/s390/kvm/pv.c new file +38
-0@@ -0,0 +1,262 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Hosting Secure Execution virtual machines +* +* Copyright IBM Corp. 2019 +* Author(s): Janosch Frank <[email protected]> +*/ +#include <linux/kvm.h> +#include <linux/kvm_host.h> +#include <linux/pagemap.h> +#include <linux/sched/signal.h> +#include <asm/pgalloc.h> +#include <asm/gmap.h> +#include <asm/uv.h> +#include <asm/gmap.h> +#include <asm/mman.h> +#include "kvm-s390.h" + +void kvm_s390_pv_dealloc_vm (struct kvm *kvm) +{ +vfree (kvm->arch.pv.stor_var); +free_pages (kvm->arch.pv.stor_base, +get_order (uv_info.guest_base_stor_len)); +memset (&kvm->arch.pv,0 ,sizeof (kvm->arch.pv)); +} + +int kvm_s390_pv_alloc_vm (struct kvm *kvm) +{ +unsigned long base = uv_info.guest_base_stor_len; +unsigned long virt = uv_info.guest_virt_var_stor_len; +unsigned long npages =0 , vlen =0 ; +struct kvm_memory_slot *memslot; + + kvm->arch.pv.stor_var =NULL ; + kvm->arch.pv.stor_base =__get_free_pages (GFP_KERNEL ,get_order (base)); +if (!kvm->arch.pv.stor_base) +return -ENOMEM ; +
arch/s390/kvm/pv.c line 48
Quoted 10 lines
arch/s390/kvm/pv.c new file +10
-0+/* +* Calculate current guest storage for allocation of the +* variable storage, which is based on the length in MB. +* +* Slots are sorted by GFN +*/ +mutex_lock (&kvm->slots_lock); + memslot =kvm_memslots (kvm)->memslots; + npages = memslot->base_gfn + memslot->npages; +mutex_unlock (&kvm->slots_lock);
Are you blocking the addition of new memslots somehow?
arch/s390/kvm/pv.c line 157
Quoted 11 lines
arch/s390/kvm/pv.c new file +11
-0+int kvm_s390_pv_create_vm (struct kvm *kvm,u16 *rc,u16 *rrc) +{ +u16 drc, drrc; +int cc; + +struct uv_cb_cgc uvcb = { + .header.cmd =UVC_CMD_CREATE_SEC_CONF , + .header.len =sizeof (uvcb) + }; + +if (kvm_s390_pv_handle (kvm))
Why is that necessary? We should only be called in PV mode.
Quoted 31 lines
arch/s390/kvm/pv.c new file +31
-0+return -EINVAL ; + +/* Inputs */ + uvcb.guest_stor_origin =0 ;/* MSO is 0 for KVM */ + uvcb.guest_stor_len = kvm->arch.pv.guest_len; + uvcb.guest_asce = kvm->arch.gmap->asce; + uvcb.guest_sca = (unsigned long )kvm->arch.sca; + uvcb.conf_base_stor_origin = (u64 )kvm->arch.pv.stor_base; + uvcb.conf_virt_stor_origin = (u64 )kvm->arch.pv.stor_var; + + cc =uv_call (0 , (u64)&uvcb); + *rc = uvcb.header.rc; + *rrc = uvcb.header.rrc; +KVM_UV_EVENT (kvm,3 ,"PROTVIRT CREATE VM: handle %llx len %llx rc %x rrc %x" , + uvcb.guest_handle, uvcb.guest_stor_len, *rc, *rrc); + +/* Outputs */ + kvm->arch.pv.handle = uvcb.guest_handle; + +if (cc && (uvcb.header.rc &UVC_RC_NEED_DESTROY )) { +kvm_s390_pv_destroy_vm (kvm, &drc, &drrc); +return -EINVAL ; + } + kvm->arch.gmap->guest_handle = uvcb.guest_handle; +atomic_set (&kvm->mm->context.is_protected,1 ); +return cc; +} + +int kvm_s390_pv_set_sec_parms (struct kvm *kvm,void *hdr,u64 length,u16 *rc, +u16 *rrc) +{
arch/s390/kvm/pv.c line 198
Quoted 10 lines
arch/s390/kvm/pv.c new file +10
-0+struct uv_cb_ssc uvcb = { + .header.cmd =UVC_CMD_SET_SEC_CONF_PARAMS , + .header.len =sizeof (uvcb), + .sec_header_origin = (u64 )hdr, + .sec_header_len = length, + .guest_handle =kvm_s390_pv_handle (kvm), + }; +int cc; + +if (!kvm_s390_pv_handle (kvm))
Why is that necessary? We should only be called in PV mode.
Quoted 11 lines
arch/s390/kvm/pv.c new file +11
-0+return -EINVAL ; + + cc =uv_call (0 , (u64)&uvcb); + *rc = uvcb.header.rc; + *rrc = uvcb.header.rrc; +KVM_UV_EVENT (kvm,3 ,"PROTVIRT VM SET PARMS: rc %x rrc %x" , + uvcb.header.rc, uvcb.header.rrc); +if (cc) +return -EINVAL ; +return 0 ; +}
[...]
Quoted 13 lines
include/uapi/linux/kvm.h +1
-0@@ -1010,6 +1010,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_ARM_NISV_TO_USER 177#define KVM_CAP_ARM_INJECT_EXT_DABT 178#define KVM_CAP_S390_VCPU_RESETS 179 +#define KVM_CAP_S390_PROTECTED 180#ifdef KVM_CAP_IRQ_ROUTING
include/uapi/linux/kvm.h struct kvm_enc_region { · line 1484
Quoted 6 lines
include/uapi/linux/kvm.h +3
-0@@ -1478,6 +1479,40 @@ struct kvm_enc_region {#define KVM_S390_NORMAL_RESET _IO(KVMIO, 0xc3)#define KVM_S390_CLEAR_RESET _IO(KVMIO, 0xc4) +struct kvm_s390_pv_sec_parm { +__u64 origin; +__u64 length;
tabs vs. spaces. (I'd use a single space like in kvm_s390_pv_unp below)
Quoted 35 lines
include/uapi/linux/kvm.h +31
-0+}; + +struct kvm_s390_pv_unp { +__u64 addr; +__u64 size; +__u64 tweak; +}; + +enum pv_cmd_id { +KVM_PV_ENABLE , +KVM_PV_DISABLE , +KVM_PV_VM_SET_SEC_PARMS , +KVM_PV_VM_UNPACK , +KVM_PV_VM_VERIFY , +KVM_PV_VCPU_CREATE , +KVM_PV_VCPU_DESTROY , +}; + +struct kvm_pv_cmd { +__u32 cmd;/* Command to be executed */ +__u16 rc;/* Ultravisor return code */ +__u16 rrc;/* Ultravisor return reason code */ +__u64 data;/* Data or address */ +__u32 flags;/* flags for future extensions. Must be 0 for now */ +__u32 reserved[3 ]; +}; + +/* Available with KVM_CAP_S390_PROTECTED */ +#define KVM_S390_PV_COMMAND _IOWR(KVMIO, 0xc5, struct kvm_pv_cmd) +#define KVM_S390_PV_COMMAND_VCPU _IOWR(KVMIO, 0xc6, struct kvm_pv_cmd) +/* Secure Encrypted Virtualization command */ enum sev_cmd_id {/* Guest initialization commands */
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v2.1] KVM: s390: protvirt: Add initial vm and cpu lifecycle handling
Quoted 18 lines · David Hildenbrand
Quoted 8 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
This contains 3 main changes:
1. changes in SIE control block handling for secure guests
2. helper functions for create/destroy/unpack secure guests
3.KVM_S390_PV_COMMANDioctl to allow userspace dealing with secure machinesQuoted 8 lines
Signed-off-by Janosch Frank <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>---
2->2.1 - combine CREATE/DESTROY CPU/VM into ENABLE DISABLE
- rework locking and check locks with lockdep
- I still have thePV_COMMAND_CPUin here for later use in theSET_IPL_PSWioctl. If wanted I can move
Quoted 5 lines
I'd prefer to move, and eventually just turn this into a clean, separate ioctl without subcommands (e.g., if we'll only need a single subcommand in the near future). And it makes this patch a alittle easier to review ... :)
Maybe the MP_STATE solution will work out. Then we can get rid of this. will look into that when dealing with the other patch.
Quoted 4 lines
[...]
Once we lock the VCPU, it cannot be running, right?
Right, while holding the vcpu->mutex, KVM_RUN is blocked.
Quoted 12 lines
arch/s390/kvm/kvm-s390.c static int kvm_s390_set_cmma_bits(struct kvm *kvm, · line 2186
Quoted 8 lines
arch/s390/kvm/kvm-s390.c +7
-0+kvm_for_each_vcpu (i, vcpu, kvm) { +mutex_lock (&vcpu->mutex); + r =kvm_s390_pv_destroy_cpu (vcpu, rc, rrc); +mutex_unlock (&vcpu->mutex); +if (r) +break ; + }Can this actually ever fail? If so, you would leave half-initialized state around. Warn and continue?
Quoted 5 lines
Especially,
kvm_arch_vcpu_destroy()ignores any error fromkvm_s390_pv_destroy_cpu()as well ...IMHO, we should make
kvm_s390_switch_from_pv()andkvm_s390_pv_destroy_cpu()never fail.
will answer this part tomorrow.
Quoted 28 lines
Quoted 28 lines
arch/s390/kvm/kvm-s390.c +27
-0+return r; +} + +static int kvm_s390_switch_to_pv (struct kvm *kvm,u16 *rc,u16 *rrc) +{ +int i, r =0 ; +u16 dummy; + +struct kvm_vcpu *vcpu; + +kvm_for_each_vcpu (i, vcpu, kvm) { +mutex_lock (&vcpu->mutex); + r =kvm_s390_pv_create_cpu (vcpu, rc, rrc); +mutex_unlock (&vcpu->mutex); +if (r) +break ; + } +if (r) +kvm_s390_switch_from_pv (kvm,&dummy, &dummy); +return r; +} + +static int kvm_s390_handle_pv (struct kvm *kvm,struct kvm_pv_cmd *cmd) +{ +int r =0 ; +u16 dummy; +void __user *argp = (void __user *)cmd->data;
Quoted 8 lines
arch/s390/kvm/kvm-s390.c static int kvm_s390_set_cmma_bits(struct kvm *kvm, · line 2219
Quoted 6 lines
arch/s390/kvm/kvm-s390.c +6
-0+ +switch (cmd->cmd) { +case KVM_PV_ENABLE : { + r = -EINVAL ; +if (kvm_s390_pv_is_protected (kvm)) +break ;Why not factor out this check, it's common for all sucommands.
Unfortunately it is not common. Sometimes it has an "!" sometimes not.
Quoted 11 lines
arch/s390/kvm/kvm-s390.c static int kvm_s390_set_cmma_bits(struct kvm *kvm, · line 2225
Quoted 7 lines
arch/s390/kvm/kvm-s390.c +6
-0+ + r =kvm_s390_pv_alloc_vm (kvm); +if (r) +break ; + +kvm_s390_vcpu_block_all (kvm);As
kvm_s390_vcpu_block_all()does not support nesting, this will not work as expected -sca_switch_to_extended()already blocks. Are thevcpu->locksnot enough?
Right, we would need to move the sca_switch out of this lock. On the other hand the vcpu->locks should be sufficent for the host integrity (and also for the secure guest integrity))
So I will just remove the block_all here and below.
Quoted 5 lines
[...]
Quoted 2 lines
(quoted diff) +0
-0@@ -2558,10 +2735,16 @@ static void kvm_free_vcpus(struct kvm *kvm)
Quoted 12 lines
arch/s390/kvm/kvm-s390.c static void kvm_free_vcpus(struct kvm *kvm) · line 2743
Quoted 9 lines
arch/s390/kvm/kvm-s390.c +3
-1void kvm_arch_destroy_vm (struct kvm *kvm) { +u16 rc, rrc;kvm_free_vcpus (kvm);sca_dispose (kvm); -debug_unregister (kvm->arch.dbf);kvm_s390_gisa_destroy (kvm); +/* do not use the lock checking variant at tear-down */ +if (kvm_s390_pv_handle (kvm)) {
kvm_s390_pv_is_protected? I dislike usingkvm_s390_pv_handle()when we're not interested in the handle.
Then I would need to take the kvm->mutex here. This is why I added the comment. We are already at the last steps of killing the kvm and the lock is not held. So the lockdep check would complain. On the other hand grabbing kvm->lock is pointless as the kvm file descriptor is already gone so the ioctls that we would protect against cannot happen.
What about Improving the comment:
/*
* We are already at the end of life and kvm->lock is not taken.
* This is ok as the file descriptor is closed by now and nobody
* can mess with the pv state. To avoid lockdep_assert_held from
* complaining we do not use kvm_s390_pv_is_protected. */
On the other hand This looks a bit too verbose.
[...]
Quoted 8 lines
arch/s390/kvm/kvm-s390.h static inline int kvm_s390_user_cpu_state_ctrl(struct kvm *kvm) · line 226
Quoted 4 lines
arch/s390/kvm/kvm-s390.h +4
-0+static inline u64 kvm_s390_pv_handle (struct kvm *kvm) +{ +return kvm->arch.pv.handle; +}Can we rename this to
kvm_s390_pv_get_handle()
ack.
Quoted 9 lines
arch/s390/kvm/kvm-s390.h static inline int kvm_s390_user_cpu_state_ctrl(struct kvm *kvm) · line 231
Quoted 6 lines
arch/s390/kvm/kvm-s390.h +5
-0+ +static inline u64 kvm_s390_pv_handle_cpu (struct kvm_vcpu *vcpu) +{ +return vcpu->arch.pv.handle; +}Can we rename this to
kvm_s390_pv_cpu_get_handle()? (so it doesn't look like the function will handle something)
ack.
[...]
Quoted 26 lines
Quoted 12 lines
arch/s390/kvm/pv.c new file +12
-0+int kvm_s390_pv_alloc_vm (struct kvm *kvm) +{ +unsigned long base = uv_info.guest_base_stor_len; +unsigned long virt = uv_info.guest_virt_var_stor_len; +unsigned long npages =0 , vlen =0 ; +struct kvm_memory_slot *memslot; + + kvm->arch.pv.stor_var =NULL ; + kvm->arch.pv.stor_base =__get_free_pages (GFP_KERNEL ,get_order (base)); +if (!kvm->arch.pv.stor_base) +return -ENOMEM ; +arch/s390/kvm/pv.c line 48
Quoted 10 lines
arch/s390/kvm/pv.c new file +10
-0+/* +* Calculate current guest storage for allocation of the +* variable storage, which is based on the length in MB. +* +* Slots are sorted by GFN +*/ +mutex_lock (&kvm->slots_lock); + memslot =kvm_memslots (kvm)->memslots; + npages = memslot->base_gfn + memslot->npages; +mutex_unlock (&kvm->slots_lock);Are you blocking the addition of new memslots somehow?
Quoted 13 lines
arch/s390/kvm/pv.c line 157
Quoted 11 lines
arch/s390/kvm/pv.c new file +11
-0+int kvm_s390_pv_create_vm (struct kvm *kvm,u16 *rc,u16 *rrc) +{ +u16 drc, drrc; +int cc; + +struct uv_cb_cgc uvcb = { + .header.cmd =UVC_CMD_CREATE_SEC_CONF , + .header.len =sizeof (uvcb) + }; + +if (kvm_s390_pv_handle (kvm))Why is that necessary? We should only be called in PV mode.
It is not because the caller already checks. It was necessary in a previous version I guess.
[...]
Quoted 7 lines
Quoted 7 lines
arch/s390/kvm/pv.c new file +7
-0+int kvm_s390_pv_set_sec_parms (struct kvm *kvm,void *hdr,u64 length,u16 *rc, +u16 *rrc) +{ +struct uv_cb_ssc uvcb = { + .header.cmd =UVC_CMD_SET_SEC_CONF_PARAMS , + .header.len =sizeof (uvcb), + .sec_header_origin = (u64 )hdr,
Quoted 8 lines
arch/s390/kvm/pv.c line 198
Quoted 6 lines
arch/s390/kvm/pv.c new file +6
-0+ .sec_header_len = length, + .guest_handle = kvm_s390_pv_handle(kvm), + }; +int cc; + +if (!kvm_s390_pv_handle (kvm))Why is that necessary? We should only be called in PV mode.
ack
[...]
Quoted 5 lines
include/uapi/linux/kvm.h struct kvm_enc_region { · line 1484
Quoted 3 lines
include/uapi/linux/kvm.h +3
-0+struct kvm_s390_pv_sec_parm { +__u64 origin; +__u64 length;tabs vs. spaces. (I'd use a single space like in
kvm_s390_pv_unpbelow)
ack.
[...]
Re: [PATCH v2.1] KVM: s390: protvirt: Add initial vm and cpu lifecycle handling
Quoted 37 lines
Quoted 28 lines
Quoted 28 lines
arch/s390/kvm/kvm-s390.c +27
-0+return r; +} + +static int kvm_s390_switch_to_pv (struct kvm *kvm,u16 *rc,u16 *rrc) +{ +int i, r =0 ; +u16 dummy; + +struct kvm_vcpu *vcpu; + +kvm_for_each_vcpu (i, vcpu, kvm) { +mutex_lock (&vcpu->mutex); + r =kvm_s390_pv_create_cpu (vcpu, rc, rrc); +mutex_unlock (&vcpu->mutex); +if (r) +break ; + } +if (r) +kvm_s390_switch_from_pv (kvm,&dummy, &dummy); +return r; +} + +static int kvm_s390_handle_pv (struct kvm *kvm,struct kvm_pv_cmd *cmd) +{ +int r =0 ; +u16 dummy; +void __user *argp = (void __user *)cmd->data;Quoted 8 lines
arch/s390/kvm/kvm-s390.c static int kvm_s390_set_cmma_bits(struct kvm *kvm, · line 2219
Quoted 6 lines
arch/s390/kvm/kvm-s390.c +6
-0+ +switch (cmd->cmd) { +case KVM_PV_ENABLE : { + r = -EINVAL ; +if (kvm_s390_pv_is_protected (kvm)) +break ;Why not factor out this check, it's common for all sucommands.
Quoted 1 line
Unfortunately it is not common. Sometimes it has an "!" sometimes not.
Right, makes sense.
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v2.1] KVM: s390: protvirt: Add initial vm and cpu lifecycle handling
In reply to David HildenbrandOn 18.02.20 10:12, David Hildenbrand wrote:
ock the VCPU, it cannot be running, right?
Quoted 10 lines
arch/s390/kvm/kvm-s390.c static int kvm_s390_set_cmma_bits(struct kvm *kvm, · line 2186
Quoted 8 lines
arch/s390/kvm/kvm-s390.c +7
-0+kvm_for_each_vcpu (i, vcpu, kvm) { +mutex_lock (&vcpu->mutex); + r =kvm_s390_pv_destroy_cpu (vcpu, rc, rrc); +mutex_unlock (&vcpu->mutex); +if (r) +break ; + }Can this actually ever fail?
Every reason for failure seems to be wrong usage by KVM. So it should not fail and if if does we should probably warn.
If so, you would leave half-initialized
Quoted 1 line
state around. Warn and continue?
So yes, maybe warn and try to continue to destroy the remaining CPUs.
Quoted 6 lines
Especially,
kvm_arch_vcpu_destroy()ignores any error fromkvm_s390_pv_destroy_cpu()as well ...IMHO, we should make
kvm_s390_switch_from_pv()andkvm_s390_pv_destroy_cpu()never fail.
ack.
Re: [PATCH v2.1] KVM: s390: protvirt: Add initial vm and cpu lifecycle handling
In reply to Christian BorntraegerQuoted 271 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
This contains 3 main changes:
1. changes in SIE control block handling for secure guests
2. helper functions for create/destroy/unpack secure guests
3.KVM_S390_PV_COMMANDioctl to allow userspace dealing with secure machinesSigned-off-by Janosch Frank <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>---
2->2.1 - combine CREATE/DESTROY CPU/VM into ENABLE DISABLE
- rework locking and check locks with lockdep
- I still have thePV_COMMAND_CPUin here for later use in theSET_IPL_PSWioctl. If wanted I can move
- change CAP numberarch/s390/include/asm/kvm_host.h | 24 ++- arch/s390/include/asm/uv.h | 69 ++++++++ arch/s390/kvm/Makefile | 2 +- arch/s390/kvm/kvm-s390.c | 231 ++++++++++++++++++++++++++- arch/s390/kvm/kvm-s390.h | 35 +++++ arch/s390/kvm/pv.c | 262 +++++++++++++++++++++++++++++++ include/uapi/linux/kvm.h | 35 +++++ 7 files changed, 654 insertions(+), 4 deletions(-) create mode 100644 arch/s390/kvm/pv.carch/s390/include/asm/kvm_host.h +22
-2@@ -160,7 +160,13 @@ struct kvm_s390_sie_block {__u8 reserved08[4 ];/* 0x0008 */ #define PROG_IN_SIE (1<<0)__u32 prog0c;/* 0x000c */ -__u8 reserved10[16 ];/* 0x0010 */ +union { +__u8 reserved10[16 ];/* 0x0010 */ +struct { +__u64 pv_handle_cpu; +__u64 pv_handle_config; + }; + };#define PROG_BLOCK_SIE (1<<0)#define PROG_REQUEST (1<<1)atomic_t prog20;/* 0x0020 */ @@ -233,7 +239,7 @@ struct kvm_s390_sie_block {#define ECB3_RI 0x01__u8 ecb3;/* 0x0063 */ __u32 scaol;/* 0x0064 */ -__u8 reserved68;/* 0x0068 */ +__u8 sdf;/* 0x0068 */ __u8 epdx;/* 0x0069 */ __u8 reserved6a[2 ];/* 0x006a */ __u32 todpr;/* 0x006c */ @@ -645,6 +651,11 @@ struct kvm_guestdbg_info_arch {unsigned long last_bp; }; +struct kvm_s390_pv_vcpu { +u64 handle; +unsigned long stor_base; +}; +struct kvm_vcpu_arch {struct kvm_s390_sie_block *sie_block;/* if vsie is active, currently executed shadow sie control block */ @@ -673,6 +684,7 @@ struct kvm_vcpu_arch {__u64 cputm_start;bool gs_enabled;bool skey_enabled; +struct kvm_s390_pv_vcpu pv; };struct kvm_vm_stat {@@ -843,6 +855,13 @@ struct kvm_s390_gisa_interrupt {DECLARE_BITMAP (kicked_mask,KVM_MAX_VCPUS ); }; +struct kvm_s390_pv { +u64 handle; +u64 guest_len; +unsigned long stor_base; +void *stor_var; +}; +struct kvm_arch {void *sca;int use_esca;@@ -878,6 +897,7 @@ struct kvm_arch{DECLARE_BITMAP (cpu_feat,KVM_S390_VM_CPU_FEAT_NR_BITS );DECLARE_BITMAP (idle_mask,KVM_MAX_VCPUS );struct kvm_s390_gisa_interrupt gisa_int; +struct kvm_s390_pv pv; };#define KVM_HVA_ERR_BAD (-1UL)arch/s390/include/asm/uv.h +69
-0@@ -23,11 +23,19 @@#define UVC_RC_INV_STATE 0x0003#define UVC_RC_INV_LEN 0x0005#define UVC_RC_NO_RESUME 0x0007 +#define UVC_RC_NEED_DESTROY 0x8000#define UVC_CMD_QUI 0x0001#define UVC_CMD_INIT_UV 0x000f +#define UVC_CMD_CREATE_SEC_CONF 0x0100 +#define UVC_CMD_DESTROY_SEC_CONF 0x0101 +#define UVC_CMD_CREATE_SEC_CPU 0x0120 +#define UVC_CMD_DESTROY_SEC_CPU 0x0121#define UVC_CMD_CONV_TO_SEC_STOR 0x0200#define UVC_CMD_CONV_FROM_SEC_STOR 0x0201 +#define UVC_CMD_SET_SEC_CONF_PARAMS 0x0300 +#define UVC_CMD_UNPACK_IMG 0x0301 +#define UVC_CMD_VERIFY_IMG 0x0302#define UVC_CMD_PIN_PAGE_SHARED 0x0341#define UVC_CMD_UNPIN_PAGE_SHARED 0x0342#define UVC_CMD_SET_SHARED_ACCESS 0x1000@@ -37,10 +45,17 @@enum uv_cmds_inst {BIT_UVC_CMD_QUI =0 ,BIT_UVC_CMD_INIT_UV =1 , +BIT_UVC_CMD_CREATE_SEC_CONF =2 , +BIT_UVC_CMD_DESTROY_SEC_CONF =3 , +BIT_UVC_CMD_CREATE_SEC_CPU =4 , +BIT_UVC_CMD_DESTROY_SEC_CPU =5 ,BIT_UVC_CMD_CONV_TO_SEC_STOR =6 ,BIT_UVC_CMD_CONV_FROM_SEC_STOR =7 ,BIT_UVC_CMD_SET_SHARED_ACCESS =8 ,BIT_UVC_CMD_REMOVE_SHARED_ACCESS =9 , +BIT_UVC_CMD_SET_SEC_PARMS =11 , +BIT_UVC_CMD_UNPACK_IMG =13 , +BIT_UVC_CMD_VERIFY_IMG =14 ,BIT_UVC_CMD_PIN_PAGE_SHARED =21 ,BIT_UVC_CMD_UNPIN_PAGE_SHARED =22 , };@@ -52,6 +67,7 @@ struct uv_cb_header {u16 rrc;/* Return Reason Code */ } __packed__aligned(8) ; +/* Query Ultravisor Information */ struct uv_cb_qui {struct uv_cb_header header;u64 reserved08;@@ -71,6 +87,7 @@ struct uv_cb_qui {u64 reserveda0; } __packed__aligned(8) ; +/* Initialize Ultravisor */ struct uv_cb_init {struct uv_cb_header header;u64 reserved08[2 ];@@ -79,6 +96,35 @@ struct uv_cb_init {u64 reserved28[4 ]; } __packed__aligned(8) ; +/* Create Guest Configuration */ +struct uv_cb_cgc { +struct uv_cb_header header; +u64 reserved08[2 ]; +u64 guest_handle; +u64 conf_base_stor_origin; +u64 conf_virt_stor_origin; +u64 reserved30; +u64 guest_stor_origin; +u64 guest_stor_len; +u64 guest_sca; +u64 guest_asce; +u64 reserved58[5 ]; +} __packed__aligned(8) ; + +/* Create Secure CPU */ +struct uv_cb_csc { +struct uv_cb_header header; +u64 reserved08[2 ]; +u64 cpu_handle; +u64 guest_handle; +u64 stor_origin; +u8 reserved30[6 ]; +u16 num; +u64 state_origin; +u64 reserved40[4 ]; +} __packed__aligned(8) ; + +/* Convert to Secure */ struct uv_cb_cts {struct uv_cb_header header;u64 reserved08[2 ];@@ -86,12 +132,34 @@ struct uv_cb_cts {u64 gaddr; } __packed__aligned(8) ; +/* Convert from Secure / Pin Page Shared */ struct uv_cb_cfs {struct uv_cb_header header;u64 reserved08[2 ];u64 paddr; } __packed__aligned(8) ; +/* Set Secure Config Parameter */ +struct uv_cb_ssc { +struct uv_cb_header header; +u64 reserved08[2 ]; +u64 guest_handle; +u64 sec_header_origin; +u32 sec_header_len; +u32 reserved2c; +u64 reserved30[4 ]; +} __packed__aligned(8) ; + +/* Unpack */ +struct uv_cb_unp { +struct uv_cb_header header; +u64 reserved08[2 ]; +u64 guest_handle; +u64 gaddr; +u64 tweak[2 ]; +u64 reserved38[3 ]; +} __packed__aligned(8) ; +/* * A common UV call struct for calls that take no payload * Examples: @@ -105,6 +173,7 @@ struct uv_cb_nodata {u64 reserved20[4 ]; } __packed__aligned(8) ; +/* Set Shared Access */ struct uv_cb_share {struct uv_cb_header header;u64 reserved08[3 ];arch/s390/kvm/Makefile +1
-1@@ -9,6 +9,6 @@ common-objs = $(KVM)/kvm_main.o $(KVM)/eventfd.o $(KVM)/async_pf.o $(KVM)/irqch ccflags-y := -Ivirt/kvm -Iarch/s390/kvm kvm-objs := $(common-objs) kvm-s390.o intercept.o interrupt.o priv.o sigp.o -kvm-objs += diag.o gaccess.o guestdbg.o vsie.o +kvm-objs += diag.o gaccess.o guestdbg.o vsie.o pv.o obj-$(CONFIG_KVM) += kvm.oarch/s390/kvm/kvm-s390.c +3
-0@@ -44,6 +44,7 @@#include <asm/cpacf.h> #include <asm/timex.h> #include <asm/ap.h> +#include <asm/uv.h> #include "kvm-s390.h" #include "gaccess.h" @@ -234,8 +235,10 @@ int kvm_arch_check_processor_compat(void)return 0 ; } +/* forward declarations */ static void kvm_gmap_notifier (struct gmap *gmap,unsigned long start,unsigned long end); +static int sca_switch_to_extended (struct kvm *kvm);static void kvm_clock_sync_scb (struct kvm_s390_sie_block *scb,u64 delta) {
arch/s390/kvm/kvm-s390.c int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) · line 579
Quoted 6 lines
arch/s390/kvm/kvm-s390.c +3
-0@@ -571,6 +574,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)case KVM_CAP_S390_BPB : r =test_facility (82 );break ; +case KVM_CAP_S390_PROTECTED : + r =is_prot_virt_host (); +break ;
FWIW, the clean thing to do is to enable the capability only after all features have been implemented, so as the very last patch.
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v2.1] KVM: s390: protvirt: Add initial vm and cpu lifecycle handling
Quoted 13 lines · David Hildenbrand
arch/s390/kvm/kvm-s390.c int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) · line 579
Quoted 7 lines · Christian Borntraeger
arch/s390/kvm/kvm-s390.c +3
-0@@ -571,6 +574,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)case KVM_CAP_S390_BPB : r =test_facility (82 );break ; +case KVM_CAP_S390_PROTECTED : + r =is_prot_virt_host (); +break ;FWIW, the clean thing to do is to enable the capability only after all features have been implemented, so as the very last patch.
Ack.
PATCH v2 10/42 KVM: s390: protvirt: Add KVM api documentation
In reply to Christian BorntraegerFrom: Janosch Frank <[email protected]>
Add documentation for KVM_CAP_S390_PROTECTED capability and the KVM_S390_PV_COMMAND and KVM_S390_PV_COMMAND_VCPU ioctls.
--- Documentation/virt/kvm/api.rst | 69 ++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+)
Documentation/virt/kvm/api.rst +69 -0
@@ -4646,6 +4646,68 @@ the clear cpu reset definition in the POP. However, the cpu is not put into ESA mode. This reset is a superset of the initial reset. +4.125 KVM_S390_PV_COMMAND +------------------------- + +:Capability: KVM_CAP_S390_PROTECTED +:Architectures: s390 +:Type: vm ioctl +:Parameters: struct kvm_pv_cmd +:Returns: 0 on success, < 0 on error + +:: + + struct kvm_pv_cmd { + __u32 cmd; /* Command to be executed */ + __u16 rc; /* Ultravisor return code */ + __u16 rrc; /* Ultravisor return reason code */ + __u64 data; /* Data or address */ + __u32 flags; /* flags for future extensions. Must be 0 for now */ + __u32 reserved[3]; + }; + +cmd values: + +KVM_PV_VM_CREATE + Allocate memory and register the VM with the Ultravisor, thereby + donating memory to the Ultravisor making it inaccessible to KVM. + +KVM_PV_VM_DESTROY + Deregisters the VM from the Ultravisor and frees memory that was + donated, so the kernel can use it again. All registered VCPUs have to + be unregistered beforehand and all memory has to be exported or + shared. + +KVM_PV_VM_SET_SEC_PARMS + Pass the image header from VM memory to the Ultravisor in + preparation of image unpacking and verification. + +KVM_PV_VM_UNPACK + Unpack (protect and decrypt) a page of the encrypted boot image. + +KVM_PV_VM_VERIFY + Verify the integrity of the unpacked image. Only if this succeeds, + KVM is allowed to start protected VCPUs. + +4.126 KVM_S390_PV_COMMAND_VCPU +------------------------------ + +:Capability: KVM_CAP_S390_PROTECTED +:Architectures: s390 +:Type: vcpu ioctl +:Parameters: struct kvm_pv_cmd +:Returns: 0 on success, < 0 on error + +cmd values: + +KVM_PV_VCPU_CREATE + Allocate memory and register a VCPU with the Ultravisor, thereby + donating memory to the Ultravisor making it inaccessible to KVM. + +KVM_PV_VCPU_DESTROY + Unregisters the VCPU from the Ultravisor and frees memory that was + donated, so the kernel can use it again. + 5. The kvm_run structure ========================
@@ -6024,3 +6086,10 @@ Architectures: s390 This capability indicates that the KVM_S390_NORMAL_RESET and KVM_S390_CLEAR_RESET ioctls are available. + +8.23 KVM_CAP_S390_PROTECTED + +Architecture: s390 + +This capability indicates that KVM can start protected VMs and the +Ultravisor has therefore been initialized.
Signature · 1 line
2.25.0
PATCH v2 11/42 KVM: s390: protvirt: Secure memory is not mergeable
In reply to Christian BorntraegerFrom: Janosch Frank <[email protected]>
KSM will not work on secure pages, because when the kernel reads a secure page, it will be encrypted and hence no two pages will look the same.
Let's mark the guest pages as unmergeable when we transition to secure mode.
--- arch/s390/include/asm/gmap.h | 1 + arch/s390/kvm/kvm-s390.c | 8 ++++++++ arch/s390/mm/gmap.c | 30 ++++++++++++++++++++---------- 3 files changed, 29 insertions(+), 10 deletions(-)
arch/s390/include/asm/gmap.h +1 -0
@@ -148,4 +148,5 @@ int gmap_mprotect_notify(struct gmap *, unsigned long start,void gmap_sync_dirty_log_pmd (struct gmap *gmap,unsigned long dirty_bitmap[4 ],unsigned long gaddr,unsigned long vmaddr); +int gmap_mark_unmergeable (void );#endif /* _ASM_S390_GMAP_H */
arch/s390/kvm/kvm-s390.c +8 -0
@@ -2186,6 +2186,14 @@ static int kvm_s390_handle_pv(struct kvm *kvm, struct kvm_pv_cmd *cmd)if (r)break ; +down_write (¤t->mm->mmap_sem); + r =gmap_mark_unmergeable (); +up_write (¤t->mm->mmap_sem); +if (r) { +kvm_s390_pv_dealloc_vm (kvm); +break ; + } +mutex_lock (&kvm->lock);kvm_s390_vcpu_block_all (kvm);/* FMT 4 SIE needs esca */
arch/s390/mm/gmap.c +20 -10
@@ -2548,6 +2548,22 @@ int s390_enable_sie(void) }EXPORT_SYMBOL_GPL (s390_enable_sie); +int gmap_mark_unmergeable (void ) +{ +struct mm_struct *mm = current->mm; +struct vm_area_struct *vma; + +for (vma = mm->mmap; vma; vma = vma->vm_next) { +if (ksm_madvise (vma, vma->vm_start, vma->vm_end, +MADV_UNMERGEABLE , &vma->vm_flags)) { +return -ENOMEM ; + } + } + mm->def_flags &= ~VM_MERGEABLE ; +return 0 ; +} +EXPORT_SYMBOL_GPL (gmap_mark_unmergeable); +/* * Enable storage key handling from now on and initialize the storage * keys with the default key.
@@ -2593,7 +2609,6 @@ static const struct mm_walk_ops enable_skey_walk_ops = {int s390_enable_skey (void ) {struct mm_struct *mm = current->mm; -struct vm_area_struct *vma;int rc =0 ;down_write (&mm->mmap_sem);
@@ -2601,16 +2616,11 @@ int s390_enable_skey(void) goto out_up; mm->context.uses_skeys =1 ; -for (vma = mm->mmap; vma; vma = vma->vm_next) { -if (ksm_madvise (vma, vma->vm_start, vma->vm_end, -MADV_UNMERGEABLE , &vma->vm_flags)) { - mm->context.uses_skeys =0 ; - rc = -ENOMEM ; - goto out_up; - } + rc =gmap_mark_unmergeable (); +if (rc) { + mm->context.uses_skeys =0 ; + goto out_up; } - mm->def_flags &= ~VM_MERGEABLE ; -walk_page_range (mm,0 ,TASK_SIZE , &enable_skey_walk_ops,NULL ); out_up:
Signature · 1 line
2.25.0
PATCH v2 12/42 KVM: s390/mm: Make pages accessible before destroying the guest
In reply to Christian BorntraegerBefore we destroy the secure configuration, we better make all pages accessible again. This also happens during reboot, where we reboot into a non-secure guest that then can go again into secure mode. As this "new" secure guest will have a new ID we cannot reuse the old page state.
--- arch/s390/include/asm/gmap.h | 1 + arch/s390/kvm/pv.c | 2 ++ arch/s390/mm/gmap.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+)
arch/s390/include/asm/gmap.h +1 -0
@@ -149,4 +149,5 @@ int gmap_mprotect_notify(struct gmap *, unsigned long start,void gmap_sync_dirty_log_pmd (struct gmap *gmap,unsigned long dirty_bitmap[4 ],unsigned long gaddr,unsigned long vmaddr);int gmap_mark_unmergeable (void ); +void s390_reset_acc (struct mm_struct *mm);#endif /* _ASM_S390_GMAP_H */
arch/s390/kvm/pv.c +2 -0
@@ -66,6 +66,8 @@ int kvm_s390_pv_destroy_vm(struct kvm *kvm, u16 *rc, u16 *rrc) {int cc; +/* make all pages accessible before destroying the guest */ +s390_reset_acc (kvm->mm); cc =uv_cmd_nodata (kvm_s390_pv_handle (kvm),UVC_CMD_DESTROY_SEC_CONF , rc, rrc);WRITE_ONCE (kvm->arch.gmap->guest_handle,0 );
arch/s390/mm/gmap.c +35 -0
@@ -2650,3 +2650,38 @@ void s390_reset_cmma(struct mm_struct *mm)up_write (&mm->mmap_sem); }EXPORT_SYMBOL_GPL (s390_reset_cmma); + +/* +* make inaccessible pages accessible again +*/ +static int __s390_reset_acc (pte_t *ptep,unsigned long addr, +unsigned long next,struct mm_walk *walk) +{ +pte_t pte =READ_ONCE (*ptep); + +if (pte_present (pte)) +WARN_ON_ONCE (uv_convert_from_secure (pte_val (pte) &PAGE_MASK )); +return 0 ; +} + +static const struct mm_walk_ops reset_acc_walk_ops = { + .pte_entry = __s390_reset_acc, +}; + +#include <linux/sched/mm.h> +void s390_reset_acc (struct mm_struct *mm) +{ +/* +* we might be called during +* reset: we walk the pages and clear +* close of all kvm file descriptors: we walk the pages and clear +* exit of process on fd closure: vma already gone, do nothing +*/ +if (!mmget_not_zero (mm)) +return ; +down_read (&mm->mmap_sem); +walk_page_range (mm,0 ,TASK_SIZE , &reset_acc_walk_ops,NULL ); +up_read (&mm->mmap_sem); +mmput (mm); +} +EXPORT_SYMBOL_GPL (s390_reset_acc);
Signature · 1 line
2.25.0
PATCH v2 13/42 KVM: s390: protvirt: Handle SE notification interceptions
In reply to Christian BorntraegerFrom: Janosch Frank <[email protected]>
Since there is no interception for load control and load psw instruction in the protected mode, we need a new way to get notified whenever we can inject an IRQ right after the guest has just enabled the possibility for receiving them.
The new interception codes solve that problem by providing a notification for changes to IRQ enablement relevant bits in CRs 0, 6 and 14, as well a the machine check mask bit in the PSW.
No special handling is needed for these interception codes, the KVM pre-run code will consult all necessary CRs and PSW bits and inject IRQs the guest is enabled for.
--- arch/s390/include/asm/kvm_host.h | 2 ++ arch/s390/kvm/intercept.c | 9 +++++++++ 2 files changed, 11 insertions(+)
arch/s390/include/asm/kvm_host.h +2 -0
@@ -215,6 +215,8 @@ struct kvm_s390_sie_block {#define ICPT_PARTEXEC 0x38#define ICPT_IOINST 0x40#define ICPT_KSS 0x5c +#define ICPT_MCHKREQ 0x60 +#define ICPT_INT_ENABLE 0x64__u8 icptcode;/* 0x0050 */ __u8 icptstatus;/* 0x0051 */ __u16 ihcpu;/* 0x0052 */
arch/s390/kvm/intercept.c +9 -0
@@ -480,6 +480,15 @@ int kvm_handle_sie_intercept(struct kvm_vcpu *vcpu)case ICPT_KSS : rc =kvm_s390_skey_check_enable (vcpu);break ; +case ICPT_MCHKREQ : +case ICPT_INT_ENABLE : +/* +* PSW bit 13 or a CR (0, 6, 14) changed and we might +* now be able to deliver interrupts. The pre-run code +* will take care of this. +*/ + rc =0 ; +break ;default :return -EOPNOTSUPP ; }
Signature · 1 line
2.25.0
PATCH v2 14/42 KVM: s390: protvirt: Instruction emulation
In reply to Christian BorntraegerFrom: Janosch Frank <[email protected]>
We have two new SIE exit codes dealing with instructions. 104 (0x68) for a secure instruction interception, on which the SIE needs hypervisor action to complete the instruction. We can piggy-back on the existing instruction handlers.
108 which is merely a notification and provides data for tracking and management. For example this is used to tell the host about a new value for the prefix register. As there will be several special case handlers in later patches, we handle this in a separate function.
--- arch/s390/include/asm/kvm_host.h | 2 ++ arch/s390/kvm/intercept.c | 11 +++++++++++ 2 files changed, 13 insertions(+)
arch/s390/include/asm/kvm_host.h +2 -0
@@ -217,6 +217,8 @@ struct kvm_s390_sie_block {#define ICPT_KSS 0x5c#define ICPT_MCHKREQ 0x60#define ICPT_INT_ENABLE 0x64 +#define ICPT_PV_INSTR 0x68 +#define ICPT_PV_NOTIFY 0x6c__u8 icptcode;/* 0x0050 */ __u8 icptstatus;/* 0x0051 */ __u16 ihcpu;/* 0x0052 */
arch/s390/kvm/intercept.c +11 -0
@@ -444,6 +444,11 @@ static int handle_operexc(struct kvm_vcpu *vcpu)return kvm_s390_inject_program_int (vcpu,PGM_OPERATION ); } +static int handle_pv_notification (struct kvm_vcpu *vcpu) +{ +return handle_instruction (vcpu); +} +int kvm_handle_sie_intercept (struct kvm_vcpu *vcpu) {int rc, per_rc =0 ;
@@ -489,6 +494,12 @@ int kvm_handle_sie_intercept(struct kvm_vcpu *vcpu)*/ rc =0 ;break ; +case ICPT_PV_INSTR : + rc =handle_instruction (vcpu); +break ; +case ICPT_PV_NOTIFY : + rc =handle_pv_notification (vcpu); +break ;default :return -EOPNOTSUPP ; }
Signature · 1 line
2.25.0
PATCH v2 15/42 KVM: s390: protvirt: Add interruption injection controls
In reply to Christian BorntraegerFrom: Michael Mueller <[email protected]>
This defines the necessary data structures in the SIE control block to inject machine checks,external and I/O interrupts. We first define the the interrupt injection control, which defines the next interrupt to inject. Then we define the fields that contain the payload for machine checks,external and I/O interrupts
--- arch/s390/include/asm/kvm_host.h | 56 +++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 12 deletions(-)
arch/s390/include/asm/kvm_host.h +44 -12
@@ -222,7 +222,15 @@ struct kvm_s390_sie_block {__u8 icptcode;/* 0x0050 */ __u8 icptstatus;/* 0x0051 */ __u16 ihcpu;/* 0x0052 */ -__u8 reserved54[2 ];/* 0x0054 */ +__u8 reserved54;/* 0x0054 */ +#define IICTL_CODE_NONE 0x00 +#define IICTL_CODE_MCHK 0x01 +#define IICTL_CODE_EXT 0x02 +#define IICTL_CODE_IO 0x03 +#define IICTL_CODE_RESTART 0x04 +#define IICTL_CODE_SPECIFICATION 0x10 +#define IICTL_CODE_OPERAND 0x11 +__u8 iictl;/* 0x0055 */ __u16 ipa;/* 0x0056 */ __u32 ipb;/* 0x0058 */ __u32 scaoh;/* 0x005c */
@@ -259,24 +267,48 @@ struct kvm_s390_sie_block {#define HPID_KVM 0x4#define HPID_VSIE 0x5__u8 hpid;/* 0x00b8 */ -__u8 reservedb9[11 ];/* 0x00b9 */ -__u16 extcpuaddr;/* 0x00c4 */ -__u16 eic;/* 0x00c6 */ +__u8 reservedb9[7 ];/* 0x00b9 */ +union { +struct { +__u32 eiparams;/* 0x00c0 */ +__u16 extcpuaddr;/* 0x00c4 */ +__u16 eic;/* 0x00c6 */ + }; +__u64 mcic;/* 0x00c0 */ + } __packed;__u32 reservedc8;/* 0x00c8 */ -__u16 pgmilc;/* 0x00cc */ -__u16 iprcc;/* 0x00ce */ -__u32 dxc;/* 0x00d0 */ -__u16 mcn;/* 0x00d4 */ -__u8 perc;/* 0x00d6 */ -__u8 peratmid;/* 0x00d7 */ +union { +struct { +__u16 pgmilc;/* 0x00cc */ +__u16 iprcc;/* 0x00ce */ + }; +__u32 edc;/* 0x00cc */ + } __packed; +union { +struct { +__u32 dxc;/* 0x00d0 */ +__u16 mcn;/* 0x00d4 */ +__u8 perc;/* 0x00d6 */ +__u8 peratmid;/* 0x00d7 */ + }; +__u64 faddr;/* 0x00d0 */ + } __packed;__u64 peraddr;/* 0x00d8 */ __u8 eai;/* 0x00e0 */ __u8 peraid;/* 0x00e1 */ __u8 oai;/* 0x00e2 */ __u8 armid;/* 0x00e3 */ __u8 reservede4[4 ];/* 0x00e4 */ -__u64 tecmc;/* 0x00e8 */ -__u8 reservedf0[12 ];/* 0x00f0 */ +union { +__u64 tecmc;/* 0x00e8 */ +struct { +__u16 subchannel_id;/* 0x00e8 */ +__u16 subchannel_nr;/* 0x00ea */ +__u32 io_int_parm;/* 0x00ec */ +__u32 io_int_word;/* 0x00f0 */ + }; + } __packed; +__u8 reservedf4[8 ];/* 0x00f4 */ #define CRYCB_FORMAT_MASK 0x00000003#define CRYCB_FORMAT0 0x00000000#define CRYCB_FORMAT1 0x00000001
Signature · 1 line
2.25.0
Re: [PATCH v2 15/42] KVM: s390: protvirt: Add interruption injection controls
Quoted 88 lines · Christian Borntraeger
From: Michael Mueller <[email protected]>
This defines the necessary data structures in the SIE control block to inject machine checks,external and I/O interrupts. We first define the the interrupt injection control, which defines the next interrupt to inject. Then we define the fields that contain the payload for machine checks,external and I/O interrupts
Signed-off-by Michael Mueller <[email protected]>Reviewed-by Thomas Huth <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/include/asm/kvm_host.h | 56 +++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 12 deletions(-)arch/s390/include/asm/kvm_host.h +37
-12@@ -222,7 +222,15 @@ struct kvm_s390_sie_block {__u8 icptcode;/* 0x0050 */ __u8 icptstatus;/* 0x0051 */ __u16 ihcpu;/* 0x0052 */ -__u8 reserved54[2 ];/* 0x0054 */ +__u8 reserved54;/* 0x0054 */ +#define IICTL_CODE_NONE 0x00 +#define IICTL_CODE_MCHK 0x01 +#define IICTL_CODE_EXT 0x02 +#define IICTL_CODE_IO 0x03 +#define IICTL_CODE_RESTART 0x04 +#define IICTL_CODE_SPECIFICATION 0x10 +#define IICTL_CODE_OPERAND 0x11 +__u8 iictl;/* 0x0055 */ __u16 ipa;/* 0x0056 */ __u32 ipb;/* 0x0058 */ __u32 scaoh;/* 0x005c */ @@ -259,24 +267,48 @@ struct kvm_s390_sie_block {#define HPID_KVM 0x4#define HPID_VSIE 0x5__u8 hpid;/* 0x00b8 */ -__u8 reservedb9[11 ];/* 0x00b9 */ -__u16 extcpuaddr;/* 0x00c4 */ -__u16 eic;/* 0x00c6 */ +__u8 reservedb9[7 ];/* 0x00b9 */ +union { +struct { +__u32 eiparams;/* 0x00c0 */ +__u16 extcpuaddr;/* 0x00c4 */ +__u16 eic;/* 0x00c6 */ + }; +__u64 mcic;/* 0x00c0 */ + } __packed;__u32 reservedc8;/* 0x00c8 */ -__u16 pgmilc;/* 0x00cc */ -__u16 iprcc;/* 0x00ce */ -__u32 dxc;/* 0x00d0 */ -__u16 mcn;/* 0x00d4 */ -__u8 perc;/* 0x00d6 */ -__u8 peratmid;/* 0x00d7 */ +union { +struct { +__u16 pgmilc;/* 0x00cc */ +__u16 iprcc;/* 0x00ce */ + }; +__u32 edc;/* 0x00cc */ + } __packed; +union { +struct { +__u32 dxc;/* 0x00d0 */ +__u16 mcn;/* 0x00d4 */ +__u8 perc;/* 0x00d6 */ +__u8 peratmid;/* 0x00d7 */ + }; +__u64 faddr;/* 0x00d0 */ + } __packed;__u64 peraddr;/* 0x00d8 */ __u8 eai;/* 0x00e0 */ __u8 peraid;/* 0x00e1 */ __u8 oai;/* 0x00e2 */ __u8 armid;/* 0x00e3 */ __u8 reservede4[4 ];/* 0x00e4 */ -__u64 tecmc;/* 0x00e8 */ -__u8 reservedf0[12 ];/* 0x00f0 */ + union { + __u64 tecmc; /* 0x00e8 */ + struct {
arch/s390/include/asm/kvm_host.h struct kvm_s390_sie_block { · line 314
Quoted 10 lines
arch/s390/include/asm/kvm_host.h +7
-0+__u16 subchannel_id;/* 0x00e8 */ +__u16 subchannel_nr;/* 0x00ea */ +__u32 io_int_parm;/* 0x00ec */ +__u32 io_int_word;/* 0x00f0 */ + }; + } __packed; +__u8 reservedf4[8 ];/* 0x00f4 */ #define CRYCB_FORMAT_MASK 0x00000003#define CRYCB_FORMAT0 0x00000000#define CRYCB_FORMAT1 0x00000001
I'd just squash that into the patch where it is actually used. (IOW, the next one)
Signature · 3 lines
Thanks, David / dhildenb
PATCH v2 16/42 KVM: s390: protvirt: Implement interruption injection
In reply to Christian BorntraegerFrom: Michael Mueller <[email protected]>
The patch implements interruption injection for the following list of interruption types:
- I/O (uses inject io interruption)
__deliver_io
- External (uses inject external interruption)
__deliver_cpu_timer
__deliver_ckc
__deliver_emergency_signal
__deliver_external_call
- cpu restart (uses inject restart interruption) __deliver_restart
- machine checks (uses mcic, failing address and external damage) __write_machine_check
Please note that posted interrupts (GISA) are not used for protected guests as of today.
The service interrupt is handled in a followup patch.
--- arch/s390/include/asm/kvm_host.h | 6 ++ arch/s390/kvm/interrupt.c | 110 +++++++++++++++++++++++-------- 2 files changed, 89 insertions(+), 27 deletions(-)
arch/s390/include/asm/kvm_host.h +6 -0
@@ -578,6 +578,12 @@ enum irq_types {#define IRQ_PEND_MCHK_MASK ((1UL << IRQ_PEND_MCHK_REP) | \ (1UL << IRQ_PEND_MCHK_EX)) +#define IRQ_PEND_EXT_II_MASK ((1UL << IRQ_PEND_EXT_CPU_TIMER) | \ + (1UL << IRQ_PEND_EXT_CLOCK_COMP) | \ + (1UL << IRQ_PEND_EXT_EMERGENCY) | \ + (1UL << IRQ_PEND_EXT_EXTERNAL) | \ + (1UL << IRQ_PEND_EXT_SERVICE)) +struct kvm_s390_interrupt_info {struct list_head list;u64 type;
arch/s390/kvm/interrupt.c +83 -27
189 lines not on this page · raw message
Signature · 1 line
2.25.0
PATCH v2 17/42 KVM: s390: protvirt: Add SCLP interrupt handling
In reply to Christian BorntraegerThe sclp interrupt is kind of special. The ultravisor polices that we do not inject an sclp interrupt with payload if no sccb is outstanding. On the other hand we have "asynchronous" event interrupts, e.g. for console input.
We separate both variants into sclp interrupt and sclp event interrupt. The sclp interrupt is masked until a previous servc instruction has finished (sie exit 108).
--- arch/s390/include/asm/kvm_host.h | 6 ++- arch/s390/kvm/intercept.c | 27 ++++++++++ arch/s390/kvm/interrupt.c | 93 +++++++++++++++++++++++++------- arch/s390/kvm/kvm-s390.c | 4 ++ 4 files changed, 111 insertions(+), 19 deletions(-)
arch/s390/include/asm/kvm_host.h +5 -1
@@ -518,6 +518,7 @@ enum irq_types {IRQ_PEND_PFAULT_INIT ,IRQ_PEND_EXT_HOST ,IRQ_PEND_EXT_SERVICE , +IRQ_PEND_EXT_SERVICE_EV ,IRQ_PEND_EXT_TIMING ,IRQ_PEND_EXT_CPU_TIMER , IRQ_PEND_EXT_CLOCK_COMP,
@@ -562,6 +563,7 @@ enum irq_types { (1UL <<IRQ_PEND_EXT_TIMING ) | \ (1UL <<IRQ_PEND_EXT_HOST ) | \ (1UL <<IRQ_PEND_EXT_SERVICE ) | \ + (1UL <<IRQ_PEND_EXT_SERVICE_EV ) | \ (1UL <<IRQ_PEND_VIRTIO ) | \ (1UL <<IRQ_PEND_PFAULT_INIT ) | \ (1UL << IRQ_PEND_PFAULT_DONE))
@@ -582,7 +584,8 @@ enum irq_types { (1UL << IRQ_PEND_EXT_CLOCK_COMP) | \ (1UL << IRQ_PEND_EXT_EMERGENCY) | \ (1UL << IRQ_PEND_EXT_EXTERNAL) | \ - (1UL << IRQ_PEND_EXT_SERVICE)) + (1UL << IRQ_PEND_EXT_SERVICE) | \ + (1UL << IRQ_PEND_EXT_SERVICE_EV)) struct kvm_s390_interrupt_info { struct list_head list;
@@ -642,6 +645,7 @@ struct kvm_s390_local_interrupt {struct kvm_s390_float_interrupt {unsigned long pending_irqs; +unsigned long masked_irqs;spinlock_t lock;struct list_head lists[FIRQ_LIST_COUNT ];int counters[FIRQ_MAX_COUNT ];
arch/s390/kvm/intercept.c +27 -0
@@ -444,8 +444,35 @@ static int handle_operexc(struct kvm_vcpu *vcpu)return kvm_s390_inject_program_int (vcpu,PGM_OPERATION ); } +static int handle_pv_sclp (struct kvm_vcpu *vcpu) +{ +struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; + +spin_lock (&fi->lock); +/* +* 2 cases: +* a: an sccb answering interrupt was already pending or in flight. +* As the sccb value is not known we can simply set some value to +* trigger delivery of a saved SCCB. UV will then use its saved +* copy of the SCCB value. +* b: an error SCCB interrupt needs to be injected so we also inject +* a fake SCCB address. Firmware will use the proper one. +* This makes sure, that both errors and real sccb returns will only +* be delivered after a notification intercept (instruction has +* finished) but not after others. +*/ + fi->srv_signal.ext_params |=0x43000 ; +set_bit (IRQ_PEND_EXT_SERVICE , &fi->pending_irqs); +clear_bit (IRQ_PEND_EXT_SERVICE , &fi->masked_irqs); +spin_unlock (&fi->lock); +return 0 ; +} +static int handle_pv_notification (struct kvm_vcpu *vcpu) { +if (vcpu->arch.sie_block->ipa ==0xb220 ) +return handle_pv_sclp (vcpu); +return handle_instruction (vcpu); }
arch/s390/kvm/interrupt.c +75 -18
161 lines not on this page · raw message
arch/s390/kvm/kvm-s390.c +4 -0
@@ -2206,6 +2206,8 @@ static int kvm_s390_handle_pv(struct kvm *kvm, struct kvm_pv_cmd *cmd) } r =kvm_s390_pv_create_vm (kvm, &cmd->rc, &cmd->rrc);kvm_s390_vcpu_unblock_all (kvm); +/* we need to block service interrupts from now on */ +set_bit (IRQ_PEND_EXT_SERVICE , &kvm->arch.float_int.masked_irqs);mutex_unlock (&kvm->lock);break ; }
@@ -2221,6 +2223,8 @@ static int kvm_s390_handle_pv(struct kvm *kvm, struct kvm_pv_cmd *cmd)if (!r)kvm_s390_pv_dealloc_vm (kvm);kvm_s390_vcpu_unblock_all (kvm); +/* no need to block service interrupts any more */ +clear_bit (IRQ_PEND_EXT_SERVICE , &kvm->arch.float_int.masked_irqs);mutex_unlock (&kvm->lock);break ; }
Signature · 1 line
2.25.0
PATCH v2 18/42 KVM: s390: protvirt: Handle spec exception loops
In reply to Christian BorntraegerFrom: Janosch Frank <[email protected]>
SIE intercept code 8 is used only on exception loops for protected guests. That means we need to stop the guest when we see it. This is done by userspace.
--- arch/s390/kvm/intercept.c | 7 +++++++ 1 file changed, 7 insertions(+)
arch/s390/kvm/intercept.c +7 -0
@@ -231,6 +231,13 @@ static int handle_prog(struct kvm_vcpu *vcpu) vcpu->stat.exit_program_interruption++; +/* +* Intercept 8 indicates a loop of specification exceptions +* for protected guests. +*/ +if (kvm_s390_pv_is_protected (vcpu->kvm)) +return -EOPNOTSUPP ; +if (guestdbg_enabled (vcpu) &&per_event (vcpu)) { rc =kvm_s390_handle_per_event (vcpu);if (rc)
Signature · 1 line
2.25.0
PATCH v2 19/42 KVM: s390: protvirt: Add new gprs location handling
In reply to Christian BorntraegerFrom: Janosch Frank <[email protected]>
Guest registers for protected guests are stored at offset 0x380.
--- arch/s390/include/asm/kvm_host.h | 4 +++- arch/s390/kvm/kvm-s390.c | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-)
arch/s390/include/asm/kvm_host.h +3 -1
@@ -343,7 +343,9 @@ struct kvm_s390_itdb {struct sie_page {struct kvm_s390_sie_block sie_block;struct mcck_volatile_info mcck_info;/* 0x0200 */ -__u8 reserved218[1000 ];/* 0x0218 */ +__u8 reserved218[360 ];/* 0x0218 */ +__u64 pv_grregs[16 ];/* 0x0380 */ +__u8 reserved400[512 ];/* 0x0400 */ struct kvm_s390_itdb itdb;/* 0x0600 */ __u8 reserved700[2304 ];/* 0x0700 */ };
arch/s390/kvm/kvm-s390.c +11 -0
@@ -3999,6 +3999,7 @@ static int vcpu_post_run(struct kvm_vcpu *vcpu, int exit_reason)static int __vcpu_run (struct kvm_vcpu *vcpu) {int rc, exit_reason; +struct sie_page *sie_page = (struct sie_page *)vcpu->arch.sie_block;/* * We try to hold kvm->srcu during most of vcpu_run (except when run-
@@ -4020,8 +4021,18 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)guest_enter_irqoff ();__disable_cpu_timer_accounting (vcpu);local_irq_enable (); +if (kvm_s390_pv_is_protected (vcpu->kvm)) { +memcpy (sie_page->pv_grregs, + vcpu->run->s.regs.gprs, +sizeof (sie_page->pv_grregs)); + } exit_reason =sie64a (vcpu->arch.sie_block, vcpu->run->s.regs.gprs); +if (kvm_s390_pv_is_protected (vcpu->kvm)) { +memcpy (vcpu->run->s.regs.gprs, + sie_page->pv_grregs, +sizeof (sie_page->pv_grregs)); + }local_irq_disable ();__enable_cpu_timer_accounting (vcpu);guest_exit_irqoff ();
Signature · 1 line
2.25.0
Re: [PATCH v2 19/42] KVM: s390: protvirt: Add new gprs location handling
Quoted 51 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
Guest registers for protected guests are stored at offset
0x380.Signed-off-by Janosch Frank <[email protected]>Reviewed-by Thomas Huth <[email protected]>Reviewed-by Cornelia Huck <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/include/asm/kvm_host.h | 4 +++- arch/s390/kvm/kvm-s390.c | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-)arch/s390/include/asm/kvm_host.h +3
-1@@ -343,7 +343,9 @@ struct kvm_s390_itdb {struct sie_page {struct kvm_s390_sie_block sie_block;struct mcck_volatile_info mcck_info;/* 0x0200 */ -__u8 reserved218[1000 ];/* 0x0218 */ +__u8 reserved218[360 ];/* 0x0218 */ +__u64 pv_grregs[16 ];/* 0x0380 */ +__u8 reserved400[512 ];/* 0x0400 */ struct kvm_s390_itdb itdb;/* 0x0600 */ __u8 reserved700[2304 ];/* 0x0700 */ };arch/s390/kvm/kvm-s390.c +6
-0@@ -3999,6 +3999,7 @@ static int vcpu_post_run(struct kvm_vcpu *vcpu, int exit_reason)static int __vcpu_run (struct kvm_vcpu *vcpu) {int rc, exit_reason; +struct sie_page *sie_page = (struct sie_page *)vcpu->arch.sie_block;/* * We try to hold kvm->srcu during most of vcpu_run (except when run- @@ -4020,8 +4021,18 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)guest_enter_irqoff ();__disable_cpu_timer_accounting (vcpu);local_irq_enable (); +if (kvm_s390_pv_is_protected (vcpu->kvm)) { +memcpy (sie_page->pv_grregs, + vcpu->run->s.regs.gprs, +sizeof (sie_page->pv_grregs)); + }
arch/s390/kvm/kvm-s390.c static int __vcpu_run(struct kvm_vcpu *vcpu) · line 4038
Quoted 10 lines
arch/s390/kvm/kvm-s390.c +5
-0exit_reason =sie64a (vcpu->arch.sie_block, vcpu->run->s.regs.gprs); +if (kvm_s390_pv_is_protected (vcpu->kvm)) { +memcpy (vcpu->run->s.regs.gprs, + sie_page->pv_grregs, +sizeof (sie_page->pv_grregs)); + }local_irq_disable ();__enable_cpu_timer_accounting (vcpu);guest_exit_irqoff ();
As discussed, I think there is room for improvement in the future (which we could have documented in the patch description), because this is obviously sub-optimal.
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v2 19/42] KVM: s390: protvirt: Add new gprs location handling
Quoted 4 lines · David Hildenbrand
As discussed, I think there is room for improvement in the future (which we could have documented in the patch description), because this is obviously sub-optimal.
Will use the following as patch description
Guest registers for protected guests are stored at offset 0x380. We will copy those to the usual places. Long term we could refactor this or use register access functions.
Quoted 2 lines
Reviewed-by David Hildenbrand <[email protected]>
Janosch Frank
maintainerRe: [PATCH v2 19/42] KVM: s390: protvirt: Add new gprs location handling
In reply to David HildenbrandQuoted 58 lines · David Hildenbrand
Quoted 57 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
Guest registers for protected guests are stored at offset
0x380.Signed-off-by Janosch Frank <[email protected]>Reviewed-by Thomas Huth <[email protected]>Reviewed-by Cornelia Huck <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/include/asm/kvm_host.h | 4 +++- arch/s390/kvm/kvm-s390.c | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-)arch/s390/include/asm/kvm_host.h +3
-1@@ -343,7 +343,9 @@ struct kvm_s390_itdb {struct sie_page {struct kvm_s390_sie_block sie_block;struct mcck_volatile_info mcck_info;/* 0x0200 */ -__u8 reserved218[1000 ];/* 0x0218 */ +__u8 reserved218[360 ];/* 0x0218 */ +__u64 pv_grregs[16 ];/* 0x0380 */ +__u8 reserved400[512 ];/* 0x0400 */ struct kvm_s390_itdb itdb;/* 0x0600 */ __u8 reserved700[2304 ];/* 0x0700 */ };arch/s390/kvm/kvm-s390.c +11
-0@@ -3999,6 +3999,7 @@ static int vcpu_post_run(struct kvm_vcpu *vcpu, int exit_reason)static int __vcpu_run (struct kvm_vcpu *vcpu) {int rc, exit_reason; +struct sie_page *sie_page = (struct sie_page *)vcpu->arch.sie_block;/* * We try to hold kvm->srcu during most of vcpu_run (except when run- @@ -4020,8 +4021,18 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)guest_enter_irqoff ();__disable_cpu_timer_accounting (vcpu);local_irq_enable (); +if (kvm_s390_pv_is_protected (vcpu->kvm)) { +memcpy (sie_page->pv_grregs, + vcpu->run->s.regs.gprs, +sizeof (sie_page->pv_grregs)); + } exit_reason =sie64a (vcpu->arch.sie_block, vcpu->run->s.regs.gprs); +if (kvm_s390_pv_is_protected (vcpu->kvm)) { +memcpy (vcpu->run->s.regs.gprs, + sie_page->pv_grregs, +sizeof (sie_page->pv_grregs)); + }
Quoted 8 lines
arch/s390/kvm/kvm-s390.c static int __vcpu_run(struct kvm_vcpu *vcpu) · line 4038
Quoted 4 lines
arch/s390/kvm/kvm-s390.c +0
-0local_irq_disable ();__enable_cpu_timer_accounting (vcpu);guest_exit_irqoff ();As discussed, I think there is room for improvement in the future (which we could have documented in the patch description), because this is obviously sub-optimal.
I added it to my KVM TODO list.
Quoted 2 lines
Reviewed-by David Hildenbrand <[email protected]>
Thanks for reviewing this patch and all the others :-)
PATCH v2 20/42 KVM: S390: protvirt: Introduce instruction data area bounce buffer
In reply to Christian BorntraegerFrom: Janosch Frank <[email protected]>
Now that we can't access guest memory anymore, we have a dedicated satellite block that's a bounce buffer for instruction data.
We re-use the memop interface to copy the instruction data to / from userspace. This lets us re-use a lot of QEMU code which used that interface to make logical guest memory accesses which are not possible anymore in protected mode anyway.
--- arch/s390/include/asm/kvm_host.h | 11 ++++++++- arch/s390/kvm/kvm-s390.c | 42 ++++++++++++++++++++++++++++++++ arch/s390/kvm/pv.c | 9 +++++++ include/uapi/linux/kvm.h | 6 ++++- 4 files changed, 66 insertions(+), 2 deletions(-)
arch/s390/include/asm/kvm_host.h +10 -1
@@ -127,6 +127,12 @@ struct mcck_volatile_info {#define CR14_INITIAL_MASK (CR14_UNUSED_32 | CR14_UNUSED_33 | \ CR14_EXTERNAL_DAMAGE_SUBMASK) +#define SIDAD_SIZE_MASK 0xff +#define sida_origin (sie_block) \ + ((sie_block)->sidad & PAGE_MASK) +#define sida_size (sie_block) \ + ((((sie_block)->sidad & SIDAD_SIZE_MASK) + 1) * PAGE_SIZE) +#define CPUSTAT_STOPPED 0x80000000#define CPUSTAT_WAIT 0x10000000#define CPUSTAT_ECALL_PEND 0x08000000
@@ -315,7 +321,10 @@ struct kvm_s390_sie_block {#define CRYCB_FORMAT2 0x00000003__u32 crycbd;/* 0x00fc */ __u64 gcr[16 ];/* 0x0100 */ -__u64 gbea;/* 0x0180 */ +union { +__u64 gbea;/* 0x0180 */ +__u64 sidad; + };__u8 reserved188[8 ];/* 0x0188 */ __u64 sdnxo;/* 0x0190 */ __u8 reserved198[8 ];/* 0x0198 */
arch/s390/kvm/kvm-s390.c +42 -0
72 lines not on this page · raw message
arch/s390/kvm/pv.c +9 -0
@@ -92,6 +92,7 @@ int kvm_s390_pv_destroy_cpu(struct kvm_vcpu *vcpu, u16 *rc, u16 *rrc)free_pages (vcpu->arch.pv.stor_base,get_order (uv_info.guest_cpu_stor_len)); +free_page (sida_origin (vcpu->arch.sie_block)); vcpu->arch.sie_block->pv_handle_cpu =0 ; vcpu->arch.sie_block->pv_handle_config =0 ;memset (&vcpu->arch.pv,0 ,sizeof (vcpu->arch.pv));
@@ -121,6 +122,14 @@ int kvm_s390_pv_create_cpu(struct kvm_vcpu *vcpu, u16 *rc, u16 *rrc) uvcb.state_origin = (u64 )vcpu->arch.sie_block; uvcb.stor_origin = (u64 )vcpu->arch.pv.stor_base; +/* Alloc Secure Instruction Data Area Designation */ + vcpu->arch.sie_block->sidad =__get_free_page (GFP_KERNEL | __GFP_ZERO); +if (!vcpu->arch.sie_block->sidad) { +free_pages (vcpu->arch.pv.stor_base, +get_order (uv_info.guest_cpu_stor_len)); +return -ENOMEM ; + } + cc =uv_call (0 , (u64)&uvcb); *rc = uvcb.header.rc; *rrc = uvcb.header.rrc;
include/uapi/linux/kvm.h +5 -1
@@ -475,11 +475,15 @@ struct kvm_s390_mem_op {__u32 op;/* type of operation */ __u64 buf;/* buffer in userspace */ __u8 ar;/* the access register number */ -__u8 reserved[31 ];/* should be set to 0 */ +__u8 reserved21[3 ];/* should be set to 0 */ +__u32 sida_offset;/* offset into the sida */ +__u8 reserved28[24 ];/* should be set to 0 */ };/* types for kvm_s390_mem_op->op */ #define KVM_S390_MEMOP_LOGICAL_READ 0#define KVM_S390_MEMOP_LOGICAL_WRITE 1 +#define KVM_S390_MEMOP_SIDA_READ 2 +#define KVM_S390_MEMOP_SIDA_WRITE 3/* flags for kvm_s390_mem_op->flags */ #define KVM_S390_MEMOP_F_CHECK_ONLY (1ULL << 0)#define KVM_S390_MEMOP_F_INJECT_EXCEPTION (1ULL << 1)
Signature · 1 line
2.25.0
Re: [PATCH v2 20/42] KVM: S390: protvirt: Introduce instruction data area bounce buffer
arch/s390/kvm/kvm-s390.c static long kvm_s390_guest_mem_op(struct kvm_vcpu *vcpu, · line 4495
Quoted 8 lines
arch/s390/kvm/kvm-s390.c +4
-0@@ -4460,6 +4489,10 @@ static long kvm_s390_guest_mem_op(struct kvm_vcpu *vcpu,switch (mop->op) {case KVM_S390_MEMOP_LOGICAL_READ : +if (kvm_s390_pv_is_protected (vcpu->kvm)) { + r = -EINVAL ; +break ; + }
Could we have a possible race with disabling code, especially while concurrently freeing? (sorry if I ask again, there was just a flood of emails)
arch/s390/kvm/kvm-s390.c static long kvm_s390_guest_mem_op(struct kvm_vcpu *vcpu, · line 4511
Quoted 11 lines
arch/s390/kvm/kvm-s390.c +4
-0if (mop->flags &KVM_S390_MEMOP_F_CHECK_ONLY ) { r =check_gva_range (vcpu, mop->gaddr, mop->ar, mop->size,GACC_FETCH );@@ -4472,6 +4505,10 @@ static long kvm_s390_guest_mem_op(struct kvm_vcpu *vcpu, }break ;case KVM_S390_MEMOP_LOGICAL_WRITE : +if (kvm_s390_pv_is_protected (vcpu->kvm)) { + r = -EINVAL ; +break ; + }
dito
Quoted 47 lines
arch/s390/kvm/kvm-s390.c +5
-0if (mop->flags &KVM_S390_MEMOP_F_CHECK_ONLY ) { r =check_gva_range (vcpu, mop->gaddr, mop->ar, mop->size,GACC_STORE );@@ -4483,6 +4520,11 @@ static long kvm_s390_guest_mem_op(struct kvm_vcpu *vcpu, } r =write_guest (vcpu, mop->gaddr, mop->ar, tmpbuf, mop->size);break ; +case KVM_S390_MEMOP_SIDA_READ : +case KVM_S390_MEMOP_SIDA_WRITE : +/* we are locked against sida going away by the vcpu->mutex */ + r =kvm_s390_guest_sida_op (vcpu, mop); +break ;default : r = -EINVAL ; }arch/s390/kvm/pv.c +9
-0@@ -92,6 +92,7 @@ int kvm_s390_pv_destroy_cpu(struct kvm_vcpu *vcpu, u16 *rc, u16 *rrc)free_pages (vcpu->arch.pv.stor_base,get_order (uv_info.guest_cpu_stor_len)); +free_page (sida_origin (vcpu->arch.sie_block)); vcpu->arch.sie_block->pv_handle_cpu =0 ; vcpu->arch.sie_block->pv_handle_config =0 ;memset (&vcpu->arch.pv,0 ,sizeof (vcpu->arch.pv));@@ -121,6 +122,14 @@ int kvm_s390_pv_create_cpu(struct kvm_vcpu *vcpu, u16 *rc, u16 *rrc) uvcb.state_origin = (u64 )vcpu->arch.sie_block; uvcb.stor_origin = (u64 )vcpu->arch.pv.stor_base; +/* Alloc Secure Instruction Data Area Designation */ + vcpu->arch.sie_block->sidad =__get_free_page (GFP_KERNEL | __GFP_ZERO); +if (!vcpu->arch.sie_block->sidad) { +free_pages (vcpu->arch.pv.stor_base, +get_order (uv_info.guest_cpu_stor_len)); +return -ENOMEM ; + } + cc =uv_call (0 , (u64)&uvcb); *rc = uvcb.header.rc; *rrc = uvcb.header.rrc;include/uapi/linux/kvm.h +0
-0
include/uapi/linux/kvm.h struct kvm_s390_mem_op { · line 481
Quoted 8 lines
include/uapi/linux/kvm.h +3
-1@@ -475,11 +475,15 @@ struct kvm_s390_mem_op {__u32 op;/* type of operation */ __u64 buf;/* buffer in userspace */ __u8 ar;/* the access register number */ -__u8 reserved[31 ];/* should be set to 0 */ +__u8 reserved21[3 ];/* should be set to 0 */ +__u32 sida_offset;/* offset into the sida */ +__u8 reserved28[24 ];/* should be set to 0 */ };
As discussed, I'd prefer an overlaying layout for the sida, as the ar does not make any sense (correct me if I'm wrong :) )
__u32 op; /* type of operation */__u64 buf; /* buffer in userspace */
uinon {
__u8 ar; /* the access register number */
__u32 sida_offset; /* offset into the sida */
__u8 reserved[32]; /* should be set to 0 */
};
With something like that
Signature · 3 lines
Thanks, David / dhildenb
Janosch Frank
maintainerRe: [PATCH v2 20/42] KVM: S390: protvirt: Introduce instruction data area bounce buffer
Quoted 77 lines · David Hildenbrand
arch/s390/kvm/kvm-s390.c static long kvm_s390_guest_mem_op(struct kvm_vcpu *vcpu, · line 4495
Quoted 8 lines
arch/s390/kvm/kvm-s390.c +4
-0@@ -4460,6 +4489,10 @@ static long kvm_s390_guest_mem_op(struct kvm_vcpu *vcpu,switch (mop->op) {case KVM_S390_MEMOP_LOGICAL_READ : +if (kvm_s390_pv_is_protected (vcpu->kvm)) { + r = -EINVAL ; +break ; + }Could we have a possible race with disabling code, especially while concurrently freeing? (sorry if I ask again, there was just a flood of emails)
arch/s390/kvm/kvm-s390.c static long kvm_s390_guest_mem_op(struct kvm_vcpu *vcpu, · line 4511
Quoted 11 lines
arch/s390/kvm/kvm-s390.c +4
-0if (mop->flags &KVM_S390_MEMOP_F_CHECK_ONLY ) { r =check_gva_range (vcpu, mop->gaddr, mop->ar, mop->size,GACC_FETCH );@@ -4472,6 +4505,10 @@ static long kvm_s390_guest_mem_op(struct kvm_vcpu *vcpu, }break ;case KVM_S390_MEMOP_LOGICAL_WRITE : +if (kvm_s390_pv_is_protected (vcpu->kvm)) { + r = -EINVAL ; +break ; + }dito
Quoted 50 lines
arch/s390/kvm/kvm-s390.c +5
-0if (mop->flags &KVM_S390_MEMOP_F_CHECK_ONLY ) { r =check_gva_range (vcpu, mop->gaddr, mop->ar, mop->size,GACC_STORE );@@ -4483,6 +4520,11 @@ static long kvm_s390_guest_mem_op(struct kvm_vcpu *vcpu, } r =write_guest (vcpu, mop->gaddr, mop->ar, tmpbuf, mop->size);break ; +case KVM_S390_MEMOP_SIDA_READ : +case KVM_S390_MEMOP_SIDA_WRITE : +/* we are locked against sida going away by the vcpu->mutex */ + r =kvm_s390_guest_sida_op (vcpu, mop); +break ;default : r = -EINVAL ; }arch/s390/kvm/pv.c +9
-0@@ -92,6 +92,7 @@ int kvm_s390_pv_destroy_cpu(struct kvm_vcpu *vcpu, u16 *rc, u16 *rrc)free_pages (vcpu->arch.pv.stor_base,get_order (uv_info.guest_cpu_stor_len)); +free_page (sida_origin (vcpu->arch.sie_block)); vcpu->arch.sie_block->pv_handle_cpu =0 ; vcpu->arch.sie_block->pv_handle_config =0 ;memset (&vcpu->arch.pv,0 ,sizeof (vcpu->arch.pv));@@ -121,6 +122,14 @@ int kvm_s390_pv_create_cpu(struct kvm_vcpu *vcpu, u16 *rc, u16 *rrc) uvcb.state_origin = (u64 )vcpu->arch.sie_block; uvcb.stor_origin = (u64 )vcpu->arch.pv.stor_base; +/* Alloc Secure Instruction Data Area Designation */ + vcpu->arch.sie_block->sidad =__get_free_page (GFP_KERNEL | __GFP_ZERO); +if (!vcpu->arch.sie_block->sidad) { +free_pages (vcpu->arch.pv.stor_base, +get_order (uv_info.guest_cpu_stor_len)); +return -ENOMEM ; + } + cc =uv_call (0 , (u64)&uvcb); *rc = uvcb.header.rc; *rrc = uvcb.header.rrc;include/uapi/linux/kvm.h +0
-0@@ -475,11 +475,15 @@ struct kvm_s390_mem_op {__u32 op;/* type of operation */ __u64 buf;/* buffer in userspace */ __u8 ar;/* the access register number */
Quoted 8 lines
include/uapi/linux/kvm.h struct kvm_s390_mem_op { · line 481
Quoted 5 lines
include/uapi/linux/kvm.h +3
-1-__u8 reserved[31 ];/* should be set to 0 */ +__u8 reserved21[3 ];/* should be set to 0 */ +__u32 sida_offset;/* offset into the sida */ +__u8 reserved28[24 ];/* should be set to 0 */ };As discussed, I'd prefer an overlaying layout for the sida, as the ar does not make any sense (correct me if I'm wrong :) )
That wouldn't work, because we still check mop->ar < 16 in kvm_s390_guest_mem_op(). Also we currently check mop contents twice because we overload mem_op() with the SIDA operations.
Using a separate IOCTL is cleaner...
Quoted 12 lines
__u32op; /* type of operation */__u64buf; /* buffer in userspace */
uinon {
__u8ar; /* the access register number */
__u32sida_offset; /* offset into the sida */
__u8reserved[32]; /* should be set to 0 */
};With something like that
Reviewed-by David Hildenbrand <[email protected]>
Re: [PATCH v2 20/42] KVM: S390: protvirt: Introduce instruction data area bounce buffer
Quoted 13 lines · Janosch Frank
Quoted 12 lines · David Hildenbrand
arch/s390/kvm/kvm-s390.c static long kvm_s390_guest_mem_op(struct kvm_vcpu *vcpu, · line 4495
Quoted 8 lines
arch/s390/kvm/kvm-s390.c +4
-0@@ -4460,6 +4489,10 @@ static long kvm_s390_guest_mem_op(struct kvm_vcpu *vcpu,switch (mop->op) {case KVM_S390_MEMOP_LOGICAL_READ : +if (kvm_s390_pv_is_protected (vcpu->kvm)) { + r = -EINVAL ; +break ; + }Could we have a possible race with disabling code, especially while concurrently freeing? (sorry if I ask again, there was just a flood of emails)
see my other reply. Hopefully fixed soon.[...]
Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
include/uapi/linux/kvm.h +0
-0@@ -475,11 +475,15 @@ struct kvm_s390_mem_op {__u32 op;/* type of operation */ __u64 buf;/* buffer in userspace */ __u8 ar;/* the access register number */ Quoted 8 lines
include/uapi/linux/kvm.h struct kvm_s390_mem_op { · line 481
Quoted 5 lines
include/uapi/linux/kvm.h +3
-1-__u8 reserved[31 ];/* should be set to 0 */ +__u8 reserved21[3 ];/* should be set to 0 */ +__u32 sida_offset;/* offset into the sida */ +__u8 reserved28[24 ];/* should be set to 0 */ };As discussed, I'd prefer an overlaying layout for the sida, as the ar does not make any sense (correct me if I'm wrong :) )
Quoted 5 lines
That wouldn't work, because we still check
mop->ar< 16 inkvm_s390_guest_mem_op(). Also we currently check mop contents twice because we overloadmem_op()with the SIDA operations.Using a separate IOCTL is cleaner...
I would rather use the current patch instead of adding a new ioctl.
Janosch Frank
maintainerRe: [PATCH v2 20/42] KVM: S390: protvirt: Introduce instruction data area bounce buffer
Quoted 36 lines · Christian Borntraeger
Quoted 13 lines · Janosch Frank
Quoted 12 lines · David Hildenbrand
arch/s390/kvm/kvm-s390.c static long kvm_s390_guest_mem_op(struct kvm_vcpu *vcpu, · line 4495
Quoted 8 lines
arch/s390/kvm/kvm-s390.c +4
-0@@ -4460,6 +4489,10 @@ static long kvm_s390_guest_mem_op(struct kvm_vcpu *vcpu,switch (mop->op) {case KVM_S390_MEMOP_LOGICAL_READ : +if (kvm_s390_pv_is_protected (vcpu->kvm)) { + r = -EINVAL ; +break ; + }Could we have a possible race with disabling code, especially while concurrently freeing? (sorry if I ask again, there was just a flood of emails)
see my other reply. Hopefully fixed soon.[...]
Quoted 17 lines
Quoted 16 lines
include/uapi/linux/kvm.h struct kvm_s390_mem_op { · line 481
Quoted 13 lines
include/uapi/linux/kvm.h +3
-1@@ -475,11 +475,15 @@ struct kvm_s390_mem_op {__u32 op;/* type of operation */ __u64 buf;/* buffer in userspace */ __u8 ar;/* the access register number */ -__u8 reserved[31 ];/* should be set to 0 */ +__u8 reserved21[3 ];/* should be set to 0 */ +__u32 sida_offset;/* offset into the sida */ +__u8 reserved28[24 ];/* should be set to 0 */ };As discussed, I'd prefer an overlaying layout for the sida, as the ar does not make any sense (correct me if I'm wrong :) )
Quoted 8 lines
Quoted 5 lines
That wouldn't work, because we still check
mop->ar< 16 inkvm_s390_guest_mem_op(). Also we currently check mop contents twice because we overloadmem_op()with the SIDA operations.Using a separate IOCTL is cleaner...
I would rather use the current patch instead of adding a new ioctl.
Well, then I'd suggest moving the normal memop ops into an own function and also move the ar check into there.
Re: [PATCH v2 20/42] KVM: S390: protvirt: Introduce instruction data area bounce buffer
Quoted 5 lines · Janosch Frank
Quoted 2 lines
I would rather use the current patch instead of adding a new ioctl.
Well, then I'd suggest moving the normal memop ops into an own function and also move the ar check into there.
Yes, I will refactor that and change the kvm_s390_mem_op structure.
PATCH v2 21/42 KVM: s390: protvirt: handle secure guest prefix pages
In reply to Christian BorntraegerFrom: Janosch Frank <[email protected]>
The SPX instruction is handled by the ultravisor. We do get a notification intercept, though. Let us update our internal view.
In addition to that, when the guest prefix page is not secure, an intercept 112 (0x70) is indicated. Let us make the prefix pages secure again.
--- arch/s390/include/asm/kvm_host.h | 1 + arch/s390/kvm/intercept.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+)
arch/s390/include/asm/kvm_host.h +1 -0
@@ -225,6 +225,7 @@ struct kvm_s390_sie_block {#define ICPT_INT_ENABLE 0x64#define ICPT_PV_INSTR 0x68#define ICPT_PV_NOTIFY 0x6c +#define ICPT_PV_PREF 0x70__u8 icptcode;/* 0x0050 */ __u8 icptstatus;/* 0x0051 */ __u16 ihcpu;/* 0x0052 */
arch/s390/kvm/intercept.c +18 -0
@@ -451,6 +451,15 @@ static int handle_operexc(struct kvm_vcpu *vcpu)return kvm_s390_inject_program_int (vcpu,PGM_OPERATION ); } +static int handle_pv_spx (struct kvm_vcpu *vcpu) +{ +u32 pref = *(u32 *)vcpu->arch.sie_block->sidad; + +kvm_s390_set_prefix (vcpu, pref); +trace_kvm_s390_handle_prefix (vcpu,1 , pref); +return 0 ; +} +static int handle_pv_sclp (struct kvm_vcpu *vcpu) {struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int;
@@ -477,6 +486,8 @@ static int handle_pv_sclp(struct kvm_vcpu *vcpu)static int handle_pv_notification (struct kvm_vcpu *vcpu) { +if (vcpu->arch.sie_block->ipa ==0xb210 ) +return handle_pv_spx (vcpu);if (vcpu->arch.sie_block->ipa ==0xb220 )return handle_pv_sclp (vcpu);
@@ -534,6 +545,13 @@ int kvm_handle_sie_intercept(struct kvm_vcpu *vcpu)case ICPT_PV_NOTIFY : rc =handle_pv_notification (vcpu);break ; +case ICPT_PV_PREF : + rc =0 ; +gmap_convert_to_secure (vcpu->arch.gmap, +kvm_s390_get_prefix (vcpu)); +gmap_convert_to_secure (vcpu->arch.gmap, +kvm_s390_get_prefix (vcpu) +PAGE_SIZE ); +break ;default :return -EOPNOTSUPP ; }
Signature · 1 line
2.25.0
Re: [PATCH v2 21/42] KVM: s390: protvirt: handle secure guest prefix pages
Quoted 59 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
The SPX instruction is handled by the ultravisor. We do get a notification intercept, though. Let us update our internal view.
In addition to that, when the guest prefix page is not secure, an intercept 112 (
0x70) is indicated. Let us make the prefix pages secure again.Signed-off-by Janosch Frank <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/include/asm/kvm_host.h | 1 + arch/s390/kvm/intercept.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+)arch/s390/include/asm/kvm_host.h +1
-0@@ -225,6 +225,7 @@ struct kvm_s390_sie_block {#define ICPT_INT_ENABLE 0x64#define ICPT_PV_INSTR 0x68#define ICPT_PV_NOTIFY 0x6c +#define ICPT_PV_PREF 0x70__u8 icptcode;/* 0x0050 */ __u8 icptstatus;/* 0x0051 */ __u16 ihcpu;/* 0x0052 */ arch/s390/kvm/intercept.c +11
-0@@ -451,6 +451,15 @@ static int handle_operexc(struct kvm_vcpu *vcpu)return kvm_s390_inject_program_int (vcpu,PGM_OPERATION ); } +static int handle_pv_spx (struct kvm_vcpu *vcpu) +{ +u32 pref = *(u32 *)vcpu->arch.sie_block->sidad; + +kvm_s390_set_prefix (vcpu, pref); +trace_kvm_s390_handle_prefix (vcpu,1 , pref); +return 0 ; +} +static int handle_pv_sclp (struct kvm_vcpu *vcpu) {struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int;@@ -477,6 +486,8 @@ static int handle_pv_sclp(struct kvm_vcpu *vcpu)static int handle_pv_notification (struct kvm_vcpu *vcpu) { +if (vcpu->arch.sie_block->ipa ==0xb210 ) +return handle_pv_spx (vcpu);if (vcpu->arch.sie_block->ipa ==0xb220 )return handle_pv_sclp (vcpu);
arch/s390/kvm/intercept.c int kvm_handle_sie_intercept(struct kvm_vcpu *vcpu) · line 553
Quoted 9 lines
arch/s390/kvm/intercept.c +6
-0@@ -534,6 +545,13 @@ int kvm_handle_sie_intercept(struct kvm_vcpu *vcpu)case ICPT_PV_NOTIFY : rc =handle_pv_notification (vcpu);break ; +case ICPT_PV_PREF : + rc =0 ; +gmap_convert_to_secure (vcpu->arch.gmap, +kvm_s390_get_prefix (vcpu)); +gmap_convert_to_secure (vcpu->arch.gmap, +kvm_s390_get_prefix (vcpu) +PAGE_SIZE );
So, no need to go via KVM_REQ_MMU_RELOAD anymore, right? Good.
Signature · 3 lines
Thanks, David / dhildenb
PATCH v2 22/42 KVM: s390/mm: handle guest unpin events
In reply to Christian BorntraegerFrom: Claudio Imbrenda <[email protected]>
The current code tries to first pin shared pages, if that fails (e.g. because the page is not shared) it will export them. For shared pages this means that we get a new intercept telling us that the guest is unsharing that page. We will make the page secure at that point in time and revoke the host access. This is synchronized with other host events, e.g. the code will wait until host I/O has finished.
--- arch/s390/kvm/intercept.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
arch/s390/kvm/intercept.c +24 -0
@@ -16,6 +16,7 @@#include <asm/asm-offsets.h> #include <asm/irq.h> #include <asm/sysinfo.h> +#include <asm/uv.h> #include "kvm-s390.h" #include "gaccess.h"
@@ -484,12 +485,35 @@ static int handle_pv_sclp(struct kvm_vcpu *vcpu)return 0 ; } +static int handle_pv_uvc (struct kvm_vcpu *vcpu) +{ +struct uv_cb_share *guest_uvcb = (void *)vcpu->arch.sie_block->sidad; +struct uv_cb_cts uvcb = { + .header.cmd =UVC_CMD_UNPIN_PAGE_SHARED , + .header.len =sizeof (uvcb), + .guest_handle =kvm_s390_pv_handle (vcpu->kvm), + .gaddr = guest_uvcb->paddr, + }; +int rc; + +if (guest_uvcb->header.cmd !=UVC_CMD_REMOVE_SHARED_ACCESS ) { +WARN_ONCE (1 ,"Unexpected UVC 0x%x!\n" , guest_uvcb->header.cmd); +return 0 ; + } + rc =gmap_make_secure (vcpu->arch.gmap, uvcb.gaddr, &uvcb); +if (rc == -EINVAL ) +return 0 ; +return rc; +} +static int handle_pv_notification (struct kvm_vcpu *vcpu) {if (vcpu->arch.sie_block->ipa ==0xb210 )return handle_pv_spx (vcpu);if (vcpu->arch.sie_block->ipa ==0xb220 )return handle_pv_sclp (vcpu); +if (vcpu->arch.sie_block->ipa ==0xb9a4 ) +return handle_pv_uvc (vcpu);return handle_instruction (vcpu); }
Signature · 1 line
2.25.0
Re: [PATCH v2 22/42] KVM: s390/mm: handle guest unpin events
Quoted 55 lines · Christian Borntraeger
From: Claudio Imbrenda <[email protected]>
The current code tries to first pin shared pages, if that fails (e.g. because the page is not shared) it will export them. For shared pages this means that we get a new intercept telling us that the guest is unsharing that page. We will make the page secure at that point in time and revoke the host access. This is synchronized with other host events, e.g. the code will wait until host I/O has finished.
Signed-off-by Claudio Imbrenda <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/kvm/intercept.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)arch/s390/kvm/intercept.c +22
-0@@ -16,6 +16,7 @@#include <asm/asm-offsets.h> #include <asm/irq.h> #include <asm/sysinfo.h> +#include <asm/uv.h> #include "kvm-s390.h" #include "gaccess.h" @@ -484,12 +485,35 @@ static int handle_pv_sclp(struct kvm_vcpu *vcpu)return 0 ; } +static int handle_pv_uvc (struct kvm_vcpu *vcpu) +{ +struct uv_cb_share *guest_uvcb = (void *)vcpu->arch.sie_block->sidad; +struct uv_cb_cts uvcb = { + .header.cmd =UVC_CMD_UNPIN_PAGE_SHARED , + .header.len =sizeof (uvcb), + .guest_handle =kvm_s390_pv_handle (vcpu->kvm), + .gaddr = guest_uvcb->paddr, + }; +int rc; + +if (guest_uvcb->header.cmd !=UVC_CMD_REMOVE_SHARED_ACCESS ) { +WARN_ONCE (1 ,"Unexpected UVC 0x%x!\n" , guest_uvcb->header.cmd); +return 0 ; + } + rc =gmap_make_secure (vcpu->arch.gmap, uvcb.gaddr, &uvcb); +if (rc == -EINVAL ) +return 0 ; +return rc; +} +static int handle_pv_notification (struct kvm_vcpu *vcpu)
arch/s390/kvm/intercept.c static int handle_pv_sclp(struct kvm_vcpu *vcpu) · line 519
Quoted 10 lines
arch/s390/kvm/intercept.c +2
-0{if (vcpu->arch.sie_block->ipa ==0xb210 )return handle_pv_spx (vcpu);if (vcpu->arch.sie_block->ipa ==0xb220 )return handle_pv_sclp (vcpu); +if (vcpu->arch.sie_block->ipa ==0xb9a4 ) +return handle_pv_uvc (vcpu);return handle_instruction (vcpu); }
Signature · 3 lines
Thanks, David / dhildenb
PATCH v2 23/42 KVM: s390: protvirt: Write sthyi data to instruction data area
In reply to Christian BorntraegerFrom: Janosch Frank <[email protected]>
STHYI data has to go through the bounce buffer.
--- arch/s390/kvm/intercept.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
arch/s390/kvm/intercept.c +10 -5
@@ -392,7 +392,7 @@ int handle_sthyi(struct kvm_vcpu *vcpu) goto out; } -if (addr & ~PAGE_MASK ) +if (!kvm_s390_pv_is_protected (vcpu->kvm) && (addr & ~PAGE_MASK ))return kvm_s390_inject_program_int (vcpu,PGM_SPECIFICATION ); sctns = (void *)get_zeroed_page (GFP_KERNEL );
@@ -403,10 +403,15 @@ int handle_sthyi(struct kvm_vcpu *vcpu) out:if (!cc) { - r =write_guest (vcpu, addr, reg2, sctns,PAGE_SIZE ); -if (r) { -free_page ((unsigned long )sctns); -return kvm_s390_inject_prog_cond (vcpu, r); +if (kvm_s390_pv_is_protected (vcpu->kvm)) { +memcpy ((void *)(sida_origin (vcpu->arch.sie_block)), + sctns,PAGE_SIZE ); + }else { + r =write_guest (vcpu, addr, reg2, sctns,PAGE_SIZE ); +if (r) { +free_page ((unsigned long )sctns); +return kvm_s390_inject_prog_cond (vcpu, r); + } } }
Signature · 1 line
2.25.0
Re: [PATCH v2 23/42] KVM: s390: protvirt: Write sthyi data to instruction data area
Quoted 27 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
STHYI data has to go through the bounce buffer.
Signed-off-by Janosch Frank <[email protected]>Reviewed-by Thomas Huth <[email protected]>Reviewed-by Cornelia Huck <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/kvm/intercept.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)arch/s390/kvm/intercept.c +1
-1@@ -392,7 +392,7 @@ int handle_sthyi(struct kvm_vcpu *vcpu) goto out; } -if (addr & ~PAGE_MASK ) +if (!kvm_s390_pv_is_protected (vcpu->kvm) && (addr & ~PAGE_MASK ))return kvm_s390_inject_program_int (vcpu,PGM_SPECIFICATION ); sctns = (void *)get_zeroed_page (GFP_KERNEL );
arch/s390/kvm/intercept.c int handle_sthyi(struct kvm_vcpu *vcpu) · line 406
Quoted 8 lines
arch/s390/kvm/intercept.c +1
-4@@ -403,10 +403,15 @@ int handle_sthyi(struct kvm_vcpu *vcpu) out:if (!cc) { - r =write_guest (vcpu, addr, reg2, sctns,PAGE_SIZE ); -if (r) { -free_page ((unsigned long )sctns); -return kvm_s390_inject_prog_cond (vcpu, r); +if (kvm_s390_pv_is_protected (vcpu->kvm)) {
I have the feeling that we might have to think about proper locking for kvm_s390_pv_is_protected(). We have to make sure there cannot be any races with user space. Smells like a new r/w lock maybe.
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v2 23/42] KVM: s390: protvirt: Write sthyi data to instruction data area
Quoted 29 lines · David Hildenbrand
Quoted 28 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
STHYI data has to go through the bounce buffer.
Signed-off-by Janosch Frank <[email protected]>Reviewed-by Thomas Huth <[email protected]>Reviewed-by Cornelia Huck <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/kvm/intercept.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)arch/s390/kvm/intercept.c +1
-1@@ -392,7 +392,7 @@ int handle_sthyi(struct kvm_vcpu *vcpu) goto out; } -if (addr & ~PAGE_MASK ) +if (!kvm_s390_pv_is_protected (vcpu->kvm) && (addr & ~PAGE_MASK ))return kvm_s390_inject_program_int (vcpu,PGM_SPECIFICATION ); sctns = (void *)get_zeroed_page (GFP_KERNEL );@@ -403,10 +403,15 @@ int handle_sthyi(struct kvm_vcpu *vcpu)
Quoted 11 lines
arch/s390/kvm/intercept.c int handle_sthyi(struct kvm_vcpu *vcpu) · line 406
Quoted 7 lines
arch/s390/kvm/intercept.c +1
-4out:if (!cc) { - r =write_guest (vcpu, addr, reg2, sctns,PAGE_SIZE ); -if (r) { -free_page ((unsigned long )sctns); -return kvm_s390_inject_prog_cond (vcpu, r); +if (kvm_s390_pv_is_protected (vcpu->kvm)) {I have the feeling that we might have to think about proper locking for
kvm_s390_pv_is_protected(). We have to make sure there cannot be any races with user space. Smells like a new r/w lock maybe.
I think we can keep that within kvm->lock (for the global changes) and vcpu->mutex. All the intercepts only happen within the vcpu run ioctl and that takes the vcpu->mutex. See my other patch (with mutex_lock(&vcpu->mutex) and mutex_unlock(&vcpu->mutex) around the create/destroy functions). lockdep_assert_help is happy and as long as the pv_handle reflects the state of the control block of that CPU we are good.
I pushed out the patch/rfcs to pv_worktree on kvms390.git.
Re: [PATCH v2 23/42] KVM: s390: protvirt: Write sthyi data to instruction data area
Quoted 44 lines · Christian Borntraeger
Quoted 29 lines · David Hildenbrand
Quoted 28 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
STHYI data has to go through the bounce buffer.
Signed-off-by Janosch Frank <[email protected]>Reviewed-by Thomas Huth <[email protected]>Reviewed-by Cornelia Huck <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/kvm/intercept.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)arch/s390/kvm/intercept.c +1
-1@@ -392,7 +392,7 @@ int handle_sthyi(struct kvm_vcpu *vcpu) goto out; } -if (addr & ~PAGE_MASK ) +if (!kvm_s390_pv_is_protected (vcpu->kvm) && (addr & ~PAGE_MASK ))return kvm_s390_inject_program_int (vcpu,PGM_SPECIFICATION ); sctns = (void *)get_zeroed_page (GFP_KERNEL );@@ -403,10 +403,15 @@ int handle_sthyi(struct kvm_vcpu *vcpu)Quoted 11 lines
arch/s390/kvm/intercept.c int handle_sthyi(struct kvm_vcpu *vcpu) · line 406
Quoted 7 lines
arch/s390/kvm/intercept.c +1
-4out:if (!cc) { - r =write_guest (vcpu, addr, reg2, sctns,PAGE_SIZE ); -if (r) { -free_page ((unsigned long )sctns); -return kvm_s390_inject_prog_cond (vcpu, r); +if (kvm_s390_pv_is_protected (vcpu->kvm)) {I have the feeling that we might have to think about proper locking for
kvm_s390_pv_is_protected(). We have to make sure there cannot be any races with user space. Smells like a new r/w lock maybe.
Quoted 7 lines
I think we can keep that within
kvm->lock(for the global changes) andvcpu->mutex. All the intercepts only happen within the vcpu run ioctl and that takes thevcpu->mutex. See my other patch (withmutex_lock(&vcpu->mutex)andmutex_unlock(&vcpu->mutex)around the create/destroy functions).lockdep_assert_helpis happy and as long as thepv_handlereflects the state of the control block of that CPU we are good.I pushed out the patch/rfcs to
pv_worktreeon kvms390.git.
Fine with me!
Signature · 3 lines
Thanks, David / dhildenb
PATCH v2 24/42 KVM: s390: protvirt: STSI handling
In reply to Christian BorntraegerFrom: Janosch Frank <[email protected]>
Save response to sidad and disable address checking for protected guests.
--- arch/s390/kvm/priv.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
arch/s390/kvm/priv.c +8 -3
@@ -872,7 +872,7 @@ static int handle_stsi(struct kvm_vcpu *vcpu) operand2 =kvm_s390_get_base_disp_s (vcpu, &ar); -if (operand2 &0xfff ) +if (!kvm_s390_pv_is_protected (vcpu->kvm) && (operand2 &0xfff ))return kvm_s390_inject_program_int (vcpu,PGM_SPECIFICATION );switch (fc) {
@@ -893,8 +893,13 @@ static int handle_stsi(struct kvm_vcpu *vcpu)handle_stsi_3_2_2 (vcpu, (void *) mem);break ; } - - rc =write_guest (vcpu, operand2, ar, (void *)mem,PAGE_SIZE ); +if (kvm_s390_pv_is_protected (vcpu->kvm)) { +memcpy ((void *)sida_origin (vcpu->arch.sie_block), (void *)mem, +PAGE_SIZE ); + rc =0 ; + }else { + rc =write_guest (vcpu, operand2, ar, (void *)mem,PAGE_SIZE ); + }if (rc) { rc =kvm_s390_inject_prog_cond (vcpu, rc); goto out;
Signature · 1 line
2.25.0
Re: [PATCH v2 24/42] KVM: s390: protvirt: STSI handling
Quoted 19 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
Save response to sidad and disable address checking for protected guests.
Signed-off-by Janosch Frank <[email protected]>Reviewed-by Thomas Huth <[email protected]>Reviewed-by Cornelia Huck <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/kvm/priv.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)arch/s390/kvm/priv.c +0
-0
arch/s390/kvm/priv.c static int handle_stsi(struct kvm_vcpu *vcpu) · line 876
Quoted 6 lines
arch/s390/kvm/priv.c +1
-1@@ -872,7 +872,7 @@ static int handle_stsi(struct kvm_vcpu *vcpu) operand2 =kvm_s390_get_base_disp_s (vcpu, &ar); -if (operand2 &0xfff ) +if (!kvm_s390_pv_is_protected (vcpu->kvm) && (operand2 &0xfff ))return kvm_s390_inject_program_int (vcpu,PGM_SPECIFICATION );
Why is that needed? I'd assume the hardware handles this for us and this case can never happen for PV? (IOW, change is not necessary)
Quoted 9 lines
arch/s390/kvm/priv.c +0
-2switch (fc) {@@ -893,8 +893,13 @@ static int handle_stsi(struct kvm_vcpu *vcpu)handle_stsi_3_2_2 (vcpu, (void *) mem);break ; } - - rc =write_guest (vcpu, operand2, ar, (void *)mem,PAGE_SIZE );
arch/s390/kvm/priv.c static int handle_stsi(struct kvm_vcpu *vcpu) · line 905
Quoted 10 lines
arch/s390/kvm/priv.c +7
-0+if (kvm_s390_pv_is_protected (vcpu->kvm)) { +memcpy ((void *)sida_origin (vcpu->arch.sie_block), (void *)mem, +PAGE_SIZE ); + rc =0 ; + }else { + rc =write_guest (vcpu, operand2, ar, (void *)mem,PAGE_SIZE ); + }if (rc) { rc =kvm_s390_inject_prog_cond (vcpu, rc); goto out;
I'd pull the interrupt injection into the else case, makes things clearer.
What about user_stsi? Will that still work? (I assume user space will write to the sida and it should work just fine)
(I assume races regarding kvm_s390_pv_is_protected() will be dealt with in your next series)
In general, looks good to me.
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v2 24/42] KVM: s390: protvirt: STSI handling
Quoted 21 lines · David Hildenbrand
Quoted 20 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
Save response to sidad and disable address checking for protected guests.
Signed-off-by Janosch Frank <[email protected]>Reviewed-by Thomas Huth <[email protected]>Reviewed-by Cornelia Huck <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/kvm/priv.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)arch/s390/kvm/priv.c +0
-0@@ -872,7 +872,7 @@ static int handle_stsi(struct kvm_vcpu *vcpu)
Quoted 8 lines
arch/s390/kvm/priv.c static int handle_stsi(struct kvm_vcpu *vcpu) · line 876
Quoted 5 lines
arch/s390/kvm/priv.c +1
-1operand2 =kvm_s390_get_base_disp_s (vcpu, &ar); -if (operand2 &0xfff ) +if (!kvm_s390_pv_is_protected (vcpu->kvm) && (operand2 &0xfff ))return kvm_s390_inject_program_int (vcpu,PGM_SPECIFICATION );Why is that needed? I'd assume the hardware handles this for us and this case can never happen for PV? (IOW, change is not necessary)
Hardware is handling this for us AND we are not allowed to inject a specification exception. The ultravisor guards the program checks that we are allowed to inject.
Quoted 14 lines
Quoted 14 lines
arch/s390/kvm/priv.c +5
-2switch (fc) {@@ -893,8 +893,13 @@ static int handle_stsi(struct kvm_vcpu *vcpu)handle_stsi_3_2_2 (vcpu, (void *) mem);break ; } - - rc =write_guest (vcpu, operand2, ar, (void *)mem,PAGE_SIZE ); +if (kvm_s390_pv_is_protected (vcpu->kvm)) { +memcpy ((void *)sida_origin (vcpu->arch.sie_block), (void *)mem, +PAGE_SIZE ); + rc =0 ; + }else {
Quoted 8 lines
arch/s390/kvm/priv.c static int handle_stsi(struct kvm_vcpu *vcpu) · line 905
Quoted 6 lines
arch/s390/kvm/priv.c +2
-0+ rc =write_guest (vcpu, operand2, ar, (void *)mem,PAGE_SIZE ); + }if (rc) { rc =kvm_s390_inject_prog_cond (vcpu, rc); goto out;I'd pull the interrupt injection into the else case, makes things clearer.
Well, no. Thhe else case could set rc to 0.
Quoted 3 lines
What about
user_stsi? Will that still work? (I assume user space will write to the sida and it should work just fine)
will still work.
Quoted 6 lines
(I assume races regarding
kvm_s390_pv_is_protected()will be dealt with in your next series)In general, looks good to me.
Re: [PATCH v2 24/42] KVM: s390: protvirt: STSI handling
Quoted 33 lines · Christian Borntraeger
Quoted 21 lines · David Hildenbrand
Quoted 20 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
Save response to sidad and disable address checking for protected guests.
Signed-off-by Janosch Frank <[email protected]>Reviewed-by Thomas Huth <[email protected]>Reviewed-by Cornelia Huck <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/kvm/priv.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)arch/s390/kvm/priv.c +0
-0@@ -872,7 +872,7 @@ static int handle_stsi(struct kvm_vcpu *vcpu)Quoted 8 lines
arch/s390/kvm/priv.c static int handle_stsi(struct kvm_vcpu *vcpu) · line 876
Quoted 5 lines
arch/s390/kvm/priv.c +1
-1operand2 =kvm_s390_get_base_disp_s (vcpu, &ar); -if (operand2 &0xfff ) +if (!kvm_s390_pv_is_protected (vcpu->kvm) && (operand2 &0xfff ))return kvm_s390_inject_program_int (vcpu,PGM_SPECIFICATION );Why is that needed? I'd assume the hardware handles this for us and this case can never happen for PV? (IOW, change is not necessary)
Quoted 3 lines
Hardware is handling this for us AND we are not allowed to inject a specification exception. The ultravisor guards the program checks that we are allowed to inject.
Yeah, but can this ever trigger without the check? AFAIKs, no. So why add it?
(rather add a BUG_ON in kvm_s390_inject_program_int() in case we are in PV mode)
Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
arch/s390/kvm/priv.c +5
-2switch (fc) {@@ -893,8 +893,13 @@ static int handle_stsi(struct kvm_vcpu *vcpu)handle_stsi_3_2_2 (vcpu, (void *) mem);break ; } - - rc =write_guest (vcpu, operand2, ar, (void *)mem,PAGE_SIZE ); +if (kvm_s390_pv_is_protected (vcpu->kvm)) { +memcpy ((void *)sida_origin (vcpu->arch.sie_block), (void *)mem, +PAGE_SIZE ); + rc =0 ; + }else {Quoted 8 lines
arch/s390/kvm/priv.c static int handle_stsi(struct kvm_vcpu *vcpu) · line 905
Quoted 6 lines
arch/s390/kvm/priv.c +2
-0+ rc =write_guest (vcpu, operand2, ar, (void *)mem,PAGE_SIZE ); + }if (rc) { rc =kvm_s390_inject_prog_cond (vcpu, rc); goto out;I'd pull the interrupt injection into the else case, makes things clearer.
Quoted 1 line
Well, no. Thhe else case could set rc to 0.
Huh?!
if (kvm_s390_pv_is_protected(vcpu->kvm)) {
memcpy((void *)sida_origin(vcpu->arch.sie_block), (void *)mem,
rc = 0;
} else {
rc = write_guest(vcpu, operand2, ar, (void *)mem, PAGE_SIZE);
if (rc) {
rc = kvm_s390_inject_prog_cond(vcpu, rc);
goto out;
}
}What am I missing?
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v2 24/42] KVM: s390: protvirt: STSI handling
Quoted 34 lines · David Hildenbrand
Quoted 33 lines · Christian Borntraeger
Quoted 29 lines · David Hildenbrand
Quoted 19 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
Save response to sidad and disable address checking for protected guests.
Signed-off-by Janosch Frank <[email protected]>Reviewed-by Thomas Huth <[email protected]>Reviewed-by Cornelia Huck <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/kvm/priv.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)arch/s390/kvm/priv.c +0
-0arch/s390/kvm/priv.c static int handle_stsi(struct kvm_vcpu *vcpu) · line 876
Quoted 6 lines
arch/s390/kvm/priv.c +1
-1@@ -872,7 +872,7 @@ static int handle_stsi(struct kvm_vcpu *vcpu) operand2 =kvm_s390_get_base_disp_s (vcpu, &ar); -if (operand2 &0xfff ) +if (!kvm_s390_pv_is_protected (vcpu->kvm) && (operand2 &0xfff ))return kvm_s390_inject_program_int (vcpu,PGM_SPECIFICATION );Why is that needed? I'd assume the hardware handles this for us and this case can never happen for PV? (IOW, change is not necessary)
Quoted 6 lines
Quoted 3 lines
Hardware is handling this for us AND we are not allowed to inject a specification exception. The ultravisor guards the program checks that we are allowed to inject.
Yeah, but can this ever trigger without the check? AFAIKs, no. So why add it?
It can. the GPRS can contain stale data and so can operand2.
Quoted 31 lines
(rather add a
BUG_ONinkvm_s390_inject_program_int()in case we are in PV mode)Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
arch/s390/kvm/priv.c +5
-2switch (fc) {@@ -893,8 +893,13 @@ static int handle_stsi(struct kvm_vcpu *vcpu)handle_stsi_3_2_2 (vcpu, (void *) mem);break ; } - - rc =write_guest (vcpu, operand2, ar, (void *)mem,PAGE_SIZE ); +if (kvm_s390_pv_is_protected (vcpu->kvm)) { +memcpy ((void *)sida_origin (vcpu->arch.sie_block), (void *)mem, +PAGE_SIZE ); + rc =0 ; + }else {Quoted 8 lines
arch/s390/kvm/priv.c static int handle_stsi(struct kvm_vcpu *vcpu) · line 905
Quoted 6 lines
arch/s390/kvm/priv.c +2
-0+ rc =write_guest (vcpu, operand2, ar, (void *)mem,PAGE_SIZE ); + }if (rc) { rc =kvm_s390_inject_prog_cond (vcpu, rc); goto out;I'd pull the interrupt injection into the else case, makes things clearer.
Quoted 1 line
Well, no. Thhe else case could set rc to 0.
Huh?!
Quoted 11 lines
if (kvm_s390_pv_is_protected(vcpu->kvm)) {
memcpy((void *)sida_origin(vcpu->arch.sie_block), (void *)mem,
rc = 0;
} else {
rc = write_guest(vcpu, operand2, ar, (void *)mem, PAGE_SIZE);
if (rc) {
rc = kvm_s390_inject_prog_cond(vcpu, rc);
goto out;
}
}Hmm, I find that one harder to read.
Re: [PATCH v2 24/42] KVM: s390: protvirt: STSI handling
Quoted 5 lines
Quoted 2 lines
Yeah, but can this ever trigger without the check? AFAIKs, no. So why add it?
It can. the GPRS can contain stale data and so can operand2.
Oh, ok. Makes sense.
Quoted 43 lines
Quoted 31 lines
(rather add a
BUG_ONinkvm_s390_inject_program_int()in case we are in PV mode)Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
arch/s390/kvm/priv.c +5
-2switch (fc) {@@ -893,8 +893,13 @@ static int handle_stsi(struct kvm_vcpu *vcpu)handle_stsi_3_2_2 (vcpu, (void *) mem);break ; } - - rc =write_guest (vcpu, operand2, ar, (void *)mem,PAGE_SIZE ); +if (kvm_s390_pv_is_protected (vcpu->kvm)) { +memcpy ((void *)sida_origin (vcpu->arch.sie_block), (void *)mem, +PAGE_SIZE ); + rc =0 ; + }else {Quoted 8 lines
arch/s390/kvm/priv.c static int handle_stsi(struct kvm_vcpu *vcpu) · line 905
Quoted 6 lines
arch/s390/kvm/priv.c +2
-0+ rc =write_guest (vcpu, operand2, ar, (void *)mem,PAGE_SIZE ); + }if (rc) { rc =kvm_s390_inject_prog_cond (vcpu, rc); goto out;I'd pull the interrupt injection into the else case, makes things clearer.
Quoted 1 line
Well, no. Thhe else case could set rc to 0.
Huh?!
Quoted 11 lines
if (kvm_s390_pv_is_protected(vcpu->kvm)) { memcpy((void *)sida_origin(vcpu->arch.sie_block), (void *)mem, rc = 0; } else { rc = write_guest(vcpu, operand2, ar, (void *)mem, PAGE_SIZE); if (rc) { rc = kvm_s390_inject_prog_cond(vcpu, rc); goto out; } }
Quoted 1 line
Hmm, I find that one harder to read.
It's clearer that you only inject a program check when not in pv mode ... ;) No strong feelings.
Signature · 3 lines
Thanks, David / dhildenb
PATCH v2 25/42 KVM: s390: protvirt: disallow one_reg
In reply to Christian BorntraegerFrom: Janosch Frank <[email protected]>
A lot of the registers are controlled by the Ultravisor and never visible to KVM. Some fields in the sie control block are overlayed, like gbea. As no known userspace uses the ONE_REG interface on s390 if sync regs are available, no functionality is lost if it is disabled for protected guests.
--- Documentation/virt/kvm/api.rst | 6 ++++-- arch/s390/kvm/kvm-s390.c | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-)
Documentation/virt/kvm/api.rst +4 -2
@@ -2117,7 +2117,8 @@ Errors: ====== ============================================================ ENOENT no such register - EINVAL invalid register ID, or no such register + EINVAL invalid register ID, or no such register, ONE_REG forbidden + for protected guests (s390) EPERM (arm64) register access not allowed before vcpu finalization ====== ============================================================
@@ -2552,7 +2553,8 @@ Errors include: ======== ============================================================ ENOENT no such register - EINVAL invalid register ID, or no such register + EINVAL invalid register ID, or no such register, ONE_REG forbidden + for protected guests (s390) EPERM (arm64) register access not allowed before vcpu finalization ======== ============================================================
arch/s390/kvm/kvm-s390.c +3 -0
@@ -4638,6 +4638,9 @@ long kvm_arch_vcpu_ioctl(struct file *filp,case KVM_SET_ONE_REG :case KVM_GET_ONE_REG : {struct kvm_one_reg reg; + r = -EINVAL ; +if (kvm_s390_pv_is_protected (vcpu->kvm)) +break ; r = -EFAULT ;if (copy_from_user (®, argp,sizeof (reg)))break ;
Signature · 1 line
2.25.0
Re: [PATCH v2 25/42] KVM: s390: protvirt: disallow one_reg
Quoted 1 line · Christian Borntraeger
From: Janosch Frank <[email protected]>
"KVM: s390: protvirt: disallow KVM_GET_ONE_REG/KVM_SET_ONE_REG"
Quoted 22 lines
A lot of the registers are controlled by the Ultravisor and never visible to KVM. Some fields in the sie control block are overlayed, like gbea. As no known userspace uses the
ONE_REGinterface on s390 if sync regs are available, no functionality is lost if it is disabled for protected guests.Signed-off-by Janosch Frank <[email protected]>Reviewed-by Thomas Huth <[email protected]>Reviewed-by Cornelia Huck <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- Documentation/virt/kvm/api.rst | 6 ++++-- arch/s390/kvm/kvm-s390.c | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-)Documentation/virt/kvm/api.rst +0
-0
Documentation/virt/kvm/api.rst Errors: · line 2121
Quoted 6 lines
Documentation/virt/kvm/api.rst +2
-1@@ -2117,7 +2117,8 @@ Errors: ====== ============================================================ ENOENT no such register - EINVAL invalid register ID, or no such register + EINVAL invalid register ID, or no such register, ONE_REG forbidden + for protected guests (s390)
"invalid register ID, no such register, or used with VMs in protected virtualization mode on s390" ?
Documentation/virt/kvm/api.rst Errors include: · line 2557
Quoted 10 lines
Documentation/virt/kvm/api.rst +2
-1EPERM (arm64) register access not allowed before vcpu finalization ====== ============================================================@@ -2552,7 +2553,8 @@ Errors include: ======== ============================================================ ENOENT no such register - EINVAL invalid register ID, or no such register + EINVAL invalid register ID, or no such register, ONE_REG forbidden + for protected guests (s390)
dito
Quoted 8 lines
Documentation/virt/kvm/api.rst +0
-0EPERM (arm64) register access not allowed before vcpu finalization ======== ============================================================arch/s390/kvm/kvm-s390.c +0
-0
arch/s390/kvm/kvm-s390.c long kvm_arch_vcpu_ioctl(struct file *filp, · line 4643
Quoted 6 lines
arch/s390/kvm/kvm-s390.c +3
-0@@ -4638,6 +4638,9 @@ long kvm_arch_vcpu_ioctl(struct file *filp,case KVM_SET_ONE_REG :case KVM_GET_ONE_REG : {struct kvm_one_reg reg; + r = -EINVAL ; +if (kvm_s390_pv_is_protected (vcpu->kvm)) +break ;
I assume races will be dealt with in your next series.
arch/s390/kvm/kvm-s390.c long kvm_arch_vcpu_ioctl(struct file *filp, · line 4646
Quoted 4 lines
arch/s390/kvm/kvm-s390.c +0
-0r = -EFAULT ;if (copy_from_user (®, argp,sizeof (reg)))break ;
With the two nits fixed
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v2 25/42] KVM: s390: protvirt: disallow one_reg
Quoted 28 lines · David Hildenbrand
Quoted 1 line · Christian Borntraeger
From: Janosch Frank <[email protected]>
"KVM: s390: protvirt: disallow KVM_GET_ONE_REG/KVM_SET_ONE_REG"
Quoted 23 lines
A lot of the registers are controlled by the Ultravisor and never visible to KVM. Some fields in the sie control block are overlayed, like gbea. As no known userspace uses the
ONE_REGinterface on s390 if sync regs are available, no functionality is lost if it is disabled for protected guests.Signed-off-by Janosch Frank <[email protected]>Reviewed-by Thomas Huth <[email protected]>Reviewed-by Cornelia Huck <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- Documentation/virt/kvm/api.rst | 6 ++++-- arch/s390/kvm/kvm-s390.c | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-)Documentation/virt/kvm/api.rst +0
-0@@ -2117,7 +2117,8 @@ Errors:
Quoted 8 lines
Documentation/virt/kvm/api.rst Errors: · line 2121
Quoted 5 lines
Documentation/virt/kvm/api.rst +2
-1====== ============================================================ ENOENT no such register - EINVAL invalid register ID, or no such register + EINVAL invalid register ID, or no such register, ONE_REG forbidden + for protected guests (s390)"invalid register ID, no such register, or used with VMs in protected virtualization mode on s390" ?
ack.
Quoted 6 lines
Quoted 6 lines
Documentation/virt/kvm/api.rst +0
-0EPERM (arm64) register access not allowed before vcpu finalization ====== ============================================================@@ -2552,7 +2553,8 @@ Errors include:
Quoted 7 lines
Documentation/virt/kvm/api.rst Errors include: · line 2557
Quoted 5 lines
Documentation/virt/kvm/api.rst +2
-1======== ============================================================ ENOENT no such register - EINVAL invalid register ID, or no such register + EINVAL invalid register ID, or no such register, ONE_REG forbidden + for protected guests (s390)dito
ack
Quoted 4 lines
Quoted 4 lines
Documentation/virt/kvm/api.rst +0
-0EPERM (arm64) register access not allowed before vcpu finalization ======== ============================================================
Quoted 13 lines
arch/s390/kvm/kvm-s390.c long kvm_arch_vcpu_ioctl(struct file *filp, · line 4643
Quoted 11 lines
arch/s390/kvm/kvm-s390.c +3
-0@@ -4638,6 +4638,9 @@ long kvm_arch_vcpu_ioctl(struct file *filp,case KVM_SET_ONE_REG :case KVM_GET_ONE_REG : {struct kvm_one_reg reg; + r = -EINVAL ; +if (kvm_s390_pv_is_protected (vcpu->kvm)) +break ;I assume races will be dealt with in your next series.
yes. This is running under vcpu_mutex and we will hold that lock when doing the gear shift.
Quoted 10 lines
arch/s390/kvm/kvm-s390.c long kvm_arch_vcpu_ioctl(struct file *filp, · line 4646
Quoted 5 lines
arch/s390/kvm/kvm-s390.c +0
-0r = -EFAULT ;if (copy_from_user (®, argp,sizeof (reg)))break ;With the two nits fixed
Reviewed-by David Hildenbrand <[email protected]>
PATCH v2 26/42 KVM: s390: protvirt: Do only reset registers that are accessible
In reply to Christian BorntraegerFrom: Janosch Frank <[email protected]>
For protected VMs the hypervisor can not access guest breaking event address, program parameter, bpbc and todpr. Do not reset those fields as the control block does not provide access to these fields.
--- arch/s390/kvm/kvm-s390.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
arch/s390/kvm/kvm-s390.c +6 -4
@@ -3442,14 +3442,16 @@ static void kvm_arch_vcpu_ioctl_initial_reset(struct kvm_vcpu *vcpu)kvm_s390_set_prefix (vcpu,0 );kvm_s390_set_cpu_timer (vcpu,0 ); vcpu->arch.sie_block->ckc =0 ; - vcpu->arch.sie_block->todpr =0 ;memset (vcpu->arch.sie_block->gcr,0 ,sizeof (vcpu->arch.sie_block->gcr)); vcpu->arch.sie_block->gcr[0 ] =CR0_INITIAL_MASK ; vcpu->arch.sie_block->gcr[14 ] =CR14_INITIAL_MASK ; vcpu->run->s.regs.fpc =0 ; - vcpu->arch.sie_block->gbea =1 ; - vcpu->arch.sie_block->pp =0 ; - vcpu->arch.sie_block->fpf &= ~FPF_BPBC ; +if (!kvm_s390_pv_handle_cpu (vcpu)) { + vcpu->arch.sie_block->gbea =1 ; + vcpu->arch.sie_block->pp =0 ; + vcpu->arch.sie_block->fpf &= ~FPF_BPBC ; + vcpu->arch.sie_block->todpr =0 ; + } }static void kvm_arch_vcpu_ioctl_clear_reset (struct kvm_vcpu *vcpu)
Signature · 1 line
2.25.0
Re: [PATCH v2 26/42] KVM: s390: protvirt: Do only reset registers that are accessible
Quoted 20 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
For protected VMs the hypervisor can not access guest breaking event address, program parameter, bpbc and todpr. Do not reset those fields as the control block does not provide access to these fields.
Signed-off-by Janosch Frank <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/kvm/kvm-s390.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)arch/s390/kvm/kvm-s390.c +0
-0@@ -3442,14 +3442,16 @@ static void kvm_arch_vcpu_ioctl_initial_reset(struct kvm_vcpu *vcpu)kvm_s390_set_prefix (vcpu,0 );kvm_s390_set_cpu_timer (vcpu,0 );
arch/s390/kvm/kvm-s390.c static void kvm_arch_vcpu_ioctl_initial_reset(struct kvm_vcpu *vcpu) · line 3449
Quoted 10 lines
arch/s390/kvm/kvm-s390.c +1
-4vcpu->arch.sie_block->ckc =0 ; - vcpu->arch.sie_block->todpr =0 ;memset (vcpu->arch.sie_block->gcr,0 ,sizeof (vcpu->arch.sie_block->gcr)); vcpu->arch.sie_block->gcr[0 ] =CR0_INITIAL_MASK ; vcpu->arch.sie_block->gcr[14 ] =CR14_INITIAL_MASK ; vcpu->run->s.regs.fpc =0 ; - vcpu->arch.sie_block->gbea =1 ; - vcpu->arch.sie_block->pp =0 ; - vcpu->arch.sie_block->fpf &= ~FPF_BPBC ; +if (!kvm_s390_pv_handle_cpu (vcpu)) {
Shouldn't we instead check if the VM is in PV mode? (with changed lifecycle handling). Easier to understand.
(side not: the name kvm_s390_pv_handle_cpu() is very confusing. I'd suggest kvm_s390_pv_cpu_get_handle(). Will reply to the other patch)
Quoted 9 lines
arch/s390/kvm/kvm-s390.c +5
-0+ vcpu->arch.sie_block->gbea =1 ; + vcpu->arch.sie_block->pp =0 ; + vcpu->arch.sie_block->fpf &= ~FPF_BPBC ; + vcpu->arch.sie_block->todpr =0 ; + } }static void kvm_arch_vcpu_ioctl_clear_reset (struct kvm_vcpu *vcpu)
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v2 26/42] KVM: s390: protvirt: Do only reset registers that are accessible
Quoted 26 lines · David Hildenbrand
Quoted 25 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
For protected VMs the hypervisor can not access guest breaking event address, program parameter, bpbc and todpr. Do not reset those fields as the control block does not provide access to these fields.
Signed-off-by Janosch Frank <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/kvm/kvm-s390.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)arch/s390/kvm/kvm-s390.c +0
-1@@ -3442,14 +3442,16 @@ static void kvm_arch_vcpu_ioctl_initial_reset(struct kvm_vcpu *vcpu)kvm_s390_set_prefix (vcpu,0 );kvm_s390_set_cpu_timer (vcpu,0 ); vcpu->arch.sie_block->ckc =0 ; - vcpu->arch.sie_block->todpr =0 ;memset (vcpu->arch.sie_block->gcr,0 ,sizeof (vcpu->arch.sie_block->gcr)); vcpu->arch.sie_block->gcr[0 ] =CR0_INITIAL_MASK ; vcpu->arch.sie_block->gcr[14 ] =CR14_INITIAL_MASK ;
Quoted 8 lines
arch/s390/kvm/kvm-s390.c static void kvm_arch_vcpu_ioctl_initial_reset(struct kvm_vcpu *vcpu) · line 3449
Quoted 5 lines
arch/s390/kvm/kvm-s390.c +1
-3vcpu->run->s.regs.fpc =0 ; - vcpu->arch.sie_block->gbea =1 ; - vcpu->arch.sie_block->pp =0 ; - vcpu->arch.sie_block->fpf &= ~FPF_BPBC ; +if (!kvm_s390_pv_handle_cpu (vcpu)) {Shouldn't we instead check if the VM is in PV mode? (with changed lifecycle handling). Easier to understand.
No. these ioctls are under the vcpu->mutex, so I am going to compare against the per cpu variant.
I will use kvm_s390_pv_cpu_is_protected instead to have the lockdep assertion.
Quoted 15 lines
(side not: the name
kvm_s390_pv_handle_cpu()is very confusing. I'd suggestkvm_s390_pv_cpu_get_handle(). Will reply to the other patch)Quoted 9 lines
arch/s390/kvm/kvm-s390.c +5
-0+ vcpu->arch.sie_block->gbea =1 ; + vcpu->arch.sie_block->pp =0 ; + vcpu->arch.sie_block->fpf &= ~FPF_BPBC ; + vcpu->arch.sie_block->todpr =0 ; + } }static void kvm_arch_vcpu_ioctl_clear_reset (struct kvm_vcpu *vcpu)
Re: [PATCH v2 26/42] KVM: s390: protvirt: Do only reset registers that are accessible
Quoted 38 lines · Christian Borntraeger
Quoted 26 lines · David Hildenbrand
Quoted 25 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
For protected VMs the hypervisor can not access guest breaking event address, program parameter, bpbc and todpr. Do not reset those fields as the control block does not provide access to these fields.
Signed-off-by Janosch Frank <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/kvm/kvm-s390.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)arch/s390/kvm/kvm-s390.c +0
-1@@ -3442,14 +3442,16 @@ static void kvm_arch_vcpu_ioctl_initial_reset(struct kvm_vcpu *vcpu)kvm_s390_set_prefix (vcpu,0 );kvm_s390_set_cpu_timer (vcpu,0 ); vcpu->arch.sie_block->ckc =0 ; - vcpu->arch.sie_block->todpr =0 ;memset (vcpu->arch.sie_block->gcr,0 ,sizeof (vcpu->arch.sie_block->gcr)); vcpu->arch.sie_block->gcr[0 ] =CR0_INITIAL_MASK ; vcpu->arch.sie_block->gcr[14 ] =CR14_INITIAL_MASK ;Quoted 8 lines
arch/s390/kvm/kvm-s390.c static void kvm_arch_vcpu_ioctl_initial_reset(struct kvm_vcpu *vcpu) · line 3449
Quoted 5 lines
arch/s390/kvm/kvm-s390.c +1
-3vcpu->run->s.regs.fpc =0 ; - vcpu->arch.sie_block->gbea =1 ; - vcpu->arch.sie_block->pp =0 ; - vcpu->arch.sie_block->fpf &= ~FPF_BPBC ; +if (!kvm_s390_pv_handle_cpu (vcpu)) {Shouldn't we instead check if the VM is in PV mode? (with changed lifecycle handling). Easier to understand.
Quoted 4 lines
No. these ioctls are under the
vcpu->mutex, so I am going to compare against the per cpu variant.I will use
kvm_s390_pv_cpu_is_protectedinstead to have the lockdep assertion.
That's what I meant!
Signature · 3 lines
Thanks, David / dhildenb
PATCH v2 27/42 KVM: s390: protvirt: Only sync fmt4 registers
In reply to Christian BorntraegerFrom: Janosch Frank <[email protected]>
A lot of the registers are controlled by the Ultravisor and never visible to KVM. Also some registers are overlayed, like gbea is with sidad, which might leak data to userspace.
Hence we sync a minimal set of registers for both SIE formats and then check and sync format 2 registers if necessary.
--- arch/s390/kvm/kvm-s390.c | 110 +++++++++++++++++++++++++-------------- 1 file changed, 70 insertions(+), 40 deletions(-)
arch/s390/kvm/kvm-s390.c +70 -40
@@ -4048,7 +4048,7 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)return rc; } -static void sync_regs (struct kvm_vcpu *vcpu,struct kvm_run *kvm_run) +static void sync_regs_fmt2 (struct kvm_vcpu *vcpu,struct kvm_run *kvm_run) {struct runtime_instr_cb *riccb;struct gs_cb *gscb;
@@ -4057,16 +4057,7 @@ static void sync_regs(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) gscb = (struct gs_cb *) &kvm_run->s.regs.gscb; vcpu->arch.sie_block->gpsw.mask = kvm_run->psw_mask; vcpu->arch.sie_block->gpsw.addr = kvm_run->psw_addr; -if (kvm_run->kvm_dirty_regs &KVM_SYNC_PREFIX ) -kvm_s390_set_prefix (vcpu, kvm_run->s.regs.prefix); -if (kvm_run->kvm_dirty_regs &KVM_SYNC_CRS ) { -memcpy (&vcpu->arch.sie_block->gcr, &kvm_run->s.regs.crs,128 ); -/* some control register changes require a tlb flush */ -kvm_make_request (KVM_REQ_TLB_FLUSH , vcpu); - }if (kvm_run->kvm_dirty_regs &KVM_SYNC_ARCH0 ) { -kvm_s390_set_cpu_timer (vcpu, kvm_run->s.regs.cputm); - vcpu->arch.sie_block->ckc = kvm_run->s.regs.ckc; vcpu->arch.sie_block->todpr = kvm_run->s.regs.todpr; vcpu->arch.sie_block->pp = kvm_run->s.regs.pp; vcpu->arch.sie_block->gbea = kvm_run->s.regs.gbea;
@@ -4107,6 +4098,36 @@ static void sync_regs(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) vcpu->arch.sie_block->fpf &= ~FPF_BPBC ; vcpu->arch.sie_block->fpf |= kvm_run->s.regs.bpbc ?FPF_BPBC :0 ; } +if (MACHINE_HAS_GS ) { +preempt_disable (); +__ctl_set_bit (2 ,4 ); +if (current->thread.gs_cb) { + vcpu->arch.host_gscb = current->thread.gs_cb; +save_gs_cb (vcpu->arch.host_gscb); + } +if (vcpu->arch.gs_enabled) { + current->thread.gs_cb = (struct gs_cb *) + &vcpu->run->s.regs.gscb; +restore_gs_cb (current->thread.gs_cb); + } +preempt_enable (); + } +/* SIE will load etoken directly from SDNX and therefore kvm_run */ +} + +static void sync_regs (struct kvm_vcpu *vcpu,struct kvm_run *kvm_run) +{ +if (kvm_run->kvm_dirty_regs &KVM_SYNC_PREFIX ) +kvm_s390_set_prefix (vcpu, kvm_run->s.regs.prefix); +if (kvm_run->kvm_dirty_regs &KVM_SYNC_CRS ) { +memcpy (&vcpu->arch.sie_block->gcr, &kvm_run->s.regs.crs,128 ); +/* some control register changes require a tlb flush */ +kvm_make_request (KVM_REQ_TLB_FLUSH , vcpu); + } +if (kvm_run->kvm_dirty_regs &KVM_SYNC_ARCH0 ) { +kvm_s390_set_cpu_timer (vcpu, kvm_run->s.regs.cputm); + vcpu->arch.sie_block->ckc = kvm_run->s.regs.ckc; + }save_access_regs (vcpu->arch.host_acrs);restore_access_regs (vcpu->run->s.regs.acrs);/* save host (userspace) fprs/vrs */
@@ -4121,23 +4142,47 @@ static void sync_regs(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)if (test_fp_ctl (current->thread.fpu.fpc))/* User space provided an invalid FPC, let's clear it */ current->thread.fpu.fpc =0 ; + +/* Sync fmt2 only data */ +if (likely (!kvm_s390_pv_is_protected (vcpu->kvm))) { +sync_regs_fmt2 (vcpu, kvm_run); + }else { +/* +* In several places we have to modify our internal view to +* not do things that are disallowed by the ultravisor. For +* example we must not inject interrupts after specific exits +* (e.g. 112 prefix page not secure). We do this by turning +* off the machine check, external and I/O interrupt bits +* of our PSW copy. To avoid getting validity intercepts, we +* do only accept the condition code from userspace. +*/ + vcpu->arch.sie_block->gpsw.mask &= ~PSW_MASK_CC ; + vcpu->arch.sie_block->gpsw.mask |= kvm_run->psw_mask & +PSW_MASK_CC ; + } + + kvm_run->kvm_dirty_regs =0 ; +} + +static void store_regs_fmt2 (struct kvm_vcpu *vcpu,struct kvm_run *kvm_run) +{ + kvm_run->s.regs.todpr = vcpu->arch.sie_block->todpr; + kvm_run->s.regs.pp = vcpu->arch.sie_block->pp; + kvm_run->s.regs.gbea = vcpu->arch.sie_block->gbea; + kvm_run->s.regs.bpbc = (vcpu->arch.sie_block->fpf &FPF_BPBC ) ==FPF_BPBC ;if (MACHINE_HAS_GS ) { -preempt_disable ();__ctl_set_bit (2 ,4 ); -if (current->thread.gs_cb) { - vcpu->arch.host_gscb = current->thread.gs_cb; -save_gs_cb (vcpu->arch.host_gscb); - } -if (vcpu->arch.gs_enabled) { - current->thread.gs_cb = (struct gs_cb *) - &vcpu->run->s.regs.gscb; -restore_gs_cb (current->thread.gs_cb); - } +if (vcpu->arch.gs_enabled) +save_gs_cb (current->thread.gs_cb); +preempt_disable (); + current->thread.gs_cb = vcpu->arch.host_gscb; +restore_gs_cb (vcpu->arch.host_gscb);preempt_enable (); +if (!vcpu->arch.host_gscb) +__ctl_clear_bit (2 ,4 ); + vcpu->arch.host_gscb =NULL ; } -/* SIE will load etoken directly from SDNX and therefore kvm_run */ - - kvm_run->kvm_dirty_regs =0 ; +/* SIE will save etoken directly into SDNX and therefore kvm_run */ }static void store_regs (struct kvm_vcpu *vcpu,struct kvm_run *kvm_run)
@@ -4148,13 +4193,9 @@ static void store_regs(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)memcpy (&kvm_run->s.regs.crs, &vcpu->arch.sie_block->gcr,128 ); kvm_run->s.regs.cputm =kvm_s390_get_cpu_timer (vcpu); kvm_run->s.regs.ckc = vcpu->arch.sie_block->ckc; - kvm_run->s.regs.todpr = vcpu->arch.sie_block->todpr; - kvm_run->s.regs.pp = vcpu->arch.sie_block->pp; - kvm_run->s.regs.gbea = vcpu->arch.sie_block->gbea; kvm_run->s.regs.pft = vcpu->arch.pfault_token; kvm_run->s.regs.pfs = vcpu->arch.pfault_select; kvm_run->s.regs.pfc = vcpu->arch.pfault_compare; - kvm_run->s.regs.bpbc = (vcpu->arch.sie_block->fpf &FPF_BPBC ) ==FPF_BPBC ;save_access_regs (vcpu->run->s.regs.acrs);restore_access_regs (vcpu->arch.host_acrs);/* Save guest register state */
@@ -4163,19 +4204,8 @@ static void store_regs(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)/* Restore will be done lazily at return */ current->thread.fpu.fpc = vcpu->arch.host_fpregs.fpc; current->thread.fpu.regs = vcpu->arch.host_fpregs.regs; -if (MACHINE_HAS_GS ) { -__ctl_set_bit (2 ,4 ); -if (vcpu->arch.gs_enabled) -save_gs_cb (current->thread.gs_cb); -preempt_disable (); - current->thread.gs_cb = vcpu->arch.host_gscb; -restore_gs_cb (vcpu->arch.host_gscb); -preempt_enable (); -if (!vcpu->arch.host_gscb) -__ctl_clear_bit (2 ,4 ); - vcpu->arch.host_gscb =NULL ; - } -/* SIE will save etoken directly into SDNX and therefore kvm_run */ +if (likely (!kvm_s390_pv_is_protected (vcpu->kvm))) +store_regs_fmt2 (vcpu, kvm_run); }int kvm_arch_vcpu_ioctl_run (struct kvm_vcpu *vcpu,struct kvm_run *kvm_run)
Signature · 1 line
2.25.0
PATCH v2 28/42 KVM: s390: protvirt: Add program exception injection
In reply to Christian BorntraegerFrom: Janosch Frank <[email protected]>
Only two program exceptions can be injected for a protected guest:
specification and operand.
For both, a code needs to be specified in the interrupt injection control of the state description, as the guest prefix page is not accessible to KVM for such guests.
--- arch/s390/kvm/interrupt.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
arch/s390/kvm/interrupt.c +18 -0
@@ -836,6 +836,21 @@ static int __must_check __deliver_external_call(struct kvm_vcpu *vcpu)return rc ? -EFAULT :0 ; } +static int __deliver_prog_pv (struct kvm_vcpu *vcpu,u16 code) +{ +switch (code) { +case PGM_SPECIFICATION : + vcpu->arch.sie_block->iictl =IICTL_CODE_SPECIFICATION ; +break ; +case PGM_OPERAND : + vcpu->arch.sie_block->iictl =IICTL_CODE_OPERAND ; +break ; +default : +return -EINVAL ; + } +return 0 ; +} +static int __must_check __deliver_prog (struct kvm_vcpu *vcpu) {struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
@@ -856,6 +871,9 @@ static int __must_check __deliver_prog(struct kvm_vcpu *vcpu)trace_kvm_s390_deliver_interrupt (vcpu->vcpu_id,KVM_S390_PROGRAM_INT , pgm_info.code,0 ); +if (kvm_s390_pv_is_protected (vcpu->kvm)) +return __deliver_prog_pv (vcpu, pgm_info.code & ~PGM_PER ); +switch (pgm_info.code & ~PGM_PER ) {case PGM_AFX_TRANSLATION :case PGM_ASX_TRANSLATION :
Signature · 1 line
2.25.0
Re: [PATCH v2 28/42] KVM: s390: protvirt: Add program exception injection
Quoted 45 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
Only two program exceptions can be injected for a protected guest:
specification and operand.For both, a code needs to be specified in the interrupt injection control of the state description, as the guest prefix page is not accessible to KVM for such guests.
Signed-off-by Janosch Frank <[email protected]>Reviewed-by Cornelia Huck <[email protected]>Reviewed-by Thomas Huth <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/kvm/interrupt.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)arch/s390/kvm/interrupt.c +15
-0@@ -836,6 +836,21 @@ static int __must_check __deliver_external_call(struct kvm_vcpu *vcpu)return rc ? -EFAULT :0 ; } +static int __deliver_prog_pv (struct kvm_vcpu *vcpu,u16 code) +{ +switch (code) { +case PGM_SPECIFICATION : + vcpu->arch.sie_block->iictl =IICTL_CODE_SPECIFICATION ; +break ; +case PGM_OPERAND : + vcpu->arch.sie_block->iictl =IICTL_CODE_OPERAND ; +break ; +default : +return -EINVAL ; + } +return 0 ; +} +static int __must_check __deliver_prog (struct kvm_vcpu *vcpu) {struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
arch/s390/kvm/interrupt.c static int __must_check __deliver_prog(struct kvm_vcpu *vcpu) · line 874
Quoted 4 lines
arch/s390/kvm/interrupt.c +1
-0@@ -856,6 +871,9 @@ static int __must_check __deliver_prog(struct kvm_vcpu *vcpu)trace_kvm_s390_deliver_interrupt (vcpu->vcpu_id,KVM_S390_PROGRAM_INT , pgm_info.code,0 ); +if (kvm_s390_pv_is_protected (vcpu->kvm))
Can we actually ever have PER set, and what would happen if so? Shouldn't we also return -EINVAL?
Quoted 6 lines
arch/s390/kvm/interrupt.c +2
-0+return __deliver_prog_pv (vcpu, pgm_info.code & ~PGM_PER ); +switch (pgm_info.code & ~PGM_PER ) {case PGM_AFX_TRANSLATION :case PGM_ASX_TRANSLATION :
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v2 28/42] KVM: s390: protvirt: Add program exception injection
On 18.02.20 10:33, David Hildenbrand wrote:eliver_prog(struct kvm_vcpu *vcpu)
Quoted 10 lines
arch/s390/kvm/interrupt.c static int __must_check __deliver_prog(struct kvm_vcpu *vcpu) · line 874
Quoted 7 lines
{
arch/s390/kvm/interrupt.c +1
-0struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;@@ -856,6 +871,9 @@ static int __must_check __deliver_prog(struct kvm_vcpu *vcpu)trace_kvm_s390_deliver_interrupt (vcpu->vcpu_id,KVM_S390_PROGRAM_INT , pgm_info.code,0 ); +if (kvm_s390_pv_is_protected (vcpu->kvm))Can we actually ever have PER set, and what would happen if so? Shouldn't we also return
-EINVAL?
The ultravisor would add a concurrent PER event if appropriate.
David Hildenbrand
Reviewed-byRe: [PATCH v2 28/42] KVM: s390: protvirt: Add program exception injection
Quoted 10 lines · Christian Borntraeger
On 18.02.20 10:33, David Hildenbrand wrote:
eliver_prog(struct kvm_vcpu *vcpu)Quoted 6 lines
Quoted 6 lines
{
arch/s390/kvm/interrupt.c +0
-0struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;@@ -856,6 +871,9 @@ static int __must_check __deliver_prog(struct kvm_vcpu *vcpu)trace_kvm_s390_deliver_interrupt (vcpu->vcpu_id,KVM_S390_PROGRAM_INT , pgm_info.code,0 );
Quoted 7 lines
Quoted 4 lines
arch/s390/kvm/interrupt.c static int __must_check __deliver_prog(struct kvm_vcpu *vcpu) · line 874
Quoted 1 line
arch/s390/kvm/interrupt.c +1
-0+if (kvm_s390_pv_is_protected (vcpu->kvm))Can we actually ever have PER set, and what would happen if so? Shouldn't we also return
-EINVAL?The ultravisor would add a concurrent PER event if appropriate.
Please add that to the patch description.
Signature · 3 lines
Thanks, David / dhildenb
PATCH v2 29/42 KVM: s390: protvirt: Add diag 308 subcode 8 - 10 handling
In reply to Christian BorntraegerFrom: Janosch Frank <[email protected]>
If the host initialized the Ultravisor, we can set stfle bit 161 (protected virtual IPL enhancements facility), which indicates that the IPL subcodes 8, 9, and 10 are valid. These subcodes are used by a normal guest to set/retrieve an IPL information block of type 5 (for protected virtual machines) and transition into protected mode.
Once in protected mode, the Ultravisor will conceal the facility bit. Therefore each boot into protected mode has to go through non-protected mode. There is no secure re-ipl with subcode 10 without a previous subcode 3.
In protected mode, there is no subcode 4 available, as the VM has no more access to its memory from non-protected mode. I.e., only a IPL clear is possible.
The error cases will all be handled in userspace.
--- arch/s390/kvm/kvm-s390.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/s390/kvm/kvm-s390.c +5 -0
@@ -2621,6 +2621,11 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)if (css_general_characteristics.aiv &&test_facility (65 ))set_kvm_facility (kvm->arch.model.fac_mask,65 ); +if (is_prot_virt_host ()) { +set_kvm_facility (kvm->arch.model.fac_mask,161 ); +set_kvm_facility (kvm->arch.model.fac_list,161 ); + } + kvm->arch.model.cpuid =kvm_s390_get_initial_cpuid (); kvm->arch.model.ibc = sclp.ibc &0x0fff ;
Signature · 1 line
2.25.0
Re: [PATCH v2 29/42] KVM: s390: protvirt: Add diag 308 subcode 8 - 10 handling
Quoted 32 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
If the host initialized the Ultravisor, we can set stfle bit 161 (protected virtual IPL enhancements facility), which indicates that the IPL subcodes 8, 9, and 10 are valid. These subcodes are used by a normal guest to set/retrieve an IPL information block of type 5 (for protected virtual machines) and transition into protected mode.
Once in protected mode, the Ultravisor will conceal the facility bit. Therefore each boot into protected mode has to go through non-protected mode. There is no secure re-ipl with subcode 10 without a previous subcode 3.
In protected mode, there is no subcode 4 available, as the VM has no more access to its memory from non-protected mode. I.e., only a IPL clear is possible.
The error cases will all be handled in userspace.
Signed-off-by Janosch Frank <[email protected]>Reviewed-by Cornelia Huck <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/kvm/kvm-s390.c | 5 +++++ 1 file changed, 5 insertions(+)arch/s390/kvm/kvm-s390.c +0
-0
arch/s390/kvm/kvm-s390.c int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) · line 2628
Quoted 8 lines
arch/s390/kvm/kvm-s390.c +5
-0@@ -2621,6 +2621,11 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)if (css_general_characteristics.aiv &&test_facility (65 ))set_kvm_facility (kvm->arch.model.fac_mask,65 ); +if (is_prot_virt_host ()) { +set_kvm_facility (kvm->arch.model.fac_mask,161 ); +set_kvm_facility (kvm->arch.model.fac_list,161 ); + } +
Aren't these IPL subcodes completely emulated in QEMU? If so, rather QEMU with support should enable them when the kernel capability for PV (=== is_prot_virt_host()) is in place.
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v2 29/42] KVM: s390: protvirt: Add diag 308 subcode 8 - 10 handling
On 18.02.20 10:38, David Hildenbrand wrote:
[...]
set_kvm_facility(kvm->arch.model.fac_mask, 65);
Quoted 10 lines
arch/s390/kvm/kvm-s390.c int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) · line 2628
Quoted 6 lines
arch/s390/kvm/kvm-s390.c +5
-0+if (is_prot_virt_host ()) { +set_kvm_facility (kvm->arch.model.fac_mask,161 ); +set_kvm_facility (kvm->arch.model.fac_list,161 ); + } +Aren't these IPL subcodes completely emulated in QEMU? If so, rather QEMU with support should enable them when the kernel capability for PV (===
is_prot_virt_host()) is in place.
ack. will drop this patch.
PATCH v2 30/42 KVM: s390: protvirt: UV calls in support of diag308 0, 1
In reply to Christian BorntraegerFrom: Janosch Frank <[email protected]>
diag 308 subcode 0 and 1 require several KVM and Ultravisor interactions. Specific to these "soft" reboots are
* The "unshare all" UVC
* The "prepare for reset" UVC
--- arch/s390/include/asm/uv.h | 4 ++++ arch/s390/kvm/kvm-s390.c | 22 ++++++++++++++++++++++ include/uapi/linux/kvm.h | 2 ++ 3 files changed, 28 insertions(+)
arch/s390/include/asm/uv.h +4 -0
@@ -36,6 +36,8 @@#define UVC_CMD_SET_SEC_CONF_PARAMS 0x0300#define UVC_CMD_UNPACK_IMG 0x0301#define UVC_CMD_VERIFY_IMG 0x0302 +#define UVC_CMD_PREPARE_RESET 0x0320 +#define UVC_CMD_SET_UNSHARE_ALL 0x0340#define UVC_CMD_PIN_PAGE_SHARED 0x0341#define UVC_CMD_UNPIN_PAGE_SHARED 0x0342#define UVC_CMD_SET_SHARED_ACCESS 0x1000
@@ -56,6 +58,8 @@ enum uv_cmds_inst {BIT_UVC_CMD_SET_SEC_PARMS =11 ,BIT_UVC_CMD_UNPACK_IMG =13 ,BIT_UVC_CMD_VERIFY_IMG =14 , +BIT_UVC_CMD_PREPARE_RESET =18 , +BIT_UVC_CMD_UNSHARE_ALL =20 ,BIT_UVC_CMD_PIN_PAGE_SHARED =21 , BIT_UVC_CMD_UNPIN_PAGE_SHARED = 22, };
arch/s390/kvm/kvm-s390.c +22 -0
@@ -2285,6 +2285,28 @@ static int kvm_s390_handle_pv(struct kvm *kvm, struct kvm_pv_cmd *cmd) cmd->rrc);break ; } +case KVM_PV_VM_PREP_RESET : { + r = -EINVAL ; +if (!kvm_s390_pv_is_protected (kvm)) +break ; + + r =uv_cmd_nodata (kvm_s390_pv_handle (kvm), +UVC_CMD_PREPARE_RESET , &cmd->rc, &cmd->rrc); +KVM_UV_EVENT (kvm,3 ,"PROTVIRT PREP RESET: rc %x rrc %x" , + cmd->rc, cmd->rrc); +break ; + } +case KVM_PV_VM_UNSHARE_ALL : { + r = -EINVAL ; +if (!kvm_s390_pv_is_protected (kvm)) +break ; + + r =uv_cmd_nodata (kvm_s390_pv_handle (kvm), +UVC_CMD_SET_UNSHARE_ALL , &cmd->rc, &cmd->rrc); +KVM_UV_EVENT (kvm,3 ,"PROTVIRT UNSHARE: rc %x rrc %x" , + cmd->rc, cmd->rrc); +break ; + }default :return -ENOTTY ; }
include/uapi/linux/kvm.h +2 -0
@@ -1500,6 +1500,8 @@ enum pv_cmd_id {KVM_PV_VM_SET_SEC_PARMS ,KVM_PV_VM_UNPACK ,KVM_PV_VM_VERIFY , +KVM_PV_VM_PREP_RESET , +KVM_PV_VM_UNSHARE_ALL ,KVM_PV_VCPU_CREATE , KVM_PV_VCPU_DESTROY, };
Signature · 1 line
2.25.0
Re: [PATCH v2 30/42] KVM: s390: protvirt: UV calls in support of diag308 0, 1
Quoted 57 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
diag 308 subcode 0 and 1 require several KVM and Ultravisor interactions. Specific to these "soft" reboots are
* The "unshare all" UVC
* The "prepare for reset" UVCSigned-off-by Janosch Frank <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/include/asm/uv.h | 4 ++++ arch/s390/kvm/kvm-s390.c | 22 ++++++++++++++++++++++ include/uapi/linux/kvm.h | 2 ++ 3 files changed, 28 insertions(+)arch/s390/include/asm/uv.h +4
-0@@ -36,6 +36,8 @@#define UVC_CMD_SET_SEC_CONF_PARAMS 0x0300#define UVC_CMD_UNPACK_IMG 0x0301#define UVC_CMD_VERIFY_IMG 0x0302 +#define UVC_CMD_PREPARE_RESET 0x0320 +#define UVC_CMD_SET_UNSHARE_ALL 0x0340#define UVC_CMD_PIN_PAGE_SHARED 0x0341#define UVC_CMD_UNPIN_PAGE_SHARED 0x0342#define UVC_CMD_SET_SHARED_ACCESS 0x1000@@ -56,6 +58,8 @@ enum uv_cmds_inst {BIT_UVC_CMD_SET_SEC_PARMS =11 ,BIT_UVC_CMD_UNPACK_IMG =13 ,BIT_UVC_CMD_VERIFY_IMG =14 , +BIT_UVC_CMD_PREPARE_RESET =18 , +BIT_UVC_CMD_UNSHARE_ALL =20 ,BIT_UVC_CMD_PIN_PAGE_SHARED =21 , BIT_UVC_CMD_UNPIN_PAGE_SHARED = 22, };arch/s390/kvm/kvm-s390.c +10
-0@@ -2285,6 +2285,28 @@ static int kvm_s390_handle_pv(struct kvm *kvm, struct kvm_pv_cmd *cmd) cmd->rrc);break ; } +case KVM_PV_VM_PREP_RESET : { + r = -EINVAL ; +if (!kvm_s390_pv_is_protected (kvm)) +break ; + + r =uv_cmd_nodata (kvm_s390_pv_handle (kvm), +UVC_CMD_PREPARE_RESET , &cmd->rc, &cmd->rrc); +KVM_UV_EVENT (kvm,3 ,"PROTVIRT PREP RESET: rc %x rrc %x" , + cmd->rc, cmd->rrc); +break ;
arch/s390/kvm/kvm-s390.c static int kvm_s390_handle_pv(struct kvm *kvm, struct kvm_pv_cmd *cmd) · line 2307
Quoted 10 lines
arch/s390/kvm/kvm-s390.c +10
-0+ } +case KVM_PV_VM_UNSHARE_ALL : { + r = -EINVAL ; +if (!kvm_s390_pv_is_protected (kvm)) +break ; + + r =uv_cmd_nodata (kvm_s390_pv_handle (kvm), +UVC_CMD_SET_UNSHARE_ALL , &cmd->rc, &cmd->rrc); +KVM_UV_EVENT (kvm,3 ,"PROTVIRT UNSHARE: rc %x rrc %x" , + cmd->rc, cmd->rrc);
I do wonder if that has any possible races with CPUs currently running, which try to mark pages shared. That no other VCPUs are running is not enforced here AFAIKs.
Apart from that, looks good to me.
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v2 30/42] KVM: s390: protvirt: UV calls in support of diag308 0, 1
Quoted 64 lines · David Hildenbrand
Quoted 63 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
diag 308 subcode 0 and 1 require several KVM and Ultravisor interactions. Specific to these "soft" reboots are
* The "unshare all" UVC
* The "prepare for reset" UVCSigned-off-by Janosch Frank <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/include/asm/uv.h | 4 ++++ arch/s390/kvm/kvm-s390.c | 22 ++++++++++++++++++++++ include/uapi/linux/kvm.h | 2 ++ 3 files changed, 28 insertions(+)arch/s390/include/asm/uv.h +4
-0@@ -36,6 +36,8 @@#define UVC_CMD_SET_SEC_CONF_PARAMS 0x0300#define UVC_CMD_UNPACK_IMG 0x0301#define UVC_CMD_VERIFY_IMG 0x0302 +#define UVC_CMD_PREPARE_RESET 0x0320 +#define UVC_CMD_SET_UNSHARE_ALL 0x0340#define UVC_CMD_PIN_PAGE_SHARED 0x0341#define UVC_CMD_UNPIN_PAGE_SHARED 0x0342#define UVC_CMD_SET_SHARED_ACCESS 0x1000@@ -56,6 +58,8 @@ enum uv_cmds_inst {BIT_UVC_CMD_SET_SEC_PARMS =11 ,BIT_UVC_CMD_UNPACK_IMG =13 ,BIT_UVC_CMD_VERIFY_IMG =14 , +BIT_UVC_CMD_PREPARE_RESET =18 , +BIT_UVC_CMD_UNSHARE_ALL =20 ,BIT_UVC_CMD_PIN_PAGE_SHARED =21 , BIT_UVC_CMD_UNPIN_PAGE_SHARED = 22, };arch/s390/kvm/kvm-s390.c +16
-0@@ -2285,6 +2285,28 @@ static int kvm_s390_handle_pv(struct kvm *kvm, struct kvm_pv_cmd *cmd) cmd->rrc);break ; } +case KVM_PV_VM_PREP_RESET : { + r = -EINVAL ; +if (!kvm_s390_pv_is_protected (kvm)) +break ; + + r =uv_cmd_nodata (kvm_s390_pv_handle (kvm), +UVC_CMD_PREPARE_RESET , &cmd->rc, &cmd->rrc); +KVM_UV_EVENT (kvm,3 ,"PROTVIRT PREP RESET: rc %x rrc %x" , + cmd->rc, cmd->rrc); +break ; + } +case KVM_PV_VM_UNSHARE_ALL : { + r = -EINVAL ; +if (!kvm_s390_pv_is_protected (kvm)) +break ; +
Quoted 8 lines
arch/s390/kvm/kvm-s390.c static int kvm_s390_handle_pv(struct kvm *kvm, struct kvm_pv_cmd *cmd) · line 2307
Quoted 4 lines
arch/s390/kvm/kvm-s390.c +4
-0+ r =uv_cmd_nodata (kvm_s390_pv_handle (kvm), +UVC_CMD_SET_UNSHARE_ALL , &cmd->rc, &cmd->rrc); +KVM_UV_EVENT (kvm,3 ,"PROTVIRT UNSHARE: rc %x rrc %x" , + cmd->rc, cmd->rrc);I do wonder if that has any possible races with CPUs currently running, which try to mark pages shared. That no other VCPUs are running is not enforced here AFAIKs.
The only concern would be that the newly bootet guest (e.g. via kexec/kdump) will have pages shared that it dont want to share. As it is the responsiblity of the ultravisor to prevent data leakage, it is enforced that we do an UNSHARE all on diag 308 subcode 0 and 1. At the same time the ultravisor will enforce that no CPU will run before we have finished the full dance of reset activity. (The ultravisor must guarantee guest secrecy and integrity no matter what KVM does).
Quoted 3 lines
Apart from that, looks good to me.
PATCH v2 31/42 KVM: s390: protvirt: Report CPU state to Ultravisor
In reply to Christian BorntraegerFrom: Janosch Frank <[email protected]>
VCPU states have to be reported to the ultravisor for SIGP interpretation, kdump, kexec and reboot.
--- arch/s390/include/asm/uv.h | 15 +++++++++++++++ arch/s390/kvm/kvm-s390.c | 7 ++++++- arch/s390/kvm/kvm-s390.h | 2 ++ arch/s390/kvm/pv.c | 22 ++++++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-)
arch/s390/include/asm/uv.h +15 -0
@@ -37,6 +37,7 @@#define UVC_CMD_UNPACK_IMG 0x0301#define UVC_CMD_VERIFY_IMG 0x0302#define UVC_CMD_PREPARE_RESET 0x0320 +#define UVC_CMD_CPU_SET_STATE 0x0330#define UVC_CMD_SET_UNSHARE_ALL 0x0340#define UVC_CMD_PIN_PAGE_SHARED 0x0341#define UVC_CMD_UNPIN_PAGE_SHARED 0x0342
@@ -58,6 +59,7 @@ enum uv_cmds_inst {BIT_UVC_CMD_SET_SEC_PARMS =11 ,BIT_UVC_CMD_UNPACK_IMG =13 ,BIT_UVC_CMD_VERIFY_IMG =14 , +BIT_UVC_CMD_CPU_SET_STATE =17 ,BIT_UVC_CMD_PREPARE_RESET =18 ,BIT_UVC_CMD_UNSHARE_ALL =20 , BIT_UVC_CMD_PIN_PAGE_SHARED = 21,
@@ -164,6 +166,19 @@ struct uv_cb_unp {u64 reserved38[3 ]; } __packed__aligned(8) ; +#define PV_CPU_STATE_OPR 1 +#define PV_CPU_STATE_STP 2 +#define PV_CPU_STATE_CHKSTP 3 + +struct uv_cb_cpu_set_state { +struct uv_cb_header header; +u64 reserved08[2 ]; +u64 cpu_handle; +u8 reserved20[7 ]; +u8 state; +u64 reserved28[5 ]; +}; +/* * A common UV call struct for calls that take no payload * Examples:
arch/s390/kvm/kvm-s390.c +6 -1
@@ -4396,6 +4396,7 @@ static void __enable_ibs_on_vcpu(struct kvm_vcpu *vcpu)void kvm_s390_vcpu_start (struct kvm_vcpu *vcpu) {int i, online_vcpus, started_vcpus =0 ; +u16 rc, rrc;if (!is_vcpu_stopped (vcpu))return ;
@@ -4421,7 +4422,8 @@ void kvm_s390_vcpu_start(struct kvm_vcpu *vcpu)*/ __disable_ibs_on_all_vcpus (vcpu->kvm); } - +/* Let's tell the UV that we want to start again */ +kvm_s390_pv_set_cpu_state (vcpu,PV_CPU_STATE_OPR , &rc, &rrc);kvm_s390_clear_cpuflags (vcpu,CPUSTAT_STOPPED );/* * Another VCPU might have used IBS while we were offline.
@@ -4436,6 +4438,7 @@ void kvm_s390_vcpu_stop(struct kvm_vcpu *vcpu) {int i, online_vcpus, started_vcpus =0 ;struct kvm_vcpu *started_vcpu =NULL ; +u16 rc, rrc;if (is_vcpu_stopped (vcpu))return ;
@@ -4449,6 +4452,8 @@ void kvm_s390_vcpu_stop(struct kvm_vcpu *vcpu)kvm_s390_clear_stop_irq (vcpu);kvm_s390_set_cpuflags (vcpu,CPUSTAT_STOPPED ); +/* Let's tell the UV that we successfully stopped the vcpu */ +kvm_s390_pv_set_cpu_state (vcpu,PV_CPU_STATE_STP , &rc, &rrc);__disable_ibs_on_vcpu (vcpu);for (i =0 ; i < online_vcpus; i++) {
arch/s390/kvm/kvm-s390.h +2 -0
@@ -218,6 +218,8 @@ int kvm_s390_pv_set_sec_parms(struct kvm *kvm, void *hdr, u64 length, u16 *rc, u16 *rrc);int kvm_s390_pv_unpack (struct kvm *kvm,unsigned long addr,unsigned long size,unsigned long tweak,u16 *rc,u16 *rrc); +int kvm_s390_pv_set_cpu_state (struct kvm_vcpu *vcpu,u8 state,u16 *rc, +u16 *rrc);static inline bool kvm_s390_pv_is_protected (struct kvm *kvm) {
arch/s390/kvm/pv.c +22 -0
@@ -271,3 +271,25 @@ int kvm_s390_pv_unpack(struct kvm *kvm, unsigned long addr, unsigned long size,KVM_UV_EVENT (kvm,3 ,"%s" ,"PROTVIRT VM UNPACK: successful" );return ret; } + +int kvm_s390_pv_set_cpu_state (struct kvm_vcpu *vcpu,u8 state,u16 *rc, +u16 *rrc) +{ +struct uv_cb_cpu_set_state uvcb = { + .header.cmd =UVC_CMD_CPU_SET_STATE , + .header.len =sizeof (uvcb), + .cpu_handle =kvm_s390_pv_handle_cpu (vcpu), + .state = state, + }; +int cc; + +if (!kvm_s390_pv_handle_cpu (vcpu)) +return -EINVAL ; + + cc =uv_call (0 , (u64)&uvcb); + *rc = uvcb.header.rc; + *rrc = uvcb.header.rrc; +if (cc) +return -EINVAL ; +return 0 ; +}
Signature · 1 line
2.25.0
Re: [PATCH v2 31/42] KVM: s390: protvirt: Report CPU state to Ultravisor
Quoted 120 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
VCPU states have to be reported to the ultravisor for SIGP interpretation, kdump, kexec and reboot.
Signed-off-by Janosch Frank <[email protected]>Reviewed-by Thomas Huth <[email protected]>Reviewed-by Cornelia Huck <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/include/asm/uv.h | 15 +++++++++++++++ arch/s390/kvm/kvm-s390.c | 7 ++++++- arch/s390/kvm/kvm-s390.h | 2 ++ arch/s390/kvm/pv.c | 22 ++++++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-)arch/s390/include/asm/uv.h +15
-0@@ -37,6 +37,7 @@#define UVC_CMD_UNPACK_IMG 0x0301#define UVC_CMD_VERIFY_IMG 0x0302#define UVC_CMD_PREPARE_RESET 0x0320 +#define UVC_CMD_CPU_SET_STATE 0x0330#define UVC_CMD_SET_UNSHARE_ALL 0x0340#define UVC_CMD_PIN_PAGE_SHARED 0x0341#define UVC_CMD_UNPIN_PAGE_SHARED 0x0342@@ -58,6 +59,7 @@ enum uv_cmds_inst {BIT_UVC_CMD_SET_SEC_PARMS =11 ,BIT_UVC_CMD_UNPACK_IMG =13 ,BIT_UVC_CMD_VERIFY_IMG =14 , +BIT_UVC_CMD_CPU_SET_STATE =17 ,BIT_UVC_CMD_PREPARE_RESET =18 ,BIT_UVC_CMD_UNSHARE_ALL =20 , BIT_UVC_CMD_PIN_PAGE_SHARED = 21,@@ -164,6 +166,19 @@ struct uv_cb_unp {u64 reserved38[3 ]; } __packed__aligned(8) ; +#define PV_CPU_STATE_OPR 1 +#define PV_CPU_STATE_STP 2 +#define PV_CPU_STATE_CHKSTP 3 + +struct uv_cb_cpu_set_state { +struct uv_cb_header header; +u64 reserved08[2 ]; +u64 cpu_handle; +u8 reserved20[7 ]; +u8 state; +u64 reserved28[5 ]; +}; +/* * A common UV call struct for calls that take no payload * Examples: arch/s390/kvm/kvm-s390.c +6
-1@@ -4396,6 +4396,7 @@ static void __enable_ibs_on_vcpu(struct kvm_vcpu *vcpu)void kvm_s390_vcpu_start (struct kvm_vcpu *vcpu) {int i, online_vcpus, started_vcpus =0 ; +u16 rc, rrc;if (!is_vcpu_stopped (vcpu))return ;@@ -4421,7 +4422,8 @@ void kvm_s390_vcpu_start(struct kvm_vcpu *vcpu)*/ __disable_ibs_on_all_vcpus (vcpu->kvm); } - +/* Let's tell the UV that we want to start again */ +kvm_s390_pv_set_cpu_state (vcpu,PV_CPU_STATE_OPR , &rc, &rrc);kvm_s390_clear_cpuflags (vcpu,CPUSTAT_STOPPED );/* * Another VCPU might have used IBS while we were offline. @@ -4436,6 +4438,7 @@ void kvm_s390_vcpu_stop(struct kvm_vcpu *vcpu) {int i, online_vcpus, started_vcpus =0 ;struct kvm_vcpu *started_vcpu =NULL ; +u16 rc, rrc;if (is_vcpu_stopped (vcpu))return ;@@ -4449,6 +4452,8 @@ void kvm_s390_vcpu_stop(struct kvm_vcpu *vcpu)kvm_s390_clear_stop_irq (vcpu);kvm_s390_set_cpuflags (vcpu,CPUSTAT_STOPPED ); +/* Let's tell the UV that we successfully stopped the vcpu */ +kvm_s390_pv_set_cpu_state (vcpu,PV_CPU_STATE_STP , &rc, &rrc);__disable_ibs_on_vcpu (vcpu);for (i =0 ; i < online_vcpus; i++) {arch/s390/kvm/kvm-s390.h +2
-0@@ -218,6 +218,8 @@ int kvm_s390_pv_set_sec_parms(struct kvm *kvm, void *hdr, u64 length, u16 *rc, u16 *rrc);int kvm_s390_pv_unpack (struct kvm *kvm,unsigned long addr,unsigned long size,unsigned long tweak,u16 *rc,u16 *rrc); +int kvm_s390_pv_set_cpu_state (struct kvm_vcpu *vcpu,u8 state,u16 *rc, +u16 *rrc);static inline bool kvm_s390_pv_is_protected (struct kvm *kvm) {arch/s390/kvm/pv.c +3
-0@@ -271,3 +271,25 @@ int kvm_s390_pv_unpack(struct kvm *kvm, unsigned long addr, unsigned long size,KVM_UV_EVENT (kvm,3 ,"%s" ,"PROTVIRT VM UNPACK: successful" );return ret; } + +int kvm_s390_pv_set_cpu_state (struct kvm_vcpu *vcpu,u8 state,u16 *rc, +u16 *rrc)
arch/s390/kvm/pv.c int kvm_s390_pv_unpack(struct kvm *kvm, unsigned long addr, unsigned long size, · line 286
Quoted 10 lines
arch/s390/kvm/pv.c +10
-0+{ +struct uv_cb_cpu_set_state uvcb = { + .header.cmd =UVC_CMD_CPU_SET_STATE , + .header.len =sizeof (uvcb), + .cpu_handle =kvm_s390_pv_handle_cpu (vcpu), + .state = state, + }; +int cc; + +if (!kvm_s390_pv_handle_cpu (vcpu))
I'd actually prefer to move this to the caller. (and sue the _protected variant)
arch/s390/kvm/pv.c int kvm_s390_pv_unpack(struct kvm *kvm, unsigned long addr, unsigned long size, · line 293
Quoted 7 lines
arch/s390/kvm/pv.c +7
-0+return -EINVAL ; + + cc =uv_call (0 , (u64)&uvcb); + *rc = uvcb.header.rc; + *rrc = uvcb.header.rrc; +if (cc) +return -EINVAL ;
All return values are ignored. warn instead and make this a void function?
Quoted 3 lines
arch/s390/kvm/pv.c +2
-0+return 0 ; +}
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v2 31/42] KVM: s390: protvirt: Report CPU state to Ultravisor
Quoted 126 lines · David Hildenbrand
Quoted 125 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
VCPU states have to be reported to the ultravisor for SIGP interpretation, kdump, kexec and reboot.
Signed-off-by Janosch Frank <[email protected]>Reviewed-by Thomas Huth <[email protected]>Reviewed-by Cornelia Huck <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/include/asm/uv.h | 15 +++++++++++++++ arch/s390/kvm/kvm-s390.c | 7 ++++++- arch/s390/kvm/kvm-s390.h | 2 ++ arch/s390/kvm/pv.c | 22 ++++++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-)arch/s390/include/asm/uv.h +15
-0@@ -37,6 +37,7 @@#define UVC_CMD_UNPACK_IMG 0x0301#define UVC_CMD_VERIFY_IMG 0x0302#define UVC_CMD_PREPARE_RESET 0x0320 +#define UVC_CMD_CPU_SET_STATE 0x0330#define UVC_CMD_SET_UNSHARE_ALL 0x0340#define UVC_CMD_PIN_PAGE_SHARED 0x0341#define UVC_CMD_UNPIN_PAGE_SHARED 0x0342@@ -58,6 +59,7 @@ enum uv_cmds_inst {BIT_UVC_CMD_SET_SEC_PARMS =11 ,BIT_UVC_CMD_UNPACK_IMG =13 ,BIT_UVC_CMD_VERIFY_IMG =14 , +BIT_UVC_CMD_CPU_SET_STATE =17 ,BIT_UVC_CMD_PREPARE_RESET =18 ,BIT_UVC_CMD_UNSHARE_ALL =20 , BIT_UVC_CMD_PIN_PAGE_SHARED = 21,@@ -164,6 +166,19 @@ struct uv_cb_unp {u64 reserved38[3 ]; } __packed__aligned(8) ; +#define PV_CPU_STATE_OPR 1 +#define PV_CPU_STATE_STP 2 +#define PV_CPU_STATE_CHKSTP 3 + +struct uv_cb_cpu_set_state { +struct uv_cb_header header; +u64 reserved08[2 ]; +u64 cpu_handle; +u8 reserved20[7 ]; +u8 state; +u64 reserved28[5 ]; +}; +/* * A common UV call struct for calls that take no payload * Examples: arch/s390/kvm/kvm-s390.c +6
-1@@ -4396,6 +4396,7 @@ static void __enable_ibs_on_vcpu(struct kvm_vcpu *vcpu)void kvm_s390_vcpu_start (struct kvm_vcpu *vcpu) {int i, online_vcpus, started_vcpus =0 ; +u16 rc, rrc;if (!is_vcpu_stopped (vcpu))return ;@@ -4421,7 +4422,8 @@ void kvm_s390_vcpu_start(struct kvm_vcpu *vcpu)*/ __disable_ibs_on_all_vcpus (vcpu->kvm); } - +/* Let's tell the UV that we want to start again */ +kvm_s390_pv_set_cpu_state (vcpu,PV_CPU_STATE_OPR , &rc, &rrc);kvm_s390_clear_cpuflags (vcpu,CPUSTAT_STOPPED );/* * Another VCPU might have used IBS while we were offline. @@ -4436,6 +4438,7 @@ void kvm_s390_vcpu_stop(struct kvm_vcpu *vcpu) {int i, online_vcpus, started_vcpus =0 ;struct kvm_vcpu *started_vcpu =NULL ; +u16 rc, rrc;if (is_vcpu_stopped (vcpu))return ;@@ -4449,6 +4452,8 @@ void kvm_s390_vcpu_stop(struct kvm_vcpu *vcpu)kvm_s390_clear_stop_irq (vcpu);kvm_s390_set_cpuflags (vcpu,CPUSTAT_STOPPED ); +/* Let's tell the UV that we successfully stopped the vcpu */ +kvm_s390_pv_set_cpu_state (vcpu,PV_CPU_STATE_STP , &rc, &rrc);__disable_ibs_on_vcpu (vcpu);for (i =0 ; i < online_vcpus; i++) {arch/s390/kvm/kvm-s390.h +2
-0@@ -218,6 +218,8 @@ int kvm_s390_pv_set_sec_parms(struct kvm *kvm, void *hdr, u64 length, u16 *rc, u16 *rrc);int kvm_s390_pv_unpack (struct kvm *kvm,unsigned long addr,unsigned long size,unsigned long tweak,u16 *rc,u16 *rrc); +int kvm_s390_pv_set_cpu_state (struct kvm_vcpu *vcpu,u8 state,u16 *rc, +u16 *rrc);static inline bool kvm_s390_pv_is_protected (struct kvm *kvm) {arch/s390/kvm/pv.c +8
-0@@ -271,3 +271,25 @@ int kvm_s390_pv_unpack(struct kvm *kvm, unsigned long addr, unsigned long size,KVM_UV_EVENT (kvm,3 ,"%s" ,"PROTVIRT VM UNPACK: successful" );return ret; } + +int kvm_s390_pv_set_cpu_state (struct kvm_vcpu *vcpu,u8 state,u16 *rc, +u16 *rrc) +{ +struct uv_cb_cpu_set_state uvcb = { + .header.cmd =UVC_CMD_CPU_SET_STATE , + .header.len =sizeof (uvcb), + .cpu_handle =kvm_s390_pv_handle_cpu (vcpu),
Quoted 8 lines
arch/s390/kvm/pv.c int kvm_s390_pv_unpack(struct kvm *kvm, unsigned long addr, unsigned long size, · line 286
Quoted 5 lines
arch/s390/kvm/pv.c +5
-0+ .state = state, + }; +int cc; + +if (!kvm_s390_pv_handle_cpu (vcpu))I'd actually prefer to move this to the caller. (and sue the
_protectedvariant)
ack this makes sense.
Quoted 10 lines
arch/s390/kvm/pv.c int kvm_s390_pv_unpack(struct kvm *kvm, unsigned long addr, unsigned long size, · line 293
Quoted 8 lines
arch/s390/kvm/pv.c +7
-0+return -EINVAL ; + + cc =uv_call (0 , (u64)&uvcb); + *rc = uvcb.header.rc; + *rrc = uvcb.header.rrc; +if (cc) +return -EINVAL ;All return values are ignored. warn instead and make this a void function?
Hmm, I think userspace can trigger errors (e.g. invalid state or invalid point in time) So Warning is not good. We should actually return an error to userspace I guess.
by requiring user sigp for protvirt we can minimize the changes. Something like this on top of the current tree
arch/s390/kvm/kvm-s390.c +17 -13
@@ -2441,6 +2441,8 @@ long kvm_arch_vm_ioctl(struct file *filp,case KVM_S390_PV_COMMAND : {struct kvm_pv_cmd args; +/* protvirt means user sigp */ + kvm->arch.user_cpu_state_ctrl =1 ; r =0 ;if (!is_prot_virt_host ()) { r = -EINVAL ;
@@ -3702,17 +3704,17 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,switch (mp_state->mp_state) {case KVM_MP_STATE_STOPPED : -kvm_s390_vcpu_stop (vcpu); + rc =kvm_s390_vcpu_stop (vcpu);break ;case KVM_MP_STATE_OPERATING : -kvm_s390_vcpu_start (vcpu); + rc =kvm_s390_vcpu_start (vcpu);break ;case KVM_MP_STATE_LOAD :if (!kvm_s390_pv_cpu_is_protected (vcpu)) { rc = -ENXIO ;break ; } -kvm_s390_pv_set_cpu_state (vcpu,PV_CPU_STATE_OPR_LOAD ); + rc =kvm_s390_pv_set_cpu_state (vcpu,PV_CPU_STATE_OPR_LOAD );break ;case KVM_MP_STATE_CHECK_STOP :/* fall through - CHECK_STOP and LOAD are not supported yet */
@@ -4444,12 +4446,12 @@ static void __enable_ibs_on_vcpu(struct kvm_vcpu *vcpu)kvm_s390_sync_request (KVM_REQ_ENABLE_IBS , vcpu); } -void kvm_s390_vcpu_start (struct kvm_vcpu *vcpu) +int kvm_s390_vcpu_start (struct kvm_vcpu *vcpu) { -int i, online_vcpus, started_vcpus =0 ; +int i, online_vcpus, r=0 , started_vcpus =0 ;if (!is_vcpu_stopped (vcpu)) -return ; +return 0 ;trace_kvm_s390_vcpu_start_stop (vcpu->vcpu_id,1 );/* Only one cpu at a time may enter/leave the STOPPED state. */
@@ -4473,7 +4475,8 @@ void kvm_s390_vcpu_start(struct kvm_vcpu *vcpu)__disable_ibs_on_all_vcpus (vcpu->kvm); }/* Let's tell the UV that we want to start again */ -kvm_s390_pv_set_cpu_state (vcpu,PV_CPU_STATE_OPR ); +if (kvm_s390_pv_cpu_is_protected (vcpu)) + r =kvm_s390_pv_set_cpu_state (vcpu,PV_CPU_STATE_OPR );kvm_s390_clear_cpuflags (vcpu,CPUSTAT_STOPPED );/* * The real PSW might have changed due to a RESTART interpreted by the
@@ -4488,16 +4491,16 @@ void kvm_s390_vcpu_start(struct kvm_vcpu *vcpu)*/ kvm_make_request (KVM_REQ_TLB_FLUSH , vcpu);spin_unlock (&vcpu->kvm->arch.start_stop_lock); -return ; +return r; } -void kvm_s390_vcpu_stop (struct kvm_vcpu *vcpu) +int kvm_s390_vcpu_stop (struct kvm_vcpu *vcpu) { -int i, online_vcpus, started_vcpus =0 ; +int i, online_vcpus, r =0 , started_vcpus =0 ;struct kvm_vcpu *started_vcpu =NULL ;if (is_vcpu_stopped (vcpu)) -return ; +return 0 ;trace_kvm_s390_vcpu_start_stop (vcpu->vcpu_id,0 );/* Only one cpu at a time may enter/leave the STOPPED state. */
@@ -4509,7 +4512,8 @@ void kvm_s390_vcpu_stop(struct kvm_vcpu *vcpu)kvm_s390_set_cpuflags (vcpu,CPUSTAT_STOPPED );/* Let's tell the UV that we successfully stopped the vcpu */ -kvm_s390_pv_set_cpu_state (vcpu,PV_CPU_STATE_STP ); +if (kvm_s390_pv_cpu_is_protected (vcpu)) + r =kvm_s390_pv_set_cpu_state (vcpu,PV_CPU_STATE_STP );__disable_ibs_on_vcpu (vcpu);for (i =0 ; i < online_vcpus; i++) {
@@ -4528,7 +4532,7 @@ void kvm_s390_vcpu_stop(struct kvm_vcpu *vcpu) }spin_unlock (&vcpu->kvm->arch.start_stop_lock); -return ; +return r; } static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
arch/s390/kvm/kvm-s390.h +2 -2
@@ -333,8 +333,8 @@ void kvm_s390_set_tod_clock(struct kvm *kvm,long kvm_arch_fault_in_page (struct kvm_vcpu *vcpu,gpa_t gpa,int writable);int kvm_s390_store_status_unloaded (struct kvm_vcpu *vcpu,unsigned long addr);int kvm_s390_vcpu_store_status (struct kvm_vcpu *vcpu,unsigned long addr); -void kvm_s390_vcpu_start (struct kvm_vcpu *vcpu); -void kvm_s390_vcpu_stop (struct kvm_vcpu *vcpu); +int kvm_s390_vcpu_start (struct kvm_vcpu *vcpu); +int kvm_s390_vcpu_stop (struct kvm_vcpu *vcpu);void kvm_s390_vcpu_block (struct kvm_vcpu *vcpu);void kvm_s390_vcpu_unblock (struct kvm_vcpu *vcpu);bool kvm_s390_vcpu_sie_inhibited (struct kvm_vcpu *vcpu);
Re: [PATCH v2 31/42] KVM: s390: protvirt: Report CPU state to Ultravisor
I could add a comment to all other users of kvm_s390_vcpu_start/stop like
/*
* no need to check the return value of vcpu_stop as it can only have
* an error for protvirt, but protvirt means user cpu state
*/
if (!kvm_s390_user_cpu_state_ctrl(vcpu->kvm))
kvm_s390_vcpu_stop(vcpu);to make clear why we do not check the return everywhere
Re: [PATCH v2 31/42] KVM: s390: protvirt: Report CPU state to Ultravisor
Quoted 11 lines · Christian Borntraeger
I could add a comment to all other users of kvm_s390_vcpu_start/stop like
/* * no need to check the return value of vcpu_stop as it can only have * an error for protvirt, but protvirt means user cpu state */ if (!kvm_s390_user_cpu_state_ctrl(vcpu->kvm)) kvm_s390_vcpu_stop(vcpu);
Quoted 2 lines
to make clear why we do not check the return everywhere
Makes sense!
Signature · 3 lines
Thanks, David / dhildenb
PATCH v2 32/42 KVM: s390: protvirt: Support cmd 5 operation state
In reply to Christian BorntraegerFrom: Janosch Frank <[email protected]>
Code 5 for the set cpu state UV call tells the UV to load a PSW from the SE header (first IPL) or from guest location 0x0 (diag 308 subcode 0/1). Also it sets the cpu into operating state afterwards, so we can start it.
--- arch/s390/include/asm/uv.h | 1 + arch/s390/kvm/kvm-s390.c | 8 ++++++++ include/uapi/linux/kvm.h | 1 + 3 files changed, 10 insertions(+)
arch/s390/include/asm/uv.h +1 -0
@@ -169,6 +169,7 @@ struct uv_cb_unp {#define PV_CPU_STATE_OPR 1#define PV_CPU_STATE_STP 2#define PV_CPU_STATE_CHKSTP 3 +#define PV_CPU_STATE_OPR_LOAD 5struct uv_cb_cpu_set_state {struct uv_cb_header header;
arch/s390/kvm/kvm-s390.c +8 -0
@@ -4656,6 +4656,14 @@ static int kvm_s390_handle_pv_vcpu(struct kvm_vcpu *vcpu, r =kvm_s390_pv_destroy_cpu (vcpu, &cmd->rc, &cmd->rrc);break ; } +case KVM_PV_VCPU_SET_IPL_PSW : { +if (!kvm_s390_pv_handle_cpu (vcpu)) +return -EINVAL ; + + r =kvm_s390_pv_set_cpu_state (vcpu,PV_CPU_STATE_OPR_LOAD , + &cmd->rc, &cmd->rrc); +break ; + }default : r = -ENOTTY ; }
include/uapi/linux/kvm.h +1 -0
@@ -1504,6 +1504,7 @@ enum pv_cmd_id {KVM_PV_VM_UNSHARE_ALL ,KVM_PV_VCPU_CREATE ,KVM_PV_VCPU_DESTROY , + KVM_PV_VCPU_SET_IPL_PSW, }; struct kvm_pv_cmd {
Signature · 1 line
2.25.0
Re: [PATCH v2 32/42] KVM: s390: protvirt: Support cmd 5 operation state
Quoted 35 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
Code 5 for the set cpu state UV call tells the UV to load a PSW from the SE header (first IPL) or from guest location
0x0(diag 308 subcode 0/1). Also it sets the cpu into operating state afterwards, so we can start it.Signed-off-by Janosch Frank <[email protected]>Reviewed-by Thomas Huth <[email protected]>Reviewed-by Cornelia Huck <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/include/asm/uv.h | 1 + arch/s390/kvm/kvm-s390.c | 8 ++++++++ include/uapi/linux/kvm.h | 1 + 3 files changed, 10 insertions(+)arch/s390/include/asm/uv.h +1
-0@@ -169,6 +169,7 @@ struct uv_cb_unp {#define PV_CPU_STATE_OPR 1#define PV_CPU_STATE_STP 2#define PV_CPU_STATE_CHKSTP 3 +#define PV_CPU_STATE_OPR_LOAD 5struct uv_cb_cpu_set_state {struct uv_cb_header header;arch/s390/kvm/kvm-s390.c +0
-0
arch/s390/kvm/kvm-s390.c static int kvm_s390_handle_pv_vcpu(struct kvm_vcpu *vcpu, · line 4664
Quoted 9 lines
arch/s390/kvm/kvm-s390.c +6
-0@@ -4656,6 +4656,14 @@ static int kvm_s390_handle_pv_vcpu(struct kvm_vcpu *vcpu, r =kvm_s390_pv_destroy_cpu (vcpu, &cmd->rc, &cmd->rrc);break ; } +case KVM_PV_VCPU_SET_IPL_PSW : { +if (!kvm_s390_pv_handle_cpu (vcpu)) +return -EINVAL ; + + r =kvm_s390_pv_set_cpu_state (vcpu,PV_CPU_STATE_OPR_LOAD , + &cmd->rc, &cmd->rrc);
Can we squeeze that into kvm_arch_vcpu_ioctl_set_mpstate() instead? The interface seems to do exactly what you want it to do.
KVM_MP_STATE_OPERATING_LOAD
Allow it only when in PV.
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v2 32/42] KVM: s390: protvirt: Support cmd 5 operation state
Quoted 49 lines · David Hildenbrand
Quoted 35 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
Code 5 for the set cpu state UV call tells the UV to load a PSW from the SE header (first IPL) or from guest location
0x0(diag 308 subcode 0/1). Also it sets the cpu into operating state afterwards, so we can start it.Signed-off-by Janosch Frank <[email protected]>Reviewed-by Thomas Huth <[email protected]>Reviewed-by Cornelia Huck <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/include/asm/uv.h | 1 + arch/s390/kvm/kvm-s390.c | 8 ++++++++ include/uapi/linux/kvm.h | 1 + 3 files changed, 10 insertions(+)arch/s390/include/asm/uv.h +1
-0@@ -169,6 +169,7 @@ struct uv_cb_unp {#define PV_CPU_STATE_OPR 1#define PV_CPU_STATE_STP 2#define PV_CPU_STATE_CHKSTP 3 +#define PV_CPU_STATE_OPR_LOAD 5struct uv_cb_cpu_set_state {struct uv_cb_header header;arch/s390/kvm/kvm-s390.c +0
-0arch/s390/kvm/kvm-s390.c static int kvm_s390_handle_pv_vcpu(struct kvm_vcpu *vcpu, · line 4664
Quoted 9 lines
arch/s390/kvm/kvm-s390.c +6
-0@@ -4656,6 +4656,14 @@ static int kvm_s390_handle_pv_vcpu(struct kvm_vcpu *vcpu, r =kvm_s390_pv_destroy_cpu (vcpu, &cmd->rc, &cmd->rrc);break ; } +case KVM_PV_VCPU_SET_IPL_PSW : { +if (!kvm_s390_pv_handle_cpu (vcpu)) +return -EINVAL ; + + r =kvm_s390_pv_set_cpu_state (vcpu,PV_CPU_STATE_OPR_LOAD , + &cmd->rc, &cmd->rrc);Can we squeeze that into
kvm_arch_vcpu_ioctl_set_mpstate()instead? The interface seems to do exactly what you want it to do.
Quoted 3 lines
KVM_MP_STATE_OPERATING_LOADAllow it only when in PV.
Ack, something like this seems to work.
arch/s390/kvm/kvm-s390.c +6 -0
@@ -3710,6 +3710,12 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,kvm_s390_vcpu_start (vcpu);break ;case KVM_MP_STATE_LOAD : +if (!kvm_s390_pv_cpu_is_protected (vcpu)) { + rc = -ENXIO ; +break ; + } +kvm_s390_pv_set_cpu_state (vcpu,PV_CPU_STATE_OPR_LOAD ); +break ;case KVM_MP_STATE_CHECK_STOP :/* fall through - CHECK_STOP and LOAD are not supported yet */ default :
Re: [PATCH v2 32/42] KVM: s390: protvirt: Support cmd 5 operation state
Quoted 67 lines · Christian Borntraeger
Quoted 49 lines · David Hildenbrand
Quoted 35 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
Code 5 for the set cpu state UV call tells the UV to load a PSW from the SE header (first IPL) or from guest location
0x0(diag 308 subcode 0/1). Also it sets the cpu into operating state afterwards, so we can start it.Signed-off-by Janosch Frank <[email protected]>Reviewed-by Thomas Huth <[email protected]>Reviewed-by Cornelia Huck <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/include/asm/uv.h | 1 + arch/s390/kvm/kvm-s390.c | 8 ++++++++ include/uapi/linux/kvm.h | 1 + 3 files changed, 10 insertions(+)arch/s390/include/asm/uv.h +1
-0@@ -169,6 +169,7 @@ struct uv_cb_unp {#define PV_CPU_STATE_OPR 1#define PV_CPU_STATE_STP 2#define PV_CPU_STATE_CHKSTP 3 +#define PV_CPU_STATE_OPR_LOAD 5struct uv_cb_cpu_set_state {struct uv_cb_header header;arch/s390/kvm/kvm-s390.c +0
-0arch/s390/kvm/kvm-s390.c static int kvm_s390_handle_pv_vcpu(struct kvm_vcpu *vcpu, · line 4664
Quoted 9 lines
arch/s390/kvm/kvm-s390.c +6
-0@@ -4656,6 +4656,14 @@ static int kvm_s390_handle_pv_vcpu(struct kvm_vcpu *vcpu, r =kvm_s390_pv_destroy_cpu (vcpu, &cmd->rc, &cmd->rrc);break ; } +case KVM_PV_VCPU_SET_IPL_PSW : { +if (!kvm_s390_pv_handle_cpu (vcpu)) +return -EINVAL ; + + r =kvm_s390_pv_set_cpu_state (vcpu,PV_CPU_STATE_OPR_LOAD , + &cmd->rc, &cmd->rrc);Can we squeeze that into
kvm_arch_vcpu_ioctl_set_mpstate()instead? The interface seems to do exactly what you want it to do.Quoted 3 lines
KVM_MP_STATE_OPERATING_LOADAllow it only when in PV.
Ack, something like this seems to work.
arch/s390/kvm/kvm-s390.c +0
-0@@ -3710,6 +3710,12 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,kvm_s390_vcpu_start (vcpu);break ;
arch/s390/kvm/kvm-s390.c int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, · line 3721
Quoted 10 lines
arch/s390/kvm/kvm-s390.c +6
-0case KVM_MP_STATE_LOAD : +if (!kvm_s390_pv_cpu_is_protected (vcpu)) { + rc = -ENXIO ; +break ; + } +kvm_s390_pv_set_cpu_state (vcpu,PV_CPU_STATE_OPR_LOAD ); +break ;case KVM_MP_STATE_CHECK_STOP :/* fall through - CHECK_STOP and LOAD are not supported yet */ default :
We might want to allow KVM_MP_STATE_LOAD always. Without PV, it's currently just a NOP. Whatever you think is best.
Signature · 3 lines
Thanks, David / dhildenb
PATCH v2 33/42 KVM: s390: protvirt: Mask PSW interrupt bits for interception 104 and 112
In reply to Christian BorntraegerFrom: Janosch Frank <[email protected]>
We're not allowed to inject interrupts on intercepts that leave the guest state in an "in-between" state where the next SIE entry will do a continuation, namely secure instruction interception (104) and secure prefix interception (112).
As our PSW is just a copy of the real one that will be replaced on the next exit, we can mask out the interrupt bits in the PSW to make sure that we do not inject anything.
--- arch/s390/kvm/kvm-s390.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
arch/s390/kvm/kvm-s390.c +11 -0
@@ -4025,6 +4025,7 @@ static int vcpu_post_run(struct kvm_vcpu *vcpu, int exit_reason)return vcpu_post_run_fault_in_sie (vcpu); } +#define PSW_INT_MASK (PSW_MASK_EXT | PSW_MASK_IO | PSW_MASK_MCHECK)static int __vcpu_run (struct kvm_vcpu *vcpu) {int rc, exit_reason;
@@ -4061,6 +4062,16 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)memcpy (vcpu->run->s.regs.gprs, sie_page->pv_grregs,sizeof (sie_page->pv_grregs)); +/* +* We're not allowed to inject interrupts on intercepts +* that leave the guest state in an "in-between" state +* where the next SIE entry will do a continuation. +* Fence interrupts in our "internal" PSW. +*/ +if (vcpu->arch.sie_block->icptcode ==ICPT_PV_INSTR || + vcpu->arch.sie_block->icptcode ==ICPT_PV_PREF ) { + vcpu->arch.sie_block->gpsw.mask &= ~PSW_INT_MASK ; + } }local_irq_disable ();__enable_cpu_timer_accounting (vcpu);
Signature · 1 line
2.25.0
Re: [PATCH v2 33/42] KVM: s390: protvirt: Mask PSW interrupt bits for interception 104 and 112
Quoted 35 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
We're not allowed to inject interrupts on intercepts that leave the guest state in an "in-between" state where the next SIE entry will do a continuation, namely secure instruction interception (104) and secure prefix interception (112).
As our PSW is just a copy of the real one that will be replaced on the next exit, we can mask out the interrupt bits in the PSW to make sure that we do not inject anything.Signed-off-by Janosch Frank <[email protected]>Reviewed-by Thomas Huth <[email protected]>Reviewed-by Cornelia Huck <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/kvm/kvm-s390.c | 11 +++++++++++ 1 file changed, 11 insertions(+)arch/s390/kvm/kvm-s390.c +1
-0@@ -4025,6 +4025,7 @@ static int vcpu_post_run(struct kvm_vcpu *vcpu, int exit_reason)return vcpu_post_run_fault_in_sie (vcpu); } +#define PSW_INT_MASK (PSW_MASK_EXT | PSW_MASK_IO | PSW_MASK_MCHECK)static int __vcpu_run (struct kvm_vcpu *vcpu) {int rc, exit_reason;@@ -4061,6 +4062,16 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)memcpy (vcpu->run->s.regs.gprs, sie_page->pv_grregs,sizeof (sie_page->pv_grregs));
arch/s390/kvm/kvm-s390.c static int __vcpu_run(struct kvm_vcpu *vcpu) · line 4074
Quoted 10 lines
arch/s390/kvm/kvm-s390.c +10
-0+/* +* We're not allowed to inject interrupts on intercepts +* that leave the guest state in an "in-between" state +* where the next SIE entry will do a continuation. +* Fence interrupts in our "internal" PSW. +*/ +if (vcpu->arch.sie_block->icptcode ==ICPT_PV_INSTR || + vcpu->arch.sie_block->icptcode ==ICPT_PV_PREF ) { + vcpu->arch.sie_block->gpsw.mask &= ~PSW_INT_MASK ; + }
Is this actually the right approach? I mean, you lose PSW masks, but you only want to teach the interrupt delivery code to skip delivering interrupts until the intercept has been handled. Does not look clean to me TBH.
Signature · 3 lines
Thanks, David / dhildenb
David Hildenbrand
Reviewed-byRe: [PATCH v2 33/42] KVM: s390: protvirt: Mask PSW interrupt bits for interception 104 and 112
Quoted 43 lines · David Hildenbrand
Quoted 42 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
We're not allowed to inject interrupts on intercepts that leave the guest state in an "in-between" state where the next SIE entry will do a continuation, namely secure instruction interception (104) and secure prefix interception (112).
As our PSW is just a copy of the real one that will be replaced on the next exit, we can mask out the interrupt bits in the PSW to make sure that we do not inject anything.Signed-off-by Janosch Frank <[email protected]>Reviewed-by Thomas Huth <[email protected]>Reviewed-by Cornelia Huck <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/kvm/kvm-s390.c | 11 +++++++++++ 1 file changed, 11 insertions(+)arch/s390/kvm/kvm-s390.c +8
-0@@ -4025,6 +4025,7 @@ static int vcpu_post_run(struct kvm_vcpu *vcpu, int exit_reason)return vcpu_post_run_fault_in_sie (vcpu); } +#define PSW_INT_MASK (PSW_MASK_EXT | PSW_MASK_IO | PSW_MASK_MCHECK)static int __vcpu_run (struct kvm_vcpu *vcpu) {int rc, exit_reason;@@ -4061,6 +4062,16 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)memcpy (vcpu->run->s.regs.gprs, sie_page->pv_grregs,sizeof (sie_page->pv_grregs)); +/* +* We're not allowed to inject interrupts on intercepts +* that leave the guest state in an "in-between" state +* where the next SIE entry will do a continuation. +* Fence interrupts in our "internal" PSW. +*/ + if (vcpu->arch.sie_block->icptcode == ICPT_PV_INSTR ||
Quoted 8 lines
arch/s390/kvm/kvm-s390.c static int __vcpu_run(struct kvm_vcpu *vcpu) · line 4074
Quoted 3 lines
arch/s390/kvm/kvm-s390.c +3
-0+ vcpu->arch.sie_block->icptcode == ICPT_PV_PREF) { + vcpu->arch.sie_block->gpsw.mask &= ~PSW_INT_MASK ; + }Is this actually the right approach? I mean, you lose PSW masks, but you only want to teach the interrupt delivery code to skip delivering interrupts until the intercept has been handled. Does not look clean to me TBH.
After reading the patch description again :)
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v2 33/42] KVM: s390: protvirt: Mask PSW interrupt bits for interception 104 and 112
In reply to David HildenbrandQuoted 43 lines · David Hildenbrand
Quoted 42 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
We're not allowed to inject interrupts on intercepts that leave the guest state in an "in-between" state where the next SIE entry will do a continuation, namely secure instruction interception (104) and secure prefix interception (112).
As our PSW is just a copy of the real one that will be replaced on the next exit, we can mask out the interrupt bits in the PSW to make sure that we do not inject anything.Signed-off-by Janosch Frank <[email protected]>Reviewed-by Thomas Huth <[email protected]>Reviewed-by Cornelia Huck <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/kvm/kvm-s390.c | 11 +++++++++++ 1 file changed, 11 insertions(+)arch/s390/kvm/kvm-s390.c +8
-0@@ -4025,6 +4025,7 @@ static int vcpu_post_run(struct kvm_vcpu *vcpu, int exit_reason)return vcpu_post_run_fault_in_sie (vcpu); } +#define PSW_INT_MASK (PSW_MASK_EXT | PSW_MASK_IO | PSW_MASK_MCHECK)static int __vcpu_run (struct kvm_vcpu *vcpu) {int rc, exit_reason;@@ -4061,6 +4062,16 @@ static int __vcpu_run(struct kvm_vcpu *vcpu)memcpy (vcpu->run->s.regs.gprs, sie_page->pv_grregs,sizeof (sie_page->pv_grregs)); +/* +* We're not allowed to inject interrupts on intercepts +* that leave the guest state in an "in-between" state +* where the next SIE entry will do a continuation. +* Fence interrupts in our "internal" PSW. +*/ + if (vcpu->arch.sie_block->icptcode == ICPT_PV_INSTR ||
Quoted 8 lines
arch/s390/kvm/kvm-s390.c static int __vcpu_run(struct kvm_vcpu *vcpu) · line 4074
Quoted 3 lines
arch/s390/kvm/kvm-s390.c +3
-0+ vcpu->arch.sie_block->icptcode == ICPT_PV_PREF) { + vcpu->arch.sie_block->gpsw.mask &= ~PSW_INT_MASK ; + }Is this actually the right approach? I mean, you lose PSW masks, but you only want to teach the interrupt delivery code to skip delivering interrupts until the intercept has been handled. Does not look clean to me TBH.
The only purpose of the PSW mask in PV is to tell the hypervisor what interrupts are deliverable or if we are in wait state. In fact those bits are the only ones that we see. So I think its fair to use those.
PATCH v2 34/42 KVM: s390: protvirt: do not inject interrupts after start
In reply to Christian BorntraegerAs PSW restart is handled by the ultravisor (and we only get a start notification) we must re-check the PSW after a start before injecting interrupts.
--- arch/s390/kvm/kvm-s390.c | 7 +++++++ 1 file changed, 7 insertions(+)
arch/s390/kvm/kvm-s390.c +7 -0
@@ -4436,6 +4436,13 @@ void kvm_s390_vcpu_start(struct kvm_vcpu *vcpu)/* Let's tell the UV that we want to start again */ kvm_s390_pv_set_cpu_state (vcpu,PV_CPU_STATE_OPR , &rc, &rrc);kvm_s390_clear_cpuflags (vcpu,CPUSTAT_STOPPED ); +/* +* The real PSW might have changed due to a RESTART interpreted by the +* ultravisor. We block all interrupts and let the next sie exit +* refresh our view. +*/ +if (kvm_s390_pv_is_protected (vcpu->kvm)) + vcpu->arch.sie_block->gpsw.mask &= ~PSW_INT_MASK ;/* * Another VCPU might have used IBS while we were offline. * Let's play safe and flush the VCPU at startup.
Signature · 1 line
2.25.0
Re: [PATCH v2 34/42] KVM: s390: protvirt: do not inject interrupts after start
Quoted 16 lines · Christian Borntraeger
As PSW restart is handled by the ultravisor (and we only get a start notification) we must re-check the PSW after a start before injecting interrupts.
Signed-off-by Christian Borntraeger <[email protected]>Reviewed-by Cornelia Huck <[email protected]>Reviewed-by Thomas Huth <[email protected]>--- arch/s390/kvm/kvm-s390.c | 7 +++++++ 1 file changed, 7 insertions(+)arch/s390/kvm/kvm-s390.c +0
-0
arch/s390/kvm/kvm-s390.c void kvm_s390_vcpu_start(struct kvm_vcpu *vcpu) · line 4445
Quoted 10 lines
arch/s390/kvm/kvm-s390.c +7
-0@@ -4436,6 +4436,13 @@ void kvm_s390_vcpu_start(struct kvm_vcpu *vcpu)/* Let's tell the UV that we want to start again */ kvm_s390_pv_set_cpu_state (vcpu,PV_CPU_STATE_OPR , &rc, &rrc);kvm_s390_clear_cpuflags (vcpu,CPUSTAT_STOPPED ); +/* +* The real PSW might have changed due to a RESTART interpreted by the +* ultravisor. We block all interrupts and let the next sie exit +* refresh our view. +*/ +if (kvm_s390_pv_is_protected (vcpu->kvm)) + vcpu->arch.sie_block->gpsw.mask &= ~PSW_INT_MASK ;
Same comment as to the previous patch.
Signature · 3 lines
Thanks, David / dhildenb
David Hildenbrand
Reviewed-byRe: [PATCH v2 34/42] KVM: s390: protvirt: do not inject interrupts after start
Quoted 21 lines · David Hildenbrand
Quoted 20 lines · Christian Borntraeger
As PSW restart is handled by the ultravisor (and we only get a start notification) we must re-check the PSW after a start before injecting interrupts.
Signed-off-by Christian Borntraeger <[email protected]>Reviewed-by Cornelia Huck <[email protected]>Reviewed-by Thomas Huth <[email protected]>--- arch/s390/kvm/kvm-s390.c | 7 +++++++ 1 file changed, 7 insertions(+)arch/s390/kvm/kvm-s390.c +1
-0@@ -4436,6 +4436,13 @@ void kvm_s390_vcpu_start(struct kvm_vcpu *vcpu)/* Let's tell the UV that we want to start again */ kvm_s390_pv_set_cpu_state (vcpu,PV_CPU_STATE_OPR , &rc, &rrc);kvm_s390_clear_cpuflags (vcpu,CPUSTAT_STOPPED ); +/*
Quoted 8 lines
arch/s390/kvm/kvm-s390.c void kvm_s390_vcpu_start(struct kvm_vcpu *vcpu) · line 4445
Quoted 6 lines
arch/s390/kvm/kvm-s390.c +6
-0+* The real PSW might have changed due to a RESTART interpreted by the +* ultravisor. We block all interrupts and let the next sie exit +* refresh our view. +*/ +if (kvm_s390_pv_is_protected (vcpu->kvm)) + vcpu->arch.sie_block->gpsw.mask &= ~PSW_INT_MASK ;Same comment as to the previous patch.
As I understood how it works
Signature · 3 lines
Thanks, David / dhildenb
PATCH v2 35/42 KVM: s390: protvirt: Add UV cpu reset calls
In reply to Christian BorntraegerFrom: Janosch Frank <[email protected]>
For protected VMs, the VCPU resets are done by the Ultravisor, as KVM has no access to the VCPU registers.
Note that the ultravisor will only accept a call for the exact reset that has been requested.
--- arch/s390/include/asm/uv.h | 6 ++++++ arch/s390/kvm/kvm-s390.c | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+)
arch/s390/include/asm/uv.h +6 -0
@@ -36,7 +36,10 @@#define UVC_CMD_SET_SEC_CONF_PARAMS 0x0300#define UVC_CMD_UNPACK_IMG 0x0301#define UVC_CMD_VERIFY_IMG 0x0302 +#define UVC_CMD_CPU_RESET 0x0310 +#define UVC_CMD_CPU_RESET_INITIAL 0x0311#define UVC_CMD_PREPARE_RESET 0x0320 +#define UVC_CMD_CPU_RESET_CLEAR 0x0321#define UVC_CMD_CPU_SET_STATE 0x0330#define UVC_CMD_SET_UNSHARE_ALL 0x0340#define UVC_CMD_PIN_PAGE_SHARED 0x0341
@@ -59,8 +62,11 @@ enum uv_cmds_inst {BIT_UVC_CMD_SET_SEC_PARMS =11 ,BIT_UVC_CMD_UNPACK_IMG =13 ,BIT_UVC_CMD_VERIFY_IMG =14 , +BIT_UVC_CMD_CPU_RESET =15 , +BIT_UVC_CMD_CPU_RESET_INITIAL =16 ,BIT_UVC_CMD_CPU_SET_STATE =17 ,BIT_UVC_CMD_PREPARE_RESET =18 , +BIT_UVC_CMD_CPU_PERFORM_CLEAR_RESET =19 ,BIT_UVC_CMD_UNSHARE_ALL =20 ,BIT_UVC_CMD_PIN_PAGE_SHARED =21 , BIT_UVC_CMD_UNPIN_PAGE_SHARED = 22,
arch/s390/kvm/kvm-s390.c +20 -0
@@ -4695,6 +4695,7 @@ long kvm_arch_vcpu_ioctl(struct file *filp,void __user *argp = (void __user *)arg;int idx;long r; +u16 rc, rrc;vcpu_load (vcpu);
@@ -4716,14 +4717,33 @@ long kvm_arch_vcpu_ioctl(struct file *filp,case KVM_S390_CLEAR_RESET : r =0 ;kvm_arch_vcpu_ioctl_clear_reset (vcpu); +if (kvm_s390_pv_handle_cpu (vcpu)) { + r =uv_cmd_nodata (kvm_s390_pv_handle_cpu (vcpu), +UVC_CMD_CPU_RESET_CLEAR , &rc, &rrc); +VCPU_EVENT (vcpu,3 ,"PROTVIRT RESET CLEAR VCPU: rc %x rrc %x" , + rc, rrc); + }break ;case KVM_S390_INITIAL_RESET : r =0 ;kvm_arch_vcpu_ioctl_initial_reset (vcpu); +if (kvm_s390_pv_handle_cpu (vcpu)) { + r =uv_cmd_nodata (kvm_s390_pv_handle_cpu (vcpu), +UVC_CMD_CPU_RESET_INITIAL , + &rc, &rrc); +VCPU_EVENT (vcpu,3 ,"PROTVIRT RESET INITIAL VCPU: rc %x rrc %x" , + rc, rrc); + }break ;case KVM_S390_NORMAL_RESET : r =0 ;kvm_arch_vcpu_ioctl_normal_reset (vcpu); +if (kvm_s390_pv_handle_cpu (vcpu)) { + r =uv_cmd_nodata (kvm_s390_pv_handle_cpu (vcpu), +UVC_CMD_CPU_RESET , &rc, &rrc); +VCPU_EVENT (vcpu,3 ,"PROTVIRT RESET NORMAL VCPU: rc %x rrc %x" , + rc, rrc); + }break ;case KVM_SET_ONE_REG :case KVM_GET_ONE_REG : {
Signature · 1 line
2.25.0
Re: [PATCH v2 35/42] KVM: s390: protvirt: Add UV cpu reset calls
Quoted 59 lines · Christian Borntraeger
From: Janosch Frank <[email protected]>
For protected VMs, the VCPU resets are done by the Ultravisor, as KVM has no access to the VCPU registers.
Note that the ultravisor will only accept a call for the exact reset that has been requested.
Signed-off-by Janosch Frank <[email protected]>Reviewed-by Thomas Huth <[email protected]>Reviewed-by David Hildenbrand <[email protected]>Reviewed-by Cornelia Huck <[email protected]>[[email protected]: patch merging, splitting, fixing]Signed-off-by Christian Borntraeger <[email protected]>--- arch/s390/include/asm/uv.h | 6 ++++++ arch/s390/kvm/kvm-s390.c | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+)arch/s390/include/asm/uv.h +6
-0@@ -36,7 +36,10 @@#define UVC_CMD_SET_SEC_CONF_PARAMS 0x0300#define UVC_CMD_UNPACK_IMG 0x0301#define UVC_CMD_VERIFY_IMG 0x0302 +#define UVC_CMD_CPU_RESET 0x0310 +#define UVC_CMD_CPU_RESET_INITIAL 0x0311#define UVC_CMD_PREPARE_RESET 0x0320 +#define UVC_CMD_CPU_RESET_CLEAR 0x0321#define UVC_CMD_CPU_SET_STATE 0x0330#define UVC_CMD_SET_UNSHARE_ALL 0x0340#define UVC_CMD_PIN_PAGE_SHARED 0x0341@@ -59,8 +62,11 @@ enum uv_cmds_inst {BIT_UVC_CMD_SET_SEC_PARMS =11 ,BIT_UVC_CMD_UNPACK_IMG =13 ,BIT_UVC_CMD_VERIFY_IMG =14 , +BIT_UVC_CMD_CPU_RESET =15 , +BIT_UVC_CMD_CPU_RESET_INITIAL =16 ,BIT_UVC_CMD_CPU_SET_STATE =17 ,BIT_UVC_CMD_PREPARE_RESET =18 , +BIT_UVC_CMD_CPU_PERFORM_CLEAR_RESET =19 ,BIT_UVC_CMD_UNSHARE_ALL =20 ,BIT_UVC_CMD_PIN_PAGE_SHARED =21 , BIT_UVC_CMD_UNPIN_PAGE_SHARED = 22,arch/s390/kvm/kvm-s390.c +1
-0@@ -4695,6 +4695,7 @@ long kvm_arch_vcpu_ioctl(struct file *filp,void __user *argp = (void __user *)arg;int idx;long r; +u16 rc, rrc;vcpu_load (vcpu);
arch/s390/kvm/kvm-s390.c long kvm_arch_vcpu_ioctl(struct file *filp, · line 4720
Quoted 4 lines
arch/s390/kvm/kvm-s390.c +1
-0@@ -4716,14 +4717,33 @@ long kvm_arch_vcpu_ioctl(struct file *filp,case KVM_S390_CLEAR_RESET : r =0 ;kvm_arch_vcpu_ioctl_clear_reset (vcpu); +if (kvm_s390_pv_handle_cpu (vcpu)) {
_protected checks please. (if not already converted in your tree :) )
Signature · 3 lines
Thanks, David / dhildenb
PATCH v2 36/42 DOCUMENTATION: Protected virtual machine introduction and IPL
In reply to Christian BorntraegerFrom: Janosch Frank <[email protected]>
Add documentation about protected KVM guests and description of changes that are necessary to move a KVM VM into Protected Virtualization mode.
--- Documentation/virt/kvm/index.rst | 2 + Documentation/virt/kvm/s390-pv-boot.rst | 83 +++++++++++++++++ Documentation/virt/kvm/s390-pv.rst | 116 ++++++++++++++++++++++++ MAINTAINERS | 1 + 4 files changed, 202 insertions(+) create mode 100644 Documentation/virt/kvm/s390-pv-boot.rst create mode 100644 Documentation/virt/kvm/s390-pv.rst
Documentation/virt/kvm/index.rst +2 -0
@@ -18,6 +18,8 @@ KVM nested-vmx ppc-pv s390-diag + s390-pv + s390-pv-boot timekeeping vcpu-requests
Documentation/virt/kvm/s390-pv-boot.rst new file +83 -0
83 lines not on this page · raw message
Documentation/virt/kvm/s390-pv.rst new file +116 -0
116 lines not on this page · raw message
MAINTAINERS +1 -0
@@ -9209,6 +9209,7 @@ L: [email protected] W: http://www.ibm.com/developerworks/linux/linux390/ T: git git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git S: Supported +F: Documentation/virt/kvm/s390* F: arch/s390/include/uapi/asm/kvm* F: arch/s390/include/asm/gmap.h F: arch/s390/include/asm/kvm*
Signature · 1 line
2.25.0
PATCH v2 37/42 s390/uv: Fix handling of length extensions (already in s390 tree)
In reply to Christian BorntraegerThe query parameter block might contain additional information and can be extended in the future. If the size of the block does not suffice we get an error code of rc=0x100. The buffer will contain all information up to the specified size and the hypervisor/guest simply do not need the additional information as they do not know about the new data. That means that we can (and must) accept rc=0x100 as success.
--- arch/s390/boot/uv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/boot/uv.c +1 -1
@@ -21,7 +21,7 @@ void uv_query_info(void)if (!test_facility (158 ))return ; -if (uv_call (0 , (uint64_t )&uvcb)) +if (uv_call (0 , (uint64_t )&uvcb) && uvcb.header.rc !=0x100 )return ;if (IS_ENABLED (CONFIG_KVM )) {
Signature · 1 line
2.25.0
PATCH v2 38/42 s390: protvirt: Add sysfs firmware interface for Ultravisor information
In reply to Christian BorntraegerFrom: Janosch Frank <[email protected]>
That information, e.g. the maximum number of guests or installed Ultravisor facilities, is interesting for QEMU, Libvirt and administrators.
Let's provide an easily parsable API to get that information.
--- arch/s390/kernel/uv.c | 86 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+)
arch/s390/kernel/uv.c +86 -0
@@ -322,5 +322,91 @@ int arch_make_page_accessible(struct page *page)return rc; }EXPORT_SYMBOL_GPL (arch_make_page_accessible); +#endif + +#if defined(CONFIG_PROTECTED_VIRTUALIZATION_GUEST ) ||IS_ENABLED (CONFIG_KVM ) +static ssize_t uv_query_facilities (struct kobject *kobj, +struct kobj_attribute *attr,char *page) +{ +return snprintf (page,PAGE_SIZE ,"%lx\n%lx\n%lx\n%lx\n" , + uv_info.inst_calls_list[0 ], + uv_info.inst_calls_list[1 ], + uv_info.inst_calls_list[2 ], + uv_info.inst_calls_list[3 ]); +} + +static struct kobj_attribute uv_query_facilities_attr = +__ATTR (facilities,0444 , uv_query_facilities,NULL ); + +static ssize_t uv_query_max_guest_cpus (struct kobject *kobj, +struct kobj_attribute *attr,char *page) +{ +return snprintf (page,PAGE_SIZE ,"%d\n" , + uv_info.max_guest_cpus); +} + +static struct kobj_attribute uv_query_max_guest_cpus_attr = +__ATTR (max_cpus,0444 , uv_query_max_guest_cpus,NULL ); + +static ssize_t uv_query_max_guest_vms (struct kobject *kobj, +struct kobj_attribute *attr,char *page) +{ +return snprintf (page,PAGE_SIZE ,"%d\n" , + uv_info.max_num_sec_conf); +} + +static struct kobj_attribute uv_query_max_guest_vms_attr = +__ATTR (max_guests,0444 , uv_query_max_guest_vms,NULL ); + +static ssize_t uv_query_max_guest_addr (struct kobject *kobj, +struct kobj_attribute *attr,char *page) +{ +return snprintf (page,PAGE_SIZE ,"%lx\n" , + uv_info.max_sec_stor_addr); +} + +static struct kobj_attribute uv_query_max_guest_addr_attr = +__ATTR (max_address,0444 , uv_query_max_guest_addr,NULL ); + +static struct attribute *uv_query_attrs[] = { + &uv_query_facilities_attr.attr, + &uv_query_max_guest_cpus_attr.attr, + &uv_query_max_guest_vms_attr.attr, + &uv_query_max_guest_addr_attr.attr, +NULL , +}; + +static struct attribute_group uv_query_attr_group = { + .attrs = uv_query_attrs, +}; +static struct kset *uv_query_kset; +struct kobject *uv_kobj; + +static int __init uv_info_init (void ) +{ +int rc = -ENOMEM ; + +if (!test_facility (158 )) +return 0 ; + + uv_kobj =kobject_create_and_add ("uv" , firmware_kobj); +if (!uv_kobj) +return -ENOMEM ; + + uv_query_kset =kset_create_and_add ("query" ,NULL , uv_kobj); +if (!uv_query_kset) + goto out_kobj; + + rc =sysfs_create_group (&uv_query_kset->kobj, &uv_query_attr_group); +if (!rc) +return 0 ; + +kset_unregister (uv_query_kset); +out_kobj: +kobject_del (uv_kobj); +kobject_put (uv_kobj); +return rc; +} +device_initcall (uv_info_init);#endif
Signature · 1 line
2.25.0
PATCH v2 39/42 example for future extension: mm:gup/writeback: add callbacks for inaccessible pages: error cases
In reply to Christian BorntraegerFrom: Claudio Imbrenda <[email protected]>
This is a potential extension to do error handling if we fail to make the page accessible if we know what others need.
--- mm/gup.c | 17 ++++++++++++----- mm/page-writeback.c | 6 +++++- 2 files changed, 17 insertions(+), 6 deletions(-)
mm/gup.c +12 -5
@@ -193,6 +193,7 @@ static struct page *follow_page_pte(struct vm_area_struct *vma,struct page *page;spinlock_t *ptl;pte_t *ptep, pte; +int ret;/* FOLL_GET and FOLL_PIN are mutually exclusive. */ if (WARN_ON_ONCE((flags & (FOLL_PIN | FOLL_GET)) ==
@@ -250,8 +251,6 @@ static struct page *follow_page_pte(struct vm_area_struct *vma,if (is_zero_pfn (pte_pfn (pte))) { page =pte_page (pte); }else { -int ret; - ret =follow_pfn_pte (vma, address, ptep, flags); page =ERR_PTR (ret); goto out;
@@ -259,7 +258,6 @@ static struct page *follow_page_pte(struct vm_area_struct *vma, }if (flags &FOLL_SPLIT &&PageTransCompound (page)) { -int ret;get_page (page);pte_unmap_unlock (ptep, ptl);lock_page (page);
@@ -276,7 +274,12 @@ static struct page *follow_page_pte(struct vm_area_struct *vma, page =ERR_PTR (-ENOMEM ); goto out; } -arch_make_page_accessible (page); + ret =arch_make_page_accessible (page); +if (ret) { +put_page (page); + page =ERR_PTR (ret); + goto out; + } }if (flags &FOLL_TOUCH ) { if ((flags & FOLL_WRITE) &&
@@ -1920,7 +1923,11 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end,VM_BUG_ON_PAGE (compound_head (page) != head, page); -arch_make_page_accessible (page); + ret =arch_make_page_accessible (page); +if (ret) { +put_page (head); + goto pte_unmap; + }SetPageReferenced (page); pages[*nr] = page; (*nr)++;
mm/page-writeback.c +5 -1
@@ -2807,7 +2807,11 @@ int __test_set_page_writeback(struct page *page, bool keep_write)inc_zone_page_state (page,NR_ZONE_WRITE_PENDING ); }unlock_page_memcg (page); -arch_make_page_accessible (page); +/* +* If writeback has been triggered on a page that cannot be made +* accessible, it is too late. +*/ +WARN_ON (arch_make_page_accessible (page));return ret; }
Signature · 1 line
2.25.0
Re: [PATCH v2 39/42] example for future extension: mm:gup/writeback: add callbacks for inaccessible pages: error cases
Quoted 10 lines · Christian Borntraeger
From: Claudio Imbrenda <[email protected]>
This is a potential extension to do error handling if we fail to make the page accessible if we know what others need.
Signed-off-by Claudio Imbrenda <[email protected]>--- mm/gup.c | 17 ++++++++++++----- mm/page-writeback.c | 6 +++++- 2 files changed, 17 insertions(+), 6 deletions(-)
Sorry, I missed this when replying elsewhere in the thread! Anyway, looks good to me:
Thanks,
Will
Re: [PATCH v2 39/42] example for future extension: mm:gup/writeback: add callbacks for inaccessible pages: error cases
Quoted 12 lines · Will Deacon
Quoted 10 lines · Christian Borntraeger
From: Claudio Imbrenda <[email protected]>
This is a potential extension to do error handling if we fail to make the page accessible if we know what others need.
Signed-off-by Claudio Imbrenda <[email protected]>--- mm/gup.c | 17 ++++++++++++----- mm/page-writeback.c | 6 +++++- 2 files changed, 17 insertions(+), 6 deletions(-)
Quoted 4 lines
Sorry, I missed this when replying elsewhere in the thread! Anyway, looks good to me:
Acked-by Will Deacon <[email protected]>
I can use that for a combined patch (this one merged into the first) ? Correct?
Re: [PATCH v2 39/42] example for future extension: mm:gup/writeback: add callbacks for inaccessible pages: error cases
Quoted 13 lines · Christian Borntraeger
Quoted 12 lines · Will Deacon
Quoted 10 lines · Christian Borntraeger
From: Claudio Imbrenda <[email protected]>
This is a potential extension to do error handling if we fail to make the page accessible if we know what others need.
Signed-off-by Claudio Imbrenda <[email protected]>--- mm/gup.c | 17 ++++++++++++----- mm/page-writeback.c | 6 +++++- 2 files changed, 17 insertions(+), 6 deletions(-)
Quoted 6 lines
Quoted 4 lines
Sorry, I missed this when replying elsewhere in the thread! Anyway, looks good to me:
Acked-by Will Deacon <[email protected]>I can use that for a combined patch (this one merged into the first) ? Correct?
Fine by me!
Will
PATCH v2 40/42 example for future extension: mm:gup/writeback: add callbacks for inaccessible pages: source indication
In reply to Christian BorntraegerFrom: Claudio Imbrenda <[email protected]>
We might want to do different things depending on where we are coming from.
--- include/linux/gfp.h | 8 +++++++- mm/gup.c | 4 ++-- mm/page-writeback.c | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-)
include/linux/gfp.h +7 -1
@@ -485,8 +485,14 @@ static inline void arch_free_page(struct page *page, int order) { }#ifndef HAVE_ARCH_ALLOC_PAGE static inline void arch_alloc_page (struct page *page,int order) { }#endif +enum access_type { +MAKE_ACCESSIBLE_GENERIC , +MAKE_ACCESSIBLE_GET , +MAKE_ACCESSIBLE_GET_FAST , +MAKE_ACCESSIBLE_WRITEBACK +};#ifndef HAVE_ARCH_MAKE_PAGE_ACCESSIBLE -static inline int arch_make_page_accessible (struct page *page) +static inline int arch_make_page_accessible (struct page *page,int where) {return 0 ; }
mm/gup.c +2 -2
@@ -274,7 +274,7 @@ static struct page *follow_page_pte(struct vm_area_struct *vma, page =ERR_PTR (-ENOMEM ); goto out; } - ret =arch_make_page_accessible (page); + ret =arch_make_page_accessible (page,MAKE_ACCESSIBLE_GET );if (ret) {put_page (page); page =ERR_PTR (ret);
@@ -1923,7 +1923,7 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end,VM_BUG_ON_PAGE (compound_head (page) != head, page); - ret =arch_make_page_accessible (page); + ret =arch_make_page_accessible (page,MAKE_ACCESSIBLE_GET_FAST );if (ret) {put_page (head); goto pte_unmap;
mm/page-writeback.c +1 -1
@@ -2811,7 +2811,7 @@ int __test_set_page_writeback(struct page *page, bool keep_write)* If writeback has been triggered on a page that cannot be made * accessible, it is too late. */ -WARN_ON (arch_make_page_accessible (page)); +WARN_ON (arch_make_page_accessible (page,MAKE_ACCESSIBLE_WRITEBACK ));return ret; }
Signature · 1 line
2.25.0
Re: [PATCH v2 40/42] example for future extension: mm:gup/writeback: add callbacks for inaccessible pages: source indication
include/linux/gfp.h static inline void arch_free_page(struct page *page, int order) { } · line 495
Quoted 9 lines · Christian Borntraeger
include/linux/gfp.h +7
-1+enum access_type { +MAKE_ACCESSIBLE_GENERIC , +MAKE_ACCESSIBLE_GET , +MAKE_ACCESSIBLE_GET_FAST , +MAKE_ACCESSIBLE_WRITEBACK +};#ifndef HAVE_ARCH_MAKE_PAGE_ACCESSIBLE -static inline int arch_make_page_accessible (struct page *page) +static inline int arch_make_page_accessible (struct page *page,int where)
If we want to make this distinction, wouldn't it be simpler to just use different function names, like
arch_make_page_accessible_for_writeback arch_make_page_accessible_for_gup
etc.
Bye,
Ulrich
Signature · 3 lines
Dr. Ulrich Weigand GNU/Linux compilers and toolchain [email protected]
Re: [PATCH v2 40/42] example for future extension: mm:gup/writeback: add callbacks for inaccessible pages: source indication
Quoted 16 lines · Ulrich Weigand
include/linux/gfp.h static inline void arch_free_page(struct page *page, int order) { } · line 495
Quoted 9 lines · Christian Borntraeger
include/linux/gfp.h +7
-1+enum access_type { +MAKE_ACCESSIBLE_GENERIC , +MAKE_ACCESSIBLE_GET , +MAKE_ACCESSIBLE_GET_FAST , +MAKE_ACCESSIBLE_WRITEBACK +};#ifndef HAVE_ARCH_MAKE_PAGE_ACCESSIBLE -static inline int arch_make_page_accessible (struct page *page) +static inline int arch_make_page_accessible (struct page *page,int where)If we want to make this distinction, wouldn't it be simpler to just use different function names, like
arch_make_page_accessible_for_writebackarch_make_page_accessible_for_gup
etc.
Agreed.
I would suggest to do these changes when somebody needs them, though. On the other hand, Patch 39 (the error handling) is something that we could merge now.
PATCH v2 41/42 potential fixup for "s390/mm: provide memory management functions for protected KVM guests"
In reply to Christian BorntraegerFrom: Claudio Imbrenda <[email protected]>
Needed when "example for future extension: mm:gup/writeback: add callbacks for inaccessible pages: source indication" is applied.
--- arch/s390/include/asm/page.h | 2 +- arch/s390/kernel/uv.c | 2 +- arch/s390/mm/fault.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
arch/s390/include/asm/page.h +1 -1
@@ -154,7 +154,7 @@ static inline int devmem_is_allowed(unsigned long pfn)#define HAVE_ARCH_ALLOC_PAGE #if IS_ENABLED (CONFIG_PGSTE ) -int arch_make_page_accessible (struct page *page); +int arch_make_page_accessible (struct page *page,int where);#define HAVE_ARCH_MAKE_PAGE_ACCESSIBLE #endif
arch/s390/kernel/uv.c +1 -1
@@ -287,7 +287,7 @@ EXPORT_SYMBOL_GPL(gmap_convert_to_secure);/** * To be called with the page locked or with an extra reference! */ -int arch_make_page_accessible (struct page *page) +int arch_make_page_accessible (struct page *page,int where) {int rc =0 ;
arch/s390/mm/fault.c +2 -2
@@ -842,7 +842,7 @@ void do_secure_storage_access(struct pt_regs *regs)up_read (&mm->mmap_sem);break ; } -if (arch_make_page_accessible (page)) +if (arch_make_page_accessible (page,MAKE_ACCESSIBLE_GENERIC ))send_sig (SIGSEGV , current,0 );put_page (page);up_read (&mm->mmap_sem);
@@ -851,7 +851,7 @@ void do_secure_storage_access(struct pt_regs *regs) page =phys_to_page (addr);if (unlikely (!try_get_page (page)))break ; - rc =arch_make_page_accessible (page); + rc =arch_make_page_accessible (page,MAKE_ACCESSIBLE_GENERIC );put_page (page);if (rc)BUG ();
Signature · 1 line
2.25.0
PATCH v2 42/42 KVM: s390: rstify new ioctls in api.rst
In reply to Christian BorntraegerWe also need to rstify the new ioctls that we added in parallel to the rstification of the kvm docs.
--- Documentation/virt/kvm/api.rst | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-)
Documentation/virt/kvm/api.rst +18 -15
@@ -4613,35 +4613,38 @@ unpins the VPA pages and releases all the device pages that are used to track the secure pages by hypervisor. 4.122 KVM_S390_NORMAL_RESET +--------------------------- -Capability: KVM_CAP_S390_VCPU_RESETS -Architectures: s390 -Type: vcpu ioctl -Parameters: none -Returns: 0 +:Capability: KVM_CAP_S390_VCPU_RESETS +:Architectures: s390 +:Type: vcpu ioctl +:Parameters: none +:Returns: 0 This ioctl resets VCPU registers and control structures according to the cpu reset definition in the POP (Principles Of Operation). 4.123 KVM_S390_INITIAL_RESET +---------------------------- -Capability: none -Architectures: s390 -Type: vcpu ioctl -Parameters: none -Returns: 0 +:Capability: none +:Architectures: s390 +:Type: vcpu ioctl +:Parameters: none +:Returns: 0 This ioctl resets VCPU registers and control structures according to the initial cpu reset definition in the POP. However, the cpu is not put into ESA mode. This reset is a superset of the normal reset. 4.124 KVM_S390_CLEAR_RESET +-------------------------- -Capability: KVM_CAP_S390_VCPU_RESETS -Architectures: s390 -Type: vcpu ioctl -Parameters: none -Returns: 0 +:Capability: KVM_CAP_S390_VCPU_RESETS +:Architectures: s390 +:Type: vcpu ioctl +:Parameters: none +:Returns: 0 This ioctl resets VCPU registers and control structures according to the clear cpu reset definition in the POP. However, the cpu is not put
Signature · 1 line
2.25.0