From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18694C433FE for ; Tue, 8 Nov 2022 09:45:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AAC166B0071; Tue, 8 Nov 2022 04:45:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A5C466B0073; Tue, 8 Nov 2022 04:45:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 94B538E0001; Tue, 8 Nov 2022 04:45:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 843A66B0071 for ; Tue, 8 Nov 2022 04:45:39 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 5D8904092C for ; Tue, 8 Nov 2022 09:45:39 +0000 (UTC) X-FDA: 80109792798.13.0B8656F Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by imf25.hostedemail.com (Postfix) with ESMTP id EF9B3A0002 for ; Tue, 8 Nov 2022 09:45:38 +0000 (UTC) Received: by mail-pj1-f54.google.com with SMTP id d59-20020a17090a6f4100b00213202d77e1so17406482pjk.2 for ; Tue, 08 Nov 2022 01:45:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=EltmttPv1aajbJvkkZuu7Ed6j0gX6iRdTC92MZ581LM=; b=qxi3KO8JxVnwxH2eg9/tQWmFmhBIhHu3k9DO+k/Kq7U9xxAjWj80r71Cz5IGxigvMY /407aRjDwa2glD8sOwb16KkkeEeZNzgOSFS5Ja/nmuXkQHFAO6OxOCmI3D5a3t54EYtd wvzcxaqi9UqGxRsvG7alqyGaLXnwQnpXj/Cj7F3MZUhyiy66UmlhNxGKdkSvvZ2RWiMZ jz1CMoqR44JveJpGe7A1ibnARmbEa4Dsdi2P9zTtd0aPbr/8pzRC8Okd3MOJ2Ni/6eEe /s8uV+x69EPHHRmvviUPtcjG4wmZqkCsibxIRxDgWoVaXnftkToIbtiGcGyxLwyC0xlI MKBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=EltmttPv1aajbJvkkZuu7Ed6j0gX6iRdTC92MZ581LM=; b=2dtA3r4ThyiTNqlpYr3AgfiS5TMeyz7u41T2l2Aruecm2tR3ZB6U4uto3tTwt/SB1i YPsDY81gl2JCAoZ4FzWwu0S+SaW+NMWRXICqPLQvvdxK46CLUAXD55t1uAqVwTQP10T1 +Dn+8WfR+yAKCTKHZcVO+9jEjWMPnbxK0GdlA4TX9TAdkGlm8sSBYjYEf+wpAiplAFfp gt4hyT1nsKiq+xNrwl0cbhmRtmXyJ742SzwX47huy5G3WHKacU2TIJLMmrI4XbHtVjeO rGKlHftgOWsoRf8Qrqm6BaJvbISUNDL9HtLJ4FVCQVm0LAUsttIquqHcVArVruZH4rWH mytw== X-Gm-Message-State: ACrzQf2UipfPdM+OiexmG7+H6Jb2+MSIG/2A7eJse6CUiYCwuh4CkDkH vGWrJuSHsrGmltDb/iqo0nzXXQ== X-Google-Smtp-Source: AMsMyM5Evx/Sr2yMfplQAAAxvuWIYOKr4w4wY6MlwMpN9xZGdZfHWXtdlE30rOjH1wlZIwvKyf+oVg== X-Received: by 2002:a17:902:9888:b0:186:9c32:79ca with SMTP id s8-20020a170902988800b001869c3279camr54710615plp.17.1667900737874; Tue, 08 Nov 2022 01:45:37 -0800 (PST) Received: from [10.255.93.192] ([139.177.225.251]) by smtp.gmail.com with ESMTPSA id j5-20020a170903024500b001785a72d285sm6548162plh.48.2022.11.08.01.45.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 08 Nov 2022 01:45:37 -0800 (PST) Message-ID: Date: Tue, 8 Nov 2022 17:45:30 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Subject: Re: [PATCH v2] mm: fix unexpected changes to {failslab|fail_page_alloc}.attr Content-Language: en-US To: Wei Yongjun , dvyukov@google.com, jgg@nvidia.com, willy@infradead.org, akinobu.mita@gmail.com Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, stable@vger.kernel.org References: <20221108035232.87180-1-zhengqi.arch@bytedance.com> <65863340-b32f-a2fe-67ae-f1079b19eee4@huawei.com> <70dfbac1-4c84-9567-30be-1e2594157e62@bytedance.com> From: Qi Zheng In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667900739; a=rsa-sha256; cv=none; b=J7oAXN0AJxlzGGLtSzXvtlAI/o707PARaoMvqESRJI4HbNV+5s1YJSedWGvHyzt5ifRJFL 0bKJu/fQlMYnUpHDcAR4S0wn5NRYtIRBf/LysV2NiS5p8hkiryhc8N1KwgLc0bkb3aCRrB GJ8JDD+dVdWocs7hqEeCGdt94MzijsU= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=qxi3KO8J; spf=pass (imf25.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.216.54 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667900739; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=EltmttPv1aajbJvkkZuu7Ed6j0gX6iRdTC92MZ581LM=; b=C99rmDRos7UCowHuE7gKTDuOaHPRYuz8gnMoim5XQrEjvZtT+qwNuBrCxYLgFHwKDQv296 p8b01dGEOJcHF7RTp3E76vKTXVP5ssA7+K3XMgV+CtYptZsxfylxomNeYu/+OEUop6GB4u I3mFWZmmzvL20UKeFVVRbC4AoZsxMao= Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=qxi3KO8J; spf=pass (imf25.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.216.54 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-Rspamd-Server: rspam12 X-Rspam-User: X-Stat-Signature: 7mknuaa9ksuj5ha6pnqhjk9kwfjmf3wz X-Rspamd-Queue-Id: EF9B3A0002 X-HE-Tag: 1667900738-560730 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: On 2022/11/8 17:32, Wei Yongjun wrote: > > > On 2022/11/8 16:58, Qi Zheng wrote: >> >> >> On 2022/11/8 16:44, Wei Yongjun wrote: >>> Hi Zheng Qi, >>> >>> On 2022/11/8 11:52, Qi Zheng wrote: >>>> When we specify __GFP_NOWARN, we only expect that no warnings >>>> will be issued for current caller. But in the __should_failslab() >>>> and __should_fail_alloc_page(), the local GFP flags alter the >>>> global {failslab|fail_page_alloc}.attr, which is persistent and >>>> shared by all tasks. This is not what we expected, let's fix it. >>>> >>>> Cc: stable@vger.kernel.org >>>> Fixes: 3f913fc5f974 ("mm: fix missing handler for __GFP_NOWARN") >>>> Reported-by: Dmitry Vyukov >>>> Signed-off-by: Qi Zheng >>>> --- >>>>   v1: https://lore.kernel.org/lkml/20221107033109.59709-1-zhengqi.arch@bytedance.com/ >>>> >>>>   Changelog in v1 -> v2: >>>>    - add comment for __should_failslab() and __should_fail_alloc_page() >>>>      (suggested by Jason) >>>> >>>>   include/linux/fault-inject.h |  7 +++++-- >>>>   lib/fault-inject.c           | 14 +++++++++----- >>>>   mm/failslab.c                | 12 ++++++++++-- >>>>   mm/page_alloc.c              |  7 +++++-- >>>>   4 files changed, 29 insertions(+), 11 deletions(-) >>>> >>>> diff --git a/include/linux/fault-inject.h b/include/linux/fault-inject.h >>>> index 9f6e25467844..444236dadcf0 100644 >>>> --- a/include/linux/fault-inject.h >>>> +++ b/include/linux/fault-inject.h >>>> @@ -20,7 +20,6 @@ struct fault_attr { >>>>       atomic_t space; >>>>       unsigned long verbose; >>>>       bool task_filter; >>>> -    bool no_warn; >>>>       unsigned long stacktrace_depth; >>>>       unsigned long require_start; >>>>       unsigned long require_end; >>>> @@ -32,6 +31,10 @@ struct fault_attr { >>>>       struct dentry *dname; >>>>   }; >>>>   +enum fault_flags { >>>> +    FAULT_NOWARN =    1 << 0, >>>> +}; >>>> + >>>>   #define FAULT_ATTR_INITIALIZER {                    \ >>>>           .interval = 1,                        \ >>>>           .times = ATOMIC_INIT(1),                \ >>>> @@ -40,11 +43,11 @@ struct fault_attr { >>>>           .ratelimit_state = RATELIMIT_STATE_INIT_DISABLED,    \ >>>>           .verbose = 2,                        \ >>>>           .dname = NULL,                        \ >>>> -        .no_warn = false,                    \ >>> >>> How about keep no_warn attr as it be, and export it to user? >>> >>> When testing with fault injection, and each fault will print an backtrace. >>> but not all of the testsuit can tell us which one is fault injection >>> message or other is a real warning/crash like syzkaller do. >>> >>> In my case, to make things simple, we usually used a regex to detect whether >>> wanring/error happend. So we disabled the slab/page fault warning message by >>> default, and only enable it when debug real issue. >> >> So you want to set/clear this no_warn attr through the procfs or sysfs >> interface, so that you can easily disable/enable the slab/page fault >> warning message from the user mode. Right? > > Yes, just like: > > echo 1 > /sys/kernel/debug/failslab/no_warn #disable message > echo 0 > /sys/kernel/debug/failslab/no_warn #enable message Got it. Let's wait for the other people's comments and suggestions. :) > > Regards > Wei Yongjun > >> >> Seems reasonable to me. Anyone else has an opinion on this? If it is >> really needed, I can do it later. >> >> Thanks, >> Qi >> >>> >>> Regards, >>> >>> >>>>       } >>>>     #define DECLARE_FAULT_ATTR(name) struct fault_attr name = FAULT_ATTR_INITIALIZER >>>>   int setup_fault_attr(struct fault_attr *attr, char *str); >>>> +bool should_fail_ex(struct fault_attr *attr, ssize_t size, int flags); >>>>   bool should_fail(struct fault_attr *attr, ssize_t size); >>>>     #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS >>>> diff --git a/lib/fault-inject.c b/lib/fault-inject.c >>>> index 4b8fafce415c..5971f7c3e49e 100644 >>>> --- a/lib/fault-inject.c >>>> +++ b/lib/fault-inject.c >>>> @@ -41,9 +41,6 @@ EXPORT_SYMBOL_GPL(setup_fault_attr); >>>>     static void fail_dump(struct fault_attr *attr) >>>>   { >>>> -    if (attr->no_warn) >>>> -        return; >>>> - >>>>       if (attr->verbose > 0 && __ratelimit(&attr->ratelimit_state)) { >>>>           printk(KERN_NOTICE "FAULT_INJECTION: forcing a failure.\n" >>>>                  "name %pd, interval %lu, probability %lu, " >>>> @@ -103,7 +100,7 @@ static inline bool fail_stacktrace(struct fault_attr *attr) >>>>    * http://www.nongnu.org/failmalloc/ >>>>    */ >>>>   -bool should_fail(struct fault_attr *attr, ssize_t size) >>>> +bool should_fail_ex(struct fault_attr *attr, ssize_t size, int flags) >>>>   { >>>>       bool stack_checked = false; >>>>   @@ -152,13 +149,20 @@ bool should_fail(struct fault_attr *attr, ssize_t size) >>>>           return false; >>>>     fail: >>>> -    fail_dump(attr); >>>> +    if (!(flags & FAULT_NOWARN)) >>>> +        fail_dump(attr); >>>>         if (atomic_read(&attr->times) != -1) >>>>           atomic_dec_not_zero(&attr->times); >>>>         return true; >>>>   } >>>> +EXPORT_SYMBOL_GPL(should_fail_ex); >>>> + >>>> +bool should_fail(struct fault_attr *attr, ssize_t size) >>>> +{ >>>> +    return should_fail_ex(attr, size, 0); >>>> +} >>>>   EXPORT_SYMBOL_GPL(should_fail); >>>>     #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS >>>> diff --git a/mm/failslab.c b/mm/failslab.c >>>> index 58df9789f1d2..ffc420c0e767 100644 >>>> --- a/mm/failslab.c >>>> +++ b/mm/failslab.c >>>> @@ -16,6 +16,8 @@ static struct { >>>>     bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags) >>>>   { >>>> +    int flags = 0; >>>> + >>>>       /* No fault-injection for bootstrap cache */ >>>>       if (unlikely(s == kmem_cache)) >>>>           return false; >>>> @@ -30,10 +32,16 @@ bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags) >>>>       if (failslab.cache_filter && !(s->flags & SLAB_FAILSLAB)) >>>>           return false; >>>>   +    /* >>>> +     * In some cases, it expects to specify __GFP_NOWARN >>>> +     * to avoid printing any information(not just a warning), >>>> +     * thus avoiding deadlocks. See commit 6b9dbedbe349 for >>>> +     * details. >>>> +     */ >>>>       if (gfpflags & __GFP_NOWARN) >>>> -        failslab.attr.no_warn = true; >>>> +        flags |= FAULT_NOWARN; >>>>   -    return should_fail(&failslab.attr, s->object_size); >>>> +    return should_fail_ex(&failslab.attr, s->object_size, flags); >>>>   } >>>>     static int __init setup_failslab(char *str) >>>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c >>>> index 7192ded44ad0..cb6fe715d983 100644 >>>> --- a/mm/page_alloc.c >>>> +++ b/mm/page_alloc.c >>>> @@ -3902,6 +3902,8 @@ __setup("fail_page_alloc=", setup_fail_page_alloc); >>>>     static bool __should_fail_alloc_page(gfp_t gfp_mask, unsigned int order) >>>>   { >>>> +    int flags = 0; >>>> + >>>>       if (order < fail_page_alloc.min_order) >>>>           return false; >>>>       if (gfp_mask & __GFP_NOFAIL) >>>> @@ -3912,10 +3914,11 @@ static bool __should_fail_alloc_page(gfp_t gfp_mask, unsigned int order) >>>>               (gfp_mask & __GFP_DIRECT_RECLAIM)) >>>>           return false; >>>>   +    /* See comment in __should_failslab() */ >>>>       if (gfp_mask & __GFP_NOWARN) >>>> -        fail_page_alloc.attr.no_warn = true; >>>> +        flags |= FAULT_NOWARN; >>>>   -    return should_fail(&fail_page_alloc.attr, 1 << order); >>>> +    return should_fail_ex(&fail_page_alloc.attr, 1 << order, flags); >>>>   } >>>>     #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS >> -- Thanks, Qi