Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3775739imm; Mon, 18 Jun 2018 04:00:18 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI8pHVzlnVTPBzLwzpa5J2tJyS6le7jV16rUhRfx7JPfth//L7cOM/o6Wmmpp59savj8WRD X-Received: by 2002:a62:cd82:: with SMTP id o124-v6mr13036905pfg.250.1529319618319; Mon, 18 Jun 2018 04:00:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529319618; cv=none; d=google.com; s=arc-20160816; b=iHkMJxIzCdmw4HhUSfnXXsdzZl035kHOa8w9OLwYHjEIYcuqIdZWT6pIkGF3mPfXDq xoyhl5XErpdeeY2pc7/ZpoKVjfZd9wzgzIE/l2jibvWZYv/bcSeBubPXQNeJOxpVTLiq W0ysxaUk92zUSfTckebTp7dJdcpbvBibhN10F6Q9TyyeYUE34MB11Ekrkrl6soNZZHv1 pCxuQ8GyjngSBoUhoxtzolb86Pm6DycZf3esYpp+rsTVecJcwMSaf2IZvHtKPPSlM0hf y4KDYKTmRktYiCMhHZ3Dk8J2paSZIuHQ1ypzdZ6kT5Hg9Kmpv+3JRUnWRa5s82SYo/YB zT+w== 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:arc-authentication-results; bh=D52vz4Xb5aJ5itarmFdRXKDNF1R2yWlJ4him1L6fkW4=; b=kCwzbpnTKeQ0pd/kgs0Db/Jd5Ac93LuyUc6pnYdifsfM8aVUpWU3Jn1cLd0NLd9s0U cHUNBpT/SDEXG5Lf2luf5s1nvmGifnYvVery8etf67j3Y7OO/3+INq7sM2u8Q8r7tdSG Le5DTOKUal2hOmKLTXvTpSuN9kYNA+cqThEdwvFEsCqOSiyL90VjMkO3N8lc0sHa64hH 7vQUJerScUW2ktgByYnMGqUB2Qz5cOwdg0ouzQ1Pbnu+IOpErhClIFcm/bJHXEpJ75Ze 8DV+hEgnkH8WUneXJDax2AhuqUeMy0F1MREzVVCNjaliHZMQrN163FkWpfdU3QT3OPhX Wo2A== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g12-v6si14382407pla.194.2018.06.18.04.00.04; Mon, 18 Jun 2018 04:00:18 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936935AbeFRKSc (ORCPT + 99 others); Mon, 18 Jun 2018 06:18:32 -0400 Received: from mga18.intel.com ([134.134.136.126]:26855 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933852AbeFRKSa (ORCPT ); Mon, 18 Jun 2018 06:18:30 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Jun 2018 03:18:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,238,1526367600"; d="scan'208";a="50188052" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga008.jf.intel.com with ESMTP; 18 Jun 2018 03:18:27 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id A9E03F8; Mon, 18 Jun 2018 13:18:28 +0300 (EEST) Date: Mon, 18 Jun 2018 13:18:28 +0300 From: "Kirill A. Shutemov" To: Dave Hansen Cc: Ingo Molnar , x86@kernel.org, Thomas Gleixner , "H. Peter Anvin" , Tom Lendacky , Kai Huang , Jacob Pan , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCHv3 10/17] x86/mm: Implement prep_encrypted_page() and arch_free_page() Message-ID: <20180618101828.hxp2dw3fmfxwk2ka@black.fi.intel.com> References: <20180612143915.68065-1-kirill.shutemov@linux.intel.com> <20180612143915.68065-11-kirill.shutemov@linux.intel.com> <36997c9c-73c0-1d9d-6251-10315a4158f0@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <36997c9c-73c0-1d9d-6251-10315a4158f0@intel.com> User-Agent: NeoMutt/20170714-126-deb55f (1.8.3) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 13, 2018 at 06:26:10PM +0000, Dave Hansen wrote: > On 06/12/2018 07:39 AM, Kirill A. Shutemov wrote: > > prep_encrypted_page() also takes care about zeroing the page. We have to > > do this after KeyID is set for the page. > > This is an implementation detail that has gone unmentioned until now but > has impacted at least half a dozen locations in previous patches. Can > you rectify that, please? It was mentioned in commit message of 04/17. > > +void prep_encrypted_page(struct page *page, int order, int keyid, bool zero) > > +{ > > + int i; > > + > > + /* > > + * The hardware/CPU does not enforce coherency between mappings of the > > + * same physical page with different KeyIDs or encrypt ion keys. > > What are "encrypt ion"s? :) :P > > + * We are responsible for cache management. > > + * > > + * We flush cache before allocating encrypted page > > + */ > > + clflush_cache_range(page_address(page), PAGE_SIZE << order); > > + > > + for (i = 0; i < (1 << order); i++) { > > + WARN_ON_ONCE(lookup_page_ext(page)->keyid); > > /* All pages coming out of the allocator should have KeyID 0 */ > Okay. > > + lookup_page_ext(page)->keyid = keyid; > > + /* Clear the page after the KeyID is set. */ > > + if (zero) > > + clear_highpage(page); > > + } > > +} > > How expensive is this? It just shifts cost of zeroing from page allocator here. It should not have huge effect. > > +void arch_free_page(struct page *page, int order) > > +{ > > + int i; > > > > /* KeyId-0 pages were not used for MKTME and need no work */ > > ... or something Okay. > > + if (!page_keyid(page)) > > + return; > > Is page_keyid() optimized so that all this goes away automatically when > MKTME is compiled out or unsupported? If MKTME is not enabled compile-time, this translation unit doesn't compile at all. I have not yet optimized for run-time unsupported case. I'll optimized it based on performance measurements. > > + for (i = 0; i < (1 << order); i++) { > > + WARN_ON_ONCE(lookup_page_ext(page)->keyid > mktme_nr_keyids); > > + lookup_page_ext(page)->keyid = 0; > > + } > > + > > + clflush_cache_range(page_address(page), PAGE_SIZE << order); > > +} > > > > -- Kirill A. Shutemov