iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: lijiang <lijiang@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: "Lendacky, Thomas" <thomas.lendacky@amd.com>,
	jroedel@suse.de, iommu@lists.linux-foundation.org,
	will@kernel.org
Subject: Re: [PATCH] iommu: check for the deferred attach when attaching a device
Date: Tue, 5 Jan 2021 15:52:06 +0800	[thread overview]
Message-ID: <b385db3b-4506-6d75-49e1-e11064e65d6a@redhat.com> (raw)
In-Reply-To: <33b6f925-71e6-5d9e-74c3-3e1eaf13398e@redhat.com>

在 2021年01月05日 11:55, lijiang 写道:
> Hi,
> 
> Also add Joerg to cc list.
> 

Also add more people to cc list, Jerry Snitselaar and Tom Lendacky.

Thanks.

> Thanks.
> Lianbo
> 在 2020年12月26日 13:39, Lianbo Jiang 写道:
>> Currently, because domain attach allows to be deferred from iommu
>> driver to device driver, and when iommu initializes, the devices
>> on the bus will be scanned and the default groups will be allocated.
>>
>> Due to the above changes, some devices could be added to the same
>> group as below:
>>
>> [    3.859417] pci 0000:01:00.0: Adding to iommu group 16
>> [    3.864572] pci 0000:01:00.1: Adding to iommu group 16
>> [    3.869738] pci 0000:02:00.0: Adding to iommu group 17
>> [    3.874892] pci 0000:02:00.1: Adding to iommu group 17
>>
>> But when attaching these devices, it doesn't allow that a group has
>> more than one device, otherwise it will return an error. This conflicts
>> with the deferred attaching. Unfortunately, it has two devices in the
>> same group for my side, for example:
>>
>> [    9.627014] iommu_group_device_count(): device name[0]:0000:01:00.0
>> [    9.633545] iommu_group_device_count(): device name[1]:0000:01:00.1
>> ...
>> [   10.255609] iommu_group_device_count(): device name[0]:0000:02:00.0
>> [   10.262144] iommu_group_device_count(): device name[1]:0000:02:00.1
>>
>> Finally, which caused the failure of tg3 driver when tg3 driver calls
>> the dma_alloc_coherent() to allocate coherent memory in the tg3_test_dma().
>>
>> [    9.660310] tg3 0000:01:00.0: DMA engine test failed, aborting
>> [    9.754085] tg3: probe of 0000:01:00.0 failed with error -12
>> [    9.997512] tg3 0000:01:00.1: DMA engine test failed, aborting
>> [   10.043053] tg3: probe of 0000:01:00.1 failed with error -12
>> [   10.288905] tg3 0000:02:00.0: DMA engine test failed, aborting
>> [   10.334070] tg3: probe of 0000:02:00.0 failed with error -12
>> [   10.578303] tg3 0000:02:00.1: DMA engine test failed, aborting
>> [   10.622629] tg3: probe of 0000:02:00.1 failed with error -12
>>
>> In addition, the similar situations also occur in other drivers such
>> as the bnxt_en driver. That can be reproduced easily in kdump kernel
>> when SME is active.
>>
>> Add a check for the deferred attach in the iommu_attach_device() and
>> allow to attach the deferred device regardless of how many devices
>> are in a group.
>>
>> Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
>> ---
>>  drivers/iommu/iommu.c | 5 ++++-
>>  1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
>> index ffeebda8d6de..dccab7b133fb 100644
>> --- a/drivers/iommu/iommu.c
>> +++ b/drivers/iommu/iommu.c
>> @@ -1967,8 +1967,11 @@ int iommu_attach_device(struct iommu_domain *domain, struct device *dev)
>>  	 */
>>  	mutex_lock(&group->mutex);
>>  	ret = -EINVAL;
>> -	if (iommu_group_device_count(group) != 1)
>> +	if (!iommu_is_attach_deferred(domain, dev) &&
>> +	    iommu_group_device_count(group) != 1) {
>> +		dev_err_ratelimited(dev, "Group has more than one device\n");
>>  		goto out_unlock;
>> +	}
>>  
>>  	ret = __iommu_attach_group(domain, group);
>>  
>>

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

  reply	other threads:[~2021-01-05  7:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-26  5:39 [PATCH] iommu: check for the deferred attach when attaching a device Lianbo Jiang
2021-01-05  3:55 ` lijiang
2021-01-05  7:52   ` lijiang [this message]
2021-01-12 17:29     ` Robin Murphy
2021-01-15 14:26       ` lijiang
2021-01-15 15:15         ` Robin Murphy
2021-01-18  8:41           ` lijiang

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=b385db3b-4506-6d75-49e1-e11064e65d6a@redhat.com \
    --to=lijiang@redhat.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=jroedel@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=thomas.lendacky@amd.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;
as well as URLs for NNTP newsgroup(s).