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 20F58E77188 for ; Mon, 6 Jan 2025 03:50:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A6FBF6B0082; Sun, 5 Jan 2025 22:50:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A1FCF6B0088; Sun, 5 Jan 2025 22:50:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C0166B0089; Sun, 5 Jan 2025 22:50:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6934C6B0082 for ; Sun, 5 Jan 2025 22:50:03 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A5AAC1A1318 for ; Mon, 6 Jan 2025 03:50:02 +0000 (UTC) X-FDA: 82975648644.11.82B6D86 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by imf10.hostedemail.com (Postfix) with ESMTP id 1B337C0002 for ; Mon, 6 Jan 2025 03:49:59 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Vl7WrzPo; spf=pass (imf10.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.216.54 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736135400; 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:dkim-signature; bh=M/CQCfwbCGmNbncAnjTVlLDBhrllfolDtdV4jFWfmgY=; b=sidJSvQajESm3b7OUP1SHt8QOWCXMEqiNpjvJadGHAGUYP/26DIRduh/axdfZsWd7B83hE jpbrbOyxNKg/SprL2DkRWN4bCe+X22YA6dqV6DNJm3OTkyf0PLOdXgH1gzObZ3dEkx/Ays IUEcDFH0XkXZvG2Sdi6YZw3o6teYpFY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736135400; a=rsa-sha256; cv=none; b=lsE2Gm+4SnmgoT+7Da+PLrdM2QYKD0EqWIglNrQfHvk0eW68TPcgxRIjKehfhz+A/nzSQx wvJVYCipAmpN/+SlsOI3lh/DolLrYhMc8lF/0gFjUdXHfGmOdv5EN/bDbnhZ3y7Cqq4D+J hR5wFiYp1ztk+9VKyjE2tiQJihWpok0= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Vl7WrzPo; spf=pass (imf10.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.216.54 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-2efded08c79so15670635a91.0 for ; Sun, 05 Jan 2025 19:49:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1736135398; x=1736740198; darn=kvack.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=M/CQCfwbCGmNbncAnjTVlLDBhrllfolDtdV4jFWfmgY=; b=Vl7WrzPoHfcFtcmVthYfeVrzmhwCyOLJn0Eh2wfpvgbx0x9xqRD2v2Ifu3La+aAb9W knla1SK7mpe1hVTbwpZfKXa1Ju8NdrO1ZdUv2feUUqRvsQbFbfa/aCyjTTVZcy5smeFM 4jcXju5PAe6OVo080+TOR+VYYKsF5tAhy/3P18NKnXBx7uEnH005Zz5Dk2cAxFvTAL0K n3JKPtvoPl34dh+M+eV+iqHwY4ZwT6Vm+EVJyZRaK1y35wBT4e8NXrtZfDW3+67Zlm32 4igtBmpz/RlFzL86q7fOtQ0lkZumRobNz13LUAoWSDYDnuOy6/HqjJRbe0o6Yjyt/Xb4 hBUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736135398; x=1736740198; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=M/CQCfwbCGmNbncAnjTVlLDBhrllfolDtdV4jFWfmgY=; b=fTzdUnAovDpLXEx7sRJN6esGcfYnnSnv+rtoGqbhFarJ/0wZjqix34DKOnU4GYtDlh rciDofWgM4cIJOHlY4MQq1yvQvIiz4FPHbLrGyjTDYe6XGvZuUwYMaOI4yBtbeX9sQdA kyBLU1gaHRhQfEuqBNU6uC3Gcpq04P5T6V+PQLtYdrhqgVKbf3g3OtUmw8rZ/EFUot1d t4tMdKzjc5ylQ3wruyeLzaS4Lx7YcZwlTrFE+KbDlCjcnQWMB3j7w/r7Ya+MQY2MMTlb WjY93DXW5DbQc4zy82+JYgerBeMFDmBUnIF28cN6p1xOXbspRgCm1JvHGDawzSc4IiXz OeNA== X-Forwarded-Encrypted: i=1; AJvYcCWaFTWTmc9MHx2Kvu7Lf9fyl80FakKtzhRGL1WL2ZhR2T3elm65zh24y8cS6m9sfry3rsA3WlRybg==@kvack.org X-Gm-Message-State: AOJu0YxEuegx6DISb6N2LwgiFeQGIOBI6LjZJ1PMXvMuRrhQ844kxToZ wboPyWhg/WKAObU6ugXg5OMdiCoCrvSTAk3IX9AMxkZTYvgQ9986LQcd2rKdnGY= X-Gm-Gg: ASbGncux+ykeJ2BVcFAMB1vRl4IpXNLj32o/6XNmUplpoZoh613y/HXWmNERfzR/djX LWLpFZJR8rAUgu9KSjMDBmGWOYNxfP2X66p728JDFeLtjiGzLGqEGJQ98Qrv4Q9JtAukflviNQH kKrUuX6jFQVpiD/1sQcAqTT+Tmns8MIG8xJY9v5Xe46FY0qCZuPuUwZPNv69LWbajFrekmyIaox plYPdSZBs56EmyixKC+e3QfdgiHweEEaIFkATWo4mu0E5l+vNSzsAjgjpBLVOKbrMqwuotN2Cny +G5ilA== X-Google-Smtp-Source: AGHT+IHpHJsHb9mpdlPf1WMyDHeUmOQ71xKKXnSQB+gdiLoxCAO6i7uhLAJzOXuDIN6Nxvn4zgv7zA== X-Received: by 2002:a17:90b:53c8:b0:2ee:c2df:5d30 with SMTP id 98e67ed59e1d1-2f452eb11e2mr54849162a91.26.1736135398510; Sun, 05 Jan 2025 19:49:58 -0800 (PST) Received: from [10.84.148.23] ([203.208.167.150]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f447799048sm32821110a91.10.2025.01.05.19.49.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 05 Jan 2025 19:49:58 -0800 (PST) Message-ID: Date: Mon, 6 Jan 2025 11:49:41 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 10/15] riscv: pgtable: move pagetable_dtor() to __tlb_remove_table() Content-Language: en-US To: Kevin Brodsky , peterz@infradead.org, akpm@linux-foundation.org Cc: agordeev@linux.ibm.com, palmer@dabbelt.com, tglx@linutronix.de, david@redhat.com, jannh@google.com, hughd@google.com, yuzhao@google.com, willy@infradead.org, muchun.song@linux.dev, vbabka@kernel.org, lorenzo.stoakes@oracle.com, rientjes@google.com, vishal.moola@gmail.com, arnd@arndb.de, will@kernel.org, aneesh.kumar@kernel.org, npiggin@gmail.com, dave.hansen@linux.intel.com, rppt@kernel.org, ryan.roberts@arm.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, linux-arch@vger.kernel.org, linux-csky@vger.kernel.org, linux-hexagon@vger.kernel.org, loongarch@lists.linux.dev, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-openrisc@vger.kernel.org, linux-sh@vger.kernel.org, linux-um@lists.infradead.org References: <0e8f0b3835c15e99145e0006ac1020ae45a2b166.1735549103.git.zhengqi.arch@bytedance.com> <1b09335c-f0b6-4ccb-9800-5fb22f7e8083@arm.com> <7e2c26c8-f5df-4833-a93f-3409b00b58fd@arm.com> <31e1a033-00a7-4953-81e7-0caedd0227a9@bytedance.com> From: Qi Zheng In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 1B337C0002 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: dc3cr7a5xhjdpm8k6nsdo6mmftisnj7q X-HE-Tag: 1736135399-382117 X-HE-Meta: U2FsdGVkX19pR/jKdZ4caieVr0y1fZGxuouXqJrWs0kceUqplij/upbscCHMm4FsHf7z+aews//y4YCvBjgxC6nKz4TDCWQpqZoaKI3ubMfSqbfJ8UDaGqLs1Y5NmbaTmvLZsU239QYddR0JyYNSiT8WvS0s7Zx7vyTPI5fltQE/ICYhYssFVtqdjNs6rG8RFWx8NGV68akiAaabybiOerb2+Yu5FZknU9jphqYGkLqev+XSVHinN+Z9yBAuZTS3B84rmjfhZURQ8RJsxBe5wEkyLvbnQi5CqHmhL9aRzcoaguQn+rus9W6HLoB2brIUxYF+RlOvJ665Q8oU+etOo0Lo6QGdLb1ZuEZlV2tyS2fCLKHazv1kx3++Gtzz0JRhFzTcu+PeU3dFJLVrGfWug+krKbYvRmDIGd006AZ5TKIHK/eU/JBUVQ1zeB5NFt1tdA+vmlIqluoURZguYVwl1ZsjutyGK/aW1W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i0Pz5D9/YUJ3F+uv2zvyFUT3+pGmL0vJVyZ4nuyLn3jaexTu9XGP+dlCXaF3hij7cg== 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: Hi Kevin, On 2025/1/3 21:27, Kevin Brodsky wrote: > On 03/01/2025 10:35, Qi Zheng wrote: >> On 2025/1/3 17:13, Qi Zheng wrote: >>> On 2025/1/3 16:02, Kevin Brodsky wrote: >>>> On 03/01/2025 04:48, Qi Zheng wrote: >>>>> [...] >>>>> >>>>> In __tlb_batch_free_encoded_pages(), we can indeed detect PageTable() >>>>> and call pagetable_dtor() to dtor the page table pages. >>>>> But __tlb_batch_free_encoded_pages() is also used to free normal pages >>>>> (not page table pages), so I don't want to add overhead there. >>>> >>>> Interesting, can a tlb batch refer to pages than are not PTPs then? >>> >>> Yes, you can see the caller of __tlb_remove_folio_pages() or >>> tlb_remove_page_size(). > > I had a brief look but clearly not a good enough one! I hadn't realised > that "table" in tlb_remove_table() means PTP, while "page" in > tlb_remove_page() can mean any page, and it's making more sense now. > > [...] > >>> >>> For arm, the call to pagetable_dtor() is indeed missed in the >>> non-MMU_GATHER_RCU_TABLE_FREE case. This needs to be fixed. But we >>> can't fix this by adding pagetable_dtor() to tlb_remove_table(), >>> because some architectures call tlb_remove_table() but don't support >>> page table statistics, like sparc. > > When I investigated this for my own series, I found that the only case > where ctor/dtor are not called for page-sized page tables is 32-bit > sparc (see table at the end of [1]). However only 64-bit sparc makes use > of tlb_remove_table() (at PTE level, where ctor/dtor are already called). Thanks for providing this information. > > So really calling pagetable_dtor() from tlb_remove_table() in the > non-MMU_GATHER_TABLE_FREE case seems to be the obvious thing to do. Right. Currently, only powerpc, sparc and x86 will directly call tlb_remove_table(), and all of them are in the MMU_GATHER_TABLE_FREE case. Therefore, I think the modification you mentioned below is feasible. In summary, currently only arm calls tlb_remove_table() in the non-MMU_GATHER_RCU_TABLE_FREE case. So I think we can add this fix directly to patch #8. If I haven't missed anything, I'll send an updated patch #8. > > Once this is done, we should be able to replace all those confusing > calls to tlb_remove_page() on PTPs with tlb_remove_table() and remove > the explicit call to pagetable_dtor(). AIUI this is essentially what > Peter suggested on v3 [2]. Since this patch series is mainly for bug fix, I think that these things can be done in separate patch series later. > > [1] > https://lore.kernel.org/linux-mm/20241219164425.2277022-1-kevin.brodsky@arm.com/ > [2] > https://lore.kernel.org/linux-mm/20250103111457.GC22934@noisy.programming.kicks-ass.net/ > > [...] > >> Or can we just not let tlb_remove_table() fall back to >> tlb_remove_page()? Like the following: >> >> diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h >> index a59205863f431..354ffaa4bd120 100644 >> --- a/include/asm-generic/tlb.h >> +++ b/include/asm-generic/tlb.h >> @@ -195,8 +195,6 @@ >>   *  various ptep_get_and_clear() functions. >>   */ >> >> -#ifdef CONFIG_MMU_GATHER_TABLE_FREE >> - >>  struct mmu_table_batch { >>  #ifdef CONFIG_MMU_GATHER_RCU_TABLE_FREE >>         struct rcu_head         rcu; >> @@ -219,16 +217,6 @@ static inline void __tlb_remove_table(void *table) >> >>  extern void tlb_remove_table(struct mmu_gather *tlb, void *table); >> >> -#else /* !CONFIG_MMU_GATHER_HAVE_TABLE_FREE */ >> - >> -/* >> - * Without MMU_GATHER_TABLE_FREE the architecture is assumed to have >> page based >> - * page directories and we can use the normal page batching to free >> them. >> - */ >> -#define tlb_remove_table(tlb, page) tlb_remove_page((tlb), (page)) > > We still need a different implementation of tlb_remove_table() in this > case. We could define it inline here: > > static inline void tlb_remove_table(struct mmu_gather *tlb, void *table) > { >     struct page *page = table; > >     pagetable_dtor(page_ptdesc(page)); >     tlb_remove_page(page); > } Right. As I said above, will add this to the updated patch #8. Thanks! > > - Kevin