Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1820794rwn; Fri, 16 Sep 2022 00:59:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5V6aAhB2jtzq0eusRQR+Rb1/4StRbI75g9kmSingNTcUmISl3b64MH37cZzGlz1Dk9sF5R X-Received: by 2002:a17:90b:17ca:b0:200:b25e:cd7c with SMTP id me10-20020a17090b17ca00b00200b25ecd7cmr4130490pjb.53.1663315193626; Fri, 16 Sep 2022 00:59:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663315193; cv=none; d=google.com; s=arc-20160816; b=lT9ZzGjVKy/63eEXhAOpAEsWh56IL7QnmI+7i1mPw6kzBRg9FVBfs8bmrjRBTXF0Te pei5NoIT3/r5nt1Qa2kLWK9LMmrh4FRo4hoPX2m3VCI+muMlATGKKfij1r5uk2IuXUBX /Pnwk64EM32y7E3WiMED6zhTWyose5MUHvh6DAoVayfF5Hho6ukrfMSbfbll56MLqFGv Am5c1fMcpJYGYdXQYfvGeAwE19P+nCkk3yyOhRY94xcmEVfuODvJ/bpu7P8V3FP0QCTt 7EH4jL1T4BSxV3K9mDcOnvxE3d92NrpNOoS2njmLpqBBPQJ8FbkxWm8InsVAL1dmyTGR L5Ug== 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 :message-id:date:subject:cc:to:from; bh=qzdEUHS2fv3kmZHh+wzXnyNbU6yr0uq1yoHTlXN3ZLg=; b=lVd5+WKc/o3jLedtzblpTvd1317aP0mA7FIGrZ9LdAPZF+iDNu5j0zALQJ92cDMqtg QBG0IIjY3uFnWoKz7fGxD57QAroIUQ+dUDGRWssqstWyr6Mk0QdH5zS/YOYZ88T2cQ7D j49azvsZQXvoaELdSaXIOnIrT4Q3JGbYTqPxe5mhCOAbGFBqwztbRaHM4OGJUqvd63YK XNcU/VkjkBlNZsCRS06n1w9mVIDLcH3iCtw4D1OiAa2QeQHSrEU7N5PkqtSjGrEyaBhP XmTkWuuW5rcX8r+ggITKQYsn5GAYowGkz9a43b/Zh42Z0ZoAHlTubSVLm/cqfhXmqZER S0OQ== 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s12-20020a056a0008cc00b0054170e35633si6310488pfu.144.2022.09.16.00.59.42; Fri, 16 Sep 2022 00:59:53 -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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230045AbiIPHbG (ORCPT + 99 others); Fri, 16 Sep 2022 03:31:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229479AbiIPHbD (ORCPT ); Fri, 16 Sep 2022 03:31:03 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99D7B67C9C; Fri, 16 Sep 2022 00:30:58 -0700 (PDT) Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MTQcc44YFzlVxM; Fri, 16 Sep 2022 15:26:56 +0800 (CST) Received: from kwepemm600006.china.huawei.com (7.193.23.105) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 16 Sep 2022 15:30:57 +0800 Received: from huawei.com (10.44.142.108) by kwepemm600006.china.huawei.com (7.193.23.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 16 Sep 2022 15:30:56 +0800 From: To: , , , , , , CC: , , , , , , Longjun Luo Subject: [PATCH] uprobe: add UPROBE_ALTER_PC flag for uprobe handlers Date: Fri, 16 Sep 2022 15:28:46 +0800 Message-ID: <20220916072846.2145735-1-luolongjun@huawei.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.44.142.108] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600006.china.huawei.com (7.193.23.105) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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 From: Longjun Luo Within uprobe handlers, the pc register could be modified. In this situation, there is no need to do a single stepping. Just like the kprobe, we skip it. Signed-off-by: Longjun Luo --- include/linux/uprobes.h | 5 +++-- kernel/events/uprobes.c | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/include/linux/uprobes.h b/include/linux/uprobes.h index f46e0ca0169c..0670fecbe1ce 100644 --- a/include/linux/uprobes.h +++ b/include/linux/uprobes.h @@ -22,8 +22,9 @@ struct inode; struct notifier_block; struct page; -#define UPROBE_HANDLER_REMOVE 1 -#define UPROBE_HANDLER_MASK 1 +#define UPROBE_HANDLER_REMOVE 0x1 +#define UPROBE_ALTER_PC 0x2 +#define UPROBE_HANDLER_MASK 0x3 /* (UPROBE_HANDLER_REMOVE | UPROBE_ALTER_PC) */ #define MAX_URETPROBE_DEPTH 64 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index 2eaa327f8158..d01a668fecae 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -2064,10 +2064,16 @@ static struct uprobe *find_active_uprobe(unsigned long bp_vaddr, int *is_swbp) return uprobe; } -static void handler_chain(struct uprobe *uprobe, struct pt_regs *regs) +/* + * The return value of handler_chain tags events that happen during + * calling handlers. If UPROBE_ALTER_PC happens, we must skip the + * single stepping. + */ +static int handler_chain(struct uprobe *uprobe, struct pt_regs *regs) { struct uprobe_consumer *uc; int remove = UPROBE_HANDLER_REMOVE; + int all_events = 0; bool need_prep = false; /* prepare return uprobe, when needed */ down_read(&uprobe->register_rwsem); @@ -2084,6 +2090,7 @@ static void handler_chain(struct uprobe *uprobe, struct pt_regs *regs) need_prep = true; remove &= rc; + all_events |= rc; } if (need_prep && !remove) @@ -2094,6 +2101,7 @@ static void handler_chain(struct uprobe *uprobe, struct pt_regs *regs) unapply_uprobe(uprobe, current->mm); } up_read(&uprobe->register_rwsem); + return all_events; } static void @@ -2183,7 +2191,7 @@ static void handle_swbp(struct pt_regs *regs) { struct uprobe *uprobe; unsigned long bp_vaddr; - int is_swbp; + int is_swbp, all_events; bp_vaddr = uprobe_get_swbp_addr(regs); if (bp_vaddr == get_trampoline_vaddr()) @@ -2235,7 +2243,9 @@ static void handle_swbp(struct pt_regs *regs) if (arch_uprobe_ignore(&uprobe->arch, regs)) goto out; - handler_chain(uprobe, regs); + all_events = handler_chain(uprobe, regs); + if (all_events & UPROBE_ALTER_PC) + goto out; if (arch_uprobe_skip_sstep(&uprobe->arch, regs)) goto out; -- 2.37.3