Re: [PATCH v1 3/3] KEYS: trusted: Introduce support for NXP CAAM-based trusted keys

2021-03-24 Thread Sumit Garg
On Wed, 24 Mar 2021 at 19:37, Ahmad Fatoum wrote: > > Hello Sumit, > > On 24.03.21 11:47, Sumit Garg wrote: > > On Wed, 24 Mar 2021 at 14:56, Ahmad Fatoum wrote: > >> > >> Hello Mimi, > >> > >> On 23.03.21 19:07, Mimi Zohar wrote: > >>> On Tue, 2021-03-23 at 17:35 +0100, Ahmad Fatoum wrote: > >>>

Re: [PATCH -next] crypto: hisilicon/hpre - fix build error without CONFIG_CRYPTO_ECDH

2021-03-24 Thread tanghui20
Thinks, there is a similar patch to yours that was send in advance: https://www.spinics.net/lists/linux-crypto/msg54238.html On 2021/3/24 22:42, 'Wei Yongjun wrote: From: Wei Yongjun GCC reports build error as following: x86_64-linux-gnu-ld: drivers/crypto/hisilicon/hpre/hpre_crypto.o: in fun

Re: [PATCH v1 3/3] KEYS: trusted: Introduce support for NXP CAAM-based trusted keys

2021-03-24 Thread James Bottomley
On Wed, 2021-03-24 at 16:49 -0400, Mimi Zohar wrote: > On Wed, 2021-03-24 at 09:14 -0700, James Bottomley wrote: > > On Tue, 2021-03-23 at 14:07 -0400, Mimi Zohar wrote: > > > On Tue, 2021-03-23 at 17:35 +0100, Ahmad Fatoum wrote: > > > > Hello Horia, > > > > > > > > On 21.03.21 21:48, Horia Geant

Re: [PATCH v1 3/3] KEYS: trusted: Introduce support for NXP CAAM-based trusted keys

2021-03-24 Thread Mimi Zohar
On Wed, 2021-03-24 at 09:14 -0700, James Bottomley wrote: > On Tue, 2021-03-23 at 14:07 -0400, Mimi Zohar wrote: > > On Tue, 2021-03-23 at 17:35 +0100, Ahmad Fatoum wrote: > > > Hello Horia, > > > > > > On 21.03.21 21:48, Horia Geantă wrote: > > > > On 3/16/2021 7:02 PM, Ahmad Fatoum wrote: > > >

Re: [RFC Part2 PATCH 06/30] x86/fault: dump the RMP entry on #PF

2021-03-24 Thread Brijesh Singh
On 3/24/21 12:47 PM, Andy Lutomirski wrote: > On Wed, Mar 24, 2021 at 10:04 AM Brijesh Singh wrote: >> If hardware detects an RMP violation, it will raise a page-fault exception >> with the RMP bit set. To help the debug, dump the RMP entry of the faulting >> address. >> >> Cc: Thomas Gleixner

Re: [RFC Part2 PATCH 05/30] x86: define RMP violation #PF error code

2021-03-24 Thread Dave Hansen
> diff --git a/arch/x86/include/asm/trap_pf.h b/arch/x86/include/asm/trap_pf.h > index 10b1de500ab1..107f9d947e8d 100644 > --- a/arch/x86/include/asm/trap_pf.h > +++ b/arch/x86/include/asm/trap_pf.h > @@ -12,6 +12,7 @@ > * bit 4 ==1: fault was an instruction > f

Re: [RFC Part2 PATCH 06/30] x86/fault: dump the RMP entry on #PF

2021-03-24 Thread Andy Lutomirski
On Wed, Mar 24, 2021 at 10:04 AM Brijesh Singh wrote: > > If hardware detects an RMP violation, it will raise a page-fault exception > with the RMP bit set. To help the debug, dump the RMP entry of the faulting > address. > > Cc: Thomas Gleixner > Cc: Ingo Molnar > Cc: Borislav Petkov > Cc: Joe

[RFC Part2 PATCH 30/30] KVM: X86: Add support to handle the RMP nested page fault

2021-03-24 Thread Brijesh Singh
Follow the recommendation from APM2 section 15.36.10 and 15.36.11 to resolve the RMP violation encountered during the NPT table walk. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Joerg Roedel Cc: "H. Peter Anvin" Cc: Tony Luck Cc: Dave Hansen Cc: "Peter Zijlstra (Intel)" Cc:

[RFC Part2 PATCH 28/30] KVM: SVM: add support to handle Page State Change VMGEXIT

