From patchwork Wed Dec 18 13:04:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13913617 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 8A41FE77187 for ; Wed, 18 Dec 2024 13:05:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1CCEA6B0099; Wed, 18 Dec 2024 08:05:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 161546B009A; Wed, 18 Dec 2024 08:05:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F11E36B009B; Wed, 18 Dec 2024 08:05:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id CC0AA6B0099 for ; Wed, 18 Dec 2024 08:05:55 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 68BE4C0DC3 for ; Wed, 18 Dec 2024 13:05:55 +0000 (UTC) X-FDA: 82908100800.19.F670F81 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by imf09.hostedemail.com (Postfix) with ESMTP id C53CE14001A for ; Wed, 18 Dec 2024 13:05:31 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=IwHLwzm0; spf=pass (imf09.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.180 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=1734527129; 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=qA0mhWnXo6upWemI3POPEc6VJyAkyxFJggkOB6WNq2k=; b=kXM6JASTBaz3Yd6pfzfqxgbifp65LuwSI8OChPEVjYBPKRSr19gPwlJ3CSZfUV4GFa16pd 0rpjiD3SRdCCAifY2hXFDR5lt3cvOKHMNSiEaE6eAwokocbJspvWSZA+CmMmoL/1brew8I EJIdqGWH/YNurWYQJwlccPS9ha4dMVM= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=IwHLwzm0; spf=pass (imf09.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.180 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=1734527129; a=rsa-sha256; cv=none; b=GzdC0gOZtsMBWKut6gx5/wJuglJwJHVRWDiluMvYJeO1qlSL3Lj67nJqvL60LT21eC909Y O8L/wKZ30ljzw7mREjZw7iptYIykfeLYLE1LgfppE01CO3tmcvRSEesrgqYuH51633twUs D2GmEvRT3+GhtxPbLoQA2dCdGK7V6FA= Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2163b0c09afso57214295ad.0 for ; Wed, 18 Dec 2024 05:05:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1734527152; x=1735131952; 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=qA0mhWnXo6upWemI3POPEc6VJyAkyxFJggkOB6WNq2k=; b=IwHLwzm0yQ8V+eDK4LYBT1dPs2QgxPMbTgRIb+sZGERcZN5eYakVf21S3+iE/CRQ9b 9MDfWkfpQ7l/8q21zrv8wj0FeQConjjQcXJY4VeXn9RKDDbAYkIDLZUNhs/Mcze5JaWo t3nSVPmQmjf1v6Hsv4MFkdDvbIEs/EtvwRK9CZVA3ez22FDw/2YGghQt7INxRJKGJI5r TsAyXgdG6bm/C5FuPnlrr7iYWX3gVApAgO+sOFsikpGTr1zV3D8IkV9bStOkM3bEIy+a zsIQTPFPt+UdJnyp8TngsINSJ6OfoHAloZdFnUGLZw3J0HPBwjD39ISnXzfUwvS9xcsw aqkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734527152; x=1735131952; 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=qA0mhWnXo6upWemI3POPEc6VJyAkyxFJggkOB6WNq2k=; b=CEwrwn7R8itkOpBHyV6xDc8MtsyqH+XIP7SxV0kWBeKLU6Dt8rvFWVu3LMshrCNbpR Cd0VsuDeDbAJ1bazNw3FMUbFyRYMysu7BWVTGavnDhGt/K2kXMEHA1nLvT5vLVOxZ/t4 v99efd/Oowk5QVGA4Ahew2ItV0M77hNkvUu83bsAtw4WSkOi50VpmgpKJc+8WZsMg2WK pW+K8opM0bMmm0cKj8m4ohPTP3FmnjYp5vhZggZKM3O/g/uGXmn0yOKYcXZ1Vaak3R/5 tIHYVyr1LYwYDsRdl5vWPkxvMrWyDKUxrFZbithFksIuFSD0rJS7nVmk6mRq08HmlrWw AYUg== X-Gm-Message-State: AOJu0YyXOsfpC3jGrcjrAqcjEUznODh0VitlGCZWe1X0ar3tW49E5mEQ mZkrNc/hdPUdoJ5jdgxBROD5XUxzNciyJ2uZHKsHQkD7flkMPjYsaBduYvE5xLA= X-Gm-Gg: ASbGnct2Bv2fGWohNUfS60KyAdMJVC5CZVHWw+Al6wUqJNatamqTYX8kFjKGkE4o1+N Zr20SGHVSz/3O4DvR5kZkLSXJOk3HTQI+Zq2/vqF8+oP/X/7gb8bNz2zl7JV6pYiWKTKRW4qh/X p93S9BLsX0wGgietxGml67PGvuMikgHzcdellDV+RqHnW8vCOUc/Ot8jzk2A5DK4w/8872qNVWJ cOFyR3S81lz6OVh4bewob/Igk2LMBa6uoMzhZcuSu5S1yodv+Z1SWiUilwtmxSvKJXAZMiIvcvS 3Ro97wK7ydBJIsddoz9QHw== X-Google-Smtp-Source: AGHT+IFdeNYkaToIEDdUvkBTd8lP/0QrRZpL4HARu9WlaN/FvfyhXaaWSW9JhSu0jLr2tRkQ6EUdVw== X-Received: by 2002:a17:902:f68d:b0:215:b058:289c with SMTP id d9443c01a7336-218d70fe050mr36430515ad.8.1734527152123; Wed, 18 Dec 2024 05:05:52 -0800 (PST) Received: from C02DW0BEMD6R.bytedance.net ([139.177.225.238]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-218a1db755dsm75751825ad.42.2024.12.18.05.05.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2024 05:05:51 -0800 (PST) From: Qi Zheng To: peterz@infradead.org, 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 Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Qi Zheng , linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 06/15] arm: pgtable: move pagetable_dtor() to __tlb_remove_table() Date: Wed, 18 Dec 2024 21:04:42 +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: C53CE14001A X-Rspamd-Server: rspam12 X-Stat-Signature: fx5m4pgmqodoyry7pjnhkg5iobkmnur8 X-Rspam-User: X-HE-Tag: 1734527131-950737 X-HE-Meta: U2FsdGVkX1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/rpGHwuXMPsKj1SqZafOVkDg1t+Op4WpQAzvrTjn0vvBKk7CAlxpG9tRGSYVtsqt4XtUqTuqaSYPXQ8wRvTJvjSonvaszeNBXd85QxnMqiXPMpgj1H1E5tQNVQ13koneNN8qOlqwd2U9sznf02/TJecJ/LH8LoXRzWTB1KRsnIBhn/a0C8LWLkkQ8JnQrVQ77rcg+f4XnZeE09zp1PO4q1BgZlFIdBz04oGSY7g/TUyc25OjFC/GhkucO8brn9oUHmrVjHj1QvHUr0NYAq58qwwu2q51zvlQlt+iq1+PY4DDye8SKJFSVAzdhxyjyH0G98D0smsHc+8mHEfGardJUN8iviLTBtzA94jtcFK2W+8HFvRTKWXNo= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000018, 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/arm/include/asm/tlb.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/arch/arm/include/asm/tlb.h b/arch/arm/include/asm/tlb.h index ef79bf1e8563f..264ab635e807a 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,8 +43,6 @@ __pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte, unsigned long addr) { struct ptdesc *ptdesc = page_ptdesc(pte); - pagetable_dtor(ptdesc); - #ifndef CONFIG_ARM_LPAE /* * With the classic ARM MMU, a pte page has two corresponding pmd @@ -61,7 +61,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 }