Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6110554ybi; Wed, 31 Jul 2019 08:30:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqxbNd7Wv5xfWhJvelCus1S+eikcvJ9D/ChBka8G0/QrQAJLSWJY8B7rPZQELtLJn0jl+Qzi X-Received: by 2002:a17:902:ba8e:: with SMTP id k14mr120849962pls.256.1564587040163; Wed, 31 Jul 2019 08:30:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564587040; cv=none; d=google.com; s=arc-20160816; b=LcwhIv/UzFGsxD6rHlIpz8KEuUEECIPJ6oDvl6+52YvLU+nobDopkJGW9FWWmWH4/+ SlOq3aNBueGtDZWrrl5DtZ401eyUI57vBeoiOg6twUInC4iB8O+xLYRNcDAk3jo+RJLI hpGuD6MPm0c/PycWzXgBuTT19RU+cIoPJSVYJRzMAt4TLm1MC7M9Q+Q1BS+mdPykb1AS 3n578CneAx+ByOWwVvazuselrLunONZPyFRku6yIent7CwX7UCkUyugTZj74AwFfP1AK ogYkzfyYauziKLanCJzU/ZPwposlR15eUYEbkBfOTo9YJcTmPOl7L+QuCBBZoXqisSyk LZ1w== 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 :dkim-signature; bh=Eu+g52fZa4bEGKyIAIp4EBxePC6msthuJH3Uu+nPhTw=; b=iOp28HeyqVWJnNMnMYZCMlK/2Oy4nVoP/2fFqzkX3wfB1/dllYwOQVinT0iv1mE2Sf PPwqBDKzLz/2WYK/Mdxsmw50WAB9e5HrKBqQ8DN4ltAioX5G/BIWEKSUKEpa3k2+DY7t 6aSEmHTpQSLZDJ9KALbGyjlR0V/dL7psP5ib7SENouuzbcKQRJ7HHPeHPLCygl9gst+y gVD9QASbCzMmCvwJz5XJzRAnYKoGxeyX/hh85elT/9xIDS48NUdWRsepGBNv9gCeUZ90 3QSZLcYdlQ3S+/a0JaRy7EWwlDcA10jET6yHWjgFTcr5fEviVg0EOz0Ppth1mtU9zPOb qxtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=wnJQX8mA; 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 e35si24021905pge.300.2019.07.31.08.30.24; Wed, 31 Jul 2019 08:30:40 -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=wnJQX8mA; 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 S1728193AbfGaPWB (ORCPT + 99 others); Wed, 31 Jul 2019 11:22:01 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:39860 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727877AbfGaPV7 (ORCPT ); Wed, 31 Jul 2019 11:21:59 -0400 Received: by mail-ed1-f68.google.com with SMTP id m10so66051557edv.6 for ; Wed, 31 Jul 2019 08:21:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Eu+g52fZa4bEGKyIAIp4EBxePC6msthuJH3Uu+nPhTw=; b=wnJQX8mAznJJYoCaujK7jTh3QOUX6PWjjuHiLLJcqeV5ss0Z+2QOjKE/V/f7i2iOiK nWVMBrRzOEuvD50CqQeMSrlLn2yn9nza0e9HYNf9Ci+gZHXztuPcnXQO8Dv/jueUicfh 7x8hxn+DoCcOemE+5xb8GVrcsoOF21pEeWL359gwrBqCcOEFkYVISmg99A9v32xeC8nY K1fXvjaKfAQ0uf1yUKgRc0FXE0a1c8GjVdeZkh9RF4YCM+ZniD98ehoTPZKfBwPrhyWd vT4LGzn8l+GiV/PrV8efZhSU7sLAmcDsKabNfPrtzDTZJ+6VtoCaBOiq1M24C/XlfUJi ySJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Eu+g52fZa4bEGKyIAIp4EBxePC6msthuJH3Uu+nPhTw=; b=mY7hQfJoWiEWuj+Y6VGuv0osK/yywFEGqokEkvIaMvtm9bgaFJHmFF4OyFrjOgy/kl nkneycoT0JB+rnSK+zUHAR1rTA4rbv/GbUnmEJ2ryV8c7SajeD/ILf16/sanNyP6CEMV EMqLrLD91rtNK9e7Qc+20qNyrkQ/J42JE3IsqINtesR527Qy3l+BYOMe9Dc4wgcsz2l1 aqohRRVBa4jiTctsdOBnF4u/to2Ll03kjOnym2J/8NMLarYyo7zFOMlwQ0JA9PFXMSvz SY1+zuNpkkYrYZcQi3ys0PVi89WdAxgMA5U/3jLOQgr54NEDfyYech6ABxjgcJfG6nWL YBBw== X-Gm-Message-State: APjAAAVQVursjuP7J15WvfFnGuFmMsDR5z35b57w4rGCHDvmnKxKJkLQ RA3HiJwNPG1xkgBHggavH50= X-Received: by 2002:a50:addc:: with SMTP id b28mr108191573edd.174.1564586031854; Wed, 31 Jul 2019 08:13:51 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id l2sm16613746edn.59.2019.07.31.08.13.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 Jul 2019 08:13:50 -0700 (PDT) From: "Kirill A. Shutemov" X-Google-Original-From: "Kirill A. Shutemov" Received: by box.localdomain (Postfix, from userid 1000) id 7A1691030BB; Wed, 31 Jul 2019 18:08:16 +0300 (+03) 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: [PATCHv2 20/59] x86/mm: Handle encrypted memory in page_to_virt() and __pa() Date: Wed, 31 Jul 2019 18:07:34 +0300 Message-Id: <20190731150813.26289-21-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190731150813.26289-1-kirill.shutemov@linux.intel.com> References: <20190731150813.26289-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 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 . Signed-off-by: Kirill A. Shutemov --- arch/x86/include/asm/page.h | 3 +++ arch/x86/include/asm/page_64.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h index 39af59487d5f..aff30554f38e 100644 --- a/arch/x86/include/asm/page.h +++ b/arch/x86/include/asm/page.h @@ -72,6 +72,9 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr, extern bool __virt_addr_valid(unsigned long kaddr); #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr)) +#define page_to_virt(x) \ + (__va(PFN_PHYS(page_to_pfn(x))) + page_keyid(x) * direct_mapping_size) + #endif /* __ASSEMBLY__ */ #include diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h index f57fc3cc2246..a4f394e3471d 100644 --- a/arch/x86/include/asm/page_64.h +++ b/arch/x86/include/asm/page_64.h @@ -24,7 +24,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_mask; } #ifdef CONFIG_DEBUG_VIRTUAL -- 2.21.0