From patchwork Mon May 28 13:05:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuo Handa X-Patchwork-Id: 10432487 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A3F27602CB for ; Mon, 28 May 2018 13:05:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92AB928814 for ; Mon, 28 May 2018 13:05:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 870BA288DD; Mon, 28 May 2018 13:05:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 97C7B28814 for ; Mon, 28 May 2018 13:05:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 57EF76B0003; Mon, 28 May 2018 09:05:40 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 554926B0006; Mon, 28 May 2018 09:05:40 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 46BFE6B0007; Mon, 28 May 2018 09:05:40 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f70.google.com (mail-pl0-f70.google.com [209.85.160.70]) by kanga.kvack.org (Postfix) with ESMTP id 08D9F6B0003 for ; Mon, 28 May 2018 09:05:40 -0400 (EDT) Received: by mail-pl0-f70.google.com with SMTP id w6-v6so5601318plp.14 for ; Mon, 28 May 2018 06:05:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:subject:to:cc :references:from:message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=CGtFizGy4WQtwFK2vhxsJqmGrenvDTe/N7CckD9A2wc=; b=HlduOPbW0RKdEmbZdYucLHAE2TvBNhl8CGTXXjhzSzoLwlLKgHLkSoEkZ/XFmLSoV7 SksEMykktkLYCIKUtl5H15ouYi5kizsxuNJu5Bg5Z8ZiNm72+jbqadZ2TKmPAZ5JTy8o KQUlR7WpIoDYsnN3Mcfv+crVsi9teAyLXUMHBTbfec28Fcb69RULhod66PcUibCK27rA xC90/PM7aY2DUxvV7xact1+ZkDG7J+sUJYdfZ/sfeob11aTvOVQCXcsWF7iUDAaJiDjk OuCKrcVBkc6LBR11VjC62HijveRQUtguUrR7UNfFy2sEJfsG8TMa/iTeq7/Cuz8cbH06 jwdA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of penguin-kernel@i-love.sakura.ne.jp designates 202.181.97.72 as permitted sender) smtp.mailfrom=penguin-kernel@i-love.sakura.ne.jp X-Gm-Message-State: ALKqPwc/y4LzTLYycUYwC3OuEpBXzfrWfGDgPV4OPWDuUmCEZ5Fk1M2j bnqjVfQkAP6D+o7rY9siJI4XnwL6QxFoFBm0dZJSTNu7ffkW4RR/IwZ0PC6Wicj7SHF93AXIYsI UgmlpmIo2rl4z/X4RyUsGS5p2tViCsy2fUPPJcWWQoWvzmEgp1t/LzEkLWqVuBVuhyQ== X-Received: by 2002:a63:7c04:: with SMTP id x4-v6mr10453756pgc.67.1527512739684; Mon, 28 May 2018 06:05:39 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpWNMjI0tGEpGaET3ocitpDSBrixAU6ArPK6nwNh936J+nPaLVrdOOMSXWnsWpbOsKMqj/v X-Received: by 2002:a63:7c04:: with SMTP id x4-v6mr10453673pgc.67.1527512738031; Mon, 28 May 2018 06:05:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527512738; cv=none; d=google.com; s=arc-20160816; b=VfuevuqH3xsTDVfkyoIcyx+EHW/Ifb5QIDKLYI1nV7qj8Xvw651QLMl2Q/QZuU84ZU pkDmTRotWfpyta80OlJxnfXWBXwDgHiWKYzjxBjsGspdTfIvqkKZB2Sj0OnGO/I1LOHG hl/vwO0dtyaBPhiRp0xvUvA0pMzjBJ//vi2WTqg3vRX8pt5o5jZHQgjiDU7Y3QRFT2sP KqoYx7kLZi3jVdwuJuhmSE/k8QOOMN2Th/vrECMGBCc+eRMECXQ4g4puZgoOnExuP9wn RUxwHNJWAqgDv8i3a/9dykQJZdoCZ7IPFZ2bCEyLUFRcFdOMdkZ8rtZwohcNwj1DpDVE 0XAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:references:cc:to:subject :arc-authentication-results; bh=CGtFizGy4WQtwFK2vhxsJqmGrenvDTe/N7CckD9A2wc=; b=vV2hlyeK4m+VuMCNDhB2vY+iVjKK7NZRREMNOB2v3s2ffTQV833kp053AZdZY2W8iM PlEDZwT2h0hmbM8kNlBeFP/xMaNEz8W/mkOmXyAunRDp9ctXUdig+1yc0qFpONbZ8HIt JqDpuKy4ghp06sBd90HDMtV044Pko6+y/oPhb+tviLi15ejD4Q4JCdaQgx/LVvmer60s ojYzFOo+Dfv1RUBI/vZLJp2FQGe7zetADvBObd7AQA9GfJCuVxQ3EdgPojbjhbVPxnDU QeMq71SyVJtm7wrrR4iEWgedgsmE2qZr4c5K8yJKSf1dZyRSrizqOXO0ZWjCrdAwO+6J E6BA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of penguin-kernel@i-love.sakura.ne.jp designates 202.181.97.72 as permitted sender) smtp.mailfrom=penguin-kernel@i-love.sakura.ne.jp Received: from www262.sakura.ne.jp (www262.sakura.ne.jp. [202.181.97.72]) by mx.google.com with ESMTPS id 1-v6si29637371plo.20.2018.05.28.06.05.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 May 2018 06:05:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of penguin-kernel@i-love.sakura.ne.jp designates 202.181.97.72 as permitted sender) client-ip=202.181.97.72; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of penguin-kernel@i-love.sakura.ne.jp designates 202.181.97.72 as permitted sender) smtp.mailfrom=penguin-kernel@i-love.sakura.ne.jp Received: from fsav405.sakura.ne.jp (fsav405.sakura.ne.jp [133.242.250.104]) by www262.sakura.ne.jp (8.14.5/8.14.5) with ESMTP id w4SD5Rf3002522; Mon, 28 May 2018 22:05:27 +0900 (JST) (envelope-from penguin-kernel@i-love.sakura.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav405.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav405.sakura.ne.jp); Mon, 28 May 2018 22:05:27 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav405.sakura.ne.jp) Received: from [192.168.1.8] (softbank126074194044.bbtec.net [126.74.194.44]) (authenticated bits=0) by www262.sakura.ne.jp (8.14.5/8.14.5) with ESMTP id w4SD5M3Q002341 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 28 May 2018 22:05:27 +0900 (JST) (envelope-from penguin-kernel@i-love.sakura.ne.jp) Subject: [PATCH] kmemleak: don't use __GFP_NOFAIL To: Michal Hocko , Mathieu Malaterre , Dmitry Vyukov Cc: linux-mm@kvack.org, Catalin Marinas References: <20180528083451.GE1517@dhcp22.suse.cz> From: Tetsuo Handa Message-ID: Date: Mon, 28 May 2018 22:05:21 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180528083451.GE1517@dhcp22.suse.cz> Content-Language: en-US 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: X-Virus-Scanned: ClamAV using ClamSMTP From f0b7f6c2146f693fec6706bf9e3c34687c73f21a Mon Sep 17 00:00:00 2001 From: Tetsuo Handa Date: Mon, 28 May 2018 21:49:51 +0900 Subject: [PATCH] kmemleak: don't use __GFP_NOFAIL Commit d9570ee3bd1d4f20 ("kmemleak: allow to coexist with fault injection") added __GFP_NOFAIL to gfp_kmemleak_mask() macro because memory allocation fault injection trivially disables kmemleak. But since !__GFP_DIRECT_RECLAIM && __GFP_NOFAIL memory allocation is not supported, Mathieu Malaterre is observing warning messages upon mempool_alloc(gfp_msk & ~__GFP_DIRECT_RECLAIM) allocation request. [ 269.039118] NIP [c020e8f8] __alloc_pages_nodemask+0xa88/0xfec [ 269.039124] LR [c020e2e0] __alloc_pages_nodemask+0x470/0xfec [ 269.039128] Call Trace: [ 269.039136] [dde3b750] [c020e2e0] __alloc_pages_nodemask+0x470/0xfec (unreliable) [ 269.039146] [dde3b820] [c0288c14] new_slab+0x53c/0x970 [ 269.039155] [dde3b880] [c028b61c] ___slab_alloc.constprop.23+0x28c/0x468 [ 269.039163] [dde3b920] [c028c754] kmem_cache_alloc+0x290/0x3dc [ 269.039177] [dde3b990] [c02a6030] create_object+0x50/0x3d0 [ 269.039185] [dde3b9e0] [c028c7a8] kmem_cache_alloc+0x2e4/0x3dc [ 269.039193] [dde3ba50] [c0200f88] mempool_alloc+0x7c/0x164 [ 269.039205] [dde3bab0] [c03e33c0] bio_alloc_bioset+0x130/0x298 [ 269.039216] [dde3baf0] [c0278694] get_swap_bio+0x34/0xe8 [ 269.039223] [dde3bb30] [c0278fb4] __swap_writepage+0x22c/0x644 [ 269.039237] [dde3bbb0] [c022528c] pageout.isra.13+0x238/0x52c [ 269.039246] [dde3bc10] [c02288a0] shrink_page_list+0x9d4/0x1768 [ 269.039254] [dde3bcb0] [c022a264] shrink_inactive_list+0x2c4/0xa34 [ 269.039262] [dde3bd40] [c022b454] shrink_node_memcg+0x344/0xe34 [ 269.039270] [dde3bde0] [c022c068] shrink_node+0x124/0x73c [ 269.039277] [dde3be50] [c022d78c] kswapd+0x318/0xb2c [ 269.039291] [dde3bf10] [c008e264] kthread+0x138/0x1f0 [ 269.039300] [dde3bf40] [c001b2e4] ret_from_kernel_thread+0x5c/0x64 Since the intent of adding __GFP_NOFAIL is not to disable kmemleak by failing the N'th allocation request, it should be possible to workaround it by simply retrying N'th allocation request. Thus, this patch changes callers of gfp_kmemleak_mask() macro to retry for several times. Signed-off-by: Tetsuo Handa Reported-by: Mathieu Malaterre Cc: Dmitry Vyukov Cc: Catalin Marinas Cc: Michal Hocko --- mm/kmemleak.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 9a085d5..973998b 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -126,7 +126,7 @@ /* GFP bitmask for kmemleak internal allocations */ #define gfp_kmemleak_mask(gfp) (((gfp) & (GFP_KERNEL | GFP_ATOMIC)) | \ __GFP_NORETRY | __GFP_NOMEMALLOC | \ - __GFP_NOWARN | __GFP_NOFAIL) + __GFP_NOWARN) /* scanning area inside a memory block */ struct kmemleak_scan_area { @@ -548,10 +548,12 @@ static struct kmemleak_object *create_object(unsigned long ptr, size_t size, int min_count, gfp_t gfp) { unsigned long flags; - struct kmemleak_object *object, *parent; + struct kmemleak_object *object = NULL, *parent; struct rb_node **link, *rb_parent; + unsigned int i; - object = kmem_cache_alloc(object_cache, gfp_kmemleak_mask(gfp)); + for (i = 0; i < 10 && !object; i++) + object = kmem_cache_alloc(object_cache, gfp_kmemleak_mask(gfp)); if (!object) { pr_warn("Cannot allocate a kmemleak_object structure\n"); kmemleak_disable(); @@ -763,7 +765,8 @@ static void add_scan_area(unsigned long ptr, size_t size, gfp_t gfp) { unsigned long flags; struct kmemleak_object *object; - struct kmemleak_scan_area *area; + struct kmemleak_scan_area *area = NULL; + unsigned int i; object = find_and_get_object(ptr, 1); if (!object) { @@ -772,7 +775,9 @@ static void add_scan_area(unsigned long ptr, size_t size, gfp_t gfp) return; } - area = kmem_cache_alloc(scan_area_cache, gfp_kmemleak_mask(gfp)); + for (i = 0; i < 10 && !area; i++) + area = kmem_cache_alloc(scan_area_cache, + gfp_kmemleak_mask(gfp)); if (!area) { pr_warn("Cannot allocate a scan area\n"); goto out;