From patchwork Sat Oct 22 07:25:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7542 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1105881wrr; Sat, 22 Oct 2022 01:36:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6gksgpmCsYPvRRjSulh5P+/tMBzxR6jNxDe+YWNmN0QPd3MEFOiz+Z5T6aoRlhe1iGR0yl X-Received: by 2002:a17:903:2111:b0:185:4ca4:7511 with SMTP id o17-20020a170903211100b001854ca47511mr23220401ple.164.1666427785862; Sat, 22 Oct 2022 01:36:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666427785; cv=none; d=google.com; s=arc-20160816; b=MKUJVbiMs5FUUi9sIFXnajw434zl1JGVcrWQsMuR9p2m/GioBt+YLjs9AdflBEfekB l2EiEI4YTQtlxGtTAAetouDICHg9Dt0FEwvOqfTCydsqImOr6KDM2pyonfuM2vsE18kj LGCk5JB9Ec1RrvZmPLJ8R7AjmRr1BQZeHTWkO/eNVXeIs+30ck5lUQ+73/NBVQ0XH+MR MfoYUIxfOhy9ockACyal1xsfmQYPko8bjSc1BHG1JUVO/55SshU4CJPOevhzM3KeYsIF gMinDAypwz7o5f1tDpyK+MUnw4JBqZhKcpOF5z+OQ1Pvu/9rCVuOjqfHDHpKH5/mp4Mm cX0g== 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=D4aeKO3li6DXpfT9DJMVqwM4QmuvNIwWWCVGysYMwoY=; b=Ardaoe95sF1Y9SFRtgWjaARZzOROSOXia7tXiKP5+E2+AKZtH5BkJRhYCP76UxgmXV N122MF0Qxs2bi/zMz7ZEK1dw0zu1ZPV6Sk04MNtdvvtpm5MCAJ7W/mz9MeDuVs52bI1A g6Kh9ngkf1Kc/1/ve8sxEvn/jV+bCfzzBvjHacc1p5rBWdRl/mLgiuYtPUAtygA15HLb YqzmpmbD2eKKw9zYQ1k7VAGnJY7oDZmysFB1K8aqwQZSh2V23c2XmapCDMsMUW8nLUS0 bfu41A83YmY/D7T3CQPMUEEtQ9baMMBlB5CQHO8Ul5Ik4Upt7HeVlcbjp3Gd2EB6zLVP QtBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iWAKuVi5; 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 x26-20020a634a1a000000b0044601bb2f90si27236887pga.530.2022.10.22.01.36.11; Sat, 22 Oct 2022 01:36:25 -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=iWAKuVi5; 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 S233282AbiJVIRb (ORCPT + 99 others); Sat, 22 Oct 2022 04:17:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233969AbiJVIPp (ORCPT ); Sat, 22 Oct 2022 04:15:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2ACBD2DA77A; Sat, 22 Oct 2022 00:56:41 -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 E462B60AF8; Sat, 22 Oct 2022 07:54:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 064B5C433C1; Sat, 22 Oct 2022 07:54:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425298; bh=C+1GBcd4vi3x1Lbhy7+9mb4yrjJTjU/i8BhkPvezHH8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iWAKuVi5it03s0E+v5VSeUBucyNq0WeIe5USLp3uAbf9LCXxWN+QvIj40HnKfIqs5 nQvdW2kY1vC2nO3HjCDBpod9IIxVoGx9T+hZ6cFhoHhvt13cxuMdlmyxWtCrJY5TGT 62jAhvSJSaVa3WWl0maO656Trrbk+X8qHQNea8GE= 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 5.19 454/717] firmware: google: Test spinlock on panic path to avoid lockups Date: Sat, 22 Oct 2022 09:25:33 +0200 Message-Id: <20221022072518.367097504@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.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 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?1747376182381835547?= X-GMAIL-MSGID: =?utf-8?q?1747376182381835547?= 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 adaa492c3d2d..4e2575dfeb90 100644 --- a/drivers/firmware/google/gsmi.c +++ b/drivers/firmware/google/gsmi.c @@ -681,6 +681,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; }