diff mbox series

[v2,1/2] x86/sgx: Add the missing ifdef for sgx_set_attribute()

Message ID 20210819124824.52169-1-jarkko@kernel.org (mailing list archive)
State New, archived
Headers show
Series [v2,1/2] x86/sgx: Add the missing ifdef for sgx_set_attribute() | expand

Commit Message

Jarkko Sakkinen Aug. 19, 2021, 12:48 p.m. UTC
Similarly as sgx_virt_*, decorate sgx_set_attribute() with ifdef, so that
calling it without appropraite config flags, will cause a compilation
error, and not a linking error.

Fixes: b3754e5d3da3 ("x86/sgx: Move provisioning device creation out of SGX driver")
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 arch/x86/include/asm/sgx.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Sean Christopherson Aug. 19, 2021, 4:07 p.m. UTC | #1
On Thu, Aug 19, 2021, Jarkko Sakkinen wrote:
> Similarly as sgx_virt_*, decorate sgx_set_attribute() with ifdef, so that
> calling it without appropraite config flags, will cause a compilation
> error, and not a linking error.
> 
> Fixes: b3754e5d3da3 ("x86/sgx: Move provisioning device creation out of SGX driver")
> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
> ---
>  arch/x86/include/asm/sgx.h | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/include/asm/sgx.h b/arch/x86/include/asm/sgx.h
> index 05f3e21f01a7..38c397ef35a8 100644
> --- a/arch/x86/include/asm/sgx.h
> +++ b/arch/x86/include/asm/sgx.h
> @@ -365,6 +365,11 @@ struct sgx_sigstruct {
>   * comment!
>   */
>  
> +#if defined(CONFIG_X86_SGX) || defined(CONFIG_X86_SGX_KVM)

X86_SGX_KVM depends on X86_SGX

And rather than shuffle code, you can wrap all of the prototypes, which has the
added bonus of "documenting" the aformentioned dependency, e.g.

diff --git a/arch/x86/include/asm/sgx.h b/arch/x86/include/asm/sgx.h
index 05f3e21f01a7..d5f3e617cc38 100644
--- a/arch/x86/include/asm/sgx.h
+++ b/arch/x86/include/asm/sgx.h
@@ -365,6 +365,7 @@ struct sgx_sigstruct {
  * comment!
  */

+#ifdef CONFIG_X86_SGX
 #ifdef CONFIG_X86_SGX_KVM
 int sgx_virt_ecreate(struct sgx_pageinfo *pageinfo, void __user *secs,
                     int *trapnr);
@@ -374,5 +375,6 @@ int sgx_virt_einit(void __user *sigstruct, void __user *token,

 int sgx_set_attribute(unsigned long *allowed_attributes,
                      unsigned int attribute_fd);
+#endif /* CONFIG_X86_SGX */

 #endif /* _ASM_X86_SGX_H */
Jarkko Sakkinen Aug. 25, 2021, 8:35 p.m. UTC | #2
On Thu, 2021-08-19 at 16:07 +0000, Sean Christopherson wrote:
> On Thu, Aug 19, 2021, Jarkko Sakkinen wrote:
> > Similarly as sgx_virt_*, decorate sgx_set_attribute() with ifdef, so that
> > calling it without appropraite config flags, will cause a compilation
> > error, and not a linking error.
> > 
> > Fixes: b3754e5d3da3 ("x86/sgx: Move provisioning device creation out of SGX driver")
> > Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
> > ---
> >  arch/x86/include/asm/sgx.h | 8 +++++---
> >  1 file changed, 5 insertions(+), 3 deletions(-)
> > 
> > diff --git a/arch/x86/include/asm/sgx.h b/arch/x86/include/asm/sgx.h
> > index 05f3e21f01a7..38c397ef35a8 100644
> > --- a/arch/x86/include/asm/sgx.h
> > +++ b/arch/x86/include/asm/sgx.h
> > @@ -365,6 +365,11 @@ struct sgx_sigstruct {
> >   * comment!
> >   */
> >  
> > +#if defined(CONFIG_X86_SGX) || defined(CONFIG_X86_SGX_KVM)
> 
> X86_SGX_KVM depends on X86_SGX
> 
> And rather than shuffle code, you can wrap all of the prototypes, which has the
> added bonus of "documenting" the aformentioned dependency, e.g.
> 
> diff --git a/arch/x86/include/asm/sgx.h b/arch/x86/include/asm/sgx.h
> index 05f3e21f01a7..d5f3e617cc38 100644
> --- a/arch/x86/include/asm/sgx.h
> +++ b/arch/x86/include/asm/sgx.h
> @@ -365,6 +365,7 @@ struct sgx_sigstruct {
>   * comment!
>   */
> 
> +#ifdef CONFIG_X86_SGX
>  #ifdef CONFIG_X86_SGX_KVM
>  int sgx_virt_ecreate(struct sgx_pageinfo *pageinfo, void __user *secs,
>                      int *trapnr);
> @@ -374,5 +375,6 @@ int sgx_virt_einit(void __user *sigstruct, void __user *token,
> 
>  int sgx_set_attribute(unsigned long *allowed_attributes,
>                       unsigned int attribute_fd);
> +#endif /* CONFIG_X86_SGX */
> 
>  #endif /* _ASM_X86_SGX_H */

Right, makes sense.

A bit off from this patch set, but I'm wondering if there would be any benefit to
have a compile time flag for just the allocator part, since KVM depends only that.

I.e. you could compile a kernel with just KVM required bits for SGX.

/Jarkko
diff mbox series

Patch

diff --git a/arch/x86/include/asm/sgx.h b/arch/x86/include/asm/sgx.h
index 05f3e21f01a7..38c397ef35a8 100644
--- a/arch/x86/include/asm/sgx.h
+++ b/arch/x86/include/asm/sgx.h
@@ -365,6 +365,11 @@  struct sgx_sigstruct {
  * comment!
  */
 
+#if defined(CONFIG_X86_SGX) || defined(CONFIG_X86_SGX_KVM)
+int sgx_set_attribute(unsigned long *allowed_attributes,
+		      unsigned int attribute_fd);
+#endif
+
 #ifdef CONFIG_X86_SGX_KVM
 int sgx_virt_ecreate(struct sgx_pageinfo *pageinfo, void __user *secs,
 		     int *trapnr);
@@ -372,7 +377,4 @@  int sgx_virt_einit(void __user *sigstruct, void __user *token,
 		   void __user *secs, u64 *lepubkeyhash, int *trapnr);
 #endif
 
-int sgx_set_attribute(unsigned long *allowed_attributes,
-		      unsigned int attribute_fd);
-
 #endif /* _ASM_X86_SGX_H */