All of lore.kernel.org
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Cc: jeremy@goop.org, xen-devel@lists.xensource.com, Ian.Campbell@citrix.com
Subject: Re: [PATCH 1/6 v2] xen-gntdev: Change page limit to be global instead of per-open
Date: Fri, 21 Jan 2011 10:04:11 -0500	[thread overview]
Message-ID: <20110121150411.GB4567@dumpdata.com> (raw)
In-Reply-To: <4D35D47F.2050609@tycho.nsa.gov>

On Tue, Jan 18, 2011 at 12:57:19PM -0500, Daniel De Graaf wrote:
> Because there is no limitation on how many times a user can open a
> given device file, an per-file-description limit on the number of
> pages granted offers little to no benefit. Change to a global limit
> and remove the ioctl() as the parameter can now be changed via sysfs.
> 
> Xen tools changeset 22768:f8d801e5573e is needed to eliminate the
> error this change produces in xc_gnttab_set_max_grants.

Can you also run this through the checkpath.pl tool and fix up the
failures, please?

> 
> Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
> ---
>  drivers/xen/gntdev.c |   52 +++++++++++++++----------------------------------
>  1 files changed, 16 insertions(+), 36 deletions(-)
> 
> diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c
> index 1e31cdc..59e6a51 100644
> --- a/drivers/xen/gntdev.c
> +++ b/drivers/xen/gntdev.c
> @@ -45,15 +45,15 @@ MODULE_AUTHOR("Derek G. Murray <Derek.Murray@cl.cam.ac.uk>, "
>  	      "Gerd Hoffmann <kraxel@redhat.com>");
>  MODULE_DESCRIPTION("User-space granted page access driver");
>  
> -static int limit = 1024;
> +static int limit = 1024*1024;
>  module_param(limit, int, 0644);
> -MODULE_PARM_DESC(limit, "Maximum number of grants that may be mapped at "
> -		"once by a gntdev instance");
> +MODULE_PARM_DESC(limit, "Maximum number of grants that may be mapped by "
> +		"the gntdev device");
> +
> +static atomic_t pages_mapped = ATOMIC_INIT(0);
>  
>  struct gntdev_priv {
>  	struct list_head maps;
> -	uint32_t used;
> -	uint32_t limit;
>  	/* lock protects maps from concurrent changes */
>  	spinlock_t lock;
>  	struct mm_struct *mm;
> @@ -82,9 +82,8 @@ static void gntdev_print_maps(struct gntdev_priv *priv,
>  #ifdef DEBUG
>  	struct grant_map *map;
>  
> -	pr_debug("maps list (priv %p, usage %d/%d)\n",
> -	       priv, priv->used, priv->limit);
> -
> +	pr_debug("%s: maps list (priv %p)\n",
> +	       __FUNCTION__, priv);
>  	list_for_each_entry(map, &priv->maps, next)
>  		pr_debug("  index %2d, count %2d %s\n",
>  		       map->index, map->count,
> @@ -121,9 +120,6 @@ static struct grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count)
>  	add->count = count;
>  	add->priv  = priv;
>  
> -	if (add->count + priv->used > priv->limit)
> -		goto err;
> -
>  	return add;
>  
>  err:
> @@ -154,7 +150,6 @@ static void gntdev_add_map(struct gntdev_priv *priv, struct grant_map *add)
>  	list_add_tail(&add->next, &priv->maps);
>  
>  done:
> -	priv->used += add->count;
>  	gntdev_print_maps(priv, "[new]", add->index);
>  }
>  
> @@ -200,7 +195,7 @@ static int gntdev_del_map(struct grant_map *map)
>  		if (map->unmap_ops[i].handle)
>  			return -EBUSY;
>  
> -	map->priv->used -= map->count;
> +	atomic_sub(map->count, &pages_mapped);
>  	list_del(&map->next);
>  	return 0;
>  }
> @@ -386,7 +381,6 @@ static int gntdev_open(struct inode *inode, struct file *flip)
>  
>  	INIT_LIST_HEAD(&priv->maps);
>  	spin_lock_init(&priv->lock);
> -	priv->limit = limit;
>  
>  	priv->mm = get_task_mm(current);
>  	if (!priv->mm) {
> @@ -443,19 +437,25 @@ static long gntdev_ioctl_map_grant_ref(struct gntdev_priv *priv,
>  	pr_debug("priv %p, add %d\n", priv, op.count);
>  	if (unlikely(op.count <= 0))
>  		return -EINVAL;
> -	if (unlikely(op.count > priv->limit))
> -		return -EINVAL;
>  
>  	err = -ENOMEM;
>  	map = gntdev_alloc_map(priv, op.count);
>  	if (!map)
>  		return err;
> +
>  	if (copy_from_user(map->grants, &u->refs,
>  			   sizeof(map->grants[0]) * op.count) != 0) {
>  		gntdev_free_map(map);
>  		return err;
>  	}
>  
> +	if (unlikely(atomic_add_return(op.count, &pages_mapped) > limit))
> +	{
> +		pr_debug("%s: can't map: over limit\n", __FUNCTION__);
> +		gntdev_free_map(map);
> +		return err;
> +	}
> +
>  	spin_lock(&priv->lock);
>  	gntdev_add_map(priv, map);
>  	op.index = map->index << PAGE_SHIFT;
> @@ -518,23 +518,6 @@ static long gntdev_ioctl_get_offset_for_vaddr(struct gntdev_priv *priv,
>  	return 0;
>  }
>  
> -static long gntdev_ioctl_set_max_grants(struct gntdev_priv *priv,
> -					struct ioctl_gntdev_set_max_grants __user *u)
> -{
> -	struct ioctl_gntdev_set_max_grants op;
> -
> -	if (copy_from_user(&op, u, sizeof(op)) != 0)
> -		return -EFAULT;
> -	pr_debug("priv %p, limit %d\n", priv, op.count);
> -	if (op.count > limit)
> -		return -E2BIG;
> -
> -	spin_lock(&priv->lock);
> -	priv->limit = op.count;
> -	spin_unlock(&priv->lock);
> -	return 0;
> -}
> -
>  static long gntdev_ioctl(struct file *flip,
>  			 unsigned int cmd, unsigned long arg)
>  {
> @@ -551,9 +534,6 @@ static long gntdev_ioctl(struct file *flip,
>  	case IOCTL_GNTDEV_GET_OFFSET_FOR_VADDR:
>  		return gntdev_ioctl_get_offset_for_vaddr(priv, ptr);
>  
> -	case IOCTL_GNTDEV_SET_MAX_GRANTS:
> -		return gntdev_ioctl_set_max_grants(priv, ptr);
> -
>  	default:
>  		pr_debug("priv %p, unknown cmd %x\n", priv, cmd);
>  		return -ENOIOCTLCMD;

  reply	other threads:[~2011-01-21 15:04 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-14 15:46 [PATCH v4] Userspace grant communication Daniel De Graaf
2011-01-14 15:46 ` [PATCH 1/6] xen-gntdev: Change page limit to be global instead of per-open Daniel De Graaf
2011-01-14 16:20   ` Konrad Rzeszutek Wilk
2011-01-14 21:09     ` Daniel De Graaf
2011-01-14 22:19       ` Konrad Rzeszutek Wilk
2011-01-18 17:57         ` [PATCH 1/6 v2] " Daniel De Graaf
2011-01-21 15:04           ` Konrad Rzeszutek Wilk [this message]
2011-01-14 15:46 ` [PATCH 2/6] xen-gntdev: Remove unneeded structures from grant_map tracking data Daniel De Graaf
2011-01-19 20:11   ` Jeremy Fitzhardinge
2011-01-14 15:46 ` [PATCH 3/6] xen-gntdev: Use find_vma rather than iterating our vma list manually Daniel De Graaf
2011-01-14 15:46 ` [PATCH 4/6] xen-gntdev: Add reference counting to maps Daniel De Graaf
2011-01-20 21:07   ` Konrad Rzeszutek Wilk
2011-01-14 15:46 ` [PATCH 5/6] xen-gntdev: Support mapping in HVM domains Daniel De Graaf
2011-01-17 14:28   ` Stefano Stabellini
2011-01-18 16:09     ` Daniel De Graaf
2011-01-18 17:27       ` Stefano Stabellini
2011-01-14 15:46 ` [PATCH 6/6] xen-gntalloc: Userspace grant allocation driver Daniel De Graaf
2011-01-21 15:02   ` [SPAM] " Konrad Rzeszutek Wilk
2011-01-21 14:36 ` [PATCH v4.2 3/5] xen-gntdev: Add reference counting to maps Daniel De Graaf
2011-01-21 14:38 ` [PATCH v4.2 4/5] xen-gntdev: Support mapping in HVM domains Daniel De Graaf

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=20110121150411.GB4567@dumpdata.com \
    --to=konrad.wilk@oracle.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=dgdegra@tycho.nsa.gov \
    --cc=jeremy@goop.org \
    --cc=xen-devel@lists.xensource.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.