Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp6070675rdb; Mon, 18 Sep 2023 03:19:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEb9PbgBGrldnHio5AZYHsAHgxVubJD8I5cK16Y4WlMiqYgyRjtSPk64INjb1w/2l/s7Gdr X-Received: by 2002:a05:6870:568a:b0:1b7:2d92:58d6 with SMTP id p10-20020a056870568a00b001b72d9258d6mr12003893oao.32.1695032351414; Mon, 18 Sep 2023 03:19:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695032351; cv=none; d=google.com; s=arc-20160816; b=oAXYu1ZMyVCy1gxcm2VYY+em9Cd9Z8ga588dOJnrDupGFsCkJ4qQBuVtk3i87Gs034 muHFTc5vxQqBJveFdLC2/6/Bb0/FEmkgoznvXJc3YUWpN3kAmlDKMIBGp8p56IynwU0V fDEOwOiuxBKAXr7Ul5DpMrZHDPVNjUIZZg39g8TSzIFcQkrbDm0n68D0kAkm1dibrYpC W4CFUvHq/N1QdJZApGUXKLHyGc2dwRt83xN52iJENxEoatqJHj6mG8IX+ZS1f0ruVtce 7HRX4Sjc2Gp82GST6mrfelpYxp9lv5pfyUw9rD3yQpDTAR7Tcs1JvowDLqVV6IyLC10x VCmw== 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:message-id:subject:cc:to:from:date:dkim-signature; bh=xapoFvkjj3w53O3/VZ2BfXZWl7DGBJM29OWV7YTpgyI=; fh=iOANTSv2jWdIfRc0VsN5c9moqSuLSCLqzjLyJtdl5XA=; b=L7BDxJK4eFjaFlVbC6xaUO4U56mT1A/Locjf12GgKqS6MKwc4/CY8Kn1rvyk2I8xIj CA4TyTrOIdvaB3ncsjU2ugRMGWEMJ4OoSdze4CIakWG5QhjHGpCbTrrbSXwFBY1XggEO a3olPrid9Q2LOigj1c761CBvAIvFd9rVIHBSkDv+6UoMlb08NPpctGHl/1Ujy+HOHHLb lubeUFdhGnY+zDiqKgbig0gjswImr7ZLwqQ53aZ/Ti4EY6HV+voLVDGHfFgNlpaljhxD VoT0k1f/k2VFeKeESjwLmIAIqWXAo+5YKic+PVeZCyABDmdtkGj27P2ffu61bWhCJDTN Vrpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=x4BlyBJD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id s11-20020a17090a948b00b00271af83a25asi1694162pjo.59.2023.09.18.03.19.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 03:19:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=x4BlyBJD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 77DA08022001; Mon, 18 Sep 2023 01:11:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240285AbjIRIKu (ORCPT + 99 others); Mon, 18 Sep 2023 04:10:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240500AbjIRIK0 (ORCPT ); Mon, 18 Sep 2023 04:10:26 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D87394; Mon, 18 Sep 2023 01:10:20 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 738C4C433C7; Mon, 18 Sep 2023 08:10:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1695024620; bh=CRIeDeVdhZmvgG8ZW1WaCGgmchWzoCZjUdxtSTLJV/A=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=x4BlyBJDiBWr1kd1Ig5VTJA/mMN3WIZiY996QmmespWNm9IV8PFWp3yInsK68FA9X pAu+exvk7+koqJmeI5LwNpb+dUoceo1O/C6DB6/ykYfPdnYwTvI53vdUXWg81qQogQ l0viG6PRuoPEA5xzSfKbu9QpAHlcpPq/YPeeX2KU= Date: Mon, 18 Sep 2023 10:10:16 +0200 From: Greg Kroah-Hartman To: Muhammad Usama Anjum Cc: Jiri Slaby , Ingo Molnar , kernel@collabora.com, stable@vger.kernel.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Subject: Re: [PATCH v3] tty/sysrq: replace smp_processor_id() with get_cpu() Message-ID: <2023091835-quill-congress-b691@gregkh> References: <20230822102606.2821311-1-usama.anjum@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230822102606.2821311-1-usama.anjum@collabora.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,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 fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 18 Sep 2023 01:11:34 -0700 (PDT) On Tue, Aug 22, 2023 at 03:26:06PM +0500, Muhammad Usama Anjum wrote: > The smp_processor_id() shouldn't be called from preemptible code. > Instead use get_cpu() and put_cpu() which disables preemption in > addition to getting the processor id. This fixes the following bug: > > [ 119.143590] sysrq: Show backtrace of all active CPUs > [ 119.143902] BUG: using smp_processor_id() in preemptible [00000000] code: bash/873 > [ 119.144586] caller is debug_smp_processor_id+0x20/0x30 > [ 119.144827] CPU: 6 PID: 873 Comm: bash Not tainted 5.10.124-dirty #3 > [ 119.144861] Hardware name: QEMU QEMU Virtual Machine, BIOS 2023.05-1 07/22/2023 > [ 119.145053] Call trace: > [ 119.145093] dump_backtrace+0x0/0x1a0 > [ 119.145122] show_stack+0x18/0x70 > [ 119.145141] dump_stack+0xc4/0x11c > [ 119.145159] check_preemption_disabled+0x100/0x110 > [ 119.145175] debug_smp_processor_id+0x20/0x30 > [ 119.145195] sysrq_handle_showallcpus+0x20/0xc0 > [ 119.145211] __handle_sysrq+0x8c/0x1a0 > [ 119.145227] write_sysrq_trigger+0x94/0x12c > [ 119.145247] proc_reg_write+0xa8/0xe4 > [ 119.145266] vfs_write+0xec/0x280 > [ 119.145282] ksys_write+0x6c/0x100 > [ 119.145298] __arm64_sys_write+0x20/0x30 > [ 119.145315] el0_svc_common.constprop.0+0x78/0x1e4 > [ 119.145332] do_el0_svc+0x24/0x8c > [ 119.145348] el0_svc+0x10/0x20 > [ 119.145364] el0_sync_handler+0x134/0x140 > [ 119.145381] el0_sync+0x180/0x1c0 > > Cc: stable@vger.kernel.org > Fixes: 47cab6a722d4 ("debug lockups: Improve lockup detection, fix generic arch fallback") > Signed-off-by: Muhammad Usama Anjum > --- > Changes since v2: > - Add changelog and resend > > Changes since v1: > - Add "Cc: stable@vger.kernel.org" tag > --- > drivers/tty/sysrq.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c > index 23198e3f1461a..6b4a28bcf2f5f 100644 > --- a/drivers/tty/sysrq.c > +++ b/drivers/tty/sysrq.c > @@ -262,13 +262,14 @@ static void sysrq_handle_showallcpus(u8 key) > if (in_hardirq()) > regs = get_irq_regs(); > > - pr_info("CPU%d:\n", smp_processor_id()); > + pr_info("CPU%d:\n", get_cpu()); Why not call put_cpu() right here? > if (regs) > show_regs(regs); > else > show_stack(NULL, NULL, KERN_INFO); > > schedule_work(&sysrq_showallcpus); > + put_cpu(); Why wait so long here after you have scheduled work? Please drop the cpu reference right away, you don't need to hold it for this length of time, right? thanks, greg k-h