On 03/02/2020 14.19, Christian Borntraeger wrote: > Before 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 a secure mode. As > this "new" secure guest will have a new ID we cannot reuse the old page > state. > > Signed-off-by: Christian Borntraeger <borntraeger@xxxxxxxxxx> > --- > arch/s390/include/asm/pgtable.h | 1 + > arch/s390/kvm/pv.c | 2 ++ > arch/s390/mm/gmap.c | 35 +++++++++++++++++++++++++++++++++ > 3 files changed, 38 insertions(+) > > diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h > index 65b6bb47af0a..6e167dcc35f1 100644 > --- a/arch/s390/include/asm/pgtable.h > +++ b/arch/s390/include/asm/pgtable.h > @@ -1669,6 +1669,7 @@ extern int vmem_remove_mapping(unsigned long start, unsigned long size); > extern int s390_enable_sie(void); > extern int s390_enable_skey(void); > extern void s390_reset_cmma(struct mm_struct *mm); > +extern void s390_reset_acc(struct mm_struct *mm); > > /* s390 has a private copy of get unmapped area to deal with cache synonyms */ > #define HAVE_ARCH_UNMAPPED_AREA > diff --git a/arch/s390/kvm/pv.c b/arch/s390/kvm/pv.c > index a867b9e9c069..24d802072ac7 100644 > --- a/arch/s390/kvm/pv.c > +++ b/arch/s390/kvm/pv.c > @@ -66,6 +66,8 @@ int kvm_s390_pv_destroy_vm(struct kvm *kvm) > int rc; > u32 ret; > > + /* make all pages accessible before destroying the guest */ > + s390_reset_acc(kvm->mm); > rc = uv_cmd_nodata(kvm_s390_pv_handle(kvm), > UVC_CMD_DESTROY_SEC_CONF, &ret); > WRITE_ONCE(kvm->arch.gmap->se_handle, 0); > diff --git a/arch/s390/mm/gmap.c b/arch/s390/mm/gmap.c > index bf365a09f900..0b00e8d5fa39 100644 > --- a/arch/s390/mm/gmap.c > +++ b/arch/s390/mm/gmap.c > @@ -2648,3 +2648,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)) > + uv_convert_from_secure(pte_val(pte) & PAGE_MASK); Is it ok to ignore the return value from uv_convert_from_secure() ? Problems might go unnoticed ... maybe use at least a WARN_ONCE ? > + 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 descriptor: 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); > Anyway, Reviewed-by: Thomas Huth <thuth@xxxxxxxxxx>