Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp6557486rwd; Mon, 19 Jun 2023 08:53:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6OJTXgwZTEiC+8fOP8dpTCNU8zt0PmyTBxAeP3CJti8SI1p3oxh3aSCc5VVVnp+IJxQwS1 X-Received: by 2002:a17:902:778c:b0:1b3:b998:8007 with SMTP id o12-20020a170902778c00b001b3b9988007mr1009963pll.55.1687190027805; Mon, 19 Jun 2023 08:53:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1687190027; cv=pass; d=google.com; s=arc-20160816; b=KYbw8nr/9F0jKlJJM1agFRop9AOgnCfguf6uBdPwrqEC2RAFLJu6wLrdutTJTI91Wd SYhZnxQi7Z/H5gVh/l9/VMaQZu2VcizNs1JcK8148VjtK+F2nCKH+AYGuFFQrQus0tal JmecnHjNd1WOvYltUiqJK//PhHL0sOk2io/8IR038Qy8Ym9l1LB/+tV5yGDyQYmp3lFz 27wBal/7f5PbTNenAMsd42sFomxv3gObjRn935ZnAjp35YovZZ+EjG43dURnATOV62+m eF4IDITWZgEIbnvsBZ2TsBamr/klvDEKQ3NyUiLVdwJUWbD1lolCOAJIAftmSf58MkHa HFKA== 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=ElkEMehmHQ16BFioE94BrMNQRr9GhjTdPz5MkzRc7lU=; b=exM0H1kduH5aTJKFB0VrnlgDB8R2iVBhnbpVmYMNAQpTMQhBCjD790cZqWk0Z3GgMY 9kWGcusuZhJQimruwWY90EqWfzSS7bpVSucwRXaTpviaD98RXcrQ0PTwCNB/v+PAVHKZ sO7G8xfbB/TD0OfqLwJAPolSLXGGzicC51tz4A6Cz9LSBXMREQyc5ajqEw5qeftUW21Z 7WYGlj3YFx0RfO3AGNkI4hWHnT7PpDsjvu8TsIooHkUmjBlRLfGdsTBhs9PJEtUbLgP8 3otdqDOC8Q5Y2pCPwouqKoqJZNrriiZW6KbE0XDrzns96toqSNGON92ACmMTyxNY579O Xnxw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=q3OhNRlb; 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 a17-20020a170902ecd100b001b025685062si13025plh.574.2023.06.19.08.53.31; Mon, 19 Jun 2023 08:53:47 -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=q3OhNRlb; 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 S230444AbjFSPab (ORCPT + 99 others); Mon, 19 Jun 2023 11:30:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229519AbjFSPa3 (ORCPT ); Mon, 19 Jun 2023 11:30:29 -0400 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2051.outbound.protection.outlook.com [40.107.96.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD3C8B8; Mon, 19 Jun 2023 08:30:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PvwkYyiOuzqB+c1W/oG3BI3nVqtmwPE9CMh3aLH1FTfIBxAbrtMKdWQpdBMMMk/6NW3AW4yJJhmVrfTLzQN7t2lg26Psdw/93phSGFU5qKKQYH/S3M5pSbW3182uzBsW/sE1Q87sbjUYMroBh92SkCFmj3QJqZI2FxgS5WV2u8jmZK8c+vzfuf3OYg4FfRV4ZTdxTf79+vCcK1e0P+kk9Y/SUQdYlCruSzGmozl1s/GtiWa8MIjuVNhdfDMGKuu5ldEMUfpxYLu6Yj6r5PSossKh8H4f+YsLhLyLsKEJjc/sZ4vXfU8j34uwLu2vIyJBeMoZqCvHdaA/lf1k9qPPlg== 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=ElkEMehmHQ16BFioE94BrMNQRr9GhjTdPz5MkzRc7lU=; b=IgkL12+PSK/lqaT6Zl+zsoGhZSLI4x9NIn7NvVQtGpQHkaeBPgaPGoP3JeFZZ4lY4jgEgyFfqMb4r+FjXWRtkhAYxwNU9/yrFFwCPqEuQxBAoX46wJou83I4KA3G4YRmmeIcKTU0mMhw+J6hkh+NcbXIXvX3p7WZRt9zoBmi8ANn7XUwgxnENbRR5fXPBcMkQw56e4Ap/MVjTFJmnUls6cmjDn6Zp44gAP8zmvOEFhmUl/rvDyF8mgquC27Ko7vv6FkfLZviytUbSXZB9s1IGW9gm9FHW7BiyMbdgX2iky2PIqFK5dN6Xj+4YKrOTLg0G1vel6Zfdv5BzZcyqSAGZw== 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=ElkEMehmHQ16BFioE94BrMNQRr9GhjTdPz5MkzRc7lU=; b=q3OhNRlbcjAEzRhQFHQucpie2+ml6oHoDOWXCDO3N7y0g7OpRbjsCYRCLcBOu6beov+joz63U+XRGs34OSFBc9EVt3I6UdyfbzqoQQnJdvcy+txbro4G2tNycmfZKCQ2YSOMMNcumdMjoup0LjBoF3xk8WysDr7OI7nSfMU3LSh02wRoGxzdDbTmzG0k40d4HbuVogUZOMRrEEEcDmAMnYIEOP2b8zJpZNyuduiUYbidT9FCp6WdkGeeMnaytKW6krjEHvW5+IdwXIVsAm7xz+y/LwosYk1NxMSlMSu8QE9LVkNJSOXURvW9Os0sEPjGvCaWNOlc//CwmxCaJm3HKw== 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 PH0PR12MB7792.namprd12.prod.outlook.com (2603:10b6:510:281::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6500.36; Mon, 19 Jun 2023 15:30:25 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::f7a7:a561:87e9:5fab%7]) with mapi id 15.20.6500.031; Mon, 19 Jun 2023 15:30:25 +0000 Date: Mon, 19 Jun 2023 12:30:23 -0300 From: Jason Gunthorpe To: Robin Murphy Cc: Lu Baolu , Kevin Tian , Joerg Roedel , Will Deacon , Alex Williamson , Nicolin Chen , iommu@lists.linux.dev, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] iommu: Prevent RESV_DIRECT devices from blocking domains Message-ID: References: <20230607035145.343698-1-baolu.lu@linux.intel.com> <20230607035145.343698-2-baolu.lu@linux.intel.com> <5d0d6665-93e4-f61f-d700-008c0fcb4a2f@arm.com> <0c1aec7a-8724-0f49-bccb-6025f5863bb7@arm.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0c1aec7a-8724-0f49-bccb-6025f5863bb7@arm.com> X-ClientProxiedBy: CH0PR07CA0028.namprd07.prod.outlook.com (2603:10b6:610:32::33) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|PH0PR12MB7792:EE_ X-MS-Office365-Filtering-Correlation-Id: 022926f2-32c3-47d8-77fd-08db70da1a7e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: usYU88jerYII0JZLWR6Qk8Q7x2kTJugFkLnfZ21pg2juc23+Zl/0RcbqN464MlxLqpBITjS2AvTsRBLCzczqtBDODCSzX+oNpF9ETBkf1ZXiPC0jLNMk5jajye9GSn9mSvxR6/LJQfDaopJCFiASmdXOwkl8jyeb2dkasVs7DtjTWhIW1DEf27MFCWzIrfkb04P7eczCoY17FVEB/u07+mSA412F5W2yno2SgY4gekYzEsShdvw0/Z4YWLS6a13vve6K3MAXBJSgP5K19oBgZO/OMTmQeb9oam2+WfTHMhSu2bYs6D7ZItukAIuZlXqzT95QmfkSC5DeT9y0fBqiqq8HghxuhHhL0wcgz72V0znuY9oaSa1ZO5GtDymxr0kT7b9S+Aptt0yB2IU8p0540vBHFiCvyvESdTPK5yz3ciqxYoEDul14V9GVPoQbghZTegowR11cV4++2B1dedgdCkVB1j30QBFxMxZSPKF0yOu7pCcqz5+MQyZg4PncCMcWHR7Nis15A1EWlI9vJ/ma9UN/TYgECEXrcf0fiAoSFYk9aY6qNtLYr77l5YC3uAgd 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)(366004)(136003)(396003)(39860400002)(376002)(346002)(451199021)(186003)(8936002)(8676002)(66946007)(66556008)(66476007)(66899021)(5660300002)(54906003)(4326008)(6486002)(316002)(38100700002)(478600001)(36756003)(41300700001)(26005)(53546011)(6512007)(6506007)(6916009)(86362001)(2906002)(83380400001)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?Cl5FLVGFI9mehQE0xvWxXHQ6JHr53OeE2vffWv0DRlrLnH+TkQ2H3MGfON9E?= =?us-ascii?Q?T8x9UGhxg7O662jA8CeD4xjZVF4qwJ+K1apO7KJh3sBeDTQfZopWSWUy7/wm?= =?us-ascii?Q?KYOcHlF3iT/+Z9qEWFtaA0FuH2BCGURYH6KO3imnCqYbEQaNI+Rae8ZQ4dDI?= =?us-ascii?Q?K+XMGOAEzF0+xbpR+y2I5WNXNwLPB8FHcCJ9OD9uuAfwUtA5q3KxfRxIDPvJ?= =?us-ascii?Q?huxlHiR8ay/Fz3TRqFq6ZmiVt4P4wcxfpDlUcTIIjBf0Tg0k1vRvj9Koh5f6?= =?us-ascii?Q?Th3cPAIRY+NHyYDK7qvigCem+nFAdzwvdgkhJETUd3kv3zyiSTFAhN/hVnk2?= =?us-ascii?Q?RCQdmj9KUvV0T2fwbO+r3PNUJfg3lA+pnhmaMCoM4zMcvrt4jWet5KLjx3hV?= =?us-ascii?Q?XQHCRF4Ppp5Ai8P75YwdimNO18OEA7bB5ZkvaimPlbKNaClZ0NIhhv0DldLF?= =?us-ascii?Q?0Vlwo91ArWL+R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ascii?Q?xNFnVu1PXXxZ3j6vzNhFuQaZbCR3dqBxyue4g2ruFwVTJiA47NUXYNl/rBLk?= =?us-ascii?Q?Nv6xgOxgnAe1lr3sH/3LAb3k1AXZ5fxMYEp00BTAb05+4KXTNNG2Uk8LWMpw?= =?us-ascii?Q?ZRX49aDSdXGLhFmrJhXlD8yj6jqHOszuFGDUMDrEgC4qZgXuAZ5t7Apcwb6M?= =?us-ascii?Q?sk9mlOyQX05PdEbEJrL1IQjRgqAXn6iYpuKzIQs3?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 022926f2-32c3-47d8-77fd-08db70da1a7e X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jun 2023 15:30:25.3929 (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: ZRex/TUHQp06pBAtM9X4XJLY4oSBmHX9fPHQ501znX8GZeIXr0Ri2jB+Bm8Zz6K0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7792 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 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, Jun 19, 2023 at 03:20:30PM +0100, Robin Murphy wrote: > On 19/06/2023 2:41 pm, Jason Gunthorpe wrote: > > On Mon, Jun 19, 2023 at 02:33:18PM +0100, Robin Murphy wrote: > > > > @@ -2121,6 +2125,21 @@ static int __iommu_device_set_domain(struct iommu_group *group, > > > > { > > > > int ret; > > > > + /* > > > > + * If the driver has requested IOMMU_RESV_DIRECT then we cannot allow > > > > + * the blocking domain to be attached as it does not contain the > > > > + * required 1:1 mapping. This test effectively exclusive the device from > > > > + * being used with iommu_group_claim_dma_owner() which will block vfio > > > > + * and iommufd as well. > > > > + */ > > > > + if (dev->iommu->requires_direct && > > > > + (new_domain->type == IOMMU_DOMAIN_BLOCKED || > > > > > > Given the notion elsewhere that we want to use the blocking domain as a last > > > resort to handle an attach failure, > > > > We shouldn't do that for cases where requires_direct is true, the last > > resort will have to be the static identity domain. > > > > > at face value it looks suspect that failing to attach to a blocking > > > domain could also be a thing. I guess technically this is failing at > > > a slightly different level so maybe it does work out OK, but it's > > > still smelly. > > > > It basically says that this driver doesn't support blocking domains on > > this device. What we don't want is for the driver to fail blocking or > > identity attaches. > > Is that really the relevant semantic though? It is the semantic I have had in mind. The end goal: 1) Driver never fails identity or blocking attachments 2) Identity and blocking domains are global static so always available 3) Core code puts restrictions on when identity and blocking domains can be used (eg trusted, reserved regions) 4) Catastrophic error recovery ends up moving to either blocking (preferred) or identity. > I thought the point was to prevent userspace (or anyone else for > that matter) taking ownership of a device with reserved regions > which we can't trust them to honour. Yes, this is the practical side effect of enforcing the rules. The other side effect is that it removes another special case where a driver has special behavior tied to IOMMU_DOMAIN_DMA. > assignment", not anything about attaching to blocking domains. Plus the > existing intel-iommu behaviour being generalised is specific to > IOMMU_DOMAIN_UNMANAGED. Being specific to UNMANAGED is a driver mistake, IMHO. It is a hack to make it only work with VFIO and avoid dma-iommu. > On reflection, I don't think that aspect actually matters anyway - nobody > can explicitly request attachment to a blocking domain They are used as part of the ownership mechanism, blocking domains are effectively explicitly requested by detaching domains from owned groups. Yes, take_ownership is very carefully a sufficient place to put the check with today's design, but it feels wrong because the blocking domain compatability has conceptually nothing to do with ownership. If we use blocking domains in the future then the check will be in the wrong place. > so if the only time they're used is when the IOMMU driver has > already had a catastrophic internal failure such that we decide to > declare the device toasted and deliberately put it into an unusable > state, blocking its reserved regions doesn't seem like a big deal. I think we should discuss then when we get to actually implementing the error recovery flow we want. I do like blocking in general for the reasons you give, and that was my first plan.. But if the BIOS will crash or something if we don't do the reserved region maps that isn't so good either. IDK would like to hear from the people using this BIOS feature. Thanks, Jason