Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp955582iog; Mon, 13 Jun 2022 17:12:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqrD+GY3AEk0qNHGYVzMIMATuCVbUviaNHuxn/XdxE/ERneefYLPLN4qIv4ZDgMNdeOYra X-Received: by 2002:a05:6402:1f0e:b0:42d:e38a:51f7 with SMTP id b14-20020a0564021f0e00b0042de38a51f7mr2833599edb.68.1655165535090; Mon, 13 Jun 2022 17:12:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655165535; cv=none; d=google.com; s=arc-20160816; b=yDbk4+ps7Tpfnj+0up4/2TLhmTgZkwSJqlUXX0ntaCQ9OeOxC5AMCjOxV4YQldpMFY bFWZ81dKWjEPqgHcPB2mtzyRkIBt8qBvOLR9sQFtlJFj5fHZC1Z6eynU3Oqi5Mw2xehm uwtdDQUoojC3PR+JK3xg6C4lHwBb7JY5hhKU7CT69YZJ1u3gUJngn6i8q1hxv8E/z0Vw GEpzrgc/JoHuCawOKaO+cp3TukMpDhrS/NHxtmfbOykLcIK2dOX26rTYdPuqHMHPic3U xUigbmTbyyVlRY/DVXG1uVrO+NabHTWSFAo7N6iR0KyLNhy6Cu6/XwMxh3kQRMLECizQ X1IA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=77fjyb0O10zWM4Uxjs3yDlYfTzs9s7YOXSjoYiisHbg=; b=EJUD4GfRRfpPJvxiaHCQVrpetwgcAuo3waJFdb1BAbN5lhc8hlVXaNzWxKrQP4bSse w8QvdyRLArj3vWMyZtC4Uaa2Ya9YsWXxg4Ts7bxSq3VUsFvo6nVsca8GyIudtVrXiZ98 FQHyU673r43t8ICDDbojuH8/wzLwY0HRPA2Mrj9HIVfVKZDBNj/uQVNWXJ7Nt9E4YXJZ 6I2VTI/GCVWuWacb5afygrIzdcfMLoqV5RhLyAfsJv4vm0vsWSEWUNlZhfx5m3TcZBip qKU+8Nrbl/FZif6F5g49f0fqohSBamk7LPVoFeKs1zyWtVdXMc1ggbBC/8LowXcXkj4F 98Tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ILbgpOy1; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p21-20020a17090664d500b006e874b9da7fsi9310427ejn.28.2022.06.13.17.11.40; Mon, 13 Jun 2022 17:12:15 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=ILbgpOy1; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233996AbiFMXr4 (ORCPT + 99 others); Mon, 13 Jun 2022 19:47:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229848AbiFMXrz (ORCPT ); Mon, 13 Jun 2022 19:47:55 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58F85326EE; Mon, 13 Jun 2022 16:47:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EF37B614C2; Mon, 13 Jun 2022 23:47:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58B92C34114; Mon, 13 Jun 2022 23:47:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655164073; bh=5yF9QhQ4vupDYJDrsb4LKrVEEhEOsB8IRWAY1UxEZWA=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=ILbgpOy13nDDak7Lrna/R70a3H6ippqe2kRaGvA+m5KL0+jDHo99ikreSmx0POhv0 UONVHG2mxkMxs1XkWckhtVhKg+H71NcHCpXR5ENL7TwTwlWTN5j+JNsQ4Q7Ts86P8l IooymKlhbo3VDW5YJNiuRrEpndIn6Cfc00f6jRjfa8P0QSSUhcTeS+23Qpph0/T0uo Ko/C2/ULjscjW+buqIrv6O/87kmL2fN9lw1jYv+cuqfUIwZ10gdn6Yt33k4w1wJdaK P1U7YkCUVmT7yPlxqRsVQnTJr6Cwq7iujZIjCxF5b6AvDxaiVWUMKm39halM5BlZmL +YV97oW7vsmzw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id F3CE65C02F9; Mon, 13 Jun 2022 16:47:52 -0700 (PDT) Date: Mon, 13 Jun 2022 16:47:52 -0700 From: "Paul E. McKenney" To: Li Qiong Cc: Davidlohr Bueso , Josh Triplett , Frederic Weisbecker , Neeraj Upadhyay , Steven Rostedt , Lai Jiangshan , Joel Fernandes , linux-kernel@vger.kernel.org, rcu@vger.kernel.org, hukun@nfschina.com, qixu@nfschina.com, yuzhe@nfschina.com, renyu@nfschina.com Subject: Re: [PATCH v2] rcu: Handle failure of memory allocation functions Message-ID: <20220613234752.GL1790663@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20220611093055.1473-1-liqiong@nfschina.com> <20220612064825.32273-1-liqiong@nfschina.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220612064825.32273-1-liqiong@nfschina.com> X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On Sun, Jun 12, 2022 at 02:48:25PM +0800, Li Qiong wrote: > Add warning when these functions (eg:kmalloc,vmalloc) fail, handle the > failure. > > Signed-off-by: Li Qiong Queued for review and testing with a bit of wordsmithing, thank you! Please see below to check whether I messed something up. Thanx, Paul ------------------------------------------------------------------------ commit 19deffcffe66991c9a9e435ae90b16b97b83e4c1 Author: Li Qiong Date: Sun Jun 12 14:48:25 2022 +0800 rcu: Handle failure of memory allocation functions This commit adds warnings and ends the mem_dump_obj() test when allocation functions (kmalloc(), vmalloc(), ...) fail. Signed-off-by: Li Qiong Signed-off-by: Paul E. McKenney diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c index 21470ebb15eb4..ccc1af23dc1f2 100644 --- a/kernel/rcu/rcutorture.c +++ b/kernel/rcu/rcutorture.c @@ -2051,7 +2051,13 @@ static void rcu_torture_mem_dump_obj(void) static int z; kcp = kmem_cache_create("rcuscale", 136, 8, SLAB_STORE_USER, NULL); + if (WARN_ON_ONCE(!kcp)) + return; rhp = kmem_cache_alloc(kcp, GFP_KERNEL); + if (WARN_ON_ONCE(!rhp)) { + kmem_cache_destroy(kcp); + return; + } pr_alert("mem_dump_obj() slab test: rcu_torture_stats = %px, &rhp = %px, rhp = %px, &z = %px\n", stats_task, &rhp, rhp, &z); pr_alert("mem_dump_obj(ZERO_SIZE_PTR):"); mem_dump_obj(ZERO_SIZE_PTR); @@ -2068,6 +2074,8 @@ static void rcu_torture_mem_dump_obj(void) kmem_cache_free(kcp, rhp); kmem_cache_destroy(kcp); rhp = kmalloc(sizeof(*rhp), GFP_KERNEL); + if (WARN_ON_ONCE(!rhp)) + return; pr_alert("mem_dump_obj() kmalloc test: rcu_torture_stats = %px, &rhp = %px, rhp = %px\n", stats_task, &rhp, rhp); pr_alert("mem_dump_obj(kmalloc %px):", rhp); mem_dump_obj(rhp); @@ -2075,6 +2083,8 @@ static void rcu_torture_mem_dump_obj(void) mem_dump_obj(&rhp->func); kfree(rhp); rhp = vmalloc(4096); + if (WARN_ON_ONCE(!rhp)) + return; pr_alert("mem_dump_obj() vmalloc test: rcu_torture_stats = %px, &rhp = %px, rhp = %px\n", stats_task, &rhp, rhp); pr_alert("mem_dump_obj(vmalloc %px):", rhp); mem_dump_obj(rhp);