diff mbox series

x86/sgx: handle VA page allocation failure for EAUG on PF.

Message ID 20220812191224.15561-1-haitao.huang@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series x86/sgx: handle VA page allocation failure for EAUG on PF. | expand

Commit Message

Haitao Huang Aug. 12, 2022, 7:12 p.m. UTC
Return VM_FAULT_NOPAGE to allow the swapping thread to catch up.

link: https://lore.kernel.org/all/20220804201456.33418-1-vijay.dhanraj@intel.com/

Signed-off-by: Haitao Huang <haitao.huang@linux.intel.com>
---
 arch/x86/kernel/cpu/sgx/encl.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Dhanraj, Vijay Aug. 12, 2022, 10:41 p.m. UTC | #1
Hi Haitao,

> -----Original Message-----
> From: Haitao Huang <haitao.huang@linux.intel.com>
> Sent: Friday, August 12, 2022 12:12 PM
> To: linux-sgx@vger.kernel.org; jarkko@kernel.org; Chatre, Reinette
> <reinette.chatre@intel.com>; dave.hansen@linux.intel.com; Dhanraj, Vijay
> <vijay.dhanraj@intel.com>
> Subject: [PATCH] x86/sgx: handle VA page allocation failure for EAUG on PF.
> 
> Return VM_FAULT_NOPAGE to allow the swapping thread to catch up.
> 
> link: https://lore.kernel.org/all/20220804201456.33418-1-
> vijay.dhanraj@intel.com/
> 
> Signed-off-by: Haitao Huang <haitao.huang@linux.intel.com>
> ---
>  arch/x86/kernel/cpu/sgx/encl.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c
> index 24c1bb8eb196..1f88f80c4477 100644
> --- a/arch/x86/kernel/cpu/sgx/encl.c
> +++ b/arch/x86/kernel/cpu/sgx/encl.c
> @@ -344,8 +344,11 @@ static vm_fault_t sgx_encl_eaug_page(struct
> vm_area_struct *vma,
>  	}
> 
>  	va_page = sgx_encl_grow(encl, false);
> -	if (IS_ERR(va_page))
> -		goto err_out_epc;
> +	if (IS_ERR(va_page)) {
> +        if (PTR_ERR(va_page) == -EBUSY)
> +            vmret =  VM_FAULT_NOPAGE;
> +        goto err_out_epc;
> +    }
> 
>  	if (va_page)
>  		list_add(&va_page->list, &encl->va_pages);
> --
> 2.25.1

After applying this patch, I don't see the allocation failure issue with `augment_via_eaccept_long` test case. Ran the test for about ~60 times and all the time it passes.
Tested-by: Vijay Dhanraj <vijay.dhanraj@intel.com>
Jarkko Sakkinen Aug. 14, 2022, 7:36 p.m. UTC | #2
On Fri, Aug 12, 2022 at 12:12:24PM -0700, Haitao Huang wrote:
> Return VM_FAULT_NOPAGE to allow the swapping thread to catch up.
> 
> link: https://lore.kernel.org/all/20220804201456.33418-1-vijay.dhanraj@intel.com/
> 
> Signed-off-by: Haitao Huang <haitao.huang@linux.intel.com>
> ---
>  arch/x86/kernel/cpu/sgx/encl.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c
> index 24c1bb8eb196..1f88f80c4477 100644
> --- a/arch/x86/kernel/cpu/sgx/encl.c
> +++ b/arch/x86/kernel/cpu/sgx/encl.c
> @@ -344,8 +344,11 @@ static vm_fault_t sgx_encl_eaug_page(struct vm_area_struct *vma,
>  	}
>  
>  	va_page = sgx_encl_grow(encl, false);
> -	if (IS_ERR(va_page))
> -		goto err_out_epc;
> +	if (IS_ERR(va_page)) {
> +        if (PTR_ERR(va_page) == -EBUSY)
> +            vmret =  VM_FAULT_NOPAGE;
> +        goto err_out_epc;
> +    }
>  
>  	if (va_page)
>  		list_add(&va_page->list, &encl->va_pages);
> -- 
> 2.25.1
> 

Indentation is probably not right, but the fix look legit.

You need to use real tab-characters to fix that. Run the
patch with scripts/checkpatch.pl and it will report you
these issues.

Vijay, can you check if this fixes the issue for you?

