Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp388297pxb; Wed, 13 Apr 2022 03:36:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxO1tiOic7i6JvDoc75pt+GiJ+g13YwDCCmxiN3dVKGsAAD+2WkygK940ZVYmySioM/C7ok X-Received: by 2002:a17:902:f682:b0:154:8500:80bf with SMTP id l2-20020a170902f68200b00154850080bfmr42002092plg.112.1649846169345; Wed, 13 Apr 2022 03:36:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649846169; cv=none; d=google.com; s=arc-20160816; b=tLBPvr9PaAh0+scyA1XgB/liBy8sCJ2mxUjCVbhE1QtsAfTqyZhEqgvLx4kPv5IJt9 7BayZ05g2z/DjJ1KnNpolopEPxSY/uIIkcB68ajiOU8ddYhGfIODHRfPjNv/Wd8IFQgp ZMQre6hcsn/s4YAmneeUBdbXxiwFMCTDfMalbKYAAl9c4WzJzuGU6dGLK6H1rb1BpwFU cj9Tq0kr9Ms08cJ/kJTCTJAl1lUOD9f7OpnBB9gG+jq2K3Diu6BEBV26upIgVaYVxoMx wcSSlVqLRbED7TiGZ1V4NHJsFDGAPfSk7gta4qh4Uh99AUx6HWYvfzTxr8RjmTVu7VyI jfJA== 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 :dkim-signature; bh=EgTL4VNIKYlvmdQhFawLMMFW9frxcSpLBWlCsK4+EuA=; b=PI31Lemj4TtbEUSDMCrncFXdIkAVQawqtj3rlNHLsYN87huC0C9phoOxfEQ1gv2MVR U25PezW3A0TluVeMq3Vmpw45nuYvxnZBGJAmW45ov4MGeuBGoB+eNPB0lEWCpysR7Hdm VTdZd+CRmZXvDTLFRffk9z2pe5AnjOV9uH00a8ZY+mFJcPPVepwjlhf5+rhJDCpJlVlu uczKQPB/TcbYo4xfFnFe9LV5rYbE3WOG2CKhAjmprMn2Ouh8d/i/4DDp0ixLOY40LRAT RyS8RjQllMn4DUv2VbGBTes4G2VlefeQ/AqS/+V0sdxWYA1ZHcJqzvbsImtnrC87oq2h AGFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lpC2u8VB; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b15-20020a170903228f00b00153b2d16641si1342165plh.585.2022.04.13.03.35.56; Wed, 13 Apr 2022 03:36:09 -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; dkim=pass header.i=@linaro.org header.s=google header.b=lpC2u8VB; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233182AbiDMG57 (ORCPT + 99 others); Wed, 13 Apr 2022 02:57:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233200AbiDMG5i (ORCPT ); Wed, 13 Apr 2022 02:57:38 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0AA92DD72 for ; Tue, 12 Apr 2022 23:55:18 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id a16-20020a17090a6d9000b001c7d6c1bb13so1157840pjk.4 for ; Tue, 12 Apr 2022 23:55:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EgTL4VNIKYlvmdQhFawLMMFW9frxcSpLBWlCsK4+EuA=; b=lpC2u8VBw8yiA8bju+WTgVAQeQ744QXVIWPCGFjCUzzcOz28RCZWHmAwzHlFqIJMK8 Ri03+jB1jNbHP719pH63Q/KRDMzokqkdMVZQ6mgkPBGdwZD+nL6rEHTLslPWIOOBZdpJ RM7N3nADJnZ1U+PNc4XdxpGOU5uFE34w4aFgx6Gn0dJeMPQL/AJAgzhsaG1buqJSp1YR taEqks+wbqS+pLwurwG1liXYsSPna5gmTmMMzFy1nWhu979ZpiEkZ6+RqGPaPbWyRUD3 o10ETRrHulw6Hpirni26g+5nYgltoC3CtNVFKAZNUWeq0OM4agJXexl/5rzA78gNq5I4 1ACA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EgTL4VNIKYlvmdQhFawLMMFW9frxcSpLBWlCsK4+EuA=; b=EOf5/Ae+tQng+SK1+dWKxTv7qezbJjBL+AcVAnRhbo1/A2ojh5m5+J6BzglRA+ZftI u5Jc4ne4uqFbztDJ5zrcM4K8TRo1OpAWO8EPU8+pQuUscUsR89WyPxHQKCs0ZlR9/zdB UpqAUXe12YFFteICpNvF1r5WbCq7XbTXbDGNIJr5k3sr67ilJIK2Ft1parDGuWYQQA3g E6KjK2sa4MyXA/QI6WEpJEXhVjpDoGTuwa2hElX46rKK3OxNGfkXccQfg8JuRupi2q9J rxNuOsLPCT9WPwzRisLmOLwY5+Q4ko+dT05IAg5kyLcpdAo29pIR5y+vHhX9JaeQvK78 1M4w== X-Gm-Message-State: AOAM5323/d5yUCWg3ATXXrAPVcnzsreOoxxk+LIUQC17fTDuEfjuq2XU XawPi7KGBpv2ovJPJkhLipqS9w== X-Received: by 2002:a17:903:11d1:b0:151:9fb2:9858 with SMTP id q17-20020a17090311d100b001519fb29858mr40419078plh.136.1649832918149; Tue, 12 Apr 2022 23:55:18 -0700 (PDT) Received: from localhost.localdomain ([223.177.215.72]) by smtp.gmail.com with ESMTPSA id m15-20020a638c0f000000b003827bfe1f5csm4926908pgd.7.2022.04.12.23.55.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 23:55:17 -0700 (PDT) From: Sumit Garg To: linux-arm-kernel@lists.infradead.org, dianders@chromium.org, will@kernel.org, liwei391@huawei.com Cc: catalin.marinas@arm.com, mark.rutland@arm.com, mhiramat@kernel.org, daniel.thompson@linaro.org, jason.wessel@windriver.com, maz@kernel.org, linux-kernel@vger.kernel.org, Sumit Garg Subject: [PATCH v2 1/2] arm64: entry: Skip single stepping interrupt handlers Date: Wed, 13 Apr 2022 12:24:57 +0530 Message-Id: <20220413065458.88541-2-sumit.garg@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220413065458.88541-1-sumit.garg@linaro.org> References: <20220413065458.88541-1-sumit.garg@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,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 Current implementation allows single stepping into interrupt handlers for interrupts that were received during single stepping. But interrupt handlers aren't something that the user expect to debug. Moreover single stepping interrupt handlers is risky as it may sometimes leads to unbalanced locking when we resume from single-step debug. Fix broken single-step implementation via skipping single-step over interrupt handlers. The methodology is when we receive an interrupt from EL1, check if we are single stepping (pstate.SS). If yes then we save MDSCR_EL1.SS and clear the register bit if it was set. Then unmask only D and leave I set. On return from the interrupt, set D and restore MDSCR_EL1.SS. Along with this skip reschedule if we were stepping. Suggested-by: Will Deacon Signed-off-by: Sumit Garg --- arch/arm64/kernel/entry-common.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c index 878c65aa7206..dd2d3af615de 100644 --- a/arch/arm64/kernel/entry-common.c +++ b/arch/arm64/kernel/entry-common.c @@ -458,19 +458,35 @@ static __always_inline void __el1_irq(struct pt_regs *regs, do_interrupt_handler(regs, handler); irq_exit_rcu(); - arm64_preempt_schedule_irq(); + /* Don't reschedule in case we are single stepping */ + if (!(regs->pstate & DBG_SPSR_SS)) + arm64_preempt_schedule_irq(); exit_to_kernel_mode(regs); } + static void noinstr el1_interrupt(struct pt_regs *regs, void (*handler)(struct pt_regs *)) { + unsigned long reg; + + /* Disable single stepping within interrupt handler */ + if (regs->pstate & DBG_SPSR_SS) { + reg = read_sysreg(mdscr_el1); + write_sysreg(reg & ~DBG_MDSCR_SS, mdscr_el1); + } + write_sysreg(DAIF_PROCCTX_NOIRQ, daif); if (IS_ENABLED(CONFIG_ARM64_PSEUDO_NMI) && !interrupts_enabled(regs)) __el1_pnmi(regs, handler); else __el1_irq(regs, handler); + + if (regs->pstate & DBG_SPSR_SS) { + write_sysreg(DAIF_PROCCTX_NOIRQ | PSR_D_BIT, daif); + write_sysreg(reg, mdscr_el1); + } } asmlinkage void noinstr el1h_64_irq_handler(struct pt_regs *regs) -- 2.25.1