All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] kexec: move locking into do_kexec_load
@ 2023-03-01 16:18 wenyang.linux
  2023-03-15  7:54 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 5+ messages in thread
From: wenyang.linux @ 2023-03-01 16:18 UTC (permalink / raw)
  To: Sasha Levin, Greg Kroah-Hartman
  Cc: Arnd Bergmann, Eric Biederman, Christoph Hellwig,
	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, H. Peter Anvin,
	Al Viro, Feng Tang, Christoph Hellwig, Andrew Morton,
	Linus Torvalds, stable, Wen Yang

From: Arnd Bergmann <arnd@arndb.de>

commit 4b692e861619353ce069e547a67c8d0e32d9ef3d upstream.

Patch series "compat: remove compat_alloc_user_space", v5.

Going through compat_alloc_user_space() to convert indirect system call
arguments tends to add complexity compared to handling the native and
compat logic in the same code.

This patch (of 6):

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.

Link: https://lkml.kernel.org/r/20210727144859.4150043-1-arnd@kernel.org
Link: https://lkml.kernel.org/r/20210727144859.4150043-2-arnd@kernel.org
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Co-developed-by: Eric Biederman <ebiederm@xmission.com>
Co-developed-by: Christoph Hellwig <hch@infradead.org>
Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: Helge Deller <deller@gmx.de>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Feng Tang <feng.tang@intel.com>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: stable@vger.kernel.org # 5.10+
Signed-off-by: Wen Yang <wenyang.linux@foxmail.com>
---
 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
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/3] kexec: move locking into do_kexec_load
  2023-03-01 16:18 [PATCH 1/3] kexec: move locking into do_kexec_load wenyang.linux
@ 2023-03-15  7:54 ` Greg Kroah-Hartman
  2023-03-15 19:45   ` Andrew Morton
  2023-03-16 17:18   ` Wen Yang
  0 siblings, 2 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2023-03-15  7:54 UTC (permalink / raw)
  To: wenyang.linux
  Cc: Sasha Levin, Arnd Bergmann, Eric Biederman, Christoph Hellwig,
	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, H. Peter Anvin,
	Al Viro, Feng Tang, Christoph Hellwig, Andrew Morton,
	Linus Torvalds, stable

On Thu, Mar 02, 2023 at 12:18:04AM +0800, wenyang.linux@foxmail.com wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> commit 4b692e861619353ce069e547a67c8d0e32d9ef3d upstream.
> 
> Patch series "compat: remove compat_alloc_user_space", v5.
> 
> Going through compat_alloc_user_space() to convert indirect system call
> arguments tends to add complexity compared to handling the native and
> compat logic in the same code.
> 
> This patch (of 6):

What about the other 6?

And what kernel is this going to, just 5.10.y?

Can you resend this as an actual patch series linked together?  They do
not show up properly for some reason (same for your 5.15.y patches.)

Try using git send-email to send them out.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/3] kexec: move locking into do_kexec_load
  2023-03-15  7:54 ` Greg Kroah-Hartman
@ 2023-03-15 19:45   ` Andrew Morton
  2023-03-16 17:18   ` Wen Yang
  1 sibling, 0 replies; 5+ messages in thread
From: Andrew Morton @ 2023-03-15 19:45 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: wenyang.linux, Sasha Levin, Arnd Bergmann, Eric Biederman,
	Christoph Hellwig, 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,
	H. Peter Anvin, Al Viro, Feng Tang, Christoph Hellwig,
	Linus Torvalds, stable

On Wed, 15 Mar 2023 08:54:38 +0100 Greg Kroah-Hartman <gregkh@linuxfoundation.org> wrote:

> On Thu, Mar 02, 2023 at 12:18:04AM +0800, wenyang.linux@foxmail.com wrote:
> > From: Arnd Bergmann <arnd@arndb.de>
> > 
> > commit 4b692e861619353ce069e547a67c8d0e32d9ef3d upstream.
> > 
> > Patch series "compat: remove compat_alloc_user_space", v5.
> > 
> > Going through compat_alloc_user_space() to convert indirect system call
> > arguments tends to add complexity compared to handling the native and
> > compat logic in the same code.
> > 
> > This patch (of 6):
> 
> What about the other 6?
> 
> And what kernel is this going to, just 5.10.y?
> 
> Can you resend this as an actual patch series linked together?  They do
> not show up properly for some reason (same for your 5.15.y patches.)
> 
> Try using git send-email to send them out.
> 

Well...  what bugs does this series fix?  I originally saw nothing
indicating that a backport was needed.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/3] kexec: move locking into do_kexec_load
  2023-03-15  7:54 ` Greg Kroah-Hartman
  2023-03-15 19:45   ` Andrew Morton
@ 2023-03-16 17:18   ` Wen Yang
  2023-03-17  8:21     ` Arnd Bergmann
  1 sibling, 1 reply; 5+ messages in thread
