From: Will Deacon <will@kernel.org>
To: Marc Zyngier <maz@kernel.org>
Cc: Yanan Wang <wangyanan55@huawei.com>,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
Catalin Marinas <catalin.marinas@arm.com>,
James Morse <james.morse@arm.com>,
Julien Thierry <julien.thierry.kdev@gmail.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Gavin Shan <gshan@redhat.com>,
Quentin Perret <qperret@google.com>,
wanghaibin.wang@huawei.com, yezengruan@huawei.com,
zhukeqian1@huawei.com, yuzenghui@huawei.com,
jiangkunkun@huawei.com, wangjingyi11@huawei.com,
lushenming@huawei.com
Subject: Re: [RFC PATCH] KVM: arm64: Add prejudgement for relaxing permissions only case in stage2 translation fault handler
Date: Fri, 11 Dec 2020 10:00:27 +0000 [thread overview]
Message-ID: <20201211100026.GA11352@willie-the-truck> (raw)
In-Reply-To: <8d006755e5afce7e49b03993316c4fcc@kernel.org>
On Fri, Dec 11, 2020 at 09:49:28AM +0000, Marc Zyngier wrote:
> On 2020-12-11 08:01, Yanan Wang wrote:
> > @@ -461,25 +462,56 @@ static int stage2_map_set_prot_attr(enum
> > kvm_pgtable_prot prot,
> > return 0;
> > }
> >
> > +static bool stage2_set_valid_leaf_pte_pre(u64 addr, u32 level,
> > + kvm_pte_t *ptep, kvm_pte_t new,
> > + struct stage2_map_data *data)
> > +{
> > + kvm_pte_t old = *ptep, old_attr, new_attr;
> > +
> > + if ((old ^ new) & (~KVM_PTE_LEAF_ATTR_PERMS))
> > + return false;
> > +
> > + /*
> > + * Skip updating if we are trying to recreate exactly the same mapping
> > + * or to reduce the access permissions only. And update the valid leaf
> > + * PTE without break-before-make if we are trying to add more access
> > + * permissions only.
> > + */
> > + old_attr = (old & KVM_PTE_LEAF_ATTR_PERMS) ^
> > KVM_PTE_LEAF_ATTR_HI_S2_XN;
> > + new_attr = (new & KVM_PTE_LEAF_ATTR_PERMS) ^
> > KVM_PTE_LEAF_ATTR_HI_S2_XN;
> > + if (new_attr <= old_attr)
> > + return true;
> > +
> > + WRITE_ONCE(*ptep, new);
> > + kvm_call_hyp(__kvm_tlb_flush_vmid_ipa, data->mmu, addr, level);
>
> I think what bothers me the most here is that we are turning a mapping into
> a permission update, which makes the code really hard to read, and mixes
> two things that were so far separate.
>
> I wonder whether we should instead abort the update and simply take the
> fault
> again, if we ever need to do it.
That's a nice idea. If we could enforce that we don't alter permissions on
the map path, and instead just return e.g. -EAGAIN then that would be a
very neat solution and would cement the permission vs translation fault
division.
Will
next prev parent reply other threads:[~2020-12-11 10:02 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-11 8:01 [RFC PATCH 0/1] Add prejudgement for relaxing permissions only case Yanan Wang
2020-12-11 8:01 ` [RFC PATCH] KVM: arm64: Add prejudgement for relaxing permissions only case in stage2 translation fault handler Yanan Wang
2020-12-11 9:49 ` Marc Zyngier
2020-12-11 10:00 ` Will Deacon [this message]
2020-12-14 7:20 ` wangyanan (Y)
2020-12-15 13:18 ` Marc Zyngier
2020-12-14 7:20 ` wangyanan (Y)
2020-12-11 9:53 ` Will Deacon
2020-12-14 7:20 ` wangyanan (Y)
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=20201211100026.GA11352@willie-the-truck \
--to=will@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=gshan@redhat.com \
--cc=james.morse@arm.com \
--cc=jiangkunkun@huawei.com \
--cc=julien.thierry.kdev@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lushenming@huawei.com \
--cc=maz@kernel.org \
--cc=qperret@google.com \
--cc=suzuki.poulose@arm.com \
--cc=wanghaibin.wang@huawei.com \
--cc=wangjingyi11@huawei.com \
--cc=wangyanan55@huawei.com \
--cc=yezengruan@huawei.com \
--cc=yuzenghui@huawei.com \
--cc=zhukeqian1@huawei.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).