All of lore.kernel.org
 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: Thu, 12 Dec 2024 15:27:39 +0800	[thread overview]
Message-ID: <c893e582-9526-4832-97fc-2487348bfa91@intel.com> (raw)
In-Reply-To: <BN9PR11MB5276F5B100BD155B371533238C3F2@BN9PR11MB5276.namprd11.prod.outlook.com>

On 2024/12/12 13:46, Tian, Kevin wrote:
>> From: Liu, Yi L <yi.l.liu@intel.com>
>> Sent: Wednesday, December 11, 2024 5:27 PM
>>
>> 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.
> 
> so this is a case where there is already a s2_hwpt with valid mappings
> before creating this parent s2. When replay happens this bug is hit.

yes. In QEMU, we will allocate parent hwpt when guest iommu enables
translation (TE bit). We also have a choice to reuse the hwpt created
during VM boot up (allocated by VFIO module within QEMU), but we have RO
mapping errata, so creating a parent hwpt that does not have RO mappings is
better. When this parent hwpt is created, we would replay the GPA->HPA
mappings, hence hit the problem as the parent hwpt has not been attached to
this device at all. This also means, this issue can be hidden if the parent
hwpt has been attached to the device. And this is exactly the reason we
didn't see it in the qi_batch merging. My test application has attached the
parent hwpt to PASIDs of the device to test out the pasid attach path, so
it WA the issue by accident. Recently, I'm clean up the tests by adding
them one by one, then hit this bug.

-- 
Regards,
Yi Liu

  reply	other threads:[~2024-12-12  7: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
2024-12-12  5:46     ` Tian, Kevin
2024-12-12  7:27       ` Yi Liu [this message]
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=c893e582-9526-4832-97fc-2487348bfa91@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.