Message ID | 20221208151514.3840720-1-vladimir.oltean@nxp.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp256281wrr; Thu, 8 Dec 2022 07:20:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf7AjHuK+RidUog+E/BCkaT2IgeJqzBAITgROMDnZYLxJJmTpQjFIG3dMsZ1/N2JZOqPKqiH X-Received: by 2002:a17:907:d60b:b0:7bc:dbd8:184b with SMTP id wd11-20020a170907d60b00b007bcdbd8184bmr49085586ejc.110.1670512844939; Thu, 08 Dec 2022 07:20:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1670512844; cv=pass; d=google.com; s=arc-20160816; b=v4YlzNswLUt0z3JdevbBXrhv4GJTeJrlZJ4tOkp8r0oSaLSuWL19S1AN91w5btcx0w LxKe4u2Beje0fse3uApagwADfdX912HMTalA2+/8zpb9CKgjmwbKX5efYbI9UwmUmnu+ AzfuYqPCpfDEazXS5Jwwbsv6+Am7Qm6Qx+1XZK08kfIrs1VlAyTxLG0LMecPE+WuYuo+ iSHTdzOjZGR5KqtuZ3wbhduBr3ohxXIVFMhwcJYn4gxBskzRunsypdMd2SB7CIMT2Nhc +rYXETQhnxHnrxVIATz3BGLBWfLY2lRN1X6XhEZTavL5/cx06DrmAkVE23IFxCAIQyWf 8UFA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=NfB0hF8xj5xSy45sSCvyNvucOad/YqfjphkS6J56NhY=; b=d8JrWMqwA3E+G7hXIdqwL5raY9mM/bTMNJ6bcYknYYRMmSrJ66ArL2V8Z3dj8ZHYfR Tap/1qXPOqEOZiIRg2C0DLdkriX7Do4we3lTPcyoBgqxhRsWonSXT5W4Takilgfqmg2E XbWxEqN4BuNRrMIA0SCqDSHxTb35rhuE0PuJVVv3iSA8TmjWZmqLuhJXRXPZ+Oou74iu 35AJBXVKRZDDWK5IwtYn5+O7hNNn5RYWaUpSHitH0K7njeOYMXsY1/7frwTVtMmzRMVx QLn2fBjIPEZoExZl7WjYJAt1ssdvw02vT1TPi39Xj9ubeHH8XFamLz2cG+Y+zzyj3GIB ohiA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=nZhYsTRk; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bb5-20020a1709070a0500b007c0b9466effsi9028771ejc.656.2022.12.08.07.20.20; Thu, 08 Dec 2022 07:20:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=nZhYsTRk; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230281AbiLHPSV (ORCPT <rfc822;foxyelen666@gmail.com> + 99 others); Thu, 8 Dec 2022 10:18:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230273AbiLHPRt (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 8 Dec 2022 10:17:49 -0500 Received: from EUR02-DB5-obe.outbound.protection.outlook.com (mail-db5eur02on2068.outbound.protection.outlook.com [40.107.249.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13D699B29C; Thu, 8 Dec 2022 07:15:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lcqoCOw6M8G6DxzZYlJHrAkXkhgtoArxrPTnxZLLGRjW1cTQL2Mp/MiLu6KW5Kqe1U03eOCKtDL+nNEnc9kTnouX/WaviZAh0z5yTGzB/7uW3S5u4n1a5a6mE/TeR/FajBJVQgUHkB1wOETINTjH4N6pXKk3ytp1DiS5YbgKXZYlQZyFYI6qcTdZbED/lAUxe4WTlThOvFnDB+msFTQ/pSZGQlGZ8Aj4veR7x1Q8bio1pC2LkEoTmd+gRGU+pprjgVliYLa+3qRPx4O7VEH7fqL+vo5i8cMhXMthNxvFrCugt1saj3OCttci+DQcr0Y7E1oZq4S7pxD0F8LZFbHObw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=NfB0hF8xj5xSy45sSCvyNvucOad/YqfjphkS6J56NhY=; b=oPWPWtTGPKbvJGYpFQO49Z/070FZiThIK/bOyOTHI84wR+500R1CmqJp6TvA1klBR0x0sYKSAt1VMYC668SorP66hrRmCOfXbttHo3WTqr4u3KNt4xAqraNKcao+DIXAqclix+ods7KdNPc/DM6dtVYvLxvNTq8HM4Kbnsu9EcNZBq5tHHmCOnOzmlRtDXNS6gp3NUCurO273AyZK5yj0oSnTZinxvF1/C1uckk19iKkWK4KxoqxcG/j24UVQeeFBwyfg4YvkvtysIfUlWgTHYRIH6Xbo70yBnnEJ2A2qzd/pg6Hgo9mCf5yEQBMnMkTdptOIzFMyRlk0ByNx4K4AQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NfB0hF8xj5xSy45sSCvyNvucOad/YqfjphkS6J56NhY=; b=nZhYsTRkG/93nZmBNouWbPjzH59p93yzHwKldTlnAs8W2KOJqGuFfvgW6mB95gdT2BfMsT19nBKsbCSAJFcuq2Q6foXXdFDIBWXwsK+XcCAlfiEEQYCpl2yRbXzEoKsSkKE+iA5FX6gQDnWWFvzWw33pKEjcYk+Lt829mDkGyiU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by AM0PR04MB6961.eurprd04.prod.outlook.com (2603:10a6:208:180::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.10; Thu, 8 Dec 2022 15:15:34 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::9317:77dc:9be2:63b]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::9317:77dc:9be2:63b%7]) with mapi id 15.20.5880.014; Thu, 8 Dec 2022 15:15:34 +0000 From: Vladimir Oltean <vladimir.oltean@nxp.com> To: devicetree@vger.kernel.org, iommu@lists.linux.dev Cc: Laurentiu Tudor <laurentiu.tudor@nxp.com>, Will Deacon <will@kernel.org>, Robin Murphy <robin.murphy@arm.com>, linux-arm-kernel@lists.infradead.org, Shawn Guo <shawnguo@kernel.org>, Li Yang <leoyang.li@nxp.com>, Rob Herring <robh+dt@kernel.org>, Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>, linux-kernel@vger.kernel.org, Michael Walle <michael@walle.cc> Subject: [RFC PATCH] arm64: dts: ls1028a: mark ARM SMMU as DMA coherent Date: Thu, 8 Dec 2022 17:15:14 +0200 Message-Id: <20221208151514.3840720-1-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: AM0PR01CA0096.eurprd01.prod.exchangelabs.com (2603:10a6:208:10e::37) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR04MB5136:EE_|AM0PR04MB6961:EE_ X-MS-Office365-Filtering-Correlation-Id: 59ce40fc-2661-469c-ad3f-08dad92f0d90 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pSdjvIS8GKY73MzPot8K3qFJffhLGvpTIcXvUBsgqfg79j0X8oQk/yHPhRrYY9tqZSGyRF56bO8s6LXLXqEL8gBk22lrFaHMQ8hAYwGGjt3c3hxCyH3CaJ3b0TsGfpnpe+L4FSOa22PsNa6aIo5ozh6XlBUSY1OoxI4AZXyeydcDIaGbBti1qhU5nNBw+5O2in2R64UCXsLLDFmsY1mwTDNnWhw9PxL2/iSD27vMytR/U8AtWNg0rdemL4ogHwNN09e6EpJk3bP165ebE+ID6OUbYqJFLgM1aWO11qT+3FhxQgFWQzKI5L/4oF+wBzxa4cbZhfksiMaG6ZO6rqGF3hLFPqSTL3aAw6FanIeRfAVIrxdnfj0JP26orTlfmdccOg+sa3ds6TKyT3ByzlXpB2/qsqRMznnWxhI2akf7aoLK/MInUx09kGQy05IzXRXBSQXFfemFPFq0aUm1sP8PqIMyPr2H9IHFCj6DEgYHc8+zHQRv5X3uNj3Vzi64Gr00xSFCRTLARw0e0o6R9A0E6lzhfmix7GCBMuJfv5TChEXEDJtRv2DPrqk7QaN6x9410xZI1EVax1V8okKP6B/7X8aW0i4ZXnl0lzvTkVVTlulApGZP0sGzN7fFmDLbomYr5qbzctUKQZiOf6Jgql3jVTxeAnkPcpQmIewly2wSXOZiR3//cbsT6IG5k/dFm803PaICWnpWlgecaxeQ1X0Vgg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB5136.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(136003)(366004)(39860400002)(376002)(396003)(451199015)(6486002)(6666004)(478600001)(6506007)(52116002)(26005)(6512007)(66946007)(316002)(54906003)(66556008)(4326008)(66476007)(8676002)(1076003)(44832011)(186003)(83380400001)(2906002)(41300700001)(38350700002)(38100700002)(2616005)(36756003)(86362001)(5660300002)(7416002)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XhV0LlYPnc604XmEG1eD3vCYEX2bqAbxJJJCtRnCVuCay1AxdtGg9DcVsI1zzDASL07YCahxfj9RQWn738BEGfCIZReAD+//DJF0nuxWU4mCK/k1esioCXrNUlopUf1ZauEaaEcd5dzSbTKokLzwg9WJ154FEOM/gwo5cJ5NsdL9pgHfkV085YyYp1XZuSWOsGoVF3+XJbGuV8WyDY+FHQKhKkuwSz4WjSjP/XJtsXyMdb8K6NeaEmUDk7L/1D4spvhgGh6eaD2DwshpPJMikFBShzWBdVWYGisvgK9I7PuufwNqwvZoyyoABckzRXlu0a2ruO+Dyd/QhgDuKnkAM2+eYI1TrXDvm4EJs34CaGBxpdnThYwDvggwKhVD0maCD7WAE/XWQYOWcs9Xx5IPtqSdXMBmHfV5yASiUzxqoFG2I0tmAAue4rhoZcETwjfv50OJw3AOUql6N6yzVrsjzdfGgPQeZtcnwhs8zv0GVSgcSDQZMdaJ3OzZlPAFU8RkPgMMa4bEigmyPOLUpIQsVvM4NfcUeUkxUOb6fFSjdN/VZOQF3F/3t9eaXR0KuG3YHgq3Tn5lrZd2MLtc9NvwEuVUaY1m8t/5qqMY2SQwFOFK/UAOYVVhqLbmHxmZ6kj3UOU3IMPYqHAlT9TY8eU+ZXzHNN6WczhGG2cf0QZo2U7migmPy5Qu+ooWl5wbdjnAgp8LEN+AhvLUdSMV7dIdpEAhodT0Yf7kHfraIFlWlr7x7GcyeSSBUzQnfC2isiMIusWXifiBweSmT7tD7+3jdfF/tkSmzRLU/DytUBeJyUhNM+IzNajnj3HanzLp9Uephm1hY0Xw00Osu/QAHQ3moj1Auo+4KeV8kN6A0K6LG4jd74AmpuKefRiRrvL6vxASIqJAZowdm2gkeu3vomAT4zBHKQgZqT+mdDefENp+MNbIz8+uRbczbXEsVhjYMBcYr7gSNuy9ucd4+cusxoLPV6y+v8HpKqY1AWxLj/ao8W6GtStuHzHZpeq0n+CIJ4HzZoftJaaIXHmaRnbExkMQ+BfrW431rwi0UqObzwXhluy41EJLPppTRyuTTiJDDnzUJnMLfviAGALmx7fF+gxBfP11ldzXXNKFFMMCHQtImdjew0X6EqTTnIn4Hcy9vVZsyw8kFHHi2GFffUSczHorJF8owWyNDmiUwxG+Z3hvsvSqbTIF6Guxx6PvmU7Br8ibP7RcvqI5fB0UppSkwJClUSAjzppII6U+mfCPBDOd9MJtVPmli52UMsR9wRrhdH0OQEV3aTz5dOOsSgPMG773ENSWfJC2hDtvPMHkKqPMMnS2/O6NLrG89QeRVd7C2lLBD+OKd3Jra9SgfBkpfoxwMocXxWG3knL7BIxd5Qx6KQeIfuD1h3P/6O+5yh9sidT7UAL7IW0hzUkUoAtSV5MHuYKwBBSK9oel9vpZEiNQ2bD8TDe7Y8b1e2TDwawDljzWwNnDuuH2FXvUNQcWdO5tfHzb7O1wGPeEFBU3azvDaPFw8kSATctjDkBz8TBbgFhU+eYbYlvYLtrzvZeTXQbatmhGH0fBearxIrV9SnuJoN7isqHHYSokfUwiFnA9BsxzG6+GfZLfeG5KbOJRnK/BSg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 59ce40fc-2661-469c-ad3f-08dad92f0d90 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2022 15:15:34.2653 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: wX5X+rKRdsE75FzdbgxeonAd1T82UIoPLPCG9OY3dzrUUvKRIJb/Apgx36q/rZqB2x9qFeAOAEmLrM52mjeLHQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6961 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751659676938826369?= X-GMAIL-MSGID: =?utf-8?q?1751659676938826369?= |
Series |
[RFC] arm64: dts: ls1028a: mark ARM SMMU as DMA coherent
|
|
Commit Message
Vladimir Oltean
Dec. 8, 2022, 3:15 p.m. UTC
Since commit df198b37e72c ("iommu/arm-smmu: Report
IOMMU_CAP_CACHE_COHERENCY better"), the SMMU driver will say that a
device has the IOMMU_CAP_CACHE_COHERENCY capability if the
ARM_SMMU_FEAT_COHERENT_WALK bit was set in smmu->features.
This breaks vfio-pci, as can be seen below:
$ echo 0000:00:00.0 > /sys/bus/pci/drivers/fsl_enetc/unbind
$ echo vfio-pci > /sys/bus/pci/devices/0000\:00\:00.0/driver_override
$ echo 0000:00:00.0 > /sys/bus/pci/drivers/vfio-pci/bind
[ 25.261941] vfio-pci 0000:00:00.0: arm_smmu_capable: smmu features 0xe9e
[ 25.268877] vfio-pci 0000:00:00.0: vfio_group_find_or_alloc: device_iommu_capable() returned false
[ 25.279271] vfio-pci 0000:00:00.0: vfio_pci_core_register_device: failed to register group dev: -EINVAL
[ 25.301377] vfio-pci: probe of 0000:00:00.0 failed with error -22
The ARM_SMMU_FEAT_COHERENT_WALK feature is set in
arm_smmu_device_dt_probe() if the OF node of the SMMU device was set as
dma-coherent. In the case of LS1028A, it wasn't.
Fix that.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
The LS1028A is not the only SoC affected by this, it seems.
fsl-ls1088a.dtsi seems to be in the same situation where vfio-pci worked
before. There are also other SoCs which don't have dma-coherent in the
iommu node. There's also something I don't quite like about this patch
technically introducing a regression which requires a device tree update.
Can something different be done about that, or are LS1028A/LS1088A
simply to blame because of breaching the dt-bindings contract, and in
that case, I'll have to suck it up, put a Fixes tag here, write another
patch for LS1088A, and resend?
arch/arm64/boot/dts/freescale/fsl-ls1028a.dtsi | 1 +
1 file changed, 1 insertion(+)
Comments
On 08/12/2022 3:15 pm, Vladimir Oltean wrote: > Since commit df198b37e72c ("iommu/arm-smmu: Report > IOMMU_CAP_CACHE_COHERENCY better"), the SMMU driver will say that a > device has the IOMMU_CAP_CACHE_COHERENCY capability if the > ARM_SMMU_FEAT_COHERENT_WALK bit was set in smmu->features. > > This breaks vfio-pci, as can be seen below: > > $ echo 0000:00:00.0 > /sys/bus/pci/drivers/fsl_enetc/unbind > $ echo vfio-pci > /sys/bus/pci/devices/0000\:00\:00.0/driver_override > $ echo 0000:00:00.0 > /sys/bus/pci/drivers/vfio-pci/bind > [ 25.261941] vfio-pci 0000:00:00.0: arm_smmu_capable: smmu features 0xe9e > [ 25.268877] vfio-pci 0000:00:00.0: vfio_group_find_or_alloc: device_iommu_capable() returned false > [ 25.279271] vfio-pci 0000:00:00.0: vfio_pci_core_register_device: failed to register group dev: -EINVAL > [ 25.301377] vfio-pci: probe of 0000:00:00.0 failed with error -22 > > The ARM_SMMU_FEAT_COHERENT_WALK feature is set in > arm_smmu_device_dt_probe() if the OF node of the SMMU device was set as > dma-coherent. In the case of LS1028A, it wasn't. > > Fix that. > > Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> > --- > The LS1028A is not the only SoC affected by this, it seems. > fsl-ls1088a.dtsi seems to be in the same situation where vfio-pci worked > before. There are also other SoCs which don't have dma-coherent in the > iommu node. There's also something I don't quite like about this patch > technically introducing a regression which requires a device tree update. > > Can something different be done about that, or are LS1028A/LS1088A > simply to blame because of breaching the dt-bindings contract, and in > that case, I'll have to suck it up, put a Fixes tag here, write another > patch for LS1088A, and resend? It's more just good fortune that it ever worked properly at all. We have to make the DT authoritative about coherency because cases exist where the ID register is misconfigured. You've been telling Linux that that is the case, and now the message is finally getting through to VFIO. If we weren't also lazy in io-pgtable-arm about what shareability attribute to use for IOMMU_CACHE, you would have actually had the broken VFIO behaviour that that check is now defending against. I'd argue that you do want to make the DT change, because it's the truth of the hardware. Even if you did want to keep doing the significant extra work of maintaining non-coherent pagetables (there is a dubious snoop latency vs. TLB miss rate argument), that would be better achieved at the level of the io_pgtable_cfg, not by lying about the entire SMMU. However, since Jason refactored things at the VFIO end too, it looks like this should now be consistently checked for every individual device bound to a VFIO driver, so we might be able to do a bit better, as below. I'd be rather surprised if anyone ever genuinely built this topology, but it does happen to be the one other combination that's easy to infer with reasonable confidence. Thanks, Robin. ----->8----- diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c index 30dab1418e3f..a5ad9d6b51cf 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c @@ -1320,7 +1320,8 @@ static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap) switch (cap) { case IOMMU_CAP_CACHE_COHERENCY: /* Assume that a coherent TCU implies coherent TBUs */ - return cfg->smmu->features & ARM_SMMU_FEAT_COHERENT_WALK; + return cfg->smmu->features & ARM_SMMU_FEAT_COHERENT_WALK || + device_get_dma_attr(dev) == DEV_DMA_COHERENT; case IOMMU_CAP_NOEXEC: return true; default:
Hi Robin, On Thu, Dec 08, 2022 at 07:01:16PM +0000, Robin Murphy wrote: > It's more just good fortune that it ever worked properly at all. Thanks for the response. I don't know much about IOMMUs or the ARM SMMU, I'm trying to understand what you've said. I hope you don't mind a few foolish questions. > We have to make the DT authoritative about coherency because cases exist where > the ID register is misconfigured. Which ID register? The ARM_SMMU_ID0_CTTW bit in ARM_SMMU_GR0_ID0, as read by arm_smmu_device_cfg_probe()? I tried to find more about this bit (driver suggests it's bit 14), but I'm a bit lost. First of all, I don't know where to find the ID0 register for MMU-500. I looked at the register summary here and didn't find it: https://developer.arm.com/documentation/ddi0517/f/programmers-model/register-summary/global-address-space-0-registers-summary?lang=en Then I googled it and found this page, where it just says that at bit 14 there's indeed something named CTTW (unexplained) which is hardcoded to 0: https://developer.arm.com/documentation/ddi0517/e/programmers-model/memory-model/reset-values?lang=en I did however download the SMMU v2 arch spec PDF at https://developer.arm.com/documentation/ihi0062/latest and there, I did find it. But I'm not sure why the MMU-500 says it *should* be hardcoded to 0? Is this what you call "misconfigured"? On my hardware (both LS1028A and LS1088A), it reads: $ dmesg | grep smmu [ 4.825109] arm-smmu 5000000.iommu: probing hardware configuration... [ 4.831625] arm-smmu 5000000.iommu: SMMUv2 with: [ 4.836293] arm-smmu 5000000.iommu: GR0_ID0: 0x7c013e80 [ 4.841569] arm-smmu 5000000.iommu: stage 1 translation [ 4.846931] arm-smmu 5000000.iommu: stage 2 translation [ 4.852293] arm-smmu 5000000.iommu: nested translation [ 4.857573] arm-smmu 5000000.iommu: stream matching with 128 register groups [ 4.864776] arm-smmu 5000000.iommu: 64 context banks (0 stage-2 only) [ 4.871372] arm-smmu 5000000.iommu: Supported page sizes: 0x61311000 [ 4.877868] arm-smmu 5000000.iommu: Stage-1: 48-bit VA -> 48-bit IPA [ 4.884375] arm-smmu 5000000.iommu: Stage-2: 48-bit IPA -> 48-bit PA [ 4.893113] arm-smmu 5000000.iommu: preserved 0 boot mappings On the other hand, in the verbal (no registers) documentation of the MMU-500 integration in my SoCs, it does say that "The SMMU supports cache coherency for page table walks and DVM transactions for page table cache maintenance operations." Does looking at the CTTW bit make any sense for MMU-500? > You've been telling Linux that that is the case, and now the message > is finally getting through to VFIO. If we weren't also lazy in > io-pgtable-arm about what shareability attribute to use for IOMMU_CACHE, > you would have actually had the broken VFIO behaviour that that check > is now defending against. lazy in io-pgtable-arm == ?? I assume you're talking about something which is (not) done in arm_lpae_prot_to_pte()? Could you please clarify, as I didn't understand? IIUC (and I've been wrong before), the IOMMU_CACHE "prot" flag means that memory mapped by the IOMMU for DMA is coherent w.r.t. CPU caches, and VFIO specifically needs it because: * VFIO always sets IOMMU_CACHE because we offer no way for userspace to * restore cache coherency. i.o.w. user space can't execute cache invalidation instructions (DC CIVAC etc), which would make cache-coherent DMA transactions the only viable possibility. Right? > I'd argue that you do want to make the DT change, because it's the truth > of the hardware. Even if you did want to keep doing the significant > extra work of maintaining non-coherent pagetables (there is a dubious > snoop latency vs. TLB miss rate argument), that would be better achieved > at the level of the io_pgtable_cfg, not by lying about the entire SMMU. I do agree that we could set the dma-coherent property in the SMMU node to skip some of the wmb() instructions in the TLB invalidation procedures for stage 1/stage 2 translations. I wasn't trying to make any argument in favor of manually maintaining the cache coherency with the page tables. I'm just not exactly clear what does the page table walk of the SMMU TCU have to do with the cache coherence of the DMA transactions forwarded/translated by the TBUs. I mean, I saw the comment below: /* Assume that a coherent TCU implies coherent TBUs */ but I simply don't understand what is it that gives this assumption any grounds. > However, since Jason refactored things at the VFIO end too, it looks like > this should now be consistently checked for every individual device > bound to a VFIO driver, so we might be able to do a bit better, as > below. hmm, the change in vfio_group_find_or_alloc() between iommu_capable(dev->bus) and device_iommu_capable(dev) took place in commit a9cf69d0e7f2 ("Merge tag 'vfio-v6.0-rc1' of https://github.com/awilliam/linux-vfio"), says my git blame. Pretty strange. I had to use git log --graph to find your commit specifically: 3b498b665621 ("vfio: Use device_iommu_capable()"). > I'd be rather surprised if anyone ever genuinely built this > topology, but it does happen to be the one other combination that's easy > to infer with reasonable confidence. this topology == ? non-coherent SMMU page table walks but cache coherent DMA traffic of SMMU upstream device? Feasible or not, VFIO doesn't have a problem working with that device even if the SMMU doesn't do coherent walking of its translation tables, no? > > Thanks, > Robin. > > ----->8----- > diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c > index 30dab1418e3f..a5ad9d6b51cf 100644 > --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c > +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c > @@ -1320,7 +1320,8 @@ static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap) > switch (cap) { > case IOMMU_CAP_CACHE_COHERENCY: > /* Assume that a coherent TCU implies coherent TBUs */ > - return cfg->smmu->features & ARM_SMMU_FEAT_COHERENT_WALK; > + return cfg->smmu->features & ARM_SMMU_FEAT_COHERENT_WALK || > + device_get_dma_attr(dev) == DEV_DMA_COHERENT; So this works for enetc, thanks. However, do we need to also consider handling DEV_DMA_NOT_SUPPORTED, and thus, testing != DEV_DMA_NON_COHERENT could be better than == DEV_DMA_COHERENT? But from your response and the explanation in commit df198b37e72c ("iommu/arm-smmu: Report IOMMU_CAP_CACHE_COHERENCY better"), I'm not clear why we would keep looking at the COHERENT_WALK feature at all? It seems to my layman eyes that we are artificially coupling 2 concepts that have nothing in common, and bad reporting for one of them is causing trouble with the other. > case IOMMU_CAP_NOEXEC: > return true; > default: Thanks!
On 2022-12-14 16:53, Vladimir Oltean wrote: > Hi Robin, > > On Thu, Dec 08, 2022 at 07:01:16PM +0000, Robin Murphy wrote: >> It's more just good fortune that it ever worked properly at all. > > Thanks for the response. I don't know much about IOMMUs or the ARM SMMU, > I'm trying to understand what you've said. I hope you don't mind a few > foolish questions. > >> We have to make the DT authoritative about coherency because cases exist where >> the ID register is misconfigured. > > Which ID register? The ARM_SMMU_ID0_CTTW bit in ARM_SMMU_GR0_ID0, as > read by arm_smmu_device_cfg_probe()? Yes. > I tried to find more about this bit (driver suggests it's bit 14), but I'm a bit lost. > First of all, I don't know where to find the ID0 register for MMU-500. > I looked at the register summary here and didn't find it: > https://developer.arm.com/documentation/ddi0517/f/programmers-model/register-summary/global-address-space-0-registers-summary?lang=en > Then I googled it and found this page, where it just says that at bit 14 > there's indeed something named CTTW (unexplained) which is hardcoded to 0: > https://developer.arm.com/documentation/ddi0517/e/programmers-model/memory-model/reset-values?lang=en > I did however download the SMMU v2 arch spec PDF at > https://developer.arm.com/documentation/ihi0062/latest > > and there, I did find it. But I'm not sure why the MMU-500 says it > *should* be hardcoded to 0? Is this what you call "misconfigured"? For some reason, SMMU TRMs seem to have a tradition of describing their implementation of architectural registers in weird and unexpected places... Anyway that appears to be a documentation bug, since the actual SMMU_IDR0.CTTW value should reflect whatever is sampled on the cfg_cttw input at reset, per: https://developer.arm.com/documentation/ddi0517/f/signal-descriptions/miscellaneous-signals/tie-off-signals > On my hardware (both LS1028A and LS1088A), it reads: > > $ dmesg | grep smmu > [ 4.825109] arm-smmu 5000000.iommu: probing hardware configuration... > [ 4.831625] arm-smmu 5000000.iommu: SMMUv2 with: > [ 4.836293] arm-smmu 5000000.iommu: GR0_ID0: 0x7c013e80 > [ 4.841569] arm-smmu 5000000.iommu: stage 1 translation > [ 4.846931] arm-smmu 5000000.iommu: stage 2 translation > [ 4.852293] arm-smmu 5000000.iommu: nested translation > [ 4.857573] arm-smmu 5000000.iommu: stream matching with 128 register groups > [ 4.864776] arm-smmu 5000000.iommu: 64 context banks (0 stage-2 only) > [ 4.871372] arm-smmu 5000000.iommu: Supported page sizes: 0x61311000 > [ 4.877868] arm-smmu 5000000.iommu: Stage-1: 48-bit VA -> 48-bit IPA > [ 4.884375] arm-smmu 5000000.iommu: Stage-2: 48-bit IPA -> 48-bit PA > [ 4.893113] arm-smmu 5000000.iommu: preserved 0 boot mappings > > On the other hand, in the verbal (no registers) documentation of the > MMU-500 integration in my SoCs, it does say that "The SMMU supports cache > coherency for page table walks and DVM transactions for page table cache > maintenance operations." > > Does looking at the CTTW bit make any sense for MMU-500? In general, yes. The result above does imply that NXP have inadvertently set cfg_cttw wrong. For the avoidance of doubt, here's another MMU-500 showing SMMU_IDR0.CTTW set: [ 3.014972] arm-smmu arm-smmu.0.auto: probing hardware configuration... [ 3.014974] arm-smmu arm-smmu.0.auto: SMMUv2 with: [ 3.014976] arm-smmu arm-smmu.0.auto: stage 2 translation [ 3.014977] arm-smmu arm-smmu.0.auto: coherent table walk [ 3.014979] arm-smmu arm-smmu.0.auto: stream matching with 128 register groups [ 3.014981] arm-smmu arm-smmu.0.auto: 128 context banks (128 stage-2 only) [ 3.014984] arm-smmu arm-smmu.0.auto: Supported page sizes: 0x60211000 [ 3.014986] arm-smmu arm-smmu.0.auto: Stage-2: 48-bit IPA -> 48-bit PA >> You've been telling Linux that that is the case, and now the message >> is finally getting through to VFIO. If we weren't also lazy in >> io-pgtable-arm about what shareability attribute to use for IOMMU_CACHE, >> you would have actually had the broken VFIO behaviour that that check >> is now defending against. > > lazy in io-pgtable-arm == ?? > > I assume you're talking about something which is (not) done in > arm_lpae_prot_to_pte()? Could you please clarify, as I didn't understand? Strictly, a Cacheable mapping for a non-coherent device should probably have the Non-Shareable attribute, but since we assume that a non-coherent interconnect would ignore the shareability anyway, we don't bother, and just always use Inner-Shareable since that's the right value for when it *will* matter. Also io-pgtable couldn't make that decision itself, since it doesn't know anything about the intended use of the mapping other than an input address, and output address, and some abstract iommu_prot flags. > IIUC (and I've been wrong before), the IOMMU_CACHE "prot" flag means > that memory mapped by the IOMMU for DMA is coherent w.r.t. CPU caches, > and VFIO specifically needs it because: > > * VFIO always sets IOMMU_CACHE because we offer no way for userspace to > * restore cache coherency. > > i.o.w. user space can't execute cache invalidation instructions (DC CIVAC etc), > which would make cache-coherent DMA transactions the only viable possibility. > Right? Yes, userspace is in general not allowed to bypass CPU coherency for security reasons, so the only way it's viable for a device to operate directly on userspace mappings is if that device can snoop caches as well. Of course it's technically a bit different when that "userspace" is a virtual machine manager that's then going to hand control of the device to a VM that *can* do its own non-coherent cache maintenance, but I don't think we can easily make that distinction at the VFIO level. >> I'd argue that you do want to make the DT change, because it's the truth >> of the hardware. Even if you did want to keep doing the significant >> extra work of maintaining non-coherent pagetables (there is a dubious >> snoop latency vs. TLB miss rate argument), that would be better achieved >> at the level of the io_pgtable_cfg, not by lying about the entire SMMU. > > I do agree that we could set the dma-coherent property in the SMMU node > to skip some of the wmb() instructions in the TLB invalidation procedures > for stage 1/stage 2 translations. I wasn't trying to make any argument > in favor of manually maintaining the cache coherency with the page tables. FWIW it's not about the TLB maintenance in the driver, it's io-pgtable's cache maintenance on PTE updates, and even more so the synchronisation thereof, that gets pretty involved. > I'm just not exactly clear what does the page table walk of the SMMU TCU > have to do with the cache coherence of the DMA transactions forwarded/translated > by the TBUs. I mean, I saw the comment below: > > /* Assume that a coherent TCU implies coherent TBUs */ > > but I simply don't understand what is it that gives this assumption any > grounds. In short, it's based on how people tend to design SoCs in practice; I'm yet to come across any system where it doesn't hold. >> However, since Jason refactored things at the VFIO end too, it looks like >> this should now be consistently checked for every individual device >> bound to a VFIO driver, so we might be able to do a bit better, as >> below. > > hmm, the change in vfio_group_find_or_alloc() between iommu_capable(dev->bus) > and device_iommu_capable(dev) took place in commit a9cf69d0e7f2 ("Merge > tag 'vfio-v6.0-rc1' of https://github.com/awilliam/linux-vfio"), says my > git blame. Pretty strange. I had to use git log --graph to find your > commit specifically: 3b498b665621 ("vfio: Use device_iommu_capable()"). That's because that line does actually belong to the merge commit, where Linus resolved the conflict between my IOMMU patch changing the call and Jason's VFIO patch moving the callsite. >> I'd be rather surprised if anyone ever genuinely built this >> topology, but it does happen to be the one other combination that's easy >> to infer with reasonable confidence. > > this topology == ? > non-coherent SMMU page table walks but cache coherent DMA traffic of > SMMU upstream device? Yes. > Feasible or not, VFIO doesn't have a problem working with that device > even if the SMMU doesn't do coherent walking of its translation tables, > no? As you've quoted from the SoC documentation and demonstrated with this patch, this SMMU *is* coherent for both pagetable walks and client translation, and that's what matters in terms of VFIO not being completely broken. It makes no difference what pagetable walk attributes Linux actually uses, the underlying hardware is there to make IOMMU_CACHE snoop, which in this one weird corner case means that a couple of assumptions based on incorrect information cancel out, and something that seemingly shouldn't work, does. >> >> Thanks, >> Robin. >> >> ----->8----- >> diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c >> index 30dab1418e3f..a5ad9d6b51cf 100644 >> --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c >> +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c >> @@ -1320,7 +1320,8 @@ static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap) >> switch (cap) { >> case IOMMU_CAP_CACHE_COHERENCY: >> /* Assume that a coherent TCU implies coherent TBUs */ >> - return cfg->smmu->features & ARM_SMMU_FEAT_COHERENT_WALK; >> + return cfg->smmu->features & ARM_SMMU_FEAT_COHERENT_WALK || >> + device_get_dma_attr(dev) == DEV_DMA_COHERENT; > > So this works for enetc, thanks. However, do we need to also consider > handling DEV_DMA_NOT_SUPPORTED, and thus, testing != DEV_DMA_NON_COHERENT > could be better than == DEV_DMA_COHERENT? If firmware says the device can't access memory, can we make its memory accesses coherent?... Since it's likely to have a pretty bad time with VFIO either way, I think we can dodge getting philosophical here :) > But from your response and the explanation in commit df198b37e72c > ("iommu/arm-smmu: Report IOMMU_CAP_CACHE_COHERENCY better"), I'm not > clear why we would keep looking at the COHERENT_WALK feature at all? Because if the SMMU is coherent, then a stage 1 translation with IOMMU_CACHE can output cache-snooping attributes even if the device can't do so natively. Of course that isn't necessarily true for stage 2 (without venturing into S2CR attribute overrides), so we're still some way off giving an accurate answer here, but as the original commit said, the aim was not to be right, just less wrong. I'll try to improve the comment when I spin this tweak into a proper patch. Thanks, Robin. > It seems to my layman eyes that we are artificially coupling 2 concepts > that have nothing in common, and bad reporting for one of them is > causing trouble with the other. > >> case IOMMU_CAP_NOEXEC: >> return true; >> default: > > Thanks!
Hi Robin, On Wed, Dec 14, 2022 at 08:33:10PM +0000, Robin Murphy wrote: > > Does looking at the CTTW bit make any sense for MMU-500? > > In general, yes. The result above does imply that NXP have inadvertently set > cfg_cttw wrong. For the avoidance of doubt, here's another MMU-500 showing > SMMU_IDR0.CTTW set: > > [ 3.014972] arm-smmu arm-smmu.0.auto: probing hardware configuration... > [ 3.014974] arm-smmu arm-smmu.0.auto: SMMUv2 with: > [ 3.014976] arm-smmu arm-smmu.0.auto: stage 2 translation > [ 3.014977] arm-smmu arm-smmu.0.auto: coherent table walk > [ 3.014979] arm-smmu arm-smmu.0.auto: stream matching with 128 register groups > [ 3.014981] arm-smmu arm-smmu.0.auto: 128 context banks (128 stage-2 only) > [ 3.014984] arm-smmu arm-smmu.0.auto: Supported page sizes: 0x60211000 > [ 3.014986] arm-smmu arm-smmu.0.auto: Stage-2: 48-bit IPA -> 48-bit PA Thanks for the explanations and the patch you've sent separately. I have a side question, why is the dev_name() of your SMMU set to "arm-smmu.0.auto" (determined by PLATFORM_DEVID_AUTO if I'm not mistaken)? I'm asking because I would like to study the mechanism through which your SMMU platform device get probed, to make sure that it's not possible, during shutdown, for both platform_driver :: shutdown() and platform_driver :: remove() methods to get called by the driver core. This is generally not disallowed, and even possible if the entity who registers these platform devices has its ->shutdown() method pointing at ->remove().
On 19/12/2022 12:16 pm, Vladimir Oltean wrote: > Hi Robin, > > On Wed, Dec 14, 2022 at 08:33:10PM +0000, Robin Murphy wrote: >>> Does looking at the CTTW bit make any sense for MMU-500? >> >> In general, yes. The result above does imply that NXP have inadvertently set >> cfg_cttw wrong. For the avoidance of doubt, here's another MMU-500 showing >> SMMU_IDR0.CTTW set: >> >> [ 3.014972] arm-smmu arm-smmu.0.auto: probing hardware configuration... >> [ 3.014974] arm-smmu arm-smmu.0.auto: SMMUv2 with: >> [ 3.014976] arm-smmu arm-smmu.0.auto: stage 2 translation >> [ 3.014977] arm-smmu arm-smmu.0.auto: coherent table walk >> [ 3.014979] arm-smmu arm-smmu.0.auto: stream matching with 128 register groups >> [ 3.014981] arm-smmu arm-smmu.0.auto: 128 context banks (128 stage-2 only) >> [ 3.014984] arm-smmu arm-smmu.0.auto: Supported page sizes: 0x60211000 >> [ 3.014986] arm-smmu arm-smmu.0.auto: Stage-2: 48-bit IPA -> 48-bit PA > > Thanks for the explanations and the patch you've sent separately. > > I have a side question, why is the dev_name() of your SMMU set to > "arm-smmu.0.auto" (determined by PLATFORM_DEVID_AUTO if I'm not mistaken)? This is an ACPI-based machine, where platform device discovery and creation is... different :) SMMUs are among those managed by drivers/acpi/arm64/iort.c > I'm asking because I would like to study the mechanism through which > your SMMU platform device get probed, to make sure that it's not > possible, during shutdown, for both platform_driver :: shutdown() > and platform_driver :: remove() methods to get called by the driver core. > This is generally not disallowed, and even possible if the entity who > registers these platform devices has its ->shutdown() method pointing > at ->remove(). Yikes, I'd very much hope that that's not a thing! Cheers, Robin.
On Tue, Jan 03, 2023 at 06:12:29PM +0000, Robin Murphy wrote: > > I have a side question, why is the dev_name() of your SMMU set to > > "arm-smmu.0.auto" (determined by PLATFORM_DEVID_AUTO if I'm not mistaken)? > > This is an ACPI-based machine, where platform device discovery and creation > is... different :) > > SMMUs are among those managed by drivers/acpi/arm64/iort.c > > > I'm asking because I would like to study the mechanism through which > > your SMMU platform device get probed, to make sure that it's not > > possible, during shutdown, for both platform_driver :: shutdown() > > and platform_driver :: remove() methods to get called by the driver core. > > This is generally not disallowed, and even possible if the entity who > > registers these platform devices has its ->shutdown() method pointing > > at ->remove(). > > Yikes, I'd very much hope that that's not a thing! Ah, ok. Appears to be fine. Looking at drivers/acpi/arm64/iort.c, it seems that no one is removing those platform devices.
diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1028a.dtsi b/arch/arm64/boot/dts/freescale/fsl-ls1028a.dtsi index 383829ec7be7..bcce189c7a0a 100644 --- a/arch/arm64/boot/dts/freescale/fsl-ls1028a.dtsi +++ b/arch/arm64/boot/dts/freescale/fsl-ls1028a.dtsi @@ -715,6 +715,7 @@ smmu: iommu@5000000 { #global-interrupts = <8>; #iommu-cells = <1>; stream-match-mask = <0x7c00>; + dma-coherent; /* global secure fault */ interrupts = <GIC_SPI 13 IRQ_TYPE_LEVEL_HIGH>, /* combined secure interrupt */