Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp985382ybi; Fri, 14 Jun 2019 06:45:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqwkNJLDQ3EmBHzRqElGvbF5hSLvEAaqGlcNanqv6tA57ogiNpSYt7XQpg/0r/DDkAOrOtA5 X-Received: by 2002:a17:902:8609:: with SMTP id f9mr86869642plo.252.1560519925231; Fri, 14 Jun 2019 06:45:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560519925; cv=none; d=google.com; s=arc-20160816; b=Mb9/p8GkpFQ6lb78rtyQ/jotSFE32FpsBpRmxB6P6IpU6644k3D71jWWi6BZbmm4lq tc7iAEeVE0R70hvKS0ZrrxOcnRwJBgJwDpguxNMMHoHsHYI9SoM69v5IEBJftNxxIuq5 ekw6e3c6oiw0AIBMOw6tDbU470A5/8lAuqnkvebbzpGjsu43hIIbcymml1F+aeMAbxsF RKcn1g/SsJV1dujTlrF8d197PkV5AOOOQXtosHwyCe3u72saWnm2QAIMtS5WtjUDyL2a EFsCZsUxXiGQpExwRba5hw88k3kx4wBTAsmWYdzVRDwYtroFL73KZLsb0mkQ+gUhoQ7T gB1Q== 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=CEpLzxWl0gVhhE2loe/wZNC7HEFBNtusAecwnKLSC9Y=; b=Px7qVo/QEK602hfWMaBikgk8tXaJB3duiU7YsQAgTJn+Onqi6kAv9HC2oI+Iy/ADie 9wrqIOQ0YMxoHzXCMZY+civ9cKVV+lYQJoTKDHSFk3uEr1BuM1mTAH/ueAXEVOk0KiWK 42Kf0laR/g0ddaYJrrpgU7Gzm2xLE3RdbLBTeW3HGQoVVIrC0OR2vvkQ6BobizJi9iPb tNUsyL0UgyIBXw8v4nKrbMc/RcQnEQ4MLlCxN6IEnoLkJbwoBWejK+P0OZLpHBtVdQ/o xrcKHR25DrnLXtxrI64VXm1XnYve26vAWFyM/A2l9kkCIZkihrq7lzrUUi7Y8XTKjI7q Akig== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=wJWUaH4K; 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 x9si2230226pll.347.2019.06.14.06.45.09; Fri, 14 Jun 2019 06:45:25 -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=fail header.i=@infradead.org header.s=merlin.20170209 header.b=wJWUaH4K; 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 S1728432AbfFNNnt (ORCPT + 99 others); Fri, 14 Jun 2019 09:43:49 -0400 Received: from merlin.infradead.org ([205.233.59.134]:39208 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727979AbfFNNnr (ORCPT ); Fri, 14 Jun 2019 09:43:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=CEpLzxWl0gVhhE2loe/wZNC7HEFBNtusAecwnKLSC9Y=; b=wJWUaH4KBhaf6FksZmx6YleNS SqJt2t24BqEHD50uiboct62KgbUmDCuQAqSNqCr87Vaizsbh9ww1KCcI+top6ZWkFHX3dyskStBzq UIViB3eY+V4668fgqSO5LtEzseW5ElzpJsd3aNvCMF/RVO9Lg/DIm9iLz357FOEQ+WxQ4pw2Q077W kf4mJRIvgRsBYqbPyY7CtR7XUwXqeFv4KrkG8WnWDVb7ouPheOhasUPP57/2hdI+uSHSKuH4XsfuR +Si9/YiEQVF9qWr46i2A8Hr8Uzh3Su4WRqmqOee1TLNOHja45yFHb/hTiCA++kVXKwxYFFWwXNFqx pH+R4j+Fg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1hbmUS-00087g-TV; Fri, 14 Jun 2019 13:43:37 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 983BF20292FD5; Fri, 14 Jun 2019 15:43:35 +0200 (CEST) Date: Fri, 14 Jun 2019 15:43:35 +0200 From: Peter Zijlstra To: "Kirill A. Shutemov" Cc: "Kirill A. Shutemov" , Andrew Morton , x86@kernel.org, Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Borislav Petkov , Andy Lutomirski , David Howells , Kees Cook , Dave Hansen , Kai Huang , Jacob Pan , Alison Schofield , linux-mm@kvack.org, kvm@vger.kernel.org, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH, RFC 13/62] x86/mm: Add hooks to allocate and free encrypted pages Message-ID: <20190614134335.GU3436@hirez.programming.kicks-ass.net> References: <20190508144422.13171-1-kirill.shutemov@linux.intel.com> <20190508144422.13171-14-kirill.shutemov@linux.intel.com> <20190614093409.GX3436@hirez.programming.kicks-ass.net> <20190614110458.GN3463@hirez.programming.kicks-ass.net> <20190614132836.spl6bmk2kkx65nfr@box> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190614132836.spl6bmk2kkx65nfr@box> 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 04:28:36PM +0300, Kirill A. Shutemov wrote: > On Fri, Jun 14, 2019 at 01:04:58PM +0200, Peter Zijlstra wrote: > > On Fri, Jun 14, 2019 at 11:34:09AM +0200, Peter Zijlstra wrote: > > > On Wed, May 08, 2019 at 05:43:33PM +0300, Kirill A. Shutemov wrote: > > > > > > > + lookup_page_ext(page)->keyid = keyid; > > > > > > + lookup_page_ext(page)->keyid = 0; > > > > Also, perhaps paranoid; but do we want something like: > > > > static inline void page_set_keyid(struct page *page, int keyid) > > { > > /* ensure nothing creeps after changing the keyid */ > > barrier(); > > WRITE_ONCE(lookup_page_ext(page)->keyid, keyid); > > barrier(); > > /* ensure nothing creeps before changing the keyid */ > > } > > > > And this is very much assuming there is no concurrency through the > > allocator locks. > > There's no concurrency for this page: it has been off the free list, but > have not yet passed on to user. Nobody else sees the page before > allocation is finished. > > And barriers/WRITE_ONCE() looks excessive to me. It's just yet another bit > of page's metadata and I don't see why it's has to be handled in a special > way. > > Does it relax your paranoia? :P Not really, it all 'works' because clflush_cache_range() includes mb() and page_address() has an address dependency on the store, and there are no other sites that will ever change 'keyid', which is all kind of fragile. At the very least that should be explicitly called out in a comment.