From patchwork Wed Nov 25 11:22:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 11931241 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD58FC5519F for ; Wed, 25 Nov 2020 11:22:12 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4A16020857 for ; Wed, 25 Nov 2020 11:22:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="E8EB971J" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4A16020857 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B30616B0071; Wed, 25 Nov 2020 06:22:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AE1CD6B0074; Wed, 25 Nov 2020 06:22:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A1EAA6B0075; Wed, 25 Nov 2020 06:22:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0031.hostedemail.com [216.40.44.31]) by kanga.kvack.org (Postfix) with ESMTP id 8D8486B0071 for ; Wed, 25 Nov 2020 06:22:11 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 5AB41180AD80F for ; Wed, 25 Nov 2020 11:22:11 +0000 (UTC) X-FDA: 77522701662.12.girls61_25008f827376 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 3728618010610 for ; Wed, 25 Nov 2020 11:22:11 +0000 (UTC) X-HE-Tag: girls61_25008f827376 X-Filterd-Recvd-Size: 4757 Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by imf10.hostedemail.com (Postfix) with ESMTP for ; Wed, 25 Nov 2020 11:22:10 +0000 (UTC) Received: by mail-wm1-f65.google.com with SMTP id a186so1678084wme.1 for ; Wed, 25 Nov 2020 03:22:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fkeU+R8hqLO6M6EoSSQ3Z29F32RAQfX44gbdUvYuYKk=; b=E8EB971JHAm+5d5XLDQX6YbXCuqVqPuLgJ1Hz/bldINFx2P2ms9DadykgPwgXwrGez n6jOMRdIehPlp1KETAoMMKWh98ua8fThgESdlBnfaR1wa7rL+Xx9CHCUiUWKryhZ4anl kSbdcLGUGcf5/0oFw0S4p9gz7zJOa733BapxXQ9CyBBxq5NQpd2FC2yXckJZN8ha1pAy 0CCr/igSBRaA1KG8/Ths79oGhK4k+IGFBq6MlvlwXskbvhTDZZ83hfPWQKIP2PdOMzEG G7LEFCmVvG24nc0t17bK+/gyIyzx9y/OqEfFb8v5u8EbxAnL6dJvNFrgCKE7dh/IojW+ 37CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fkeU+R8hqLO6M6EoSSQ3Z29F32RAQfX44gbdUvYuYKk=; b=K7ImM3yuL1qWESYp7ehC6eShc32Y7dkgVLllshK101oJB6mbJ7OQw6GBKkI9OvFmHQ 21wxMC1wnO+zxjQQFXq1smq5Q76jfjERSU/Lz8/eYGbxFPPAbMnu1lyycT7UzFfIgKZe 4K054XEtP+KfbL2Fm8vsb9C03FGKiiw/6maz7WA1AUK1sluJ6xnKLAlW/RV/0gJ7wCEy Fg2wEhzENa7In01Ev+cp/GXFYGZ5c9xVrP6Z6raZxRDrU6euDZxeqObadrcinyXBqQOI Yrl2ZW+blfCOnVgkeKq28oJtcCNmGUNU/u7ofgmTropuJqRYLVsOI60szTnDi7XSYA6b Iyug== X-Gm-Message-State: AOAM530KlyPflFMnvFHAIqUihaat77OTDKZWOZcqG/3i95K2BlZHoFub 0P0FuVlqohPZ5nPNMP+mQEQ= X-Google-Smtp-Source: ABdhPJxPtFUEP3o1/V4ITcxbabd0jUN6MY3lbmBnmAFzZ4At5rGyoSPRDyoiSzCvocglqxVj8mNKmg== X-Received: by 2002:a1c:5a08:: with SMTP id o8mr2821605wmb.142.1606303329695; Wed, 25 Nov 2020 03:22:09 -0800 (PST) Received: from localhost.localdomain (host86-145-187-174.range86-145.btcentralplus.com. [86.145.187.174]) by smtp.gmail.com with ESMTPSA id 34sm3971188wrh.78.2020.11.25.03.22.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Nov 2020 03:22:08 -0800 (PST) From: Lorenzo Stoakes To: Alex Shi , Johannes Weiner , Hui Su , Stephen Rothwell , Shakeel Butt , Roman Gushchin Cc: syzbot , Linux Kernel Mailing List , linux-mm , Linux-Next Mailing List , syzkaller-bugs , Lorenzo Stoakes Subject: [PATCH] mm/memcg: warn on missing memcg on mem_cgroup_page_lruvec() Date: Wed, 25 Nov 2020 11:22:02 +0000 Message-Id: <20201125112202.387009-1-lstoakes@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <00000000000054aea005b4d59e71@google.com> References: <00000000000054aea005b4d59e71@google.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Move memcg check to mem_cgroup_page_lruvec() as there are callers which may invoke this with !memcg in mem_cgroup_lruvec(), whereas they should not in mem_cgroup_page_lruvec(). We expect that we have always charged a page to the memcg before mem_cgroup_page_lruvec() is invoked, so add a warning to assert that this is the case. Signed-off-by: Lorenzo Stoakes Reported-by: syzbot+ce635500093181f39c1c@syzkaller.appspotmail.com Acked-by: Alex Shi --- include/linux/memcontrol.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 87ed56dc75f9..3e6a1df3bdb9 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -618,7 +618,6 @@ static inline struct lruvec *mem_cgroup_lruvec(struct mem_cgroup *memcg, goto out; } - VM_WARN_ON_ONCE(!memcg); if (!memcg) memcg = root_mem_cgroup; @@ -645,7 +644,10 @@ static inline struct lruvec *mem_cgroup_lruvec(struct mem_cgroup *memcg, static inline struct lruvec *mem_cgroup_page_lruvec(struct page *page, struct pglist_data *pgdat) { - return mem_cgroup_lruvec(page_memcg(page), pgdat); + struct mem_cgroup *memcg = page_memcg(page); + + VM_WARN_ON_ONCE_PAGE(!memcg, page); + return mem_cgroup_lruvec(memcg, pgdat); } static inline bool lruvec_holds_page_lru_lock(struct page *page,