Skip to content

Commit

Permalink
[S390] take mmap_sem when walking guest page table
Browse files Browse the repository at this point in the history
gmap_fault needs to walk the guest page table. However, parts of
that may change if some other thread does munmap. In that case
gmap_unmap_notifier will also unmap the corresponding parts from
the guest page table. We need to take mmap_sem in order to serialize
these operations.
do_exception now calls __gmap_fault with mmap_sem held which does
not get exported to modules. The exported function, which is called
from KVM, now takes mmap_sem.

Reported-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Carsten Otte <cotte@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
  • Loading branch information
Carsten Otte authored and Martin Schwidefsky committed Oct 30, 2011
1 parent cc77245 commit 499069e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions arch/s390/include/asm/pgtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ void gmap_disable(struct gmap *gmap);
int gmap_map_segment(struct gmap *gmap, unsigned long from,
unsigned long to, unsigned long length);
int gmap_unmap_segment(struct gmap *gmap, unsigned long to, unsigned long len);
unsigned long __gmap_fault(unsigned long address, struct gmap *);
unsigned long gmap_fault(unsigned long address, struct gmap *);

/*
Expand Down
2 changes: 1 addition & 1 deletion arch/s390/mm/fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ static inline int do_exception(struct pt_regs *regs, int access,

#ifdef CONFIG_PGSTE
if (test_tsk_thread_flag(current, TIF_SIE) && S390_lowcore.gmap) {
address = gmap_fault(address,
address = __gmap_fault(address,
(struct gmap *) S390_lowcore.gmap);
if (address == -EFAULT) {
fault = VM_FAULT_BADMAP;
Expand Down
15 changes: 14 additions & 1 deletion arch/s390/mm/pgtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,10 @@ int gmap_map_segment(struct gmap *gmap, unsigned long from,
}
EXPORT_SYMBOL_GPL(gmap_map_segment);

unsigned long gmap_fault(unsigned long address, struct gmap *gmap)
/*
* this function is assumed to be called with mmap_sem held
*/
unsigned long __gmap_fault(unsigned long address, struct gmap *gmap)
{
unsigned long *table, vmaddr, segment;
struct mm_struct *mm;
Expand Down Expand Up @@ -461,7 +464,17 @@ unsigned long gmap_fault(unsigned long address, struct gmap *gmap)
return vmaddr | (address & ~PMD_MASK);
}
return -EFAULT;
}

unsigned long gmap_fault(unsigned long address, struct gmap *gmap)
{
unsigned long rc;

down_read(&gmap->mm->mmap_sem);
rc = __gmap_fault(address, gmap);
up_read(&gmap->mm->mmap_sem);

return rc;
}
EXPORT_SYMBOL_GPL(gmap_fault);

Expand Down

0 comments on commit 499069e

Please sign in to comment.