Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp226865lqj; Sat, 1 Jun 2024 16:39:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWaeEre2134iXp4Mk3l6NDJ2KwIz2f9lFFrMfknqN+fFa/A8774J+db5b9+aMJ/RyN3eP735iyAE6W2umZ1CxM5gKgcoq4SXd0t5enKPA== X-Google-Smtp-Source: AGHT+IFjqEslcrwNzZI2FWfgaFV+MJul8czwZPJ3G9RoXGNmsQMWoKoAQJ5P8LNukJ2XOBwPypqF X-Received: by 2002:a50:8ac4:0:b0:57a:4af6:319e with SMTP id 4fb4d7f45d1cf-57a4af632b3mr1492583a12.1.1717285140194; Sat, 01 Jun 2024 16:39:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717285140; cv=pass; d=google.com; s=arc-20160816; b=wRjzADACrlsnVqFWwFNEzVHzxnVRYzN+N7hmOgC9hVgxcq4LmWKQMgevljZbpieGH+ 0KwmFsC56O32Fxf5Uv+vlh81wZ05UTaDEJ3lhJWiyv5gg49GJfEOuGiqEB72e7SHL7nu m1GHU68291mGUBBJFUrzPPAOCJb4e0b0V5xIITk/LM6oU7WdYpPkwCgu4naXYBnRcyiX wXBL4++uvShI3dYWX8j5TYa/tuIoeIifUHPsWwxB8BUicEn7mVFsx/A+BufSrEV0wy1P jh+NNcEMsx3XRU+um1AJJVGrUmrBQz1koUN9Dgu1y0cR9N7d4x+8LjbIVS0U7heMxzu3 u/6w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=FPlK8KMOgiMH8BL53S6QmZVvN+9Fwb20HpIRKgBlI3A=; fh=uXx3xLmm9TMFbMT4U8jG01gL5GKbTeAzJvFm93Wv7ms=; b=Jp5W+FDcUWrn8hFhe/2qn2GUcLEK8OTWmywypxdiWNMh2Nk6w3u36T0NznEHhujiDv bx2M+d/HTJ+lkmcJxN9KyWfT6p9Wmc5NzvTQ2kFcLaCSKXmSiNnHCY4hW4j8qelH7tHG H14m6ye8hOcOAnSH/O/PDhQPzBBhlGXuBg2rj/OA6nsYRdzbTB6Vy8Exke4r6I+q4jI6 1/Lyrl9e+C0vA8vETb+Aemzvjx/QOnlMmtf9G1PtFgxVSgh3OG8jMYXL13ixEQgvbd4A zEfbF6RzsLXtTC/HqAWqSDhvQSSSzmQp+aEJOQuIvR/6cmMC1s8DHQXPKGrC60Npw5Vt axiA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="yRqlS/sR"; arc=pass (i=1 spf=pass spfdomain=flex--surenb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-198046-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198046-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57a31b811bdsi2478916a12.105.2024.06.01.16.39.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jun 2024 16:39:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-198046-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="yRqlS/sR"; arc=pass (i=1 spf=pass spfdomain=flex--surenb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-198046-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198046-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E83941F21789 for ; Sat, 1 Jun 2024 23:38:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 223C547A7C; Sat, 1 Jun 2024 23:38:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="yRqlS/sR" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 D966444366 for ; Sat, 1 Jun 2024 23:38:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717285126; cv=none; b=QFl6E+sJ9m1XSp1ZeInqTZdU2mcJb9NSWKdI0ZHSpvJHCxj6yQL+yjEr+PmHrbdCBVN5VaTsva9eqPP8yFzC3aL9r3t7PoG13q08LsscasZYeBGYKyVVAmpqrePk6llU1BDYN5SG8EqK+CAiKWMGDoEzRgc01HSZJLqDWSvstR4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717285126; c=relaxed/simple; bh=YGSo7bG+CVxTrsXCdfBRBuScN4cwkutrM9kK/+P5JwQ=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=Qxx31MjM7+1+kzrAqAjR00HRsIZWkNem1eaQ4t+N/dx0L0lkeJbuyomFWLT+0t7ue/xxjnsTlYNQwYsEJYOTYkh142uxCvCKQv3DHynvYMdyk3luqg7YOpMOktX8Xnbi/RUTmUOQYSmsmWunz3kG7uQSl4WlscfvXIH5makvLiQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=yRqlS/sR; arc=none smtp.client-ip=209.85.128.202 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--surenb.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-629f8a92145so39465547b3.0 for ; Sat, 01 Jun 2024 16:38:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717285124; x=1717889924; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=FPlK8KMOgiMH8BL53S6QmZVvN+9Fwb20HpIRKgBlI3A=; b=yRqlS/sRirV602MobLDL8IVK3+OjkYx0jscuRGCqWZ83KgUA2D3UpBmqIX2lToXUH+ +uLgv6+QvyZPJD+18rfoDFksjzq/P+XYu/fL7WA70Hcm45Sg5jAqbajzuuDslkr6gmNS VFU7PsmNeNU/V4WunONPJKR/3UxGUvjyCrZrn50yxuwVkYVPX7EzJ2XSyvTRjfVK74Vv k63P7JJi33CnAEFRzELU8nhxzQM1SmXFDBBTJVM3+b9x4gSOMhlvfiuHk4QCfUnbd9tU bn9n/Vh4GLJhC6zbuEfElh2Y5zPVhbQ7RlwZQ1cQoWtChltzv+1J6lg9ErVqcQW4WUeK pBYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717285124; x=1717889924; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=FPlK8KMOgiMH8BL53S6QmZVvN+9Fwb20HpIRKgBlI3A=; b=k8pbS3Fl366JVW3zy19ELjV3QTM4YpdOOxH7DVTRr+tKVru1QM2CUZ/gVISLYdYaZC KOxH7yFZ/8qhHqNkRn3xHH/UDcKn1bpOcokYyaDxj3fp7Pt2nAf84c+83IFJzqik8Y1E D7mMDZeNAQEuTquk0uty4wA+gZZx+3B9Cx0fcKegPcaRFzbz6fcCHJFQSbxA1vusRX7q Uj1L3OCH/nBdTwrTNtCaKkV239UrYkKd91PHbQeuxBOmfmyWf4MTl7LIsS13gAf6Fv6J xpB0VTCIY85bm+JyFE4KRylTTYgBJV2Ebs21Dx5xw5aP2tTfVAV9rEikB9Dl8g51o8bJ UIWA== X-Forwarded-Encrypted: i=1; AJvYcCW5zuxOhrHvaZNJkdgxTsojGlThQkFYfuhyDjgbysIcIPPbimMsTz1hayB+hOvY88jWmipBf36wxCPtK79TxMNqi1TuHoUP2HQ9399U X-Gm-Message-State: AOJu0YzjlGdJPp9mHsRYQgrbkyFyIuI3BrBpV4mmDXHnVhXytVe9IGg7 soBZZxG/LQ50MJUkhhwjUudOfRfZtmz52QEYEi4zXBncig+8OulMRfaD+LKDDqLo566ALB5ZtF4 +KQ== X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:81fd:fd40:a37b:76d1]) (user=surenb job=sendgmr) by 2002:a05:690c:d83:b0:62a:45ce:a268 with SMTP id 00721157ae682-62c79863e6fmr15511257b3.9.1717285123926; Sat, 01 Jun 2024 16:38:43 -0700 (PDT) Date: Sat, 1 Jun 2024 16:38:40 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog Message-ID: <20240601233840.617458-1-surenb@google.com> Subject: [PATCH 1/1] lib/alloc_tag: fix RCU imbalance in pgalloc_tag_get() From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: kent.overstreet@linux.dev, pasha.tatashin@soleen.com, vbabka@suse.cz, keescook@chromium.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Suren Baghdasaryan , kernel test robot Content-Type: text/plain; charset="UTF-8" put_page_tag_ref() should be called only when get_page_tag_ref() returns a valid reference because only in that case get_page_tag_ref() enters RCU read section while put_page_tag_ref() will call rcu_read_unlock() even if the provided reference is NULL. Fix pgalloc_tag_get() which does not follow this rule causing RCU imbalance. Add a warning in put_page_tag_ref() to catch any future mistakes. Fixes: cc92eba1c88b ("mm: fix non-compound multi-order memory accounting in __free_pages") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202405271029.6d2f9c4c-lkp@intel.com Signed-off-by: Suren Baghdasaryan Cc: Kent Overstreet --- include/linux/pgalloc_tag.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/include/linux/pgalloc_tag.h b/include/linux/pgalloc_tag.h index 86ba5d33e43b..9cacadbd61f8 100644 --- a/include/linux/pgalloc_tag.h +++ b/include/linux/pgalloc_tag.h @@ -37,6 +37,9 @@ static inline union codetag_ref *get_page_tag_ref(struct page *page) static inline void put_page_tag_ref(union codetag_ref *ref) { + if (WARN_ON(!ref)) + return; + page_ext_put(page_ext_from_codetag_ref(ref)); } @@ -102,9 +105,11 @@ static inline struct alloc_tag *pgalloc_tag_get(struct page *page) union codetag_ref *ref = get_page_tag_ref(page); alloc_tag_sub_check(ref); - if (ref && ref->ct) - tag = ct_to_alloc_tag(ref->ct); - put_page_tag_ref(ref); + if (ref) { + if (ref->ct) + tag = ct_to_alloc_tag(ref->ct); + put_page_tag_ref(ref); + } } return tag; base-commit: 065d3634d60843b8e338d405b844cc7f2e5e1c66 -- 2.45.1.288.g0e0cd299f1-goog