Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5290372yba; Wed, 8 May 2019 10:45:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqw8UPTiETOH6+HudqLk+qGZxALNObTS7JR/i4mCRJ/ynFgwgDN8Fjag6JqLKFFvQ+QF3Z7R X-Received: by 2002:a63:ff0f:: with SMTP id k15mr47551259pgi.407.1557337542118; Wed, 08 May 2019 10:45:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557337542; cv=none; d=google.com; s=arc-20160816; b=acCCaazvbAW79cLFvjzfosHXk2BROZzAATdnsTfM8qd9NYJfYbHivxB2ZYTenocBhW E1GOIf7hxFP5kJ2yohuBFbX+iyWTvmMTqlXRWGA+sBhmsXIEss4C/asuUh74kYrdZ4w6 zSch4PpfhWT6gK2zqBpQQHu7A5C/L67PODQcgPHHiLj1cBG9LozLj8R7XlCjiR0IYzCf NdpEbx9xw2wFtjVLJn9k0A/5uJJxVpY9efak/fQcCpKwf0JIkdkUNHtRamcjAd6bQdAa t5Ohvh/v3M84Lx3wmTgNoul+ACiVl3ZNCBAcQuDE+XeljEdJaOkALqclQ+Bdidbxnf+W slaw== 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:message-id:date:subject:cc:to:from; bh=SVmYwDv3j5Zqu2stWHOAZhr/mhJK4ly92EXT5VclcOA=; b=b9dS3w2fOFQLAcNTz5LoK3LNLQ1u3ajUX9lMCVVxsfFVbSl7w14TqZlmFzaXE/bSyj ki9gh1ITXVRI9RNIyLvYgpN2v7af2Vt1sxtruSaT3hW5X4AnDj+0MddfDkogh0umWkN0 +fnTF8nLdIpjSWkss7Yg2Pu5G+/zJBsZAOIcqizJYI5xMv6+Q2LxyY35/Nzbkb77nusK DHxDV2OmMAQUdSaPy3TpVq8snuc+t2tJfq8uGpD6WJF+4lGpsPKpt/EUlUGiZCLfpOTE 0IK/yxifR4qh/TrXxBGLbdRdtPcT7FhYSYtarwyJYLZRkj/3Ef5h4pBOfRvvSYXfbCmY nLqA== 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 b12si785935pge.261.2019.05.08.10.45.26; Wed, 08 May 2019 10:45:42 -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 S1728794AbfEHOwC (ORCPT + 99 others); Wed, 8 May 2019 10:52:02 -0400 Received: from mga11.intel.com ([192.55.52.93]:7358 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728142AbfEHOok (ORCPT ); Wed, 8 May 2019 10:44:40 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 May 2019 07:44:39 -0700 X-ExtLoop1: 1 Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga004.fm.intel.com with ESMTP; 08 May 2019 07:44:35 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 58DEC858; Wed, 8 May 2019 17:44:29 +0300 (EEST) From: "Kirill A. Shutemov" To: Andrew Morton , x86@kernel.org, Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Borislav Petkov , Peter Zijlstra , Andy Lutomirski , David Howells Cc: 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, "Kirill A. Shutemov" Subject: [PATCH, RFC 14/62] x86/mm: Map zero pages into encrypted mappings correctly Date: Wed, 8 May 2019 17:43:34 +0300 Message-Id: <20190508144422.13171-15-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190508144422.13171-1-kirill.shutemov@linux.intel.com> References: <20190508144422.13171-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Zero pages are never encrypted. Keep KeyID-0 for them. Signed-off-by: Kirill A. Shutemov --- arch/x86/include/asm/pgtable.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 50b3e2d963c9..59c3dd50b8d5 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -803,6 +803,19 @@ static inline unsigned long pmd_index(unsigned long address) */ #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot)) +#define mk_zero_pte mk_zero_pte +static inline pte_t mk_zero_pte(unsigned long addr, pgprot_t prot) +{ + extern unsigned long zero_pfn; + pte_t entry; + + prot.pgprot &= ~mktme_keyid_mask; + entry = pfn_pte(zero_pfn, prot); + entry = pte_mkspecial(entry); + + return entry; +} + /* * the pte page can be thought of an array like this: pte_t[PTRS_PER_PTE] * @@ -1133,6 +1146,12 @@ static inline void ptep_set_wrprotect(struct mm_struct *mm, #define mk_pmd(page, pgprot) pfn_pmd(page_to_pfn(page), (pgprot)) +#define mk_zero_pmd(zero_page, prot) \ +({ \ + prot.pgprot &= ~mktme_keyid_mask; \ + pmd_mkhuge(mk_pmd(zero_page, prot)); \ +}) + #define __HAVE_ARCH_PMDP_SET_ACCESS_FLAGS extern int pmdp_set_access_flags(struct vm_area_struct *vma, unsigned long address, pmd_t *pmdp, -- 2.20.1