Re: [RFC PATCH v1 09/28] x86/efi: Access EFI data as encrypted when SEV is active

2016-09-23 Thread Kai Huang
On 23/09/16 06:37, Borislav Petkov wrote: On Thu, Sep 22, 2016 at 08:23:36PM +0200, Paolo Bonzini wrote: Unless this is part of some spec, it's easier if things are the same in SME and SEV. Yeah, I was pondering over how sprinkling sev_active checks might not be so clean. I'm wondering if we

Re: [intel-sgx-kernel-dev] [PATCH v5 11/11] intel_sgx: driver documentation

2017-11-13 Thread Kai Huang
On Mon, 2017-11-13 at 21:45 +0200, Jarkko Sakkinen wrote: > Signed-off-by: Jarkko Sakkinen > --- > Documentation/index.rst | 1 + > Documentation/x86/intel_sgx.rst | 131 > > 2 files changed, 132 insertions(+) > create mode 100644 Documentation/

Re: [intel-sgx-kernel-dev] [PATCH v5 11/11] intel_sgx: driver documentation

2017-11-14 Thread Kai Huang
On Tue, 2017-11-14 at 21:47 +0200, Jarkko Sakkinen wrote: > On Tue, Nov 14, 2017 at 04:01:05PM +1300, Kai Huang wrote: > > Not sure whether you should talk about MEE staff here. They are not > > in > > SDM and (thus) may potentially be changed in the future. > > The

Re: [PATCHv5 08/19] x86/mm: Introduce variables to store number, shift and mask of KeyIDs

2018-07-30 Thread Kai Huang
On Tue, 2018-07-17 at 14:20 +0300, Kirill A. Shutemov wrote: > mktme_nr_keyids holds number of KeyIDs available for MKTME, excluding > KeyID zero which used by TME. MKTME KeyIDs start from 1. > > mktme_keyid_shift holds shift of KeyID within physical address. > > mktme_keyid_mask holds mask to ex

Re: [tip:x86/mm] x86/tme: Detect if TME and MKTME is activated by BIOS

2018-03-12 Thread Kai Huang
ve to do this even if we are not going to use KeyID bits > ourself. VM guests still have to know that these bits are not usable > for physical address. > > Signed-off-by: Kirill A. Shutemov > Cc: Dave Hansen > Cc: Kai Huang > Cc: Linus Torvalds > Cc: Peter

Re: [tip:x86/mm] x86/tme: Detect if TME and MKTME is activated by BIOS

2018-03-13 Thread Kai Huang
On Tue, 2018-03-13 at 15:49 +0300, Kirill A. Shutemov wrote: > On Tue, Mar 13, 2018 at 03:12:02PM +1300, Kai Huang wrote: > > It seems setup_pku() will call get_cpu_cap to restore c- > > >x86_phys_bits > > later? In which case I think you need to change setup_pku as well.

[PATCH] x86/sgx: Fix a W=1 build warning in function comment

2024-08-25 Thread Kai Huang
27;high' not described in 'sgx_calc_section_metric' ... The function sgx_calc_section_metric() is a simple helper which is only used in sgx/main.c. There's no need to use k-doc style comment for it. Downgrade to normal comment to silence this warning. Signed-off-by: Kai H

Re: [PATCH v3 03/25] x86/sgx: Wipe out EREMOVE from sgx_free_epc_page()

2021-03-24 Thread Kai Huang
On Wed, 24 Mar 2021 11:09:20 +0100 Paolo Bonzini wrote: > On 24/03/21 10:38, Kai Huang wrote: > > Hi Sean, Boris, Paolo, > > > > Thanks for the discussion. I tried to digest all your conversations and > > hopefully I have understood you correctly. I pasted the new pat

Re: [PATCH v3 03/25] x86/sgx: Wipe out EREMOVE from sgx_free_epc_page()

2021-03-24 Thread Kai Huang
> > > +/* Error message for EREMOVE failure, when kernel is about to leak EPC > > page */ > > +#define EREMOVE_ERROR_MESSAGE \ > > + "EREMOVE returned %d (0x%x), kernel bug likely. EPC page leaked, > > SGX may become > > unusuable. Please refer to Documentation/x86/sgx.rst for more inf

Re: [PATCH v3 03/25] x86/sgx: Wipe out EREMOVE from sgx_free_epc_page()

