Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp7770136rwp; Tue, 18 Jul 2023 23:14:09 -0700 (PDT) X-Google-Smtp-Source: APBJJlEqlMBRwwvAzEwwaStFF7n9bMlthGPPC3/W1YaSFY71+BP9lvpAyT4IIHjpcf+F1P3ea888 X-Received: by 2002:aa7:c312:0:b0:514:a4cd:85d7 with SMTP id l18-20020aa7c312000000b00514a4cd85d7mr1609895edq.26.1689747248730; Tue, 18 Jul 2023 23:14:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1689747248; cv=pass; d=google.com; s=arc-20160816; b=0k2UDAIoV2+rduF/v93qmmZpVeO01TSKquZh4UgzDSFzGiIMSfQ4oY0leUT6jffPKT MJmxkwo/yeT3I95WgTfaj6n5BxSrjKwnwkz1wzqqSu86hoiIi0AwjhhUHJFJkeD99Xpe fgY9HgwpnAxv4HFEHdhw3BHRmNXsQsxB9WKf+2DOigdXJMhfo6D0XsshXEIPgh0JraqN KvxjI/EYkzDQ8/jaRGiEgZsOmOahqyH+8eC7RWMK6J/tpJa87gg/OwL0pIg3Uf2JItXt bsNDVKSE2IIos28jWedMvNtUSOiUohpCTN9vB9HPubMM4j/6TjNZqwIihs+yr83e0QVM UXTg== 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=ug7J83PlBYKiDv89D72Y+xbTbyuEJxN0v9tsfrkv85M=; fh=P8zOaopwbo/sPYpl6FspkAfi5W+moQEKNcdPqV3+jkc=; b=KTOyelUmxbbjFyvKsl5f11LS/MaBBQhwGebZMSMljDTDB0W5UmitlZ0MMi5IKoC0Vl /eDaqd6kxNHckc7YrypybmHhVBgkvopChYt4UL9Ql7HzgvZwQMpVFbhaAnT8HhkUU3gb WaUOGlEAYxxEPMp0ozPQReLBke8rxfFmgVcaKfV3bM3u91r5B9b9JeewCV8d87vLNXvQ JYeTZbdbpcXjMxLA558vbzOOJPJLF4g/UGDJ/hBqmXtV84/ibAC9owUSP+KIaW7AELXk Ege5zSvW/mki63+DLGp6uq4pYXLclgASRpESb8eCUmZlqar7SkRqVGatynJqLy9jcNnU tl3w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b="R9mS1j/p"; 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 k21-20020aa7d8d5000000b0051e1a404638si2622706eds.277.2023.07.18.23.13.44; Tue, 18 Jul 2023 23:14:08 -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="R9mS1j/p"; 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 S229808AbjGSFmn (ORCPT + 99 others); Wed, 19 Jul 2023 01:42:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229554AbjGSFml (ORCPT ); Wed, 19 Jul 2023 01:42:41 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2064.outbound.protection.outlook.com [40.107.93.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63582D2; Tue, 18 Jul 2023 22:42:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dxwWjnf4xVIlUKMwdk3EPs32x5NZm3ZSsM+nEZyGp9+Lb73opMDyMLHJiaYKGsLYy2uCI/rDk4t58VLlfbFjHy/FFldljrNAzYCEWpvn8GgPoUWARaPOLT5popDS1LW5TM9jn/r5iVDYt7SdPV2Opj/Q9s4xqEUKMp4xQi6xb1aSPTjTVvwiuw1d1SY4+pYsbjcKg5ertl6cCo6fG/E9UzkHbRUCpvu0ua1F25CFKRIUSqFZwBWBCLl3nY+/zRzTt4QtL7y32y6BBw0tPf1UgSU4BK/C2fX27Li67J+NG7r22BbDcoMkBKQsbZBmgKUe/oAHbnUBNzGeifljoHhRIQ== 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=ug7J83PlBYKiDv89D72Y+xbTbyuEJxN0v9tsfrkv85M=; b=kuw2dDn40dWYSZq/LH9pSoscZwRgh/vwgH0OvY8N9fV4zYW/Zi4tktqlZjfxCk9cvhRF0F5YlXIQyYQ75TyfZ7N+cXqKrtmsQbXQebzdygARBzBQ8A0Tb4+9uWm8DKvwEite1l2lMOdj63wetq+YnijArm0nwhIelxnU9ex2eJCG/1UH9NaasJdms3GGD1EiIMGKNLTv9VAgAPWKazzCFEUZcjkFD3EtsBrZ6j111hgtc5P2nyJ0eCaDtpRAop4wepcg6vsdisHv0JjWuA5QaWr4AYYRr21VtySKIIkJCGC3geYXhHDZEm7YMN1nbjBlvxUxDEcCkPBrScDPgBHxVg== 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=ug7J83PlBYKiDv89D72Y+xbTbyuEJxN0v9tsfrkv85M=; b=R9mS1j/punJDGK+ltdf4t4uSd8Ht7LSj+Gz+T68PZ4NiyPnbhaUdcM0uj7UKlExKBsXBCLviReHNsOrBeodvDHHkIBcqBfpL8z9vCW9F8eK5n7KGkP9Bfx7HHctghDx2eIV6HhEM67EXJ5lWHMHpTE/2iMEmgHG/VSOIMP0LkLWY/5ZOE4RfU3eHBGLpjq/vorVBjsiD/KgG6c11iWNO54Nu6y8Lzhwtpegh+S/AIiiqcug6N+7cQAqQF7KRrgJ9WUTJ84rr5MOjWTg0UleV7sq4NdUov/TwtludzfHgnglVFcU0E/9lHJN34Enp614C2y1oVBuUnvcwKr9Ih5AULQ== 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 SA1PR12MB6799.namprd12.prod.outlook.com (2603:10b6:806:25b::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Wed, 19 Jul 2023 05:42:38 +0000 Received: from BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::cd5e:7e33:c2c9:fb74]) by BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::cd5e:7e33:c2c9:fb74%7]) with mapi id 15.20.6588.031; Wed, 19 Jul 2023 05:42:37 +0000 References: <45fadf89-27ec-07a9-746a-e5d14aba62a3@arm.com> User-agent: mu4e 1.8.13; emacs 28.2 From: Alistair Popple To: "Tian, Kevin" Cc: Anshuman Khandual , "akpm@linux-foundation.org" , "ajd@linux.ibm.com" , "catalin.marinas@arm.com" , "fbarrat@linux.ibm.com" , "iommu@lists.linux.dev" , "jgg@ziepe.ca" , "jhubbard@nvidia.com" , "kvm@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , "linuxppc-dev@lists.ozlabs.org" , "mpe@ellerman.id.au" , "nicolinc@nvidia.com" , "npiggin@gmail.com" , "robin.murphy@arm.com" , "Christopherson,, Sean" , "will@kernel.org" , "x86@kernel.org" , "zhi.wang.linux@gmail.com" Subject: Re: [PATCH 0/4] Invalidate secondary IOMMU TLB on permission upgrade Date: Wed, 19 Jul 2023 15:42:29 +1000 In-reply-to: Message-ID: <87fs5klant.fsf@nvdebian.thelocal> Content-Type: text/plain X-ClientProxiedBy: SYAPR01CA0025.ausprd01.prod.outlook.com (2603:10c6:1:1::13) To BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR12MB3176:EE_|SA1PR12MB6799:EE_ X-MS-Office365-Filtering-Correlation-Id: 33c852e3-6403-4586-a24f-08db881af57f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HhmV8NXVyugUsGrmfRhG/2jZ7pW51lvCvLkSCl6PEXcUS0bN/sfqjo48Ug7fnI7drVWfXljKgCJOSoXjPokcBkW1Cxc4cUsSJFSTceoeOYI2PlQNLu0eapaAj4BVAx+LcnCRVu30z7kZ7kcKhuWNYUa5GHB098XD6jCLTtuyEy2hNTdS8gVuNl+3flE+zmX9JP1/9MHK741qbKMWMW1xn5XNp+jgIxfrvn+NN64oDPvIWNo3B2CFcgUTQ0xhV4tRt457TctZmOQSNtMZYK01/yMYRFU8n/gAb6YyE2Wsn7pjWcJo0Kw0G0Sttclp6UVAevxFPlvl1kIlk2sF9Giw6ESHxW0Ic5xpopO5FGdJ5V4E8m6Ss5m9Zx8IbV1+1zY97EUx1WJIH/uGT+NMYm3bjyU1EZrPxpE7RQVPDh8K5Buq7uDA1epn7KFgHeF1HWoQiMOHpi5hU0kxlKBhxUj2Za4xuhxmQ9QI8at9IkVewkjPwTOmVZI9Vliev4DT/kiSKV7KAgU2LvCsB/JbNygQyX7AICfrUewyWPlEm3m32G4ackEekJlMw/oRTfjEbx8uxTsHj/51jXJ7lDk4ptgcEgD0QlF8lytSY1YZbgwHs/k= 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:(13230028)(4636009)(346002)(396003)(39860400002)(376002)(136003)(366004)(451199021)(66899021)(2906002)(478600001)(54906003)(6486002)(6666004)(8676002)(7416002)(4326008)(6916009)(316002)(66556008)(66476007)(41300700001)(66946007)(8936002)(83380400001)(6512007)(38100700002)(966005)(9686003)(53546011)(86362001)(186003)(6506007)(26005)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?2K7KOLw2wkn2EMyyNlZF6F/psv425mVC0P6SfNBntUx4AC8UORfkLqEUbsxp?= =?us-ascii?Q?EQlvTBwNJl3xrODo8HFrrJ1skBI2md/6JLSpW84N2TGKh2CT5DHCs4ub6Pxk?= =?us-ascii?Q?zEF7kQh2k48zCNWwgu9a+GytmvEUIE2tkBJP0DvIc9mpgaMDNzJDgNCbJ5nz?= =?us-ascii?Q?CBK/u2Ti05F1D9jU86056uiQG43unwR+bh0CX+35NnZoZjvu1y3MvmI0Falb?= =?us-ascii?Q?QwAKl6s6eYhle6cL9XbXfMamcyqX4Z8j6QtLmrCP8zKM9CmeKBLWOXRQMDVJ?= =?us-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5N+3VvuoCMPvWzsKoHTsRl4IHPcub?= =?us-ascii?Q?suS7Fg3KoTa0m1kxOiWNWrZvCRdIECdK5VYK2URsN2BsuMpp1EckGuZUVS+F?= =?us-ascii?Q?+uCBl6E1Yy/rB6y1Tat6YsTS8ZmTpv5UBhW51CjOlUittmONXyURaLp/i1fr?= =?us-ascii?Q?SEC6w55i0tWI6rjL5qdQTRTtQ//BbAsqDD6+WgcK2B6BuKBTc/KTZV52m3Kk?= =?us-ascii?Q?inNv0V50P/atjyxJycD6nqC63M8o8j6V5Do9GIaoYpb3SrM71DiQeoUBbteX?= =?us-ascii?Q?RYJXc5dQJB1C2UCYku5IshT/bU5fmlk578Q5VGcbnh370G5oMX6ejaB638Z+?= =?us-ascii?Q?4JnjxYgla0uRavFJKZiMwtsEAeIGhNEPJqwLgm3Ti1x1fdmYwsBesC8oom86?= =?us-ascii?Q?L0XQULqEkVLwFUTilaxLi/gLntt4fzP2+MZ+NOU8?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 33c852e3-6403-4586-a24f-08db881af57f X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB3176.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jul 2023 05:42:37.4180 (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: HNHyaRd44k9t3QIra0ZYSb+NTE2zL14hxzps/zJ8kuaEZXfohPdr08fzJh8ggwUCwhqcfxGEpRFxGjD/k9VK5A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB6799 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_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 "Tian, Kevin" writes: >> From: Anshuman Khandual >> Sent: Wednesday, July 19, 2023 11:04 AM >> >> On 7/18/23 13:26, Alistair Popple wrote: >> > The main change is to move secondary TLB invalidation mmu notifier >> > callbacks into the architecture specific TLB flushing functions. This >> > makes secondary TLB invalidation mostly match CPU invalidation while >> > still allowing efficient range based invalidations based on the >> > existing TLB batching code. >> > >> > ========== >> > Background >> > ========== >> > >> > The arm64 architecture specifies TLB permission bits may be cached and >> > therefore the TLB must be invalidated during permission upgrades. For >> > the CPU this currently occurs in the architecture specific >> > ptep_set_access_flags() routine. >> > >> > Secondary TLBs such as implemented by the SMMU IOMMU match the CPU >> > architecture specification and may also cache permission bits and >> > require the same TLB invalidations. This may be achieved in one of two >> > ways. >> > >> > Some SMMU implementations implement broadcast TLB maintenance >> > (BTM). This snoops CPU TLB invalidates and will invalidate any >> > secondary TLB at the same time as the CPU. However implementations are >> > not required to implement BTM. >> >> So, the implementations with BTM do not even need a MMU notifier callback >> for secondary TLB invalidation purpose ? Perhaps mmu_notifier_register() >> could also be skipped for such cases i.e with ARM_SMMU_FEAT_BTM >> enabled ? >> A notifier callback is still required to send the PCIe ATC request to devices. As I understand it BTM means just that SMMU TLB maintenance isn't required. In other words SMMU with BTM will snoop CPU TLB invalidates to maintain the SMMU TLB but still won't generate ATC requests based on snooping. > Out of curiosity. How does BTM work with device tlb? Can SMMU translate > a TLB broadcast request (based on ASID) into a set of PCI ATS invalidation > requests (based on PCI requestor ID and PASID) in hardware? See above but I don't think so. > If software intervention is required then it might be the reason why mmu > notifier cannot be skipped. With BTM enabled it just means the notifier > callback can skip iotlb invalidation... Right. If you look at the implementation for arm_smmu_mm_arch_invalidate_secondary_tlbs() you can see arm_smmu_tlb_inv_range_asid() is only called if BTM is not supported to invalidate SMMU TLB vs. arm_smmu_atc_inv_domain() which is always called to send the invalidations down to the devices. >> Based on feedback from Jason [2] the proposed solution to the bug is >> to move the calls to mmu_notifier_arch_invalidate_secondary_tlbs() >> closer to the architecture specific TLB invalidation code. This >> ensures the secondary TLB won't miss invalidations, including the >> existing invalidation in the ARM64 code to deal with permission >> upgrade. > > ptep_set_access_flags() is the only problematic place where this issue > is being reported ? If yes, why dont fix that instead of moving these > into platform specific callbacks ? OR there are other problematic areas > I might be missing. See the previous feedback, and in particular this thread - https://lore.kernel.org/all/5d8e1f752051173d2d1b5c3e14b54eb3506ed3ef.1684892404.git-series.apopple@nvidia.com/. TLDR - I don't think there are any other problematic areas, but it's hard to reason about when TLB notifiers should be called when it all happens out of band and it's easy to miss. For example this bug would not have been possible had they been called from the TLB flushing code. Ideally I think most kernel code should call some generic TLB flushing function that could call this. However at the moment no intermediate functions exist - kernel calls the architecture specific implementations directly. Adding a layer of indirection seems like it would be a lot of churn with possible performance implications as well.