From patchwork Fri Nov 18 10:00:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 22244 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp102459wrr; Fri, 18 Nov 2022 02:10:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf4e1vtFZ75sbTKCyAqPuHGnmMbFM/nC2CgE6ARvYNwb1ffy+Ud8mAoYQrPtKyit5HCC0Nzh X-Received: by 2002:a17:90b:394e:b0:20a:6106:a283 with SMTP id oe14-20020a17090b394e00b0020a6106a283mr7199610pjb.107.1668766242385; Fri, 18 Nov 2022 02:10:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668766242; cv=none; d=google.com; s=arc-20160816; b=VpBjJtNAESZhCFH8D0sgGV8iM6UaTh5L9IIAC1GbYLOYvNpHey1IMiwN1guef4I7xa 35FNmLTs8/LjLH+in+SDGpVmYR4JvLoEYr0yS/Wr0SMvjNENEz96AH4tTC6+kq3hmpRE nLkKrxiTImbHthZWByQ4f+x1Dwwi0tCorjM8WuAgo+Judp+q5v6S20fT68/m1Ftzwjdt FzeMN4ol5bK0rKFGA4iQM96ls7vPdda6oInaOPhdy3wk+1LU04IhtG6y8Lmd6lt9i/m+ 0jNI7rxVthZ8DUZvHlUPjncphIzmiNDG5ikftpZ+LKJ49SjlP2nvPebAdweWZBGLx2em 7QHg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=w4Tv0F1uItwO4IHFiNDZHG9aEzkG+Q+HP5zfgRRlg7Q=; b=QqsS9fEuDibTz74I+uDBC6mTV3m/7fcXbUOtRjR6i5sRfhqvbJgMWM3Sthw57BTb6P PO1gBj7jy2/g5TPk6eCUJM9ZNJH37lB47ubiWGIi+15ylxqm/8ITicWtX9yOHtUHD/+1 d0f7WTwyy3G2qGW1w19q1yH528+dWvKDx0KKt6abXumCrdfNzXDD2ZIZ/TWeTY41tdxS hZ3eNZoq2o4Ta+lcOPfWtfwDL5FutXZnUF81v10ORQsjaA2SzmypSnzqYOs5KDN8H22u QTiGuNSVKpUMPrKPSI3BCoHNK14Yx3Zdf/IFOgWwITYkwfdOsETqIqDGDU9sLPjEVneH A1OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=lseM9UHt; 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 l6-20020a170902ec0600b00186e34524besi3106768pld.522.2022.11.18.02.10.29; Fri, 18 Nov 2022 02:10:42 -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=lseM9UHt; 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 S241240AbiKRKA3 (ORCPT + 99 others); Fri, 18 Nov 2022 05:00:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235245AbiKRKAY (ORCPT ); Fri, 18 Nov 2022 05:00:24 -0500 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E9D54C27E for ; Fri, 18 Nov 2022 02:00:22 -0800 (PST) Received: by mail-pj1-x1034.google.com with SMTP id e7-20020a17090a77c700b00216928a3917so7851210pjs.4 for ; Fri, 18 Nov 2022 02:00:22 -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:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=w4Tv0F1uItwO4IHFiNDZHG9aEzkG+Q+HP5zfgRRlg7Q=; b=lseM9UHtQiSZ5wY8hPbQUGoaPEPzQ2N4x5yTzW3cVgV1oqQ7kONRnY3bNQ7o5TurHT ZJHvXvXxNrWZENrgIr3MoKP4IIAsCK5xsrneVz2kCe3EAzcLKMzuXYnuCmp774nlmizR V6Xist7V8Qc5qrBOsrgRug0vCgLJhrfi/2/5ufqo5k05Kpwlkhq/EG95pTLNwKkarURn XIrfDCuPPnCPwOpICKjcmJcezfJeWTERGRTbqlacXzig465HsZpXK+MzmeG8KYIKFajR ixdRkOzWla7EwqxCFBc/iMor6RvoKGaFSRU4R86r/fI0b5bdSWm40+WL5zSh15pSxXTR CSZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=w4Tv0F1uItwO4IHFiNDZHG9aEzkG+Q+HP5zfgRRlg7Q=; b=VI1xed2gMg92gHIqoCLbKVoBZoxOfwV9PuYtKhpqIzQ1+97B5jaHz64EYGDpfxVWZk e6hDJl1qX62204kuvTjfU3YaRK665bdJYcSvSl64l5pbIND7YMgdt6HBYrFfi5bVj4SL 1pNWxQXR41Vi8jZOOGmwfHrO8bIdSXzgar+EqSn3nbvJUCBE6eLZsf8NKIzI2N6ieQUY 3fC75x2MrAV4q/32ZTRkeoC4Tl2icmOtBRrUSO/4C4cLmggf+LCWfRxObHn23pfAn/ig E7qaRPEj1tteNJV1geG4URHflyG+XyQPcQ8faYzEEj2/z2kFTHuBJAhHs3Az3zyAbPWi itAQ== X-Gm-Message-State: ANoB5pk1Nn5A3ewGJDM2swHTqf3dORxitD0kr5YBF1ZlV0YK6/F9w+aq OWEYSfysSbOFZa8yfuMS7Ij7zg== X-Received: by 2002:a17:90b:4390:b0:218:4d16:e0c7 with SMTP id in16-20020a17090b439000b002184d16e0c7mr7118201pjb.105.1668765621883; Fri, 18 Nov 2022 02:00:21 -0800 (PST) Received: from C02DW0BEMD6R.bytedance.net ([2404:9dc0:cd01::24]) by smtp.gmail.com with ESMTPSA id n10-20020a6563ca000000b0043a18cef977sm2439463pgv.13.2022.11.18.02.00.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Nov 2022 02:00:21 -0800 (PST) From: Qi Zheng To: akpm@linux-foundation.org Cc: akinobu.mita@gmail.com, dvyukov@google.com, jgg@nvidia.com, willy@infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, stable@vger.kernel.org, Qi Zheng Subject: [PATCH v3] mm: fix unexpected changes to {failslab|fail_page_alloc}.attr Date: Fri, 18 Nov 2022 18:00:11 +0800 Message-Id: <20221118100011.2634-1-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) 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=unavailable 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?1749828231394905494?= X-GMAIL-MSGID: =?utf-8?q?1749828231394905494?= 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 Reviewed-by: Akinobu Mita Reviewed-by: Jason Gunthorpe --- v1: https://lore.kernel.org/lkml/20221107033109.59709-1-zhengqi.arch@bytedance.com/ v2: https://lore.kernel.org/lkml/20221108035232.87180-1-zhengqi.arch@bytedance.com/ Changelog in v2 -> v3: - collect Reviewed-by - rebase onto the next-20221118 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, \ } #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 f7a63684e6c4..baf97166172c 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3909,6 +3909,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) @@ -3919,10 +3921,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