Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp2475626rwp; Fri, 14 Jul 2023 06:50:20 -0700 (PDT) X-Google-Smtp-Source: APBJJlFoLn8gZgVuUSjQaSIICXch0UNuo5lYZMEtS21IY12x3W0dxu8pGope1zZtDdK5Smx6Gk6n X-Received: by 2002:aa7:c9d6:0:b0:51e:4fa:14e9 with SMTP id i22-20020aa7c9d6000000b0051e04fa14e9mr4124980edt.29.1689342620157; Fri, 14 Jul 2023 06:50:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1689342620; cv=pass; d=google.com; s=arc-20160816; b=Y7tGx6BAKijQ9AsXjWyPjcrc7HEM+nbrACF5Kmom1TF7/R1yifWMaAjvYTYGtVfFFg IMFtyImGPyKX461v5E/S1U+3eQHtTIG0nCZBS4xyWFmNQVdOpr5m1QB2oTdk18ipuP60 1gRH66tIwB8H5L12FUOrliXkRIp7kwhvewx89HR9CiTZHErV2/fXGAhi0NYge+m16TAB N1eP1N1XFow+aYi8jdwIGwUH9/mvUYaHjEpyYzxfcdAtlB9xhkakPE+nJgvJ8gnV9MP3 ewL7p/e3k1l6pJhM2R96096eXGuT+OBeUGxWQIIGQV9Mha7JjjCYy9P05VAaZ7mkH/p2 bwKg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:in-reply-to :content-transfer-encoding:content-disposition:references:message-id :subject:cc:to:from:date:dkim-signature; bh=Hh7dGIyrUfe/kJXD7jc2k58MEsA/vvgHQgLGgTRXK/4=; fh=uAgfBMYdT9xYq5aKQLfnl9zLsfCNEr6IBP1Gss7vyS8=; b=XBfZcK6xQAohMhpiAte8Wy3UktYeWg62uc6qFU6Mhz3G0D3eRwXg4+sTR8E/c4njty 7n1D/MYHB2U+MkSjcRQM2JNQJBoBdDjoZSyZCDodDfL6StmvmIvY3nhgQjSbFBb2T+m7 GkhL4wU0zU9Gtqap3kwW7dWLp2cxWHeEGJ3lkjuOXcH1HzEmmHulMN4fS0l5pxnGxNgc Ki1wzc0Pu1066Fkm0UauOONuzDN3j27ZlfrJdF3DQVRuNg0wtFZh1rVBsAiBkde9g5UW ABDabxrtd82ZIEKcXRayaVcboCpj5CKc778n8UunVw80yvCB6PDbTT5eT47jwfzW7PqI E92g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=mNUX2dhh; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d22-20020aa7d696000000b0051dec4bd870si9315689edr.101.2023.07.14.06.49.56; Fri, 14 Jul 2023 06:50:20 -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=mNUX2dhh; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=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 S235444AbjGNNVZ (ORCPT + 99 others); Fri, 14 Jul 2023 09:21:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233638AbjGNNVY (ORCPT ); Fri, 14 Jul 2023 09:21:24 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2040.outbound.protection.outlook.com [40.107.223.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D38DA1B6 for ; Fri, 14 Jul 2023 06:21:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IAq3yNAcl8LDm7ZvMX1ztZZD62j0Ymh+FhxhpPxDD9Tog71CoY3l9UTvlsc1G+5DTwrarhTqiBh3p9xzECafFtbRr79TkBLMDIQkBMxbeq8xosfAtGMruEoMuZAnzyErQOSxmFZYWyHwRjSmA3Mk8krUQL+qosAHaEwOt49GXEkfF7ImN9TID4S7mMIzdhztHZbsD1hagatqC9U+jD+ic9UqXOAipRGcB5TMhmy+hrPYxPjmVjvlp/6D43ESA9YEvNvjNjeaZMCYe1RCMRxp8q7296+r7TCCF0mmMp/Yz9vcO+X7RgpPLvdVRA9MuG/PWWB0K5LE8CklmAH/g4O/9w== 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=Hh7dGIyrUfe/kJXD7jc2k58MEsA/vvgHQgLGgTRXK/4=; b=nGsD87xIc6OsIVlIKJazTYI2u2TyJwA71LO+HPRpEmXjtulezCNn6vLsLahjXPeedF7SVYnByf7QcWfcXe+CaejGeU3f+aer64iIbRn0wws+cL6sp3Ki8oh5RmckdKWBygCtS/qGmbXZrBi6JP+9ocoNx2d9B0a/UdVwpW5KfSGJEHuAIn9J+vx5jG66An+PdswH2/u6i/4/gExJJKtaYJElifnT1tdfH3clYSqPSNDEy/dGCL5EhN/4EfG1EA5pJyEhxvIMjiK1h7poKsTe2do8iaOOogxo18JHgsyF4m9ivRqDHlOmwnFo8IjowANoKT/KaeBh5j3aVPRNpgtFVg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=Hh7dGIyrUfe/kJXD7jc2k58MEsA/vvgHQgLGgTRXK/4=; b=mNUX2dhh60L2nFgERIKbBf3n616VmTt4vTG9a5vHf1Nl0/ECLl3gi+7TGu8oGpPAYNF0OyN/XAyQNZ/VL7FQftRRzAy2I63yC5cJ4uZS/tNE4uE+bVBzVkpoiiI5h+j39lV8Di4oGQHKWTlBoyCuJNW9EdG7uJfywndr6iqBWCgDZQ6WV0wLodEiR9BH8HPspjQ010FzA8iyBXBVsDNiauyHACe9xeoQpyp6eExXzj5NAsnayMpHiiEQLNdRv1cvH/wFTIZb4FEB3CqmpEWzLOnfUlJYgE+eyp9Pfs7lxl7yKkIYSAf5JImc8bS8oM+1U94XWZA8eS674REkpWlFQA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) by CYYPR12MB8655.namprd12.prod.outlook.com (2603:10b6:930:c4::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.26; Fri, 14 Jul 2023 13:21:18 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::69c1:5d87:c73c:cc55]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::69c1:5d87:c73c:cc55%4]) with mapi id 15.20.6565.028; Fri, 14 Jul 2023 13:21:17 +0000 Date: Fri, 14 Jul 2023 10:21:14 -0300 From: Jason Gunthorpe To: Michael Shavit Cc: Nicolin Chen , Will Deacon , Robin Murphy , Joerg Roedel , jean-philippe@linaro.org, baolu.lu@linux.intel.com, linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 02/13] iommu/arm-smmu-v3: Add smmu_s1_cfg to smmu_master Message-ID: References: <20230621063825.268890-1-mshavit@google.com> <20230621063825.268890-3-mshavit@google.com> Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-ClientProxiedBy: SJ0PR13CA0069.namprd13.prod.outlook.com (2603:10b6:a03:2c4::14) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|CYYPR12MB8655:EE_ X-MS-Office365-Filtering-Correlation-Id: 83f59c63-da88-470a-920c-08db846d34a0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ky3EAGPtqMO1CJzxwU5V+hXEgwcIJbe1LQX59vWZ/FrTBraasIQekLCMXjYnX7+s9CgLk3D/xJtQgVmCOq7JlnWIPFtowcVbwotUoF0hY2joo3dJ0X2RAY99k7i6h2n7O80g2lsDTjoPnrGs+nv0kb3qN99hzRH157/zew6la5NFMpL1++S2ITs1SPtSekjVswtux0c1bbD2jyo9M8usqcQDuv37IYBbQYnvSOcam8aLjS4wNkBO0kD6Hmwf4KqxgM1Yba3EDtnzftVjJgyXHyt/O6OLPzcNbcc//eIbAKL+wN4h/toG83icbOExTSFP+wkqGhj3z4YSJg/43QxLcTsTq9aESDUs3wIKJYAIm2w0ZZwCJAP7jvZ9E/Fg5p6G4LCLCIitASCXk2O/Dg6nXUOVi+LGkSNxVa8e19RaKB7Rzgr5K+iWK/TNbrAzH3Wl/s/B8Q4PVLASxjf+d2E5wJFwYDUf+GNzM9Ykfh4vhLxiC2b4lvrsKkeE24SqK+Tr0xA+El6Jg/YICGM7d04KJvbEQkDhig3gsMyAdU5lq4GmNdgViVWeelMevhajKppi1qqu2CHBXHSRCY313EDtbXViikBFxuc4hNk11Wy1LrCKkm/1PdyfYE6jIB4nKRuU3CB4EIIxAYA5AnCpEu4RNQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LV2PR12MB5869.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(136003)(396003)(346002)(366004)(376002)(451199021)(6666004)(54906003)(6486002)(478600001)(86362001)(83380400001)(2616005)(36756003)(316002)(186003)(53546011)(6506007)(6512007)(2906002)(38100700002)(66476007)(66556008)(8676002)(26005)(41300700001)(6916009)(5660300002)(8936002)(66946007)(4326008)(67856001)(473944003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?Tkhta0xPRkxWSDRlTXJ6Y0VCN3Axb2V2enFpeVBxTjMzRzJDdlVzYk1wWHJh?= =?utf-8?B?RmpMdFJsbWhId2tQTFJaY3pLUWtnbnVBeG01N3ZpYk1LUk5oZ21RQzJRVnV2?= =?utf-8?B?SVNsK29YMDlFQnp0aFUxbmhRWVoyUGIxZ2VSU0lKUzk4R3ZDdnNGdGpVOGRL?= =?utf-8?B?aWRPbXdEaGVSdisySk9KaWJBOW1KRmNBNW1kY2FsN0JXM280U2lFYnRMVnBX?= =?utf-8?B?T29ZeUhDcmxkVlBhcFhiNE1sN0M3cUw4QWcxVStDR1JlcHVmUUpSblVVTjIr?= =?utf-8?B?cng0R2xONUh3TjRtR05uNlNrQUlCYzgxWGlJRytjWUFRU2s0N3BVbmt4UXpQ?= =?utf-8?B?Mld6MjRpZUc3UWlCdG9lQjZCa1NOZFFqWExiU240RmY5QXR1TGwxZ1NkMjZr?= =?utf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MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2023 13:21:17.4495 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Z2+mWhY9GkMfyYYXCm2kxGBplv792tTwBFK0UNkdX/nbVZF49XMHQe1RGf6Q4PVW X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB8655 X-Spam-Status: No, score=-1.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, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 14, 2023 at 04:02:50PM +0800, Michael Shavit wrote: > On Fri, Jul 14, 2023 at 12:41 AM Jason Gunthorpe wrote: > > The master object owns an optional CD table. If it is exsists it is > > used by every domain that is attached to that master. > > > > In the code flow there are two entry points to attach a domain, attach > > to a PASID or attach to a RID. > > > > For attach to PASID the code should always force the master to have a > > CD table and then attach the domain to the CD table. > > > > For attach to RID the code should do a bunch of checks and decide if > > it should force the master to have a CD table and attach the domain to > > that, or directly attach the domain to the STE. > > Yes. This is the current flow (except that we fail instead of forcing > when a CD table isn't already attached in the PASID flow). > owned_s1_cfg is simply a pre-allocated version of your optional CD > table. Really? That seems like a terrible name for the CD table. > > When the master gains a CD table then the CD table object becomes > > attached to the STE. In all cases we should be able to point to the > > object the STE points at and don't need a cfg or pointer to cfg since > > the object itself can provide the cfg. > > Ok, practically speaking, are we just talking about reverting patch 3 > and keeping a handle to the primary domain in arm_smmu_master? I think the master should have a pointer to the iommu_domain that owns the STE or if NULL the master should assign its internal CD table to the STE. The iommu_domain structs should not have any references to a CD table. > > I would suggest a 'cd table struct' that as all the stuff related to > > the CD table, including an API to cacluate the STE this CD table > > requires. If not in actual code with a real struct, then in a logical > > sense in that a chunk of the master struct is the "CD table". > > Sure, that's almost exactly what s1_cfg is today (with these patches).... > * s1_cfg.arm_smmu_ctx_desc_cfg describes the CD table > * s1_cfg.s1fmt and s1_cfg.s1cdmax describes attributes of that CD > table. These could technically be deduced-back from > arm_smmu_ctx_desc_cfg's l1_desc and num_l1_ents Yes, this makes sense, there is some redundancy here for sure. patch 1 makes sense, arm_smmu_ctx_desc is effectively the Context Descriptor Entry, and it belongs in the domain patch 2 should delete arm_smmu_s1_cfg and just put arm_smmu_ctx_desc_cfg directly in the master. arm_smmu_ctx_desc_cfg is a weird name for the contex descriptor table, but it is much less weird than s1_cfg. As you say s1fmt/s1cdmax are redundant. patch 3 I don't understand, we should not add something called s1_cfg/s2_cfg to the master. The master should have 'arm_smmu_ctx_desc_cfg cd_table' and 'arm_smmu_domain ste_domain' patch 4 should have everything working with the cd table accept a 'struct arm_smmu_ctx_desc_cfg *', eg arm_smmu_get_cd_ptr (get a pointer to a CD entry in the CD table). patch 5 makes sense, but something seems odd about the order as we somehow half moved it in patch 2? My suggestion for patch structure is to start by cleaning up the CD table object. Make arm_smmu_ctx_desc_cfg the CD table, remove the redudencies, remove arm_s1_cfg, clean the CD table APIs to only use 'struct arm_smmu_ctx_desc_cfg *', add the 'ste_domain' to the master, and then as the last step just move the arm_smmu_ctx_desc_cfg from the iommu_domain to the master. And that is a nice little series on its own - you end up with a shared CD table in the master, and no CD table in any domains. Jason