Skip to content

Commit d6c8097

Browse files
author
Claudio Imbrenda
committed
KVM: s390: Simplify and move pv code
All functions in kvm/gmap.c fit better in kvm/pv.c instead. Move and rename them appropriately, then delete the now empty kvm/gmap.c and kvm/gmap.h. Reviewed-by: Nina Schoetterl-Glausch <[email protected]> Reviewed-by: Steffen Eiden <[email protected]> Reviewed-by: Christoph Schlameuss <[email protected]> Acked-by: Janosch Frank <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Claudio Imbrenda <[email protected]> Message-ID: <[email protected]>
1 parent 2001979 commit d6c8097

File tree

11 files changed

+133
-182
lines changed

11 files changed

+133
-182
lines changed

arch/s390/kernel/uv.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ int uv_destroy_folio(struct folio *folio)
136136
{
137137
int rc;
138138

139-
/* See gmap_make_secure(): large folios cannot be secure */
139+
/* Large folios cannot be secure */
140140
if (unlikely(folio_test_large(folio)))
141141
return 0;
142142

@@ -185,7 +185,7 @@ int uv_convert_from_secure_folio(struct folio *folio)
185185
{
186186
int rc;
187187

188-
/* See gmap_make_secure(): large folios cannot be secure */
188+
/* Large folios cannot be secure */
189189
if (unlikely(folio_test_large(folio)))
190190
return 0;
191191

@@ -462,15 +462,15 @@ EXPORT_SYMBOL_GPL(make_hva_secure);
462462

463463
/*
464464
* To be called with the folio locked or with an extra reference! This will
465-
* prevent gmap_make_secure from touching the folio concurrently. Having 2
466-
* parallel arch_make_folio_accessible is fine, as the UV calls will become a
467-
* no-op if the folio is already exported.
465+
* prevent kvm_s390_pv_make_secure() from touching the folio concurrently.
466+
* Having 2 parallel arch_make_folio_accessible is fine, as the UV calls will
467+
* become a no-op if the folio is already exported.
468468
*/
469469
int arch_make_folio_accessible(struct folio *folio)
470470
{
471471
int rc = 0;
472472

473-
/* See gmap_make_secure(): large folios cannot be secure */
473+
/* Large folios cannot be secure */
474474
if (unlikely(folio_test_large(folio)))
475475
return 0;
476476

arch/s390/kvm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ include $(srctree)/virt/kvm/Makefile.kvm
88
ccflags-y := -Ivirt/kvm -Iarch/s390/kvm
99

1010
kvm-y += kvm-s390.o intercept.o interrupt.o priv.o sigp.o
11-
kvm-y += diag.o gaccess.o guestdbg.o vsie.o pv.o gmap.o gmap-vsie.o
11+
kvm-y += diag.o gaccess.o guestdbg.o vsie.o pv.o gmap-vsie.o
1212

1313
kvm-$(CONFIG_VFIO_PCI_ZDEV_KVM) += pci.o
1414
obj-$(CONFIG_KVM) += kvm.o

arch/s390/kvm/gaccess.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
#include <asm/gmap.h>
1717
#include <asm/dat-bits.h>
1818
#include "kvm-s390.h"
19-
#include "gmap.h"
2019
#include "gaccess.h"
2120

21+
#define GMAP_SHADOW_FAKE_TABLE 1ULL
22+
2223
/*
2324
* vaddress union in order to easily decode a virtual address into its
2425
* region first index, region second index etc. parts.

arch/s390/kvm/gmap-vsie.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <asm/uv.h>
2323

2424
#include "kvm-s390.h"
25-
#include "gmap.h"
2625

2726
/**
2827
* gmap_find_shadow - find a specific asce in the list of shadow tables

arch/s390/kvm/gmap.c

Lines changed: 0 additions & 121 deletions
This file was deleted.

arch/s390/kvm/gmap.h

Lines changed: 0 additions & 39 deletions
This file was deleted.

arch/s390/kvm/intercept.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616
#include <asm/irq.h>
1717
#include <asm/sysinfo.h>
1818
#include <asm/uv.h>
19-
#include <asm/gmap.h>
2019

2120
#include "kvm-s390.h"
2221
#include "gaccess.h"
2322
#include "trace.h"
2423
#include "trace-s390.h"
25-
#include "gmap.h"
2624

2725
u8 kvm_s390_get_ilen(struct kvm_vcpu *vcpu)
2826
{
@@ -546,7 +544,7 @@ static int handle_pv_uvc(struct kvm_vcpu *vcpu)
546544
guest_uvcb->header.cmd);
547545
return 0;
548546
}
549-
rc = gmap_make_secure(vcpu->arch.gmap, uvcb.gaddr, &uvcb);
547+
rc = kvm_s390_pv_make_secure(vcpu->kvm, uvcb.gaddr, &uvcb);
550548
/*
551549
* If the unpin did not succeed, the guest will exit again for the UVC
552550
* and we will retry the unpin.
@@ -654,10 +652,8 @@ int kvm_handle_sie_intercept(struct kvm_vcpu *vcpu)
654652
break;
655653
case ICPT_PV_PREF:
656654
rc = 0;
657-
gmap_convert_to_secure(vcpu->arch.gmap,
658-
kvm_s390_get_prefix(vcpu));
659-
gmap_convert_to_secure(vcpu->arch.gmap,
660-
kvm_s390_get_prefix(vcpu) + PAGE_SIZE);
655+
kvm_s390_pv_convert_to_secure(vcpu->kvm, kvm_s390_get_prefix(vcpu));
656+
kvm_s390_pv_convert_to_secure(vcpu->kvm, kvm_s390_get_prefix(vcpu) + PAGE_SIZE);
661657
break;
662658
default:
663659
return -EOPNOTSUPP;

arch/s390/kvm/kvm-s390.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
#include "kvm-s390.h"
5454
#include "gaccess.h"
5555
#include "pci.h"
56-
#include "gmap.h"
5756

5857
#define CREATE_TRACE_POINTS
5958
#include "trace.h"
@@ -4976,7 +4975,7 @@ static int vcpu_post_run_handle_fault(struct kvm_vcpu *vcpu)
49764975
* previous protected guest. The old pages need to be destroyed
49774976
* so the new guest can use them.
49784977
*/
4979-
if (gmap_destroy_page(vcpu->arch.gmap, gaddr)) {
4978+
if (kvm_s390_pv_destroy_page(vcpu->kvm, gaddr)) {
49804979
/*
49814980
* Either KVM messed up the secure guest mapping or the
49824981
* same page is mapped into multiple secure guests.
@@ -4998,7 +4997,7 @@ static int vcpu_post_run_handle_fault(struct kvm_vcpu *vcpu)
49984997
* guest has not been imported yet. Try to import the page into
49994998
* the protected guest.
50004999
*/
5001-
rc = gmap_convert_to_secure(vcpu->arch.gmap, gaddr);
5000+
rc = kvm_s390_pv_convert_to_secure(vcpu->kvm, gaddr);
50025001
if (rc == -EINVAL)
50035002
send_sig(SIGSEGV, current, 0);
50045003
if (rc != -ENXIO)

arch/s390/kvm/kvm-s390.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ int kvm_s390_pv_dump_stor_state(struct kvm *kvm, void __user *buff_user,
308308
u64 *gaddr, u64 buff_user_len, u16 *rc, u16 *rrc);
309309
int kvm_s390_pv_dump_complete(struct kvm *kvm, void __user *buff_user,
310310
u16 *rc, u16 *rrc);
311+
int kvm_s390_pv_destroy_page(struct kvm *kvm, unsigned long gaddr);
312+
int kvm_s390_pv_convert_to_secure(struct kvm *kvm, unsigned long gaddr);
313+
int kvm_s390_pv_make_secure(struct kvm *kvm, unsigned long gaddr, void *uvcb);
311314

312315
static inline u64 kvm_s390_pv_get_handle(struct kvm *kvm)
313316
{
@@ -319,6 +322,41 @@ static inline u64 kvm_s390_pv_cpu_get_handle(struct kvm_vcpu *vcpu)
319322
return vcpu->arch.pv.handle;
320323
}
321324

325+
/**
326+
* __kvm_s390_pv_destroy_page() - Destroy a guest page.
327+
* @page: the page to destroy
328+
*
329+
* An attempt will be made to destroy the given guest page. If the attempt
330+
* fails, an attempt is made to export the page. If both attempts fail, an
331+
* appropriate error is returned.
332+
*
333+
* Context: must be called holding the mm lock for gmap->mm
334+
*/
335+
static inline int __kvm_s390_pv_destroy_page(struct page *page)
336+
{
337+
struct folio *folio = page_folio(page);
338+
int rc;
339+
340+
/* Large folios cannot be secure. Small folio implies FW_LEVEL_PTE. */
341+
if (folio_test_large(folio))
342+
return -EFAULT;
343+
344+
rc = uv_destroy_folio(folio);
345+
/*
346+
* Fault handlers can race; it is possible that two CPUs will fault
347+
* on the same secure page. One CPU can destroy the page, reboot,
348+
* re-enter secure mode and import it, while the second CPU was
349+
* stuck at the beginning of the handler. At some point the second
350+
* CPU will be able to progress, and it will not be able to destroy
351+
* the page. In that case we do not want to terminate the process,
352+
* we instead try to export the page.
353+
*/
354+
if (rc)
355+
rc = uv_convert_from_secure_folio(folio);
356+
357+
return rc;
358+
}
359+
322360
/* implemented in interrupt.c */
323361
int kvm_s390_handle_wait(struct kvm_vcpu *vcpu);
324362
void kvm_s390_vcpu_wakeup(struct kvm_vcpu *vcpu);
@@ -398,6 +436,10 @@ void kvm_s390_vsie_gmap_notifier(struct gmap *gmap, unsigned long start,
398436
unsigned long end);
399437
void kvm_s390_vsie_init(struct kvm *kvm);
400438
void kvm_s390_vsie_destroy(struct kvm *kvm);
439+
int gmap_shadow_valid(struct gmap *sg, unsigned long asce, int edat_level);
440+
441+
/* implemented in gmap-vsie.c */
442+
struct gmap *gmap_shadow(struct gmap *parent, unsigned long asce, int edat_level);
401443

402444
/* implemented in sigp.c */
403445
int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu);

0 commit comments

Comments
 (0)