From: Wen Yang @ 2023-03-16 17:18 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Sasha Levin, Arnd Bergmann, Eric Biederman, Christoph Hellwig,
	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, H. Peter Anvin,
	Al Viro, Feng Tang, Christoph Hellwig, Andrew Morton,
	Linus Torvalds, stable


在 2023/3/15 15:54, Greg Kroah-Hartman 写道:
> On Thu, Mar 02, 2023 at 12:18:04AM +0800, wenyang.linux@foxmail.com wrote:
>> From: Arnd Bergmann <arnd@arndb.de>
>>
>> commit 4b692e861619353ce069e547a67c8d0e32d9ef3d upstream.
>>
>> Patch series "compat: remove compat_alloc_user_space", v5.
>>
>> Going through compat_alloc_user_space() to convert indirect system call
>> arguments tends to add complexity compared to handling the native and
>> compat logic in the same code.
>>
>> This patch (of 6):
> What about the other 6?

Hi,
Both 4b692e861619 ("kexec: move locking into do_kexec_load") and 
7bb5da0d490b
("kexec: turn all kexec_mutex acquisitions into trylocks") are prerequisites
for 05c6257433b7 ("panic, kexec: make __crash_kexec() NMI safe").

In addition, although 4b692e861619 ("kexec: move locking into 
do_kexec_load")
is part of patch series "compat: remove compat_alloc_user_space", it is also
independent and a general optimization,  and here we just need is it, as 
follows:

Arnd Bergmann (6):
   kexec: move locking into do_kexec_load
   kexec: avoid compat_alloc_user_space
   mm: simplify compat_sys_move_pages
   mm: simplify compat numa syscalls
   compat: remove some compat entry points
   arch: remove compat_alloc_user_space

https://lore.kernel.org/all/20210727144859.4150043-7-arnd@kernel.org/T/#u


> And what kernel is this going to, just 5.10.y?

For 5.10.y, these three patches are needed:

4b692e861619 ("kexec: move locking into do_kexec_load")
7bb5da0d490b ("kexec: turn all kexec_mutex acquisitions into trylocks")
05c6257433b7 ("panic, kexec: make __crash_kexec() NMI safe").

For 5.15.y, only these two patches are needed:

7bb5da0d490b ("kexec: turn all kexec_mutex acquisitions into trylocks")
05c6257433b7 ("panic, kexec: make __crash_kexec() NMI safe").


> Can you resend this as an actual patch series linked together?  They do
> not show up properly for some reason (same for your 5.15.y patches.)
>
> Try using git send-email to send them out.
>
OK, we'll resend it later.

-- 

Best wishes,

Wen



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/3] kexec: move locking into do_kexec_load
  2023-03-16 17:18   ` Wen Yang
@ 2023-03-17  8:21     ` Arnd Bergmann
  0 siblings, 0 replies; 5+ messages in thread
From: Arnd Bergmann @ 2023-03-17  8:21 UTC (permalink / raw)
  To: Wen Yang, Greg Kroah-Hartman
  Cc: Sasha Levin, Eric W. Biederman, Christoph Hellwig,
	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, H. Peter Anvin,
	Alexander Viro, Feng Tang, Christoph Hellwig, Andrew Morton,
	Linus Torvalds, stable

On Thu, Mar 16, 2023, at 18:18, Wen Yang wrote:
> 在 2023/3/15 15:54, Greg Kroah-Hartman 写道:
>> On Thu, Mar 02, 2023 at 12:18:04AM +0800, wenyang.linux@foxmail.com wrote:
>>> From: Arnd Bergmann <arnd@arndb.de>
>>>
>>> commit 4b692e861619353ce069e547a67c8d0e32d9ef3d upstream.
>>>
>>> Patch series "compat: remove compat_alloc_user_space", v5.
>>>
>>> Going through compat_alloc_user_space() to convert indirect system call
>>> arguments tends to add complexity compared to handling the native and
>>> compat logic in the same code.
>>>
>>> This patch (of 6):
>> What about the other 6?
>
> Hi,
> Both 4b692e861619 ("kexec: move locking into do_kexec_load") and 
> 7bb5da0d490b
> ("kexec: turn all kexec_mutex acquisitions into trylocks") are prerequisites
> for 05c6257433b7 ("panic, kexec: make __crash_kexec() NMI safe").
>
> In addition, although 4b692e861619 ("kexec: move locking into 
> do_kexec_load")
> is part of patch series "compat: remove compat_alloc_user_space", it is also
> independent and a general optimization,  and here we just need is it, as 
> follows:

Ok, this makes much more sense then, without the explanation
I had no idea why you would backport my old patch.

      Arnd

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-03-17  8:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-01 16:18 [PATCH 1/3] kexec: move locking into do_kexec_load wenyang.linux
2023-03-15  7:54 ` Greg Kroah-Hartman
2023-03-15 19:45   ` Andrew Morton
2023-03-16 17:18   ` Wen Yang
2023-03-17  8:21     ` Arnd Bergmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.