From patchwork Tue Jun 2 07:48:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: You-Sheng Yang X-Patchwork-Id: 1302203 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49bkhG0D1Kz9sSd; Tue, 2 Jun 2020 17:49:18 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1jg1fd-0005Hd-Vn; Tue, 02 Jun 2020 07:49:13 +0000 Received: from mail-pl1-f194.google.com ([209.85.214.194]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1fb-0005Er-Rw for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:49:12 +0000 Received: by mail-pl1-f194.google.com with SMTP id g12so1010645pll.10 for ; Tue, 02 Jun 2020 00:49:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QavVStEtdJ2qnNCyT6p3/I1MBn6QnIt0NqbW0OEUXWo=; b=g4uj6NxgUZE3yE4tD7Fw+nKMXNPqmiAgXp5y9ssg9L/iz76HqCij1Y6vdwrUqajqur dmCdrSa1p6RojWIJSmUZbSxOcYtMDkmD1YG98icwY0yvYLKdAUJZhBnf3A96yk2sPu8s 8S/jW5NWGTBcQHuR9jRrcGHGE19dksm1EfHxDaDvlM5uVoYVCAVXWbsEEKKJtWZihqjr y9ucOn538+sRpbmwiB8pqzwvttfQaY4a4fqz3lZGTqiH9hXsVN3meK+Aw44gq8MdkNCd ZQJOhLLGy5RIEZodjUmNiUoiU5hxOg+8FmP2cX0fJ8ldiMn4wgx8BF3jEUiByokHFDVr mbIA== X-Gm-Message-State: AOAM532zla+AG3ccn9HLZbtdOjVKUZPf6piRVxc3Bzpo+vCH2/3H/kTr bi8fe+/2KPcGQzGJv43SS3OP6YRgD6E= X-Google-Smtp-Source: ABdhPJwduc4RxMB8oZAadzzlOVBgp0HBcfeRRnZnt/6JAd0fqDVWfJLpnAL5p9hlKhl6E4os7UXb/g== X-Received: by 2002:a17:90a:de95:: with SMTP id n21mr4023049pjv.100.1591084149515; Tue, 02 Jun 2020 00:49:09 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id c138sm1483389pfc.97.2020.06.02.00.49.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:49:08 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 09/42][SRU][U] iommu: Keep a list of allocated groups in __iommu_probe_device() Date: Tue, 2 Jun 2020 15:48:10 +0800 Message-Id: <20200602074843.1743493-10-vicamo.yang@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200602074843.1743493-1-vicamo.yang@canonical.com> References: <20200602074843.1743493-1-vicamo.yang@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Joerg Roedel BugLink: https://bugs.launchpad.net/bugs/1876707 This is needed to defer default_domain allocation for new IOMMU groups until all devices have been added to the group. Signed-off-by: Joerg Roedel Tested-by: Marek Szyprowski Acked-by: Marek Szyprowski Link: https://lore.kernel.org/r/20200429133712.31431-10-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit 41df6dcc0a3ff4fb654c3d969ab96ba9c4f0e796 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/iommu.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index fa5c8c737fe9..87706d225dba 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -44,6 +44,7 @@ struct iommu_group { int id; struct iommu_domain *default_domain; struct iommu_domain *domain; + struct list_head entry; }; struct group_device { @@ -185,7 +186,7 @@ static void dev_iommu_free(struct device *dev) dev->iommu = NULL; } -static int __iommu_probe_device(struct device *dev) +static int __iommu_probe_device(struct device *dev, struct list_head *group_list) { const struct iommu_ops *ops = dev->bus->iommu_ops; struct iommu_device *iommu_dev; @@ -205,6 +206,9 @@ static int __iommu_probe_device(struct device *dev) } iommu_group_put(group); + if (group_list && !group->default_domain && list_empty(&group->entry)) + list_add_tail(&group->entry, group_list); + iommu_device_link(iommu_dev, dev); return 0; @@ -235,7 +239,7 @@ int iommu_probe_device(struct device *dev) if (ops->probe_device) { struct iommu_group *group; - ret = __iommu_probe_device(dev); + ret = __iommu_probe_device(dev, NULL); /* * Try to allocate a default domain - needs support from the @@ -568,6 +572,7 @@ struct iommu_group *iommu_group_alloc(void) group->kobj.kset = iommu_group_kset; mutex_init(&group->mutex); INIT_LIST_HEAD(&group->devices); + INIT_LIST_HEAD(&group->entry); BLOCKING_INIT_NOTIFIER_HEAD(&group->notifier); ret = ida_simple_get(&iommu_group_ida, 0, 0, GFP_KERNEL);