Message ID | 1522156531-28348-22-git-send-email-suzuki.poulose@arm.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Hi Suzuki, On 27/03/18 14:15, Suzuki K Poulose wrote: > 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 | 21 +++++++++++++++++++++ > 2 files changed, 26 insertions(+), 1 deletion(-) > > diff --git a/arm/include/arm-common/kvm-arch.h b/arm/include/arm-common/kvm-arch.h > index ca7ab0f..64bc92a 100644 > --- a/arm/include/arm-common/kvm-arch.h > +++ b/arm/include/arm-common/kvm-arch.h > @@ -42,7 +42,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..a9a9140 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,25 @@ 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, 0x0a) > +#endif Once the IOCTL is agreed, I think you would need to update include/linux/kvm.h. > + > +void kvm__arch_init_hyp(struct kvm *kvm) > +{ > + unsigned 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); > + kvm_arm_type = kvm->cfg.arch.phys_shift; FWIW, older Linux will not accept a KVM type other than 0. So I think the best would be to bail out if KVM_ARM_GET_MAX_VM_PHYS_SHIFT does not exist. For safety, you could even check that arch.phys_shift is always 40 when running under older Linux. Cheers,
Hi, On 27/03/18 14:15, Suzuki K Poulose wrote: > diff --git a/arm/kvm.c b/arm/kvm.c > index 5701d41..a9a9140 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,25 @@ 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, 0x0a) > +#endif > + > +void kvm__arch_init_hyp(struct kvm *kvm) > +{ > + unsigned max_ipa; > + > + max_ipa = ioctl(kvm->sys_fd, KVM_ARM_GET_MAX_VM_PHYS_SHIFT); > + if (max_ipa < 0) Another issues spotted while doing some testing. This will always be false because max_ipa is unsigned. I think we want to turn max_ipa to signed. Cheers,
On 30/04/18 15:17, Julien Grall wrote: > Hi, > > On 27/03/18 14:15, Suzuki K Poulose wrote: >> diff --git a/arm/kvm.c b/arm/kvm.c >> index 5701d41..a9a9140 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,25 @@ 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, 0x0a) >> +#endif >> + >> +void kvm__arch_init_hyp(struct kvm *kvm) >> +{ >> + unsigned max_ipa; >> + >> + max_ipa = ioctl(kvm->sys_fd, KVM_ARM_GET_MAX_VM_PHYS_SHIFT); >> + if (max_ipa < 0) > > Another issues spotted while doing some testing. This will always be false because max_ipa is unsigned. > > I think we want to turn max_ipa to signed. Good catch. I will fix it. Cheers Suzuki
diff --git a/arm/include/arm-common/kvm-arch.h b/arm/include/arm-common/kvm-arch.h index ca7ab0f..64bc92a 100644 --- a/arm/include/arm-common/kvm-arch.h +++ b/arm/include/arm-common/kvm-arch.h @@ -42,7 +42,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..a9a9140 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,25 @@ 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, 0x0a) +#endif + +void kvm__arch_init_hyp(struct kvm *kvm) +{ + unsigned 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); + 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 | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-)