Linux s390 Architecture development
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: "Carlos López" <clopez@suse.de>
Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>,
	kvm@vger.kernel.org, linux-mm@kvack.org,  pbonzini@redhat.com,
	linux-s390@vger.kernel.org
Subject: Re: [RFC PATCH 0/4] KVM: x86/mmu: don't zap secondary MMU on permission upgrade
Date: Wed, 4 Nov 2026 07:38:45 -0800	[thread overview]
Message-ID: <autRhZjOfLyw2OXo@google.com> (raw)
In-Reply-To: <7ba2ca65-1eab-40fd-ae4c-f7cd9e156d8c@suse.de>

On Wed, Nov 04, 2026, Carlos López wrote:
> On 11/3/26 4:03 PM, Sean Christopherson wrote:
> > On Tue, Nov 03, 2026, Carlos López wrote:
> >> On 11/2/26 4:31 PM, Sean Christopherson wrote:
> >>> On Fri, Oct 30, 2026, Claudio Imbrenda wrote:
> >>>> On Fri, 30 Oct 2026 12:11:07 +0100
> >>>> Carlos López <clopez@suse.de> wrote:
> >>>>
> >>>> [...]
> >>>>
> >>>>>> regarding this series:
> >>>>>>
> >>>>>> on x86 you don't care what the new permissions are, because you're
> >>>>>> updating when re-faulting (if I understood correctly).  
> >>>>>
> >>>>> Correct.
> >>>>>
> >>>>>> for s390 it might be beneficial to know what the new permissions are;
> >>>>>> of course we could look up the vma and find out, but since you are
> >>>>>> already checking the permissions, maybe you can find a way to also
> >>>>>> convey the new permission bits?
> >>>>>>
> >>>>>> that would make our life on s390 easier :)  
> >>>>>
> >>>>> Right, getting the new bits from vma->flags should be trivially done
> >>>>> from the MMU_NOTIFY_PROTECTION_VMA callsites. There'd be no users in
> >>>>> this series though.  The rest of architectures still need the notifier to
> >>>>> tell them if the change is an upgrade, since they don't have an easy way
> >>>>> to grab the old RWX bits. Passing the old RWX bits from the MMU notifier
> >>>>> does not seem trivial to me either.
> >>>
> >>> But why is core MM even doing mmu_notifier_invalidate_range_{start,end}() in the
> >>> first place?  I.e. why add MMU_NOTIFIER_RANGE_PERM_UPGRADE?  Just skip the
> >>> "invalidation".
> >>
> >> I briefly mention this in the cover letter, but in short, denying other
> >> users the notification seems like an overly intrusive change for KVM's
> >> benefit. 
> > 
> > There are all of two other users:
> > 
> >   $ git grep -w "\.invalidate_range_start"
> >   drivers/gpu/drm/nouveau/nouveau_svm.c:  .invalidate_range_start = nouveau_svmm_invalidate_range_start,
> >   drivers/infiniband/hw/hfi1/mmu_rb.c:    .invalidate_range_start = mmu_notifier_range_start,
> >   virt/kvm/kvm_main.c:    .invalidate_range_start = kvm_mmu_notifier_invalidate_range_start,
> > 
> > and AFAICT neither of them wants an invalidation even for protection upgrades
> > either.
> 
> There are more users that register for notifications via

Ugh, I didn't realize we gained a variant of .invalidate_range_{start,end}(),
I thought those were for what is now arch_invalidate_secondary_tlbs().

> mmu_interval_notifier_insert():
> 
>   $ git grep -l -e "mmu_interval_notifier_insert(" \
>           -e "mmu_interval_notifier_insert_locked(" -- drivers/ | wc -l
>   12
> 
> I haven't audited all of them, but I'd say that at least amdkfd relies
> on the invalidation for upgrades. Without XNACK, GPU page faults are not
> retried, so the driver maps ranges up front with the VMA permissions
> (svm_range_validate_and_map()) and relies on an invalidation to remap
> them when those change. So mprotect(PROT_READ) followed by
> mprotect(PROT_READ|PROT_WRITE) would cause the GPU mapping to stay
> read-only and the next GPU write to fault. Unlike the APIC access page,
> this is the application's own memory, mprotect() should be perfectly valid.
> 
> This is the kind of subtle reliance that I mentioned before, and why I'd
> rather not open that can of worms.

Yeah, agreed.

> >> A flag allows users to opt in instead.
> >>
> >> It is also not clear to me that secondary MMUs are not relying on the
> >> notification in some subtle way. In fact, Sashiko points out in reply to
> >> patch 4 that the notification lets KVM retry the APIC access page reload
> >> in case userspace shoots itself in the foot by calling
> >> mprotect(PROT_READ) on it. This would require a really weird VMM,
> > 
> > s/weird/misbehaving
> > 
> >> as it would need to go looking for the page's address, but breaking this
> >> would be a "regression" nonetheless. I will address this in v2.
> > 
> > Nah, there's zero chance any real VMM is doing mprotect() on the APIC access page.
> > 
> > More importantly, doing nothing if updating the mapping fails and APICv is enabled
> > is wrong.  KVM needs to ensure vmcs.APIC_ACCESS_ADDR is fresh when running a vCPU
> > with APICv enabled, even if that means putting the vCPU into an infinite loop.
> > VMX doesn't support "inhibiting" the APIC access page, i.e. the memslot can't
> > disappear while the VM is alive, and if userspace mucks with the VMA, then KVM
> > needs to prevent running the vCPU until the mapping is restored, irrespective of
> > mmu_notifiers.
> 
> Fair point. Should I just carry the diff below in v2 with your
> Signed-off-by?

Nah, I'll send a standalone patch.  It doesn't have a direct relationship to your
series, and the bug is pre-existing despite what Sashiko thinks.

Thanks!

      reply	other threads:[~2026-11-04 15:38 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-29 14:33 [RFC PATCH 0/4] KVM: x86/mmu: don't zap secondary MMU on permission upgrade Carlos López
2026-10-29 14:33 ` [RFC PATCH 1/4] mm/mprotect: add MM_CP_PERM_UPGRADE Carlos López
2026-10-30 14:44   ` sashiko-bot
2026-10-29 14:33 ` [RFC PATCH 2/4] mm/mmu_notifier: add MMU_NOTIFIER_RANGE_PERM_UPGRADE Carlos López
2026-10-30 14:44   ` sashiko-bot
2026-10-29 14:33 ` [RFC PATCH 3/4] KVM: plumb MMU_NOTIFIER_RANGE_PERM_UPGRADE into kvm_gfn_range Carlos López
2026-10-30 14:44   ` sashiko-bot
2026-10-29 14:33 ` [RFC PATCH 4/4] KVM: x86/mmu: don't zap the secondary MMU on permission upgrade Carlos López
2026-10-30 14:44   ` sashiko-bot
2026-10-29 16:52 ` [RFC PATCH 0/4] KVM: x86/mmu: don't zap " Claudio Imbrenda
2026-10-30 11:11   ` Carlos López
2026-10-30 12:39     ` Claudio Imbrenda
2026-11-02 15:31       ` Sean Christopherson
2026-11-03 11:09         ` Carlos López
2026-11-03 15:03           ` Sean Christopherson
2026-11-04  0:38             ` Carlos López
2026-11-04 15:38               ` Sean Christopherson [this message]

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=autRhZjOfLyw2OXo@google.com \
    --to=seanjc@google.com \
    --cc=clopez@suse.de \
    --cc=imbrenda@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=pbonzini@redhat.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