From: ebiederm@xmission.com (Eric W. Biederman)
To: Avi Kivity <avi@redhat.com>
Cc: Bryan Donlan <bdonlan@gmail.com>,
Christopher Yeoh <cyeoh@au1.ibm.com>,
linux-kernel@vger.kernel.org,
Linux Memory Management List <linux-mm@kvack.org>,
Ingo Molnar <mingo@elte.hu>,
Linus Torvalds <torvalds@linux-foundation.org>,
Valdis.Kletnieks@vt.edu, Alan Cox <alan@lxorguk.ukuu.org.uk>,
Robin Holt <holt@sgi.com>
Subject: Re: [RFC][PATCH] Cross Memory Attach
Date: Wed, 15 Sep 2010 12:35:02 -0700 [thread overview]
Message-ID: <m1pqwe6brt.fsf@fess.ebiederm.org> (raw)
In-Reply-To: <4C90F09F.9080307@redhat.com> (Avi Kivity's message of "Wed, 15 Sep 2010 18:13:19 +0200")
Avi Kivity <avi@redhat.com> writes:
> On 09/15/2010 04:46 PM, Bryan Donlan wrote:
>> On Wed, Sep 15, 2010 at 19:58, Avi Kivity<avi@redhat.com> wrote:
>>
>>> Instead of those two syscalls, how about a vmfd(pid_t pid, ulong start,
>>> ulong len) system call which returns an file descriptor that represents a
>>> portion of the process address space. You can then use preadv() and
>>> pwritev() to copy memory, and io_submit(IO_CMD_PREADV) and
>>> io_submit(IO_CMD_PWRITEV) for asynchronous variants (especially useful with
>>> a dma engine, since that adds latency).
>>>
>>> With some care (and use of mmu_notifiers) you can even mmap() your vmfd and
>>> access remote process memory directly.
>> Rather than introducing a new vmfd() API for this, why not just add
>> implementations for these more efficient operations to the existing
>> /proc/$pid/mem interface?
>
> Yes, opening that file should be equivalent (and you could certainly implement
> aio via dma for it).
I will second this /proc/$pid/mem is semantically the same and it would
really be good if this patch became a patch optimizing that case.
Otherwise we have code duplication and thus dilution of knowledge in
two different places for no discernable reason. Hindering long term
maintenance.
+int copy_to_from_process_allowed(struct task_struct *task)
+{
+ /* Allow copy_to_from_process to access another process using
+ the same critera as a process would be allowed to ptrace
+ that same process */
+ const struct cred *cred = current_cred(), *tcred;
+
+ rcu_read_lock();
+ tcred = __task_cred(task);
+ if ((cred->uid != tcred->euid ||
+ cred->uid != tcred->suid ||
+ cred->uid != tcred->uid ||
+ cred->gid != tcred->egid ||
+ cred->gid != tcred->sgid ||
+ cred->gid != tcred->gid) &&
+ !capable(CAP_SYS_PTRACE)) {
+ rcu_read_unlock();
+ return 0;
+ }
+ rcu_read_unlock();
+ return 1;
+}
This hunk of the patch is a copy of __ptrace_may_access without security
hooks removed. Both the code duplication, the removal of the dumpable
check and the removal of the security hooks look like a bad idea.
Removing the other checks in check_mem_permission seems reasonable as
those appear to be overly paranoid.
Hmm. This is weird:
+ /* Get the pages we're interested in */
+ pages_pinned = get_user_pages(task, task->mm, pa,
+ nr_pages_to_copy,
+ copy_to, 0, process_pages, NULL);
+
+ if (pages_pinned != nr_pages_to_copy)
+ goto end;
+
+ /* Do the copy for each page */
+ for (i = 0; i < nr_pages_to_copy; i++) {
+ target_kaddr = kmap(process_pages[i]) + start_offset;
+ bytes_to_copy = min(PAGE_SIZE - start_offset,
+ len - *bytes_copied);
+ if (start_offset)
+ start_offset = 0;
+
+ if (copy_to) {
+ ret = copy_from_user(target_kaddr,
+ user_buf + *bytes_copied,
+ bytes_to_copy);
+ if (ret) {
+ kunmap(process_pages[i]);
+ goto end;
+ }
+ } else {
+ ret = copy_to_user(user_buf + *bytes_copied,
+ target_kaddr, bytes_to_copy);
+ if (ret) {
+ kunmap(process_pages[i]);
+ goto end;
+ }
+ }
+ kunmap(process_pages[i]);
+ *bytes_copied += bytes_to_copy;
+ }
+
That hunk of code appears to be an copy of mm/memmory.c:access_process_vm.
A little more optimized by taking the get_user_pages out of the inner
loop but otherwise pretty much the same code.
So I would argue it makes sense to optimize access_process_vm.
So unless there are fundamental bottlenecks to performance I am not
seeing please optimize the existing code paths in the kernel that do
exactly what you are trying to do.
Thanks,
Eric
WARNING: multiple messages have this Message-ID (diff)
From: ebiederm@xmission.com (Eric W. Biederman)
To: Avi Kivity <avi@redhat.com>
Cc: Bryan Donlan <bdonlan@gmail.com>,
Christopher Yeoh <cyeoh@au1.ibm.com>,
linux-kernel@vger.kernel.org,
Linux Memory Management List <linux-mm@kvack.org>,
Ingo Molnar <mingo@elte.hu>,
Linus Torvalds <torvalds@linux-foundation.org>,
Valdis.Kletnieks@vt.edu, Alan Cox <alan@lxorguk.ukuu.org.uk>,
Robin Holt <holt@sgi.com>
Subject: Re: [RFC][PATCH] Cross Memory Attach
Date: Wed, 15 Sep 2010 12:35:02 -0700 [thread overview]
Message-ID: <m1pqwe6brt.fsf@fess.ebiederm.org> (raw)
In-Reply-To: <4C90F09F.9080307@redhat.com> (Avi Kivity's message of "Wed, 15 Sep 2010 18:13:19 +0200")
Avi Kivity <avi@redhat.com> writes:
> On 09/15/2010 04:46 PM, Bryan Donlan wrote:
>> On Wed, Sep 15, 2010 at 19:58, Avi Kivity<avi@redhat.com> wrote:
>>
>>> Instead of those two syscalls, how about a vmfd(pid_t pid, ulong start,
>>> ulong len) system call which returns an file descriptor that represents a
>>> portion of the process address space. You can then use preadv() and
>>> pwritev() to copy memory, and io_submit(IO_CMD_PREADV) and
>>> io_submit(IO_CMD_PWRITEV) for asynchronous variants (especially useful with
>>> a dma engine, since that adds latency).
>>>
>>> With some care (and use of mmu_notifiers) you can even mmap() your vmfd and
>>> access remote process memory directly.
>> Rather than introducing a new vmfd() API for this, why not just add
>> implementations for these more efficient operations to the existing
>> /proc/$pid/mem interface?
>
> Yes, opening that file should be equivalent (and you could certainly implement
> aio via dma for it).
I will second this /proc/$pid/mem is semantically the same and it would
really be good if this patch became a patch optimizing that case.
Otherwise we have code duplication and thus dilution of knowledge in
two different places for no discernable reason. Hindering long term
maintenance.
+int copy_to_from_process_allowed(struct task_struct *task)
+{
+ /* Allow copy_to_from_process to access another process using
+ the same critera as a process would be allowed to ptrace
+ that same process */
+ const struct cred *cred = current_cred(), *tcred;
+
+ rcu_read_lock();
+ tcred = __task_cred(task);
+ if ((cred->uid != tcred->euid ||
+ cred->uid != tcred->suid ||
+ cred->uid != tcred->uid ||
+ cred->gid != tcred->egid ||
+ cred->gid != tcred->sgid ||
+ cred->gid != tcred->gid) &&
+ !capable(CAP_SYS_PTRACE)) {
+ rcu_read_unlock();
+ return 0;
+ }
+ rcu_read_unlock();
+ return 1;
+}
This hunk of the patch is a copy of __ptrace_may_access without security
hooks removed. Both the code duplication, the removal of the dumpable
check and the removal of the security hooks look like a bad idea.
Removing the other checks in check_mem_permission seems reasonable as
those appear to be overly paranoid.
Hmm. This is weird:
+ /* Get the pages we're interested in */
+ pages_pinned = get_user_pages(task, task->mm, pa,
+ nr_pages_to_copy,
+ copy_to, 0, process_pages, NULL);
+
+ if (pages_pinned != nr_pages_to_copy)
+ goto end;
+
+ /* Do the copy for each page */
+ for (i = 0; i < nr_pages_to_copy; i++) {
+ target_kaddr = kmap(process_pages[i]) + start_offset;
+ bytes_to_copy = min(PAGE_SIZE - start_offset,
+ len - *bytes_copied);
+ if (start_offset)
+ start_offset = 0;
+
+ if (copy_to) {
+ ret = copy_from_user(target_kaddr,
+ user_buf + *bytes_copied,
+ bytes_to_copy);
+ if (ret) {
+ kunmap(process_pages[i]);
+ goto end;
+ }
+ } else {
+ ret = copy_to_user(user_buf + *bytes_copied,
+ target_kaddr, bytes_to_copy);
+ if (ret) {
+ kunmap(process_pages[i]);
+ goto end;
+ }
+ }
+ kunmap(process_pages[i]);
+ *bytes_copied += bytes_to_copy;
+ }
+
That hunk of code appears to be an copy of mm/memmory.c:access_process_vm.
A little more optimized by taking the get_user_pages out of the inner
loop but otherwise pretty much the same code.
So I would argue it makes sense to optimize access_process_vm.
So unless there are fundamental bottlenecks to performance I am not
seeing please optimize the existing code paths in the kernel that do
exactly what you are trying to do.
Thanks,
Eric
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2010-09-15 19:35 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-15 1:18 [RFC][PATCH] Cross Memory Attach Christopher Yeoh
2010-09-15 8:02 ` Ingo Molnar
2010-09-15 8:02 ` Ingo Molnar
2010-09-15 8:16 ` Ingo Molnar
2010-09-15 8:16 ` Ingo Molnar
2010-09-15 13:23 ` Christopher Yeoh
2010-09-15 13:23 ` Christopher Yeoh
2010-09-15 13:20 ` Christopher Yeoh
2010-09-15 13:20 ` Christopher Yeoh
2010-09-15 10:58 ` Avi Kivity
2010-09-15 10:58 ` Avi Kivity
2010-09-15 13:51 ` Ingo Molnar
2010-09-15 13:51 ` Ingo Molnar
2010-09-15 16:10 ` Avi Kivity
2010-09-15 16:10 ` Avi Kivity
2010-09-15 14:42 ` Christopher Yeoh
2010-09-15 14:42 ` Christopher Yeoh
2010-09-15 14:52 ` Linus Torvalds
2010-09-15 14:52 ` Linus Torvalds
2010-09-15 15:44 ` Robin Holt
2010-09-15 15:44 ` Robin Holt
2010-09-16 6:32 ` Brice Goglin
2010-09-16 6:32 ` Brice Goglin
2010-09-16 9:15 ` Brice Goglin
2010-09-16 9:15 ` Brice Goglin
2010-09-16 14:00 ` Christopher Yeoh
2010-09-16 14:00 ` Christopher Yeoh
2010-09-15 14:46 ` Bryan Donlan
2010-09-15 14:46 ` Bryan Donlan
2010-09-15 16:13 ` Avi Kivity
2010-09-15 16:13 ` Avi Kivity
2010-09-15 19:35 ` Eric W. Biederman [this message]
2010-09-15 19:35 ` Eric W. Biederman
2010-09-16 1:18 ` Christopher Yeoh
2010-09-16 1:18 ` Christopher Yeoh
2010-09-16 9:26 ` Avi Kivity
2010-09-16 9:26 ` Avi Kivity
2010-11-02 3:37 ` Christopher Yeoh
2010-11-02 3:37 ` Christopher Yeoh
2010-11-02 11:10 ` Avi Kivity
2010-11-02 11:10 ` Avi Kivity
2010-09-16 1:58 ` KOSAKI Motohiro
2010-09-16 1:58 ` KOSAKI Motohiro
2010-09-16 8:08 ` Ingo Molnar
2010-09-16 8:08 ` Ingo Molnar
2010-09-15 15:11 ` Linus Torvalds
2010-09-15 15:14 ` Linus Torvalds
2010-09-16 2:25 ` Christopher Yeoh
2010-09-16 16:27 ` Peter Zijlstra
2010-09-16 16:54 ` Linus Torvalds
2010-09-16 17:13 ` Peter Zijlstra
2010-09-16 17:34 ` Linus Torvalds
2010-09-16 17:47 ` Peter Zijlstra
2010-09-16 17:54 ` Linus Torvalds
2010-09-16 18:00 ` Linus Torvalds
2010-09-19 4:44 ` Yuhong Bao
2010-09-19 19:20 ` Yuhong Bao
2010-09-19 21:48 ` Russell King - ARM Linux
2010-09-19 22:47 ` Yuhong Bao
2010-09-19 4:55 ` Yuhong Bao
2010-09-15 16:07 ` Valdis.Kletnieks
2010-09-16 2:17 ` Christopher Yeoh
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=m1pqwe6brt.fsf@fess.ebiederm.org \
--to=ebiederm@xmission.com \
--cc=Valdis.Kletnieks@vt.edu \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=avi@redhat.com \
--cc=bdonlan@gmail.com \
--cc=cyeoh@au1.ibm.com \
--cc=holt@sgi.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mingo@elte.hu \
--cc=torvalds@linux-foundation.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 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.