From patchwork Tue May 26 13:02:00 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: 1298070 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 49WZ2z4ZYNz9sTv; Tue, 26 May 2020 23:06:03 +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 1jdZHK-00081f-5y; Tue, 26 May 2020 13:05:58 +0000 Received: from mail-pl1-f196.google.com ([209.85.214.196]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jdZFz-0006mO-3Q for kernel-team@lists.ubuntu.com; Tue, 26 May 2020 13:04:35 +0000 Received: by mail-pl1-f196.google.com with SMTP id i17so160949pli.13 for ; Tue, 26 May 2020 06:04:35 -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=75mL55IjNIpSD/JEfybqLbdtJer8hsZ73jqUUXn+Z1o=; b=nKc0Baw6NongdWe30zCSpidUJ7ExLp6xy2KxVfRFt86ofZPB3SSYMjPriGqFn+wMCE qxI5nYMAXxv5vjO3Pxlh7CFEH5BMWvacvKORVHK57RwvlktcqXVAr93hsGiqUUjcYOO/ NW2utLL+1tAItS338sWULxhtesJcA+4VIvLeaembYbya+JqEGYUUnsbI5F6jDE8LIGQ5 cwk6FnIaHJ8fxP9n3GCW0Tf4HBPRn5pnJkpAM+iqhIOxWSGqDE2q+uSIygfDm1gN5rBb WFiswpo4cImtX2Cadnztupesw+K0Xx813KWm0TiIDv4aLV1LNSAiP3ATrEIisxLdsaDw /YUg== X-Gm-Message-State: AOAM532QohucAVk3RHOayEkDJggG2iMdbXQ9/UDWzwqz8qtvp7faqBbF onfvDpvWZnvG8dJ+KiZ24LBDwAZAZbo= X-Google-Smtp-Source: ABdhPJytOtu8fZ6Tqrm3BrQARk3D5RcpF6RcmAOdi2WC8LfxMtDGoebXByGsm6Tc6PH3Ekjv98BAaQ== X-Received: by 2002:a17:90a:1217:: with SMTP id f23mr25074775pja.150.1590498271776; Tue, 26 May 2020 06:04:31 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id z20sm13965860pgv.52.2020.05.26.06.04.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 May 2020 06:04:31 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH 56/60][SRU][OEM-5.6] UBUNTU: SAUCE: iommu: Don't call .probe_finalize() under group->mutex Date: Tue, 26 May 2020 21:02:00 +0800 Message-Id: <20200526130204.238445-57-vicamo.yang@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200526130204.238445-1-vicamo.yang@canonical.com> References: <20200526130204.238445-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 iommu/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 9888a3c82b15..39dea54a9cdd 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1671,17 +1671,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) @@ -1690,6 +1681,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; @@ -1742,6 +1748,8 @@ int bus_iommu_probe(struct bus_type *bus) if (ret) break; + + __iommu_group_dma_finalize(group); } return ret;