All of lore.kernel.org
 help / color / mirror / Atom feed
From: marc.zyngier@arm.com (Marc Zyngier)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 8/8] KVM: arm-vgic: Support CPU interface reg access
Date: Thu, 26 Sep 2013 11:47:28 +0100	[thread overview]
Message-ID: <524410C0.6020201@arm.com> (raw)
In-Reply-To: <20130925211150.GH32311@cbox>

On 25/09/13 22:30, Christoffer Dall wrote:
> On Sun, Aug 25, 2013 at 04:24:20PM +0100, Alexander Graf wrote:
>>
>> On 23.08.2013, at 20:20, Christoffer Dall wrote:
>>
>>> Implement support for the CPU interface register access driven by MMIO
>>> address offsets from the CPU interface base address.  Useful for user
>>> space to support save/restore of the VGIC state.
>>>
>>> This commit adds support only for the same logic as the current VGIC
>>> support, and no more.  For example, the active priority registers are
>>> handled as RAZ/WI, just like setting priorities on the emulated
>>> distributor.
>>>
>>> Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
>>> ---
>>> virt/kvm/arm/vgic.c |   66 +++++++++++++++++++++++++++++++++++++++++++++++----
>>> 1 file changed, 62 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c
>>> index d44b5a1..257dbae 100644
>>> --- a/virt/kvm/arm/vgic.c
>>> +++ b/virt/kvm/arm/vgic.c
>>> @@ -1684,9 +1684,67 @@ int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write)
>>> static bool handle_cpu_mmio_misc(struct kvm_vcpu *vcpu,
>>> 				 struct kvm_exit_mmio *mmio, phys_addr_t offset)
>>> {
>>> -	return true;
>>> +	struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
>>> +	u32 reg, mask = 0, shift = 0;
>>> +	bool updated = false;
>>> +
>>> +	switch (offset & ~0x3) {
>>> +	case GIC_CPU_CTRL:
>>> +		mask = GICH_VMCR_CTRL_MASK;
>>> +		shift = GICH_VMCR_CTRL_SHIFT;
>>> +		break;
>>> +	case GIC_CPU_PRIMASK:
>>> +		mask = GICH_VMCR_PRIMASK_MASK;
>>> +		shift = GICH_VMCR_PRIMASK_SHIFT;
>>> +		break;
>>> +	case GIC_CPU_BINPOINT:
>>> +		mask = GICH_VMCR_BINPOINT_MASK;
>>> +		shift = GICH_VMCR_BINPOINT_SHIFT;
>>> +		break;
>>> +	case GIC_CPU_ALIAS_BINPOINT:
>>> +		mask = GICH_VMCR_ALIAS_BINPOINT_MASK;
>>> +		shift = GICH_VMCR_ALIAS_BINPOINT_SHIFT;
>>> +		break;
>>> +	}
>>> +
>>> +	if (!mmio->is_write) {
>>> +		reg = (vgic_cpu->vgic_vmcr & mask) >> shift;
>>> +		memcpy(mmio->data, &reg, sizeof(reg));
>>> +	} else {
>>> +		memcpy(&reg, mmio->data, sizeof(reg));
>>> +		reg = (reg << shift) & mask;
>>> +		if (reg != (vgic_cpu->vgic_vmcr & mask))
>>> +			updated = true;
>>> +		vgic_cpu->vgic_vmcr &= ~mask;
>>> +		vgic_cpu->vgic_vmcr |= reg;
>>> +	}
>>> +	return updated;
>>> +}
>>> +
>>> +static bool handle_mmio_abpr(struct kvm_vcpu *vcpu,
>>> +			     struct kvm_exit_mmio *mmio, phys_addr_t offset)
>>> +{
>>> +	return handle_cpu_mmio_misc(vcpu, mmio, GIC_CPU_ALIAS_BINPOINT);
>>> +}
>>> +
>>> +static bool handle_cpu_mmio_ident(struct kvm_vcpu *vcpu,
>>> +				  struct kvm_exit_mmio *mmio,
>>> +				  phys_addr_t offset)
>>> +{
>>> +	u32 reg;
>>> +
>>> +	if (mmio->is_write)
>>> +		return false;
>>> +
>>> +	reg = 0x0002043B;
>>
>> This wants a comment and probably also a #define :).
>>
> 
> Marc, where does the 0x4b0 product id code come from for the distributor
> IIDR?

0x4B is the ASCII value for 'K', and the whole thing is intended to read
as KVM/ARM. Call that a feeble attempt at an Easter Egg.

I'd very much refrain from pretending we emulate an existing GICv2
implementation, as the damned thing is behaving very differently from
the hardware.

	M.
-- 
Jazz is not dead. It just smells funny...

WARNING: multiple messages have this Message-ID (diff)
From: Marc Zyngier <marc.zyngier@arm.com>
To: Christoffer Dall <christoffer.dall@linaro.org>
Cc: Alexander Graf <agraf@suse.de>,
	"kvmarm@lists.cs.columbia.edu" <kvmarm@lists.cs.columbia.edu>,
	"linaro-kernel@lists.linaro.org" <linaro-kernel@lists.linaro.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"patches@linaro.org" <patches@linaro.org>
Subject: Re: [PATCH 8/8] KVM: arm-vgic: Support CPU interface reg access
Date: Thu, 26 Sep 2013 11:47:28 +0100	[thread overview]
Message-ID: <524410C0.6020201@arm.com> (raw)
In-Reply-To: <20130925211150.GH32311@cbox>

On 25/09/13 22:30, Christoffer Dall wrote:
> On Sun, Aug 25, 2013 at 04:24:20PM +0100, Alexander Graf wrote:
>>
>> On 23.08.2013, at 20:20, Christoffer Dall wrote:
>>
>>> Implement support for the CPU interface register access driven by MMIO
>>> address offsets from the CPU interface base address.  Useful for user
>>> space to support save/restore of the VGIC state.
>>>
>>> This commit adds support only for the same logic as the current VGIC
>>> support, and no more.  For example, the active priority registers are
>>> handled as RAZ/WI, just like setting priorities on the emulated
>>> distributor.
>>>
>>> Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
>>> ---
>>> virt/kvm/arm/vgic.c |   66 +++++++++++++++++++++++++++++++++++++++++++++++----
>>> 1 file changed, 62 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c
>>> index d44b5a1..257dbae 100644
>>> --- a/virt/kvm/arm/vgic.c
>>> +++ b/virt/kvm/arm/vgic.c
>>> @@ -1684,9 +1684,67 @@ int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write)
>>> static bool handle_cpu_mmio_misc(struct kvm_vcpu *vcpu,
>>> 				 struct kvm_exit_mmio *mmio, phys_addr_t offset)
>>> {
>>> -	return true;
>>> +	struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
>>> +	u32 reg, mask = 0, shift = 0;
>>> +	bool updated = false;
>>> +
>>> +	switch (offset & ~0x3) {
>>> +	case GIC_CPU_CTRL:
>>> +		mask = GICH_VMCR_CTRL_MASK;
>>> +		shift = GICH_VMCR_CTRL_SHIFT;
>>> +		break;
>>> +	case GIC_CPU_PRIMASK:
>>> +		mask = GICH_VMCR_PRIMASK_MASK;
>>> +		shift = GICH_VMCR_PRIMASK_SHIFT;
>>> +		break;
>>> +	case GIC_CPU_BINPOINT:
>>> +		mask = GICH_VMCR_BINPOINT_MASK;
>>> +		shift = GICH_VMCR_BINPOINT_SHIFT;
>>> +		break;
>>> +	case GIC_CPU_ALIAS_BINPOINT:
>>> +		mask = GICH_VMCR_ALIAS_BINPOINT_MASK;
>>> +		shift = GICH_VMCR_ALIAS_BINPOINT_SHIFT;
>>> +		break;
>>> +	}
>>> +
>>> +	if (!mmio->is_write) {
>>> +		reg = (vgic_cpu->vgic_vmcr & mask) >> shift;
>>> +		memcpy(mmio->data, &reg, sizeof(reg));
>>> +	} else {
>>> +		memcpy(&reg, mmio->data, sizeof(reg));
>>> +		reg = (reg << shift) & mask;
>>> +		if (reg != (vgic_cpu->vgic_vmcr & mask))
>>> +			updated = true;
>>> +		vgic_cpu->vgic_vmcr &= ~mask;
>>> +		vgic_cpu->vgic_vmcr |= reg;
>>> +	}
>>> +	return updated;
>>> +}
>>> +
>>> +static bool handle_mmio_abpr(struct kvm_vcpu *vcpu,
>>> +			     struct kvm_exit_mmio *mmio, phys_addr_t offset)
>>> +{
>>> +	return handle_cpu_mmio_misc(vcpu, mmio, GIC_CPU_ALIAS_BINPOINT);
>>> +}
>>> +
>>> +static bool handle_cpu_mmio_ident(struct kvm_vcpu *vcpu,
>>> +				  struct kvm_exit_mmio *mmio,
>>> +				  phys_addr_t offset)
>>> +{
>>> +	u32 reg;
>>> +
>>> +	if (mmio->is_write)
>>> +		return false;
>>> +
>>> +	reg = 0x0002043B;
>>
>> This wants a comment and probably also a #define :).
>>
> 
> Marc, where does the 0x4b0 product id code come from for the distributor
> IIDR?

0x4B is the ASCII value for 'K', and the whole thing is intended to read
as KVM/ARM. Call that a feeble attempt at an Easter Egg.

I'd very much refrain from pretending we emulate an existing GICv2
implementation, as the damned thing is behaving very differently from
the hardware.

	M.
-- 
Jazz is not dead. It just smells funny...


  parent reply	other threads:[~2013-09-26 10:47 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-23 19:19 [PATCH 0/8] Support VGIC save/restore using device control API Christoffer Dall
2013-08-23 19:19 ` Christoffer Dall
2013-08-23 19:19 ` [PATCH 1/8] ARM: KVM: Allow creating the VGIC after VCPUs Christoffer Dall
2013-08-23 19:19   ` Christoffer Dall
2013-08-23 19:20 ` [PATCH 2/8] KVM: arm-vgic: Support KVM_CREATE_DEVICE for VGIC Christoffer Dall
2013-08-23 19:20   ` Christoffer Dall
2013-08-23 19:20 ` [PATCH 3/8] KVM: arm-vgic: Set base addr through device API Christoffer Dall
2013-08-23 19:20   ` Christoffer Dall
2013-08-23 19:20 ` [PATCH 4/8] irqchip: arm-gic: Define additional MMIO offsets and masks Christoffer Dall
2013-08-23 19:20   ` Christoffer Dall
2013-08-23 19:20 ` [PATCH 5/8] KVM: arm-vgic: Make vgic mmio functions more generic Christoffer Dall
2013-08-23 19:20   ` Christoffer Dall
2013-08-23 19:20 ` [PATCH 6/8] KVM: arm-vgic: Add vgic reg access from dev attr Christoffer Dall
2013-08-23 19:20   ` Christoffer Dall
2013-08-25 15:21   ` Alexander Graf
2013-08-25 15:21     ` Alexander Graf
2013-09-25 20:38     ` Christoffer Dall
2013-09-25 20:38       ` Christoffer Dall
2013-09-25 20:49       ` Christoffer Dall
2013-09-25 20:49         ` Christoffer Dall
2013-08-23 19:20 ` [PATCH 7/8] KVM: arm-vgic: Add GICD_SPENDSGIR and GICD_CPENDSGIR handlers Christoffer Dall
2013-08-23 19:20   ` Christoffer Dall
2013-08-23 19:20 ` [PATCH 8/8] KVM: arm-vgic: Support CPU interface reg access Christoffer Dall
2013-08-23 19:20   ` Christoffer Dall
2013-08-25 15:24   ` Alexander Graf
2013-08-25 15:24     ` Alexander Graf
2013-09-25 21:30     ` Christoffer Dall
2013-09-25 21:30       ` Christoffer Dall
2013-09-25 22:37       ` Alexander Graf
2013-09-25 22:37         ` Alexander Graf
2013-09-26  0:54         ` Christoffer Dall
2013-09-26  0:54           ` Christoffer Dall
2013-09-26  1:15           ` Alexander Graf
2013-09-26  1:15             ` Alexander Graf
2013-09-26  1:36             ` Alexander Graf
2013-09-26  1:36               ` Alexander Graf
2013-09-26  1:48               ` Alexander Graf
2013-09-26  1:48                 ` Alexander Graf
2013-09-26  2:49             ` Christoffer Dall
2013-09-26  2:49               ` Christoffer Dall
2013-09-26 10:25               ` Alexander Graf
2013-09-26 10:25                 ` Alexander Graf
2013-09-26 10:47       ` Marc Zyngier [this message]
2013-09-26 10:47         ` Marc Zyngier
2013-08-25 15:24 ` [PATCH 0/8] Support VGIC save/restore using device control API Alexander Graf
2013-08-25 15:24   ` Alexander Graf

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=524410C0.6020201@arm.com \
    --to=marc.zyngier@arm.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.