From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2060.outbound.protection.outlook.com [40.107.220.60]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8AF6C808; Fri, 9 Sep 2022 12:07:36 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B00nukpiaouWrESuHMzlTQWIt8LAnlN00myVRFiQ8tqe1MdMWvmym4Hc01v0B0+SUeRas1dusZam+/k4dpeKsSDGYRm3HvL4Q80i55J1ljljJpCSjWBtLfY+NW75xIDUYxs+h7pkzudUCS0KbTHb6mBRfaOtoVvSDjQI1qFTuei1ez1Efl7sb10eVVkw60G5ZT+wdO7igEWaviMFYr19ssXS5Zlg0tz7Eww+t5Qb8bTEP56+u+IDaYwUu4OYAQaatudrOKmXM5JecNcfFafpsbPUuJCtPR+Oyy7GtDUeK+zEjsJB6GAUduWRkB0COu0qk4SKFqikyo/v2RGqI3cTmA== 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=TwZ+ncAsGDvDTUcaffwI8N5fKJsCdk1RcYxGsoIN4Io=; b=UBjnTngFuvO7+vy6Z3WB0x+Bt7j4hZ4CkB8pQRJPicp0T/uC7TvkTiT+CxOCINdXrpX6yRhM7v+HqnDoARs6SzvI0QzqUiZe61+s7lKObWx/L0MIaTD3Ipw9hDohiMQaVgwt9afupDG8FnMFjmLCbqQN6IcVZhQQ8t4tRAOzc2doA8/fy03mT7yx0w5SBOA58fi3WjB6VvGz3QgAOExOtx+S0a1R/Va6tq7tR8gzP7BR6hetKuzW6iGVJGvANnmzZXQPEIsLUocZwmt8DOLvMsnXWR8+hzMe4LgBqGrVrMTW4wcdDasjpGVQGNZ1jB7IaJkm/Rk4KDC5Om3GC4CXHg== 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=TwZ+ncAsGDvDTUcaffwI8N5fKJsCdk1RcYxGsoIN4Io=; b=lyTusMJeJJYkY9WkkZBf+T0IyGq299DhhzkYbR31NtOpkO2BLgqYQwQ20cqBF5m1SuVTa4qDTnXUBLcf1DNGmNuwykzvHrQOwUqCkqytJH2E0tgDRLz76ijZJqJVnsON6EwcyoBRf82xapB5iq05fe3vt3T1DHzmZKVHVn9PGli5BrJN5GOAzstzC755yMcf2sG67QdAbOkuc9YkmAYu7h31kYMUU9ewl6zfX9BVNv+TR6q81eudhDXLP7VNsVlFH1ixzvabCB0BVPgoe7/4nWOI1ay9wog9P3sHfrF7px8W0t1dpgYYBcN8OTt/Ybrbe5vkZENd078MmqoZzm8Iug== 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 SJ1PR12MB6243.namprd12.prod.outlook.com (2603:10b6:a03:456::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5588.10; Fri, 9 Sep 2022 12:07:34 +0000 Received: from MN2PR12MB4192.namprd12.prod.outlook.com ([fe80::462:7fe:f04f:d0d5]) by MN2PR12MB4192.namprd12.prod.outlook.com ([fe80::462:7fe:f04f:d0d5%7]) with mapi id 15.20.5612.019; Fri, 9 Sep 2022 12:07:34 +0000 Date: Fri, 9 Sep 2022 09:07:33 -0300 From: Jason Gunthorpe To: "Tian, Kevin" Cc: Nicolin Chen , Joerg Roedel , "will@kernel.org" , "robin.murphy@arm.com" , "alex.williamson@redhat.com" , "suravee.suthikulpanit@amd.com" , "marcan@marcan.st" , "sven@svenpeter.dev" , "alyssa@rosenzweig.io" , "robdclark@gmail.com" , "dwmw2@infradead.org" , "baolu.lu@linux.intel.com" , "mjrosato@linux.ibm.com" , "gerald.schaefer@linux.ibm.com" , "orsonzhai@gmail.com" , "baolin.wang@linux.alibaba.com" , "zhang.lyra@gmail.com" , "thierry.reding@gmail.com" , "vdumpa@nvidia.com" , "jonathanh@nvidia.com" , "jean-philippe@linaro.org" , "cohuck@redhat.com" , "tglx@linutronix.de" , "shameerali.kolothum.thodi@huawei.com" , "thunder.leizhen@huawei.com" , "christophe.jaillet@wanadoo.fr" , "yangyingliang@huawei.com" , "jon@solid-run.com" , "iommu@lists.linux.dev" , "linux-kernel@vger.kernel.org" , "asahi@lists.linux.dev" , "linux-arm-kernel@lists.infradead.org" , "linux-arm-msm@vger.kernel.org" , "linux-s390@vger.kernel.org" , "linux-tegra@vger.kernel.org" , "virtualization@lists.linux-foundation.org" , "kvm@vger.kernel.org" Subject: Re: [PATCH v6 1/5] iommu: Return -EMEDIUMTYPE for incompatible domain and device/group Message-ID: References: <20220815181437.28127-1-nicolinc@nvidia.com> <20220815181437.28127-2-nicolinc@nvidia.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: MN2PR06CA0005.namprd06.prod.outlook.com (2603:10b6:208:23d::10) To MN2PR12MB4192.namprd12.prod.outlook.com (2603:10b6:208:1d5::15) Precedence: bulk X-Mailing-List: asahi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR12MB4192:EE_|SJ1PR12MB6243:EE_ X-MS-Office365-Filtering-Correlation-Id: 7ce2790d-faf5-4d2b-4687-08da925be108 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hpGzPH5dsGB1NiFKb/pVoxkD188JQVUUexvePazbBaJAppZCylyIh9BPnTcdemv2Ea2zEfaFkAX6Wy0EH20kN3bvAsGd+PEm04atBgVQHiX7D0mBynvC59WUe8ZPqyPImaEnXEq31DjCjqEQBj/qJYw0CJmcfvNygnxpXXi2o676lmdIJdly6EBlkQ0p3he0RlNd9iadf4fkapTbgtuotj0nne5eTfyxrJ5qM6ke9rsojIUm0JEYrSAXax31wJeKvbqVCslOp/c9LjkLcXPX2i+ciUignKQEiAMkOq/CvRjRKKVBFTJdZbjN80u1E4l3F9/Mlj3P0xFW5GsXIWS1Oq32qY67LsAL/Kesqd1llYU4n44ktcgUMnckaVZiOcR6OhrtN772nLFhkQLeTFp1D+54FKo7t34vHYo1OllRShjjwcGhiZcSmP76xraZh++iZ+9laH9+AfdfDUePgDNAC2PAyOma/jMvc1wt7pdOk58w49Z746WtwDAY/Uo1k/wFoGhI8Nid+75pnDYAdffQcGGLzDTe3E2uPdTQB6TfYBlxzMDjU+RvvxR8xBbsUMrgLNWrRIbbC88QrJY/gh1GcZ8XcxgFoLxICm4+t37Hb5netBUPakFe/kBr+h6ptSyXYgQfA0nAlK/ZL4qukK+BhShQIyBNqsQrzx7GY5CwpnThS5NYWfWdKPGCGawvvc60bCoBVBF4p8zto6Qa0iFdqg== 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)(396003)(346002)(39860400002)(376002)(136003)(366004)(6916009)(54906003)(6506007)(316002)(41300700001)(478600001)(6486002)(38100700002)(26005)(86362001)(6512007)(186003)(36756003)(5660300002)(7416002)(8936002)(4326008)(2906002)(7406005)(66946007)(66476007)(66556008)(8676002)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?wswE3pIfxZbTKsUzF+6sst4J3x3rNGDr8FTpfVb9U/VmHOwNneoqbNxyru4t?= =?us-ascii?Q?3RLj4Vbom3kzX5HVGWHPcmV1zHaig/T4beLLfUqupXvO/0TIykYROZuOHBMg?= =?us-ascii?Q?GkGBmaG6HuwNGwhApYDf45zBQpUf00ukMHQHpX7XywZ/6gwkLW3/UYUolRp1?= =?us-ascii?Q?57bcqWFaAc3N6UpKc9orQ9PtyYuogOOM77aLjI/m1whWdJQr6/h9ANGpQ7gS?= =?us-ascii?Q?Ae8zO+7RK6uqZJwkTEHpiUzpvfD6VaXSVWlmBqx7w/dkJHIpDxQL9x6/Jek/?= =?us-ascii?Q?D3X3bikisoHhtVBoB9M44AvgZOi+EQO4KiE6QDlpldERqxrM4HXM+PWtoAxR?= =?us-ascii?Q?j+GIjfTOAokzjHUOKTIb9ue0m6YtQyoYwd+JcFX1+1jVCP8o+AzhacoOWt0c?= =?us-ascii?Q?xZ69iqoQWO7LaiIVwxJKrP5tBFNAd4xVsdw0Ym6UZWX3GliSKAgbV9S92LIT?= =?us-ascii?Q?ZKi3NJezfN6X898WCTyLv6+nz8MJWnStkz8m9hi5uM0QDzkx0YArCH61T5PV?= =?us-ascii?Q?nlLqMKeQ3s5ab8T+GIKMwHbtike8NNsb34zfeJU1vkJ8LnhxmCM7YU7Camsz?= =?us-ascii?Q?QUACud74qtLAkewM2nWXySkgsJR9utPOR6nLxHYn3HVznnr7pxPJQKrUu/CB?= =?us-ascii?Q?jLpdk0AmDx0se/0TSXvDyxsmllEAFEqpyr+3rAhgbUQgU/unnmq5do00tbL8?= =?us-ascii?Q?9sqLuOVCdnU+snB60z0alY8alKmYTrYU4nv2r+KVHOP7agF0VQMm/7FpmE8A?= =?us-ascii?Q?WAz69r6YHU36LTKZ4YfkyguvFmw+XsDHcJ6YWELfDuD/kfrpPN2GrhqOlIre?= =?us-ascii?Q?xLYhrpTTO1JS9BNriz1PIkuP1uG7dblzgHAd4EuHMwZzJb7QeRNhVPwHev4L?= =?us-ascii?Q?TeTvPnx9b0V1hVt6Zlz1zC8Bb1q5wn2oZLpqdHb1wLa1eblzGA3jrIOaYmZ9?= =?us-ascii?Q?tZD9fhJu1IEi4HuOCp+fS+R1fPdwZnsGOu/+XRdAJfMOVlBRC6zixeHf1QFg?= =?us-ascii?Q?IXJFolor94PRbws/Yy7bUDfcCbMHO3OEw+WdNcHseCh7xSYkaF/h5FB9+Kv6?= =?us-ascii?Q?uZJNQAusRqT+vaa0bdiCiB5LsfE2ILTeT9cZ0+GF5twGs91D8vdUiFcZ6DNx?= =?us-ascii?Q?ZhCbpu11Dzps9oUeSaL19LwtJtiHhUDn0lLHN6fq3A9z0OUfAoYxCYVYNMDZ?= =?us-ascii?Q?GrKnmQm/yIYKwmgEME5M56jMLK8gBS1sbdl7j1CBULUwJTBu3yztMdBt9/qB?= =?us-ascii?Q?wr7PU8wIC8Z//+Do0BnWNm2CmuManhc3aTFzEw8P95XigYws1aqOfhEv9FRs?= =?us-ascii?Q?m3WFcbca5DKwPz7cLTEiG4NyOUnEleIeZdrn65Sqr8b6Yo0tDa02p99m9yMF?= =?us-ascii?Q?SZCpX83HleE+jfrnfmIpppLuWX6NhrY/CMoP1XTjFv9ALq2Tc68v5RsmPcZh?= =?us-ascii?Q?LOfIVPn1N/ev1/rkRFDiLxdUFG+9thr7rzESK26K/KXWuo31iwRKgy7LrYsO?= =?us-ascii?Q?8QPyeqDpTlvqbqqIG9oLgU6rAUfXmDiB9CFQjAnAK8eftMNzNuib72e+Qnu+?= =?us-ascii?Q?HVyqWO0yzAmnkLnVA49Q6cyz3PFFlMl4c45qR1Ms?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7ce2790d-faf5-4d2b-4687-08da925be108 X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB4192.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2022 12:07:34.3953 (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: ejCYihcDn46SxiPdi4juY2L32J5j6+PYHbbkbIWsrp7LTbDa8hyspCKJZk2OgCl2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6243 On Fri, Sep 09, 2022 at 05:00:16AM +0000, Tian, Kevin wrote: > > I have started this effort by combining this list and the one from > > the side thread: > > > > @@ -266,6 +266,13 @@ struct iommu_ops { > > /** > > * struct iommu_domain_ops - domain specific operations > > * @attach_dev: attach an iommu domain to a device > > + * Rules of its return errno: > > + * ENOMEM - Out of memory > > + * EINVAL - Device and domain are incompatible > > + * EBUSY - Device is attached to a domain and cannot be changed > > With this definition then probably @attach_dev should not return -EBUSY > at all given it's already checked in the start of __iommu_attach_group(): I think the EBUSY would be only for non-conforming drivers. The API semantic is you can always attach a new domain and replace an existing domain. So things like AMD's "can't do anything but idenitity on RID when PASID enabled" would be -EBUSY. Seems right that it should be rare though. > > + * ENODEV - Device or domain is messed up: device is not mapped > > + * to an IOMMU, no domain can attach, and etc. > > if domain is messed up then should return -EINVAL given using another domain > might just work. IMHO here -ENODEV should only cover device specific problems > preventing this device from being attached to by any domain. Agree > > + * - Same behavior as ENODEV, use is discouraged > > didn't get the "Same behavior" part. Does it suggest all other errnos should > be converted to ENODEV? It says all other errnos should be treated as ENODEV by the caller but forwarded to userspace for further detail. > btw what about -ENOSPC? It's sane to allocate some resource in the attach > path while the resource might be not available, e.g.: Seems resaonable that it is similar to ENOMEM > As discussed in a side thread a note might be added to exempt calling > kAPI outside of the iommu driver. Sadly, not really.. The driver is responsible to santize this if it is relevant. It is the main downside of this approach. Jason From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 686B0ECAAA1 for ; Fri, 9 Sep 2022 12:09:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7oo2mjW+fGHts1mGD1ZznfCt7pt7Ix8Q6hXb0KKef8A=; b=NuGpcLCpVji8VK Vpzc1UmitD27r8bNHymA2324hy9NrHRey1liJuBZgRlMRl/u36kPRJ6gey0patctFrwBegS6up+NF zNgkvPGWtEVLKDcIRtd8cmxdx02sNZWg0H0ZRtaKd9BQOZhGb9GtQUAXukbvKdzJQjGibuqx8mTdt csmyYXAW9tWYDg4GJMiMd77RQfKZwTkiCEEYEbGE+Zx6TflZgNBgWHWsQeKj0y8T+c+EgKnxBsBml 2vpjyHzP775iAPsqbJha86YzPZ3bt2Ir/FrH55/hngfW1su9rvT2lUs23JgfUoRAbENY+ZysDYsL4 3ga62gKHrlPGhIQUAa3A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWcnd-00FtMm-Pg; Fri, 09 Sep 2022 12:07:58 +0000 Received: from mail-co1nam11on2040.outbound.protection.outlook.com ([40.107.220.40] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWcna-00FtH9-Lm for linux-arm-kernel@lists.infradead.org; Fri, 09 Sep 2022 12:07:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B00nukpiaouWrESuHMzlTQWIt8LAnlN00myVRFiQ8tqe1MdMWvmym4Hc01v0B0+SUeRas1dusZam+/k4dpeKsSDGYRm3HvL4Q80i55J1ljljJpCSjWBtLfY+NW75xIDUYxs+h7pkzudUCS0KbTHb6mBRfaOtoVvSDjQI1qFTuei1ez1Efl7sb10eVVkw60G5ZT+wdO7igEWaviMFYr19ssXS5Zlg0tz7Eww+t5Qb8bTEP56+u+IDaYwUu4OYAQaatudrOKmXM5JecNcfFafpsbPUuJCtPR+Oyy7GtDUeK+zEjsJB6GAUduWRkB0COu0qk4SKFqikyo/v2RGqI3cTmA== 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=TwZ+ncAsGDvDTUcaffwI8N5fKJsCdk1RcYxGsoIN4Io=; b=UBjnTngFuvO7+vy6Z3WB0x+Bt7j4hZ4CkB8pQRJPicp0T/uC7TvkTiT+CxOCINdXrpX6yRhM7v+HqnDoARs6SzvI0QzqUiZe61+s7lKObWx/L0MIaTD3Ipw9hDohiMQaVgwt9afupDG8FnMFjmLCbqQN6IcVZhQQ8t4tRAOzc2doA8/fy03mT7yx0w5SBOA58fi3WjB6VvGz3QgAOExOtx+S0a1R/Va6tq7tR8gzP7BR6hetKuzW6iGVJGvANnmzZXQPEIsLUocZwmt8DOLvMsnXWR8+hzMe4LgBqGrVrMTW4wcdDasjpGVQGNZ1jB7IaJkm/Rk4KDC5Om3GC4CXHg== 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=TwZ+ncAsGDvDTUcaffwI8N5fKJsCdk1RcYxGsoIN4Io=; b=lyTusMJeJJYkY9WkkZBf+T0IyGq299DhhzkYbR31NtOpkO2BLgqYQwQ20cqBF5m1SuVTa4qDTnXUBLcf1DNGmNuwykzvHrQOwUqCkqytJH2E0tgDRLz76ijZJqJVnsON6EwcyoBRf82xapB5iq05fe3vt3T1DHzmZKVHVn9PGli5BrJN5GOAzstzC755yMcf2sG67QdAbOkuc9YkmAYu7h31kYMUU9ewl6zfX9BVNv+TR6q81eudhDXLP7VNsVlFH1ixzvabCB0BVPgoe7/4nWOI1ay9wog9P3sHfrF7px8W0t1dpgYYBcN8OTt/Ybrbe5vkZENd078MmqoZzm8Iug== 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 SJ1PR12MB6243.namprd12.prod.outlook.com (2603:10b6:a03:456::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5588.10; Fri, 9 Sep 2022 12:07:34 +0000 Received: from MN2PR12MB4192.namprd12.prod.outlook.com ([fe80::462:7fe:f04f:d0d5]) by MN2PR12MB4192.namprd12.prod.outlook.com ([fe80::462:7fe:f04f:d0d5%7]) with mapi id 15.20.5612.019; Fri, 9 Sep 2022 12:07:34 +0000 Date: Fri, 9 Sep 2022 09:07:33 -0300 From: Jason Gunthorpe To: "Tian, Kevin" Subject: Re: [PATCH v6 1/5] iommu: Return -EMEDIUMTYPE for incompatible domain and device/group Message-ID: References: <20220815181437.28127-1-nicolinc@nvidia.com> <20220815181437.28127-2-nicolinc@nvidia.com> Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: MN2PR06CA0005.namprd06.prod.outlook.com (2603:10b6:208:23d::10) To MN2PR12MB4192.namprd12.prod.outlook.com (2603:10b6:208:1d5::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR12MB4192:EE_|SJ1PR12MB6243:EE_ X-MS-Office365-Filtering-Correlation-Id: 7ce2790d-faf5-4d2b-4687-08da925be108 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hpGzPH5dsGB1NiFKb/pVoxkD188JQVUUexvePazbBaJAppZCylyIh9BPnTcdemv2Ea2zEfaFkAX6Wy0EH20kN3bvAsGd+PEm04atBgVQHiX7D0mBynvC59WUe8ZPqyPImaEnXEq31DjCjqEQBj/qJYw0CJmcfvNygnxpXXi2o676lmdIJdly6EBlkQ0p3he0RlNd9iadf4fkapTbgtuotj0nne5eTfyxrJ5qM6ke9rsojIUm0JEYrSAXax31wJeKvbqVCslOp/c9LjkLcXPX2i+ciUignKQEiAMkOq/CvRjRKKVBFTJdZbjN80u1E4l3F9/Mlj3P0xFW5GsXIWS1Oq32qY67LsAL/Kesqd1llYU4n44ktcgUMnckaVZiOcR6OhrtN772nLFhkQLeTFp1D+54FKo7t34vHYo1OllRShjjwcGhiZcSmP76xraZh++iZ+9laH9+AfdfDUePgDNAC2PAyOma/jMvc1wt7pdOk58w49Z746WtwDAY/Uo1k/wFoGhI8Nid+75pnDYAdffQcGGLzDTe3E2uPdTQB6TfYBlxzMDjU+RvvxR8xBbsUMrgLNWrRIbbC88QrJY/gh1GcZ8XcxgFoLxICm4+t37Hb5netBUPakFe/kBr+h6ptSyXYgQfA0nAlK/ZL4qukK+BhShQIyBNqsQrzx7GY5CwpnThS5NYWfWdKPGCGawvvc60bCoBVBF4p8zto6Qa0iFdqg== 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)(396003)(346002)(39860400002)(376002)(136003)(366004)(6916009)(54906003)(6506007)(316002)(41300700001)(478600001)(6486002)(38100700002)(26005)(86362001)(6512007)(186003)(36756003)(5660300002)(7416002)(8936002)(4326008)(2906002)(7406005)(66946007)(66476007)(66556008)(8676002)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?wswE3pIfxZbTKsUzF+6sst4J3x3rNGDr8FTpfVb9U/VmHOwNneoqbNxyru4t?= =?us-ascii?Q?3RLj4Vbom3kzX5HVGWHPcmV1zHaig/T4beLLfUqupXvO/0TIykYROZuOHBMg?= =?us-ascii?Q?GkGBmaG6HuwNGwhApYDf45zBQpUf00ukMHQHpX7XywZ/6gwkLW3/UYUolRp1?= =?us-ascii?Q?57bcqWFaAc3N6UpKc9orQ9PtyYuogOOM77aLjI/m1whWdJQr6/h9ANGpQ7gS?= =?us-ascii?Q?Ae8zO+7RK6uqZJwkTEHpiUzpvfD6VaXSVWlmBqx7w/dkJHIpDxQL9x6/Jek/?= =?us-ascii?Q?D3X3bikisoHhtVBoB9M44AvgZOi+EQO4KiE6QDlpldERqxrM4HXM+PWtoAxR?= =?us-ascii?Q?j+GIjfTOAokzjHUOKTIb9ue0m6YtQyoYwd+JcFX1+1jVCP8o+AzhacoOWt0c?= =?us-ascii?Q?xZ69iqoQWO7LaiIVwxJKrP5tBFNAd4xVsdw0Ym6UZWX3GliSKAgbV9S92LIT?= =?us-ascii?Q?ZKi3NJezfN6X898WCTyLv6+nz8MJWnStkz8m9hi5uM0QDzkx0YArCH61T5PV?= =?us-ascii?Q?nlLqMKeQ3s5ab8T+GIKMwHbtike8NNsb34zfeJU1vkJ8LnhxmCM7YU7Camsz?= =?us-ascii?Q?QUACud74qtLAkewM2nWXySkgsJR9utPOR6nLxHYn3HVznnr7pxPJQKrUu/CB?= =?us-ascii?Q?jLpdk0AmDx0se/0TSXvDyxsmllEAFEqpyr+3rAhgbUQgU/unnmq5do00tbL8?= =?us-ascii?Q?9sqLuOVCdnU+snB60z0alY8alKmYTrYU4nv2r+KVHOP7agF0VQMm/7FpmE8A?= =?us-ascii?Q?WAz69r6YHU36LTKZ4YfkyguvFmw+XsDHcJ6YWELfDuD/kfrpPN2GrhqOlIre?= =?us-ascii?Q?xLYhrpTTO1JS9BNriz1PIkuP1uG7dblzgHAd4EuHMwZzJb7QeRNhVPwHev4L?= =?us-ascii?Q?TeTvPnx9b0V1hVt6Zlz1zC8Bb1q5wn2oZLpqdHb1wLa1eblzGA3jrIOaYmZ9?= =?us-ascii?Q?tZD9fhJu1IEi4HuOCp+fS+R1fPdwZnsGOu/+XRdAJfMOVlBRC6zixeHf1QFg?= =?us-ascii?Q?IXJFolor94PRbws/Yy7bUDfcCbMHO3OEw+WdNcHseCh7xSYkaF/h5FB9+Kv6?= =?us-ascii?Q?uZJNQAusRqT+vaa0bdiCiB5LsfE2ILTeT9cZ0+GF5twGs91D8vdUiFcZ6DNx?= =?us-ascii?Q?ZhCbpu11Dzps9oUeSaL19LwtJtiHhUDn0lLHN6fq3A9z0OUfAoYxCYVYNMDZ?= =?us-ascii?Q?GrKnmQm/yIYKwmgEME5M56jMLK8gBS1sbdl7j1CBULUwJTBu3yztMdBt9/qB?= =?us-ascii?Q?wr7PU8wIC8Z//+Do0BnWNm2CmuManhc3aTFzEw8P95XigYws1aqOfhEv9FRs?= =?us-ascii?Q?m3WFcbca5DKwPz7cLTEiG4NyOUnEleIeZdrn65Sqr8b6Yo0tDa02p99m9yMF?= =?us-ascii?Q?SZCpX83HleE+jfrnfmIpppLuWX6NhrY/CMoP1XTjFv9ALq2Tc68v5RsmPcZh?= =?us-ascii?Q?LOfIVPn1N/ev1/rkRFDiLxdUFG+9thr7rzESK26K/KXWuo31iwRKgy7LrYsO?= =?us-ascii?Q?8QPyeqDpTlvqbqqIG9oLgU6rAUfXmDiB9CFQjAnAK8eftMNzNuib72e+Qnu+?= =?us-ascii?Q?HVyqWO0yzAmnkLnVA49Q6cyz3PFFlMl4c45qR1Ms?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7ce2790d-faf5-4d2b-4687-08da925be108 X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB4192.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Sep 2022 12:07:34.3953 (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: ejCYihcDn46SxiPdi4juY2L32J5j6+PYHbbkbIWsrp7LTbDa8hyspCKJZk2OgCl2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6243 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220909_050754_740081_34796A2C X-CRM114-Status: GOOD ( 23.17 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "linux-s390@vger.kernel.org" , "marcan@marcan.st" , "mjrosato@linux.ibm.com" , "linux-kernel@vger.kernel.org" , "thierry.reding@gmail.com" , "will@kernel.org" , "alyssa@rosenzweig.io" , "jean-philippe@linaro.org" , "kvm@vger.kernel.org" , "zhang.lyra@gmail.com" , Joerg Roedel , "jon@solid-run.com" , "jonathanh@nvidia.com" , "iommu@lists.linux.dev" , Nicolin Chen , "yangyingliang@huawei.com" , "orsonzhai@gmail.com" , "gerald.schaefer@linux.ibm.com" , "sven@svenpeter.dev" , "linux-arm-msm@vger.kernel.org" , "christophe.jaillet@wanadoo.fr" , "baolin.wang@linux.alibaba.com" , "thunder.leizhen@huawei.com" , "linux-tegra@vger.kernel.org" , "tglx@linutronix.de" , "virtualization@lists.linux-foundation.org" , "linux-arm-kernel@lists.infradead.org" , "dwmw2@infradead.org" , "cohuck@redhat.com" , "alex.williamson@redhat.com" , "shameerali.kolothum.thodi@huawei.com" , "robdclark@gmail.com" , "asahi@lists.linux.dev" , "suravee.suthikulpanit@amd.com" , "robin.murphy@arm.com" , "baolu.lu@linux.intel.com" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Sep 09, 2022 at 05:00:16AM +0000, Tian, Kevin wrote: > > I have started this effort by combining this list and the one from > > the side thread: > > > > @@ -266,6 +266,13 @@ struct iommu_ops { > > /** > > * struct iommu_domain_ops - domain specific operations > > * @attach_dev: attach an iommu domain to a device > > + * Rules of its return errno: > > + * ENOMEM - Out of memory > > + * EINVAL - Device and domain are incompatible > > + * EBUSY - Device is attached to a domain and cannot be changed > > With this definition then probably @attach_dev should not return -EBUSY > at all given it's already checked in the start of __iommu_attach_group(): I think the EBUSY would be only for non-conforming drivers. The API semantic is you can always attach a new domain and replace an existing domain. So things like AMD's "can't do anything but idenitity on RID when PASID enabled" would be -EBUSY. Seems right that it should be rare though. > > + * ENODEV - Device or domain is messed up: device is not mapped > > + * to an IOMMU, no domain can attach, and etc. > > if domain is messed up then should return -EINVAL given using another domain > might just work. IMHO here -ENODEV should only cover device specific problems > preventing this device from being attached to by any domain. Agree > > + * - Same behavior as ENODEV, use is discouraged > > didn't get the "Same behavior" part. Does it suggest all other errnos should > be converted to ENODEV? It says all other errnos should be treated as ENODEV by the caller but forwarded to userspace for further detail. > btw what about -ENOSPC? It's sane to allocate some resource in the attach > path while the resource might be not available, e.g.: Seems resaonable that it is similar to ENOMEM > As discussed in a side thread a note might be added to exempt calling > kAPI outside of the iommu driver. Sadly, not really.. The driver is responsible to santize this if it is relevant. It is the main downside of this approach. Jason _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel