From patchwork Tue Jun 26 14:22:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "kirill.shutemov@linux.intel.com" X-Patchwork-Id: 10489165 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 03C3A6031B for ; Tue, 26 Jun 2018 14:23:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E652E28A58 for ; Tue, 26 Jun 2018 14:23:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DAE9128A68; Tue, 26 Jun 2018 14:23:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7677B28A58 for ; Tue, 26 Jun 2018 14:23:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 969196B0007; Tue, 26 Jun 2018 10:22:57 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 91DF56B0273; Tue, 26 Jun 2018 10:22:57 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5BB696B026E; Tue, 26 Jun 2018 10:22:57 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg0-f71.google.com (mail-pg0-f71.google.com [74.125.83.71]) by kanga.kvack.org (Postfix) with ESMTP id 109256B0272 for ; Tue, 26 Jun 2018 10:22:57 -0400 (EDT) Received: by mail-pg0-f71.google.com with SMTP id j13-v6so6511272pgp.16 for ; Tue, 26 Jun 2018 07:22:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=eX4hOL6mdxo8wovE4LKiTmPsdPR3/h2k6AOvEOcUYBA=; b=VlCCJybPuD++3r1ffEYiQKEUSmBD+0/w5a20bvgLDWf3n9Rrh9fZV1P+WRTC4Uc26c S6KWfFubAXBBzyBzHMTHOzHx6bTBgj3VNCNr4OPT03bmnFrqaPQ09TTazYDUWnu5f4nu DAxrpJJxUW8YzBks/rB3m96tGwyzq0BoLVM9AgmiHuxQuNUScN/99AjroKLXplSWyYDm +zHIz4/iHjUr/4ap8N3xhpdbKO+6cXlzFwvVnB3u0sDysnu+uH81WARxnUh/kgMARxbM N0Ug2j4+S+33ECtkZZWoFyRHA8vJ9hhgBl+iwQeyKzZWO7h5hOGUlc7iXF+FFCp/YuAN kBJg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: APt69E16NSkhcRks13niELlKtns+TJ0YRTNFj0aSgpuF7VeoKgvMkBOn TDw9QeALL9MMuc+FKSWGDJFYyewmiOnqy9GQ21G4fWIFoeZf8ItfDEv0+kKg2WeMSWHbZToHcDw L9xbGsO6eYc/WpnEDg9ueWRWo5Ey8Ok+rpr3OXVPRNgKo7sis3fe1KT2cFoAzFyTqAQ== X-Received: by 2002:a63:81c7:: with SMTP id t190-v6mr1582127pgd.413.1530022976740; Tue, 26 Jun 2018 07:22:56 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJFjXuM+H+W0jy2Tky2ZsEHxvpPDLS2IEB0+nTINkjvZSxXeg6xHu0txlt6FeIjESBKjXXX X-Received: by 2002:a63:81c7:: with SMTP id t190-v6mr1582086pgd.413.1530022975807; Tue, 26 Jun 2018 07:22:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530022975; cv=none; d=google.com; s=arc-20160816; b=a9Ix6z0VF8/on/WEUbCNaqJEKkphWl2HAtldte0kPG2b2HyaZhiXfVwJ938b3rTbSF pFIsNey31TOJxjDgNSKMjiihLc8nFcECPce8JU7U6396lFSnsa0+We3HtzCthCeJaKi5 S/UWmcZqF89LR+e8tMfCwO5MzeKVuGNtA0kty0Qfg2sBugksOMziD2B0vgno+TCP8h6y bFtpZzrtXBNkIkMcjKTfte0bJKBL9CrRr80tlPnFIVmNMRHJIUZ6WBs8WcdzTSLCENSh nCM+bqHBPUQXlAzS1w/SzcM3BrPSwDxOi5CiHAX9y6rrw+95iTNpXuSLVm9HBVbeNGxB U4pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=eX4hOL6mdxo8wovE4LKiTmPsdPR3/h2k6AOvEOcUYBA=; b=R+0G6qwjxaWuqdPKveeGPgr5AaKCK2Zh5/BIt6hZOZmVPgECSyDAMd0vYQM4dOUphc moMmP5Wy107GneLK5hD3vQzECq9NKV6z0GgawjqFwpa8Bx+FvS2PHbTBaEMJL3GoBiEk 8A77DlZwpNIzT1xIyI5oMNvuG5M8vL29PQjfEhyXSm6iXPFsPnaY5m5bciImbXFygZNx tPyLbu8ahK3kNbOsa488JEB9wWESIXE3fGlWYaqil7hDPyYVEq/37uVM2+bNvN+L0klR JvLfOq84IxK8iCrx5IJpyKJvI3NsQ1tgUb1Fioz0wY21jW5rqfQxlKMFx6VQssuUnVMA KECQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga03.intel.com (mga03.intel.com. [134.134.136.65]) by mx.google.com with ESMTPS id l190-v6si1524248pgd.375.2018.06.26.07.22.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 07:22:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 134.134.136.65 as permitted sender) client-ip=134.134.136.65; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Jun 2018 07:22:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,274,1526367600"; d="scan'208";a="240770208" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga006.fm.intel.com with ESMTP; 26 Jun 2018 07:22:52 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id D00E073D; Tue, 26 Jun 2018 17:22:51 +0300 (EEST) From: "Kirill A. Shutemov" To: Ingo Molnar , x86@kernel.org, Thomas Gleixner , "H. Peter Anvin" , Tom Lendacky Cc: Dave Hansen , Kai Huang , Jacob Pan , linux-kernel@vger.kernel.org, linux-mm@kvack.org, "Kirill A. Shutemov" Subject: [PATCHv4 08/18] x86/mm: Preserve KeyID on pte_modify() and pgprot_modify() Date: Tue, 26 Jun 2018 17:22:35 +0300 Message-Id: <20180626142245.82850-9-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180626142245.82850-1-kirill.shutemov@linux.intel.com> References: <20180626142245.82850-1-kirill.shutemov@linux.intel.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP An encrypted VMA will have KeyID stored in vma->vm_page_prot. This way we don't need to do anything special to setup encrypted page table entries and don't need to reserve space for KeyID in a VMA. This patch changes _PAGE_CHG_MASK to include KeyID bits. Otherwise they are going to be stripped from vm_page_prot on the first pgprot_modify(). Define PTE_PFN_MASK_MAX similar to PTE_PFN_MASK but based on __PHYSICAL_MASK_SHIFT. This way we include whole range of bits architecturally available for PFN without referencing physical_mask and mktme_keyid_mask variables. Signed-off-by: Kirill A. Shutemov --- arch/x86/include/asm/pgtable_types.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h index 99fff853c944..3731f7e08757 100644 --- a/arch/x86/include/asm/pgtable_types.h +++ b/arch/x86/include/asm/pgtable_types.h @@ -120,8 +120,21 @@ * protection key is treated like _PAGE_RW, for * instance, and is *not* included in this mask since * pte_modify() does modify it. + * + * They include the physical address and the memory encryption keyID. + * The paddr and the keyID never occupy the same bits at the same time. + * But, a given bit might be used for the keyID on one system and used for + * the physical address on another. As an optimization, we manage them in + * one unit here since their combination always occupies the same hardware + * bits. PTE_PFN_MASK_MAX stores combined mask. + * + * Cast PAGE_MASK to a signed type so that it is sign-extended if + * virtual addresses are 32-bits but physical addresses are larger + * (ie, 32-bit PAE). */ -#define _PAGE_CHG_MASK (PTE_PFN_MASK | _PAGE_PCD | _PAGE_PWT | \ +#define PTE_PFN_MASK_MAX \ + (((signed long)PAGE_MASK) & ((1ULL << __PHYSICAL_MASK_SHIFT) - 1)) +#define _PAGE_CHG_MASK (PTE_PFN_MASK_MAX | _PAGE_PCD | _PAGE_PWT | \ _PAGE_SPECIAL | _PAGE_ACCESSED | _PAGE_DIRTY | \ _PAGE_SOFT_DIRTY) #define _HPAGE_CHG_MASK (_PAGE_CHG_MASK | _PAGE_PSE)