From: Oliver Upton <oliver.upton@linux.dev>
To: Marc Zyngier <maz@kernel.org>
Cc: kvmarm@lists.linux.dev, James Morse <james.morse@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Reiji Watanabe <reijiw@google.com>,
stable@vger.kernel.org, Yu Zhao <yuzhao@google.com>
Subject: Re: [PATCH v2] KVM: arm64: Correctly handle page aging notifiers for unaligned memslot
Date: Tue, 11 Jul 2023 11:04:27 -0700 [thread overview]
Message-ID: <ZK2Zq9YbN4G/Pf0+@linux.dev> (raw)
In-Reply-To: <86edlewyh2.wl-maz@kernel.org>
Hey Marc,
On Tue, Jul 11, 2023 at 11:10:01AM +0100, Marc Zyngier wrote:
> On Wed, 28 Jun 2023 00:54:05 +0100, Oliver Upton <oliver.upton@linux.dev> wrote:
> > +static int stage2_age_walker(const struct kvm_pgtable_visit_ctx *ctx,
> > + enum kvm_pgtable_walk_flags visit)
> > {
> > - kvm_pte_t pte = 0;
> > - stage2_update_leaf_attrs(pgt, addr, 1, 0, KVM_PTE_LEAF_ATTR_LO_S2_AF,
> > - &pte, NULL, 0);
> > + kvm_pte_t new = ctx->old & ~KVM_PTE_LEAF_ATTR_LO_S2_AF;
> > + struct stage2_age_data *data = ctx->arg;
> > +
> > + if (!kvm_pte_valid(ctx->old) || new == ctx->old)
> > + return 0;
> > +
> > + data->young = true;
> > +
> > + if (data->mkold && !stage2_try_set_pte(ctx, new))
> > + return -EAGAIN;
> > +
> > /*
> > * "But where's the TLBI?!", you scream.
> > * "Over in the core code", I sigh.
> > *
> > * See the '->clear_flush_young()' callback on the KVM mmu notifier.
> > */
> > - return pte;
> > + return 0;
> > }
> >
> > -bool kvm_pgtable_stage2_is_young(struct kvm_pgtable *pgt, u64 addr)
> > +bool kvm_pgtable_stage2_test_clear_young(struct kvm_pgtable *pgt, u64 addr,
> > + u64 size, bool mkold)
> > {
> > - kvm_pte_t pte = 0;
> > - stage2_update_leaf_attrs(pgt, addr, 1, 0, 0, &pte, NULL, 0);
> > - return pte & KVM_PTE_LEAF_ATTR_LO_S2_AF;
> > + struct stage2_age_data data = {
> > + .mkold = mkold,
> > + };
> > + struct kvm_pgtable_walker walker = {
> > + .cb = stage2_age_walker,
> > + .arg = &data,
> > + .flags = KVM_PGTABLE_WALK_LEAF,
> > + };
> > +
> > + WARN_ON(kvm_pgtable_walk(pgt, addr, size, &walker));
>
> Do we really want a WARN_ON() here? From what I can tell, it can be
> (trivially?) triggered by the previous function returning -EAGAIN if
> the pte update fails in the case of a shared walk.
I threw the -EAGAIN in there just due to reflexes, we're holding the MMU
write lock at this point so stage2_try_set_pte() will always succeed. A
tad fragile, but wanted to make it trivial to change the locking around
stage2_age_walker() in the future.
The reason I wanted to have a WARN here is because we're unable to
return an error on the MMU notifier and might need some breadcrumbs to
debug any underlying issues in the table walker. I'd really like to keep
it in some form.
I can either replace stage2_try_set_pte() with a direct WRITE_ONCE()
(eliminating the error path) or leave it as-is. Which do you prefer?
--
Thanks,
Oliver
next prev parent reply other threads:[~2023-07-11 18:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-27 23:54 [PATCH v2] KVM: arm64: Correctly handle page aging notifiers for unaligned memslot Oliver Upton
2023-06-28 0:00 ` Oliver Upton
2023-07-11 10:10 ` Marc Zyngier
2023-07-11 18:04 ` Oliver Upton [this message]
2023-07-12 7:07 ` Marc Zyngier
2023-07-12 12:01 ` Shaoqin Huang
2023-07-12 20:12 ` Oliver Upton
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=ZK2Zq9YbN4G/Pf0+@linux.dev \
--to=oliver.upton@linux.dev \
--cc=james.morse@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=maz@kernel.org \
--cc=reijiw@google.com \
--cc=stable@vger.kernel.org \
--cc=suzuki.poulose@arm.com \
--cc=yuzenghui@huawei.com \
--cc=yuzhao@google.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;
as well as URLs for NNTP newsgroup(s).