Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1375299ybf; Thu, 27 Feb 2020 09:45:41 -0800 (PST) X-Google-Smtp-Source: APXvYqyuu/1t+A94HK6lLCrDPPoicWzGhBSVx17cuVs6PNKw3JB3L+W15s2BxA3QfB80Vh1hESjl X-Received: by 2002:aca:5447:: with SMTP id i68mr136295oib.31.1582825541501; Thu, 27 Feb 2020 09:45:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582825541; cv=none; d=google.com; s=arc-20160816; b=Cm4AbBiPZxC1xuFucyIplM2yHgLV7Q5pjvG0vAh078RsTP5iz8P0UqcufWT4HkNxbR jKYOHC0QFTxfLinOGG6Pv0UB9xCE/bZ2FtEqQLmOBRdFC5ZqvzDmDsz5ElgMBU7M+VVV itoYHgwMZeA74Ni3nII4909WpJJS/syAa6Mr2nr6tBkNc9PS5Bso2z7K5Qbb8GwhWAEq cKfyA3I/29B+9nFMG275MNqqLZlIqhTfMVvwRtgTOf8dxiBE4VpAhQSzLx2LXn6M3QLf c9mhxrRY/5w5oQXwQix6kaV/gytHEWxr70IwHUTrwxzUh5bB9J//50/pbs5gR9cqHvNQ R16Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=aUbiGIP2IoUMQsdsY/AEqGhg7oXZoDLcBF9y24IEooI=; b=HN/JJtMYULcLTljLsJj+iLPGvaLYkG2brMQ9CmyY/cyMMSgEwGjqnzTYwBWhBZhzJk u2nRqLsZ0IE94aeoaeemKmgRF+fg7UdxRd94Zut7z8+D8DxwrbvAyYEwxCNCCSHpbX4q dNpWqIWtMrNrmPA72wyz1PnvoM0Rp6u1GTr+kcIxQCEKZe+lV4jtBZNb5duWywFytUC1 p9u+8K4A4cjDJDaOrs0HTuwaRO0gfI++56hocacx5mVbvPrW3RZ3PF5UMlZsvW9F3x4C oTegAngIMIF2Ix38dSTwUA4jH9MQ/otfgATPXic+pfMcwYrZSEU+1DGpXZUdSMiJMSVo KGsg== 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; dmarc=fail (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 c8si437742oto.95.2020.02.27.09.45.29; Thu, 27 Feb 2020 09:45:41 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730683AbgB0Roj (ORCPT + 99 others); Thu, 27 Feb 2020 12:44:39 -0500 Received: from foss.arm.com ([217.140.110.172]:55620 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730666AbgB0Roi (ORCPT ); Thu, 27 Feb 2020 12:44:38 -0500 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 224F44B2; Thu, 27 Feb 2020 09:44:38 -0800 (PST) Received: from localhost (unknown [10.37.6.21]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 64F893F73B; Thu, 27 Feb 2020 09:44:37 -0800 (PST) From: Mark Brown To: Catalin Marinas , Will Deacon Cc: Alexander Viro , Paul Elliott , Peter Zijlstra , Yu-cheng Yu , Amit Kachhap , Vincenzo Frascino , Marc Zyngier , Eugene Syromiatnikov , Szabolcs Nagy , "H . J . Lu " , Andrew Jones , Kees Cook , Arnd Bergmann , Jann Horn , Richard Henderson , =?UTF-8?q?Kristina=20Mart=C5=A1enko?= , Thomas Gleixner , Florian Weimer , Sudakshina Das , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-fsdevel@vger.kernel.org, Dave Martin , Mark Rutland , Mark Brown Subject: [PATCH v8 07/11] arm64: unify native/compat instruction skipping Date: Thu, 27 Feb 2020 17:44:13 +0000 Message-Id: <20200227174417.23722-8-broonie@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200227174417.23722-1-broonie@kernel.org> References: <20200227174417.23722-1-broonie@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dave Martin Skipping of an instruction on AArch32 works a bit differently from AArch64, mainly due to the different CPSR/PSTATE semantics. Currently arm64_skip_faulting_instruction() is only suitable for AArch64, and arm64_compat_skip_faulting_instruction() handles the IT state machine but is local to traps.c. 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. Signed-off-by: Dave Martin Reviewed-by: Mark Rutland Reviewed-by: Kees Cook Signed-off-by: Mark Brown --- arch/arm64/kernel/traps.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index b8c714dda851..bc9f4292bfc3 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -272,6 +272,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; @@ -282,6 +284,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); @@ -644,19 +649,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[] = { @@ -676,7 +674,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[] = { @@ -697,7 +695,7 @@ void 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; } -- 2.20.1