diff mbox series

[v2,08/25] x86/sgx: Expose SGX architectural definitions to the kernel

Message ID b60e1d665c17ed6430166d659bd0f547a53aea0f.1615250634.git.kai.huang@intel.com (mailing list archive)
State New, archived
Headers show
Series KVM SGX virtualization support | expand

Commit Message

Huang, Kai March 9, 2021, 1:39 a.m. UTC
From: Sean Christopherson <sean.j.christopherson@intel.com>

Expose SGX architectural structures, as KVM will use many of the
architectural constants and structs to virtualize SGX.

Name the new header file as asm/sgx.h, rather than asm/sgx_arch.h, to
have single header to provide SGX facilities to share with other kernel
componments.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Co-developed-by: Kai Huang <kai.huang@intel.com>
Acked-by: Dave Hansen <dave.hansen@intel.com>
Signed-off-by: Kai Huang <kai.huang@intel.com>
---
 .../cpu/sgx/arch.h => include/asm/sgx.h}      | 20 ++++++++++++++-----
 arch/x86/kernel/cpu/sgx/encl.c                |  2 +-
 arch/x86/kernel/cpu/sgx/sgx.h                 |  2 +-
 tools/testing/selftests/sgx/defines.h         |  2 +-
 4 files changed, 18 insertions(+), 8 deletions(-)
 rename arch/x86/{kernel/cpu/sgx/arch.h => include/asm/sgx.h} (95%)

Comments

Sean Christopherson March 12, 2021, 9:58 p.m. UTC | #1
On Tue, Mar 09, 2021, Kai Huang wrote:
> From: Sean Christopherson <sean.j.christopherson@intel.com>
> 
> Expose SGX architectural structures, as KVM will use many of the
> architectural constants and structs to virtualize SGX.
> 
> Name the new header file as asm/sgx.h, rather than asm/sgx_arch.h, to
> have single header to provide SGX facilities to share with other kernel
> componments.
> 
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> Co-developed-by: Kai Huang <kai.huang@intel.com>
> Acked-by: Dave Hansen <dave.hansen@intel.com>

Same checkpatch warning.  Probably doesn't matter.

