Skip to contentSkip to conversation

iommu: Fix a few issues related to PRQ

PATCH Superseded Yi Sun 3 participants 10 messages Oct 28, 2020 – Oct 29, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yi Sun

author
#0 lore raw

cover iommu: Fix a few issues related to PRQ

We found a few issues about PRQ. So, three patches are cooked to fix them. Please have a review. Thanks!

Jacob Pan (1):
iommu: Fix an issue in iommu_page_response() flags check

Liu Yi L (1):
iommu/vt-d: Fix prq reporting issues

Liu, Yi L (1):
iommu/vt-d: Fix a bug for PDP check in prq_event_thread

 drivers/iommu/intel/svm.c | 5 ++++-
 drivers/iommu/iommu.c     | 6 ++++--
 2 files changed, 8 insertions(+), 3 deletions(-)
Signature · 6 lines
2.7.4

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
author
#1 lore raw

PATCH 1/3 iommu/vt-d: Fix prq reporting issues

From: Liu Yi L <[email protected]>

Should get correct sid and set it into sdev. Because we execute 'sdev->sid != req->rid' in the loop of prq_event_thread().

---
 drivers/iommu/intel/svm.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/iommu/intel/svm.c +3 -0
index f1861fa..75d9dc9 100644
@@ -277,6 +277,7 @@ int intel_svm_bind_gpasid(struct iommu_domain *domain, struct device *dev,
 			  struct iommu_gpasid_bind_data *data)
 {
 	struct intel_iommu *iommu = device_to_iommu(dev, NULL, NULL);
+	struct device_domain_info *info;
 	struct intel_svm_dev *sdev = NULL;
 	struct dmar_domain *dmar_domain;
 	struct intel_svm *svm = NULL;
@@ -357,6 +358,8 @@ int intel_svm_bind_gpasid(struct iommu_domain *domain, struct device *dev,
 		goto out;
 	}
 	sdev->dev = dev;
+	info = get_domain_info(dev);
+	sdev->sid = PCI_DEVID(info->bus, info->devfn);
 
 	/* Only count users if device has aux domains */
 	if (iommu_dev_feature_enabled(dev, IOMMU_DEV_FEAT_AUX))
Signature · 6 lines
2.7.4

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
author
#4 lore raw

PATCH 2/3 iommu: Fix an issue in iommu_page_response() flags check

In reply to Yi Sun

From: Jacob Pan <[email protected]>

original code fails when LAST_PAGE is set in flags.

---
 drivers/iommu/iommu.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/iommu/iommu.c +4 -2
index 8c470f4..053cec3 100644
@@ -1200,9 +1200,11 @@ int iommu_page_response(struct device *dev,
 		return -EINVAL;
 
 	if (msg->version != IOMMU_PAGE_RESP_VERSION_1 ||
-	    msg->flags & ~IOMMU_PAGE_RESP_PASID_VALID)
+		!(msg->flags & IOMMU_PAGE_RESP_PASID_VALID)) {
+		dev_warn_ratelimited(dev, "%s:Invalid ver %x: flags %x\n",
+				__func__, msg->version, msg->flags);
 		return -EINVAL;
-
+	}
 	/* Only send response if there is a fault report pending */
 	mutex_lock(&param->fault_param->lock);
 	if (list_empty(&param->fault_param->faults)) {
Signature · 6 lines
2.7.4

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
author
#7 lore raw

PATCH 3/3 iommu/vt-d: Fix a bug for PDP check in prq_event_thread

In reply to Yi Sun

From: "Liu, Yi L" <[email protected]>

---
 drivers/iommu/intel/svm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/intel/svm.c +1 -1
index 75d9dc9..1870248 100644
@@ -1032,7 +1032,7 @@ static irqreturn_t prq_event_thread(int irq, void *d)
 			resp.qw0 = QI_PGRP_PASID(req->pasid) |
 				QI_PGRP_DID(req->rid) |
 				QI_PGRP_PASID_P(req->pasid_present) |
-				QI_PGRP_PDP(req->pasid_present) |
+				QI_PGRP_PDP(req->priv_data_present) |
 				QI_PGRP_RESP_CODE(result) |
 				QI_PGRP_RESP_TYPE;
 			resp.qw1 = QI_PGRP_IDX(req->prg_index) |
Signature · 6 lines
2.7.4

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
maintainer
#2 lore raw

Re: [PATCH v1 1/3] iommu/vt-d: Fix prq reporting issues

In reply to Yi Sun

Hi Yi,

Quoted 4 lines · Yi Sun

From: Liu Yi L <[email protected]>

Should get correct sid and set it into sdev. Because we execute 'sdev->sid != req->rid' in the loop of prq_event_thread().

How about making the title more accurate, how about something like:

iommu/vt-d: Fix use before set issue in intel_svm_bind_gpasid()

Quoted 21 lines
---
  drivers/iommu/intel/svm.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/iommu/intel/svm.c +1 -0
index f1861fa..75d9dc9 100644
@@ -277,6 +277,7 @@ int intel_svm_bind_gpasid(struct iommu_domain *domain, struct device *dev,
  			  struct iommu_gpasid_bind_data *data)
  {
  	struct intel_iommu *iommu = device_to_iommu(dev, NULL, NULL);
+	struct device_domain_info *info;
  	struct intel_svm_dev *sdev = NULL;
  	struct dmar_domain *dmar_domain;
  	struct intel_svm *svm = NULL;

drivers/iommu/intel/svm.c int intel_svm_bind_gpasid(struct iommu_domain *domain, struct device *dev, · line 365

Quoted 8 lines
drivers/iommu/intel/svm.c +2 -0
@@ -357,6 +358,8 @@ int intel_svm_bind_gpasid(struct iommu_domain *domain, struct device *dev,
  		goto out;
  	}
  	sdev->dev = dev;
+	info = get_domain_info(dev);
+	sdev->sid = PCI_DEVID(info->bus, info->devfn);
 
  	/* Only count users if device has aux domains */
  	if (iommu_dev_feature_enabled(dev, IOMMU_DEV_FEAT_AUX))

How about moving get_domain_info() up to the sanity check part?

drivers/iommu/intel/svm.c +6 -0
index f1861fa3d0e4..75846692f2f2 100644
@@ -279,6 +279,7 @@ int intel_svm_bind_gpasid(struct iommu_domain *domain, struct device *dev,
        struct intel_iommu *iommu = device_to_iommu(dev, NULL, NULL);
        struct intel_svm_dev *sdev = NULL;
        struct dmar_domain *dmar_domain;
+       struct device_domain_info *info;
        struct intel_svm *svm = NULL;
        int ret = 0;
 
@@ -310,6 +311,10 @@ int intel_svm_bind_gpasid(struct iommu_domain *domain, struct device *dev,
        if (data->hpasid <= 0 || data->hpasid >= PASID_MAX)
                return -EINVAL;
 
+       info = get_domain_info(dev);
+       if (!info)
+               return -EINVAL;
+
        dmar_domain = to_dmar_domain(domain);
 
        mutex_lock(&pasid_mutex);
@@ -357,6 +362,7 @@ int intel_svm_bind_gpasid(struct iommu_domain *domain, struct device *dev,
                goto out;
        }
        sdev->dev = dev;
+       sdev->sid = PCI_DEVID(info->bus, info->devfn);
 
        /* Only count users if device has aux domains */
        if (iommu_dev_feature_enabled(dev, IOMMU_DEV_FEAT_AUX))

Best regards,
baolu
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

maintainer
#8 lore raw

Re: [PATCH v1 3/3] iommu/vt-d: Fix a bug for PDP check in prq_event_thread

In reply to Yi Sun

Hi Yi,

Quoted 1 line · Yi Sun

From: "Liu, Yi L" <[email protected]>

Can you please add some description here? How far should this patch back ported? A Fixes tag?

Best regards,
baolu

Quoted 13 lines
---
  drivers/iommu/intel/svm.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/intel/svm.c +0 -0
index 75d9dc9..1870248 100644

drivers/iommu/intel/svm.c static irqreturn_t prq_event_thread(int irq, void *d) · line 1038

Quoted 8 lines
drivers/iommu/intel/svm.c +1 -1
@@ -1032,7 +1032,7 @@ static irqreturn_t prq_event_thread(int irq, void *d)
  			resp.qw0 = QI_PGRP_PASID(req->pasid) |
  				QI_PGRP_DID(req->rid) |
  				QI_PGRP_PASID_P(req->pasid_present) |
-				QI_PGRP_PDP(req->pasid_present) |
+				QI_PGRP_PDP(req->priv_data_present) |
  				QI_PGRP_RESP_CODE(result) |
  				QI_PGRP_RESP_TYPE;
  			resp.qw1 = QI_PGRP_IDX(req->prg_index) |

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

author
#3 lore raw

Re: [PATCH v1 1/3] iommu/vt-d: Fix prq reporting issues

In reply to Lu Baolu

Thanks! Will do the modifications according to your comments in next version.

Quoted 78 lines · Lu Baolu

Hi Yi,

Quoted 4 lines · Yi Sun

From: Liu Yi L <[email protected]>

Should get correct sid and set it into sdev. Because we execute 'sdev->sid != req->rid' in the loop of prq_event_thread().

How about making the title more accurate, how about something like:

iommu/vt-d: Fix use before set issue in intel_svm_bind_gpasid()

Quoted 20 lines
---
 drivers/iommu/intel/svm.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/iommu/intel/svm.c +1 -0
index f1861fa..75d9dc9 100644
@@ -277,6 +277,7 @@ int intel_svm_bind_gpasid(struct iommu_domain *domain, struct device *dev,
 			  struct iommu_gpasid_bind_data *data)
 {
 	struct intel_iommu *iommu = device_to_iommu(dev, NULL, NULL);
+	struct device_domain_info *info;
 	struct intel_svm_dev *sdev = NULL;
 	struct dmar_domain *dmar_domain;
 	struct intel_svm *svm = NULL;

drivers/iommu/intel/svm.c int intel_svm_bind_gpasid(struct iommu_domain *domain, struct device *dev, · line 365

Quoted 8 lines
drivers/iommu/intel/svm.c +2 -0
@@ -357,6 +358,8 @@ int intel_svm_bind_gpasid(struct iommu_domain *domain, struct device *dev,
 		goto out;
 	}
 	sdev->dev = dev;
+	info = get_domain_info(dev);
+	sdev->sid = PCI_DEVID(info->bus, info->devfn);
 	/* Only count users if device has aux domains */
 	if (iommu_dev_feature_enabled(dev, IOMMU_DEV_FEAT_AUX))
 

How about moving get_domain_info() up to the sanity check part?

drivers/iommu/intel/svm.c +5 -0
index f1861fa3d0e4..75846692f2f2 100644
@@ -279,6 +279,7 @@ int intel_svm_bind_gpasid(struct iommu_domain
 *domain, struct device *dev,
        struct intel_iommu *iommu = device_to_iommu(dev, NULL, NULL);
        struct intel_svm_dev *sdev = NULL;
        struct dmar_domain *dmar_domain;
+       struct device_domain_info *info;
        struct intel_svm *svm = NULL;
        int ret = 0;
@@ -310,6 +311,10 @@ int intel_svm_bind_gpasid(struct iommu_domain
 *domain, struct device *dev,
        if (data->hpasid <= 0 || data->hpasid >= PASID_MAX)
                return -EINVAL;
 
+       info = get_domain_info(dev);
+       if (!info)
+               return -EINVAL;
+
        dmar_domain = to_dmar_domain(domain);
 
        mutex_lock(&pasid_mutex);
drivers/iommu/intel/svm.c +1 -0
@@ -357,6 +362,7 @@ int intel_svm_bind_gpasid(struct iommu_domain
 *domain, struct device *dev,
                goto out;
        }
        sdev->dev = dev;
+       sdev->sid = PCI_DEVID(info->bus, info->devfn);
 
        /* Only count users if device has aux domains */

if (iommu_dev_feature_enabled(dev, IOMMU_DEV_FEAT_AUX))

Quoted 2 lines

Best regards,
baolu

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

author
#9 lore raw

Re: [PATCH v1 3/3] iommu/vt-d: Fix a bug for PDP check in prq_event_thread

In reply to Lu Baolu
Quoted 8 lines · Lu Baolu

Hi Yi,

Quoted 1 line · Yi Sun

From: "Liu, Yi L" <[email protected]>

Can you please add some description here? How far should this patch back ported? A Fixes tag?

Sure. Will add description and Fixes tag.

Quoted 10 lines

Best regards,
baolu

Quoted 7 lines
---
 drivers/iommu/intel/svm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines
Quoted 6 lines
drivers/iommu/intel/svm.c +0 -0
index 75d9dc9..1870248 100644

drivers/iommu/intel/svm.c static irqreturn_t prq_event_thread(int irq, void *d) · line 1038

Quoted 8 lines
drivers/iommu/intel/svm.c +1 -1
@@ -1032,7 +1032,7 @@ static irqreturn_t prq_event_thread(int irq, void *d)
 			resp.qw0 = QI_PGRP_PASID(req->pasid) |
 				QI_PGRP_DID(req->rid) |
 				QI_PGRP_PASID_P(req->pasid_present) |
-				QI_PGRP_PDP(req->pasid_present) |
+				QI_PGRP_PDP(req->priv_data_present) |
 				QI_PGRP_RESP_CODE(result) |
 				QI_PGRP_RESP_TYPE;
 			resp.qw1 = QI_PGRP_IDX(req->prg_index) |

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

#5 lore raw

Re: [PATCH v1 2/3] iommu: Fix an issue in iommu_page_response() flags check

In reply to Yi Sun

Hi,

Quoted 3 lines · Yi Sun

From: Jacob Pan <[email protected]>

original code fails when LAST_PAGE is set in flags.

LAST_PAGE is not documented to be a valid flags for page_response. So isn't failing the right thing to do?

Quoted 13 lines
---
 drivers/iommu/iommu.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/iommu/iommu.c +0 -0
index 8c470f4..053cec3 100644

drivers/iommu/iommu.c int iommu_page_response(struct device *dev, · line 1203

Quoted 5 lines
drivers/iommu/iommu.c +1 -1
@@ -1200,9 +1200,11 @@ int iommu_page_response(struct device *dev,
 		return -EINVAL;
 
 	if (msg->version != IOMMU_PAGE_RESP_VERSION_1 ||
-	    msg->flags & ~IOMMU_PAGE_RESP_PASID_VALID)
+		!(msg->flags & IOMMU_PAGE_RESP_PASID_VALID)) {

It should be OK not to have PASID_VALID set, we're just checking for undefined flags here.

Thanks,
Jean

Quoted 15 lines
drivers/iommu/iommu.c +3 -1
+		dev_warn_ratelimited(dev, "%s:Invalid ver %x: flags %x\n",
+				__func__, msg->version, msg->flags);
 		return -EINVAL;
-
+	}
 	/* Only send response if there is a fault report pending */
 	mutex_lock(&param->fault_param->lock);
 	if (list_empty(&param->fault_param->faults)) {
Signature · 6 lines
2.7.4

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

author
#6 lore raw

Re: [PATCH v1 2/3] iommu: Fix an issue in iommu_page_response() flags check

Quoted 25 lines · Jean-Philippe Brucker

Hi,

Quoted 3 lines · Yi Sun

From: Jacob Pan <[email protected]>

original code fails when LAST_PAGE is set in flags.

LAST_PAGE is not documented to be a valid flags for page_response. So isn't failing the right thing to do?

Quoted 15 lines
---
 drivers/iommu/iommu.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/iommu/iommu.c +0 -0
index 8c470f4..053cec3 100644
@@ -1200,9 +1200,11 @@ int iommu_page_response(struct device *dev,
 		return -EINVAL;
 
Quoted 7 lines

drivers/iommu/iommu.c int iommu_page_response(struct device *dev, · line 1203

Quoted 3 lines
drivers/iommu/iommu.c +1 -1
 	if (msg->version != IOMMU_PAGE_RESP_VERSION_1 ||
-	    msg->flags & ~IOMMU_PAGE_RESP_PASID_VALID)
+		!(msg->flags & IOMMU_PAGE_RESP_PASID_VALID)) {

It should be OK not to have PASID_VALID set, we're just checking for undefined flags here.

Thanks! You are right. Per published spec, we should not care LAST_PAGE for page_response. I will remove this patch in next version.

Quoted 14 lines

Thanks,
Jean

Quoted 11 lines
drivers/iommu/iommu.c +3 -1
+		dev_warn_ratelimited(dev, "%s:Invalid ver %x: flags %x\n",
+				__func__, msg->version, msg->flags);
 		return -EINVAL;
-
+	}
 	/* Only send response if there is a fault report pending */
 	mutex_lock(&param->fault_param->lock);
 	if (list_empty(&param->fault_param->faults)) {
Signature · 1 line
2.7.4
Quoted 4 lines
Quoted 4 lines

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu