From patchwork Sun Aug 14 23:07:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Rzeszutek Wilk X-Patchwork-Id: 9280205 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 7121B60780 for ; Sun, 14 Aug 2016 23:11:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61D3928A13 for ; Sun, 14 Aug 2016 23:11:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5692D28A4A; Sun, 14 Aug 2016 23:11:37 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 16BAE28A13 for ; Sun, 14 Aug 2016 23:11:35 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bZ4W9-00017m-1U; Sun, 14 Aug 2016 23:08:33 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bZ4W7-00016m-3P for xen-devel@lists.xenproject.org; Sun, 14 Aug 2016 23:08:31 +0000 Received: from [85.158.137.68] by server-13.bemta-3.messagelabs.com id 86/72-06162-EE9F0B75; Sun, 14 Aug 2016 23:08:30 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupgkeJIrShJLcpLzFFi42LpnVTnqvv254Z wg6OLtCy+b5nM5MDocfjDFZYAxijWzLyk/IoE1ozD718yF5yTqXiz7x97A+MfkS5GLg4hgQ4m iTMNf5kgnC+MEnO27INyNjJKTPq8ixXCmcAo8fjoUiCHg4NNwETizSrHLkZODhGBCInel6dYQ GqYBWYzSjyafZENJCEsYCux/vF8FhCbRUBVovHKIjCbV8BVovfoShaQORIC8hLPbteDhDkF3C T+3zsLViIEVPLiRCfYGAkBY4m+WX0sExj5FjAyrGLUKE4tKkst0jUy0ksqykzPKMlNzMzRNTQ w1stNLS5OTE/NSUwq1kvOz93ECAyVegYGxh2MU0/4HWKU5GBSEuXVMV8XLsSXlJ9SmZFYnBFf VJqTWnyIUYaDQ0mCVxgYekKCRanpqRVpmTnAoIVJS3DwKInw5oGkeYsLEnOLM9MhUqcYdTmW7 HqwlkmIJS8/L1VKnHfJD6AiAZCijNI8uBGwCLrEKCslzMvIwMAgxFOQWpSbWYIq/4pRnINRSZ jXAmQVT2ZeCdymV0BHMAEdoS8NdkRJIkJKqoFRt6RS0rl9JreptLGn7JpAxbWGPH16s1VSpmQ u6Ar+k+N2Yf6rAt1T21u37Dp4KKHmbcuy5yKLtx9esmjyHXGOme85ds+ZtNXm22S2hqnilxR8 2JJcTllKbO2tMPEoOLYreb7H1o5VV/3fH1dcGvVqn9Genv+bhN7wcOfPm/50T55w5tlwb+MaJ ZbijERDLeai4kQA6EAT5ZsCAAA= X-Env-Sender: konrad.wilk@oracle.com X-Msg-Ref: server-4.tower-31.messagelabs.com!1471216108!5340212!1 X-Originating-IP: [141.146.126.69] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTQxLjE0Ni4xMjYuNjkgPT4gMjc3MjE4\n X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 35248 invoked from network); 14 Aug 2016 23:08:29 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-4.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 14 Aug 2016 23:08:29 -0000 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u7EN8LF5010434 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 14 Aug 2016 23:08:21 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u7EN8KnI004496 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 14 Aug 2016 23:08:21 GMT Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id u7EN8KfQ021581; Sun, 14 Aug 2016 23:08:20 GMT Received: from localhost.localdomain.com (/209.6.196.81) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 14 Aug 2016 16:08:19 -0700 From: Konrad Rzeszutek Wilk To: xen-devel@lists.xenproject.org, konrad@kernel.org, ross.lagerwall@citrix.com Date: Sun, 14 Aug 2016 19:07:49 -0400 Message-Id: <1471216074-3007-5-git-send-email-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.4.11 In-Reply-To: <1471216074-3007-1-git-send-email-konrad.wilk@oracle.com> References: <1471216074-3007-1-git-send-email-konrad.wilk@oracle.com> X-Source-IP: aserv0021.oracle.com [141.146.126.233] Cc: Andrew Cooper , julien.grall@arm.com, sstabellini@kernel.org, Konrad Rzeszutek Wilk Subject: [Xen-devel] [PATCH v1 4/9] arm/mm: Introduce modify_xen_mappings X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Which is only used by Livepatch code. The purpose behind this call is to modify the page table entries flags. Specifically the .ro and .nx flags. The current mechanism puts cache attributes in the flags and the .ro and .nx are locked down and assumed to be .ro=0, nx=1. Livepatch needs .nx=0 and also .ro to be set to 1. We introduce a new 'flags' where various bits determine whether .ro and .nx bits are set or cleared. We can't use an enum as the function prototype would diverge from x86. Signed-off-by: Konrad Rzeszutek Wilk --- Cc: Ross Lagerwall Cc: Stefano Stabellini Cc: Julien Grall Cc: Andrew Cooper [Added as he wrote the x86 modify_xen_mappings version] RFC: First submission. v1: Add #defines to make it simpler to understand the bit-shifting. --- xen/arch/arm/mm.c | 21 ++++++++++++++++++--- xen/include/asm-arm/page.h | 11 +++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 4e256c2..520c0e0 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -836,6 +836,7 @@ static int create_xen_table(lpae_t *entry) enum xenmap_operation { INSERT, REMOVE, + MODIFY, RESERVE }; @@ -881,14 +882,22 @@ static int create_xen_entries(enum xenmap_operation op, pte.pt.table = 1; write_pte(&third[third_table_offset(addr)], pte); break; + case MODIFY: case REMOVE: if ( !third[third_table_offset(addr)].pt.valid ) { - printk("create_xen_entries: trying to remove a non-existing mapping addr=%lx\n", - addr); + printk("create_xen_entries: trying to %s a non-existing mapping addr=%lx\n", + op == REMOVE ? "remove" : "modify", addr); return -EINVAL; } - pte.bits = 0; + if ( op == REMOVE ) + pte.bits = 0; + else + { + pte = third[third_table_offset(addr)]; + pte.pt.ro = PTE_RO_MASK(ai); + pte.pt.xn = PTE_NX_MASK(ai); + } write_pte(&third[third_table_offset(addr)], pte); break; default: @@ -922,6 +931,12 @@ void destroy_xen_mappings(unsigned long v, unsigned long e) create_xen_entries(REMOVE, v, 0, (e - v) >> PAGE_SHIFT, 0); } +void modify_xen_mappings(unsigned long s, unsigned long e, unsigned int flags) +{ + ASSERT((flags & (PTE_NX | PTE_RO)) == flags); + create_xen_entries(MODIFY, s, 0, (e - s) >> PAGE_SHIFT, flags); +} + enum mg { mg_clear, mg_ro, mg_rw, mg_rx }; static void set_pte_flags_on_range(const char *p, unsigned long l, enum mg mg) { diff --git a/xen/include/asm-arm/page.h b/xen/include/asm-arm/page.h index 05d9f82..2f66740 100644 --- a/xen/include/asm-arm/page.h +++ b/xen/include/asm-arm/page.h @@ -66,6 +66,17 @@ #define PAGE_HYPERVISOR_WC (DEV_WC) /* + * Defines for changing the PTE .ro and .nx bits. This is only to be + * used with modify_xen_mappings. + */ +#define _PTE_NX_BIT 0U +#define _PTE_RO_BIT 1U +#define PTE_NX (1U << _PTE_NX_BIT) +#define PTE_RO (1U << _PTE_RO_BIT) +#define PTE_NX_MASK(x) (((x) >> _PTE_NX_BIT) & 0x1U) +#define PTE_RO_MASK(x) (((x) >> _PTE_RO_BIT) & 0x1U) + +/* * Stage 2 Memory Type. * * These are valid in the MemAttr[3:0] field of an LPAE stage 2 page