2021-03-24 Thread Brijesh Singh
SEV-SNP VMs can ask the hypervisor to change the page state in the RMP table to be private or shared using the Page State Change NAE event as defined in the GHCB specification section 4.1.6. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Joerg Roedel Cc: "H. Peter Anvin" Cc: Tony

[RFC Part2 PATCH 23/30] KVM: X86: Introduce kvm_mmu_get_tdp_walk() for SEV-SNP use

2021-03-24 Thread Brijesh Singh
The SEV-SNP VMs may call the page state change VMGEXIT to add the GPA as private or shared in the RMP table. The page state change VMGEXIT will contain the RMP page level to be used in the RMP entry. If the page level between the TDP and RMP does not match then, it will result in nested-page-fault

[RFC Part2 PATCH 27/30] KVM: SVM: add support to handle MSR based Page State Change VMGEXIT

2021-03-24 Thread Brijesh Singh
SEV-SNP VMs can ask the hypervisor to change the page state in the RMP table to be private or shared using the Page State Change MSR protocol as defined in the GHCB specification section 2.5.1. Before changing the page state in the RMP entry, we lookup the page in the TDP to make sure that there i

[RFC Part2 PATCH 24/30] KVM: X86: define new RMP check related #NPF error bits

2021-03-24 Thread Brijesh Singh
When SEV-SNP is enabled globally, the hardware places restrictions on all memory accesses based on the RMP entry, whether the hyperviso or a VM, performs the accesses. When hardware encounters an RMP access violation during a guest access, it will cause a #VMEXIT(NPF). See APM2 section 16.36.10 fo

[RFC Part2 PATCH 29/30] KVM: X86: export the kvm_zap_gfn_range() for the SNP use

2021-03-24 Thread Brijesh Singh
While resolving the RMP page fault, we may run into cases where the page level between the RMP entry and TDP does not match and the 2M RMP entry must be split into 4K RMP entries. Or a 2M TDP page need to be broken into multiple of 4K pages. To keep the RMP and TDP page level in sync, we will zap

[RFC Part2 PATCH 26/30] KVM: SVM: add support to handle GHCB GPA register VMGEXIT

2021-03-24 Thread Brijesh Singh
SEV-SNP guests are required to perform a GHCB GPA registration (see section 2.5.2 in GHCB specification). Before using a GHCB GPA for a vCPU the first time, a guest must register the vCPU GHCB GPA. If hypervisor can work with the guest requested GPA then it must respond back with the same GPA other

[RFC Part2 PATCH 21/30] KVM: X86: Add kvm_x86_ops to get the max page level for the TDP

2021-03-24 Thread Brijesh Singh
When running an SEV-SNP VM, the sPA used to index the RMP entry is obtained through the TDP translation (gva->gpa->spa). The TDP page level is checked against the page level programmed in the RMP entry. If the page level does not match, then it will cause a nested page fault with the RMP bit set to

[RFC Part2 PATCH 25/30] KVM: X86: update page-fault trace to log the 64-bit error code

2021-03-24 Thread Brijesh Singh
The page-fault error code is a 64-bit value, but the trace prints only the lower 32-bits. Some of the SEV-SNP RMP fault error codes are available in the upper 32-bits. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Joerg Roedel Cc: "H. Peter Anvin" Cc: Tony Luck Cc: Dave Hansen

[RFC Part2 PATCH 22/30] x86/mmu: Introduce kvm_mmu_map_tdp_page() for use by SEV

2021-03-24 Thread Brijesh Singh
Introduce a helper to directly fault-in a TDP page without going through the full page fault path. This allows SEV-SNP to build the netsted-page-table while handling the page state change VMGEXIT. A guest may issue a page state change VMGEXIT before accessing the page. Creating a fault-in, we can

[RFC Part2 PATCH 19/30] KVM: SVM: Reclaim the guest pages when SEV-SNP VM terminates

2021-03-24 Thread Brijesh Singh
The guest pages of the SEV-SNP VM maybe added as a private page in the RMP entry (assigned bit is set). While terminating the guest we must unassign those pages so that pages are transitioned to the hypervisor state before they can be freed. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petko

[RFC Part2 PATCH 20/30] KVM: SVM: add KVM_SEV_SNP_LAUNCH_FINISH command

2021-03-24 Thread Brijesh Singh
The KVM_SEV_SNP_LAUNCH_FINISH finalize the cryptographic digest and stores it as the measurement of the guest at launch. While finalizing the launch flow, it also issues the LAUNCH_UPDATE command to encrypt the VMSA pages. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Joerg Roede

