Linux IOMMU Development
 help / color / mirror / Atom feed
From: Yanfei Xu <yanfei.xu@intel.com>
To: Baolu Lu <baolu.lu@linux.intel.com>, <dwmw2@infradead.org>,
	<joro@8bytes.org>, <will@kernel.org>, <robin.murphy@arm.com>
Cc: <iommu@lists.linux.dev>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] iommu/vt-d: Use BUG_ON to check NULL value of 'table'
Date: Wed, 31 May 2023 15:09:56 +0800	[thread overview]
Message-ID: <a745c910-f4be-62f6-cb02-a610c04f4698@intel.com> (raw)
In-Reply-To: <3e75f9de-4c67-93aa-9fb4-28da9849dd48@linux.intel.com>

Hi Baolu,

On 5/31/2023 11:26 AM, Baolu Lu wrote:
> On 5/30/23 5:25 PM, Yanfei Xu wrote:
>> Checking NULL value of 'table' variable deserves a BUG_ON as the
>> following code will trigger a crash by dereferencing the NULL
>> 'table' pointer. Crash in advance with BUG_ON to avoid WARN_ON
>> plus NULL pointer dereferencing can simplify the crash log.
>>
>> Signed-off-by: Yanfei Xu<yanfei.xu@intel.com>
>> ---
>>   drivers/iommu/intel/iommu.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
>> index e98f1b122b49..8aa3bfdb7f95 100644
>> --- a/drivers/iommu/intel/iommu.c
>> +++ b/drivers/iommu/intel/iommu.c
>> @@ -1944,7 +1944,7 @@ static int domain_context_mapping_one(struct 
>> dmar_domain *domain,
>>       if (sm_supported(iommu)) {
>>           unsigned long pds;
>>   -        WARN_ON(!table);
>> +        BUG_ON(!table);
>
> BUG_ON() is not recommended. Perhaps,
>
>         if (!table)
>             -ENODEV;
>
Agree:) It is always better to handle the error than crash kernel.

How about:
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 8096273b034c..7f077e3a4128 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -1944,7 +1944,10 @@ static int domain_context_mapping_one(struct 
dmar_domain *domain,
         if (sm_supported(iommu)) {
                 unsigned long pds;

-               WARN_ON(!table);
+               if (WARN_ON(!table)) {
+                       ret = -ENODEV;
+                       goto out_unlock;
+               }

Thanks,
Yanfei

> ?
>
> Best regards,
> baolu

  reply	other threads:[~2023-05-31  7:10 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-30  9:25 [PATCH 0/2] Misc cleanup for iommu/vt-d Yanfei Xu
2023-05-30  9:25 ` [PATCH 1/2] iommu/vt-d: Remove the dead code in init_iommu_hw() Yanfei Xu
2023-05-31  3:24   ` Baolu Lu
2023-05-31  6:55     ` Yanfei Xu
2023-06-01  1:15       ` Baolu Lu
2023-06-01  7:49         ` Yanfei Xu
2023-05-30  9:25 ` [PATCH 2/2] iommu/vt-d: Use BUG_ON to check NULL value of 'table' Yanfei Xu
2023-05-31  3:26   ` Baolu Lu
2023-05-31  7:09     ` Yanfei Xu [this message]
2023-06-01  1:23       ` Baolu Lu
2023-06-01  4:47         ` Yanfei Xu
2023-06-02 14:32     ` 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=a745c910-f4be-62f6-cb02-a610c04f4698@intel.com \
    --to=yanfei.xu@intel.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=dwmw2@infradead.org \
    --cc=iommu@lists.linux.dev \
    --cc=joro@8bytes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=will@kernel.org \
    /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