From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5628A154C0C for ; Mon, 6 Jan 2025 03:49:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736135402; cv=none; b=NGZQ8fdSk/oA0/0C5AdKa9HiVv6xYkGysLq3H+JnFAZDRCv+zOfwuXJsIG4wt+qiqEPaC85bVLKyQhCJ3OGsNItWo464mopQr3sxg5utmAvOXt3Cweiq7DmUN2QTbCglpL1wpyYOcGJQM8FkxlbwSD3lCxjGSX1kcrIGwSAA+DU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736135402; c=relaxed/simple; bh=4dk7AAJmezfFi3ZfUWBsyuZRMbx4LQ4Y67CoiCMSr1k=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=q2qWtB7LLQ8khbmYbeqvcVBy9Q3IeN2CEw1/m9bA87q9NIUSGNX8ycLVDiKox8dtHOhvWmKj/L8MqatjYJsBcDEQ290KK4SZsYFMWcrCH6Gc60zJVXMt8+PSaslGJxcv4XV2EDJ5S0O3M466EArKXkplzCFJnZ5KXgquJWw47RQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=Ew721MlX; arc=none smtp.client-ip=209.85.216.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="Ew721MlX" Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-2ee51f8c47dso15664371a91.1 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=lists.linux-m68k.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=Ew721MlX/ce274i+4rfBm0YLv4+qan6iuzvu/qlquonGmfDtapuccJUloU3k/x2fkm bhTz01iYkzYzqZ5+yBuC4P1ulVAk00jMg1Lr6yqSV35ok3J886HGmHXfLWKDM4f7vJo3 aTGm32Zlhk4PTTcfmDoJSjqNodIvRW2AXGcCVkUm4DdH5xmXrus/QGRNK9Bt0x3jlS7p uy17bWi7nL3TJyOCbjyHfVAD2+Uwf/DaldMJmbU+yy9Bg6KzOLVICHqSjvkKyeBj9u0s El11jLik2vKd5hYIJgJkSAX8EX9t/vbqVhQameCyg+8/CZWjxxtwDeDqPpqDlqXHJZ4a jLRA== 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=JxxKUo4jd32DTlV+O0b0CL3dZo2PBTUCqMtaXaDqRD10py/me6VrLRPpuoBoTiGo4I beEWxKUyloaZX/qN5ukxlb2HoNBAS6DziE66lcclsXoE/HP5ArqdoQntSC6UNek4qfth AgRIrNpy6LbVt0IQQ4j1Rn9qckQ2n68TIGb01tPaF+Nuf3HWOafjTMSL75bpzrVIAoLO ox40hV3XKLQQe9NhWwm2T0noeMyEk3YW9MlRg/dKEiwRF1+UmbQE1FVYYu7JE6pJMcK+ 8888rdznOhj72wV0249T0gUoQb6yG+ZteEoj+qZDmC6oFSqJFPwZ/qhrYTwZQIcnIt9I mxkA== X-Forwarded-Encrypted: i=1; AJvYcCXzz8JfyD8tUIu9K3ZWeSp9C9XnJ0+IRMyIgLXS5Sj6uQHyr11Nsq3vk2rg4jMr+Pg2im/vcanRyUpx@lists.linux-m68k.org X-Gm-Message-State: AOJu0YzmnzUfQ4YOIPZCQwO9Ah3G/oNGQ9JV0olGav1GoyAXoojZkMH7 7E5lVDQdx/Q6HZ6d78TJy1LXT8AqjuGFlDU4c3N/flYkgghOaSHr39IH5KTeV7A= X-Gm-Gg: ASbGnctLDZOdz9/0jCBWa9uyKHuLOAaOgW4CcEY0o/9/QUK8meW1KGSHp9VCPdgDx47 BwqdXncxrJCU6PV7z0GWK7pGZotHX9ld6WcX/ZPij26IJX5tBjmwQW/t9iOpApj/mP8e3B81CSX L3ECHzYg5SEsaQnk/rkRttm1RantPICPhc+7RNRSq+LnpHWpZQlPJcHz3qrsQW4DuM3xXOEJPrs jRH5dZE6jSe8vXd7r6Q8lRpswNti7UcI8Va2UJ1aZ1ZwbASm9odBlJBubTwBMw0dWJUD46Z+L3A ZLucnA== 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 Precedence: bulk X-Mailing-List: linux-m68k@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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