Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp29193945rwd; Wed, 5 Jul 2023 08:26:08 -0700 (PDT) X-Google-Smtp-Source: APBJJlE8VqUna0/6s4KlvGUkJ9TEBj2cGrR5cq1im4IBxla0zfJs6IA2mxBLrJ20Cp8CiQBbHuu+ X-Received: by 2002:a17:903:1246:b0:1b4:5697:d991 with SMTP id u6-20020a170903124600b001b45697d991mr20890548plh.15.1688570768395; Wed, 05 Jul 2023 08:26:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688570768; cv=none; d=google.com; s=arc-20160816; b=FB/8sgUAIp0Me/67JoqZ1aGo1XMsXiULghtaWy7AUASuABfrlwvCT99G8OWLxZ/RQ7 xhC7BZz5YMdKOU+7PRKn2nCkvJIqoU59mrLk4KNFzza1bXyjcufuRb5XIpLkTeP1dKJc izF/5jXQYvWM9lNM1qiizmPLEqBZ64BpsWNEOS/4zC07XfYsxDODkClt2WmXdn+lh3my z//r1M7QnRCZxM55H12V6xfZj1mN1khAwmjPUfTkVGEftVK6HiQrvO/7ERtaUteBfMPg IopBk9/LTlOqs7zm5CfUVPLeL+PS5FIjQ8cvtbUNHmzuc5WaUmibRStJMtQI95F0678j LrYQ== 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; bh=Ktiz5JnGjct41q/JncoKfLTAzr51zniMpUOq72kwQDk=; fh=sZ3qLCU0RhUeDnDWtWVk2KPuPfXvOkCJdB5u1XVbboI=; b=dk9W48BYzjTmIiZ27TFQ7/RIEQN+y+OtpHnXetnm0BPpSTRZF8SvwBennAXBK4YcpW MsJSiJmRbHTV2rp5uN3EFfzSYXv7QGXocLr/fMRIO0UNFU73FXDcyyXKstFv7fyDcrcu saBgRdnEVmGpVQEXQSF24HTJY1LtuFuTHm3NRm5ljs/ts+Ad5/hw3ZOgYIjrgANQPIxK ww9pyVU816kVc/RWmMht4CpnDi248iM3b4KPqmmpiI+fNk3w+Diay11fOBPPNfKqvPhj m2txrQfQRvtbe4KC096fj7i3i991Afqjg0AWZpXPxYNG6wBdIEMEBC98cLWO7RH8rwE0 tHag== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w18-20020a170902d71200b001b3b2697004si22305020ply.333.2023.07.05.08.25.45; Wed, 05 Jul 2023 08:26:08 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231815AbjGEOyl (ORCPT + 99 others); Wed, 5 Jul 2023 10:54:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232303AbjGEOyi (ORCPT ); Wed, 5 Jul 2023 10:54:38 -0400 Received: from baptiste.telenet-ops.be (baptiste.telenet-ops.be [IPv6:2a02:1800:120:4::f00:13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE52C1985 for ; Wed, 5 Jul 2023 07:54:16 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:5979:7b6f:39a:b9cb]) by baptiste.telenet-ops.be with bizsmtp id HSuC2A00Z45Xpxs01SuCGm; Wed, 05 Jul 2023 16:54:13 +0200 Received: from rox.of.borg ([192.168.97.57] helo=rox) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1qH3tR-000ccO-2b; Wed, 05 Jul 2023 16:54:12 +0200 Received: from geert by rox with local (Exim 4.95) (envelope-from ) id 1qH3tU-00Aw3y-K5; Wed, 05 Jul 2023 16:54:12 +0200 From: Geert Uytterhoeven To: Andrew Morton , Dan Carpenter Cc: linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] lib: dhry: Fix sleeping allocations inside non-preemptable section Date: Wed, 5 Jul 2023 16:54:04 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE, 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 The Smatch static checker reports the following warnings: lib/dhry_run.c:38 dhry_benchmark() warn: sleeping in atomic context lib/dhry_run.c:43 dhry_benchmark() warn: sleeping in atomic context Indeed, dhry() does sleeping allocations inside the non-preemptable section delimited by get_cpu()/put_cpu(). Fix this by using atomic allocations instead. Add error handling, as atomic these allocations may fail. Fixes: 13684e966d46283e ("lib: dhry: fix unstable smp_processor_id(_) usage") Reported-by: Dan Carpenter Closes: https://lore.kernel.org/r/0469eb3a-02eb-4b41-b189-de20b931fa56@moroto.mountain Signed-off-by: Geert Uytterhoeven --- Alternatively, memory (de)allocation could be spin off into their own functions, and called outside the non-preemptable section. But that would be more intrusive. --- lib/dhry_1.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/dhry_1.c b/lib/dhry_1.c index 83247106824cc7f4..08edbbb19f573ff7 100644 --- a/lib/dhry_1.c +++ b/lib/dhry_1.c @@ -139,8 +139,15 @@ int dhry(int n) /* Initializations */ - Next_Ptr_Glob = (Rec_Pointer)kzalloc(sizeof(Rec_Type), GFP_KERNEL); - Ptr_Glob = (Rec_Pointer)kzalloc(sizeof(Rec_Type), GFP_KERNEL); + Next_Ptr_Glob = (Rec_Pointer)kzalloc(sizeof(Rec_Type), GFP_ATOMIC); + if (!Next_Ptr_Glob) + return -ENOMEM; + + Ptr_Glob = (Rec_Pointer)kzalloc(sizeof(Rec_Type), GFP_ATOMIC); + if (!Ptr_Glob) { + kfree(Next_Ptr_Glob); + return -ENOMEM; + } Ptr_Glob->Ptr_Comp = Next_Ptr_Glob; Ptr_Glob->Discr = Ident_1; -- 2.34.1