From patchwork Thu Oct 10 18:44:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 175822 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp2683502ill; Thu, 10 Oct 2019 11:46:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqzZvjjCXRzD57OwM8AL6radGjEbZ6GMUCv2fa82zaIoNaMb++AREhkX44dAHXL8vGTU4Y4j X-Received: by 2002:aa7:c595:: with SMTP id g21mr9608089edq.79.1570733160308; Thu, 10 Oct 2019 11:46:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570733160; cv=none; d=google.com; s=arc-20160816; b=Nhw3tJjoVOXdEM5J9d26a79QVcrn9i0vOo/i+n5uU+1/jH2zccJbwTzrmYOKT07Yjn NqOKbPV3U0JeE98b0ERaWOSyGhipe49ohl26efe2xHTDoqrdQUuF9DCffxEYY79Mbe61 yMVuX5gd1ke/apT1pUbLR3iM6cSB5HJlPtt3vkgAPABcDAV/oD8hHPWH1IUDsVHGAP7m 6aOt9lJZ/Rb4MAv2jQTtrHMu/oZ/KTRdze+opj5y8TERRxsRIbCtDhXEW3RBoq7qP2ln GhVt1fHB5aILUPcpRAtzCeePHntNjXg3o5BPJUFNdiG4j7acMINFmWg6oRmAh9KN71dv pViQ== 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; bh=p502GKCfS7X7orgzhKITwI3bv9L7QdGCKFHxmbISN4U=; b=Mqobm/AvKoXu8UHyqiD+Xijy6XVDHfcVlVDD6/NLmXeV60r3JoYriTMgRfvuZf0J0k WcMK/k5ermfnRqcTGP3vMXA6IPzQbkRx1DuSRiOgkqBapAsHA0BlrYreZJpSM4GfIFaW WCAwbOmzw0dJsh6zsaBLDzCF6OkYCGQ2ITVX40iw1Bn8LAVBFJH4Wf/GNz6LUj2VQXPw WuvRdxXgFTO1ySNJM8ZpfuhNy1bMkQheZpShOFt7y20UXybzrSu1qjxex+DArY/3rBO7 stlT1PW/+DUbM355iu8OVKULHvkrEp0+cZrlvM0e26Kso0Uq53vk9WY0JCLyBUUFRms6 4gHA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u2si3728637ejr.332.2019.10.10.11.46.00; Thu, 10 Oct 2019 11:46:00 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727278AbfJJSp7 (ORCPT + 22 others); Thu, 10 Oct 2019 14:45:59 -0400 Received: from foss.arm.com ([217.140.110.172]:38512 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727261AbfJJSp4 (ORCPT ); Thu, 10 Oct 2019 14:45:56 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 14B051570; Thu, 10 Oct 2019 11:45:56 -0700 (PDT) Received: from e103592.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 654383F703; Thu, 10 Oct 2019 11:45:53 -0700 (PDT) From: Dave Martin To: linux-kernel@vger.kernel.org Cc: Andrew Jones , Arnd Bergmann , Catalin Marinas , Eugene Syromiatnikov , Florian Weimer , "H.J. Lu" , Jann Horn , Kees Cook , =?utf-8?q?Kristina_Mart=C5=A1enko?= , Mark Brown , Paul Elliott , Peter Zijlstra , Richard Henderson , Sudakshina Das , Szabolcs Nagy , Thomas Gleixner , Will Deacon , Yu-cheng Yu , Amit Kachhap , Vincenzo Frascino , linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 09/12] arm64: traps: Fix inconsistent faulting instruction skipping Date: Thu, 10 Oct 2019 19:44:37 +0100 Message-Id: <1570733080-21015-10-git-send-email-Dave.Martin@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1570733080-21015-1-git-send-email-Dave.Martin@arm.com> References: <1570733080-21015-1-git-send-email-Dave.Martin@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Correct skipping of an instruction on AArch32 works a bit differently from AArch64, mainly due to the different CPSR/PSTATE semantics. There have been various attempts to get this right. Currenty arm64_skip_faulting_instruction() mostly does the right thing, but does not advance the IT state machine for the AArch32 case. arm64_compat_skip_faulting_instruction() handles the IT state machine but is local to traps.c, and porting other code to use it will make a mess since there are some call sites that apply for both the compat and native cases. Since manual instruction skipping implies a trap, it's a relatively slow path. So, make arm64_skip_faulting_instruction() handle both compat and native, and get rid of the arm64_compat_skip_faulting_instruction() special case. Fixes: 32a3e635fb0e ("arm64: compat: Add CNTFRQ trap handler") Fixes: 1f1c014035a8 ("arm64: compat: Add condition code checks and IT advance") Fixes: 6436beeee572 ("arm64: Fix single stepping in kernel traps") Fixes: bd35a4adc413 ("arm64: Port SWP/SWPB emulation support from arm") Signed-off-by: Dave Martin --- arch/arm64/kernel/traps.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) -- 2.1.4 Reviewed-by: Mark Rutland diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index 15e3c4f..44c91d4 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -268,6 +268,8 @@ void arm64_notify_die(const char *str, struct pt_regs *regs, } } +static void advance_itstate(struct pt_regs *regs); + void arm64_skip_faulting_instruction(struct pt_regs *regs, unsigned long size) { regs->pc += size; @@ -278,6 +280,9 @@ void arm64_skip_faulting_instruction(struct pt_regs *regs, unsigned long size) */ if (user_mode(regs)) user_fastforward_single_step(current); + + if (regs->pstate & PSR_MODE32_BIT) + advance_itstate(regs); } static LIST_HEAD(undef_hook); @@ -629,19 +634,12 @@ static void advance_itstate(struct pt_regs *regs) compat_set_it_state(regs, it); } -static void arm64_compat_skip_faulting_instruction(struct pt_regs *regs, - unsigned int sz) -{ - advance_itstate(regs); - arm64_skip_faulting_instruction(regs, sz); -} - static void compat_cntfrq_read_handler(unsigned int esr, struct pt_regs *regs) { int reg = (esr & ESR_ELx_CP15_32_ISS_RT_MASK) >> ESR_ELx_CP15_32_ISS_RT_SHIFT; pt_regs_write_reg(regs, reg, arch_timer_get_rate()); - arm64_compat_skip_faulting_instruction(regs, 4); + arm64_skip_faulting_instruction(regs, 4); } static const struct sys64_hook cp15_32_hooks[] = { @@ -661,7 +659,7 @@ static void compat_cntvct_read_handler(unsigned int esr, struct pt_regs *regs) pt_regs_write_reg(regs, rt, lower_32_bits(val)); pt_regs_write_reg(regs, rt2, upper_32_bits(val)); - arm64_compat_skip_faulting_instruction(regs, 4); + arm64_skip_faulting_instruction(regs, 4); } static const struct sys64_hook cp15_64_hooks[] = { @@ -682,7 +680,7 @@ asmlinkage void __exception do_cp15instr(unsigned int esr, struct pt_regs *regs) * There is no T16 variant of a CP access, so we * always advance PC by 4 bytes. */ - arm64_compat_skip_faulting_instruction(regs, 4); + arm64_skip_faulting_instruction(regs, 4); return; }