From patchwork Sat Jun 1 23:38:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13682573 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 C9D60C25B76 for ; Sat, 1 Jun 2024 23:38:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 570F76B009A; Sat, 1 Jun 2024 19:38:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 51F5F6B009E; Sat, 1 Jun 2024 19:38:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 40DDA6B00A0; Sat, 1 Jun 2024 19:38:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 2061C6B009A for ; Sat, 1 Jun 2024 19:38:47 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 820751A0351 for ; Sat, 1 Jun 2024 23:38:46 +0000 (UTC) X-FDA: 82183937052.28.2443ED6 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf24.hostedemail.com (Postfix) with ESMTP id D2DA3180003 for ; Sat, 1 Jun 2024 23:38:44 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=1SMeZrKM; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of 3A7FbZgYKCA4685s1pu22uzs.q20zw18B-00y9oqy.25u@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3A7FbZgYKCA4685s1pu22uzs.q20zw18B-00y9oqy.25u@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717285124; 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:in-reply-to: references:dkim-signature; bh=FPlK8KMOgiMH8BL53S6QmZVvN+9Fwb20HpIRKgBlI3A=; b=FlOJxOjuX2MkvL2jGNfqxWSlkk4vw3npOxRrgswFN0rDTqcHMSpAogCNyGmsfR4a+Rt+BO rrW9Cy49LdnMLvFk20Eevp7ZApHZIc55O0kSXUBi66Q2FzoFBoHKQNCZTVLw91wJBPuQdT VCOWyv2NMc3eDNELAyGhlsDYc92PpSk= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=1SMeZrKM; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of 3A7FbZgYKCA4685s1pu22uzs.q20zw18B-00y9oqy.25u@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3A7FbZgYKCA4685s1pu22uzs.q20zw18B-00y9oqy.25u@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717285124; a=rsa-sha256; cv=none; b=IlPq8KX62u4Il57YVq9oVmTJjJGRGLiKiwTzxsicAuCteKCca07rxjuPvGHsZRAHObuOA/ PO49DijK8vFl/SsK9EIR1L++a1x/K6jqJRmXUW1IIb9qGGRl5P1ILG3BedLxZce0O9qr1T gpwW0B6+8ISIE88GrnyoxxVPyARuCis= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-62777fe7b86so32794047b3.1 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=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=FPlK8KMOgiMH8BL53S6QmZVvN+9Fwb20HpIRKgBlI3A=; b=1SMeZrKMaIjRP+6n5QHJLjvOpMblGIZXtW0SE1v2E6N3HbqGYKesyUg9V4UnxDr9Re 6dZSY5YxywaAYxleAQqUBqaxCC2Rm1WJTfdvzchFWMyv2wbhOP8Lf6UHbH8TwVQe7MXM 1dhk6oTtnVKh1DdRfyis8SY0z4+VfOSxPSyFFAZ4l3Sry5mNhSpjgZ63zaqP6+9cdKPV 8coICoSuirFd2Y9LIy9jo3IxG1ppaF9soGmuzEf2w/aif93WJRBbUAt4LDQLqZFFDf9u /9HQJyIvaQP85oFPWDR41va21rUbkkoKpZZJ4DGurt1T018u3iF9SmDtT7Im8rjZw812 fS2Q== 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=OYOWR6CbcqMedK8ZAeaU3AuSVwWsEqKVSo843dXeuNWIRa1j6JJG6w76YLpali4BDw 8rdE0rHGnkbXggAKootQy7SPPyCNH8SZZyx5nw0jqaRp6tvM06yGj7sh76T+kNcEPqYW PgE9LGvl5XeQiEcUpwMI2DkgcYtybJJe0QRkpLcFZ/+zXFdjJq7HvyTZ9mtlNIPP1cek UZ3s1HF15bNarWQ0QVmFWSCdnVGEzqq/JzkgJ+aQ9yTUbm1U7BrMRd5wi6cUiXLvVykv UgxLuIOdQvvDwFbpi1DeFYjXZrZ5vseVw6GzwRpRzxTbRBFoMVBon6jDRXhJCkqI9aNv tIug== X-Forwarded-Encrypted: i=1; AJvYcCU14vkd7/BDToVz1SFqIxaiGKvVR8ix1qMNh73sQNQOR1aOmGhiSz0MBpKHiz8JH+RQQU4P4Jjpmi2vjGz9sYaL7n0= X-Gm-Message-State: AOJu0YwcBG5BqyKCwufO5sW8tE4pqPopS07ZgUbBFZKZZ0/LU7q72cpE 65chaoJD5I6Z4i1q5AdVV0y41RE3FTMzcOLQdvuLTudMMuLFFG6DymyG8sxg7mGAsYEPFHJ9S2C kRw== X-Google-Smtp-Source: AGHT+IGm8HxfFZovshJ86zIj9g/16DuQC3fPXmHv4ccZrIbf0SyFq/cubbk5fdciVXmRxizXb7oOgEqk7+A= 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 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 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: D2DA3180003 X-Stat-Signature: u55quprkqdqqsqad7q5edticg96aft8n X-HE-Tag: 1717285124-579690 X-HE-Meta: U2FsdGVkX1+zFJZLs2nPFfBI8FfvhhPo3SXaecSKmIhtNIHoY7gxu5hGtqNRfxCNr0uX+qVEF4ic8+mdzt5BihN1bPHll5W5vhZQ6ag2sgWrfpn6dMGBFZ7ulyiXCvBvYHt5ZfA5klvxnWKsC10wKhUHPdAXK9fCD58VyeQdhSticPesdzzmipkZ3DmR+hhRJHTRllobiaWo5ReHbsMWXxam3dew+p+qQC2omxfThY4rjAMB/90Rht5Qni0rhcHc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YsG87vFYiZNeTK3tmyGcydjhyOo5FcIGvvYRvRN55sNUa870hn3dYR0JyOkWRk8QjbP9utvglcX+K3fRrE7YnZ5QMjn26S4gHj7VR5TGvneCqygBP0mq4UbtNmLCpONb2gBIBDf24363kwuU43cldZz2H8E/8bPmkoFj6pjNz8XaP5hOPTj6EibLsuUMga0OwEXfmZbRQ9GXYT2tJPF5RRPXDy9fJce5VW/euURPAPeWTFZh759/pJmV1nO8gzyhuatUPjU2tblYSzG5emgOy929kfIOrtdQcerI1Ifd3zzovTAr/MNn7CVIdv4wjR5TFTceOza9fNr7L46XZbiTn3Z/eshXj7aAMOEheCMSjsHCpN8zNZGyfuDUQQk2SoQlyh8CZeA34/3ZrwxNw= X-Bogosity: Ham, tests=bogofilter, spamicity=0.001917, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 Acked-by: Vlastimil Babka --- include/linux/pgalloc_tag.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) base-commit: 065d3634d60843b8e338d405b844cc7f2e5e1c66 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;