From: Heiko Carstens <hca@linux.ibm.com>
To: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: sashiko-reviews@lists.linux.dev, linux-s390@vger.kernel.org,
Alexander Gordeev <agordeev@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
kvm@vger.kernel.org
Subject: Re: [PATCH 1/4] KVM: s390: pv: Use VM_SPARSE area for guest variable storage area
Date: Sun, 19 Jul 2026 15:03:39 +0200 [thread overview]
Message-ID: <20260719130339.22878A6e-hca@linux.ibm.com> (raw)
In-Reply-To: <778ba45f-bd2e-46e0-8b08-fcd209dd174d@linux.ibm.com>
On Fri, Jul 17, 2026 at 11:12:09AM +0200, Christian Borntraeger wrote:
> Am 16.07.26 um 16:33 schrieb sashiko-bot@kernel.org:
> [...]
> > [Severity: High]
> > Does this create a Use-After-Free window during VM teardown?
> >
> > In uv_free_stor_var(), we call apply_to_existing_page_range() which invokes
> > uv_free_range_cb() for each page. The callback frees the physical page
> > directly to the buddy allocator via __free_page() while the PTE remains
> > fully present and writable in the init_mm page tables.
> >
> > After all pages are freed, free_vm_area() is called to clear the PTEs and
> > flush the TLB. If a freed page is immediately reallocated to another
> > subsystem, can concurrent accesses via the stale vmalloc alias read or
> > overwrite the newly reallocated page before free_vm_area() completes?
>
> I guess this is a very very theoretical problem. Not sure if we really want
> to address this. The necessary allocation in a freeing function might be
> worse than temporary access via the kernel mapping.
I added a comment why this won't be addressed. The existing vmalloc
code already implements lazy TLB flushing (even though it is not
active on only s390 because of our special ptep_get_and_clear()
implementation).
> > > +void *uv_alloc_stor_var(unsigned long size)
> > > +{
> > > + struct vm_struct *area;
> > > + unsigned long addr;
> > > +
> > > + area = get_vm_area(size, VM_SPARSE);
> > > + if (!area)
> > > + return NULL;
> > > + addr = (unsigned long)area->addr;
> > > + if (apply_to_page_range(&init_mm, addr, size, uv_alloc_range_cb, NULL))
> >
> > [Severity: High]
> > If an unaligned size is passed to uv_alloc_stor_var(), could this cause an
> > infinite loop in the page table walker?
> >
> > The size parameter is passed directly to apply_to_page_range(). The internal
> > page table walker loop relies on the end boundary being exactly page-aligned
> > to terminate:
>
> This is one of those things that wont happen in reality as the returned sized
> will be aligned, but as the interface for base variable storage returns bytes
> and in theory _COULD_ be unaligned
> maybe change belows hunk to
>
> @@ -369,7 +369,7 @@ static int kvm_s390_pv_alloc_vm(struct kvm *kvm)
> /* Allocate variable storage */
> vlen = ALIGN(virt * ((npages * PAGE_SIZE) / HPAGE_SIZE), PAGE_SIZE);
> ----> vlen += uv_info.guest_virt_base_stor_len; <--- also add ALIGN here
> - kvm->arch.pv.stor_var = vzalloc(vlen);
> + kvm->arch.pv.stor_var = uv_alloc_stor_var(vlen);
> if (!kvm->arch.pv.stor_var)
> goto out_err;
> return 0;
>
> Could also be a separate patch if we want to.
I added the alignment handling uv_alloc_stor_var(), so that it doesn't
matter what callers pass.
next prev parent reply other threads:[~2026-07-19 13:03 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-16 14:14 [PATCH 0/4] s390: Reintroduce support for DCACHE_WORD_ACCESS Heiko Carstens
2026-07-16 14:14 ` [PATCH 1/4] KVM: s390: pv: Use VM_SPARSE area for guest variable storage area Heiko Carstens
2026-07-16 14:33 ` sashiko-bot
2026-07-17 9:12 ` Christian Borntraeger
2026-07-19 13:03 ` Heiko Carstens [this message]
2026-07-16 14:14 ` [PATCH 2/4] s390/mm: Fix handling of secure storage access exceptions in vmalloc area Heiko Carstens
2026-07-16 14:14 ` [PATCH 3/4] s390/mm: Remove folio handling for secure storage access exceptions Heiko Carstens
2026-07-16 14:19 ` David Hildenbrand (Arm)
2026-07-16 14:14 ` [PATCH 4/4] s390: Add support for DCACHE_WORD_ACCESS (again) Heiko Carstens
2026-07-17 9:05 ` [PATCH 0/4] s390: Reintroduce support for DCACHE_WORD_ACCESS Christian Borntraeger
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=20260719130339.22878A6e-hca@linux.ibm.com \
--to=hca@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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