From: Sean Christopherson <sean.j.christopherson@intel.com>
To: Borislav Petkov <bp@suse.de>
Cc: "Brijesh Singh" <brijesh.singh@amd.com>,
x86@kernel.org, linux-kernel@vger.kernel.org,
kvm@vger.kernel.org, "Tom Lendacky" <thomas.lendacky@amd.com>,
"Thomas Gleixner" <tglx@linutronix.de>,
"H. Peter Anvin" <hpa@zytor.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Radim Krčmář" <rkrcmar@redhat.com>
Subject: Re: [PATCH v5 5/5] x86/kvm: Avoid dynamic allocation of pvclock data when SEV is active
Date: Thu, 6 Sep 2018 06:50:41 -0700 [thread overview]
Message-ID: <20180906135041.GB32336@linux.intel.com> (raw)
In-Reply-To: <20180906122423.GA11144@zn.tnic>
On Thu, Sep 06, 2018 at 02:24:23PM +0200, Borislav Petkov wrote:
> On Thu, Sep 06, 2018 at 06:43:02AM -0500, Brijesh Singh wrote:
> > Currently, the per-cpu pvclock data is allocated dynamically when
> > cpu > HVC_BOOT_ARRAY_SIZE. The physical address of this variable is
> > shared between the guest and the hypervisor hence it must be mapped as
> > unencrypted (ie. C=0) when SEV is active.
> >
> > When SEV is active, we will be wasting fairly sizeable amount of memory
> > since each CPU will be doing a separate 4k allocation so that it can clear
> > C-bit. Let's define few extra static page sized array of pvclock data.
> > In the preparatory stage of CPU hotplug, use the element of this static
> > array to avoid the dynamic allocation. This array will be put in
> > the .data..decrypted section so that its mapped with C=0 during the boot.
> >
> > In non-SEV case, this static page will unused and free'd by the
> > free_decrypted_mem().
> >
> > Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
> > Suggested-by: Sean Christopherson <sean.j.christopherson@intel.com>
> > Cc: Tom Lendacky <thomas.lendacky@amd.com>
> > Cc: kvm@vger.kernel.org
> > Cc: Thomas Gleixner <tglx@linutronix.de>
> > Cc: Borislav Petkov <bp@suse.de>
> > Cc: "H. Peter Anvin" <hpa@zytor.com>
> > Cc: linux-kernel@vger.kernel.org
> > Cc: Paolo Bonzini <pbonzini@redhat.com>
> > Cc: Sean Christopherson <sean.j.christopherson@intel.com>
> > Cc: kvm@vger.kernel.org
> > Cc: "Radim Krčmář" <rkrcmar@redhat.com>
> > ---
> > arch/x86/include/asm/mem_encrypt.h | 4 ++++
> > arch/x86/kernel/kvmclock.c | 22 +++++++++++++++++++---
> > arch/x86/kernel/vmlinux.lds.S | 3 +++
> > arch/x86/mm/init.c | 3 +++
> > arch/x86/mm/mem_encrypt.c | 10 ++++++++++
> > 5 files changed, 39 insertions(+), 3 deletions(-)
> >
> > diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h
> > index 802b2eb..aa204af 100644
> > --- a/arch/x86/include/asm/mem_encrypt.h
> > +++ b/arch/x86/include/asm/mem_encrypt.h
> > @@ -48,11 +48,13 @@ int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long size);
> >
> > /* Architecture __weak replacement functions */
> > void __init mem_encrypt_init(void);
> > +void __init free_decrypted_mem(void);
> >
> > bool sme_active(void);
> > bool sev_active(void);
> >
> > #define __decrypted __attribute__((__section__(".data..decrypted")))
> > +#define __decrypted_hvclock __attribute__((__section__(".data..decrypted_hvclock")))
>
> So are we going to be defining a decrypted section for every piece of
> machinery now?
>
> That's a bit too much in my book.
>
> Why can't you simply free everything in .data..decrypted on !SVE guests?
That would prevent adding __decrypted to existing declarations, e.g.
hv_clock_boot, which would be ugly in its own right. A more generic
solution would be to add something like __decrypted_exclusive to mark
data that is used if and only if SEV is active, and then free the
SEV-only data when SEV is disabled.
Originally, my thought was that this would be a one-off case and the
array could be freed directly in kvmclock_init(), e.g.:
static struct pvclock_vsyscall_time_info
hv_clock_aux[HVC_AUX_ARRAY_SIZE] __decrypted __aligned(PAGE_SIZE);
...
void __init kvmclock_init(void)
{
u8 flags;
if (!sev_active())
free_init_pages("unused decrypted",
(unsigned long)hv_clock_aux,
(unsigned long)hv_clock_aux + sizeof(hv_clock_aux));
>
> --
> Regards/Gruss,
> Boris.
>
> SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
> --
next prev parent reply other threads:[~2018-09-06 13:50 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-06 11:42 [PATCH v5 0/5] x86: Fix SEV guest regression Brijesh Singh
2018-09-06 11:42 ` [PATCH v5 1/5] x86/mm: Restructure sme_encrypt_kernel() Brijesh Singh
2018-09-06 11:42 ` [PATCH v5 2/5] x86/mm: fix sme_populate_pgd() to update page flags Brijesh Singh
2018-09-06 11:43 ` [PATCH v5 3/5] x86/mm: add .data..decrypted section to hold shared variables Brijesh Singh
2018-09-06 11:43 ` [PATCH v5 4/5] x86/kvm: use __decrypted attribute in " Brijesh Singh
2018-09-06 11:43 ` [PATCH v5 5/5] x86/kvm: Avoid dynamic allocation of pvclock data when SEV is active Brijesh Singh
2018-09-06 12:24 ` Borislav Petkov
2018-09-06 13:50 ` Sean Christopherson [this message]
2018-09-06 14:18 ` Sean Christopherson
2018-09-06 14:44 ` Borislav Petkov
2018-09-06 18:37 ` Brijesh Singh
2018-09-06 18:47 ` Sean Christopherson
2018-09-06 19:24 ` Brijesh Singh
2018-09-06 19:46 ` Brijesh Singh
2018-09-06 19:47 ` Sean Christopherson
2018-09-06 20:20 ` Brijesh Singh
2018-09-06 20:39 ` Sean Christopherson
2018-09-06 21:56 ` Brijesh Singh
2018-09-06 14:43 ` Borislav Petkov
2018-09-06 14:56 ` Sean Christopherson
2018-09-06 15:19 ` Borislav Petkov
2018-09-06 15:54 ` Sean Christopherson
2018-09-06 18:33 ` Borislav Petkov
2018-09-06 18:43 ` Brijesh Singh
2018-09-06 18:45 ` Sean Christopherson
2018-09-06 19:03 ` Borislav Petkov
2018-09-06 17:50 ` Brijesh Singh
2018-09-06 14:07 ` Sean Christopherson
2018-09-06 18:50 ` Brijesh Singh
2018-09-07 3:57 ` Brijesh Singh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180906135041.GB32336@linux.intel.com \
--to=sean.j.christopherson@intel.com \
--cc=bp@suse.de \
--cc=brijesh.singh@amd.com \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=rkrcmar@redhat.com \
--cc=tglx@linutronix.de \
--cc=thomas.lendacky@amd.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).