From patchwork Thu Jan 17 00:32:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgecombe, Rick P" X-Patchwork-Id: 10767235 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F1BFC14E5 for ; Thu, 17 Jan 2019 00:33:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E0BCA2FD0E for ; Thu, 17 Jan 2019 00:33:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D4F5D2FD2B; Thu, 17 Jan 2019 00:33:45 +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 46EE82FD0E for ; Thu, 17 Jan 2019 00:33:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 930C78E0003; Wed, 16 Jan 2019 19:33:39 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 85D368E0007; Wed, 16 Jan 2019 19:33:39 -0500 (EST) 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 7261E8E0006; Wed, 16 Jan 2019 19:33:39 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by kanga.kvack.org (Postfix) with ESMTP id 306708E0005 for ; Wed, 16 Jan 2019 19:33:39 -0500 (EST) Received: by mail-pl1-f197.google.com with SMTP id g12so4907677pll.22 for ; Wed, 16 Jan 2019 16:33:39 -0800 (PST) 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=dIBVlpwSnsc3TOZe2Cceb+JTk5oYVFqlObcXRp5oqJs=; b=t//AXpJfktTaD97UarZ9y0G4q+xLeO2WPWWDzx1o9we+JrQxWW8Hrwc6DP7YGos3e3 e60IbkvrgqRWDsGnnqfIbMvIj3DtK6vExP4VZY0oQbgBp8oz6oo+j4c2h3CZwCc0y3RH +81mCcJRDDlHJAZUCyqd153jrO+5PHkYB0jlFpYDnvjWQPN1p1fJBalfnqJrBZ5Z+obU 1wJDZXi4WGjJv+ssQojNwb6QjxoDulqKuxsQpxEH5DTGClOTyNOWTw1tVGYuuDWj3CRL c0q70mba01Vf1qnZ0MaK8HKTwh8QY6GkM2gXMvJqxmAX3B7IqyPBgR+Dy0sG9kBFeYyK h4AA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: AJcUukfRJHugwLguVQE4F0g+q5oAYm4HR1SYmdyrxERizv3xKT6WIfPy R3HXo3QS61wVyO2IShBN8gEOMO2lyQMCITMwpo1bLcAEgaaaJMFd1tJ8EZ35k0DUT6SKTOJt74f guXUVn329G/hRtStPzmEzj1HcUMNGVWhbyfWWf3oHUGK3U+zkSERb13bs4YohRahFiw== X-Received: by 2002:a17:902:584:: with SMTP id f4mr13147858plf.28.1547685218848; Wed, 16 Jan 2019 16:33:38 -0800 (PST) X-Google-Smtp-Source: ALg8bN64rnhVDG+YSOk6T9qkjX6WGIQ6BLPqKZ2tGMsyWWzqZveriTar+uNEVTTFuG0erjI+TKBF X-Received: by 2002:a17:902:584:: with SMTP id f4mr13147751plf.28.1547685217721; Wed, 16 Jan 2019 16:33:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547685217; cv=none; d=google.com; s=arc-20160816; b=uR3yDYT5oIBnuBZL/BztZVes53yoHzx8Gx1CMGtRsktIhFPab4kbp0EQqzNi5UvYe3 1DRi7yWKaeSfwhIduQs2THoXVop1GOM6dhha/FTT5uw9Mgg8tP5XjkJ6dYstxCzBhdHD LktLw1mgKHVkQ8t5ArmnkJTd/wogiRp5lN+pmbpO0mLoyjogoldKAb6N7BWCCUwsAFTk +AdsLSUL1dKBy7jn8omtA/ZFohSh21l/dwnv0lfwNytZiYoPHO3aldo42qoDY2MT88sr ryTTXPcoqR6/VAJiCc3qeHdNpD1xmve/VdwZqAmCboI0a0d/0rAqWC8S4EXaI4YeuObI i9WA== 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; bh=dIBVlpwSnsc3TOZe2Cceb+JTk5oYVFqlObcXRp5oqJs=; b=xb+cdRa2pmomo9FP165AEK0s4hXPIVMU8mUh2fbPvkvVaE8xShGJd1dk0I4MDYvDY1 jNDeKnef4U/bflLtEXcQACwjW3Lu2OOWN352HikDHUr3bwfy3Yz0vJ2s/nSPRS/ClGTy BRpA5AdVrj2YvHU0BeLtq0I2VdWU6/W4WA6tClwVoeoTVvhxNvUd+/DPi14uirEyTFoH Q7u0fyhdFIDG65hQZJdiQV3fkpq4BZvFEEUuAKWFguDB8j363G4Imqo81zJJtBik8W56 4cmDIpWMTlBQgA+n7vXjbur0SxtQvYNjDsk3qs7ULeAH+xAQQpNhEXIVDi2vn2kDblhO P4KA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga05.intel.com (mga05.intel.com. [192.55.52.43]) by mx.google.com with ESMTPS id m3si7883258pld.331.2019.01.16.16.33.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Jan 2019 16:33:37 -0800 (PST) Received-SPF: pass (google.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.43 as permitted sender) client-ip=192.55.52.43; Authentication-Results: mx.google.com; spf=pass (google.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (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 orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jan 2019 16:33:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,488,1539673200"; d="scan'208";a="292166050" Received: from rpedgeco-desk5.jf.intel.com ([10.54.75.79]) by orsmga005.jf.intel.com with ESMTP; 16 Jan 2019 16:33:36 -0800 From: Rick Edgecombe To: Andy Lutomirski , Ingo Molnar Cc: linux-kernel@vger.kernel.org, x86@kernel.org, hpa@zytor.com, Thomas Gleixner , Borislav Petkov , Nadav Amit , Dave Hansen , Peter Zijlstra , linux_dti@icloud.com, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, akpm@linux-foundation.org, kernel-hardening@lists.openwall.com, linux-mm@kvack.org, will.deacon@arm.com, ard.biesheuvel@linaro.org, kristen@linux.intel.com, deneen.t.dock@intel.com, Rick Edgecombe Subject: [PATCH 13/17] Add set_alias_ function and x86 implementation Date: Wed, 16 Jan 2019 16:32:55 -0800 Message-Id: <20190117003259.23141-14-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190117003259.23141-1-rick.p.edgecombe@intel.com> References: <20190117003259.23141-1-rick.p.edgecombe@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 This adds two new functions set_alias_default_noflush and set_alias_nv_noflush for setting the alias mapping for the page to its default valid permissions and to an invalid state that cannot be cached in a TLB, respectively. These functions to not flush the TLB. Note, __kernel_map_pages does something similar but flushes the TLB and doesn't reset the permission bits to default on all architectures. There is also an ARCH config ARCH_HAS_SET_ALIAS for specifying whether these have an actual implementation or a default empty one. Cc: Dave Hansen Cc: Andy Lutomirski Cc: Peter Zijlstra Signed-off-by: Rick Edgecombe --- arch/Kconfig | 4 ++++ arch/x86/Kconfig | 1 + arch/x86/include/asm/set_memory.h | 3 +++ arch/x86/mm/pageattr.c | 14 +++++++++++--- include/linux/set_memory.h | 10 ++++++++++ 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index 4cfb6de48f79..4ef9db190f2d 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -249,6 +249,10 @@ config ARCH_HAS_FORTIFY_SOURCE config ARCH_HAS_SET_MEMORY bool +# Select if arch has all set_alias_nv/default() functions +config ARCH_HAS_SET_ALIAS + bool + # Select if arch init_task must go in the __init_task_data section config ARCH_TASK_STRUCT_ON_STACK bool diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 15af091611e2..14ad28769256 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -66,6 +66,7 @@ config X86 select ARCH_HAS_UACCESS_FLUSHCACHE if X86_64 select ARCH_HAS_UACCESS_MCSAFE if X86_64 && X86_MCE select ARCH_HAS_SET_MEMORY + select ARCH_HAS_SET_ALIAS select ARCH_HAS_STRICT_KERNEL_RWX select ARCH_HAS_STRICT_MODULE_RWX select ARCH_HAS_SYNC_CORE_BEFORE_USERMODE diff --git a/arch/x86/include/asm/set_memory.h b/arch/x86/include/asm/set_memory.h index 07a25753e85c..2ef4e4222df1 100644 --- a/arch/x86/include/asm/set_memory.h +++ b/arch/x86/include/asm/set_memory.h @@ -85,6 +85,9 @@ int set_pages_nx(struct page *page, int numpages); int set_pages_ro(struct page *page, int numpages); int set_pages_rw(struct page *page, int numpages); +int set_alias_nv_noflush(struct page *page); +int set_alias_default_noflush(struct page *page); + extern int kernel_set_to_readonly; void set_kernel_text_rw(void); void set_kernel_text_ro(void); diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c index 4f8972311a77..3a51915a1410 100644 --- a/arch/x86/mm/pageattr.c +++ b/arch/x86/mm/pageattr.c @@ -2209,8 +2209,6 @@ int set_pages_rw(struct page *page, int numpages) return set_memory_rw(addr, numpages); } -#ifdef CONFIG_DEBUG_PAGEALLOC - static int __set_pages_p(struct page *page, int numpages) { unsigned long tempaddr = (unsigned long) page_address(page); @@ -2249,6 +2247,17 @@ static int __set_pages_np(struct page *page, int numpages) return __change_page_attr_set_clr(&cpa, 0); } +int set_alias_nv_noflush(struct page *page) +{ + return __set_pages_np(page, 1); +} + +int set_alias_default_noflush(struct page *page) +{ + return __set_pages_p(page, 1); +} + +#ifdef CONFIG_DEBUG_PAGEALLOC void __kernel_map_pages(struct page *page, int numpages, int enable) { if (PageHighMem(page)) @@ -2282,7 +2291,6 @@ void __kernel_map_pages(struct page *page, int numpages, int enable) } #ifdef CONFIG_HIBERNATION - bool kernel_page_present(struct page *page) { unsigned int level; diff --git a/include/linux/set_memory.h b/include/linux/set_memory.h index 2a986d282a97..d19481ac6a8f 100644 --- a/include/linux/set_memory.h +++ b/include/linux/set_memory.h @@ -10,6 +10,16 @@ #ifdef CONFIG_ARCH_HAS_SET_MEMORY #include +#ifndef CONFIG_ARCH_HAS_SET_ALIAS +static inline int set_alias_nv_noflush(struct page *page) +{ + return 0; +} +static inline int set_alias_default_noflush(struct page *page) +{ + return 0; +} +#endif #else static inline int set_memory_ro(unsigned long addr, int numpages) { return 0; } static inline int set_memory_rw(unsigned long addr, int numpages) { return 0; }