iommufd: Avoid PRI Response Failure
cover iommufd: Avoid PRI Response Failure
This series is a follow-up for the discussion that happened here.
https://lore.kernel.org/linux-iommu/[email protected]/
It prevents user space from responding to a group of page faults with a response code other than IOMMUFD_PAGE_RESP_SUCCESS and IOMMUFD_PAGE_RESP_INVALID, which will be treated by the device as Response Failure according to the PCI spec.
Please help review and comment.
Lu Baolu (3):
iommufd: Remove IOMMUFD_PAGE_RESP_FAILURE
iommufd: Add check on user response code
iommu: Convert response code from failure to invalid
include/uapi/linux/iommufd.h | 4 ---- drivers/iommu/io-pgfault.c | 2 +- drivers/iommu/iommufd/fault.c | 6 ++++++ 3 files changed, 7 insertions(+), 5 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/3 iommufd: Remove IOMMUFD_PAGE_RESP_FAILURE
The response code of IOMMUFD_PAGE_RESP_FAILURE was defined to be equivalent to the "Response Failure" in PCI spec, section 10.4.2.1. This response code indicates that one or more pages within the associated request group have encountered or caused an unrecoverable error. Therefore, this response disables the PRI at the function.
Modern I/O virtualization technologies, like SR-IOV, share PRI among the assignable device units. Therefore, a response failure on one unit might cause I/O failure on other units.
Remove this response code so that user space can only respond with SUCCESS or INVALID. The VMM is recommended to emulate a failure response as a PRI reset, or PRI disable and changing to a non-PRI domain.
--- include/uapi/linux/iommufd.h | 4 ---- 1 file changed, 4 deletions(-)
include/uapi/linux/iommufd.h +0 -4
@@ -765,14 +765,10 @@ struct iommu_hwpt_pgfault {* @IOMMUFD_PAGE_RESP_INVALID: Could not handle this fault, don't retry the * access. This is the "Invalid Request" in PCI * 10.4.2.1. -* @IOMMUFD_PAGE_RESP_FAILURE: General error. Drop all subsequent faults from -* this device if possible. This is the "Response -* Failure" in PCI 10.4.2.1. */ enum iommufd_page_response_code {IOMMUFD_PAGE_RESP_SUCCESS =0 ,IOMMUFD_PAGE_RESP_INVALID , -IOMMUFD_PAGE_RESP_FAILURE , };/**
Signature · 1 line
2.34.1
PATCH 2/3 iommufd: Add check on user response code
In reply to Lu BaoluThe response code from user space is only allowed to be SUCCESS or INVALID. All other values are treated by the device as a response code of Response Failure according to PCI spec, section 10.4.2.1. This response disables the Page Request Interface for the Function.
Add a check in iommufd_fault_fops_write() to avoid invalid response code.
--- drivers/iommu/iommufd/fault.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/iommu/iommufd/fault.c +6 -0
@@ -305,6 +305,12 @@ static ssize_t iommufd_fault_fops_write(struct file *filep, const char __user *bif (rc)break ; +if (response.code !=IOMMUFD_PAGE_RESP_SUCCESS && + response.code !=IOMMUFD_PAGE_RESP_INVALID ) { + rc = -EINVAL ; +break ; + } + group =xa_erase (&fault->response, response.cookie);if (!group) { rc = -EINVAL ;
Signature · 1 line
2.34.1
PATCH 3/3 iommu: Convert response code from failure to invalid
In reply to Lu BaoluIn the iopf deliver path, iommu_report_device_fault() currently responds a code of "Response Failure" to the hardware if it can't find a suitable iopf-capable domain where the page faults should be handled. The Response Failure is defined in PCI spec (section 10.4.2.1) as a catastrophic error, and the device will disable PRI for the function.
Failing to dispatch a set of fault messages is not a catastrophic error and the iommu core has no code to recover the PRI once it is disabled.
Replace it with a response code of "Invalid Response".
--- drivers/iommu/io-pgfault.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/io-pgfault.c +1 -1
@@ -229,7 +229,7 @@ void iommu_report_device_fault(struct device *dev, struct iopf_fault *evt) err_abort:dev_warn_ratelimited (dev,"iopf with pasid %d aborted\n" , fault->prm.pasid); -iopf_group_response (group,IOMMU_PAGE_RESP_FAILURE ); +iopf_group_response (group,IOMMU_PAGE_RESP_INVALID );if (group == &abort_group)__iopf_free_group (group);else
Signature · 1 line
2.34.1
RE: [PATCH 1/3] iommufd: Remove IOMMUFD_PAGE_RESP_FAILURE
In reply to Lu BaoluQuoted 40 lines
From: Lu Baolu <[email protected]>
Sent: Wednesday, July 10, 2024 4:34 PMThe response code of
IOMMUFD_PAGE_RESP_FAILUREwas defined to be equivalent to the "Response Failure" in PCI spec, section 10.4.2.1. This response code indicates that one or more pages within the associated request group have encountered or caused an unrecoverable error. Therefore, this response disables the PRI at the function.Modern I/O virtualization technologies, like SR-IOV, share PRI among the assignable device units. Therefore, a response failure on one unit might cause I/O failure on other units.
Remove this response code so that user space can only respond with SUCCESS or INVALID. The VMM is recommended to emulate a failure response
as a PRI reset, or PRI disable and changing to a non-PRI domain.Fixes c714f15860fc ("iommufd: Add fault and response message definitions")Signed-off-by Lu Baolu <[email protected]>--- include/uapi/linux/iommufd.h | 4 ---- 1 file changed, 4 deletions(-)include/uapi/linux/iommufd.h +0
-0@@ -765,14 +765,10 @@ struct iommu_hwpt_pgfault {* @IOMMUFD_PAGE_RESP_INVALID: Could not handle this fault, don't retry the
* access. This is the "Invalid Request" in PCI
* 10.4.2.1.
- * @IOMMUFD_PAGE_RESP_FAILURE: General error. Drop all subsequent faults from
- * this device if possible. This is the "Response
- * Failure" in PCI 10.4.2.1.
*/
enumiommufd_page_response_code{
include/uapi/linux/iommufd.h struct iommu_hwpt_pgfault { · line 772
Quoted 4 lines
include/uapi/linux/iommufd.h +0
-1IOMMUFD_PAGE_RESP_SUCCESS =0 , IOMMUFD_PAGE_RESP_INVALID, - IOMMUFD_PAGE_RESP_FAILURE, };
It's probably good to add some words here for why FAILURE is not allowed.
RE: [PATCH 2/3] iommufd: Add check on user response code
In reply to Lu BaoluQuoted 10 lines
From: Lu Baolu <[email protected]>
Sent: Wednesday, July 10, 2024 4:34 PMThe response code from user space is only allowed to be SUCCESS or INVALID. All other values are treated by the device as a response code of Response Failure according to PCI spec, section 10.4.2.1. This response disables the Page Request Interface for the Function.
Add a check in
iommufd_fault_fops_write()to avoid invalid response code.
"avoid invalid response code" but "RESP_INVALID is allowed" 😊.
I know what it means though...
Quoted 3 lines
Fixes 07838f7fd529 ("iommufd: Add iommufd fault object")Signed-off-by Lu Baolu <[email protected]>
Tian, Kevin
maintainerRE: [PATCH 3/3] iommu: Convert response code from failure to invalid
In reply to Lu BaoluQuoted 33 lines
From: Lu Baolu <[email protected]>
Sent: Wednesday, July 10, 2024 4:34 PMIn the iopf deliver path,
iommu_report_device_fault()currently responds a code of "Response Failure" to the hardware if it can't find a suitable iopf-capable domain where the page faults should be handled. The Response Failure is defined in PCI spec (section 10.4.2.1) as a catastrophic error, and the device will disable PRI for the function.Failing to dispatch a set of fault messages is not a catastrophic error and the iommu core has no code to recover the PRI once it is disabled.
Replace it with a response code of "Invalid Response".
Fixes b554e396e51c ("iommu: Make iopf_group_response() return void")Signed-off-by Lu Baolu <[email protected]>--- drivers/iommu/io-pgfault.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iommu/io-pgfault.c +1
-1@@ -229,7 +229,7 @@ void iommu_report_device_fault(struct device *dev, struct iopf_fault *evt) err_abort: dev_warn_ratelimited(dev, "iopf with pasid %d aborted\n", fault->prm.pasid); -iopf_group_response (group,IOMMU_PAGE_RESP_FAILURE ); +iopf_group_response (group,IOMMU_PAGE_RESP_INVALID );if (group == &abort_group)__iopf_free_group (group);
Quoted 1 line
else
this doesn't match the spec words on the use of INVALID:
One or more pages within the associated PRG do not exist or requests access privilege(s) that cannot be granted. Unless the page mapping associated with the Function is altered, re-issuance of the associated request will never result in success.
this situation is not related to the permission of page mapping. Instead it's a global problem applying to all functions submitting page requests at this moment.
Though using FAILURE affects more functions sharing the PRI interface, it also proactively avoids adding more in-fly requests to worsen the low memory situation.
So none of the options looks perfect to me, but the existing code responding FAILURE is more aligned to the spec?
Re: [PATCH 3/3] iommu: Convert response code from failure to invalid
Quoted 46 lines · Kevin
Quoted 33 lines
From: Lu Baolu <[email protected]>
Sent: Wednesday, July 10, 2024 4:34 PMIn the iopf deliver path,
iommu_report_device_fault()currently responds a code of "Response Failure" to the hardware if it can't find a suitable iopf-capable domain where the page faults should be handled. The Response Failure is defined in PCI spec (section 10.4.2.1) as a catastrophic error, and the device will disable PRI for the function.Failing to dispatch a set of fault messages is not a catastrophic error and the iommu core has no code to recover the PRI once it is disabled.
Replace it with a response code of "Invalid Response".
Fixes b554e396e51c ("iommu: Make iopf_group_response() return void")Signed-off-by Lu Baolu <[email protected]>--- drivers/iommu/io-pgfault.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iommu/io-pgfault.c +1
-1@@ -229,7 +229,7 @@ void iommu_report_device_fault(struct device *dev, struct iopf_fault *evt) err_abort: dev_warn_ratelimited(dev, "iopf with pasid %d aborted\n", fault->prm.pasid); -iopf_group_response (group,IOMMU_PAGE_RESP_FAILURE ); +iopf_group_response (group,IOMMU_PAGE_RESP_INVALID );if (group == &abort_group)__iopf_free_group (group);Quoted 1 line
else
this doesn't match the spec words on the use of INVALID:
One or more pages within the associated PRG do not exist or requests access privilege(s) that cannot be granted. Unless the page mapping associated with the Function is altered, re-issuance of the associated request will never result in success.
this situation is not related to the permission of page mapping. Instead it's a global problem applying to all functions submitting page requests at this moment.
Quoted 6 lines
Though using FAILURE affects more functions sharing the PRI interface, it also proactively avoids adding more in-fly requests to worsen the low memory situation.
So none of the options looks perfect to me, but the existing code responding FAILURE is more aligned to the spec?
Fair enough. Perhaps we can keep the existing code as-is unless any real issues arise.
Thanks,
baolu
Re: [PATCH 3/3] iommu: Convert response code from failure to invalid
In reply to Tian, KevinQuoted 46 lines · Kevin
Quoted 33 lines
From: Lu Baolu <[email protected]>
Sent: Wednesday, July 10, 2024 4:34 PMIn the iopf deliver path,
iommu_report_device_fault()currently responds a code of "Response Failure" to the hardware if it can't find a suitable iopf-capable domain where the page faults should be handled. The Response Failure is defined in PCI spec (section 10.4.2.1) as a catastrophic error, and the device will disable PRI for the function.Failing to dispatch a set of fault messages is not a catastrophic error and the iommu core has no code to recover the PRI once it is disabled.
Replace it with a response code of "Invalid Response".
Fixes b554e396e51c ("iommu: Make iopf_group_response() return void")Signed-off-by Lu Baolu <[email protected]>--- drivers/iommu/io-pgfault.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iommu/io-pgfault.c +1
-1@@ -229,7 +229,7 @@ void iommu_report_device_fault(struct device *dev, struct iopf_fault *evt) err_abort: dev_warn_ratelimited(dev, "iopf with pasid %d aborted\n", fault->prm.pasid); -iopf_group_response (group,IOMMU_PAGE_RESP_FAILURE ); +iopf_group_response (group,IOMMU_PAGE_RESP_INVALID );if (group == &abort_group)__iopf_free_group (group);Quoted 1 line
else
this doesn't match the spec words on the use of INVALID:
One or more pages within the associated PRG do not exist or requests access privilege(s) that cannot be granted. Unless the page mapping associated with the Function is altered, re-issuance of the associated request will never result in success.
this situation is not related to the permission of page mapping. Instead it's a global problem applying to all functions submitting page requests at this moment.
Quoted 6 lines
Though using FAILURE affects more functions sharing the PRI interface, it also proactively avoids adding more in-fly requests to worsen the low memory situation.
So none of the options looks perfect to me, but the existing code responding FAILURE is more aligned to the spec?
Yeah, I don't know what to do here either, I guess the system is going to explode if you OOM during this stage.
If it is some problem we'd probably have to preallocate this memory in a pool and rate limite the number of PRIs we allow open at once, using INVALID to create some back pressure. Seems wild.
Lets keep it as FAILURE for now, or at least it can be rediscussed another time.
Jason
Re: [PATCH 2/3] iommufd: Add check on user response code
In reply to Lu BaoluQuoted 19 lines · Lu Baolu
The response code from user space is only allowed to be SUCCESS or INVALID. All other values are treated by the device as a response code of Response Failure according to PCI spec, section 10.4.2.1. This response disables the Page Request Interface for the Function.
Add a check in
iommufd_fault_fops_write()to avoid invalid response code.Fixes 07838f7fd529 ("iommufd: Add iommufd fault object")Signed-off-by Lu Baolu <[email protected]>--- drivers/iommu/iommufd/fault.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/iommu/iommufd/fault.c +0
-0
drivers/iommu/iommufd/fault.c static ssize_t iommufd_fault_fops_write(struct file *filep, const char __user *b · line 312
Quoted 8 lines
drivers/iommu/iommufd/fault.c +5
-0@@ -305,6 +305,12 @@ static ssize_t iommufd_fault_fops_write(struct file *filep, const char __user *bif (rc)break ; +if (response.code !=IOMMUFD_PAGE_RESP_SUCCESS && + response.code !=IOMMUFD_PAGE_RESP_INVALID ) { + rc = -EINVAL ; +break ; + }
I added this:
static_assert(IOMMUFD_PAGE_RESP_SUCCESS == IOMMU_PAGE_RESP_SUCCESS); static_assert(IOMMUFD_PAGE_RESP_INVALID == IOMMU_PAGE_RESP_INVALID);
As well
Jason
Jason Gunthorpe
AppliedQuoted 9 lines · Lu Baolu
This series is a follow-up for the discussion that happened here.
https://lore.kernel.org/linux-iommu/[email protected]/
It prevents user space from responding to a group of page faults with a response code other than
IOMMUFD_PAGE_RESP_SUCCESSandIOMMUFD_PAGE_RESP_INVALID, which will be treated by the device as Response Failure according to the PCI spec.
Quoted 6 lines
Please help review and comment.
Lu Baolu (3):
iommufd: RemoveIOMMUFD_PAGE_RESP_FAILURE
iommufd: Add check on user response code
iommu: Convert response code from failure to invalid
Applied to iommufd for-next
Thanks,
Jason
Re: [PATCH 2/3] iommufd: Add check on user response code
In reply to Jason GunthorpeQuoted 31 lines · Jason Gunthorpe
Quoted 19 lines · Lu Baolu
The response code from user space is only allowed to be SUCCESS or INVALID. All other values are treated by the device as a response code of Response Failure according to PCI spec, section 10.4.2.1. This response disables the Page Request Interface for the Function.
Add a check in
iommufd_fault_fops_write()to avoid invalid response code.Fixes 07838f7fd529 ("iommufd: Add iommufd fault object")Signed-off-by Lu Baolu<[email protected]>--- drivers/iommu/iommufd/fault.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/iommu/iommufd/fault.c +0
-0drivers/iommu/iommufd/fault.c static ssize_t iommufd_fault_fops_write(struct file *filep, const char __user *b · line 312
Quoted 8 lines
drivers/iommu/iommufd/fault.c +5
-0@@ -305,6 +305,12 @@ static ssize_t iommufd_fault_fops_write(struct file *filep, const char __user *bif (rc)break ; +if (response.code !=IOMMUFD_PAGE_RESP_SUCCESS && + response.code !=IOMMUFD_PAGE_RESP_INVALID ) { + rc = -EINVAL ; +break ; + }I added this:
Quoted 4 lines
static_assert(IOMMUFD_PAGE_RESP_SUCCESS == IOMMU_PAGE_RESP_SUCCESS); static_assert(IOMMUFD_PAGE_RESP_INVALID == IOMMU_PAGE_RESP_INVALID);
Above change cause below build warning:
drivers/iommu/iommufd/fault.c: In function ‘iommufd_fault_fops_write’:drivers/iommu/iommufd/fault.c:308:57: warning: comparison between ‘enum iommufd_page_response_code’ and ‘enum iommu_page_response_code’ [-Wenum-compare]
308 | static_assert(IOMMUFD_PAGE_RESP_SUCCESS ==
| ^~./include/linux/build_bug.h:78:56: note: in definition of macro ‘__static_assert’
78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
| ^~~~drivers/iommu/iommufd/fault.c:308:17: note: in expansion of macro ‘static_assert’
308 | static_assert(IOMMUFD_PAGE_RESP_SUCCESS ==
| ^~~~~~~~~~~~~drivers/iommu/iommufd/fault.c:310:57: warning: comparison between ‘enum iommufd_page_response_code’ and ‘enum iommu_page_response_code’ [-Wenum-compare]
310 | static_assert(IOMMUFD_PAGE_RESP_INVALID ==
| ^~./include/linux/build_bug.h:78:56: note: in definition of macro ‘__static_assert’
78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
| ^~~~drivers/iommu/iommufd/fault.c:310:17: note: in expansion of macro ‘static_assert’
310 | static_assert(IOMMUFD_PAGE_RESP_INVALID ==
| ^~~~~~~~~~~~~Perhaps convert them to 'int' before compare?
drivers/iommu/iommufd/fault.c +4 -4
@@ -305,10 +305,10 @@ static ssize_t iommufd_fault_fops_write(struct file *filep, const char __user *bif (rc)break ; -static_assert (IOMMUFD_PAGE_RESP_SUCCESS == -IOMMU_PAGE_RESP_SUCCESS ); -static_assert (IOMMUFD_PAGE_RESP_INVALID == -IOMMU_PAGE_RESP_INVALID ); +static_assert ((int )IOMMUFD_PAGE_RESP_SUCCESS == + (int )IOMMU_PAGE_RESP_SUCCESS ); +static_assert ((int )IOMMUFD_PAGE_RESP_INVALID == + (int )IOMMU_PAGE_RESP_INVALID );if (response.code !=IOMMUFD_PAGE_RESP_SUCCESS && response.code !=IOMMUFD_PAGE_RESP_INVALID ) { rc = -EINVAL ;
Thanks,
baolu
Re: [PATCH 2/3] iommufd: Add check on user response code
Quoted 19 lines · Baolu Lu
drivers/iommu/iommufd/fault.c +4
-4@@ -305,10 +305,10 @@ static ssize_t iommufd_fault_fops_write(struct file *filep, const char __user *bif (rc)break ; -static_assert (IOMMUFD_PAGE_RESP_SUCCESS == -IOMMU_PAGE_RESP_SUCCESS ); -static_assert (IOMMUFD_PAGE_RESP_INVALID == -IOMMU_PAGE_RESP_INVALID ); +static_assert ((int )IOMMUFD_PAGE_RESP_SUCCESS == + (int )IOMMU_PAGE_RESP_SUCCESS ); +static_assert ((int )IOMMUFD_PAGE_RESP_INVALID == + (int )IOMMU_PAGE_RESP_INVALID );if (response.code !=IOMMUFD_PAGE_RESP_SUCCESS && response.code !=IOMMUFD_PAGE_RESP_INVALID ) {
Quoted 1 line
rc = -EINVAL;
Yep, my compiler doesn't warn on that apparently..
Jason