Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2388067ybi; Mon, 17 Jun 2019 04:04:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqzHpK90Lfsp6TCdJlrnLPq1uR10MOBSIAHg03MDLXof0OBPz6NIpUPlUVOeD855Jase686v X-Received: by 2002:a62:2ec4:: with SMTP id u187mr111497840pfu.84.1560769480055; Mon, 17 Jun 2019 04:04:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560769480; cv=none; d=google.com; s=arc-20160816; b=NLh+I4DiSG1sA3gdmtl73Dz+1XLq+8+stlTM4Pye+62s6q/XlUmnlZsi/6CeWM9g4D Dt9f6U6XhJQbQCLiMDVm0T74H8xM3PCPz0BD9KoAtPZrZ2WqDOh4fc1lKlQkIFWgnAJP 3USx39wjxg4Hg/ToM5cWiqKQt2CcjwEmMpaMb4TvopV8zQdPIF3ZTVBM8P/icOYEeRRw zQ4Ub0LjdkhSU3GXUN6iWhJxHxBPAS0lcgFFJwVX6Evx8hVkf/el4KzNdry1L3gWz3TP E1YSXAwFHm4SpgEv82La4I9B6Nsx3DKnJZIOr131mdSv0futAhy5PV8Km1FOoOeAZePx mzmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=OijPc0WWIfdOsltA5SOHD4hbuYIyRTxsd1+8sNjTtHk=; b=Tf6DrPJwZEhZmvqULxxGHU+Q6nrtVhXqQfNmcsAnjVaC7h5cTJZJCCR/2heL9FVkjr 6nHRAvQviPL65sNvARbF9DSuZqWDAwGUYNSwCuRhBg9ZV3qrttGUrVfFUxYFZlHXl+NO +e7VU93wsFlOu753khrPIVz0UtTR//ePXE0CVYQYvhE85JgcS25wRMYkGDcA31UZ2ved yefNbb4WeWiK6SqKH0CbBntWlwtl8rio6T33CwuLWO5ceSGC+Jj96qsU5NiPmxBbFhZo CfRQWH7EXuftLtN+XkjIj88u7tPzqFcqck49YanRN/vZdnxWE8v6xoQrjdx16i9bvRjf Gy/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=ecdcx5xI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 67si10947903plf.400.2019.06.17.04.04.23; Mon, 17 Jun 2019 04:04:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=ecdcx5xI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727653AbfFQLCu (ORCPT + 99 others); Mon, 17 Jun 2019 07:02:50 -0400 Received: from mail.skyhub.de ([5.9.137.197]:47556 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726174AbfFQLCt (ORCPT ); Mon, 17 Jun 2019 07:02:49 -0400 Received: from zn.tnic (p200300EC2F0613006087DD9CF534030C.dip0.t-ipconnect.de [IPv6:2003:ec:2f06:1300:6087:dd9c:f534:30c]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 600511EC0249; Mon, 17 Jun 2019 13:02:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1560769368; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=OijPc0WWIfdOsltA5SOHD4hbuYIyRTxsd1+8sNjTtHk=; b=ecdcx5xI9o4i+Zruw2Jkv8SaWdeKSbRo0kW3W5sAxfi2Mm0yXsU7Svn7y2GNa7OYHm7xj0 wEov1MZL0HcvVRSFSFGVMzgUgdpBppioXX0ycCOO1wSqtrqV1nVYiVEx7z5dWPG86o2F08 BLpu0+pEE+e7y0tx1sX3UhXLHjWxhKc= Date: Mon, 17 Jun 2019 13:02:41 +0200 From: Borislav Petkov To: "Lendacky, Thomas" Cc: "linux-kernel@vger.kernel.org" , "x86@kernel.org" , Thomas Gleixner , Ingo Molnar , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Baoquan He , Lianbo Jiang Subject: Re: [PATCH v2 2/2] x86/mm: Create an SME workarea in the kernel for early encryption Message-ID: <20190617110241.GH27127@zn.tnic> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 14, 2019 at 09:15:19PM +0000, Lendacky, Thomas wrote: > diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S > index ca2252ca6ad7..a7aa65b44c71 100644 > --- a/arch/x86/kernel/vmlinux.lds.S > +++ b/arch/x86/kernel/vmlinux.lds.S > @@ -387,6 +387,30 @@ SECTIONS > . = ALIGN(PAGE_SIZE); /* keep VO_INIT_SIZE page aligned */ > _end = .; > > +#ifdef CONFIG_AMD_MEM_ENCRYPT > + /* > + * SME workarea section: Lives outside of the kernel proper (_text - > + * _end) for performing in-place encryption of the kernel during boot. > + * > + * Resides after _end because even though the .brk section is after > + * __end_of_kernel_reserve, the .brk section is later reserved as a > + * part of the kernel. It is used in very early boot code and not > + * needed after that, so it is located after __end_of_kernel_reserve > + * so that it will be discarded and become part of the available > + * memory. > + * > + * Resides on a 2MB boundary to simplify the pagetable setup used for > + * the encryption. > + */ > + . = ALIGN(HPAGE_SIZE); > + .sme : AT(ADDR(.sme) - LOAD_OFFSET) { Should we call that section something more generic as .early_scratch or so? Someone else might need something like that too, in the future... Also, the DISCARDS sections do get freed at runtime so why not make it part of the DISCARD section...? > + __sme_begin = .; > + *(.sme) > + . = ALIGN(HPAGE_SIZE); > + __sme_end = .; > + } > +#endif > + > STABS_DEBUG > DWARF_DEBUG > > diff --git a/arch/x86/mm/mem_encrypt_identity.c b/arch/x86/mm/mem_encrypt_identity.c > index 4aa9b1480866..c55c2ec8fb12 100644 > --- a/arch/x86/mm/mem_encrypt_identity.c > +++ b/arch/x86/mm/mem_encrypt_identity.c > @@ -73,6 +73,19 @@ struct sme_populate_pgd_data { > unsigned long vaddr_end; > }; > > +/* > + * This work area lives in the .sme section, which lives outside of > + * the kernel proper. It is sized to hold the intermediate copy buffer > + * and more than enough pagetable pages. > + * > + * By using this section, the kernel can be encrypted in place and we replace that "we" with an impartial passive formulation. Other than that, I like the commenting, very helpful! Thx. -- Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.