From: Marc Zyngier <maz@kernel.org>
To: James Morse <james.morse@arm.com>
Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu,
linux-arm-kernel@lists.infradead.org,
Julien Thierry <julien.thierry.kdev@gmail.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
kernel-team@android.com
Subject: Re: [PATCH 3/8] KVM: arm64: Map AArch32 cp15 register to AArch64 sysregs
Date: Tue, 10 Nov 2020 10:14:02 +0000 [thread overview]
Message-ID: <256242247e00a3dba3ab281c3a06c1dc@kernel.org> (raw)
In-Reply-To: <b6628cea-520a-90bd-3c42-82ed2863c4af@arm.com>
On 2020-11-03 18:29, James Morse wrote:
> Hi Marc,
>
> On 02/11/2020 19:16, Marc Zyngier wrote:
>> Move all the cp15 registers over to their AArch64 counterpart.
>> This requires the annotation of a few of them (such as the usual
>> DFAR/IFAR vs FAR_EL1), and a new helper that generates mask/shift
>> pairs for the various configurations.
>
>> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
>> index 26c7c25f8a6d..137818793a4a 100644
>> --- a/arch/arm64/kvm/sys_regs.c
>> +++ b/arch/arm64/kvm/sys_regs.c
>> @@ -138,26 +156,16 @@ static bool access_vm_reg(struct kvm_vcpu *vcpu,
>> const struct sys_reg_desc *r)
>> {
>> bool was_enabled = vcpu_has_cache_enabled(vcpu);
>> - u64 val;
>> - int reg = r->reg;
>> + u64 val, mask, shift;
>>
>> BUG_ON(!p->is_write);
>>
>> - /* See the 32bit mapping in kvm_host.h */
>> - if (p->is_aarch32)
>> - reg = r->reg / 2;
>> + get_access_mask(r, &mask, &shift);
>>
>> - if (!p->is_aarch32 || !p->is_32bit) {
>> - val = p->regval;
>> - } else {
>> - val = vcpu_read_sys_reg(vcpu, reg);
>> - if (r->reg % 2)
>> - val = (p->regval << 32) | (u64)lower_32_bits(val);
>> - else
>> - val = ((u64)upper_32_bits(val) << 32) |
>> - lower_32_bits(p->regval);
>> - }
>> - vcpu_write_sys_reg(vcpu, val, reg);
>
>> + val = vcpu_read_sys_reg(vcpu, r->reg);
>> + val &= ~mask;
>> + val |= (p->regval & (mask >> shift)) << shift;
>> + vcpu_write_sys_reg(vcpu, val, r->reg);
>
> I can't tell if the compiler has worked out ithat it can skip the
> sys_read most of the
> time... Won't some of these trap for a nested VHE hypervisor?
>
> | if (~mask) {
> | val = vcpu_read_sys_reg(vcpu, r->reg);
> | val &= ~mask;
> | }
Seems like a good call. I'm happy to fold that in.
>
>
> But, as the sys_reg arrays already have indirection for this function,
> why does
> access_vm_reg() have to deal with this at all? Its not even needed for
> all the aarch32 registers...
>
>
> | { AA32(LO), Op1( 0), CRn(10), CRm( 2), Op2( 0),
> access_aarch32_alias, NULL, MAIR_EL1 },
>
> Where access_aarch32_alias() does the shift+mask and read_modify-write
> on the sys_reg?
I don't really like the idea of separate handlers. The whole point is to
unify the two view, and I feel like having yet another indirection makes
it harder to maintain.
>
>> kvm_toggle_cache(vcpu, was_enabled);
>> return true;
>
>> @@ -1919,19 +1919,24 @@ static const struct sys_reg_desc
>> cp14_64_regs[] = {
>> */
>> static const struct sys_reg_desc cp15_regs[] = {
>
>> - { Op1( 0), CRn( 2), CRm( 0), Op2( 2), access_vm_reg, NULL, c2_TTBCR
>> },
>
>> + { Op1( 0), CRn( 2), CRm( 0), Op2( 2), access_vm_reg, NULL, TCR_EL1
>> },
>
> Don't look now ... TTBRCR2 means this one is a LO/HI job.
That's the problem with AArch32. You stop looking for a couple of years,
and it decides to throw a new sysreg at you without any notice. WTF?
> (I'm guessing that should be fixed before this series to make the
> backport easy)
I'll work something out as a prologue to this series.
Thanks,
M.
--
Jazz is not dead. It just smells funny...
next prev parent reply other threads:[~2020-11-10 10:14 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-02 19:16 [PATCH 0/8] KVM: arm64: Kill the copro array Marc Zyngier
2020-11-02 19:16 ` [PATCH 1/8] KVM: arm64: Move AArch32 exceptions over to AArch64 sysregs Marc Zyngier
2020-11-03 18:29 ` James Morse
2020-11-10 10:01 ` Marc Zyngier
2020-11-02 19:16 ` [PATCH 2/8] KVM: arm64: Add AArch32 mapping annotation Marc Zyngier
2020-11-02 19:16 ` [PATCH 3/8] KVM: arm64: Map AArch32 cp15 register to AArch64 sysregs Marc Zyngier
2020-11-03 18:29 ` James Morse
2020-11-10 10:14 ` Marc Zyngier [this message]
2020-11-02 19:16 ` [PATCH 4/8] KVM: arm64: Map AArch32 cp14 " Marc Zyngier
2020-11-03 18:29 ` James Morse
2020-11-10 10:27 ` Marc Zyngier
2020-11-02 19:16 ` [PATCH 5/8] KVM: arm64: Drop is_32bit trap attribute Marc Zyngier
2020-11-02 19:16 ` [PATCH 6/8] KVM: arm64: Drop is_aarch32 " Marc Zyngier
2020-11-02 19:16 ` [PATCH 7/8] KVM: arm64: Drop legacy copro shadow register Marc Zyngier
2020-11-02 19:16 ` [PATCH 8/8] KVM: arm64: Drop kvm_coproc.h Marc Zyngier
2020-11-03 18:29 ` [PATCH 0/8] KVM: arm64: Kill the copro array James Morse
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=256242247e00a3dba3ab281c3a06c1dc@kernel.org \
--to=maz@kernel.org \
--cc=james.morse@arm.com \
--cc=julien.thierry.kdev@gmail.com \
--cc=kernel-team@android.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=suzuki.poulose@arm.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).