From patchwork Tue Jul 17 11:20:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A . Shutemov" X-Patchwork-Id: 10529055 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 619A6600F4 for ; Tue, 17 Jul 2018 11:22:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 500E128BAB for ; Tue, 17 Jul 2018 11:22:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 43E1128C20; Tue, 17 Jul 2018 11:22:46 +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=unavailable 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 E010F28BAB for ; Tue, 17 Jul 2018 11:22:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 243456B0283; Tue, 17 Jul 2018 07:22:11 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1A5106B0284; Tue, 17 Jul 2018 07:22:11 -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 EBF9D6B0285; Tue, 17 Jul 2018 07:22:10 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by kanga.kvack.org (Postfix) with ESMTP id A4AC66B0283 for ; Tue, 17 Jul 2018 07:22:10 -0400 (EDT) Received: by mail-pg1-f197.google.com with SMTP id n5-v6so325761pgp.20 for ; Tue, 17 Jul 2018 04:22:10 -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=Oi+rJI0orA5sIeAYPorZAiEofc0R+/ovPpORMv1Rh94=; b=WJ6DJnthUwsZMjz8YkW0yDefWeigUiWEGVZupazg4ZcMVbuEayESlsp+ICc/cR0FZS hOfYVlHSGKrrTgoOGuoMPp5uz8ldN3K0gu+cvTLPnnax/DMlXyaevRoYjzdnuK+3xUL+ rwkG7aHREbxOTk3Exub6zA4vJR8N9DA8U5ZKOoXFoLIS2WbuQdW/dy2d/uXtnc8H1k+V EodAKkPR5qB8IO5Ew0CcFOETmQS4BmfQfWF01So9pwhtB80KxdLT5mu5f9vAUfRArvBg Rg5SYk/eRJzZxkVEKEIR6oOU6/3SeER7WYUmtJ00APZC5OhVDPgY9u/f1EJQ0zUaGjpE TRvA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 192.55.52.136 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: AOUpUlGUjuy8TCSFOkGqG+f3Z88mO1ztffde6LMilyKCl1ObSIAzrF4x eK4yFy5s0E2hzryg8206ZmX+ABDNbQj761ZmBATM+ShLvx9YVrhLRu/zaxWpn8LutLXjf3vMyp1 gSUIfxl5020Fo3I3U1pfuViZr7fkmbeRGCdUxEqAjCfbBPFcTQ+itQsOlvvgx1Gmwiw== X-Received: by 2002:a62:5543:: with SMTP id j64-v6mr275661pfb.188.1531826530354; Tue, 17 Jul 2018 04:22:10 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdJFwaMzpLGvVcgpKHE1v0QOGoB4/O1dHL2A/ujjOfMOqqD4/wWfAQrsx++F223c6u62yUU X-Received: by 2002:a62:5543:: with SMTP id j64-v6mr275630pfb.188.1531826529684; Tue, 17 Jul 2018 04:22:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531826529; cv=none; d=google.com; s=arc-20160816; b=NLGgoffpTrFDKhuhTF/pF4WC6hn0/FEDVfA224/F7XNmV36SdQnuiJqHBVWib+hYK1 rfC878yN2BbVx/62WKJaPNw6GAOLfx2zFS3zLJ735ef+InfIFbAsDrGNy7jTGEmJ8te9 UulQN51Ydr9R4yM6mZCpnGZ1eTBhvzduiBxMPSR7EC16178pixV1EgW577t/8TAhM4xn +1/f7b/aMr6VbSm1oznlb4q9dPu9SPRV1l7aLSa5hPOagd/k6H+kwsSOgMCkxrDZfgVl jwe7TpqYmI+2ryUfn6f0Ux0HKsKcWA+o2ZNCs6IXM/WSPe5f4wIs9HLhzNV2fhXOMsUR JJ9Q== 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=Oi+rJI0orA5sIeAYPorZAiEofc0R+/ovPpORMv1Rh94=; b=xC/7O7tjKiO913DRUCep5yYblcIVkLvyh8KKCuL95oxWIqb8utG3q2db0wEQ0DQ8Dn tF5duxjRMW10dh6i6gUUo4xsBwMxw48G5v+lrl71Rcoay0EW4/ey57CKhQZkXjVMWCuu 7wcnlwGnkSt3EYZiSVbzqULGdrkrQaCQ8JNlrypHoaEnkMuycAe8SiU5OYrj/HZM2BCR vbOnO37VUY1D+BsDuez3fXpQcZ1cen/Y5O0iU+ZU0+YWvxKP5PxCZx7ZHkXedo2+Ftr2 b0dGzNS9SZbixzjcLZwbFGvKqX/hb0qtamhjWysF1TWK3qY3VBMEXrhIkH6ZAtxL3UjC 8w4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 192.55.52.136 as permitted sender) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga12.intel.com (mga12.intel.com. [192.55.52.136]) by mx.google.com with ESMTPS id 6-v6si675799pgv.508.2018.07.17.04.22.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jul 2018 04:22:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 192.55.52.136 as permitted sender) client-ip=192.55.52.136; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 192.55.52.136 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 orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Jul 2018 04:22:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,365,1526367600"; d="scan'208";a="58320654" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 17 Jul 2018 04:21:49 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 729B884E; Tue, 17 Jul 2018 14:21:49 +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: [PATCHv5 18/19] x86/mm: Handle encrypted memory in page_to_virt() and __pa() Date: Tue, 17 Jul 2018 14:20:28 +0300 Message-Id: <20180717112029.42378-19-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180717112029.42378-1-kirill.shutemov@linux.intel.com> References: <20180717112029.42378-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 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 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