All of lore.kernel.org
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: xen-devel <xen-devel@lists.xenproject.org>
Subject: Re: [PATCH] linux-2.6.18/privcmd: sprinkle around cond_resched() calls in mmap ioctl handling
Date: Tue, 28 Jan 2014 10:39:02 -0500	[thread overview]
Message-ID: <20140128153902.GD4308@phenom.dumpdata.com> (raw)
In-Reply-To: <52E7B61202000078001178E3@nat28.tlf.novell.com>

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

  reply	other threads:[~2014-01-28 15:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2014-01-28 15:43   ` Jan Beulich

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=20140128153902.GD4308@phenom.dumpdata.com \
    --to=konrad.wilk@oracle.com \
    --cc=JBeulich@suse.com \
    --cc=xen-devel@lists.xenproject.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.