From patchwork Mon Oct 24 11:31:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8806 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp430928wru; Mon, 24 Oct 2022 05:42:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6iPjOjw+0wmA/11Ptqiv1Q6GQ/1pePH/ssijF9nMzTTpCqs/WEwayP5Aik2Ts/f+HUupZ1 X-Received: by 2002:a17:90a:b00a:b0:213:623:2c12 with SMTP id x10-20020a17090ab00a00b0021306232c12mr7105418pjq.153.1666615352916; Mon, 24 Oct 2022 05:42:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615352; cv=none; d=google.com; s=arc-20160816; b=OBlGfSSQT3ZDb9lnOh76guaqE0P3jLoT3xIZb9nw6S5nFNVqOlI7XaeTDsZsVGE9Hi LlE75VSKDFaUyLSsfhIb9kiZwpjb6RFli87gIyWddYLMZXWxRw7g7m1+mr0YqdnqlKpF 28UeyyZjKaUdUWCbxDC8bgtDLqMAOrmAeEfYeExfICVYqJrSuyWaxusWs3Vxcft5Gsi3 8SQvRlvXRBrHFfMa/QeGmOUk0IolEL2hrmzDHRlYP6SOpb4ViJ5BSXTFvZEGtGHLZltN J84UGEyrXA1GNGPsUm49V4MiZgKBQr6NPey+DPqdRRXzpp+mptVKJb9QnhNu8c+Kvggd WEtA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GnJpkuClr5zuRENPkKpllEHzXugCqzTNJizcrXcdXYc=; b=hhmVZoowEWrJE1Fj5DwWYLkYREG8Aanp1kZVAO4dL1jCkIW8SlKdgoGpfyvsxvpwGh DT7WNGUzHYwuZYQ3d2tAxgfpl9SXvPWTtKQ8S4Wa9m10MBA5sx9WX9elFnZq5KtpOjLq 9U2sbJPzu0afUfiHsk7DcMzXmOgjq7k2O6bgGM2jpGyigPJi5svsvsy4uJK3AjuJIvs3 avEcO0qkgDFZODQ8CtPexPbL49ve4RbUEsnD/KL1IOVEE9hyngOBNefCkupiIu6DEUla tK/HPCcTpL77PUuswdgGu6wmefygTFEtzNSdTdLhNCd3gfPvNecarLlGGs0F23TW7oHz kxlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QH+KIpME; 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=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bj4-20020a170902850400b001865c57b5adsi14898123plb.87.2022.10.24.05.42.19; Mon, 24 Oct 2022 05:42:32 -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=@linuxfoundation.org header.s=korg header.b=QH+KIpME; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234484AbiJXMfJ (ORCPT + 99 others); Mon, 24 Oct 2022 08:35:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234238AbiJXM3o (ORCPT ); Mon, 24 Oct 2022 08:29:44 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7449318F; Mon, 24 Oct 2022 05:03:45 -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 ams.source.kernel.org (Postfix) with ESMTPS id 8A56FB81219; Mon, 24 Oct 2022 12:01:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0437C433D7; Mon, 24 Oct 2022 12:01:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612862; bh=sqEKswuUxTriNBWzsTySPH303zgQ9wiLoNPZnKShKxM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QH+KIpMER4dTvd6y7DnAiakYLcSUPIDPfGTh2NlZf6AJnaTigTKrIbuR+xp8TwSok hWZc6MCuIz5kH79W2ys5z0nTqfw0aCiq8K2lZ7an9xx/2V+YtA9vL48MNHyFlIr/Mz 7aMLwu9cfpBdweTgYWhKCnQtrmvLjkfyki3rRUsE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrew Morton , Ard Biesheuvel , David Gow , Julius Werner , Petr Mladek , Evan Green , "Guilherme G. Piccoli" , Sasha Levin Subject: [PATCH 4.19 146/229] firmware: google: Test spinlock on panic path to avoid lockups Date: Mon, 24 Oct 2022 13:31:05 +0200 Message-Id: <20221024113003.735381166@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112959.085534368@linuxfoundation.org> References: <20221024112959.085534368@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747572860259177066?= X-GMAIL-MSGID: =?utf-8?q?1747572860259177066?= From: Guilherme G. Piccoli [ Upstream commit 3e081438b8e639cc76ef1a5ce0c1bd8a154082c7 ] Currently the gsmi driver registers a panic notifier as well as reboot and die notifiers. The callbacks registered are called in atomic and very limited context - for instance, panic disables preemption and local IRQs, also all secondary CPUs (not executing the panic path) are shutdown. With that said, taking a spinlock in this scenario is a dangerous invitation for lockup scenarios. So, fix that by checking if the spinlock is free to acquire in the panic notifier callback - if not, bail-out and avoid a potential hang. Fixes: 74c5b31c6618 ("driver: Google EFI SMI") Cc: Andrew Morton Cc: Ard Biesheuvel Cc: David Gow Cc: Greg Kroah-Hartman Cc: Julius Werner Cc: Petr Mladek Reviewed-by: Evan Green Signed-off-by: Guilherme G. Piccoli Link: https://lore.kernel.org/r/20220909200755.189679-1-gpiccoli@igalia.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/firmware/google/gsmi.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/firmware/google/gsmi.c b/drivers/firmware/google/gsmi.c index 62337be07afc..2e3ef0eb6e82 100644 --- a/drivers/firmware/google/gsmi.c +++ b/drivers/firmware/google/gsmi.c @@ -661,6 +661,15 @@ static struct notifier_block gsmi_die_notifier = { static int gsmi_panic_callback(struct notifier_block *nb, unsigned long reason, void *arg) { + + /* + * Panic callbacks are executed with all other CPUs stopped, + * so we must not attempt to spin waiting for gsmi_dev.lock + * to be released. + */ + if (spin_is_locked(&gsmi_dev.lock)) + return NOTIFY_DONE; + gsmi_shutdown_reason(GSMI_SHUTDOWN_PANIC); return NOTIFY_DONE; }