Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3052761imm; Fri, 20 Jul 2018 09:18:03 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf6YwUtyhEU+s6xySyZu5fezkMqqZwuowwLFZ8O1TG/mptc7HwGh9+gXHHH/rn+EbMqrpDx X-Received: by 2002:aa7:818b:: with SMTP id g11-v6mr2867559pfi.50.1532103483048; Fri, 20 Jul 2018 09:18:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532103483; cv=none; d=google.com; s=arc-20160816; b=jmRiPctb/l9XSklq+0iDALSN2LWCOpcmc4sx57bexHFqQ+3i6e68e4DkBBX1zGsa8l VKWOv2JzgEcS0Km51Le2qarKiAYsXwmMbalTFr8aDV7tKPDALPU4ARhQAKjj+ko7o6Nk Vuongnfoqw5gJD36wTeH3uCXC+nSN7qKwmNk1D4BV5DyBRG4TB9lcCOYvwzhwjVXTZ0e rVnQ4SCJ+4r8Gl9CiY52zfNiiFJ6sfHpfQAIHj241v0AlrWPfelwak0Tt/lVhsNosbb/ UEYbEg1yYadNaDuWzVlta7Ff6eto9S+RS7SruMG8sCRl7Ej7C5SJL2ah0MB5e1LeU1D+ ik8w== 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 :arc-authentication-results; bh=/zxfXLwWBK3T3Db8C8zCoeD3jh9nGrADZQvLsOWG8kE=; b=eMuoEjiwVNhjAGETvAzKBusdWul2/3LxtQfMwaGWHPO8ZCFMQkyIUt6hD8NMUurQbN 2u3R7wxrsFCOj8C0P4RXgWrkCFnLp8dV+S/guV22Y1P1AXBu59uWuvOLmnzzGzRs9U+Q DbcuY4FOnVXXkaD9ktxwMVGKGh4Zdi/0wL0pLT2goRWe3dzkcHOnPLvg9bUnQPHulOLm apla/e/Y+k1Zpw3znshM3+OddNFK0dOXws51/aTAvYnlUoohlBhMBHCQhPKBTb9sA47u D+vMgmWwvRT8kHLU6HYCrdbvXyu/jMaplAOge2KygvoZKeUF+sE50iNKjBVbCqFw3yi/ hAow== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v2-v6si2319015pfv.57.2018.07.20.09.17.48; Fri, 20 Jul 2018 09:18:03 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387908AbeGTRGB (ORCPT + 99 others); Fri, 20 Jul 2018 13:06:01 -0400 Received: from laurent.telenet-ops.be ([195.130.137.89]:57092 "EHLO laurent.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731746AbeGTRGB (ORCPT ); Fri, 20 Jul 2018 13:06:01 -0400 Received: from ramsan.of.borg ([84.194.111.163]) by laurent.telenet-ops.be with bizsmtp id D4H11y01d3XaVaC014H2pJ; Fri, 20 Jul 2018 18:17:02 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.86_2) (envelope-from ) id 1fgY5V-0005wv-Sz; Fri, 20 Jul 2018 18:17:01 +0200 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1fgY5V-0007lX-QW; Fri, 20 Jul 2018 18:17:01 +0200 From: Geert Uytterhoeven To: Joerg Roedel , Magnus Damm , Laurent Pinchart Cc: iommu@lists.linux-foundation.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] iommu/ipmmu-vmsa: Fix allocation in atomic context Date: Fri, 20 Jul 2018 18:16:59 +0200 Message-Id: <20180720161659.29800-1-geert+renesas@glider.be> 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 When attaching a device to an IOMMU group with CONFIG_DEBUG_ATOMIC_SLEEP=y: BUG: sleeping function called from invalid context at mm/slab.h:421 in_atomic(): 1, irqs_disabled(): 128, pid: 61, name: kworker/1:1 ... Call trace: ... arm_lpae_alloc_pgtable+0x114/0x184 arm_64_lpae_alloc_pgtable_s1+0x2c/0x128 arm_32_lpae_alloc_pgtable_s1+0x40/0x6c alloc_io_pgtable_ops+0x60/0x88 ipmmu_attach_device+0x140/0x334 ipmmu_attach_device() takes a spinlock, while arm_lpae_alloc_pgtable() allocates memory using GFP_KERNEL. Originally, the ipmmu-vmsa driver had its own custom page table allocation implementation using GFP_ATOMIC, hence the spinlock was fine. Fix this by replacing the spinlock by a mutex, like the arm-smmu driver does. Fixes: f20ed39f53145e45 ("iommu/ipmmu-vmsa: Use the ARM LPAE page table allocator") Signed-off-by: Geert Uytterhoeven --- drivers/iommu/ipmmu-vmsa.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c index 6a0e7142f41bf667..8f54f25404456035 100644 --- a/drivers/iommu/ipmmu-vmsa.c +++ b/drivers/iommu/ipmmu-vmsa.c @@ -73,7 +73,7 @@ struct ipmmu_vmsa_domain { struct io_pgtable_ops *iop; unsigned int context_id; - spinlock_t lock; /* Protects mappings */ + struct mutex mutex; /* Protects mappings */ }; static struct ipmmu_vmsa_domain *to_vmsa_domain(struct iommu_domain *dom) @@ -599,7 +599,7 @@ static struct iommu_domain *__ipmmu_domain_alloc(unsigned type) if (!domain) return NULL; - spin_lock_init(&domain->lock); + mutex_init(&domain->mutex); return &domain->io_domain; } @@ -645,7 +645,6 @@ static int ipmmu_attach_device(struct iommu_domain *io_domain, struct iommu_fwspec *fwspec = dev->iommu_fwspec; struct ipmmu_vmsa_device *mmu = to_ipmmu(dev); struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain); - unsigned long flags; unsigned int i; int ret = 0; @@ -654,7 +653,7 @@ static int ipmmu_attach_device(struct iommu_domain *io_domain, return -ENXIO; } - spin_lock_irqsave(&domain->lock, flags); + mutex_lock(&domain->mutex); if (!domain->mmu) { /* The domain hasn't been used yet, initialize it. */ @@ -678,7 +677,7 @@ static int ipmmu_attach_device(struct iommu_domain *io_domain, } else dev_info(dev, "Reusing IPMMU context %u\n", domain->context_id); - spin_unlock_irqrestore(&domain->lock, flags); + mutex_unlock(&domain->mutex); if (ret < 0) return ret; -- 2.17.1