Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2442262rdg; Mon, 16 Oct 2023 04:58:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXpZSTYlckAUxgbfKqWgnlaMNa7tTYl8b7NvXJtRLcdFqhW2th8PFv8MhI6praxkqpuWmQ X-Received: by 2002:a05:6a00:189a:b0:68e:3616:604a with SMTP id x26-20020a056a00189a00b0068e3616604amr11957360pfh.8.1697457482535; Mon, 16 Oct 2023 04:58:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697457482; cv=pass; d=google.com; s=arc-20160816; b=1LXBveGF+IgY9ZFrBp1jzrv1Qj/NsYOcI51DQEt9yhv8fKzjPLdjf/2wfd/bL23bgJ WRn5l0qMFVioSKEejy/ojc5VtrMVXx6fmSvcmiVG9rjp7EWbvj2Vv3BohVGzxJ1dCkHv crVXEI84KWAUq6Oq/w1ZGlJXK5qJZRx6oQUVbJBLQqokYKZsyZskPIwXIZVdbtFimDb8 CsSMyqXDKgKdvqIr4HlkuAedr084PAXXfGnPW25ZvYje5wlCT5TM/Bk1cSNtpxksd8HM XO6+zLp437fdQSPAehScY7Y3wpR/10vt5Vh5G5AJYAavileq2ptC/Pco7lNhuHN29WaV 1Www== 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=v13PLWkXZ66wysx6qv0HBBTwj9vKz5xqJXtl+0KE4mU=; fh=2UN7IjYuijkJBvyh9pz7V8dcFsArKSxF7HU9xR+3p68=; b=HNJan7TnRAwKUvVLT1t5cHMTE3Yp195MayKlQblHY5Te9jTSY2LSUYU/s/q31QzUJO 88k9Br9OBebLbSy0InAnqtSDu9O323JTiStt5BxlPGITZE39Jf5BhUilXbeZIU7+54My eShCjLWauSWwjbjjvvvFM/zEi2lpQ0K+uX6Yv8g8ML/3T+G7KsiakaFxagwgoGO77hbH KS4oBDoxV4eOG6IMTX8PspBzEYvAQtxcZsFPIyxJKJuxVYqbUVjTvYpy99aYNbDIsEgO rhkrhehFV7L2UHfCBI/O691zr8aJyU+AghmgHueuMVaDK0EwPYVwnWVGI3SQoIY5bL8K +qFQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=HACbzcz+; 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.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id x19-20020a63f713000000b00589878c0a5bsi10165604pgh.71.2023.10.16.04.58.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 04:58:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=HACbzcz+; 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.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id CBB36808AB8C; Mon, 16 Oct 2023 04:57:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231508AbjJPL5o (ORCPT + 99 others); Mon, 16 Oct 2023 07:57:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230514AbjJPL5m (ORCPT ); Mon, 16 Oct 2023 07:57:42 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2089.outbound.protection.outlook.com [40.107.243.89]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64B72EE; Mon, 16 Oct 2023 04:57:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZS2ezBuLt69S/hk72IftAzpqcTurMU2d3DUwXjIOmBjtpOJEq6AxsuDLYQeA2nvZZtnRrGdhK+YBKEbPgNZuhTWRoDtWUAtW/0RP9AXLl3C/mVC0DmlbsuNWajliIntHAv31zuWwUA55ORQCky8vkdWjsANu0XBowQZLFIZXVU1Pzi/jYek+KTeKE1mPXTB0Z/rwVWTgxVcBRGZZbcOkb2gmLqL1ZgGc323q7DA6yw8Lt6hipzoJaxYmmQLxGGDFOlA1So40M+ZxDVP2QxwEQTaw+M28q3xBeHwf6SJ02JUSk7g4pzufgG7RVe9OZSVNQMBQTFWhp5icMruHpIUJqg== 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=v13PLWkXZ66wysx6qv0HBBTwj9vKz5xqJXtl+0KE4mU=; b=n6Cb35g5lmsJFsGjvtJe4MdGEginUnXDLEY7pBPPtN8CdPQzss56OAvLVRe4dkdhx2D0HF3MS6FPeJgybfHzuYwY/isMzY6eTuEPi/67iCBohPfUCOjj/5dXGmrCpb/VeM/LpqFE5XkUoOAR5B3jGqaPI7t8Ta8NeIXhJ3md1qH+ZSQcd0Jq5MoJ7U3nDWTO8AIaJAK3zmk6/phP0zSFGZAKBHBPfrEESaeEW7LnYkCcMSNhN8/K6ujl+7UGrzSe+LLuwO5EPqQ7VULI3U/d4HDzZ7X7MBP4bSMnibkVtI7XqL9G9G+p/+Vfjro0HEWrcLqWs5850nd5sX1bKJ+ZVw== 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=v13PLWkXZ66wysx6qv0HBBTwj9vKz5xqJXtl+0KE4mU=; b=HACbzcz+3IEHwH91KumijGfznDZh/TXugP50rC5cE29Os6OtiqfKB6s8RCN+4pYCl4n4d5C0ZJz4Dsrc+2IbyoUoON2+xDs+2GQ1zRrI/a3yycI0Sageu32spc/WIgLquItLh4E8gjvDMKUhKXsS5ihdTcO5r9CxiuzBL4eTW8EI7DsxUpL8NsFlMO6qnArVRlP7h3ZAiPOwZcWvA+e9RBUKWJO+h4m7rToJ6F0WDAWpNaewC442RQ5bVjcZEZYKHSAeprN6Qo4dExqTRtBbGNH8jqLNR7gxGXW1hRk8ouvnKeYk2wenfPyElUtbGcjvTVZF8cqtWhEP9weJNGM6Ig== 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 SA1PR12MB7368.namprd12.prod.outlook.com (2603:10b6:806:2b7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35; Mon, 16 Oct 2023 11:57:38 +0000 Received: from LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2]) by LV2PR12MB5869.namprd12.prod.outlook.com ([fe80::3f66:c2b6:59eb:78c2%6]) with mapi id 15.20.6863.046; Mon, 16 Oct 2023 11:57:38 +0000 Date: Mon, 16 Oct 2023 08:57:36 -0300 From: Jason Gunthorpe To: "Tian, Kevin" Cc: Nicolin Chen , "Liu, Yi L" , "joro@8bytes.org" , "alex.williamson@redhat.com" , "robin.murphy@arm.com" , "baolu.lu@linux.intel.com" , "cohuck@redhat.com" , "eric.auger@redhat.com" , "kvm@vger.kernel.org" , "mjrosato@linux.ibm.com" , "chao.p.peng@linux.intel.com" , "yi.y.sun@linux.intel.com" , "peterx@redhat.com" , "jasowang@redhat.com" , "shameerali.kolothum.thodi@huawei.com" , "lulu@redhat.com" , "suravee.suthikulpanit@amd.com" , "iommu@lists.linux.dev" , "linux-kernel@vger.kernel.org" , "linux-kselftest@vger.kernel.org" , "Duan, Zhenzhong" , "Martins, Joao" Subject: Re: [PATCH v4 08/17] iommufd: Always setup MSI and anforce cc on kernel-managed domains Message-ID: <20231016115736.GP3952@nvidia.com> References: <20230921075138.124099-1-yi.l.liu@intel.com> <20230921075138.124099-9-yi.l.liu@intel.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: BL1P221CA0025.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:2c5::13) To LV2PR12MB5869.namprd12.prod.outlook.com (2603:10b6:408:176::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LV2PR12MB5869:EE_|SA1PR12MB7368:EE_ X-MS-Office365-Filtering-Correlation-Id: 61a481a6-1720-4908-598e-08dbce3f178f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: n6/xQ+PNfsNskXNgWQberyLLXx/Wm+MTLitZJGKWoZ8soi9VK3Eswyn0cMT32OtQSOKP06zSp6yfsbruBtag57gulLFjRjOr5LgQTOUD8zjPEbRMRRPjPYKjpDoFoP4Av/zkxXZqsLCu9xBGh1EX0uanReNu6HCxluUmtiRWBIM8ClEn+N4gWSnGAZSRo+IOiQJjDNgZIm0yy9Kz3LT5oPN+83+TQ5kcEESS1lrfb+ty6qeDyQMhrMyjp52QZarpPmEO0GoI67sYulGnRebk31zHMXoZqBSGiEQStx1J7WVU1OHzYJv+TCy5ZOcUaWxDXLkKouRRtvRugm9CTCT13cGyMdDEtzeOndo6wJQppgXANAmOzt1hMvEW2VjIEDD/jIMz1pb30dWZOqnY4MSqD/GacJy63WaanKksgz2zrRYNXroROOcYk6GwS/CeUrxAvvwnTHYQQ29FGBv7O6BjzufCItRqAhqYMW8YY/ye1ZuKa53nM5sbItBZAd9d0G16/j4TSHCPTon5ElrI7A45zGyWVMfPnOg6zxOVsjpAfbOYPaRyX9st95/DqK2pPpFt 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:(13230031)(136003)(396003)(376002)(346002)(366004)(39860400002)(230922051799003)(451199024)(1800799009)(64100799003)(186009)(478600001)(6486002)(66946007)(66476007)(54906003)(6916009)(66556008)(83380400001)(86362001)(38100700002)(6512007)(316002)(2616005)(26005)(1076003)(6506007)(41300700001)(33656002)(5660300002)(36756003)(4326008)(8936002)(8676002)(7416002)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?FsrlPBU7f8zhWFz6B0SQm61A1F7df8ShQLCoWqk9OHmaa+dN/RKrbgVtvYLs?= =?us-ascii?Q?DkLyFFSYD8mtrue+7zmynnYXBoP08yIBWNYrCb/Fp0/0gpwEQjyzs8tqV8oV?= =?us-ascii?Q?Z474Fh11rPa9PLHrMxTK/NyH8XSacY34IfaktB5ZCDlXz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xtn/FjgiTjr2qouE9SonRYI6/ITpkKup4fZ1amfPtkjAGfjE?= =?us-ascii?Q?PGMJPrqa6nFwWL5J00ToKDt6Nrk1KfzuNLWS67NoLUhY4AbXP2WDRvSPDeDh?= =?us-ascii?Q?srvPEjsVjJwyxC+wR9eW/Il+oVsfNobxHTP/cFiRktlybrIkPF88Txo6AbHj?= =?us-ascii?Q?d5xOqSUg5UX99ta5McbLTLdRDkGbRz3nA6R31TIt2jZWxa26Vf81e1fexI2k?= =?us-ascii?Q?0d4oAnQ9iR6Np50cLoHTO1slPJZKjuUE+Z7CuQwsVebGSJAV6v76gdLWQymx?= =?us-ascii?Q?uwspDTe6b/3xgJPjhgjqVNAHKlsTUOWeZ6//WRsheO+uwE5vjfLFIhVOQIXD?= =?us-ascii?Q?xOY75YXFjYORG/CEWf0U6Gch5Vt2xDtyNxpGBrlhvcNxxaRm1T5alNFHxeQ4?= =?us-ascii?Q?1NQuIbsZUvLc5XUbgnDseAvW4Uv4jIOynaH9vgydn6lFcDW0YtgTc6pKkOq5?= =?us-ascii?Q?VoYI+meDBLanJqW5a/tiP/aGbATiYMXQAuUvXaTBVeppwaLbv21o1+PXk+TC?= =?us-ascii?Q?fW22IIZyA73YmXAqMcE=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 61a481a6-1720-4908-598e-08dbce3f178f X-MS-Exchange-CrossTenant-AuthSource: LV2PR12MB5869.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2023 11:57:38.1317 (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: YbtT0U1cuRZAuylEEWagtiiw3vNjfg9ikpj/DYeezdqTJgf0LG41PSPybhD8oAdD X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB7368 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 16 Oct 2023 04:58:00 -0700 (PDT) On Mon, Oct 16, 2023 at 08:48:03AM +0000, Tian, Kevin wrote: > > From: Nicolin Chen > > Sent: Saturday, October 14, 2023 8:45 AM > > > > On Tue, Sep 26, 2023 at 01:16:35AM -0700, Tian, Kevin wrote: > > > > From: Liu, Yi L > > > > Sent: Thursday, September 21, 2023 3:51 PM > > > > > > > > From: Nicolin Chen > > > > > > > > Now enforce_cache_coherency and msi_cookie are kernel-managed hwpt > > > > things. > > > > So, they should be only setup on kernel-managed domains. If the > > attaching > > > > domain is a user-managed domain, redirect the hwpt to hwpt->parent to > > do > > > > it correctly. > > > > > > > > > > No redirection. The parent should already have the configuration done > > > when it's created. It shouldn't be triggered in the nesting path. > > > > iommufd_hw_pagetable_enforce_cc() is not only called in alloc(), > > but also in hwpt_attach/replace() if cc is not enforced by the > > alloc() because the idev that initiates the hwpt_alloc() might > > not have idev->enforce_cache_coherency. Only when another idev > > that has idev->enforce_cache_coherency attaches to the shared > > hwpt, the cc configuration would be done. > > is this a bug already? If the 1st device doesn't have enforce_cc in its > iommu, setting the snp bit in the hwpt would lead to reserved > bit violation. I suspect there are technically some gaps in the intel driver, yes.. > another problem is that intel_iommu_enforce_cache_coherency() > doesn't update existing entries. It only sets a domain flag to affect > future mappings. so it means the 2nd idev is also broken. This is such a gap, intel driver should not permit that. > The simplest option is to follow vfio type1 i.e. don't mix devices > with different enforce_cc in one domain. This is why I wanted to get rid of this bad mechanism going forward. Manually created hwpt should have a manual specification of cc and then we don't have so many problems. It means userspace needs to compute if they want to use CC or not, but userspace already needs to figure this out since without autodomains it must create two hwpts manually anyhow. Jason