From patchwork Fri Nov 22 10:12:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13883026 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 994D7E65D3F for ; Fri, 22 Nov 2024 10:12:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2B0746B00C1; Fri, 22 Nov 2024 05:12:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 264476B00C2; Fri, 22 Nov 2024 05:12:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 101416B00C3; Fri, 22 Nov 2024 05:12:32 -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 E143F6B00C1 for ; Fri, 22 Nov 2024 05:12:31 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5CB921211D5 for ; Fri, 22 Nov 2024 10:12:31 +0000 (UTC) X-FDA: 82813313730.03.EF446BD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf05.hostedemail.com (Postfix) with ESMTP id 982A4100007 for ; Fri, 22 Nov 2024 10:10:47 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HZAmrM0e; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf05.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732270162; 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-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=jBafrgP5HxGm/QDUZj/NqLP1VcubbKCnQ9XDzhE9RrE=; b=NEn10kn+afJlDa6CBIwkXCWI0YoEl7FLaj3Eb0aw/6JofeYfbTrD6+c2J0zp+G03kpZLEp DOr3N8wgY1F0ce7egcjbsS/yNIUDTyMVdZI927tzIdX62BfpVybO+roEGqT512RZQyvDXd j64j5VBkB67WnB3PUu0t9Q1FW9PWCEU= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HZAmrM0e; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf05.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732270162; a=rsa-sha256; cv=none; b=5HZRJq2I/JanjV9YXXnr9MjeMoCTPF8n7xnRWhhdqB8RLgIX4Oz04bJCzd8iH5FyhreKUE 6xmKG6h3SwVqrSLSUBMFFZPxUA3xr1ndtxSpO6mXRaDB5H1m/FOEQlF3Cy3Of/Qo1QjNwq S3CaISlvCgIGBYPFBME3f1z/sjWLk7U= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732270348; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jBafrgP5HxGm/QDUZj/NqLP1VcubbKCnQ9XDzhE9RrE=; b=HZAmrM0etEeiAxk1jyGcBIoUL7wzJRI3OqO+xxX9DvdIs+N41P89YBP4AGThn9+C3h/uOj VKWqRcuTzRbcExZA2k0/kqHK3T6l9igZy+3w6Jd0koxO0nLJPl3gYjJE9lrD/LL4wl4TpV uQZTrBGG0de8pEW7EoKfcs757rxYyO4= Received: from mx-prod-mc-04.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-501-M3OJm6p8O0KqWWwQY26wxA-1; Fri, 22 Nov 2024 05:12:25 -0500 X-MC-Unique: M3OJm6p8O0KqWWwQY26wxA-1 X-Mimecast-MFC-AGG-ID: M3OJm6p8O0KqWWwQY26wxA Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 30A6C1955F69; Fri, 22 Nov 2024 10:12:24 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.22.64.129]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A5E3230000DF; Fri, 22 Nov 2024 10:12:21 +0000 (UTC) From: David Hildenbrand To: kexec-ml Cc: linux-mm@kvack.org, David Hildenbrand , Masamitsu Yamazaki , Kazuhito Hagio , Matthew Wilcox Subject: [PATCH v1] makedumpfile: fix detection of typed (compound) pages (Linux 6.12) Date: Fri, 22 Nov 2024 11:12:19 +0100 Message-ID: <20241122101219.936746-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: D4yTUCmqY8mglpWjQwCKzbHOCacXDcpzELHLzFi3hZA_1732270344 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Rspamd-Server: rspam04 X-R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zIun SGhVE/0YuWfIP6QB4yfacdqvs4bQSk1Q96Xd710OGUph1rmIKtqsPJET/6PA0z9PlDzpgIhsu90Im9F7sxdBaILV6xkGD8GrimhN9ycOo5y2izxkLTmvIMgvhcSYT9ONSCYDlcOK39vCpud5QQvsNxkxRe7zjCXawqxiAedHoWXod9ex6+1uvHaZc9dvFYadmJxaDU/6DBvPoDpDflGBFOuNgzSfYVkXUO9D6pc6qsKnN187cBJsv4zaCl53benmZ9E3wSRldpGyjXMKwwAz6uV90ksIfiv5uIKrxFFlP7T59CTlgyWUL22/mPdLK/saQUB+q9LB8eO0ElJg+VmARQcBOSg7/JA9dc5rzAh5kB1YGYyCnwHQq6EStPRHtqQbLpFXxLwzrSAgo9lyx8dy4/Uo5ZkRIDKDs3ZKV5opryc5ku1GKKtA3JqcXUUO1PkDCkA2NVYdYfytLDkzIVeFFeM/wh2Vjbm1KMe2M2uxLTBeqcSE= 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: Ever since kernel commit 4ffca5a96678c ("mm: support only one page_type per page"), page types are no longer flags (PG_slab, PG_offline, ...) stored in page->_mapcount, but values stored in the top byte. Because we currently try deriving flags from the mapcount values to check for slab and hugetlb pages, we get: (1) "false positives" from isSlab(), making us not detect free (buddy) pages and offline pages anymore. (2) "false positives" when detecting hugetlb pages. In the common case we now simply dump all memory, and fail to exclude offline and free (buddy) pages, assuming they are all slab pages, which is bad. We should just consistently compare the page->_mapcount with the unmodified PAGE_*_MAPCOUNT_VALUE, like we already did for free (buddy) and offline pages already. This also works for older kernels, because the kernel never supported having multiple page types set on a single page, so there was never the need to derive flags from the PAGE_*_MAPCOUNT_VALUE. It is worth noting that the lower 24bit of the page->_mapcount field can be used while a page type is set. This is, however, currently not the case for any of the involved page types (slab, buddy, offline, hugetlb). In the future, the kernel could either just tell us the types, or provide a mask to be applied to the page->_mapcount ("bits to ignore") when comparing the values. But, there might be bigger changes coming up with the "memdesc" work in the kernel, where the type would not longer be stored in page->_mapcount ... so for now we can keep it simple. Link: https://github.com/makedumpfile/makedumpfile/issues/16 Cc: Masamitsu Yamazaki Cc: Kazuhito Hagio Cc: Matthew Wilcox Signed-off-by: David Hildenbrand --- makedumpfile.c | 6 ++---- makedumpfile.h | 2 -- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/makedumpfile.c b/makedumpfile.c index b356eb3..bad3c48 100644 --- a/makedumpfile.c +++ b/makedumpfile.c @@ -280,8 +280,7 @@ isSlab(unsigned long flags, unsigned int _mapcount) { /* Linux 6.10 and later */ if (NUMBER(PAGE_SLAB_MAPCOUNT_VALUE) != NOT_FOUND_NUMBER) { - unsigned int PG_slab = ~NUMBER(PAGE_SLAB_MAPCOUNT_VALUE); - if ((_mapcount & (PAGE_TYPE_BASE | PG_slab)) == PAGE_TYPE_BASE) + if (_mapcount == (int)NUMBER(PAGE_SLAB_MAPCOUNT_VALUE)) return TRUE; } @@ -6549,11 +6548,10 @@ __exclude_unnecessary_pages(unsigned long mem_map, */ if (NUMBER(PAGE_HUGETLB_MAPCOUNT_VALUE) != NOT_FOUND_NUMBER) { unsigned long _flags_1 = ULONG(addr + OFFSET(page.flags)); - unsigned int PG_hugetlb = ~NUMBER(PAGE_HUGETLB_MAPCOUNT_VALUE); compound_order = _flags_1 & 0xff; - if ((_mapcount & (PAGE_TYPE_BASE | PG_hugetlb)) == PAGE_TYPE_BASE) + if (_mapcount == (int)NUMBER(PAGE_HUGETLB_MAPCOUNT_VALUE)) compound_dtor = IS_HUGETLB; goto check_order; diff --git a/makedumpfile.h b/makedumpfile.h index 7ed566d..2b3495e 100644 --- a/makedumpfile.h +++ b/makedumpfile.h @@ -164,8 +164,6 @@ test_bit(int nr, unsigned long addr) #define isAnon(mapping, flags, _mapcount) \ (((unsigned long)mapping & PAGE_MAPPING_ANON) != 0 && !isSlab(flags, _mapcount)) -#define PAGE_TYPE_BASE (0xf0000000) - #define PTOB(X) (((unsigned long long)(X)) << PAGESHIFT()) #define BTOP(X) (((unsigned long long)(X)) >> PAGESHIFT())