Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6739819rwi; Mon, 24 Oct 2022 05:38:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5dwpK+QEFAx7ecml6qidum9O9zudC/HC1xAlcrDYqfXW3z37W5BhAtMjJ9bMlqhQzF1y+T X-Received: by 2002:a63:4c23:0:b0:45f:eab4:4f47 with SMTP id z35-20020a634c23000000b0045feab44f47mr28025691pga.532.1666615099393; Mon, 24 Oct 2022 05:38:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615099; cv=none; d=google.com; s=arc-20160816; b=w7aqDbr46jYH+WohM4ZZs1gt2b2oTpl4O1OcYwgV8jIZgkeUvnyx8xubRdWPBve5DK zgzVzJymziEbMwBAM3SiwzoYOzz5ZO5GxFBBwVXTpvixvwU04+wwI6AkhEULdfKQq+zi FrnvVhlPOV1yFFksjx7BdcsJhC2CJOXdumcO5PB8a+twnC3YtoqzkZK3ESEEJit/Soqf DAhJQ0EYUcjUI6clq5hjy3BwzaITtkVD7lGAg4YtKlC9kIJtR19DhyeCPJuw7b6JovPv YCd35gd4Q7iORIBOoHaLEVNFuD8bB/J3ErKNg5qWXm5Vu4ZVLJpZ1FGjIJjuZz8KhWnS TK6w== 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=mpyfel1ljPXv+mobuJDWpv8rRhG3juJokBrMBCiolr8=; b=SXrnPvlTSXB+ZmVQVmLWUyF8PDHLARsveJQtUnTV3YUXDPIyODPrJdnW0VSz+AT64N T297LP51IwxNQLKc2LoEssG18mrSEGl3hzUB6ASdAgI9XdJpMm3Z2kRViG9PG7ugL8bF MTGAKJqJkhnGZ1bWaKrZ5phQyRYjZ6ePq0V82MC64x9kZZyfcs1t3DsardRaTF0O8nba ltQAU/js869/W7BBtz6W6EiwQEeC3wTgcWqyREkMUqpSfn9/8mrNzqlJwvb6rbizL5qb qj9e/AuqC9ypRGwzBo2To5bXJhbXp4aoYHhbjNtWPYOjdGp1p2ePuObsM/h81C+VPMZP Hzvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xw1EX1wO; 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 ot1-20020a17090b3b4100b00200acd39846si21043656pjb.63.2022.10.24.05.38.06; Mon, 24 Oct 2022 05:38:19 -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=xw1EX1wO; 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 S231868AbiJXLu7 (ORCPT + 99 others); Mon, 24 Oct 2022 07:50:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231889AbiJXLtK (ORCPT ); Mon, 24 Oct 2022 07:49:10 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B7DB4AD70; Mon, 24 Oct 2022 04:43: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 sin.source.kernel.org (Postfix) with ESMTPS id 90EFDCE134D; Mon, 24 Oct 2022 11:43:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F414C433D6; Mon, 24 Oct 2022 11:43:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611783; bh=oKN9viX4e06D0KhEWdRPQUYrtQaktvqyp40hiQNA+ZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xw1EX1wOHZIB5Vf+6ViBi2BVT9Qotp/US00NdivGDvg8/+G+8Fs9zImBH7UdzKKaL 2+jYF90MwiicqLEQLy2frsHw4FMXGps7XU6w7BuGWB02sbYzJ17t8lH7UDxmHW2QjU 1xvVfuEsb8vPiR+FRvAU/un9WL9R8eLWwq4X0muY= 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.9 109/159] firmware: google: Test spinlock on panic path to avoid lockups Date: Mon, 24 Oct 2022 13:31:03 +0200 Message-Id: <20221024112953.430987428@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112949.358278806@linuxfoundation.org> References: <20221024112949.358278806@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.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 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 98cdfc2ee0df..6fd5f6776735 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; } -- 2.35.1