From patchwork Tue Sep 7 14:13:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 12478817 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=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 BA9E5C4332F for ; Tue, 7 Sep 2021 14:14:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5FA6661101 for ; Tue, 7 Sep 2021 14:14:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5FA6661101 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id F32906B0071; Tue, 7 Sep 2021 10:14:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E9263940007; Tue, 7 Sep 2021 10:14:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D5A9A6B0073; Tue, 7 Sep 2021 10:14:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0148.hostedemail.com [216.40.44.148]) by kanga.kvack.org (Postfix) with ESMTP id C57846B0071 for ; Tue, 7 Sep 2021 10:14:04 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 83C942D230 for ; Tue, 7 Sep 2021 14:14:04 +0000 (UTC) X-FDA: 78560971608.19.75A5AF7 Received: from mail-qv1-f73.google.com (mail-qv1-f73.google.com [209.85.219.73]) by imf02.hostedemail.com (Postfix) with ESMTP id 3EB1B700178D for ; Tue, 7 Sep 2021 14:14:04 +0000 (UTC) Received: by mail-qv1-f73.google.com with SMTP id l12-20020a0cc20c000000b0037766e5daaeso15143194qvh.10 for ; Tue, 07 Sep 2021 07:14:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=0HnGqpsoRrU1QmVhpHGIABru/4TEzN09iOx6pzAlIgs=; b=FIdzWcWCyYBHcYo+lYxCb/BdxuxeVQKjDQ/8C68Uldd4DOqqkqMqCwIeQM1k4P9tWX R8aeVxljaZLDg34Q6E0a+AE+8FDZ5CAIJZfmaaUIM5L+OoC9twTp3x3PzXdn2TJ6cSvL XDZEbf54+JNvayl39VYEvwRDh10ike0Oej78UbMSwLihb8i2K1nBW+KMycZFTvB1Yvz1 FUQbNIxlvJ9BNM9ojDKkE3Bm+q3a4FAGDZmG3LyjlHhNUkK+5lfAqWCsw8Jc2t3f54+k jO5osWRFtwTDJ2aVCPkmi4fHVbaq+hWV2RasAXtJt2+02uOHHuDlDnNjAesNHtBmUVg/ rn2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=0HnGqpsoRrU1QmVhpHGIABru/4TEzN09iOx6pzAlIgs=; b=uFg6X3GOZxLi4YpuJhUyo5zidshzonzaFt6XcFeMuwqODiNpEdpgmmw5DJhUIiQTFe +mKiHX4p3HsCKYl3TxreXOTYq1lwpDUWTUwRxgA85K53/elFeRSKGPvJ36o4OXaC1D0v ggUL/Ofc2wr6ruTqJuZ9CfAs23E0pjz4PSwhqo9oFIIWo44cZga9+DkP4ZTPXVcwfgu2 ghtq25kNEI7xMlk2hB9FMmsttEXceMOFXG4Z+HRHb4vcLgg7L52ss8D8wrkz2jWlXqEU L3RQFWzMY+4c9tA7wcEn/Ubt3FWENhlGt59q/8xsCMI2WIbsksYhEed37XxUjoN77AfP 1Orw== X-Gm-Message-State: AOAM531qGuw7PNPBGIpdKSczzIy0TS6NeZ693GKl6Ijhoho1Z6PMRwF/ 24bwoF7SvkeN4VToIL8t++I/cLQgWA== X-Google-Smtp-Source: ABdhPJwPd2W6LAa6evsW67Ve6ymtbHJ7iRdwBWR2WoZEZcz4Wcc4dovrJsftmGoxoLGs6bjyJoqRVo+WTw== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:6800:c1ea:4271:5898]) (user=elver job=sendgmr) by 2002:a0c:e1cf:: with SMTP id v15mr17153429qvl.50.1631024043569; Tue, 07 Sep 2021 07:14:03 -0700 (PDT) Date: Tue, 7 Sep 2021 16:13:02 +0200 In-Reply-To: <20210907141307.1437816-1-elver@google.com> Message-Id: <20210907141307.1437816-2-elver@google.com> Mime-Version: 1.0 References: <20210907141307.1437816-1-elver@google.com> X-Mailer: git-send-email 2.33.0.153.gba50c8fa24-goog Subject: [PATCH 1/6] lib/stackdepot: include gfp.h From: Marco Elver To: elver@google.com Cc: Andrew Morton , Shuah Khan , Tejun Heo , Lai Jiangshan , Andrey Konovalov , Walter Wu , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Vijayanand Jitta , Vinayak Menon , "Gustavo A. R. Silva" , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Aleksandr Nogikh , Taras Madan Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=FIdzWcWC; spf=pass (imf02.hostedemail.com: domain of 3q3M3YQUKCIAipzivksskpi.gsqpmry1-qqozego.svk@flex--elver.bounces.google.com designates 209.85.219.73 as permitted sender) smtp.mailfrom=3q3M3YQUKCIAipzivksskpi.gsqpmry1-qqozego.svk@flex--elver.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: 6om5ko3bcsg6eb4qkzenm55nz96q3pyg X-Rspamd-Queue-Id: 3EB1B700178D X-Rspamd-Server: rspam04 X-HE-Tag: 1631024044-938421 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: refers to gfp_t, but doesn't include gfp.h. Fix it by including . Signed-off-by: Marco Elver Reviewed-by: Alexander Potapenko --- include/linux/stackdepot.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h index 6bb4bc1a5f54..97b36dc53301 100644 --- a/include/linux/stackdepot.h +++ b/include/linux/stackdepot.h @@ -11,6 +11,8 @@ #ifndef _LINUX_STACKDEPOT_H #define _LINUX_STACKDEPOT_H +#include + typedef u32 depot_stack_handle_t; depot_stack_handle_t stack_depot_save(unsigned long *entries, From patchwork Tue Sep 7 14:13:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 12478819 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=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 2E33BC433EF for ; Tue, 7 Sep 2021 14:14:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C376D61101 for ; Tue, 7 Sep 2021 14:14:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C376D61101 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 54718940008; Tue, 7 Sep 2021 10:14:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F4F8940007; Tue, 7 Sep 2021 10:14:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 40B1C940008; Tue, 7 Sep 2021 10:14:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0006.hostedemail.com [216.40.44.6]) by kanga.kvack.org (Postfix) with ESMTP id 2D021940007 for ; Tue, 7 Sep 2021 10:14:07 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id D010A181B0493 for ; Tue, 7 Sep 2021 14:14:06 +0000 (UTC) X-FDA: 78560971692.26.F679DC3 Received: from mail-qk1-f201.google.com (mail-qk1-f201.google.com [209.85.222.201]) by imf12.hostedemail.com (Postfix) with ESMTP id 94E5810000A3 for ; Tue, 7 Sep 2021 14:14:06 +0000 (UTC) Received: by mail-qk1-f201.google.com with SMTP id e22-20020a05620a209600b003d5ff97bff7so14665223qka.1 for ; Tue, 07 Sep 2021 07:14:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=N/5YJhYADcqy8sBs5vH/zCaS3u8GV2W+ZzJdQ0X+ILI=; b=LRISar8+QTrl1Cr1oyWe4vLdGfZUfkMlRlMDd/NK0Kmk7Y/DRBslXQaQ0X7mSxUXmi wm531M1XS426nqxMn1W8GRMqNBjylH38g87qY5EpxICYsHkCs5qHSUKERzjptpi6719j /H4m3kZq8l2uvNx0QnqHX3MM5QXCLSysyxGeMIbtYrxq/s1FGDvWMfmDgG9F/ec3c3xj idHtizK63LEw5945mpWMf49WMrAuJykA23g6B0zm+xUHYrMwrU9WiHBpfUfzb2yEvcES 922lt7ECnXTIRcMYgYMWsz6BweWTWVC1fORFAVsMLnaSefXxhf96MSDLdFD0jEgeaOy2 4+QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=N/5YJhYADcqy8sBs5vH/zCaS3u8GV2W+ZzJdQ0X+ILI=; b=KE1h2ldioA+aL4mK30iunwvwl7N9rsNIsXJ1pimYkRA6Q5d0vP4hgm7QFKp+HEfR4d 0oy5/1VFd0KsjXHeKAKX98b+RxpJDIC5pyApriyXZ5VDhVE8fyj0vRoiRP7GP0rDuFyH y2Liax/L5BNsos1m4eOflMg1MAao59lvCvTX7dQ4J6j81jVRiqXn1RW1ij6ymYKjphMQ cp5KdG2wOAZrpNT8d4ueUJxDl0SREgmNZFta79S15C6fKlyf3y9MBccjFGY9JsvoY6hq ijEir2LXbYgZ6lIkVHqJSpkYep5kt/daQpBUKknNwcMydWDtu8/3+SKRPFXMn54nTrrG yD9w== X-Gm-Message-State: AOAM531p1diZMCPfe+mhYEND+zyIvVU10aqo2kbkTqORWAXFfdGiIlR0 8/yH8czVsT8yGjZKgiC53O8I0SceQA== X-Google-Smtp-Source: ABdhPJyR8jDVjdhyUz93LlcEeykwrpaVXBAWFlVsgNr0Lvtqc/eGJKRewlggnz5eecPqJQAot9SMUph8Aw== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:6800:c1ea:4271:5898]) (user=elver job=sendgmr) by 2002:a0c:be85:: with SMTP id n5mr17013941qvi.59.1631024045883; Tue, 07 Sep 2021 07:14:05 -0700 (PDT) Date: Tue, 7 Sep 2021 16:13:03 +0200 In-Reply-To: <20210907141307.1437816-1-elver@google.com> Message-Id: <20210907141307.1437816-3-elver@google.com> Mime-Version: 1.0 References: <20210907141307.1437816-1-elver@google.com> X-Mailer: git-send-email 2.33.0.153.gba50c8fa24-goog Subject: [PATCH 2/6] lib/stackdepot: remove unused function argument From: Marco Elver To: elver@google.com Cc: Andrew Morton , Shuah Khan , Tejun Heo , Lai Jiangshan , Andrey Konovalov , Walter Wu , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Vijayanand Jitta , Vinayak Menon , "Gustavo A. R. Silva" , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Aleksandr Nogikh , Taras Madan Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=LRISar8+; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.hostedemail.com: domain of 3rXM3YQUKCIIkr1kxmuumrk.iusrot03-ssq1giq.uxm@flex--elver.bounces.google.com designates 209.85.222.201 as permitted sender) smtp.mailfrom=3rXM3YQUKCIIkr1kxmuumrk.iusrot03-ssq1giq.uxm@flex--elver.bounces.google.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 94E5810000A3 X-Stat-Signature: om6bbzrsw99e1esx4fretn3gauhxiqpe X-HE-Tag: 1631024046-1495 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: alloc_flags in depot_alloc_stack() is no longer used; remove it. Signed-off-by: Marco Elver Reviewed-by: Alexander Potapenko --- lib/stackdepot.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 0a2e417f83cb..c80a9f734253 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -102,8 +102,8 @@ static bool init_stack_slab(void **prealloc) } /* Allocation of a new stack in raw storage */ -static struct stack_record *depot_alloc_stack(unsigned long *entries, int size, - u32 hash, void **prealloc, gfp_t alloc_flags) +static struct stack_record * +depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) { struct stack_record *stack; size_t required_size = struct_size(stack, entries, size); @@ -309,9 +309,8 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries, found = find_stack(*bucket, entries, nr_entries, hash); if (!found) { - struct stack_record *new = - depot_alloc_stack(entries, nr_entries, - hash, &prealloc, alloc_flags); + struct stack_record *new = depot_alloc_stack(entries, nr_entries, hash, &prealloc); + if (new) { new->next = *bucket; /* From patchwork Tue Sep 7 14:13:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 12478821 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=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 5ADE3C433EF for ; Tue, 7 Sep 2021 14:14:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 03D4661103 for ; Tue, 7 Sep 2021 14:14:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 03D4661103 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 9B2A1940009; Tue, 7 Sep 2021 10:14:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 93ABA940007; Tue, 7 Sep 2021 10:14:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7DCB1940009; Tue, 7 Sep 2021 10:14:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0236.hostedemail.com [216.40.44.236]) by kanga.kvack.org (Postfix) with ESMTP id 690FF940007 for ; Tue, 7 Sep 2021 10:14:09 -0400 (EDT) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 215DF181B0493 for ; Tue, 7 Sep 2021 14:14:09 +0000 (UTC) X-FDA: 78560971818.31.1C8F43D Received: from mail-qk1-f202.google.com (mail-qk1-f202.google.com [209.85.222.202]) by imf18.hostedemail.com (Postfix) with ESMTP id E2039400209E for ; Tue, 7 Sep 2021 14:14:08 +0000 (UTC) Received: by mail-qk1-f202.google.com with SMTP id 23-20020a05620a071700b00426392c0e6eso14643517qkc.4 for ; Tue, 07 Sep 2021 07:14:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=ClauTO0DAc/W2CE5FaWJtasGRNKjOeQhVVw0fZ55opA=; b=ICdgop9Bb/UlNIicMIQWpjefBvU62X7yD2tARPBACjMMeNeFKwL6hpa4za3Q+GViph 59yYezR+3aidPQ4onhqjPPPGR4f/IJ0F0Lq2blaciGq800jLMrwOi6qn9Tr39ECNIEHI wpHPULsvIva0eZTmQLyc2Xu/kI8dANICLgD99thQF9/xwBQM453Fcpo01BqwkjaiJEc7 VW6igdwjJSIfWLdmnBMhQ/2AmmT/YbgKiSok59dlxnsL7bOq1G9Xf8FpiQS0SGrGT4sc IDimGSf/TGzEFVj2tZta1r7d+1QalLw3e4KnH938MLWkG9cgJiBntBlEk2MNKDx+r5/O XgnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ClauTO0DAc/W2CE5FaWJtasGRNKjOeQhVVw0fZ55opA=; b=KOq+gDZUsCM3Lk8KuSxd9hxv698qQFPOfv3kJo5Kcv5cmq/9T3ZveTq92zn8NDH70t kV4PEsjGHokfeuNHW8aJ38CBGdnbxIe2zOU/pFE42TVXGL8LjhkzRIvYs9V+S9+bb4cI f/ZBSxe5gh0VzD/c0crOCfJwEzBn8VO3GoOMF1sMGnIZrDYVgV9rzaaQMMnx5jwW8Wx0 OvfCM+GKjtshpvk3mHI1a/EBA/8SO7yuvKAmXyL0VAACzWlFSv/9FCG3bF6rZwMvwMhP qvf2F3KQ+DhkGC43TGrQs+QeGUs5UZSqXFwNZfBnQyEhztyuSaq2bYIXTAvl/DpQHZig PeMA== X-Gm-Message-State: AOAM533Mt7a+OTHD1Lx7+INM3yOlEJDutVle18LYhp0XQOtjX3oujLAC WNXY/njMjKbzBE9sOhcWVH/K3DeMJw== X-Google-Smtp-Source: ABdhPJw87QSuzKKPiaQWZq+ibYy/Wvgp6rb9RM4pXrZmwrnDnpMuaZQjS0f+oetPSFS2lDFVXSeJ2ZruVQ== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:6800:c1ea:4271:5898]) (user=elver job=sendgmr) by 2002:a05:6214:14f2:: with SMTP id k18mr17256135qvw.19.1631024048156; Tue, 07 Sep 2021 07:14:08 -0700 (PDT) Date: Tue, 7 Sep 2021 16:13:04 +0200 In-Reply-To: <20210907141307.1437816-1-elver@google.com> Message-Id: <20210907141307.1437816-4-elver@google.com> Mime-Version: 1.0 References: <20210907141307.1437816-1-elver@google.com> X-Mailer: git-send-email 2.33.0.153.gba50c8fa24-goog Subject: [PATCH 3/6] lib/stackdepot: introduce __stack_depot_save() From: Marco Elver To: elver@google.com Cc: Andrew Morton , Shuah Khan , Tejun Heo , Lai Jiangshan , Andrey Konovalov , Walter Wu , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Vijayanand Jitta , Vinayak Menon , "Gustavo A. R. Silva" , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Aleksandr Nogikh , Taras Madan Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=ICdgop9B; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf18.hostedemail.com: domain of 3sHM3YQUKCIUnu4n0pxxpun.lxvurw36-vvt4jlt.x0p@flex--elver.bounces.google.com designates 209.85.222.202 as permitted sender) smtp.mailfrom=3sHM3YQUKCIUnu4n0pxxpun.lxvurw36-vvt4jlt.x0p@flex--elver.bounces.google.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: E2039400209E X-Stat-Signature: ssqg9uk75a4cwbxk5yqbige7h8tgdw7j X-HE-Tag: 1631024048-635541 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: Add __stack_depot_save(), which provides more fine-grained control over stackdepot's memory allocation behaviour, in case stackdepot runs out of "stack slabs". Normally stackdepot uses alloc_pages() in case it runs out of space; passing can_alloc==false to __stack_depot_save() prohibits this, at the cost of more likely failure to record a stack trace. Signed-off-by: Marco Elver --- include/linux/stackdepot.h | 4 ++++ lib/stackdepot.c | 42 ++++++++++++++++++++++++++++++++------ 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h index 97b36dc53301..b2f7e7c6ba54 100644 --- a/include/linux/stackdepot.h +++ b/include/linux/stackdepot.h @@ -15,6 +15,10 @@ typedef u32 depot_stack_handle_t; +depot_stack_handle_t __stack_depot_save(unsigned long *entries, + unsigned int nr_entries, + gfp_t gfp_flags, bool can_alloc); + depot_stack_handle_t stack_depot_save(unsigned long *entries, unsigned int nr_entries, gfp_t gfp_flags); diff --git a/lib/stackdepot.c b/lib/stackdepot.c index c80a9f734253..cab6cf117290 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -248,17 +248,28 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle, EXPORT_SYMBOL_GPL(stack_depot_fetch); /** - * stack_depot_save - Save a stack trace from an array + * __stack_depot_save - Save a stack trace from an array * * @entries: Pointer to storage array * @nr_entries: Size of the storage array * @alloc_flags: Allocation gfp flags + * @can_alloc: Allocate stack slabs (increased chance of failure if false) + * + * Saves a stack trace from @entries array of size @nr_entries. If @can_alloc is + * %true, is allowed to replenish the stack slab pool in case no space is left + * (allocates using GFP flags of @alloc_flags). If @can_alloc is %false, avoids + * any allocations and will fail if no space is left to store the stack trace. + * + * Context: Any context, but setting @can_alloc to %false is required if + * alloc_pages() cannot be used from the current context. Currently + * this is the case from contexts where neither %GFP_ATOMIC nor + * %GFP_NOWAIT can be used (NMI, raw_spin_lock). * - * Return: The handle of the stack struct stored in depot + * Return: The handle of the stack struct stored in depot, 0 on failure. */ -depot_stack_handle_t stack_depot_save(unsigned long *entries, - unsigned int nr_entries, - gfp_t alloc_flags) +depot_stack_handle_t __stack_depot_save(unsigned long *entries, + unsigned int nr_entries, + gfp_t alloc_flags, bool can_alloc) { struct stack_record *found = NULL, **bucket; depot_stack_handle_t retval = 0; @@ -291,7 +302,7 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries, * The smp_load_acquire() here pairs with smp_store_release() to * |next_slab_inited| in depot_alloc_stack() and init_stack_slab(). */ - if (unlikely(!smp_load_acquire(&next_slab_inited))) { + if (unlikely(can_alloc && !smp_load_acquire(&next_slab_inited))) { /* * Zero out zone modifiers, as we don't have specific zone * requirements. Keep the flags related to allocation in atomic @@ -339,6 +350,25 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries, fast_exit: return retval; } +EXPORT_SYMBOL_GPL(__stack_depot_save); + +/** + * stack_depot_save - Save a stack trace from an array + * + * @entries: Pointer to storage array + * @nr_entries: Size of the storage array + * @alloc_flags: Allocation gfp flags + * + * Context: Contexts where allocations via alloc_pages() are allowed. + * + * Return: The handle of the stack struct stored in depot, 0 on failure. + */ +depot_stack_handle_t stack_depot_save(unsigned long *entries, + unsigned int nr_entries, + gfp_t alloc_flags) +{ + return __stack_depot_save(entries, nr_entries, alloc_flags, true); +} EXPORT_SYMBOL_GPL(stack_depot_save); static inline int in_irqentry_text(unsigned long ptr) From patchwork Tue Sep 7 14:13:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 12478823 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=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 BCC56C433F5 for ; Tue, 7 Sep 2021 14:14:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7014C61101 for ; Tue, 7 Sep 2021 14:14:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7014C61101 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 1271394000A; Tue, 7 Sep 2021 10:14:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0D763940007; Tue, 7 Sep 2021 10:14:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE17794000A; Tue, 7 Sep 2021 10:14:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0243.hostedemail.com [216.40.44.243]) by kanga.kvack.org (Postfix) with ESMTP id DCB2A940007 for ; Tue, 7 Sep 2021 10:14:12 -0400 (EDT) Received: from smtpin32.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 8D9A38249980 for ; Tue, 7 Sep 2021 14:14:12 +0000 (UTC) X-FDA: 78560971944.32.C7AAED6 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf26.hostedemail.com (Postfix) with ESMTP id 3D54A20019ED for ; Tue, 7 Sep 2021 14:14:12 +0000 (UTC) Received: by mail-wr1-f74.google.com with SMTP id j1-20020adff541000000b001593715d384so2158462wrp.1 for ; Tue, 07 Sep 2021 07:14:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=+Rc+8EwMgZeFDUhTR7EsEOP4LhinEf5yz1jFhEz7Lys=; b=C+fu87GoZkKgIPoEvuCyV89//ZnQ2k/l0TxbqWn0XEyAUEP7eZBz2sQEtKAoLtfAPo i4LUEghiCtacFi/u4ZPEyOr9w+StX0mLitUoVCMJrqQv26+ON3iTipxat+SJB8Z4OWpj Rjz/abmjaqw+fhtK2VgNo5/xLy2Bj8tBR17vDoq2moBJSp0TqEYKtCs4bEiiPYdPpcNa zmBkQP95QLt2XqYlZbVycFi+CRCBDXubJIy0o7OrzSw6+xm+W9cElegagvtA2UzKNxCV R72bRGrU0M/WoCET7xXJt4z286/MhTPWFbyAS4LNDW1YWWBcJfHejyx1DKCTIoVzuCZo 4Pyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=+Rc+8EwMgZeFDUhTR7EsEOP4LhinEf5yz1jFhEz7Lys=; b=PWNDU49DxCE25qmK9cm7uzsKyIp+eCuLfuf1Nvm4bQKfz9tS8MDHtYM0xGg54Gb1vk P1yr0TNR7dwB/wXlfWV8LBfnozSqR0qIT6OtLoN/6p8Dp0vpL+x4UCvaZ1UvmeQwC451 cP5mjh6SOgpEogdzeByl/+wPjMIoBxVeoJg8kYp88ABli7z3C8tLKFbhxd29B53A2fer U741+GfxVimtrqNBd6upKkv8RrfXYgMDxi8aGVSnT0KEwNkcK8mW29oDOebUGj/etYQ+ u9lWDCA+uvWdQKmLCxgK9IyIts5a3jhPh4o6jqaVk5tszW57uYYqK4eO/wKb0M9uI3w7 pzvg== X-Gm-Message-State: AOAM530eZupe9GEC97QibKag1AC+6hhCYGxOlVBQYJ0zSJA5fl5kh73e Y2QtdclqGcLCmbZR7pezXNy1An4Q5g== X-Google-Smtp-Source: ABdhPJy5j8OSOmcWadIfuPxP8jPndBqUduiq6MfhVDnHUz5ko0W2/iEvw7OfLAojWDgpFpRc1AZPp+GF2w== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:6800:c1ea:4271:5898]) (user=elver job=sendgmr) by 2002:a05:600c:4106:: with SMTP id j6mr4288917wmi.102.1631024050593; Tue, 07 Sep 2021 07:14:10 -0700 (PDT) Date: Tue, 7 Sep 2021 16:13:05 +0200 In-Reply-To: <20210907141307.1437816-1-elver@google.com> Message-Id: <20210907141307.1437816-5-elver@google.com> Mime-Version: 1.0 References: <20210907141307.1437816-1-elver@google.com> X-Mailer: git-send-email 2.33.0.153.gba50c8fa24-goog Subject: [PATCH 4/6] kasan: common: provide can_alloc in kasan_save_stack() From: Marco Elver To: elver@google.com Cc: Andrew Morton , Shuah Khan , Tejun Heo , Lai Jiangshan , Andrey Konovalov , Walter Wu , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Vijayanand Jitta , Vinayak Menon , "Gustavo A. R. Silva" , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Aleksandr Nogikh , Taras Madan X-Rspamd-Queue-Id: 3D54A20019ED Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=C+fu87Go; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf26.hostedemail.com: domain of 3snM3YQUKCIcpw6p2rzzrwp.nzxwty58-xxv6lnv.z2r@flex--elver.bounces.google.com designates 209.85.221.74 as permitted sender) smtp.mailfrom=3snM3YQUKCIcpw6p2rzzrwp.nzxwty58-xxv6lnv.z2r@flex--elver.bounces.google.com X-Rspamd-Server: rspam01 X-Stat-Signature: ou5bargsrb3u3ddyx7g3f8s4ar5kdb7h X-HE-Tag: 1631024052-839117 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: Add another argument, can_alloc, to kasan_save_stack() which is passed as-is to __stack_depot_save(). No functional change intended. Signed-off-by: Marco Elver --- mm/kasan/common.c | 6 +++--- mm/kasan/generic.c | 2 +- mm/kasan/kasan.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 2baf121fb8c5..3e0999892c36 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -30,20 +30,20 @@ #include "kasan.h" #include "../slab.h" -depot_stack_handle_t kasan_save_stack(gfp_t flags) +depot_stack_handle_t kasan_save_stack(gfp_t flags, bool can_alloc) { unsigned long entries[KASAN_STACK_DEPTH]; unsigned int nr_entries; nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 0); nr_entries = filter_irq_stacks(entries, nr_entries); - return stack_depot_save(entries, nr_entries, flags); + return __stack_depot_save(entries, nr_entries, flags, can_alloc); } void kasan_set_track(struct kasan_track *track, gfp_t flags) { track->pid = current->pid; - track->stack = kasan_save_stack(flags); + track->stack = kasan_save_stack(flags, true); } #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index c3f5ba7a294a..2a8e59e6326d 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -345,7 +345,7 @@ void kasan_record_aux_stack(void *addr) return; alloc_meta->aux_stack[1] = alloc_meta->aux_stack[0]; - alloc_meta->aux_stack[0] = kasan_save_stack(GFP_NOWAIT); + alloc_meta->aux_stack[0] = kasan_save_stack(GFP_NOWAIT, true); } void kasan_set_free_info(struct kmem_cache *cache, diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index fa02c88b6948..e442d94a8f6e 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -260,7 +260,7 @@ void kasan_report_invalid_free(void *object, unsigned long ip); struct page *kasan_addr_to_page(const void *addr); -depot_stack_handle_t kasan_save_stack(gfp_t flags); +depot_stack_handle_t kasan_save_stack(gfp_t flags, bool can_alloc); void kasan_set_track(struct kasan_track *track, gfp_t flags); void kasan_set_free_info(struct kmem_cache *cache, void *object, u8 tag); struct kasan_track *kasan_get_free_track(struct kmem_cache *cache, From patchwork Tue Sep 7 14:13:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 12478825 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=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 DC731C433EF for ; Tue, 7 Sep 2021 14:14:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8E7CF610E9 for ; Tue, 7 Sep 2021 14:14:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8E7CF610E9 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 2FBE094000B; Tue, 7 Sep 2021 10:14:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E730940007; Tue, 7 Sep 2021 10:14:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D84E94000B; Tue, 7 Sep 2021 10:14:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0196.hostedemail.com [216.40.44.196]) by kanga.kvack.org (Postfix) with ESMTP id F3955940007 for ; Tue, 7 Sep 2021 10:14:14 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id AFC5D2D019 for ; Tue, 7 Sep 2021 14:14:14 +0000 (UTC) X-FDA: 78560972028.08.38E558D Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf02.hostedemail.com (Postfix) with ESMTP id 6DF817001700 for ; Tue, 7 Sep 2021 14:14:14 +0000 (UTC) Received: by mail-wm1-f73.google.com with SMTP id s197-20020a1ca9ce000000b002e72ba822dcso1251572wme.6 for ; Tue, 07 Sep 2021 07:14:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=xcObahmn+nrr83zfh05tWVTdAkOdXoaYlFTrwb+vDxw=; b=PwTMtZh9hU0VqLk69hEXqYfnxKsjVqFY7wOSFa1J0JB6DQhg2CtMHi//BlIXmlAJcR yl9HreJGMh+fm26LpJy0ArZAj++4Fu4KvyaIdfJ82LB3ATSviQI6qC2cUv53tm+SqOqo ZgPg/NhW5nrFtj6UtT6b7nwehz/BqtUvvuNGJ7Xqvz7NDleWgKV/yIGmUsypiwLCBrLH w/wrxaP8qWrm/esdH1O/wqUUWOxZN/0ETQ/gcpzJMgGZnv0+XxeRCAyCu+4EaPQOHmwf 3rgpocuiCwu5u0uohAPSkFEYqzBswRdhUe+J3Ce5DVzKXUaqfnRxeVl7hFxA8IARySQj rdOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=xcObahmn+nrr83zfh05tWVTdAkOdXoaYlFTrwb+vDxw=; b=cdUI+4ZE+1v4veIdf9XHICzcVh4rQV4Pn7QecXgeOLCtfXppzI9k9oV91uCqYccuVT /cfD1Ou75ryEHbPTKMm7m1Au1rKb2JB3wBq82ayEn7QgQA0bgAdrdzK2DxT3mMQW99sJ /Qq18j0HTpLyXOt3raoRMVH2Ol9SSzRmYkbmIrqonTZx8KLM85BIBP4+IzYdSdqF1eWF ALzSNfoT1w2ZI25qWHe+Xmswq3s1/c2BJNlppmKmGOjUg4HrqA0KLflsC0AIkXZduIzp OgBFIfAdO/h6TX1hSz790v12HnlyDeZeZ5Wntmdn4lEwT8ol9IzvNMd57ob0Ua80dAgu sN8w== X-Gm-Message-State: AOAM532TQfLao3ZFWnf8xm3E/j8Xa3RStzhJnkI04vpyFxBTX37kt7c4 RovC7Lv6X1xWpP5+8mnh0dz2rcaADA== X-Google-Smtp-Source: ABdhPJz1b1Axug1WWI+1xRe0YSX8kMPS6z8VQ8CJ0thqYCiLI9VeUYCGXaKQD6xIAXx4V6nEcFtte+5HyQ== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:6800:c1ea:4271:5898]) (user=elver job=sendgmr) by 2002:a05:600c:2193:: with SMTP id e19mr4229864wme.40.1631024053139; Tue, 07 Sep 2021 07:14:13 -0700 (PDT) Date: Tue, 7 Sep 2021 16:13:06 +0200 In-Reply-To: <20210907141307.1437816-1-elver@google.com> Message-Id: <20210907141307.1437816-6-elver@google.com> Mime-Version: 1.0 References: <20210907141307.1437816-1-elver@google.com> X-Mailer: git-send-email 2.33.0.153.gba50c8fa24-goog Subject: [PATCH 5/6] kasan: generic: introduce kasan_record_aux_stack_noalloc() From: Marco Elver To: elver@google.com Cc: Andrew Morton , Shuah Khan , Tejun Heo , Lai Jiangshan , Andrey Konovalov , Walter Wu , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Vijayanand Jitta , Vinayak Menon , "Gustavo A. R. Silva" , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Aleksandr Nogikh , Taras Madan Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=PwTMtZh9; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of 3tXM3YQUKCIosz9s5u22uzs.q20zw18B-00y9oqy.25u@flex--elver.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=3tXM3YQUKCIosz9s5u22uzs.q20zw18B-00y9oqy.25u@flex--elver.bounces.google.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 6DF817001700 X-Stat-Signature: wiom7hwpi9yat37ka536fccy79oefd8z X-HE-Tag: 1631024054-457349 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: Introduce a variant of kasan_record_aux_stack() that does not do any memory allocation through stackdepot. This will permit using it in contexts that cannot allocate any memory. Signed-off-by: Marco Elver --- include/linux/kasan.h | 2 ++ mm/kasan/generic.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index dd874a1ee862..736d7b458996 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -370,12 +370,14 @@ static inline void kasan_unpoison_task_stack(struct task_struct *task) {} void kasan_cache_shrink(struct kmem_cache *cache); void kasan_cache_shutdown(struct kmem_cache *cache); void kasan_record_aux_stack(void *ptr); +void kasan_record_aux_stack_noalloc(void *ptr); #else /* CONFIG_KASAN_GENERIC */ static inline void kasan_cache_shrink(struct kmem_cache *cache) {} static inline void kasan_cache_shutdown(struct kmem_cache *cache) {} static inline void kasan_record_aux_stack(void *ptr) {} +static inline void kasan_record_aux_stack_noalloc(void *ptr) {} #endif /* CONFIG_KASAN_GENERIC */ diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index 2a8e59e6326d..84a038b07c6f 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -328,7 +328,7 @@ DEFINE_ASAN_SET_SHADOW(f3); DEFINE_ASAN_SET_SHADOW(f5); DEFINE_ASAN_SET_SHADOW(f8); -void kasan_record_aux_stack(void *addr) +static void __kasan_record_aux_stack(void *addr, bool can_alloc) { struct page *page = kasan_addr_to_page(addr); struct kmem_cache *cache; @@ -345,7 +345,17 @@ void kasan_record_aux_stack(void *addr) return; alloc_meta->aux_stack[1] = alloc_meta->aux_stack[0]; - alloc_meta->aux_stack[0] = kasan_save_stack(GFP_NOWAIT, true); + alloc_meta->aux_stack[0] = kasan_save_stack(GFP_NOWAIT, can_alloc); +} + +void kasan_record_aux_stack(void *addr) +{ + return __kasan_record_aux_stack(addr, true); +} + +void kasan_record_aux_stack_noalloc(void *addr) +{ + return __kasan_record_aux_stack(addr, false); } void kasan_set_free_info(struct kmem_cache *cache, From patchwork Tue Sep 7 14:13:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 12478827 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=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 1C417C433EF for ; Tue, 7 Sep 2021 14:14:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C2B8961106 for ; Tue, 7 Sep 2021 14:14:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C2B8961106 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 67E4494000C; Tue, 7 Sep 2021 10:14:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 60797940007; Tue, 7 Sep 2021 10:14:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4CF1E94000C; Tue, 7 Sep 2021 10:14:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0190.hostedemail.com [216.40.44.190]) by kanga.kvack.org (Postfix) with ESMTP id 3EE80940007 for ; Tue, 7 Sep 2021 10:14:17 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 06A08181B0493 for ; Tue, 7 Sep 2021 14:14:17 +0000 (UTC) X-FDA: 78560972154.29.FBC5243 Received: from mail-ed1-f73.google.com (mail-ed1-f73.google.com [209.85.208.73]) by imf07.hostedemail.com (Postfix) with ESMTP id B0B1D10000BA for ; Tue, 7 Sep 2021 14:14:16 +0000 (UTC) Received: by mail-ed1-f73.google.com with SMTP id m30-20020a50999e000000b003cdd7680c8cso382224edb.11 for ; Tue, 07 Sep 2021 07:14:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=7ChlQWANvSBXBNUBCDuMgq5Cekd+HYTjR/ntyIg1Zyg=; b=edoUkiH2Kkf33Hq4VE8PDcQnBfHm5jDj20cp4k+Ev2uzNaB5gKzMC6RyQBjJ/HqWeA 9uhk1YYgKb1sTHBCprikkPstROStRUGJt+ih9Bl0vPYrM4fJzRNU+8YVNEU2c/lesHKs fMkeV5JG0zhQBnMlXbQB78wv25kORlv1naya33fky1/kGMs6AoB4XkDmbXevrTe9zsdB 3gvNw2jML5LfuIwNd8Uu5m9X7nB5Sy0pv7mJcrSPiRtPY0KRkWCf8dbv6a6uZAWAdm7w HYrhWzMSDLxOwDjA2liJXFub2QPHIr2N2pdYf3Z6AsIazDG3kWr4p7d8hMmTeoUc2pBb Q5/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=7ChlQWANvSBXBNUBCDuMgq5Cekd+HYTjR/ntyIg1Zyg=; b=rmGzvdsHBrP0uq6fT8sRPdehKS+Mn1NrU5BcW03yWtfYrgRCnY96CDGB7mnZesuJm0 NUSh/PUcygSmwHPeqH/UiI2jDRQux06Q3ksmAeaWC58mDEP1eBOxhmcAo0AIW/BF8VVS Bfx74lmNBDH/t+xie22m3obusgbPmpyDvjMthc/ugqenWlCDu6DQh80SSFbHwZeAKn6t YFm4VnS60syug/dgsaZMan0KKGwIM/sT/VkpmzgRN9iUp9xE1MSypnPAVbSTq0sv1D4m VflL748JXWpbhQT2gvLTnkUr8MsPtTMb/rizQcB4IhZ7Nlax/UQbWR1w9UXHfc68m4A9 trTw== X-Gm-Message-State: AOAM533sUAe3w0psLPi5QiLPSszw/IeDjPYVHFNXICxDy6GL6tC1h3rb G619SGf4rKfdtM5DsrwKww9b/wsiTw== X-Google-Smtp-Source: ABdhPJyGsdfkionufVLXwZil0TbakqGI5ZpVw9BOrl5sbBB/o1m93aEaygEZ4Rn6IuxIMOU0utYtynfPFQ== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:6800:c1ea:4271:5898]) (user=elver job=sendgmr) by 2002:a05:6402:3107:: with SMTP id dc7mr18886580edb.341.1631024055406; Tue, 07 Sep 2021 07:14:15 -0700 (PDT) Date: Tue, 7 Sep 2021 16:13:07 +0200 In-Reply-To: <20210907141307.1437816-1-elver@google.com> Message-Id: <20210907141307.1437816-7-elver@google.com> Mime-Version: 1.0 References: <20210907141307.1437816-1-elver@google.com> X-Mailer: git-send-email 2.33.0.153.gba50c8fa24-goog Subject: [PATCH 6/6] workqueue, kasan: avoid alloc_pages() when recording stack From: Marco Elver To: elver@google.com Cc: Andrew Morton , Shuah Khan , Tejun Heo , Lai Jiangshan , Andrey Konovalov , Walter Wu , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Vijayanand Jitta , Vinayak Menon , "Gustavo A. R. Silva" , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Aleksandr Nogikh , Taras Madan Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=edoUkiH2; spf=pass (imf07.hostedemail.com: domain of 3t3M3YQUKCIwu1Bu7w44w1u.s421y3AD-220Bqs0.47w@flex--elver.bounces.google.com designates 209.85.208.73 as permitted sender) smtp.mailfrom=3t3M3YQUKCIwu1Bu7w44w1u.s421y3AD-220Bqs0.47w@flex--elver.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: B0B1D10000BA X-Stat-Signature: tgqgic3nqhsr1hij1b4g4hmysmczrsbm X-HE-Tag: 1631024056-626507 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: Shuah Khan reported: | When CONFIG_PROVE_RAW_LOCK_NESTING=y and CONFIG_KASAN are enabled, | kasan_record_aux_stack() runs into "BUG: Invalid wait context" when | it tries to allocate memory attempting to acquire spinlock in page | allocation code while holding workqueue pool raw_spinlock. | | There are several instances of this problem when block layer tries | to __queue_work(). Call trace from one of these instances is below: | | kblockd_mod_delayed_work_on() | mod_delayed_work_on() | __queue_delayed_work() | __queue_work() (rcu_read_lock, raw_spin_lock pool->lock held) | insert_work() | kasan_record_aux_stack() | kasan_save_stack() | stack_depot_save() | alloc_pages() | __alloc_pages() | get_page_from_freelist() | rm_queue() | rm_queue_pcplist() | local_lock_irqsave(&pagesets.lock, flags); | [ BUG: Invalid wait context triggered ] The default kasan_record_aux_stack() calls stack_depot_save() with GFP_NOWAIT, which in turn can then call alloc_pages(GFP_NOWAIT, ...). In general, however, it is not even possible to use either GFP_ATOMIC nor GFP_NOWAIT in certain non-preemptive contexts, including raw_spin_locks (see gfp.h and ab00db216c9c7). Fix it by instructing stackdepot to not expand stack storage via alloc_pages() in case it runs out by using kasan_record_aux_stack_noalloc(). While there is an increased risk of failing to insert the stack trace, this is typically unlikely, especially if the same insertion had already succeeded previously (stack depot hit). For frequent calls from the same location, it therefore becomes extremely unlikely that kasan_record_aux_stack_noalloc() fails. Link: https://lkml.kernel.org/r/20210902200134.25603-1-skhan@linuxfoundation.org Reported-by: Shuah Khan Signed-off-by: Marco Elver Acked-by: Tejun Heo --- kernel/workqueue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 50142fc08902..0681774e6908 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -1329,7 +1329,7 @@ static void insert_work(struct pool_workqueue *pwq, struct work_struct *work, struct worker_pool *pool = pwq->pool; /* record the work call stack in order to print it in KASAN reports */ - kasan_record_aux_stack(work); + kasan_record_aux_stack_noalloc(work); /* we own @work, set data and link */ set_work_pwq(work, pwq, extra_flags);