Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp536414pxa; Fri, 21 Aug 2020 13:51:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyk4TwfeDKKZbYxhTbAmJiUhAAr85PGYQkfWhEiWuQ0GohpwglVLlXmFqeJIdJj2IIPZpH0 X-Received: by 2002:a17:906:cb0a:: with SMTP id lk10mr4624891ejb.209.1598043106242; Fri, 21 Aug 2020 13:51:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598043106; cv=none; d=google.com; s=arc-20160816; b=Jnv19sMJPM3vNTpfRE5KVcqknd3+GjBKnYqTG4rKuXCcoysI8Z2Beereln6ph0Ppo6 4w0EssPAwYZnA60ALYt612QP0e3a3kOdd7kLE+Xexi2ky2aGMAWyinPmIO18WJCw24zL m67yGyH8FXGIOcVfcLWACcjR/ZlOGXHAzkK3K1/8AvCcnew9pSOjsMh8/gs+mGJGnSCp 6PN0VsfCNrFkNhgyvhfS/9YmxW9ybfgQlJegE5ZHmMvLNz/Gr5F0NZiuOuBxn39IqcGv lZTKb3XAL2eBOg2tm3cD+xgmx9cb/EOw3PhzQkwsfpEMH4o8jrFNXceAvWZqNnvC7P9K pu1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=H9y/yHIAYb4QbGfh+T+xMylZAkVCHIA56XkqxJq/zY4=; b=inV5WAzwIV4zgfohWcZrAFmyAJEnhWOuOk8z3hoPsTu76Uxd5VhMERbdVESYpE9K3L Z3gnJr9p0HQi9ugBqhW/r4yqamXV/5cSPJWlHqUyse9YowLFDIgTJGq6k8NZhn4AS0yX ygZiqN8RepxvngJH0BbWXYs1N4dNGe/IPrCP3ADqKPeUIcQHNf5Y62xJqnWiYBXNDcay XJQvcx1yb7ClDUIjvZ1niQEZs38mgwcUCwr/0vlS/IjLb+3xToxx6o9eqons8Eb+oBnn eJpqKouJRSwvOEK4hcJxY663SS9zojbiINNSCAEmS2kNjVx3qgQ8PYS/dKf9DUOg5QHQ Ktng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qtDsUUMH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ch17si1998933ejb.627.2020.08.21.13.51.23; Fri, 21 Aug 2020 13:51:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qtDsUUMH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726709AbgHUUr4 (ORCPT + 99 others); Fri, 21 Aug 2020 16:47:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:49410 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725831AbgHUUrz (ORCPT ); Fri, 21 Aug 2020 16:47:55 -0400 Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1C91A20724; Fri, 21 Aug 2020 20:47:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598042874; bh=ky40Y5YjHz90o9pVQm0aMe9wxiKFgD1hSlf/t9X1qUE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=qtDsUUMHyFKgEaATg3dwQZQXMoQsoAkigUCnJL75KZyhTKfDeTYb9+V1ORJGrvYFp VMXFD18kKw233JixIVRahJsVwXqpsF+MeThiEAoBRjLvSsAIJnbC8gC1st3ymLwyzC 4jH6AS2LBmfoklsI6bpnyDi1lzUImy6tc1yt/woc= Date: Fri, 21 Aug 2020 13:47:53 -0700 From: Andrew Morton To: Steven Rostedt Cc: Joerg Vehlow , Thomas Gleixner , Sebastian Andrzej Siewior , Huang Ying , linux-kernel@vger.kernel.org, Joerg Vehlow Subject: Re: [BUG RT] dump-capture kernel not executed for panic in interrupt context Message-Id: <20200821134753.9547695c9b782275be3c95b5@linux-foundation.org> In-Reply-To: <20200821110848.6c3183d1@oasis.local.home> References: <2c243f59-6d10-7abb-bab4-e7b1796cd54f@jv-coder.de> <20200528084614.0c949e8d@gandalf.local.home> <20200727163655.8c94c8e245637b62311f5053@linux-foundation.org> <20200821110848.6c3183d1@oasis.local.home> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 21 Aug 2020 11:08:48 -0400 Steven Rostedt wro= te: > On Fri, 21 Aug 2020 12:25:33 +0200 > Joerg Vehlow wrote: >=20 > > Hi Andrew and Others (please read at least the part with @RT developers= ), > >=20 > > > Yup, mutex_trylock() from interrupt is improper. Well dang, that's a > > > bit silly. Presumably the 2006 spin_lock_mutex() wasn't taken with > > > irqs-off. > > > > > > Ho hum, did you look at switching the kexec code back to the xchg > > > approach? > > > =20 > > I looked into reverting to the xchg approach, but that seems to be > > not a good solution anymore, because the mutex is used in many places, > > a lot with waiting locks and I guess that would require spinning now, > > if we do this with bare xchg. > >=20 > > Instead I thought about using a spinlock, because they are supposed > > to be used in interrupt context as well, if I understand the documentat= ion > > correctly ([1]). > > @RT developers > > Unfortunately the rt patches seem to interpret it a bit different and > > spin_trylock uses __rt_mutex_trylock again, with the same consequences = as > > with the current code. > >=20 > > I tried raw_spinlocks, but it looks like they result in a deadlock at > > least in the rt kernel. Thiy may be because of memory allocations in the > > critical sections, that are not allowed if I understand it correctly. > >=20 > > I have no clue how to fix it at this point. > >=20 > > J=F6rg > >=20 > > [1] https://kernel.readthedocs.io/en/sphinx-samples/kernel-locking.html >=20 > There's only two places that wait on the mutex, and all other places > try to get it, and if it fails, it simply exits. >=20 > What I would do is introduce a kexec_busy counter, and have something > like this: >=20 > For the two locations that actually wait on the mutex: >=20 > loop: > mutex_lock(&kexec_mutex); > ret =3D atomic_inc_return(&kexec_busy); > if (ret > 1) { > /* Atomic context is busy on this counter, spin */ > atomic_dec(&kexec_busy); > mutex_unlock(&kexec_mutex); > goto loop; > } > [..] > atomic_dec(&kexec_busy); > mutex_unlock(&kexec_mutex); >=20 > And then all the other places that do the trylock: >=20 > cant_sleep(); > ret =3D atomic_inc_return(&kexec_busy); > if (ret > 1) { > atomic_dec(&kexec_busy); > return; > } > [..] > atomic_dec(&kexec_busy); Aw gee. Hide all this in include/linux/rostedt_lock.h... Sigh. Is it too hard to make mutex_trylock() usable from interrupt context?