From: Shameerali Kolothum Thodi <shameerali.kolothum.thodi@huawei.com>
To: Oliver Upton <oliver.upton@linux.dev>
Cc: "kvmarm@lists.linux.dev" <kvmarm@lists.linux.dev>,
"iommu@lists.linux.dev" <iommu@lists.linux.dev>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
Linuxarm <linuxarm@huawei.com>,
"kevin.tian@intel.com" <kevin.tian@intel.com>,
"jgg@ziepe.ca" <jgg@ziepe.ca>,
"alex.williamson@redhat.com" <alex.williamson@redhat.com>,
"maz@kernel.org" <maz@kernel.org>,
"will@kernel.org" <will@kernel.org>,
"robin.murphy@arm.com" <robin.murphy@arm.com>,
"jean-philippe@linaro.org" <jean-philippe@linaro.org>,
Jonathan Cameron <jonathan.cameron@huawei.com>
Subject: RE: [RFC PATCH v2 2/7] KVM: arm64: Introduce support to pin VMIDs
Date: Mon, 24 Jun 2024 19:34:42 +0000 [thread overview]
Message-ID: <99b822b154504531b490055bc0f4006c@huawei.com> (raw)
In-Reply-To: <ZnnHbM0p8amCqkeJ@linux.dev>
> -----Original Message-----
> From: Oliver Upton <oliver.upton@linux.dev>
> Sent: Monday, June 24, 2024 8:22 PM
> To: Shameerali Kolothum Thodi <shameerali.kolothum.thodi@huawei.com>
> Cc: kvmarm@lists.linux.dev; iommu@lists.linux.dev; linux-arm-
> kernel@lists.infradead.org; Linuxarm <linuxarm@huawei.com>;
> kevin.tian@intel.com; jgg@ziepe.ca; alex.williamson@redhat.com;
> maz@kernel.org; will@kernel.org; robin.murphy@arm.com; jean-
> philippe@linaro.org; Jonathan Cameron <jonathan.cameron@huawei.com>
> Subject: Re: [RFC PATCH v2 2/7] KVM: arm64: Introduce support to pin
> VMIDs
>
> Hi Shameer,
>
> On Thu, Feb 08, 2024 at 03:18:32PM +0000, Shameer Kolothum wrote:
>
> [...]
>
> > +unsigned long kvm_arm_pinned_vmid_get(struct kvm_vmid *kvm_vmid)
> > +{
> > + unsigned long flags;
> > + u64 vmid;
> > +
> > + if (!pinned_vmid_map)
> > + return 0;
>
> Like I'd mentioned over in the other thread, returning 0 for error
> conditions is rather confusing unless one is staring at the VMID
> allocator code.
Agree. It gives the impression VMID 0 is valid.
>
> Can you rework this to return an actual error (e.g. -EINVAL) on failure?
Ok.
>
> > + raw_spin_lock_irqsave(&cpu_vmid_lock, flags);
> > +
> > + vmid = atomic64_read(&kvm_vmid->id);
> > +
> > + if (refcount_inc_not_zero(&kvm_vmid->pinned))
> > + goto out_unlock;
> > +
> > + if (nr_pinned_vmids >= max_pinned_vmids) {
> > + vmid = 0;
> > + goto out_unlock;
> > + }
>
> You need to decrement the refcount in this error path.
Hmm..do we? We are here means refcount is zero, right?
>
> > +
> > + /*
> > + * If we went through one or more rollover since that VMID was
> > + * used, make sure it is still valid, or generate a new one.
> > + */
> > + if (!vmid_gen_match(vmid))
> > + vmid = new_vmid(kvm_vmid);
> > +
> > + nr_pinned_vmids++;
> > + __set_bit(vmid2idx(vmid), pinned_vmid_map);
> > + refcount_set(&kvm_vmid->pinned, 1);
> > +
> > +out_unlock:
> > + raw_spin_unlock_irqrestore(&cpu_vmid_lock, flags);
> > +
> > + vmid &= ~VMID_MASK;
> > +
> > + return vmid;
> > +}
> > +
> > +void kvm_arm_pinned_vmid_put(struct kvm_vmid *kvm_vmid)
> > +{
> > + unsigned long flags;
> > + u64 vmid = atomic64_read(&kvm_vmid->id);
> > +
> > + if (!pinned_vmid_map)
> > + return;
> > +
> > + raw_spin_lock_irqsave(&cpu_vmid_lock, flags);
> > +
> > + if (refcount_dec_and_test(&kvm_vmid->pinned)) {
> > + __clear_bit(vmid2idx(vmid), pinned_vmid_map);
> > + nr_pinned_vmids--;
> > + }
> > +
> > + raw_spin_unlock_irqrestore(&cpu_vmid_lock, flags);
> > +}
> > +
> > /*
> > * Initialize the VMID allocator
> > */
> > @@ -191,10 +263,20 @@ int __init kvm_arm_vmid_alloc_init(void)
> > if (!vmid_map)
> > return -ENOMEM;
> >
> > + pinned_vmid_map = bitmap_zalloc(NUM_USER_VMIDS,
> GFP_KERNEL);
> > + nr_pinned_vmids = 0;
> > +
> > + /*
> > + * Ensure we have at least one emty slot available after rollover
>
> typo: empty
Thanks,
Shameer
next prev parent reply other threads:[~2024-06-24 19:34 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-08 15:18 [RFC PATCH v2 0/7] iommu/arm-smmu-v3: Use pinned KVM VMID for stage 2 Shameer Kolothum
2024-02-08 15:18 ` [RFC PATCH v2 1/7] KVM: Add generic infrastructure to support pinned VMIDs Shameer Kolothum
2024-06-24 15:48 ` Sean Christopherson
2024-02-08 15:18 ` [RFC PATCH v2 2/7] KVM: arm64: Introduce support to pin VMIDs Shameer Kolothum
2024-06-24 19:22 ` Oliver Upton
2024-06-24 19:34 ` Shameerali Kolothum Thodi [this message]
2024-06-24 19:52 ` Oliver Upton
2024-02-08 15:18 ` [RFC PATCH v2 3/7] KVM: arm64: Add interfaces for pinned VMID support Shameer Kolothum
2024-02-08 15:18 ` [RFC PATCH v2 4/7] iommufd: Associate kvm pointer to iommufd ctx Shameer Kolothum
2024-02-08 15:42 ` Jason Gunthorpe
2024-06-24 16:53 ` Sean Christopherson
2024-06-24 17:07 ` Jason Gunthorpe
2024-06-24 17:54 ` Sean Christopherson
2024-06-24 18:01 ` Jason Gunthorpe
2024-06-24 19:12 ` Oliver Upton
2024-06-24 19:29 ` Sean Christopherson
2024-06-24 19:51 ` Oliver Upton
2024-06-24 22:35 ` Jason Gunthorpe
2024-06-25 2:21 ` Tian, Kevin
2024-06-24 19:13 ` Shameerali Kolothum Thodi
2024-06-25 1:53 ` Tian, Kevin
2024-02-08 15:18 ` [RFC PATCH v2 5/7] iommu: Pass in kvm pointer to domain_alloc_user Shameer Kolothum
2024-02-08 15:43 ` Jason Gunthorpe
2024-02-08 15:18 ` [RFC PATCH v2 6/7] iommu/arm-smmu-v3: Use KVM VMID for s2 stage Shameer Kolothum
2024-02-08 15:59 ` Jason Gunthorpe
2024-02-08 16:14 ` Shameerali Kolothum Thodi
2024-02-08 16:26 ` Jason Gunthorpe
2024-02-08 16:36 ` Shameerali Kolothum Thodi
2024-02-08 15:18 ` [RFC PATCH v2 7/7] iommu/arm-smmu-v3: Enable broadcast TLB maintenance Shameer Kolothum
2024-02-08 15:35 ` [RFC PATCH v2 0/7] iommu/arm-smmu-v3: Use pinned KVM VMID for stage 2 Jason Gunthorpe
2024-02-08 15:49 ` Shameerali Kolothum Thodi
2024-02-08 16:07 ` Jason Gunthorpe
2024-02-09 11:58 ` Jean-Philippe Brucker
2024-02-09 12:48 ` Jason Gunthorpe
2024-02-09 13:54 ` Shameerali Kolothum Thodi
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=99b822b154504531b490055bc0f4006c@huawei.com \
--to=shameerali.kolothum.thodi@huawei.com \
--cc=alex.williamson@redhat.com \
--cc=iommu@lists.linux.dev \
--cc=jean-philippe@linaro.org \
--cc=jgg@ziepe.ca \
--cc=jonathan.cameron@huawei.com \
--cc=kevin.tian@intel.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linuxarm@huawei.com \
--cc=maz@kernel.org \
--cc=oliver.upton@linux.dev \
--cc=robin.murphy@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