Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp992642imm; Sun, 2 Sep 2018 06:13:27 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZRJlrMHwSJkJXzPwBhAgv6KQ1czciFOwHKyiZT36AiLFQwCi4fv3PifyczOckTj1WYcDY+ X-Received: by 2002:a63:c14a:: with SMTP id p10-v6mr22218707pgi.305.1535894007269; Sun, 02 Sep 2018 06:13:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535894007; cv=none; d=google.com; s=arc-20160816; b=ZLenEvIdrungDvoACi4ZAU15r6bdnWCd9XSzh+zN5sBRkVx1QRdLI3wjYFHyUapey9 H59EK3WJBzB0tzcWx5E0DFKFgLiv47+sVmATl57adtesu45bD/17M6RQfijq2bBkF32a EoK2WiAfB21Wp/rhXD3/R6ZfegnwukRW0wCg66BBMZxg+ebICftBJk/s8/9X3XcN4AEk 8tSNfO9rF6xeVdZnI6xYOMNzRfZ5eSpBf1F/7npOiDLF5b54Xs/HwkQUvc/klFGQLz37 z2tdhpyI42TAHNyumnl+VMXvXChCWdRN8TNZ4DbrGiCPznzdl9TrVtzDupzmBxbLliLt gKdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=55dVMBef+LN9Lr2WR74L8m/VaoJJzIM74xzpOduoo5g=; b=zYXGytIub0otJcoJbO7Hd9JKdV0FKgq04pS2Anwc6RT1EDp9bbYag5RudIroJCIZ54 wvtE7M9Bu8yvoytZTT0JnMHgjEJ58nmRj0DViXAUYJscixrjmZhHNQooBhkQX06H+wb7 JH3aU8rW8QhSN/OTXEJtaQ1Uudz8182XdA3RLj8WeKHFdcdn9ZYR0JfpnXcH18JsVA6G r7icsiBVLBi9IKUQy4U3rfqbCH5zVrtdZy5U8YpgnMqvYDRtt9K+ExNr5M1I/KamlNjm TasJj0tuBz2FNn2mGkuSEptRhW7icBEwJ0MeZdCspSR4BAaiGDZdDFJl5KtBepzZAW4M Ef9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=jhjLMCH4; 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d12-v6si15778584pla.421.2018.09.02.06.13.12; Sun, 02 Sep 2018 06:13:27 -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=@microsoft.com header.s=selector1 header.b=jhjLMCH4; 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729561AbeIBRYE (ORCPT + 99 others); Sun, 2 Sep 2018 13:24:04 -0400 Received: from mail-dm3nam03on0120.outbound.protection.outlook.com ([104.47.41.120]:20016 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727480AbeIBRYD (ORCPT ); Sun, 2 Sep 2018 13:24:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=55dVMBef+LN9Lr2WR74L8m/VaoJJzIM74xzpOduoo5g=; b=jhjLMCH4HPkeR3zFqesD7qUpil3aEW8cNG1i7kn2OuO/OJN+Q7tBKaJozSsvhKrRz9yDMtbKIznfuB/Qz/zjwat9bTthrA3ly/d/A6iAsX/G89GI6xH6lXcHbQoaScQkza/K2yPx+V2sBPyBrzLkkcIqJBOiicWE7qlyeZvbzQY= Received: from CY4PR21MB0776.namprd21.prod.outlook.com (10.173.192.22) by CY4PR21MB0149.namprd21.prod.outlook.com (10.173.189.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1122.2; Sun, 2 Sep 2018 13:08:09 +0000 Received: from CY4PR21MB0776.namprd21.prod.outlook.com ([fe80::7c3a:eea8:1391:1611]) by CY4PR21MB0776.namprd21.prod.outlook.com ([fe80::7c3a:eea8:1391:1611%7]) with mapi id 15.20.1143.000; Sun, 2 Sep 2018 13:08:09 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Geert Uytterhoeven , Joerg Roedel , Sasha Levin Subject: [PATCH AUTOSEL 4.14 74/89] iommu/ipmmu-vmsa: Fix allocation in atomic context Thread-Topic: [PATCH AUTOSEL 4.14 74/89] iommu/ipmmu-vmsa: Fix allocation in atomic context Thread-Index: AQHUQr3tafKdFKxyukOt8FnqSQcHyg== Date: Sun, 2 Sep 2018 13:07:40 +0000 Message-ID: <20180902064918.183387-74-alexander.levin@microsoft.com> References: <20180902064918.183387-1-alexander.levin@microsoft.com> In-Reply-To: <20180902064918.183387-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;CY4PR21MB0149;6:D5p3qgvfADAQJtF6x5d0/m+xDLPcPbnz34Zkryr5TFr2scaaYYyppvJ2Nz7Lyz3fKKJek771fgbyrjEtDRmjapESryD+7zz+yrO8DnVbnwpIengf6bYiG4aStkrnYN7alc1DHN/nP/oMt2VDvXftSG8MvedPzJIHbYU01XrCbvoRlSQG6gb8f9eP++l6RrYuTxeVT4dY744zfWWruAAY+Dva2Hu+MwkDZ53QE+WI70abqHHnkuEBhbGoiw5L564HgqlzlUqr/2kZu4WIZ4VNMrTCMKvuPNd13IQy9LdcvC7cD+3+txM6W2ma+EvJavJg2rEj9xs3nWnEs1xXipGxdZV7wCQG6R2AZ1LpCZJV53EzEz+8CD+BmhDYpWMExYt58laqX6UdmU0HQy9Y6toD71UJIuJ+xUjyr7mFgTTidbjvc59JqOh4hz+uBvIFlfmGn9E0BQJ6FSeacuFSbgWChA==;5:0iB63vr9nIwToTtgAz/1wZRstVwy+72fgZDgLPeBO1porYCyjSMLVkAIntCkMLV50k66tTNmc0p7iGejNoR7CbBm+wr1yUPKKbWBRRnsFPuiHegxHzE6GkRpeUgbLj0NEjadlfwWla79rtrRe0ogGs0eL0mG2Iq6JaFQrA5e+g0=;7:LdCxfiiYccGe8oAdZADjMEvQ3SCN2KMpCuaFGXh862p/Bgi8Vl2WAzHdtfxKLKu/uzHoNpjxvaa+Bq5EBK1SzlX3By9qQPxQKlFLz1Yt6qLb5FUHOzj0mj+dXG6lBuwapdFVlcbdM4CFi/wDQe5EwPdqjh7m/3SmMw9fTIHPfYjfdhcBiLpq9nTJsqSipKLjhX8YjSAlT9NDwMuk3zStFo7WXhju3FrACvyCR1ICmvaNnY5Om7SkpGzdqsrn0P66 x-ms-office365-filtering-correlation-id: 1b9de22e-0a01-4815-c190-08d610d52181 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(4534165)(4627221)(201703031133081)(201702281549075)(5600074)(711020)(4618075)(2017052603328)(7193020);SRVR:CY4PR21MB0149; x-ms-traffictypediagnostic: CY4PR21MB0149: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(269456686620040); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3002001)(3231340)(944501410)(52105095)(2018427008)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123558120)(20161123562045)(201708071742011)(7699049)(76991033);SRVR:CY4PR21MB0149;BCL:0;PCL:0;RULEID:;SRVR:CY4PR21MB0149; x-forefront-prvs: 078310077C x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(366004)(376002)(39860400002)(136003)(346002)(396003)(199004)(189003)(76176011)(6116002)(446003)(11346002)(3846002)(5660300001)(110136005)(54906003)(102836004)(26005)(22452003)(316002)(99286004)(6506007)(186003)(6666003)(107886003)(25786009)(1076002)(4326008)(305945005)(2501003)(7736002)(66066001)(97736004)(10090500001)(68736007)(5250100002)(8676002)(81156014)(81166006)(6486002)(6512007)(6436002)(2906002)(53936002)(256004)(14444005)(5024004)(217873002)(36756003)(575784001)(86362001)(10290500003)(105586002)(106356001)(72206003)(14454004)(478600001)(2616005)(476003)(486006)(2900100001)(8936002)(86612001);DIR:OUT;SFP:1102;SCL:1;SRVR:CY4PR21MB0149;H:CY4PR21MB0776.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: GMFuEyXkkGb3lnHdluhMpTgA+V4RbVM6mN1rKvyArjXVy3ymZQiEFoSnpeVUt2IMFAztg9bcKaMm2wSO8nJbF0QTJaRok8mIjkMRt5hLnMBv0wRax6bSbrIOHg1D3IWXomHxwLOE57Fwd5e6mPg0lRdHo7ItZGNeLK9ElrOrSpnwLECKB7cAYBkz1i2GagVg02DwOKyj3L3PIXmCegM4fhPy/IFPfCZmzJE55avCUbKXlPkJVOHVMz/zRAQuwBGwpJFOEbAkq9Efzvbp9KZNzlmzyS+I9GcyKe214phQ9ciivJOhqMb6IFctmNQT80bpKa8HQu2D2214rBDK39q30OwHbUJeHQ6V2v6xXiFS2NE= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1b9de22e-0a01-4815-c190-08d610d52181 X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Sep 2018 13:07:40.2015 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR21MB0149 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Geert Uytterhoeven [ Upstream commit 46583e8c48c5a094ba28060615b3a7c8c576690f ] When attaching a device to an IOMMU group with CONFIG_DEBUG_ATOMIC_SLEEP=3Dy: 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 all= ocator") Signed-off-by: Geert Uytterhoeven Reviewed-by: Laurent Pinchart Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- 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 195d6e93ac71..5d0ba5f644c4 100644 --- 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; =20 unsigned int context_id; - spinlock_t lock; /* Protects mappings */ + struct mutex mutex; /* Protects mappings */ }; =20 struct ipmmu_vmsa_iommu_priv { @@ -523,7 +523,7 @@ static struct iommu_domain *__ipmmu_domain_alloc(unsign= ed type) if (!domain) return NULL; =20 - spin_lock_init(&domain->lock); + mutex_init(&domain->mutex); =20 return &domain->io_domain; } @@ -548,7 +548,6 @@ static int ipmmu_attach_device(struct iommu_domain *io_= domain, struct iommu_fwspec *fwspec =3D dev->iommu_fwspec; struct ipmmu_vmsa_device *mmu =3D priv->mmu; struct ipmmu_vmsa_domain *domain =3D to_vmsa_domain(io_domain); - unsigned long flags; unsigned int i; int ret =3D 0; =20 @@ -557,7 +556,7 @@ static int ipmmu_attach_device(struct iommu_domain *io_= domain, return -ENXIO; } =20 - spin_lock_irqsave(&domain->lock, flags); + mutex_lock(&domain->mutex); =20 if (!domain->mmu) { /* The domain hasn't been used yet, initialize it. */ @@ -574,7 +573,7 @@ static int ipmmu_attach_device(struct iommu_domain *io_= domain, } else dev_info(dev, "Reusing IPMMU context %u\n", domain->context_id); =20 - spin_unlock_irqrestore(&domain->lock, flags); + mutex_unlock(&domain->mutex); =20 if (ret < 0) return ret; --=20 2.17.1