Message ID | 1530270944-11351-25-git-send-email-suzuki.poulose@arm.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Fri, Jun 29, 2018 at 12:15:44PM +0100, Suzuki K Poulose wrote: > diff --git a/arm/kvm.c b/arm/kvm.c > index 5701d41..b1969be 100644 > --- a/arm/kvm.c > +++ b/arm/kvm.c > @@ -11,6 +11,8 @@ > #include <linux/kvm.h> > #include <linux/sizes.h> > > +unsigned long kvm_arm_type; > + > struct kvm_ext kvm_req_ext[] = { > { DEFINE_KVM_EXT(KVM_CAP_IRQCHIP) }, > { DEFINE_KVM_EXT(KVM_CAP_ONE_REG) }, > @@ -18,6 +20,26 @@ struct kvm_ext kvm_req_ext[] = { > { 0, 0 }, > }; > > +#ifndef KVM_ARM_GET_MAX_VM_PHYS_SHIFT > +#define KVM_ARM_GET_MAX_VM_PHYS_SHIFT _IO(KVMIO, 0x0b) > +#endif > + > +void kvm__arch_init_hyp(struct kvm *kvm) > +{ > + int max_ipa; > + > + max_ipa = ioctl(kvm->sys_fd, KVM_ARM_GET_MAX_VM_PHYS_SHIFT); > + if (max_ipa < 0) > + max_ipa = 40; > + if (!kvm->cfg.arch.phys_shift) > + kvm->cfg.arch.phys_shift = 40; > + if (kvm->cfg.arch.phys_shift > max_ipa) > + die("Requested PA size (%u) is not supported by the host (%ubits)\n", > + kvm->cfg.arch.phys_shift, max_ipa); > + if (kvm->cfg.arch.phys_shift != 40) > + kvm_arm_type = kvm->cfg.arch.phys_shift; > +} Seems a bit weird that the "machine type identifier" to KVM_CREATE_VM is dedicated entirely to holding the physical address shift verbatim. Is this really the ABI? Also, couldn't KVM figure it out automatically if you add memslots at high addresses, making this a niche tunable outside of testing? Will
On Wed, 04 Jul 2018 15:22:42 +0100, Will Deacon <will.deacon@arm.com> wrote: > > On Fri, Jun 29, 2018 at 12:15:44PM +0100, Suzuki K Poulose wrote: > > diff --git a/arm/kvm.c b/arm/kvm.c > > index 5701d41..b1969be 100644 > > --- a/arm/kvm.c > > +++ b/arm/kvm.c > > @@ -11,6 +11,8 @@ > > #include <linux/kvm.h> > > #include <linux/sizes.h> > > > > +unsigned long kvm_arm_type; > > + > > struct kvm_ext kvm_req_ext[] = { > > { DEFINE_KVM_EXT(KVM_CAP_IRQCHIP) }, > > { DEFINE_KVM_EXT(KVM_CAP_ONE_REG) }, > > @@ -18,6 +20,26 @@ struct kvm_ext kvm_req_ext[] = { > > { 0, 0 }, > > }; > > > > +#ifndef KVM_ARM_GET_MAX_VM_PHYS_SHIFT > > +#define KVM_ARM_GET_MAX_VM_PHYS_SHIFT _IO(KVMIO, 0x0b) > > +#endif > > + > > +void kvm__arch_init_hyp(struct kvm *kvm) > > +{ > > + int max_ipa; > > + > > + max_ipa = ioctl(kvm->sys_fd, KVM_ARM_GET_MAX_VM_PHYS_SHIFT); > > + if (max_ipa < 0) > > + max_ipa = 40; > > + if (!kvm->cfg.arch.phys_shift) > > + kvm->cfg.arch.phys_shift = 40; > > + if (kvm->cfg.arch.phys_shift > max_ipa) > > + die("Requested PA size (%u) is not supported by the host (%ubits)\n", > > + kvm->cfg.arch.phys_shift, max_ipa); > > + if (kvm->cfg.arch.phys_shift != 40) > > + kvm_arm_type = kvm->cfg.arch.phys_shift; > > +} > > Seems a bit weird that the "machine type identifier" to KVM_CREATE_VM is > dedicated entirely to holding the physical address shift verbatim. Is this > really the ABI? > > Also, couldn't KVM figure it out automatically if you add memslots at high > addresses, making this a niche tunable outside of testing? Not really. Let's say I want my IPA space split in two: memory covers the low 47 bit, and I want MMIO spanning the top 47 bit. With your scheme, you'd end-up with a 47bit IPA space, while you really want 48 bits (MMIO space implemented by userspace isn't registered to the kernel). M.
On Wed, Jul 04, 2018 at 03:41:18PM +0100, Marc Zyngier wrote: > On Wed, 04 Jul 2018 15:22:42 +0100, > Will Deacon <will.deacon@arm.com> wrote: > > > > On Fri, Jun 29, 2018 at 12:15:44PM +0100, Suzuki K Poulose wrote: > > > diff --git a/arm/kvm.c b/arm/kvm.c > > > index 5701d41..b1969be 100644 > > > --- a/arm/kvm.c > > > +++ b/arm/kvm.c > > > @@ -11,6 +11,8 @@ > > > #include <linux/kvm.h> > > > #include <linux/sizes.h> > > > > > > +unsigned long kvm_arm_type; > > > + > > > struct kvm_ext kvm_req_ext[] = { > > > { DEFINE_KVM_EXT(KVM_CAP_IRQCHIP) }, > > > { DEFINE_KVM_EXT(KVM_CAP_ONE_REG) }, > > > @@ -18,6 +20,26 @@ struct kvm_ext kvm_req_ext[] = { > > > { 0, 0 }, > > > }; > > > > > > +#ifndef KVM_ARM_GET_MAX_VM_PHYS_SHIFT > > > +#define KVM_ARM_GET_MAX_VM_PHYS_SHIFT _IO(KVMIO, 0x0b) > > > +#endif > > > + > > > +void kvm__arch_init_hyp(struct kvm *kvm) > > > +{ > > > + int max_ipa; > > > + > > > + max_ipa = ioctl(kvm->sys_fd, KVM_ARM_GET_MAX_VM_PHYS_SHIFT); > > > + if (max_ipa < 0) > > > + max_ipa = 40; > > > + if (!kvm->cfg.arch.phys_shift) > > > + kvm->cfg.arch.phys_shift = 40; > > > + if (kvm->cfg.arch.phys_shift > max_ipa) > > > + die("Requested PA size (%u) is not supported by the host (%ubits)\n", > > > + kvm->cfg.arch.phys_shift, max_ipa); > > > + if (kvm->cfg.arch.phys_shift != 40) > > > + kvm_arm_type = kvm->cfg.arch.phys_shift; > > > +} > > > > Seems a bit weird that the "machine type identifier" to KVM_CREATE_VM is > > dedicated entirely to holding the physical address shift verbatim. Is this > > really the ABI? > > > > Also, couldn't KVM figure it out automatically if you add memslots at high > > addresses, making this a niche tunable outside of testing? > > Not really. Let's say I want my IPA space split in two: memory covers > the low 47 bit, and I want MMIO spanning the top 47 bit. With your > scheme, you'd end-up with a 47bit IPA space, while you really want 48 > bits (MMIO space implemented by userspace isn't registered to the > kernel). That still sounds quite niche for a VM. Does QEMU do that? In any case, having KVM automatically increase the IPA bits to cover the memslots it knows about would make sense to me, and also be sufficient for kvmtool without us having to add an extra command-line argument. The MMIO case might be better dealt with by having a way to register MMIO regions rather than having the PA bits exposed directly. Will
Hi Will, On 07/04/2018 03:22 PM, Will Deacon wrote: > On Fri, Jun 29, 2018 at 12:15:44PM +0100, Suzuki K Poulose wrote: >> diff --git a/arm/kvm.c b/arm/kvm.c >> index 5701d41..b1969be 100644 >> --- a/arm/kvm.c >> +++ b/arm/kvm.c >> @@ -11,6 +11,8 @@ >> #include <linux/kvm.h> >> #include <linux/sizes.h> >> >> +unsigned long kvm_arm_type; >> + >> struct kvm_ext kvm_req_ext[] = { >> { DEFINE_KVM_EXT(KVM_CAP_IRQCHIP) }, >> { DEFINE_KVM_EXT(KVM_CAP_ONE_REG) }, >> @@ -18,6 +20,26 @@ struct kvm_ext kvm_req_ext[] = { >> { 0, 0 }, >> }; >> >> +#ifndef KVM_ARM_GET_MAX_VM_PHYS_SHIFT >> +#define KVM_ARM_GET_MAX_VM_PHYS_SHIFT _IO(KVMIO, 0x0b) >> +#endif >> + >> +void kvm__arch_init_hyp(struct kvm *kvm) >> +{ >> + int max_ipa; >> + >> + max_ipa = ioctl(kvm->sys_fd, KVM_ARM_GET_MAX_VM_PHYS_SHIFT); >> + if (max_ipa < 0) >> + max_ipa = 40; >> + if (!kvm->cfg.arch.phys_shift) >> + kvm->cfg.arch.phys_shift = 40; >> + if (kvm->cfg.arch.phys_shift > max_ipa) >> + die("Requested PA size (%u) is not supported by the host (%ubits)\n", >> + kvm->cfg.arch.phys_shift, max_ipa); >> + if (kvm->cfg.arch.phys_shift != 40) >> + kvm_arm_type = kvm->cfg.arch.phys_shift; >> +} > > Seems a bit weird that the "machine type identifier" to KVM_CREATE_VM is > dedicated entirely to holding the physical address shift verbatim. Is this > really the ABI? The bits[7:0] of the machine type has been reserved for the IPA shift. This version is missing the updates to the ABI documentation, I have it for the next version. > > Also, couldn't KVM figure it out automatically if you add memslots at high > addresses, making this a niche tunable outside of testing? The stage2 pgd size is really dependent on the max IPA. Also, unlike the stage1 (where the maximum size will be 1 page), the size can go upto 16 pages (and different number of levels due to concatenation), so we need to finalize this at least before the first memory gets mapped (RAM or Device). That implies, we cannot wait until all the memory slots are created. The first version of the series added a separate ioctl for specifying the limit, which had its own complexities. So, this ABI was suggested to keep things simpler. Suzuki
On 4 July 2018 at 16:51, Will Deacon <will.deacon@arm.com> wrote: > On Wed, Jul 04, 2018 at 03:41:18PM +0100, Marc Zyngier wrote: >> Not really. Let's say I want my IPA space split in two: memory covers >> the low 47 bit, and I want MMIO spanning the top 47 bit. With your >> scheme, you'd end-up with a 47bit IPA space, while you really want 48 >> bits (MMIO space implemented by userspace isn't registered to the >> kernel). > > That still sounds quite niche for a VM. Does QEMU do that? Not at 47 bits, but we have RAM up to the 256GB mark, and MMIO above that (including a large PCI window), so the general arrangement of having the top end of the IPA space not necessarily be things we've told the kernel about definitely exists. thanks -- PMM
Hi, On 07/05/2018 09:51 AM, Peter Maydell wrote: > On 4 July 2018 at 16:51, Will Deacon <will.deacon@arm.com> wrote: >> On Wed, Jul 04, 2018 at 03:41:18PM +0100, Marc Zyngier wrote: >>> Not really. Let's say I want my IPA space split in two: memory covers >>> the low 47 bit, and I want MMIO spanning the top 47 bit. With your >>> scheme, you'd end-up with a 47bit IPA space, while you really want 48 >>> bits (MMIO space implemented by userspace isn't registered to the >>> kernel). >> >> That still sounds quite niche for a VM. Does QEMU do that? > > Not at 47 bits, but we have RAM up to the 256GB mark, and > MMIO above that (including a large PCI window), so the general > arrangement of having the top end of the IPA space not > necessarily be things we've told the kernel about definitely > exists. Is this document (2012) still a reference document? http://infocenter.arm.com/help/topic/com.arm.doc.den0001c/DEN0001C_principles_of_arm_memory_maps.pdf (especially Fig 5?) Peter, comments in QEMU hw/arm/virt.c suggested next RAM chunk should be added at 2TB. This doc suggests to put it at 8TB. I understand the PA memory map only is suggested but shouldn't we align? Thanks Eric > > thanks > -- PMM > _______________________________________________ > kvmarm mailing list > kvmarm@lists.cs.columbia.edu > https://lists.cs.columbia.edu/mailman/listinfo/kvmarm >
diff --git a/arm/include/arm-common/kvm-arch.h b/arm/include/arm-common/kvm-arch.h index b29b4b1..d77f3ac 100644 --- a/arm/include/arm-common/kvm-arch.h +++ b/arm/include/arm-common/kvm-arch.h @@ -44,7 +44,11 @@ #define KVM_IRQ_OFFSET GIC_SPI_IRQ_BASE -#define KVM_VM_TYPE 0 +extern unsigned long kvm_arm_type; +extern void kvm__arch_init_hyp(struct kvm *kvm); + +#define KVM_VM_TYPE kvm_arm_type +#define kvm__arch_init_hyp kvm__arch_init_hyp #define VIRTIO_DEFAULT_TRANS(kvm) \ ((kvm)->cfg.arch.virtio_trans_pci ? VIRTIO_PCI : VIRTIO_MMIO) diff --git a/arm/kvm.c b/arm/kvm.c index 5701d41..b1969be 100644 --- a/arm/kvm.c +++ b/arm/kvm.c @@ -11,6 +11,8 @@ #include <linux/kvm.h> #include <linux/sizes.h> +unsigned long kvm_arm_type; + struct kvm_ext kvm_req_ext[] = { { DEFINE_KVM_EXT(KVM_CAP_IRQCHIP) }, { DEFINE_KVM_EXT(KVM_CAP_ONE_REG) }, @@ -18,6 +20,26 @@ struct kvm_ext kvm_req_ext[] = { { 0, 0 }, }; +#ifndef KVM_ARM_GET_MAX_VM_PHYS_SHIFT +#define KVM_ARM_GET_MAX_VM_PHYS_SHIFT _IO(KVMIO, 0x0b) +#endif + +void kvm__arch_init_hyp(struct kvm *kvm) +{ + int max_ipa; + + max_ipa = ioctl(kvm->sys_fd, KVM_ARM_GET_MAX_VM_PHYS_SHIFT); + if (max_ipa < 0) + max_ipa = 40; + if (!kvm->cfg.arch.phys_shift) + kvm->cfg.arch.phys_shift = 40; + if (kvm->cfg.arch.phys_shift > max_ipa) + die("Requested PA size (%u) is not supported by the host (%ubits)\n", + kvm->cfg.arch.phys_shift, max_ipa); + if (kvm->cfg.arch.phys_shift != 40) + kvm_arm_type = kvm->cfg.arch.phys_shift; +} + bool kvm__arch_cpu_supports_vm(void) { /* The KVM capability check is enough. */
Specify the physical size for the VM encoded in the vm type. Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com> --- arm/include/arm-common/kvm-arch.h | 6 +++++- arm/kvm.c | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-)