Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp176450imd; Wed, 31 Oct 2018 16:51:32 -0700 (PDT) X-Google-Smtp-Source: AJdET5cYOjXZg44dzIYto+Vo0u7s/qzb7sGGoB4UrDFJ8Zr0cyTbGimIrS401uLNfl+oJAS0g7yy X-Received: by 2002:a62:9015:: with SMTP id a21-v6mr5415195pfe.49.1541029892412; Wed, 31 Oct 2018 16:51:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541029892; cv=none; d=google.com; s=arc-20160816; b=HGHemJrftkcjLQnsr9IOBE2jkRMkmNTh7xb0IMd4Ra3W4/F/2WaMWfaeP19278ARDX IUGQNXX4SLQWKDn3R/PE71RpgJXN+6y2N+Za/t0OQ1cw4y/vXU88kPMeIxdJmojsHikA t3rzfX9cF3LJRp2pSVJioQN7OViaF3kcg/fPU1aj558szm6sdZPSwQlJO/tBwWpgiZNB 1m/RjB8FRYAr4CweYiYB9DCF187+QPKAuZwrR4mIufEBKZlxo3hlJ1GytFofVLpgJFKx zFqeocmiOFJheALR0+fM0mhdKm+0c15sksyzVKAXZa8vss84PoUHi16H9t2XawzJahUQ Qi0g== 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 y35-v6si24559658pgl.14.2018.10.31.16.51.17; Wed, 31 Oct 2018 16:51:32 -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 S1728340AbeKAIGr (ORCPT + 99 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(-) 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) -- 2.17.1