Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6022814rdb; Thu, 14 Dec 2023 06:28:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IF7U5SxaLUHBn92bBkqkEkkJ5TeaLTUxbHhI7fYqoALwuT7gmegqGB5cIaP5T/KhIi/qidZ X-Received: by 2002:a05:6358:2c93:b0:170:c41c:8107 with SMTP id l19-20020a0563582c9300b00170c41c8107mr10580429rwm.6.1702564113564; Thu, 14 Dec 2023 06:28:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702564113; cv=none; d=google.com; s=arc-20160816; b=u5ku+RPaArWnMyytwzkrKQdK2XlRJZ7wHG1V+gvS1neg+GlftLl0nj6dSEOxWQHjXU OCOky8D7ltLa8bRAQ+gEnsmKZ2E4BOsCGrOo4kPlmvfHcJwSnZEWFaILZaPw+3WsCQPI +WvSGFOAGL/7BSzBRY/JIrj6e/QXoKDCYb+Bt6/9d2WSAicUvYNoBW+jtV/OddpH27Ca TZpNrEWPtQUFXmXCBJjPntk1nHzAzOodbWJUQokOymNFPLilJKo2QCBmzrWIf97avakS yykTCIa9VrSdf1lpkZExOy4J85SpHATmmELVPvjfsvkV/lKwki+CuO3gZjYEOJMmWPCZ kIDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=ZoC5JW6feUSgX4MnpzRlkfih4BNQIs4OIA8CRGE9QLU=; fh=smhDU5qr0HXqs8IjA+DWGpfD9xmGgq/1UyxF8xpiaGA=; b=uuZEWf+nArjTRPOiSnm1HRspjltPl1+dwmnZKBrKD/R9te8o5b7kDB3BjrUPQUZmUG mYuCxV6wKTYTtu5t/qavMn5g4y6Tt8NADqwPp7KYOtdRhtxBJEHNMZQpHY5B0FpjNzLN Wd5gAFzxD3Com0QZ7PUgiM3UMGhQidAWO18uQpbAsthpVEBaNsqFSRta/ZElLYXVB2Bv DXHwQdnxMxwg1LkaFmc+aBYKhWmFaI/+n68ObKDjARXDFzlPy6TebmyrQ8hd1WK3Gq+1 tVFQQ1YE77j6VhedT1gX8Im2onjK6SN7oXPZ7F6gSRnY3GeyC6JuuQw4GeACrWjJ/U6L npTg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id e6-20020a654786000000b005c6650f66b5si11022449pgs.267.2023.12.14.06.28.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 06:28:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 0388D816F0BB; Thu, 14 Dec 2023 06:28:31 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573460AbjLNO2N (ORCPT + 99 others); Thu, 14 Dec 2023 09:28:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230237AbjLNO2M (ORCPT ); Thu, 14 Dec 2023 09:28:12 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6BDA29C for ; Thu, 14 Dec 2023 06:28:18 -0800 (PST) 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-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Thu, 14 Dec 2023 06:28:31 -0800 (PST) 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.