From patchwork Wed Jan 8 06:57:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13930200 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 8B14EE77199 for ; Wed, 8 Jan 2025 07:01:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1E01A6B0089; Wed, 8 Jan 2025 02:01:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 190596B00A6; Wed, 8 Jan 2025 02:01:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EFE026B00A7; Wed, 8 Jan 2025 02:01:40 -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 81B786B0089 for ; Wed, 8 Jan 2025 02:01:40 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3AD21140FCA for ; Wed, 8 Jan 2025 07:01:40 +0000 (UTC) X-FDA: 82983389160.23.0DFD5EE Received: from relay.hostedemail.com (unirelay09 [10.200.18.72]) by imf09.hostedemail.com (Postfix) with ESMTP id 04926140012 for ; Wed, 8 Jan 2025 07:01:37 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; arc=pass ("hostedemail.com:s=arc-20220608:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736319698; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xRYydr57EpvJJkVepk/VS3bq1fMuYMijkZdKL5zejaA=; b=7z3GO83jCA0AXO8KqhXGA9Kns6YRbdfBqi24olaa8MdIFLl+R/N2dh/ymDl5EurnbpypAr u0VCoQoduqAe35AANfjCc5auqcCjD+/GTKGx8RgEEDmHUR7BSkgXH6vepUUhR3F0iEPaUP pPTfCbAxDZtlP0leE7m6fMm9gxfRw6w= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1736319698; a=rsa-sha256; cv=pass; b=V01vo8NjMcQ4xc2Eb5RgzgVOOoMqRt0drbJTlMKTi9SfJmzaYAE4fPXeiuV9BLjSSuZn9t RojQK0jeHpLNigT1O3+y3hBsTukzAQStdy3wdZgBcicqiQmqG4P03l5ztR4DpO0q7i4s3u hlf+Z9OCH7p2z6NZAZfxV587++9lHAg= ARC-Authentication-Results: i=2; imf09.hostedemail.com; arc=pass ("hostedemail.com:s=arc-20220608:i=1") Received: from relay.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 87F8380F27 for ; Wed, 8 Jan 2025 07:01:37 +0000 (UTC) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5303716059C for ; Wed, 8 Jan 2025 07:01:37 +0000 (UTC) X-FDA: 82983389034.11.C742A43 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf22.hostedemail.com (Postfix) with ESMTP id 1F4FEC0014 for ; Wed, 8 Jan 2025 07:01:20 +0000 (UTC) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736319681; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xRYydr57EpvJJkVepk/VS3bq1fMuYMijkZdKL5zejaA=; b=4MHi23wsKyl6H0Q1She232XG/3/Si5T2miCi9hNacAh7m5I031xJKQt+aFzEZ4CfgSWmja hA3NS+AM4CFqv1SuDAIwqUJqMnXHMWmx128YumephsSyK9Brk3dPqKajlxE9D1qPVTvBMv hdc6HukXKVynqLzzq8tD6CipkR5dPkY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736319681; a=rsa-sha256; cv=none; b=NJK04NM94cSsg/ljZxhKkoEBJawjh1K/77t397UkSWCkiG8xqbOHIdcT13Hcv7l15Cs/Um l2bFBU8C0qfjWUs2Mm2bpScm3xxx5MGGj1X62InVypJRr1yUqqj8JSjPLWC8XBPYICa77C CKe8AH2xOU73TxAYrWh9KL22yAjuwbo= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=X9S8jE5T; spf=pass (imf22.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2164b662090so213580825ad.1 for ; Tue, 07 Jan 2025 23:01:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1736319680; x=1736924480; darn=kvack.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=xRYydr57EpvJJkVepk/VS3bq1fMuYMijkZdKL5zejaA=; b=X9S8jE5TpDvt3kiGDvAxoHHJdO70E5ViVsPfRtmjVBMFgDq/am0+YCY59cQKHgeM0O VDVClY71Dyrdy075I+u67wFgpwpJi43m5JiABb6WCj9lBXDvWG4Dli8ucNQKqC/zCFM0 6Oh8GlU1SbXI7OMKWkZXdxS5jOhaAqtMRFcuckKewQhruISBoIMRIfOWXWk5GDgIr3cz 1oFxK9pCxyjRTImYRsNo86WhvL/R5fKWiaP+xWNjHI1vsGHKOH5GQ0DSNLO+3GJ+yu3o 9FPud/iVXtRDWMl07/BcwaJ1G7wWUsJfi9KnTs1FZTETYUwiDHspnyEhjp4FR96AjMuk 3yaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736319680; x=1736924480; 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=xRYydr57EpvJJkVepk/VS3bq1fMuYMijkZdKL5zejaA=; b=i7+Nk5yN+Pwk+jl0P09eIjJJh1jJf0A7EXkEpjRnN9HKWTmD6iP7Bpp6LmxZyW9oSe AqgUjHzsU1Z4duIX5W1swexXhdrTQ36i/Ix5AT91GMIbxgIOXyk0kYxP+6HA2ZWxSyjx kBNg4sSxH//ViLG+N+5GYfpjx/4c1FVAKJ0eZwT3UIaSKE2+Gyyn3nyGRL7tcbdCTUlM 2T5IKGc+8yFBS03ogs1oPRj6jPIINjNor3JR0yZ01fEAjZoQTWff1JoUm1zYx26biCpF 9fz0+s6sOn2fQ8J00ZBy3vnk53ssRHXpeG89JOYWpUvcOVfe7lNRVrYk8U30vrBgth2i OciQ== X-Gm-Message-State: AOJu0YymL3rTdehkTqKBENm22yIcJNGMyiSYL9viMrunXi6TTlIJm/Am TWoXEQzfj+9JHHqZiPt0KIo7ipuVubFktFuRl9jdNkbmQvPdYCvaVaHTMLMUQm8= X-Gm-Gg: ASbGncu4W5JLednCPya7oweXWZk8CD8qFk1fWXu9vHoV9z8LQV2EwcpaKS1VRBSZHZ8 vPgiGosPLJXdqL5YmDWvfwBjbnOv2zv0k+r4XJM6LeUJCQWS1FOEjqjcW/DcP1zDpDKeBDG0PlC SB+5BB6MolWbdbLoIk4wXIATt30kQwmxELl28vvgk/kiIZlBDSCzzGzhPHolBXvVfFKdePpCqZm 0RD2awBpD02t3rHNcwXwrbkSpGtCL1gyfYgvwKkRN/KS+X9RSRv4Xtu8Z2qinCwgxxS/1sncwcM LjQmBCBCzDAybsSJKEgigYvr5QU= X-Google-Smtp-Source: AGHT+IGA+MEO+KKVHOehVcxKdAaP4kVFc+4x/MGW5FidU7ZYZhG+ejtfRbHdQiRj7WdzfqmV0LUjgQ== X-Received: by 2002:a17:902:d352:b0:215:8847:435c with SMTP id d9443c01a7336-21a83f4b133mr25527805ad.12.1736319679689; Tue, 07 Jan 2025 23:01:19 -0800 (PST) Received: from C02DW0BEMD6R.bytedance.net ([139.177.225.244]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dca023a3sm320067275ad.250.2025.01.07.23.01.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 23:01:19 -0800 (PST) From: Qi Zheng To: peterz@infradead.org, agordeev@linux.ibm.com, kevin.brodsky@arm.com, alex@ghiti.fr, andreas@gaisler.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 Cc: 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, Qi Zheng Subject: [PATCH v5 08/17] arm: pgtable: move pagetable_dtor() to __tlb_remove_table() Date: Wed, 8 Jan 2025 14:57:24 +0800 Message-Id: <327b4b8990729edd4ce97d9d5acbdaff2d9fa1d1.1736317725.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-HE-Meta: U2FsdGVkX1+mnjlw4bB8FoAyqSEkOpQG4ye59DJ0uVkIoqfJ6AJbshSJKiWBFYaNA17Nuv5QpbLhFOJzW9b7ReC5OO6od6mou58SuBt7OXD54EUZplEeSGvd0z0/CvF8Dk+prQExBA/e5B6X0Gr4eUtdJM7seG2sjpW9VVHDDSmnTFW1Gd/lZHWzxKARQB71sFXckS+2WPbNe/G1KO1Xic0wznbtbZtntGO7O5HLW+6lVE2TF/ZFk08oQrQZnXGrL+IOL98UzpYMMFttb/QnRpgHX8gvoMXKlvhRh+vwTRvR+IEbae8iHewRP8BKP4K1CmuiAKAQttIFOKvzZQaaNBvtnjlbyzU62gHASv3bquqTWJul66S7+qcfB0KJ732RpjZHWnCIL6lDnrFKq5vkPTeXfn6oSK+Du0LFzCDZCynvuH4cJDeUlBVJXnBh2GOAJyHSlBXVMroQg6K7lhLq4WUo0TRu7z7qJBaQ7HCfu0vIXdjfwbGr8/ELCUGKhEOPUQMphyLXc8FZTw6XSf2UNSAv7ia59hB8JznK7j+U/souyU8c5P9LeG2PYgaBEsDH54rYjd0S9hVKLEOqBKYWkFkgB2I7pQNonkU4vV72tZCvbNyFBtnxbTH2BGK5adEhuuUDTg16LgBnAHZTIIfCm+BTDCOW/wN1eidWNf0yxUPl9EARFUQsgsvw2JBJyYQCBNne9lFGzyaF8lCl6YGABJh+xJlxzn4Ptqk+5m8XK4ODVAZ+pZWsBrgp287JjR8Xd8yhOF8lFoBsBwVExqxuEgwnim94jdVzW6b/j0Y8J5RkGht1epHkPEAZvOuoNU2HE16bh859FnYSaTh13zgMbedFaFBrfkZAKX/CTV3eQl82BsBq/K8Go7TdtnXiuDe9+QG9hVx1zNy/enhK9B/fpPkIpqdag0LxJBmHBiWkJ0+buBY6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vPv8lLVYgy 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: Move pagetable_dtor() to __tlb_remove_table(), so that ptlock and page table pages can be freed together (regardless of whether RCU is used). This prevents the use-after-free problem where the ptlock is freed immediately but the page table pages is freed later via RCU. Page tables shouldn't have swap cache, so use pagetable_free() instead of free_page_and_swap_cache() to free page table pages. Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) Reviewed-by: Kevin Brodsky Cc: linux-arm-kernel@lists.infradead.org --- arch/arm/include/asm/tlb.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/arm/include/asm/tlb.h b/arch/arm/include/asm/tlb.h index ef79bf1e8563f..59854c6b97bc5 100644 --- a/arch/arm/include/asm/tlb.h +++ b/arch/arm/include/asm/tlb.h @@ -26,12 +26,14 @@ #else /* !CONFIG_MMU */ -#include #include static inline void __tlb_remove_table(void *_table) { - free_page_and_swap_cache((struct page *)_table); + struct ptdesc *ptdesc = (struct ptdesc *)_table; + + pagetable_dtor(ptdesc); + pagetable_free(ptdesc); } #include @@ -41,7 +43,9 @@ __pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte, unsigned long addr) { struct ptdesc *ptdesc = page_ptdesc(pte); +#ifndef CONFIG_MMU_GATHER_TABLE_FREE pagetable_dtor(ptdesc); +#endif #ifndef CONFIG_ARM_LPAE /* @@ -61,7 +65,6 @@ __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmdp, unsigned long addr) #ifdef CONFIG_ARM_LPAE struct ptdesc *ptdesc = virt_to_ptdesc(pmdp); - pagetable_dtor(ptdesc); tlb_remove_ptdesc(tlb, ptdesc); #endif }