From patchwork Tue Apr 1 03:23:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 14034323 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 15451C36008 for ; Tue, 1 Apr 2025 03:23:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 56385280002; Mon, 31 Mar 2025 23:23:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 511FE280001; Mon, 31 Mar 2025 23:23:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3DA6E280002; Mon, 31 Mar 2025 23:23:44 -0400 (EDT) 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 1FCCC280001 for ; Mon, 31 Mar 2025 23:23:44 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id CB4BF1CAF97 for ; Tue, 1 Apr 2025 03:23:43 +0000 (UTC) X-FDA: 83284030326.05.9E98631 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf10.hostedemail.com (Postfix) with ESMTP id 06EC2C000F for ; Tue, 1 Apr 2025 03:23:41 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=QtQ+N83r; spf=pass (imf10.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743477822; 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=GyTHIHtfK/M/EaItKiDbKrlUkEHiNDtcEd/dqqaWX4k=; b=n0Sp2WGeLG3iRc7HZv/ZlQclDllaIpNwfVpB5yOZFodiK+bUv0FksvItBM0vKRALesL+qY FhmDEpqD2rPb3N45SO66HrC9sgx67BVrXO5xlmGWB6KcbuQ+jUY7q1uVuZbnwPY3dTgfFY 0t0WNf49YSiYvWyrBx6/QywwNCToQ6E= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=QtQ+N83r; spf=pass (imf10.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743477822; a=rsa-sha256; cv=none; b=kUqGMXZpYNQ4f5J0lK8kXpXOkNLhUYzcSQ/PIcPGZWcv8v0/s8KQ7HsklZcD/ZumVjc/GK R44hmv4FNjvZlr0Dc+75Gr1NGDHzRvg/SXhYum/dI+WR047tTCcjzvz4zyHOEfZaDS8LXr f4OrpYL8561/If9+JYGb7zbgifZOWf0= Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2240b4de12bso74764105ad.2 for ; Mon, 31 Mar 2025 20:23:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743477821; x=1744082621; 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=GyTHIHtfK/M/EaItKiDbKrlUkEHiNDtcEd/dqqaWX4k=; b=QtQ+N83rBHdH34amnHWPIZ2caAl2UUO2bAGhA+mTEjVT9GDGQBECv6+nvX99zJFP9J J6r8Vyr9TTpgNd+C8b4yZajP39VofASKDPr0PYHu84E9DlR4eiTfZENG4NaBCnVghM2H PIoSGVGsQpNIBIXEgz2fQc5G9N43UcreaBQwW07wUi5qRK83taF/HnAAcpT1R7t+fK3X WPx+1oF7Qmai82lhM2XrmdfvqAiYjUCz+qz+jL99XzCqjlg8Wkj7Hl8i7SBD2exgkrny rQ4hBu+1WHdY1jJ+4DG5Ph0cWPA22jlJ0zE6MtMqjXfji1iOfU9qrEz9m2g7Z05cTTWW NT3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743477821; x=1744082621; 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=GyTHIHtfK/M/EaItKiDbKrlUkEHiNDtcEd/dqqaWX4k=; b=aXUXIGtZFZnp9BxwjBjZdFIjRowymHCQn+eXS2syzVsb0rKnSvLCNo5wlH76m0GMgM usFIS5TPf7t3mKdCDHyPmwIVzFM4J1Jbt8CWb7I9GzwWUpzeEb3wWojGd6HTapbHr0FJ j0jxFsuxZnnR9jyGYz4t15WsEppUU46puKWhbktdgBcTZZRQjx5QqVfSUYi14Fx+VTYx ewi9zrRnfBdsqFjKlHrC/3hpUqfIDCX42Pu+VGZ0EQ6GgcNtFtnlVeSDup9BB1CQ4OeU /WChwJQV6LK5yJ+1++PkGLQR0sO7sLIXZyv7tM5yVeGUUao+mW6DmCnCoiopPJreDJuF 5VbQ== X-Forwarded-Encrypted: i=1; AJvYcCWGj9yQRXIm/PXk1YAm7KIjHHvRo8t//DHP88HfgzFMOFcUOxlY9/+9mjZAszR/ee2GvlpZ3gweQw==@kvack.org X-Gm-Message-State: AOJu0YxTjmbjQSEOOJKO+HMWdI98oEELZVwtyxmUp1kaRo7pgAlR5TFF 5XJv3gn7yU/W1006XQtvPzI4vVSQhKvu+C0h/99Dz/kp0+s6sfHt X-Gm-Gg: ASbGncsDK4qlAYChr0Q/Uq1L75RSStdaa+buHjKXsN0nVtYobZUyZzdDD9BjoyKeAML 3/aUmuMiW3JEZIrWdF+/9NvG46/rItMq06sMGKnYXMd5ukIyw08ZypXopjiraYYoU7yKojlhbcC FHfjxi13+lWJbvbm1DJyWuXFiec2OlAbilSoEbeEc7yXW+LqzjSpCHTXcQVJxOJ2g6p1VFjZMgP USAdbvfuLNwv0LnrYU5vGn8i/+a2cxKNXxgIDu426xKAblh9efbBXrzT0IluQIZ2eiltkOL4Tb7 A/98HOuU/J4ALg/E2qgSpa8ieAZP7Ua9BGwN2hv+PtuvWwqob/8CyG4uand5NK6y6xUNLeHp X-Google-Smtp-Source: AGHT+IGbATZ37yRIwmSJcgIyIsI9pZaO2Extab2UnYDBjvUc6rmoB6R1Uotr7JtV9bUkdDI9s3wWEA== X-Received: by 2002:a17:902:d48a:b0:220:c178:b2e with SMTP id d9443c01a7336-2292f954d7cmr193286665ad.17.1743477820888; Mon, 31 Mar 2025 20:23:40 -0700 (PDT) Received: from localhost.localdomain ([2620:10d:c090:400::5:22d1]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2291eee0290sm77399575ad.79.2025.03.31.20.23.38 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 31 Mar 2025 20:23:40 -0700 (PDT) From: Alexei Starovoitov To: Linus Torvalds Cc: bpf@vger.kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@kernel.org, akpm@linux-foundation.org, peterz@infradead.org, vbabka@suse.cz, bigeasy@linutronix.de, rostedt@goodmis.org, shakeel.butt@linux.dev, mhocko@suse.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm/page_alloc: Fix try_alloc_pages Date: Mon, 31 Mar 2025 20:23:36 -0700 Message-Id: <20250401032336.39657-1-alexei.starovoitov@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) MIME-Version: 1.0 X-Rspamd-Queue-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b1tKkShcO7puG24U0h4RB4uTrJR MHkmjGq9 0x8j6AbyOXZ2FiRFB6F1R9Snn+Vv1DkjjhW3qwimQ8w9rinsNx+el5/UL6gEnWuFaUzwZ1DiNcMCwickFdK6luanAMdYLr0WejeSZe5HDePUtsmbN4fThtKg7mqT2E/rSTzxmJbpnGjeyo86Uuxq1Uzr7Suv9ocY/hDNDeuomEDobQVkLI8H2uwy3oJnTY4gflcTheSH8Cg+GhNv1wYKCcrmGg9EukYZuZDBk9JaO0arwVPYCq2Jr4zux0KV8+0B2sNsTzVIYwcus38CqNPXqsth1elSHiIaNXsuQuW8DWqw+dNS9R+MN9N0eSFV9cSJMfRe+5C0Q3ReQOdGgx9i9573Is4+cw+TaueiaabQGjh8x9IW7lOaa6FDS9XFWXOk/AtgRZ4Y+Fw5sNDY5yq9y8sXM/ll1wiLyK6D01F5zbq0Yow0hOndPkXatD4cvlujLgxY3Cf6Xwa0OoKMQ4lJP0XwaaLHMjw/2zDR/W4A0/VE/VQNIZz6Ymd0VrA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000176, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Alexei Starovoitov Fix an obvious bug. try_alloc_pages() should set_page_refcounted. Fixes: 97769a53f117 ("mm, bpf: Introduce try_alloc_pages() for opportunistic page allocation") Signed-off-by: Alexei Starovoitov Reviewed-by: Harry Yoo Acked-by: Vlastimil BAbka Acked-by: Michal Hocko Reviewed-by: Shakeel Butt --- As soon as I fast forwarded and rerun the tests the bug was seen immediately. I'm completely baffled how I managed to lose this hunk. I'm pretty sure I manually tested various code paths of trylock logic with CONFIG_DEBUG_VM=y. Pure incompetence :( Shame. --- mm/page_alloc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index ffbb5678bc2f..c0bcfe9d0dd9 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -7248,6 +7248,9 @@ struct page *try_alloc_pages_noprof(int nid, unsigned int order) /* Unlike regular alloc_pages() there is no __alloc_pages_slowpath(). */ + if (page) + set_page_refcounted(page); + if (memcg_kmem_online() && page && unlikely(__memcg_kmem_charge_page(page, alloc_gfp, order) != 0)) { free_pages_nolock(page, order);