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 96107E77188 for ; Fri, 3 Jan 2025 09:35:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0EC6C6B0082; Fri, 3 Jan 2025 04:35:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0A5A26B0085; Fri, 3 Jan 2025 04:35:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E7DB66B0088; Fri, 3 Jan 2025 04:35:50 -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 C5BB66B0082 for ; Fri, 3 Jan 2025 04:35:50 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 719191206BA for ; Fri, 3 Jan 2025 09:35:50 +0000 (UTC) X-FDA: 82965633072.02.6139DB0 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf12.hostedemail.com (Postfix) with ESMTP id 0CFBD40015 for ; Fri, 3 Jan 2025 09:35:24 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=bDFPUteI; spf=pass (imf12.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.179 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=1735896925; 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=cWtjK5g4BM/SvEXkEBPomhMpQ0cOqD61cD7+kwN1xqo=; b=SRjRhwR3FYRiHELscCTjPSfU+IhQ1e8XzG9JFo1Nr5xRi6x0NDYRuy9LxYBL6L/8j0jYPl lAbI1EkvvDtQ//o7YXJiDPE5SVl8/AmW6+ZLhhNYEOrwjhUf+rK9UqnUCd+Z18L/bT6/kL 4JsRBfEqrrwTGS1Qmb1lKTYqwzcyHJM= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=bDFPUteI; spf=pass (imf12.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1735896925; a=rsa-sha256; cv=none; b=NeOMKzS2yVENrd1Y11qBig+H7AAPfyykyL9qeyliInsxGz8dQRZDdB/f1A1c0d0JRPTHFU IY6/vBJ7+hOL/Mwz1T9eiiD47/P+N1aeDaMeOm6q1JJ2c7NV52mvjP1QQSFDsDyuYyYAdE InSdjm8MbWcDaq9Zr7/xYgI6k3BgGfQ= Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2166022c5caso147469135ad.2 for ; Fri, 03 Jan 2025 01:35:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1735896946; x=1736501746; darn=kvack.org; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=cWtjK5g4BM/SvEXkEBPomhMpQ0cOqD61cD7+kwN1xqo=; b=bDFPUteI0g6DXXi6vyQk1jMbDM5pyhSMxpNR5zJXnNumHZK9yh6EcUtiLZi0U9nbRN aKqlvOYxlZFbH2WuVd4fqPCMf4PGdkjUYyzW/KT4LpmuQHQVnVsL7wLnkQZvcluMUnMc wqgET49vdS9O7ZOOLM7JWju53D7HaKc7XQSxVwgVQutAnfQGhicCrUln0pUBqosnGlvz PUtEdzncn/e3p440ZYxx2MDw0kkGRT7oQA3Lg2+9tNxYOqy+83kpQVZXPr4UCwtj4jcy C3gyPS8erLso+iJXOIx18hrGLCjU1JGhWr2ddJgees+jy4zpTlmgleMDrJHxpWnXD8ZB V5Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735896946; x=1736501746; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cWtjK5g4BM/SvEXkEBPomhMpQ0cOqD61cD7+kwN1xqo=; b=M9Eu6e08Y1VFO3cmnyPTX+zZ6UzUeXU7oHURR8T1v9qGWN+Tc3Fg+ZbdPx1X8ed3ln DaMOIGOBbcOSBLlqxC/G+anvCClRh/DWV4HffW2e2Uteo2oOobSMVS5OA17QgJeTaafa JVOGBuBJnetvXR3bdnKRVaTU0z0NhZeym22rxzlA8mtFDw46GV5fub9ab3n+25mEstYF b/B4RgJbXWIKSaCJBwUxulJMC6mmKRLwJ1OzaUM2TyM0vDSwj4KZj5QEXbsJZdZ667qw Grvmw5bE9mzN3uC2eOdttug9zXzJigSBIVFH/bO3O2ULluBi1QG8uiSiOc4ilmiEV1f1 /+Cw== X-Forwarded-Encrypted: i=1; AJvYcCVMQvTlOaj4su0uFaWOhCVY1srpJA5fOwl2yTorNBLw8o5VrqFdIeze2Ncjn/SaW3+UHZD5r/fAdw==@kvack.org X-Gm-Message-State: AOJu0YwKG9MAclipqQV8COdIFlLIijZVvhsZ9hXYPgfJLZoEk5PXUHoN UKicmQknnzl5ygDg9+ppAsfFD5d0zwW4FGk5dMJrbYPaPNxw6bZ46rdzCF4PHLg= X-Gm-Gg: ASbGncvTMh1OrVSfw94GCG97VXd9/9GKpt3Z6Lfj7dDYtBfu94gXVy/BZoB/0N3O2zd NXOsG+mULymGquEL1HYpbVIpj3DI6qWi6Cx7F02IFKldBGOGBb2q5F8gp+RK3GBBauo3uxBlpGn ozhm1/h3q/hVyoZY17vHIsp1GopnXVAf5ioxZKLA9BG7sh/B3w6u7Y9gtZna8QJ0pbrlzYQXeRq JorzbRXvEm/jmu2RT59p17qExzb1o5vbfcecy4TE1wdaYFDb6kMGLaScGeiD0IUpYdKC3kER6n8 +JcO+A== X-Google-Smtp-Source: AGHT+IE9O96BS3RyGLgD9ozZE9cvlEJyEf8vCWPZNZOt2fNtD1RyepOtwaueaYCtTF24hvZZQqYEyw== X-Received: by 2002:a17:902:d481:b0:215:6fcd:6cd1 with SMTP id d9443c01a7336-219e6e8c508mr551854195ad.7.1735896945927; Fri, 03 Jan 2025 01:35:45 -0800 (PST) Received: from [10.84.148.23] ([203.208.167.150]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc9cddf2sm241537305ad.166.2025.01.03.01.35.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Jan 2025 01:35:45 -0800 (PST) Message-ID: <31e1a033-00a7-4953-81e7-0caedd0227a9@bytedance.com> Date: Fri, 3 Jan 2025 17:35:30 +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 From: Qi Zheng To: Kevin Brodsky , peterz@infradead.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, akpm@linux-foundation.org, 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> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 0CFBD40015 X-Stat-Signature: px3au73rfn9d96gbxtzc3oujesya7ygk X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1735896924-668070 X-HE-Meta: U2FsdGVkX19aR2RFfnAPaBodiZ0kPssyOmLL70tLBKfQhc8R2lN7viprMZGYiqPnzF2qLUbDIR+qq8AORzQPzEBHkDnmUug1v7QYEXUbKpi3bJw8N5punX8jU5+LDu79UTV0dCXFqw7Hnwktz7L17BSDE43Fiz7jL4X/J/984qZj70wLjX8dxCO5du0fPbAFOhL2xdw9NqWEVZFGUmzDsEVUmiSs/Em3Hspu7I0L/eUis9spXwcFC7nwIWGbvsvUc9I/z7T9cTDtku+W/ABNd45Fwmm6nv6T3foGScsm4v2AZWQibPUr7SObYVX0QPzgcIGzIYaQngypFC7DWgYCtRujh+0AquOcGqpXtsFQf20kGkviP0XTd+1nMn9cA9fNfA4tfkxer9wVaPRoasbNUNayM1Qr1RCu6868+g4Z7tKNkXFFQfuYfzunjqVGjjbMydHITKxaH3KExYTaZ38rW9XOIDeOWaHGnrSQRdpXKszCRwK50x3uUKyt8054QEXveLfJFhn7H5cvrjBTQ0iw7TrvcHN3fV8F8LSbzAR1yChx6qBglg4TBir5+wCXPE9yP0moU58Bym603d9h4ebx31KDvRjtMqPw/l3pdU/lsuDD50IBAmsvVt+wUTDK4aB6yja9GndFD16qUeFDWmXgvEvJ/IpNpTL2sSZMWlkEhA4J3aLLzhufh635R1Du44GhDE/Rk6pZt4EozjjZRQtsFunXp7Mvk1twm04DWPPdfRFJs7oYSsw6B+YLJAPffP8WOLtyioFfBgmSTe4C7KKRYG6gJ+lT5xATFPxRhLjWKedqsvIYsPrb+OLS/GTS1TcVP60cuZQgfz78IKd92qCwzlLPYmJKeLZTkjQdp0x1XO9rs/2QePFk80Zin8nhpDDFJEv9zDt2XwuAT4R7bk51Uq+d5lARPv5yI1l/M85gS5eQoim87akxd14wMy77fM/i57drib9rajKO7u6LHWu kQzpGm+v Zhmzh1jXhgpzY55XuTvu1pRip7z9pW71tEubtvkWukibkzlYI1LO8G9VGaN4FtMwXuqGUvh4edlTcPjSwZ/NfdtGuSA2Iw2HcacEwNjEeZvUH6a1vvFsp7AY0iRAcz2AGrEgqsjNkhNAECsz0Qcep0PJc7Q23Nqw9QlMQvBMPOlBvATDWlrmP+W4IXLRbVoEAlXSak86JJ9YNl6orSghHpjKf1lqkSz6/s9TELAcH6TrmLyCn4jMSTnTSZBH5p38Ukn0M5f+iuyqFUYGoZyKjGE/jIHn/5p2+zsayYjxp3ycejbP2bdtOgRmBTJcZ2Z0o5n2KZCGu91s0rfPEvkKAVRFeFuPbM6IbqJ17zCp2MRacWhvkL4c02JA57BeOllhBLuXxau4D0M6ZHcfbR1Rsg6Cfl9BiNnn7gkbT30/wVIGbWDwVvL63j3kQDgGOnqfCTAVgKKOu7qhK4nAmB543NQ8M11R1LmM/vz5e 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 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: >>> Hi Kevin, >>> >>> On 2025/1/3 00:53, Kevin Brodsky wrote: >>>> On 30/12/2024 10:07, Qi Zheng wrote: >>>>>    static inline void riscv_tlb_remove_ptdesc(struct mmu_gather *tlb, >>>>> void *pt) >>>>>    { >>>>> -    if (riscv_use_sbi_for_rfence()) >>>>> +    if (riscv_use_sbi_for_rfence()) { >>>>>            tlb_remove_ptdesc(tlb, pt); >>>>> -    else >>>>> +    } else { >>>>> +        pagetable_dtor(pt); >>>>>            tlb_remove_page_ptdesc(tlb, pt); >>>> >>>> I find the imbalance pretty confusing: pagetable_dtor() is called >>>> explicitly before using tlb_remove_page() but not tlb_remove_ptdesc(). >>>> Doesn't that assume that CONFIG_MMU_GATHER_HAVE_TABLE_FREE is selected? >>>> Could we not call pagetable_dtor() from >>>> __tlb_batch_free_encoded_pages() >>>> to ensure that the dtor is always called just before freeing, and >>>> remove >>> >>> 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(). > >> >>> >>> But now I think maybe we can do this in tlb_remove_page_ptdesc(), like >>> this: >>> >>> diff --git a/arch/csky/include/asm/pgalloc.h >>> b/arch/csky/include/asm/pgalloc.h >>> index f1ce5b7b28f22..e45c7e91dcbf9 100644 >>> --- a/arch/csky/include/asm/pgalloc.h >>> +++ b/arch/csky/include/asm/pgalloc.h >>> @@ -63,7 +63,6 @@ static inline pgd_t *pgd_alloc(struct mm_struct *mm) >>> >>>   #define __pte_free_tlb(tlb, pte, address)              \ >>>   do {                                                   \ >>> -       pagetable_dtor(page_ptdesc(pte));               \ >>>          tlb_remove_page_ptdesc(tlb, page_ptdesc(pte));  \ >>>   } while (0) >>> >>> [...] >>> >>> diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h >>> index a96d4b440f3da..a59205863f431 100644 >>> --- a/include/asm-generic/tlb.h >>> +++ b/include/asm-generic/tlb.h >>> @@ -506,6 +506,7 @@ static inline void tlb_remove_ptdesc(struct >>> mmu_gather *tlb, void *pt) >>>   /* Like tlb_remove_ptdesc, but for page-like page directories. */ >>>   static inline void tlb_remove_page_ptdesc(struct mmu_gather *tlb, >>> struct ptdesc *pt) >>>   { >>> +       pagetable_dtor(pt); >>>          tlb_remove_page(tlb, ptdesc_page(pt)); >>>   } >> >> I think this is an interesting idea, it does make arch code easier to >> follow. OTOH it would have been more natural to me to call >> pagetable_dtor() from tlb_remove_page(). I can however see that this >> doesn't work, because tlb_remove_table() is defined as tlb_remove_page() >> if CONFIG_MMU_GATHER_HAVE_TABLE_FREE isn't selected. Which brings me >> back to my earlier question: in that case, aren't we missing a call to >> pagetable_dtor() when using tlb_remove_table() (or tlb_remove_ptdesc())? > > Thank you for pointing this out! > > Now, there are the following architectures selected > CONFIG_MMU_GATHER_RCU_TABLE_FREE: > > 1. arm: select MMU_GATHER_RCU_TABLE_FREE if SMP && ARM_LPAE > 2. arm64: select MMU_GATHER_RCU_TABLE_FREE > 3. powerpc: select MMU_GATHER_RCU_TABLE_FREE > 4. riscv: select MMU_GATHER_RCU_TABLE_FREE if SMP && MMU > 5. s390: select MMU_GATHER_RCU_TABLE_FREE > 6. sparc: select MMU_GATHER_RCU_TABLE_FREE if SMP > 7. x86: select MMU_GATHER_RCU_TABLE_FREE    if PARAVIRT > > If CONFIG_MMU_GATHER_TABLE_FREE is selected, an architecture is expected > to provide __tlb_remove_table(). This patch series modifies the > __tlb_remove_table() in arm, arm64, riscv, s390 and x86. Among them, > arm64 and s390 unconditionally select MMU_GATHER_RCU_TABLE_FREE, so we > only need to double-check arm, riscv and x86. > > For x86, it was called tlb_remove_page() in the non-PARAVIRT case, and I > added pagetable_dtor() for it explicitly (see patch #11), so this should > be no problem. > > For riscv, it will only call tlb_remove_ptdesc() in the case of > SMP && MMU, so this should be no problem. > > 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. > > So a more direct fix might be: > > diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h > index a59205863f431..0a131444a18ca 100644 > --- a/include/asm-generic/tlb.h > +++ b/include/asm-generic/tlb.h > @@ -500,6 +500,9 @@ static inline void tlb_remove_page(struct mmu_gather > *tlb, struct page *page) > >  static inline void tlb_remove_ptdesc(struct mmu_gather *tlb, void *pt) >  { > +#ifndef CONFIG_MMU_GATHER_TABLE_FREE > +       pagetable_dtor(pt); > +#endif >         tlb_remove_table(tlb, pt); >  } > > Or fix it directly in arm? Like the following: > > diff --git a/arch/arm/include/asm/tlb.h b/arch/arm/include/asm/tlb.h > index ea4fbe7b17f6f..cf5d0ca021440 100644 > --- a/arch/arm/include/asm/tlb.h > +++ b/arch/arm/include/asm/tlb.h > @@ -43,6 +43,9 @@ __pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte, > unsigned long addr) >         __tlb_adjust_range(tlb, addr - PAGE_SIZE, 2 * PAGE_SIZE); >  #endif > > +#ifndef CONFIG_MMU_GATHER_TABLE_FREE > +       pagetable_dtor(ptdesc); > +#endif >         tlb_remove_ptdesc(tlb, ptdesc); >  } 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)) - -#endif /* CONFIG_MMU_GATHER_TABLE_FREE */ - #ifdef CONFIG_MMU_GATHER_RCU_TABLE_FREE /* * This allows an architecture that does not use the linux page-tables for > > Thanks, > Qi > >> >> - Kevin