Message ID | 20221103043852.24718-1-pshete@nvidia.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp315556wru; Wed, 2 Nov 2022 21:39:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7hglV1bTf8bUYar9V0v8XPdaTO+i0C46/VmGEQ5OqKq5oTUeaEitxv8tPUawY/L/xet3mH X-Received: by 2002:a17:902:7849:b0:186:68b9:e1ae with SMTP id e9-20020a170902784900b0018668b9e1aemr28334174pln.139.1667450377832; Wed, 02 Nov 2022 21:39:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1667450377; cv=pass; d=google.com; s=arc-20160816; b=0Umv2ziWau4JsSNCZgVu882G6t/N1I70txNUM+7g1cnkXoY0POsRBkzlYFabpNhm2v Gk00AjEKhpfhf6OOEAaqyzx99ue3e7XGMgKYd5zAwZCtQ2cq0aN8vkmXGDZB6insfwxD 6iuqIPAUoXkyuGHVJh3u0mm2wBWig7fOF2Gmw1oIhr86fLlBHeggrdew7cpeiqGTxNSN DH9Zb7U5ZLKZQpr/jkoQgg49fHKn3xLIUM40RgCUK4P1gFgxXUALuSE9i5pKvPxpUFlg o6gJisccwnnnCTnDG1ylcBWIfXtiWvFi+FDFBJzoE92BEFCQVM6m0zGiw42n4smfpVsO IBcQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=WOe3tdJRd878bJJt9S8xdg0gSuSIR/ugq8eLK5r+2OY=; b=qQOwoRAl+xGZlhafqO6yMHCAZxUpF6P+q0HDlyEbkq6ER0H/6qwMpRDguTXIiw6XXN 4P4kr/lTW1yxorzIPLvE9WbTlHNQn2OawNYibPar5V/xm6QiolCI7/zzWcWl7LrcsngR 57/Z6xr9pjllvw/TXbJ5dfAZm4mEn+28q3W6hQpxn0NlEG39E1H/egF2mgY0kwrw1SHk /W2NZ3lS+jI3qIxEH/yDJfqVacDS4W8RWSvKkMCrG4odDequSkd5FOuECj5cfgllWNq/ 7GhoW/k+W2qPL191RVbVMhMWgvyuDVBtFYzD4rbkOpYvnikv4tKKSVglSZLSaDx2JPeF 2NsA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b="b9YGY8/E"; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.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=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 14-20020a63000e000000b0046ee85f1477si18942651pga.712.2022.11.02.21.39.24; Wed, 02 Nov 2022 21:39:37 -0700 (PDT) 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=@Nvidia.com header.s=selector2 header.b="b9YGY8/E"; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.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=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230175AbiKCEjQ (ORCPT <rfc822;yves.mi.zy@gmail.com> + 99 others); Thu, 3 Nov 2022 00:39:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229980AbiKCEjN (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 3 Nov 2022 00:39:13 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2045.outbound.protection.outlook.com [40.107.92.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC72113E39; Wed, 2 Nov 2022 21:39:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hw3Y0Rz/NzVtvvjpPSXfGoakyEUZ6Wxej9Wf2he/G1ZELJzUghmWRjtTvuPngedCvjCVE09mz/z6yn9fUt35wlb9ZxYPGxmfzKUR3eme3pnZS72YpXLfPoUiN7pOa+l8sOMIxjKujY4uxWR+B66VdWE6WIxNlPkYf9uaokFM7VhB7vUMzmDiRV/rh51Q7cBZfHgI4fSyEz/xb4J1Y67FlSFQAxDQqd7ggkCQQHU+G6/49l+pfpvNP79Qw0sgd1VmYT0NyZ31IPnz/3wRWoClHI3CTibiIMOP3Ok38Qu1tIWXwu+/0HByICbWwWhBEcnWw/8AB+j+vEHlnup+yPnSOA== 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=WOe3tdJRd878bJJt9S8xdg0gSuSIR/ugq8eLK5r+2OY=; b=VP32l3j7o8tdbxOgYASxJp6Y/gyddG+ZohLsA42KQoWWpKKQ9tQZggLizN+mwTo5CTrwea7COjAOWcGQmiSaujdRqAz3TOLaVGk8r1FWUiQz0arorXMOLd9P9Lvr7NvrK1WpNLUwpvQs4j9xDP9t8nKYtOdaAr2e61tPAAF5ew1rTmMJKTZNsLPCnRXn3Lf0uHE241Y25QD0uM0l7wdYty8k8QtNtBmZHWCSbxpz33c2Io69r3jZF8K0D4afQqVn3Kw+2PNvn3iwng8AtJHqvjq2zkcLVIUvB2TjMXivYtBvtbPT1sqwQfN9yIOL7L0iEVaiCDSxPAyoweWE3UvXKQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=8bytes.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WOe3tdJRd878bJJt9S8xdg0gSuSIR/ugq8eLK5r+2OY=; b=b9YGY8/EFvUVfZ3Jb+ap4YseYYwJsVBwmJG7jKxQ/vJlldcY4m2RJS9yoewbRJKxXnwOeGvu9wvv5ieNvSfhug9Fw9N2Dkz8lOrvsWBWJNo0ns0kdYMRDPiLvcEYMwN38hKgbihJi3nBZq1gvTWi24GzlgrngQx2SFLHybg61n12mP+PfMVyHsZY4LPULuZPQDPefxL/q648RpLced1YB2g5BAeg44RP/eV6rjHDKBjK8203ZLiEdfr9zx3X/Xdkz7U4jeg1PR4kbYac2M1OlplxItLhT3vUGSeUETNsAj+WLXlmwddw0Tj8p+UKVkCzKWQCkii+7oYYi/4a3cKPUQ== Received: from MW4P221CA0016.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::21) by BY5PR12MB4068.namprd12.prod.outlook.com (2603:10b6:a03:203::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.19; Thu, 3 Nov 2022 04:39:10 +0000 Received: from CO1NAM11FT019.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8b:cafe::42) by MW4P221CA0016.outlook.office365.com (2603:10b6:303:8b::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.21 via Frontend Transport; Thu, 3 Nov 2022 04:39:10 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by CO1NAM11FT019.mail.protection.outlook.com (10.13.175.57) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.20 via Frontend Transport; Thu, 3 Nov 2022 04:39:10 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Wed, 2 Nov 2022 21:38:59 -0700 Received: from drhqmail202.nvidia.com (10.126.190.181) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.29; Wed, 2 Nov 2022 21:38:59 -0700 Received: from pshete-ubuntu.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.181) with Microsoft SMTP Server id 15.2.986.29 via Frontend Transport; Wed, 2 Nov 2022 21:38:54 -0700 From: Prathamesh Shete <pshete@nvidia.com> To: <joro@8bytes.org>, <adrian.hunter@intel.com>, <ulf.hansson@linaro.org>, <thierry.reding@gmail.com>, <jonathanh@nvidia.com>, <p.zabel@pengutronix.de>, <linux-mmc@vger.kernel.org>, <linux-tegra@vger.kernel.org>, <linux-kernel@vger.kernel.org> CC: <will@kernel.org>, <iommu@lists.linux.dev>, <robin.murphy@arm.com>, <anrao@nvidia.com>, <smangipudi@nvidia.com>, <pshete@nvidia.com>, <kyarlagadda@nvidia.com>, Thierry Reding <treding@nvidia.com> Subject: [PATCH v10 1/4] iommu: Always define struct iommu_fwspec Date: Thu, 3 Nov 2022 10:08:49 +0530 Message-ID: <20221103043852.24718-1-pshete@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <CAPDyKFqJdiCDkAfrONfnBVKw1v8=jZ+hEJiKGK70EQ4o7BSxaQ@mail.gmail.com> References: <CAPDyKFqJdiCDkAfrONfnBVKw1v8=jZ+hEJiKGK70EQ4o7BSxaQ@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT019:EE_|BY5PR12MB4068:EE_ X-MS-Office365-Filtering-Correlation-Id: dafdc173-8727-4487-e8e3-08dabd5559c8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HeieWi24wSWr18zRt3Z1hcyyQR1KvP8fIGhX2YodgJU//WbKfdbk9qNnphLZiBtcB8nXuY9/fO/lXHxAZusEh3B8FP3SO75aBb99PFT+WoYKZZxkIfRp2qDH6a9YJyoiZp3s00D0Z/Fttdrn3rvo+i4yTKtTN+rP2shU2UIKv6NvE9AvG+XnPbEb+gmqdaaIUx90V6YHlmIkYdAfKLFIgBf3vVwtEJnW9vDg/tXNaW/EBXTokJpmYOqshgPg4UY5LhXkVL3nnTzouNil331V+ezPyd0DvIfXjIrKLKoeUomwfmQPhEerupi3M3Bo2UaGMCKgPoJcWgd16DOp4OWAyayVuJj2xtETqa0Y771RVXcIquIe4oVkUzC8pRKPDdnRgpVW4wwiCLAOSVqfbN9WwZ/BVluqFLyNRvrbdjAcIdQQlKiHc5IQGrI8FDSqLsDvjYjjazDXYZbGVvmgf5715D1Lc+QRCIodN9Mx73qjreYvrGzromgmv9fMKxgOrXFWWpiZNpsBzswRDHKU88zdp/p1t7J/0iqNfZTQMeNpZXk5MLAJsbiJS0pWTxghRQX4UWoISrGt/BQuI26bl+taoKO635/Hw6gg2FGH3aWpHohGzRegqQjBRoFeao6wWEwPc2Fnw1+CkLfladnBoeQoo98UmUir/6T87rETdgckaRog+E0OxEx/ZVlpTcETtL+hPAvjP03MjpQTfuaSotHqfcTY2+NifQpVIDPAeXhO8I0GH92d0UO8Pnnv+BxxH1oRLbR+gxzwv8BAUMFIyo7XVg== X-Forefront-Antispam-Report: CIP:216.228.118.232;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge1.nvidia.com;CAT:NONE;SFS:(13230022)(4636009)(346002)(376002)(136003)(39860400002)(396003)(451199015)(36840700001)(40470700004)(46966006)(83380400001)(86362001)(82310400005)(40480700001)(36860700001)(36756003)(107886003)(110136005)(40460700003)(82740400003)(7636003)(316002)(356005)(6666004)(54906003)(2616005)(478600001)(426003)(41300700001)(5660300002)(26005)(8936002)(336012)(7416002)(8676002)(4326008)(186003)(7696005)(1076003)(47076005)(70586007)(70206006)(2906002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2022 04:39:10.1617 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dafdc173-8727-4487-e8e3-08dabd5559c8 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.232];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT019.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4068 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE 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?1748448447639997713?= X-GMAIL-MSGID: =?utf-8?q?1748448447639997713?= |
Series |
[v10,1/4] iommu: Always define struct iommu_fwspec
|
|
Commit Message
Prathamesh Shete
Nov. 3, 2022, 4:38 a.m. UTC
In order to fully make use of the !IOMMU_API stub functions, make the struct iommu_fwspec always available so that users of the stubs can keep using the structure's internals without causing compile failures. Signed-off-by: Thierry Reding <treding@nvidia.com> Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org> --- include/linux/iommu.h | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-)
Comments
On Thu, 3 Nov 2022 at 05:39, Prathamesh Shete <pshete@nvidia.com> wrote: > > In order to fully make use of the !IOMMU_API stub functions, make the > struct iommu_fwspec always available so that users of the stubs can keep > using the structure's internals without causing compile failures. > > Signed-off-by: Thierry Reding <treding@nvidia.com> > Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org> Joerg, Will, Robin - may I have an ack from some of you for $subject patch, so I can funnel it via my mmc tree for v6.2? Kind regards Uffe > --- > include/linux/iommu.h | 39 +++++++++++++++++++-------------------- > 1 file changed, 19 insertions(+), 20 deletions(-) > > diff --git a/include/linux/iommu.h b/include/linux/iommu.h > index ea30f00dc145..afa829bc4356 100644 > --- a/include/linux/iommu.h > +++ b/include/linux/iommu.h > @@ -173,6 +173,25 @@ enum iommu_dev_features { > > #define IOMMU_PASID_INVALID (-1U) > > +/** > + * struct iommu_fwspec - per-device IOMMU instance data > + * @ops: ops for this device's IOMMU > + * @iommu_fwnode: firmware handle for this device's IOMMU > + * @flags: IOMMU_FWSPEC_* flags > + * @num_ids: number of associated device IDs > + * @ids: IDs which this device may present to the IOMMU > + */ > +struct iommu_fwspec { > + const struct iommu_ops *ops; > + struct fwnode_handle *iommu_fwnode; > + u32 flags; > + unsigned int num_ids; > + u32 ids[]; > +}; > + > +/* ATS is supported */ > +#define IOMMU_FWSPEC_PCI_RC_ATS (1 << 0) > + > #ifdef CONFIG_IOMMU_API > > /** > @@ -600,25 +619,6 @@ extern struct iommu_group *generic_device_group(struct device *dev); > /* FSL-MC device grouping function */ > struct iommu_group *fsl_mc_device_group(struct device *dev); > > -/** > - * struct iommu_fwspec - per-device IOMMU instance data > - * @ops: ops for this device's IOMMU > - * @iommu_fwnode: firmware handle for this device's IOMMU > - * @flags: IOMMU_FWSPEC_* flags > - * @num_ids: number of associated device IDs > - * @ids: IDs which this device may present to the IOMMU > - */ > -struct iommu_fwspec { > - const struct iommu_ops *ops; > - struct fwnode_handle *iommu_fwnode; > - u32 flags; > - unsigned int num_ids; > - u32 ids[]; > -}; > - > -/* ATS is supported */ > -#define IOMMU_FWSPEC_PCI_RC_ATS (1 << 0) > - > /** > * struct iommu_sva - handle to a device-mm bond > */ > @@ -682,7 +682,6 @@ bool iommu_group_dma_owner_claimed(struct iommu_group *group); > > struct iommu_ops {}; > struct iommu_group {}; > -struct iommu_fwspec {}; > struct iommu_device {}; > struct iommu_fault_param {}; > struct iommu_iotlb_gather {}; > -- > 2.17.1 >
On 2022-11-03 04:38, Prathamesh Shete wrote: > In order to fully make use of the !IOMMU_API stub functions, make the > struct iommu_fwspec always available so that users of the stubs can keep > using the structure's internals without causing compile failures. I'm really in two minds about this... fwspecs are an internal detail of the IOMMU API that are meant to be private between individual drivers and firmware code, so anything poking at them arguably does and should depend on CONFIG_IOMMU_API. It looks like the stub for dev_iommu_fwspec_get() was only added for the sake of one driver that was misusing it where it really wanted device_iommu_mapped(), and has since been fixed, so if anything my preference would be to remove that stub :/ I don't technically have much objection to this patch in isolation, but what I don't like is the direction of travel it implies. I see the anti-pattern is only spread across Tegra drivers, making Tegra-specific assumptions, so in my view the best answer would be to abstract that fwpsec dependency into a single Tegra-specific helper, which would better represent the nature of what's really going on here. Thanks, Robin. > Signed-off-by: Thierry Reding <treding@nvidia.com> > Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org> > --- > include/linux/iommu.h | 39 +++++++++++++++++++-------------------- > 1 file changed, 19 insertions(+), 20 deletions(-) > > diff --git a/include/linux/iommu.h b/include/linux/iommu.h > index ea30f00dc145..afa829bc4356 100644 > --- a/include/linux/iommu.h > +++ b/include/linux/iommu.h > @@ -173,6 +173,25 @@ enum iommu_dev_features { > > #define IOMMU_PASID_INVALID (-1U) > > +/** > + * struct iommu_fwspec - per-device IOMMU instance data > + * @ops: ops for this device's IOMMU > + * @iommu_fwnode: firmware handle for this device's IOMMU > + * @flags: IOMMU_FWSPEC_* flags > + * @num_ids: number of associated device IDs > + * @ids: IDs which this device may present to the IOMMU > + */ > +struct iommu_fwspec { > + const struct iommu_ops *ops; > + struct fwnode_handle *iommu_fwnode; > + u32 flags; > + unsigned int num_ids; > + u32 ids[]; > +}; > + > +/* ATS is supported */ > +#define IOMMU_FWSPEC_PCI_RC_ATS (1 << 0) > + > #ifdef CONFIG_IOMMU_API > > /** > @@ -600,25 +619,6 @@ extern struct iommu_group *generic_device_group(struct device *dev); > /* FSL-MC device grouping function */ > struct iommu_group *fsl_mc_device_group(struct device *dev); > > -/** > - * struct iommu_fwspec - per-device IOMMU instance data > - * @ops: ops for this device's IOMMU > - * @iommu_fwnode: firmware handle for this device's IOMMU > - * @flags: IOMMU_FWSPEC_* flags > - * @num_ids: number of associated device IDs > - * @ids: IDs which this device may present to the IOMMU > - */ > -struct iommu_fwspec { > - const struct iommu_ops *ops; > - struct fwnode_handle *iommu_fwnode; > - u32 flags; > - unsigned int num_ids; > - u32 ids[]; > -}; > - > -/* ATS is supported */ > -#define IOMMU_FWSPEC_PCI_RC_ATS (1 << 0) > - > /** > * struct iommu_sva - handle to a device-mm bond > */ > @@ -682,7 +682,6 @@ bool iommu_group_dma_owner_claimed(struct iommu_group *group); > > struct iommu_ops {}; > struct iommu_group {}; > -struct iommu_fwspec {}; > struct iommu_device {}; > struct iommu_fault_param {}; > struct iommu_iotlb_gather {};
On Thu, Nov 03, 2022 at 12:23:20PM +0000, Robin Murphy wrote: > On 2022-11-03 04:38, Prathamesh Shete wrote: > > In order to fully make use of the !IOMMU_API stub functions, make the > > struct iommu_fwspec always available so that users of the stubs can keep > > using the structure's internals without causing compile failures. > > I'm really in two minds about this... fwspecs are an internal detail of the > IOMMU API that are meant to be private between individual drivers and > firmware code, so anything poking at them arguably does and should depend on > CONFIG_IOMMU_API. It looks like the stub for dev_iommu_fwspec_get() was only > added for the sake of one driver that was misusing it where it really wanted > device_iommu_mapped(), and has since been fixed, so if anything my > preference would be to remove that stub :/ Tegra has been using this type of weak dependency on IOMMU_API mainly in order to allow building without the IOMMU support on some old platforms where people may actually care about the kernel size (Tegra20 systems were sometimes severely constrained and don't have anything that we'd call an IOMMU today). We have similar stubs in place for most other major subsystems in order to allow code to simply compile out if the subsystem is disabled, which is quite convenient for sharing code between platforms that may want a given feature and other platforms that may not want it, without causing too much of a hassle with compile-testing. > I don't technically have much objection to this patch in isolation, but what > I don't like is the direction of travel it implies. I see the anti-pattern > is only spread across Tegra drivers, making Tegra-specific assumptions, so > in my view the best answer would be to abstract that fwpsec dependency into > a single Tegra-specific helper, which would better represent the nature of > what's really going on here. I don't see how this is an anti-pattern. It might not be common for drivers to need to reach into iommu_fwspec, so that might indeed be specific to Tegra (for whatever reason our IP seems to want extra flexibility), but the general pattern of using stubs is wide-spread, so I don't see why IOMMU_API would need to be special. Of course we could get rid of the stubs and make these hard dependencies, but I suspect some people may then get mad that they can no longer disable the IOMMU dependency. Thierry
On Thu, 3 Nov 2022 at 15:01, Thierry Reding <thierry.reding@gmail.com> wrote: > > On Thu, Nov 03, 2022 at 12:23:20PM +0000, Robin Murphy wrote: > > On 2022-11-03 04:38, Prathamesh Shete wrote: > > > In order to fully make use of the !IOMMU_API stub functions, make the > > > struct iommu_fwspec always available so that users of the stubs can keep > > > using the structure's internals without causing compile failures. > > > > I'm really in two minds about this... fwspecs are an internal detail of the > > IOMMU API that are meant to be private between individual drivers and > > firmware code, so anything poking at them arguably does and should depend on > > CONFIG_IOMMU_API. It looks like the stub for dev_iommu_fwspec_get() was only > > added for the sake of one driver that was misusing it where it really wanted > > device_iommu_mapped(), and has since been fixed, so if anything my > > preference would be to remove that stub :/ > > Tegra has been using this type of weak dependency on IOMMU_API mainly in > order to allow building without the IOMMU support on some old platforms > where people may actually care about the kernel size (Tegra20 systems > were sometimes severely constrained and don't have anything that we'd > call an IOMMU today). > > We have similar stubs in place for most other major subsystems in order > to allow code to simply compile out if the subsystem is disabled, which > is quite convenient for sharing code between platforms that may want a > given feature and other platforms that may not want it, without causing > too much of a hassle with compile-testing. I agree with the above. Moreover, the stubs make the code more portable/scalable and so it becomes easier to maintain. > > > I don't technically have much objection to this patch in isolation, but what > > I don't like is the direction of travel it implies. I see the anti-pattern > > is only spread across Tegra drivers, making Tegra-specific assumptions, so > > in my view the best answer would be to abstract that fwpsec dependency into > > a single Tegra-specific helper, which would better represent the nature of > > what's really going on here. > > I don't see how this is an anti-pattern. It might not be common for > drivers to need to reach into iommu_fwspec, so that might indeed be > specific to Tegra (for whatever reason our IP seems to want extra > flexibility), but the general pattern of using stubs is wide-spread, > so I don't see why IOMMU_API would need to be special. Again, I agree. Moreover, a "git grep CONFIG_IOMMU_API" indicates that the problem isn't specific to Tegra. The "#ifdef CONFIG_IOMMU_API" seems to be sprinkled across the kernel. I think it would be nice if we could improve the situation. So far, using stubs along with what the $subject patch proposes, seems to me to be the best approach. [...] Kind regards Uffe
On 2022-11-03 14:55, Ulf Hansson wrote: > On Thu, 3 Nov 2022 at 15:01, Thierry Reding <thierry.reding@gmail.com> wrote: >> >> On Thu, Nov 03, 2022 at 12:23:20PM +0000, Robin Murphy wrote: >>> On 2022-11-03 04:38, Prathamesh Shete wrote: >>>> In order to fully make use of the !IOMMU_API stub functions, make the >>>> struct iommu_fwspec always available so that users of the stubs can keep >>>> using the structure's internals without causing compile failures. >>> >>> I'm really in two minds about this... fwspecs are an internal detail of the >>> IOMMU API that are meant to be private between individual drivers and >>> firmware code, so anything poking at them arguably does and should depend on >>> CONFIG_IOMMU_API. It looks like the stub for dev_iommu_fwspec_get() was only >>> added for the sake of one driver that was misusing it where it really wanted >>> device_iommu_mapped(), and has since been fixed, so if anything my >>> preference would be to remove that stub :/ >> >> Tegra has been using this type of weak dependency on IOMMU_API mainly in >> order to allow building without the IOMMU support on some old platforms >> where people may actually care about the kernel size (Tegra20 systems >> were sometimes severely constrained and don't have anything that we'd >> call an IOMMU today). >> >> We have similar stubs in place for most other major subsystems in order >> to allow code to simply compile out if the subsystem is disabled, which >> is quite convenient for sharing code between platforms that may want a >> given feature and other platforms that may not want it, without causing >> too much of a hassle with compile-testing. > > I agree with the above. > > Moreover, the stubs make the code more portable/scalable and so it > becomes easier to maintain. Are you suggesting that having the same thing open-coded slightly differently (with bugs) in 8 different places is somehow more maintainable than abstracting it into a single centralised implementation? Is it "easier to maintain" when already seemingly every thing I try to clean up or refactor in the IOMMU API at the moment is stymied by finding Tegra drivers doing unexpected (and often questionable) things? Is it "more scalable" to make it even easier for people to copy questionable code without a second thought, leaving API maintainers to play an ever-expanding game of whack-a-mole to clean it up? No. No it chuffing well isn't :( >>> I don't technically have much objection to this patch in isolation, but what >>> I don't like is the direction of travel it implies. I see the anti-pattern >>> is only spread across Tegra drivers, making Tegra-specific assumptions, so >>> in my view the best answer would be to abstract that fwpsec dependency into >>> a single Tegra-specific helper, which would better represent the nature of >>> what's really going on here. >> >> I don't see how this is an anti-pattern. It might not be common for >> drivers to need to reach into iommu_fwspec, so that might indeed be >> specific to Tegra (for whatever reason our IP seems to want extra >> flexibility), but the general pattern of using stubs is wide-spread, >> so I don't see why IOMMU_API would need to be special. > > Again, I agree. The anti-pattern is reaching into some other driver's private data assuming a particular format, with zero indication of the huge degree of assumption involved, and half the time not even checking that what's being dereferenced is valid. > Moreover, a "git grep CONFIG_IOMMU_API" indicates that the problem > isn't specific to Tegra. The "#ifdef CONFIG_IOMMU_API" seems to be > sprinkled across the kernel. I think it would be nice if we could > improve the situation. So far, using stubs along with what the > $subject patch proposes, seems to me to be the best approach. Yes, there is plenty of code through the tree that is only relevant to the IOMMU API and would be a complete waste of space without it, that is not the point in question here. Grep for dev_iommu_fwspec_get; outside drivers/iommu, the only users are IOMMU-API-specific parts of ACPI code, as intended, plus 8 random Tegra drivers. Now, there does happen to be a tacit contract between the ACPI IORT code and the Arm SMMU drivers for how SMMU StreamIDs are encoded in their respective fwspecs, but it was never intended for wider consumption. If Tegra drivers want to have a special relationship with arm-smmu then fair enough, but they can do the same as MSM and formalise it somewhere that the SMMU driver maintainers are at least aware of, rather than holding the whole generic IOMMU API hostage. Since apparently it wasn't clear, what I was proposing is a driver helper at least something like this: int tegra_arm_smmu_streamid(struct device *dev) { #ifdef CONFIG_IOMMU_API struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev) if (fwspec && fwspec->num_ids == 1) return fwspec->ids[0] & 0xffff; #endif return -EINVAL; } Now THAT is scalable and maintainable; any number of random drivers can call it without any preconditions, it's a lot clearer what's going on, and I won't have to swear profusely while herding patches through half a dozen different trees if, when my ops rework gets to the point of refactoring iommu_fwspec with dev_iommu, it ends up changing anything significant. Thanks, Robin.
On Thu, 3 Nov 2022 at 18:35, Robin Murphy <robin.murphy@arm.com> wrote: > > On 2022-11-03 14:55, Ulf Hansson wrote: > > On Thu, 3 Nov 2022 at 15:01, Thierry Reding <thierry.reding@gmail.com> wrote: > >> > >> On Thu, Nov 03, 2022 at 12:23:20PM +0000, Robin Murphy wrote: > >>> On 2022-11-03 04:38, Prathamesh Shete wrote: > >>>> In order to fully make use of the !IOMMU_API stub functions, make the > >>>> struct iommu_fwspec always available so that users of the stubs can keep > >>>> using the structure's internals without causing compile failures. > >>> > >>> I'm really in two minds about this... fwspecs are an internal detail of the > >>> IOMMU API that are meant to be private between individual drivers and > >>> firmware code, so anything poking at them arguably does and should depend on > >>> CONFIG_IOMMU_API. It looks like the stub for dev_iommu_fwspec_get() was only > >>> added for the sake of one driver that was misusing it where it really wanted > >>> device_iommu_mapped(), and has since been fixed, so if anything my > >>> preference would be to remove that stub :/ > >> > >> Tegra has been using this type of weak dependency on IOMMU_API mainly in > >> order to allow building without the IOMMU support on some old platforms > >> where people may actually care about the kernel size (Tegra20 systems > >> were sometimes severely constrained and don't have anything that we'd > >> call an IOMMU today). > >> > >> We have similar stubs in place for most other major subsystems in order > >> to allow code to simply compile out if the subsystem is disabled, which > >> is quite convenient for sharing code between platforms that may want a > >> given feature and other platforms that may not want it, without causing > >> too much of a hassle with compile-testing. > > > > I agree with the above. > > > > Moreover, the stubs make the code more portable/scalable and so it > > becomes easier to maintain. > > Are you suggesting that having the same thing open-coded slightly > differently (with bugs) in 8 different places is somehow more > maintainable than abstracting it into a single centralised implementation? > > Is it "easier to maintain" when already seemingly every thing I try to > clean up or refactor in the IOMMU API at the moment is stymied by > finding Tegra drivers doing unexpected (and often questionable) things? > Is it "more scalable" to make it even easier for people to copy > questionable code without a second thought, leaving API maintainers to > play an ever-expanding game of whack-a-mole to clean it up? No. No it > chuffing well isn't :( Ohh, I wasn't aware of these kinds of issues for the IOMMU interface. Abusing interfaces is an orthogonal problem to what I was suggesting to solve here. The main problem I was trying to address was to prevent sprinkling subsystems/drivers with "#ifdefs" all over the place, as that doesn't scale. > > >>> I don't technically have much objection to this patch in isolation, but what > >>> I don't like is the direction of travel it implies. I see the anti-pattern > >>> is only spread across Tegra drivers, making Tegra-specific assumptions, so > >>> in my view the best answer would be to abstract that fwpsec dependency into > >>> a single Tegra-specific helper, which would better represent the nature of > >>> what's really going on here. > >> > >> I don't see how this is an anti-pattern. It might not be common for > >> drivers to need to reach into iommu_fwspec, so that might indeed be > >> specific to Tegra (for whatever reason our IP seems to want extra > >> flexibility), but the general pattern of using stubs is wide-spread, > >> so I don't see why IOMMU_API would need to be special. > > > > Again, I agree. > > The anti-pattern is reaching into some other driver's private data > assuming a particular format, with zero indication of the huge degree of > assumption involved, and half the time not even checking that what's > being dereferenced is valid. I see. > > > Moreover, a "git grep CONFIG_IOMMU_API" indicates that the problem > > isn't specific to Tegra. The "#ifdef CONFIG_IOMMU_API" seems to be > > sprinkled across the kernel. I think it would be nice if we could > > improve the situation. So far, using stubs along with what the > > $subject patch proposes, seems to me to be the best approach. > > Yes, there is plenty of code through the tree that is only relevant to > the IOMMU API and would be a complete waste of space without it, that is > not the point in question here. Grep for dev_iommu_fwspec_get; outside > drivers/iommu, the only users are IOMMU-API-specific parts of ACPI code, > as intended, plus 8 random Tegra drivers. > > Now, there does happen to be a tacit contract between the ACPI IORT code > and the Arm SMMU drivers for how SMMU StreamIDs are encoded in their > respective fwspecs, but it was never intended for wider consumption. If > Tegra drivers want to have a special relationship with arm-smmu then > fair enough, but they can do the same as MSM and formalise it somewhere > that the SMMU driver maintainers are at least aware of, rather than > holding the whole generic IOMMU API hostage. Thanks for clarifying this. I certainly understand your concern better now. > > Since apparently it wasn't clear, what I was proposing is a driver > helper at least something like this: > > int tegra_arm_smmu_streamid(struct device *dev) > { > #ifdef CONFIG_IOMMU_API > struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev) > > if (fwspec && fwspec->num_ids == 1) > return fwspec->ids[0] & 0xffff; > #endif > return -EINVAL; > } > > Now THAT is scalable and maintainable; any number of random drivers can > call it without any preconditions, it's a lot clearer what's going on, > and I won't have to swear profusely while herding patches through half a > dozen different trees if, when my ops rework gets to the point of > refactoring iommu_fwspec with dev_iommu, it ends up changing anything > significant. It sure sounds like we need another level of abstraction for iommus, to avoid the interface from being abused. Perhaps something along the lines of what we have for clocks (providers and consumers use different interfaces). Anyway, to simplify future potential rework in this direction, I can agree and understand your points. What you propose above, with one or a few Tegra specific helper functions, seems like the best we can do for now. Kind regards Uffe
On Thu, Nov 03, 2022 at 05:35:19PM +0000, Robin Murphy wrote: > On 2022-11-03 14:55, Ulf Hansson wrote: > > On Thu, 3 Nov 2022 at 15:01, Thierry Reding <thierry.reding@gmail.com> wrote: > > > > > > On Thu, Nov 03, 2022 at 12:23:20PM +0000, Robin Murphy wrote: > > > > On 2022-11-03 04:38, Prathamesh Shete wrote: > > > > > In order to fully make use of the !IOMMU_API stub functions, make the > > > > > struct iommu_fwspec always available so that users of the stubs can keep > > > > > using the structure's internals without causing compile failures. > > > > > > > > I'm really in two minds about this... fwspecs are an internal detail of the > > > > IOMMU API that are meant to be private between individual drivers and > > > > firmware code, so anything poking at them arguably does and should depend on > > > > CONFIG_IOMMU_API. It looks like the stub for dev_iommu_fwspec_get() was only > > > > added for the sake of one driver that was misusing it where it really wanted > > > > device_iommu_mapped(), and has since been fixed, so if anything my > > > > preference would be to remove that stub :/ > > > > > > Tegra has been using this type of weak dependency on IOMMU_API mainly in > > > order to allow building without the IOMMU support on some old platforms > > > where people may actually care about the kernel size (Tegra20 systems > > > were sometimes severely constrained and don't have anything that we'd > > > call an IOMMU today). > > > > > > We have similar stubs in place for most other major subsystems in order > > > to allow code to simply compile out if the subsystem is disabled, which > > > is quite convenient for sharing code between platforms that may want a > > > given feature and other platforms that may not want it, without causing > > > too much of a hassle with compile-testing. > > > > I agree with the above. > > > > Moreover, the stubs make the code more portable/scalable and so it > > becomes easier to maintain. > > Are you suggesting that having the same thing open-coded slightly > differently (with bugs) in 8 different places is somehow more maintainable > than abstracting it into a single centralised implementation? > > Is it "easier to maintain" when already seemingly every thing I try to clean > up or refactor in the IOMMU API at the moment is stymied by finding Tegra > drivers doing unexpected (and often questionable) things? Is it "more > scalable" to make it even easier for people to copy questionable code > without a second thought, leaving API maintainers to play an ever-expanding > game of whack-a-mole to clean it up? No. No it chuffing well isn't :( > > > > > I don't technically have much objection to this patch in isolation, but what > > > > I don't like is the direction of travel it implies. I see the anti-pattern > > > > is only spread across Tegra drivers, making Tegra-specific assumptions, so > > > > in my view the best answer would be to abstract that fwpsec dependency into > > > > a single Tegra-specific helper, which would better represent the nature of > > > > what's really going on here. > > > > > > I don't see how this is an anti-pattern. It might not be common for > > > drivers to need to reach into iommu_fwspec, so that might indeed be > > > specific to Tegra (for whatever reason our IP seems to want extra > > > flexibility), but the general pattern of using stubs is wide-spread, > > > so I don't see why IOMMU_API would need to be special. > > > > Again, I agree. > > The anti-pattern is reaching into some other driver's private data assuming > a particular format, with zero indication of the huge degree of assumption > involved, and half the time not even checking that what's being dereferenced > is valid. If this is really driver private data that nobody else should be accessing, then this certainly is lacking documentation. And quite frankly, perhaps it should really be hidden from other drivers in that case. Remember the reason why we want to make this change is because we can already get access to all this data if we depend on IOMMU_API, while all the rest is also already available for !IOMMU_API configurations. This change removes that inconsistency. > > Moreover, a "git grep CONFIG_IOMMU_API" indicates that the problem > > isn't specific to Tegra. The "#ifdef CONFIG_IOMMU_API" seems to be > > sprinkled across the kernel. I think it would be nice if we could > > improve the situation. So far, using stubs along with what the > > $subject patch proposes, seems to me to be the best approach. > > Yes, there is plenty of code through the tree that is only relevant to the > IOMMU API and would be a complete waste of space without it, that is not the > point in question here. Grep for dev_iommu_fwspec_get; outside > drivers/iommu, the only users are IOMMU-API-specific parts of ACPI code, as > intended, plus 8 random Tegra drivers. > > Now, there does happen to be a tacit contract between the ACPI IORT code and > the Arm SMMU drivers for how SMMU StreamIDs are encoded in their respective > fwspecs, but it was never intended for wider consumption. Again, if iommu_fwspec and its accessors were somehow hidden, or if it was documented that this was not meant for wider consumption, then perhaps we wouldn't have started using it in the first place. > If Tegra drivers > want to have a special relationship with arm-smmu then fair enough, but they > can do the same as MSM and formalise it somewhere that the SMMU driver > maintainers are at least aware of, rather than holding the whole generic > IOMMU API hostage. > > Since apparently it wasn't clear, what I was proposing is a driver helper at > least something like this: > > int tegra_arm_smmu_streamid(struct device *dev) > { > #ifdef CONFIG_IOMMU_API > struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev) > > if (fwspec && fwspec->num_ids == 1) > return fwspec->ids[0] & 0xffff; > #endif > return -EINVAL; > } > > Now THAT is scalable and maintainable; any number of random drivers can call > it without any preconditions, it's a lot clearer what's going on, and I > won't have to swear profusely while herding patches through half a dozen > different trees if, when my ops rework gets to the point of refactoring > iommu_fwspec with dev_iommu, it ends up changing anything significant. I don't have any objection to making that change. It's not like we're doing all of this just for fun. We need to do this in order for the hardware to work correctly. If the above is an acceptable way to do this and preferable to using the more generic API then we can move ahead with that. In order to keep things moving, do we want to merge the change as-is for now and then subsequently do a pass over all Tegra drivers and use a common function for stream ID access? Or do you want me to make that change prior to getting the SDHCI series merged? Thierry
On Fri, Nov 04, 2022 at 03:35:32PM +0100, Ulf Hansson wrote: > On Thu, 3 Nov 2022 at 18:35, Robin Murphy <robin.murphy@arm.com> wrote: > > > > On 2022-11-03 14:55, Ulf Hansson wrote: > > > On Thu, 3 Nov 2022 at 15:01, Thierry Reding <thierry.reding@gmail.com> wrote: > > >> > > >> On Thu, Nov 03, 2022 at 12:23:20PM +0000, Robin Murphy wrote: > > >>> On 2022-11-03 04:38, Prathamesh Shete wrote: > > >>>> In order to fully make use of the !IOMMU_API stub functions, make the > > >>>> struct iommu_fwspec always available so that users of the stubs can keep > > >>>> using the structure's internals without causing compile failures. > > >>> > > >>> I'm really in two minds about this... fwspecs are an internal detail of the > > >>> IOMMU API that are meant to be private between individual drivers and > > >>> firmware code, so anything poking at them arguably does and should depend on > > >>> CONFIG_IOMMU_API. It looks like the stub for dev_iommu_fwspec_get() was only > > >>> added for the sake of one driver that was misusing it where it really wanted > > >>> device_iommu_mapped(), and has since been fixed, so if anything my > > >>> preference would be to remove that stub :/ > > >> > > >> Tegra has been using this type of weak dependency on IOMMU_API mainly in > > >> order to allow building without the IOMMU support on some old platforms > > >> where people may actually care about the kernel size (Tegra20 systems > > >> were sometimes severely constrained and don't have anything that we'd > > >> call an IOMMU today). > > >> > > >> We have similar stubs in place for most other major subsystems in order > > >> to allow code to simply compile out if the subsystem is disabled, which > > >> is quite convenient for sharing code between platforms that may want a > > >> given feature and other platforms that may not want it, without causing > > >> too much of a hassle with compile-testing. > > > > > > I agree with the above. > > > > > > Moreover, the stubs make the code more portable/scalable and so it > > > becomes easier to maintain. > > > > Are you suggesting that having the same thing open-coded slightly > > differently (with bugs) in 8 different places is somehow more > > maintainable than abstracting it into a single centralised implementation? > > > > Is it "easier to maintain" when already seemingly every thing I try to > > clean up or refactor in the IOMMU API at the moment is stymied by > > finding Tegra drivers doing unexpected (and often questionable) things? > > Is it "more scalable" to make it even easier for people to copy > > questionable code without a second thought, leaving API maintainers to > > play an ever-expanding game of whack-a-mole to clean it up? No. No it > > chuffing well isn't :( > > Ohh, I wasn't aware of these kinds of issues for the IOMMU interface. > > Abusing interfaces is an orthogonal problem to what I was suggesting > to solve here. The main problem I was trying to address was to prevent > sprinkling subsystems/drivers with "#ifdefs" all over the place, as > that doesn't scale. > > > > > >>> I don't technically have much objection to this patch in isolation, but what > > >>> I don't like is the direction of travel it implies. I see the anti-pattern > > >>> is only spread across Tegra drivers, making Tegra-specific assumptions, so > > >>> in my view the best answer would be to abstract that fwpsec dependency into > > >>> a single Tegra-specific helper, which would better represent the nature of > > >>> what's really going on here. > > >> > > >> I don't see how this is an anti-pattern. It might not be common for > > >> drivers to need to reach into iommu_fwspec, so that might indeed be > > >> specific to Tegra (for whatever reason our IP seems to want extra > > >> flexibility), but the general pattern of using stubs is wide-spread, > > >> so I don't see why IOMMU_API would need to be special. > > > > > > Again, I agree. > > > > The anti-pattern is reaching into some other driver's private data > > assuming a particular format, with zero indication of the huge degree of > > assumption involved, and half the time not even checking that what's > > being dereferenced is valid. > > I see. > > > > > > Moreover, a "git grep CONFIG_IOMMU_API" indicates that the problem > > > isn't specific to Tegra. The "#ifdef CONFIG_IOMMU_API" seems to be > > > sprinkled across the kernel. I think it would be nice if we could > > > improve the situation. So far, using stubs along with what the > > > $subject patch proposes, seems to me to be the best approach. > > > > Yes, there is plenty of code through the tree that is only relevant to > > the IOMMU API and would be a complete waste of space without it, that is > > not the point in question here. Grep for dev_iommu_fwspec_get; outside > > drivers/iommu, the only users are IOMMU-API-specific parts of ACPI code, > > as intended, plus 8 random Tegra drivers. > > > > Now, there does happen to be a tacit contract between the ACPI IORT code > > and the Arm SMMU drivers for how SMMU StreamIDs are encoded in their > > respective fwspecs, but it was never intended for wider consumption. If > > Tegra drivers want to have a special relationship with arm-smmu then > > fair enough, but they can do the same as MSM and formalise it somewhere > > that the SMMU driver maintainers are at least aware of, rather than > > holding the whole generic IOMMU API hostage. > > Thanks for clarifying this. I certainly understand your concern better now. > > > > > Since apparently it wasn't clear, what I was proposing is a driver > > helper at least something like this: > > > > int tegra_arm_smmu_streamid(struct device *dev) > > { > > #ifdef CONFIG_IOMMU_API > > struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev) > > > > if (fwspec && fwspec->num_ids == 1) > > return fwspec->ids[0] & 0xffff; > > #endif > > return -EINVAL; > > } > > > > Now THAT is scalable and maintainable; any number of random drivers can > > call it without any preconditions, it's a lot clearer what's going on, > > and I won't have to swear profusely while herding patches through half a > > dozen different trees if, when my ops rework gets to the point of > > refactoring iommu_fwspec with dev_iommu, it ends up changing anything > > significant. > > It sure sounds like we need another level of abstraction for iommus, > to avoid the interface from being abused. Perhaps something along the > lines of what we have for clocks (providers and consumers use > different interfaces). Yeah, I was thinking along the same lines. It seems a bit odd to me that Tegra would be the only chip that ever needs access to the stream IDs outside of the IOMMU driver), so a generic function that would allow a device to retrieve its stream ID seems like it would be useful. We have a few cases where a device can have multiple stream IDs where we currently force them all to be the same for simplicity. One case where this can happen is when a device is both a DMA engine and a DMA-capable microcontroller in one, where the microcontroller can then use a stream ID separate from that of the DMA engine. We have another case where a device has multiple contexts for isolation where things are a bit trickier, but we already have an implementation using multiple logical devices and iommu-map to take care of that, so it basically boils down to the above use-case. > Anyway, to simplify future potential rework in this direction, I can > agree and understand your points. > > What you propose above, with one or a few Tegra specific helper > functions, seems like the best we can do for now. If this is really a Tegra-specific need, I guess we can start with a Tegra-specific helper. We could always generalize from that at a later point. Thierry
On Thu, Nov 03, 2022 at 05:35:19PM +0000, Robin Murphy wrote: [...] > Now, there does happen to be a tacit contract between the ACPI IORT code and > the Arm SMMU drivers for how SMMU StreamIDs are encoded in their respective > fwspecs, but it was never intended for wider consumption. If Tegra drivers > want to have a special relationship with arm-smmu then fair enough, but they > can do the same as MSM and formalise it somewhere that the SMMU driver > maintainers are at least aware of, rather than holding the whole generic > IOMMU API hostage. Are you talking about qcom_adrena_smmu_is_gpu_device()? That's the only place I can find where MSM uses iommu_fwspec directly and in a "special" way. > Since apparently it wasn't clear, what I was proposing is a driver helper at > least something like this: > > int tegra_arm_smmu_streamid(struct device *dev) > { > #ifdef CONFIG_IOMMU_API > struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev) > > if (fwspec && fwspec->num_ids == 1) > return fwspec->ids[0] & 0xffff; > #endif > return -EINVAL; > } We actually also use this mechanism on devices that predate the ARM SMMU, so it'd need to be even more generic. Also, since we need to access this from a wide range of subsystems, it'd need to be in a centralized place. Do you think iommu.h would be acceptable for this? How about if I also add a comment to struct iommu_fwspec about the intended use? Thierry
diff --git a/include/linux/iommu.h b/include/linux/iommu.h index ea30f00dc145..afa829bc4356 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -173,6 +173,25 @@ enum iommu_dev_features { #define IOMMU_PASID_INVALID (-1U) +/** + * struct iommu_fwspec - per-device IOMMU instance data + * @ops: ops for this device's IOMMU + * @iommu_fwnode: firmware handle for this device's IOMMU + * @flags: IOMMU_FWSPEC_* flags + * @num_ids: number of associated device IDs + * @ids: IDs which this device may present to the IOMMU + */ +struct iommu_fwspec { + const struct iommu_ops *ops; + struct fwnode_handle *iommu_fwnode; + u32 flags; + unsigned int num_ids; + u32 ids[]; +}; + +/* ATS is supported */ +#define IOMMU_FWSPEC_PCI_RC_ATS (1 << 0) + #ifdef CONFIG_IOMMU_API /** @@ -600,25 +619,6 @@ extern struct iommu_group *generic_device_group(struct device *dev); /* FSL-MC device grouping function */ struct iommu_group *fsl_mc_device_group(struct device *dev); -/** - * struct iommu_fwspec - per-device IOMMU instance data - * @ops: ops for this device's IOMMU - * @iommu_fwnode: firmware handle for this device's IOMMU - * @flags: IOMMU_FWSPEC_* flags - * @num_ids: number of associated device IDs - * @ids: IDs which this device may present to the IOMMU - */ -struct iommu_fwspec { - const struct iommu_ops *ops; - struct fwnode_handle *iommu_fwnode; - u32 flags; - unsigned int num_ids; - u32 ids[]; -}; - -/* ATS is supported */ -#define IOMMU_FWSPEC_PCI_RC_ATS (1 << 0) - /** * struct iommu_sva - handle to a device-mm bond */ @@ -682,7 +682,6 @@ bool iommu_group_dma_owner_claimed(struct iommu_group *group); struct iommu_ops {}; struct iommu_group {}; -struct iommu_fwspec {}; struct iommu_device {}; struct iommu_fault_param {}; struct iommu_iotlb_gather {};