From: will.deacon@arm.com (Will Deacon)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v4 05/13] ARM: KVM: VGIC accept vcpu and dist base addresses from user space
Date: Mon, 3 Dec 2012 10:40:48 +0000 [thread overview]
Message-ID: <20121203104048.GC18579@mudshark.cambridge.arm.com> (raw)
In-Reply-To: <CANM98qJnobcpkPrro0rMhbONkVEwDE2X3=MK3b-koOT7mnWivA@mail.gmail.com>
On Sat, Dec 01, 2012 at 02:52:13AM +0000, Christoffer Dall wrote:
> On Wed, Nov 28, 2012 at 8:11 AM, Will Deacon <will.deacon@arm.com> wrote:
> > On Sat, Nov 10, 2012 at 03:44:51PM +0000, Christoffer Dall wrote:
> >> + kvm->arch.vgic.vgic_dist_base = addr;
> >> + break;
> >> + case KVM_VGIC_V2_ADDR_TYPE_CPU:
> >> + if (!IS_VGIC_ADDR_UNDEF(vgic->vgic_cpu_base))
> >> + return -EEXIST;
> >> + if (addr + VGIC_CPU_SIZE < addr)
> >> + return -EINVAL;
> >> + kvm->arch.vgic.vgic_cpu_base = addr;
> >> + break;
> >> + default:
> >> + r = -ENODEV;
> >> + }
> >> +
> >> + if (vgic_ioaddr_overlap(kvm)) {
> >> + kvm->arch.vgic.vgic_dist_base = VGIC_ADDR_UNDEF;
> >> + kvm->arch.vgic.vgic_cpu_base = VGIC_ADDR_UNDEF;
> >> + return -EINVAL;
> >
> > Perhaps we could put all the address checking in one place, so that the wrapping
> > round zero checks and the overlap checks can be in the same function?
> >
>
> Like this (?):
Almost:
> diff --git a/Documentation/virtual/kvm/api.txt
> b/Documentation/virtual/kvm/api.txt
> index 7f057a2..0b6b95e 100644
> --- a/Documentation/virtual/kvm/api.txt
> +++ b/Documentation/virtual/kvm/api.txt
> @@ -2163,6 +2163,7 @@ Errors:
> ENXIO: Device not supported on current system
> EEXIST: Address already set
> E2BIG: Address outside guest physical address space
> + EBUSY: Address overlaps with other device range
>
> struct kvm_device_address {
> __u64 id;
> diff --git a/arch/arm/kvm/vgic.c b/arch/arm/kvm/vgic.c
> index f697c14..660fe24 100644
> --- a/arch/arm/kvm/vgic.c
> +++ b/arch/arm/kvm/vgic.c
> @@ -1230,11 +1230,28 @@ static bool vgic_ioaddr_overlap(struct kvm *kvm)
> phys_addr_t cpu = kvm->arch.vgic.vgic_cpu_base;
>
> if (IS_VGIC_ADDR_UNDEF(dist) || IS_VGIC_ADDR_UNDEF(cpu))
> - return false;
> + return 0;
> if ((dist <= cpu && dist + VGIC_DIST_SIZE > cpu) ||
> (cpu <= dist && cpu + VGIC_CPU_SIZE > dist))
> - return true;
> - return false;
> + return -EBUSY;
> + return 0;
> +}
> +
> +static int vgic_ioaddr_assign(struct kvm *kvm, phys_addr_t *ioaddr,
> + phys_addr_t addr, phys_addr_t size)
> +{
> + int ret;
> +
> + if (!IS_VGIC_ADDR_UNDEF(*ioaddr))
> + return -EEXIST;
> + if (addr + size < addr)
> + return -EINVAL;
> +
> + ret = vgic_ioaddr_overlap(kvm);
> + if (ret)
> + return ret;
> + *ioaddr = addr;
> + return ret;
> }
>
> int kvm_vgic_set_addr(struct kvm *kvm, unsigned long type, u64 addr)
> @@ -1251,29 +1268,21 @@ int kvm_vgic_set_addr(struct kvm *kvm,
> unsigned long type, u64 addr)
> mutex_lock(&kvm->lock);
> switch (type) {
> case KVM_VGIC_V2_ADDR_TYPE_DIST:
> - if (!IS_VGIC_ADDR_UNDEF(vgic->vgic_dist_base))
> - return -EEXIST;
> - if (addr + VGIC_DIST_SIZE < addr)
> - return -EINVAL;
> - kvm->arch.vgic.vgic_dist_base = addr;
> + r = vgic_ioaddr_assign(kvm, &vgic->vgic_dist_base,
> + addr, VGIC_DIST_SIZE);
> break;
> case KVM_VGIC_V2_ADDR_TYPE_CPU:
> if (!IS_VGIC_ADDR_UNDEF(vgic->vgic_cpu_base))
> return -EEXIST;
> if (addr + VGIC_CPU_SIZE < addr)
> return -EINVAL;
> - kvm->arch.vgic.vgic_cpu_base = addr;
> + r = vgic_ioaddr_assign(kvm, &vgic->vgic_cpu_base,
> + addr, VGIC_CPU_SIZE);
You've left the checking in here, so now everything is checked twice.
Also, you should probably touch bases with Marc as I'm under the impression
that both of you are looking at addressing my comments so it would be good
to avoid tripping over each other on this.
Will
next prev parent reply other threads:[~2012-12-03 10:40 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-10 15:44 [PATCH v4 00/13] KVM/ARM vGIC support Christoffer Dall
2012-11-10 15:44 ` [PATCH v4 01/13] KVM: ARM: Introduce KVM_SET_DEVICE_ADDRESS ioctl Christoffer Dall
2012-11-10 15:44 ` [PATCH v4 02/13] ARM: KVM: Keep track of currently running vcpus Christoffer Dall
2012-11-28 12:47 ` Will Deacon
2012-11-28 13:15 ` Marc Zyngier
2012-11-30 22:39 ` Christoffer Dall
2012-11-10 15:44 ` [PATCH v4 03/13] ARM: KVM: Initial VGIC infrastructure support Christoffer Dall
2012-11-28 12:49 ` Will Deacon
2012-11-28 13:09 ` Marc Zyngier
2012-11-28 14:13 ` Will Deacon
2012-12-01 2:19 ` Christoffer Dall
2012-11-10 15:44 ` [PATCH v4 04/13] ARM: KVM: Initial VGIC MMIO support code Christoffer Dall
2012-11-12 8:54 ` Dong Aisheng
2012-11-13 13:32 ` Christoffer Dall
2012-11-28 13:09 ` Will Deacon
2012-11-28 13:44 ` Marc Zyngier
2012-11-10 15:44 ` [PATCH v4 05/13] ARM: KVM: VGIC accept vcpu and dist base addresses from user space Christoffer Dall
2012-11-12 8:56 ` Dong Aisheng
2012-11-13 13:35 ` Christoffer Dall
2012-11-28 13:11 ` Will Deacon
2012-11-28 13:22 ` [kvmarm] " Marc Zyngier
2012-12-01 2:52 ` Christoffer Dall
2012-12-01 15:57 ` Christoffer Dall
2012-12-03 10:40 ` Will Deacon [this message]
2012-11-10 15:44 ` [PATCH v4 06/13] ARM: KVM: VGIC distributor handling Christoffer Dall
2012-11-12 9:29 ` Dong Aisheng
2012-11-13 13:38 ` Christoffer Dall
2012-11-28 13:21 ` Will Deacon
2012-11-28 14:35 ` Marc Zyngier
2012-11-10 15:45 ` [PATCH v4 07/13] ARM: KVM: VGIC virtual CPU interface management Christoffer Dall
2012-12-03 13:23 ` Will Deacon
2012-12-03 14:11 ` Marc Zyngier
2012-12-03 14:34 ` Will Deacon
2012-12-03 15:24 ` Marc Zyngier
2012-12-03 14:54 ` Christoffer Dall
2012-11-10 15:45 ` [PATCH v4 08/13] ARM: KVM: vgic: retire queued, disabled interrupts Christoffer Dall
2012-12-03 13:24 ` Will Deacon
2012-11-10 15:45 ` [PATCH v4 09/13] ARM: KVM: VGIC interrupt injection Christoffer Dall
2012-12-03 13:25 ` Will Deacon
2012-12-03 14:21 ` Marc Zyngier
2012-12-03 14:58 ` Christoffer Dall
2012-12-03 19:13 ` Christoffer Dall
2012-12-03 19:22 ` Marc Zyngier
2012-11-10 15:45 ` [PATCH v4 10/13] ARM: KVM: VGIC control interface world switch Christoffer Dall
2012-12-03 13:31 ` Will Deacon
2012-12-03 14:26 ` Marc Zyngier
2012-11-10 15:45 ` [PATCH v4 11/13] ARM: KVM: VGIC initialisation code Christoffer Dall
2012-12-05 10:43 ` Will Deacon
2012-11-10 15:45 ` [PATCH v4 12/13] ARM: KVM: vgic: reduce the number of vcpu kick Christoffer Dall
2012-12-05 10:43 ` Will Deacon
2012-12-05 10:58 ` Russell King - ARM Linux
2012-12-05 12:17 ` Marc Zyngier
2012-12-05 12:29 ` Russell King - ARM Linux
2012-12-05 13:40 ` Marc Zyngier
2012-12-05 15:55 ` Russell King - ARM Linux
2012-12-05 11:16 ` Russell King - ARM Linux
2012-11-10 15:45 ` [PATCH v4 13/13] ARM: KVM: Add VGIC configuration option Christoffer Dall
2012-11-10 19:52 ` Sergei Shtylyov
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=20121203104048.GC18579@mudshark.cambridge.arm.com \
--to=will.deacon@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 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).