Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp530490iog; Wed, 29 Jun 2022 05:21:38 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vO7qXuqOODF+hlVr8/AfXANlNcM3tcXEBAjWawWGbKLJGEk2DJPqJ+YCVTVpQyQP2ddGY2 X-Received: by 2002:a63:8943:0:b0:411:8cff:8b5d with SMTP id v64-20020a638943000000b004118cff8b5dmr1394650pgd.257.1656505297844; Wed, 29 Jun 2022 05:21:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656505297; cv=none; d=google.com; s=arc-20160816; b=q2wiDW2DAgGmdU4GOAl3FT60yW9w0B2okhUnfHVRcrR2XGCZixXazr1tZU2/ldTFnz WgVPJuGsvnui0srAfJ5TTaeAh7k4491JClmoCSkE1czx4N+qg+2bHCP4kdRYl8+1SKBs zNI7AcV2wKm5zmfpelxs/6dEr4U/Rqp27v1hyCPkgBaOu/qDL/icxK7AntzFc4ORvfKr lsUecEBs82KrLv3tEV+odahraZvDtqHLR2LYcU4qw2/d9HSoh/P4LoRzzy/pVDERigNo s7X3xxdn/GqhOtV1fLzDUwTHZ73boFNzmAgGfa/xqZHtQnHk4KsGT/gfVeXcFOwivo7w J4xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=bF/LSSs2g8Q6JLHlya2E6zoiGTFvYRLz8XXwkmSkeI0=; b=Wud2ONVR3N0JfG57un6KmW6roXqRchG+3ghRDn3MiG9yFwVRVsWMit2fTThPPw9RBj MkrJuwEhHSdMiQuV05MeLk4s09jqdOL8ii58Dhw1CoQxPEBvG/V+fhZl5+b+H41mArvB NzUfapfj/iglXwoN3b8is9BP7wNckQL0ZL2IaEQ4/lfbtJLmAeG9gsXHstYrLzPbfvfl ZUVw8IcLmm9wTcE1/rrdcouPt9ofWaXRNHelBskX0WLdSrVVfoVpJosqvVis4iTVlY0m mUZmbeQOdMf+Pg4RLrMlDt4Hmh5owzrey+vAxHFM+IY7pe/9i21ObVuMv5dL4GrPP4nW iafg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b="GiHzf/Mi"; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a18-20020a631a52000000b0040cc512db04si17492839pgm.844.2022.06.29.05.21.24; Wed, 29 Jun 2022 05:21:37 -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=@suse.com header.s=susede1 header.b="GiHzf/Mi"; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232492AbiF2Lzn (ORCPT + 99 others); Wed, 29 Jun 2022 07:55:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230326AbiF2Lzm (ORCPT ); Wed, 29 Jun 2022 07:55:42 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2427E387B1; Wed, 29 Jun 2022 04:55:41 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id D6707220E0; Wed, 29 Jun 2022 11:55:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1656503739; h=from:from:reply-to: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=bF/LSSs2g8Q6JLHlya2E6zoiGTFvYRLz8XXwkmSkeI0=; b=GiHzf/Mi0x/V4my9jBprmV4ydlz1A8WxABnZ+n81Wxqgcgfa5dMtxOIA1EtJvo/rN3uJA2 lVEHsSW5xKN4UPsqhddeK8fDq9C8Ja+RTbdCzXAXQbd42plY8G+0Ag9wjXuWsqEC65fpBQ 7IkSyEbV5gRPYtEG9fw8bcHwqH1ITFM= Received: from suse.cz (pathway.suse.cz [10.100.12.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id A79142C141; Wed, 29 Jun 2022 11:55:39 +0000 (UTC) Date: Wed, 29 Jun 2022 13:55:39 +0200 From: Petr Mladek To: Valentin Schneider 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 Message-ID: <20220629115539.GB12720@pathway.suse.cz> References: <20220620111520.1039685-1-vschneid@redhat.com> <87r13c7jyp.fsf@email.froward.int.ebiederm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 Tue 2022-06-28 18:33:08, Valentin Schneider wrote: > On 27/06/22 13:42, Valentin Schneider wrote: > > On 25/06/22 12:04, Eric W. Biederman wrote: > >> At this point I recommend going back to being ``unconventional'' with > >> the kexec locking and effectively reverting commit 8c5a1cf0ad3a ("kexec: > >> use a mutex for locking rather than xchg()"). > >> > >> That would also mean that we don't have to worry about the lockdep code > >> doing something weird in the future and breaking kexec. > >> > >> Your change starting to is atomic_cmpxchng is most halfway to a revert > >> of commit 8c5a1cf0ad3a ("kexec: use a mutex for locking rather than > >> xchg()"). So we might as well go the whole way and just document that > >> the kexec on panic code can not use conventional kernel locking > >> primitives and has to dig deep and build it's own. At which point it > >> makes no sense for the rest of the kexec code to use anything different. > >> > > > > Hm, I'm a bit torn about that one, ideally I'd prefer to keep "homegrown" > > locking primitives to just where they are needed (loading & kexec'ing), but > > I'm also not immensely fond of the "hybrid" mutex+cmpxchg approach. > > > > 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(). Best Regards, Petr