> Signed-off-by: Kai Huang <kai.huang@intel.com>
> ---
>  .../cpu/sgx/arch.h => include/asm/sgx.h}      | 20 ++++++++++++++-----
>  arch/x86/kernel/cpu/sgx/encl.c                |  2 +-
>  arch/x86/kernel/cpu/sgx/sgx.h                 |  2 +-
>  tools/testing/selftests/sgx/defines.h         |  2 +-
>  4 files changed, 18 insertions(+), 8 deletions(-)
>  rename arch/x86/{kernel/cpu/sgx/arch.h => include/asm/sgx.h} (95%)
> 
> diff --git a/arch/x86/kernel/cpu/sgx/arch.h b/arch/x86/include/asm/sgx.h
> similarity index 95%
> rename from arch/x86/kernel/cpu/sgx/arch.h
> rename to arch/x86/include/asm/sgx.h
> index abf99bb71fdc..d4ad35f6319a 100644
> --- a/arch/x86/kernel/cpu/sgx/arch.h
> +++ b/arch/x86/include/asm/sgx.h
> @@ -2,15 +2,20 @@
>  /**
>   * Copyright(c) 2016-20 Intel Corporation.
>   *
> - * Contains data structures defined by the SGX architecture.  Data structures
> - * defined by the Linux software stack should not be placed here.
> + * Intel Software Guard Extensions (SGX) support.
>   */
> -#ifndef _ASM_X86_SGX_ARCH_H
> -#define _ASM_X86_SGX_ARCH_H
> +#ifndef _ASM_X86_SGX_H
> +#define _ASM_X86_SGX_H
>  
>  #include <linux/bits.h>
>  #include <linux/types.h>
>  
> +/*
> + * This file contains both data structures defined by SGX architecture and Linux
> + * defined software data structures and functions.  The two should not be mixed
> + * together for better readibility.  The architectural definitions come first.
> + */
> +
>  /* The SGX specific CPUID function. */
>  #define SGX_CPUID		0x12
>  /* EPC enumeration. */
> @@ -337,4 +342,9 @@ struct sgx_sigstruct {
>  
>  #define SGX_LAUNCH_TOKEN_SIZE 304
>  
> -#endif /* _ASM_X86_SGX_ARCH_H */
> +/*
> + * Do not put any hardware-defined SGX structure representations below this
> + * line!

Heh, which line?  Yep, it's Friday afternoon...

> + */
Huang, Kai March 15, 2021, 3:36 a.m. UTC | #2
On Fri, 12 Mar 2021 13:58:40 -0800 Sean Christopherson wrote:
> On Tue, Mar 09, 2021, Kai Huang wrote:
> > From: Sean Christopherson <sean.j.christopherson@intel.com>
> > 
> > Expose SGX architectural structures, as KVM will use many of the
> > architectural constants and structs to virtualize SGX.
> > 
> > Name the new header file as asm/sgx.h, rather than asm/sgx_arch.h, to
> > have single header to provide SGX facilities to share with other kernel
> > componments.
> > 
> > Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> > Co-developed-by: Kai Huang <kai.huang@intel.com>
> > Acked-by: Dave Hansen <dave.hansen@intel.com>
> 
> Same checkpatch warning.  Probably doesn't matter.

Will change order to make checkpatch happy for this whole series.

Thanks for pointing out.

> 
> > Signed-off-by: Kai Huang <kai.huang@intel.com>
> > ---
> >  .../cpu/sgx/arch.h => include/asm/sgx.h}      | 20 ++++++++++++++-----
> >  arch/x86/kernel/cpu/sgx/encl.c                |  2 +-
> >  arch/x86/kernel/cpu/sgx/sgx.h                 |  2 +-
> >  tools/testing/selftests/sgx/defines.h         |  2 +-
> >  4 files changed, 18 insertions(+), 8 deletions(-)
> >  rename arch/x86/{kernel/cpu/sgx/arch.h => include/asm/sgx.h} (95%)
> > 
> > diff --git a/arch/x86/kernel/cpu/sgx/arch.h b/arch/x86/include/asm/sgx.h
> > similarity index 95%
> > rename from arch/x86/kernel/cpu/sgx/arch.h
> > rename to arch/x86/include/asm/sgx.h
> > index abf99bb71fdc..d4ad35f6319a 100644
> > --- a/arch/x86/kernel/cpu/sgx/arch.h
> > +++ b/arch/x86/include/asm/sgx.h
> > @@ -2,15 +2,20 @@
> >  /**
> >   * Copyright(c) 2016-20 Intel Corporation.
> >   *
> > - * Contains data structures defined by the SGX architecture.  Data structures
> > - * defined by the Linux software stack should not be placed here.
> > + * Intel Software Guard Extensions (SGX) support.
> >   */
> > -#ifndef _ASM_X86_SGX_ARCH_H
> > -#define _ASM_X86_SGX_ARCH_H
> > +#ifndef _ASM_X86_SGX_H
> > +#define _ASM_X86_SGX_H
> >  
> >  #include <linux/bits.h>
> >  #include <linux/types.h>
> >  
> > +/*
> > + * This file contains both data structures defined by SGX architecture and Linux
> > + * defined software data structures and functions.  The two should not be mixed
> > + * together for better readibility.  The architectural definitions come first.
> > + */
> > +
> >  /* The SGX specific CPUID function. */
> >  #define SGX_CPUID		0x12
> >  /* EPC enumeration. */
> > @@ -337,4 +342,9 @@ struct sgx_sigstruct {
> >  
> >  #define SGX_LAUNCH_TOKEN_SIZE 304
> >  
> > -#endif /* _ASM_X86_SGX_ARCH_H */
> > +/*
> > + * Do not put any hardware-defined SGX structure representations below this
> > + * line!
> 
> Heh, which line?  Yep, it's Friday afternoon...

Hmm.. I will change to below this comment. :)
diff mbox series

Patch

diff --git a/arch/x86/kernel/cpu/sgx/arch.h b/arch/x86/include/asm/sgx.h
similarity index 95%
rename from arch/x86/kernel/cpu/sgx/arch.h
rename to arch/x86/include/asm/sgx.h
index abf99bb71fdc..d4ad35f6319a 100644
--- a/arch/x86/kernel/cpu/sgx/arch.h
+++ b/arch/x86/include/asm/sgx.h
@@ -2,15 +2,20 @@ 
 /**
  * Copyright(c) 2016-20 Intel Corporation.
  *
- * Contains data structures defined by the SGX architecture.  Data structures
- * defined by the Linux software stack should not be placed here.
+ * Intel Software Guard Extensions (SGX) support.
  */
-#ifndef _ASM_X86_SGX_ARCH_H
-#define _ASM_X86_SGX_ARCH_H
+#ifndef _ASM_X86_SGX_H
+#define _ASM_X86_SGX_H
 
 #include <linux/bits.h>
 #include <linux/types.h>
 
+/*
+ * This file contains both data structures defined by SGX architecture and Linux
+ * defined software data structures and functions.  The two should not be mixed
+ * together for better readibility.  The architectural definitions come first.
+ */
+
 /* The SGX specific CPUID function. */
 #define SGX_CPUID		0x12
 /* EPC enumeration. */
@@ -337,4 +342,9 @@  struct sgx_sigstruct {
 
 #define SGX_LAUNCH_TOKEN_SIZE 304
 
-#endif /* _ASM_X86_SGX_ARCH_H */
+/*
+ * Do not put any hardware-defined SGX structure representations below this
+ * line!
+ */
+
+#endif /* _ASM_X86_SGX_H */
diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c
index dcbcf840c522..130f6520438f 100644
--- a/arch/x86/kernel/cpu/sgx/encl.c
+++ b/arch/x86/kernel/cpu/sgx/encl.c
@@ -7,7 +7,7 @@ 
 #include <linux/shmem_fs.h>
 #include <linux/suspend.h>
 #include <linux/sched/mm.h>
-#include "arch.h"
+#include <asm/sgx.h>
 #include "encl.h"
 #include "encls.h"
 #include "sgx.h"
diff --git a/arch/x86/kernel/cpu/sgx/sgx.h b/arch/x86/kernel/cpu/sgx/sgx.h
index 1bff93be7bf4..5d71c9c8644d 100644
--- a/arch/x86/kernel/cpu/sgx/sgx.h
+++ b/arch/x86/kernel/cpu/sgx/sgx.h
@@ -8,7 +8,7 @@ 
 #include <linux/rwsem.h>
 #include <linux/types.h>
 #include <asm/asm.h>
-#include "arch.h"
+#include <asm/sgx.h>
 
 #undef pr_fmt
 #define pr_fmt(fmt) "sgx: " fmt
diff --git a/tools/testing/selftests/sgx/defines.h b/tools/testing/selftests/sgx/defines.h
index 592c1ccf4576..0bd73428d2f3 100644
--- a/tools/testing/selftests/sgx/defines.h
+++ b/tools/testing/selftests/sgx/defines.h
@@ -14,7 +14,7 @@ 
 #define __aligned(x) __attribute__((__aligned__(x)))
 #define __packed __attribute__((packed))
 
-#include "../../../../arch/x86/kernel/cpu/sgx/arch.h"
+#include "../../../../arch/x86/include/asm/sgx.h"
 #include "../../../../arch/x86/include/asm/enclu.h"
 #include "../../../../arch/x86/include/uapi/asm/sgx.h"