Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp508392iog; Fri, 17 Jun 2022 07:48:43 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uJhRj4jFjHsNqUm6hx+9gMFtUH0xfEzjx0nraczaF8B4DVuzo48ZPkF40Gx84EfGrLp5Al X-Received: by 2002:a05:6402:5208:b0:431:3a5e:758c with SMTP id s8-20020a056402520800b004313a5e758cmr13070930edd.250.1655477323626; Fri, 17 Jun 2022 07:48:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655477323; cv=none; d=google.com; s=arc-20160816; b=AElBPXOmFtpfL7UNGO0VHREayozzOeL9cQuX1Zckdfz/gJ/fynEA76iy6OtbmVj/k2 oQTQMOeNJAlskmlhN/zRfdNvpMM60hWzVSFMQCqMF5tAx+JixcJdEqN+fulUXa8WWQJN cpfC+guzZsOycrvpbfPg33Qekzob7Ty7N5cB18JdwkYK1St5/Cgl0JA3ACsN7WW2c/qR CQdmHcDqKj2JF1b1NOu8adOpyxdR4/QmAE169HCqCpyy1BJrLn8C0sTZRumW0DxBISNv ZNcPTr1EzRMHYH1n5p/UmUqJCKvA7BnkkpEuNFkxduMAqgLFGFUHCsrpKVWvVS07af7a r/lA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=9WJ3fcpXL0f2WOS1lh4X7CDZ3Ewdk0gaVvZYQvOA7jA=; b=FrLNWnDnKTJZE8nZzFXJ7ZQaKZ6pfcwHymBLHLfVnDe4zUiwpDXc7MU1vl7rkTkpMM K3+cDWsiZD3XTF68g+ALLvWfa4yZJdIkZjYm//oTs8qIbfCq0KKL3M0pn+xNpgm31g3e hqKFxPJNd08pAscULacKhUKrimxKDdt+Tfb5EflzsvCCWpOAnGeXX7nRHfXgQVe4F8GG gh0rBSkQ1pkgmGU55Y8vynHRey3ioljQwgikiXjVT7fco7PzcYpdtbU49oEoXEKmnuYn q1rpx7Z8QDPgYzXbdkfsu1hP5lbnrXCKwCfOWdX6pBWdlVUzqOqXFfH7oRAdI8E4Py1o 3RJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=d+rJIo9f; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sh7-20020a1709076e8700b00706ba4fdb72si3149833ejc.891.2022.06.17.07.48.17; Fri, 17 Jun 2022 07:48:43 -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=@redhat.com header.s=mimecast20190719 header.b=d+rJIo9f; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382552AbiFQOqd (ORCPT + 99 others); Fri, 17 Jun 2022 10:46:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382802AbiFQOqb (ORCPT ); Fri, 17 Jun 2022 10:46:31 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B71C53FDA1 for ; Fri, 17 Jun 2022 07:46:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655477189; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=9WJ3fcpXL0f2WOS1lh4X7CDZ3Ewdk0gaVvZYQvOA7jA=; b=d+rJIo9fNstpU1X52hJPrUAmMGTnhuVSTgZJxHx5yiPtBQ4cisIRDhWuE1pnzCV7bC7GWh tx1aWNFGVWyWWluaLAdj8+BPtU1wjIVqOBmxhMtMVlCyCpZmnU2bPvxYTfXV2xiDtIRST2 4NA1TwnLZMfj1U5+T1d5YTWoCAbdJuI= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-169-WPjPXVGsO82LwYy5duO4Rg-1; Fri, 17 Jun 2022 10:46:28 -0400 X-MC-Unique: WPjPXVGsO82LwYy5duO4Rg-1 Received: by mail-qk1-f200.google.com with SMTP id bi36-20020a05620a31a400b006a79f0706e5so5223659qkb.2 for ; Fri, 17 Jun 2022 07:46:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=9WJ3fcpXL0f2WOS1lh4X7CDZ3Ewdk0gaVvZYQvOA7jA=; b=W78abTdmoAS/XujHCyeDIZhIfE8QJRU+/IiFle7HvlUxMp9wj8H/YUhRi4cFbEFIUG gSJ5POQB+8weGJhE+Q3G8d64w1v/Ac6XvahD5hQ3G2WVjo5x5fpQUjL1dhLzUJ3GZ+Ty OwVWM+MSbnEOmEQgzGyAhMA7bm4LSwbAFox6objJoCRRr+GSAmfsy3FBZTbMptV7Ureh TwBzHsBRfNE/GmoTsNB7+y+uEXAtXkR+mhM62gWSkFFCOKMkUq19g7IMd77pXWo+b5xQ 1aaMDsNakzh3gXWnjt2RWOx8xbvP5glPYNx+aSgoxX20/cDGRHAt7HLkd/7afQZF2nU7 xvtA== X-Gm-Message-State: AJIora8Zo86mlSmIQkmZLaJwVNC+ZYydWe3ARXY1B30OHiXqONKp/o5O WY+xW5aoqLJERdijYpkmsd7dsUfe+h7uaWCzIsHz4Aa8ySaIt5naa4JXpESY4rYArBnZbMoRT1Z 0CUM408YwlC2mUeQjT3eFa7u6 X-Received: by 2002:ad4:5c4a:0:b0:464:5920:7c1a with SMTP id a10-20020ad45c4a000000b0046459207c1amr8736674qva.58.1655477188328; Fri, 17 Jun 2022 07:46:28 -0700 (PDT) X-Received: by 2002:ad4:5c4a:0:b0:464:5920:7c1a with SMTP id a10-20020ad45c4a000000b0046459207c1amr8736646qva.58.1655477188058; Fri, 17 Jun 2022 07:46:28 -0700 (PDT) Received: from vschneid.remote.csb ([185.11.37.247]) by smtp.gmail.com with ESMTPSA id a15-20020ac85b8f000000b00304e38fb3dasm4813173qta.35.2022.06.17.07.46.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jun 2022 07:46:27 -0700 (PDT) From: Valentin Schneider To: Petr Mladek Cc: Tao Zhou , linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-rt-users@vger.kernel.org, Eric Biederman , Arnd Bergmann , Thomas Gleixner , Sebastian Andrzej Siewior , Juri Lelli , "Luis Claudio R. Goncalves" Subject: Re: [PATCH] panic, kexec: Don't mutex_trylock() in __crash_kexec() In-Reply-To: References: <20220616123709.347053-1-vschneid@redhat.com> Date: Fri, 17 Jun 2022 15:46:23 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,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 17/06/22 15:52, Petr Mladek wrote: > On Fri 2022-06-17 12:52:05, Valentin Schneider wrote: >> If you look at __crash_kexec() in isolation yes, but if you look at panic() >> and nmi_panic() only a single NMI can get in there. I think that is also >> true for invocations via crash_kexec(). > > It is true that panic() could be called only once, see this code > in panic(): > > * Only one CPU is allowed to execute the panic code from here. For > this_cpu = raw_smp_processor_id(); > old_cpu = atomic_cmpxchg(&panic_cpu, PANIC_CPU_INVALID, this_cpu); > > if (old_cpu != PANIC_CPU_INVALID && old_cpu != this_cpu) > panic_smp_self_stop(); > > > One the other hand, the aproach with two variables is strage > and brings exactly these questions. > > If a trylock is enough that the mutex can be replaced by two > simple atomic operations. The mutex would be needed only > when a user really would need to wait for another one. > > > atomic_t crash_kexec_lock; > > /* trylock part */ > if (atomic_cmpxchg_acquire(&crash_kexec_lock, 0, 1) != 0) > return -EBUSY; > > /* do anything guarded by crash_kexec_lock */ > > /* release lock */ > atomic_set_release(&crash_kexec_lock, 0); > > The _acquire, _release variants will do the barriers correctly. > Looks saner! I can't think of anything wrong with it so I'll shove that in v2. Thanks! > Best Regards, > Petr