mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexander Gordeev <agordeev@linux.ibm.com>
To: Matthew Wilcox <willy@infradead.org>,
	Alexander Egorenkov <egorenar@linux.ibm.com>,
	Heiko Carstens <hca@linux.ibm.com>
Cc: Baoquan He <bhe@redhat.com>, Christoph Hellwig <hch@lst.de>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org
Subject: [PATCH v4 3/4] s390/crash: use static swap buffer for copy_to_user_real()
Date: Tue, 19 Jul 2022 07:16:35 +0200	[thread overview]
Message-ID: <334ed359680c4d45dd32feb104909f610312ef0f.1658206891.git.agordeev@linux.ibm.com> (raw)
In-Reply-To: <cover.1658206891.git.agordeev@linux.ibm.com>

Currently a temporary page-size buffer is allocated for copying
oldmem to user space. That limits copy_to_user_real() operation
only to stages when virtual memory is available and still makes
it possible to fail while the system is being dumped.

Instead of reallocating single page on each copy_oldmem_page()
iteration use a statically allocated buffer.

This also paves the way for a further memcpy_real() rework where
no swap buffer is needed altogether.

Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
---
 arch/s390/kernel/crash_dump.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/arch/s390/kernel/crash_dump.c b/arch/s390/kernel/crash_dump.c
index 8d7332d4444c..1662f1d81abe 100644
--- a/arch/s390/kernel/crash_dump.c
+++ b/arch/s390/kernel/crash_dump.c
@@ -53,6 +53,8 @@ struct save_area {
 };
 
 static LIST_HEAD(dump_save_areas);
+static DEFINE_MUTEX(memcpy_real_mutex);
+static char memcpy_real_buf[PAGE_SIZE];
 
 /*
  * Allocate a save area
@@ -178,25 +180,21 @@ int copy_oldmem_kernel(void *dst, unsigned long src, size_t count)
  */
 static int copy_to_user_real(void __user *dest, unsigned long src, unsigned long count)
 {
-	int offs = 0, size, rc;
-	char *buf;
+	unsigned long offs = 0, size;
 
-	buf = (char *)__get_free_page(GFP_KERNEL);
-	if (!buf)
-		return -ENOMEM;
-	rc = -EFAULT;
+	mutex_lock(&memcpy_real_mutex);
 	while (offs < count) {
 		size = min(PAGE_SIZE, count - offs);
-		if (memcpy_real(buf, src + offs, size))
-			goto out;
-		if (copy_to_user(dest + offs, buf, size))
-			goto out;
+		if (memcpy_real(memcpy_real_buf, src + offs, size))
+			break;
+		if (copy_to_user(dest + offs, memcpy_real_buf, size))
+			break;
 		offs += size;
 	}
-	rc = 0;
-out:
-	free_page((unsigned long)buf);
-	return rc;
+	mutex_unlock(&memcpy_real_mutex);
+	if (offs < count)
+		return -EFAULT;
+	return 0;
 }
 
 /*
-- 
2.34.1


  parent reply	other threads:[~2022-07-19  5:27 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-19  5:16 [PATCH v4 0/4] s390/crash: support multi-segment iterators Alexander Gordeev
2022-07-19  5:16 ` [PATCH v4 1/4] s390/zcore: fix race when reading from hardware system area Alexander Gordeev
2022-07-19  5:16 ` [PATCH v4 2/4] s390/crash: move copy_to_user_real() to crash_dump.c Alexander Gordeev
2022-07-19  5:16 ` Alexander Gordeev [this message]
2022-07-19  5:16 ` [PATCH v4 4/4] s390/crash: support multi-segment iterators Alexander Gordeev
2022-07-20  3:17 ` [PATCH v4 0/4] " Al Viro
2022-07-20 15:44   ` Alexander Gordeev
2022-07-21  8:46   ` Alexander Gordeev
2022-07-21 20:05     ` Al Viro
2022-07-20  9:47 ` Heiko Carstens
2022-07-20 12:15 ` Alexander Egorenkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=334ed359680c4d45dd32feb104909f610312ef0f.1658206891.git.agordeev@linux.ibm.com \
    --to=agordeev@linux.ibm.com \
    --cc=bhe@redhat.com \
    --cc=egorenar@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=hch@lst.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®