From patchwork Mon Dec 23 09:40:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13918674 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 12A7EE7718D for ; Mon, 23 Dec 2024 09:45:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9C8D56B008A; Mon, 23 Dec 2024 04:45:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 979306B00A0; Mon, 23 Dec 2024 04:45:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8423C6B00A2; Mon, 23 Dec 2024 04:45:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6580D6B008A for ; Mon, 23 Dec 2024 04:45:01 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 2599CA0CC4 for ; Mon, 23 Dec 2024 09:45:01 +0000 (UTC) X-FDA: 82925738910.12.3756D94 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf03.hostedemail.com (Postfix) with ESMTP id 1CCFE20003 for ; Mon, 23 Dec 2024 09:44:41 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="LFZkQN/E"; spf=pass (imf03.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.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=1734947056; 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=0nJ0bdEaVLB0+13gaCQHdoBfFkuXXT3Pqta7GOjv8Bo=; b=k7lK+4q2aMEmrEGrxMnkYN8ug33z+aYfebCHNb4CnrdL5Q2WgJFsSKzCGGuMvRBNO2r6Fq TJ24cRnMf2NhTBE6C5CWUjsibjrf0kWIZDkqHAHd7um6CTuhoLR196KAEIi6PV49qa2myK CyImy+0M17mYaHNG4pdEXG63YOklmcc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734947056; a=rsa-sha256; cv=none; b=AKYVxhDUWbPYojuhU153p49oapBCv+NArN+nd7r8qe86oRwoBtrrkw/YgMQRwFgX8u97zr yXTRDOiDJgXHh90zTDVG881AIP3o2Na54PAWumJIoBisva6Wb1BKr4ZbDFKFvPoAFBLn9B koseOUsnn/VWSIumBVdddeovqi3viwY= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="LFZkQN/E"; spf=pass (imf03.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-728ea1e0bdbso3575261b3a.0 for ; Mon, 23 Dec 2024 01:44:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1734947098; x=1735551898; 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=0nJ0bdEaVLB0+13gaCQHdoBfFkuXXT3Pqta7GOjv8Bo=; b=LFZkQN/Ef+KU933qTOaxaLcJDHPPWEFqnjY3cSjkKyu1NiqlAwMtAHbYFYdmMkKhTM QR33DsbT2Rb4Fnvyt+YzjLp+mlky/431iLJ6NGYKbaiB2vzAbmPWjbOksGScQBxz1Aaw 0G2K7k+/z5ZfNz91UTWlMThv/pVGtWkjj56MJ+W3iaWp767neDOry3rB0zEJAthyMqe3 e4cc0ST0M47rWXBKZN2/663dgFFyCEYxdMwE0XNplg6HaT19g57gAVuMYsNmMghtRndq oVup+BPnBAq052boLeszDLItSAsvlzV+33D4TAuSWmT/6qkYqe5qLUk5nTtVZ0t+17/h RfuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734947098; x=1735551898; 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=0nJ0bdEaVLB0+13gaCQHdoBfFkuXXT3Pqta7GOjv8Bo=; b=OesTi+RSSIrOnbTG4bpHRZCN5hQbl+/LvrPhIA70aNawhQqbXaoKhBKUgCQlpcIBHD NyoRgtjfhxIUs+W98jJ4Y+6LVkejkfe3EHEm/46s42rRlyHRTZnF9I5RDGDh0gfn6D8R Caj5v6FE60RQKdkp18aKwG+5zYfTWM3vMfEtaaQS8ZLEb/4wOVUNfH60cx8+elKZrM48 f8zcH6+XFHdRXWYdmQu176ICRxwAbALJ7RkWyoRZb+2zxKTOocZHksSgrn2Tidx23xIW xRcKfmpMeZM9fyK+7uchTZn/Xf6wql/hcDAQFQv+9l9pXwivh64Ug2EYcIsIZYoSNcFi +HTA== X-Gm-Message-State: AOJu0YyUmyvxegJ+gx9lUFtPVZON6NU4zln279Or8IaQYoIaHvR0j/sZ kIcnMB9sY81dZjGweDkKnrqAS9ibUfsnooptZ02LaAY5hciV2jkpo0mfLI2dGiE= X-Gm-Gg: ASbGncux//J+vv14R8zpKwbFe9nzI8ICaKYwps2q8UOCJM0xCxlKL14jJaxOeh01Q+s cXwzRs7i+VDpkaCbfH6eG3oCkJA4JPyaQXc1d7coUX6osHScONz4SMdAci5r7v5HC9RjAsCtZ3t 8dw6zX+9r6/uizY1YtDTsygptXchghwglFQWfJTFW9aAxDJcH3LPGXdcIzEfFPWkE9+BRgYYppJ Txl8Xt77uMgLXRuHix6UamARQbIROGSdEwagxJ3fo7I7/TpvNisKV0DSL3EBDm9ELQp65f1vDqD 8md0KdluKClpMH4lR8Fk1g== X-Google-Smtp-Source: AGHT+IH27a1l8kT42WYYi2KTFhW6smXjjCcrkYYj/EF7HLDGUXcMfllZ3ayHCCSFU+IsHMUxZvkRwQ== X-Received: by 2002:a05:6a21:6f87:b0:1db:c20f:2c4d with SMTP id adf61e73a8af0-1e5e044b1c1mr19165305637.2.1734947098042; Mon, 23 Dec 2024 01:44:58 -0800 (PST) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.150]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad8486c6sm7468309b3a.85.2024.12.23.01.44.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Dec 2024 01:44:57 -0800 (PST) From: Qi Zheng To: peterz@infradead.org, agordeev@linux.ibm.com, kevin.brodsky@arm.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 v3 09/17] arm64: pgtable: move pagetable_dtor() to __tlb_remove_table() Date: Mon, 23 Dec 2024 17:40:55 +0800 Message-Id: X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 1CCFE20003 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: hyf4qw1fj9w36pmzmtg66piqh1m3qc4y X-HE-Tag: 1734947081-673895 X-HE-Meta: U2FsdGVkX1+ocleiPhmRqwHYAY2/+2emRxs28tEX6Fv7gehZL+PYWr9ZNRIa1GgdIpXu3jtSGNsAXJ9clKtbjCLz4AHPkRQWE/hZ5ik5t4phGWXXat2FiGSfEMO3DtEG3VXBo/TXgmKGevEHfbL8mnE0ifZhNUC5pIxFk4SJ6e2OVMU6LLDQ9o9n0mrChPerXEDn4tD99v5LEnFoYtYBenL9id8eypp/luPxHfzLkPEJBfwTjZhBvr0BfR8AWnQyYeNPDWda6GTj+P0lfy29ixQ4kUS3g9w2NPkg7r63vc6FF8zZWPfAzzs76sTdN6DTmImEeAszYyQxOKSexS8q0AcjB6lgIr+kw+/Vl9GIC3GviVltzuzPqj/sitSXAWFBDZ1GZ73Oz2pxXZMfSLc01dLA8l0dOrAdXsu9eYQnxRKfkwdPCFh0kz8QRI322Ijrjj6F2QwMvN+0sbPX8uMPmFrfOjQuhkiQSws1/xcCvsYT/35/x8lUw84TOWHQbDuQJ/TKLpTO+oT89yo2nZVVit3uGOeKESJlmFf5zW/67qK+CHfokWfciJLkRjccOy88hlgdcZE9kW9QgUEeDIWLJ677zEEemhtDn+dEjWZ5I3cxMABrSNDIT06/8k061Vhd5ax4KSHws5cfgBFz0GKkclj7hnQ0u408mtjfUFDLaF6rXHLZ21t3ko8zZ9dzowDmkJ7osjqSBUMfqqMpEa5FGyWbBMCpwE/TYnKyKY+RKvMtPnQRIWuBGLkxZ7STHeqmpU53K14b0Cc0wIGEDM8A99YYtoDw82EXS90GgauGeFtVY/Ep/2He44UaGjE9QqwBs30ilaImWFhSYbW/9QOoV8UyecKgzTQ8/m3jEOpn5L9Qka66xdtQPSotFYPt9KSE+ADxXJvxMN6RIYh5Ts2nFhhA99ZciG3uYPR8FAHfMp3K7jNYBT+Euce71wFU7TwEtMNj1cM6htHxhAcynUZ XBwKFEoa EQM3ulrCgB8TEODQNOQf5EU/PE5Lunpv6AXWWeTwLm0TMZB0m7FIm1YmZ6Ej5rY72gPXBI0+MKAkxuViZVgFaJmYz7//q4iqXot/T8qJFk0mFNhyOG1TPJi3UxMRY9ep34RuKlVDp9hiUHzOsuCrm8TsLE8yBFJgexoP8Vgpm3zyA69CJ04tJN5xFRgefIGef3wLmjDHJZRlB2/TPBYs30mzrOZxPAtfSVcW5Zy5XM3SgfQFH/O1ejaU9bX0rHk98tinuppLVfRNlRu3C9bROY/rZ/y0BjZrzyeJ3mZT2INC8EXcSKsOaVorfiWwKTyeqK+rCZK0wGJwwf1sX9e3r2pRBFujRXSE6Hv/MzSt0JeKznYSjIWKd4evSBnaY01I1ST8NiMB7SfRzmleItyqUXLCwZgvmtZOJkX46Zi/+/bqTCSDIb/z2Bg0VOc+lvE/5GOd32ru+22OQnBdsjoGfcr3Att5w1MDEVDdGpgTlgiifMkwX5p1hQH59g8sWGM2V1jNbhkNIVz5U1zdei/H0I5AENpVpiDf+PmoI9kRYFkMIsFX4as1AU4RGaw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000011, 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) Cc: linux-arm-kernel@lists.infradead.org --- arch/arm64/include/asm/tlb.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/tlb.h b/arch/arm64/include/asm/tlb.h index 408d0f36a8a8f..93591a80b5bfb 100644 --- a/arch/arm64/include/asm/tlb.h +++ b/arch/arm64/include/asm/tlb.h @@ -9,11 +9,13 @@ #define __ASM_TLB_H #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); } #define tlb_flush tlb_flush @@ -82,7 +84,6 @@ static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte, { struct ptdesc *ptdesc = page_ptdesc(pte); - pagetable_dtor(ptdesc); tlb_remove_ptdesc(tlb, ptdesc); } @@ -92,7 +93,6 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmdp, { struct ptdesc *ptdesc = virt_to_ptdesc(pmdp); - pagetable_dtor(ptdesc); tlb_remove_ptdesc(tlb, ptdesc); } #endif @@ -106,7 +106,6 @@ static inline void __pud_free_tlb(struct mmu_gather *tlb, pud_t *pudp, if (!pgtable_l4_enabled()) return; - pagetable_dtor(ptdesc); tlb_remove_ptdesc(tlb, ptdesc); } #endif @@ -120,7 +119,6 @@ static inline void __p4d_free_tlb(struct mmu_gather *tlb, p4d_t *p4dp, if (!pgtable_l5_enabled()) return; - pagetable_dtor(ptdesc); tlb_remove_ptdesc(tlb, ptdesc); } #endif