Linux IOMMU Development
 help / color / mirror / Atom feed
From: Yi Liu <yi.l.liu@intel.com>
To: "Tian, Kevin" <kevin.tian@intel.com>,
	"joro@8bytes.org" <joro@8bytes.org>,
	"baolu.lu@linux.intel.com" <baolu.lu@linux.intel.com>
Cc: "chao.p.peng@linux.intel.com" <chao.p.peng@linux.intel.com>,
	"iommu@lists.linux.dev" <iommu@lists.linux.dev>
Subject: Re: [PATCH v2] iommu/vt-d: Fix qi_batch NULL pointer with nested parent domain
Date: Wed, 11 Dec 2024 17:27:00 +0800	[thread overview]
Message-ID: <c031213d-a86c-4f7c-81f8-235116638291@intel.com> (raw)
In-Reply-To: <BN9PR11MB527673D307E992D5D69CDDD18C3E2@BN9PR11MB5276.namprd11.prod.outlook.com>

On 2024/12/11 16:35, Tian, Kevin wrote:
>> From: Liu, Yi L <yi.l.liu@intel.com>
>> Sent: Tuesday, December 10, 2024 9:03 PM
>>
>> The qi_batch is allocated when assigning cache tag for a domain. While
>> for nested parent domain, it is missed. Hence, when trying to map pages
>> to the nested parent, NULL dereference occurred. Also, there is potential
>> memleak since there is no lock around domain->qi_batch allocation.
> 
> Out of curiosity. In which case does the VMM try to change the parent
> domain mapping when nesting is enabled? I know this is allowed and this
> patch does the right fix, but just curious how it's triggered.

This happens when there is map on the domain. It can be easily produced
when userspace allocates a s2_hwpt but never attach it to device. When
there is page mapped to the IOAS, the mapping is then populated to the
hwpt and its domain.

In my test, I just allocate s2_hwpt with nested parent flag, and allocate
nested domain with it. Then I attach nested domain, and replay all the
GPA mappings to s2_hwpt. It hit this issue.

> 
>> +/* 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);
>> +	if (domain->qi_batch)
>> +		goto out_unlock;
>> +
> 
> V1 discussion ends up with an agreement to use domain-lock, but
> not followed here. any reason?

Aha, there is a confusion between Baolu and I. So we had an offline chat.
We confirmed there is no locking issue using domain->cache_lock. And using
it is better then domain->lock since this is all about cache. I should
have mentioned it in the change log. :)


Regards,
Yi Liu

  reply	other threads:[~2024-12-11  9:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-10 13:03 [PATCH v2] iommu/vt-d: Fix qi_batch NULL pointer with nested parent domain Yi Liu
2024-12-11  8:35 ` Tian, Kevin
2024-12-11  9:27   ` Yi Liu [this message]
2024-12-12  5:46     ` Tian, Kevin
2024-12-12  7:27       ` Yi Liu
2024-12-13  2:45         ` Tian, Kevin

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=c031213d-a86c-4f7c-81f8-235116638291@intel.com \
    --to=yi.l.liu@intel.com \
    --cc=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 \
    /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