2021-03-24 Thread Kai Huang
On Thu, 25 Mar 2021 00:39:01 +0100 Paolo Bonzini wrote: > On 25/03/21 00:23, Kai Huang wrote: > > I changed to below (with slight modification on Paolo's): > > > > /* Error message for EREMOVE failure, when kernel is about to leak EPC page > > */ &

[PATCH v4 03/25] x86/sgx: Wipe out EREMOVE from sgx_free_epc_page()

2021-03-25 Thread Kai Huang
or message when EREMOVE fails, and add documentation to explain to user what is the bug and suggest user what to do when this bug happens, although extremely unlikely. Signed-off-by: Kai Huang --- Documentation/x86/sgx.rst | 27 +++ arch/x86/kernel/cpu/sgx/en

Re: [PATCH v3 05/25] x86/sgx: Introduce virtual EPC for use by KVM guests

2021-03-25 Thread Kai Huang
> + > +static int sgx_vepc_free_page(struct sgx_epc_page *epc_page) > +{ > + int ret; > + > + /* > + * Take a previously guest-owned EPC page and return it to the > + * general EPC page pool. > + * > + * Guests can not be trusted to have left this page in a good > +

Re: [PATCH v3 03/25] x86/sgx: Wipe out EREMOVE from sgx_free_epc_page()

2021-03-25 Thread Kai Huang
On Thu, 25 Mar 2021 09:42:41 +0100 Borislav Petkov wrote: > ... so you could send the final version of this patch as a reply to this > thread, now that everyone agrees, so that I can continue going through > the rest. > I have sent it by replying to this patch. [PATCH v4 03/25] x86/sgx: Wipe out

[PATCH] x86/sgx: Avoid returning NULL in __sgx_alloc_epc_page()

2021-03-18 Thread Kai Huang
254.711480] CR2: 0008 [ 254.735494] ---[ end trace 970dce6d4cdf7f64 ]--- [ 254.759915] RIP: 0010:sgx_alloc_epc_page+0x46/0x152 ... Fixes: 5b8719504e3a("x86/sgx: Add a basic NUMA allocation scheme to sgx_alloc_epc_page()") Signed-off-by: Kai Huang --- arch/x86/kernel/cpu/sgx/main.c |

[PATCH v3 01/25] x86/cpufeatures: Make SGX_LC feature bit depend on SGX bit

2021-03-19 Thread Kai Huang
: Sean Christopherson Signed-off-by: Kai Huang --- arch/x86/kernel/cpu/cpuid-deps.c | 1 + arch/x86/kernel/cpu/feat_ctl.c | 12 +++- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-deps.c index 42af31b64c2c

[PATCH v3 02/25] x86/cpufeatures: Add SGX1 and SGX2 sub-features

2021-03-19 Thread Kai Huang
kernel support for SGX1 and SGX2. Suppress both SGX1 and SGX2 from /proc/cpuinfo. SGX1 basically means SGX, and for SGX2 there is no concrete use case of using it in /proc/cpuinfo. Signed-off-by: Sean Christopherson Acked-by: Dave Hansen Signed-off-by: Kai Huang --- arch/x86/include/asm

[PATCH v3 03/25] x86/sgx: Wipe out EREMOVE from sgx_free_epc_page()

2021-03-19 Thread Kai Huang
() with sgx_encl_free_epc_page() in all call sites. No functional change is intended, except the new WARNING message when EREMOVE fails. Acked-by: Jarkko Sakkinen Signed-off-by: Kai Huang --- v2->v3: - Changed to replace all call sites of sgx_free_epc_page() with sgx_encl_free_epc_page()

[PATCH v3 04/25] x86/sgx: Add SGX_CHILD_PRESENT hardware error code

2021-03-19 Thread Kai Huang
to handle recoverable EREMOVE errors when saniziting EPC pages after they are freed. Signed-off-by: Sean Christopherson Acked-by: Dave Hansen Acked-by: Jarkko Sakkinen Signed-off-by: Kai Huang --- arch/x86/kernel/cpu/sgx/arch.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/

[PATCH v3 05/25] x86/sgx: Introduce virtual EPC for use by KVM guests

2021-03-19 Thread Kai Huang
SGX virtualization. Signed-off-by: Sean Christopherson Acked-by: Dave Hansen Co-developed-by: Kai Huang Signed-off-by: Kai Huang --- arch/x86/Kconfig | 12 ++ arch/x86/kernel/cpu/sgx/Makefile | 1 + arch/x86/kernel/cpu/sgx/sgx.h| 9 ++ arch/x86/kernel/cpu/sgx/virt.c

[PATCH v3 08/25] x86/sgx: Expose SGX architectural definitions to the kernel

2021-03-19 Thread Kai Huang
componments. Also update MAINTAINERS to include asm/sgx.h. Signed-off-by: Sean Christopherson Acked-by: Dave Hansen Co-developed-by: Kai Huang Signed-off-by: Kai Huang --- v1->v3: - Added MAINTAINERS file update to include new asm/sgx.h - Changed 'line' to 'comment' in the

[PATCH v3 07/25] x86/sgx: Initialize virtual EPC driver even when SGX driver is disabled

2021-03-19 Thread Kai Huang
SGX. Acked-by: Dave Hansen Reviewed-by: Sean Christopherson Signed-off-by: Kai Huang --- arch/x86/kernel/cpu/sgx/main.c | 10 +- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c index 6a734f484aa7..b73114150ff8

[PATCH v3 06/25] x86/cpu/intel: Allow SGX virtualization without Launch Control support

2021-03-19 Thread Kai Huang
: Dave Hansen Co-developed-by: Kai Huang Signed-off-by: Kai Huang --- v2->v3: - Fix nit: s/Faunch/Launch. --- arch/x86/kernel/cpu/feat_ctl.c | 59 +- 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/arch/x86/kernel/cpu/feat_ctl.c b/arch/x86/kernel/

[PATCH v3 12/25] x86/sgx: Add helper to update SGX_LEPUBKEYHASHn MSRs

2021-03-19 Thread Kai Huang
Add a helper to update SGX_LEPUBKEYHASHn MSRs. SGX virtualization also needs to update those MSRs based on guest's "virtual" SGX_LEPUBKEYHASHn before EINIT from guest. Acked-by: Dave Hansen Acked-by: Jarkko Sakkinen Signed-off-by: Kai Huang --- arch/x86/kernel/cpu/s

[PATCH v3 09/25] x86/sgx: Move ENCLS leaf definitions to sgx.h

2021-03-19 Thread Kai Huang
From: Sean Christopherson Move the ENCLS leaf definitions to sgx.h so that they can be used by KVM. Signed-off-by: Sean Christopherson Acked-by: Dave Hansen Acked-by: Jarkko Sakkinen Signed-off-by: Kai Huang --- arch/x86/include/asm/sgx.h | 15 +++ arch/x86/kernel/cpu/sgx

[PATCH v3 10/25] x86/sgx: Add SGX2 ENCLS leaf definitions (EAUG, EMODPR and EMODT)

2021-03-19 Thread Kai Huang
: Jarkko Sakkinen Signed-off-by: Kai Huang --- arch/x86/include/asm/sgx.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/include/asm/sgx.h b/arch/x86/include/asm/sgx.h index 34f44238d1d1..3b025afec0a7 100644 --- a/arch/x86/include/asm/sgx.h +++ b/arch/x86/include/asm/sgx.h @@ -40,6

[PATCH v3 14/25] x86/sgx: Move provisioning device creation out of SGX driver

2021-03-19 Thread Kai Huang
driver is not enabled due to flexible launch control is not available, SGX virtualization can still be enabled, and use it to restrict VM's capability of being able to access provisioning key. Signed-off-by: Sean Christopherson Reviewed-by: Jarkko Sakkinen Acked-by: Dave Hansen Signed-off-by

[PATCH v3 11/25] x86/sgx: Add encls_faulted() helper

2021-03-19 Thread Kai Huang
From: Sean Christopherson Add a helper to extract the fault indicator from an encoded ENCLS return value. SGX virtualization will also need to detect ENCLS faults. Signed-off-by: Sean Christopherson Acked-by: Dave Hansen Acked-by: Jarkko Sakkinen Signed-off-by: Kai Huang --- arch/x86

[PATCH v3 13/25] x86/sgx: Add helpers to expose ECREATE and EINIT to KVM

2021-03-19 Thread Kai Huang
are subject to segmentation and paging mechanisms. It's also possible to generate kernel mappings for ENCLS parameters by resolving PFN but using __uaccess_xx() is simpler. Signed-off-by: Sean Christopherson Signed-off-by: Kai Huang --- v2->v3: - Updated to use addr,size directly for acces

[PATCH v3 15/25] KVM: x86: Export kvm_mmu_gva_to_gpa_{read,write}() for SGX (VMX)

2021-03-19 Thread Kai Huang
s for non-EPC pages in order to pass user pointers directly to ECREATE and EINIT, which avoids having to copy pages worth of data into the kernel. Signed-off-by: Sean Christopherson Acked-by: Jarkko Sakkinen Signed-off-by: Kai Huang --- arch/x86/kvm/x86.c | 2 ++ 1 file changed, 2 insertions(+)

[PATCH v3 18/25] KVM: x86: Add reverse-CPUID lookup support for scattered SGX features

2021-03-19 Thread Kai Huang
Sean Christopherson Signed-off-by: Kai Huang --- arch/x86/kvm/cpuid.h | 13 - 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/cpuid.h b/arch/x86/kvm/cpuid.h index 8925a929186c..a175ff75bbbe 100644 --- a/arch/x86/kvm/cpuid.h +++ b/arch/x86/kvm/cpuid.h @@ -

[PATCH v3 19/25] KVM: VMX: Add basic handling of VM-Exit from SGX enclave

2021-03-19 Thread Kai Huang
_LOOP_EXITING only affects CPL0 and enclaves exist only at CPL3, so we also don't need to worry about that interaction. Signed-off-by: Sean Christopherson Signed-off-by: Kai Huang --- arch/x86/include/asm/vmx.h | 1 + arch/x86/include/uapi/asm/vmx.h | 1 + arch/x86/kvm/vmx/neste

[PATCH v3 16/25] KVM: x86: Define new #PF SGX error code bit

2021-03-19 Thread Kai Huang
-execute scheme for virtualizing SGX Launch Control, e.g. to inject SGX-induced #PFs if EINIT faults in the host, and to support live migration. Signed-off-by: Sean Christopherson Signed-off-by: Kai Huang --- arch/x86/include/asm/kvm_host.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch

[PATCH v3 20/25] KVM: VMX: Frame in ENCLS handler for SGX virtualization

2021-03-19 Thread Kai Huang
-off-by: Kai Huang --- arch/x86/kvm/Makefile | 2 ++ arch/x86/kvm/vmx/sgx.c | 50 ++ arch/x86/kvm/vmx/sgx.h | 15 + arch/x86/kvm/vmx/vmx.c | 9 +--- 4 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 arch/x86/kvm/vmx/sgx.c

[PATCH v3 21/25] KVM: VMX: Add SGX ENCLS[ECREATE] handler to enforce CPUID restrictions

2021-03-19 Thread Kai Huang
masks diverges from hardware in order to enforce the desired CPUID model, i.e. inject #GP if the guest attempts to set a bit that hasn't been enumerated as allowed-1 in CPUID. Note, access to the PROVISIONKEY is not yet supported. Signed-off-by: Sean Christopherson Co-developed-by: Kai Huang Sig

[PATCH v3 17/25] KVM: x86: Add support for reverse CPUID lookup of scattered features

2021-03-19 Thread Kai Huang
stopherson Signed-off-by: Kai Huang --- arch/x86/kvm/cpuid.c | 32 +++- arch/x86/kvm/cpuid.h | 39 ++- 2 files changed, 61 insertions(+), 10 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 6bd2f8b830e4..a0

[PATCH v3 22/25] KVM: VMX: Add emulation of SGX Launch Control LE hash MSRs

2021-03-19 Thread Kai Huang
e writable, e.g. to allow firmware to lock down the LE root key with a non-Intel value. Signed-off-by: Sean Christopherson Co-developed-by: Kai Huang Signed-off-by: Kai Huang --- arch/x86/kvm/vmx/sgx.c | 35 +++ arch/x86/kvm/vmx/sgx.h | 6 ++ arch/x86/kvm

[PATCH v3 23/25] KVM: VMX: Add ENCLS[EINIT] handler to support SGX Launch Control (LC)

2021-03-19 Thread Kai Huang
execute, the ~1500 cycle overhead to trap-and-execute EINIT is unlikely to be noticed by the guest, let alone impact its overall SGX performance. Signed-off-by: Sean Christopherson Signed-off-by: Kai Huang --- arch/x86/kvm/vmx/sgx.c | 55 ++ 1 file changed, 55

[PATCH v3 25/25] KVM: x86: Add capability to grant VM access to privileged SGX attribute

2021-03-19 Thread Kai Huang
guest access to privileged attributes by default. Cc: Andy Lutomirski Signed-off-by: Sean Christopherson Signed-off-by: Kai Huang --- Documentation/virt/kvm/api.rst | 23 +++ arch/x86/kvm/cpuid.c | 2 +- arch/x86/kvm/x86.c | 21

[PATCH v3 24/25] KVM: VMX: Enable SGX virtualization for SGX1, SGX2 and LC

2021-03-19 Thread Kai Huang
on key, all SGX attribute bits may be exposed to the guest. Guest access to the provision key, which is controlled via securityfs, will be added in a future patch. Note, KVM does not yet support exposing ENCLS_C leafs or ENCLV leafs. Signed-off-by: Sean Christopherson Signed-off-by: Kai Huang --- arch/

[PATCH v3 00/25] KVM SGX virtualization support

2021-03-19 Thread Kai Huang
n traps ECREATE from guest, and only allows ECREATE with provisioning key bit to run when guest supports KVM_CAP_SGX_ATTRIBUTE. Kai Huang (4): x86/cpufeatures: Make SGX_LC feature bit depend on SGX bit x86/sgx: Wipe out EREMOVE from sgx_free_epc_page() x86/sgx: Initialize virtual EPC driver even whe

Re: [PATCH] x86/sgx: Avoid returning NULL in __sgx_alloc_epc_page()

2021-03-19 Thread Kai Huang
On Fri, 19 Mar 2021 09:45:23 +0100 Borislav Petkov wrote: > On Fri, Mar 19, 2021 at 05:06:02PM +1300, Kai Huang wrote: > > Below kernel bug happened when running simple SGX application when EPC > > is under pressure. The root cause is with commit 5b8719504e3a > > ("

Re: [PATCH] x86/sgx: Avoid returning NULL in __sgx_alloc_epc_page()

2021-03-19 Thread Kai Huang
On Fri, 19 Mar 2021 22:01:41 +1300 Kai Huang wrote: > On Fri, 19 Mar 2021 09:45:23 +0100 Borislav Petkov wrote: > > On Fri, Mar 19, 2021 at 05:06:02PM +1300, Kai Huang wrote: > > > Below kernel bug happened when running simple SGX application when EPC > > > is under p

Re: [PATCH v3 03/25] x86/sgx: Wipe out EREMOVE from sgx_free_epc_page()

2021-03-22 Thread Kai Huang
On Mon, 22 Mar 2021 22:06:45 +0100 Borislav Petkov wrote: > On Mon, Mar 22, 2021 at 12:37:02PM -0700, Sean Christopherson wrote: > > Yes. Note, it's still true if you strike out the "too", KVM support is > > completely > > orthogonal to this code. The purpose of this patch is to separate out the

Re: [PATCH v3 03/25] x86/sgx: Wipe out EREMOVE from sgx_free_epc_page()

2021-03-22 Thread Kai Huang
> > Btw, I probably have seen this and forgotten again so pls remind me, > is the amount of pages available for SGX use static and limited by, > I believe BIOS, or can a leakage in EPC pages cause system memory > shortage? > Yes EPC size is fixed and configured in BIOS. Leaking EPC pages may c

Re: [PATCH v3 03/25] x86/sgx: Wipe out EREMOVE from sgx_free_epc_page()

2021-03-22 Thread Kai Huang
On Mon, 22 Mar 2021 23:37:26 +0100 Borislav Petkov wrote: > On Tue, Mar 23, 2021 at 11:06:43AM +1300, Kai Huang wrote: > > This path is called by host SGX driver only, so yes this leaking is done by > > host enclaves only. > > Yes, so I was told. > > > This patch

Re: [PATCH v3 03/25] x86/sgx: Wipe out EREMOVE from sgx_free_epc_page()

2021-03-24 Thread Kai Huang
anation of this bug to the commit msg (per Paolo). I am terrible Documentation writer, so please help to check and give comments. Thanks! --- commit 1e297a535bcb4f51a08343c40207520017d85efe (HEAD) Author: Kai Huang Date: Wed Jan 20 03:40:53 2021 +0200 x86/sgx: Wipe out EREMOVE from sgx_free_epc_page()

Re: [PATCH v3 05/25] x86/sgx: Introduce virtual EPC for use by KVM guests

2021-03-30 Thread Kai Huang
On Fri, 26 Mar 2021 16:03:55 +0100 Borislav Petkov wrote: > On Fri, Mar 19, 2021 at 08:22:21PM +1300, Kai Huang wrote: > > From: Sean Christopherson > > > > Add a misc device /dev/sgx_vepc to allow userspace to allocate "raw" EPC > > without an associated

Re: [PATCH v3 05/25] x86/sgx: Introduce virtual EPC for use by KVM guests

2021-03-30 Thread Kai Huang
On Wed, 31 Mar 2021 08:44:23 +0200 Boris Petkov wrote: > On March 31, 2021 3:10:32 AM GMT+02:00, Kai Huang > wrote: > > > The admin will be aware of > >such EPC > >allocation disjoint situation, and deploy host enclaves/KVM SGX guests > >accordingly. >

Re: [PATCH v3 05/25] x86/sgx: Introduce virtual EPC for use by KVM guests

2021-03-31 Thread Kai Huang
On Wed, 31 Mar 2021 09:44:39 +0200 Boris Petkov wrote: > On March 31, 2021 8:51:38 AM GMT+02:00, Kai Huang wrote: > >How about adding explanation to Documentation/x86/sgx.rst? > > Sure, and then we should point users at it. The thing is also indexed by > search engines so hop

Re: [PATCH v3 05/25] x86/sgx: Introduce virtual EPC for use by KVM guests

2021-03-31 Thread Kai Huang
On Wed, 31 Mar 2021 21:53:45 +1300 Kai Huang wrote: > On Wed, 31 Mar 2021 09:44:39 +0200 Boris Petkov wrote: > > On March 31, 2021 8:51:38 AM GMT+02:00, Kai Huang > > wrote: > > >How about adding explanation to Documentation/x86/sgx.rst? > > > > Sure, and t

Re: [PATCH v3 00/25] KVM SGX virtualization support

2021-03-22 Thread Kai Huang
> > I just say add my ack to SGX specific patches where it is missing. > Good enough. > > /Jarkko Thank you Jarkko! Hi Boris, If there's no other comments, should I send another version adding Jarkko's Acked-by for the x86 SGX patches that don't have it (patch 2, 5, 6, 7, 8, 13 -- in which p

Re: [PATCH v3 03/25] x86/sgx: Wipe out EREMOVE from sgx_free_epc_page()

2021-03-22 Thread Kai Huang
On Mon, 22 Mar 2021 12:37:02 -0700 Sean Christopherson wrote: > On Mon, Mar 22, 2021, Borislav Petkov wrote: > > On Mon, Mar 22, 2021 at 11:56:37AM -0700, Sean Christopherson wrote: > > > Not necessarily. This can only trigger in the host, and thus require a > > > host > > > reboot, if the host i

Re: [PATCH v3 03/25] x86/sgx: Wipe out EREMOVE from sgx_free_epc_page()

2021-03-22 Thread Kai Huang
On Mon, 22 Mar 2021 20:11:57 +0100 Paolo Bonzini wrote: > On 22/03/21 19:56, Sean Christopherson wrote: > > EREMOVE can only fail if there's a kernel or hardware bug (or a VMM bug if > > running as a guest). IME, nearly every kernel/KVM bug that I introduced > > that > > led to EREMOVE failure wa

Re: [PATCH v3 03/25] x86/sgx: Wipe out EREMOVE from sgx_free_epc_page()

2021-03-15 Thread Kai Huang
On Mon, 15 Mar 2021 15:19:32 +0200 Jarkko Sakkinen wrote: > On Mon, Mar 15, 2021 at 03:18:16PM +0200, Jarkko Sakkinen wrote: > > On Mon, Mar 15, 2021 at 08:12:36PM +1300, Kai Huang wrote: > > > On Sat, 13 Mar 2021 12:45:53 +0200 Jarkko Sakkinen wrote: > > > > On F

Re: [PATCH v2 07/25] x86/sgx: Initialize virtual EPC driver even when SGX driver is disabled

2021-03-15 Thread Kai Huang
On Mon, 15 Mar 2021 15:51:17 +0200 Jarkko Sakkinen wrote: > On Mon, Mar 15, 2021 at 03:04:59PM +0200, Jarkko Sakkinen wrote: > > On Mon, Mar 15, 2021 at 04:13:17PM +1300, Kai Huang wrote: > > > On Sun, 14 Mar 2021 17:27:18 +0200 Jarkko Sakkinen wrote: > > > > On S

Re: [PATCH v2 07/25] x86/sgx: Initialize virtual EPC driver even when SGX driver is disabled

2021-03-15 Thread Kai Huang
On Tue, 16 Mar 2021 01:08:44 +0200 Jarkko Sakkinen wrote: > On Tue, Mar 16, 2021 at 01:05:05AM +0200, Jarkko Sakkinen wrote: > > On Tue, Mar 16, 2021 at 09:48:59AM +1300, Kai Huang wrote: > > > On Mon, 15 Mar 2021 15:51:17 +0200 Jarkko Sakkinen wrote: > > > > On M

Re: [PATCH v3 03/25] x86/sgx: Wipe out EREMOVE from sgx_free_epc_page()

2021-03-15 Thread Kai Huang
On Tue, 16 Mar 2021 00:59:31 +0200 Jarkko Sakkinen wrote: > On Tue, Mar 16, 2021 at 09:29:34AM +1300, Kai Huang wrote: > > On Mon, 15 Mar 2021 15:19:32 +0200 Jarkko Sakkinen wrote: > > > On Mon, Mar 15, 2021 at 03:18:16PM +0200, Jarkko Sakkinen wrote: > > > > On M

Re: [PATCH v4 03/25] x86/sgx: Wipe out EREMOVE from sgx_free_epc_page()

2021-03-26 Thread Kai Huang
> > diff --git a/arch/x86/kernel/cpu/sgx/sgx.h b/arch/x86/kernel/cpu/sgx/sgx.h > > index 653af8ca1a25..6b21a165500e 100644 > > --- a/arch/x86/kernel/cpu/sgx/sgx.h > > +++ b/arch/x86/kernel/cpu/sgx/sgx.h > > @@ -13,6 +13,11 @@ > > #undef pr_fmt > > #define pr_fmt(fmt) "sgx: " fmt > > > > +/* E

Re: [PATCH v3 13/25] x86/sgx: Add helpers to expose ECREATE and EINIT to KVM

2021-04-06 Thread Kai Huang
On Tue, 6 Apr 2021 09:40:38 +0200 Borislav Petkov wrote: > On Tue, Apr 06, 2021 at 09:44:21AM +1200, Kai Huang wrote: > > The intention was to catch KVM bug, since KVM is the only caller, and in > > current > > implementation KVM won't call this function if @secs is

Re: [PATCH v3 05/25] x86/sgx: Introduce virtual EPC for use by KVM guests

2021-04-06 Thread Kai Huang
On Tue, 6 Apr 2021 10:28:00 +0200 Borislav Petkov wrote: > On Tue, Apr 06, 2021 at 09:46:34AM +1200, Kai Huang wrote: > > Fine to me. Please let me know if you want me to resend patches. Thanks. > > Patch updated: Looks fine. Thank you! > > --- > From: Sean Christopher

Re: [PATCH v3 13/25] x86/sgx: Add helpers to expose ECREATE and EINIT to KVM

2021-04-06 Thread Kai Huang
On Tue, 6 Apr 2021 11:09:01 +0200 Borislav Petkov wrote: > On Tue, Apr 06, 2021 at 08:59:58PM +1200, Kai Huang wrote: > > OK. My thinking was that, returning negative error value basically means > > guest > > will be killed. > > You need to define how you're go

Re: [PATCH v3 13/25] x86/sgx: Add helpers to expose ECREATE and EINIT to KVM

2021-04-06 Thread Kai Huang
On Tue, 6 Apr 2021 11:32:11 +0200 Borislav Petkov wrote: > On Tue, Apr 06, 2021 at 09:24:24PM +1200, Kai Huang wrote: > > Such invalid input has already been handled in handle_encls_xx() before > > calling > > the two helpers in this patch. KVM returns to Qemu and let it d

Re: [PATCH v3 13/25] x86/sgx: Add helpers to expose ECREATE and EINIT to KVM

2021-04-06 Thread Kai Huang
On Tue, 6 Apr 2021 19:08:58 +0200 Borislav Petkov wrote: > On Tue, Apr 06, 2021 at 09:41:52PM +1200, Kai Huang wrote: > > > Ok, I'll make the changes and you can redo the KVM rest ontop. > > > > > > > Thank you! > > I.e., something like this: Looks

[PATCH v4 05/25] x86/sgx: Introduce virtual EPC for use by KVM guests

2021-04-01 Thread Kai Huang
n Acked-by: Dave Hansen Acked-by: Jarkko Sakkinen Co-developed-by: Kai Huang Signed-off-by: Kai Huang --- v3->v4: - Added documentation to explain virtual EPC, and suggest user what to do if user wants to run both host SGX apps and KVM SGX guests, since EPC pages assigned to guest is no

Re: [PATCH v3 05/25] x86/sgx: Introduce virtual EPC for use by KVM guests

2021-04-01 Thread Kai Huang
On Wed, 31 Mar 2021 21:53:45 +1300 Kai Huang wrote: > On Wed, 31 Mar 2021 09:44:39 +0200 Boris Petkov wrote: > > On March 31, 2021 8:51:38 AM GMT+02:00, Kai Huang > > wrote: > > >How about adding explanation to Documentation/x86/sgx.rst? > > > > Sure, and t

Re: [PATCH v3 05/25] x86/sgx: Introduce virtual EPC for use by KVM guests

2021-04-01 Thread Kai Huang
On Thu, 1 Apr 2021 20:31:59 +0200 Borislav Petkov wrote: > On Thu, Apr 01, 2021 at 01:20:39AM +1300, Kai Huang wrote: > > Could you help to review whether below change is OK? > > I ended up applying this: Thank you! > > --- > From: Sean Christopherson > Date: Fri,

Re: [PATCH v3 07/25] x86/sgx: Initialize virtual EPC driver even when SGX driver is disabled

2021-04-02 Thread Kai Huang
On Fri, 2 Apr 2021 11:48:16 +0200 Borislav Petkov wrote: > On Fri, Mar 19, 2021 at 08:23:02PM +1300, Kai Huang wrote: > > Modify sgx_init() to always try to initialize the virtual EPC driver, > > even if the SGX driver is disabled. The SGX driver might be disabled > > if SGX

Re: [PATCH v3 07/25] x86/sgx: Initialize virtual EPC driver even when SGX driver is disabled

2021-04-02 Thread Kai Huang
On Fri, 2 Apr 2021 13:22:35 +0200 Borislav Petkov wrote: > On Sat, Apr 03, 2021 at 12:08:10AM +1300, Kai Huang wrote: > > Do you want me to send updated patch? > > No need. If I do, I'll ask kindly, otherwise you don't have to do > anything. > I see. Thanks.

Re: [PATCH v2 07/25] x86/sgx: Initialize virtual EPC driver even when SGX driver is disabled

2021-03-17 Thread Kai Huang
On Tue, 16 Mar 2021 14:46:05 +0200 Jarkko Sakkinen wrote: > On Mon, Mar 15, 2021 at 06:13:53PM -0700, Sean Christopherson wrote: > > On Tue, Mar 16, 2021, Jarkko Sakkinen wrote: > > > On Tue, Mar 16, 2021 at 01:05:05AM +0200, Jarkko Sakkinen wrote: > > > > The way I've understood it is that given t

Re: [PATCH v3 07/25] x86/sgx: Initialize virtual EPC driver even when SGX driver is disabled

2021-04-02 Thread Kai Huang
On Fri, 2 Apr 2021 15:42:51 + Sean Christopherson wrote: > On Fri, Apr 02, 2021, Borislav Petkov wrote: > > On Fri, Mar 19, 2021 at 08:23:02PM +1300, Kai Huang wrote: > > > Modify sgx_init() to always try to initialize the virtual EPC driver, > > > even if the SGX d

Re: [PATCH v3 13/25] x86/sgx: Add helpers to expose ECREATE and EINIT to KVM

2021-04-05 Thread Kai Huang
On Mon, 5 Apr 2021 11:07:59 +0200 Borislav Petkov wrote: > On Fri, Mar 19, 2021 at 08:23:08PM +1300, Kai Huang wrote: > > + /* > > +* @secs is an untrusted, userspace-provided address. It comes from > > +* KVM and is assumed to be a valid pointer whic

Re: [PATCH v3 05/25] x86/sgx: Introduce virtual EPC for use by KVM guests

2021-04-05 Thread Kai Huang
On Mon, 5 Apr 2021 11:01:51 +0200 Borislav Petkov wrote: > On Fri, Mar 19, 2021 at 08:22:21PM +1300, Kai Huang wrote: > > diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig > > index 35391e94bd22..007912f67a06 100644 > > --- a/arch/x86/Kconfig > > +++ b/arch/x86/Kcon

[PATCH 00/25] KVM SGX virtualization support

2021-03-01 Thread Kai Huang
with provisioning key bit to run when guest supports KVM_CAP_SGX_ATTRIBUTE. Jarkko Sakkinen (1): x86/sgx: Wipe out EREMOVE from sgx_free_epc_page() Kai Huang (3): x86/cpufeatures: Make SGX_LC feature bit depend on SGX bit x86/sgx: Initialize virtual EPC driver even when SGX driver is disabled

[PATCH 01/25] x86/cpufeatures: Make SGX_LC feature bit depend on SGX bit

2021-03-01 Thread Kai Huang
: Kai Huang --- arch/x86/kernel/cpu/cpuid-deps.c | 1 + arch/x86/kernel/cpu/feat_ctl.c | 12 +++- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-deps.c index 42af31b64c2c..d40f8e0a54ce 100644 --- a/arch/x86

[PATCH 02/25] x86/cpufeatures: Add SGX1 and SGX2 sub-features

2021-03-01 Thread Kai Huang
kernel support for SGX1 and SGX2. Signed-off-by: Sean Christopherson Acked-by: Dave Hansen Signed-off-by: Kai Huang --- arch/x86/include/asm/cpufeatures.h | 2 ++ arch/x86/kernel/cpu/cpuid-deps.c | 2 ++ arch/x86/kernel/cpu/scattered.c| 2 ++ 3 files changed, 6 insertions(+) diff --git

[PATCH 03/25] x86/sgx: Wipe out EREMOVE from sgx_free_epc_page()

2021-03-01 Thread Kai Huang
-by: Jarkko Sakkinen Co-developed-by: Kai Huang Signed-off-by: Kai Huang --- RFC v6->v1: - Removed sgx_reset_epc_page() since with it, I found it is hard to find a place to print the msg saying EPC page is leaked. - Implemented original sgx_free_epc_page() as sgx_encl_free_epc_page(),

[PATCH 06/25] x86/cpu/intel: Allow SGX virtualization without Launch Control support

2021-03-01 Thread Kai Huang
-by: Kai Huang Acked-by: Dave Hansen Signed-off-by: Kai Huang --- arch/x86/kernel/cpu/feat_ctl.c | 57 ++ 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/arch/x86/kernel/cpu/feat_ctl.c b/arch/x86/kernel/cpu/feat_ctl.c index 27533a6e04fa

[PATCH 07/25] x86/sgx: Initialize virtual EPC driver even when SGX driver is disabled

2021-03-01 Thread Kai Huang
SGX. Acked-by: Dave Hansen Signed-off-by: Kai Huang --- arch/x86/kernel/cpu/sgx/main.c | 10 +- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c index 44fe91a5bfb3..8c922e68274d 100644 --- a/arch/x86/kernel/cpu/sgx

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

2021-03-01 Thread Kai Huang
componments. Signed-off-by: Sean Christopherson Co-developed-by: Kai Huang Acked-by: Dave Hansen Signed-off-by: Kai Huang --- .../cpu/sgx/arch.h => include/asm/sgx.h} | 20 ++- arch/x86/kernel/cpu/sgx/encl.c| 2 +- arch/x86/kernel/cpu/sgx/sg

[PATCH 09/25] x86/sgx: Move ENCLS leaf definitions to sgx.h

2021-03-01 Thread Kai Huang
From: Sean Christopherson Move the ENCLS leaf definitions to sgx.h so that they can be used by KVM. And because they're architectural. Signed-off-by: Sean Christopherson Acked-by: Dave Hansen Acked-by: Jarkko Sakkinen Signed-off-by: Kai Huang --- arch/x86/include/asm/sgx.h

[PATCH 04/25] x86/sgx: Add SGX_CHILD_PRESENT hardware error code

2021-03-01 Thread Kai Huang
to handle recoverable EREMOVE errors when saniziting EPC pages after they are freed. Signed-off-by: Sean Christopherson Acked-by: Dave Hansen Acked-by: Jarkko Sakkinen Signed-off-by: Kai Huang --- arch/x86/kernel/cpu/sgx/arch.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/

[PATCH 14/25] x86/sgx: Move provisioning device creation out of SGX driver

2021-03-01 Thread Kai Huang
driver is not enabled due to flexible launch control is not available, SGX virtualization can still be enabled, and use it to restrict VM's capability of being able to access provisioning key. Signed-off-by: Sean Christopherson Reviewed-by: Jarkko Sakkinen Signed-off-by: Kai Huang --- arc

[PATCH 13/25] x86/sgx: Add helpers to expose ECREATE and EINIT to KVM

2021-03-01 Thread Kai Huang
: Kai Huang --- arch/x86/include/asm/sgx.h | 7 +++ arch/x86/kernel/cpu/sgx/virt.c | 95 ++ 2 files changed, 102 insertions(+) diff --git a/arch/x86/include/asm/sgx.h b/arch/x86/include/asm/sgx.h index 0db1e47a90c5..d2e1f9a6dd4d 100644 --- a/arch/x86/include/asm

[PATCH 16/25] KVM: x86: Define new #PF SGX error code bit

2021-03-01 Thread Kai Huang
-execute scheme for virtualizing SGX Launch Control, e.g. to inject SGX-induced #PFs if EINIT faults in the host, and to support live migration. Signed-off-by: Sean Christopherson Signed-off-by: Kai Huang --- arch/x86/include/asm/kvm_host.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch

[PATCH 15/25] KVM: x86: Export kvm_mmu_gva_to_gpa_{read,write}() for SGX (VMX)

2021-03-01 Thread Kai Huang
s for non-EPC pages in order to pass user pointers directly to ECREATE and EINIT, which avoids having to copy pages worth of data into the kernel. Signed-off-by: Sean Christopherson Acked-by: Jarkko Sakkinen Signed-off-by: Kai Huang --- arch/x86/kvm/x86.c | 2 ++ 1 file changed, 2 insertions(+)

[PATCH 11/25] x86/sgx: Add encls_faulted() helper

2021-03-01 Thread Kai Huang
From: Sean Christopherson Add a helper to extract the fault indicator from an encoded ENCLS return value. SGX virtualization will also need to detect ENCLS faults. Signed-off-by: Sean Christopherson Acked-by: Dave Hansen Acked-by: Jarkko Sakkinen Signed-off-by: Kai Huang --- arch/x86

[PATCH 19/25] KVM: VMX: Add basic handling of VM-Exit from SGX enclave

2021-03-01 Thread Kai Huang
_LOOP_EXITING only affects CPL0 and enclaves exist only at CPL3, so we also don't need to worry about that interaction. Signed-off-by: Sean Christopherson Signed-off-by: Kai Huang --- arch/x86/include/asm/vmx.h | 1 + arch/x86/include/uapi/asm/vmx.h | 1 + arch/x86/kvm/vmx/neste

[PATCH 17/25] KVM: x86: Add support for reverse CPUID lookup of scattered features

2021-03-01 Thread Kai Huang
stopherson Signed-off-by: Kai Huang --- arch/x86/kvm/cpuid.c | 32 +++- arch/x86/kvm/cpuid.h | 39 ++- 2 files changed, 61 insertions(+), 10 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 6bd2f8b830e4..a0

[PATCH 20/25] KVM: VMX: Frame in ENCLS handler for SGX virtualization

2021-03-01 Thread Kai Huang
-off-by: Kai Huang --- arch/x86/kvm/Makefile | 2 ++ arch/x86/kvm/vmx/sgx.c | 50 ++ arch/x86/kvm/vmx/sgx.h | 15 + arch/x86/kvm/vmx/vmx.c | 9 +--- 4 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 arch/x86/kvm/vmx/sgx.c

[PATCH 18/25] KVM: x86: Add reverse-CPUID lookup support for scattered SGX features

2021-03-01 Thread Kai Huang
Sean Christopherson Signed-off-by: Kai Huang --- arch/x86/kvm/cpuid.h | 13 - 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/cpuid.h b/arch/x86/kvm/cpuid.h index 8925a929186c..a175ff75bbbe 100644 --- a/arch/x86/kvm/cpuid.h +++ b/arch/x86/kvm/cpuid.h @@ -

[PATCH 21/25] KVM: VMX: Add SGX ENCLS[ECREATE] handler to enforce CPUID restrictions

2021-03-01 Thread Kai Huang
masks diverges from hardware in order to enforce the desired CPUID model, i.e. inject #GP if the guest attempts to set a bit that hasn't been enumerated as allowed-1 in CPUID. Note, access to the PROVISIONKEY is not yet supported. Signed-off-by: Sean Christopherson Co-developed-by: Kai Huang Sig

[PATCH 25/25] KVM: x86: Add capability to grant VM access to privileged SGX attribute

2021-03-01 Thread Kai Huang
guest access to privileged attributes by default. Cc: Andy Lutomirski Signed-off-by: Sean Christopherson Signed-off-by: Kai Huang --- Documentation/virt/kvm/api.rst | 23 +++ arch/x86/kvm/cpuid.c | 2 +- arch/x86/kvm/x86.c | 21

[PATCH 05/25] x86/sgx: Introduce virtual EPC for use by KVM guests

2021-03-01 Thread Kai Huang
SGX virtualization. Signed-off-by: Sean Christopherson Co-developed-by: Kai Huang Acked-by: Dave Hansen Signed-off-by: Kai Huang --- arch/x86/Kconfig | 12 ++ arch/x86/kernel/cpu/sgx/Makefile | 1 + arch/x86/kernel/cpu/sgx/sgx.h| 9 ++ arch/x86/kernel/cpu/sgx/virt.c

[PATCH 12/25] x86/sgx: Add helper to update SGX_LEPUBKEYHASHn MSRs

2021-03-01 Thread Kai Huang
Add a helper to update SGX_LEPUBKEYHASHn MSRs. SGX virtualization also needs to update those MSRs based on guest's "virtual" SGX_LEPUBKEYHASHn before EINIT from guest. Acked-by: Dave Hansen Acked-by: Jarkko Sakkinen Signed-off-by: Kai Huang --- arch/x86/kernel/cpu/s

[PATCH 10/25] x86/sgx: Add SGX2 ENCLS leaf definitions (EAUG, EMODPR and EMODT)

2021-03-01 Thread Kai Huang
: Jarkko Sakkinen Signed-off-by: Kai Huang --- arch/x86/include/asm/sgx.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/include/asm/sgx.h b/arch/x86/include/asm/sgx.h index 48f0c42027c0..0db1e47a90c5 100644 --- a/arch/x86/include/asm/sgx.h +++ b/arch/x86/include/asm/sgx.h @@ -40,6

[PATCH 22/25] KVM: VMX: Add emulation of SGX Launch Control LE hash MSRs

2021-03-01 Thread Kai Huang
e writable, e.g. to allow firmware to lock down the LE root key with a non-Intel value. Signed-off-by: Sean Christopherson Co-developed-by: Kai Huang Signed-off-by: Kai Huang --- arch/x86/kvm/vmx/sgx.c | 35 +++ arch/x86/kvm/vmx/sgx.h | 6 ++ arch/x86/kvm

[PATCH 23/25] KVM: VMX: Add ENCLS[EINIT] handler to support SGX Launch Control (LC)

2021-03-01 Thread Kai Huang
execute, the ~1500 cycle overhead to trap-and-execute EINIT is unlikely to be noticed by the guest, let alone impact its overall SGX performance. Signed-off-by: Sean Christopherson Signed-off-by: Kai Huang --- arch/x86/kvm/vmx/sgx.c | 55 ++ 1 file changed, 55

[PATCH 24/25] KVM: VMX: Enable SGX virtualization for SGX1, SGX2 and LC

2021-03-01 Thread Kai Huang
on key, all SGX attribute bits may be exposed to the guest. Guest access to the provision key, which is controlled via securityfs, will be added in a future patch. Note, KVM does not yet support exposing ENCLS_C leafs or ENCLV leafs. Signed-off-by: Sean Christopherson Signed-off-by: Kai Huang --- arch/

Re: [PATCH 02/25] x86/cpufeatures: Add SGX1 and SGX2 sub-features

2021-03-01 Thread Kai Huang
On Mon, 2021-03-01 at 11:00 +0100, Borislav Petkov wrote: > On Mon, Mar 01, 2021 at 10:44:29PM +1300, Kai Huang wrote: > > From: Sean Christopherson > > > > Add SGX1 and SGX2 feature flags, via CPUID.0x12.0x0.EAX, as scattered > > features, since adding a new leaf

Re: [PATCH 02/25] x86/cpufeatures: Add SGX1 and SGX2 sub-features

2021-03-01 Thread Kai Huang
On Mon, 2021-03-01 at 11:30 +0100, Borislav Petkov wrote: > On Mon, Mar 01, 2021 at 11:19:15PM +1300, Kai Huang wrote: > > "sgx2" is useful because it adds additional functionality. > > Useful for what? SGX2 means "Enclave Dynamic Memory Management", which s

  1   2   >