From patchwork Fri May 26 05:15:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 99289 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp239052vqr; Thu, 25 May 2023 22:20:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ57NHigGCLl0PmsiO/BOYHfc9yEqsMGz2HlRE2dwc76n6d37F7D+kbDpPKxdSHluwv9FKDd X-Received: by 2002:aa7:88c8:0:b0:64d:42f6:4c7b with SMTP id k8-20020aa788c8000000b0064d42f64c7bmr1772980pff.27.1685078441033; Thu, 25 May 2023 22:20:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685078441; cv=none; d=google.com; s=arc-20160816; b=wMTN6r3APGVoDbTPmi5/57cw5lvTd6zTuc2/Y1LE8lLKs5TVd2u6qMRr5RYKg/pRWP tw2n0hJWgFcct+2MQ4iO19D0+ivfH10oy2s7PqjK8Eff3v0JQ1oWc84eq+bMrdJV5OJF b8qTzhTcoNs3YRNFkpxSAEAIw24+/Y63ms7GoXUWdQf4CwgFN7xYV21Oqtq9166yxJLy 6zhrWAOtBZzy5lVNHovTRK6F/nFg9laoTE6OgCZYHMNYERi8pRVrKMAjkVNYyw/ijs6A TVrifHhT3ARRIzrQKZTEkwVDSYT9LKaUmHyVwrogWMyRm6vp0Pe6CZ+scgxXqehIztsq 71RQ== 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=yG2WNTKWir2mHBQG9hGg9aV1UxtPd+rzvOdIVGnOyk8=; b=NhW6//kYXlEUZBKwWWDm6nNE2xxAjS+MsqVHPV4+oBGkinc6hREg5qqU6M/7n9qhmS LC+NFxeCuI8Pq6Yaq3yPoG9l0O8d4SfbhBFh1b5T975bEShReQnGqlTs2aFuAOhvJOBE Lvw4+GD8i7Lr8+OSujBVRHqGE/AzCc59UW5rJbHnoJ9/hRImKHosIHgIGon2yGeCTXIh 1ePnwanlhnbiP184L8cvDp8YTFO4mYsMhqwD6fArzyQZkCdoaRDIyPQTLe4ml3oJ4+W2 nW3KRYzjoiC0wmpK3CSG6f1kGPd+U7V3TRD8rKMSeV1QW6XRDudiynWUIj6iS2fuIpQZ 63iQ== 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k27-20020aa79d1b000000b0064d6d833af8si3290898pfp.97.2023.05.25.22.20.27; Thu, 25 May 2023 22:20:41 -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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235081AbjEZFQK convert rfc822-to-8bit (ORCPT + 99 others); Fri, 26 May 2023 01:16:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229689AbjEZFQI (ORCPT ); Fri, 26 May 2023 01:16:08 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19750187 for ; Thu, 25 May 2023 22:16:06 -0700 (PDT) Received: from pps.filterd (m0148461.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34PKnsG8003860 for ; Thu, 25 May 2023 22:16:05 -0700 Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3qt9b0nga2-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 25 May 2023 22:16:05 -0700 Received: from twshared25760.37.frc1.facebook.com (2620:10d:c0a8:1c::11) by mail.thefacebook.com (2620:10d:c0a8:82::f) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 25 May 2023 22:16:04 -0700 Received: by devbig932.frc1.facebook.com (Postfix, from userid 4523) id CC8761E38AFF2; Thu, 25 May 2023 22:15:55 -0700 (PDT) From: Song Liu To: CC: , , , , , , , Song Liu Subject: [PATCH 2/3] ftrace: Add swap_func to ftrace_process_locs() Date: Thu, 25 May 2023 22:15:28 -0700 Message-ID: <20230526051529.3387103-3-song@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230526051529.3387103-1-song@kernel.org> References: <20230526051529.3387103-1-song@kernel.org> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: DFU50NVx-2vtlt-d7KwQUtP8fL1aCIvi X-Proofpoint-GUID: DFU50NVx-2vtlt-d7KwQUtP8fL1aCIvi X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-26_01,2023-05-25_03,2023-05-22_02 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766932811825798022?= X-GMAIL-MSGID: =?utf-8?q?1766932811825798022?= ftrace_process_locs sorts module mcount, which is inside RO memory. Add a ftrace_swap_func so that archs can use RO-memory-poke function to do the sorting. Signed-off-by: Song Liu --- include/linux/ftrace.h | 2 ++ kernel/trace/ftrace.c | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index b23bdd414394..fe443b8ed32c 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -1166,4 +1166,6 @@ unsigned long arch_syscall_addr(int nr); #endif /* CONFIG_FTRACE_SYSCALLS */ +void ftrace_swap_func(void *a, void *b, int n); + #endif /* _LINUX_FTRACE_H */ diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 764668467155..f5ddc9d4cfb6 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -6430,6 +6430,17 @@ static void test_is_sorted(unsigned long *start, unsigned long count) } #endif +void __weak ftrace_swap_func(void *a, void *b, int n) +{ + unsigned long t; + + WARN_ON_ONCE(n != sizeof(t)); + + t = *((unsigned long *)a); + *(unsigned long *)a = *(unsigned long *)b; + *(unsigned long *)b = t; +} + static int ftrace_process_locs(struct module *mod, unsigned long *start, unsigned long *end) @@ -6455,7 +6466,7 @@ static int ftrace_process_locs(struct module *mod, */ if (!IS_ENABLED(CONFIG_BUILDTIME_MCOUNT_SORT) || mod) { sort(start, count, sizeof(*start), - ftrace_cmp_ips, NULL); + ftrace_cmp_ips, ftrace_swap_func); } else { test_is_sorted(start, count); }