Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5937850rdb; Thu, 14 Dec 2023 04:13:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IGvPE+haOjqljwMlrntbPG+JoF0/SYSFo8+xC6PFmEmS4SKZ5jLEQOrlCIhLmvLuTPkW1wC X-Received: by 2002:a05:6870:c151:b0:203:18e9:804a with SMTP id g17-20020a056870c15100b0020318e9804amr4145663oad.86.1702556039079; Thu, 14 Dec 2023 04:13:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702556039; cv=none; d=google.com; s=arc-20160816; b=PyCWSc1OrYjVPIgQK1t6Tnlp2h4K5Jtdee5vciv8CrdU178k06ZkHD6E+qgS6j9Qw7 RBKuEzX2qKt9RV6Kr655OrY/hCOGVfcAtk90qzfLnooyU6dOjQuV1aQxYnkx0HOcLC0N I6UAGhU/gN+ONkMmvbgPwZOCQL8Xio6qFie9VQ1zk9PCZxNkX1oSj62npZmXBFlASlTZ DbcC6ocTxCkvOx3lLfa8NTi2PRUxoyYdoxveDoBJnZuxBhkr/TL42QGPuE89t11ktDyR 7vSIbh4T/Q017w7eg5C+CSeWdJmJ/KBaW4p89pGzBCNdzaue96+D1ceexrRZQPdYlo9/ 6yqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=wZcBJJ9hn8fPFYEAv3UJQ9N9We0suiVDp29IV4j0pG4=; fh=Pfo7+c3vagEZ5nrnHwp27/sUznIwE7zIph3vtj4WIW0=; b=g3Ek5pwR8N80HaRBccXJ38BIszH9KymN8LY/ardeis3nvZUQSmbCUUfT2jwCz+XCn1 Q+ZJvK10v9c0tyE5rxKYn/5wgiTR1fKHT1V4QBbkANX1WORp4oMCHPMKGKXGnAAg2ok8 wbORZKV3YRxFIB8F0IlZ2X8HJsF8f2IQTB/Kgq5DhAJJw7J69KwR7PIoOhZ1Tio7I8Ta t938uOduaW8vDMTVvX1LLawX4yipwPZJp+xd8J8uuGXtoysqYHfzgWK1u/L8/KYUf+KQ lwYqCg8RFe7wrMURGQ2vm/kHthUQt0vELK+yTWwHHpVo569DH7AiJMLQE6WhJwk0sly8 C7+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZIl4tQ4t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id m22-20020aa78a16000000b006ce63dbd7f4si11094966pfa.142.2023.12.14.04.13.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 04:13:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZIl4tQ4t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 4C2A6810FBCF; Thu, 14 Dec 2023 04:13:56 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1572950AbjLNMNl (ORCPT + 99 others); Thu, 14 Dec 2023 07:13:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1572930AbjLNMNk (ORCPT ); Thu, 14 Dec 2023 07:13:40 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5F08115 for ; Thu, 14 Dec 2023 04:13:45 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E84BC433C7; Thu, 14 Dec 2023 12:13:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702556025; bh=zGI9MKm0R/y1myqJM3IMh1whT+Jpo0eTry8ctu4P1bE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ZIl4tQ4tSkoE1FaBtknKS70y7rg0PHYdhs8pC5K0km1raen4r8b8buSTrlB/cQeS5 V88CmYspZi4PyQ7fUpZk1k02eq8RZ9Lazj9PQ6GQB3OMdzr5/BWdRoXx4mzwa0Nw2u HJLI2chg1HTUpTbbQZNm66O6fqhzGQh4eyeyhZOcU4pbElBM+hwMZXajVWJZzfOZw5 d8CnikTugVZdXY0UacDQpykecqCZLVHnxOHxyijCDVCzf6o1ioEjtNo/dpj4d3HJbC 2AeWA7gxst5ON/uHCIS780fqlq6nWAjEExI5RDXm5i/5JQHQfDRf8q9o2JqlWZFm0i oVkGVEehtCQRQ== Date: Thu, 14 Dec 2023 12:13:36 +0000 From: Will Deacon To: Ryan Roberts , robin.murphy@arm.com, 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 Subject: Re: [PATCH v3 12/15] arm64/mm: Split __flush_tlb_range() to elide trailing DSB Message-ID: <20231214121336.GA1015@willie-the-truck> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2e6f06d3-6c8e-4b44-b6f2-e55bd5be83d6@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 fry.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 (fry.vger.email [0.0.0.0]); Thu, 14 Dec 2023 04:13:56 -0800 (PST) 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. 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. Will