From patchwork Mon Oct 24 11:30:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9929 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp596985wru; Mon, 24 Oct 2022 11:38:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4MTaoQP74iYdqTPOHRHPpTYKu8fKMUn+oGaPYo5MDOEy3IOvcwQ4MZiIOePdv67IcLVvNo X-Received: by 2002:a17:90b:4ac1:b0:20a:de32:3650 with SMTP id mh1-20020a17090b4ac100b0020ade323650mr74181210pjb.142.1666636695287; Mon, 24 Oct 2022 11:38:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666636695; cv=none; d=google.com; s=arc-20160816; b=ruiBpgelpO8WmJ590RW3W/zDz0zTVofjLqH2Bu3BzgseKg7H9XYsoPq9qLitxFRPZS lE+BsxAFhDHj8VFkoc8jsWj357K6rA0pXZ1xVqoInI91zyzZ4nFiVMl+yCB9n2FJWtEz eS8417CDfsmDElt0LEsb2krgD1+3JrSC69pMbdszbtFfJelAP5yrkat/pXsQRk3meT0U S4zKbjgeKpqAjKLi6eoG+0pG1eKJNJ+UtERa9IqBXEVSvT/7a49tRvEpj36ozu7jihZq yL7HofEmMbOmsdLq7Xe1uVsRG4zpKcmteeyYFqnhhMP6zAFwvqEB00PAKFbpA3U79R5n cyHg== 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=oWQt/B8PqgnI0z2LrIAxTS6z0d+ql6YdF+xlLh0GoxE=; b=Y+Zq7Riv6C3FpoTWfgtzXGROPc0H/NdtOxmtyosOQ7gJZ1H3e5GWURNcHfsKiB5551 mvedaZuvKNBAJ3zkp+hbTpiZWpkIlQ9ZXE1q1IBSsyR2eGPADV9vydsNPD6NdFQlob08 +JxiqRmaFFLU3hrG9mHaLXLSImqA9ciFUlZ+0A2peZuBRMwXQvwZLUqT7eRw6ExAoECS wbg00i4GLyvFHEkS7vpt0qNMAt013L35jakGD3/4gE5MMAVLI2dn4jQ1nDFEbkrYtNNX k67/z1MY0HcDM73ARsuoIuBXNxDog9S/l1MszfqCc6rZaWpaSbEruMfyj86pIq5CwwkM CgYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="KSu/4Y4m"; 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 l191-20020a6391c8000000b004403cd15ccesi173039pge.849.2022.10.24.11.38.02; Mon, 24 Oct 2022 11:38:15 -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="KSu/4Y4m"; 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 S231801AbiJXScu (ORCPT + 99 others); Mon, 24 Oct 2022 14:32:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231277AbiJXScU (ORCPT ); Mon, 24 Oct 2022 14:32:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC380EC52E; Mon, 24 Oct 2022 10:14:05 -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 966BD612DF; Mon, 24 Oct 2022 12:26:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4268C433D6; Mon, 24 Oct 2022 12:26:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614387; bh=n4LDqRK75QqNUoCyLhZB6FxCrwa59oxkbhRpYS1K6Ns=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KSu/4Y4mkZ0OXTF55mgKau12avLWTM3EVe5uV2caZAOzTE2itSxBfamT30PbC956g WNflNrz3LPPlnThWX6hLVzNRUDCzgzFCBRuqMgUoiaEYGCb/MDCaQZAE0Lr0VId9zT 9S3n1Cu+Ldi3z0j/917Vo7JEUYgwmM6ZcfzoWdEE= 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.10 241/390] firmware: google: Test spinlock on panic path to avoid lockups Date: Mon, 24 Oct 2022 13:30:38 +0200 Message-Id: <20221024113033.079404628@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@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?1747595239615606024?= X-GMAIL-MSGID: =?utf-8?q?1747595239615606024?= 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 7d9367b22010..c1cd5ca875ca 100644 --- a/drivers/firmware/google/gsmi.c +++ b/drivers/firmware/google/gsmi.c @@ -680,6 +680,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; }