BR, Jarkko
Jarkko Sakkinen Aug. 14, 2022, 7:41 p.m. UTC | #3
On Fri, Aug 12, 2022 at 10:41:30PM +0000, Dhanraj, Vijay wrote:
> Hi Haitao,
> 
> > -----Original Message-----
> > From: Haitao Huang <haitao.huang@linux.intel.com>
> > Sent: Friday, August 12, 2022 12:12 PM
> > To: linux-sgx@vger.kernel.org; jarkko@kernel.org; Chatre, Reinette
> > <reinette.chatre@intel.com>; dave.hansen@linux.intel.com; Dhanraj, Vijay
> > <vijay.dhanraj@intel.com>
> > Subject: [PATCH] x86/sgx: handle VA page allocation failure for EAUG on PF.
> > 
> > Return VM_FAULT_NOPAGE to allow the swapping thread to catch up.
> > 
> > link: https://lore.kernel.org/all/20220804201456.33418-1-
> > vijay.dhanraj@intel.com/
> > 
> > Signed-off-by: Haitao Huang <haitao.huang@linux.intel.com>
> > 
> >  arch/x86/kernel/cpu/sgx/encl.c | 7 +++++--
> >  1 file changed, 5 insertions(+), 2 deletions(-)
> > 
> > diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c
> > index 24c1bb8eb196..1f88f80c4477 100644
> > --- a/arch/x86/kernel/cpu/sgx/encl.c
> > +++ b/arch/x86/kernel/cpu/sgx/encl.c
> > @@ -344,8 +344,11 @@ static vm_fault_t sgx_encl_eaug_page(struct
> > vm_area_struct *vma,
> >  	}
> > 
> >  	va_page = sgx_encl_grow(encl, false);
> > -	if (IS_ERR(va_page))
> > -		goto err_out_epc;
> > +	if (IS_ERR(va_page)) {
> > +        if (PTR_ERR(va_page) == -EBUSY)
> > +            vmret =  VM_FAULT_NOPAGE;
> > +        goto err_out_epc;
> > +    }
> > 
> >  	if (va_page)
> >  		list_add(&va_page->list, &encl->va_pages);
> > --
> > 2.25.1
> 
> After applying this patch, I don't see the allocation failure issue with `augment_via_eaccept_long` test case. Ran the test for about ~60 times and all the time it passes.
> Tested-by: Vijay Dhanraj <vijay.dhanraj@intel.com>

Good to hear. Thank you.

BR, Jarkko
Haitao Huang Aug. 15, 2022, 3:01 p.m. UTC | #4
On Sun, 14 Aug 2022 14:36:29 -0500, Jarkko Sakkinen <jarkko@kernel.org>  
wrote:

> On Fri, Aug 12, 2022 at 12:12:24PM -0700, Haitao Huang wrote:
>> Return VM_FAULT_NOPAGE to allow the swapping thread to catch up.
>>
>> link:  
>> https://lore.kernel.org/all/20220804201456.33418-1-vijay.dhanraj@intel.com/
>>
>> Signed-off-by: Haitao Huang <haitao.huang@linux.intel.com>
>> ---
>>  arch/x86/kernel/cpu/sgx/encl.c | 7 +++++--
>>  1 file changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/x86/kernel/cpu/sgx/encl.c  
>> b/arch/x86/kernel/cpu/sgx/encl.c
>> index 24c1bb8eb196..1f88f80c4477 100644
>> --- a/arch/x86/kernel/cpu/sgx/encl.c
>> +++ b/arch/x86/kernel/cpu/sgx/encl.c
>> @@ -344,8 +344,11 @@ static vm_fault_t sgx_encl_eaug_page(struct  
>> vm_area_struct *vma,
>>  	}
>>
>>  	va_page = sgx_encl_grow(encl, false);
>> -	if (IS_ERR(va_page))
>> -		goto err_out_epc;
>> +	if (IS_ERR(va_page)) {
>> +        if (PTR_ERR(va_page) == -EBUSY)
>> +            vmret =  VM_FAULT_NOPAGE;
>> +        goto err_out_epc;
>> +    }
>>
>>  	if (va_page)
>>  		list_add(&va_page->list, &encl->va_pages);
>> --
>> 2.25.1
>>
>
> Indentation is probably not right, but the fix look legit.

Fixed in updated patch. Can I add your "Reviewed-by" tag?
Thanks
Haitao
diff mbox series

Patch

diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c
index 24c1bb8eb196..1f88f80c4477 100644
--- a/arch/x86/kernel/cpu/sgx/encl.c
+++ b/arch/x86/kernel/cpu/sgx/encl.c
@@ -344,8 +344,11 @@  static vm_fault_t sgx_encl_eaug_page(struct vm_area_struct *vma,
 	}
 
 	va_page = sgx_encl_grow(encl, false);
-	if (IS_ERR(va_page))
-		goto err_out_epc;
+	if (IS_ERR(va_page)) {
+        if (PTR_ERR(va_page) == -EBUSY)
+            vmret =  VM_FAULT_NOPAGE;
+        goto err_out_epc;
+    }
 
 	if (va_page)
 		list_add(&va_page->list, &encl->va_pages);