From: Baolu Lu <baolu.lu@linux.intel.com>
To: Yi Liu <yi.l.liu@intel.com>, joro@8bytes.org, kevin.tian@intel.com
Cc: chao.p.peng@linux.intel.com, iommu@lists.linux.dev
Subject: Re: [PATCH] iommu/vt-d: Fix qi_batch NULL pointer with nested parent domain
Date: Mon, 9 Dec 2024 11:05:27 +0800 [thread overview]
Message-ID: <1f660d3c-04f7-4d16-beac-74412a5cf6d2@linux.intel.com> (raw)
In-Reply-To: <b25901cf-6483-4434-804e-62bda4385796@intel.com>
On 12/9/24 11:07, Yi Liu wrote:
>> Perhaps add a helper to handle the domain->qi_batch allocation? And then
>> call it in the necessary paths? Something like this:
>>
>> --- a/drivers/iommu/intel/cache.c
>> +++ b/drivers/iommu/intel/cache.c
>> @@ -105,12 +105,35 @@ static void cache_tag_unassign(struct
>> dmar_domain *domain, u16 did,
>> spin_unlock_irqrestore(&domain->cache_lock, flags);
>> }
>>
>> +/* domain->qi_batch will be freed in iommu_free_domain() path. */
>> +static int domain_qi_batch_alloc(struct dmar_domain *domain)
>> +{
>> + unsigned long flags;
>> + int ret = 0;
>> +
>> + spin_lock_irqsave(&domain->cache_lock, flags);
>
> I'm wondering if there is any difference using the domain->lock v.s. using
> the domain->cache_lock. The RID attach path acquires/releases the
> domain->lock first, and then the domain->cache_lock. While the PASID path
> does the reverse order. Although neither of the two paths hold the locks
> for a long duration (no A-B-B-A locking issue), it still means when a
> domain is shared between RID and PASID path, the domain->qi_batch check is
> not in the same phase of the two paths.
You are right. domain->lock is the right one.
>
>> + if (domain->qi_batch)
>> + goto out_unlock;
>> +
>> + domain->qi_batch = kzalloc(sizeof(*domain->qi_batch), GFP_ATOMIC);
>> + if (!domain->qi_batch)
>> + ret = -ENOMEM;
>> +out_unlock:
>> + spin_unlock_irqrestore(&domain->cache_lock, flags);
>> +
>> + return ret;
>> +}
>> +
>> static int __cache_tag_assign_domain(struct dmar_domain *domain, u16
>> did,
>> struct device *dev, ioasid_t pasid)
>> {
>> struct device_domain_info *info = dev_iommu_priv_get(dev);
>> int ret;
>>
>> + ret = domain_qi_batch_alloc(domain);
>> + if (ret)
>> + return ret;
>> +
>
> also need to call it in __cache_tag_assign_parent_domain(). BTW. Is the
> domain->qi_batch required if there is no ATS?
Yes.
Thanks,
baolu
next prev parent reply other threads:[~2024-12-09 3:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-07 12:03 [PATCH] iommu/vt-d: Fix qi_batch NULL pointer with nested parent domain Yi Liu
2024-12-09 1:39 ` Baolu Lu
2024-12-09 3:07 ` Yi Liu
2024-12-09 3:05 ` Baolu Lu [this message]
2024-12-11 8:32 ` Tian, Kevin
2024-12-11 9:29 ` Yi Liu
2024-12-09 3:10 ` Yi Liu
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=1f660d3c-04f7-4d16-beac-74412a5cf6d2@linux.intel.com \
--to=baolu.lu@linux.intel.com \
--cc=chao.p.peng@linux.intel.com \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=yi.l.liu@intel.com \
/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