Re: [PATCH v2 10/20] KVM: s390: KVM page table management functions: walks

Gerd Bayer
2025-09-12T05:48:36Z

On Thu, 2025-09-11 at 15:14 +0200, Claudio Imbrenda wrote:
> On Thu, 11 Sep 2025 14:56:59 +0200
> Janosch Frank <frankja@linux.ibm.com> wrote:
>
> > On 9/10/25 8:07 PM, Claudio Imbrenda wrote:
> > > Add page table management functions to be used for KVM guest (gmap)
> > > page tables.
> > >
> > > This patch adds functions to walk to specific table entries, or to
> > > perform actions on a range of entries.
> > >
> > > Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
> > > ---
> > > arch/s390/kvm/dat.c | 351 ++++++++++++++++++++++++++++++++++++++++++++
> > > arch/s390/kvm/dat.h | 38 +++++
> > > 2 files changed, 389 insertions(+)
> > >
> > > diff --git a/arch/s390/kvm/dat.c b/arch/s390/kvm/dat.c
> > > index f26e3579bd77..fe93e1c07158 100644
> > > --- a/arch/s390/kvm/dat.c
> > > +++ b/arch/s390/kvm/dat.c
> > > @@ -209,3 +209,354 @@ union pgste __dat_ptep_xchg(union pte *ptep, union pgste pgste, union pte new, g
> > > WRITE_ONCE(*ptep, new);
> > > return pgste;

[... snip ...]

> > > +
> > > + while (old.h.i || old.h.fc) {
> > > + init.val = pmd_origin_large(old);
> > > + init.h.p = old.h.p;
> > > + init.h.i = old.h.i;
> > > + init.s.d = old.s.fc1.d;
> > > + init.s.w = old.s.fc1.w;
> > > + init.s.y = old.s.fc1.y;
> > > + init.s.sd = old.s.fc1.sd;
> > > + init.s.pr = old.s.fc1.pr;
> >
> > This looks horrible but I haven't found a better solution.
>
> I know what you mean :)

If nothing else, you may try and encapsulate this in a helper to
concentrate the ugliness there. Then the while-body just calls some
prepare_init() or similar?