Received: by 2002:a05:6830:16d2:b0:61c:ac69:ca1b with SMTP id l18csp2123104otr; Mon, 25 Jul 2022 07:54:05 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vhuKhJ9I9mPE/vIoUyUrRrfWQbArp1l2nXveagpo8JSDG9aj5s9dC9qcIUUhkPOfFvHX4V X-Received: by 2002:a17:907:2ccc:b0:72b:6907:fce6 with SMTP id hg12-20020a1709072ccc00b0072b6907fce6mr10631648ejc.115.1658760841618; Mon, 25 Jul 2022 07:54:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1658760841; cv=pass; d=google.com; s=arc-20160816; b=dLtaHdQWrJubZOISWb4y2EvulbfO/SjytgnfspboTLf/OO8r0QiO0e4XuDEUnoxmIn IWCeDEjJhnfC+Mcz8ofJf1xbmEM7Koth2kb2eGEyB1MPVpLitw/Y/xEP3Lk3UUWMAA3Y vZocBmBL0Or7a0G5uYLpw/qrqedp4/uiFC0xuPUNiXNSt5c44OCvyEEhfC3BTlg3msEx q7EroOMLrPu1WAP2qaPZIqnVBedzel9bcEb9BzuR5Da5/KOLgHkDajMiK2vlpnRcW23G a7VjkVrp+a9F2CbepGcTbBKS2AsGyw1GzDnom3rIpkoahz9ui2TSpL1y2qlCmQKVehGu yJHg== 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-disposition :references:message-id:subject:cc:to:from:date:dkim-signature; bh=TvcwXjKfTnvwlyY6OnOArGo+/kc4ZRYtSmYHhHnGWt8=; b=X4jVEJUaEs2KYAvcG45CydeMqWT05FIF5+ghorWhd7m1Lm+UIxHiaRDngPg3h6a6+t tjhI6FV0YbuuRuQZFNMF0tPUaI2yO5HyrO/BwAfPGF6Oc3DMP7xG/tAfyG5Dv+civv74 ymul7a+fZH82K5vd1uaiQWynpfn2XFwCU+pgfSoQeNqqKbhMFMu8srwaMUysSjOGWNLR rtGBGTk6gqBYsydiGjZIi+W3GPvhHyGrDEmmicsyM1RVdcijNZr5jexdYZpqnJqbEaY9 wv3KJ/uCSHerySfsw3NN2tYZVYrftrF3jCZsUwIGCIYDzpS1WLGhjrCyO7TgacQZS20b g/Fw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=CVjXTStP; 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 ho9-20020a1709070e8900b0072f22713ae6si17537873ejc.516.2022.07.25.07.53.36; Mon, 25 Jul 2022 07:54:01 -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=CVjXTStP; 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 S234315AbiGYOsF (ORCPT + 99 others); Mon, 25 Jul 2022 10:48:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229695AbiGYOsE (ORCPT ); Mon, 25 Jul 2022 10:48:04 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2078.outbound.protection.outlook.com [40.107.93.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22DAA13EA3 for ; Mon, 25 Jul 2022 07:48:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=L+9KbHSYhX8T2W573AetTlbXSwPUPgZgFzIKPyRVexgdYWZ+92XW7TdV6yCvKb7g2mEz9OPRS4O1mGkSoMnYJJwBREFOReSnLg4SsHLpRlsZ5ACVeePPbDQv1mCYlsjKdMx04DjYg47m0s1DMBrUI4qte6tDQEUDDzeEC+OcJKtD9z29sDafBDtfozHSmbjC1pW80e0kw4b4JstcyEQhrJnJl2xzEgKBgd/wLZ67XDYDTQmvkgGt3Dk9o9ScCwY7E9WnwK5EPG82h6e4NVfNtVk5IGwzcBfYh3Ve2WcuLLEYUoZAGdjUZJSOoVmwTZaiCd9WfiKwiEA1wxNMjpeftg== 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=TvcwXjKfTnvwlyY6OnOArGo+/kc4ZRYtSmYHhHnGWt8=; b=AbOhkA9mpw8aqfu9FsYF19+7RV3DsroQQS5pC1njCTBYeBvWiBaH6F0EiefYWz1hpu1WXwGOeW1VOZ7dUFRwRCdwAsKeZN7ff9s3xvDDkeUTq+FYK2TYGjWp+9fCtv5778yF13tBcoa6qQ8qA9/IriUDcohA+PC1zCIvonqx2ko5C7odeyk66z+bnfDzcdJ9o8I93c0gy+G+LkvNN1sI976XBl+h6F4rZ2idKvAUNIAWofXTWo3df6kwvXmmnjQgADkeVA7EfvCdZE7cROgtb8+ALYcwFMa6Fn/xBp2xGxxnjC5lm8saLq/AqeKveHYx43KUEPik1dTVdTh4iZ+oOw== 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=TvcwXjKfTnvwlyY6OnOArGo+/kc4ZRYtSmYHhHnGWt8=; b=CVjXTStPlHtlOG1X0F0YW0UgaaijHyARpdmTm77gtCwhCHNy5eTNX0rnybGS6F4vTr3ErKXR6Uwe8i5mkNrTrHEY2mpm28THEuS7YGCsk0mJEamUgMA4OWB2YrMoD2ukB9kl3VvaOzy+b8zO6zkGhUeYuXFiPvENtPQNwr5Ng5voxmU1r6P1oDpabttiyyFmQZaaa34vp4Dk0QVHZQc4NEs4MO1BU+0cJ6HK81L+QPar1c7Mx4DJ6Wn9fc/DIxqFhNc5Xeme0Y1VqiZ4tl8hx9JfikFfM/Pb23TqAd+5p+s22WLNpNJtDmXrhNqF+di0moH9Aunu2KCYMPMz+srl1g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from MN2PR12MB4192.namprd12.prod.outlook.com (2603:10b6:208:1d5::15) by DM4PR12MB6134.namprd12.prod.outlook.com (2603:10b6:8:ad::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5458.24; Mon, 25 Jul 2022 14:48:01 +0000 Received: from MN2PR12MB4192.namprd12.prod.outlook.com ([fe80::ac35:7c4b:3282:abfb]) by MN2PR12MB4192.namprd12.prod.outlook.com ([fe80::ac35:7c4b:3282:abfb%3]) with mapi id 15.20.5458.024; Mon, 25 Jul 2022 14:48:01 +0000 Date: Mon, 25 Jul 2022 11:47:58 -0300 From: Jason Gunthorpe To: Baolu Lu Cc: "Tian, Kevin" , Joerg Roedel , Christoph Hellwig , "Raj, Ashok" , Will Deacon , Robin Murphy , Jean-Philippe Brucker , "Jiang, Dave" , Vinod Koul , Eric Auger , "Liu, Yi L" , "Pan, Jacob jun" , Zhangfei Gao , "Zhu, Tony" , "iommu@lists.linux.dev" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v10 08/12] iommu/sva: Refactoring iommu_sva_bind/unbind_device() Message-ID: <20220725144758.GG3747@nvidia.com> References: <20220705050710.2887204-1-baolu.lu@linux.intel.com> <20220705050710.2887204-9-baolu.lu@linux.intel.com> <20220723142650.GH79279@nvidia.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: MW4PR04CA0351.namprd04.prod.outlook.com (2603:10b6:303:8a::26) To MN2PR12MB4192.namprd12.prod.outlook.com (2603:10b6:208:1d5::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1fb377fb-6af6-4160-4d66-08da6e4cac36 X-MS-TrafficTypeDiagnostic: DM4PR12MB6134:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2uoDGR9ZErYgPThXFUDCSOysbp/2/5vRS5HqH/YdYqYasCSOUMcdoTG9KtROa+5bfWBJVjKaN9Hi6FzwSQ3StmHcXS5pgf6HeDtySh9F8rKASs/OVTdXwrYvxZQchdILPh0GwZlkhMV+lKVU6jWvKt7rLuOMUINLkGE0gTJhvEPuC0qrShnFtp42j4a1KCX8cxNGi5YTFJ3AXL81aMSYKIBBTpUma1pmnhz0Bm1GLOWrLkatu2angvt9VvV+gv06LhQrr3pQbWzjPOR+IRZahb8hN6+fmE8uzDXtIHdXz5toNv0KTVQwkDQFrwkPQ3rlrIusTelfyduSfDmYiJcIpfshqURp/zevvH5qrnE2mfqcX71pFO3UqUV55te3tvQKiGf3R3MTZ31nPliNPjLMRtQrbq5+oGCwgceKCRGpt+hFDkSbDa4uFFtCohWeO0D5Bvh5whyg7NYtwFq1DrFlWT3517uq6YhwOaS15ABtI9I7C7uBwzj01DXJKBfYmB4CCwi6iw0EHT2iKFnTdGCdyxkXXr39cGA1LT0n9v4w33+xd/+7RMNiA7xpbj8r2uli8/dozGUnA/NSTvoyIcE7P2tajPCGd40ck1Xjhtf2nYSlT0nqhAAQ9+DoGm3IG/09tfg4FGcNRF02IZk+2BbfK6UODWkiR+EXlDMMS3t0ZzJ6s4WFEYBrmrkbahhQtTsVSpnSDykseAsSKEJMU4btxrW1dDOSzTcYhXABFtiC4azJv6epPY2LxL023pli6WnU X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR12MB4192.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(366004)(39860400002)(376002)(346002)(396003)(136003)(54906003)(41300700001)(316002)(6512007)(6916009)(6506007)(6666004)(53546011)(26005)(478600001)(6486002)(66556008)(66946007)(5660300002)(4326008)(8676002)(66476007)(7416002)(8936002)(33656002)(36756003)(38100700002)(2906002)(2616005)(186003)(86362001)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?1UP71y9HpS6DyBUu7vpAKEgU6JWwdnlLM77bqB9jbQ03gSeChnHfdZ33wUg1?= =?us-ascii?Q?SXhvkYLXcQxm8QxYTS9OXHeH6jq8b3PXsDKWk2wQla+WtMQov3bEgw2n1V9Y?= =?us-ascii?Q?vnEOplq/7fDl6nYrKiyHWaskIilH8GO8gyGJwaSnbvZ57oARDdJu2js8imTZ?= =?us-ascii?Q?lzQgiKR+WIyGXu+aWbHWI1eO/a3ozYFNZCIVKTNxhQteaesoT+Z4lOUI3dVY?= =?us-ascii?Q?aCl5cmHqJvOzFaaBWRJu85Em7IARQUyPayq2vZ4WvjBiYqbY1JAWgCuEAq1I?= =?us-asc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z4kNe2CG9fqL9XdA3X+v?= =?us-ascii?Q?DUFLlNDpEzOyJXH1zohIfzTe3BIj3yNw4Dl1Eu6axLnwoFg/HrdA6L0hSNMJ?= =?us-ascii?Q?6bTgSZlmsrAIJY/fm8o2PIEITKXp4x2iZvcLee2CoBJ/Su4JO/mgGPbbqdU5?= =?us-ascii?Q?H73O8RO7q9/GK1uhhsV9P6/B6fn3ugwyqq0u9xsP7VYtfW62rsojBjrF6Nbi?= =?us-ascii?Q?AAK4jBmlokEtq5KNbCCNwJJwT9eLJ3L7sn2BmyQ8pVL8sYIKKLr2BESSnzR5?= =?us-ascii?Q?IU1QOqtXj9MUIyhGfNrz7uZN1QOvjDfJ32h1oFneUZ+t4qkGe1W3/cIxqvnY?= =?us-ascii?Q?SMIa5cN+NPP2t3WufKbKC9O826mqEkaLvzrsa7PX/pgeolgdymsSpemPQ/2C?= =?us-ascii?Q?RGi9yrZHnChAT++kU00=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1fb377fb-6af6-4160-4d66-08da6e4cac36 X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB4192.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jul 2022 14:48:01.4526 (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: 7q/hagiVKcIQPxEBAp5hSBFhtwPyyNkv56C29EN22zknnl3KXRPSNPhvCaCJ4Une X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6134 X-Spam-Status: No, score=-1.7 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=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 Mon, Jul 25, 2022 at 06:22:06PM +0800, Baolu Lu wrote: > On 2022/7/25 15:50, Tian, Kevin wrote: > > > From: Baolu Lu > > > Sent: Sunday, July 24, 2022 9:48 PM > > > > > > > > The API is really refcounting the PASID: > > > > > > > > > +struct iommu_sva *iommu_sva_bind_device(struct device *dev, > > > > > + struct mm_struct *mm); > > > > > +void iommu_sva_unbind_device(struct iommu_sva *handle); > > > > > > > > So what you need to do is store that 'iommu_sva' in the group's PASID > > > > xarray. > > > > > > > > The bind logic would be > > > > > > > > sva = xa_load(group->pasid, mm->pasid) > > > > if (sva) > > > > refcount_inc(sva->users) > > > > return sva > > > > sva = kalloc > > > > sva->domain = domain > > > > xa_store(group->pasid, sva); > > > > > > Thanks for the suggestion. It makes a lot of sense to me. > > > > > > Furthermore, I'd like to separate the generic data from the caller- > > > specific things because the group->pasid_array should also be able to > > > serve other usages. Hence, the attach/detach_device_pasid interfaces > > > might be changed like below: > > > > > > /* Collection of per-pasid IOMMU data */ > > > struct group_pasid { > > > struct iommu_domain *domain; > > > void *priv; > > > }; > > > > > > > Is there any reason why pasid refcnt is sva specific and needs to be > > in a priv field? > > I am going to store the iommu_sva data which represents the bind > relationship between device and domain. Why do you need that? If you are starting at the pasid xarray then you already know the group/device, so we don't need to store it again. The only thing needed is the refcount so just store a refcount in this structure and be done with it. If someone needs to add something later then we can use a union or something, but right now adding an untagged void * is bad. Jason