From patchwork Tue Jul 17 11:20:21 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: 10529021 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 75776600F4 for ; Tue, 17 Jul 2018 11:22:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 63643205A8 for ; Tue, 17 Jul 2018 11:22:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5781A28A05; Tue, 17 Jul 2018 11:22:11 +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 E1CC5205A8 for ; Tue, 17 Jul 2018 11:22:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4AFD86B0271; Tue, 17 Jul 2018 07:21:52 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 461896B0273; Tue, 17 Jul 2018 07:21:52 -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 215776B0274; Tue, 17 Jul 2018 07:21:52 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f199.google.com (mail-pf0-f199.google.com [209.85.192.199]) by kanga.kvack.org (Postfix) with ESMTP id D21C86B0271 for ; Tue, 17 Jul 2018 07:21:51 -0400 (EDT) Received: by mail-pf0-f199.google.com with SMTP id n17-v6so186143pff.17 for ; Tue, 17 Jul 2018 04:21:51 -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=+iL4oijNKpTNW3lrWT/HfOVJIAiXHqKSeh8gVOe0sxU=; b=qaCo6iUwp+3Tg3r5pFJc7BYFV2ojqNBFalrbajJsaUkejy4VoSiu4Lddn9tcnf3/6m fHG2JjZm4RC31OaWBryXxpanwvJDlAdVJ6f1IuxXDbsi6cTIL+4P3Qbw924u++N+Ektm VaG8v05lRjR4jfZj3zB7tRNZ54OlUwOLTc2bRDTX8DFgiUTCD9lT2ne8RHH7KjaEWirZ 919AHAf+3Euqf1odgxRQl0u9epAVL8c3VJurZKhyhyrIyOgUncdV48Za4kTk350XKlAa XnNqKdobjsjY/4wzBxpo36KGSnWbYrpZYMrBz0Ki+Q+XkmX5bwsc9XThtbJxOAm2q8GV kPTg== 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: AOUpUlHEO24mex4xXThZTni4QpotNIg9gy8aOPWnpsMNUwWPLn3HJKiz gJ3Ef3bewonrGdLcKhxX9WixPKGoilRN9DmPStYQjg8ERu7U/1CWlEecBluK9G/7zV0CgPiWm3G 5BTsN+nD0i5G8YrkksT9K3VzoJvWRcQiMgeu0rOF2iPz6d8E9/1UzRE53FOnraTYM1g== X-Received: by 2002:a63:161a:: with SMTP id w26-v6mr1217515pgl.257.1531826511564; Tue, 17 Jul 2018 04:21:51 -0700 (PDT) X-Google-Smtp-Source: AAOMgpedyHxGofkDePuXYIkqvwWI13UBik2CarMZzOsBlKKtPsc55V92IdQdfIAXyUi1H92pEbyC X-Received: by 2002:a63:161a:: with SMTP id w26-v6mr1217477pgl.257.1531826510846; Tue, 17 Jul 2018 04:21:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531826510; cv=none; d=google.com; s=arc-20160816; b=wsc+I25JufBsjVX6LKLhhIxTIvoApRd8BoDfgU4v05XVoSYfJFG1ITyvKewsEujWA2 5KiJpjfgYD8rRO73zov/poA7FqXHky4Bp2VoAUeAGuWboCXpvq0nW0b05A3ImrVOlOOb bnFeOy7qUSEuWhZJE321dGvSbMVy+7qsOFDj4vMJoN+nHKEaU2jBanmmCOUGOpU7jMRh iy8mkqqp/Vs9shlK2uMhZTFSwcra42tidFT5fO3qAQPospmJtQeYnPj5IJYwgTJwd13S mgEzWigL6mg8ndHtRu0bMfFwPB7nH+aDSau7RFGcMIaGhPGBvGnZ4GGQ3abjl2/B0PEW nL4w== 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=+iL4oijNKpTNW3lrWT/HfOVJIAiXHqKSeh8gVOe0sxU=; b=ccUa0WWLRW+04z0nYTFMKjGBO8CPamqGsIW4g5MJJlJ5YhvX0OiiNZ+wPJ+u2Uy8Qn tUMR4XmbsLKRzYOSO3dDhC3LHPcdfxi673x1JWhmyD6YTAHK3p1SOB6v8lSojlCoQ3pU LzKKc0/PVe4F95KyVlEAXMrT5wymCmQMMr6GSB66fhTsE7ZAKtTNwl7SwZ/nJXcmbOgy dvgic6UTqQkioh4V8y2WOVViWgfneEu5ZRSO+hx/oYPF0s+89hmg14EpjYu1J77OtFnn 8dp9fe6ZVN8TCC1SuYFizbnLRxU6g68+5hYaN1bWWvsKAINwYbcaX5tRQ8KJKJxPkVmt F2Gg== 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 d191-v6si673317pga.192.2018.07.17.04.21.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jul 2018 04:21:50 -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 orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Jul 2018 04:21:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,365,1526367600"; d="scan'208";a="58320644" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 17 Jul 2018 04:21:45 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 293D270F; 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 11/19] x86/mm: Implement vma_keyid() Date: Tue, 17 Jul 2018 14:20:21 +0300 Message-Id: <20180717112029.42378-12-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 We store KeyID in upper bits for vm_page_prot that match position of KeyID in PTE. vma_keyid() extracts KeyID from vm_page_prot. With KeyID in vm_page_prot we don't need to modify any page table helper to propagate the KeyID to page table entires. Signed-off-by: Kirill A. Shutemov --- arch/x86/include/asm/mktme.h | 5 +++++ arch/x86/mm/mktme.c | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/arch/x86/include/asm/mktme.h b/arch/x86/include/asm/mktme.h index 7266494b4f0a..f0b7844e36a4 100644 --- a/arch/x86/include/asm/mktme.h +++ b/arch/x86/include/asm/mktme.h @@ -4,6 +4,8 @@ #include #include +struct vm_area_struct; + #ifdef CONFIG_X86_INTEL_MKTME extern phys_addr_t mktme_keyid_mask; extern int mktme_nr_keyids; @@ -14,6 +16,9 @@ extern struct page_ext_operations page_mktme_ops; #define page_keyid page_keyid int page_keyid(const struct page *page); +#define vma_keyid vma_keyid +int vma_keyid(struct vm_area_struct *vma); + #else #define mktme_keyid_mask ((phys_addr_t)0) #define mktme_nr_keyids 0 diff --git a/arch/x86/mm/mktme.c b/arch/x86/mm/mktme.c index 09cbff678b9f..a1f40ee61b25 100644 --- a/arch/x86/mm/mktme.c +++ b/arch/x86/mm/mktme.c @@ -1,3 +1,4 @@ +#include #include phys_addr_t mktme_keyid_mask; @@ -37,3 +38,14 @@ struct page_ext_operations page_mktme_ops = { .need = need_page_mktme, .init = init_page_mktme, }; + +int vma_keyid(struct vm_area_struct *vma) +{ + pgprotval_t prot; + + if (!mktme_enabled()) + return 0; + + prot = pgprot_val(vma->vm_page_prot); + return (prot & mktme_keyid_mask) >> mktme_keyid_shift; +}