From patchwork Wed Oct 19 03:15:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 683950 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3szHR81n9pz9snm for ; Wed, 19 Oct 2016 14:26:28 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=LLH/cViZ; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3szHR80hd9zDvZ4 for ; Wed, 19 Oct 2016 14:26:28 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=LLH/cViZ; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mail-pf0-x244.google.com (mail-pf0-x244.google.com [IPv6:2607:f8b0:400e:c00::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3szHCg3Jq7zDt1j for ; Wed, 19 Oct 2016 14:16:31 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=LLH/cViZ; dkim-atps=neutral Received: by mail-pf0-x244.google.com with SMTP id 128so1092851pfz.1 for ; Tue, 18 Oct 2016 20:16:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7mhqmfxGRNd/oDp+oYziK6kcL//l+pvDRZhmIkBV42U=; b=LLH/cViZ48bODqbWyKOKqG0SQUIqu4cJhFt7fr4ALIaBRX6t0HYF/CKNDGNXpEq+Iu 9injsxw0ga0wQfZBSYpyey5v+010HnoItoGsU2KBoXZRsYCLqHSJPmDSRN7wypQORVZw uGhfqh6Bjjz1M/PA51/AR56SgM6R4iokW65jVR/AjtH0houe7SCb14/vsVj3QkV44VeE 9a8m/8xchBQIb2si2pvCQwJZESQKI16FdmM6FXHcJpsiwW2JoQOgGm2yDSTL8+t9yor8 wV1vIhuqRdf03EJFY+sH5xzUkK2Chloz3nZGZNRb/bcdr5IWUyjq4yuzPzL1+tYqu7Qo 0bJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7mhqmfxGRNd/oDp+oYziK6kcL//l+pvDRZhmIkBV42U=; b=SLsrlYwxAe3Rg/hPruK/UmOOmbeeVQOD074+tryKFPiqC2p2kXGfp/fyO0FPf2rwWn +3dDhyFjtREvDais9gyUNVC35gM5X02vTolj3uXCKdP0n43E1IOA8g9UPffZ3GFxpqre P1BRYcubhm7XJZyo/iiL8GXCM+TqoaUvSw8qHw2w0iTTD1LqickQrPeYzugWXyI5A04Z D9CRpH2lQM+Uyz/OUoe726snIp1jvONqmmIC5yWGm9xKtvAnRWrAmbZwE9pcM9QLWd57 SnIS3JQos0HlbY6lhGGo/YEVUwB+hKCKaCMuyA7p/Sltuqd+EUD/iCDTSEY1MzSha8w3 8xbA== X-Gm-Message-State: AA6/9RnQfibgw4DWw/hawWHjYUQTGSog6N7Ffc9vj/SnDxGzeiIFbZXLpw4u9WE+KGFEHw== X-Received: by 10.98.133.141 with SMTP id m13mr6686078pfk.147.1476846989748; Tue, 18 Oct 2016 20:16:29 -0700 (PDT) Received: from roar.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id aa6sm59152924pad.46.2016.10.18.20.16.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Oct 2016 20:16:29 -0700 (PDT) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 5/7] powerpc/64: handle linker stubs in low .text code Date: Wed, 19 Oct 2016 14:15:58 +1100 Message-Id: <20161019031600.17933-6-npiggin@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161019031600.17933-1-npiggin@gmail.com> References: <20161019031600.17933-1-npiggin@gmail.com> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stephen Rothwell , Nicholas Piggin Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Very large kernels require linker stubs, but the linker tends to place them in ways that make it very difficult to detect programatically with the assembler when taking absolute real (physical) addresses. This breaks the early boot code. Create a small section just before the .text section with an empty 256 - 4 bytes, and adjust the start of the .text section to match. The linker will tend to put stubs in that section and not break our start-of-.text section label. This is a tiny waste of space on common kernels, but allows large kernels to build and boot, which is convenient enough to outweigh the cost. This is a sad hack, which I will improve on if I can find out how to achieve it a better way. Until then, it seems to work. Signed-off-by: Nicholas Piggin --- arch/powerpc/include/asm/head-64.h | 16 +++++++++++++--- arch/powerpc/kernel/vmlinux.lds.S | 2 ++ arch/powerpc/tools/head_check.sh | 5 +++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/include/asm/head-64.h b/arch/powerpc/include/asm/head-64.h index 492ebe7..f7131cf 100644 --- a/arch/powerpc/include/asm/head-64.h +++ b/arch/powerpc/include/asm/head-64.h @@ -63,11 +63,21 @@ . = 0x0; \ start_##sname: +/* + * .linker_stub_catch section is used to catch linker stubs from being + * inserted in our .text section, above the start_text label (which breaks + * the ABS_ADDR calculation). See kernel/vmlinux.lds.S and tools/head_check.sh + * for more details. We would prefer to just keep a cacheline (0x80), but + * 0x100 seems to be how the linker aligns branch stub groups. + */ #define OPEN_TEXT_SECTION(start) \ - text_start = (start); \ + .section ".linker_stub_catch","ax",@progbits; \ +linker_stub_catch: \ + . = 0x4; \ .section ".text","ax",@progbits; \ - . = 0x0; \ -start_text: + text_start = (start) + 0x100; \ + .balign 0x100; \ +start_text: \ #define ZERO_FIXED_SECTION(sname, start, end) \ sname##_start = (start); \ diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S index 7de0b05..a09c666 100644 --- a/arch/powerpc/kernel/vmlinux.lds.S +++ b/arch/powerpc/kernel/vmlinux.lds.S @@ -73,6 +73,8 @@ SECTIONS } :kernel .text : AT(ADDR(.text) - LOAD_OFFSET) { + *(.linker_stub_catch); + . = . ; /* careful! __ftr_alt_* sections need to be close to .text */ ALIGN_FUNCTION(); *(.text .fixup __ftr_alt_* .ref.text); diff --git a/arch/powerpc/tools/head_check.sh b/arch/powerpc/tools/head_check.sh index 9635fe7..ae9faeb 100755 --- a/arch/powerpc/tools/head_check.sh +++ b/arch/powerpc/tools/head_check.sh @@ -23,6 +23,11 @@ # etc) in the fixed section region (0 - 0x8000ish). Check what places are # calling those stubs. # +# A ".linker_stub_catch" section is used to catch some stubs generated by +# early .text code, which tend to get placed at the start of the section. +# If there are too many such stubs, they can overflow this section. Expanding +# it may help (or reducing the number of stub branches). +# # Linker stubs use the TOC pointer, so even if fixed section code could # tolerate them being inserted into head code, they can't be allowed in low # level entry code (boot, interrupt vectors, etc) until r2 is set up. This