stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/1] iommu/vt-d: Make intel_iommu_drain_pasid_prq() cover faults for RID
@ 2025-01-21  2:31 Lu Baolu
  2025-01-21  7:01 ` Yi Liu
  0 siblings, 1 reply; 4+ messages in thread
From: Lu Baolu @ 2025-01-21  2:31 UTC (permalink / raw)
  To: Joerg Roedel, Will Deacon, Robin Murphy, Kevin Tian, Yi Liu
  Cc: iommu, linux-kernel, Lu Baolu, stable

This driver supports page faults on PCI RID since commit <9f831c16c69e>
("iommu/vt-d: Remove the pasid present check in prq_event_thread") by
allowing the reporting of page faults with the pasid_present field cleared
to the upper layer for further handling. The fundamental assumption here
is that the detach or replace operations act as a fence for page faults.
This implies that all pending page faults associated with a specific RID
or PASID are flushed when a domain is detached or replaced from a device
RID or PASID.

However, the intel_iommu_drain_pasid_prq() helper does not correctly
handle faults for RID. This leads to faults potentially remaining pending
in the iommu hardware queue even after the domain is detached, thereby
violating the aforementioned assumption.

Fix this issue by extending intel_iommu_drain_pasid_prq() to cover faults
for RID.

Fixes: 9f831c16c69e ("iommu/vt-d: Remove the pasid present check in prq_event_thread")
Cc: stable@vger.kernel.org
Suggested-by: Kevin Tian <kevin.tian@intel.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
---
 drivers/iommu/intel/prq.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Change log:
v2:
 - Add check on page faults targeting RID.

v1: https://lore.kernel.org/linux-iommu/20250120080144.810455-1-baolu.lu@linux.intel.com/

diff --git a/drivers/iommu/intel/prq.c b/drivers/iommu/intel/prq.c
index c2d792db52c3..064194399b38 100644
--- a/drivers/iommu/intel/prq.c
+++ b/drivers/iommu/intel/prq.c
@@ -87,7 +87,9 @@ void intel_iommu_drain_pasid_prq(struct device *dev, u32 pasid)
 		struct page_req_dsc *req;
 
 		req = &iommu->prq[head / sizeof(*req)];
-		if (!req->pasid_present || req->pasid != pasid) {
+		if (req->rid != sid ||
+		    (req->pasid_present && pasid != req->pasid) ||
+		    (!req->pasid_present && pasid != IOMMU_NO_PASID)) {
 			head = (head + sizeof(*req)) & PRQ_RING_MASK;
 			continue;
 		}
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/1] iommu/vt-d: Make intel_iommu_drain_pasid_prq() cover faults for RID
  2025-01-21  2:31 [PATCH v2 1/1] iommu/vt-d: Make intel_iommu_drain_pasid_prq() cover faults for RID Lu Baolu
@ 2025-01-21  7:01 ` Yi Liu
  2025-02-05  2:28   ` Baolu Lu
  0 siblings, 1 reply; 4+ messages in thread
From: Yi Liu @ 2025-01-21  7:01 UTC (permalink / raw)
  To: Lu Baolu, Joerg Roedel, Will Deacon, Robin Murphy, Kevin Tian
  Cc: iommu, linux-kernel, stable

On 2025/1/21 10:31, Lu Baolu wrote:
> This driver supports page faults on PCI RID since commit <9f831c16c69e>
> ("iommu/vt-d: Remove the pasid present check in prq_event_thread") by
> allowing the reporting of page faults with the pasid_present field cleared
> to the upper layer for further handling. The fundamental assumption here
> is that the detach or replace operations act as a fence for page faults.
> This implies that all pending page faults associated with a specific RID
> or PASID are flushed when a domain is detached or replaced from a device
> RID or PASID.
> 
> However, the intel_iommu_drain_pasid_prq() helper does not correctly
> handle faults for RID. This leads to faults potentially remaining pending
> in the iommu hardware queue even after the domain is detached, thereby
> violating the aforementioned assumption.
> 
> Fix this issue by extending intel_iommu_drain_pasid_prq() to cover faults
> for RID.
> 
> Fixes: 9f831c16c69e ("iommu/vt-d: Remove the pasid present check in prq_event_thread")
> Cc: stable@vger.kernel.org
> Suggested-by: Kevin Tian <kevin.tian@intel.com>
> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
> Reviewed-by: Kevin Tian <kevin.tian@intel.com>
> ---
>   drivers/iommu/intel/prq.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> Change log:
> v2:
>   - Add check on page faults targeting RID.
> 
> v1: https://lore.kernel.org/linux-iommu/20250120080144.810455-1-baolu.lu@linux.intel.com/
> 
> diff --git a/drivers/iommu/intel/prq.c b/drivers/iommu/intel/prq.c
> index c2d792db52c3..064194399b38 100644
> --- a/drivers/iommu/intel/prq.c
> +++ b/drivers/iommu/intel/prq.c
> @@ -87,7 +87,9 @@ void intel_iommu_drain_pasid_prq(struct device *dev, u32 pasid)
>   		struct page_req_dsc *req;
>   
>   		req = &iommu->prq[head / sizeof(*req)];
> -		if (!req->pasid_present || req->pasid != pasid) {
> +		if (req->rid != sid ||

Does intel-iommu driver managed pasid per-bdf? or global? If the prior one,
the rid check is needed even in the old time that does not PRIs in the RID
path.

> +		    (req->pasid_present && pasid != req->pasid) ||
> +		    (!req->pasid_present && pasid != IOMMU_NO_PASID)) {
>   			head = (head + sizeof(*req)) & PRQ_RING_MASK;
>   			continue;
>   		}

LGTM.

Reviewed-by: Yi Liu <yi.l.liu@intel.com>

-- 
Regards,
Yi Liu

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/1] iommu/vt-d: Make intel_iommu_drain_pasid_prq() cover faults for RID
  2025-01-21  7:01 ` Yi Liu
