From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f199.google.com (mail-pf0-f199.google.com [209.85.192.199]) by kanga.kvack.org (Postfix) with ESMTP id 5F9556B0274 for ; Tue, 26 Jun 2018 10:23:00 -0400 (EDT) Received: by mail-pf0-f199.google.com with SMTP id f24-v6so4756548pfn.10 for ; Tue, 26 Jun 2018 07:23:00 -0700 (PDT) Received: from mga09.intel.com (mga09.intel.com. [134.134.136.24]) by mx.google.com with ESMTPS id b125-v6si1501171pgc.514.2018.06.26.07.22.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 07:22:59 -0700 (PDT) From: "Kirill A. Shutemov" Subject: [PATCHv4 17/18] x86/mm: Handle encrypted memory in page_to_virt() and __pa() Date: Tue, 26 Jun 2018 17:22:44 +0300 Message-Id: <20180626142245.82850-18-kirill.shutemov@linux.intel.com> In-Reply-To: <20180626142245.82850-1-kirill.shutemov@linux.intel.com> References: <20180626142245.82850-1-kirill.shutemov@linux.intel.com> Sender: owner-linux-mm@kvack.org List-ID: 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" Per-KeyID direct mappings require changes into how we find the right virtual address for a page and virt-to-phys address translations. page_to_virt() definition overwrites default macros provided by . We only overwrite the macros if MTKME is enabled compile-time. Signed-off-by: Kirill A. Shutemov --- arch/x86/include/asm/mktme.h | 3 +++ arch/x86/include/asm/page_64.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/mktme.h b/arch/x86/include/asm/mktme.h index ba83fba4f9b3..dbfbd955da98 100644 --- a/arch/x86/include/asm/mktme.h +++ b/arch/x86/include/asm/mktme.h @@ -29,6 +29,9 @@ void arch_free_page(struct page *page, int order); int sync_direct_mapping(void); +#define page_to_virt(x) \ + (__va(PFN_PHYS(page_to_pfn(x))) + page_keyid(x) * direct_mapping_size) + #else #define mktme_keyid_mask ((phys_addr_t)0) #define mktme_nr_keyids 0 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h index 53c32af895ab..ffad496aadad 100644 --- a/arch/x86/include/asm/page_64.h +++ b/arch/x86/include/asm/page_64.h @@ -23,7 +23,7 @@ static inline unsigned long __phys_addr_nodebug(unsigned long x) /* use the carry flag to determine if x was < __START_KERNEL_map */ x = y + ((x > y) ? phys_base : (__START_KERNEL_map - PAGE_OFFSET)); - return x; + return x % direct_mapping_size; } #ifdef CONFIG_DEBUG_VIRTUAL -- 2.18.0