Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp1910410rdb; Sun, 19 Nov 2023 16:12:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IGj+ugduDXRPeXIi2gg/W75ug53b4XN/yvWTJyOk7DWjde7hs+9AgCX8vFKuKXo8Ht2JnVM X-Received: by 2002:a17:90b:3b82:b0:281:d84:a97e with SMTP id pc2-20020a17090b3b8200b002810d84a97emr8220355pjb.2.1700439170663; Sun, 19 Nov 2023 16:12:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700439170; cv=pass; d=google.com; s=arc-20160816; b=B7htWGdM8N/5YwEKnGJCEcpDijreBaQLIdlGWTaVsgJQOTFBbaXj6uZufIXBf+/6fA EJ3rotNkr2j9Dr3aRe91Prc1AlrlBNh+jVcR+503yIh4uYwf6nIiUZYoaCG6RXVxJnRq pQsEpOGcb8bjCMtDeJ1vwNfTe0TPzKg4g3E4w59iifkrCMh6E4MjCVaqG9k2X+F2Af/e 36S2ogaTunZieLSg2Zelvp3Ww9Lh2ZcfaFmZVEpKVxq6pJsFS6zx/yk2l3JsCZgK/G10 EuYFyZV5Z1QH37dlD+fH6/n16+Bx94IcfeUr7vuZBoedbYO0o701+atMF9HyZwlyuBXz WmGQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:in-reply-to:date:subject :cc:to:from:user-agent:references:dkim-signature; bh=wgjNY4NIGEzjsjQHPkywXnozGRT+pkDw7MyB0MXI4ks=; fh=o7TTbe0ahozSGNfE0uy0OB9P40Nm2+7M3ZIgEU5kZZw=; b=kc4y/Q1pul5p4baw4qNmIN67h7wpEHx0GSWlPfS7H2Z7zMJDmtfhkp69MzBzSC3PqM US9pqLWAj8n+hYC3csSdrrRM9d89MwdT7AJHYips/376weUaO/qXKl/C1YkWz2SWbICJ ZNauWT6FSO1lN8B5YUI9mMan4rbn3DN70GW98Y9VAiFwvingTYLpbB7SkrsEooeCyiEQ 6Wh5hRNLQ7E9ebctBlKUOd3RQcawTOGIbVKFknKuGW63affRQuenNzRdfokpGhX0s3gQ IWx7ZatBKWCu+MAV6sTIwbVJbaipHDATAAQXC3kvUQUEidf7tOllPhfx3BT/2k1nLEcs Lx7w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=acsDS7tR; 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::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id v4-20020a17090a898400b0027450695a78si9620319pjn.172.2023.11.19.16.12.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 16:12:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=acsDS7tR; 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::3:7 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 snail.vger.email (Postfix) with ESMTP id 313AA808E640; Sun, 19 Nov 2023 16:12:34 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231565AbjKTAMa (ORCPT + 99 others); Sun, 19 Nov 2023 19:12:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229569AbjKTAM3 (ORCPT ); Sun, 19 Nov 2023 19:12:29 -0500 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2053.outbound.protection.outlook.com [40.107.220.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC502E0; Sun, 19 Nov 2023 16:12:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MobNXeuVd8uxO7aiuZs+b/yLEVz1uxRj0I44pYGyb/Yv9glF+YCzSl/+vGjq57LKcBePZt+Dx8BNOWPGrMGlBKB2/JY3AJobFaNCCwNUB0butsz67sxaoxqGCAjiu5bFwjUQ1TBK79AsD2qQH74n5R69xhMgAxZ9N4ZAzcACMPXSCyKNrhZqrba1cKyGdSxnK23KgXmXAIuKhaXiBY7WA/UBDum3Pva6LlEVV2GLSgCPydojlrqAVeXgmIosilW3oH+PMsXRUyliorIhmvDoxkl15dixY4pdeyXChrDWPJMPjorxOx8v7f9kIzZyS7PorVxQ/w5Iku2L7dWrUr0Ptw== 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=wgjNY4NIGEzjsjQHPkywXnozGRT+pkDw7MyB0MXI4ks=; b=KOromIqZ6WjJI57Ra2zZduWXx+NJ8/YpcpmLr1LfLNMPWRl2rWVcsf4e/AhzDt+Okutwzw0Ohz6RNnuJxkEUnShMr6K6VYrMG2re3ch1Q270RbpYcldCklMUi89hLGioMFqsexnCOfC7cnZ7+4Ga214ZHxi7FzaWseowtCt40ZU6QORlPELQEPQZxRwP/biJ5p4m+ACYpu8d8fuy5XVUu5F49uWONyZasWfKFgKyxsDRt0IDaYM7IOIhi2sTl4U/QF5BXYX9UtRo7UDD+xFd30xQG5tveTGNN3Kz3GqDkv4vfrMZ2LOgsdPEAu5FmzOQBYVoibmv136bP5PTESrKSw== 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=wgjNY4NIGEzjsjQHPkywXnozGRT+pkDw7MyB0MXI4ks=; b=acsDS7tRS21qxIBlxi1ZkhzTXAsm5uJm5qOAHlIDoUfm83AWS9uIprGIJLY2jBRhw8UGbt7iafkiKObR7TtSZf97aVvO90fhmzLzThba0a7cx9iR6i9IwEJ7Hw5R7JySBrL7m+7KKBbaWsbcOQ7MQg+zYX8nmP9NSe33tVSAfevZYYhiwR3moNUd4108l1e9BzjmKcboWKUU6/owYXWVJoCrAWQ/XWxf0FfWj8yTutbQcvcsKeTIfrhOgnV0sIYFsmJE7eY/TbqqXVwqK6DXJlhlr14EV5RvfeA3Y5WwJHmTGHPVflXS9Qa/ceLzPgk58ThudYmt4bfIC9nBJJL0kQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) by IA0PR12MB8930.namprd12.prod.outlook.com (2603:10b6:208:481::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.26; Mon, 20 Nov 2023 00:12:21 +0000 Received: from BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::fb09:9679:bd22:6bcb]) by BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::fb09:9679:bd22:6bcb%7]) with mapi id 15.20.7002.026; Mon, 20 Nov 2023 00:12:20 +0000 References: <20231117090933.75267-1-baolu.lu@linux.intel.com> User-agent: mu4e 1.8.13; emacs 29.1 From: Alistair Popple To: Lu Baolu Cc: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Huang Ying , Luo Yuzhang , Tony Zhu Subject: Re: [PATCH 1/1] iommu/vt-d: Fix incorrect cache invalidation for mm notification Date: Mon, 20 Nov 2023 10:57:43 +1100 In-reply-to: <20231117090933.75267-1-baolu.lu@linux.intel.com> Message-ID: <87edgll1up.fsf@nvdebian.thelocal> Content-Type: text/plain X-ClientProxiedBy: SY6PR01CA0050.ausprd01.prod.outlook.com (2603:10c6:10:e9::19) To BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR12MB3176:EE_|IA0PR12MB8930:EE_ X-MS-Office365-Filtering-Correlation-Id: 44db5e48-c6cc-4665-0c2e-08dbe95d5c6c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: O5fMrHESOa4OvMynCkRvEB4ryO9Ow/RFiPqoWcLOlMhNGlWb/Bj6oomYL2IcLf5gH5Ls2NsjhnubCYoIr8Nl0/8R+PyWhYwdzKvAjRg6me7uk2/ivIWuG02HkQYvkPDnGpBRHfBmMvFpu4keG2FDm3l4NkSKLDCEaNnAilHJK4lKlsurl+0KQhSBZKBB2jE3NTqOntLKe1WYUpuCKX3bCOO8NwB+qQgYfDXw38WPue9LLuyehH0gkPhMeGDRYq74+dih2n+y3DF99+LbWCwxk0K2PeeOaXj5FlYM+A8jToYWpuxTIPmuZeA/Yqah8evKQ44nAzkCDLMJhHU1l6ryFAd/HeviaVueNwPDlaShZXzv4tnpDqCTAlXTajDswAGQW3wWX84EUXIdF4oMgFkUUp5quDiAD+ZD/ZWKoEe2ZPIKx2mN2CMRxCxH+DX3kSM6dZBGz5Cm3mk3gM2cXontHreOh3HEHu4e/7CrN9xEC+2xq8sBtNsTnKdm+h3ZkpWxixqSn7Y+csjS01vECrERNdlZP3WoM5sUuqPlt7BURfly/Ba5W6uah+nCFgKYyhkq X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR12MB3176.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(136003)(346002)(376002)(39860400002)(366004)(230922051799003)(451199024)(64100799003)(1800799012)(186009)(41300700001)(5660300002)(7416002)(2906002)(86362001)(6486002)(8936002)(83380400001)(6506007)(478600001)(6666004)(26005)(9686003)(6512007)(38100700002)(4326008)(8676002)(54906003)(6916009)(316002)(66946007)(66556008)(66476007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?oTKPXJJQGucwMaKDVGc8Z7WChF9BwgJK1+GfZ8F38LslhSiHyJ2kCnmuu0Mk?= =?us-ascii?Q?Bp/SSqCjVGJhgAXwgndCEpfgAfdXxMPFVfFOMYs9J3gGpOiKtVbduXf1Y8vJ?= =?us-ascii?Q?WEu53/JUhlIJ9fCcLE2umyHRNd3rNToP7wWE7aHnZqR544XQMSKafFNYwmgS?= =?us-ascii?Q?8iVyBDYdTgOu3FaDdKmZbNX18s7hgjjekjJ7d+QYjNrMD3x7i2nTRNT3hiU0?= =?us-ascii?Q?+PdSoM8J4K2y2ebhr1berDz5/smLXOBxkAnc+Y4ShzxzFOXWgmKG9s3VbGyF?= =?us-ascii?Q?mFN14zaTenHfSkZdyiBL/KQS/FAYu3madXtKX0OV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XBf4VKk6SlNHXszO88bp5noQk9gjLT5ZWK?= =?us-ascii?Q?yeFUuAEFp1lHtY8AvZ3I0ZSMayXSH4WFJwtI3tmYa8KfaYYw6uU3NRrHGxqr?= =?us-ascii?Q?mRBLZwK+8gTfH1GUFpFhL/RAXoMnxwOGHd/c9N9USqSmWnFSxfLV1Q0VPcxx?= =?us-ascii?Q?1G8ep0LNfxJtkP31f1vkPDyNG5hnXkNDlI9m0qI6whs69scz5NMIuSCRNzrg?= =?us-ascii?Q?SFxJJo1VxSuxCk35wuMhbWM3s2jrfoNrdLAaub+94ty90Sduo273LBE4mbiR?= =?us-ascii?Q?OkxEoUC1aDbK8rdWJIxyZXEUXBUkFya+4BUW8oxIsr8QqnL140xoDGVoWJ5N?= =?us-ascii?Q?vvH0Lw3U+JMVxDMlsuF7u/4FQpCXGXmLSZxC/mzJ?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 44db5e48-c6cc-4665-0c2e-08dbe95d5c6c X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB3176.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Nov 2023 00:12:19.7941 (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: 7aswaJxaiobhrFYvUUUy5EpEtEUiL30lSKvHJnLhKrXTI96QJyQWquRxAdmq7wmdeda6nhs+izIasA+LxRF98Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8930 X-Spam-Status: No, score=-0.3 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_BLOCKED,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 19 Nov 2023 16:12:34 -0800 (PST) Lu Baolu writes: > Commit 6bbd42e2df8f ("mmu_notifiers: call invalidate_range() when > invalidating TLBs") moved the secondary TLB invalidations into the TLB > invalidation functions to ensure that all secondary TLB invalidations > happen at the same time as the CPU invalidation and added a flush-all > type of secondary TLB invalidation for the batched mode, where a range > of [0, -1UL) is used to indicates that the range extends to the end of > the address space. > > However, using an end address of -1UL caused an overflow in the Intel > IOMMU driver, where the end address was rounded up to the next page. > As a result, both the IOTLB and device ATC were not invalidated correctly. Thanks for catching. This fix looks good so: Reviewed-by: Alistair Popple However examining the fixes patch again I note that we are calling mmu_notifier_invalidate_range(mm, 0, -1UL) from arch_tlbbatch_add_pending() in arch/x86/include/asm/tlbflush.h. That seems suboptimal because we would be doing an invalidate all for every page unmap, and as of db6c1f6f236d ("mm/tlbbatch: introduce arch_flush_tlb_batched_pending()") arch_flush_tlb_batched_pending() calls flush_tlb_mm() anyway. So I think we can probably drop the explicit notifier call from arch_flush_tlb_batched_pending(). Will put togeather a patch for that. - Alistair > Add a flush all helper function and call it when the invalidation range > is from 0 to -1UL, ensuring that the entire caches are invalidated > correctly. > > Fixes: 6bbd42e2df8f ("mmu_notifiers: call invalidate_range() when invalidating TLBs") > Cc: stable@vger.kernel.org > Cc: Huang Ying > Cc: Alistair Popple > Tested-by: Luo Yuzhang # QAT > Tested-by: Tony Zhu # DSA > Signed-off-by: Lu Baolu > --- > drivers/iommu/intel/svm.c | 26 ++++++++++++++++++++++++++ > 1 file changed, 26 insertions(+) > > diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c > index 50a481c895b8..588385050a07 100644 > --- a/drivers/iommu/intel/svm.c > +++ b/drivers/iommu/intel/svm.c > @@ -216,6 +216,27 @@ static void intel_flush_svm_range(struct intel_svm *svm, unsigned long address, > rcu_read_unlock(); > } > > +static void intel_flush_svm_all(struct intel_svm *svm) > +{ > + struct device_domain_info *info; > + struct intel_svm_dev *sdev; > + > + rcu_read_lock(); > + list_for_each_entry_rcu(sdev, &svm->devs, list) { > + info = dev_iommu_priv_get(sdev->dev); > + > + qi_flush_piotlb(sdev->iommu, sdev->did, svm->pasid, 0, -1UL, 1); > + if (info->ats_enabled) { > + qi_flush_dev_iotlb_pasid(sdev->iommu, sdev->sid, info->pfsid, > + svm->pasid, sdev->qdep, > + 0, 64 - VTD_PAGE_SHIFT); > + quirk_extra_dev_tlb_flush(info, 0, 64 - VTD_PAGE_SHIFT, > + svm->pasid, sdev->qdep); > + } > + } > + rcu_read_unlock(); > +} > + > /* Pages have been freed at this point */ > static void intel_arch_invalidate_secondary_tlbs(struct mmu_notifier *mn, > struct mm_struct *mm, > @@ -223,6 +244,11 @@ static void intel_arch_invalidate_secondary_tlbs(struct mmu_notifier *mn, > { > struct intel_svm *svm = container_of(mn, struct intel_svm, notifier); > > + if (start == 0 && end == -1UL) { > + intel_flush_svm_all(svm); > + return; > + } > + > intel_flush_svm_range(svm, start, > (end - start + PAGE_SIZE - 1) >> VTD_PAGE_SHIFT, 0); > }