Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp5385153imm; Tue, 12 Jun 2018 07:07:43 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLGKx9tZ40jjBWTUTHeHTRwnSkap2SFCCC/OmsiIg4puX9iXABviqYpF08qiLY6peqg9I5Q X-Received: by 2002:a17:902:7105:: with SMTP id a5-v6mr575249pll.171.1528812463233; Tue, 12 Jun 2018 07:07:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528812463; cv=none; d=google.com; s=arc-20160816; b=btXWqYWAWT797ub9OWQjgyOVdEKcKl0K5IdVqklWSohUqYy04jTQasTyHiGXpAgslZ 3N2h1FDH8RWZ5KmFn1oS4uoFw+fcrh+CQxVKSY6QrNnwUyHPQHRhCHnOLDKLYPJZrKBY TTMy5UyK2HtolZeo9n2ilFxjaFaHNAmQiKl/GBgUQGDtkalai2hmSebb7vEVxFTaD8af FqsNibIxtNKy335n6G2qibGASZ95oMWc9dP+AEvHyrGVU/G7cau6QUK8UDZIhaChXUjv XiZgNYkyhQrzsa23xHGQy+j8l1cmM/05TW1teRRWCAM7h8/XwRPLa/LMFQi2aSfdsa2B S/iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=bbYeUhSZMyYlqPxKC4a0fHeNlHuE1zrgnUaaMS2fhN8=; b=kJB5WEVLFDgpb2uHm6VCGCfXyYcq+uFqJoly2OwWqfsTv8iEIrBTOYg4qPi39cMSKF pOchLnYTnQW/FtrmKePlOmOdgM7lffOkqpb2+iQu+zeSlPq2xmiyBN/806/JqihMMv3F fUAZePqxh/YguNcaloX5HhEv3+w003BkZJ1EyRb+M32J2lkqDgVWhitMQo+tekOaEoi0 uBJMzKTWluRu38U4WmwadrUUVM8BmcCtfB5mz7Sac8eWNe0F1hJcdi5AwLRmue4cFlOM 5DDibWZXN+WTluJdMxb314+8s5eVkOYcWz9W6X2TQldnlyox3aFG6Jgay/nJNnroE1wo GQkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gNcqRb0f; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j16-v6si238448pfj.55.2018.06.12.07.07.05; Tue, 12 Jun 2018 07:07:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gNcqRb0f; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933643AbeFLOGj (ORCPT + 99 others); Tue, 12 Jun 2018 10:06:39 -0400 Received: from mail-lf0-f66.google.com ([209.85.215.66]:40636 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933350AbeFLOGh (ORCPT ); Tue, 12 Jun 2018 10:06:37 -0400 Received: by mail-lf0-f66.google.com with SMTP id q11-v6so36219173lfc.7 for ; Tue, 12 Jun 2018 07:06:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=bbYeUhSZMyYlqPxKC4a0fHeNlHuE1zrgnUaaMS2fhN8=; b=gNcqRb0fy36Zt6OBN2yDbB8loauSoFqV+ucACccZHu2utICLpdcrFcr7aTdGLLNBHD 6GuVeQjx+uvGJPuadmOul6xsknsfKR1VPKeKcnP8tHEzgXGusPLTJ3M4AkVE0lwXn5gx DiSbQ7Svt4jAtAdSHvs+2FqBzj41D/eHe7zlE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=bbYeUhSZMyYlqPxKC4a0fHeNlHuE1zrgnUaaMS2fhN8=; b=hkVoyYhWHeKhbpEq8Ldx2SLEOfOKuIGp5Zv0rwOge0+FTrWR7jlXUVpnt5R2Dh35WZ t35C4pbxBY0rZlB9Rx0cikCG0Vdj3sDZck2ckttW8MmHgw7qhtLzWZGENUXiPCifRPdL npXdQslHLYn9X3EvgOHkUMw24JFw406SpQR3sGDRau/2nibT8h9yXEDGvxcyXff1ozDP QradUWOxrwpjK+s3Ksrs3t1cP/YEN5YibTkDYh/DZS4Tx18JUxZtHm6+D19JERNWAB3g tqEMKjUJBaIkpBIsiBbsqfgaESFnv71pxKkItm34E9vB7IoIIKEvMl0LpncXsIorqDp+ WhLw== X-Gm-Message-State: APt69E2sl5LXzo0OEQLk2ddXS+T4dOkdpl1taCpfBvLBDP+s1duuTDTU y4oRrQHj5qrAo2Y4secxImFMaw== X-Received: by 2002:a19:cb96:: with SMTP id b144-v6mr331700lfg.72.1528812396033; Tue, 12 Jun 2018 07:06:36 -0700 (PDT) Received: from centauri.lan (h-229-118.A785.priv.bahnhof.se. [5.150.229.118]) by smtp.gmail.com with ESMTPSA id o25-v6sm50854lfg.41.2018.06.12.07.06.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Jun 2018 07:06:35 -0700 (PDT) From: Niklas Cassel To: Joerg Roedel Cc: linux-arm-msm@vger.kernel.org, Niklas Cassel , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH RESEND] iommu/msm: Don't call iommu_device_{,un}link from atomic context Date: Tue, 12 Jun 2018 16:06:10 +0200 Message-Id: <20180612140610.31190-1-niklas.cassel@linaro.org> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Fixes the following splat during boot: BUG: sleeping function called from invalid context at kernel/locking/mutex.c:747 in_atomic(): 1, irqs_disabled(): 128, pid: 77, name: kworker/2:1 4 locks held by kworker/2:1/77: #0: (ptrval) ((wq_completion)"events"){+.+.}, at: process_one_work+0x1fc/0x8fc #1: (ptrval) (deferred_probe_work){+.+.}, at: process_one_work+0x1fc/0x8fc #2: (ptrval) (&dev->mutex){....}, at: __device_attach+0x40/0x178 #3: (ptrval) (msm_iommu_lock){....}, at: msm_iommu_add_device+0x28/0xcc irq event stamp: 348 hardirqs last enabled at (347): [] kfree+0xe0/0x3c0 hardirqs last disabled at (348): [] _raw_spin_lock_irqsave+0x2c/0x68 softirqs last enabled at (0): [] copy_process.part.5+0x280/0x1a68 softirqs last disabled at (0): [<00000000>] (null) Preemption disabled at: [<00000000>] (null) CPU: 2 PID: 77 Comm: kworker/2:1 Not tainted 4.17.0-rc5-wt-ath-01075-gaca0516bb4cf #239 Hardware name: Generic DT based system Workqueue: events deferred_probe_work_func [] (unwind_backtrace) from [] (show_stack+0x20/0x24) [] (show_stack) from [] (dump_stack+0xa0/0xcc) [] (dump_stack) from [] (___might_sleep+0x1f8/0x2d4) ath10k_sdio mmc2:0001:1: Direct firmware load for ath10k/QCA9377/hw1.0/board-2.bin failed with error -2 [] (___might_sleep) from [] (__might_sleep+0x70/0xa8) [] (__might_sleep) from [] (__mutex_lock+0x50/0xb28) [] (__mutex_lock) from [] (mutex_lock_nested+0x2c/0x34) ath10k_sdio mmc2:0001:1: board_file api 1 bmi_id N/A crc32 544289f7 [] (mutex_lock_nested) from [] (kernfs_find_and_get_ns+0x30/0x5c) [] (kernfs_find_and_get_ns) from [] (sysfs_add_link_to_group+0x28/0x58) [] (sysfs_add_link_to_group) from [] (iommu_device_link+0x50/0xb4) [] (iommu_device_link) from [] (msm_iommu_add_device+0xa0/0xcc) [] (msm_iommu_add_device) from [] (add_iommu_group+0x3c/0x64) [] (add_iommu_group) from [] (bus_for_each_dev+0x84/0xc4) [] (bus_for_each_dev) from [] (bus_set_iommu+0xd0/0x10c) [] (bus_set_iommu) from [] (msm_iommu_probe+0x5b8/0x66c) [] (msm_iommu_probe) from [] (platform_drv_probe+0x60/0xbc) [] (platform_drv_probe) from [] (driver_probe_device+0x30c/0x4cc) [] (driver_probe_device) from [] (__device_attach_driver+0xac/0x14c) [] (__device_attach_driver) from [] (bus_for_each_drv+0x68/0xc8) [] (bus_for_each_drv) from [] (__device_attach+0xe4/0x178) [] (__device_attach) from [] (device_initial_probe+0x1c/0x20) [] (device_initial_probe) from [] (bus_probe_device+0x98/0xa0) [] (bus_probe_device) from [] (deferred_probe_work_func+0x74/0x198) [] (deferred_probe_work_func) from [] (process_one_work+0x2c4/0x8fc) [] (process_one_work) from [] (worker_thread+0x2c4/0x5cc) [] (worker_thread) from [] (kthread+0x180/0x188) [] (kthread) from [] (ret_from_fork+0x14/0x20) Fixes: 42df43b36163 ("iommu/msm: Make use of iommu_device_register interface") Signed-off-by: Niklas Cassel --- drivers/iommu/msm_iommu.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/iommu/msm_iommu.c b/drivers/iommu/msm_iommu.c index 0d3350463a3f..9a95c9b9d0d8 100644 --- a/drivers/iommu/msm_iommu.c +++ b/drivers/iommu/msm_iommu.c @@ -395,20 +395,15 @@ static int msm_iommu_add_device(struct device *dev) struct msm_iommu_dev *iommu; struct iommu_group *group; unsigned long flags; - int ret = 0; spin_lock_irqsave(&msm_iommu_lock, flags); - iommu = find_iommu_for_dev(dev); + spin_unlock_irqrestore(&msm_iommu_lock, flags); + if (iommu) iommu_device_link(&iommu->iommu, dev); else - ret = -ENODEV; - - spin_unlock_irqrestore(&msm_iommu_lock, flags); - - if (ret) - return ret; + return -ENODEV; group = iommu_group_get_for_dev(dev); if (IS_ERR(group)) @@ -425,13 +420,12 @@ static void msm_iommu_remove_device(struct device *dev) unsigned long flags; spin_lock_irqsave(&msm_iommu_lock, flags); - iommu = find_iommu_for_dev(dev); + spin_unlock_irqrestore(&msm_iommu_lock, flags); + if (iommu) iommu_device_unlink(&iommu->iommu, dev); - spin_unlock_irqrestore(&msm_iommu_lock, flags); - iommu_group_remove_device(dev); } -- 2.17.1