From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73ABAC43214 for ; Wed, 28 Jul 2021 16:11:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5CD25604DB for ; Wed, 28 Jul 2021 16:11:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237478AbhG1QLL (ORCPT ); Wed, 28 Jul 2021 12:11:11 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:47446 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237456AbhG1QKf (ORCPT ); Wed, 28 Jul 2021 12:10:35 -0400 Received: from in01.mta.xmission.com ([166.70.13.51]:32964) by out02.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1m8m8G-007CzP-LA; Wed, 28 Jul 2021 10:10:09 -0600 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95]:41378 helo=email.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1m8m8C-00A9Pq-J2; Wed, 28 Jul 2021 10:10:08 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Arnd Bergmann Cc: Andrew Morton , Arnd Bergmann , Catalin Marinas , Will Deacon , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , "David S. Miller" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Al Viro , Christoph Hellwig , Feng Tang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, linux-mm@kvack.org References: <20210727144859.4150043-1-arnd@kernel.org> <20210727144859.4150043-2-arnd@kernel.org> Date: Wed, 28 Jul 2021 11:09:22 -0500 In-Reply-To: <20210727144859.4150043-2-arnd@kernel.org> (Arnd Bergmann's message of "Tue, 27 Jul 2021 16:48:54 +0200") Message-ID: <87eebifmj1.fsf@disp2133> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1m8m8C-00A9Pq-J2;;;mid=<87eebifmj1.fsf@disp2133>;;;hst=in01.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX18xroipV9CATxhuOK1ETEIbw3EWCZZa/6o= X-SA-Exim-Connect-IP: 68.227.160.95 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: Re: [PATCH v5 1/6] kexec: move locking into do_kexec_load X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-parisc@vger.kernel.org Arnd Bergmann writes: > From: Arnd Bergmann > > The locking is the same between the native and compat version of > sys_kexec_load(), so it can be done in the common implementation > to reduce duplication. Acked-by: "Eric W. Biederman" > > Co-developed-by: Eric Biederman > Co-developed-by: Christoph Hellwig > Signed-off-by: Arnd Bergmann > --- > kernel/kexec.c | 44 ++++++++++++++++---------------------------- > 1 file changed, 16 insertions(+), 28 deletions(-) > > diff --git a/kernel/kexec.c b/kernel/kexec.c > index c82c6c06f051..9c7aef8f4bb6 100644 > --- a/kernel/kexec.c > +++ b/kernel/kexec.c > @@ -110,6 +110,17 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments, > unsigned long i; > int ret; > > + /* > + * Because we write directly to the reserved memory region when loading > + * crash kernels we need a mutex here to prevent multiple crash kernels > + * from attempting to load simultaneously, and to prevent a crash kernel > + * from loading over the top of a in use crash kernel. > + * > + * KISS: always take the mutex. > + */ > + if (!mutex_trylock(&kexec_mutex)) > + return -EBUSY; > + > if (flags & KEXEC_ON_CRASH) { > dest_image = &kexec_crash_image; > if (kexec_crash_image) > @@ -121,7 +132,8 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments, > if (nr_segments == 0) { > /* Uninstall image */ > kimage_free(xchg(dest_image, NULL)); > - return 0; > + ret = 0; > + goto out_unlock; > } > if (flags & KEXEC_ON_CRASH) { > /* > @@ -134,7 +146,7 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments, > > ret = kimage_alloc_init(&image, entry, nr_segments, segments, flags); > if (ret) > - return ret; > + goto out_unlock; > > if (flags & KEXEC_PRESERVE_CONTEXT) > image->preserve_context = 1; > @@ -171,6 +183,8 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments, > arch_kexec_protect_crashkres(); > > kimage_free(image); > +out_unlock: > + mutex_unlock(&kexec_mutex); > return ret; > } > > @@ -247,21 +261,8 @@ SYSCALL_DEFINE4(kexec_load, unsigned long, entry, unsigned long, nr_segments, > ((flags & KEXEC_ARCH_MASK) != KEXEC_ARCH_DEFAULT)) > return -EINVAL; > > - /* Because we write directly to the reserved memory > - * region when loading crash kernels we need a mutex here to > - * prevent multiple crash kernels from attempting to load > - * simultaneously, and to prevent a crash kernel from loading > - * over the top of a in use crash kernel. > - * > - * KISS: always take the mutex. > - */ > - if (!mutex_trylock(&kexec_mutex)) > - return -EBUSY; > - > result = do_kexec_load(entry, nr_segments, segments, flags); > > - mutex_unlock(&kexec_mutex); > - > return result; > } > > @@ -301,21 +302,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry, > return -EFAULT; > } > > - /* Because we write directly to the reserved memory > - * region when loading crash kernels we need a mutex here to > - * prevent multiple crash kernels from attempting to load > - * simultaneously, and to prevent a crash kernel from loading > - * over the top of a in use crash kernel. > - * > - * KISS: always take the mutex. > - */ > - if (!mutex_trylock(&kexec_mutex)) > - return -EBUSY; > - > result = do_kexec_load(entry, nr_segments, ksegments, flags); > > - mutex_unlock(&kexec_mutex); > - > return result; > } > #endif From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC32CC4338F for ; Wed, 28 Jul 2021 16:10:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 850A260F93 for ; Wed, 28 Jul 2021 16:10:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 850A260F93 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=xmission.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 0B6458D0005; Wed, 28 Jul 2021 12:10:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 047C88D0001; Wed, 28 Jul 2021 12:10:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E21BD8D0005; Wed, 28 Jul 2021 12:10:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0039.hostedemail.com [216.40.44.39]) by kanga.kvack.org (Postfix) with ESMTP id C5DDA8D0001 for ; Wed, 28 Jul 2021 12:10:23 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 7D55223E70 for ; Wed, 28 Jul 2021 16:10:23 +0000 (UTC) X-FDA: 78412483926.23.61B01F6 Received: from out02.mta.xmission.com (out02.mta.xmission.com [166.70.13.232]) by imf20.hostedemail.com (Postfix) with ESMTP id 00AF6D006920 for ; Wed, 28 Jul 2021 16:10:22 +0000 (UTC) Received: from in01.mta.xmission.com ([166.70.13.51]:32964) by out02.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1m8m8G-007CzP-LA; Wed, 28 Jul 2021 10:10:09 -0600 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95]:41378 helo=email.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1m8m8C-00A9Pq-J2; Wed, 28 Jul 2021 10:10:08 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Arnd Bergmann Cc: Andrew Morton , Arnd Bergmann , Catalin Marinas , Will Deacon , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , "David S. Miller" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Al Viro , Christoph Hellwig , Feng Tang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, linux-mm@kvack.org References: <20210727144859.4150043-1-arnd@kernel.org> <20210727144859.4150043-2-arnd@kernel.org> Date: Wed, 28 Jul 2021 11:09:22 -0500 In-Reply-To: <20210727144859.4150043-2-arnd@kernel.org> (Arnd Bergmann's message of "Tue, 27 Jul 2021 16:48:54 +0200") Message-ID: <87eebifmj1.fsf@disp2133> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1m8m8C-00A9Pq-J2;;;mid=<87eebifmj1.fsf@disp2133>;;;hst=in01.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX18xroipV9CATxhuOK1ETEIbw3EWCZZa/6o= X-SA-Exim-Connect-IP: 68.227.160.95 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: Re: [PATCH v5 1/6] kexec: move locking into do_kexec_load X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Authentication-Results: imf20.hostedemail.com; dkim=none; spf=pass (imf20.hostedemail.com: domain of ebiederm@xmission.com designates 166.70.13.232 as permitted sender) smtp.mailfrom=ebiederm@xmission.com; dmarc=pass (policy=none) header.from=xmission.com X-Rspamd-Server: rspam02 X-Stat-Signature: 3cj6nu5epjhdpc5ofm48nchk9j14qzez X-Rspamd-Queue-Id: 00AF6D006920 X-HE-Tag: 1627488622-46146 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Arnd Bergmann writes: > From: Arnd Bergmann > > The locking is the same between the native and compat version of > sys_kexec_load(), so it can be done in the common implementation > to reduce duplication. Acked-by: "Eric W. Biederman" > > Co-developed-by: Eric Biederman > Co-developed-by: Christoph Hellwig > Signed-off-by: Arnd Bergmann > --- > kernel/kexec.c | 44 ++++++++++++++++---------------------------- > 1 file changed, 16 insertions(+), 28 deletions(-) > > diff --git a/kernel/kexec.c b/kernel/kexec.c > index c82c6c06f051..9c7aef8f4bb6 100644 > --- a/kernel/kexec.c > +++ b/kernel/kexec.c > @@ -110,6 +110,17 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments, > unsigned long i; > int ret; > > + /* > + * Because we write directly to the reserved memory region when loading > + * crash kernels we need a mutex here to prevent multiple crash kernels > + * from attempting to load simultaneously, and to prevent a crash kernel > + * from loading over the top of a in use crash kernel. > + * > + * KISS: always take the mutex. > + */ > + if (!mutex_trylock(&kexec_mutex)) > + return -EBUSY; > + > if (flags & KEXEC_ON_CRASH) { > dest_image = &kexec_crash_image; > if (kexec_crash_image) > @@ -121,7 +132,8 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments, > if (nr_segments == 0) { > /* Uninstall image */ > kimage_free(xchg(dest_image, NULL)); > - return 0; > + ret = 0; > + goto out_unlock; > } > if (flags & KEXEC_ON_CRASH) { > /* > @@ -134,7 +146,7 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments, > > ret = kimage_alloc_init(&image, entry, nr_segments, segments, flags); > if (ret) > - return ret; > + goto out_unlock; > > if (flags & KEXEC_PRESERVE_CONTEXT) > image->preserve_context = 1; > @@ -171,6 +183,8 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments, > arch_kexec_protect_crashkres(); > > kimage_free(image); > +out_unlock: > + mutex_unlock(&kexec_mutex); > return ret; > } > > @@ -247,21 +261,8 @@ SYSCALL_DEFINE4(kexec_load, unsigned long, entry, unsigned long, nr_segments, > ((flags & KEXEC_ARCH_MASK) != KEXEC_ARCH_DEFAULT)) > return -EINVAL; > > - /* Because we write directly to the reserved memory > - * region when loading crash kernels we need a mutex here to > - * prevent multiple crash kernels from attempting to load > - * simultaneously, and to prevent a crash kernel from loading > - * over the top of a in use crash kernel. > - * > - * KISS: always take the mutex. > - */ > - if (!mutex_trylock(&kexec_mutex)) > - return -EBUSY; > - > result = do_kexec_load(entry, nr_segments, segments, flags); > > - mutex_unlock(&kexec_mutex); > - > return result; > } > > @@ -301,21 +302,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry, > return -EFAULT; > } > > - /* Because we write directly to the reserved memory > - * region when loading crash kernels we need a mutex here to > - * prevent multiple crash kernels from attempting to load > - * simultaneously, and to prevent a crash kernel from loading > - * over the top of a in use crash kernel. > - * > - * KISS: always take the mutex. > - */ > - if (!mutex_trylock(&kexec_mutex)) > - return -EBUSY; > - > result = do_kexec_load(entry, nr_segments, ksegments, flags); > > - mutex_unlock(&kexec_mutex); > - > return result; > } > #endif From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CD15C4338F for ; Wed, 28 Jul 2021 16:38:11 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9A17960EB9 for ; Wed, 28 Jul 2021 16:38:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9A17960EB9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=xmission.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.ozlabs.org Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4GZfV90NlLz3cnF for ; Thu, 29 Jul 2021 02:38:09 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=xmission.com (client-ip=166.70.13.232; helo=out02.mta.xmission.com; envelope-from=ebiederm@xmission.com; receiver=) Received: from out02.mta.xmission.com (out02.mta.xmission.com [166.70.13.232]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4GZfTk5H1Kz304X for ; Thu, 29 Jul 2021 02:37:46 +1000 (AEST) Received: from in01.mta.xmission.com ([166.70.13.51]:32964) by out02.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1m8m8G-007CzP-LA; Wed, 28 Jul 2021 10:10:09 -0600 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95]:41378 helo=email.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1m8m8C-00A9Pq-J2; Wed, 28 Jul 2021 10:10:08 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Arnd Bergmann References: <20210727144859.4150043-1-arnd@kernel.org> <20210727144859.4150043-2-arnd@kernel.org> Date: Wed, 28 Jul 2021 11:09:22 -0500 In-Reply-To: <20210727144859.4150043-2-arnd@kernel.org> (Arnd Bergmann's message of "Tue, 27 Jul 2021 16:48:54 +0200") Message-ID: <87eebifmj1.fsf@disp2133> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1m8m8C-00A9Pq-J2; ; ; mid=<87eebifmj1.fsf@disp2133>; ; ; hst=in01.mta.xmission.com; ; ; ip=68.227.160.95; ; ; frm=ebiederm@xmission.com; ; ; spf=neutral X-XM-AID: U2FsdGVkX18xroipV9CATxhuOK1ETEIbw3EWCZZa/6o= X-SA-Exim-Connect-IP: 68.227.160.95 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: Re: [PATCH v5 1/6] kexec: move locking into do_kexec_load X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Feng Tang , linux-mips@vger.kernel.org, "James E.J. Bottomley" , linux-mm@kvack.org, Paul Mackerras , "H. Peter Anvin" , sparclinux@vger.kernel.org, Will Deacon , linux-arch@vger.kernel.org, linux-s390@vger.kernel.org, Arnd Bergmann , Helge Deller , x86@kernel.org, Christoph Hellwig , Christian Borntraeger , Ingo Molnar , Catalin Marinas , Vasily Gorbik , Heiko Carstens , Borislav Petkov , Al Viro , Thomas Gleixner , linux-arm-kernel@lists.infradead.org, Thomas Bogendoerfer , linux-parisc@vger.kernel.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Morton , linuxppc-dev@lists.ozlabs.org, "David S. Miller" Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" Arnd Bergmann writes: > From: Arnd Bergmann > > The locking is the same between the native and compat version of > sys_kexec_load(), so it can be done in the common implementation > to reduce duplication. Acked-by: "Eric W. Biederman" > > Co-developed-by: Eric Biederman > Co-developed-by: Christoph Hellwig > Signed-off-by: Arnd Bergmann > --- > kernel/kexec.c | 44 ++++++++++++++++---------------------------- > 1 file changed, 16 insertions(+), 28 deletions(-) > > diff --git a/kernel/kexec.c b/kernel/kexec.c > index c82c6c06f051..9c7aef8f4bb6 100644 > --- a/kernel/kexec.c > +++ b/kernel/kexec.c > @@ -110,6 +110,17 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments, > unsigned long i; > int ret; > > + /* > + * Because we write directly to the reserved memory region when loading > + * crash kernels we need a mutex here to prevent multiple crash kernels > + * from attempting to load simultaneously, and to prevent a crash kernel > + * from loading over the top of a in use crash kernel. > + * > + * KISS: always take the mutex. > + */ > + if (!mutex_trylock(&kexec_mutex)) > + return -EBUSY; > + > if (flags & KEXEC_ON_CRASH) { > dest_image = &kexec_crash_image; > if (kexec_crash_image) > @@ -121,7 +132,8 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments, > if (nr_segments == 0) { > /* Uninstall image */ > kimage_free(xchg(dest_image, NULL)); > - return 0; > + ret = 0; > + goto out_unlock; > } > if (flags & KEXEC_ON_CRASH) { > /* > @@ -134,7 +146,7 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments, > > ret = kimage_alloc_init(&image, entry, nr_segments, segments, flags); > if (ret) > - return ret; > + goto out_unlock; > > if (flags & KEXEC_PRESERVE_CONTEXT) > image->preserve_context = 1; > @@ -171,6 +183,8 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments, > arch_kexec_protect_crashkres(); > > kimage_free(image); > +out_unlock: > + mutex_unlock(&kexec_mutex); > return ret; > } > > @@ -247,21 +261,8 @@ SYSCALL_DEFINE4(kexec_load, unsigned long, entry, unsigned long, nr_segments, > ((flags & KEXEC_ARCH_MASK) != KEXEC_ARCH_DEFAULT)) > return -EINVAL; > > - /* Because we write directly to the reserved memory > - * region when loading crash kernels we need a mutex here to > - * prevent multiple crash kernels from attempting to load > - * simultaneously, and to prevent a crash kernel from loading > - * over the top of a in use crash kernel. > - * > - * KISS: always take the mutex. > - */ > - if (!mutex_trylock(&kexec_mutex)) > - return -EBUSY; > - > result = do_kexec_load(entry, nr_segments, segments, flags); > > - mutex_unlock(&kexec_mutex); > - > return result; > } > > @@ -301,21 +302,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry, > return -EFAULT; > } > > - /* Because we write directly to the reserved memory > - * region when loading crash kernels we need a mutex here to > - * prevent multiple crash kernels from attempting to load > - * simultaneously, and to prevent a crash kernel from loading > - * over the top of a in use crash kernel. > - * > - * KISS: always take the mutex. > - */ > - if (!mutex_trylock(&kexec_mutex)) > - return -EBUSY; > - > result = do_kexec_load(entry, nr_segments, ksegments, flags); > > - mutex_unlock(&kexec_mutex); > - > return result; > } > #endif From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 712C0C4338F for ; Wed, 28 Jul 2021 16:18:27 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2E8C160F23 for ; Wed, 28 Jul 2021 16:18:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2E8C160F23 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=xmission.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:Message-ID: In-Reply-To:Date:References:Cc:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=FCwA/19P7Mbq+lr2HOoAbrkAppV22pfhAToqxLze8oY=; b=yo3pBTDTfcxGSqN7+eO2mV/2pU 3fhrXUdkMYUpACj8v7hBjkAHbirIPtQWyR+RZhuqR4C9oKYN2kZD1eM3VVNVTf8JFTKd6I7Gn8Orz XpqnDvpQYP5lxbhLHNHDnwftY7QmNeh2+DZ6fWfPKRKbmPFX5j+f1uVhZpXB2n62MAx2hg+upjHgk Gj7/9oqHPi4qBwnA0f9Pjilzm9NyVsU1xqu1RBn3P9oRws4Hs/Lxs+aAnonR0bMBhRiz8Qq7Rdnwh RrlQpQUXKLxruJjI9p9B0cnuugH9UHzxNWSQQMI2vYr+FoHfdnw99GLxYirkeqG1Gf3aBAzIdAJ/v rFQkgSbw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m8mD9-001Xk5-O8; Wed, 28 Jul 2021 16:15:14 +0000 Received: from out02.mta.xmission.com ([166.70.13.232]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m8m8k-001VX6-RJ for linux-arm-kernel@lists.infradead.org; Wed, 28 Jul 2021 16:10:40 +0000 Received: from in01.mta.xmission.com ([166.70.13.51]:32964) by out02.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1m8m8G-007CzP-LA; Wed, 28 Jul 2021 10:10:09 -0600 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95]:41378 helo=email.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1m8m8C-00A9Pq-J2; Wed, 28 Jul 2021 10:10:08 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Arnd Bergmann Cc: Andrew Morton , Arnd Bergmann , Catalin Marinas , Will Deacon , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , "David S. Miller" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Al Viro , Christoph Hellwig , Feng Tang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, linux-mm@kvack.org References: <20210727144859.4150043-1-arnd@kernel.org> <20210727144859.4150043-2-arnd@kernel.org> Date: Wed, 28 Jul 2021 11:09:22 -0500 In-Reply-To: <20210727144859.4150043-2-arnd@kernel.org> (Arnd Bergmann's message of "Tue, 27 Jul 2021 16:48:54 +0200") Message-ID: <87eebifmj1.fsf@disp2133> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 X-XM-SPF: eid=1m8m8C-00A9Pq-J2; ; ; mid=<87eebifmj1.fsf@disp2133>; ; ; hst=in01.mta.xmission.com; ; ; ip=68.227.160.95; ; ; frm=ebiederm@xmission.com; ; ; spf=neutral X-XM-AID: U2FsdGVkX18xroipV9CATxhuOK1ETEIbw3EWCZZa/6o= X-SA-Exim-Connect-IP: 68.227.160.95 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: Re: [PATCH v5 1/6] kexec: move locking into do_kexec_load X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210728_091038_936805_9943BFE1 X-CRM114-Status: GOOD ( 27.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Arnd Bergmann writes: > From: Arnd Bergmann > > The locking is the same between the native and compat version of > sys_kexec_load(), so it can be done in the common implementation > to reduce duplication. Acked-by: "Eric W. Biederman" > > Co-developed-by: Eric Biederman > Co-developed-by: Christoph Hellwig > Signed-off-by: Arnd Bergmann > --- > kernel/kexec.c | 44 ++++++++++++++++---------------------------- > 1 file changed, 16 insertions(+), 28 deletions(-) > > diff --git a/kernel/kexec.c b/kernel/kexec.c > index c82c6c06f051..9c7aef8f4bb6 100644 > --- a/kernel/kexec.c > +++ b/kernel/kexec.c > @@ -110,6 +110,17 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments, > unsigned long i; > int ret; > > + /* > + * Because we write directly to the reserved memory region when loading > + * crash kernels we need a mutex here to prevent multiple crash kernels > + * from attempting to load simultaneously, and to prevent a crash kernel > + * from loading over the top of a in use crash kernel. > + * > + * KISS: always take the mutex. > + */ > + if (!mutex_trylock(&kexec_mutex)) > + return -EBUSY; > + > if (flags & KEXEC_ON_CRASH) { > dest_image = &kexec_crash_image; > if (kexec_crash_image) > @@ -121,7 +132,8 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments, > if (nr_segments == 0) { > /* Uninstall image */ > kimage_free(xchg(dest_image, NULL)); > - return 0; > + ret = 0; > + goto out_unlock; > } > if (flags & KEXEC_ON_CRASH) { > /* > @@ -134,7 +146,7 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments, > > ret = kimage_alloc_init(&image, entry, nr_segments, segments, flags); > if (ret) > - return ret; > + goto out_unlock; > > if (flags & KEXEC_PRESERVE_CONTEXT) > image->preserve_context = 1; > @@ -171,6 +183,8 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments, > arch_kexec_protect_crashkres(); > > kimage_free(image); > +out_unlock: > + mutex_unlock(&kexec_mutex); > return ret; > } > > @@ -247,21 +261,8 @@ SYSCALL_DEFINE4(kexec_load, unsigned long, entry, unsigned long, nr_segments, > ((flags & KEXEC_ARCH_MASK) != KEXEC_ARCH_DEFAULT)) > return -EINVAL; > > - /* Because we write directly to the reserved memory > - * region when loading crash kernels we need a mutex here to > - * prevent multiple crash kernels from attempting to load > - * simultaneously, and to prevent a crash kernel from loading > - * over the top of a in use crash kernel. > - * > - * KISS: always take the mutex. > - */ > - if (!mutex_trylock(&kexec_mutex)) > - return -EBUSY; > - > result = do_kexec_load(entry, nr_segments, segments, flags); > > - mutex_unlock(&kexec_mutex); > - > return result; > } > > @@ -301,21 +302,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry, > return -EFAULT; > } > > - /* Because we write directly to the reserved memory > - * region when loading crash kernels we need a mutex here to > - * prevent multiple crash kernels from attempting to load > - * simultaneously, and to prevent a crash kernel from loading > - * over the top of a in use crash kernel. > - * > - * KISS: always take the mutex. > - */ > - if (!mutex_trylock(&kexec_mutex)) > - return -EBUSY; > - > result = do_kexec_load(entry, nr_segments, ksegments, flags); > > - mutex_unlock(&kexec_mutex); > - > return result; > } > #endif _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel