Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1202931pxv; Fri, 25 Jun 2021 07:39:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjL4Ymgy5q5uX6cqW5jV2++j7hIT2Hr3QqWuSCoBnGtw+SnJmMgnc32kRG+IGOjtR7Tmj9 X-Received: by 2002:a17:906:90c4:: with SMTP id v4mr11027293ejw.382.1624631942669; Fri, 25 Jun 2021 07:39:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1624631942; cv=pass; d=google.com; s=arc-20160816; b=D859emBWZTe6XdIvll/xhfsYDE/NAHyNUwueCE9H3H01L2cuKH/hvJSv748dCjx0/Q pRa5X6i+z5ToyE0FRCs0V5F3x5xuXPU2QzSvhXk8HJt7Ya9bsrtwUPIkiV3qmGZqqGs6 66cxZeZmb6CPlwCsplb0qj4T5Ky7cG87N/XdHy7m09svEQw2X4Ng3m1Qn6l5InTrOXLr XqqY2J4h95cqAcyxgeuD+NrTUXnQ8PmFecNAiVHeGyk10p38VxzagAi4dKkUE3p+CQnB VaPGQNOobkVDXtOt0jnuRFBAgTaZ+Q16Rlm16bZ+TiDdC5bjakGHpPYq+t6TAbOnL6lC LgEA== 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=UOyIbOl699TjlYnCWB7KFn411bbKptDy0onYdCb0QQ8=; b=bA8QwqexwGPxGt6yhUs4uVc6WLGAEq9WJCEEjvhfFWMgvd2AmUAZYgY3UPrYM+Ggkj qv94M2ZnL+oNwbbzdwC7pM35ipXAEK1vAMr1CkTZmjEpUMi+l3uapL3oTQwyQNjJukGd Sl3dLGjShVSf2MMNYbTzVjEzgIF+63FR1aWpqwucEeq1M9MKa7og+VMi3U4X1zxFFCci igHwpBdwESPcqATW9+ElPrHZc2TG9+Zy9DpiuOMj5mnL+ibI9mxcqVHpSsQ3C98vsSkN z7eJmG38tRyUDDFl39DcK7OsMfsaxlBJB+ZJeBZa95vslrdIv7MYt6/HfnTe81CkxxbW lijw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b="dJlPwco/"; 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 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hw6si4139403ejc.243.2021.06.25.07.38.37; Fri, 25 Jun 2021 07:39:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b="dJlPwco/"; 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 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231445AbhFYOik (ORCPT + 99 others); Fri, 25 Jun 2021 10:38:40 -0400 Received: from mail-mw2nam10on2064.outbound.protection.outlook.com ([40.107.94.64]:20832 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229940AbhFYOij (ORCPT ); Fri, 25 Jun 2021 10:38:39 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=n1nzON9ILXEaCxuJCI0yq9ejYOzlsCdFc1zzFV9iB3liMVxaQ6HAhUxb97iwyPG5cTpvoQWpa8DKYd383eTL+J/z/b2umlh/NFCN6BXDmuENT2NQF26QasVZlFColJxm43PM9xZbeuA06toGePmQB0xsKT/SPYXYJv2wSaDnp/J381MA5LXFM8rMd9WdPzqczpXXs25fdac8EJ1IhfWYVNE9dGUYmcSYB3NYg8y2/IL+8v88UL7JGFGHEMytQ1+Oj6C+eaDR/J4xbYKB/C39ySDMgX7dvyjgJ0q8Bu6BISi0pHUD3w1Dl44zuWiqJ2efdoCTVPaiwI0Bs2+fCD+4wQ== 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-SenderADCheck; bh=UOyIbOl699TjlYnCWB7KFn411bbKptDy0onYdCb0QQ8=; b=BNXngiYHLi7UYPxRaUzeEViKTat1mvD2gpCno5T+JG991y+1Ly3qqu7H8Z8pPdsrjpchVoRNDzXqFCk2+d2SDXmPw2UK/Q+ulSWps+8KiZiWRCELXg+GIJLdHLXMZIoWZiY9fxeGulnXEwSsZdS5juZtQvNRuJ76XBONAs6mLJUtfKWk3p01bG15jcDkWBvvajolj9AcmM8igC/RKex/bDxBCycChOlQbKFk0jZiHGSQOLed4vpabaPWqJx3+aBGnv/KfYR3vjsN99Y8ZMmImjaQm7d68mh+6nU8alkmRYQho5hDdY22NzCuG0wLyBveckeXs+UBxlL391WgEAQ8mQ== 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=UOyIbOl699TjlYnCWB7KFn411bbKptDy0onYdCb0QQ8=; b=dJlPwco/i2WA3Zb9oe2FwL7kEKaLeyXG6PQ8y2tBcbFMiW9W3NE6LVo7w//kLVLEOCjvq9312dOyw6Qk+Th0feGK2J701zVyuYbSnaQ1ARzX0kYf1FBakldvUlW81dlxprjTzKwaODdRYiDKK7YqBpnKzbXZny1g8R5kaCB9FPMzXPFk3J+Cl1uzuytjJjj/nI5WQNXdvPbWuPExEvQUEQ03f7SQqs+E96uKe647GiRAYw+A+5MLeB7VeNzjiXsezPdv54GMwL7xB1IcRBjpwudyG/VWf+VLAzTYSIRh5be+RQ79RqavBtG1F+6Ipe5+mB+CzPRESv2UaEH1jZn+HQ== Authentication-Results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=nvidia.com; Received: from BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) by BL1PR12MB5141.namprd12.prod.outlook.com (2603:10b6:208:309::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.19; Fri, 25 Jun 2021 14:36:17 +0000 Received: from BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::3d51:a3b9:8611:684e]) by BL0PR12MB5506.namprd12.prod.outlook.com ([fe80::3d51:a3b9:8611:684e%8]) with mapi id 15.20.4264.023; Fri, 25 Jun 2021 14:36:17 +0000 Date: Fri, 25 Jun 2021 11:36:16 -0300 From: Jason Gunthorpe To: "Tian, Kevin" Cc: "Alex Williamson (alex.williamson@redhat.com)" , Joerg Roedel , Jean-Philippe Brucker , David Gibson , Jason Wang , "parav@mellanox.com" , "Enrico Weigelt, metux IT consult" , Paolo Bonzini , Shenming Lu , Eric Auger , Jonathan Corbet , "Raj, Ashok" , "Liu, Yi L" , "Wu, Hao" , "Jiang, Dave" , Jacob Pan , Kirti Wankhede , Robin Murphy , "kvm@vger.kernel.org" , "iommu@lists.linux-foundation.org" , David Woodhouse , LKML , Lu Baolu Subject: Re: Plan for /dev/ioasid RFC v2 Message-ID: <20210625143616.GT2371267@nvidia.com> References: <20210615101215.4ba67c86.alex.williamson@redhat.com> <20210616133937.59050e1a.alex.williamson@redhat.com> <20210617151452.08beadae.alex.williamson@redhat.com> <20210618001956.GA1987166@nvidia.com> <20210618182306.GI1002214@nvidia.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Originating-IP: [47.55.113.94] X-ClientProxiedBy: MN2PR22CA0016.namprd22.prod.outlook.com (2603:10b6:208:238::21) To BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mlx.ziepe.ca (47.55.113.94) by MN2PR22CA0016.namprd22.prod.outlook.com (2603:10b6:208:238::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.18 via Frontend Transport; Fri, 25 Jun 2021 14:36:17 +0000 Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1lwmwK-00CZsu-9n; Fri, 25 Jun 2021 11:36:16 -0300 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4623085b-1004-4281-c59d-08d937e6976d X-MS-TrafficTypeDiagnostic: BL1PR12MB5141: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hhhSOARGWS+BRMOZVWQkWJXwADzMUCnU1pY2MwIBlaXdVqSpYfbY9kYKSeOc6rdCGGZa1LyAXBRq5NKi0LSUYNE0E2TJwI6E/eLZh8ZeO3WBtqhUOPRMtAHSO8Om/pHAxkxbJ5cRF46/9abfaXPEkjdHYen58u/FFt5Bewpx5CX10TJgccBDGtppzzflp6GNa/yT7QHfeS4Pe11DjPPBkUwYD79L8AxczzoIFpdo0jAQwWzP3rWAxXUHaQLiw63zZWGDcgr+0cI9tb51EO/OslJ3DcTwspHlPaGT5NEDUxSLYVUBFjWAGcwAKrtlOL7sz0e8D6itAsPqXXRGxzoHVAJADGUi420DMmkzSRPLwI+UmeWbv4YXItK/Zylnxs9K5NUbsqPFOaPxaLvCUFKWRcOCNXlgQXrJJzFmeIfuEt1TjM5fNv32MkxljtGA6qAQzdK/YCsLW0jMMFNXXKYafPGmfptq8r97HCrpGLeMbAnrxUd+GUUS8Yjw4p+kR6B83gjklmV69thAg4ohMfFFJMCqD5gt4Gi+ZGPkD6bSyJT4kOCh9tjVtTd/4XDCQyKDyuvh7mKBEIygRbnoxeEF4teZqQpdAVXknIGpjIft7s15ihq6Nu9mqKSz9ytjlWjvBm0s8JtLpa2q0rcDKy8eRQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR12MB5506.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(136003)(346002)(366004)(39860400002)(396003)(9786002)(316002)(9746002)(6916009)(33656002)(54906003)(2906002)(7416002)(478600001)(86362001)(4326008)(83380400001)(38100700002)(426003)(26005)(5660300002)(66946007)(66476007)(66556008)(36756003)(8676002)(2616005)(1076003)(186003)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?3CesEwvRv1tcs+Bfo8FUAZR0pf3wbGPmkJk3cYeVU9yrD/+lQkGvo2IxBfDL?= =?us-ascii?Q?oCyPGvod/Q+dyiPGGG/nBrOBWnOlafRNI0BMBthhP8f0vzCX48hrUhTeTApm?= =?us-ascii?Q?jxZReIQ4fpw2M520Tjzq8z92TthtLeTv7P++O61+uPaPE2SoqgXtEWoRAzma?= =?us-ascii?Q?DO9LFLlC688FgCNThzmLEr571VQXQ6S+o1ISyaFrGlOpoXlh7lJQNQjIzjwn?= =?us-ascii?Q?sRPr4qPa5yNr9zlZok//apFlXrL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fqaJSIVTs+JJRRJVXIOw4TF4c4MQchO+VcH4Lvbito30SbeTL08K?= =?us-ascii?Q?Qwdz2bP6Vypow0MnX6BfmydyDTKEhXoOt7ntoffXqGWRjk0t+s/KVcjtyLmR?= =?us-ascii?Q?biuUagqKMKUHjRVqggq7b95zh4oYRULNrsU+s7VQwpWdJ+FstS9pcBiFau51?= =?us-ascii?Q?9ERw14mVZxmJo88L/H8CflGb?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4623085b-1004-4281-c59d-08d937e6976d X-MS-Exchange-CrossTenant-AuthSource: BL0PR12MB5506.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jun 2021 14:36:17.5261 (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: Cg58ErIFco73peroYGBhhu6nlbI4pKtoPcalY14o5jokXtFjCoZ2q2n6Zq+RBN1n X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5141 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 25, 2021 at 10:27:18AM +0000, Tian, Kevin wrote: > - When receiving the binding call for the 1st device in a group, iommu_fd > calls iommu_group_set_block_dma(group, dev->driver) which does > several things: The whole problem here is trying to match this new world where we want devices to be in charge of their own IOMMU configuration and the old world where groups are in charge. Inserting the group fd and then calling a device-centric VFIO_GROUP_GET_DEVICE_FD_NEW doesn't solve this conflict, and isn't necessary. We can always get the group back from the device at any point in the sequence do to a group wide operation. What I saw as the appeal of the sort of idea was to just completely leave all the difficult multi-device-group scenarios behind on the old group centric API and then we don't have to deal with them at all, or least not right away. I'd see some progression where iommu_fd only works with 1:1 groups at the start. Other scenarios continue with the old API. Then maybe groups where all devices use the same IOASID. Then 1:N groups if the source device is reliably identifiable, this requires iommu subystem work to attach domains to sub-group objects - not sure it is worthwhile. But at least we can talk about each step with well thought out patches The only thing that needs to be done to get the 1:1 step is to broadly define how the other two cases will work so we don't get into trouble and set some way to exclude the problematic cases from even getting to iommu_fd in the first place. For instance if we go ahead and create /dev/vfio/device nodes we could do this only if the group was 1:1, otherwise the group cdev has to be used, along with its API. > a) Check group viability. A group is viable only when all devices in > the group are in one of below states: > > * driver-less > * bound to a driver which is same as dev->driver (vfio in this case) > * bound to an otherwise allowed driver (same list as in vfio) This really shouldn't use hardwired driver checks. Attached drivers should generically indicate to the iommu layer that they are safe for iommu_fd usage by calling some function around probe() Thus a group must contain only iommu_fd safe drivers, or drivers-less devices before any of it can be used. It is the more general refactoring of what VFIO is doing. > c) The iommu layer also verifies group viability on BUS_NOTIFY_ > BOUND_DRIVER event. BUG_ON if viability is broken while block_dma > is set. And with this concept of iommu_fd safety being first-class maybe we can somehow eliminate this gross BUG_ON (and the 100's of lines of code that are used to create it) by denying probe to non-iommu-safe drivers, somehow. > - Binding other devices in the group to iommu_fd just succeeds since > the group is already in block_dma. I think the rest of this more or less describes the device centric logic for multi-device groups we've already talked about. I don't think it benifits from having the group fd Jason