Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4538202imm; Mon, 17 Sep 2018 16:06:25 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZWwl6QFRut945iHvXZZNwWPmyJbcWqUobox5lvaoj+nqaLkfiskGfjwkIWCbKMu7grYvUy X-Received: by 2002:a63:3089:: with SMTP id w131-v6mr24706653pgw.79.1537225585117; Mon, 17 Sep 2018 16:06:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537225585; cv=none; d=google.com; s=arc-20160816; b=QRn1SIFSiQWTt3ufrqlmrGYvOa73tC+DZNwtKncO94fCiFcPtzDkCJmVeGicmVArww gYhxPNByOSrPEHYpW2O1TdEZMNCmousDDfQHTPglWD1MHwoao86b47sEbu01amxzyNNW 9J6vjza4L0YweLxdBn3RuRu9vQheyO4mKkqrdgcPI2t/SkPVC5OSOmnmRWQwHnePO2j3 R6hqkHJMfC0mPNEvVgXMnsmDDS0mxhXYpsz3KLuy2EqZLNdc8UqvwKmhxupMiELxYxfi U5EdbYLMOGQN1kRW7f1xTOvkI7DbIjzSEwQCw+YVuP6UvaD1Evlj3JY/81wmPWKbew35 OKGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=RlLL3503/Jg4XYUpqw/QVwBkDeJSer28kluP2dxSwhg=; b=p6yTxF16DWdVzxPF4TmoM/AHzzUMTZgyqN5LvfinNoCLu9Dx2QWHTv7VSvflYabpj6 h8e/1CJTC7RZUlgnqyqgy5HsNuFPUHuBs2HrjZdtQKthmBqqgTtXvsPmqMHVcd+ArIEs +c/SCnZhCU4Vr1Ztj5XPhCTVajleWYjn1yxJBokMw+pZ/AVnPAX2lG0SVTENfRivlhx6 9QwefN07kXbhmAQsFYwSVhhL39EDvUut5P+UTFfJ4monBwW41WAXLiE9uljAWMx1c8LH pTC0QFxy4YQ2/erJM3oBa67oXE3h2ThefxmGnJTBbuQEUDyDQS3utKi8JgPt1jH1neh0 NtWw== 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 y10-v6si17272963plp.410.2018.09.17.16.06.09; Mon, 17 Sep 2018 16:06:25 -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 S1731207AbeIREfe (ORCPT + 99 others); Tue, 18 Sep 2018 00:35:34 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:49424 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728677AbeIREfd (ORCPT ); Tue, 18 Sep 2018 00:35:33 -0400 Received: from localhost (li1825-44.members.linode.com [172.104.248.44]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 48541C49; Mon, 17 Sep 2018 23:06:03 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Geert Uytterhoeven , Laurent Pinchart , Joerg Roedel , Sasha Levin Subject: [PATCH 4.14 085/126] iommu/ipmmu-vmsa: Fix allocation in atomic context Date: Tue, 18 Sep 2018 00:42:13 +0200 Message-Id: <20180917211709.651465526@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180917211703.481236999@linuxfoundation.org> References: <20180917211703.481236999@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Geert Uytterhoeven [ Upstream commit 46583e8c48c5a094ba28060615b3a7c8c576690f ] 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 Reviewed-by: Laurent Pinchart Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/iommu/ipmmu-vmsa.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) --- a/drivers/iommu/ipmmu-vmsa.c +++ b/drivers/iommu/ipmmu-vmsa.c @@ -54,7 +54,7 @@ struct ipmmu_vmsa_domain { struct io_pgtable_ops *iop; unsigned int context_id; - spinlock_t lock; /* Protects mappings */ + struct mutex mutex; /* Protects mappings */ }; struct ipmmu_vmsa_iommu_priv { @@ -523,7 +523,7 @@ static struct iommu_domain *__ipmmu_doma if (!domain) return NULL; - spin_lock_init(&domain->lock); + mutex_init(&domain->mutex); return &domain->io_domain; } @@ -548,7 +548,6 @@ static int ipmmu_attach_device(struct io struct iommu_fwspec *fwspec = dev->iommu_fwspec; struct ipmmu_vmsa_device *mmu = priv->mmu; struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain); - unsigned long flags; unsigned int i; int ret = 0; @@ -557,7 +556,7 @@ static int ipmmu_attach_device(struct io return -ENXIO; } - spin_lock_irqsave(&domain->lock, flags); + mutex_lock(&domain->mutex); if (!domain->mmu) { /* The domain hasn't been used yet, initialize it. */ @@ -574,7 +573,7 @@ static int ipmmu_attach_device(struct io } 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;