Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2267463ybi; Mon, 17 Jun 2019 01:41:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqz3ojQ/Xe9/5sYGv72MYuNqVszeTZ35otjpyTmfvwq7VLPITdsXPAx2fyrFNAinqxSiHwDt X-Received: by 2002:a17:902:7687:: with SMTP id m7mr24711498pll.310.1560760894034; Mon, 17 Jun 2019 01:41:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560760894; cv=none; d=google.com; s=arc-20160816; b=hC4e0cvRsRdD7ArZ2LPpuSdAlfT+lvTAfnHYfp1xIaj5D/nCwymi9KezaRqSS9yrVy CuNLJsZVkFQRfmZcLQjYGWdxGj4bRa4Gr8c/r1uGv7YiXWIqmVN93oLbzMBYV+wBOZGY Ntrg/1J4KN2K3vRKu4Re/T1HvZVhoacEgXCIAlXkYq7ZkyIGeac1X5Uk/KPQistgw7Xv T2jD8mlCbRK6DJr7/NBxaLkYYfVOGuLhTAtmz2b2LgB9KcbL3U3YrNHq39/9KeB4Aa1/ OfRNbBSTIfGMgGtcZC1m9fIVRKbVj0cvtlVEOucDrwb6+F4gAZoVpQs3RHESVX/JSwFK /xoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id; bh=09I/l5lGJSa8tFtbjVCJVSuLA6OoWE0rPIDLnXVXKpQ=; b=vEyPAxV+80XzjObc0PEGRb9RbMiCv6GkXYxf0wbnWSEHo/MYSXNi+dH7tGF/q7pynn 88PEipONmyqkez22sBNuY7J8RSdmvvLItrVdWi5/dPKKa9/BXV30zfa2HWRTIZtL+ve4 2rvBiz4qw9ZQH3MDTNxlh3m3UzYTCKoX4DNQsnrQTPBSF/JWnWeLieMCenex81s/SXKE znAHjcRswZlnhzYJztHztS8eSTFU0OCjyRqnA7zJLkU7K6+fqIgSGDh15pZdKaDQ6ctN tgSP8Ayq7qAstXOIbtd0wFG7/o3SbhsU62mD+IEsHScq+3X13iY4EKS94fNm6NNySqNU ZpZA== 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 d2si9267204plo.21.2019.06.17.01.41.17; Mon, 17 Jun 2019 01:41:34 -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 S1727749AbfFQIjs (ORCPT + 99 others); Mon, 17 Jun 2019 04:39:48 -0400 Received: from mga04.intel.com ([192.55.52.120]:3979 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725837AbfFQIjs (ORCPT ); Mon, 17 Jun 2019 04:39:48 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Jun 2019 01:39:47 -0700 X-ExtLoop1: 1 Received: from khuang2-desk.gar.corp.intel.com ([10.255.91.82]) by fmsmga005.fm.intel.com with ESMTP; 17 Jun 2019 01:39:44 -0700 Message-ID: <1560760783.5187.10.camel@linux.intel.com> Subject: Re: [PATCH, RFC 49/62] mm, x86: export several MKTME variables From: Kai Huang To: Peter Zijlstra 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 , Jacob Pan , Alison Schofield , linux-mm@kvack.org, kvm@vger.kernel.org, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org Date: Mon, 17 Jun 2019 20:39:43 +1200 In-Reply-To: <20190617074643.GW3436@hirez.programming.kicks-ass.net> References: <20190508144422.13171-1-kirill.shutemov@linux.intel.com> <20190508144422.13171-50-kirill.shutemov@linux.intel.com> <20190614115647.GI3436@hirez.programming.kicks-ass.net> <1560741269.5187.7.camel@linux.intel.com> <20190617074643.GW3436@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.24.6 (3.24.6-1.fc26) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2019-06-17 at 09:46 +0200, Peter Zijlstra wrote: > On Mon, Jun 17, 2019 at 03:14:29PM +1200, Kai Huang wrote: > > On Fri, 2019-06-14 at 13:56 +0200, Peter Zijlstra wrote: > > > On Wed, May 08, 2019 at 05:44:09PM +0300, Kirill A. Shutemov wrote: > > > > From: Kai Huang > > > > > > > > KVM needs those variables to get/set memory encryption mask. > > > > > > > > Signed-off-by: Kai Huang > > > > Signed-off-by: Kirill A. Shutemov > > > > --- > > > > arch/x86/mm/mktme.c | 3 +++ > > > > 1 file changed, 3 insertions(+) > > > > > > > > diff --git a/arch/x86/mm/mktme.c b/arch/x86/mm/mktme.c > > > > index df70651816a1..12f4266cf7ea 100644 > > > > --- a/arch/x86/mm/mktme.c > > > > +++ b/arch/x86/mm/mktme.c > > > > @@ -7,13 +7,16 @@ > > > > > > > > /* Mask to extract KeyID from physical address. */ > > > > phys_addr_t mktme_keyid_mask; > > > > +EXPORT_SYMBOL_GPL(mktme_keyid_mask); > > > > /* > > > > * Number of KeyIDs available for MKTME. > > > > * Excludes KeyID-0 which used by TME. MKTME KeyIDs start from 1. > > > > */ > > > > int mktme_nr_keyids; > > > > +EXPORT_SYMBOL_GPL(mktme_nr_keyids); > > > > /* Shift of KeyID within physical address. */ > > > > int mktme_keyid_shift; > > > > +EXPORT_SYMBOL_GPL(mktme_keyid_shift); > > > > > > > > DEFINE_STATIC_KEY_FALSE(mktme_enabled_key); > > > > EXPORT_SYMBOL_GPL(mktme_enabled_key); > > > > > > NAK, don't export variables. Who owns the values, who enforces this? > > > > > > > Both KVM and IOMMU driver need page_keyid() and mktme_keyid_shift to set page's keyID to the > > right > > place in the PTE (of KVM EPT and VT-d DMA page table). > > > > MKTME key type code need to know mktme_nr_keyids in order to alloc/free keyID. > > > > Maybe better to introduce functions instead of exposing variables directly? > > > > Or instead of introducing page_keyid(), we use page_encrypt_mask(), which essentially holds > > "page_keyid() << mktme_keyid_shift"? > > Yes, that's much better, because that strictly limits the access to R/O. > Thanks. I think Kirill will be the one to handle your suggestion. :) Kirill? Thanks, -Kai