[intel-sgx-kernel-dev,FIX,3/3] fixup - intel_sgx: backing storage file for PCMD
diff mbox

Message ID 1484949673-8605-4-git-send-email-sean.j.christopherson@intel.com
State New
Headers show

Commit Message

Sean Christopherson Jan. 20, 2017, 10:01 p.m. UTC
Combine sgx_get/put_backing/pcmd functionality into common utility
functions, wrapped by inline helpers for backing and pcmd.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 drivers/platform/x86/intel_sgx.h      | 31 +++++++++++++++++++-----
 drivers/platform/x86/intel_sgx_util.c | 45 +++++------------------------------
 2 files changed, 31 insertions(+), 45 deletions(-)

Comments

Jarkko Sakkinen Jan. 21, 2017, 8:22 p.m. UTC | #1
On Fri, Jan 20, 2017 at 02:01:13PM -0800, Sean Christopherson wrote:
> Combine sgx_get/put_backing/pcmd functionality into common utility
> functions, wrapped by inline helpers for backing and pcmd.
> 
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>

I will rather pick the naming myself.

/Jarkko

> ---
>  drivers/platform/x86/intel_sgx.h      | 31 +++++++++++++++++++-----
>  drivers/platform/x86/intel_sgx_util.c | 45 +++++------------------------------
>  2 files changed, 31 insertions(+), 45 deletions(-)
> 
> diff --git a/drivers/platform/x86/intel_sgx.h b/drivers/platform/x86/intel_sgx.h
> index 1d03606..22bf3be 100644
> --- a/drivers/platform/x86/intel_sgx.h
> +++ b/drivers/platform/x86/intel_sgx.h
> @@ -195,12 +195,8 @@ long sgx_compat_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
>  int sgx_test_and_clear_young(struct sgx_encl_page *page, struct sgx_encl *encl);
>  void *sgx_get_epc_page(struct sgx_epc_page *entry);
>  void sgx_put_epc_page(void *epc_page_vaddr);
> -struct page *sgx_get_backing(struct sgx_encl *encl,
> -			     struct sgx_encl_page *entry);
> -void sgx_put_backing(struct page *backing, bool write);
> -struct page *sgx_get_pcmd(struct sgx_encl *encl,
> -			  struct sgx_encl_page *entry);
> -void sgx_put_pcmd(struct page *pcmd_page, bool write);
> +struct page *sgx_get_shmem(struct file *shmem_file, pgoff_t index);
> +void sgx_put_shmem(struct page *shmem_page, bool write);
>  void sgx_insert_pte(struct sgx_encl *encl,
>  		    struct sgx_encl_page *encl_page,
>  		    struct sgx_epc_page *epc_page,
> @@ -217,6 +213,29 @@ int sgx_find_encl(struct mm_struct *mm, unsigned long addr,
>  void sgx_encl_release(struct kref *ref);
>  void sgx_tgid_ctx_release(struct kref *ref);
>  
> +static inline struct page *sgx_get_backing(struct sgx_encl *encl,
> +					   struct sgx_encl_page *entry)
> +{
> +	pgoff_t index = (entry->addr - encl->base) >> PAGE_SHIFT;
> +	return sgx_get_shmem(encl->backing, index);
> +}
> +static inline void sgx_put_backing(struct page *backing, bool write)
> +{
> +	return sgx_put_shmem(backing, write);
> +}
> +static inline struct page *sgx_get_pcmd(struct sgx_encl *encl,
> +					struct sgx_encl_page *entry)
> +{
> +	/* 32 PCMD's per page */
> +	pgoff_t index = (entry->addr - encl->base) >> (PAGE_SHIFT + 5);
> +	return sgx_get_shmem(encl->pcmd, index);
> +}
> +static inline void sgx_put_pcmd(struct page *pcmd, bool write)
> +{
> +	return sgx_put_shmem(pcmd, write);
> +}
> +
> +
>  /* EPC page cache */
>  
>  #define SGX_NR_LOW_EPC_PAGES_DEFAULT	32
> diff --git a/drivers/platform/x86/intel_sgx_util.c b/drivers/platform/x86/intel_sgx_util.c
> index 40f5839..c7bf5e1 100644
> --- a/drivers/platform/x86/intel_sgx_util.c
> +++ b/drivers/platform/x86/intel_sgx_util.c
> @@ -78,58 +78,25 @@ void sgx_put_epc_page(void *epc_page_vaddr)
>  #endif
>  }
>  
> -struct page *sgx_get_backing(struct sgx_encl *encl,
> -			     struct sgx_encl_page *entry)
> +struct page *sgx_get_shmem(struct file *shmem_file, pgoff_t index)
>  {
> -	struct page *backing;
>  	struct inode *inode;
>  	struct address_space *mapping;
>  	gfp_t gfpmask;
> -	pgoff_t index;
>  
> -	inode = encl->backing->f_path.dentry->d_inode;
> +	inode = shmem_file->f_path.dentry->d_inode;
>  	mapping = inode->i_mapping;
>  	gfpmask = mapping_gfp_mask(mapping);
>  
> -	index = (entry->addr - encl->base) >> PAGE_SHIFT;
> -	backing = shmem_read_mapping_page_gfp(mapping, index, gfpmask);
> -
> -	return backing;
> -}
> -
> -void sgx_put_backing(struct page *backing_page, bool write)
> -{
> -	if (write)
> -		set_page_dirty(backing_page);
> -
> -	put_page(backing_page);
> -}
> -
> -struct page *sgx_get_pcmd(struct sgx_encl *encl,
> -			  struct sgx_encl_page *entry)
> -{
> -	struct page *pcmd;
> -	struct inode *inode;
> -	struct address_space *mapping;
> -	gfp_t gfpmask;
> -	pgoff_t index;
> -
> -	inode = encl->pcmd->f_path.dentry->d_inode;
> -	mapping = inode->i_mapping;
> -	gfpmask = mapping_gfp_mask(mapping);
> -	/* 32 PCMD's per page */
> -	index = (entry->addr - encl->base) >> (PAGE_SHIFT + 5);
> -	pcmd = shmem_read_mapping_page_gfp(mapping, index, gfpmask);
> -
> -	return pcmd;
> +	return shmem_read_mapping_page_gfp(mapping, index, gfpmask);
>  }
>  
> -void sgx_put_pcmd(struct page *pcmd_page, bool write)
> +void sgx_put_shmem(struct page *shmem_page, bool write)
>  {
>  	if (write)
> -		set_page_dirty(pcmd_page);
> +		set_page_dirty(shmem_page);
>  
> -	put_page(pcmd_page);
> +	put_page(shmem_page);
>  }
>  
>  struct vm_area_struct *sgx_find_vma(struct sgx_encl *encl, unsigned long addr)
> -- 
> 2.7.4
> 
> _______________________________________________
> intel-sgx-kernel-dev mailing list
> intel-sgx-kernel-dev@lists.01.org
> https://lists.01.org/mailman/listinfo/intel-sgx-kernel-dev
Jarkko Sakkinen Jan. 21, 2017, 9:21 p.m. UTC | #2
On Sat, Jan 21, 2017 at 10:22:26PM +0200, Jarkko Sakkinen wrote:
> On Fri, Jan 20, 2017 at 02:01:13PM -0800, Sean Christopherson wrote:
> > Combine sgx_get/put_backing/pcmd functionality into common utility
> > functions, wrapped by inline helpers for backing and pcmd.
> > 
> > Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> 
> I will rather pick the naming myself.
> 
> /Jarkko
> 
> > ---
> >  drivers/platform/x86/intel_sgx.h      | 31 +++++++++++++++++++-----
> >  drivers/platform/x86/intel_sgx_util.c | 45 +++++------------------------------
> >  2 files changed, 31 insertions(+), 45 deletions(-)
> > 
> > diff --git a/drivers/platform/x86/intel_sgx.h b/drivers/platform/x86/intel_sgx.h
> > index 1d03606..22bf3be 100644
> > --- a/drivers/platform/x86/intel_sgx.h
> > +++ b/drivers/platform/x86/intel_sgx.h
> > @@ -195,12 +195,8 @@ long sgx_compat_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
> >  int sgx_test_and_clear_young(struct sgx_encl_page *page, struct sgx_encl *encl);
> >  void *sgx_get_epc_page(struct sgx_epc_page *entry);
> >  void sgx_put_epc_page(void *epc_page_vaddr);
> > -struct page *sgx_get_backing(struct sgx_encl *encl,
> > -			     struct sgx_encl_page *entry);
> > -void sgx_put_backing(struct page *backing, bool write);
> > -struct page *sgx_get_pcmd(struct sgx_encl *encl,
> > -			  struct sgx_encl_page *entry);
> > -void sgx_put_pcmd(struct page *pcmd_page, bool write);
> > +struct page *sgx_get_shmem(struct file *shmem_file, pgoff_t index);
> > +void sgx_put_shmem(struct page *shmem_page, bool write);
> >  void sgx_insert_pte(struct sgx_encl *encl,
> >  		    struct sgx_encl_page *encl_page,
> >  		    struct sgx_epc_page *epc_page,
> > @@ -217,6 +213,29 @@ int sgx_find_encl(struct mm_struct *mm, unsigned long addr,
> >  void sgx_encl_release(struct kref *ref);
> >  void sgx_tgid_ctx_release(struct kref *ref);
> >  
> > +static inline struct page *sgx_get_backing(struct sgx_encl *encl,
> > +					   struct sgx_encl_page *entry)
> > +{
> > +	pgoff_t index = (entry->addr - encl->base) >> PAGE_SHIFT;
> > +	return sgx_get_shmem(encl->backing, index);
> > +}
> > +static inline void sgx_put_backing(struct page *backing, bool write)
> > +{
> > +	return sgx_put_shmem(backing, write);
> > +}
> > +static inline struct page *sgx_get_pcmd(struct sgx_encl *encl,
> > +					struct sgx_encl_page *entry)
> > +{
> > +	/* 32 PCMD's per page */
> > +	pgoff_t index = (entry->addr - encl->base) >> (PAGE_SHIFT + 5);
> > +	return sgx_get_shmem(encl->pcmd, index);
> > +}
> > +static inline void sgx_put_pcmd(struct page *pcmd, bool write)
> > +{
> > +	return sgx_put_shmem(pcmd, write);
> > +}
> > +
> > +

 will rather have something like

enum sgx_backing_flags {
	SGX_BACKING_PCMD	= BIT(0),
	SGX_BACKING_WRITE	= BIT(1),
};

struct page *sgx_get_backing(struct sgx_encl *encl,
			     struct sgx_encl_page *entry,
			     unsigned int flags);
void sgx_put_backing(struct page *backing_page,
		     unsigned int flags);

This decreases the number of functions to one where as the above
increases it to three.

/Jarkko

Patch
diff mbox

diff --git a/drivers/platform/x86/intel_sgx.h b/drivers/platform/x86/intel_sgx.h
index 1d03606..22bf3be 100644
--- a/drivers/platform/x86/intel_sgx.h
+++ b/drivers/platform/x86/intel_sgx.h
@@ -195,12 +195,8 @@  long sgx_compat_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
 int sgx_test_and_clear_young(struct sgx_encl_page *page, struct sgx_encl *encl);
 void *sgx_get_epc_page(struct sgx_epc_page *entry);
 void sgx_put_epc_page(void *epc_page_vaddr);
-struct page *sgx_get_backing(struct sgx_encl *encl,
-			     struct sgx_encl_page *entry);
-void sgx_put_backing(struct page *backing, bool write);
-struct page *sgx_get_pcmd(struct sgx_encl *encl,
-			  struct sgx_encl_page *entry);
-void sgx_put_pcmd(struct page *pcmd_page, bool write);
+struct page *sgx_get_shmem(struct file *shmem_file, pgoff_t index);
+void sgx_put_shmem(struct page *shmem_page, bool write);
 void sgx_insert_pte(struct sgx_encl *encl,
 		    struct sgx_encl_page *encl_page,
 		    struct sgx_epc_page *epc_page,
@@ -217,6 +213,29 @@  int sgx_find_encl(struct mm_struct *mm, unsigned long addr,
 void sgx_encl_release(struct kref *ref);
 void sgx_tgid_ctx_release(struct kref *ref);
 
+static inline struct page *sgx_get_backing(struct sgx_encl *encl,
+					   struct sgx_encl_page *entry)
+{
+	pgoff_t index = (entry->addr - encl->base) >> PAGE_SHIFT;
+	return sgx_get_shmem(encl->backing, index);
+}
+static inline void sgx_put_backing(struct page *backing, bool write)
+{
+	return sgx_put_shmem(backing, write);
+}
+static inline struct page *sgx_get_pcmd(struct sgx_encl *encl,
+					struct sgx_encl_page *entry)
+{
+	/* 32 PCMD's per page */
+	pgoff_t index = (entry->addr - encl->base) >> (PAGE_SHIFT + 5);
+	return sgx_get_shmem(encl->pcmd, index);
+}
+static inline void sgx_put_pcmd(struct page *pcmd, bool write)
+{
+	return sgx_put_shmem(pcmd, write);
+}
+
+
 /* EPC page cache */
 
 #define SGX_NR_LOW_EPC_PAGES_DEFAULT	32
diff --git a/drivers/platform/x86/intel_sgx_util.c b/drivers/platform/x86/intel_sgx_util.c
index 40f5839..c7bf5e1 100644
--- a/drivers/platform/x86/intel_sgx_util.c
+++ b/drivers/platform/x86/intel_sgx_util.c
@@ -78,58 +78,25 @@  void sgx_put_epc_page(void *epc_page_vaddr)
 #endif
 }
 
-struct page *sgx_get_backing(struct sgx_encl *encl,
-			     struct sgx_encl_page *entry)
+struct page *sgx_get_shmem(struct file *shmem_file, pgoff_t index)
 {
-	struct page *backing;
 	struct inode *inode;
 	struct address_space *mapping;
 	gfp_t gfpmask;
-	pgoff_t index;
 
-	inode = encl->backing->f_path.dentry->d_inode;
+	inode = shmem_file->f_path.dentry->d_inode;
 	mapping = inode->i_mapping;
 	gfpmask = mapping_gfp_mask(mapping);
 
-	index = (entry->addr - encl->base) >> PAGE_SHIFT;
-	backing = shmem_read_mapping_page_gfp(mapping, index, gfpmask);
-
-	return backing;
-}
-
-void sgx_put_backing(struct page *backing_page, bool write)
-{
-	if (write)
-		set_page_dirty(backing_page);
-
-	put_page(backing_page);
-}
-
-struct page *sgx_get_pcmd(struct sgx_encl *encl,
-			  struct sgx_encl_page *entry)
-{
-	struct page *pcmd;
-	struct inode *inode;
-	struct address_space *mapping;
-	gfp_t gfpmask;
-	pgoff_t index;
-
-	inode = encl->pcmd->f_path.dentry->d_inode;
-	mapping = inode->i_mapping;
-	gfpmask = mapping_gfp_mask(mapping);
-	/* 32 PCMD's per page */
-	index = (entry->addr - encl->base) >> (PAGE_SHIFT + 5);
-	pcmd = shmem_read_mapping_page_gfp(mapping, index, gfpmask);
-
-	return pcmd;
+	return shmem_read_mapping_page_gfp(mapping, index, gfpmask);
 }
 
-void sgx_put_pcmd(struct page *pcmd_page, bool write)
+void sgx_put_shmem(struct page *shmem_page, bool write)
 {
 	if (write)
-		set_page_dirty(pcmd_page);
+		set_page_dirty(shmem_page);
 
-	put_page(pcmd_page);
+	put_page(shmem_page);
 }
 
 struct vm_area_struct *sgx_find_vma(struct sgx_encl *encl, unsigned long addr)