Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp559291lqb; Fri, 24 May 2024 06:50:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWi74ZEKechmeMhlVkrl+/KMqS1Sj8oqk27ct08q3wKfNhdIChCBfAr3d0Q+JHFFtEg1inWR7M27emJMHdc7fO19/2jQzvOSpadQLrgLA== X-Google-Smtp-Source: AGHT+IH5CyHsTfK3j2Vc+ePUfIFFq4VK9V0KUYvp2H+iMoQgzLkg/NiLXGNGe7d//Phr21s3+TX8 X-Received: by 2002:a05:622a:19a5:b0:43d:fc88:5857 with SMTP id d75a77b69052e-43fb0edcbe4mr23819871cf.52.1716558618169; Fri, 24 May 2024 06:50:18 -0700 (PDT) Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43fb18eda84si20146211cf.772.2024.05.24.06.50.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 06:50:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-188750-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=iP7mSUH1; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-188750-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-188750-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id CE6121C21A64 for ; Fri, 24 May 2024 13:50:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2759D12C467; Fri, 24 May 2024 13:50:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="iP7mSUH1" Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2084.outbound.protection.outlook.com [40.107.244.84]) (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 6C28539FF4; Fri, 24 May 2024 13:50:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.84 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716558606; cv=fail; b=kUAgHJ5Y3u/nZ3SKir+5UbS/KYdfONniI6UXrhkey4jg4yfab1fegCZKVI5zvOef8oAteBUDa/k4Tmm71+nP5AEMclnnvQVdbcsaKlE4HnINeWgOlm2pqKqGUKWlOTQN36Cuk3ZRI0jOUltULcJrL7RbuQAGiLmGhRIv0Boad9o= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716558606; c=relaxed/simple; bh=tIq7bag9QNivcDxhTXzObAd3hx4NO2pOkzMyzMrODOk=; h=Date:From:To:Cc:Subject:Message-ID:References:Content-Type: Content-Disposition:In-Reply-To:MIME-Version; b=TnxFLj4n7zDFs2aN6xWgL4i/99IvpU88wv9+OmDLZTfSfRWmzd+qLVvcSNr8Oozsufv8jdAvkFaiASSXRe9su2uJO5syXDaGWBgMbKGL46auJnIntno2n3WzPNzqfnpykzsKOi7om1NxixZTZNV5xd24H7cYBdas1r3Z+e6XWCg= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=iP7mSUH1; arc=fail smtp.client-ip=40.107.244.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QBH1/qsYHkUxU//SRwFpOgMuIdLFFWKYwd6t7WJI6wTBW/e0jkawMG8n9xszN319hRHK4MYc1j3Q7COzvOB7AMraDDN2z943mlZ8s3l3C+SUOTiYiYXKaIdH7eCohE7Pp6naSQ+5AzcJYEfLtM4UntX7Iyt2Z/JcN9PWvALE258pGcVm8Wrwdh3T2K3pszluqC1kBM+a+fMJoh8Fie/NpyBSBN/UuI8mL9C/FrxDXz7WOO15xtKwBk6gUOFbnRiCyDgn8Nx5e/IGL4ObV/k+xnqU8X/HxVhdKBVqCWRsbvimb8zoYYDSJXOj/V3gypWvx2cpRyMG1JnMe4cgddhn+A== 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=uFd0Q+4SyUgR+368N01G8HRYTOiQfBnSRCKZzqyiitU=; b=d+AGImsu5iPJG0hWvu/LULlkrEhBUFkkKtTMLGqgvrjvrDR5REulYfD1kRQpMbfEV6tRvCKyrYk5dhUx8BcAGxhrKFQWRD1i+Gy7dSptDoTthUjnyZYUej9lrKtbygk8VUDNvlFuTW07q3tLVpkfMBurnN/1e1IBi7z3qcGDfLX2q3c/fTWzY2C/Rl0nayyCzm8q4nqsaiXl7DXZSjN0CZ2sL/BGK+q7ySy7D5LTaeOmu6EfiRabUiblQ67893bY2ilW6hztrtzleXGJJ9Cz6pQsKr7oEC4KqrfxSRqW0tzQSC9Ac7J00vdZIzjXd1GJ7w25pNzQ7UXtpyy/dXjxXQ== 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=uFd0Q+4SyUgR+368N01G8HRYTOiQfBnSRCKZzqyiitU=; b=iP7mSUH1wnuCITzSz6iznXisNfcG8zAAr2uxwoBc6P3ffYhn8eqnqWc1pOy9kPW7Soq1VD8k0XnoAiUAQ0/FwzM2SMwUrMa+ZRyIQQ+DoTYIlaTOOBwfd4pAA8hvFD3ckn31bQjb+dsjYzyyHQsJKqZh7mMtoecSzlAFbniOcy2mp8fQTYRYkdZKRFFnCWerS7o+/J+n3li9sZjRLkrlcBxVUWHokr0b8ENiEJ7EcvrW8N1bOBT+Wfut7AAvljz4dV6D7tTx6czNXxeiCCqKMxgJeGFu+yfDvHcD/B16Li5yQdZ+d/prESXEnWajSC3tjSzOQORSyO3fihcifYr5zA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) by IA0PR12MB8327.namprd12.prod.outlook.com (2603:10b6:208:40e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.20; Fri, 24 May 2024 13:50:01 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::c296:774b:a5fc:965e%4]) with mapi id 15.20.7611.016; Fri, 24 May 2024 13:50:01 +0000 Date: Fri, 24 May 2024 10:50:00 -0300 From: Jason Gunthorpe To: Alex Williamson Cc: "Tian, Kevin" , "Vetter, Daniel" , "Zhao, Yan Y" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "x86@kernel.org" , "iommu@lists.linux.dev" , "pbonzini@redhat.com" , "seanjc@google.com" , "dave.hansen@linux.intel.com" , "luto@kernel.org" , "peterz@infradead.org" , "tglx@linutronix.de" , "mingo@redhat.com" , "bp@alien8.de" , "hpa@zytor.com" , "corbet@lwn.net" , "joro@8bytes.org" , "will@kernel.org" , "robin.murphy@arm.com" , "baolu.lu@linux.intel.com" , "Liu, Yi L" Subject: Re: [PATCH 4/5] vfio/type1: Flush CPU caches on DMA pages in non-coherent domains Message-ID: <20240524135000.GY20229@nvidia.com> References: <20240521163400.GK20229@nvidia.com> <20240521121945.7f144230.alex.williamson@redhat.com> <20240521183745.GP20229@nvidia.com> <20240522122939.GT20229@nvidia.com> <20240522233213.GI20229@nvidia.com> <20240523145848.GN20229@nvidia.com> <20240523164753.32e714d5.alex.williamson@redhat.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240523164753.32e714d5.alex.williamson@redhat.com> X-ClientProxiedBy: YT1P288CA0021.CANP288.PROD.OUTLOOK.COM (2603:10b6:b01::34) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|IA0PR12MB8327:EE_ X-MS-Office365-Filtering-Correlation-Id: 1199e791-5d96-4817-cc3f-08dc7bf86866 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|7416005|376005|1800799015|366007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?HlqkLdOgkpZL+LaOBishs32c5poLj3JUoxjsBpH2khIiFzkZM6CXVqWaoxdX?= =?us-ascii?Q?Je3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+FcYNasUwJxyIWW?= =?us-ascii?Q?ynIOlGTECLezILr4/e/112x2AV1nOx4PKmuDvqEuks86S1iPcDT1Qihu3F6x?= =?us-ascii?Q?UrqOFDV31EVP2CIx0HJ9czD5fAndM0/8XYiQ0vLL7ONHuOoykjeKOcgxo2zp?= =?us-ascii?Q?7X+GFQKYbpWA4846+PTLUyDjXoTokIkF0RmZR4EBuFCV3hPizUSa1KsfCu78?= =?us-ascii?Q?wby5akqGdtCZdFl+2Z7zq9aAVqQOUJmKqYTWp+CdeBit2TrVL3MZMoEMmYaN?= =?us-ascii?Q?pm+Bebv6vTYxObWSMVep9u2YQB4GygivvaDAXVYYVvwECBiSEXcM/FWBtTX6?= =?us-ascii?Q?Ii3HynGD/1bgSo2TcVtU3R/ee192XufrvtFDNjMwPg=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(7416005)(376005)(1800799015)(366007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?qyi20CXaTPund6bEb/XpGHrRnKjIizQDQhvknlmBZyctoEA8dZ0BGTT4CJVm?= =?us-ascii?Q?nM+RfU7ZDdzQxm6v1BR3aV6gZN/78k3pLmJttpYZrcAT1Px/lqnI3DcE88Q5?= =?us-ascii?Q?GWLgk2cWOJlVeiqEhkkrszDq80zZyWmJHfHgEczmlrOIRWd18RtZs242Qeic?= =?us-ascii?Q?jX9WUv4gNxUwcjjLz1zMJ/637pzL719sH9xKJrDJYpHYiNu6T8VknBjmomry?= =?us-ascii?Q?L9RRu0kVRNMxa4g9cHHw/ag5Ll9OeT524s3pNiFp1nk8l5KYRd1YM+NXVUUw?= =?us-ascii?Q?fC99kUKFLgqeTD8YYiQfCjOu2hhrrgp+vdB+56CmnC493xY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Cqu/mvRhF+mVGBkaEyhvidVnaN5wuDPQSwp6Hiq3?= =?us-ascii?Q?V7hSL7+Spq1wHIW21JFhV9sXwo/Jd9JyA050xDCKKcwpa2TR5LbBZOxgNOyO?= =?us-ascii?Q?YCG3hhZQBTGbDzux/Sa/LgK6KQom/mpYheTj87ZrlLJldo3nzDU3V2AbgRXV?= =?us-ascii?Q?NY+im8Iq4meTNwd4ASpOQ+HJuNEIEBVdXxNsLHmT7kef87Xi3mtK/GuioHM2?= =?us-ascii?Q?45YsBQmzTDU/vQ/bbVqR44PF37DE5JAtVeFuk2F0cQuUZaqOLYfnXdwzctgI?= =?us-ascii?Q?zKbl3dcP3SgVj01yGvtW2Dc9hcjBUgXta0kuyYE+ttZrgV1bItq4h0Yddq8/?= =?us-ascii?Q?Q15cf/Jx07elv9AddDqsUVqX42ivoD/jziJoe7Hi?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1199e791-5d96-4817-cc3f-08dc7bf86866 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 May 2024 13:50:01.4578 (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: NYamzHYGlQdkhhfS717TDub7F4llImwOhhVMp6ENay7w6zJX9NcDl7p4hjKW/ij4 X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8327 On Thu, May 23, 2024 at 04:47:53PM -0600, Alex Williamson wrote: > > > > I am suggesting to do both checks: > > > > - If the iommu domain indicates it has force coherency then leave PCI > > > > no-snoop alone and no flush > > > > - If the PCI NOSNOOP bit is or can be 0 then no flush > > > > - Otherwise flush > > > > > > How to judge whether PCI NOSNOOP can be 0? If following PCI spec > > > it can always be set to 0 but then we break the requirement for Intel > > > GPU. If we explicitly exempt Intel GPU in 2nd check then what'd be > > > the value of doing that generic check? > > > > Non-PCI environments still have this problem, and the first check does > > help them since we don't have PCI config space there. > > > > PCI can supply more information (no snoop impossible) and variant > > drivers can add in too (want no snoop) > > I'm not sure I follow either. Since i915 doesn't set or test no-snoop > enable, I think we need to assume drivers expect the reset value, so a > device that supports no-snoop expects to use it, ie. we can't trap on > no-snoop enable being set, the device is more likely to just operate > with reduced performance if we surreptitiously clear the bit. I'm not sure I understand this paragraph? > The current proposal is to enable flushing based only on the domain > enforcement of coherency. I think the augmentation is therefore that > if the device is PCI and the no-snoop enable bit is zero after reset > (indicating hardwired to zero), we also don't need to flush. Yes, that is a good additional starting point. > I'm not sure the polarity of the variant drive statement above is > correct. If the no-snoop enable bit is set after reset, we'd assume > no-snoop is possible, so the variant driver would only need a way to > indicate the device doesn't actually use no-snoop. For that it might > just virtualize the no-snoop enable setting to vfio-pci-core. Thanks, I wrote that with the idea that VFIO would always force no-snoop to 0. The variant driver could opt out of this. We could also do the reverse and leave no-snoop alone and have something force it off. The other issue to keep in mind is that if no-snoop is disabled when we attach the domains we shouldn't allow the VMM to turn it on later. Jason