From: Jonathan Cameron <jonathan.cameron@huawei.com>
To: Steven Price <steven.price@arm.com>
Cc: "Mark Rutland" <mark.rutland@arm.com>,
"Radim Krčmář" <rkrcmar@redhat.com>,
kvm@vger.kernel.org, "Suzuki K Pouloze" <suzuki.poulose@arm.com>,
"Marc Zyngier" <maz@kernel.org>,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
"Russell King" <linux@armlinux.org.uk>,
"James Morse" <james.morse@arm.com>,
linux-arm-kernel@lists.infradead.org,
"Catalin Marinas" <catalin.marinas@arm.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Will Deacon" <will@kernel.org>,
kvmarm@lists.cs.columbia.edu,
"Julien Thierry" <julien.thierry.kdev@gmail.com>
Subject: Re: [PATCH v3 07/10] KVM: arm64: Provide a PV_TIME device to user space
Date: Thu, 22 Aug 2019 12:48:25 +0100 [thread overview]
Message-ID: <20190822124825.000009f1@huawei.com> (raw)
In-Reply-To: <87bc2a01-8cf5-5161-45f8-00384775cf3a@arm.com>
On Thu, 22 Aug 2019 12:11:55 +0100
Steven Price <steven.price@arm.com> wrote:
> On 22/08/2019 11:57, Jonathan Cameron wrote:
> > On Wed, 21 Aug 2019 16:36:53 +0100
> > Steven Price <steven.price@arm.com> wrote:
> >
> >> Allow user space to inform the KVM host where in the physical memory
> >> map the paravirtualized time structures should be located.
> >>
> >> A device is created which provides the base address of an array of
> >> Stolen Time (ST) structures, one for each VCPU. There must be (64 *
> >> total number of VCPUs) bytes of memory available at this location.
> >>
> >> The address is given in terms of the physical address visible to
> >> the guest and must be page aligned. The guest will discover the address
> >> via a hypercall.
> >>
> >> Signed-off-by: Steven Price <steven.price@arm.com>
> >
> > Hi Steven,
> >
> > One general question inline. I'm not particularly familiar with this area
> > of the kernel, so maybe I'm missing something obvious, but having
> > .destroy free the kvm_device which wasn't created in .create seems
> > 'unusual'.
> >
> > Otherwise, FWIW looks good to me.
> >
> > Jonathan
> >
> [...]
> >> +static void kvm_arm_pvtime_destroy(struct kvm_device *dev)
> >> +{
> >> + struct kvm_arch_pvtime *pvtime = &dev->kvm->arch.pvtime;
> >> +
> >> + pvtime->st_base = GPA_INVALID;
> >> + kfree(dev);
> >
> > Nothing to do with your patch as such... All users do the same.
> >
> > This seems miss balanced. Why do we need to free the device by hand
> > when we didn't create it in the create function? I appreciate
> > the comments say this is needed, but as far as I can see every
> > single callback does kfree(dev) at the end which seems an
> > odd thing to do.
>
> Yes I think this is odd too - indeed when I initially wrote this I
> missed off the kfree() call and had to track down the memory leak.
>
> When I looked into potentially tiding this up I found some other
> oddities, e.g. "kvm-xive" (arch/powerpc/kvm/book3s_xive.c) doesn't have
> a destroy callback. But I can't see anything in the common code which
> deals with that case. So I decided to just "go with the flow" at the
> moment, since I don't understand how some of these existing devices work
> (perhaps they are already broken?).
It has a release however and kvm_device_release also removes the
device from the list that would then be cleared by kvm_destroy_devices.
kvm_device_release is a release callback for the file operations so it
'might' be called in all paths.
Fun though, in kvm_ioctl_create_device the error handling for
the anon_inode_getfd calls ops->destroy without checking it exists.
Boom.
Possibly never happens in reality but looks like a bug to me.
Jonathan
>
> Steve
>
> >> +}
> >> +
> >> +static int kvm_arm_pvtime_set_attr(struct kvm_device *dev,
> >> + struct kvm_device_attr *attr)
> >> +{
> >> + struct kvm *kvm = dev->kvm;
> >> + struct kvm_arch_pvtime *pvtime = &kvm->arch.pvtime;
> >> + u64 __user *user = (u64 __user *)attr->addr;
> >> + struct kvm_dev_arm_st_region region;
> >> +
> >> + switch (attr->group) {
> >> + case KVM_DEV_ARM_PV_TIME_REGION:
> >> + if (copy_from_user(®ion, user, sizeof(region)))
> >> + return -EFAULT;
> >> + if (region.gpa & ~PAGE_MASK)
> >> + return -EINVAL;
> >> + if (region.size & ~PAGE_MASK)
> >> + return -EINVAL;
> >> + switch (attr->attr) {
> >> + case KVM_DEV_ARM_PV_TIME_ST:
> >> + if (pvtime->st_base != GPA_INVALID)
> >> + return -EEXIST;
> >> + pvtime->st_base = region.gpa;
> >> + pvtime->st_size = region.size;
> >> + return 0;
> >> + }
> >> + break;
> >> + }
> >> + return -ENXIO;
> >> +}
> >> +
> >> +static int kvm_arm_pvtime_get_attr(struct kvm_device *dev,
> >> + struct kvm_device_attr *attr)
> >> +{
> >> + struct kvm_arch_pvtime *pvtime = &dev->kvm->arch.pvtime;
> >> + u64 __user *user = (u64 __user *)attr->addr;
> >> + struct kvm_dev_arm_st_region region;
> >> +
> >> + switch (attr->group) {
> >> + case KVM_DEV_ARM_PV_TIME_REGION:
> >> + switch (attr->attr) {
> >> + case KVM_DEV_ARM_PV_TIME_ST:
> >> + region.gpa = pvtime->st_base;
> >> + region.size = pvtime->st_size;
> >> + if (copy_to_user(user, ®ion, sizeof(region)))
> >> + return -EFAULT;
> >> + return 0;
> >> + }
> >> + break;
> >> + }
> >> + return -ENXIO;
> >> +}
> >> +
> >> +static int kvm_arm_pvtime_has_attr(struct kvm_device *dev,
> >> + struct kvm_device_attr *attr)
> >> +{
> >> + switch (attr->group) {
> >> + case KVM_DEV_ARM_PV_TIME_REGION:
> >> + switch (attr->attr) {
> >> + case KVM_DEV_ARM_PV_TIME_ST:
> >> + return 0;
> >> + }
> >> + break;
> >> + }
> >> + return -ENXIO;
> >> +}
> >> +
> >> +static const struct kvm_device_ops pvtime_ops = {
> >> + "Arm PV time",
> >> + .create = kvm_arm_pvtime_create,
> >> + .destroy = kvm_arm_pvtime_destroy,
> >> + .set_attr = kvm_arm_pvtime_set_attr,
> >> + .get_attr = kvm_arm_pvtime_get_attr,
> >> + .has_attr = kvm_arm_pvtime_has_attr
> >> +};
> >> +
> >> +void kvm_pvtime_init(void)
> >> +{
> >> + kvm_register_device_ops(&pvtime_ops, KVM_DEV_TYPE_ARM_PV_TIME);
> >> +}
> >
> >
> >
> > _______________________________________________
> > linux-arm-kernel mailing list
> > linux-arm-kernel@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
> >
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2019-08-22 11:48 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-21 15:36 [PATCH v3 00/10] arm64: Stolen time support Steven Price
2019-08-21 15:36 ` [PATCH v3 01/10] KVM: arm64: Document PV-time interface Steven Price
2019-08-27 8:44 ` Christoffer Dall
2019-08-28 11:23 ` Steven Price
2019-08-27 8:57 ` Christoffer Dall
2019-08-28 12:09 ` Steven Price
2019-08-30 9:22 ` Christoffer Dall
2019-08-28 13:49 ` Christoffer Dall
2019-08-29 15:21 ` Steven Price
2019-08-29 17:15 ` Andrew Jones
2019-08-30 8:35 ` Steven Price
2019-08-21 15:36 ` [PATCH v3 02/10] KVM: arm/arm64: Factor out hypercall handling from PSCI code Steven Price
2019-08-21 15:36 ` [PATCH v3 03/10] KVM: arm64: Implement PV_FEATURES call Steven Price
2019-08-21 15:36 ` [PATCH v3 04/10] KVM: Implement kvm_put_guest() Steven Price
2019-08-22 10:29 ` Jonathan Cameron
2019-08-22 10:37 ` Steven Price
2019-08-22 15:28 ` Sean Christopherson
2019-08-22 15:46 ` Steven Price
2019-08-22 16:24 ` Sean Christopherson
2019-08-23 10:33 ` Steven Price
2019-08-21 15:36 ` [PATCH v3 05/10] KVM: arm64: Support stolen time reporting via shared structure Steven Price
2019-08-22 10:39 ` Jonathan Cameron
2019-08-22 11:00 ` Steven Price
2019-08-23 12:07 ` Zenghui Yu
2019-08-23 13:23 ` Steven Price
2019-08-21 15:36 ` [PATCH v3 06/10] KVM: Allow kvm_device_ops to be const Steven Price
2019-08-21 15:36 ` [PATCH v3 07/10] KVM: arm64: Provide a PV_TIME device to user space Steven Price
2019-08-22 10:57 ` Jonathan Cameron
2019-08-22 11:11 ` Steven Price
2019-08-22 11:48 ` Jonathan Cameron [this message]
2019-08-21 15:36 ` [PATCH v3 08/10] arm/arm64: Provide a wrapper for SMCCC 1.1 calls Steven Price
2019-08-21 15:36 ` [PATCH v3 09/10] arm/arm64: Make use of the SMCCC 1.1 wrapper Steven Price
2019-08-21 15:36 ` [PATCH v3 10/10] arm64: Retrieve stolen time as paravirtualized guest Steven Price
2019-08-23 11:45 ` Zenghui Yu
2019-08-23 14:22 ` Steven Price
2019-08-27 12:43 ` Zenghui Yu
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=20190822124825.000009f1@huawei.com \
--to=jonathan.cameron@huawei.com \
--cc=catalin.marinas@arm.com \
--cc=james.morse@arm.com \
--cc=julien.thierry.kdev@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=pbonzini@redhat.com \
--cc=rkrcmar@redhat.com \
--cc=steven.price@arm.com \
--cc=suzuki.poulose@arm.com \
--cc=will@kernel.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).