Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp712185imm; Fri, 14 Sep 2018 05:19:20 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZiRy6i2VFNekhSeKWg+Utp5tmslnpzfTyBVyP9YX2eddIC4/XaNXQugdpNYBZFL2yQE/3I X-Received: by 2002:a17:902:bc8b:: with SMTP id bb11-v6mr11849377plb.112.1536927560016; Fri, 14 Sep 2018 05:19:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536927559; cv=none; d=google.com; s=arc-20160816; b=N3/zke9d5IIO2xI2K8rJXqniGBj3oPmqyY1EG/XwzZNFxK0Far5R58Kdl/+WYvFXzb Euj7QrcXN2MKRzw4HGqeCV6xGxDJcvEakbblks8VOFIsMRcbG8QpF5dijakweQRfNkkQ lgMsHO+XDRIflUSDAaVzg46QvjPgRfnuI12UoB62DXrq+VNTQZkSIhmJHV45TIYf0ppn 9iRIEJ9x+E8K4RtjzKlBj0TOeSxqDn8Nnj4F7WKkjc3G0akzF60h6RFVRapmBwCsX1i/ osTqu6bJEzOvLAsO0z2+FM1hTN+a837mdK4mohw2V/T+YfQHQAZ3WsdVj+02H/P5Q9az 3Caw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=Y6ZuLuUiKt7RUHe92kxMCF8HAho/0PEWZr7h7L3I1zM=; b=h6tk8AG6BEpcoiPSG9iG5wBt3sxHC+NcQ0gTuHIhp1kRmnJoA7rSc5VSVVWwJckE7d pPboH4jNLRZcUOrJjGUCiYqsG5Q8B9fZkO6d2EFNfmHayFpRaBg6QzEFEWjKXUb0frgH BkuHQRTJ4nlPlJswpvAnRy5SaHgMEImlfStex8QPyJy5/zTOrpi0/uLO7Avw8M1F7ggq jMvSdg6r3B5DfcY2+JuSnJHJ8cURT9Mu2WxrcGuoNyFEKPGP5QActjArM1bw9g1GCPgg My/vCqO7+PyYrGJhfFfBN/xOK/AlN/imSanXbaznBfBn/iXry7D1Uw+SxricDrDUxwZf YhZQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t22-v6si7218953pgj.546.2018.09.14.05.19.04; Fri, 14 Sep 2018 05:19:19 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728049AbeINRb3 (ORCPT + 99 others); Fri, 14 Sep 2018 13:31:29 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:49484 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726905AbeINRb2 (ORCPT ); Fri, 14 Sep 2018 13:31:28 -0400 Received: from hsi-kbw-5-158-153-52.hsi19.kabel-badenwuerttemberg.de ([5.158.153.52] helo=nanos.tec.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1g0n24-0005VW-0I; Fri, 14 Sep 2018 14:17:08 +0200 Date: Fri, 14 Sep 2018 14:17:05 +0200 (CEST) From: Thomas Gleixner To: Brijesh Singh cc: Borislav Petkov , x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Tom Lendacky , "H. Peter Anvin" , Paolo Bonzini , Sean Christopherson , =?ISO-8859-2?Q?Radim_Kr=E8m=E1=F8?= Subject: Re: [PATCH v8 1/2] x86/mm: add .bss..decrypted section to hold shared variables In-Reply-To: <3517a0db-2f64-6d09-7100-dced40561d08@amd.com> Message-ID: References: <1536875471-17391-1-git-send-email-brijesh.singh@amd.com> <1536875471-17391-2-git-send-email-brijesh.singh@amd.com> <20180914071056.GA4747@zn.tnic> <3517a0db-2f64-6d09-7100-dced40561d08@amd.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="8323329-358965675-1536927428=:10480" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-358965675-1536927428=:10480 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT On Fri, 14 Sep 2018, Brijesh Singh wrote: > On 9/14/18 2:10 AM, Borislav Petkov wrote: > >> /* > >> + * Clear the memory encryption mask from the .bss..decrypted section. > >> + * The bss section will be memset to zero later in the initialization so > >> + * there is no need to zero it after changing the memory encryption > >> + * attribute. > >> + */ > >> + if (mem_encrypt_active()) { > >> + vaddr = (unsigned long)__start_bss_decrypted; > >> + vaddr_end = (unsigned long)__end_bss_decrypted; > >> + for (; vaddr < vaddr_end; vaddr += PMD_SIZE) { > >> + i = pmd_index(vaddr); > >> + pmd[i] -= sme_get_me_mask(); > >> + } > >> + } > > Why isn't this chunk at the end of sme_encrypt_kernel() instead of here? > > The sme_encrypt_kernel() does not have access to pmd (after pointer > fixup is applied). You can extend the sme_encrypt_kernel() to pass an > additional arguments but then we start getting in include hell. The pmd > is defined as "pmdval_t". If we extend the sme_encrypt_kernel() thenĀ  > asm/mem_encrypt.h need to include the header file which defines > "pmdval_t". Adding the 'asm/pgtable_type.h' was causing all kind of > compilation errors. I didn't spend much time on it. IMO, we really don't > need to go in this path unless we see some value from doing this. Keep it here then. > >> @@ -345,6 +363,7 @@ SECTIONS > >> __bss_start = .; > >> *(.bss..page_aligned) > >> *(.bss) > >> + BSS_DECRYPTED > >> . = ALIGN(PAGE_SIZE); > >> __bss_stop = .; > > Putting it in the BSS would need a bit of care in the future as it poses > > a certain ordering on the calls in x86_64_start_kernel() (not that there > > isn't any now :)): > > > Hmm, I thought since we are explicitly saying that attribute will add > the variables in the bss section so caller should not be using the > variable before bss is ready. If you are concerns that clear_bss() may > get called after the variable is used then we could memset(0) when while > clearing the C-bit. I did try to add some comments when we are clearing > the C-bit. I can include some verbatim in BSS_DECRYPTED section as well. Nah. It's clearly marked __bss_decrypted and anything which stores data in a BSS location is busted whether thats .bss or .bss..decrypted. If someone is not aware about the BSS constraints in general, i.e. don't use it before clear_bss(), then I really can't help it. Thanks, tglx --8323329-358965675-1536927428=:10480--