From patchwork Sun Sep 2 13:05:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 145729 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1487209ljw; Sun, 2 Sep 2018 06:29:33 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYR7/Qh4FShS7qTdwPGKg5bIiMiYFJZ9t1veyP03ABe/1+7KwkduwNkXf1lirNU/DpVdKUy X-Received: by 2002:a65:6109:: with SMTP id z9-v6mr22542146pgu.243.1535894973063; Sun, 02 Sep 2018 06:29:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535894973; cv=none; d=google.com; s=arc-20160816; b=iFd7Q9cru0y/4LWLqeevzWE9gfZVj1HdhVVtTOSd5S0l6gTkGpX4QrjiAj/IRyqRfr C9gWGqIu4I61JvNhcVv1F4L3WOWls7MGSqd57wLaiB1qVJ9PA5puw5wmPgSzzcD9qMQT H3XLvEkO6dweFrUYxB1QCcjoSt54l0ugIwBNLWZ+9CkmEcM+6kcpOTnspCaY6h/nCFA1 YC3+gUbFCmSqBRrtm/lbXuZBspFe8lqMgdCS80BiQsv7AyfE8Gkyz+oQf/T4PRGF4AM2 7YblzAYOE4yKFzcZ57NwsJSbUUE9VWuGje16qdOmOUvbzFoQq3tYBs/WVBCseTtr/Pco lljQ== 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=SIcAO+MNytyVGmnYF/Z2WZ1hQNmXw02dYYDMNNkF4EA=; b=qiOnld+eY4bBtr7KjOjW+lEgAC+pxe0dJvpfHbWrMyYc0ArQDgHjgsGlI1wc1ex9Lb 8AkTbdQO5iv92PYBQjYqdrVMBVK0eua1ku0tyJzuFRzFITdXKj/qS78mhHT3oRkWxDM3 4BLZxTzCliTT++UmVPyaRedV0J6qWPwjSyQRpTaAYh0yNN+jvSd7kRb8JkCo8gIdsyW6 P75Gr3v2D5y1tlB/ga+ARsJZGoAVPnCmhwyT7ZxPHFp7ezFwD4iv/mTKlQlGUU1RD41C zzFbkIMw/dib0F9tUd8VJyK6iqROhHimoqMQzRzf3Z0ZkdwaaOliv2PnihJpOlOE2MTC 5ZHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=QYIhnxLV; 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 b87-v6si16640858pfm.5.2018.09.02.06.29.32; Sun, 02 Sep 2018 06:29:33 -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=QYIhnxLV; 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 S1728631AbeIBRV1 (ORCPT + 32 others); Sun, 2 Sep 2018 13:21:27 -0400 Received: from mail-co1nam03on0121.outbound.protection.outlook.com ([104.47.40.121]:64374 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728580AbeIBRV0 (ORCPT ); Sun, 2 Sep 2018 13:21:26 -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=SIcAO+MNytyVGmnYF/Z2WZ1hQNmXw02dYYDMNNkF4EA=; b=QYIhnxLVrXx+ABX0I+lmtbZibkEw6ysKaQsHvCWR8zDeTRCod8ZX30FkmuCIkQT5PCNPwncgJ/zSl6RcT4YhqLx9hAUbZKWf75EMGRswI1j70MfZLlAcJe+o0yMN1Es+JvfOvquHI4N10M30fY5I9ydVlOse/YUSCa32QnLCEYE= 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:36 +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:35 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Will Deacon , Sasha Levin Subject: [PATCH AUTOSEL 4.18 103/131] iommu/arm-smmu-v3: Abort all transactions if SMMU is enabled in kdump kernel Thread-Topic: [PATCH AUTOSEL 4.18 103/131] iommu/arm-smmu-v3: Abort all transactions if SMMU is enabled in kdump kernel Thread-Index: AQHUQr2VqdBlQttbL0y2JM9EMV+lIA== Date: Sun, 2 Sep 2018 13:05:13 +0000 Message-ID: <20180902064601.183036-103-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:j7NOWUaXyfh9yuKYnCsQEJoDt1HLzIW5/w6xtRezwWZDA5s3c0mEiph54NIB1XMBXqD7UjnPKYlt7YrRzCJ8R9iRRNxasWoF1VO8O+8NghDoCRPaXxtKWqj3N13vTMVvEgozjNoHAJ7f1IMG/sKzGYILv6vGJkwPeqR+wdfR7V+xrt/hPBqjEJuRnSfz9C5vu3ltucXwxOoj/1uPro9wJERjPR3uJjtDagjbZme5Cy+GoGnQsuCdtrPSVI2gI9BJv5PhjKgEVtbmaekoFdtEIlHUCxlMf/Wvq2h2PVmtU98nCqo65yOH84HnX/Pe/wDxs7tZDXpMVEQQBmik15bKHdXJogcezMRkFxaLea5FDy+VdAUrSFYXClSAU9la0aFw5xvfNfIsk8a5ipWD6bkX1/JOra/wFcurP8iW1IUmAXmjp9zIU9pRKxzJs9sfmLbnHHUtHcDH8fptbRmfkuxcPQ==; 5:y4nQrPN7qlPe95l6m8Nd2loKbshu9I11CBg7EBsrBtpB8UzCm0EnN+GjTUsEnHavlRZoZe6ge2L9vw+fQ3NW5lZ+IpE5cXmGqd6VeaqAWokOgvMJYmjOCh3iHBKBqysiAggKjRTpSzCajG8ex3bGRmSNZnt3+adQqSrpkiBIHIY=; 7:zr1SkIBfZwzc616ARin3IIAtXUuIHunyKPyY/CiLO5geyO5j7NjhtIVApnu5kya2v4w0Zv87UzMh25SoMYorswj+B0R1lUGt8ENt9eaepbk4kiMQlkzG9kiNNqMqp215X1TTwSAHilRPIeYhrsGoXS3i7rkbCnS7TVHBN3nDaJ75urvpViyGYcswFwhAksu1v1XuTZp1o0zyQTuDmVKQJi7hl+UWlN1MYQXuAS3Uy+eZdqUOrWSsFjIzqG3pAA/q x-ms-office365-filtering-correlation-id: 763bd9e1-6ac3-428f-8747-08d610d4c5f6 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)(180628864354917)(89211679590171); 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)(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)(575784001)(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: uhOqNe7BtjN+SEJhUTBAlkdeCXU4XggphCtYRG5dwgz3UPk3eZ5zN7podvW6R57WSobDgvOdeEsalvV8oxa/hjOle1tCsx3LcemUX1oVnntIg+mPNkhR1Y5WnzrNZl0+sENcAW+RqsNQ9C9wfdvvoY38sV0hTL/fRfE16yQMUkE4hyljAu8yyi51i8poTR1mcXBh43v/vs2XW4XCceZs6ImIb2SPVu9WvyTuWbSt8162dXvTN6zj5T1Da4LEi/0C7hfrD43IZFu4dUMjEYPyqCb4VkChaNYdC82zYGJsoZE0OPX/fU/5X/Tuz/FROoddSMM/YdhvyCh3Fs2OOtkJNeh/csgMVJ2thV4rwZQ9jxI= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 763bd9e1-6ac3-428f-8747-08d610d4c5f6 X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Sep 2018 13:05:13.1383 (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: Will Deacon [ Upstream commit b63b3439b85609338e4faabd5d2588dbda137e5c ] If we find that the SMMU is enabled during probe, we reset it by re-initialising its registers and either enabling translation or placing it into bypass based on the disable_bypass commandline option. In the case of a kdump kernel, the SMMU won't have been shutdown cleanly by the previous kernel and there may be concurrent DMA through the SMMU. Rather than reset the SMMU to bypass, which would likely lead to rampant data corruption, we can instead configure the SMMU to abort all incoming transactions when we find that it is enabled from within a kdump kernel. Reported-by: Sameer Goel Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- drivers/iommu/arm-smmu-v3.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) -- 2.17.1 diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index 1d647104bccc..b73c6a7bf7f2 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -2211,8 +2212,12 @@ static int arm_smmu_update_gbpa(struct arm_smmu_device *smmu, u32 set, u32 clr) reg &= ~clr; reg |= set; writel_relaxed(reg | GBPA_UPDATE, gbpa); - return readl_relaxed_poll_timeout(gbpa, reg, !(reg & GBPA_UPDATE), - 1, ARM_SMMU_POLL_TIMEOUT_US); + ret = readl_relaxed_poll_timeout(gbpa, reg, !(reg & GBPA_UPDATE), + 1, ARM_SMMU_POLL_TIMEOUT_US); + + if (ret) + dev_err(smmu->dev, "GBPA not responding to update\n"); + return ret; } static void arm_smmu_free_msis(void *data) @@ -2392,8 +2397,15 @@ static int arm_smmu_device_reset(struct arm_smmu_device *smmu, bool bypass) /* Clear CR0 and sync (disables SMMU and queue processing) */ reg = readl_relaxed(smmu->base + ARM_SMMU_CR0); - if (reg & CR0_SMMUEN) + if (reg & CR0_SMMUEN) { + if (is_kdump_kernel()) { + arm_smmu_update_gbpa(smmu, GBPA_ABORT, 0); + arm_smmu_device_disable(smmu); + return -EBUSY; + } + dev_warn(smmu->dev, "SMMU currently enabled! Resetting...\n"); + } ret = arm_smmu_device_disable(smmu); if (ret) @@ -2491,10 +2503,8 @@ static int arm_smmu_device_reset(struct arm_smmu_device *smmu, bool bypass) enables |= CR0_SMMUEN; } else { ret = arm_smmu_update_gbpa(smmu, 0, GBPA_ABORT); - if (ret) { - dev_err(smmu->dev, "GBPA not responding to update\n"); + if (ret) return ret; - } } ret = arm_smmu_write_reg_sync(smmu, enables, ARM_SMMU_CR0, ARM_SMMU_CR0ACK);