Commit 0b31a3ce authored by David Hildenbrand's avatar David Hildenbrand Committed by Andrew Morton

s390/mm/fault: convert do_secure_storage_access() from follow_page() to folio_walk

Let's get rid of another follow_page() user and perform the conversion
under PTL: Note that this is also what follow_page_pte() ends up doing.

Unfortunately we cannot currently optimize out the additional reference,
because arch_make_folio_accessible() must be called with a raised refcount
to protect against concurrent conversion to secure.  We can just move the
arch_make_folio_accessible() under the PTL, like follow_page_pte() would.

We'll effectively drop the "writable" check implied by FOLL_WRITE:
follow_page_pte() would also not check that when calling
arch_make_folio_accessible(), so there is no good reason for doing that
here.

We'll lose the secretmem check from follow_page() as well, about which we
shouldn't really care.

Link: https://lkml.kernel.org/r/20240802155524.517137-10-david@redhat.comSigned-off-by: default avatarDavid Hildenbrand <david@redhat.com>
Reviewed-by: default avatarClaudio Imbrenda <imbrenda@linux.ibm.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Janosch Frank <frankja@linux.ibm.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 85a7e543
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/hugetlb.h> #include <linux/hugetlb.h>
#include <linux/kfence.h> #include <linux/kfence.h>
#include <linux/pagewalk.h>
#include <asm/asm-extable.h> #include <asm/asm-extable.h>
#include <asm/asm-offsets.h> #include <asm/asm-offsets.h>
#include <asm/ptrace.h> #include <asm/ptrace.h>
...@@ -492,9 +493,9 @@ void do_secure_storage_access(struct pt_regs *regs) ...@@ -492,9 +493,9 @@ void do_secure_storage_access(struct pt_regs *regs)
union teid teid = { .val = regs->int_parm_long }; union teid teid = { .val = regs->int_parm_long };
unsigned long addr = get_fault_address(regs); unsigned long addr = get_fault_address(regs);
struct vm_area_struct *vma; struct vm_area_struct *vma;
struct folio_walk fw;
struct mm_struct *mm; struct mm_struct *mm;
struct folio *folio; struct folio *folio;
struct page *page;
struct gmap *gmap; struct gmap *gmap;
int rc; int rc;
...@@ -536,15 +537,18 @@ void do_secure_storage_access(struct pt_regs *regs) ...@@ -536,15 +537,18 @@ void do_secure_storage_access(struct pt_regs *regs)
vma = find_vma(mm, addr); vma = find_vma(mm, addr);
if (!vma) if (!vma)
return handle_fault_error(regs, SEGV_MAPERR); return handle_fault_error(regs, SEGV_MAPERR);
page = follow_page(vma, addr, FOLL_WRITE | FOLL_GET); folio = folio_walk_start(&fw, vma, addr, 0);
if (IS_ERR_OR_NULL(page)) { if (!folio) {
mmap_read_unlock(mm); mmap_read_unlock(mm);
break; break;
} }
folio = page_folio(page); /* arch_make_folio_accessible() needs a raised refcount. */
if (arch_make_folio_accessible(folio)) folio_get(folio);
send_sig(SIGSEGV, current, 0); rc = arch_make_folio_accessible(folio);
folio_put(folio); folio_put(folio);
folio_walk_end(&fw, vma);
if (rc)
send_sig(SIGSEGV, current, 0);
mmap_read_unlock(mm); mmap_read_unlock(mm);
break; break;
case KERNEL_FAULT: case KERNEL_FAULT:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment