From patchwork Fri Jan 24 21:37:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 13949944 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 86739C02181 for ; Fri, 24 Jan 2025 21:38:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA5C76B00B0; Fri, 24 Jan 2025 16:38:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E5575280079; Fri, 24 Jan 2025 16:38:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1D70280077; Fri, 24 Jan 2025 16:38:14 -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 B49476B00B0 for ; Fri, 24 Jan 2025 16:38:14 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 5B4FE1A1942 for ; Fri, 24 Jan 2025 21:38:14 +0000 (UTC) X-FDA: 83043658908.22.FBE2E83 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf17.hostedemail.com (Postfix) with ESMTP id 7BA0740015 for ; Fri, 24 Jan 2025 21:38:12 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fyF2ntHZ; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf17.hostedemail.com: domain of luizcap@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=luizcap@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737754692; a=rsa-sha256; cv=none; b=kKZAsZUtE4yuqtK3CXKFgXbrwTkHowQH116VMQ+U9DSISczKNqdNRXn7p3wk1GdPUnDetr CW3M2j9HAA8gckj7ArUHPhGer25rU7veJmt+i80uDmzZtGewCcZPYB8PgRXBBGCk52+9j/ S9JcAZD0o+zwsI+C0+KJ3gvVKFOLiYg= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fyF2ntHZ; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf17.hostedemail.com: domain of luizcap@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=luizcap@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737754692; 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=S1Rj0QeYO3hca/MmP35mGJM4crnyiUncOhL6KeywySY=; b=TDHut9Rn4k69dkeDPyYVtDPyCNUKrWZbgwRfxTuScJLqXGzZ1bMUQ3jLJFJ52vr+V6UZSO E/n3w1HyxPR1nbUrAK95fYUVtuJQ1zdvpBt6nrhA+cMZIerQlg6+KLM6Wne0IS9ozDhfZo 37c37I6+TXKTWgeLy2/7162VIOfy9R4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737754691; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=S1Rj0QeYO3hca/MmP35mGJM4crnyiUncOhL6KeywySY=; b=fyF2ntHZJjQdteGTl2nWL/I0pjrC59qNSPW4DtOkSX6QbSNBqyFM6OpOMu9pV5ZF4iWO/H u6W4mjZdPtgdKPUGSQJ3bNp0umrPFHXVRDSAFLeDYwIkoujoLoA91ruEoPavAZHMB8HoTm ldonpDU5MXVi9rDcM4uu0zWoX8azHDY= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-594-kYvpklsIOkGruIprZdg86A-1; Fri, 24 Jan 2025 16:38:08 -0500 X-MC-Unique: kYvpklsIOkGruIprZdg86A-1 X-Mimecast-MFC-AGG-ID: kYvpklsIOkGruIprZdg86A Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 599A319560AF; Fri, 24 Jan 2025 21:38:06 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.81.148]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C0D2F1800348; Fri, 24 Jan 2025 21:38:03 +0000 (UTC) From: Luiz Capitulino To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, david@redhat.com, yuzhao@google.com Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, muchun.song@linux.dev, lcapitulino@gmail.com, luizcap@redhat.com Subject: [RFC 0/4] mm: page_ext: Fix crash when reserving 1G pages Date: Fri, 24 Jan 2025 16:37:50 -0500 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 7BA0740015 X-Stat-Signature: qrbwu788u96g1ninsx3zcicd63aamejf X-Rspam-User: X-HE-Tag: 1737754692-369235 X-HE-Meta: U2FsdGVkX1+KP45P8xPD7Pm0qzAmtD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/IfdLvovMJpox8Nu9EhDQo2OzsuLlC4gDsil740ZoM+sERS3jDzYZpwLSFWRSnrpypO6d1ENVzCo5nlrqrWaoyqQ63+llVZjBuHqXc7WZgP2GSFUDTIE/AnxSn8NpZ2gVezTJgdYJCQLcKKAEkIETcLtPzPiZ8O0iQDdtMKMSnHOatvG9gkRyBFNEO15+bUlBXTKcMtpgfEdEVreYyWSLjLWQ== 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: Hi, [ Thanks to David Hildenbrand for identifying the root cause of this issue and proving guidance on how to fix it. The new API idea, bugs and misconceptions are all mine though ] Currently, trying to reserve 1G pages with page_owner=on and sparsemem causes a crash. The reproducer is very simple: 1. Build the kernel with CONFIG_SPARSEMEM=y and the table extensions 2. Pass 'default_hugepagesz=1 page_owner=on' in the kernel command-line 3. Reserve one 1G page at run-time, this should crash (see patch 1 for backtrace) [ A crash with page_table_check is also possible, but harder to trigger ] Apparently, starting with commit e98337d11bbd ("mm/contig_alloc: support __GFP_COMP") we now pass the full allocation order to page extension clients and the page extension implementation assumes that all PFNs of an allocation range will be stored in the same memory section (which is not true for 1G pages). To fix this, this series introduces a new iteration API for page extension objects. The API ensures that we always lookup the memory sections for the next page extension in the iteration. While this series seems to fix the issue, it's RFC because: 1. page_ext_iter_next() uses brute-force. David suggested to maintain the current API but only do a memory section lookup if the next PFN aligns with PAGE_PER_SECTION (ie. it's the first PFN of a section). But I couldn't make it work: I was getting random crashes and RCU warnings 2. It's very lightly tested Luiz Capitulino (4): mm: page_ext: add an iteration API for page extensions mm: page_owner: use new iteration API mm: page_table_check: use new iteration API mm: page_ext: drop page_ext_next() include/linux/page_ext.h | 15 +++++---- mm/page_ext.c | 55 ++++++++++++++++++++++++++++++++ mm/page_owner.c | 68 ++++++++++++++++++++++++++-------------- mm/page_table_check.c | 21 +++++++------ 4 files changed, 120 insertions(+), 39 deletions(-)