From patchwork Tue Jun 12 14:39:14 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: 10460519 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 6437F602A0 for ; Tue, 12 Jun 2018 14:40:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6105C2880B for ; Tue, 12 Jun 2018 14:40:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 55802287F0; Tue, 12 Jun 2018 14:40:13 +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 F18242881E for ; Tue, 12 Jun 2018 14:40:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1EABC6B0266; Tue, 12 Jun 2018 10:39:32 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 19B4B6B026C; Tue, 12 Jun 2018 10:39:32 -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 086106B026D; Tue, 12 Jun 2018 10:39:32 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f69.google.com (mail-pl0-f69.google.com [209.85.160.69]) by kanga.kvack.org (Postfix) with ESMTP id B35406B0266 for ; Tue, 12 Jun 2018 10:39:31 -0400 (EDT) Received: by mail-pl0-f69.google.com with SMTP id w6-v6so14113419plp.14 for ; Tue, 12 Jun 2018 07:39:31 -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=StQM7r592572HhqAQp6Z1xbssYIys815jApiRiSNJeo=; b=mx3p7y6g7lhIm0dwWo/dm8Y+wmkVB3oVNSkvszzkYimGWbG7683u/LDxXbNGbulGTY +Ca6IhlaNoBDFmRQZxKl+8U+mBgZ6LL6N0CEIGJonJgV1AYXYEw5eXoI0TZxpTHZEu9V syXc/UJVuIJi79u4u6a5YMPXemQxy7aHJpOTX6L5NjyND6yn3FKsE3DUZKdv4kidg+Hd QjZyTOBAiyxZCJfGCZU1roHU+sdOMkj+qfhnghU+ZO0AxSCuGwwzTF40CUk3g8yGhG+j gKOsnVOu1pR+M7UIF5WnO5wcMc0KG2YeVLlgDcf0ObPy/6UVJkFwJFBT35vS1InGeE5e rqBA== 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.151 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: APt69E0CigKf1dbOzJgbYeOMrWBLtSS+tSdm0xorMH/Xf2mgQk+bzQI7 +2UVkukTRxCDg6KdUV2TMJiGeWpw3C+C2CO8qyBmQapivuBldUsRuHBvfVZUQkBRlPu9T0dwNoP Kv5C97pwg1phOiCCTkJM/AyzxCtIwt1FoVCmDVqKGMprs0jUiK6aJ6yYc81LmXGwTPQ== X-Received: by 2002:a62:e506:: with SMTP id n6-v6mr706622pff.116.1528814371421; Tue, 12 Jun 2018 07:39:31 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKik55I6lsUqauqm9sbVQ8gceFHnI/3C1VucK1ot/pLpHVxgm64xGCkOrVB+JXEsjiHI9Fi X-Received: by 2002:a62:e506:: with SMTP id n6-v6mr706582pff.116.1528814370499; Tue, 12 Jun 2018 07:39:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528814370; cv=none; d=google.com; s=arc-20160816; b=jjkAWDI5LUV4Wvajhxqar4uwKhLwtStcRzWrS016Ew0gI0gYKPYBQjkL8Q+XrQg5w8 0rYmMW3/IAQQpNs8CADHpc+YYiS1hO/VJnJZrCrpR4ufEtzU9yKNlnFrXJlxDtX40TU4 CXwCncWOWonn42qA0WAuq/jh5LB8bF/2Wq8uTZznFNSA2pVxqWmjDkwY6kEh9ai5Ojs9 Kn7Q4UT1fCSqAoD5CwQc2qCFVQZ+ZGmToki7/382IzoE9QNX51qdlPH9AtG8TL43CgnH h8qfBV9IJzjyTkjE1T5KC/i3FobVMUduxMf43HJ+DNxcWKajBjPAIbIqCl7y0Lqwm2dp tMgQ== 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=StQM7r592572HhqAQp6Z1xbssYIys815jApiRiSNJeo=; b=u8uOFZS/qL+OGCK3sjIErAQDqjT8MSgWAThtNaLUd7Glpsnyn9XkMZ+LPG/F+TvR2N bcIYQEASqatVKcF+ROmc1/lwQp/LT3XxWw88ULMEys3jJ/H6NSKiOBPExrk9Vm5EQD0V iNY49kIZfIbTc1LbPU1aTYFju5gpypFT7QrEjL0YQko3TwwZ4bptN4GuO0p34smlSPdG MaaO9gPKO8D7qk7I8+UgXPjR5MEguFEwwSyl1h2Eg6N/OswgwVzLy6csy3ZrAkIQi4FY a31aYmnZ/rXBj/o0rK7iSHxAcFR7Tj4/KZgUQ7vAkYzyIKMQDFFFXKj4oGMCjZ7PqJCY O0ZQ== 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.151 as permitted sender) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga17.intel.com (mga17.intel.com. [192.55.52.151]) by mx.google.com with ESMTPS id j195-v6si223743pgc.543.2018.06.12.07.39.30 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Jun 2018 07:39:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 192.55.52.151 as permitted sender) client-ip=192.55.52.151; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 192.55.52.151 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 fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Jun 2018 07:39:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,215,1526367600"; d="scan'208";a="236788346" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga006.fm.intel.com with ESMTP; 12 Jun 2018 07:39:27 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 4AEA483A; Tue, 12 Jun 2018 17:39:21 +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: [PATCHv3 16/17] x86/mm: Handle encrypted memory in page_to_virt() and __pa() Date: Tue, 12 Jun 2018 17:39:14 +0300 Message-Id: <20180612143915.68065-17-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180612143915.68065-1-kirill.shutemov@linux.intel.com> References: <20180612143915.68065-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. 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 efc0d4bb3b35..d6edcabacfc7 100644 --- a/arch/x86/include/asm/mktme.h +++ b/arch/x86/include/asm/mktme.h @@ -43,6 +43,9 @@ void mktme_disable(void); void setup_direct_mapping_size(void); 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