From patchwork Sat Jan 31 19:49:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 44092 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C4F5D2359E for ; Sat, 31 Jan 2015 19:52:38 +0000 (UTC) Received: by mail-wi0-f199.google.com with SMTP id r20sf8446126wiv.2 for ; Sat, 31 Jan 2015 11:52:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :content-type:content-transfer-encoding:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list; bh=s6ecQwVA7CnYIP34U4Nl02JYMkDVhFIGcJ7jxb9PnsA=; b=A8/j9Kv5Y1w9c1TIPs64yAiabif7j6a7Z7Yfz9/7axC7fiaQLmOsusPoWXoHw+nj4L notbL3/dY2fXIhC+8hSrIfgI364ytXvmDmIIWg2Cibr5lLOf0/n3efp8OSOsfKxpyndD cI5tA12gh2N8S++6f05MrOkr8jM2aw0xHjeNt9laZ+GGAiVRftKEtZbN2qY+zWBfQ6VX PEBxV8+4I6/QxIJaCMXZbll+Ykw9nYGYl9y0omTSgrI04AXE4O6kPzblpNDEmSDx++4B BC4oYDymgi859gpgNugBIGDf9rkMSAvKqPJx43BqZsFCm6vPgGDyUSaR3jAjZy9wuyof fDpw== X-Gm-Message-State: ALoCoQkYjzgYaXVmDq1vEVWNH+qKSasou+mdyzNjhDB8txGCSZDjbL2RsfT31O+eYfiTnOaVi73T X-Received: by 10.112.64.171 with SMTP id p11mr1502665lbs.12.1422733957853; Sat, 31 Jan 2015 11:52:37 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.28.132 with SMTP id b4ls8020lah.16.gmail; Sat, 31 Jan 2015 11:52:37 -0800 (PST) X-Received: by 10.112.125.4 with SMTP id mm4mr12138885lbb.86.1422733957634; Sat, 31 Jan 2015 11:52:37 -0800 (PST) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com. [209.85.215.54]) by mx.google.com with ESMTPS id ug7si12989920lbb.108.2015.01.31.11.52.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 31 Jan 2015 11:52:37 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.54 as permitted sender) client-ip=209.85.215.54; Received: by mail-la0-f54.google.com with SMTP id hv19so30253352lab.13 for ; Sat, 31 Jan 2015 11:52:37 -0800 (PST) X-Received: by 10.152.8.1 with SMTP id n1mr11806854laa.47.1422733957152; Sat, 31 Jan 2015 11:52:37 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp432124lbj; Sat, 31 Jan 2015 11:52:36 -0800 (PST) X-Received: by 10.68.136.228 with SMTP id qd4mr17991974pbb.122.1422733952068; Sat, 31 Jan 2015 11:52:32 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id af9si18268951pbd.3.2015.01.31.11.52.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 31 Jan 2015 11:52:32 -0800 (PST) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YHe45-0001HT-6Y; Sat, 31 Jan 2015 19:50:45 +0000 Received: from mail-wg0-f52.google.com ([74.125.82.52]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YHe3s-00015t-Hv for linux-arm-kernel@lists.infradead.org; Sat, 31 Jan 2015 19:50:34 +0000 Received: by mail-wg0-f52.google.com with SMTP id y19so32236618wgg.11 for ; Sat, 31 Jan 2015 11:50:09 -0800 (PST) X-Received: by 10.195.13.104 with SMTP id ex8mr26972350wjd.12.1422733809666; Sat, 31 Jan 2015 11:50:09 -0800 (PST) Received: from ards-macbook-pro.local ([197.130.213.20]) by mx.google.com with ESMTPSA id p6sm12474256wia.14.2015.01.31.11.50.03 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 31 Jan 2015 11:50:08 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, linux@arm.linux.org.uk, nico@linaro.org, dave.martin@linaro.org Subject: [PATCH resend 4/4] ARM: add partial interworking support to Thumb-2 kernel Date: Sat, 31 Jan 2015 19:49:19 +0000 Message-Id: <1422733759-27236-5-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1422733759-27236-1-git-send-email-ard.biesheuvel@linaro.org> References: <1422733759-27236-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150131_115032_762357_93548042 X-CRM114-Status: GOOD ( 18.05 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.52 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [74.125.82.52 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: Ard Biesheuvel X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.54 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 ARM/Thumb interworking is currently not allowed in modules at all: external module dependencies can only be fulfilled by symbols of the same flavour, but even inside a module, jumps and calls between objects are rejected if they would incur a mode switch. This patch relaxes that restriction somewhat, by allowing function calls ('bl') from T32 into A32 code. If a non-Thumb function symbol is encountered, a 'bl' instruction is converted into a 'blx' instruction, with the appropriate rounding applied to the offset. The most compelling argument for allowing this is that many modules, especially accelerated crypto, follow the pattern of a core object coded in assembly that is wired up to the kernel APIs using a glue object coded in C. With this patch, such assembly core objects no longer have to be developed, tested and maintained in both ARM and Thumb-2 modes: just having an ARM version suffices. Signed-off-by: Ard Biesheuvel --- arch/arm/kernel/module.c | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c index 6c08b2188992..ceb1812c2bbc 100644 --- a/arch/arm/kernel/module.c +++ b/arch/arm/kernel/module.c @@ -180,8 +180,9 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex, case R_ARM_THM_CALL: case R_ARM_THM_JUMP24: /* - * For function symbols, only Thumb addresses are - * allowed (no interworking). + * For function symbols, we need to force a + * Thumb -> ARM mode switch if the destination + * address has its Thumb bit (bit 0) cleared. * This applies equally to untyped symbols that * resolve to external ksyms: EXPORT_SYMBOL() * strips the function annotation, but we can @@ -197,9 +198,21 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex, (ELF32_ST_TYPE(sym->st_info) == STT_NOTYPE && sym->st_shndx == SHN_UNDEF)) && !(sym->st_value & 1)) { - pr_err("%s: section %u reloc %u sym '%s': unsupported interworking call (Thumb -> ARM)\n", - module->name, relindex, i, symname); - return -ENOEXEC; + + /* + * Only interworking call relocations can + * be supported, as long as the destination + * is in range. + */ + if (ELF32_R_TYPE(rel->r_info) != R_ARM_THM_CALL) { + pr_err("%s: section %u reloc %u sym '%s': unsupported interworking call (Thumb -> ARM)\n", + module->name, relindex, i, + symname); + return -ENOEXEC; + } + tmp = sym->st_value; + } else { + tmp = sym->st_value | 1; } upper = __mem_to_opcode_thumb16(*(u16 *)loc); @@ -227,7 +240,17 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex, ((lower & 0x07ff) << 1); if (offset & 0x01000000) offset -= 0x02000000; - offset += sym->st_value - loc; + offset += tmp; + + /* + * When fixing up a bl instruction to blx, the address + * of the call site must be rounded down in the + * calculation of 'offset'. As this could potentially + * cause 'offset' to go out of range, we need to do + * this before performing the range check. + */ + tmp = offset & 1 ? loc : loc & ~2; + offset -= tmp; /* * Route through a PLT entry if 'offset' exceeds the @@ -237,8 +260,11 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex, (offset <= (s32)0xff000000 || offset >= (s32)0x01000000)) offset = get_module_plt(module, loc, - offset + loc + 4) + offset + tmp + 4) - loc - 4; + else if (!(offset & 1)) + /* fix up bl -> blx */ + lower &= ~(1 << 12); if (offset <= (s32)0xff000000 || offset >= (s32)0x01000000) {