From patchwork Sat Dec 14 09:02:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13908425 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 9C85DE77180 for ; Sat, 14 Dec 2024 09:03:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B0E06B007B; Sat, 14 Dec 2024 04:03:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 93A196B0083; Sat, 14 Dec 2024 04:03:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B35B6B0085; Sat, 14 Dec 2024 04:03:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 5A2FE6B007B for ; Sat, 14 Dec 2024 04:03:42 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D615FA1C9B for ; Sat, 14 Dec 2024 09:03:41 +0000 (UTC) X-FDA: 82892975802.21.B6145FC Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by imf05.hostedemail.com (Postfix) with ESMTP id B8604100011 for ; Sat, 14 Dec 2024 09:02:48 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=lLOEnzVd; spf=pass (imf05.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=1734167008; 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:references:dkim-signature; bh=VQxGVZsKOv6M0IrGGX96lWptBM6M1MsM2naDTLaIS68=; b=BG4LWj7hBpFyx+QNvr97nDZ4xdsolDUAmIjcHBYbAKnyBq2hAT+UdeOGp2LECyb2YjybyV ON8PkDJJlYNcKCWMyXHanOBRzpA+OwEUgbMQ3n5JfD8dtSDI6DYCMAoGFUvC28ubJM9soK Zk0Z7Fp3cc41M13X1LYx/rUnjTqgcoQ= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=lLOEnzVd; spf=pass (imf05.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=1734167008; a=rsa-sha256; cv=none; b=0JVaPcI5dEzHpSS5tFDL9bfY7pnrSlLkaeHSYE2sQArfgTV+XpIs42YEa9iJ2+NYnXjgZ7 +tXMBQvij5VXr9s2f+KnFbAH7hXtgVh02grTZh4FLfN5YDTOC7xg+5SY/j7D8tFxc8E9tD CTyAQOe1KrynitRs2wUtGZhmPPtO1nk= Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-216634dd574so15331665ad.2 for ; Sat, 14 Dec 2024 01:03:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1734167018; x=1734771818; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=VQxGVZsKOv6M0IrGGX96lWptBM6M1MsM2naDTLaIS68=; b=lLOEnzVdQkdOnS4nlXuJrbdCaP4bN2F+wqvMHmhkoYO2BoPIcj8LKMG6oaNSjpGRrG DlOOqjgO15OYCjGF5p2vXYv1TibrK4rqCnwG6hkCmSWwIooUW143gi1CsBW+XiDAb3HB tuN5DeJ9MmcWsKPCPYsWsoBUplcZPMvtHy8jIwJaVR2MZLg5hOjzdEIzDAppSa1FXUvk myAwMm3AcVl3qOf00jFut+bkiaE5p4Dukio2FJ62S1w0LSqrQPlPhV1EhcWo9CYv+EIu B7Y6Zrt6nOTKRaQlPXHLwsd41Fk346nWSMUoF+BFDJdQf1eNinkLjuHqenR9aFEe/uhJ hkeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734167018; x=1734771818; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=VQxGVZsKOv6M0IrGGX96lWptBM6M1MsM2naDTLaIS68=; b=YQxSHKzZaaG0/QvI2dNr+143m05a6o3DvFVLa+q622tHc3O1R8TiYHGbJP+MSqK2yM YjJRFNENNMHqKa7/tzm659l0HR3TcoPjKaeige6nkDeDi6TGqRuLYD/cR3Vq4r/asmzJ xaXsl1D9PwCj8En7vszL86Y5dGI0vyi/JFJKpdD92vupU/ltktX/w48TGQ4vVc+LwtOZ z07hr0KbLfizGNfPPEKf6P489aWMHSxkrtuGW9u/iYVsgpzL8ZmSTIVjz2WlP2eMQrjX +VbwVtfQzguATft7Ncj997fMqTKGfrqR/TH2VDzCRQwOd8tfQbe6jxahYDr/TfmuHD/R rxQg== X-Gm-Message-State: AOJu0YxV4FRlIbL6UjYeNXUZcYuX/AQgUIRQQjlPLIV8QVe3AAHoDhMR z3QSPKChGJQfTYgLzyCRIinXFcCT4upnrZUyztG7mY5tkDz3y5gSBg5pwsoo050= X-Gm-Gg: ASbGncvsG70xTCDPnPIyoHPFjv9EeoEdfEUh3HKwlmKTQk6r2PmzR0NPQFXtMYumR1z axMCTOluh7QBjo3ND6nj9BcA62ujlZo8q+h3QkKXzXa/WHX7JxkUuLlI+NJ/v7etEN7mjlGsjxb rWisxSu4g53y715lVfwEvhiOvAeXd3kkyGt2/8VxOGJSmRJfAGFZ12wo+xZ8F2VFXoWuw6COpfy HMh2vuh6QEQg264TqOIPnxfOmbd10s5tqZeBDELzVSxElAerX5JhOI75wWbvqHL3YAgtZBi4fgb h6a5PJzP10ZScV8sPLPOJWkfjfaU2Q== X-Google-Smtp-Source: AGHT+IFlSDv3uZE5Q5rEc2oV0IgrgqQ7AXlRsBX7UGansTakEMu3lzKwDtU1nsVJ8ZGM9DdkCxj/KA== X-Received: by 2002:a17:902:d2ca:b0:216:2f7f:ff69 with SMTP id d9443c01a7336-2189298bbecmr80981855ad.5.1734167017987; Sat, 14 Dec 2024 01:03:37 -0800 (PST) Received: from C02DW0BEMD6R.bytedance.net ([2409:8a28:f4f:a9a4:5d46:4ef0:daa9:1db8]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-801d5a90ba0sm905731a12.16.2024.12.14.01.03.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Dec 2024 01:03:37 -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 Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Qi Zheng Subject: [PATCH 00/12] move pagetable_*_dtor() to __tlb_remove_table() Date: Sat, 14 Dec 2024 17:02:46 +0800 Message-Id: X-Mailer: git-send-email 2.24.3 (Apple Git-128) MIME-Version: 1.0 X-Rspamd-Queue-Id: B8604100011 X-Stat-Signature: o7sdcoebyaei1agowiorah4h8ecj4wmf X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1734166968-955366 X-HE-Meta: U2FsdGVkX1+RnBg41TGbG4KeO++7s4U2LUqivbBmiApr0klpL76xb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tykZmsdgWMwYf/s12bUTX8MrFuUrG3hvlNTZJVQNBQHFs7N2vCrVBGRIPptE/jTXPs8AHaUqcPPbjBCG9wkYp09E36AlFddg9y2ZJmMNYxUkY49iUUS+n8Du61UXzCxCcMfiVIFX/85MzYHSEKC9WPOJdNm4pWz8oamS4+vLHokyIAm9b3LNGWzNfQMxF5KwjhDqjjGhdHa9zmns1NoVH+8pYyJULjSg9GW+yAg2yxtJuKYXAMrBiCjB8o4pNTRB+ZX+yuRVKkW5u4G3V0R7WzMAgc9Vc+diqfzvd6rJQzAHqloZ3PPkEQrzbnHw3z7G03z6BvwgpImo7etdXyHY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.002594, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Hi all, As proposed [1] by Peter Zijlstra below, this patch series aims to move pagetable_*_dtor() into __tlb_remove_table(). This will cleanup pagetable_*_dtor() a bit and more gracefully fix the UAF issue [2] reported by syzbot. ``` Notably: - s390 pud isn't calling the existing pagetable_pud_[cd]tor() - none of the p4d things have pagetable_p4d_[cd]tor() (x86,arm64,s390,riscv) and they have inconsistent accounting - while much of the _ctor calls are in generic code, many of the _dtor calls are in arch code for hysterial raisins, this could easily be fixed - if we fix ptlock_free() to handle NULL, then all the _dtor() functions can use it, and we can observe they're all identical and can be folded after all that cleanup, you can move the _dtor from *_free_tlb() into tlb_remove_table() -- which for the above case, would then have it called from __tlb_remove_table_free(). ``` And hi Andrew, I developed the code based on the latest linux-next, so I reverted the "mm: pgtable: make ptlock be freed by RCU" first. Once the review of this patch series is completed, the "mm: pgtable: make ptlock be freed by RCU" can be dropped directly from mm tree, and this revert patch will not be needed. This series is based on next-20241213. And I tested this patch series on x86 and only cross-compiled it on arm[64], powerpc, riscv, s390 and sparc. Comments and suggestions are welcome! Thanks, Qi [1]. https://lore.kernel.org/all/20241211133433.GC12500@noisy.programming.kicks-ass.net/ [2]. https://lore.kernel.org/all/67548279.050a0220.a30f1.015b.GAE@google.com/ Qi Zheng (12): Revert "mm: pgtable: make ptlock be freed by RCU" mm: pgtable: introduce generic p4d_alloc_one() and p4d_free() arm64: pgtable: use mmu gather to free p4d level page table s390: pgtable: add statistics for PUD and P4D level page table mm: pgtable: introduce pagetable_dtor() arm: pgtable: move pagetable_dtor() to __tlb_remove_table() arm64: pgtable: move pagetable_dtor() to __tlb_remove_table() riscv: pgtable: move pagetable_dtor() to __tlb_remove_table() x86: pgtable: move pagetable_dtor() to __tlb_remove_table() s390: pgtable: also move pagetable_dtor() of PxD to __tlb_remove_table() mm: pgtable: introduce generic __tlb_remove_table() mm: pgtable: move __tlb_remove_table_one() in x86 to generic file Documentation/mm/split_page_table_lock.rst | 4 +- arch/arm/include/asm/tlb.h | 10 ---- arch/arm64/include/asm/pgalloc.h | 17 +++--- arch/arm64/include/asm/tlb.h | 21 +++++--- arch/csky/include/asm/pgalloc.h | 2 +- arch/hexagon/include/asm/pgalloc.h | 2 +- arch/loongarch/include/asm/pgalloc.h | 2 +- arch/m68k/include/asm/mcf_pgalloc.h | 4 +- arch/m68k/include/asm/sun3_pgalloc.h | 2 +- arch/m68k/mm/motorola.c | 2 +- arch/mips/include/asm/pgalloc.h | 2 +- arch/nios2/include/asm/pgalloc.h | 2 +- arch/openrisc/include/asm/pgalloc.h | 2 +- arch/powerpc/include/asm/tlb.h | 1 + arch/powerpc/mm/book3s64/mmu_context.c | 2 +- arch/powerpc/mm/book3s64/pgtable.c | 2 +- arch/powerpc/mm/pgtable-frag.c | 4 +- arch/riscv/include/asm/pgalloc.h | 51 ++++++++---------- arch/riscv/include/asm/tlb.h | 18 ------- arch/riscv/mm/init.c | 4 +- arch/s390/include/asm/pgalloc.h | 31 +++++++---- arch/s390/include/asm/tlb.h | 37 ++++++------- arch/s390/mm/pgalloc.c | 21 ++------ arch/sh/include/asm/pgalloc.h | 2 +- arch/sparc/include/asm/tlb_32.h | 1 + arch/sparc/include/asm/tlb_64.h | 1 + arch/sparc/mm/init_64.c | 2 +- arch/sparc/mm/srmmu.c | 2 +- arch/um/include/asm/pgalloc.h | 6 +-- arch/x86/include/asm/pgalloc.h | 16 +++--- arch/x86/include/asm/tlb.h | 33 ------------ arch/x86/kernel/paravirt.c | 1 + arch/x86/mm/pgtable.c | 13 ++--- include/asm-generic/pgalloc.h | 61 ++++++++++++++++++++-- include/asm-generic/tlb.h | 15 +++++- include/linux/mm.h | 44 +++++----------- include/linux/mm_types.h | 9 +--- mm/memory.c | 23 +++----- mm/mmu_gather.c | 20 ++++++- 39 files changed, 233 insertions(+), 259 deletions(-)