diff mbox series

[2/5] x86/sgx: use VM_ACCESS_FLAGS

Message ID 20221019034945.93081-3-wangkefeng.wang@huawei.com (mailing list archive)
State New, archived
Headers show
Series mm: cleanup with VM_ACCESS_FLAGS | expand

Commit Message

Kefeng Wang Oct. 19, 2022, 3:49 a.m. UTC
Simplify VM_READ|VM_WRITE|VM_EXEC with VM_ACCESS_FLAGS.

Cc: Jarkko Sakkinen <jarkko@kernel.org>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 arch/x86/kernel/cpu/sgx/encl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Jarkko Sakkinen Oct. 23, 2022, 8:07 p.m. UTC | #1
On Wed, Oct 19, 2022 at 11:49:42AM +0800, Kefeng Wang wrote:
> Simplify VM_READ|VM_WRITE|VM_EXEC with VM_ACCESS_FLAGS.
> 
> Cc: Jarkko Sakkinen <jarkko@kernel.org>
> Cc: Dave Hansen <dave.hansen@linux.intel.com>
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> ---
>  arch/x86/kernel/cpu/sgx/encl.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c
> index 1ec20807de1e..6225c525372d 100644
> --- a/arch/x86/kernel/cpu/sgx/encl.c
> +++ b/arch/x86/kernel/cpu/sgx/encl.c
> @@ -268,7 +268,7 @@ static struct sgx_encl_page *sgx_encl_load_page_in_vma(struct sgx_encl *encl,
>  						       unsigned long addr,
>  						       unsigned long vm_flags)
>  {
> -	unsigned long vm_prot_bits = vm_flags & (VM_READ | VM_WRITE | VM_EXEC);
> +	unsigned long vm_prot_bits = vm_flags & VM_ACCESS_FLAGS;
>  	struct sgx_encl_page *entry;
>  
>  	entry = xa_load(&encl->page_array, PFN_DOWN(addr));
> @@ -502,7 +502,7 @@ static void sgx_vma_open(struct vm_area_struct *vma)
>  int sgx_encl_may_map(struct sgx_encl *encl, unsigned long start,
>  		     unsigned long end, unsigned long vm_flags)
>  {
> -	unsigned long vm_prot_bits = vm_flags & (VM_READ | VM_WRITE | VM_EXEC);
> +	unsigned long vm_prot_bits = vm_flags & VM_ACCESS_FLAGS;
>  	struct sgx_encl_page *page;
>  	unsigned long count = 0;
>  	int ret = 0;
> -- 
> 2.35.3
> 

Why?

BR, Jarkko
Jarkko Sakkinen Oct. 23, 2022, 8:09 p.m. UTC | #2
On Sun, Oct 23, 2022 at 11:07:47PM +0300, Jarkko Sakkinen wrote:
> On Wed, Oct 19, 2022 at 11:49:42AM +0800, Kefeng Wang wrote:
> > Simplify VM_READ|VM_WRITE|VM_EXEC with VM_ACCESS_FLAGS.
> > 
> > Cc: Jarkko Sakkinen <jarkko@kernel.org>
> > Cc: Dave Hansen <dave.hansen@linux.intel.com>
> > Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> > ---
> >  arch/x86/kernel/cpu/sgx/encl.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c
> > index 1ec20807de1e..6225c525372d 100644
> > --- a/arch/x86/kernel/cpu/sgx/encl.c
> > +++ b/arch/x86/kernel/cpu/sgx/encl.c
> > @@ -268,7 +268,7 @@ static struct sgx_encl_page *sgx_encl_load_page_in_vma(struct sgx_encl *encl,
> >  						       unsigned long addr,
> >  						       unsigned long vm_flags)
> >  {
> > -	unsigned long vm_prot_bits = vm_flags & (VM_READ | VM_WRITE | VM_EXEC);
> > +	unsigned long vm_prot_bits = vm_flags & VM_ACCESS_FLAGS;
> >  	struct sgx_encl_page *entry;
> >  
> >  	entry = xa_load(&encl->page_array, PFN_DOWN(addr));
> > @@ -502,7 +502,7 @@ static void sgx_vma_open(struct vm_area_struct *vma)
> >  int sgx_encl_may_map(struct sgx_encl *encl, unsigned long start,
> >  		     unsigned long end, unsigned long vm_flags)
> >  {
> > -	unsigned long vm_prot_bits = vm_flags & (VM_READ | VM_WRITE | VM_EXEC);
> > +	unsigned long vm_prot_bits = vm_flags & VM_ACCESS_FLAGS;
> >  	struct sgx_encl_page *page;
> >  	unsigned long count = 0;
> >  	int ret = 0;
> > -- 
> > 2.35.3
> > 
> 
> Why?

Only benefit I see is a downside: you have xref VM_ACCESS_FLAGS, which
is counter-productive. Zero gain.

BR, Jarkko
diff mbox series

Patch

diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c
index 1ec20807de1e..6225c525372d 100644
--- a/arch/x86/kernel/cpu/sgx/encl.c
+++ b/arch/x86/kernel/cpu/sgx/encl.c
@@ -268,7 +268,7 @@  static struct sgx_encl_page *sgx_encl_load_page_in_vma(struct sgx_encl *encl,
 						       unsigned long addr,
 						       unsigned long vm_flags)
 {
-	unsigned long vm_prot_bits = vm_flags & (VM_READ | VM_WRITE | VM_EXEC);
+	unsigned long vm_prot_bits = vm_flags & VM_ACCESS_FLAGS;
 	struct sgx_encl_page *entry;
 
 	entry = xa_load(&encl->page_array, PFN_DOWN(addr));
@@ -502,7 +502,7 @@  static void sgx_vma_open(struct vm_area_struct *vma)
 int sgx_encl_may_map(struct sgx_encl *encl, unsigned long start,
 		     unsigned long end, unsigned long vm_flags)
 {
-	unsigned long vm_prot_bits = vm_flags & (VM_READ | VM_WRITE | VM_EXEC);
+	unsigned long vm_prot_bits = vm_flags & VM_ACCESS_FLAGS;
 	struct sgx_encl_page *page;
 	unsigned long count = 0;
 	int ret = 0;