From patchwork Thu Jan 23 13:26:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13948273 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F1420C0218C for ; Thu, 23 Jan 2025 13:28:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/BW94Cjo7yQ9dYoINH40Tw4gGAuqwMUCjBuZYIrewFA=; b=JqRt0fmlZCgMAL izE2gK2Nv7aO4MjgjUg2dALOYoeHnqBy94ENJdkYFrASTeyfaYCbi+Yxa/F/7j7Ki145SjuyFL0dI aBf0wBV2N1b+Qsz5DNj/UoJxQWuSfMPzEKuL9Dcve7OmzsbMkOATUEo1U6aYBlYkEGjlNI0uyEN08 fLLhMt/p554y3sfiLcNSQeHotPzWkt8DqEkWEbxZ5vl2JkdQzWbRcU1MNGhS7M8qZIZCdiRSQTeC7 y+CfwWpsDdz3a4o8oCNgUJKKrdcH1j4ZPb2JQCtUt0/Ec6AOi3Rmmighcn9UJQodl2zPYgAYuX0ix CcpyvXUaXEtDGja7aqsg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1taxG4-0000000CWCV-2v9B; Thu, 23 Jan 2025 13:28:32 +0000 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1taxG1-0000000CW8v-1UjA for linux-riscv@lists.infradead.org; Thu, 23 Jan 2025 13:28:31 +0000 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-219f8263ae0so16873265ad.0 for ; Thu, 23 Jan 2025 05:28:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1737638908; x=1738243708; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nDJpscd5iDH1/vb94JK69W34zwsdKCnkCWvmFoEl4dc=; b=A/13PZBj2WHITRvuauA8jSoIPtgDDqFZk+zBbtdCUczz+8TNOrLmYjTZG/wDhpWgin awOIrdOMQcBbrDyKZIOZ9dxD0oovzcVz9NTuhm88pzmM4SOgqDPRHiFcKFtnwhhgNNhl HKNbKU06EsftycgMe3ju/vyxA2h8V0MSqpbaB7q/uQ98MSab8ls9YqHnds0iR5/dJrGk LbmouQps64ameYQFmiI6if/SE4mP9zEMlJwczXypzBE0SqqrVSyHgOzoPLl7G00fgges g1TNQ0VVL8wa4T4PIm36iL4SIYXK5MxY6rVS4c7jl2BWCcpzly6Iz/OyQO8N76w8NM6Q gBPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737638908; x=1738243708; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nDJpscd5iDH1/vb94JK69W34zwsdKCnkCWvmFoEl4dc=; b=eIRNSHR9SMqbDKwyDKIuXAPJLlKpLYJDZZ64rUPpS2u0asl1XS6RRjvkVvmlPrvAyW dz/yLCqO7Go73NYTj2Uujf1X5a2251sXEAn/vGTPN+/N02xOjmhlljFPOzAIYUapk6TV hkWQNm1weWEg7+5NwC71aVZjKe1APrsRCw7tiEUdbybukS2QyNi7vL8rL2uN0G2cC+oh cIE6h78a3Anzk+FxYugrRmL5Z5sRRTgn5jeM5bvt+2D/E6UjDOr2TcE3PQEPjPxm36h8 JALEpX693j6v+B7tYw8gAosf7jIH0QF3o/t4XPgtJPq53ZLc5Y3XSHrVD0R/VNEleqES 8L1A== X-Forwarded-Encrypted: i=1; AJvYcCU4fMMXBT4XWFvQaZIwntkodHQ06fmTf0O+rQ7dtBBtMlhGDPnUC2o7rNx9YMH8ujABhuRg4eg5iaAQ9w==@lists.infradead.org X-Gm-Message-State: AOJu0YxN2O08cAGZL/xlwEtvnlrozUGjrWRC07dBumyoVBUt3yfcOSbt P3Qk3ej6hTN5AdjyUGg4vKHbG25tGj94vzUJbEw/0Bn9Y2QTnGrbeCTKMosT20M= X-Gm-Gg: ASbGnct+dY5acHpRHUA53lPI7xSYuPoWnwQSWXtZvsBWwLQ8QD0v0rWSVC9poZZ0Dm9 CruMoO1WX8Gson8Cf64olJtR4T3wAJmJ8WGuiQlsRdhljgDsLX0QO0lnOFrE0SRAGA2lgY77ssf xxDeTuuGPJBlIkSLQR9jr/jJ7EogdE3ilFUJ4o4giQZJ8x0NRr8WppR65Y2qir7fYUI6+wsyWDn q053CjF1YdKxMR79CbPnzzD8H3SLQm9/JXj62jRrux2jkbVIjRsuU0E6Fyo3idCPD8nVBf+Fivn WElWDnwYxZMxAX592JYvBYVS4rbp1QqcaKownU5mnzdQ X-Google-Smtp-Source: AGHT+IGvH4jPt9gEk2i8wJlEQCGHtq7Z8F/nhrt9cHdxqXKECEeUfNk2qVC/Ig+lLuwaqRjslO9WHQ== X-Received: by 2002:a17:902:da8d:b0:216:386e:dd8 with SMTP id d9443c01a7336-21c3540cd05mr367659545ad.17.1737638908563; Thu, 23 Jan 2025 05:28:28 -0800 (PST) Received: from C02DW0BEMD6R.bytedance.net ([63.216.146.178]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2d3ac3e2sm111583655ad.139.2025.01.23.05.28.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2025 05:28:28 -0800 (PST) From: Qi Zheng To: peterz@infradead.org, kevin.brodsky@arm.com, riel@surriel.com, vishal.moola@gmail.com, david@redhat.com, jannh@google.com, hughd@google.com, willy@infradead.org, yuzhao@google.com, muchun.song@linux.dev, akpm@linux-foundation.org, will@kernel.org, aneesh.kumar@kernel.org, npiggin@gmail.com, arnd@arndb.de, dave.hansen@linux.intel.com, rppt@kernel.org, alexghiti@rivosinc.com Cc: linux-mm@kvack.org, linux-kernel@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, x86@kernel.org, linux-riscv@lists.infradead.org, Qi Zheng Subject: [PATCH 1/5] mm: pgtable: make generic tlb_remove_table() use struct ptdesc Date: Thu, 23 Jan 2025 21:26:14 +0800 Message-Id: X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250123_052829_392155_D478921F X-CRM114-Status: GOOD ( 11.34 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Now only arm will call tlb_remove_ptdesc()/tlb_remove_table() when CONFIG_MMU_GATHER_TABLE_FREE is disabled. In this case, the type of the table parameter is actually struct ptdesc * instead of struct page *. Since struct ptdesc still overlaps with struct page and has not been separated from it, forcing the table parameter to struct page * will not cause any problems at this time. But this is definitely incorrect and needs to be fixed. So just like the generic __tlb_remove_table(), let generic tlb_remove_table() use struct ptdesc by default when CONFIG_MMU_GATHER_TABLE_FREE is disabled. Signed-off-by: Qi Zheng --- include/asm-generic/tlb.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h index e402aef79c93e..10cdbe0e7adfe 100644 --- a/include/asm-generic/tlb.h +++ b/include/asm-generic/tlb.h @@ -228,10 +228,10 @@ static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page); */ static inline void tlb_remove_table(struct mmu_gather *tlb, void *table) { - struct page *page = (struct page *)table; + struct ptdesc *ptdesc = (struct ptdesc *)table; - pagetable_dtor(page_ptdesc(page)); - tlb_remove_page(tlb, page); + pagetable_dtor(ptdesc); + tlb_remove_page(tlb, ptdesc_page(ptdesc)); } #endif /* CONFIG_MMU_GATHER_TABLE_FREE */ From patchwork Thu Jan 23 13:26:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13948274 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E44B9C0218B for ; Thu, 23 Jan 2025 13:28:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=LQDRrZHBnFgf9EKJYPOESATx5J5FSrbZC+TJsWWEHwk=; b=SaqT3++FmjeAXT O3fZB6f+leHZ6p+JcNbrtjzrZnziNjG/joHT6IMc9gQo7ym45T4/HRdmSFIAZ/C/GDc3+LYQYuyb3 81bmhQ3i2Gc29FoyvdOql9iUXtAwl7xlotxvsdgp3PyDLEiW1CcAT7j7YtEFGkjfomXYvBiBUuZFT b7oIZ8f2tC8LEK3572ghwvX87rdEfTxQAEh2V9jY+gci3Q3M/jhDJFxX/1m0NNoU5U5gAtYKvVIgH ziguIhNf8B8PKS+O93KL/xF/xtN0b8k6ZWlsRrR5kNPIjnBjaIdGh77S1WLnNUQpKJSp+FVD+jpXb S+iwnrf24tAsaFeDkWNA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1taxGD-0000000CWHb-2CBZ; Thu, 23 Jan 2025 13:28:41 +0000 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1taxGA-0000000CWFg-3kwF for linux-riscv@lists.infradead.org; Thu, 23 Jan 2025 13:28:40 +0000 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-216395e151bso12320745ad.0 for ; Thu, 23 Jan 2025 05:28:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1737638918; x=1738243718; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FYmxrc32hC6wxjmJA23IxEYTBygiQADV4kK+4R+dKSU=; b=KQWRXYGAn3sgGW2BrI0++STmB7ukBoOq0m3i497WU0y5i0Ra72JBClcgzItl7djK/1 wGnhsR6E7IMOa4hq9wdGRyjAfVsy9u1Fbo1P574HgUA4rptnkZFUQNqCzFjFfF2MsyWX OkJE8kj8IeN38oKkNqVo/AAtLPL2eQIrOKXZg//fAkfNc4Z3tWYvG6kidZ+cizO7qQBL Jrrh4B0zL4zMgfHT7EhP2wmtVNVrgaJa/N9e3VqkCQiaplFPhH5oCQRMiFKkV6ssAZxv 6KKoNEhd+f35KkwJQQLCohFDa4EGbiP1kFAsqrD7JBLw69r9VEBGzlutia51KpZMG8gi x8gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737638918; x=1738243718; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FYmxrc32hC6wxjmJA23IxEYTBygiQADV4kK+4R+dKSU=; b=BG9H26UcraNUZ95aRPTRspHjlGi3A8X4UGVgBDznFBFEAaGdsYvvRfbHwbkSN6uUmJ ASrOs6w4q7+pSAV6FUhOlJNs8pNVA3x4DDLFv3QUiYneJ86h3P4XvlOGRDtsEIp/8sz+ eWBmf98Hw2n86qMF2gehSze6tWp2qhnSHsoPdcb2dSwKMN7znNMqEi9rCjp5+I/cDhOd LiOjeJBOzsM2S6MksKGcRotQnIRbvHwpNy08mU2aJZQdN2L9XmRfbwnxYAt5BWMqkUGw 2/psLIGb7gV4clZVpwlSSb8rpNcGP3q+PeBoFI+fS+Cy+0/7n59wKMn29vFEZqeli/eo Rjmw== X-Forwarded-Encrypted: i=1; AJvYcCX7VRAGg9hoSHV0cGa0lPRCaLy6/ICJljKBvEQUe223qWy7mR2LKnVYBkqvQWDcKK7Swd47Nuo/fCP5Mg==@lists.infradead.org X-Gm-Message-State: AOJu0Yyvk8DVYVz1diO8NI01E+5G6AjE+oQO06ZkuedKDzWq8aYiSD1A BTIHBLNB6OO5pxGpGsrJqeiZjNFo2mz9z9KfIT0bFcHIVkdqOzvilqUoxOhaJSw= X-Gm-Gg: ASbGncsWdJKCeJwD5d/gHQDDMoQ/IghAFyT58rM6N0INno9gkjw5F1OPJ2F4ysko3+j 060cIQpJayPbVgvCvY9E2AK+BW/TDO50xLRwAYmwrJy33C0ydkqVRm0zeV9pzYS14Oav42vWTcH XPHtSZzKvCgO80crs23PIyLsSJA7ZqTKNcbmfqGt/mC5buBd0byev3hirCNMn9y5SZM7rwLv5ZI +DP8MJVMoKPruQAAvJDBs0dz8kC3Eqso9DhzYA5RLl3+isrBBzj50F+Q8i0Z1Ils7T6298jtqqy jznPR4t23ecAn35BJVtd9W3vk6smDL3TyI1p6RPVXnOi X-Google-Smtp-Source: AGHT+IG+jllXP/317uDYbnlVUGPZ9HFJ1DJp/HAbnaAGo0uqbORoOrOrnQgvR5mS4AHQ1q7HvBksTg== X-Received: by 2002:a17:902:cf45:b0:216:59f1:c7d9 with SMTP id d9443c01a7336-21d9937ac97mr46072665ad.19.1737638918431; Thu, 23 Jan 2025 05:28:38 -0800 (PST) Received: from C02DW0BEMD6R.bytedance.net ([63.216.146.178]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2d3ac3e2sm111583655ad.139.2025.01.23.05.28.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2025 05:28:37 -0800 (PST) From: Qi Zheng To: peterz@infradead.org, kevin.brodsky@arm.com, riel@surriel.com, vishal.moola@gmail.com, david@redhat.com, jannh@google.com, hughd@google.com, willy@infradead.org, yuzhao@google.com, muchun.song@linux.dev, akpm@linux-foundation.org, will@kernel.org, aneesh.kumar@kernel.org, npiggin@gmail.com, arnd@arndb.de, dave.hansen@linux.intel.com, rppt@kernel.org, alexghiti@rivosinc.com Cc: linux-mm@kvack.org, linux-kernel@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, x86@kernel.org, linux-riscv@lists.infradead.org, Qi Zheng Subject: [PATCH 2/5] mm: pgtable: convert some architectures to use tlb_remove_ptdesc() Date: Thu, 23 Jan 2025 21:26:15 +0800 Message-Id: X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250123_052838_933399_CE6354E2 X-CRM114-Status: GOOD ( 10.04 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Now, the nine architectures of csky, hexagon, loongarch, m68k, mips, nios2, openrisc, sh and um do not select CONFIG_MMU_GATHER_RCU_TABLE_FREE, and just call pagetable_dtor() + tlb_remove_page_ptdesc() (the wrapper of tlb_remove_page()). This is the same as the implementation of tlb_remove_{ptdesc|table}() under !CONFIG_MMU_GATHER_TABLE_FREE, so convert these architectures to use tlb_remove_ptdesc(). The ultimate goal is to make the architecture only use tlb_remove_ptdesc() or tlb_remove_table() for page table pages. Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) --- arch/csky/include/asm/pgalloc.h | 3 +-- arch/hexagon/include/asm/pgalloc.h | 3 +-- arch/loongarch/include/asm/pgalloc.h | 3 +-- arch/m68k/include/asm/sun3_pgalloc.h | 3 +-- arch/mips/include/asm/pgalloc.h | 3 +-- arch/nios2/include/asm/pgalloc.h | 9 ++++----- arch/openrisc/include/asm/pgalloc.h | 3 +-- arch/sh/include/asm/pgalloc.h | 3 +-- arch/um/include/asm/pgalloc.h | 9 +++------ 9 files changed, 14 insertions(+), 25 deletions(-) diff --git a/arch/csky/include/asm/pgalloc.h b/arch/csky/include/asm/pgalloc.h index bf8400c28b5a3..9d2b50265a8d8 100644 --- a/arch/csky/include/asm/pgalloc.h +++ b/arch/csky/include/asm/pgalloc.h @@ -63,8 +63,7 @@ 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)); \ + tlb_remove_ptdesc((tlb), page_ptdesc(pte)); \ } while (0) extern void pagetable_init(void); diff --git a/arch/hexagon/include/asm/pgalloc.h b/arch/hexagon/include/asm/pgalloc.h index 1ee5f5f157ca7..3d35d2bc42534 100644 --- a/arch/hexagon/include/asm/pgalloc.h +++ b/arch/hexagon/include/asm/pgalloc.h @@ -89,8 +89,7 @@ static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, #define __pte_free_tlb(tlb, pte, addr) \ do { \ - pagetable_dtor((page_ptdesc(pte))); \ - tlb_remove_page_ptdesc((tlb), (page_ptdesc(pte))); \ + tlb_remove_ptdesc((tlb), page_ptdesc(pte)); \ } while (0) #endif diff --git a/arch/loongarch/include/asm/pgalloc.h b/arch/loongarch/include/asm/pgalloc.h index 7211dff8c969e..ac026146e7e95 100644 --- a/arch/loongarch/include/asm/pgalloc.h +++ b/arch/loongarch/include/asm/pgalloc.h @@ -57,8 +57,7 @@ static inline pte_t *pte_alloc_one_kernel(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)); \ + tlb_remove_ptdesc((tlb), page_ptdesc(pte)); \ } while (0) #ifndef __PAGETABLE_PMD_FOLDED diff --git a/arch/m68k/include/asm/sun3_pgalloc.h b/arch/m68k/include/asm/sun3_pgalloc.h index f1ae4ed890db5..55a982ffb0457 100644 --- a/arch/m68k/include/asm/sun3_pgalloc.h +++ b/arch/m68k/include/asm/sun3_pgalloc.h @@ -19,8 +19,7 @@ extern const char bad_pmd_string[]; #define __pte_free_tlb(tlb, pte, addr) \ do { \ - pagetable_dtor(page_ptdesc(pte)); \ - tlb_remove_page_ptdesc((tlb), page_ptdesc(pte)); \ + tlb_remove_ptdesc((tlb), page_ptdesc(pte)); \ } while (0) static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte) diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h index 26c7a6ede983c..7e73d2f913dd4 100644 --- a/arch/mips/include/asm/pgalloc.h +++ b/arch/mips/include/asm/pgalloc.h @@ -50,8 +50,7 @@ extern 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)); \ + tlb_remove_ptdesc((tlb), page_ptdesc(pte)); \ } while (0) #ifndef __PAGETABLE_PMD_FOLDED diff --git a/arch/nios2/include/asm/pgalloc.h b/arch/nios2/include/asm/pgalloc.h index 12a536b7bfbd4..4b4a1766e2cc7 100644 --- a/arch/nios2/include/asm/pgalloc.h +++ b/arch/nios2/include/asm/pgalloc.h @@ -28,10 +28,9 @@ static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, extern pgd_t *pgd_alloc(struct mm_struct *mm); -#define __pte_free_tlb(tlb, pte, addr) \ - do { \ - pagetable_dtor(page_ptdesc(pte)); \ - tlb_remove_page_ptdesc((tlb), (page_ptdesc(pte))); \ - } while (0) +#define __pte_free_tlb(tlb, pte, addr) \ +do { \ + tlb_remove_ptdesc((tlb), page_ptdesc(pte)); \ +} while (0) #endif /* _ASM_NIOS2_PGALLOC_H */ diff --git a/arch/openrisc/include/asm/pgalloc.h b/arch/openrisc/include/asm/pgalloc.h index 3372f4e6ab4b5..2964e26980a18 100644 --- a/arch/openrisc/include/asm/pgalloc.h +++ b/arch/openrisc/include/asm/pgalloc.h @@ -66,8 +66,7 @@ extern pte_t *pte_alloc_one_kernel(struct mm_struct *mm); #define __pte_free_tlb(tlb, pte, addr) \ do { \ - pagetable_dtor(page_ptdesc(pte)); \ - tlb_remove_page_ptdesc((tlb), (page_ptdesc(pte))); \ + tlb_remove_ptdesc((tlb), page_ptdesc(pte)); \ } while (0) #endif diff --git a/arch/sh/include/asm/pgalloc.h b/arch/sh/include/asm/pgalloc.h index 96d938fdf2244..c376d4b708fda 100644 --- a/arch/sh/include/asm/pgalloc.h +++ b/arch/sh/include/asm/pgalloc.h @@ -34,8 +34,7 @@ static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, #define __pte_free_tlb(tlb, pte, addr) \ do { \ - pagetable_dtor(page_ptdesc(pte)); \ - tlb_remove_page_ptdesc((tlb), (page_ptdesc(pte))); \ + tlb_remove_ptdesc((tlb), page_ptdesc(pte)); \ } while (0) #endif /* __ASM_SH_PGALLOC_H */ diff --git a/arch/um/include/asm/pgalloc.h b/arch/um/include/asm/pgalloc.h index f0af23c3aeb2b..a70151cfd11c9 100644 --- a/arch/um/include/asm/pgalloc.h +++ b/arch/um/include/asm/pgalloc.h @@ -27,24 +27,21 @@ extern pgd_t *pgd_alloc(struct mm_struct *); #define __pte_free_tlb(tlb, pte, address) \ do { \ - pagetable_dtor(page_ptdesc(pte)); \ - tlb_remove_page_ptdesc((tlb), (page_ptdesc(pte))); \ + tlb_remove_ptdesc((tlb), page_ptdesc(pte)); \ } while (0) #if CONFIG_PGTABLE_LEVELS > 2 #define __pmd_free_tlb(tlb, pmd, address) \ do { \ - pagetable_dtor(virt_to_ptdesc(pmd)); \ - tlb_remove_page_ptdesc((tlb), virt_to_ptdesc(pmd)); \ + tlb_remove_ptdesc((tlb), virt_to_ptdesc(pmd)); \ } while (0) #if CONFIG_PGTABLE_LEVELS > 3 #define __pud_free_tlb(tlb, pud, address) \ do { \ - pagetable_dtor(virt_to_ptdesc(pud)); \ - tlb_remove_page_ptdesc((tlb), virt_to_ptdesc(pud)); \ + tlb_remove_ptdesc((tlb), virt_to_ptdesc(pud)); \ } while (0) #endif From patchwork Thu Jan 23 13:26:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13948275 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3F350C02182 for ; Thu, 23 Jan 2025 13:28:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=n6Ma2NJFcwkJSyzO/jsiEkvQwg4LtNIQ62pTriW3vkw=; b=3ZIbGW/YWV/Kqf SyoLr+c0i5NYAIB+wpwCBRRTG1h0cl9756OGAHTl9iNbznPOOJEqSDrTxPJHC/gZJPgN3OGBRfcLv VXpJQHX3lJalReP3a6efuFLPw+VaEN2R0mpLmj4wI4XIVvDU6Gzcsex5F4vLRvmptNGTBWgrxOAyM cbKD6zcCI9MsyNA23zwNxHmoJaJcb/VWjC2OFdeiYE5bQ8Wp79yEvFhJGWF7j6W5L6ODf6nWYCsmB fr38V8U0Dk38OxdRTy0k86+oSqW9tIcop7YHXcw44H2DmTdbc4hl4/bdnPoV2BNSO2KlTOUaClqj2 P3ee+UHnnDHmVX+aMmQw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1taxGO-0000000CWP5-41Lw; Thu, 23 Jan 2025 13:28:52 +0000 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1taxGL-0000000CWMR-1Qks for linux-riscv@lists.infradead.org; Thu, 23 Jan 2025 13:28:51 +0000 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-216395e151bso12324105ad.0 for ; Thu, 23 Jan 2025 05:28:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1737638929; x=1738243729; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zIKiL/cvy76O78IwclMxfA3FUb4EAj4nzgq2isZtk2Q=; b=JqtUHdpqtwvt3NgjD91tyBX8KeS1vGjWlnuBZpY1LRH1CBMIGTTn2/y6H+518rufRS bFn/GW5jjuMJlnD7m7WXvRP07du1YAlSZ9zkbIPy7ztDzDo/WqAWL0shR/l8EjphP/Ib +Lg3Y0mGNrqgaBrzvMODZELMRvPr8SXBFahKtIh7xCPA9klOUMH+gi3sbeb6mEk8jLJk tE9aNufgZSCDCWg1n2MDKDawUlyT9sUw+tNYmqSjAlnFe2VHLEYOrrGX6GyL1Ht2VLCq LZyjEY6PaGmAewz3+hfI17dp0BJgcXuhGllcZkO2FoMyfZPniAhzLnMZUmINUIlmyBSb 5LSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737638929; x=1738243729; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zIKiL/cvy76O78IwclMxfA3FUb4EAj4nzgq2isZtk2Q=; b=vFra4iQoPHLqg2J8gyZOgY4V93a9ytK1aSSlvqOH7Rmb7wblu/UWAZdYQaya050Ohc Qt188CZkGulU2O4x+rHXbcZJD+eMc3igSY7yBQdKP8vsRNM5boJWfzE0PkPiZmgsgugG 0scVVEcsRrmxBJcqiNvRG/vyY/2CODyogqtgwJi1gtxO1Vx3Zs3fipB3p0WKQK7zSGa5 M+rfyVOj0Aqq2gB6BMXZmdG1qxSNCEhx//y9xcsJJfhiH4UkWc/wg5DX3n2HdNUSAE12 QVhZs6BY1n2xRhrmbiV3m4TFvuz/yB2Wym8tM5YAT6j+jM7gKj8MvtwmEZzF1Hm5f+9Q SnmA== X-Forwarded-Encrypted: i=1; AJvYcCXJZDWZBT7HJpk+5jFcmnxeGrUj1WTJEuK6zYg+o5eCo6MsQ6ufgDbc+5ilOAXpftCphPSVHPsbTEcO2w==@lists.infradead.org X-Gm-Message-State: AOJu0YzJFgx54BtUj6ITmz/EIscz/SWLekmEV6+awIAQvWRd7bvIN63J 0gwdLi/LVwWcskJzvHgQmi+G86g6DbZCHp/ODRKHxd8V+vWbBckC5ZhoLsfpLmg= X-Gm-Gg: ASbGncsv4FCVd50sN/AVTlwi1i3Ly2ZMY6OAAo+cx0PoiS389k79YP5XZtxW8oqZ4VY RcZqpj61IFzHH5BaxWc5pT2ZoS0wZ49Q4UlY75jQg8fTb7iK34BZkPCfnphh+RZPjRtVTvjYzGt fZn4/aKrL0bc0j3eUweJ8U+S3qACvLEisOGZONLw/9cToft9YD4bs/5ER6r8G1vu+yamiS+ZHpN PoGGoNk863hYkZyYxxLJxxoErs6PtA1xuYnN7105Y/8lNb1Xc2B6M4Rv0L3C0lbiQIXnv7yM/+L oEQpNt5CiB99WTdyhkObwrx+wEdP1SW6KJYqkfQR7tlB X-Google-Smtp-Source: AGHT+IEu4HBG3SpWH9djQXZ235PefY3+YNVKU7kJShvdW8r3VF7F38seuaHQ6/TN21qUw52tcuL1Ag== X-Received: by 2002:a17:902:f541:b0:216:5db1:5dc1 with SMTP id d9443c01a7336-21d993172e2mr55309915ad.1.1737638928616; Thu, 23 Jan 2025 05:28:48 -0800 (PST) Received: from C02DW0BEMD6R.bytedance.net ([63.216.146.178]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2d3ac3e2sm111583655ad.139.2025.01.23.05.28.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2025 05:28:47 -0800 (PST) From: Qi Zheng To: peterz@infradead.org, kevin.brodsky@arm.com, riel@surriel.com, vishal.moola@gmail.com, david@redhat.com, jannh@google.com, hughd@google.com, willy@infradead.org, yuzhao@google.com, muchun.song@linux.dev, akpm@linux-foundation.org, will@kernel.org, aneesh.kumar@kernel.org, npiggin@gmail.com, arnd@arndb.de, dave.hansen@linux.intel.com, rppt@kernel.org, alexghiti@rivosinc.com Cc: linux-mm@kvack.org, linux-kernel@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, x86@kernel.org, linux-riscv@lists.infradead.org, Qi Zheng Subject: [PATCH 3/5] riscv: pgtable: unconditionally use tlb_remove_ptdesc() Date: Thu, 23 Jan 2025 21:26:16 +0800 Message-Id: <86e9fbf586912f3689e98c4dee2180b69b399638.1737637631.git.zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250123_052849_388664_68D3E7D1 X-CRM114-Status: GOOD ( 15.28 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org To support fast gup, the commit 69be3fb111e7 ("riscv: enable MMU_GATHER_RCU_TABLE_FREE for SMP && MMU") did the following: 1) use tlb_remove_page_ptdesc() for those platforms which use IPI to perform TLB shootdown 2) use tlb_remove_ptdesc() for those platforms which use SBI to perform TLB shootdown The tlb_remove_page_ptdesc() is the wrapper of the tlb_remove_page(). By design, the tlb_remove_page() should be used to remove a normal page from a page table entry, and should not be used for page table pages. The tlb_remove_ptdesc() is the wrapper of the tlb_remove_table(), which is designed specifically for freeing page table pages. If the CONFIG_MMU_GATHER_TABLE_FREE is enabled, the tlb_remove_table() will use semi RCU to free page table pages, that is: - batch table freeing: asynchronous free by RCU - single table freeing: IPI + synchronous free If the CONFIG_MMU_GATHER_TABLE_FREE is disabled, the tlb_remove_table() will fall back to pagetable_dtor() + tlb_remove_page(). For case 1), since we need to perform TLB shootdown before freeing the page table page, the local_irq_save() in fast gup can block the freeing and protect the fast gup page walker. Therefore we can ensure safety by just using tlb_remove_page_ptdesc(). In addition, we can also the tlb_remove_ptdesc()/tlb_remove_table() to achieve it, and it doesn't matter whether CONFIG_MMU_GATHER_RCU_TABLE_FREE is selected. And in theory, the performance of freeing pages asynchronously via RCU will not be lower than synchronous free. For case 2), since local_irq_save() only disable S-privilege IPI irq but not M-privilege's, which is used by the SBI implementation to perform TLB shootdown, so we must select CONFIG_MMU_GATHER_RCU_TABLE_FREE and use tlb_remove_ptdesc() to ensure safety. The riscv selects this config for SMP && MMU, the CONFIG_RISCV_SBI is dependent on MMU. Therefore, only the UP system may have the situation where CONFIG_MMU_GATHER_RCU_TABLE_FREE is disabled but CONFIG_RISCV_SBI is enabled. But there is no freeing vs fast gup race in the UP system. So, in summary, we can use tlb_remove_ptdesc() to support fast gup in all cases, and this interface is specifically designed for page table pages. So let's use it unconditionally. Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) --- arch/riscv/include/asm/pgalloc.h | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/arch/riscv/include/asm/pgalloc.h b/arch/riscv/include/asm/pgalloc.h index 3e2aebea6312d..770ce18a7328b 100644 --- a/arch/riscv/include/asm/pgalloc.h +++ b/arch/riscv/include/asm/pgalloc.h @@ -15,24 +15,6 @@ #define __HAVE_ARCH_PUD_FREE #include -/* - * While riscv platforms with riscv_ipi_for_rfence as true require an IPI to - * perform TLB shootdown, some platforms with riscv_ipi_for_rfence as false use - * SBI to perform TLB shootdown. To keep software pagetable walkers safe in this - * case we switch to RCU based table free (MMU_GATHER_RCU_TABLE_FREE). See the - * comment below 'ifdef CONFIG_MMU_GATHER_RCU_TABLE_FREE' in include/asm-generic/tlb.h - * for more details. - */ -static inline void riscv_tlb_remove_ptdesc(struct mmu_gather *tlb, void *pt) -{ - if (riscv_use_sbi_for_rfence()) { - tlb_remove_ptdesc(tlb, pt); - } else { - pagetable_dtor(pt); - tlb_remove_page_ptdesc(tlb, pt); - } -} - static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte) { @@ -108,14 +90,14 @@ static inline void __pud_free_tlb(struct mmu_gather *tlb, pud_t *pud, unsigned long addr) { if (pgtable_l4_enabled) - riscv_tlb_remove_ptdesc(tlb, virt_to_ptdesc(pud)); + tlb_remove_ptdesc(tlb, virt_to_ptdesc(pud)); } static inline void __p4d_free_tlb(struct mmu_gather *tlb, p4d_t *p4d, unsigned long addr) { if (pgtable_l5_enabled) - riscv_tlb_remove_ptdesc(tlb, virt_to_ptdesc(p4d)); + tlb_remove_ptdesc(tlb, virt_to_ptdesc(p4d)); } #endif /* __PAGETABLE_PMD_FOLDED */ @@ -143,7 +125,7 @@ static inline pgd_t *pgd_alloc(struct mm_struct *mm) static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd, unsigned long addr) { - riscv_tlb_remove_ptdesc(tlb, virt_to_ptdesc(pmd)); + tlb_remove_ptdesc(tlb, virt_to_ptdesc(pmd)); } #endif /* __PAGETABLE_PMD_FOLDED */ @@ -151,7 +133,7 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd, static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte, unsigned long addr) { - riscv_tlb_remove_ptdesc(tlb, page_ptdesc(pte)); + tlb_remove_ptdesc(tlb, page_ptdesc(pte)); } #endif /* CONFIG_MMU */ From patchwork Thu Jan 23 13:26:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13948276 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 30A63C0218B for ; Thu, 23 Jan 2025 13:29:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=RYSuZ54gLJt4PmIlG7SgJdgZSAXk15sygxerSfZF/vI=; b=esgu7KhziAa0Yp lBR8jMzG7MXAcrvMOiPJgyTFnlt8qIf/+Ow2rkMAD72HWR41Xqv1tOXvkBB9SaszzEHBB0jO5Bjhn 0FKAUHfJXj983CJWYHCylVtvwqCiheViqgSZcqIpX6nPowyzEKlpSVclSffgT09QQSTLrIkAUrYZf MX4C/IjHW12OLjMremJ20EboeT6Q7HSYHm7W2TmkM2lh02EfxLTLqG6GYn9+hll9z3layRpnipBmb rhfP76rDmZmi/0fcKb+bl0qll55gbpHlRZKWXHeA4b8esMwO2mKdaW/EmJnYXdjiANY5Bvwnnkoih iGgVKF4Hdt1ogp2zLeKg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1taxGY-0000000CWWI-41xZ; Thu, 23 Jan 2025 13:29:02 +0000 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1taxGU-0000000CWSa-47Cb for linux-riscv@lists.infradead.org; Thu, 23 Jan 2025 13:29:01 +0000 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-21661be2c2dso15403325ad.1 for ; Thu, 23 Jan 2025 05:28:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1737638938; x=1738243738; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bSVoet4BIZh93xV/DLydReH1JogDWuAFDaImcbetZJc=; b=FCHypj1dcOHI9TRPI9rp2cRm7kUpAI4BH28yD7m9lCOw5joaBJoaszb2KHodydIidF aCi8dRrjnyDp+fTGCckvymB7tkzTDhg1tPTA6nYnyT6dH9mFrD+6Ttho7kKt/7Lg8TPX 1ddZfa4HyifA5qTMw/eElunDVdR0qr1g4R+THOypMxwCza8wbeKTyubHUvOXeJ4bNSBE l3fMY66iyYpcqMAg4flsSaKUUVyPDcI0JHwakshdFSUsq6onHn+QVmmdv1bKqcZiUl91 3Axzc1jQj/vunmsgDmCPlkGfooltEo6K/wUu63Z+iajkwoYi8LwgOOitSM8RlK056Sua 80HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737638938; x=1738243738; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bSVoet4BIZh93xV/DLydReH1JogDWuAFDaImcbetZJc=; b=dePh3c3R+4MP3qgUKKo4NeNAo2Ux0dsKIfvF1SOFAPK+BuL46hutc3m8pUoreU2w3I 2hOcnRozUsVWa+UJkn9QzQBCAYzwDTI6JUzztieCP0Wfq/rJfHRzay1vekGY0uC+3+Nt Q9Evd9YH0yV4TlkdkmoVwM3PNChSgO3/Aco8rakVcZeCETzwSrpKELURQsH9OxI87cdc hwVT4ETQohw+hQ2yKhmPDOTHLblHJ/ihuN3xbvDI8yQaHNwdIEWQunkRzq6RlyeQffLT 0aibNZb3QXEkGgSZB6fGlZu4e4NJWYzAUkEaAi9DdZrJEagsDNkLW932mZS6egs+Q4a5 wnoQ== X-Forwarded-Encrypted: i=1; AJvYcCUFWI6pjkEPX/5Vd/WH7j8SMDTVCHAJDN1aF54yf9jQg0gUvxZ0DOHQs00b/tUkH0nir0QPsvBOfGH5uw==@lists.infradead.org X-Gm-Message-State: AOJu0YzTRTRrjSqvCkgnvE+97p8bltB3MEZoahY00V/5VT7DEFFDVR4t 1aMM0d/XBN565HlZj9G0e5gbb1my+ljrEBzZ2lv0eQCvzMI7uF0X4l4xDNkqfXk= X-Gm-Gg: ASbGnctAUop2kRv0ENlgUi6SBUXU/PRzPn8z4unnVb00vTEg5Y40yxqN+y4/kBuv/0W L2X+YHHNw+oA/Z3KD1NsFbnsmb4tb3GrnX9ssxpwLIBe+ySZslgI7xPldo4MPplGxP/F9p7KUNF DljJEY6/ascPBIA4YK6HDIgQhI7lQYQT0+rSRrKvNk1jZnyEEt+4+JdJYNcWGvtDrM1Hzwhv+xp 03fSiaL+hETC1TdFecHLXhRQvcdGLauWJgeP6pbGUHwmLUXODJXS9eprhfPXjIJ//a6heTm9Fdl bvuHWmfeX8Xb46GdCfXpyWxycM0/8sV4zAr0LD56KaJM X-Google-Smtp-Source: AGHT+IE9ITT+lxW4q5ku2WHS5AYNu8WFWCG+wILMASo2spfcLUt1T5YAi0clrsTLRCDPofgLk2+QPw== X-Received: by 2002:a17:902:e5ce:b0:216:6590:d472 with SMTP id d9443c01a7336-21c3551ae48mr419794535ad.21.1737638938491; Thu, 23 Jan 2025 05:28:58 -0800 (PST) Received: from C02DW0BEMD6R.bytedance.net ([63.216.146.178]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2d3ac3e2sm111583655ad.139.2025.01.23.05.28.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2025 05:28:57 -0800 (PST) From: Qi Zheng To: peterz@infradead.org, kevin.brodsky@arm.com, riel@surriel.com, vishal.moola@gmail.com, david@redhat.com, jannh@google.com, hughd@google.com, willy@infradead.org, yuzhao@google.com, muchun.song@linux.dev, akpm@linux-foundation.org, will@kernel.org, aneesh.kumar@kernel.org, npiggin@gmail.com, arnd@arndb.de, dave.hansen@linux.intel.com, rppt@kernel.org, alexghiti@rivosinc.com Cc: linux-mm@kvack.org, linux-kernel@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, x86@kernel.org, linux-riscv@lists.infradead.org, Qi Zheng Subject: [PATCH 4/5] x86: pgtable: unconditionally use tlb_remove_table() Date: Thu, 23 Jan 2025 21:26:17 +0800 Message-Id: <00bf7935d65826eee547ac195d7854b1c946dbc5.1737637631.git.zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250123_052859_019329_624F0A2F X-CRM114-Status: UNSURE ( 8.54 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org If the CONFIG_MMU_GATHER_TABLE_FREE is disabled, the tlb_remove_table() will fall back to pagetable_dtor() + tlb_remove_page(). So let's use tlb_remove_table() unconditionally to free page table pages. Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) --- arch/x86/kernel/paravirt.c | 17 +---------------- arch/x86/mm/pgtable.c | 11 ----------- 2 files changed, 1 insertion(+), 27 deletions(-) diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c index 1ccaa3397a670..527f5605aa3e5 100644 --- a/arch/x86/kernel/paravirt.c +++ b/arch/x86/kernel/paravirt.c @@ -59,21 +59,6 @@ void __init native_pv_lock_init(void) static_branch_enable(&virt_spin_lock_key); } -#ifndef CONFIG_PT_RECLAIM -static void native_tlb_remove_table(struct mmu_gather *tlb, void *table) -{ - struct ptdesc *ptdesc = (struct ptdesc *)table; - - pagetable_dtor(ptdesc); - tlb_remove_page(tlb, ptdesc_page(ptdesc)); -} -#else -static void native_tlb_remove_table(struct mmu_gather *tlb, void *table) -{ - tlb_remove_table(tlb, table); -} -#endif - struct static_key paravirt_steal_enabled; struct static_key paravirt_steal_rq_enabled; @@ -195,7 +180,7 @@ struct paravirt_patch_template pv_ops = { .mmu.flush_tlb_kernel = native_flush_tlb_global, .mmu.flush_tlb_one_user = native_flush_tlb_one_user, .mmu.flush_tlb_multi = native_flush_tlb_multi, - .mmu.tlb_remove_table = native_tlb_remove_table, + .mmu.tlb_remove_table = tlb_remove_table, .mmu.exit_mmap = paravirt_nop, .mmu.notify_page_enc_status_changed = paravirt_nop, diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c index 1fef5ad32d5a8..3bc8ad282b272 100644 --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -19,22 +19,11 @@ EXPORT_SYMBOL(physical_mask); #endif #ifndef CONFIG_PARAVIRT -#ifndef CONFIG_PT_RECLAIM -static inline -void paravirt_tlb_remove_table(struct mmu_gather *tlb, void *table) -{ - struct ptdesc *ptdesc = (struct ptdesc *)table; - - pagetable_dtor(ptdesc); - tlb_remove_page(tlb, ptdesc_page(ptdesc)); -} -#else static inline void paravirt_tlb_remove_table(struct mmu_gather *tlb, void *table) { tlb_remove_table(tlb, table); } -#endif /* !CONFIG_PT_RECLAIM */ #endif /* !CONFIG_PARAVIRT */ gfp_t __userpte_alloc_gfp = GFP_PGTABLE_USER | PGTABLE_HIGHMEM; From patchwork Thu Jan 23 13:26:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13948277 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F328FC02182 for ; Thu, 23 Jan 2025 13:29:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=btwZ9Uz1DvkX8yBlhQmnpGsry/01RRs0lmOA5XrWQU8=; b=Id8fcTM7aV5M6T +89A1wg9g+9FJzvo8hLnQiz0asjSXEn3O1gqE7Qmvq8N9weSyAQgrOIuXxq4PFgak4BMr3T30ML/S A7rcMY73zVwzo1+bFb/b+eKQU0RbN+QT8GssSoFM2L1k+AYvYAiGsmmhaY2vOK0QTwJDA4FI0vYWX F/6IaYLdZGzj/Pt0PszTQB/Z7nWOFNL3bAHi0bZQ7SwMEj/WHYOF+ZA690T5/Iok6xgG1DueMBuax q0T40D66O6ggcYHgZt5kTSpO7nBdF7oUoIWnE0Kc1/OKSvWmJYRwhTGA1ktcHRFwPdbQSlUdyLabW lGVIcBUnyBhDvtEKMTvw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1taxGi-0000000CWd1-0L4I; Thu, 23 Jan 2025 13:29:12 +0000 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1taxGf-0000000CWa1-0mGM for linux-riscv@lists.infradead.org; Thu, 23 Jan 2025 13:29:10 +0000 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-216728b1836so13931615ad.0 for ; Thu, 23 Jan 2025 05:29:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1737638948; x=1738243748; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8C94XB4BAC98f0nzKDfhip6ZZIJjZtAIgTVlkxB/zEY=; b=dZmriKqVdLkRsJYb9RCNJZvdzO+mo/QpnmTqNckodE2SQ78rkhe9QBZpfsIvf3Me8f TBJOiSuOz7b0eI3AK6bGiGH2GCLt9HCEAB20eemNpl9YTyc1T5y7TjGYjzw//f1CPP4Y AaKOzNwS+hAOYLA1r/91+tgXaGH4eKBB3D+wGcaOwR7HZDMmQn6lpeGOy5Z/tFVYIOcJ rwEfkss2axLRmk68Q8+rZr6+TgWPL9tqUkHcGgyRtLNc0l2miyUYVgjeZn+8mHo59vfu QBRhJDAEa7Tr0y6ilaMF23T1RD/oAvMfkmStftu9v8MzJ7c82UO7SAwJF022hJMU3dnw dYgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737638948; x=1738243748; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8C94XB4BAC98f0nzKDfhip6ZZIJjZtAIgTVlkxB/zEY=; b=EsrPtTUsfeGr7Ffnt9s8esTkZW7Lbbo30M4AfUtg5H48t4jPstr865yzJmxKVfQ17d QnHLlZih3eIUz5QUhapycn6mcS5ZD93GmjH7Rvu7lq/0eZgn0GbgevBmcumTeedsuptv emz4EE2mYqes4VEaPutoRLhLDQz6aPS6koNpMVh5chYY8kbyI09/SifYTDcCLmwKH/7M PjxMkbKl5lwGgk+1GxN8QRNbhSdSYNKsForv+OMuo8XKZHWWJZGXEXXESBb2qATeKOHe K2F8nQjuIsO7WSCihWK44H8M5LSoRIwLzwrJ7mhULjGcdxGAuBcVHP7r6kMBE+tPxrjT As5Q== X-Forwarded-Encrypted: i=1; AJvYcCWGqCE6ZW3PLMFH5rTL9xgwkXL1mRInY4SIJCeEBd2LiHvry4dN8XKnmRniPBzOfnm2ztAfJFj9UDc8nA==@lists.infradead.org X-Gm-Message-State: AOJu0YyxxwyuTG/6PKui+V3hQJES5STB7aatC0zN/qNu5Ho7+xhjqKGg Q1G1wTvNeav9jTOR0HWusuIiQ0c1WcXJtRZbjH9IKV8WL8yp6x/t2AS7nHMGQsg= X-Gm-Gg: ASbGncu8pCL4kGR8XxA6+MsQ9Rs7x0c5MzgSVY/rCb2EXxKOHqoQS0HEtucvamtezGB O5c3r0JOyLLZ2r2XvuBH+HbBOFWpye+8AK/9dEH8tdFCFLGeRQIbLnSZAMLCMv5mZ1ad0Htozgh uhG0wjr5jvQ6j3ntyClzCXOD/EBnw4ly8BSG7tnYDg6q1p8zWpaSW6sWzdjTux+ukOECKVIBALH zlieaiHoZposUDt6SNemkCHcmitzzEqAf9urJF950yPfyHb3kspoUhOQb1aCyvNNS/FepDsPYiN +LD+8MdZFXQBHVuUhtugbfX2OmqWnxgQ2X13Qyuu3vZL X-Google-Smtp-Source: AGHT+IFkSdO3UtmG5jKkAJtanqQZSHufZoNoVtMFPHl42HZUz79kP6iB5Pw4LWGczfrtYHtt4kZUXA== X-Received: by 2002:a17:902:f54f:b0:215:b468:1a33 with SMTP id d9443c01a7336-21c351c67acmr376126085ad.4.1737638948337; Thu, 23 Jan 2025 05:29:08 -0800 (PST) Received: from C02DW0BEMD6R.bytedance.net ([63.216.146.178]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2d3ac3e2sm111583655ad.139.2025.01.23.05.28.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2025 05:29:07 -0800 (PST) From: Qi Zheng To: peterz@infradead.org, kevin.brodsky@arm.com, riel@surriel.com, vishal.moola@gmail.com, david@redhat.com, jannh@google.com, hughd@google.com, willy@infradead.org, yuzhao@google.com, muchun.song@linux.dev, akpm@linux-foundation.org, will@kernel.org, aneesh.kumar@kernel.org, npiggin@gmail.com, arnd@arndb.de, dave.hansen@linux.intel.com, rppt@kernel.org, alexghiti@rivosinc.com Cc: linux-mm@kvack.org, linux-kernel@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, x86@kernel.org, linux-riscv@lists.infradead.org, Qi Zheng Subject: [PATCH 5/5] mm: pgtable: remove tlb_remove_page_ptdesc() Date: Thu, 23 Jan 2025 21:26:18 +0800 Message-Id: <62d6a04c3a0e70efd435cc2c8a4d9d07d94e7ece.1737637631.git.zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250123_052909_221096_9225FB8F X-CRM114-Status: UNSURE ( 6.79 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The tlb_remove_ptdesc()/tlb_remove_table() is specially designed for page table pages, and now all architectures have been converted to use it to remove page table pages. So let's remove tlb_remove_page_ptdesc(), it currently has no users and should not be used for page table pages. Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) --- include/asm-generic/tlb.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h index 10cdbe0e7adfe..dec030cb12108 100644 --- a/include/asm-generic/tlb.h +++ b/include/asm-generic/tlb.h @@ -509,12 +509,6 @@ static inline void tlb_remove_ptdesc(struct mmu_gather *tlb, void *pt) tlb_remove_table(tlb, 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) -{ - tlb_remove_page(tlb, ptdesc_page(pt)); -} - static inline void tlb_change_page_size(struct mmu_gather *tlb, unsigned int page_size) {