mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: Mostafa Saleh <smostafa@google.com>,
	Aleksandr Aprelkov <aaprelkov@usergate.com>
Cc: Will Deacon <will@kernel.org>, Joerg Roedel <joro@8bytes.org>,
	Jason Gunthorpe <jgg@ziepe.ca>,
	Nicolin Chen <nicolinc@nvidia.com>,
	Michael Shavit <mshavit@google.com>,
	Lu Baolu <baolu.lu@linux.intel.com>,
	Marc Zyngier <maz@kernel.org>,
	linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] iommu/arm-smmu-v3: Free MSIs in case of ENOMEM
Date: Tue, 9 Apr 2024 12:17:54 +0100	[thread overview]
Message-ID: <8a7f0218-39e3-4e4b-ba99-7fe4389fb703@arm.com> (raw)
In-Reply-To: <ZhUbw6gAeBjpFz5C@google.com>

On 09/04/2024 11:43 am, Mostafa Saleh wrote:
> Hi Aleksandr,
> 
> On Wed, Apr 03, 2024 at 12:37:59PM +0700, Aleksandr Aprelkov wrote:
>> If devm_add_action() returns ENOMEM, then MSIs allocated but
>> not freed on teardown.
>>
>> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>>
>> Fixes: 166bdbd23161 ("iommu/arm-smmu: Add support for MSI on SMMUv3")
>> Signed-off-by: Aleksandr Aprelkov <aaprelkov@usergate.com>
>> ---
>> v2: Use appropriate function for registration failure as
>> Jonathan Cameron <Jonathan.Cameron@Huawei.com> suggested.
>>
>>   drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
>> index 41f93c3ab160..8800af041e5f 100644
>> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
>> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
>> @@ -3402,7 +3402,9 @@ static void arm_smmu_setup_msis(struct arm_smmu_device *smmu)
>>   	smmu->priq.q.irq = msi_get_virq(dev, PRIQ_MSI_INDEX);
>>   
>>   	/* Add callback to free MSIs on teardown */
>> -	devm_add_action(dev, arm_smmu_free_msis, dev);
>> +	ret = devm_add_action_or_reset(dev, arm_smmu_free_msis, dev);
>> +	if (ret)
>> +		dev_warn(dev, "failed to add free MSIs callback - falling back to wired irqs\n");
> 
> I am not sure that is the right fix, as allowing the driver to probe
> without MSIs, seems worse than leaking MSI memory.
> 
> IMHO, we can just add something like:
>      dev_err(smmu->dev, “Can’t allocate devm action, MSIs are never freed! !\n”) ;

Honestly I don't think this matters. If we ever really did fail to 
allocate 16 bytes, SLUB would already be screaming and spewing 
stacktraces, and the system is dead already.

> Also, we can’t unconditionally fallback to wired irqs if MSI exists,
> according to the user manual:
>      An implementation must support one of, or optionally both of,
>      wired interrupts and MSIs
>      ...
>      The discovery of support for wired interrupts is IMPLEMENTATION DEFINED.
> 
> We can add some logic, to check dt/acpi irqs and to choose to fallback
> or not based on that, but, if we get -ENOMEM, (especially early at
> probe) something really went wrong, so I am not sure it’s worth
> the complexity.

That logic already exists in arm_smmu_setup_unique_irqs() - the messages 
here are in the sense of "we're giving up on MSIs and falling back to 
trying whatever wired IRQs we may or may not have." The critical point 
is that we're not using MSIs for some potentially actionable reason, 
i.e. if the user does expect the system to be MSI-capable, then it could 
be an indication of perhaps a wrong or missing msi-parent, for which 
they may pursue a firmware fix. In other cases it's normal and expected 
not to use MSIs though (e.g. the system just doesn't have an ITS), so we 
don't want to be *too* noisy about it.

Thanks,
Robin.

> 
>>   }
>>   
>>   static void arm_smmu_setup_unique_irqs(struct arm_smmu_device *smmu)
>> -- 
>> 2.34.1
>>
> Thanks,
> Mostafa

  reply	other threads:[~2024-04-09 11:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-03  5:37 Aleksandr Aprelkov
2024-04-09 10:43 ` Mostafa Saleh
2024-04-09 11:17   ` Robin Murphy [this message]
2024-04-09 11:31     ` Mostafa Saleh
2024-04-09 11:46       ` Robin Murphy
2024-04-19 15:32 ` Will Deacon

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=8a7f0218-39e3-4e4b-ba99-7fe4389fb703@arm.com \
    --to=robin.murphy@arm.com \
    --cc=aaprelkov@usergate.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@ziepe.ca \
    --cc=joro@8bytes.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=mshavit@google.com \
    --cc=nicolinc@nvidia.com \
    --cc=smostafa@google.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

Powered by JetHome