From patchwork Tue Aug 27 11:00:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liao Chang X-Patchwork-Id: 13779323 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7A262C54735 for ; Tue, 27 Aug 2024 11:11:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:CC:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=4QI6ebqbzdcmLFiAPI40cLfiV8deKDJAkUnYsjpuaaY=; b=A6seFueq7sr+wT3TsvUjgd0P9q XoaLv2lT+FDROEWWVkThtah8CZp1txeYTtPbhZPsYaIRJ1Jnh0pC9uAmGEYc4vgjf4V2H3epF+8kC jczESkrO8+gafoGOTBn5CnqMbk1sY5ELz9l+qFrCDZa0ZJDaxbUXnrx7FYxwmbCGZP2XBA2VCwo/z /v4z0IPvETfRiBLFoJ5YABcrkEnb2ZpvdRRf4LX91bJHkzo9+Kjss0mq7LIvVHoleftpMWGNRJb4H LDmINwxoAT6rNHxe12lJJYpsDtpsSXHg2+qYxCUW0pBYgyxfBW+anDWI6wYIItrhOauni8zlZTiDL wuuQj7zw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1siu6v-0000000AwFX-2IST; Tue, 27 Aug 2024 11:11:41 +0000 Received: from szxga02-in.huawei.com ([45.249.212.188]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1siu5s-0000000Aw3U-3sgY for linux-arm-kernel@lists.infradead.org; Tue, 27 Aug 2024 11:10:38 +0000 Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4WtPtL3bjRzpTpd; Tue, 27 Aug 2024 19:08:42 +0800 (CST) Received: from kwepemd200013.china.huawei.com (unknown [7.221.188.133]) by mail.maildlp.com (Postfix) with ESMTPS id 06338180064; Tue, 27 Aug 2024 19:10:23 +0800 (CST) Received: from huawei.com (10.67.174.28) by kwepemd200013.china.huawei.com (7.221.188.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Tue, 27 Aug 2024 19:10:22 +0800 From: Liao Chang To: , , , , CC: , Subject: [PATCH] arm64: Return early when break handler is found on linked-list Date: Tue, 27 Aug 2024 11:00:46 +0000 Message-ID: <20240827110046.3209679-1-liaochang1@huawei.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.67.174.28] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemd200013.china.huawei.com (7.221.188.133) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240827_041037_241939_8E7CE38C X-CRM114-Status: UNSURE ( 9.88 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The search for breakpoint handlers iterate through the entire linked list. Given that all registered hook has a valid fn field, and no registered hooks share the same mask and imm. This commit optimize the efficiency slightly by returning early as a matching handler is found. Signed-off-by: Liao Chang --- arch/arm64/kernel/debug-monitors.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c index 024a7b245056..fc998956f44c 100644 --- a/arch/arm64/kernel/debug-monitors.c +++ b/arch/arm64/kernel/debug-monitors.c @@ -281,6 +281,7 @@ static LIST_HEAD(kernel_break_hook); void register_user_break_hook(struct break_hook *hook) { + WARN_ON(!hook->fn); register_debug_hook(&hook->node, &user_break_hook); } @@ -291,6 +292,7 @@ void unregister_user_break_hook(struct break_hook *hook) void register_kernel_break_hook(struct break_hook *hook) { + WARN_ON(!hook->fn); register_debug_hook(&hook->node, &kernel_break_hook); } @@ -303,7 +305,6 @@ static int call_break_hook(struct pt_regs *regs, unsigned long esr) { struct break_hook *hook; struct list_head *list; - int (*fn)(struct pt_regs *regs, unsigned long esr) = NULL; list = user_mode(regs) ? &user_break_hook : &kernel_break_hook; @@ -313,10 +314,10 @@ static int call_break_hook(struct pt_regs *regs, unsigned long esr) */ list_for_each_entry_rcu(hook, list, node) { if ((esr_brk_comment(esr) & ~hook->mask) == hook->imm) - fn = hook->fn; + return hook->fn(regs, esr); } - return fn ? fn(regs, esr) : DBG_HOOK_ERROR; + return DBG_HOOK_ERROR; } NOKPROBE_SYMBOL(call_break_hook);