From patchwork Wed May 26 19:36:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 12282627 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.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 078C4C47088 for ; Wed, 26 May 2021 19:36:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 72A9E613BD for ; Wed, 26 May 2021 19:36:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 72A9E613BD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EB9606B0036; Wed, 26 May 2021 15:36:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E68EC6B006E; Wed, 26 May 2021 15:36:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D09936B0070; Wed, 26 May 2021 15:36:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0246.hostedemail.com [216.40.44.246]) by kanga.kvack.org (Postfix) with ESMTP id 9CDA06B0036 for ; Wed, 26 May 2021 15:36:30 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 47200B9F9 for ; Wed, 26 May 2021 19:36:30 +0000 (UTC) X-FDA: 78184388940.19.36D1B4D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf22.hostedemail.com (Postfix) with ESMTP id C5A58C0042E5 for ; Wed, 26 May 2021 19:36:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622057789; h=from:from: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:content-transfer-encoding; bh=lvXIzW1vboiHDAOnYTe4b5RTNGtYwyUKmFA6LenTEYg=; b=Sj88GGD1n5GnTwFXIwmx+1I1UyvDa+P8tfzgP7IbCU3nWanN5lNvlfYFUKuCgX3gsUGs57 lPcp6kyPTFKsR9mj1X6kCcVQZcCUxnM0+JWF31i+JpOmzA2oxD13hXJjiKa4tRlj5ffKvU u6553/CekzYTecnKanaTps62Ck/N33g= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-431-8fnfKFh9MMuYF7AksyzIIg-1; Wed, 26 May 2021 15:36:27 -0400 X-MC-Unique: 8fnfKFh9MMuYF7AksyzIIg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C4E40180FD69; Wed, 26 May 2021 19:36:25 +0000 (UTC) Received: from llong.com (ovpn-112-32.rdu2.redhat.com [10.10.112.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 65D345D723; Wed, 26 May 2021 19:36:21 +0000 (UTC) From: Waiman Long To: Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Muchun Song , Waiman Long Subject: [PATCH-next] mm/memcontrol.c: Fix potential uninitialized variable warning Date: Wed, 26 May 2021 15:36:02 -0400 Message-Id: <20210526193602.8742-1-longman@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Sj88GGD1; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf22.hostedemail.com: domain of longman@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=longman@redhat.com X-Stat-Signature: fmaeonjnafmadrrhjatc94oqtfu3c5z1 X-Rspamd-Queue-Id: C5A58C0042E5 X-Rspamd-Server: rspam02 X-HE-Tag: 1622057782-750002 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: If the -Wno-maybe-uninitialized gcc option is not specified, compilation of memcontrol.c may generate the following warnings: mm/memcontrol.c: In function ‘refill_obj_stock’: ./arch/x86/include/asm/irqflags.h:127:17: warning: ‘flags’ may be used uninitialized in this function [-Wmaybe-uninitialized] return !(flags & X86_EFLAGS_IF); ~~~~~~~^~~~~~~~~~~~~~~~ mm/memcontrol.c:3216:16: note: ‘flags’ was declared here unsigned long flags; ^~~~~ In file included from mm/memcontrol.c:29: mm/memcontrol.c: In function ‘uncharge_page’: ./include/linux/memcontrol.h:797:2: warning: ‘objcg’ may be used uninitialized in this function [-Wmaybe-uninitialized] percpu_ref_put(&objcg->refcnt); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Fix that by properly initializing *pflags in get_obj_stock() and introducing a use_objcg bool variable in uncharge_page() to avoid potentially accessing the struct page data twice. Signed-off-by: Waiman Long --- mm/memcontrol.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index cb864f87b01d..b9a6db6a7d4f 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2108,6 +2108,7 @@ static inline struct obj_stock *get_obj_stock(unsigned long *pflags) struct memcg_stock_pcp *stock; if (likely(in_task())) { + *pflags = 0UL; preempt_disable(); stock = this_cpu_ptr(&memcg_stock); return &stock->task_obj; @@ -6840,6 +6841,7 @@ static void uncharge_page(struct page *page, struct uncharge_gather *ug) unsigned long nr_pages; struct mem_cgroup *memcg; struct obj_cgroup *objcg; + bool use_objcg = PageMemcgKmem(page); VM_BUG_ON_PAGE(PageLRU(page), page); @@ -6848,7 +6850,7 @@ static void uncharge_page(struct page *page, struct uncharge_gather *ug) * page memcg or objcg at this point, we have fully * exclusive access to the page. */ - if (PageMemcgKmem(page)) { + if (use_objcg) { objcg = __page_objcg(page); /* * This get matches the put at the end of the function and @@ -6876,7 +6878,7 @@ static void uncharge_page(struct page *page, struct uncharge_gather *ug) nr_pages = compound_nr(page); - if (PageMemcgKmem(page)) { + if (use_objcg) { ug->nr_memory += nr_pages; ug->nr_kmem += nr_pages;