From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mike Stunes Subject: Re: [PATCH 40/70] x86/sev-es: Setup per-cpu GHCBs for the runtime handler Date: Tue, 14 Apr 2020 19:03:44 +0000 Message-ID: References: <20200319091407.1481-1-joro@8bytes.org> <20200319091407.1481-41-joro@8bytes.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <20200319091407.1481-41-joro@8bytes.org> Content-Language: en-US Content-ID: Sender: kvm-owner@vger.kernel.org To: Joerg Roedel Cc: "x86@kernel.org" , "hpa@zytor.com" , Andy Lutomirski , Dave Hansen , Peter Zijlstra , Thomas Hellstrom , Jiri Slaby , Dan Williams , Tom Lendacky , Juergen Gross , Kees Cook , "linux-kernel@vger.kernel.org" , "kvm@vger.kernel.org" , "virtualization@lists.linux-foundation.org" , Joerg Roedel List-Id: virtualization@lists.linuxfoundation.org On Mar 19, 2020, at 2:13 AM, Joerg Roedel wrote: >=20 > From: Tom Lendacky >=20 > The runtime handler needs a GHCB per CPU. Set them up and map them > unencrypted. >=20 > Signed-off-by: Tom Lendacky > Signed-off-by: Joerg Roedel > --- > arch/x86/include/asm/mem_encrypt.h | 2 ++ > arch/x86/kernel/sev-es.c | 28 +++++++++++++++++++++++++++- > arch/x86/kernel/traps.c | 3 +++ > 3 files changed, 32 insertions(+), 1 deletion(-) >=20 > diff --git a/arch/x86/kernel/sev-es.c b/arch/x86/kernel/sev-es.c > index c17980e8db78..4bf5286310a0 100644 > --- a/arch/x86/kernel/sev-es.c > +++ b/arch/x86/kernel/sev-es.c > @@ -197,6 +203,26 @@ static bool __init sev_es_setup_ghcb(void) > return true; > } >=20 > +void sev_es_init_ghcbs(void) > +{ > + int cpu; > + > + if (!sev_es_active()) > + return; > + > + /* Allocate GHCB pages */ > + ghcb_page =3D __alloc_percpu(sizeof(struct ghcb), PAGE_SIZE); > + > + /* Initialize per-cpu GHCB pages */ > + for_each_possible_cpu(cpu) { > + struct ghcb *ghcb =3D (struct ghcb *)per_cpu_ptr(ghcb_page, cpu); > + > + set_memory_decrypted((unsigned long)ghcb, > + sizeof(*ghcb) >> PAGE_SHIFT); > + memset(ghcb, 0, sizeof(*ghcb)); > + } > +} > + set_memory_decrypted needs to check the return value. I see it consistently return ENOMEM. I've traced that back to split_large_page in arch/x86/mm/pat/set_memory.c.