From: David Hildenbrand <david@redhat.com>
To: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Janosch Frank <frankja@linux.ibm.com>,
Claudio Imbrenda <imbrenda@linux.ibm.com>,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Andrew Morton <akpm@linux-foundation.org>,
Peter Xu <peterx@redhat.com>, Sven Schnelle <svens@linux.ibm.com>,
Gerald Schaefer <gerald.schaefer@linux.ibm.com>,
Andrea Arcangeli <aarcange@redhat.com>,
kvm@vger.kernel.org, linux-s390@vger.kernel.org
Subject: Re: [PATCH v3 2/2] s390/mm: re-enable the shared zeropage for !PV and !skeys KVM guests
Date: Mon, 15 Apr 2024 21:14:03 +0200 [thread overview]
Message-ID: <8533cb18-42ff-42bc-b9e5-b0537aa51b21@redhat.com> (raw)
In-Reply-To: <Zh1w1QTNSy+rrCH7@li-008a6a4c-3549-11b2-a85c-c5cc2836eea2.ibm.com>
On 15.04.24 20:24, Alexander Gordeev wrote:
> On Thu, Apr 11, 2024 at 06:14:41PM +0200, David Hildenbrand wrote:
>
> David, could you please clarify the below questions?
Sure, let me take a look if we're still missing to handle some corner cases correctly.
>
>> +static int __s390_unshare_zeropages(struct mm_struct *mm)
>> +{
>> + struct vm_area_struct *vma;
>> + VMA_ITERATOR(vmi, mm, 0);
>> + unsigned long addr;
>> + int rc;
>> +
>> + for_each_vma(vmi, vma) {
>> + /*
>> + * We could only look at COW mappings, but it's more future
>> + * proof to catch unexpected zeropages in other mappings and
>> + * fail.
>> + */
>> + if ((vma->vm_flags & VM_PFNMAP) || is_vm_hugetlb_page(vma))
>> + continue;
>> + addr = vma->vm_start;
>> +
>> +retry:
>> + rc = walk_page_range_vma(vma, addr, vma->vm_end,
>> + &find_zeropage_ops, &addr);
>> + if (rc <= 0)
>> + continue;
>
> So in case an error is returned for the last vma, __s390_unshare_zeropage()
> finishes with that error. By contrast, the error for a non-last vma would
> be ignored?
Right, it looks a bit off. walk_page_range_vma() shouldn't fail
unless find_zeropage_pte_entry() would fail -- which would also be
very unexpected.
To handle it cleanly in case we would ever get a weird zeropage where we
don't expect it, we should probably just exit early.
Something like the following (not compiled, addressing the comment below):
From b97cd17a3697ac402b07fe8d0033f3c10fbd6829 Mon Sep 17 00:00:00 2001
From: David Hildenbrand <david@redhat.com>
Date: Mon, 15 Apr 2024 20:56:20 +0200
Subject: [PATCH] fixup
Signed-off-by: David Hildenbrand <david@redhat.com>
---
arch/s390/mm/gmap.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/arch/s390/mm/gmap.c b/arch/s390/mm/gmap.c
index 9233b0acac89..3e3322a9cc32 100644
--- a/arch/s390/mm/gmap.c
+++ b/arch/s390/mm/gmap.c
@@ -2618,7 +2618,8 @@ static int __s390_unshare_zeropages(struct mm_struct *mm)
struct vm_area_struct *vma;
VMA_ITERATOR(vmi, mm, 0);
unsigned long addr;
- int rc;
+ vm_fault_t rc;
+ int zero_page;
for_each_vma(vmi, vma) {
/*
@@ -2631,9 +2632,11 @@ static int __s390_unshare_zeropages(struct mm_struct *mm)
addr = vma->vm_start;
retry:
- rc = walk_page_range_vma(vma, addr, vma->vm_end,
- &find_zeropage_ops, &addr);
- if (rc <= 0)
+ zero_page = walk_page_range_vma(vma, addr, vma->vm_end,
+ &find_zeropage_ops, &addr);
+ if (zero_page < 0)
+ return zero_page;
+ else if (!zero_page)
continue;
/* addr was updated by find_zeropage_pte_entry() */
@@ -2656,7 +2659,7 @@ static int __s390_unshare_zeropages(struct mm_struct *mm)
goto retry;
}
- return rc;
+ return 0;
}
static int __s390_disable_cow_sharing(struct mm_struct *mm)
--
2.44.0
>
>> +
>> + /* addr was updated by find_zeropage_pte_entry() */
>> + rc = handle_mm_fault(vma, addr,
>> + FAULT_FLAG_UNSHARE | FAULT_FLAG_REMOTE,
>> + NULL);
>> + if (rc & VM_FAULT_OOM)
>> + return -ENOMEM;
>
> Heiko pointed out that rc type is inconsistent vs vm_fault_t returned by
Right, let's use another variable for that.
> handle_mm_fault(). While fixing it up, I've got concerned whether is it
> fine to continue in case any other error is met (including possible future
> VM_FAULT_xxxx)?
Such future changes would similarly break break_ksm(). Staring at it, I do wonder
if break_ksm() should be handling VM_FAULT_HWPOISON ... very likely we should
handle it and fail -- we might get an MC while copying from the source page.
VM_FAULT_HWPOISON on the shared zeropage would imply a lot of trouble, so
I'm not concerned about that for the case here, but handling it in the future
would be cleaner.
Note that we always retry the lookup, so we won't just skip a zeropage on unexpected
errors.
We could piggy-back on vm_fault_to_errno(). We could use
vm_fault_to_errno(rc, FOLL_HWPOISON), and only continue (retry) if the rc is 0 or
-EFAULT, otherwise fail with the returned error.
But I'd do that as a follow up, and also use it in break_ksm() in the same fashion.
--
Cheers,
David / dhildenb
next prev parent reply other threads:[~2024-04-15 19:14 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-11 16:14 [PATCH v3 0/2] s390/mm: shared zeropage + KVM fixes David Hildenbrand
2024-04-11 16:14 ` [PATCH v3 1/2] mm/userfaultfd: don't place zeropages when zeropages are disallowed David Hildenbrand
2024-04-11 16:14 ` [PATCH v3 2/2] s390/mm: re-enable the shared zeropage for !PV and !skeys KVM guests David Hildenbrand
2024-04-11 16:37 ` Alexander Gordeev
2024-04-11 21:09 ` David Hildenbrand
2024-04-15 11:49 ` Christian Borntraeger
2024-04-15 13:14 ` Alexander Gordeev
2024-04-15 18:24 ` Alexander Gordeev
2024-04-15 19:14 ` David Hildenbrand [this message]
2024-04-16 6:37 ` Alexander Gordeev
2024-04-16 7:05 ` David Hildenbrand
2024-04-16 12:02 ` Christian Borntraeger
2024-04-16 13:41 ` David Hildenbrand
2024-04-18 13:09 ` Christian Borntraeger
2024-04-11 21:28 ` [PATCH v3 0/2] s390/mm: shared zeropage + KVM fixes Andrew Morton
2024-04-11 21:56 ` David Hildenbrand
2024-04-12 13:25 ` Alexander Gordeev
2024-04-17 12:46 ` Alexander Gordeev
2024-04-17 12:47 ` David Hildenbrand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8533cb18-42ff-42bc-b9e5-b0537aa51b21@redhat.com \
--to=david@redhat.com \
--cc=aarcange@redhat.com \
--cc=agordeev@linux.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=borntraeger@linux.ibm.com \
--cc=frankja@linux.ibm.com \
--cc=gerald.schaefer@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=imbrenda@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-s390@vger.kernel.org \
--cc=peterx@redhat.com \
--cc=svens@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox