Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp821635rwi; Wed, 19 Oct 2022 03:28:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5jVe03QBGGeRCZeYTUIV7GZ0uOYX86feOY7t//f8v/NWmfZY1XOzvA9PJtdxZ7JlIIM3Yg X-Received: by 2002:a17:906:30c8:b0:73c:81a9:f8e1 with SMTP id b8-20020a17090630c800b0073c81a9f8e1mr6086497ejb.649.1666175332204; Wed, 19 Oct 2022 03:28:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666175332; cv=none; d=google.com; s=arc-20160816; b=Bx5geyvqCZDbQwYGIldRzELol0ZQLAoy+xBlV3dpPtozZwkfOJzaC0IApFgoN6aIvx eEQvSXGwFdK58hze51WjhJPwE0Kyeg2ksMNil6qnXBqE4YTDXVaiqbPXvLQtY0niuW9M Nwcu3LWU6Kpe+h8h7DAScFBUHFn5kZCNKXPuro07j7I0hiYNpdcvnRPq6eOnYY6Qp/XK CGiOGr58Cb44xOPYxH68zegZll+JD+69K5pJh0KNcoZzMrDfuu+ps90neJUEgdn31CgS +UsAD2NVxTEKK3lgYeOwtJBewSB4VZhodHOCitodtAVI0cT1BQsXAwx82sasDDRRx8R1 eI0Q== 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=SmihWAamdfqiM1Wwh0Zh2Nd3cOnxsVYYtNhHhY5CsUEQ2E4F/nkustJC4pn53/f3oJ lhbTDeICq0d5muyfnkLxZvwkUdFwEL+jiKvU9CXER2IpSQ2PQZm01krS0KCBlwFOj+IR lYkTHlASdegOUgveNWGhaJdNCfmI0qzR3RbxNeA2TgWVfiOnQ+ofV+WI6yg3Df4/GOqf wBRuvSKIH6x9DCUq3dZvc22MtSD2fdeAB/XeCS7wTJ9nOU/UF8B5V7C1RnUr+mTBJgJv g/kiB9c8QRN2jJVy+qaXmNlQEq0aJYVxZor4QoLgUDLxDWAksH4rZolO7pnlVnK9coa3 gG9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="VCU/fSTZ"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fj3-20020a1709069c8300b0078d0a31f987si15549622ejc.755.2022.10.19.03.28.25; Wed, 19 Oct 2022 03:28:52 -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="VCU/fSTZ"; 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 S233142AbiJSJRt (ORCPT + 99 others); Wed, 19 Oct 2022 05:17:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233349AbiJSJOm (ORCPT ); Wed, 19 Oct 2022 05:14:42 -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 923AD42D7E; Wed, 19 Oct 2022 02:04:57 -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 5560B617DF; Wed, 19 Oct 2022 09:04:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6CE17C433D6; Wed, 19 Oct 2022 09:04:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170293; bh=C+1GBcd4vi3x1Lbhy7+9mb4yrjJTjU/i8BhkPvezHH8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VCU/fSTZxFMQKTQa5D3I19vpyszspxuEd4PuWiJDOfCjBIMpxq0Lezvg/5tKMmjcs yU2DNkzayF5+Tdi+zfsu8gCOHtqWKk1FDQKBLRsFTvgtHO4xbmF28AK+vmEZlXLzbR 3WoiO+drPWydrlPm232Um7UB+7rg7wJ0vKLfXlQs= 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 6.0 563/862] firmware: google: Test spinlock on panic path to avoid lockups Date: Wed, 19 Oct 2022 10:30:50 +0200 Message-Id: <20221019083314.864066698@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.4 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 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; } -- 2.35.1