* [PATCH] linux-2.6.18/privcmd: sprinkle around cond_resched() calls in mmap ioctl handling
@ 2014-01-28 12:52 Jan Beulich
2014-01-28 15:39 ` Konrad Rzeszutek Wilk
0 siblings, 1 reply; 3+ messages in thread
From: Jan Beulich @ 2014-01-28 12:52 UTC (permalink / raw)
To: xen-devel
[-- Attachment #1: Type: text/plain, Size: 3678 bytes --]
Many of these operations can be arbitrarily long, which can become a
problem irrespective of them being exposed to privileged users only.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- sle11sp3.orig/drivers/xen/privcmd/privcmd.c 2012-12-12 12:05:51.000000000 +0100
+++ sle11sp3/drivers/xen/privcmd/privcmd.c 2014-01-16 10:01:23.000000000 +0100
@@ -126,6 +126,9 @@ static long privcmd_ioctl(struct file *f
p = mmapcmd.entry;
for (i = 0; i < mmapcmd.num;) {
+ if (i)
+ cond_resched();
+
nr = min(mmapcmd.num - i, MMAP_NR_PER_PAGE);
ret = -ENOMEM;
@@ -158,6 +161,9 @@ static long privcmd_ioctl(struct file *f
i = 0;
list_for_each(l, &pagelist) {
+ if (i)
+ cond_resched();
+
nr = i + min(mmapcmd.num - i, MMAP_NR_PER_PAGE);
msg = (privcmd_mmap_entry_t*)(l + 1);
@@ -186,6 +192,9 @@ static long privcmd_ioctl(struct file *f
addr = vma->vm_start;
i = 0;
list_for_each(l, &pagelist) {
+ if (i)
+ cond_resched();
+
nr = i + min(mmapcmd.num - i, MMAP_NR_PER_PAGE);
msg = (privcmd_mmap_entry_t*)(l + 1);
@@ -209,8 +218,12 @@ static long privcmd_ioctl(struct file *f
mmap_out:
up_write(&mm->mmap_sem);
- list_for_each_safe(l,l2,&pagelist)
+ i = 0;
+ list_for_each_safe(l, l2, &pagelist) {
+ if (!(++i & 7))
+ cond_resched();
free_page((unsigned long)l);
+ }
}
#undef MMAP_NR_PER_PAGE
break;
@@ -236,6 +249,9 @@ static long privcmd_ioctl(struct file *f
p = m.arr;
for (i=0; i<nr_pages; ) {
+ if (i)
+ cond_resched();
+
nr = min(nr_pages - i, MMAPBATCH_NR_PER_PAGE);
ret = -ENOMEM;
@@ -270,6 +286,9 @@ static long privcmd_ioctl(struct file *f
ret = 0;
paged_out = 0;
list_for_each(l, &pagelist) {
+ if (i)
+ cond_resched();
+
nr = i + min(nr_pages - i, MMAPBATCH_NR_PER_PAGE);
mfn = (unsigned long *)(l + 1);
@@ -302,6 +321,9 @@ static long privcmd_ioctl(struct file *f
else
ret = 0;
list_for_each(l, &pagelist) {
+ if (i)
+ cond_resched();
+
nr = min(nr_pages - i, MMAPBATCH_NR_PER_PAGE);
mfn = (unsigned long *)(l + 1);
if (copy_to_user(p, mfn, nr*sizeof(*mfn)))
@@ -310,8 +332,12 @@ static long privcmd_ioctl(struct file *f
}
}
mmapbatch_out:
- list_for_each_safe(l,l2,&pagelist)
+ i = 0;
+ list_for_each_safe(l, l2, &pagelist) {
+ if (!(++i & 7))
+ cond_resched();
free_page((unsigned long)l);
+ }
}
break;
@@ -335,6 +361,9 @@ static long privcmd_ioctl(struct file *f
p = m.arr;
for (i = 0; i < nr_pages; i += nr, p += nr) {
+ if (i)
+ cond_resched();
+
nr = min(nr_pages - i, MMAPBATCH_NR_PER_PAGE);
ret = -ENOMEM;
@@ -367,6 +396,9 @@ static long privcmd_ioctl(struct file *f
ret = 0;
paged_out = 0;
list_for_each(l, &pagelist) {
+ if (i)
+ cond_resched();
+
nr = i + min(nr_pages - i, MMAPBATCH_NR_PER_PAGE);
mfn = (void *)(l + 1);
err = (void *)(l + 1);
@@ -397,6 +429,9 @@ static long privcmd_ioctl(struct file *f
ret = paged_out ? -ENOENT : 0;
i = 0;
list_for_each(l, &pagelist) {
+ if (i)
+ cond_resched();
+
nr = min(nr_pages - i, MMAPBATCH_NR_PER_PAGE);
err = (void *)(l + 1);
if (copy_to_user(p, err, nr * sizeof(*err)))
@@ -407,8 +442,12 @@ static long privcmd_ioctl(struct file *f
ret = -EFAULT;
mmapbatch_v2_out:
- list_for_each_safe(l, l2, &pagelist)
+ i = 0;
+ list_for_each_safe(l, l2, &pagelist) {
+ if (!(++i & 7))
+ cond_resched();
free_page((unsigned long)l);
+ }
#undef MMAPBATCH_NR_PER_PAGE
}
break;
[-- Attachment #2: xen-privcmd-mmap-cond-resched.patch --]
[-- Type: text/plain, Size: 3744 bytes --]
privcmd: sprinkle around cond_resched() calls in mmap ioctl handling
Many of these operations can be arbitrarily long, which can become a
problem irrespective of them being exposed to privileged users only.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- sle11sp3.orig/drivers/xen/privcmd/privcmd.c 2012-12-12 12:05:51.000000000 +0100
+++ sle11sp3/drivers/xen/privcmd/privcmd.c 2014-01-16 10:01:23.000000000 +0100
@@ -126,6 +126,9 @@ static long privcmd_ioctl(struct file *f
p = mmapcmd.entry;
for (i = 0; i < mmapcmd.num;) {
+ if (i)
+ cond_resched();
+
nr = min(mmapcmd.num - i, MMAP_NR_PER_PAGE);
ret = -ENOMEM;
@@ -158,6 +161,9 @@ static long privcmd_ioctl(struct file *f
i = 0;
list_for_each(l, &pagelist) {
+ if (i)
+ cond_resched();
+
nr = i + min(mmapcmd.num - i, MMAP_NR_PER_PAGE);
msg = (privcmd_mmap_entry_t*)(l + 1);
@@ -186,6 +192,9 @@ static long privcmd_ioctl(struct file *f
addr = vma->vm_start;
i = 0;
list_for_each(l, &pagelist) {
+ if (i)
+ cond_resched();
+
nr = i + min(mmapcmd.num - i, MMAP_NR_PER_PAGE);
msg = (privcmd_mmap_entry_t*)(l + 1);
@@ -209,8 +218,12 @@ static long privcmd_ioctl(struct file *f
mmap_out:
up_write(&mm->mmap_sem);
- list_for_each_safe(l,l2,&pagelist)
+ i = 0;
+ list_for_each_safe(l, l2, &pagelist) {
+ if (!(++i & 7))
+ cond_resched();
free_page((unsigned long)l);
+ }
}
#undef MMAP_NR_PER_PAGE
break;
@@ -236,6 +249,9 @@ static long privcmd_ioctl(struct file *f
p = m.arr;
for (i=0; i<nr_pages; ) {
+ if (i)
+ cond_resched();
+
nr = min(nr_pages - i, MMAPBATCH_NR_PER_PAGE);
ret = -ENOMEM;
@@ -270,6 +286,9 @@ static long privcmd_ioctl(struct file *f
ret = 0;
paged_out = 0;
list_for_each(l, &pagelist) {
+ if (i)
+ cond_resched();
+
nr = i + min(nr_pages - i, MMAPBATCH_NR_PER_PAGE);
mfn = (unsigned long *)(l + 1);
@@ -302,6 +321,9 @@ static long privcmd_ioctl(struct file *f
else
ret = 0;
list_for_each(l, &pagelist) {
+ if (i)
+ cond_resched();
+
nr = min(nr_pages - i, MMAPBATCH_NR_PER_PAGE);
mfn = (unsigned long *)(l + 1);
if (copy_to_user(p, mfn, nr*sizeof(*mfn)))
@@ -310,8 +332,12 @@ static long privcmd_ioctl(struct file *f
}
}
mmapbatch_out:
- list_for_each_safe(l,l2,&pagelist)
+ i = 0;
+ list_for_each_safe(l, l2, &pagelist) {
+ if (!(++i & 7))
+ cond_resched();
free_page((unsigned long)l);
+ }
}
break;
@@ -335,6 +361,9 @@ static long privcmd_ioctl(struct file *f
p = m.arr;
for (i = 0; i < nr_pages; i += nr, p += nr) {
+ if (i)
+ cond_resched();
+
nr = min(nr_pages - i, MMAPBATCH_NR_PER_PAGE);
ret = -ENOMEM;
@@ -367,6 +396,9 @@ static long privcmd_ioctl(struct file *f
ret = 0;
paged_out = 0;
list_for_each(l, &pagelist) {
+ if (i)
+ cond_resched();
+
nr = i + min(nr_pages - i, MMAPBATCH_NR_PER_PAGE);
mfn = (void *)(l + 1);
err = (void *)(l + 1);
@@ -397,6 +429,9 @@ static long privcmd_ioctl(struct file *f
ret = paged_out ? -ENOENT : 0;
i = 0;
list_for_each(l, &pagelist) {
+ if (i)
+ cond_resched();
+
nr = min(nr_pages - i, MMAPBATCH_NR_PER_PAGE);
err = (void *)(l + 1);
if (copy_to_user(p, err, nr * sizeof(*err)))
@@ -407,8 +442,12 @@ static long privcmd_ioctl(struct file *f
ret = -EFAULT;
mmapbatch_v2_out:
- list_for_each_safe(l, l2, &pagelist)
+ i = 0;
+ list_for_each_safe(l, l2, &pagelist) {
+ if (!(++i & 7))
+ cond_resched();
free_page((unsigned long)l);
+ }
#undef MMAPBATCH_NR_PER_PAGE
}
break;
[-- Attachment #3: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] linux-2.6.18/privcmd: sprinkle around cond_resched() calls in mmap ioctl handling
2014-01-28 12:52 [PATCH] linux-2.6.18/privcmd: sprinkle around cond_resched() calls in mmap ioctl handling Jan Beulich
@ 2014-01-28 15:39 ` Konrad Rzeszutek Wilk
2014-01-28 15:43 ` Jan Beulich
0 siblings, 1 reply; 3+ messages in thread
From: Konrad Rzeszutek Wilk @ 2014-01-28 15:39 UTC (permalink / raw)
To: Jan Beulich; +Cc: xen-devel
On Tue, Jan 28, 2014 at 12:52:18PM +0000, Jan Beulich wrote:
> Many of these operations can be arbitrarily long, which can become a
> problem irrespective of them being exposed to privileged users only.
You probably also want to sprinkle that in the balloon driver as well.
Any thoughts of upstreaming this as well?
Thanks.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>
> --- sle11sp3.orig/drivers/xen/privcmd/privcmd.c 2012-12-12 12:05:51.000000000 +0100
> +++ sle11sp3/drivers/xen/privcmd/privcmd.c 2014-01-16 10:01:23.000000000 +0100
> @@ -126,6 +126,9 @@ static long privcmd_ioctl(struct file *f
>
> p = mmapcmd.entry;
> for (i = 0; i < mmapcmd.num;) {
> + if (i)
> + cond_resched();
> +
> nr = min(mmapcmd.num - i, MMAP_NR_PER_PAGE);
>
> ret = -ENOMEM;
> @@ -158,6 +161,9 @@ static long privcmd_ioctl(struct file *f
>
> i = 0;
> list_for_each(l, &pagelist) {
> + if (i)
> + cond_resched();
> +
> nr = i + min(mmapcmd.num - i, MMAP_NR_PER_PAGE);
>
> msg = (privcmd_mmap_entry_t*)(l + 1);
> @@ -186,6 +192,9 @@ static long privcmd_ioctl(struct file *f
> addr = vma->vm_start;
> i = 0;
> list_for_each(l, &pagelist) {
> + if (i)
> + cond_resched();
> +
> nr = i + min(mmapcmd.num - i, MMAP_NR_PER_PAGE);
>
> msg = (privcmd_mmap_entry_t*)(l + 1);
> @@ -209,8 +218,12 @@ static long privcmd_ioctl(struct file *f
>
> mmap_out:
> up_write(&mm->mmap_sem);
> - list_for_each_safe(l,l2,&pagelist)
> + i = 0;
> + list_for_each_safe(l, l2, &pagelist) {
> + if (!(++i & 7))
> + cond_resched();
> free_page((unsigned long)l);
> + }
> }
> #undef MMAP_NR_PER_PAGE
> break;
> @@ -236,6 +249,9 @@ static long privcmd_ioctl(struct file *f
>
> p = m.arr;
> for (i=0; i<nr_pages; ) {
> + if (i)
> + cond_resched();
> +
> nr = min(nr_pages - i, MMAPBATCH_NR_PER_PAGE);
>
> ret = -ENOMEM;
> @@ -270,6 +286,9 @@ static long privcmd_ioctl(struct file *f
> ret = 0;
> paged_out = 0;
> list_for_each(l, &pagelist) {
> + if (i)
> + cond_resched();
> +
> nr = i + min(nr_pages - i, MMAPBATCH_NR_PER_PAGE);
> mfn = (unsigned long *)(l + 1);
>
> @@ -302,6 +321,9 @@ static long privcmd_ioctl(struct file *f
> else
> ret = 0;
> list_for_each(l, &pagelist) {
> + if (i)
> + cond_resched();
> +
> nr = min(nr_pages - i, MMAPBATCH_NR_PER_PAGE);
> mfn = (unsigned long *)(l + 1);
> if (copy_to_user(p, mfn, nr*sizeof(*mfn)))
> @@ -310,8 +332,12 @@ static long privcmd_ioctl(struct file *f
> }
> }
> mmapbatch_out:
> - list_for_each_safe(l,l2,&pagelist)
> + i = 0;
> + list_for_each_safe(l, l2, &pagelist) {
> + if (!(++i & 7))
> + cond_resched();
> free_page((unsigned long)l);
> + }
> }
> break;
>
> @@ -335,6 +361,9 @@ static long privcmd_ioctl(struct file *f
>
> p = m.arr;
> for (i = 0; i < nr_pages; i += nr, p += nr) {
> + if (i)
> + cond_resched();
> +
> nr = min(nr_pages - i, MMAPBATCH_NR_PER_PAGE);
>
> ret = -ENOMEM;
> @@ -367,6 +396,9 @@ static long privcmd_ioctl(struct file *f
> ret = 0;
> paged_out = 0;
> list_for_each(l, &pagelist) {
> + if (i)
> + cond_resched();
> +
> nr = i + min(nr_pages - i, MMAPBATCH_NR_PER_PAGE);
> mfn = (void *)(l + 1);
> err = (void *)(l + 1);
> @@ -397,6 +429,9 @@ static long privcmd_ioctl(struct file *f
> ret = paged_out ? -ENOENT : 0;
> i = 0;
> list_for_each(l, &pagelist) {
> + if (i)
> + cond_resched();
> +
> nr = min(nr_pages - i, MMAPBATCH_NR_PER_PAGE);
> err = (void *)(l + 1);
> if (copy_to_user(p, err, nr * sizeof(*err)))
> @@ -407,8 +442,12 @@ static long privcmd_ioctl(struct file *f
> ret = -EFAULT;
>
> mmapbatch_v2_out:
> - list_for_each_safe(l, l2, &pagelist)
> + i = 0;
> + list_for_each_safe(l, l2, &pagelist) {
> + if (!(++i & 7))
> + cond_resched();
> free_page((unsigned long)l);
> + }
> #undef MMAPBATCH_NR_PER_PAGE
> }
> break;
>
>
>
> privcmd: sprinkle around cond_resched() calls in mmap ioctl handling
>
> Many of these operations can be arbitrarily long, which can become a
> problem irrespective of them being exposed to privileged users only.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>
> --- sle11sp3.orig/drivers/xen/privcmd/privcmd.c 2012-12-12 12:05:51.000000000 +0100
> +++ sle11sp3/drivers/xen/privcmd/privcmd.c 2014-01-16 10:01:23.000000000 +0100
> @@ -126,6 +126,9 @@ static long privcmd_ioctl(struct file *f
>
> p = mmapcmd.entry;
> for (i = 0; i < mmapcmd.num;) {
> + if (i)
> + cond_resched();
> +
> nr = min(mmapcmd.num - i, MMAP_NR_PER_PAGE);
>
> ret = -ENOMEM;
> @@ -158,6 +161,9 @@ static long privcmd_ioctl(struct file *f
>
> i = 0;
> list_for_each(l, &pagelist) {
> + if (i)
> + cond_resched();
> +
> nr = i + min(mmapcmd.num - i, MMAP_NR_PER_PAGE);
>
> msg = (privcmd_mmap_entry_t*)(l + 1);
> @@ -186,6 +192,9 @@ static long privcmd_ioctl(struct file *f
> addr = vma->vm_start;
> i = 0;
> list_for_each(l, &pagelist) {
> + if (i)
> + cond_resched();
> +
> nr = i + min(mmapcmd.num - i, MMAP_NR_PER_PAGE);
>
> msg = (privcmd_mmap_entry_t*)(l + 1);
> @@ -209,8 +218,12 @@ static long privcmd_ioctl(struct file *f
>
> mmap_out:
> up_write(&mm->mmap_sem);
> - list_for_each_safe(l,l2,&pagelist)
> + i = 0;
> + list_for_each_safe(l, l2, &pagelist) {
> + if (!(++i & 7))
> + cond_resched();
> free_page((unsigned long)l);
> + }
> }
> #undef MMAP_NR_PER_PAGE
> break;
> @@ -236,6 +249,9 @@ static long privcmd_ioctl(struct file *f
>
> p = m.arr;
> for (i=0; i<nr_pages; ) {
> + if (i)
> + cond_resched();
> +
> nr = min(nr_pages - i, MMAPBATCH_NR_PER_PAGE);
>
> ret = -ENOMEM;
> @@ -270,6 +286,9 @@ static long privcmd_ioctl(struct file *f
> ret = 0;
> paged_out = 0;
> list_for_each(l, &pagelist) {
> + if (i)
> + cond_resched();
> +
> nr = i + min(nr_pages - i, MMAPBATCH_NR_PER_PAGE);
> mfn = (unsigned long *)(l + 1);
>
> @@ -302,6 +321,9 @@ static long privcmd_ioctl(struct file *f
> else
> ret = 0;
> list_for_each(l, &pagelist) {
> + if (i)
> + cond_resched();
> +
> nr = min(nr_pages - i, MMAPBATCH_NR_PER_PAGE);
> mfn = (unsigned long *)(l + 1);
> if (copy_to_user(p, mfn, nr*sizeof(*mfn)))
> @@ -310,8 +332,12 @@ static long privcmd_ioctl(struct file *f
> }
> }
> mmapbatch_out:
> - list_for_each_safe(l,l2,&pagelist)
> + i = 0;
> + list_for_each_safe(l, l2, &pagelist) {
> + if (!(++i & 7))
> + cond_resched();
> free_page((unsigned long)l);
> + }
> }
> break;
>
> @@ -335,6 +361,9 @@ static long privcmd_ioctl(struct file *f
>
> p = m.arr;
> for (i = 0; i < nr_pages; i += nr, p += nr) {
> + if (i)
> + cond_resched();
> +
> nr = min(nr_pages - i, MMAPBATCH_NR_PER_PAGE);
>
> ret = -ENOMEM;
> @@ -367,6 +396,9 @@ static long privcmd_ioctl(struct file *f
> ret = 0;
> paged_out = 0;
> list_for_each(l, &pagelist) {
> + if (i)
> + cond_resched();
> +
> nr = i + min(nr_pages - i, MMAPBATCH_NR_PER_PAGE);
> mfn = (void *)(l + 1);
> err = (void *)(l + 1);
> @@ -397,6 +429,9 @@ static long privcmd_ioctl(struct file *f
> ret = paged_out ? -ENOENT : 0;
> i = 0;
> list_for_each(l, &pagelist) {
> + if (i)
> + cond_resched();
> +
> nr = min(nr_pages - i, MMAPBATCH_NR_PER_PAGE);
> err = (void *)(l + 1);
> if (copy_to_user(p, err, nr * sizeof(*err)))
> @@ -407,8 +442,12 @@ static long privcmd_ioctl(struct file *f
> ret = -EFAULT;
>
> mmapbatch_v2_out:
> - list_for_each_safe(l, l2, &pagelist)
> + i = 0;
> + list_for_each_safe(l, l2, &pagelist) {
> + if (!(++i & 7))
> + cond_resched();
> free_page((unsigned long)l);
> + }
> #undef MMAPBATCH_NR_PER_PAGE
> }
> break;
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] linux-2.6.18/privcmd: sprinkle around cond_resched() calls in mmap ioctl handling
2014-01-28 15:39 ` Konrad Rzeszutek Wilk
@ 2014-01-28 15:43 ` Jan Beulich
0 siblings, 0 replies; 3+ messages in thread
From: Jan Beulich @ 2014-01-28 15:43 UTC (permalink / raw)
To: Konrad Rzeszutek Wilk; +Cc: xen-devel
>>> On 28.01.14 at 16:39, Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> wrote:
> On Tue, Jan 28, 2014 at 12:52:18PM +0000, Jan Beulich wrote:
>> Many of these operations can be arbitrarily long, which can become a
>> problem irrespective of them being exposed to privileged users only.
>
> You probably also want to sprinkle that in the balloon driver as well.
At least in that old code I don't think there is a need - the batches
that get processed already get limited by the size of the static
frame_list[] array.
> Any thoughts of upstreaming this as well?
Eventually, yes. But not something I have time for right now.
Jan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-01-28 15:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-28 12:52 [PATCH] linux-2.6.18/privcmd: sprinkle around cond_resched() calls in mmap ioctl handling Jan Beulich
2014-01-28 15:39 ` Konrad Rzeszutek Wilk
2014-01-28 15:43 ` Jan Beulich
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.