linux-sgx.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: Haitao Huang <haitao.huang@linux.intel.com>
Cc: linux-sgx@vger.kernel.org, dave.hansen@linux.intel.com,
	reinette.chatre@intel.com, vijay.dhanraj@intel.com
Subject: Re: [RFC PATCH v3 2/4] x86/sgx: Implement support for MADV_WILLNEED
Date: Thu, 26 Jan 2023 21:24:39 +0000	[thread overview]
Message-ID: <Y9LvlzYO5B0MbH3E@kernel.org> (raw)
In-Reply-To: <op.1zcd91mxwjvjmi@hhuan26-mobl.amr.corp.intel.com>

On Wed, Jan 25, 2023 at 01:40:39PM -0600, Haitao Huang wrote:
> On Tue, 15 Nov 2022 16:03:45 -0600, Jarkko Sakkinen <jarkko@kernel.org>
> wrote:
> 
> 
> > > +	if (!encl)
> > > +		return -EINVAL;
> > 
> > Why !encl check is needed?
> It was intended as sanity check. But I think encl should not be null at this
> point so will remove in next version.
> 
> > 
> > > +	if (!cpu_feature_enabled(X86_FEATURE_SGX2))
> > > +		return -EINVAL;
> > 
> > This should be done first before doing anything else in the function.
> 
> Will do
> 
> > 
> > > +
> > > +	if (offset + len < offset)
> > > +		return -EINVAL;
> > > +	if (encl->base + offset < encl->base)
> > > +		return -EINVAL;
> > > +	start  = offset + encl->base;
> > > +	end = start + len;
> > 
> > These could be just as well assigned in the declarations, which would
> > definitely be also less convoluted.
> > 
> Will do
> 
> ...
> > > diff --git a/arch/x86/kernel/cpu/sgx/encl.c
> > > b/arch/x86/kernel/cpu/sgx/encl.c
> > > index 1abc5e7f2660..c57e60d5a0aa 100644
> > > --- a/arch/x86/kernel/cpu/sgx/encl.c
> > > +++ b/arch/x86/kernel/cpu/sgx/encl.c
> > > @@ -305,11 +305,11 @@ struct sgx_encl_page
> > > *sgx_encl_load_page(struct sgx_encl *encl,
> > >   * on a SGX2 system then the EPC can be added dynamically via the SGX2
> > >   * ENCLS[EAUG] instruction.
> > >   *
> > > - * Returns: Appropriate vm_fault_t: VM_FAULT_NOPAGE when PTE was
> > > installed
> > > - * successfully, VM_FAULT_SIGBUS or VM_FAULT_OOM as error otherwise.
> > > + * Returns: 0 when PTE was installed successfully, -EBUSY for
> > > waiting on
> > > + * reclaimer to free EPC, -ENOMEM for out of RAM, -EFAULT as error
> > > otherwise.
> > >   */
> > > -vm_fault_t sgx_encl_eaug_page(struct vm_area_struct *vma,
> > > -			      struct sgx_encl *encl, unsigned long addr)
> > > +int sgx_encl_eaug_page(struct vm_area_struct *vma,
> > > +		       struct sgx_encl *encl, unsigned long addr)
> > >  {
> > >  	vm_fault_t vmret = VM_FAULT_SIGBUS;
> > >  	struct sgx_pageinfo pginfo = {0};
> > > @@ -318,10 +318,10 @@ vm_fault_t sgx_encl_eaug_page(struct
> > > vm_area_struct *vma,
> > >  	struct sgx_va_page *va_page;
> > >  	unsigned long phys_addr;
> > >  	u64 secinfo_flags;
> > > -	int ret;
> > > +	int ret = -EFAULT;
> > 
> > Why?
> Original code uses ret only to temporarily store return values from the
> called functions.
> Now I also use it as return of this function and assign -EFAULT as default
> in all cases that ret is not assigned explicitly below, e.g., -EBUSY cases.
> Basically -EFAULT cases are the same as VM_FAULT_SIGBUS cases in original
> code.
> I'll clarify in comments above for the return values.
> 
> Thanks
> Haitao

OK, will look forward to it.

BR, Jarkko

  reply	other threads:[~2023-01-26 21:24 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-07 22:02 [RFC PATCH v3 0/4] x86/sgx: implement support for MADV_WILLNEED Haitao Huang
2022-11-07 22:02 ` [RFC PATCH v3 1/4] x86/sgx: Export sgx_encl_eaug_page Haitao Huang
2022-11-07 22:02   ` [RFC PATCH v3 2/4] x86/sgx: Implement support for MADV_WILLNEED Haitao Huang
2022-11-07 22:02     ` [RFC PATCH v3 3/4] selftests/sgx: add len field for EACCEPT op Haitao Huang
2022-11-07 22:02       ` [RFC PATCH v3 4/4] selftests/sgx: Add test for madvise(..., WILLNEED) Haitao Huang
2022-11-15 23:24       ` [RFC PATCH v3 3/4] selftests/sgx: add len field for EACCEPT op Jarkko Sakkinen
2022-11-16 19:26         ` Haitao Huang
2022-11-27 17:16           ` Jarkko Sakkinen
2022-11-15 22:03     ` [RFC PATCH v3 2/4] x86/sgx: Implement support for MADV_WILLNEED Jarkko Sakkinen
2023-01-25 19:40       ` Haitao Huang
2023-01-26 21:24         ` Jarkko Sakkinen [this message]
2022-11-15 21:54   ` [RFC PATCH v3 1/4] x86/sgx: Export sgx_encl_eaug_page Jarkko Sakkinen

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=Y9LvlzYO5B0MbH3E@kernel.org \
    --to=jarkko@kernel.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=haitao.huang@linux.intel.com \
    --cc=linux-sgx@vger.kernel.org \
    --cc=reinette.chatre@intel.com \
    --cc=vijay.dhanraj@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).