@ 2025-02-05  2:28   ` Baolu Lu
  2025-02-11  9:02     ` Yi Liu
  0 siblings, 1 reply; 4+ messages in thread
From: Baolu Lu @ 2025-02-05  2:28 UTC (permalink / raw)
  To: Yi Liu, Joerg Roedel, Will Deacon, Robin Murphy, Kevin Tian
  Cc: baolu.lu, iommu, linux-kernel, stable

On 2025/1/21 15:01, Yi Liu wrote:
> On 2025/1/21 10:31, Lu Baolu wrote:
>> This driver supports page faults on PCI RID since commit <9f831c16c69e>
>> ("iommu/vt-d: Remove the pasid present check in prq_event_thread") by
>> allowing the reporting of page faults with the pasid_present field 
>> cleared
>> to the upper layer for further handling. The fundamental assumption here
>> is that the detach or replace operations act as a fence for page faults.
>> This implies that all pending page faults associated with a specific RID
>> or PASID are flushed when a domain is detached or replaced from a device
>> RID or PASID.
>>
>> However, the intel_iommu_drain_pasid_prq() helper does not correctly
>> handle faults for RID. This leads to faults potentially remaining pending
>> in the iommu hardware queue even after the domain is detached, thereby
>> violating the aforementioned assumption.
>>
>> Fix this issue by extending intel_iommu_drain_pasid_prq() to cover faults
>> for RID.
>>
>> Fixes: 9f831c16c69e ("iommu/vt-d: Remove the pasid present check in 
>> prq_event_thread")
>> Cc: stable@vger.kernel.org
>> Suggested-by: Kevin Tian <kevin.tian@intel.com>
>> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
>> Reviewed-by: Kevin Tian <kevin.tian@intel.com>
>> ---
>>   drivers/iommu/intel/prq.c | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> Change log:
>> v2:
>>   - Add check on page faults targeting RID.
>>
>> v1: https://lore.kernel.org/linux-iommu/20250120080144.810455-1- 
>> baolu.lu@linux.intel.com/
>>
>> diff --git a/drivers/iommu/intel/prq.c b/drivers/iommu/intel/prq.c
>> index c2d792db52c3..064194399b38 100644
>> --- a/drivers/iommu/intel/prq.c
>> +++ b/drivers/iommu/intel/prq.c
>> @@ -87,7 +87,9 @@ void intel_iommu_drain_pasid_prq(struct device *dev, 
>> u32 pasid)
>>           struct page_req_dsc *req;
>>           req = &iommu->prq[head / sizeof(*req)];
>> -        if (!req->pasid_present || req->pasid != pasid) {
>> +        if (req->rid != sid ||
> 
> Does intel-iommu driver managed pasid per-bdf? or global? If the prior one,
> the rid check is needed even in the old time that does not PRIs in the RID
> path.

Do you mean that this fix should be back ported farther than the fix tag
commit?

The iommu driver doesn't manage the PASID. IOMMUFD and SVA do actually.
The SVA uses global PASID. IOMMUFD doesn't yet support PASIDs, pending
the merging of your patches. Therefore, per-BDF PASID management is not
currently implemented in the Linux tree. Anything I overlooked?

---
baolu

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/1] iommu/vt-d: Make intel_iommu_drain_pasid_prq() cover faults for RID
  2025-02-05  2:28   ` Baolu Lu
@ 2025-02-11  9:02     ` Yi Liu
  0 siblings, 0 replies; 4+ messages in thread
From: Yi Liu @ 2025-02-11  9:02 UTC (permalink / raw)
  To: Baolu Lu, Joerg Roedel, Will Deacon, Robin Murphy, Kevin Tian
  Cc: iommu, linux-kernel, stable

On 2025/2/5 10:28, Baolu Lu wrote:
> On 2025/1/21 15:01, Yi Liu wrote:
>> On 2025/1/21 10:31, Lu Baolu wrote:
>>> This driver supports page faults on PCI RID since commit <9f831c16c69e>
>>> ("iommu/vt-d: Remove the pasid present check in prq_event_thread") by
>>> allowing the reporting of page faults with the pasid_present field cleared
>>> to the upper layer for further handling. The fundamental assumption here
>>> is that the detach or replace operations act as a fence for page faults.
>>> This implies that all pending page faults associated with a specific RID
>>> or PASID are flushed when a domain is detached or replaced from a device
>>> RID or PASID.
>>>
>>> However, the intel_iommu_drain_pasid_prq() helper does not correctly
>>> handle faults for RID. This leads to faults potentially remaining pending
>>> in the iommu hardware queue even after the domain is detached, thereby
>>> violating the aforementioned assumption.
>>>
>>> Fix this issue by extending intel_iommu_drain_pasid_prq() to cover faults
>>> for RID.
>>>
>>> Fixes: 9f831c16c69e ("iommu/vt-d: Remove the pasid present check in 
>>> prq_event_thread")
>>> Cc: stable@vger.kernel.org
>>> Suggested-by: Kevin Tian <kevin.tian@intel.com>
>>> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
>>> Reviewed-by: Kevin Tian <kevin.tian@intel.com>
>>> ---
>>>   drivers/iommu/intel/prq.c | 4 +++-
>>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>>
>>> Change log:
>>> v2:
>>>   - Add check on page faults targeting RID.
>>>
>>> v1: https://lore.kernel.org/linux-iommu/20250120080144.810455-1- 
>>> baolu.lu@linux.intel.com/
>>>
>>> diff --git a/drivers/iommu/intel/prq.c b/drivers/iommu/intel/prq.c
>>> index c2d792db52c3..064194399b38 100644
>>> --- a/drivers/iommu/intel/prq.c
>>> +++ b/drivers/iommu/intel/prq.c
>>> @@ -87,7 +87,9 @@ void intel_iommu_drain_pasid_prq(struct device *dev, 
>>> u32 pasid)
>>>           struct page_req_dsc *req;
>>>           req = &iommu->prq[head / sizeof(*req)];
>>> -        if (!req->pasid_present || req->pasid != pasid) {
>>> +        if (req->rid != sid ||
>>
>> Does intel-iommu driver managed pasid per-bdf? or global? If the prior one,
>> the rid check is needed even in the old time that does not PRIs in the RID
>> path.
> 
> Do you mean that this fix should be back ported farther than the fix tag
> commit?

correct.

> The iommu driver doesn't manage the PASID. IOMMUFD and SVA do actually.
> The SVA uses global PASID. IOMMUFD doesn't yet support PASIDs, pending
> the merging of your patches. Therefore, per-BDF PASID management is not
> currently implemented in the Linux tree. Anything I overlooked?

then, it's fine. No need to backport it I suppose.

-- 
Regards,
Yi Liu

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-02-11  8:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-21  2:31 [PATCH v2 1/1] iommu/vt-d: Make intel_iommu_drain_pasid_prq() cover faults for RID Lu Baolu
2025-01-21  7:01 ` Yi Liu
2025-02-05  2:28   ` Baolu Lu
2025-02-11  9:02     ` Yi Liu

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).