From: Brijesh Singh Subject: Re: SEV guest regression in 4.18 Date: Fri, 24 Aug 2018 13:47:10 -0500 Message-ID: <47b8f9dc-fb55-f14d-cb88-343810ad5763@amd.com> References: <20ad6cd5-394c-d3ae-d99c-b656d7ef8293@amd.com> <20180821083911.GF24940@nazgul.tnic> <3d46f44c-dd78-8fa9-02ac-8206676ffde9@amd.com> <20180821151938.GA31212@nazgul.tnic> <92e2b80c-0dcc-94be-8d3a-5e11e5cf2370@amd.com> <20180822081417.GB4069@nazgul.tnic> <20180822150033.GA14200@linux.intel.com> <4d6ee892-a34f-28b3-18b7-1c663eb281c6@amd.com> <9635ebf0-7c99-6edf-1240-8dec28036a70@redhat.com> <20180823152907.GA1488@linux.intel.com> <60acb594-abe3-912f-9702-2f34961e575d@redhat.com> <25d2cf1f-11ee-ecba-73a9-15a9553a3d96@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Cc: brijesh.singh@amd.com, Borislav Petkov , "x86@kernel.org" , "linux-kernel@vger.kernel.org" , "kvm@vger.kernel.org" , "Lendacky, Thomas" , Thomas Gleixner To: Paolo Bonzini , Sean Christopherson Return-path: In-Reply-To: <25d2cf1f-11ee-ecba-73a9-15a9553a3d96@redhat.com> Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On 08/24/2018 10:50 AM, Paolo Bonzini wrote: > On 24/08/2018 17:41, Brijesh Singh wrote: >>>> >>>> Wouldn't that result in exposing/leaking whatever code/data happened >>>> to reside on the same 2M page (or corrupting it if the entire page >>>> isn't decrypted)?  Or are you suggesting that we'd also leave the >>>> encrypted mapping intact? >>> >>> Yes, exactly the latter, because... >> >> >> Hardware does not enforce coherency between the encrypted and >> unencrypted mapping for the same physical page. So, creating a >> two mapping of same physical address will lead a possible data >> corruption. >> >> Note, SME creates two mapping of the same physical address to perform >> in-place encryption of kernel and initrd images; this is a special case >> and APM documents steps on how to do this. > > Ah, so that's what I was thinking about. But a single cache line would > never be used both encrypted and unencrypted, would it? > No. If we create two mapping of same physical address and ensure that accesses are cache line aligned and size then I think we will safe from cache point of view. I have not tried early remap from kvmclock_init() yet and not sure if it will work so early. The downside of this approach is, we will put too many constraints on caller; it will need to ensure that variables are cache line aligned and sized, never accessed with C=1, and must create a new mapping before accessing it. I am more inclined towards creating a new section with PMD aligned and sized. This section will contains the decrypted data. In early boot code we will update the mapping with C=0. If caller wants to create a shared variable then it can do so with: static int foo __decrypted; I will submit patch fir review. thanks