Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1001992imm; Sun, 2 Sep 2018 06:30:46 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbGHg8D7S+c0qJh8BcYWTF8+MSG02mwtOejIgVZkdFQ0UfHCx1arK5S2nzbvkIpW9nhTByF X-Received: by 2002:a62:9e08:: with SMTP id s8-v6mr25039528pfd.23.1535895046261; Sun, 02 Sep 2018 06:30:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535895046; cv=none; d=google.com; s=arc-20160816; b=ble+XFo3ISNqNMMNjWNKv5SGv2RCmjfS0cZwJOvkX3aAcpoHqfK3N2DkGADJXIyhXN 6zX8jGoVeKBvaTgMCnrfID+YxkH7AhSgjhPtsP4VOuTscPDJtNpzSqR1pti5O65jepNt uKbvS9JCDohYYonGfxNXEBGMFwznBlbMtjBW9H4iSxAu/PCGOC2zCMsDicNJu5ptquOe VNPnAhhMPeJ22nzn8N5xQxnFuGpQyyghIS+cfwRKUyZYEbVu4Ya5GcirGKDQtETXH/Kk zL9PMIjyviSrXPVaeznbqxEd3lbCsaTtHPZTe4a5AbYA3TIYmUYabbnn02hk84AldJWh Od3g== 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=M3a8VG0xFJoxF7TF61zt5I0InBxXtPnRJ3ODPR3Rdvk=; b=mZ+0yT69sKB9w0LOhQM0kraRxLfTdpzPm6/a+3qpeeAF0QGelL+XeriW2yAm6DgNm2 DBeARRuCEQZnJ6hAP5LBieAPutakW7tS0ins/CJIpzWz0x4ZjRvwJmKdO1WdgZIgw7sR 09f9u33Vt1N9WtUzSdeUo+FWb99g+IKE03UYU+cjLvOYsUTV7KJLTv+suy5VHxY70aJx p7rTkJB8oMHpzECIhmq/5vWYC7rhxFzsgdqX+Z8+yssdjH/3ANYjjrs1xI81FYOrRfqy VZwc81v6VbbW1rk57G0URpZK8i7TDpoVaUMpbbz3IYPy9YbyeUZmqLziM2tncAWPuZWl nkdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b="a6/94pfy"; 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 5-v6si14884960pgf.18.2018.09.02.06.30.31; Sun, 02 Sep 2018 06:30:46 -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="a6/94pfy"; 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 S1728946AbeIBRoz (ORCPT + 99 others); Sun, 2 Sep 2018 13:44:55 -0400 Received: from mail-eopbgr710105.outbound.protection.outlook.com ([40.107.71.105]:27886 "EHLO NAM05-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728662AbeIBRV3 (ORCPT ); Sun, 2 Sep 2018 13:21:29 -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=M3a8VG0xFJoxF7TF61zt5I0InBxXtPnRJ3ODPR3Rdvk=; b=a6/94pfyHQA/NCZSCiibYcr0q5IFo/0j/Ok7YVMSz3x2zuNHLlG3fcZTnDoITUvECCvW5SE8QQPXorS9yk/bYKg79g9utwWgkVIjBHptBjJTUi/VCWuD1hYfGE6zDVnwe0RxQF8I2xsv8zhZhWAUdJlRFaUx3s9dHyr3ycCWCQY= Received: from CY4PR21MB0776.namprd21.prod.outlook.com (10.173.192.22) by CY4PR21MB0184.namprd21.prod.outlook.com (10.173.193.10) 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:05:38 +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:05:38 +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.18 110/131] iommu/ipmmu-vmsa: Fix allocation in atomic context Thread-Topic: [PATCH AUTOSEL 4.18 110/131] iommu/ipmmu-vmsa: Fix allocation in atomic context Thread-Index: AQHUQr2a0nD9tQ4iPkigZ+RzAilQOw== Date: Sun, 2 Sep 2018 13:05:21 +0000 Message-ID: <20180902064601.183036-110-alexander.levin@microsoft.com> References: <20180902064601.183036-1-alexander.levin@microsoft.com> In-Reply-To: <20180902064601.183036-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;CY4PR21MB0184;6:eDxuPseflItpIM+NlqzS1vDEAr6Pz6xwzLnVGrFMNmeCGQ4ZF8KIPzajpEmXfb6EQf9JO6HpCX9t6a8LPz5yF6FckRGp8JieE3cyajhgFavmObz7tMGOV23E7p0Zwd7E1dufo56toxkbbocp/SQHW3P3LM8YIaTmcrvHKAGZnjW3RwClnihEHgMWJ0Q9WGvY6Px3+lquiaKMKU2yMn6nU5v6fVsB3qX3HXjxB8alXI7ydK3i4HoXBrRKv+IKnR4oEKiVl859Ug5BJ9ymeRymHNrqfYhXMFO7OhBnRUTE/s3div2sjN9hCG9wika/cAF+9WGgNSQgxMJxrFVrhyrZMe7jfZl962vZluyR3r3FnZFu6lV39XsjGfIPu/67gD+E4dbCAbDPggiuHS3OwZoz1gfltKupauhMn6PYtXtMniJQKUpPRDgYzJeyuHaLqfZz7Pn/n8unEuROe/+gnNN17A==;5:6Eyg97OTfBpwrgCkAcOnIKgI2UNzTojaZwNUy5h+c6iX//tATnQxrc7iPxM3ILv7xpFvSKGeibXRvQSa1DohOFWpMWkp7s7TmJVmdj1MvzelfQtqE5q6FuFCmy0Xvoz6vZKxIvC1MLyfFTmE+rqD2lN2y5/bI9Wmn2nfA6nXNvQ=;7:SfVIVsUvImksFxtRimIDli9W4hi4AzOZ3VMXu2ek1SxCiiqSPSkXI5Mf9CTuz1ZSxQfgSYtyQ0Wh+XFC+fL2ZTQQkCkrnZLvJP35rXzxIYLP5ZrWjczbi+V2gilFk1RnY3VHO+PKSDHhtL9NYnuS8FI2dp/OLR/8Fw7kO4xDnPv2E1gX518DfD9LTonJBX8uJ5J35IPE4tlzFsIWPLA1KuuEmfCt0E9UfUMo+Nh+lotLRo9xrYZO5sS77EvlvB7J x-ms-office365-filtering-correlation-id: 8b59b1da-30e8-4493-dabd-08d610d4c79d 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:CY4PR21MB0184; x-ms-traffictypediagnostic: CY4PR21MB0184: 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)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3002001)(3231340)(944501410)(52105095)(2018427008)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(201708071742011)(7699049)(76991033);SRVR:CY4PR21MB0184;BCL:0;PCL:0;RULEID:;SRVR:CY4PR21MB0184; x-forefront-prvs: 078310077C x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39860400002)(366004)(136003)(396003)(376002)(346002)(189003)(199004)(6512007)(53936002)(6436002)(97736004)(105586002)(22452003)(25786009)(106356001)(107886003)(4326008)(6486002)(110136005)(54906003)(316002)(10090500001)(5024004)(14444005)(5250100002)(256004)(66066001)(36756003)(6116002)(2501003)(26005)(6506007)(5660300001)(3846002)(81156014)(76176011)(99286004)(102836004)(1076002)(8676002)(81166006)(10290500003)(2616005)(68736007)(476003)(2906002)(8936002)(11346002)(72206003)(186003)(305945005)(7736002)(486006)(6666003)(217873002)(86362001)(2900100001)(86612001)(446003)(14454004)(478600001);DIR:OUT;SFP:1102;SCL:1;SRVR:CY4PR21MB0184;H:CY4PR21MB0776.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: eZeqt2Iwtz9Y06YqDGr4wGqu2Cv3MQpVAFN/l9yXrE0KQVlc4DczSMpapNdVvgUmv8l3YW4bIMthzQ98tzeKlFC/EliogFrt5RS//DYMXeUDSKa1VOmC4h80RZeI5PDlOTveS9n89KFyYKcwNJpVzkrtQ7bwh43OrwRJ6SB/fN5RcnK4R6MeW23K+eZMuf4UkeVGoGQjSqr7G9Y86OnhICaGHyi7RXVUXimM8Q7xvvO0D2iW4rx9BciGNQQJotm4We/lTJVo/FQyGPEbGt0yCNvnUV2IU2VN/Jt9aHf3MkGczCOOxVKgQwFESqJ9UxH6BHBHjHGUwuZTJ+oTI3xHtcNuM5EvmRV1UOnYm7NbjRY= 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: 8b59b1da-30e8-4493-dabd-08d610d4c79d X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Sep 2018 13:05:21.2510 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR21MB0184 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 40ae6e87cb88..ef566b4989d6 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; =20 unsigned int context_id; - spinlock_t lock; /* Protects mappings */ + struct mutex mutex; /* Protects mappings */ }; =20 static struct ipmmu_vmsa_domain *to_vmsa_domain(struct iommu_domain *dom) @@ -595,7 +595,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; } @@ -641,7 +641,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 to_ipmmu(dev); struct ipmmu_vmsa_domain *domain =3D to_vmsa_domain(io_domain); - unsigned long flags; unsigned int i; int ret =3D 0; =20 @@ -650,7 +649,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. */ @@ -674,7 +673,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