From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0DB853EB11D for ; Wed, 15 Jul 2026 09:04:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784106253; cv=none; b=soOO044b2716vRXqK4OtLKLIxVP1Bfm4nUED3mGwbjLuNm5j9X3yFQyHm3QEcCKIpqF6sdFsFsBKluVw1nigiXXJ8JWcDL1FOSyJvlR7ZsGZ7b4qd5CyHUF3KiOMy0wb3OxCTZ7DwxjS0+S2qY2d7kVRop/5lm0GJsM4JE8Jx5M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784106253; c=relaxed/simple; bh=T132sxp6UaJ+WwsQy/GiXCN6xCpAzZ0KSvradejtUNI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=XQRkzH66kzFh7AwQ0B0jFW3eBZZqy8xVR0lKaeTmLWyG1SO/doJnmweSatsAGSOtvufetfyRIrm7V0Rc49p/BUjI3hQat6K9C+n+PBOFgRRGnNaZvrQDb6vgwOiB/keXPRUul39mLi9ZkRr1V5s2wuiSlKm0g81Ooh5XcSjok64= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ErZCpzGg; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ErZCpzGg" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-493b21b1fe8so16787185e9.0 for ; Wed, 15 Jul 2026 02:04:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784106245; x=1784711045; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=tAjEggZE5XRXoCbkcOS6/MLSgIQDuHRdiYiNvUA8HH0=; b=ErZCpzGgMGRZa9gNKYXx4yIMAVdYtEgDoNT1B0eNQDRZPo09BtN/32Wc6YLMTd8TKF 7qiuo3KBS1aIdDufYifiliP1CIJzzrhqKlpD2+h13w4JkrIBxNZSYqHzg1fHXeREwSXc EbXhLiz6oVNxkdnu8H/hZ1zWyHOLmSYk984tnPFi88G2NloROxarRtz9/AlJvT1SgHaq Q7pfHJTrjWrpWker0/QIMpWMpK3NjEWuHJJ45WUrOYQ9+DKZ9+MqaLeKpI/RmQ+5wAyO rfRcRxJDzYsGfiTcnzxJ8qtr8MmPFaTJK1L8x5/FUuqNi/hzssROPAOkltOvgT8aKqOW AxUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784106245; x=1784711045; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=tAjEggZE5XRXoCbkcOS6/MLSgIQDuHRdiYiNvUA8HH0=; b=BdXhfLzGXR8+ochYZ0Ku1HhyAvM8CAz3m7NBdLPRSBvALleCqF3q1aW6OHEkEcpFl5 D83QhXVEZiBnDdNKsDF/E3m5DBjKJoib3a73mgtw70ixfyUWZOPsV30KxPVgt2dI7xOp bg1xOsCZhmxiGG3IXnHnozk5YuMELA5MfHbGOjDeu5Obw8oBgtu0zpNmzr9Hn6F6z93v lCMyRmhVq7xjhmS1U5M6vWa+lmpCKIJ70M/b2ZAmZdJGBOiZgrF1kGKxys2aSYing4Bz wWJPYXg/aed0GZHW7QKV5NfhJpeYm3ErXvn/D9606LBGbofxn1ULQD1Q2q8/YNSenEW9 VtZg== X-Forwarded-Encrypted: i=1; AHgh+Rot6+XWaLxfo57KFwt3WpQ0Oc7bDo1VZeVJFuOncC7AR7P1dEH+xBGk+ZVNpmhu/i6kfZbs7++kNy9BRX4=@vger.kernel.org X-Gm-Message-State: AOJu0YzNSra3BEu34+Tms/QizqacNdUtoIDNYYovzMBUtK9LPqRwzIV8 sH5/uXtZQE3WidXExCAz2NSVkQS06HUKKEy8+F0moZDn9JBZri7NQjjVBcp/6KFO4h1JIAhdOZF q3lAvhjFdNYvoVQ== X-Received: from wmby15.prod.google.com ([2002:a05:600c:c04f:b0:493:bdba:620b]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:8217:b0:495:3c6d:f294 with SMTP id 5b1f17b1804b1-4953cbdc7e6mr20439975e9.23.1784106244314; Wed, 15 Jul 2026 02:04:04 -0700 (PDT) Date: Wed, 15 Jul 2026 09:03:59 +0000 In-Reply-To: <20260715-alloc-nolock-fixes-v1-0-fadc49952dda@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260715-alloc-nolock-fixes-v1-0-fadc49952dda@google.com> X-Mailer: b4 0.15.2 Message-ID: <20260715-alloc-nolock-fixes-v1-2-fadc49952dda@google.com> Subject: [PATCH 2/2] mm/page_alloc: don't spin_trylock() when disallowed in free_one_page() From: Brendan Jackman To: Andrew Morton , Vlastimil Babka , Suren Baghdasaryan , Michal Hocko , Johannes Weiner , Zi Yan , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Alexei Starovoitov , Harry Yoo , Shakeel Butt Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Brendan Jackman , sashiko-bot@kernel.org Content-Type: text/plain; charset="utf-8" __free_frozen_pages() checks can_spin_trylock() before entering into the main free_frozen_page_commit()/free_one_page() path, but before this it can get to free_one_page() via the !pcp_allowed_order() and MIGRATE_ISOLATE paths. The !pcp_allowed_order() path depends on usage by callers so might not be possible in practice. The MIGRATE_ISOLATE path probably means kernel crashes and privilege escalation if anyone ever did memory hotplug and BPF tracing on a PREEMPT_RT or !SMP build. Cc: stable@vger.kernel.org Fixes: 8c57b687e8331 ("mm, bpf: Introduce free_pages_nolock()") Reported-by: sashiko-bot@kernel.org Link: https://sashiko.dev/#/patchset/20260710-spin-trylock-followup-v1-0-affb5fe5ed00%40google.com?part=2 Signed-off-by: Brendan Jackman --- mm/page_alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 5f9873dfccc5a..46e5ea59c71df 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1559,7 +1559,7 @@ static void free_one_page(struct zone *zone, struct page *page, unsigned long flags; if (unlikely(fpi_flags & FPI_TRYLOCK)) { - if (!spin_trylock_irqsave(&zone->lock, flags)) { + if (!can_spin_trylock() || !spin_trylock_irqsave(&zone->lock, flags)) { add_page_to_zone_llist(zone, page, order); return; } -- 2.54.0