From: christoffer.dall@linaro.org (Christoffer Dall)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH RESEND v2 7/8] KVM: arm-vgic: Add GICD_SPENDSGIR and GICD_CPENDSGIR handlers
Date: Sun, 27 Oct 2013 17:20:52 +0000 [thread overview]
Message-ID: <20131027172052.GD21180@lvm> (raw)
In-Reply-To: <775b0df085e5a39ab9006e20d72f1bb7@www.loen.fr>
On Wed, Oct 23, 2013 at 05:00:43PM +0100, Marc Zyngier wrote:
> On 2013-10-22 10:08, Christoffer Dall wrote:
> >Handle MMIO accesses to the two registers which should support
> >both the
> >case where the VMs want to read/write either of these registers
> >and the
> >case where user space reads/writes these registers to do
> >save/restore of
> >the VGIC state.
> >
> >Note that the added complexity compared to simple set/clear enable
> >registers stems from the bookkeping of source cpu ids. It may be
> >possible to change the underlying data structure to simplify the
> >complexity, but since this is not in the critical path, at all,
> >this is
> >left as an interesting excercise to the reader.
> >
> >Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
> >Reviewed-by: Alexander Graf <agraf@suse.de>
> >
> >---
> >Changelog[v2]:
> > - Use struct kvm_exit_mmio accessors for ->data field.
> >---
> > virt/kvm/arm/vgic.c | 114
> >++++++++++++++++++++++++++++++++++++++++++++++++++-
> > 1 file changed, 112 insertions(+), 2 deletions(-)
> >
> >diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c
> >index f2dc72a..4e8c3ab 100644
> >--- a/virt/kvm/arm/vgic.c
> >+++ b/virt/kvm/arm/vgic.c
> >@@ -589,18 +589,128 @@ static bool handle_mmio_sgi_reg(struct
> >kvm_vcpu *vcpu,
> > return false;
> > }
> >
> >+static void read_sgi_set_clear(struct kvm_vcpu *vcpu,
> >+ struct kvm_exit_mmio *mmio,
> >+ phys_addr_t offset)
>
> set_clear is a bit unclear. How about reset?
>
it's not a reset, it handles reads of the clear/set pending registers:
/* Handle reads of GICD_CPENDSGIRn and GICD_SPENDSGIRn */
static void read_set_clear_sgi_pend_reg(...)
Does that work?
> >+{
> >+ struct vgic_dist *dist = &vcpu->kvm->arch.vgic;
> >+ struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
> >+ int i, sgi, cpu;
> >+ int min_sgi = (offset & ~0x3) * 4;
> >+ int max_sgi = min_sgi + 3;
> >+ int vcpu_id = vcpu->vcpu_id;
> >+ u32 lr, reg = 0;
> >+
> >+ /* Copy source SGIs from distributor side */
> >+ for (sgi = min_sgi; sgi <= max_sgi; sgi++) {
> >+ int shift = 8 * (sgi - min_sgi);
> >+ reg |= (u32)dist->irq_sgi_sources[vcpu_id][sgi] << shift;
> >+ }
> >+
> >+ /* Copy source SGIs already on LRs */
> >+ for_each_set_bit(i, vgic_cpu->lr_used, vgic_cpu->nr_lr) {
> >+ lr = vgic_cpu->vgic_lr[i];
> >+ sgi = lr & GICH_LR_VIRTUALID;
> >+ cpu = (lr & GICH_LR_PHYSID_CPUID) >> GICH_LR_PHYSID_CPUID_SHIFT;
>
> Please wrap these lr accesses into separate functions. There is
> quite a bit of duplication in this patch and I wonder if we could
> factor things a bit.
>
> At least, please isolate what is emulation related from what is
> actually what the underlying HW provides. It will help mitigating my
> headache in the future... ;-)
>
hmmm, yeah, this actually quite sucks, and the problems repeats itself
for other pending registers as well.
Making defines for the loop logic will be too ugly macro-mess and having
a looping function with an ops fn pointer will also suck, so I actually
think the solution is quite a different one:
Before accessing any of the register state, make sure everything is
stopped (which is probably something we should have done anyway) and
move all state from the LRs to the distributor.
I will add a separate patch for this in v3.
> >+ if (sgi >= min_sgi && sgi <= max_sgi) {
> >+ if (lr & GICH_LR_STATE)
> >+ reg |= (1 << cpu) << (8 * (sgi - min_sgi));
> >+ }
> >+ }
> >+
> >+ mmio_data_write(mmio, ~0, reg);
> >+}
> >+
> > static bool handle_mmio_sgi_clear(struct kvm_vcpu *vcpu,
> > struct kvm_exit_mmio *mmio,
> > phys_addr_t offset)
> > {
> >- return false;
> >+ struct vgic_dist *dist = &vcpu->kvm->arch.vgic;
> >+ struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
> >+ int i, sgi, cpu;
> >+ int min_sgi = (offset & ~0x3) * 4;
> >+ int max_sgi = min_sgi + 3;
> >+ int vcpu_id = vcpu->vcpu_id;
> >+ u32 *lr, reg;
> >+ bool updated = false;
> >+
> >+ if (!mmio->is_write) {
> >+ read_sgi_set_clear(vcpu, mmio, offset);
> >+ return false;
> >+ }
> >+
> >+ reg = mmio_data_read(mmio, ~0);
> >+
> >+ /* Clear pending SGIs on distributor side */
> >+ for (sgi = min_sgi; sgi <= max_sgi; sgi++) {
> >+ u8 mask = reg >> (8 * (sgi - min_sgi));
> >+ if (dist->irq_sgi_sources[vcpu_id][sgi] & mask)
> >+ updated = true;
> >+ dist->irq_sgi_sources[vcpu_id][sgi] &= ~mask;
> >+ }
> >+
> >+ /* Clear SGIs already on LRs */
> >+ for_each_set_bit(i, vgic_cpu->lr_used, vgic_cpu->nr_lr) {
> >+ lr = &vgic_cpu->vgic_lr[i];
> >+ sgi = *lr & GICH_LR_VIRTUALID;
> >+ cpu = (*lr & GICH_LR_PHYSID_CPUID) >> GICH_LR_PHYSID_CPUID_SHIFT;
> >+
> >+ if (sgi >= min_sgi && sgi <= max_sgi) {
> >+ if (reg & ((1 << cpu) << (8 * (sgi - min_sgi)))) {
> >+ if (*lr & GICH_LR_PENDING_BIT)
> >+ updated = true;
> >+ *lr &= GICH_LR_PENDING_BIT;
> >+ }
> >+ }
> >+ }
> >+
> >+ return updated;
> > }
> >
> > static bool handle_mmio_sgi_set(struct kvm_vcpu *vcpu,
> > struct kvm_exit_mmio *mmio,
> > phys_addr_t offset)
> > {
> >- return false;
> >+ struct vgic_dist *dist = &vcpu->kvm->arch.vgic;
> >+ struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
> >+ int i, sgi, cpu;
> >+ int min_sgi = (offset & ~0x3) * 4;
> >+ int max_sgi = min_sgi + 3;
> >+ int vcpu_id = vcpu->vcpu_id;
> >+ u32 *lr, reg;
> >+ bool updated = false;
> >+
> >+ if (!mmio->is_write) {
> >+ read_sgi_set_clear(vcpu, mmio, offset);
> >+ return false;
> >+ }
> >+
> >+ reg = mmio_data_read(mmio, ~0);
> >+
> >+ /* Set pending SGIs on distributor side */
> >+ for (sgi = min_sgi; sgi <= max_sgi; sgi++) {
> >+ u8 mask = reg >> (8 * (sgi - min_sgi));
> >+ if ((dist->irq_sgi_sources[vcpu_id][sgi] & mask) != mask)
> >+ updated = true;
> >+ dist->irq_sgi_sources[vcpu_id][sgi] |= mask;
> >+ }
> >+
> >+ /* Set active SGIs already on LRs to pending and active */
> >+ for_each_set_bit(i, vgic_cpu->lr_used, vgic_cpu->nr_lr) {
> >+ lr = &vgic_cpu->vgic_lr[i];
> >+ sgi = *lr & GICH_LR_VIRTUALID;
> >+ cpu = (*lr & GICH_LR_PHYSID_CPUID) >> GICH_LR_PHYSID_CPUID_SHIFT;
> >+
> >+ if (sgi >= min_sgi && sgi <= max_sgi) {
> >+ if (reg & ((1 << cpu) << (8 * (sgi - min_sgi)))) {
> >+ if (!(*lr & GICH_LR_PENDING_BIT))
> >+ updated = true;
> >+ *lr |= GICH_LR_PENDING_BIT;
> >+ }
> >+ }
> >+ }
> >+
> >+ return updated;
> > }
> >
> > /*
>
> Overall, I feel like I've read the same function three times. Hint,
> hint... ;-)
>
Yeah yeah yeah, you're right, this was broken :)
--
Christoffer
next prev parent reply other threads:[~2013-10-27 17:20 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-22 9:08 [PATCH RESEND v2 0/8] Support VGIC save/restore using device control API Christoffer Dall
2013-10-22 9:08 ` [PATCH RESEND v2 1/8] ARM: KVM: Allow creating the VGIC after VCPUs Christoffer Dall
2013-10-22 9:08 ` [PATCH RESEND v2 2/8] KVM: arm-vgic: Support KVM_CREATE_DEVICE for VGIC Christoffer Dall
2013-10-23 14:55 ` Marc Zyngier
2013-10-27 17:18 ` Christoffer Dall
2013-10-22 9:08 ` [PATCH RESEND v2 3/8] KVM: arm-vgic: Set base addr through device API Christoffer Dall
2013-10-23 15:10 ` Marc Zyngier
2013-10-27 17:18 ` Christoffer Dall
2013-10-22 9:08 ` [PATCH RESEND v2 4/8] irqchip: arm-gic: Define additional MMIO offsets and masks Christoffer Dall
2013-10-22 9:08 ` [PATCH RESEND v2 5/8] KVM: arm-vgic: Make vgic mmio functions more generic Christoffer Dall
2013-10-22 9:08 ` [PATCH RESEND v2 6/8] KVM: arm-vgic: Add vgic reg access from dev attr Christoffer Dall
2013-10-23 15:46 ` Marc Zyngier
2013-10-27 17:19 ` Christoffer Dall
2013-10-22 9:08 ` [PATCH RESEND v2 7/8] KVM: arm-vgic: Add GICD_SPENDSGIR and GICD_CPENDSGIR handlers Christoffer Dall
2013-10-23 16:00 ` Marc Zyngier
2013-10-27 17:20 ` Christoffer Dall [this message]
2013-10-22 9:08 ` [PATCH RESEND v2 8/8] KVM: arm-vgic: Support CPU interface reg access Christoffer Dall
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=20131027172052.GD21180@lvm \
--to=christoffer.dall@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
/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).