Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1021448rwe; Thu, 1 Sep 2022 11:07:56 -0700 (PDT) X-Google-Smtp-Source: AA6agR7I3UUpOToYjrH6SF1JKmz3Kmwd2yCKB4lJhVZMFNgxvx21sha2SmqE4ovzkq6IuLzySt3a X-Received: by 2002:a05:6402:3591:b0:448:a15e:3ca0 with SMTP id y17-20020a056402359100b00448a15e3ca0mr14904480edc.195.1662055675848; Thu, 01 Sep 2022 11:07:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662055675; cv=none; d=google.com; s=arc-20160816; b=y6wXlBEu+nny73RAp/IOZ4sNRWJ86bIR33pqK+btAKffv0eOr30h/EZhmNfE3WzKC9 ClpDxuhZeopFcVdz8aqc1xsrnJuhkYrUX3qJNyU3Eaq6+9Im14jWjFQYB8+CuM3THQaJ Wompj/MQdPUwKHkf/AYt3ezmrMjwwQ3jjZXqrgp5f149Ees7pDC/CpTojTztCXi0QxlY P0tX9EjUC52CKoYw/UN6QQtCf8G2B5okKjh+sR2zbIK5GekIDZxSWFtDQnvsqWC/PGXs Z2tgMnuuNSK5iytk61R+O8vZrGWJBI6snrQ1KRBsilIoThDwz8+UTa6b6XYhjMQOvhLa l/gQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=k0D9VfjgTgm+9qoDqpjRzjWJhfwb4zZRUexBuAsmIYo=; b=CxQjI0pitB5+c4pAJAadg2nuJs9sZq0v04j3FA4zCUzFtnZpUmnBqheicOQSrY7WUf IAMjK4GKYAoPj1h3SMRL/YzVe/bQFMvl5S0IiVJzX3vcFPLnJbe3fgRBvJydv1KlHcQu Ej/aHyqWirCAV21lYcIdm0SoRIxXaD1N/8q3iBW2UV8KYyHBKIePxfTTLzKkb3uwED4z zQ20iYkkryfRFHdK3tG87DJv082N2JYypJtV8hEAVs3LubNioXtQUOwK947978pTxtCe ksRwn6BlGTepLy0wY60E7IrCUz4YQmqgdtA9ho535q6Y4Aq7WiJYtLJkSCXQjAqMrB7q YWYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Kf92I5lz; 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 sg42-20020a170907a42a00b0070bf25f1732si14648225ejc.155.2022.09.01.11.07.27; Thu, 01 Sep 2022 11:07:55 -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=Kf92I5lz; 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 S232877AbiIAQpP (ORCPT + 99 others); Thu, 1 Sep 2022 12:45:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234384AbiIAQpH (ORCPT ); Thu, 1 Sep 2022 12:45:07 -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 1574E30561; Thu, 1 Sep 2022 09:45:03 -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 63117B82844; Thu, 1 Sep 2022 16:45:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 886E4C433C1; Thu, 1 Sep 2022 16:44:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662050701; bh=WTVoLyArljMwvj6zU+m2L6cOF0xZFcbBpY3XVPZOeBU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Kf92I5lzjXCibPDPWmxIHXKuoDoS+UwpSkVq3OFDFg9hc+aE6t0CRar10bQx6lRpP LwLi3pZm1yHhBgRj77UycglMGL1AUhHSoP06PsLM6vrT7rbENbsa4cmPQv8jUDN/xo 2pQB7bA0s91jdt8UopkLwsPIzulsc/XcWERrrmTE= Date: Thu, 1 Sep 2022 18:44:57 +0200 From: Greg KH To: "Guilherme G. Piccoli" Cc: evgreen@chromium.org, arnd@arndb.de, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@gpiccoli.net, ardb@kernel.org, davidgow@google.com, jwerner@chromium.org, Petr Mladek Subject: Re: [PATCH V3] firmware: google: Test spinlock on panic path to avoid lockups Message-ID: References: <20220819155059.451674-1-gpiccoli@igalia.com> <6bc5dbc3-2cdd-5cb8-1632-11de2008a85a@igalia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6bc5dbc3-2cdd-5cb8-1632-11de2008a85a@igalia.com> X-Spam-Status: No, score=-7.1 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,T_SCC_BODY_TEXT_LINE 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 On Thu, Sep 01, 2022 at 01:24:46PM -0300, Guilherme G. Piccoli wrote: > On 01/09/2022 13:04, Greg KH wrote: > > [...] > >>> What happens if the lock is grabbed right after testing for it? > >>> Shouldn't you use lockdep_assert_held() instead as the documentation > >>> says to? > >> > >> How, if in this point only a single CPU (this one, executing the code) > >> is running? > > > > How are we supposed to know this here? > > > > Reading the code? > Or you mean, in the commit description this should be mentioned? Yes, and in the comment as this type of call is very rare and should almost never be used. > >> other CPUs, except this one executing the code. So, either the lock was > >> taken (and we bail), or it wasn't and it's safe to continue. > > > > Then who else could have taken the lock? And if all other CPUs are > > stopped, who cares about the lock at all? Just don't grab it (you > > should check for that when you want to grab it) and then you can work > > properly at that point in time. > > > > I don't think it is so simple - we are in the panic path. Great, then the lock doesn't matter :) > So, imagine the lock was taken in CPU0, where GSMI is doing some > operation. During that operation, CPU1 panics! > > When that happens, panic() executes in CPU1, disabling CPU0 through > "strong" mechanisms (NMI). So, CPU0 had the lock, it is now off, and > when CPU1 goes through the panic notifiers, it'll eventually wait > forever for this lock in the GSMI handler, unless we have this patch > that would prevent the handler to run in such case. > Makes sense? I'm trying to say "if you are in panic, never grab the lock in the first place". So change the place when you grab the lock, not here. thanks, greg k-h