From patchwork Wed Oct 31 23:04:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 149890 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp97561ljp; Wed, 31 Oct 2018 16:06:39 -0700 (PDT) X-Google-Smtp-Source: AJdET5cRsThLDWQGNCCooXdfReOmn21db1KEPsddK8HO/cbQPOlwHD988hNyEwugY/dDF1uu/Zka X-Received: by 2002:a62:cc4:: with SMTP id 65-v6mr5253646pfm.127.1541027199493; Wed, 31 Oct 2018 16:06:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541027199; cv=none; d=google.com; s=arc-20160816; b=I++LhoNfQo23/74BYIXb3u0x7eP6RXpRylw4bT/AUfrAprLS1jnnHVLwFIpUO+Zr3+ D7zY2SSocJ1e4MdxfK34FT9kONXpPKOBeKvqkU03xYKQfckx6jfYUoHo8hNxKq6/1ftL QmQxow5e8kZQY4bVhWm9sSTUcJKM0M57fRMhlGDLAiNKV/XRevMXrqrX06prJ60lir+H qdXzzmjDbbXRmbcLFcEubRSMNq6IQGcqJkpqZ04WpQLJuRal5HIVrWmenx5r/0CM3fI7 EWOoDtprJKwybXorx1F0S3kLCHoCP7TyZmtK/zf9XyfIm19pGzshBgNRU3RfV+yCwLAz VLHw== 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; bh=blAKvVLFvLojGzhhtzh9H7sgMmwUksxipShHtmyKVSU=; b=EZUlqJ1znXrbmIyuxmw66C+eCJA+nnZme4eP6oMdDkT2ik02AHOlBnnUPMXX5wAK9k vs8+G4bkscUdJ/jlqCz858+VUH8J9VvWJ9aM/++epPMFUnk222AWh2bvTXQRAwOovM2G 0WkvxHNYECR3ZhX0h+iK27qV2nzUjx0skdWpn1r2VBQdWwL35MUMPnbrDBD+JhNRMbmZ 5yNjG7rfQ3GmQgxBeS+OeiKod1fzKSUSkVAeK+7Af5d06OtWRINjg2ohETchoXq0u3cU 64ed0y6YkspAYypU1Kv47r+co2yIngczF+awYjjRsFm64TMFPcGeJxXF0VmNhmznhcR0 YdJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="K/0EarHu"; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p12-v6si30763165pll.1.2018.10.31.16.06.39; Wed, 31 Oct 2018 16:06:39 -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=@kernel.org header.s=default header.b="K/0EarHu"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728344AbeKAIGr (ORCPT + 32 others); Thu, 1 Nov 2018 04:06:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:53942 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728327AbeKAIGq (ORCPT ); Thu, 1 Nov 2018 04:06:46 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2976420848; Wed, 31 Oct 2018 23:06:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027195; bh=QDC0TrLDjh7aIeb4fIot4Qxg9H6BuU/V2SPXreVQJaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K/0EarHur9QqcHMQsK+MhDccWzCqFpJoYpz4t5Izzw69v5mt10knGLpWwZTfbk0TG 348YcE+TpYOLrzLIZjVLlLe9YB/cX8UpOg4h9KNqiPszVs+ImJT1Q4tjEnvsg13q6E w1TkopWAUtzzjzPRyrDLnvR39zmhNYoaWANTHNBc= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Will Deacon , Catalin Marinas , Sasha Levin Subject: [PATCH AUTOSEL 4.19 059/146] arm64: entry: Allow handling of undefined instructions from EL1 Date: Wed, 31 Oct 2018 19:04:14 -0400 Message-Id: <20181031230541.28822-59-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Will Deacon [ Upstream commit 0bf0f444b2c49241b2b39aa3cf210d7c95ef6c34 ] Rather than panic() when taking an undefined instruction exception from EL1, allow a hook to be registered in case we want to emulate the instruction, like we will for the SSBS PSTATE manipulation instructions. Signed-off-by: Will Deacon Signed-off-by: Catalin Marinas Signed-off-by: Sasha Levin --- arch/arm64/kernel/entry.S | 2 +- arch/arm64/kernel/traps.c | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) -- 2.17.1 diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 09dbea221a27..8556876c9109 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -589,7 +589,7 @@ el1_undef: inherit_daif pstate=x23, tmp=x2 mov x0, sp bl do_undefinstr - ASM_BUG() + kernel_exit 1 el1_dbg: /* * Debug exception handling diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index 039e9ff379cc..b9da093e0341 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -310,10 +310,12 @@ static int call_undef_hook(struct pt_regs *regs) int (*fn)(struct pt_regs *regs, u32 instr) = NULL; void __user *pc = (void __user *)instruction_pointer(regs); - if (!user_mode(regs)) - return 1; - - if (compat_thumb_mode(regs)) { + if (!user_mode(regs)) { + __le32 instr_le; + if (probe_kernel_address((__force __le32 *)pc, instr_le)) + goto exit; + instr = le32_to_cpu(instr_le); + } else if (compat_thumb_mode(regs)) { /* 16-bit Thumb instruction */ __le16 instr_le; if (get_user(instr_le, (__le16 __user *)pc)) @@ -407,6 +409,7 @@ asmlinkage void __exception do_undefinstr(struct pt_regs *regs) return; force_signal_inject(SIGILL, ILL_ILLOPC, regs->pc); + BUG_ON(!user_mode(regs)); } void cpu_enable_cache_maint_trap(const struct arm64_cpu_capabilities *__unused)