[RFC Part2 PATCH 18/30] KVM: SVM: add KVM_SEV_SNP_LAUNCH_UPDATE command

2021-03-24 Thread Brijesh Singh
The KVM_SEV_SNP_LAUNCH_UPDATE command can be used to insert data into the guest's memory. The data is encrypted with the cryptographic context created with the KVM_SEV_SNP_LAUNCH_START. In addition to the inserting data, it can insert a two special pages into the guests memory: the secrets page an

[RFC Part2 PATCH 17/30] KVM: SVM: add KVM_SEV_SNP_LAUNCH_START command

2021-03-24 Thread Brijesh Singh
KVM_SEV_SNP_LAUNCH_START begins the launch process for an SEV-SNP guest. The command initializes a cryptographic digest context used to construct the measurement of the guest. If the guest is expected to be migrated, the command also binds a migration agent (MA) to the guest. For more information

[RFC Part2 PATCH 14/30] KVM: SVM: make AVIC backing, VMSA and VMCB memory allocation SNP safe

2021-03-24 Thread Brijesh Singh
When SEV-SNP is globally enabled on a system, the VMRUN instruction performs additional security checks on AVIC backing, VMSA, and VMCB page. On a successful VMRUN, these pages are marked "in-use" by the hardware in the RMP entry, and any attempt to modify the RMP entry for these pages will result

[RFC Part2 PATCH 15/30] KVM: SVM: define new SEV_FEATURES field in the VMCB Save State Area

2021-03-24 Thread Brijesh Singh
The hypervisor uses the SEV_FEATURES field (offset 3B0h) in the Save State Area to control the SEV-SNP guest features such as SNPActive, vTOM, ReflectVC etc. An SEV-SNP guest can read the SEV_FEATURES fields through the SEV_STATUS MSR. See APM2 Table 15-34 and B-4 for more details. Cc: Thomas Gle

[RFC Part2 PATCH 16/30] KVM: SVM: add KVM_SNP_INIT command

2021-03-24 Thread Brijesh Singh
The KVM_SNP_INIT command is used by the hypervisor to initialize the SEV-SNP platform context. In a typical workflow, this command should be the first command issued. When creating SEV-SNP guest, the VMM must use this command instead of the KVM_SEV_INIT or KVM_SEV_ES_INIT. Cc: Thomas Gleixner Cc:

[RFC Part2 PATCH 13/30] KVM: SVM: add initial SEV-SNP support

2021-03-24 Thread Brijesh Singh
The next generation of SEV is called SEV-SNP (Secure Nested Paging). SEV-SNP builds upon existing SEV and SEV-ES functionality while adding new hardware based security protection. SEV-SNP adds strong memory encryption integrity protection to help prevent malicious hypervisor-based attacks such as

[RFC Part2 PATCH 11/30] crypto:ccp: provide APIs to issue SEV-SNP commands

2021-03-24 Thread Brijesh Singh
Provide the APIs for the hypervisor to manage an SEV-SNP guest. The commands for SEV-SNP is defined in the SEV-SNP firmware specification. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Joerg Roedel Cc: "H. Peter Anvin" Cc: Tony Luck Cc: Dave Hansen Cc: "Peter Zijlstra (Intel)"

[RFC Part2 PATCH 12/30] crypto ccp: handle the legacy SEV command when SNP is enabled

2021-03-24 Thread Brijesh Singh
The behavior of the SEV-legacy commands is altered when the SNP firmware is in the INIT state. When SNP is in INIT state, all the SEV-legacy commands that cause the firmware to write to memory must be in the firmware state before issuing the command.. See SEV-SNP spec section 5.3.7 for more detail

[RFC Part2 PATCH 08/30] crypto:ccp: define the SEV-SNP commands

2021-03-24 Thread Brijesh Singh
AMD introduced the next generation of SEV called SEV-SNP (Secure Nested Paging). SEV-SNP builds upon existing SEV and SEV-ES functionality while adding new hardware security protection. Define the commands and structures used to communicate with the AMD-SP when creating and managing the SEV-SNP gu

[RFC Part2 PATCH 10/30] crypto: ccp: shutdown SNP firmware on kexec

2021-03-24 Thread Brijesh Singh
When the kernel is getting ready to kexec, it calls the device_shutdown() to allow drivers to cleanup before the kexec. If SEV firmware is initialized then shut it down before kexec'ing the new kernel. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Joerg Roedel Cc: "H. Peter Anvin

