From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E1CBC4167B for ; Thu, 14 Dec 2023 14:28:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A7F218D00C4; Thu, 14 Dec 2023 09:28:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B7F98D00B1; Thu, 14 Dec 2023 09:28:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 76F378D00C4; Thu, 14 Dec 2023 09:28:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 5554C8D00B1 for ; Thu, 14 Dec 2023 09:28:22 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2261780CBD for ; Thu, 14 Dec 2023 14:28:22 +0000 (UTC) X-FDA: 81565654044.16.FAAF600 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf27.hostedemail.com (Postfix) with ESMTP id 3D5514000D for ; Thu, 14 Dec 2023 14:28:19 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf27.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702564099; a=rsa-sha256; cv=none; b=P18O8GCRgy258xVtAzgmakZL92uJO+AenqVQJ0UXeP91zhP0XoJfD6GSmhvM0kJwX3Nnxf CM5tXg9tR5BtQqzzj2BRjqOtlJd6hxAAx1H3RxskJNaZVAEIASSr29C3rJDPOmBWi3P6Ew ef/1LBOm8+kx3o8hZterHoP/Qt1NmfE= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf27.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702564099; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZoC5JW6feUSgX4MnpzRlkfih4BNQIs4OIA8CRGE9QLU=; b=pFJMfg7Ib7HADVIwa3IrhMcGjjR8jTpt+d70XgzVYvuHS+pxZY0elax3kc+6tw9AqP9cot Wr4KwCdMtpKu5xzY6eUa9B4BIIOMZWLXDJIyiy7Z39uiUEoNEiSrGjQpPfm+d+uLOd02iQ eGlruAQxDyy2FWCXkMr9NTEKpL2Ml9M= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A84EAC15; Thu, 14 Dec 2023 06:29:03 -0800 (PST) Received: from [10.1.38.142] (XHFQ2J9959.cambridge.arm.com [10.1.38.142]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9BB3B3F5A1; Thu, 14 Dec 2023 06:28:14 -0800 (PST) Message-ID: <123a58b0-2ea6-4da3-9719-98ca55c8095e@arm.com> Date: Thu, 14 Dec 2023 14:28:13 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 12/15] arm64/mm: Split __flush_tlb_range() to elide trailing DSB Content-Language: en-GB To: Robin Murphy , Will Deacon , jean-philippe@linaro.org Cc: Catalin Marinas , Ard Biesheuvel , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , Andrew Morton , Anshuman Khandual , Matthew Wilcox , Yu Zhao , Mark Rutland , David Hildenbrand , Kefeng Wang , John Hubbard , Zi Yan , Barry Song <21cnbao@gmail.com>, Alistair Popple , Yang Shi , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20231204105440.61448-1-ryan.roberts@arm.com> <20231204105440.61448-13-ryan.roberts@arm.com> <20231212113517.GA28857@willie-the-truck> <0969c413-bf40-4c46-9f1e-a92101ff2d2e@arm.com> <2e6f06d3-6c8e-4b44-b6f2-e55bd5be83d6@arm.com> <20231214121336.GA1015@willie-the-truck> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 3D5514000D X-Stat-Signature: u56upzstdxcc7mxyk1ejqb9im3md1ssx X-Rspam-User: X-HE-Tag: 1702564099-704983 X-HE-Meta: U2FsdGVkX1+SZxZGsgn3GcMan4RBtk9EvLKjgLhtV8fOd0ybv7MOuCPX0FwHOx57j++jTIk4Yg8LKgUN8wadTwtpb3gKjVq8KX0+PMZmzkTH59LcE58UIWF2ncAQB3t4zqi/dHF3iILY4oZT23BkAySPV4aJisEqoinnuE4xGpvUaLm2Hx+DhgxRJ1Miy0RpGeMCvMxufsQncqfL8/WnEac8LxezzbB2YrQmCWTlEmFuqcn1ToJeLAPkXyQ88CefgSMektGF68V3wcTxPRSVn/Vm2IqCUCwbJ0fLRmoT04qeouo5FjfNoxwAiP/gnefIB2sWo7EjPQ7xZqLPwlSTtiFkQB5UsOuey1/xe2hY1jqIVrFRMJ1irLYtih+P6BTCmanBY5YjeMc43jy0GXgNBcbjDlEbSxW7CyFpfJ19ghz/Qx2w/aYGkqwix7ZxpRYGsvZ3/DGJTLn45V08i6F7o+UJZymku5ayU2MYDTsRV0JfVqOgl+BP2M7MpqY6HChn1UZXqO3GRWiVDV1ICna/w7S1NMjnBoxMSv8oA9+XICqoTaSvqD88ejKTWlOz1yhqJz5fkaC4j1Az3Wh4oE/QX3Uo9vDtFaVbn5qPDQXj/ksx+Tzk6Xa7V866DyI2M82WoPJ2V9doITe8QW7GwX4XHMVYcSYzs/pwSlMvvIwuaZQxa+H5vBypBj9iVPUhwLpSXzeMqZ8MeYmL1jQ437tO7z0TkA4go2MiPedHCQOYpGs7HKun6U0lGVcko+3WYZ3Vg3Ugcpw2R1ypx5Ndzd9gPJGIMeRiiNDNWcHv/eyP3eFpYD1lpyJMPg/BWRtQ6sPTbYx2bFUWqiQ+cOk8iR/FeSHgRRoqmBc8YNg5Vv7i15BqAT6IqtqYTxZ1LNFb3x8MOHpBVRxbOzzN/mkx0eXmagWEiozNOAoY5TwCACAAlDRAtJFkDFXxG/1W+GJGKrOY9mx/lo0HMYicBCaHkLk kQFY2TQE ITNMt6N4Zi9lgXOAZmVFEi567f1sxeHDs2zoDWOiSwswN0sCYc6pZq7/i0TDoRZqIWhqet2ExH2I5zYt37cs0eKp8JqM2U80XCU4DwvbGYuK/Degkdyzhsr18NDQ1t5qCqD8cfCS59jC9lFapill8ZSGYI/YqTtphHMMFjc9mqvaOhXkbrHdbsyuFNUrZfHfOGKZXwxhjgBdbKHKhCwbva8zc1Ag1QpJc+jQSwClyR/mBW4xVdsGIbFTReF44LXSmmnOelOsVRm2BW6g= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 14/12/2023 12:30, Robin Murphy wrote: > On 2023-12-14 12:13 pm, Will Deacon wrote: >> On Thu, Dec 14, 2023 at 11:53:52AM +0000, Ryan Roberts wrote: >>> On 12/12/2023 11:47, Ryan Roberts wrote: >>>> On 12/12/2023 11:35, Will Deacon wrote: >>>>> On Mon, Dec 04, 2023 at 10:54:37AM +0000, Ryan Roberts wrote: >>>>>> diff --git a/arch/arm64/include/asm/tlbflush.h >>>>>> b/arch/arm64/include/asm/tlbflush.h >>>>>> index bb2c2833a987..925ef3bdf9ed 100644 >>>>>> --- a/arch/arm64/include/asm/tlbflush.h >>>>>> +++ b/arch/arm64/include/asm/tlbflush.h >>>>>> @@ -399,7 +399,7 @@ do {                                    \ >>>>>>   #define __flush_s2_tlb_range_op(op, start, pages, stride, tlb_level) \ >>>>>>       __flush_tlb_range_op(op, start, pages, stride, 0, tlb_level, false) >>>>>>   -static inline void __flush_tlb_range(struct vm_area_struct *vma, >>>>>> +static inline void __flush_tlb_range_nosync(struct vm_area_struct *vma, >>>>>>                        unsigned long start, unsigned long end, >>>>>>                        unsigned long stride, bool last_level, >>>>>>                        int tlb_level) >>>>>> @@ -431,10 +431,19 @@ static inline void __flush_tlb_range(struct >>>>>> vm_area_struct *vma, >>>>>>       else >>>>>>           __flush_tlb_range_op(vae1is, start, pages, stride, asid, >>>>>> tlb_level, true); >>>>>>   -    dsb(ish); >>>>>>       mmu_notifier_arch_invalidate_secondary_tlbs(vma->vm_mm, start, end); >>>>>>   } >>>>>>   +static inline void __flush_tlb_range(struct vm_area_struct *vma, >>>>>> +                     unsigned long start, unsigned long end, >>>>>> +                     unsigned long stride, bool last_level, >>>>>> +                     int tlb_level) >>>>>> +{ >>>>>> +    __flush_tlb_range_nosync(vma, start, end, stride, >>>>>> +                 last_level, tlb_level); >>>>>> +    dsb(ish); >>>>>> +} >>>>> >>>>> Hmm, are you sure it's safe to defer the DSB until after the secondary TLB >>>>> invalidation? It will have a subtle effect on e.g. an SMMU participating >>>>> in broadcast TLB maintenance, because now the ATC will be invalidated >>>>> before completion of the TLB invalidation and it's not obviously safe to me. >>>> >>>> I'll be honest; I don't know that it's safe. The notifier calls turned up >>>> during >>>> a rebase and I stared at it for a while, before eventually concluding that I >>>> should just follow the existing pattern in __flush_tlb_page_nosync(): That one >>>> calls the mmu notifier without the dsb, then flush_tlb_page() does the dsb >>>> after. So I assumed it was safe. >>>> >>>> If you think it's not safe, I guess there is a bug to fix in >>>> __flush_tlb_page_nosync()? >>> >>> Did you have an opinion on this? I'm just putting together a v4 of this series, >>> and I'll remove this optimization if you think it's unsound. But in that case, I >>> guess we have an existing bug to fix too? >> >> Sorry, Ryan, I've not had a chance to look into it in more detail. But as >> you rightly point out, you're not introducing the issue (assuming it is >> one), so I don't think it needs to hold you up. Your code just makes the >> thing more "obvious" to me. OK thanks. I'll leave my code as is for now then - that makes it easier to do A/B performance comparison with the existing code. And I can change it if/when mainline changes (presumably to add the dsb between the tlbi and the mmu notifier callback). >> >> Robin, Jean-Philippe -- do we need to make sure that the SMMU has completed >> its TLB invalidation before issuing an ATC invalidate? My half-baked worry >> is whether or not an ATS request could refill the ATC before the TLBI >> has completed, therefore rendering the ATC invalidation useless. > > I would agree, and the spec for CMD_ATC_INV does call out a > TLBI->sync->ATCI->sync sequence. At the moment the SVA notifier is issuing its > own command-based TLBIs anyway so the necessary sync is implicit there, but if > and when we get BTM support wired up properly it would be nice not to have to > bodge in an additional sync/DSB. > > Cheers, > Robin.