From patchwork Tue Jun 2 07:44:17 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: 1302189 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 49bkfK16rbz9sT8; Tue, 2 Jun 2020 17:47:37 +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 1jg1e0-0004YM-2t; Tue, 02 Jun 2020 07:47:32 +0000 Received: from mail-pl1-f195.google.com ([209.85.214.195]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1dL-0003nv-Tt for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:46:52 +0000 Received: by mail-pl1-f195.google.com with SMTP id bh7so1007539plb.11 for ; Tue, 02 Jun 2020 00:46:51 -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=WSJLq+HyC4QhVx7xQYA3YR57cJk0+5FGrljkGp3hrk0=; b=MErH0UtY8Ikn51BsmdYUqfW1i7ckA5xBGqeFBAVJMmdwVlZI8hEJQO+T+aszHQsdH4 a3vvuM4K4cOiwq6nRO54KgDIfhrp6SW4KzpmvhZi5nJuAMBRggv3aY3kb7Ow+LUNAzwp Gr7HCQa0U7R4VqKwv469m/XAxaFMBme0Ggt71/UDOUapdkKnouPau/ZexvZIHHghTfSb HVhKiDfmtisc1dtjKlAsTJISYBUx2Q83ECrCjENkW46Wp2SUDcmodWtfEid9yXMVcb9v f03LqucsVoQ1uxy7xJf+fHq17096Ya6EWtax3JYi5GCNvds6vwGcfvVkLoH+e0i+iarw 1pHg== X-Gm-Message-State: AOAM531NONGaXH789j5slEXg0Ei9uEJsEJVM6CVsEAuAnojTO/nAe3Au mzVJIikTPziS697C8tG8wbWMYoZ+pJQ= X-Google-Smtp-Source: ABdhPJwNpiRZ4KqnXKJCyRuqQCWVGNNEwkW/jrV8vqVWQ5DZg/+OvJQa6Y6H9l9GnVA6poQGNPBapQ== X-Received: by 2002:a17:90a:2c48:: with SMTP id p8mr3978855pjm.189.1591084009476; Tue, 02 Jun 2020 00:46:49 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id m9sm1539443pfo.200.2020.06.02.00.46.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:46:48 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 56/60][SRU][OEM-5.6] iommu: Don't call .probe_finalize() under group->mutex Date: Tue, 2 Jun 2020 15:44:17 +0800 Message-Id: <20200602074421.1742802-57-vicamo.yang@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200602074421.1742802-1-vicamo.yang@canonical.com> References: <20200602074421.1742802-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 The .probe_finalize() call-back of some IOMMU drivers calls into arm_iommu_attach_device(). This function will call back into the IOMMU core code, where it tries to take group->mutex again, resulting in a deadlock. As there is no reason why .probe_finalize() needs to be called under that mutex, move it after the lock has been released to fix the deadlock. Fixes: deac0b3bed26 ("iommu: Split off default domain allocation from group assignment") Reported-by: Yong Wu Signed-off-by: Joerg Roedel Cc: Yong Wu Link: https://lore.kernel.org/r/20200519132824.15163-1-joro@8bytes.org (cherry picked from commit 8350a49c2ef8aa166e498595e68ef3833fd74e55 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/iommu.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 13455abd0a93..c3e55e361051 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1680,17 +1680,8 @@ static void probe_alloc_default_domain(struct bus_type *bus, static int iommu_group_do_dma_attach(struct device *dev, void *data) { struct iommu_domain *domain = data; - const struct iommu_ops *ops; - int ret; - - ret = __iommu_attach_device(domain, dev); - - ops = domain->ops; - - if (ret == 0 && ops->probe_finalize) - ops->probe_finalize(dev); - return ret; + return __iommu_attach_device(domain, dev); } static int __iommu_group_dma_attach(struct iommu_group *group) @@ -1699,6 +1690,21 @@ static int __iommu_group_dma_attach(struct iommu_group *group) iommu_group_do_dma_attach); } +static int iommu_group_do_probe_finalize(struct device *dev, void *data) +{ + struct iommu_domain *domain = data; + + if (domain->ops->probe_finalize) + domain->ops->probe_finalize(dev); + + return 0; +} + +static void __iommu_group_dma_finalize(struct iommu_group *group) +{ + __iommu_group_for_each_dev(group, group->default_domain, + iommu_group_do_probe_finalize); +} static int iommu_do_create_direct_mappings(struct device *dev, void *data) { struct iommu_group *group = data; @@ -1751,6 +1757,8 @@ int bus_iommu_probe(struct bus_type *bus) if (ret) break; + + __iommu_group_dma_finalize(group); } return ret;