ia64/xen-unstable

changeset 11790:5b3ec078993b

[IA64] Add support for enforcing singleshot mmap() semantics at the
privcmd interface.
From: Isaku Yamahata <yamahata@valinux.co.jp>
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Thu Oct 12 13:55:03 2006 +0100 (2006-10-12)
parents d2e6a7be622d
children 5339785f8be8
files linux-2.6-xen-sparse/arch/ia64/xen/hypervisor.c linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c linux-2.6-xen-sparse/include/asm-ia64/hypervisor.h
line diff
     1.1 --- a/linux-2.6-xen-sparse/arch/ia64/xen/hypervisor.c	Thu Oct 12 11:44:53 2006 +0100
     1.2 +++ b/linux-2.6-xen-sparse/arch/ia64/xen/hypervisor.c	Thu Oct 12 13:55:03 2006 +0100
     1.3 @@ -546,6 +546,7 @@ struct xen_ia64_privcmd_range {
     1.4  };
     1.5  
     1.6  struct xen_ia64_privcmd_vma {
     1.7 +	int				is_privcmd_mmapped;
     1.8  	struct xen_ia64_privcmd_range*	range;
     1.9  
    1.10  	unsigned long			num_entries;
    1.11 @@ -684,12 +685,15 @@ static void
    1.12  static void
    1.13  xen_ia64_privcmd_vma_open(struct vm_area_struct* vma)
    1.14  {
    1.15 +	struct xen_ia64_privcmd_vma* old_privcmd_vma = (struct xen_ia64_privcmd_vma*)vma->vm_private_data;
    1.16  	struct xen_ia64_privcmd_vma* privcmd_vma = (struct xen_ia64_privcmd_vma*)vma->vm_private_data;
    1.17  	struct xen_ia64_privcmd_range* privcmd_range = privcmd_vma->range;
    1.18  
    1.19  	atomic_inc(&privcmd_range->ref_count);
    1.20  	// vm_op->open() can't fail.
    1.21  	privcmd_vma = kmalloc(sizeof(*privcmd_vma), GFP_KERNEL | __GFP_NOFAIL);
    1.22 +	// copy original value if necessary
    1.23 +	privcmd_vma->is_privcmd_mmapped = old_privcmd_vma->is_privcmd_mmapped;
    1.24  
    1.25  	__xen_ia64_privcmd_vma_open(vma, privcmd_vma, privcmd_range);
    1.26  }
    1.27 @@ -725,6 +729,14 @@ xen_ia64_privcmd_vma_close(struct vm_are
    1.28  }
    1.29  
    1.30  int
    1.31 +privcmd_enforce_singleshot_mapping(struct vm_area_struct *vma)
    1.32 +{
    1.33 +	struct xen_ia64_privcmd_vma* privcmd_vma =
    1.34 +		(struct xen_ia64_privcmd_vma *)vma->vm_private_data;
    1.35 +	return (xchg(&privcmd_vma->is_privcmd_mmapped, 1) == 0);
    1.36 +}
    1.37 +
    1.38 +int
    1.39  privcmd_mmap(struct file * file, struct vm_area_struct * vma)
    1.40  {
    1.41  	int error;
    1.42 @@ -749,6 +761,8 @@ privcmd_mmap(struct file * file, struct 
    1.43  	if (privcmd_vma == NULL) {
    1.44  		goto out_enomem1;
    1.45  	}
    1.46 +	privcmd_vma->is_privcmd_mmapped = 0;
    1.47 +
    1.48  	res = kzalloc(sizeof(*res), GFP_KERNEL);
    1.49  	if (res == NULL) {
    1.50  		goto out_enomem1;
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c	Thu Oct 12 11:44:53 2006 +0100
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c	Thu Oct 12 13:55:03 2006 +0100
     2.3 @@ -35,14 +35,9 @@
     2.4  static struct proc_dir_entry *privcmd_intf;
     2.5  static struct proc_dir_entry *capabilities_intf;
     2.6  
     2.7 -static int privcmd_enforce_singleshot_mapping(struct vm_area_struct *vma)
     2.8 -{
     2.9  #ifndef HAVE_ARCH_PRIVCMD_MMAP
    2.10 -	if (xchg(&vma->vm_private_data, (void *)1) != NULL)
    2.11 -		return 0;
    2.12 +static int privcmd_enforce_singleshot_mapping(struct vm_area_struct *vma);
    2.13  #endif
    2.14 -	return 1;
    2.15 -}
    2.16  
    2.17  static int privcmd_ioctl(struct inode *inode, struct file *file,
    2.18  			 unsigned int cmd, unsigned long data)
    2.19 @@ -255,6 +250,11 @@ static int privcmd_mmap(struct file * fi
    2.20  
    2.21  	return 0;
    2.22  }
    2.23 +
    2.24 +static int privcmd_enforce_singleshot_mapping(struct vm_area_struct *vma)
    2.25 +{
    2.26 +	return (xchg(&vma->vm_private_data, (void *)1) == NULL);
    2.27 +}
    2.28  #endif
    2.29  
    2.30  static struct file_operations privcmd_file_ops = {
     3.1 --- a/linux-2.6-xen-sparse/include/asm-ia64/hypervisor.h	Thu Oct 12 11:44:53 2006 +0100
     3.2 +++ b/linux-2.6-xen-sparse/include/asm-ia64/hypervisor.h	Thu Oct 12 13:55:03 2006 +0100
     3.3 @@ -138,6 +138,7 @@ int direct_remap_pfn_range(struct vm_are
     3.4  			   pgprot_t prot,
     3.5  			   domid_t  domid);
     3.6  struct file;
     3.7 +int privcmd_enforce_singleshot_mapping(struct vm_area_struct *vma);
     3.8  int privcmd_mmap(struct file * file, struct vm_area_struct * vma);
     3.9  #define HAVE_ARCH_PRIVCMD_MMAP
    3.10