From patchwork Tue Jun 19 19:26:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 139239 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp5598527lji; Tue, 19 Jun 2018 12:27:51 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLEHFe278/peKZJdpwXIGqUlqBHQTweRO6Q9Hk4e2pq8q92I2tRoQ2X4cMNCXbMLDNhEyqC X-Received: by 2002:a65:634a:: with SMTP id p10-v6mr15998035pgv.184.1529436471829; Tue, 19 Jun 2018 12:27:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529436471; cv=none; d=google.com; s=arc-20160816; b=DfVcNHcqCGOwYAMd8gkviKhhtVzgtznPzvhgTAaEuikBLBz9ceAjPVjYrHw/owsn+x +mTUIfvLso5LKPuq356eztE37jF6zdKTOxUXAynUBju71C6bqUbWzy6i3NoPWkyHjZXQ qvRTZDj7tQ4WduvaGWqiFJ+z2yVHZlx6+I9F3V9rpXVZxImwjvPoiRCwrWplmMc0I6p1 MnF+e7vIl8hagFR0+CD6KbH11jlnZQFN7dmqjnfBB0t1rrSjbtJ7iSctvgH+U2+638CF Xona9IfZfdmzVggsgEt5MKtMZJczGkuoOW7h3ZTnTH5/r9N6kW8B5XbKy7e49jhCHTFr LpnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=DW28HMLEUGoRqgLlA7upbDDKO5Z+/RlxqvmR8s+h2lw=; b=Q4H7Gw43xX/aKHFDBF6ud9XGGZfC2p361YwYfftekGIwa+EGvFSeeymn7bQrcWQnx8 jLwbcfQRBgT8irPq2osfUvqEh46k9H8IHtuVkdnM9l61zHdbcHqywPrQ7fKd6tAD924e kFRmHhF0r6U/rN8DW26OxOyIxMT1drTKFIZhP573i00ZV7cnTRypFRZqmVq5UhvekbJ3 AGQvK9jIaELJimCcwKlQaz6TOYAgAtcmI3DzObivNPkoWr0gdIclACpTYASwLP2LYj1W NKThaU1VRpDEIpvpsaaFN+jpXFGK04LSfRNLtPqKFcBhs5KerD/DjYyH4gamj6gy7DHe 8Gkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hj1YTnmP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i64-v6si345685pgc.673.2018.06.19.12.27.51; Tue, 19 Jun 2018 12:27:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hj1YTnmP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030443AbeFST1t (ORCPT + 30 others); Tue, 19 Jun 2018 15:27:49 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:38735 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967219AbeFST1r (ORCPT ); Tue, 19 Jun 2018 15:27:47 -0400 Received: by mail-wr0-f196.google.com with SMTP id e18-v6so798106wrs.5 for ; Tue, 19 Jun 2018 12:27:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DW28HMLEUGoRqgLlA7upbDDKO5Z+/RlxqvmR8s+h2lw=; b=hj1YTnmPbXxhKwvZEAVYKAjMPvGhzmGIgOZPls9AssyYVdfnulHJUr1bdvCOeNVBOF VLQRfv2CfWaZDO6wolpcmcWLW69oOD69fccM2NZ0maQgaUAvVYEYx+knBdKq6C+O7v4N Fh3E7OXHIkK65PWzlDmcpb88sSwdw6+ttuDtg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DW28HMLEUGoRqgLlA7upbDDKO5Z+/RlxqvmR8s+h2lw=; b=Ld3/qHFYF0TLleDpKLt0g1BXFlh99IUR/PUtCh6X9E5Q9VVk5BxcspxR1weXcm8/ez g+5bjrsaQTFDGm/cx6G4UEyfwn28NYJr97UTp+jeJyEmdJSjFHeqRduTdBG75bpWSlTR xIOINXQW/L2W5Ext8It30lR3fshOBZC9OeU8Ro7kcYKbR32/JXQL71491i/KPc58h58B Bb69fFd/+v8FcNt+Ncrw4tozMQ3JH5GKsDBHIJkliT1BLrGPB5nkoXB3cB8TaYO+9Cgt luLWVuD+yOfL4iYQHWxUU0Q86TZyzdpsxDaRRoA8rAMAhtsbm3pj/P04t5A7EGs8uWK5 KLug== X-Gm-Message-State: APt69E0iznjjHBiQQdJnyTG5cQvKfKmpoDipMjKrObnJoIw8RrsKpRbM BZrwTaUL0eDGAgNm2yV6haJrJw== X-Received: by 2002:adf:9187:: with SMTP id 7-v6mr16335104wri.69.1529436466172; Tue, 19 Jun 2018 12:27:46 -0700 (PDT) Received: from dogfood.home ([2a01:cb1d:112:6f00:a06d:5653:4fd5:13a]) by smtp.gmail.com with ESMTPSA id c53-v6sm982601wrg.12.2018.06.19.12.27.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Jun 2018 12:27:45 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: linux@armlinux.org.uk, linux@roeck-us.net, mark.rutland@arm.com, arnd@arndb.de, linux-kernel@vger.kernel.org, Ard Biesheuvel Subject: [PATCH 1/2] ARM: avoid badr macro for switching to Thumb-2 mode Date: Tue, 19 Jun 2018 21:26:32 +0200 Message-Id: <20180619192633.21846-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180619192633.21846-1-ard.biesheuvel@linaro.org> References: <20180619192633.21846-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Switching to Thumb-2 mode can be done using a single 'sub' instruction so use that instead of the badr macro in various places in the code. This allows us to reimplement the macro in a way that does not allow it to be used in ARM code sequences when building a Thumb2 kernel. Signed-off-by: Ard Biesheuvel --- arch/arm/common/mcpm_head.S | 5 ++--- arch/arm/kernel/head-nommu.S | 7 +++---- arch/arm/kernel/head.S | 15 +++++++-------- arch/arm/kernel/sleep.S | 7 +++---- 4 files changed, 15 insertions(+), 19 deletions(-) -- 2.17.1 diff --git a/arch/arm/common/mcpm_head.S b/arch/arm/common/mcpm_head.S index 08b3bb9bc6a2..4c72314e87a3 100644 --- a/arch/arm/common/mcpm_head.S +++ b/arch/arm/common/mcpm_head.S @@ -49,10 +49,9 @@ ENTRY(mcpm_entry_point) ARM_BE8(setend be) - THUMB( badr r12, 1f ) - THUMB( bx r12 ) + THUMB( sub pc, pc, #3 ) THUMB( .thumb ) -1: + mrc p15, 0, r0, c0, c0, 5 @ MPIDR ubfx r9, r0, #0, #8 @ r9 = cpu ubfx r10, r0, #8, #8 @ r10 = cluster diff --git a/arch/arm/kernel/head-nommu.S b/arch/arm/kernel/head-nommu.S index dae8fa2f72c5..406dab0b773c 100644 --- a/arch/arm/kernel/head-nommu.S +++ b/arch/arm/kernel/head-nommu.S @@ -47,10 +47,9 @@ ENTRY(stext) .arm ENTRY(stext) - THUMB( badr r9, 1f ) @ Kernel is always entered in ARM. - THUMB( bx r9 ) @ If this is a Thumb-2 kernel, - THUMB( .thumb ) @ switch to Thumb now. - THUMB(1: ) + THUMB( sub pc, pc, #3 ) @ Kernel is always entered in ARM. + THUMB( .thumb ) @ If this is a Thumb-2 kernel, + @ switch to Thumb now. #endif setmode PSR_F_BIT | PSR_I_BIT | SVC_MODE, r9 @ ensure svc mode diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S index 4b815821ec02..1e44ee9b2074 100644 --- a/arch/arm/kernel/head.S +++ b/arch/arm/kernel/head.S @@ -80,10 +80,9 @@ ENTRY(stext) ARM_BE8(setend be ) @ ensure we are in BE8 mode - THUMB( badr r9, 1f ) @ Kernel is always entered in ARM. - THUMB( bx r9 ) @ If this is a Thumb-2 kernel, - THUMB( .thumb ) @ switch to Thumb now. - THUMB(1: ) + THUMB( sub pc, pc, #3 ) @ Kernel is always entered in ARM. + THUMB( .thumb ) @ If this is a Thumb-2 kernel, + @ switch to Thumb now. #ifdef CONFIG_ARM_VIRT_EXT bl __hyp_stub_install @@ -363,10 +362,10 @@ __turn_mmu_on_loc: .text .arm ENTRY(secondary_startup_arm) - THUMB( badr r9, 1f ) @ Kernel is entered in ARM. - THUMB( bx r9 ) @ If this is a Thumb-2 kernel, - THUMB( .thumb ) @ switch to Thumb now. - THUMB(1: ) + THUMB( sub pc, pc, #3 ) @ Kernel is entered in ARM. + THUMB( .thumb ) @ If this is a Thumb-2 kernel, + @ switch to Thumb now. + ENTRY(secondary_startup) /* * Common entry point for secondary CPUs. diff --git a/arch/arm/kernel/sleep.S b/arch/arm/kernel/sleep.S index a8257fc9cf2a..76b3d7c1c8d0 100644 --- a/arch/arm/kernel/sleep.S +++ b/arch/arm/kernel/sleep.S @@ -123,10 +123,9 @@ ENDPROC(cpu_resume_after_mmu) #ifdef CONFIG_MMU .arm ENTRY(cpu_resume_arm) - THUMB( badr r9, 1f ) @ Kernel is entered in ARM. - THUMB( bx r9 ) @ If this is a Thumb-2 kernel, - THUMB( .thumb ) @ switch to Thumb now. - THUMB(1: ) + THUMB( sub pc, pc, #3 ) @ Kernel is entered in ARM. + THUMB( .thumb ) @ If this is a Thumb-2 kernel, + @ switch to Thumb now. #endif ENTRY(cpu_resume) From patchwork Tue Jun 19 19:26:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 139240 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp5598780lji; Tue, 19 Jun 2018 12:28:08 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKyr1N5iVaw+zDIhEjw2C9R3O2iFQVcCf2DCW5tS9NzufJ7+JwOvs0+njSc5Og9x94H5jNg X-Received: by 2002:a62:1747:: with SMTP id 68-v6mr19229082pfx.69.1529436488784; Tue, 19 Jun 2018 12:28:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529436488; cv=none; d=google.com; s=arc-20160816; b=cg88lvHYJpmwPgtIAiWHLFkCLINBUJkfZli3iOXpTui46BymjIXE6hmULfrW3p0rRu IZUVJRn4cV4UZf9p3kAdUO04Hjd56XTlJTIBLughDuIfdYhlyf+1QatedXo+QyDbp9MS I6nPNST1mWI4exhjqKQlhdjS1owrmo76ExBPEt7dieNhRyd21JC9vGBl7f64Hm7Sn7yR Ry7bMnlUelm1azVKlvigjIPpzuLlTrmR6bq2WZn75v/ST6HSx0DfWuDfsBirlyqb5aJn 4KtyXSuslumr+rz5P+Z7pYr6/KzzaFHJN3zr8Rc/7fEtfDvUgEBNq18Uj9AoEVb0OtMz NGMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=vXkMZMdtqXwQabFANthjvHFgEKPyu0gVz46zl6OeIVE=; b=K+pvKoU/9m7CFwwzv0QC8tdHUUaS6PndI4pHntUQo3KWFXdCOy09f3/vAaqdgHLmvB mZ+5hV/UWU9X2BrFUI1hgXvFcAzdA/EBl0t9HTOs6sm3tH5npAFpWCo+Nbo8yJe8zP7Q 0KUVPH+bzsi+sn25f1J3K710ZoprMVabHD2V0CBi3KjWCOpO1GTPRo6CcaWhcdISogFl VWTPMWdNSt+/7kjXpHDIL/jI4gKijEwh8sChkAwnV9mUqGSyWpYgwN0IuPBt2YmJGb8u OlW7evWzVFq4pw7HtsRm741vA4bz1IO9Swltwg+kqWAP1i8OxWLVB2suhuq1Qk1Mp5gb sJzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="i7GNC/TH"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j9-v6si389459pgt.16.2018.06.19.12.28.08; Tue, 19 Jun 2018 12:28:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="i7GNC/TH"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030488AbeFST2G (ORCPT + 30 others); Tue, 19 Jun 2018 15:28:06 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:46563 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967238AbeFST1s (ORCPT ); Tue, 19 Jun 2018 15:27:48 -0400 Received: by mail-wr0-f193.google.com with SMTP id v13-v6so768577wrp.13 for ; Tue, 19 Jun 2018 12:27:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vXkMZMdtqXwQabFANthjvHFgEKPyu0gVz46zl6OeIVE=; b=i7GNC/THtkqIFgVKnHdxUVIbmlKJIQy7v3p4BwEj1erCZvwTmWIa+/hKBzYZjD56Xu vMlyj27HMPXKIPMNFtnWvldICGi16v2J1M9Azc3oD69HaghjPgbPIKjvcmISiImH0rnq ++UP/h6sU4C+UubeUp2yZaTEL9W4nKhSquTcU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vXkMZMdtqXwQabFANthjvHFgEKPyu0gVz46zl6OeIVE=; b=gQ3r1qy/ea1v5/P2TWVwN42LifKdBtnh8cyySSQPeJ3DSRKWktlmrkS1SBqYMTmYmT U9azr7hNee4hsBJNhrEL34ybrumJaf3IqCxSC/+t/faES/PlrW4MFrdp9UeN4ypeUX94 E6M/XFEN2/ta60IHgXtF3mMBxTXa7vXypcBfv+6LYXvrqltssfPqXPVUvqtBe0rECmhP 87Pgt6Iez9xM42SUJNNM/i6F+HpxhKZ63SUDyny3wPEDt2IOuoov4fDxMcWyu9O5Rm21 sOP4zHRL9g1PpNGZSTbuYnX1rNggSFQd8hK3wPkS9i6TPdKxhhNM94j7r/lZxqYgXbRk 4cug== X-Gm-Message-State: APt69E0axfwloUWAtuBFhrctDww70tmVw6XzJ6jebJy+ot+USEx7QhS3 xoyn3l6KWEUG+lZl3PFC9f+VJg== X-Received: by 2002:adf:88ca:: with SMTP id g10-v6mr14060672wrg.62.1529436467570; Tue, 19 Jun 2018 12:27:47 -0700 (PDT) Received: from dogfood.home ([2a01:cb1d:112:6f00:a06d:5653:4fd5:13a]) by smtp.gmail.com with ESMTPSA id c53-v6sm982601wrg.12.2018.06.19.12.27.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Jun 2018 12:27:46 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: linux@armlinux.org.uk, linux@roeck-us.net, mark.rutland@arm.com, arnd@arndb.de, linux-kernel@vger.kernel.org, Ard Biesheuvel Subject: [PATCH 2/2] ARM: assembler: prevent ADR from setting the Thumb bit twice Date: Tue, 19 Jun 2018 21:26:33 +0200 Message-Id: <20180619192633.21846-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180619192633.21846-1-ard.biesheuvel@linaro.org> References: <20180619192633.21846-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To work around recent issues where ADR references to Thumb function symbols may or may not have the Thumb bit set already when they are resolved by GAS, reference the symbol indirectly via a local symbol typed as 'function', and emit the reference in a way that prevents the assembler from resolving it directly. Instead, it will be fixed up by the linker, which behaves consistently and according to spec when it comes to relocations of symbols with function annotation targetting wide ADR instructions. Signed-off-by: Ard Biesheuvel --- arch/arm/include/asm/assembler.h | 22 +++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h index 6ae42ad29518..ee2d4eb26318 100644 --- a/arch/arm/include/asm/assembler.h +++ b/arch/arm/include/asm/assembler.h @@ -195,13 +195,33 @@ .irp c,,eq,ne,cs,cc,mi,pl,vs,vc,hi,ls,ge,lt,gt,le,hs,lo .macro badr\c, rd, sym #ifdef CONFIG_THUMB2_KERNEL - adr\c \rd, \sym + 1 + __badr \c, \rd, \sym #else adr\c \rd, \sym #endif .endm .endr + /* + * GAS's behavior with respect to setting the Thumb bit on addresses + * of locally defined symbols taken using adr instructions is + * inconsistent, and so we are better off letting the linker handle + * it instead. So emit the reference as a relocation, and force a + * wide encoding so that we can support both forward and backward + * references, and avoid the R_ARM_THM_PC8 relocation that operates + * on the narrow encoding, which is documented as not taking the + * Thumb bit into account. (IHI 0044E ELF for the ARM Architecture) + * + * Note that this needs to be a separate macro or \@ does not work + * correctly. + */ + .macro __badr, c, rd, sym + .set .Lsym\@, \sym + .type .Lsym\@, %function + .reloc ., R_ARM_THM_ALU_PREL_11_0, .Lsym\@ + adr\c\().w \rd, . + .endm + /* * Get current thread_info. */