From: Baolu Lu <baolu.lu@linux.intel.com>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: baolu.lu@linux.intel.com, Kevin Tian <kevin.tian@intel.com>,
Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
Nicolin Chen <nicolinc@nvidia.com>, Yi Liu <yi.l.liu@intel.com>,
iommu@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] iommufd: Add check on user response code
Date: Fri, 12 Jul 2024 10:54:11 +0800 [thread overview]
Message-ID: <b4758476-6de2-4d3e-91b2-10599a37d00e@linux.intel.com> (raw)
In-Reply-To: <20240711233950.GU14050@ziepe.ca>
On 7/12/24 7:39 AM, Jason Gunthorpe wrote:
> On Wed, Jul 10, 2024 at 04:33:40PM +0800, Lu Baolu wrote:
>> 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<baolu.lu@linux.intel.com>
>> ---
>> drivers/iommu/iommufd/fault.c | 6 ++++++
>> 1 file changed, 6 insertions(+)
>>
>> diff --git a/drivers/iommu/iommufd/fault.c b/drivers/iommu/iommufd/fault.c
>> index 54d6cd20a673..044b9b97da31 100644
>> --- a/drivers/iommu/iommufd/fault.c
>> +++ b/drivers/iommu/iommufd/fault.c
>> @@ -305,6 +305,12 @@ static ssize_t iommufd_fault_fops_write(struct file *filep, const char __user *b
>> if (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);
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?
diff --git a/drivers/iommu/iommufd/fault.c b/drivers/iommu/iommufd/fault.c
index 29f522819759..a643d5c7c535 100644
--- a/drivers/iommu/iommufd/fault.c
+++ b/drivers/iommu/iommufd/fault.c
@@ -305,10 +305,10 @@ static ssize_t iommufd_fault_fops_write(struct
file *filep, const char __user *b
if (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
next prev parent reply other threads:[~2024-07-12 2:57 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-10 8:33 [PATCH 0/3] iommufd: Avoid PRI Response Failure Lu Baolu
2024-07-10 8:33 ` [PATCH 1/3] iommufd: Remove IOMMUFD_PAGE_RESP_FAILURE Lu Baolu
2024-07-10 9:45 ` Tian, Kevin
2024-07-10 8:33 ` [PATCH 2/3] iommufd: Add check on user response code Lu Baolu
2024-07-10 9:47 ` Tian, Kevin
2024-07-11 23:39 ` Jason Gunthorpe
2024-07-12 2:54 ` Baolu Lu [this message]
2024-07-12 12:43 ` Jason Gunthorpe
2024-07-10 8:33 ` [PATCH 3/3] iommu: Convert response code from failure to invalid Lu Baolu
2024-07-10 9:56 ` Tian, Kevin
2024-07-11 4:42 ` Baolu Lu
2024-07-11 23:37 ` Jason Gunthorpe
2024-07-11 23:45 ` [PATCH 0/3] iommufd: Avoid PRI Response Failure Jason Gunthorpe
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=b4758476-6de2-4d3e-91b2-10599a37d00e@linux.intel.com \
--to=baolu.lu@linux.intel.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@ziepe.ca \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nicolinc@nvidia.com \
--cc=robin.murphy@arm.com \
--cc=will@kernel.org \
--cc=yi.l.liu@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