Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2409210ybi; Mon, 17 Jun 2019 04:25:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqxVadQA5I2eixyq/FR1DZ5rnl1XgAFYTLxbemlD3I89Htrq7CU1dvoKZF4VhYuucRcHMlgM X-Received: by 2002:a62:5487:: with SMTP id i129mr107660336pfb.68.1560770738673; Mon, 17 Jun 2019 04:25:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560770738; cv=none; d=google.com; s=arc-20160816; b=vsdIDgtIlOvMKf1SBSap/c7+ZAOu8Sj7ZmNyCewPsaokk43/nsHnwwf6GMW652bH7P ZOXtVWKW9Qrb7PSVV/bHrz/5ofjEOoFBp/j6xEBQ7rKL+FYt48L7VtS/RI/Rhlk1GVc+ SIP3hCZLUNBt/KDNHTPN8UpkMsJ5VB17JI/13Kw1e8HRAoqLqaCThZTqPc9wNLB8/Prm 458ubBp6LvT5nixVUjY5V1ZyJNCIZPk/i77o4/O52CxZ4xmIBSholuvuKY/4eFq50xie Z/X9CE9ryI/SN1lXFD1oh7IGO6njmIRQFfaoJ9IlQUZwTxjy+H0Fpa7yIa9BByMHkWH1 PyeA== 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=9AwinP98tyRtHdg0mJkLa6bfVqgtL4TsktjuNz76Who=; b=b13gXuWcvh5XN5CizZn37gSiREnvQE3D91GsW8YaaJTjRfLtCyLwGUxFg2PrXak9tx KMFlkYDeGme+kjvSCsVo2bIxJ4kXxpwet4qa0c725VjPyhz0Fg3TsEjeGsEQOf4Wu7Z4 EjTlLxaH8tf5HzSXHDQd/5ygRmLbwkKq2ME46T1KC1SAzRWeO1Ye9USXEvmR2jvfOAYT fhrkX9q61igmqdTle7qCZ2LgBd47a4hS3xsixQHvpJ1MHraCYP1DLx94/xbL5jbodG5h AaQ+HvXRzx4KuUNrHNKlRmCWTPa4xuq5cp3Rqbq07qSZ8Fw6A0rbER36ILrF7TelXotl ZNtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=uV36HBJj; 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 x1si10066580pfb.45.2019.06.17.04.25.23; Mon, 17 Jun 2019 04:25:38 -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=uV36HBJj; 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 S1728289AbfFQLZH (ORCPT + 99 others); Mon, 17 Jun 2019 07:25:07 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:33070 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728234AbfFQLZD (ORCPT ); Mon, 17 Jun 2019 07:25:03 -0400 Received: by mail-ed1-f66.google.com with SMTP id i11so15693091edq.0 for ; Mon, 17 Jun 2019 04:25:02 -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=9AwinP98tyRtHdg0mJkLa6bfVqgtL4TsktjuNz76Who=; b=uV36HBJjLuM8IaSJ5lnIjDPz/NT6Ima0VTqA5XgxtXzYGLtD5Zk1oOFcZIOs5eNXNV pH0NKGr3K5PIEFLdfJ4QY5MASu8ZolMiISb4+T5+hLkqTyBzPrnUDdx/hU3vjrgigEg5 XFnoHWLNGGyz/u66QlR4uui8QiQ+svYc42qDT7NRAQYv6KgqnNwvy4xSWlxjmoYgo9KT ekxQsjh1gx+i56hFixjDbLIdHmzETZGZXB2016IB59YaBabg47ntq/77FeVXdTQW9Mw5 aQMao99SPvxYN97xvhncTxzUgIhypTKI32Gazqeb0JGoQgELhGOXdv5DquuY1RhnraGV TZKQ== 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=9AwinP98tyRtHdg0mJkLa6bfVqgtL4TsktjuNz76Who=; b=Hh0fXHvyyGlOL+yx6gorU0u74+e14eE4dRPlhYmNR0jNdJClC1OppF0Y1tPU3G2VJX gnBvf6QAYBNWlK9A2PFb6WPnqReQ/CBPFdCQu4j3XOxIx8Mbln+5nncEjIjJPyrYbqWh cEdZBV3BnJw09jSVOBJ8qo0ETDO7nLG4pMs/Q4U65NLG5T1/TMkGuj1o2O0Zg3PmZ0Q7 Cy7t6qUrvDcGpwCsygPEfjpW7rM3Vc4vsx5IL8wviw4bPQG9xm2n9q3f0mJCiiqJccHd 4e5loqv1V/rS3XOUHwMB203QcbBfMf7PFejNMeTsImUnxBlpbeXgGW9VrMhUtl6Dm1PD Alhg== X-Gm-Message-State: APjAAAXX5+gme083LugaOUybEH/NZZ86ui+Z0h1hWwEGl7RJ/qSdy7ev Zo8svikA1s9lg6Y/9B9rjRMY7g== X-Received: by 2002:a50:a48a:: with SMTP id w10mr11385422edb.1.1560770702235; Mon, 17 Jun 2019 04:25:02 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id w35sm1152436edd.32.2019.06.17.04.25.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Jun 2019 04:25:01 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id 122F1100F6D; Mon, 17 Jun 2019 14:25:00 +0300 (+03) Date: Mon, 17 Jun 2019 14:25:00 +0300 From: "Kirill A. Shutemov" To: Kai Huang Cc: Peter Zijlstra , "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 Subject: Re: [PATCH, RFC 49/62] mm, x86: export several MKTME variables Message-ID: <20190617112500.vmuu4kcjoep34hwe@box> 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> <1560760783.5187.10.camel@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1560760783.5187.10.camel@linux.intel.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 17, 2019 at 08:39:43PM +1200, Kai Huang wrote: > 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? Will do. -- Kirill A. Shutemov