From: Andrew Morton <akpm@linux-foundation.org>
To: thnkslprpt@gmail.com,brads@mainlining.org,akpm@linux-foundation.org,linux-kernel@vger.kernel.org
Subject: [PATCH 2/3] profile: account for partial /proc/profile reads
Date: Tue, 20 Oct 2026 17:52:00 -0700 [thread overview]
Message-ID: <e7e8de4d10204573a54c2044c060379b.2@linux-foundation.org> (raw)
In-Reply-To: <e7e8de4d10204573a54c2044c060379b.1@linux-foundation.org>
From: Andrew Morton <akpm@linux-foundation.org>
Subject: profile: account for partial /proc/profile reads
Date: Tue, 20 Oct 2026 15:28:00 -0700
read_profile() returns -EFAULT without advancing the file position
when a user copy faults, even if earlier header bytes or a prefix of
the counters were successfully copied. A retry can therefore copy
the same bytes again despite the previous read having delivered data.
Return the number of successfully copied bytes and advance *ppos by
that amount. Return -EFAULT only if the fault occurs before any bytes
are copied. Preserve the four-byte sampling-step header, raw counter
representation, and normal successful-read behavior.
Avi Weiss's "profiling: fix sampling step on 64-bit big-endian
systems" is unchanged. This patch changes only short-read and
fault reporting, not the output format.
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Avi Weiss <thnkslprpt@gmail.com>
Cc: Bradley Morgan <brads@mainlining.org>
---
Tested the combined three-patch series on x86-64 QEMU/KVM with
CONFIG_PROFILING=y, CONFIG_PROC_FS=y and profile=12.
profile-read-test.c: PASS (0 failures). Covered header decoding,
short and boundary reads, EOF, partial user-copy faults, return
values and file-position accounting.
The 64-bit big-endian fix was not runtime tested. There was no
individual-patch or unpatched-versus-patched runtime comparison.
kernel/profile.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
--- a/kernel/profile.c~profile-account-for-partial-proc-profile-reads
+++ a/kernel/profile.c
@@ -157,6 +157,7 @@ read_profile(struct file *file, char __u
ssize_t read;
char *pnt;
unsigned int sample_step = (unsigned int)(1UL << prof_shift);
+ size_t not_copied;
if (p >= (prof_len+1)*sizeof(unsigned int))
return 0;
@@ -166,15 +167,21 @@ read_profile(struct file *file, char __u
while (p < sizeof(unsigned int) && count > 0) {
if (put_user(*((char *)(&sample_step)+p), buf))
- return -EFAULT;
+ goto out;
buf++; p++; count--; read++;
}
- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
- if (copy_to_user(buf, (void *)pnt, count))
- return -EFAULT;
- read += count;
+ if (count) {
+ pnt = (char *)prof_buffer + p - sizeof(atomic_t);
+ not_copied = copy_to_user(buf, pnt, count);
+ read += count - not_copied;
+ if (not_copied)
+ goto out;
+ }
*ppos += read;
return read;
+out:
+ *ppos += read;
+ return read ? read : -EFAULT;
}
/* default is to not implement this call */
_
next prev parent reply other threads:[~2026-10-21 0:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-21 0:51 [PATCH 1/3] profiling: fix sampling step on 64-bit big-endian systems Andrew Morton
2026-10-21 0:52 ` Andrew Morton [this message]
2026-10-21 0:52 ` [PATCH 3/3] profile: simplify /proc/profile read layout Andrew Morton
2026-10-21 1:27 ` Andrew Morton
2026-10-21 14:49 ` Bradley Morgan
2026-10-29 12:11 ` Bradley Morgan
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=e7e8de4d10204573a54c2044c060379b.2@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=brads@mainlining.org \
--cc=linux-kernel@vger.kernel.org \
--cc=thnkslprpt@gmail.com \
/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 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.