Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp542818iog; Wed, 29 Jun 2022 05:36:32 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uJJvsflV5I2aqF1Z6J8cCXEzIMxpwAiMJBBVtNazlYJXfQK6ce/hDpLO/42kImNYz6tB+Z X-Received: by 2002:a05:6402:150:b0:437:b93c:3a9 with SMTP id s16-20020a056402015000b00437b93c03a9mr3839263edu.82.1656506192006; Wed, 29 Jun 2022 05:36:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656506192; cv=none; d=google.com; s=arc-20160816; b=nxkN3UAWuy52oSZX5mnkqSkaL9gCeoSXkx1DjB6OH43kSa1S5fzyVHzzALko3EGZgJ k58d8dt3goeF/2qJedeWeQX/H4JaTxddhV4d3zzoLHQCGuZOGX3UQd1vvJkhqTf3uwB5 y1l7NKOk1bGSw5WAGVln+uuT9ZVfBwq6oc+7cmCcMkmwxV0orRHPOPpCFv5lh56RADh8 lNJI1b5G5OLbNupp0vRmAdufOcUQzZ9YZ4SS4V3W4meGb4Zaf+LZWXlCsNDWwFmRRXtu W5KNam6ROgwPrtf9ZoHk+iX4Trd0tkR6udHG0GAiS8J4+DnXOloSG4LuHLy1V6UBRnUX l5/g== 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=D4xckCgJ4Bw0w9xbbVbINWepGBRVBzb5aJNwu4HG9GY=; b=jQn54eecVat/rTkwuE799dMROfLNBOdaU+B0knkytUBFv8oAUFZ9iCwIwKPGpwwuSe a2pcWQSj/M3jGPwnpxV3qh2++jd3Azr57fq/3TSggtSyuHB7sIXPYi01+ZkXESAX9A5v tHNoQG/cSE0Wf0FvFvZc5e4v0nQ0mje3c0lRs63i6BHWbiMzli8ioGAbWUUYlHVDOX2N woZQsTcGOQuYFcu9JYdH/0tOcYvXWBy4aNMNYBqjTtuj7QX3cgoPVW563ejGjXoVMYFV 4hksUwGHmx9QjI1GhU6QoH13XI0SWI86+JVpiBC8MTXALHAuRkU4rbqpfXv9/aiMxmtL 6Ltw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MUk4+8DZ; 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 mp20-20020a1709071b1400b0072a47b5dbc4si221514ejc.767.2022.06.29.05.36.04; Wed, 29 Jun 2022 05:36:31 -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=MUk4+8DZ; 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 S232446AbiF2MXl (ORCPT + 99 others); Wed, 29 Jun 2022 08:23:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231313AbiF2MXi (ORCPT ); Wed, 29 Jun 2022 08:23:38 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 982651EB for ; Wed, 29 Jun 2022 05:23:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656505415; 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=D4xckCgJ4Bw0w9xbbVbINWepGBRVBzb5aJNwu4HG9GY=; b=MUk4+8DZ9vaOOyJG99XLyLqnjld4/nDfTKuEyCLRTHP0VjM+huhaKtytZL3ysf5AXqRN2k FnhiPjxCidfbmDi5ut1qst96dSyfvGQsQv1tW+iSRhD6pQD0Fuj4sdrRWfYXWBCfM2Mtrz hxLyWVUwU+nUfVaIuAKNG+r2H59y+BA= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-468-cCEXTSNGMhKkmNAUso5MSQ-1; Wed, 29 Jun 2022 08:23:27 -0400 X-MC-Unique: cCEXTSNGMhKkmNAUso5MSQ-1 Received: by mail-wr1-f69.google.com with SMTP id e5-20020adff345000000b0021b9f00e882so2358855wrp.6 for ; Wed, 29 Jun 2022 05:23:26 -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=D4xckCgJ4Bw0w9xbbVbINWepGBRVBzb5aJNwu4HG9GY=; b=efwEq4f+XtJBdgHkEM5uNk8ohNXZO4K19QwaQbDeu7Oh8aGDJmA7nN170RkWerbQpK yelgib6HCwPWuhjxqRXEvB2n6UyKxg06w/RMXEJzIsd1/y7PcFsrpLmBdL6g7qUgBpRy d1MY692ck/IG8aVZW32SpULtXcA2LC1TllDkrb6IWU+E+HmNoarAkyaVTknWat2dQdZ3 jxn/8LnqHddG7b7g2Y3JAsACR5oQr5aLZ7Zbw5sv88vJcLrgp81pEu7ZpnCQLzpdse5b HPWMIuFt6tBvgORLGvUnSOY1tCP3P0RdScXITth8XCFTCllAYEZM9K+Lu2UOHMkGgyy7 oqOw== X-Gm-Message-State: AJIora8B7/7HHYYj/ISELjX+sIjT+IrWFazAFJ6t0g33bOS+FOwmUFm0 SmnPuqRdb+1dhp9OrgBce8HNokRcF0L9dwQ/vcVunnyJsDfheGZmzo9ZRMF2O2oBx+dhRas3qFV ywY1x19CRc8cR2LauFs5EocOd X-Received: by 2002:a05:6000:1281:b0:21b:9c01:df79 with SMTP id f1-20020a056000128100b0021b9c01df79mr2793340wrx.563.1656505405847; Wed, 29 Jun 2022 05:23:25 -0700 (PDT) X-Received: by 2002:a05:6000:1281:b0:21b:9c01:df79 with SMTP id f1-20020a056000128100b0021b9c01df79mr2793306wrx.563.1656505405591; Wed, 29 Jun 2022 05:23:25 -0700 (PDT) Received: from vschneid.remote.csb ([185.11.37.247]) by smtp.gmail.com with ESMTPSA id o12-20020a1c750c000000b003a04b248896sm2888552wmc.35.2022.06.29.05.23.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jun 2022 05:23:24 -0700 (PDT) From: Valentin Schneider To: Petr Mladek Cc: "Eric W. Biederman" , linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-rt-users@vger.kernel.org, Arnd Bergmann , Thomas Gleixner , Sebastian Andrzej Siewior , Juri Lelli , "Luis Claudio R. Goncalves" , Andrew Morton , Vivek Goyal Subject: Re: [PATCH v2] panic, kexec: Make __crash_kexec() NMI safe In-Reply-To: <20220629115539.GB12720@pathway.suse.cz> References: <20220620111520.1039685-1-vschneid@redhat.com> <87r13c7jyp.fsf@email.froward.int.ebiederm.org> <20220629115539.GB12720@pathway.suse.cz> Date: Wed, 29 Jun 2022 13:23:08 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 29/06/22 13:55, Petr Mladek wrote: > On Tue 2022-06-28 18:33:08, Valentin Schneider wrote: >> >> 8c5a1cf0ad3a ("kexec: use a mutex for locking rather than xchg()") was >> straightforward enough because it turned >> >> if (xchg(&lock, 1)) >> return -EBUSY; >> >> into >> >> if (!mutex_trylock(&lock)) >> return -EBUSY; >> >> Now, most of the kexec_mutex uses are trylocks, except for: >> - crash_get_memory_size() >> - crash_shrink_memory() >> >> I really don't want to go down the route of turning those into cmpxchg >> try-loops, would it be acceptable to make those use trylocks (i.e. return >> -EBUSY if the cmpxchg fails)? > > IMHO, -EBUSY is acceptable for both crash_get_memory_size() > and crash_shrink_memory(). They are used in the sysfs interface. > >> Otherwise, we keep the mutexes for functions like those which go nowhere >> near an NMI. > > If we go this way then I would hide the locking into some wrappers, > like crash_kexec_trylock()/unlock() that would do both mutex > and xchg. The xchg part might be hidden in a separate wrapper > __crash_kexec_trylock()/unlock() or > crash_kexec_atomic_trylock()/unlock(). > Makes sense, thanks. I've started playing with the trylock/-EBUSY approach, I'll toss it out if I don't end up hating it. > Best Regards, > Petr