Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp14398921pxu; Mon, 4 Jan 2021 23:56:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJwC9uun0JpS8xGYLEfW+lmOwy3obyjENWC0o4wrI9wdWMgCt9xXwN6U5VcZ5pnbZPnCPvkS X-Received: by 2002:a17:906:eca9:: with SMTP id qh9mr53697196ejb.188.1609833403275; Mon, 04 Jan 2021 23:56:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609833403; cv=none; d=google.com; s=arc-20160816; b=IselA5uo9EO//k1k0jfViuR1/3qcJi2SFENm1ekB+e5WI67hp1l30+XgXr8zTzMJ8T nJtzL5vWqCuzvemsKgSULqtTRbfSi5JB8BZptf4qTSNRhj4ziApN7RR8FFOPaNzjj32Y PASKp7MtTONHsUoHBLLxP0rIm45g0L2IMxi8VZKbRvbEBMEtqvVdBYS59yX7GFWrIK35 77d0xcnabCfE4ifp2dH4XAL9Is5tJPGhnBKgpUkh5k+OXcdSShl9vwvZWOLh9aMuw8hY +0Z7oYAgiZ61uu8wFg7Anz/HNPrfGHZBK74mnx3XXfpG8UFO8qUSqcawqepQ2dANsV/e CHmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:references:cc :to:from:subject:dkim-signature; bh=igdDX6nTf4cbA39W1H+W8RdNCNfFYs684pcl8DlTBJY=; b=kcOGgtHS2uEteqaDLlkfJHmkEHrGIOPFk9TwNOUchHO4ytFsQm2qYUQP0ABu1xTR5M vZMLbLdZtBmumdnHKtVKBkOE+PUVsNFURZmhWvj4ZG+IuR6psjczYdIwO40JRIsO0Zc/ WliRzcdXTVbD+fSaVsTq5ZAgWw0hE3jVMjCrOKgEpujoB8OQ/JBxIqQutYgJ7vC4NEmL Er7LkcWAK5KvngyfW/lYU7p3OObxisauG4v2eVwO6wn6PXzMqwvZQj2OnY5bLa1lonCr J9iPMTgsHHw49k9F5sYjw4jLWtjiVfCYNnmHb19QgczrowtSOrBWjgSolPNYG68ZARUi k47w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LASJhgSl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a15si33674449edb.360.2021.01.04.23.56.20; Mon, 04 Jan 2021 23:56:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LASJhgSl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727313AbhAEHxn (ORCPT + 99 others); Tue, 5 Jan 2021 02:53:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:51994 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726993AbhAEHxn (ORCPT ); Tue, 5 Jan 2021 02:53:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609833136; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=igdDX6nTf4cbA39W1H+W8RdNCNfFYs684pcl8DlTBJY=; b=LASJhgSlmwIG9iwoIkzL06R/hMZu3anQBIFyTQTnvhEnfz7LsoEsaTr48sz9XEtemYRqf9 CIRKytR3YiaaS0nwNaZ+VuWtZHxikuzDfWClXyfFEQWbBSfR525eKrH8WIpEC/Er5sROA3 eRgtdmA+iwzRvbgtztQ8H5v5VqGLz0w= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-592-uovIrgZqNJWO4xmv1igrsg-1; Tue, 05 Jan 2021 02:52:12 -0500 X-MC-Unique: uovIrgZqNJWO4xmv1igrsg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A4A9015720; Tue, 5 Jan 2021 07:52:11 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-214.pek2.redhat.com [10.72.12.214]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2FF7971CA1; Tue, 5 Jan 2021 07:52:08 +0000 (UTC) Subject: Re: [PATCH] iommu: check for the deferred attach when attaching a device From: lijiang To: linux-kernel@vger.kernel.org Cc: joro@8bytes.org, will@kernel.org, iommu@lists.linux-foundation.org, jroedel@suse.de, jsnitsel@redhat.com, "Lendacky, Thomas" References: <20201226053959.4222-1-lijiang@redhat.com> <33b6f925-71e6-5d9e-74c3-3e1eaf13398e@redhat.com> Message-ID: Date: Tue, 5 Jan 2021 15:52:06 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <33b6f925-71e6-5d9e-74c3-3e1eaf13398e@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 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 >> --- >> 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); >> >>