[RFC Part2 PATCH 09/30] crypto: ccp: Add support to initialize the AMD-SP for SEV-SNP

2021-03-24 Thread Brijesh Singh
Before SNP VMs can be launched, the platform must be appropriately configured and initialized. Platform initialization is accomplished via the SNP_INIT command. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Joerg Roedel Cc: "H. Peter Anvin" Cc: Tony Luck Cc: Dave Hansen Cc: "P

[RFC Part2 PATCH 06/30] x86/fault: dump the RMP entry on #PF

2021-03-24 Thread Brijesh Singh
If hardware detects an RMP violation, it will raise a page-fault exception with the RMP bit set. To help the debug, dump the RMP entry of the faulting address. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Joerg Roedel Cc: "H. Peter Anvin" Cc: Tony Luck Cc: Dave Hansen Cc: "Pe

[RFC Part2 PATCH 07/30] mm: add support to split the large THP based on RMP violation

2021-03-24 Thread Brijesh Singh
When SEV-SNP is enabled globally in the system, a write from the hypervisor can raise an RMP violation. We can resolve the RMP violation by splitting the virtual address to a lower page level. e.g - guest made a page shared in the RMP entry so that the hypervisor can write to it. - the hyperviso

[RFC Part2 PATCH 03/30] x86: add helper functions for RMPUPDATE and PSMASH instruction

2021-03-24 Thread Brijesh Singh
The RMPUPDATE instruction writes a new RMP entry in the RMP Table. The hypervisor will use the instruction to add pages to the RMP table. See APM3 for details on the instruction operations. The PSMASH instruction expands a 2MB RMP entry into a corresponding set of contiguous 4KB-Page RMP entries.

[RFC Part2 PATCH 04/30] x86/mm: split the physmap when adding the page in RMP table

2021-03-24 Thread Brijesh Singh
The integrity guarantee of SEV-SNP is enforced through the RMP table. The RMP is used in conjuntion with standard x86 and IOMMU page tables to enforce memory restrictions and page access rights. The RMP is indexed by system physical address, and is checked at the end of CPU and IOMMU table walks. T

[RFC Part2 PATCH 05/30] x86: define RMP violation #PF error code

2021-03-24 Thread Brijesh Singh
Bit 31 in the page fault-error bit will be set when processor encounters an RMP violation. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Joerg Roedel Cc: "H. Peter Anvin" Cc: Tony Luck Cc: Dave Hansen Cc: "Peter Zijlstra (Intel)" Cc: Paolo Bonzini Cc: Tom Lendacky Cc: David

[RFC Part2 PATCH 00/30] Add AMD Secure Nested Paging (SEV-SNP) Hypervisor Support

2021-03-24 Thread Brijesh Singh
This part of the Secure Encrypted Paging (SEV-SNP) series focuses on the changes required in a host OS for SEV-SNP support. The series builds upon SEV-SNP Part-1 https://marc.info/?l=kvm&m=161660430125343&w=2 . This series provides the basic building blocks to support booting the SEV-SNP VMs, it d

[RFC Part2 PATCH 02/30] x86/sev-snp: add RMP entry lookup helpers

2021-03-24 Thread Brijesh Singh
The lookup_page_in_rmptable() can be used by the host to read the RMP entry for a given page. The RMP entry format is documented in PPR section 2.1.5.2. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Joerg Roedel Cc: "H. Peter Anvin" Cc: Tony Luck Cc: Dave Hansen Cc: "Peter Zij

[RFC Part2 PATCH 01/30] x86: Add the host SEV-SNP initialization support

2021-03-24 Thread Brijesh Singh
The memory integrity guarantees of SEV-SNP are enforced through a new structure called the Reverse Map Table (RMP). The RMP is a single data structure shared across the system that contains one entry for every 4K page of DRAM that may be used by SEV-SNP VMs. The goal of RMP is to track the owner of

Re: [PATCH v1 3/3] KEYS: trusted: Introduce support for NXP CAAM-based trusted keys

