Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp32591rdh; Fri, 22 Sep 2023 23:51:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFqcQfLizs8iFstz3o9/nvDJv+yC/M+aNWbqV8YZtgekCGG5r7kNUUnwIEGQEnDc4luyTqa X-Received: by 2002:a17:902:db0c:b0:1c4:48c4:969b with SMTP id m12-20020a170902db0c00b001c448c4969bmr1311812plx.52.1695451869230; Fri, 22 Sep 2023 23:51:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695451869; cv=none; d=google.com; s=arc-20160816; b=JoiVi9dQHhOq2QTpCArtqXDypzPKKl2+vpOA5/F2z/t1T2xggSngAImX98UnYYqkrG A1YPUa0Qpet4JtyFCCVvQ2vrrxxpttOIJfOOfgdSmKP89mWKB69audaS4HLHFhXZnv1+ +oeBGkOJ/ULicr4/7Xl3AeO7Er12gylQz293JqEd6+248XQ9cyxBIawTsUObcl2/obPq 3YO4L4396Ms5PePRobKMHG4qTuz3dq6vVTVPzwyoYBeZ3TGeW5ga2PW3hUNL/Sf62XH3 SAXMOEA8bHPnqYjAjxkEmR4WrevA0Kk5OZyZMlwgdb1RMH2RiPVtEC1VTqfs+NWzF6NZ 9YZw== 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=nRQ3+p4XcET1bcqGNVOLqwdH4/wR+jQ5PPEPDi382mU=; fh=okZOMvIwxq+4pO6mZnfXi+1sr+pixH5lzHxQKDJr6VE=; b=Lsok6uwFxyUdre7QxMJiFg7YjaOCyl7xun6QWc6IW9qwyjaRImu3RlPmgbx4qn/e/R XAvuGZtZPQ8529Dt/znAhXOV7Ka6y/Xr0DBczOcCypFVHwvQ4yy/j62jdqvCgtbspoAF rDl29E9PsLpuQisQ1P3ANfAI+HP49eikUUhV7bswSeb11/XQQN6X0s8HG1RanGYZgNR4 d7JHryK4GxU6amzQfidqO4BUBatyWdOie7bqi6eRyOieJO+EN4XFxBisPwoHgqW6a4b1 eMY79b6nctHR7GoCTRD8zraYxqKwxBLmFlP4Tj4Q/CMLK1gVH2dLpyJJ/zZ/g8nk68Sr CmDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RhVCi26T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id h20-20020a170902f7d400b001c56edc4b7asi5304486plw.278.2023.09.22.23.51.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 23:51:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RhVCi26T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 8C9D183CCA80; Fri, 22 Sep 2023 17:06:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230308AbjIWAFv (ORCPT + 99 others); Fri, 22 Sep 2023 20:05:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229628AbjIWAFu (ORCPT ); Fri, 22 Sep 2023 20:05:50 -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 ESMTPS id 857C51A5 for ; Fri, 22 Sep 2023 17:04:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695427497; 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=nRQ3+p4XcET1bcqGNVOLqwdH4/wR+jQ5PPEPDi382mU=; b=RhVCi26TMQb+smv4eQ8tK4f1JcbnVUGlWLQsXn1RcjqCYpnwV5m/8I+nNe7wENUgoas7X5 0X8wmeb2gdS3NS67F+ci4MCv1zgA9mb3o693PkUueonq3JfvWlV83wwEQWEqLwvmg2618D wvVsGB2UjrpXgg6QvBKUF3NMzjccqpQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-298-GS7LEWNiP8ihW9ffbmUtzg-1; Fri, 22 Sep 2023 20:04:54 -0400 X-MC-Unique: GS7LEWNiP8ihW9ffbmUtzg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 99C54801779; Sat, 23 Sep 2023 00:04:53 +0000 (UTC) Received: from localhost (unknown [10.72.112.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BF08851E3; Sat, 23 Sep 2023 00:04:52 +0000 (UTC) Date: Sat, 23 Sep 2023 08:04:49 +0800 From: Baoquan He To: Eric DeVolder Cc: Valentin Schneider , linux-kernel@vger.kernel.org, vgoyal@redhat.com, dyoung@redhat.com, ebiederm@xmission.com, kexec@lists.infradead.org, sourabhjain@linux.ibm.com, konrad.wilk@oracle.com, boris.ostrovsky@oracle.com, Andrew Morton Subject: Re: [PATCH] kexec: change locking mechanism to a mutex Message-ID: References: <20230921215938.2192-1-eric.devolder@oracle.com> <0ec5f56e-6b55-627a-39c0-ff0a1680794d@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0ec5f56e-6b55-627a-39c0-ff0a1680794d@oracle.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Spam-Status: No, score=2.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 22 Sep 2023 17:06:13 -0700 (PDT) X-Spam-Level: ** On 09/22/23 at 12:35pm, Eric DeVolder wrote: > > > On 9/22/23 11:28, Valentin Schneider wrote: > > On 21/09/23 17:59, Eric DeVolder wrote: > > > The design decision to use the atomic lock is described in the comment > > > from kexec_internal.h, cited above. However, examining the code of > > > __crash_kexec(): > > > > > > if (kexec_trylock()) { > > > if (kexec_crash_image) { > > > ... > > > } > > > kexec_unlock(); > > > } > > > > > > reveals that the use of kexec_trylock() here is actually a "best effort" > > > due to the atomic lock. This atomic lock, prior to crash hotplug, > > > would almost always be assured (another kexec syscall could hold the lock > > > and prevent this, but that is about it). > > > > > > So at the point where the capture kernel would be invoked, if the lock > > > is not obtained, then kdump doesn't occur. > > > > > > It is possible to instead use a mutex with proper waiting, and utilize > > > mutex_trylock() as the "best effort" in __crash_kexec(). The use of a > > > mutex then avoids all the lock acquisition problems that were revealed > > > by the crash hotplug activity. > > > > > > > @Dave thanks for the Cc, I'd have missed this otherwise. > > > > > > Prior to the atomic thingie, we actually had a mutex and did > > mutex_trylock() in __crash_kexec(). I'm a bit confused as this looks like a > > revert of > > 05c6257433b7 ("panic, kexec: make __crash_kexec() NMI safe") > > with just the helpers kept in - this doesn't seem to address any of the > > original issues regarding NMIs? > > > > Sebastian raised some good points in [1] regarding these issues. > > The main hurdle pointed out there is, if we end up in the slowpath during > > the unlock, then we can can up acquiring the ->wait_lock which isn't NMI > > safe. > > > > This is even worse on PREEMPT_RT, as both trylock and the unlock can end up > > acquiring the ->wait_lock. > > > > [1]: https://lore.kernel.org/all/YqyZ%2FUf14qkYtMDX@linutronix.de/ > > > Having reviewed the references, it would seem that Baoquan's approach of a new > lock to handle the hotplug activity is the way to go? If so, I have posted a formal one. It's simple and should work to fix the issue.