Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4781137imw; Tue, 19 Jul 2022 13:08:41 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vUfgmMAVDPPMXKTYFn8giS8YAK0+w2gvOKTiR6LZj7OLEU8ssv3VJBwDLVefZ8FVpRgwlY X-Received: by 2002:a17:906:8478:b0:72b:4f81:29d8 with SMTP id hx24-20020a170906847800b0072b4f8129d8mr32352518ejc.179.1658261320900; Tue, 19 Jul 2022 13:08:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658261320; cv=none; d=google.com; s=arc-20160816; b=iaUUz7dPaIW/4ubYCnHNxnAr7iJARvQs8DBl6QUEgaeOv2Y5+N0N5mVqSecHl0ePdH f8ITqClCyAgi19XYt3yzZhto50jZ7FFNI+JRBMcOUM29IAq64pUJAewxH3h7pFCMtO8n P074KkoEeO2+V6S7LyrFX3j4b64i2Y7hoU8FwVQ4mAcgbuY7STyGqL3cFc8sJ9rexZAU rtxrGV4rIN83xidOZaP7K8NIJHbCN2FuVltsMhLzfaUv2ET1sB1vD8+a7Wd4ni2eMwOn 5tFIyLdNpA7IAcrfCXlhsb9Hh8gSazOLI8LCl7ZnzBycioiCVQqZaK8mFGQh1RNAWEip zGOA== 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=C1vK0PqoODM7/n3gyOjq8NgLf2lP/RehFU6zSZW0fzc=; b=UbT4Tr4v1twdj7s7MvVdWIZEVdDMj0VV1a82br26RkKSkDjYZvVfLfnJ/RB/A1Ga6d 03VIHbVauGaH4gZzLGRdlJBtsiHbpeXz9jGLNeqE2AhhWaDcXFo0W13r2XoI6aZufcCt y9mI1RGnChVSGXOkpYez/01C0kWh6+J7GpH3mBETRIG6jOPoV9ehnAIUp5w7uSu26XeH 7MoHPVIwAd5T85jWtyzY2K++mOb8SURYAlNF6/YGMs/2QNWMrbOuUcqgtFFNPmpsblPX OE5ut1WpC5xO75LlrKsFtyi8yqQiDxiF9aJYoyglYyXxw8YtoNSr04BLdd8i2BqY4r9c lOXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@igalia.com header.s=20170329 header.b=f8EgDLqs; 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 fg23-20020a1709069c5700b007262d20d6cesi3675040ejc.200.2022.07.19.13.08.15; Tue, 19 Jul 2022 13:08:40 -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=fail header.i=@igalia.com header.s=20170329 header.b=f8EgDLqs; 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 S239903AbiGST6z (ORCPT + 99 others); Tue, 19 Jul 2022 15:58:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239806AbiGST62 (ORCPT ); Tue, 19 Jul 2022 15:58:28 -0400 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C4B85E831; Tue, 19 Jul 2022 12:57:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=C1vK0PqoODM7/n3gyOjq8NgLf2lP/RehFU6zSZW0fzc=; b=f8EgDLqs9fiPg4nZcLPm2GylL6 GFiz2gnwuYyiUCMoOS3M5WoxW0K7sMN+Cn+RmnEfBcUIkDF/iK0gKF6SgYUgJ+072EfoKnczRB48j BtwV0OZzs3Z8d/bVifZPOFuRdkj5FanoI960l5fzfpk65Qmhs50r9Al4ujbJl7o86Mxhu1neT50Cs JY/nYTfazCtM3N+sEuP0oIe0o+9kqt01LGBKy2PImvVrGX3yzYNS9Fmp8pOyD8BpXan3hJYt6Sm2V 5iOhIzgUuSmXCszoMXx888rxqJKWrWLOVLz8N4rW7By+H9A50m0UF0iRO2e92fJAKpvpKdQg6ReHo w5iA5ShQ==; Received: from 200-100-212-117.dial-up.telesp.net.br ([200.100.212.117] helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1oDtLj-006fen-Cd; Tue, 19 Jul 2022 21:57:44 +0200 From: "Guilherme G. Piccoli" To: akpm@linux-foundation.org, bhe@redhat.com, pmladek@suse.com, kexec@lists.infradead.org Cc: linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, x86@kernel.org, kernel-dev@igalia.com, kernel@gpiccoli.net, halves@canonical.com, fabiomirmar@gmail.com, alejandro.j.jimenez@oracle.com, andriy.shevchenko@linux.intel.com, arnd@arndb.de, bp@alien8.de, corbet@lwn.net, d.hatayama@jp.fujitsu.com, dave.hansen@linux.intel.com, dyoung@redhat.com, feng.tang@intel.com, gregkh@linuxfoundation.org, mikelley@microsoft.com, hidehiro.kawai.ez@hitachi.com, jgross@suse.com, john.ogness@linutronix.de, keescook@chromium.org, luto@kernel.org, mhiramat@kernel.org, mingo@redhat.com, paulmck@kernel.org, peterz@infradead.org, rostedt@goodmis.org, senozhatsky@chromium.org, stern@rowland.harvard.edu, tglx@linutronix.de, vgoyal@redhat.com, vkuznets@redhat.com, will@kernel.org, "Guilherme G. Piccoli" , Andrea Parri , Dexuan Cui , Haiyang Zhang , "K. Y. Srinivasan" , Stephen Hemminger , Tianyu Lan , Wei Liu Subject: [PATCH v2 11/13] video/hyperv_fb: Avoid taking busy spinlock on panic path Date: Tue, 19 Jul 2022 16:53:24 -0300 Message-Id: <20220719195325.402745-12-gpiccoli@igalia.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719195325.402745-1-gpiccoli@igalia.com> References: <20220719195325.402745-1-gpiccoli@igalia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 The Hyper-V framebuffer code registers a panic notifier in order to try updating its fbdev if the kernel crashed. The notifier callback is straightforward, but it calls the vmbus_sendpacket() routine eventually, and such function takes a spinlock for the ring buffer operations. Panic path runs in atomic context, with local interrupts and preemption disabled, and all secondary CPUs shutdown. That said, taking a spinlock might cause a lockup if a secondary CPU was disabled with such lock taken. Fix it here by checking if the ring buffer spinlock is busy on Hyper-V framebuffer panic notifier; if so, bail-out avoiding the potential lockup scenario. Cc: Andrea Parri (Microsoft) Cc: Dexuan Cui Cc: Haiyang Zhang Cc: "K. Y. Srinivasan" Cc: Michael Kelley Cc: Stephen Hemminger Cc: Tianyu Lan Cc: Wei Liu Tested-by: Fabio A M Martins Signed-off-by: Guilherme G. Piccoli --- V2: - new patch, based on the discussion in [0]. [0] https://lore.kernel.org/lkml/2787b476-6366-1c83-db80-0393da417497@igalia.com/ drivers/hv/ring_buffer.c | 16 ++++++++++++++++ drivers/video/fbdev/hyperv_fb.c | 8 +++++++- include/linux/hyperv.h | 2 ++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c index 59a4aa86d1f3..9ceb3a7e8d19 100644 --- a/drivers/hv/ring_buffer.c +++ b/drivers/hv/ring_buffer.c @@ -280,6 +280,22 @@ void hv_ringbuffer_cleanup(struct hv_ring_buffer_info *ring_info) ring_info->pkt_buffer_size = 0; } +/* + * Check if the ring buffer spinlock is available to take or not; used on + * atomic contexts, like panic path (see the Hyper-V framebuffer driver). + */ + +bool hv_ringbuffer_spinlock_busy(struct vmbus_channel *channel) +{ + struct hv_ring_buffer_info *rinfo = &channel->outbound; + + if (spin_is_locked(&rinfo->ring_lock)) + return true; + + return false; +} +EXPORT_SYMBOL_GPL(hv_ringbuffer_spinlock_busy); + /* Write to the ring buffer. */ int hv_ringbuffer_write(struct vmbus_channel *channel, const struct kvec *kv_list, u32 kv_count, diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c index 886c564787f1..e1b65a01fb96 100644 --- a/drivers/video/fbdev/hyperv_fb.c +++ b/drivers/video/fbdev/hyperv_fb.c @@ -783,12 +783,18 @@ static void hvfb_ondemand_refresh_throttle(struct hvfb_par *par, static int hvfb_on_panic(struct notifier_block *nb, unsigned long e, void *p) { + struct hv_device *hdev; struct hvfb_par *par; struct fb_info *info; par = container_of(nb, struct hvfb_par, hvfb_panic_nb); - par->synchronous_fb = true; info = par->info; + hdev = device_to_hv_device(info->device); + + if (hv_ringbuffer_spinlock_busy(hdev->channel)) + return NOTIFY_DONE; + + par->synchronous_fb = true; if (par->need_docopy) hvfb_docopy(par, 0, dio_fb_size); synthvid_update(info, 0, 0, INT_MAX, INT_MAX); diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index 3b42264333ef..646f1da9f27e 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -1341,6 +1341,8 @@ struct hv_ring_buffer_debug_info { int hv_ringbuffer_get_debuginfo(struct hv_ring_buffer_info *ring_info, struct hv_ring_buffer_debug_info *debug_info); +bool hv_ringbuffer_spinlock_busy(struct vmbus_channel *channel); + /* Vmbus interface */ #define vmbus_driver_register(driver) \ __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME) -- 2.37.1