Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp5944309rwr; Tue, 9 May 2023 08:13:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4/cuEk8UHA6n1/T9cXSaGBb5nkwvYNl2vQHJLqnvNqp4NopbjMu2SNHOJHUeMHvqLj0aXQ X-Received: by 2002:a05:6a00:cc8:b0:644:d220:64ac with SMTP id b8-20020a056a000cc800b00644d22064acmr14278600pfv.2.1683645237784; Tue, 09 May 2023 08:13:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683645237; cv=none; d=google.com; s=arc-20160816; b=iNeh7w7+HeKdSPBV/qcFLBoAJn4Bd05wn7ltO7z5A73aJ/hnQLIhJ1UUVwuwMONF6Z O1ay0GaSiw/49QocpjNQbZTX6TBNmNkDCJsfL8YPMm3vV87OYZM3xszLSyGfWKDx0OV1 DYFHVkA/9HvAKZaS3cOGbMxv841uQfISEckq7NfqEDZVkfwZaOGnuaL+RP09qYUa3cnY xoXiFvac92H/GBAVzI3NUNOIn4VGQD1vT4a8qXah6hN3dWE2LGrj6jaDqvR1IeUXs3Bx yrlY7ZCPOwuy8NjF2FuxgR8t0e03zF/5nzWO124Q9pSr2ElvYVfAy5fYTObY5K+HDtAx gG2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Ltmbw9GT0qn9eToGdm1T4ILANMieR8zXuM8b4MpiZ0s=; b=xWJkLEchtdfAhve+HJg0gqDH8jEc9ArzG3FBqmv3TGWVxfy+v5AkUEN0ufy5ZcaGjB Kg34/5Enp1QAF3HVy/txr9PVQnelAN1+R9o8x0WSnUXrYN9jmP1RIcOEJEQ/krsPmNOs FnUEYUz0kurNRoaASMfUXmm8SyfS7a0r/p5PImMh7Fuj5QtIB9TEkw1NX4KYIlnXM028 WPmEMDZFTy9hbDijZKqsZPa5FyNPia2Y7/xhFoWVlQV1OCS7rKb4FNWqHSci+Rpqb4p+ jJKocXMk2Bm9dAzzD4ngukFlJyULHGX0DpiKSc2a0OirZGus51HSCO7pcd+1LHh7F8dy GIjw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a28-20020a637f1c000000b0052502825c67si1789549pgd.387.2023.05.09.08.13.41; Tue, 09 May 2023 08:13:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235898AbjEIOYK (ORCPT + 99 others); Tue, 9 May 2023 10:24:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235869AbjEIOYC (ORCPT ); Tue, 9 May 2023 10:24:02 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6B6B13C0D for ; Tue, 9 May 2023 07:23:41 -0700 (PDT) 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 24A0DFEC; Tue, 9 May 2023 07:24:25 -0700 (PDT) Received: from e126864.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4407D3F663; Tue, 9 May 2023 07:23:38 -0700 (PDT) From: Kristina Martsenko To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev Cc: Catalin Marinas , Will Deacon , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Mark Rutland , Mark Brown , Luis Machado , Vladimir Murzin , linux-kernel@vger.kernel.org Subject: [PATCH v2 08/11] arm64: mops: handle single stepping after MOPS exception Date: Tue, 9 May 2023 15:22:32 +0100 Message-Id: <20230509142235.3284028-9-kristina.martsenko@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230509142235.3284028-1-kristina.martsenko@arm.com> References: <20230509142235.3284028-1-kristina.martsenko@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When a MOPS main or epilogue instruction is being executed, the task may get scheduled on a different CPU and restart execution from the prologue instruction. If the main or epilogue instruction is being single stepped then it makes sense to finish the step and take the step exception before starting to execute the next (prologue) instruction. So fast-forward the single step state machine when taking a MOPS exception. This means that if a main or epilogue instruction is single stepped with ptrace, the debugger will sometimes observe the PC moving back to the prologue instruction. (As already mentioned, this should be rare as it only happens when the task is scheduled to another CPU during the step.) This also ensures that perf breakpoints count prologue instructions consistently (i.e. every time they are executed), rather than skipping them when there also happens to be a breakpoint on a main or epilogue instruction. Acked-by: Catalin Marinas Signed-off-by: Kristina Martsenko --- arch/arm64/kernel/traps.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index 32dc692bffd3..4363e3b53a81 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -563,6 +563,12 @@ void do_el0_mops(struct pt_regs *regs, unsigned long esr) regs->pc -= 8; else regs->pc -= 4; + + /* + * If single stepping then finish the step before executing the + * prologue instruction. + */ + user_fastforward_single_step(current); } #define __user_cache_maint(insn, address, res) \ -- 2.25.1