From: Alexander Gordeev <agordeev@linux.ibm.com>
To: Heiko Carstens <hca@linux.ibm.com>
Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>,
linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] s390/mm: Fix fail path in crst_table_upgrade()
Date: Wed, 19 Aug 2026 13:22:50 +0200 [thread overview]
Message-ID: <9e707e9c-2da5-4325-9bf3-b41aefb2f8ab-agordeev@linux.ibm.com> (raw)
In-Reply-To: <20260811141203.12308B7d-hca@linux.ibm.com>
On Tue, Aug 11, 2026 at 04:12:03PM +0200, Heiko Carstens wrote:
> On Tue, Aug 11, 2026 at 02:13:16PM +0200, Alexander Gordeev wrote:
> > On a 4-to-5 level upgrade (unlike 3-to-5) p4d local variable
> > stays NULL. If the pgd allocation then fails, the fault code
> > path calls pagetable_dtor(virt_to_ptdesc(p4d)) with NULL.
> >
> > Fixes: 502269ab98b5 ("s390/mm: add missing ctor/dtor on page table upgrade")
> > Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
> > ---
> > arch/s390/mm/pgalloc.c | 17 ++++++++---------
> > 1 file changed, 8 insertions(+), 9 deletions(-)
> >
> > diff --git a/arch/s390/mm/pgalloc.c b/arch/s390/mm/pgalloc.c
> > index 9610770fcf6d..87a8bdb3e51e 100644
> > --- a/arch/s390/mm/pgalloc.c
> > +++ b/arch/s390/mm/pgalloc.c
> > @@ -69,14 +69,19 @@ int crst_table_upgrade(struct mm_struct *mm, unsigned long end)
> > if (asce_limit == _REGION2_SIZE) {
> > p4d = crst_table_alloc(mm);
> > if (unlikely(!p4d))
> > - goto err_p4d;
> > + return -ENOMEM;
> > crst_table_init(p4d, _REGION2_ENTRY_EMPTY);
> > pagetable_p4d_ctor(virt_to_ptdesc(p4d));
> > }
> > if (end > _REGION1_SIZE) {
> > pgd = crst_table_alloc(mm);
> > - if (unlikely(!pgd))
> > - goto err_pgd;
> > + if (unlikely(!pgd)) {
> > + if (p4d) {
> > + pagetable_dtor(virt_to_ptdesc(p4d));
> > + crst_table_free(mm, p4d);
> > + }
> > + return -ENOMEM;
> > + }
> > crst_table_init(pgd, _REGION1_ENTRY_EMPTY);
> > pagetable_pgd_ctor(virt_to_ptdesc(pgd));
> > }
> > @@ -106,12 +111,6 @@ int crst_table_upgrade(struct mm_struct *mm, unsigned long end)
> > on_each_cpu(__crst_table_upgrade, mm, 0);
> >
> > return 0;
> > -
> > -err_pgd:
> > - pagetable_dtor(virt_to_ptdesc(p4d));
> > - crst_table_free(mm, p4d);
> > -err_p4d:
> > - return -ENOMEM;
> > }
>
> Imho this makes the code even more uglier than it is/was. This is also yet
> another bug which is/was only possible after loop unrolling happened with
> [1]. Another bug, which would not have been possible without the rework back
> then, is [2].
>
> So I would _much_ rather prefer to go back to what we had with [1], of course
> including the additional dtor/ctor code. But that code was much more readable
> compared to what we have now, especially considering the additional fix which
> is proposed now.
Frankly, to me personally the old version is more difficult to read.
In addition, in case of 3-5 upgrade on 4-5 allocation failure it has
(a) 4-level table leak and (b) useless 3-4 upgrade.
Should all of those get fixed, I doubt the end result will look as
simple as the original version. But I can try if you insist.
> [1] 31932757c612 ("s390/mm: optimize page table upgrade routine")
> [2] b5efb63acf7b ("s390/mm: Add NULL pointer check to crst_table_free() base_crst_free()")
Thanks!
next prev parent reply other threads:[~2026-08-19 11:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-11 12:13 Alexander Gordeev
2026-08-11 14:12 ` Heiko Carstens
2026-08-19 11:22 ` Alexander Gordeev [this message]
2026-08-24 14:22 ` Heiko Carstens
2026-08-27 7:51 ` Alexander Gordeev
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=9e707e9c-2da5-4325-9bf3-b41aefb2f8ab-agordeev@linux.ibm.com \
--to=agordeev@linux.ibm.com \
--cc=gerald.schaefer@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
/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
all inboxes | Powered by JetHome®