From patchwork Mon Sep 13 11:26: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: 12488575 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.2 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 81891C433F5 for ; Mon, 13 Sep 2021 11:26:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2518961029 for ; Mon, 13 Sep 2021 11:26:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2518961029 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 B8B3D6B0072; Mon, 13 Sep 2021 07:26:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B3AA06B0073; Mon, 13 Sep 2021 07:26:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A2B91900002; Mon, 13 Sep 2021 07:26:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0004.hostedemail.com [216.40.44.4]) by kanga.kvack.org (Postfix) with ESMTP id 9632D6B0072 for ; Mon, 13 Sep 2021 07:26:31 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 4A6CF181AC9BF for ; Mon, 13 Sep 2021 11:26:31 +0000 (UTC) X-FDA: 78582322182.30.586369B Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf30.hostedemail.com (Postfix) with ESMTP id 0231FE001981 for ; Mon, 13 Sep 2021 11:26:30 +0000 (UTC) Received: by mail-wr1-f74.google.com with SMTP id r5-20020adfb1c5000000b0015cddb7216fso2477611wra.3 for ; Mon, 13 Sep 2021 04:26:30 -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=jCMn+6PWYm/AH96CM8EJiUE6dV7GrC639I1pxBug/fo=; b=eEroU4oVN2heQHlxNbvxaYfKjjK4j0WrUk+DRUAHoiLJ7PHD/WGsgXFEFk2f/wzLJg SqZ6jWZ4lFj2qIY+JsT3eI7pM9dA50VSRexQe6w5ozloiZMl7FxSpycCzFl8sVLTJGYg fTJTaY+wvvdvIxWWmm6pQDvpRsVYRE8hcujHELJkIoebWgQ8Nb1v4+c7QsgigSJJ3HpO TJqu31JeWWteM/HjzOBnSKRerXZvPCt9CGl0gogOcnVAGFFIrKMbs8h+ignHfeF3VTv6 JbJiosAcmcIfi6PnhXyiraPEuoc6RFK7e7fBDa/LWF/mM3/m9NhcHyI0g7IJHA1G9hN0 yxcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=jCMn+6PWYm/AH96CM8EJiUE6dV7GrC639I1pxBug/fo=; b=e8iJ4JJXc07VWoAbzqXtziXO+E5EJsnJpVdPPj+Kkg/clukdNQ6rVL19/GkXnJy7QS 0rltHppKch0I7x1tCoiulYYmR7VbdWPLep/ZV9cQqASpaoPxePphe7vAOAqKUYqVNXtT 1aoFMHyagddeXNfe9USQIq/iiKp4vKlHBPnl5xzpLY4GoE0bRANsw3TsrO8UAVCevsYu r/fscjm3xPbq8PqpVzgdyZCCUGcpAdkjs+erKMOqI+y3DL1rfxM/8LaZM4fuPFJAIjEQ EqHV+YUEhqJGJ31e8LDTbhZwKgoMtg8oawAkJ7ky+AKCQ4MR0vimxe2I+nsVx4ewX1y8 lMPg== X-Gm-Message-State: AOAM530I4dKyOgh5XY1aHIAtpkhlZVSvASg7qIHxjw4izw784l9D+7MG /ckEmOQfN7OR7bHu07nGqTk/nW3mKw== X-Google-Smtp-Source: ABdhPJwnccwL1pQ2aLBEviHvXVGI3QBXG8frezSWuniMCg1hwhbFkPmOVasOpj8typD1bkBIN3TYMGNvag== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:1f19:d46:38c8:7e48]) (user=elver job=sendgmr) by 2002:adf:e745:: with SMTP id c5mr11878126wrn.321.1631532389487; Mon, 13 Sep 2021 04:26:29 -0700 (PDT) Date: Mon, 13 Sep 2021 13:26:04 +0200 In-Reply-To: <20210913112609.2651084-1-elver@google.com> Message-Id: <20210913112609.2651084-2-elver@google.com> Mime-Version: 1.0 References: <20210913112609.2651084-1-elver@google.com> X-Mailer: git-send-email 2.33.0.309.g3052b89438-goog Subject: [PATCH v2 1/6] lib/stackdepot: include gfp.h From: Marco Elver To: elver@google.com, Andrew Morton Cc: Shuah Khan , Tejun Heo , Lai Jiangshan , Andrey Konovalov , Walter Wu , Sebastian Andrzej Siewior , Thomas Gleixner , 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-Stat-Signature: 3c7g5tm6g58cyxfb3wwozkwyin5ufypm Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=eEroU4oV; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf30.hostedemail.com: domain of 3ZTU_YQUKCNwCJTCPEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--elver.bounces.google.com designates 209.85.221.74 as permitted sender) smtp.mailfrom=3ZTU_YQUKCNwCJTCPEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--elver.bounces.google.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 0231FE001981 X-HE-Tag: 1631532390-996342 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 Tested-by: Shuah Khan Acked-by: Sebastian Andrzej Siewior --- 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 Mon Sep 13 11:26: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: 12488577 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.2 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 2B1B6C433F5 for ; Mon, 13 Sep 2021 11:26:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9DCDD60ED8 for ; Mon, 13 Sep 2021 11:26:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9DCDD60ED8 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 4382E6B0073; Mon, 13 Sep 2021 07:26:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C11A6B0074; Mon, 13 Sep 2021 07:26:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2B233900002; Mon, 13 Sep 2021 07:26:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0004.hostedemail.com [216.40.44.4]) by kanga.kvack.org (Postfix) with ESMTP id 1E46B6B0073 for ; Mon, 13 Sep 2021 07:26:33 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E2D078249980 for ; Mon, 13 Sep 2021 11:26:32 +0000 (UTC) X-FDA: 78582322224.15.477881C Received: from mail-qk1-f202.google.com (mail-qk1-f202.google.com [209.85.222.202]) by imf25.hostedemail.com (Postfix) with ESMTP id 98541B000185 for ; Mon, 13 Sep 2021 11:26:32 +0000 (UTC) Received: by mail-qk1-f202.google.com with SMTP id v21-20020a05620a0a9500b003d5c1e2f277so40514486qkg.13 for ; Mon, 13 Sep 2021 04:26:32 -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=heQI9hJRYZNN0F3wqdwBsNM0iszmJ1+UNOx43ei/BCA=; b=i2hbw8Fe7sVHU566q0FLXy62ugeDqkJJyt5CZ0CRDVVlErfT6R2EnyiQMD2UU2/8b0 ScsIl8ZafYdGmTDU17WrkZjAdWMBTxCG84VNlB90cTj1wPLvAbpdRu5MzsQCort61cMg 62WdBVzIcnTrZR5wU6SLRHuQPFSjZNCt/uUuQfyR84h4tq6uZoRPBXGeR6Bt69NhJd/8 nn7Kd4Bl1ctKe69OVC4+J5P9F+lHpQcq2TthmzMBZKOs7YMXnuXxKLh2KJ/WGDKyXb/C eMBlk2cF39wbq6Z8BALvgLIF4+TBDj+vD93yBLW4fvWl0PLVrsDqhQhFeBcpTMwHL6lg PW1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=heQI9hJRYZNN0F3wqdwBsNM0iszmJ1+UNOx43ei/BCA=; b=HWJcCFmvd/a03LXH49weX+kH7LZjSwdoxTOjyrRyEDYxEvg1wJ8WPlSYaipgkY4i4u Z62HCxbXQh3tS42uN5Gok3wwpm/VwjO0A5DyruuuyXAtha0ETiasWEQ+r7vVOKabrINa lKiIRPagUlQSZQKbQm74xI24YqN05md1QjC6g2VJ7J7Qu1VNrDN+T18d4bMizMxkGZx0 K9yDERCDXyA83l52UtHWO3HADYWDVUVxgt362xDn6qHVhW+pSxmC11XLm5MB9kRIWgt3 O6LNC4fm7zJMYRPCXpfdUf1zbRaV2BC1AeMvEbWXbfWGIyr3utAi3n+xnJUPsloXosmP tGjw== X-Gm-Message-State: AOAM533EjBVdo7EI8ymE6qvuK+CoicVD8ZaNk/Csg96damaQqcafa1QC PBUSDHRPCezdNchuAcsclWIFdxbYlA== X-Google-Smtp-Source: ABdhPJyW/EhPrZl53ptstiIf3nFkaM5zOt+a6HCqqc/9uUTbLofGIrfJ/QCoYU1DvLk95ohhAm6quwmfXQ== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:1f19:d46:38c8:7e48]) (user=elver job=sendgmr) by 2002:a05:6214:250f:: with SMTP id gf15mr10095078qvb.2.1631532391965; Mon, 13 Sep 2021 04:26:31 -0700 (PDT) Date: Mon, 13 Sep 2021 13:26:05 +0200 In-Reply-To: <20210913112609.2651084-1-elver@google.com> Message-Id: <20210913112609.2651084-3-elver@google.com> Mime-Version: 1.0 References: <20210913112609.2651084-1-elver@google.com> X-Mailer: git-send-email 2.33.0.309.g3052b89438-goog Subject: [PATCH v2 2/6] lib/stackdepot: remove unused function argument From: Marco Elver To: elver@google.com, Andrew Morton Cc: Shuah Khan , Tejun Heo , Lai Jiangshan , Andrey Konovalov , Walter Wu , Sebastian Andrzej Siewior , Thomas Gleixner , 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: imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=i2hbw8Fe; spf=pass (imf25.hostedemail.com: domain of 3ZzU_YQUKCN4ELVERGOOGLE.COMLINUX-MMKVACK.ORG@flex--elver.bounces.google.com designates 209.85.222.202 as permitted sender) smtp.mailfrom=3ZzU_YQUKCN4ELVERGOOGLE.COMLINUX-MMKVACK.ORG@flex--elver.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 98541B000185 X-Stat-Signature: 345scb9g7yawm5semyfqcjoh4xhs5pqi X-HE-Tag: 1631532392-835133 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 Tested-by: Shuah Khan Acked-by: Sebastian Andrzej Siewior --- 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 Mon Sep 13 11:26: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: 12488579 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.2 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 9845DC433EF for ; Mon, 13 Sep 2021 11:26:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4AD2660F38 for ; Mon, 13 Sep 2021 11:26:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4AD2660F38 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 DD68D6B0074; Mon, 13 Sep 2021 07:26:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D87DC900002; Mon, 13 Sep 2021 07:26:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C73E96B0078; Mon, 13 Sep 2021 07:26:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0218.hostedemail.com [216.40.44.218]) by kanga.kvack.org (Postfix) with ESMTP id BAB446B0074 for ; Mon, 13 Sep 2021 07:26:35 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 6372024388 for ; Mon, 13 Sep 2021 11:26:35 +0000 (UTC) X-FDA: 78582322350.01.3030800 Received: from mail-qk1-f202.google.com (mail-qk1-f202.google.com [209.85.222.202]) by imf23.hostedemail.com (Postfix) with ESMTP id 205699000093 for ; Mon, 13 Sep 2021 11:26:35 +0000 (UTC) Received: by mail-qk1-f202.google.com with SMTP id o4-20020ae9f504000000b003d39d97b227so40688341qkg.2 for ; Mon, 13 Sep 2021 04:26:34 -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=9lBuIl0uPI1ZQBCrnGIbYZD+uvnKuUY9gwGZHXFGUeM=; b=rfFKZJW7387I8bY6bZwe3tpbSrQulDsb6V7Xwc91XTAZqQ2rVHjixGGJPtC/N1ZUqQ yhGp8ziZ7XDZv++dd0r1xKomcebuFt3fXxSrL14JZIjrz/g8w0QFsopRiUg/0B2fCOH6 sHz903yPsr4JP3JTMVutIG/T3ajRAjA349fLtSXz14Z+WkEdiriM41DBAbg0wTdPuxG9 Lcx2B0ZuQeG1z+UazCNJm6rxW3utVeBQf7qnv1h3JL+uElYgkA03GRabboaMPc2S9oPD U5e58FCuQ2G0kN3WoUCCgjUslqVlfBfYUQAAwIp32EZpc3ctNvzIoyOFTt9EUg88uK6t XegA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=9lBuIl0uPI1ZQBCrnGIbYZD+uvnKuUY9gwGZHXFGUeM=; b=alWEh19Mg+WQdC80Tz58w26zXO8rY5RtF5JwoH6WYxYy0q0nRPQWnSySLAJEs72zUi LRRJ7RxxfzAGlPjZcT6zPpERymY9Let2J8hwsvNIWQBkugzM4Ezdfcm9I2hvs9sDffDx q58I9pq53seG+bcgLFW57365vQKx6aFBuCApX6ZpsXAWgC0CulkfyHzttCqdQ9fNfGcF mywFl4kknp8T2+uwHnGSE97bdaod4N+b4m6+9IkowsEolXnsRbRaFkNUYCMH3Iq9OBQU jNInfV56GaFP6T0Jw+pMKMqo2kxOfuiyWU5nLsZfVPThl/wqjHKycL+5QldeMpVNQzjp 9cVw== X-Gm-Message-State: AOAM5306JTOT/2FUnh9A2JXL7g/PNLSRL1bvrRae5lQJVpW10PBuczPC N/4xLng/fi2VaCUkUI2iqYM/tm8uIg== X-Google-Smtp-Source: ABdhPJyNUgHw7kceOqsp4Cupmd43ozMe7QekCJ0d68BoVeT370Wlv0ct72Ik/tHi4n3BsxxrwHEYtaLuOg== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:1f19:d46:38c8:7e48]) (user=elver job=sendgmr) by 2002:a0c:ffc3:: with SMTP id h3mr1804390qvv.22.1631532394351; Mon, 13 Sep 2021 04:26:34 -0700 (PDT) Date: Mon, 13 Sep 2021 13:26:06 +0200 In-Reply-To: <20210913112609.2651084-1-elver@google.com> Message-Id: <20210913112609.2651084-4-elver@google.com> Mime-Version: 1.0 References: <20210913112609.2651084-1-elver@google.com> X-Mailer: git-send-email 2.33.0.309.g3052b89438-goog Subject: [PATCH v2 3/6] lib/stackdepot: introduce __stack_depot_save() From: Marco Elver To: elver@google.com, Andrew Morton Cc: Shuah Khan , Tejun Heo , Lai Jiangshan , Andrey Konovalov , Walter Wu , Sebastian Andrzej Siewior , Thomas Gleixner , 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-Server: rspam01 X-Rspamd-Queue-Id: 205699000093 Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=rfFKZJW7; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf23.hostedemail.com: domain of 3ajU_YQUKCOEHOYHUJRRJOH.FRPOLQXa-PPNYDFN.RUJ@flex--elver.bounces.google.com designates 209.85.222.202 as permitted sender) smtp.mailfrom=3ajU_YQUKCOEHOYHUJRRJOH.FRPOLQXa-PPNYDFN.RUJ@flex--elver.bounces.google.com X-Stat-Signature: j16hjxwk8nax9omrufbjf1zhi1fqtop1 X-HE-Tag: 1631532395-303560 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 Tested-by: Shuah Khan Acked-by: Sebastian Andrzej Siewior --- v2: * Refer to __stack_depot_save() in comment of stack_depot_save(). --- include/linux/stackdepot.h | 4 ++++ lib/stackdepot.c | 43 ++++++++++++++++++++++++++++++++------ 2 files changed, 41 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..bda58597e375 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,26 @@ 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. + * See __stack_depot_save() for more details. + * + * 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 Mon Sep 13 11:26: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: 12488581 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.2 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 EB55DC433FE for ; Mon, 13 Sep 2021 11:26:38 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9E42760F44 for ; Mon, 13 Sep 2021 11:26:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9E42760F44 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 438EC6B0075; Mon, 13 Sep 2021 07:26:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3E8D76B0078; Mon, 13 Sep 2021 07:26:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 288A16B007B; Mon, 13 Sep 2021 07:26:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0217.hostedemail.com [216.40.44.217]) by kanga.kvack.org (Postfix) with ESMTP id 1B3EC6B0075 for ; Mon, 13 Sep 2021 07:26:38 -0400 (EDT) Received: from smtpin40.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id D4D428249980 for ; Mon, 13 Sep 2021 11:26:37 +0000 (UTC) X-FDA: 78582322434.40.4738860 Received: from mail-qv1-f73.google.com (mail-qv1-f73.google.com [209.85.219.73]) by imf16.hostedemail.com (Postfix) with ESMTP id 9B239F000091 for ; Mon, 13 Sep 2021 11:26:37 +0000 (UTC) Received: by mail-qv1-f73.google.com with SMTP id h9-20020a05621413a900b0037a2d3eaf8fso55845748qvz.8 for ; Mon, 13 Sep 2021 04:26:37 -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=ptSP4yyc5ltqSERpcwLdEP2vwQAqnRLUENIn1iThCXw=; b=lQJHcNeX6xmyAzHEBQijP50dslqB4ng/uZaXNlPMDkefvXL1DmklWKmkgYFNycLqh6 QqZ10XQ247wUWTQ2+uMyHvCrbximNAhp396NL4rInA4JSL8Y1fxCDV2JelnMx0Ndarrq 1iB+NB6DcgsFstDQpdu787ZRUaVXbr6bQJ8y60pGHOGar1RbB+jBt9vBN2OrR4Zmg2SC D3khYK6nF+5Wbzrq9be7/M/x9nXkcbXtPyOeanOwJ4M5+aHD4kQ2McxcB55ee7N396Ed 4/wIsAvhPXKTYR/JvOWtXQkyQi7jh+z85TBd7hBgH3lONGOFlRRPiZ2/BetPVsWzDX/v GH9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ptSP4yyc5ltqSERpcwLdEP2vwQAqnRLUENIn1iThCXw=; b=HDgkdEEuN7LFrJAYvTpziAoqDoPerytbewNaPQXNdAFTGgaUuY3jojVp4J40x97Lop tthBiOwY9ksd2MgGBCrDF2qlVEGQf37weSkz8HvuBqYYmIsEhBQ6rWlHDThNcEso+SPl FCugJwYzZBDdeRxZMEVNlMymTiUjRRA4Is2WV8ED6JJ/cYFqarXQGF2jMK3HTyiP1vP7 pPURYwSe8o0lHgX5cm+blxKZzi8/gwKLtV2P/J2e1SpFDMI+0EnxDFhgTVFwqusPyaSc sKlQpqPc5XDmShMwc70moxpF9abcqTx3EpATO9j+9wyzeSv10EfaTO5NJ5+MxyYg5Q6W 1jSQ== X-Gm-Message-State: AOAM5327AGkY9uTPzFhh0FaT+KQ9vpDKWfqsZsn0iqollEh7ImLtYYRI 3PL3d8mYj7ic/kAs5a/cUeuGx2GYeA== X-Google-Smtp-Source: ABdhPJwEq/LT0qtGFvFgCGkRgy6m1M7iEma80J+GQ4oANgWzfE9nbLt7djdJjIebizDl8HvmEU3Ms3Ha7Q== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:1f19:d46:38c8:7e48]) (user=elver job=sendgmr) by 2002:a05:6214:1142:: with SMTP id b2mr10077845qvt.0.1631532396945; Mon, 13 Sep 2021 04:26:36 -0700 (PDT) Date: Mon, 13 Sep 2021 13:26:07 +0200 In-Reply-To: <20210913112609.2651084-1-elver@google.com> Message-Id: <20210913112609.2651084-5-elver@google.com> Mime-Version: 1.0 References: <20210913112609.2651084-1-elver@google.com> X-Mailer: git-send-email 2.33.0.309.g3052b89438-goog Subject: [PATCH v2 4/6] kasan: common: provide can_alloc in kasan_save_stack() From: Marco Elver To: elver@google.com, Andrew Morton Cc: Shuah Khan , Tejun Heo , Lai Jiangshan , Andrey Konovalov , Walter Wu , Sebastian Andrzej Siewior , Thomas Gleixner , 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-Server: rspam01 X-Rspamd-Queue-Id: 9B239F000091 Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=lQJHcNeX; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf16.hostedemail.com: domain of 3bDU_YQUKCOMJQaJWLTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--elver.bounces.google.com designates 209.85.219.73 as permitted sender) smtp.mailfrom=3bDU_YQUKCOMJQaJWLTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--elver.bounces.google.com X-Stat-Signature: si1xzyq7cj9ogss1ah6yft6ddjwrbpo6 X-HE-Tag: 1631532397-332524 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: 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 Tested-by: Shuah Khan Acked-by: Sebastian Andrzej Siewior --- 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 8bf568a80eb8..fa6b48d08513 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -251,7 +251,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 Mon Sep 13 11:26:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 12488583 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.2 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 4C9A2C433EF for ; Mon, 13 Sep 2021 11:26:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D471460F44 for ; Mon, 13 Sep 2021 11:26:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D471460F44 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 7BADB6B0078; Mon, 13 Sep 2021 07:26:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 792676B007B; Mon, 13 Sep 2021 07:26:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A9A46B007D; Mon, 13 Sep 2021 07:26:40 -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 57B256B0078 for ; Mon, 13 Sep 2021 07:26:40 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 1A8FA1C967 for ; Mon, 13 Sep 2021 11:26:40 +0000 (UTC) X-FDA: 78582322560.17.D6B2F3F Received: from mail-qv1-f73.google.com (mail-qv1-f73.google.com [209.85.219.73]) by imf08.hostedemail.com (Postfix) with ESMTP id CFFF730000AB for ; Mon, 13 Sep 2021 11:26:39 +0000 (UTC) Received: by mail-qv1-f73.google.com with SMTP id a11-20020a0ca98b000000b0037855a1171fso55550454qvb.12 for ; Mon, 13 Sep 2021 04:26:39 -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=RLfVSTnmaFR6BCLsdGDNNy/lIjkdCKWfb/4pjdgI7U4=; b=FgLtShlMOVfjaXGo7f/oS0G8myvJmOGkAHupBhG1n66pC03AfWY1h02QQwxGm/BC2q NIiVoAt5RptGMta67XGFwYCxNjlG5g+z4pbIT5EDeS+HaFlHPyxz6XLuLeBlG+4Abr3v kYNbhUcrEFGFUE4/+CaCg1scl6StUbvOZxBpqOPfJgxIHfBIzP1tOoqI5daIERLmD/Xx y79UikpTXnQMSKEd6Zhq79VGWW3+g8XJG6WHCYb1QvfRVRgYch7iMM9pNUn3WOVf62yO rmPhlXm2OXvKXpmRroN3j6TxIJlZD+7fafvKRni0OdTZ5WyJIp789q/oqpIb9A8/9eM7 hrjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=RLfVSTnmaFR6BCLsdGDNNy/lIjkdCKWfb/4pjdgI7U4=; b=lVejBGjqh7eSx9jH7nwQQirKL4ljWIQklMWrMaRCAodS/j9Ss5yQqOhc2xdO1VNIWo EAzDWFwGN9vemju1KA4ADdxSM+nV2wSjE4vZNnvcJkQN0Wj24x4k2SW5KVLwcDVx/Pbi 3Y39gEObzEYNM/4QoFdUcEWmjUYLru24zB/8/en11mBJxdhHZdXh1m78EvZku1zS8lsR X5UZYGy7WanRfG3ij58uyD00f5qzKvSuC0oiOObjdm5gFvDTgZ1Cg6hJrRJ530S8Dx+R IrGFPaENvvdGttCZ6bwKZPbeRIXJiPn3hh6vxAL9nsg5vtjNUneaTcx0RXPCLC3f6oya c2pA== X-Gm-Message-State: AOAM531hpoQh24Exzp/PVB8Mieds/piBEleWRj+UK3MRd3gOfHVgLtk9 2542tIZCucIz9UV7U2d/RP5tm7ypJg== X-Google-Smtp-Source: ABdhPJwEBO7FeGHgJTcmfUUVA+smyLBjaAlSYjqDfG51drrvptWMJdaA6VPLMTvhcadpEq6oPbHI9LyatA== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:1f19:d46:38c8:7e48]) (user=elver job=sendgmr) by 2002:ad4:56a8:: with SMTP id bd8mr9898132qvb.0.1631532399089; Mon, 13 Sep 2021 04:26:39 -0700 (PDT) Date: Mon, 13 Sep 2021 13:26:08 +0200 In-Reply-To: <20210913112609.2651084-1-elver@google.com> Message-Id: <20210913112609.2651084-6-elver@google.com> Mime-Version: 1.0 References: <20210913112609.2651084-1-elver@google.com> X-Mailer: git-send-email 2.33.0.309.g3052b89438-goog Subject: [PATCH v2 5/6] kasan: generic: introduce kasan_record_aux_stack_noalloc() From: Marco Elver To: elver@google.com, Andrew Morton Cc: Shuah Khan , Tejun Heo , Lai Jiangshan , Andrey Konovalov , Walter Wu , Sebastian Andrzej Siewior , Thomas Gleixner , 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-Stat-Signature: ks7xr7n7jcq64hii5m3i9yr56ibqxboc Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=FgLtShlM; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf08.hostedemail.com: domain of 3bzU_YQUKCOYMTdMZOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--elver.bounces.google.com designates 209.85.219.73 as permitted sender) smtp.mailfrom=3bzU_YQUKCOYMTdMZOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--elver.bounces.google.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: CFFF730000AB X-HE-Tag: 1631532399-802244 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000005, 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 Tested-by: Shuah Khan Acked-by: Sebastian Andrzej Siewior --- 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 Mon Sep 13 11:26:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 12488585 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.2 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 3578EC433FE for ; Mon, 13 Sep 2021 11:26:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CDF8561029 for ; Mon, 13 Sep 2021 11:26:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org CDF8561029 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 745646B007B; Mon, 13 Sep 2021 07:26:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F5106B007D; Mon, 13 Sep 2021 07:26:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 60B466B007E; Mon, 13 Sep 2021 07:26:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0083.hostedemail.com [216.40.44.83]) by kanga.kvack.org (Postfix) with ESMTP id 517426B007B for ; Mon, 13 Sep 2021 07:26:43 -0400 (EDT) Received: from smtpin32.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 1A01B181AC9BF for ; Mon, 13 Sep 2021 11:26:43 +0000 (UTC) X-FDA: 78582322686.32.0614255 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf04.hostedemail.com (Postfix) with ESMTP id C52CC50000B3 for ; Mon, 13 Sep 2021 11:26:42 +0000 (UTC) Received: by mail-wr1-f74.google.com with SMTP id d10-20020adffbca000000b00157bc86d94eso2537437wrs.20 for ; Mon, 13 Sep 2021 04:26:42 -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=uXbisNK0hzVjo0x7v5RilsBzlcwLLC23aSoidmJI5Q0=; b=H9qgnMTa7AwCb5iArY+iTSmQ//hjkA1MCsuLuaE4/RUP/gDWt1slOPQx83Is1+UEkZ 7ldVIUBdbaEIP8vDVZbuoQ50dIniyyxtoZvPOB7cxVpBscdCyAJjLOWmnqdQeR+x+CNV R59jlsb5GGt4EU0SDMVHt3JiOYWGuHTSUdLo8AkvkHKv5yH8yYTSjCJrl4UZcNae/xqq wktQQsT9+pUVwO6scHnOqIkHX9607WZlLiri4nKPcHURD/uZZHKIepPX2DvcPENMqu+3 F0+uiIXW/gXBoLzzXUe4/bIjb/o7pcxzwMA2jaCf0hlT4hzHNQQxAMwxo+HxFlz61eyy yNow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=uXbisNK0hzVjo0x7v5RilsBzlcwLLC23aSoidmJI5Q0=; b=gfqEaCZEGIR82uYcPiy4Ah2ZjfvcHJhSTnhA635J9HA5EF2huxi6IPo8H5Z2s6mSNb wOGmES7BqSUc5uX+KzmHm0VSRkWtRIUpnSRCMZ43T3+Z6KDxerpVGYFFKde1gCjdgo/c UEDd4cIX2ayXbNXaGn13HXd0tE1awZcxIHLvsKGuE+H9oqvLL/w0PwtZ0V48F7Dst7Mz Ng6U0O3V9GTYFGxegPWytOlFuc2c8oStDQ4JaXYbc1s6oUnUouqcdW1zOFX9ylYZ5xjt 07kpYs3lIE3EaSlFhAzXsiZrX3oUNbEICH/KLV9ocly4ViJZQI2ZUKk8nRLrmK7tLQUh hWYw== X-Gm-Message-State: AOAM532y0X2UCUxVR7JgSeIg0JRyx9VKCzO/5HlGmeC+6RWdBritCKyF 93X8bqHXHhKWgIDziQqUX9OiRWQKag== X-Google-Smtp-Source: ABdhPJwrHYb2pQNJIWj/O8r94l5tGwmsJgjQ5oX69os6T91IbgkHBm7FGNsYkspC/6g0HsRIyu30TJmAcA== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:1f19:d46:38c8:7e48]) (user=elver job=sendgmr) by 2002:a05:600c:245:: with SMTP id 5mr9896478wmj.53.1631532401563; Mon, 13 Sep 2021 04:26:41 -0700 (PDT) Date: Mon, 13 Sep 2021 13:26:09 +0200 In-Reply-To: <20210913112609.2651084-1-elver@google.com> Message-Id: <20210913112609.2651084-7-elver@google.com> Mime-Version: 1.0 References: <20210913112609.2651084-1-elver@google.com> X-Mailer: git-send-email 2.33.0.309.g3052b89438-goog Subject: [PATCH v2 6/6] workqueue, kasan: avoid alloc_pages() when recording stack From: Marco Elver To: elver@google.com, Andrew Morton Cc: Shuah Khan , Tejun Heo , Lai Jiangshan , Andrey Konovalov , Walter Wu , Sebastian Andrzej Siewior , Thomas Gleixner , 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: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=H9qgnMTa; spf=pass (imf04.hostedemail.com: domain of 3cTU_YQUKCOgOVfObQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--elver.bounces.google.com designates 209.85.221.74 as permitted sender) smtp.mailfrom=3cTU_YQUKCOgOVfObQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--elver.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: C52CC50000B3 X-Stat-Signature: xp48xui5qk7z3wpzp5zbageryboribyg X-HE-Tag: 1631532402-285165 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 Tested-by: Shuah Khan Acked-by: Sebastian Andrzej Siewior 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 33a6b4a2443d..9a042a449002 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -1350,7 +1350,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);