From patchwork Wed Sep 20 22:31:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Rzeszutek Wilk X-Patchwork-Id: 9962721 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 05CFF6056A for ; Wed, 20 Sep 2017 22:34:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC2C129258 for ; Wed, 20 Sep 2017 22:34:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E11602926F; Wed, 20 Sep 2017 22:34:52 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RCVD_IN_SORBS_SPAM,T_DKIM_INVALID 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 49CA629273 for ; Wed, 20 Sep 2017 22:34:52 +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 1dunXR-0007Fw-7k; Wed, 20 Sep 2017 22:32:13 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dunXP-0007F1-Nx for xen-devel@lists.xenproject.org; Wed, 20 Sep 2017 22:32:11 +0000 Received: from [85.158.137.68] by server-7.bemta-3.messagelabs.com id 57/66-02224-A6CE2C95; Wed, 20 Sep 2017 22:32:10 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrEIsWRWlGSWpSXmKPExsVyMfTGId2sN4c iDSZO47L4vmUykwOjx+EPV1gCGKNYM/OS8isSWDM2b1MoOGNZsWXfXbYGxsk6XYxcHEIC0xkl tmz7wQzisAh8YJFo3/WPDcSREJjGKvHvdi97FyMHkJMl0XFCrouRE8hMkzj68D4jRLhCYusVe 5CwkICSxJbJjxkhhh5ikjj9YT4LSEJYQE9i8rfbjCA2m4C+xNO115ghet0kPl3jAqkXEWhnlJ h95RcrSA2zgKFE69ujbBC92RIrfncxgdgsAqoSWzctBzuHV8Ba4vgaLohz5CUm9k4DG88pYCO x/1MnM8Q91hJPtp5mm8AovICRYRWjenFqUVlqka6hXlJRZnpGSW5iZo6uoYGxXm5qcXFiempO YlKxXnJ+7iZGYGgyAMEOxuUfnQ4xSnIwKYnyWr88FCnEl5SfUpmRWJwRX1Sak1p8iFGGg0NJg jfhNVBOsCg1PbUiLTMHGCUwaQkOHiURXg+QNG9xQWJucWY6ROoUoz3HhTuX/jBxHNhzC0h23L wLJKfcApJCLHn5ealS4rxfXwG1CYC0ZZTmwQ2FRfUlRlkpYV5GoDOFeApSi3IzS1DlXzGKczA qCfN6gyznycwrgdv9CugsJqCzsjccADmrJBEhJdXA2Fi0KD5ydsK1lFvlJ1N1j4oy/roqLmzQ 99s0lXnx4QOT1n34NWeuimkf24SV9cZvVx3/cWGa/luOo5Fygs89mJu/vhQqT0y62Ffy6PJ29 jPONY9XSdVXXDKeKDBFpErWPWaj+D+9svgT2Zock50YBBS/HgzgvHrtmLnaWdWds61inI/Nvj HPRYmlOCPRUIu5qDgRAMJBKoDlAgAA X-Env-Sender: ketuzsezr@gmail.com X-Msg-Ref: server-2.tower-31.messagelabs.com!1505946729!104086543!1 X-Originating-IP: [209.85.216.194] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 51864 invoked from network); 20 Sep 2017 22:32:09 -0000 Received: from mail-qt0-f194.google.com (HELO mail-qt0-f194.google.com) (209.85.216.194) by server-2.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 20 Sep 2017 22:32:09 -0000 Received: by mail-qt0-f194.google.com with SMTP id q8so2677320qtb.1 for ; Wed, 20 Sep 2017 15:32:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=UyvVI+nXLK8n4XbpMJDimK/OkJrXaZliAqADByaxn90=; b=hkiUUAjaNcSPp05P8X9FEkN3+35NZSFPbbgFXcZ6vlrwM+82dJmRbudPpRZ1uYLW3k 0TB7joESc2NrEnOT6Gs2eLn7Y6jKoR1DiB0zJJuiaZAjfGMQPe//9F50SN+01cskWcHU YNqL53kGPFHbicsKT1Arm3AcGvvSPNoVNkKbZb8rrbfZy2PNFEdoQyn4syy9E1HwiZ3a XG+h+SpVc3R1x+ZdKDC/gOIgZZeM95oJkzoGXdhsT18sG7YfyWRdbRt84Rr8jRmcSN4i HC8jnuguV5obKTDyTn/aoidHKNP5qG1W9g/zrHTJIDRLN1MWCRy0jLPXjLC3k0vYJUXl aRIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=UyvVI+nXLK8n4XbpMJDimK/OkJrXaZliAqADByaxn90=; b=plzBFOaMLLw3MGDBqyvKlnNJDHeuimVT72JgxhCOMW6jp+u/5bFhS1f6OrA5PMu6Ih AP+96lo+v0BDtE4RAenCVMVwitfIXCrzBW+4P7RhjrjlP0H4WE5p0czY9SKA8z/vhtN7 O4rsS5cpC2ck1As2nDEg0LpsSRM+OIUgI8Ky8uLJb+uaasqBJQwkdeGdDVHX9HAIKPpH +97RNg/zG9f//NQez+5uT+SsmJEIqmSJSuM3+DpPHhsx0tI+JuCUELoZdLhNhNffTm0q VbGgrFpMgYU61YYLdpNfrnOQQ/X8SZnc4Ud6O8AmluON0OO4bgn230PmkJOCoCrSKiv7 po0A== X-Gm-Message-State: AHPjjUjTeRSlCXQOCt3LF+9Xuk2OxmCAVzaPW8yrgi70FR29sQXw4H46 qLKMJfrhz5kPb7JFGLtQ8U7gCA== X-Google-Smtp-Source: AOwi7QDyryM80j2J7WNZyAnBISZGye+rKU8mJKN9YLGa7DM6AKA43L/JKAKu6YMnj5XGe0V5/+PpgQ== X-Received: by 10.237.60.37 with SMTP id t34mr367781qte.224.1505946728735; Wed, 20 Sep 2017 15:32:08 -0700 (PDT) Received: from localhost.localdomain (209-6-200-48.s4398.c3-0.smr-ubr2.sbo-smr.ma.cable.rcncustomer.com. [209.6.200.48]) by smtp.gmail.com with ESMTPSA id z192sm2012656qka.91.2017.09.20.15.32.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Sep 2017 15:32:07 -0700 (PDT) From: Konrad Rzeszutek Wilk X-Google-Original-From: Konrad Rzeszutek Wilk To: xen-devel@lists.xenproject.org, ross.lagerwall@citrix.com, konrad.wilk@oracle.com, julien.grall@arm.com, sstabellini@kernel.org Date: Wed, 20 Sep 2017 18:31:42 -0400 Message-Id: <20170920223148.13137-6-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170920223148.13137-1-konrad.wilk@oracle.com> References: <20170920223148.13137-1-konrad.wilk@oracle.com> Cc: andrew.cooper3@citrix.com, jbeulich@suse.com Subject: [Xen-devel] [PATCH v4 05/11] alternative/x86/arm32: Align altinstructions (and altinstr_replacement) sections. 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 This is very similar to 137c59b9ff3f7a214f03b52d9c00a0a02374af1f "bug/x86/arm: Align bug_frames sections." On ARM and on x86 the C and assembler macros don't include any alignment information - hence they end up being the default byte granularity. On ARM32 it is paramount that the alignment is word-size (4) otherwise if one tries to use (uint32_t*) access (such as livepatch ELF relocations) we get a Data Abort. Specifically this issue was observed on ARM32 with a cross compiler for the livepatches. Mainly the livepatches .data section size was not padded to the section alignment: ARM32 native: Contents of section .rodata: 0000 68695f66 756e6300 63686563 6b5f666e hi_func.check_fn 0010 63000000 78656e5f 65787472 615f7665 c...xen_extra_ve 0020 7273696f 6e000000 rsion... ARM32 cross compiler: Contents of section .rodata: 0000 68695f66 756e6300 63686563 6b5f666e hi_func.check_fn 0010 63000000 78656e5f 65787472 615f7665 c...xen_extra_ve 0020 7273696f 6e00 rsion. And when we loaded it the next section would be put right behind it: native: (XEN) livepatch.c:413: livepatch: xen_hello_world: Loaded .text at 00a02000 (XEN) livepatch.c:413: livepatch: xen_hello_world: Loaded .rodata at 00a04024 (XEN) livepatch.c:413: livepatch: xen_hello_world: Loaded .altinstructions at 00a0404c cross compiler: (XEN) livepatch.c:413: livepatch: xen_hello_world: Loaded .text at 00a02000 (XEN) livepatch.c:413: livepatch: xen_hello_world: Loaded .rodata at 00a04024 (XEN) livepatch.c:413: livepatch: xen_hello_world: Loaded .altinstructions at 00a0404a (See 4a vs 4c) native readelf: [ 4] .rodata PROGBITS 00000000 000164 000028 00 A 0 0 4 [ 5] .altinstructions PROGBITS 00000000 00018c 00000c 00 A 0 0 1 cross compiler readelf --sections: [ 4] .rodata PROGBITS 00000000 000164 000026 00 A 0 0 4 [ 5] .altinstructions PROGBITS 00000000 00018a 00000c 00 A 0 0 1 And as can be seen the .altinstructions have alignment of 1 which from 'man elf' is: "Values of zero and one mean no alignment is required." which means we can ignore it. Enforcing .altinstructions (and also .altinstr_replacement for completness on ARM) to have the proper alignment across all architectures and in both C and x86 makes them all the same. On x86 the bloat-o-meter detects that with this change the file shrinks: add/remove: 1/0 grow/shrink: 0/2 up/down: 156/-367 (-211) function old new delta get_page_from_gfn - 156 +156 do_mmu_update 4578 4569 -9 do_mmuext_op 5604 5246 -358 Total: Before=3170439, After=3170228, chg -0.01% But as found adding even "#Hi!\n" will casue this optimization, so the bloat-o-meter value here is useless. While on ARM 32/64: add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0 (0) function old new delta Total: Before=822563, After=822563, chg +0.00% Also since the macros have the alignment coded in them there is no need to do that for the xen.lds.S anymore. Signed-off-by: Konrad Rzeszutek Wilk Acked-by: Jan Beulich --- Cc: Ross Lagerwall Cc: Stefano Stabellini Cc: Julien Grall Cc: Jan Beulich Cc: Andrew Cooper v2: - First posting. v3: - Figured out the x86 bloat-o-meter results. - Removed the .ALIGN from xen.lds.S - Removed the .p2align on .altinstr_replacement per Jan's request. - Put most of the commit description for the original issue v4: - Added one .ALIGN back on xen.lds.S (arm) - Changed the .ALIGN(8) to ALIGN(4) on xen.lds.S (x86) - Moved p2align inside of the macros (ALTINSTR_ENTRY and altinstruction_entry) --- xen/arch/arm/xen.lds.S | 1 - xen/arch/x86/xen.lds.S | 2 +- xen/include/asm-arm/alternative.h | 4 ++++ xen/include/asm-x86/alternative.h | 2 ++ 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/xen.lds.S b/xen/arch/arm/xen.lds.S index c9b9546435..84ee475405 100644 --- a/xen/arch/arm/xen.lds.S +++ b/xen/arch/arm/xen.lds.S @@ -159,7 +159,6 @@ SECTIONS __alt_instructions = .; *(.altinstructions) __alt_instructions_end = .; - . = ALIGN(4); *(.altinstr_replacement) #endif diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S index d5e8821d41..b03cca011b 100644 --- a/xen/arch/x86/xen.lds.S +++ b/xen/arch/x86/xen.lds.S @@ -202,7 +202,7 @@ SECTIONS * "Alternative instructions for different CPU types or capabilities" * Think locking instructions on spinlocks. */ - . = ALIGN(8); + . = ALIGN(4); __alt_instructions = .; *(.altinstructions) __alt_instructions_end = .; diff --git a/xen/include/asm-arm/alternative.h b/xen/include/asm-arm/alternative.h index 6cc9d0dc5f..5e0d2b39a5 100644 --- a/xen/include/asm-arm/alternative.h +++ b/xen/include/asm-arm/alternative.h @@ -28,6 +28,7 @@ void __init apply_alternatives_all(void); int apply_alternatives(const struct alt_instr *start, const struct alt_instr *end); #define ALTINSTR_ENTRY(feature) \ + " .p2align 2\n" \ " .word 661b - .\n" /* label */ \ " .word 663f - .\n" /* new instruction */ \ " .hword " __stringify(feature) "\n" /* feature bit */ \ @@ -57,6 +58,7 @@ int apply_alternatives(const struct alt_instr *start, const struct alt_instr *en ALTINSTR_ENTRY(feature) \ ".popsection\n" \ ".pushsection .altinstr_replacement, \"a\"\n" \ + ".p2align 2\n" \ "663:\n\t" \ newinstr "\n" \ "664:\n\t" \ @@ -73,6 +75,7 @@ int apply_alternatives(const struct alt_instr *start, const struct alt_instr *en #include .macro altinstruction_entry orig_offset alt_offset feature orig_len alt_len + .p2align 2 .word \orig_offset - . .word \alt_offset - . .hword \feature @@ -103,6 +106,7 @@ int apply_alternatives(const struct alt_instr *start, const struct alt_instr *en .macro alternative_if_not cap, enable = 1 .if \enable .pushsection .altinstructions, "a" + .p2align 2 altinstruction_entry 661f, 663f, \cap, 662f-661f, 664f-663f .popsection 661: diff --git a/xen/include/asm-x86/alternative.h b/xen/include/asm-x86/alternative.h index db4f08e0e7..56574ceb0d 100644 --- a/xen/include/asm-x86/alternative.h +++ b/xen/include/asm-x86/alternative.h @@ -5,6 +5,7 @@ #ifdef __ASSEMBLY__ .macro altinstruction_entry orig alt feature orig_len alt_len + .p2align 2 .long \orig - . .long \alt - . .word \feature @@ -42,6 +43,7 @@ extern void alternative_instructions(void); #define alt_rlen(number) e_replacement(number)"f-"b_replacement(number)"f" #define ALTINSTR_ENTRY(feature, number) \ + " .p2align 2\n" \ " .long 661b - .\n" /* label */ \ " .long " b_replacement(number)"f - .\n" /* new instruction */ \ " .word " __stringify(feature) "\n" /* feature bit */ \