Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1127465ybk; Sat, 16 May 2020 01:49:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6go3mcbtY7nrhnkuyM+HlC4ela+ebGYlrkhxj1rJbrhGa03aCxtbfJarpkBHrZqWSZdmq X-Received: by 2002:a05:6402:297:: with SMTP id l23mr6430833edv.57.1589618965938; Sat, 16 May 2020 01:49:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589618965; cv=none; d=google.com; s=arc-20160816; b=IgDT6NsmasyA4ODYPnsbX/5PE0ULopvEMAIhkW3QMy0CNZ6FQ2ccR0VWNFiVXEWeGI 5NiwPo4wFb1rfWQSIBysS82dPP8tGMGOQGzuX6CYilZlpSB3lS+7TpvqaYNBAd1OOJ4U ZG0yWs6DQw4LbuGL6EALuOzkjtXqzSe4smsASgfCZItbRe2s2d3NK0oyAkwulzhdRG2l F+5y+dklemgS0cNXzFnZMswiFDkyFrqJ5/KIOQy66BP5cGkJtAqlaIjKg0m1MBdx0Vrh NBGjsWZtAZGQuBuqJakaESuMWw9Z8aHIO+WfUR3rScBEv5xEVr0DcEsPOQ8ByGjkDN61 TeaA== 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:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=vvabkU7YxRVztQYaExDJKhDqBfpm5aCVKu3i5EXUNpI=; b=WG7cRDTzw2ai1+/MfeiTCk3QEQqWu2VAJ+NqlkSB+ksBboZvpE+q53lENFXepSxgiy I7dhMFffY3U/HV+e1NXHNugQvVqFNz57TcpbUXd1FJ1s/bV0KIe37VD8p4mx6GkYteX2 3xLfsmVdO7B1XfFwhPF7OuP8rkxzZmbvQQO5+EKNqqLsQHG7ZOUSFqLeUM8LWSIEcVdx /Pa8F1UKxPQdLZygkRI6h/L6i1a7DmNfLj929xQ2weiZtCN5IOoygfZqjwbU/2IVBK/P KD/5DUnmyjX6LqGaGxZcs/XZL4SUdN5dzC0IISSTCyZCZWtPs8prWPAiqPPcTsmt/jSy i+hQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h10si2682509eja.307.2020.05.16.01.48.59; Sat, 16 May 2020 01:49:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726899AbgEPIrN (ORCPT + 99 others); Sat, 16 May 2020 04:47:13 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:4799 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725997AbgEPIrM (ORCPT ); Sat, 16 May 2020 04:47:12 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 7880A39151B447A1EF14; Sat, 16 May 2020 16:47:11 +0800 (CST) Received: from [10.166.215.145] (10.166.215.145) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.487.0; Sat, 16 May 2020 16:47:08 +0800 Subject: Re: [PATCH 2/4] arm64: Extract kprobes_save_local_irqflag() and kprobes_restore_local_irqflag() To: Doug Anderson CC: Daniel Thompson , Jason Wessel , Marc Zyngier , Mark Rutland , Masami Hiramatsu , David Miller , Will Deacon , Catalin Marinas , Linux ARM , LKML , References: <20200509214159.19680-1-liwei391@huawei.com> <20200509214159.19680-3-liwei391@huawei.com> From: "liwei (GF)" Message-ID: Date: Sat, 16 May 2020 16:47:07 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.3.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.166.215.145] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Douglas, On 2020/5/14 8:21, Doug Anderson wrote: (SNIP) >> +/* >> + * Interrupts need to be disabled before single-step mode is set, and not >> + * reenabled until after single-step mode ends. >> + * Without disabling interrupt on local CPU, there is a chance of >> + * interrupt occurrence in the period of exception return and start of >> + * out-of-line single-step, that result in wrongly single stepping >> + * into the interrupt handler. >> + */ >> +void kernel_prepare_single_step(unsigned long *flags, >> + struct pt_regs *regs) >> +{ >> + *flags = regs->pstate & DAIF_MASK; >> + regs->pstate |= PSR_I_BIT; >> + /* Unmask PSTATE.D for enabling software step exceptions. */ >> + regs->pstate &= ~PSR_D_BIT; >> +} >> +NOKPROBE_SYMBOL(kernel_prepare_single_step); > > nit: why not just return unsigned long rather than passing by reference? Because i just extract this function from kprobes_save_local_irqflag(), i think return unsigned long is fine. > >> + >> +void kernel_cleanup_single_step(unsigned long flags, >> + struct pt_regs *regs) >> +{ >> + regs->pstate &= ~DAIF_MASK; >> + regs->pstate |= flags; >> +} >> +NOKPROBE_SYMBOL(kernel_cleanup_single_step); >> + >> /* ptrace API */ >> void user_enable_single_step(struct task_struct *task) >> { >> diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c >> index d1c95dcf1d78..c655b6b543e3 100644 >> --- a/arch/arm64/kernel/probes/kprobes.c >> +++ b/arch/arm64/kernel/probes/kprobes.c >> @@ -168,30 +168,6 @@ static void __kprobes set_current_kprobe(struct kprobe *p) >> __this_cpu_write(current_kprobe, p); >> } >> >> -/* >> - * Interrupts need to be disabled before single-step mode is set, and not >> - * reenabled until after single-step mode ends. >> - * Without disabling interrupt on local CPU, there is a chance of >> - * interrupt occurrence in the period of exception return and start of >> - * out-of-line single-step, that result in wrongly single stepping >> - * into the interrupt handler. >> - */ >> -static void __kprobes kprobes_save_local_irqflag(struct kprobe_ctlblk *kcb, >> - struct pt_regs *regs) >> -{ >> - kcb->saved_irqflag = regs->pstate & DAIF_MASK; >> - regs->pstate |= PSR_I_BIT; >> - /* Unmask PSTATE.D for enabling software step exceptions. */ >> - regs->pstate &= ~PSR_D_BIT; >> -} >> - >> -static void __kprobes kprobes_restore_local_irqflag(struct kprobe_ctlblk *kcb, >> - struct pt_regs *regs) >> -{ >> - regs->pstate &= ~DAIF_MASK; >> - regs->pstate |= kcb->saved_irqflag; >> -} >> - >> static void __kprobes >> set_ss_context(struct kprobe_ctlblk *kcb, unsigned long addr) >> { >> @@ -227,7 +203,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, >> set_ss_context(kcb, slot); /* mark pending ss */ >> >> /* IRQs and single stepping do not mix well. */ >> - kprobes_save_local_irqflag(kcb, regs); >> + kernel_prepare_single_step(&kcb->saved_irqflag, regs); > > Is there some reason to have two functions? It seems like every time > you call kernel_enable_single_step() you'd want to call > kernel_prepare_single_step(). ...and every time you call > kernel_disable_single_step() you'd want to call > kernel_cleanup_single_step(). > > Maybe you can just add the flags parameter to > kernel_enable_single_step() / kernel_disable_single_step() and put the > code in there? > As kernel_enable_single_step() / kernel_disable_single_step() are also called in breakpoint_handler() and watchpoint_handler(), i am not sure it's a right thing to put the daif flag prepare/cleanup into them, especially we don't have a context to save the flags. Thanks, Wei