From patchwork Mon Nov 7 03:31:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 16223 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1810376wru; Sun, 6 Nov 2022 19:38:04 -0800 (PST) X-Google-Smtp-Source: AMsMyM6/1TRv6hiDr6VakQeXCPoABEMo3N9P4FoYNwZr3mLLvkLT5hg2gS0WjuXCkTUK9fkLO6Rx X-Received: by 2002:a17:90b:254e:b0:20b:7e26:f0a0 with SMTP id nw14-20020a17090b254e00b0020b7e26f0a0mr65038039pjb.203.1667792284048; Sun, 06 Nov 2022 19:38:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667792284; cv=none; d=google.com; s=arc-20160816; b=07y1YIFk0QZsMbrI1IOW3MtjRJGM/zLxF8ylVnT6zEqodKPZ7C51Jfp1JyIHROZKUA mjFbh/VN28GTQOiPONS1Fj7zBKVkgQx6y9pGBAnJt1+YWgLMV9slZKobuyH6I/OBLrXA 6+unIkPEm2XvxWX0VkD1KcYfzkYBFWHys/YoqTMqJS5tJye1EbCaqBvCsbT4nqvfpxct EmQAR2o8vBgoTRDNjn5rSzqUHf8FqXgWeMVW7IH9iBYr2tf3kJEM3GOQjz00PEuACSRR 3hQBlCQE4FV2RPfIffk8FFJF1pOJX63RpdxpzrlI02L/bLhhwWdnULfJZ8sFM0ajkyEq dg4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=czrfw6zGMNqQokKkTKz9bsRdwo0W+o1G6oGlRZsSGc0=; b=dw7o800JjhUeuZGhqacXkEu7x6oHZPIPyBswIoJTHNaHLgtignip3+oB0oGVO7Ybzv gE9IF8bHme0KzMhKEZy1tfdg3b9KF0qo9eXNS9fciNGlx/JfnVklWijjcijzqovH3YwC +EY+O+mzunNYytoAD8p5Mg9av2naCSzkxp6fSIzKvzm3g05DHLy5fA4Z+X1Y3G5QuWN/ ESYDudcxdUH4ho2txuR+FfX5skH83aTp4dWROCxEcpoY/0003kgwkeP2uf6Etix3Cpdj VB1w+h3/ztMX8KYq4ZqEx55Q9zxeCArgIAhwMAErWe6eG1oSNwl4ut900voCn0QbuRba DvaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=ZyVMHo5+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y13-20020a17090a2b4d00b001fd7d02c976si11843585pjc.87.2022.11.06.19.37.49; Sun, 06 Nov 2022 19:38:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=ZyVMHo5+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230345AbiKGDbm (ORCPT + 99 others); Sun, 6 Nov 2022 22:31:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230265AbiKGDbk (ORCPT ); Sun, 6 Nov 2022 22:31:40 -0500 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB0389FCC for ; Sun, 6 Nov 2022 19:31:38 -0800 (PST) Received: by mail-pl1-x636.google.com with SMTP id io19so9927519plb.8 for ; Sun, 06 Nov 2022 19:31: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:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=czrfw6zGMNqQokKkTKz9bsRdwo0W+o1G6oGlRZsSGc0=; b=ZyVMHo5+aBgoVD+dwght5ynvpKfVcgxqS+A7UJXaRSrZ57BXzMET9Cz0Hyk0rkJW+N lv/kEYz/SXtZ9/wvTGpSbLaM54f8PSdvwyl5ZIok2Li2vdEAdYoXKJ8IhvjbHp9lwiLj ftOT8lIf/KeQVNIoum8CuCpFajthTOq44oktTPOc8k7uHpgCnwB7EcDrpcF7vVCtqFHa IejjAwkdondAr1rQcITTh0vfuY2ka3w71qnNn+DnmwNS8E/aL8Od14/nQ32B3ausdyzT tgeXXAHmJEBSrE0eMqKEZRrUx5OsSWHlLahYD3k/AQAQxnhxtLWOkfHtvG8OP/7XzVcL k4Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=czrfw6zGMNqQokKkTKz9bsRdwo0W+o1G6oGlRZsSGc0=; b=l3kB7fuo821kjxeQURWcISw52mf82TKXkBy5hWFsrafx9hNn9sE6EEapGOnpIArXnK ny3mNaN3USUzjMLNG6yTm2T/7hAww687BlSBIM2p6+DjMuk1ytec4zGkC0TAScWv92Y2 WW5C+I1NazeldwcmFpR+UhBRegEjoLnea3WB6yx1H9QwXZmvInnijc3TGacBSdxXRBvG nvL6HJF14keCA8LFRQvGi/IJWGpeKuPVPXr9P6CzMifK13cpsBTnOMUbbFs5V9CuvTe4 kqHxtTTG/zwgC/mGXAukcHyxZs/4/1gsS1DuZj4DXYEcwnEUZv22UgdOexlvP/IDJxI0 yZJg== X-Gm-Message-State: ACrzQf0yUhV8qc0MhUXcDjFbeN4rUqgsV6G+zlT205/JJcfoihtCadDJ CXKafJiPSzKNbc40ZhTTK/8aRA== X-Received: by 2002:a17:90a:12c4:b0:213:fbf0:319a with SMTP id b4-20020a17090a12c400b00213fbf0319amr35375398pjg.65.1667791898468; Sun, 06 Nov 2022 19:31:38 -0800 (PST) Received: from C02DW0BEMD6R.bytedance.net ([139.177.225.251]) by smtp.gmail.com with ESMTPSA id ci11-20020a17090afc8b00b0020de216d0f7sm3179114pjb.18.2022.11.06.19.31.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Nov 2022 19:31:37 -0800 (PST) From: Qi Zheng To: 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, Qi Zheng , stable@vger.kernel.org Subject: [PATCH] mm: fix unexpected changes to {failslab|fail_page_alloc}.attr Date: Mon, 7 Nov 2022 11:31:09 +0800 Message-Id: <20221107033109.59709-1-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748806961926198486?= X-GMAIL-MSGID: =?utf-8?q?1748806961926198486?= 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 --- include/linux/fault-inject.h | 7 +++++-- lib/fault-inject.c | 14 +++++++++----- mm/failslab.c | 6 ++++-- mm/page_alloc.c | 6 ++++-- 4 files changed, 22 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, \ } #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..fc046f26606c 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; @@ -31,9 +33,9 @@ bool __should_failslab(struct kmem_cache *s, gfp_t gfpflags) return false; 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..e537d3a950a4 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) @@ -3913,9 +3915,9 @@ static bool __should_fail_alloc_page(gfp_t gfp_mask, unsigned int order) return false; 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