Received: by 10.213.65.68 with SMTP id h4csp1595994imn; Thu, 29 Mar 2018 07:35:23 -0700 (PDT) X-Google-Smtp-Source: AIpwx49oLOuMl4prc2oJQack6doc1bbhGTcOgQYANljM83qnvbbXGQvlt6TFEeNWiJqsbQ58OMhU X-Received: by 10.98.224.93 with SMTP id f90mr6541555pfh.21.1522334123886; Thu, 29 Mar 2018 07:35:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522334123; cv=none; d=google.com; s=arc-20160816; b=eBHOpSzpB128Jeqr8NFYOCmWm2Egy2rMIHsH09TUyzPPVFpncLu6M+uuCKyPop9Vkr 5W0Q8YQi5UEvfa2eSuzwqpOAqSc7w7dUizA8wAa5Ao40vEZ+5oYOhamkwyrlqGlLMXKF 278miGmeIKyNrQ7RpPjhu++UQRym94kgmBQf5z4YBwtqeF9+M3R53jUwYA+wE8JB4bLO 3qMtGrxK6s3s6ylLEMZKKWk9gf7qAlSeVXzT43jU7jxN9UM0IuLSWdjnJQlUM/FhzTdk EJQqSyzPeEJqLVbZR0py8hfqpEU2dwa3x6rp0qUin2KfC9QCqPdD9h1YCW1R2obJW+eV 2YGA== 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:arc-authentication-results; bh=xAL0o4j1+4RpfC5cAcjmgDWhyP32Ng1TB113DYS7VXU=; b=c5FYDGYAbZQo4a49paIxgHnx4Wb8kX2ReFW5QNsKxaZ1prdejH9jzGRNnInJDz4n5y 64P1Duo5VDhCQWRQNjPxoKhwy/7J/TIGR7rHV3Dyih85PAr/awebQ5ft6k9J2TKV5S/R 6sorMuY0kYIBnrklDFiOadz5bpzr4rnzB4pCPMJB2HK8Oce+nl1OardZhT/IIAz+XM2J fBmaFyvuOB4QPXteXJvRjxHQDN9E9AUA8D4m5kucn0QC3FNOtuXPFMD5SiTxXyW9CLw7 ghhw6EEd8MW861sjsNp0yR3CFJS2D4PUiv+zV612Oshjxq8bTpJed1yNeYNNdcdBrsjE X62g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=Rd1ZE4dm; 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 o65si4712569pfj.144.2018.03.29.07.35.08; Thu, 29 Mar 2018 07:35:23 -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=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=Rd1ZE4dm; 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 S1751230AbeC2Odz (ORCPT + 99 others); Thu, 29 Mar 2018 10:33:55 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:51668 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751096AbeC2Ody (ORCPT ); Thu, 29 Mar 2018 10:33:54 -0400 Received: by mail-wm0-f65.google.com with SMTP id v21so11249541wmc.1 for ; Thu, 29 Mar 2018 07:33:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=xAL0o4j1+4RpfC5cAcjmgDWhyP32Ng1TB113DYS7VXU=; b=Rd1ZE4dmh0vNi36pa4BAKWV03ViKetMO8PmpZTNNUAJoOcz5M2yexMg1gvNMZdt2He L2YwLfqQdSeFF1KYAWlS/rgk/K/n2gtXBal6+W517OxtmrLqFR3Hgh3LVvEyKTEaox5t FYUY7KfWT80H93D+XGTs+bcXyJ1h3oZ3V7BbGXyMEbnSxApu/CwMGlPP+IQEMy6osSte 9twNGvcEqCSWp4f+u/iWO8P0A/ehvzU9bq5bGGOO/34rIrdPyr2GUGZI0R84uNrUxK3Z FQk9V0JckJ0mQ8Ht2e+yRrzo8pNnSe2NGeRd3H9GFsc6koFaa2TBkrmWOGGemlbwZHkH iWiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=xAL0o4j1+4RpfC5cAcjmgDWhyP32Ng1TB113DYS7VXU=; b=C+llKQPSqRq5KjfwvWvlfZ5cFgBEPTqsDms3VOaRHuEQdQ5NwS6dubVmijasz/Xdbb TxVAE4Yhe4Kh5gc41Vrjp5k7lcPW5lK4ob20LOWdzA1bzMGry4dXVtDc1kDE0XIcpMvc KDiwFPphpnE6fGmnXQ23fmNZr7EAux6kdGFlM4FG8vUIQxcioj3Z5265OAyQioaOTJXh cBnA/CVbYqhBV0202XKeQAh7U+o+Pz94R+9mnWepeEe0wO1X5/qgMWHtNougmcoOLoPs s+FHSvsWMhPCgBnwMkZlsnvJgRwhLRjo73FtxG0LIjSAij8j+09WrkJMknbhwdqmR87Y O7ZA== X-Gm-Message-State: AElRT7EsFXi0qNaFCniOWL7VlFI0UbOaPvoy143XnupGeblmdIzVqC2U Bj8ua7rGqqOPuMhBWFaX7r/7FQ== X-Received: by 10.80.158.169 with SMTP id a38mr7775051edf.78.1522334032923; Thu, 29 Mar 2018 07:33:52 -0700 (PDT) Received: from node.shutemov.name ([178.124.220.81]) by smtp.gmail.com with ESMTPSA id y15sm3984036edm.95.2018.03.29.07.33.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Mar 2018 07:33:51 -0700 (PDT) Received: by node.shutemov.name (Postfix, from userid 1000) id 5F2BB648D520; Thu, 29 Mar 2018 17:33:16 +0300 (+03) Date: Thu, 29 Mar 2018 17:33:16 +0300 From: "Kirill A. Shutemov" To: Michal Hocko Cc: "Kirill A. Shutemov" , Ingo Molnar , x86@kernel.org, Thomas Gleixner , "H. Peter Anvin" , Tom Lendacky , Dave Hansen , Kai Huang , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCHv2 06/14] mm/page_alloc: Propagate encryption KeyID through page allocator Message-ID: <20180329143316.2qreoaw6dng2kvct@node.shutemov.name> References: <20180328165540.648-1-kirill.shutemov@linux.intel.com> <20180328165540.648-7-kirill.shutemov@linux.intel.com> <20180329112034.GE31039@dhcp22.suse.cz> <20180329123712.zlo6qmstj3zm5v27@node.shutemov.name> <20180329125227.GF31039@dhcp22.suse.cz> <20180329131308.cq64n3dvnre2wcz5@node.shutemov.name> <20180329133700.GG31039@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180329133700.GG31039@dhcp22.suse.cz> User-Agent: NeoMutt/20180223 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 29, 2018 at 03:37:00PM +0200, Michal Hocko wrote: > On Thu 29-03-18 16:13:08, Kirill A. Shutemov wrote: > > On Thu, Mar 29, 2018 at 02:52:27PM +0200, Michal Hocko wrote: > > > On Thu 29-03-18 15:37:12, Kirill A. Shutemov wrote: > > > > On Thu, Mar 29, 2018 at 01:20:34PM +0200, Michal Hocko wrote: > > > > > On Wed 28-03-18 19:55:32, Kirill A. Shutemov wrote: > > > > > > Modify several page allocation routines to pass down encryption KeyID to > > > > > > be used for the allocated page. > > > > > > > > > > > > There are two basic use cases: > > > > > > > > > > > > - alloc_page_vma() use VMA's KeyID to allocate the page. > > > > > > > > > > > > - Page migration and NUMA balancing path use KeyID of original page as > > > > > > KeyID for newly allocated page. > > > > > > > > > > I am sorry but I am out of time to look closer but this just raised my > > > > > eyebrows. This looks like a no-go. The basic allocator has no business > > > > > in fancy stuff like a encryption key. If you need something like that > > > > > then just build a special allocator API on top. This looks like a no-go > > > > > to me. > > > > > > > > The goal is to make memory encryption first class citizen in memory > > > > management and not to invent parallel subsysustem (as we did with hugetlb). > > > > > > How do you get a page_keyid for random kernel allocation? > > > > Initial feature enabling only targets userspace anonymous memory, but we > > can definately use the same technology in the future for kernel hardening > > if we would choose so. > > So what kind of key are you going to use for those allocations. KeyID zero is default. You can think about this as do-not-encrypt. In MKTME case it means that this memory is encrypted with TME key (random generated at boot). > Moreover why cannot you simply wrap those few places which are actually > using the encryption now? We can wrap these few places. And I tried this approach. It proved to be slow. Hardware doesn't enforce coherency between mappings of the same physical page with different KeyIDs. OS is responsible for cache management: the cache has flushed before switching the page to other KeyID. As we allocate encrypted and unencrypted pages from the same pool, the approach with wrapper forces us to flush cache on allocation (to switch it non-zero KeyID) *and* freeing (to switch it back to KeyID-0) encrypted page. We don't know if the page will be allocated next time using wrapper or not, so we have to play safe. This way it's about 4-6 times slower to allocate-free encrypted page comparing to unencrypted one. On macrobenchmark, I see about 15% slowdown. With approach I propose we can often avoid cache flushing: we can only flush the cache on allocation and only if the page had different KeyID last time it was allocated. It brings slowdown on macrobenchmark to 3.6% which is more reasonable (more optimizations possible). Other way to keep separate pool of encrypted pages within page allocator. I think it would cause more troubles... I would be glad to find less intrusive way to get reasonable performance. Any suggestions? > > For anonymous memory, we can get KeyID from VMA or from other page > > (migration case). > > > > > > Making memory encryption integral part of Linux VM would involve handing > > > > encrypted page everywhere we expect anonymous page to appear. > > > > > > How many architectures will implement this feature? > > > > I can't read the future. > > Fair enough, only few of us can, but you are proposing a generic code > changes based on a single architecture design so we should better make > sure other architectures can work with that approach without a major > refactoring. I tried to keep the implementation as generic as possible: VMA may be encrypted, you can point to deseried key with an integer (KeyID), allocation of encrypted page *may* require special handling. Ther only assumption I made is that KeyID 0 is special, meaning no-encryption. I think it's reasonable assumption, but easily fixable if proved to be wrong. If you see other places I made the abstaction too tied to specific HW implementation, let me know. -- Kirill A. Shutemov