2021-03-24 Thread James Bottomley
On Tue, 2021-03-23 at 14:07 -0400, Mimi Zohar wrote: > On Tue, 2021-03-23 at 17:35 +0100, Ahmad Fatoum wrote: > > Hello Horia, > > > > On 21.03.21 21:48, Horia Geantă wrote: > > > On 3/16/2021 7:02 PM, Ahmad Fatoum wrote: > > > [...] > > > > +struct trusted_key_ops caam_trusted_key_ops = { > > > >

[PATCH -next] crypto: hisilicon/hpre - fix build error without CONFIG_CRYPTO_ECDH

2021-03-24 Thread 'Wei Yongjun
From: Wei Yongjun GCC reports build error as following: x86_64-linux-gnu-ld: drivers/crypto/hisilicon/hpre/hpre_crypto.o: in function `hpre_ecdh_set_secret': hpre_crypto.c:(.text+0x269c): undefined reference to `crypto_ecdh_decode_key' Fix it by selecting CRYPTO_ECDH. Reported-by: Hulk Robot

Re: [PATCH v1 3/3] KEYS: trusted: Introduce support for NXP CAAM-based trusted keys

2021-03-24 Thread Ahmad Fatoum
Hello Sumit, On 24.03.21 11:47, Sumit Garg wrote: > On Wed, 24 Mar 2021 at 14:56, Ahmad Fatoum wrote: >> >> Hello Mimi, >> >> On 23.03.21 19:07, Mimi Zohar wrote: >>> On Tue, 2021-03-23 at 17:35 +0100, Ahmad Fatoum wrote: On 21.03.21 21:48, Horia Geantă wrote: > caam has random number ge

[PATCH v2 2/2] init/Kconfig: support sign module with SM2-with-SM3 algorithm

2021-03-24 Thread Tianjia Zhang
The kernel module signature supports the option to use the SM3 secure hash (OSCCA GM/T 0004-2012 SM3). SM2 and SM3 always appear in pairs. The former is used for signing and the latter is used for hash calculation. To sign a kernel module, first, prepare a configuration file openssl.cnf with the f

[PATCH v2 0/2] support sign module with SM2-with-SM3 algorithm

2021-03-24 Thread Tianjia Zhang
The kernel module signature supports the option to use the SM3 secure hash (OSCCA GM/T 0004-2012 SM3). SM2 and SM3 always appear in pairs. The former is used for signing and the latter is used for hash calculation. To sign a kernel module, first, prepare openssl 3.0.0 alpha6 and a configuration fi

[PATCH v2 1/2] pkcs7: make parser enable SM2 and SM3 algorithms combination

2021-03-24 Thread Tianjia Zhang
Support parsing the message signature of the SM2 and SM3 algorithm combination. This group of algorithms has been well supported. One of the main users is module signature verification. Signed-off-by: Tianjia Zhang --- crypto/asymmetric_keys/pkcs7_parser.c | 7 +++ 1 file changed, 7 insertio

Re: [PATCH v1 3/3] KEYS: trusted: Introduce support for NXP CAAM-based trusted keys

2021-03-24 Thread Sumit Garg
On Wed, 24 Mar 2021 at 14:56, Ahmad Fatoum wrote: > > Hello Mimi, > > On 23.03.21 19:07, Mimi Zohar wrote: > > On Tue, 2021-03-23 at 17:35 +0100, Ahmad Fatoum wrote: > >> On 21.03.21 21:48, Horia Geantă wrote: > >>> caam has random number generation capabilities, so it's worth using that > >>> by

Re: [PATCH] init/Kconfig: Support sign module with SM3 hash algorithm

2021-03-24 Thread Tianjia Zhang
Hi, On 3/24/21 6:14 AM, Ard Biesheuvel wrote: On Tue, 23 Mar 2021 at 09:36, Tianjia Zhang wrote: The kernel module signature supports the option to use the SM3 secure hash (OSCCA GM/T 0004-2012 SM3). Signed-off-by: Tianjia Zhang A secure hash is not the same as a signature. Looking at the

Re: [PATCH] init/Kconfig: Support sign module with SM3 hash algorithm

2021-03-24 Thread Tianjia Zhang
Hi, On 3/24/21 12:43 AM, Randy Dunlap wrote: On 3/23/21 1:35 AM, Tianjia Zhang wrote: The kernel module signature supports the option to use the SM3 secure hash (OSCCA GM/T 0004-2012 SM3). Signed-off-by: Tianjia Zhang --- Documentation/admin-guide/module-signing.rst | 5 +++-- crypto/asymm

Re: [PATCH v1 3/3] KEYS: trusted: Introduce support for NXP CAAM-based trusted keys

2021-03-24 Thread Ahmad Fatoum
Hello Mimi, On 23.03.21 19:07, Mimi Zohar wrote: > On Tue, 2021-03-23 at 17:35 +0100, Ahmad Fatoum wrote: >> On 21.03.21 21:48, Horia Geantă wrote: >>> caam has random number generation capabilities, so it's worth using that >>> by implementing .get_random. >> >> If the CAAM HWRNG is already seedi