From patchwork Mon Dec 5 08:29:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Chen X-Patchwork-Id: 29598 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2131650wrr; Mon, 5 Dec 2022 00:37:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf6UT9YO6cNnA+2vY9Mgz9F9gtAvLh6R3tjqlJ4c01gsdQrd7wwEs7Sb5pYBupN00LOWcTMT X-Received: by 2002:a17:906:180e:b0:7a2:6d38:1085 with SMTP id v14-20020a170906180e00b007a26d381085mr52499280eje.114.1670229421615; Mon, 05 Dec 2022 00:37:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670229421; cv=none; d=google.com; s=arc-20160816; b=mF70RlznbtkhARCgDy6hV56L+LLqg4ZHs7lhCAI8/3r4A67ozoRfFd0S/Ef24aRIqN Cul98ijbqV08UMrkS2sk5Ei417x7EI/dfG3aXbiUEq0MFVTOPJ7YaJ7JtdwaqeOFZImw w15SjImqhyUsctdeUJyUhsY6O6sxJKYdAfs/xKX1zoCu8UkAJsFmw6h1LXO9ygChFO85 c389Lsg7knOJuFm7LnENITkbjukfAdKh7kWWQ+rWX9hkAe8kxh0V1eHOYQOJ4BN/+fUi a4gHJQ+ig9EH5VxTaEqT5ZOeEl/dL1tIMQ4d2XZRTahhRKEWrlJvONxzkSivVE7+tbCo yYPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from:sender :hmm_source_type:hmm_attache_num:hmm_source_ip; bh=T0iubkX/aGcE5J0sCAGGmZH3x+m4tjyk3l6b6YP0zOQ=; b=RYZEjBTwHEBwgnHxcBuqfyB3XZIZUUO/GN7rGu6FWuyeYKEBF80qpRwUCbZaJUjMFi t1plD5xRmzP5VA8kex306JQAWEaGmYvWrx7DGQFSv4jiuoLJRvbFcuRJDwWmkipx6p8Y Jp3b2A1+TMzh8+gqZ/Img0Rt5FdwmXUfcs38gm5Ohpvc1LoZw9O99NOFrPVaJTh9VM22 pRU55L1Z4tfe7ppwf8bS2e6V7X4b+jHRsH7SAbdh2ynRDhJpJjWt+okTwMGWmpgzLOtF 3ePh5hfDHBYWQmxAkOvqkf+DMdL20LVjYtvL9TkYflpLbUf2OQBjO8dUk/6egIq5V9ng jGgw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gb40-20020a170907962800b007ae4717bf08si12671470ejc.359.2022.12.05.00.36.38; Mon, 05 Dec 2022 00:37:01 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231825AbiLEI0d (ORCPT + 99 others); Mon, 5 Dec 2022 03:26:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231530AbiLEI0b (ORCPT ); Mon, 5 Dec 2022 03:26:31 -0500 X-Greylist: delayed 224 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 05 Dec 2022 00:26:29 PST Received: from 189.cn (ptr.189.cn [183.61.185.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7710DA1A9; Mon, 5 Dec 2022 00:26:29 -0800 (PST) HMM_SOURCE_IP: 10.64.8.31:42842.508648307 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-123.150.8.42 (unknown [10.64.8.31]) by 189.cn (HERMES) with SMTP id 3A51D1002F0; Mon, 5 Dec 2022 16:22:57 +0800 (CST) Received: from ([123.150.8.42]) by gateway-153622-dep-6cffbd87dd-pzsb9 with ESMTP id 284d2c4e1823427eb96ba1d9d9009b4e for rostedt@goodmis.org; Mon, 05 Dec 2022 16:22:58 CST X-Transaction-ID: 284d2c4e1823427eb96ba1d9d9009b4e X-Real-From: chensong_2000@189.cn X-Receive-IP: 123.150.8.42 X-MEDUSA-Status: 0 Sender: chensong_2000@189.cn From: Song Chen To: rostedt@goodmis.org, mhiramat@kernel.org, arnd@arndb.de Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-arch@vger.kernel.org, Song Chen Subject: [PATCH v3 1/4] kernel/trace: Introduce trace_probe_print_args and use it in *probes Date: Mon, 5 Dec 2022 16:29:47 +0800 Message-Id: <1670228987-3977-1-git-send-email-chensong_2000@189.cn> X-Mailer: git-send-email 2.7.4 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,SPF_HELO_PASS,SPF_PASS autolearn=no 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?1751362486005738730?= X-GMAIL-MSGID: =?utf-8?q?1751362486005738730?= print_probe_args is currently inplemented in trace_probe_tmpl.h and included by *probes, as a result, each probe has an identical copy. This patch will move it to trace_probe.c as an new API, each probe calls it to print their args in trace file. Signed-off-by: Song Chen --- kernel/trace/trace_eprobe.c | 2 +- kernel/trace/trace_kprobe.c | 4 ++-- kernel/trace/trace_probe.c | 27 +++++++++++++++++++++++++++ kernel/trace/trace_probe.h | 2 ++ kernel/trace/trace_probe_tmpl.h | 28 ---------------------------- kernel/trace/trace_uprobe.c | 2 +- 6 files changed, 33 insertions(+), 32 deletions(-) diff --git a/kernel/trace/trace_eprobe.c b/kernel/trace/trace_eprobe.c index 5dd0617e5df6..bdb26eee7a0c 100644 --- a/kernel/trace/trace_eprobe.c +++ b/kernel/trace/trace_eprobe.c @@ -310,7 +310,7 @@ print_eprobe_event(struct trace_iterator *iter, int flags, trace_seq_putc(s, ')'); - if (print_probe_args(s, tp->args, tp->nr_args, + if (trace_probe_print_args(s, tp->args, tp->nr_args, (u8 *)&field[1], field) < 0) goto out; diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index 5a75b039e586..a4ffa864dbb7 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c @@ -1426,7 +1426,7 @@ print_kprobe_event(struct trace_iterator *iter, int flags, trace_seq_putc(s, ')'); - if (print_probe_args(s, tp->args, tp->nr_args, + if (trace_probe_print_args(s, tp->args, tp->nr_args, (u8 *)&field[1], field) < 0) goto out; @@ -1461,7 +1461,7 @@ print_kretprobe_event(struct trace_iterator *iter, int flags, trace_seq_putc(s, ')'); - if (print_probe_args(s, tp->args, tp->nr_args, + if (trace_probe_print_args(s, tp->args, tp->nr_args, (u8 *)&field[1], field) < 0) goto out; diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index 36dff277de46..ae13b6b2d5da 100644 --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c @@ -1218,3 +1218,30 @@ int trace_probe_create(const char *raw_command, int (*createfn)(int, const char return ret; } + +int trace_probe_print_args(struct trace_seq *s, struct probe_arg *args, int nr_args, + u8 *data, void *field) +{ + void *p; + int i, j; + + for (i = 0; i < nr_args; i++) { + struct probe_arg *a = args + i; + + trace_seq_printf(s, " %s=", a->name); + if (likely(!a->count)) { + if (!a->type->print(s, data + a->offset, field)) + return -ENOMEM; + continue; + } + trace_seq_putc(s, '{'); + p = data + a->offset; + for (j = 0; j < a->count; j++) { + if (!a->type->print(s, p, field)) + return -ENOMEM; + trace_seq_putc(s, j == a->count - 1 ? '}' : ','); + p += a->type->size; + } + } + return 0; +} diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h index de38f1c03776..cfef198013af 100644 --- a/kernel/trace/trace_probe.h +++ b/kernel/trace/trace_probe.h @@ -343,6 +343,8 @@ int trace_probe_compare_arg_type(struct trace_probe *a, struct trace_probe *b); bool trace_probe_match_command_args(struct trace_probe *tp, int argc, const char **argv); int trace_probe_create(const char *raw_command, int (*createfn)(int, const char **)); +int trace_probe_print_args(struct trace_seq *s, struct probe_arg *args, int nr_args, + u8 *data, void *field); #define trace_probe_for_each_link(pos, tp) \ list_for_each_entry(pos, &(tp)->event->files, list) diff --git a/kernel/trace/trace_probe_tmpl.h b/kernel/trace/trace_probe_tmpl.h index b3bdb8ddb862..1b57420857e1 100644 --- a/kernel/trace/trace_probe_tmpl.h +++ b/kernel/trace/trace_probe_tmpl.h @@ -212,31 +212,3 @@ store_trace_args(void *data, struct trace_probe *tp, void *rec, } } } - -static inline int -print_probe_args(struct trace_seq *s, struct probe_arg *args, int nr_args, - u8 *data, void *field) -{ - void *p; - int i, j; - - for (i = 0; i < nr_args; i++) { - struct probe_arg *a = args + i; - - trace_seq_printf(s, " %s=", a->name); - if (likely(!a->count)) { - if (!a->type->print(s, data + a->offset, field)) - return -ENOMEM; - continue; - } - trace_seq_putc(s, '{'); - p = data + a->offset; - for (j = 0; j < a->count; j++) { - if (!a->type->print(s, p, field)) - return -ENOMEM; - trace_seq_putc(s, j == a->count - 1 ? '}' : ','); - p += a->type->size; - } - } - return 0; -} diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c index fb58e86dd117..1ff8f87211a6 100644 --- a/kernel/trace/trace_uprobe.c +++ b/kernel/trace/trace_uprobe.c @@ -1041,7 +1041,7 @@ print_uprobe_event(struct trace_iterator *iter, int flags, struct trace_event *e data = DATAOF_TRACE_ENTRY(entry, false); } - if (print_probe_args(s, tu->tp.args, tu->tp.nr_args, data, entry) < 0) + if (trace_probe_print_args(s, tu->tp.args, tu->tp.nr_args, data, entry) < 0) goto out; trace_seq_putc(s, '\n'); From patchwork Mon Dec 5 08:29:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Chen X-Patchwork-Id: 29593 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2130552wrr; Mon, 5 Dec 2022 00:33:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf5ZE5vc6KirPDbYimh3PniEuRL907ByHFGnt5Q08+hfZVFGLFIvw2iLoEa4AuoW8xnFPkyf X-Received: by 2002:a17:903:2350:b0:189:9004:cf1f with SMTP id c16-20020a170903235000b001899004cf1fmr35982394plh.154.1670229215543; Mon, 05 Dec 2022 00:33:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670229215; cv=none; d=google.com; s=arc-20160816; b=A3rNDNMps0RDAPxABWqYkZ8V0uNaQ3GmYyqUOBnRkUNRUIXX7XSU/250HNkqvTACdw NgDyTXUhf97n+OibDdsZAnz+oLt4rF0PsMqOOUKC5HnCqVQMzUau847DlPpn3IkZi4n/ OGJJFuMPGJI+Tz4I4tbgykHeGmGogphfgsss1MXnr+lfN2LaAYY15EGA19XUXUGZKtcn yMyiPUfyWJ7gO1Qag4fWoJ4/L0OhbWctR73wZWA5bkzCaz632agTks5L0LUUoR9vtJ2p NnosVWDlNT6H3T0xc8ZGn96ywpYirbTA2zz+Ee2mcLSrXwPbzXa4GnYlkdxJT2tUgrXs 6kHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from:sender :hmm_source_type:hmm_attache_num:hmm_source_ip; bh=82GAsG6b6ZjNMCP9L2DiozFewOSC7w/uJ5jXVqwXtM4=; b=QCQxXBpfw6V9uRu8n5vTKQ4Z7u6gR5HDc/zJimi5aTBqdbm9NN6tnH2zIED6eJl98x OvuLZm5XTaOQpP1JBctqYIFwuaWeJVosB+GX4I4hhSJtHxa7+S85cjyNrBnLKMR47BkN IbstvMwofw38jeDfFKDPtHbTnzYmyDiB4iX8OJ6KcpxiAEAalA2ootvxTNlIx2kELwms 7eOHobzNu1tenAODgV6YbZISdT3lC30K5tKRD4l1JwiXkH7eZoiyfwmd4UsaV7A7IhB9 XITQWkHxrW0sxmA+n9RoQq4JaB2BpNgjpjPucHRcvcKASEhnFTC/JO6xa4fkMXQkna/i /Lkw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x24-20020a63db58000000b0046edccffb8dsi13834114pgi.535.2022.12.05.00.33.22; Mon, 05 Dec 2022 00:33:35 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232042AbiLEIXT (ORCPT + 99 others); Mon, 5 Dec 2022 03:23:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232053AbiLEIXN (ORCPT ); Mon, 5 Dec 2022 03:23:13 -0500 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 33CACBF78; Mon, 5 Dec 2022 00:23:10 -0800 (PST) HMM_SOURCE_IP: 10.64.8.43:35220.400595759 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-123.150.8.42 (unknown [10.64.8.43]) by 189.cn (HERMES) with SMTP id 419131002AD; Mon, 5 Dec 2022 16:23:08 +0800 (CST) Received: from ([123.150.8.42]) by gateway-153622-dep-6cffbd87dd-f7vjc with ESMTP id 4e7e58c84af44ac9b6c60322be2d869a for rostedt@goodmis.org; Mon, 05 Dec 2022 16:23:09 CST X-Transaction-ID: 4e7e58c84af44ac9b6c60322be2d869a X-Real-From: chensong_2000@189.cn X-Receive-IP: 123.150.8.42 X-MEDUSA-Status: 0 Sender: chensong_2000@189.cn From: Song Chen To: rostedt@goodmis.org, mhiramat@kernel.org, arnd@arndb.de Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-arch@vger.kernel.org, Song Chen Subject: [PATCH v3 2/4] kernel/trace: Provide default impelentations defined in trace_probe_tmpl.h Date: Mon, 5 Dec 2022 16:29:54 +0800 Message-Id: <1670228994-4020-1-git-send-email-chensong_2000@189.cn> X-Mailer: git-send-email 2.7.4 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,SPF_HELO_PASS,SPF_PASS autolearn=no 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?1751362269926336234?= X-GMAIL-MSGID: =?utf-8?q?1751362269926336234?= There are 7 function definitions in trace_probe_tmpl.h, they are: 1, process_fetch_insn 2, fetch_store_strlen 3, fetch_store_string 4, fetch_store_strlen_user 5, fetch_store_string_user 6, probe_mem_read 7, probe_mem_read_user Every C file which includes trace_probe_tmpl.h has to implement them, otherwise it gets warnings and errors. However, some of them are identical, like kprobe and eprobe, as a result, there is a lot redundant code in those 2 files. This patch would like to provide default behaviors for those functions which kprobe and eprobe can share by just including trace_probe_kernel.h with trace_probe_tmpl.h together. It removes redundant code, increases readability, and more importantly, makes it easier to introduce a new feature based on trace probe (it's possible). Signed-off-by: Song Chen --- v2: 1, mark nokprobe_inline for get_event_field --- kernel/trace/trace_eprobe.c | 144 ------------------------------ kernel/trace/trace_events_synth.c | 7 +- kernel/trace/trace_kprobe.c | 102 --------------------- kernel/trace/trace_probe_kernel.h | 141 +++++++++++++++++++++++++++-- 4 files changed, 139 insertions(+), 255 deletions(-) diff --git a/kernel/trace/trace_eprobe.c b/kernel/trace/trace_eprobe.c index bdb26eee7a0c..60ced4a7a25d 100644 --- a/kernel/trace/trace_eprobe.c +++ b/kernel/trace/trace_eprobe.c @@ -319,64 +319,6 @@ print_eprobe_event(struct trace_iterator *iter, int flags, return trace_handle_return(s); } -static unsigned long get_event_field(struct fetch_insn *code, void *rec) -{ - struct ftrace_event_field *field = code->data; - unsigned long val; - void *addr; - - addr = rec + field->offset; - - if (is_string_field(field)) { - switch (field->filter_type) { - case FILTER_DYN_STRING: - val = (unsigned long)(rec + (*(unsigned int *)addr & 0xffff)); - break; - case FILTER_RDYN_STRING: - val = (unsigned long)(addr + (*(unsigned int *)addr & 0xffff)); - break; - case FILTER_STATIC_STRING: - val = (unsigned long)addr; - break; - case FILTER_PTR_STRING: - val = (unsigned long)(*(char *)addr); - break; - default: - WARN_ON_ONCE(1); - return 0; - } - return val; - } - - switch (field->size) { - case 1: - if (field->is_signed) - val = *(char *)addr; - else - val = *(unsigned char *)addr; - break; - case 2: - if (field->is_signed) - val = *(short *)addr; - else - val = *(unsigned short *)addr; - break; - case 4: - if (field->is_signed) - val = *(int *)addr; - else - val = *(unsigned int *)addr; - break; - default: - if (field->is_signed) - val = *(long *)addr; - else - val = *(unsigned long *)addr; - break; - } - return val; -} - static int get_eprobe_size(struct trace_probe *tp, void *rec) { struct fetch_insn *code; @@ -419,92 +361,6 @@ static int get_eprobe_size(struct trace_probe *tp, void *rec) return ret; } -/* Kprobe specific fetch functions */ - -/* Note that we don't verify it, since the code does not come from user space */ -static int -process_fetch_insn(struct fetch_insn *code, void *rec, void *dest, - void *base) -{ - unsigned long val; - - retry: - switch (code->op) { - case FETCH_OP_TP_ARG: - val = get_event_field(code, rec); - break; - case FETCH_OP_IMM: - val = code->immediate; - break; - case FETCH_OP_COMM: - val = (unsigned long)current->comm; - break; - case FETCH_OP_DATA: - val = (unsigned long)code->data; - break; - case FETCH_NOP_SYMBOL: /* Ignore a place holder */ - code++; - goto retry; - default: - return -EILSEQ; - } - code++; - return process_fetch_insn_bottom(code, val, dest, base); -} -NOKPROBE_SYMBOL(process_fetch_insn) - -/* Return the length of string -- including null terminal byte */ -static nokprobe_inline int -fetch_store_strlen_user(unsigned long addr) -{ - return kern_fetch_store_strlen_user(addr); -} - -/* Return the length of string -- including null terminal byte */ -static nokprobe_inline int -fetch_store_strlen(unsigned long addr) -{ - return kern_fetch_store_strlen(addr); -} - -/* - * Fetch a null-terminated string from user. Caller MUST set *(u32 *)buf - * with max length and relative data location. - */ -static nokprobe_inline int -fetch_store_string_user(unsigned long addr, void *dest, void *base) -{ - return kern_fetch_store_string_user(addr, dest, base); -} - -/* - * Fetch a null-terminated string. Caller MUST set *(u32 *)buf with max - * length and relative data location. - */ -static nokprobe_inline int -fetch_store_string(unsigned long addr, void *dest, void *base) -{ - return kern_fetch_store_string(addr, dest, base); -} - -static nokprobe_inline int -probe_mem_read_user(void *dest, void *src, size_t size) -{ - const void __user *uaddr = (__force const void __user *)src; - - return copy_from_user_nofault(dest, uaddr, size); -} - -static nokprobe_inline int -probe_mem_read(void *dest, void *src, size_t size) -{ -#ifdef CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE - if ((unsigned long)src < TASK_SIZE) - return probe_mem_read_user(dest, src, size); -#endif - return copy_from_kernel_nofault(dest, src, size); -} - /* eprobe handler */ static inline void __eprobe_trace_func(struct eprobe_data *edata, void *rec) diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_synth.c index e310052dc83c..7460f18ba973 100644 --- a/kernel/trace/trace_events_synth.c +++ b/kernel/trace/trace_events_synth.c @@ -18,6 +18,7 @@ #include #include #include "trace_probe.h" +#include "trace_probe_tmpl.h" #include "trace_probe_kernel.h" #include "trace_synth.h" @@ -420,12 +421,12 @@ static unsigned int trace_string(struct synth_trace_event *entry, data_offset += event->n_u64 * sizeof(u64); data_offset += data_size; - len = kern_fetch_store_strlen((unsigned long)str_val); + len = fetch_store_strlen((unsigned long)str_val); data_offset |= len << 16; *(u32 *)&entry->fields[*n_u64] = data_offset; - ret = kern_fetch_store_string((unsigned long)str_val, &entry->fields[*n_u64], entry); + ret = fetch_store_string((unsigned long)str_val, &entry->fields[*n_u64], entry); (*n_u64)++; } else { @@ -473,7 +474,7 @@ static notrace void trace_event_raw_event_synth(void *__data, val_idx = var_ref_idx[field_pos]; str_val = (char *)(long)var_ref_vals[val_idx]; - len = kern_fetch_store_strlen((unsigned long)str_val); + len = fetch_store_strlen((unsigned long)str_val); fields_size += len; } diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index a4ffa864dbb7..c2e0b741ae82 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c @@ -1218,108 +1218,6 @@ static const struct file_operations kprobe_profile_ops = { .release = seq_release, }; -/* Kprobe specific fetch functions */ - -/* Return the length of string -- including null terminal byte */ -static nokprobe_inline int -fetch_store_strlen_user(unsigned long addr) -{ - return kern_fetch_store_strlen_user(addr); -} - -/* Return the length of string -- including null terminal byte */ -static nokprobe_inline int -fetch_store_strlen(unsigned long addr) -{ - return kern_fetch_store_strlen(addr); -} - -/* - * Fetch a null-terminated string from user. Caller MUST set *(u32 *)buf - * with max length and relative data location. - */ -static nokprobe_inline int -fetch_store_string_user(unsigned long addr, void *dest, void *base) -{ - return kern_fetch_store_string_user(addr, dest, base); -} - -/* - * Fetch a null-terminated string. Caller MUST set *(u32 *)buf with max - * length and relative data location. - */ -static nokprobe_inline int -fetch_store_string(unsigned long addr, void *dest, void *base) -{ - return kern_fetch_store_string(addr, dest, base); -} - -static nokprobe_inline int -probe_mem_read_user(void *dest, void *src, size_t size) -{ - const void __user *uaddr = (__force const void __user *)src; - - return copy_from_user_nofault(dest, uaddr, size); -} - -static nokprobe_inline int -probe_mem_read(void *dest, void *src, size_t size) -{ -#ifdef CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE - if ((unsigned long)src < TASK_SIZE) - return probe_mem_read_user(dest, src, size); -#endif - return copy_from_kernel_nofault(dest, src, size); -} - -/* Note that we don't verify it, since the code does not come from user space */ -static int -process_fetch_insn(struct fetch_insn *code, void *rec, void *dest, - void *base) -{ - struct pt_regs *regs = rec; - unsigned long val; - -retry: - /* 1st stage: get value from context */ - switch (code->op) { - case FETCH_OP_REG: - val = regs_get_register(regs, code->param); - break; - case FETCH_OP_STACK: - val = regs_get_kernel_stack_nth(regs, code->param); - break; - case FETCH_OP_STACKP: - val = kernel_stack_pointer(regs); - break; - case FETCH_OP_RETVAL: - val = regs_return_value(regs); - break; - case FETCH_OP_IMM: - val = code->immediate; - break; - case FETCH_OP_COMM: - val = (unsigned long)current->comm; - break; - case FETCH_OP_DATA: - val = (unsigned long)code->data; - break; -#ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API - case FETCH_OP_ARG: - val = regs_get_kernel_argument(regs, code->param); - break; -#endif - case FETCH_NOP_SYMBOL: /* Ignore a place holder */ - code++; - goto retry; - default: - return -EILSEQ; - } - code++; - - return process_fetch_insn_bottom(code, val, dest, base); -} -NOKPROBE_SYMBOL(process_fetch_insn) /* Kprobe handler */ static nokprobe_inline void diff --git a/kernel/trace/trace_probe_kernel.h b/kernel/trace/trace_probe_kernel.h index 77dbd9ff9782..8c42abe0dacf 100644 --- a/kernel/trace/trace_probe_kernel.h +++ b/kernel/trace/trace_probe_kernel.h @@ -12,7 +12,7 @@ */ /* Return the length of string -- including null terminal byte */ static nokprobe_inline int -kern_fetch_store_strlen_user(unsigned long addr) +fetch_store_strlen_user(unsigned long addr) { const void __user *uaddr = (__force const void __user *)addr; int ret; @@ -29,14 +29,14 @@ kern_fetch_store_strlen_user(unsigned long addr) /* Return the length of string -- including null terminal byte */ static nokprobe_inline int -kern_fetch_store_strlen(unsigned long addr) +fetch_store_strlen(unsigned long addr) { int ret, len = 0; u8 c; #ifdef CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE if (addr < TASK_SIZE) - return kern_fetch_store_strlen_user(addr); + return fetch_store_strlen_user(addr); #endif do { @@ -63,7 +63,7 @@ static nokprobe_inline void set_data_loc(int ret, void *dest, void *__dest, void * with max length and relative data location. */ static nokprobe_inline int -kern_fetch_store_string_user(unsigned long addr, void *dest, void *base) +fetch_store_string_user(unsigned long addr, void *dest, void *base) { const void __user *uaddr = (__force const void __user *)addr; int maxlen = get_loc_len(*(u32 *)dest); @@ -86,7 +86,7 @@ kern_fetch_store_string_user(unsigned long addr, void *dest, void *base) * length and relative data location. */ static nokprobe_inline int -kern_fetch_store_string(unsigned long addr, void *dest, void *base) +fetch_store_string(unsigned long addr, void *dest, void *base) { int maxlen = get_loc_len(*(u32 *)dest); void *__dest; @@ -94,7 +94,7 @@ kern_fetch_store_string(unsigned long addr, void *dest, void *base) #ifdef CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE if ((unsigned long)addr < TASK_SIZE) - return kern_fetch_store_string_user(addr, dest, base); + return fetch_store_string_user(addr, dest, base); #endif if (unlikely(!maxlen)) @@ -112,4 +112,133 @@ kern_fetch_store_string(unsigned long addr, void *dest, void *base) return ret; } +static nokprobe_inline int +probe_mem_read_user(void *dest, void *src, size_t size) +{ + const void __user *uaddr = (__force const void __user *)src; + + return copy_from_user_nofault(dest, uaddr, size); +} + +static nokprobe_inline int +probe_mem_read(void *dest, void *src, size_t size) +{ +#ifdef CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE + if ((unsigned long)src < TASK_SIZE) + return probe_mem_read_user(dest, src, size); +#endif + return copy_from_kernel_nofault(dest, src, size); +} + +static nokprobe_inline unsigned long +get_event_field(struct fetch_insn *code, void *rec) +{ + struct ftrace_event_field *field = code->data; + unsigned long val; + void *addr; + + addr = rec + field->offset; + + if (is_string_field(field)) { + switch (field->filter_type) { + case FILTER_DYN_STRING: + val = (unsigned long)(rec + (*(unsigned int *)addr & 0xffff)); + break; + case FILTER_RDYN_STRING: + val = (unsigned long)(addr + (*(unsigned int *)addr & 0xffff)); + break; + case FILTER_STATIC_STRING: + val = (unsigned long)addr; + break; + case FILTER_PTR_STRING: + val = (unsigned long)(*(char *)addr); + break; + default: + WARN_ON_ONCE(1); + return 0; + } + return val; + } + + switch (field->size) { + case 1: + if (field->is_signed) + val = *(char *)addr; + else + val = *(unsigned char *)addr; + break; + case 2: + if (field->is_signed) + val = *(short *)addr; + else + val = *(unsigned short *)addr; + break; + case 4: + if (field->is_signed) + val = *(int *)addr; + else + val = *(unsigned int *)addr; + break; + default: + if (field->is_signed) + val = *(long *)addr; + else + val = *(unsigned long *)addr; + break; + } + return val; +} + +/* Note that we don't verify it, since the code does not come from user space */ +static int +process_fetch_insn(struct fetch_insn *code, void *rec, void *dest, + void *base) +{ + struct pt_regs *regs = rec; + unsigned long val; + +retry: + /* 1st stage: get value from context */ + switch (code->op) { + case FETCH_OP_REG: + val = regs_get_register(regs, code->param); + break; + case FETCH_OP_STACK: + val = regs_get_kernel_stack_nth(regs, code->param); + break; + case FETCH_OP_STACKP: + val = kernel_stack_pointer(regs); + break; + case FETCH_OP_RETVAL: + val = regs_return_value(regs); + break; + case FETCH_OP_IMM: + val = code->immediate; + break; + case FETCH_OP_COMM: + val = (unsigned long)current->comm; + break; + case FETCH_OP_DATA: + val = (unsigned long)code->data; + break; +#ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API + case FETCH_OP_ARG: + val = regs_get_kernel_argument(regs, code->param); + break; +#endif + case FETCH_NOP_SYMBOL: /* Ignore a place holder */ + code++; + goto retry; + case FETCH_OP_TP_ARG: + val = get_event_field(code, rec); + break; + default: + return -EILSEQ; + } + code++; + + return process_fetch_insn_bottom(code, val, dest, base); +} +NOKPROBE_SYMBOL(process_fetch_insn) + #endif /* __TRACE_PROBE_KERNEL_H_ */ From patchwork Mon Dec 5 08:30:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Chen X-Patchwork-Id: 29594 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2130639wrr; Mon, 5 Dec 2022 00:33:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf6+Fb0t1ZYDFYrES7/GDm1kqUDMdkKM7RHwjJG/wSNWS2dvY30KMIveEncWkUb86lVi4MXb X-Received: by 2002:aa7:9389:0:b0:576:cee7:41b0 with SMTP id t9-20020aa79389000000b00576cee741b0mr6335007pfe.76.1670229228430; Mon, 05 Dec 2022 00:33:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670229228; cv=none; d=google.com; s=arc-20160816; b=Laf+Rs3yLpesYTzG4IIa6IXd6+tBqo1dch0TSkq/SEqoEd6iZB+huA84fManhgT3Ld m+epGC1i3U9TTNZdcct7tOIBtEr9VMBG0t9h+NNUx3WIvf8DfjPjTzfW9ntN9ngM23Cr es//beeSxVooPpYlZVh2nE7YBXY/QoOJo2EQNxlUjXOC1OfM2RZ7CyN18pDKOBttmcXH A8eKSRnWq8YtiuHuYV141rZREs7bHokH8CH3DQ1eRYiPKr20OT8Qz/yKButZSathXlQu xEJNWaXiSS8pRy+m1F7xo37c5EMb62TKXzXB+9rpxzvW0HO9VVtvMUW91Y6cecZSuMhj JJuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from:sender :hmm_source_type:hmm_attache_num:hmm_source_ip; bh=122mnxlu5mbqt0+Fw/xz4k8uPC30lukZawjPO0ptdhw=; b=TgtBzcO9J789FOWPjJMiOXyRLTqPjVqGrd7N2Ekp4JYy3ZGi8YTsV9eqL5sKtTu6GF pOLrOiEmiWiPIwP3DrUKV6kckMDq24gJBAds3eoORID4b+pGmPGWkg5xfXsOTBzZdeME sfiPYM/8LDsaBxlut53XLbGH8Qq4/lo60IeIlgz3juJD0FUswoh3xOYc06BNsK8XA4dX bR574FiyADIod40t2A52oNe1vJQbaVcSnmi2ms/GxJ2X5V9VhSct1ogLaRtv7EAq7EF0 oCHgOg7/SUpTKZFVZ3PG3ITVQXvGDH1R9uhlG2LzPzfvcxWd9f1NSLCm6HEWW+rkFqxL +E7A== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p10-20020a056a000b4a00b005750855ff7dsi4868646pfo.107.2022.12.05.00.33.35; Mon, 05 Dec 2022 00:33:48 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232056AbiLEIXW (ORCPT + 99 others); Mon, 5 Dec 2022 03:23:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232048AbiLEIXU (ORCPT ); Mon, 5 Dec 2022 03:23:20 -0500 Received: from 189.cn (ptr.189.cn [183.61.185.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B3D926301; Mon, 5 Dec 2022 00:23:18 -0800 (PST) HMM_SOURCE_IP: 10.64.8.41:38226.171270457 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-123.150.8.42 (unknown [10.64.8.41]) by 189.cn (HERMES) with SMTP id 0F3471002FA; Mon, 5 Dec 2022 16:23:17 +0800 (CST) Received: from ([123.150.8.42]) by gateway-153622-dep-6cffbd87dd-5n69v with ESMTP id 45464105cef54241af91040c29347a1f for rostedt@goodmis.org; Mon, 05 Dec 2022 16:23:18 CST X-Transaction-ID: 45464105cef54241af91040c29347a1f X-Real-From: chensong_2000@189.cn X-Receive-IP: 123.150.8.42 X-MEDUSA-Status: 0 Sender: chensong_2000@189.cn From: Song Chen To: rostedt@goodmis.org, mhiramat@kernel.org, arnd@arndb.de Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-arch@vger.kernel.org, Song Chen Subject: [PATCH v3 3/4] include/asm-generic/io.h: remove performing pointer arithmetic on a null pointer Date: Mon, 5 Dec 2022 16:30:06 +0800 Message-Id: <1670229006-4063-1-git-send-email-chensong_2000@189.cn> X-Mailer: git-send-email 2.7.4 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,SPF_HELO_PASS,SPF_PASS autolearn=no 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?1751362283063947913?= X-GMAIL-MSGID: =?utf-8?q?1751362283063947913?= kernel test robot reports below warnings: In file included from kernel/trace/trace_events_synth.c:18: In file included from include/linux/trace_events.h:9: In file included from include/linux/hardirq.h:11: In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/hexagon/include/asm/io.h:334: include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __raw_readb(PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr)); ~~~~~~~~~~ ^ include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu' #define __le16_to_cpu(x) ((__force __u16)(__le16)(x)) The reason could be constant literal zero converted to any pointer type decays into the null pointer constant. I'm not sure why those warnings are only triggered when building hexagon instead of x86 or arm, but anyway, i found a work around: void *pci_iobase = PCI_IOBASE; val = __raw_readb(pci_iobase + addr); The pointer is not evaluated at compile time, so the warnings are removed. Signed-off-by: Song Chen Reported-by: kernel test robot --- include/asm-generic/io.h | 45 +++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h index a68f8fbf423b..394538fd2585 100644 --- a/include/asm-generic/io.h +++ b/include/asm-generic/io.h @@ -542,9 +542,10 @@ static inline void writesq(volatile void __iomem *addr, const void *buffer, static inline u8 _inb(unsigned long addr) { u8 val; + void *pci_iobase = PCI_IOBASE; __io_pbr(); - val = __raw_readb(PCI_IOBASE + addr); + val = __raw_readb(pci_iobase + addr); __io_par(val); return val; } @@ -555,9 +556,10 @@ static inline u8 _inb(unsigned long addr) static inline u16 _inw(unsigned long addr) { u16 val; + void *pci_iobase = PCI_IOBASE; __io_pbr(); - val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr)); + val = __le16_to_cpu((__le16 __force)__raw_readw(pci_iobase + addr)); __io_par(val); return val; } @@ -568,9 +570,10 @@ static inline u16 _inw(unsigned long addr) static inline u32 _inl(unsigned long addr) { u32 val; + void *pci_iobase = PCI_IOBASE; __io_pbr(); - val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr)); + val = __le32_to_cpu((__le32 __force)__raw_readl(pci_iobase + addr)); __io_par(val); return val; } @@ -580,8 +583,10 @@ static inline u32 _inl(unsigned long addr) #define _outb _outb static inline void _outb(u8 value, unsigned long addr) { + void *pci_iobase = PCI_IOBASE; + __io_pbw(); - __raw_writeb(value, PCI_IOBASE + addr); + __raw_writeb(value, pci_iobase + addr); __io_paw(); } #endif @@ -590,8 +595,10 @@ static inline void _outb(u8 value, unsigned long addr) #define _outw _outw static inline void _outw(u16 value, unsigned long addr) { + void *pci_iobase = PCI_IOBASE; + __io_pbw(); - __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr); + __raw_writew((u16 __force)cpu_to_le16(value), pci_iobase + addr); __io_paw(); } #endif @@ -600,8 +607,10 @@ static inline void _outw(u16 value, unsigned long addr) #define _outl _outl static inline void _outl(u32 value, unsigned long addr) { + void *pci_iobase = PCI_IOBASE; + __io_pbw(); - __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr); + __raw_writel((u32 __force)cpu_to_le32(value), pci_iobase + addr); __io_paw(); } #endif @@ -689,7 +698,9 @@ static inline void outl_p(u32 value, unsigned long addr) #define insb insb static inline void insb(unsigned long addr, void *buffer, unsigned int count) { - readsb(PCI_IOBASE + addr, buffer, count); + void *pci_iobase = PCI_IOBASE; + + readsb(pci_iobase + addr, buffer, count); } #endif @@ -697,7 +708,9 @@ static inline void insb(unsigned long addr, void *buffer, unsigned int count) #define insw insw static inline void insw(unsigned long addr, void *buffer, unsigned int count) { - readsw(PCI_IOBASE + addr, buffer, count); + void *pci_iobase = PCI_IOBASE; + + readsw(pci_iobase + addr, buffer, count); } #endif @@ -705,7 +718,9 @@ static inline void insw(unsigned long addr, void *buffer, unsigned int count) #define insl insl static inline void insl(unsigned long addr, void *buffer, unsigned int count) { - readsl(PCI_IOBASE + addr, buffer, count); + void *pci_iobase = PCI_IOBASE; + + readsl(pci_iobase + addr, buffer, count); } #endif @@ -714,7 +729,9 @@ static inline void insl(unsigned long addr, void *buffer, unsigned int count) static inline void outsb(unsigned long addr, const void *buffer, unsigned int count) { - writesb(PCI_IOBASE + addr, buffer, count); + void *pci_iobase = PCI_IOBASE; + + writesb(pci_iobase + addr, buffer, count); } #endif @@ -723,7 +740,9 @@ static inline void outsb(unsigned long addr, const void *buffer, static inline void outsw(unsigned long addr, const void *buffer, unsigned int count) { - writesw(PCI_IOBASE + addr, buffer, count); + void *pci_iobase = PCI_IOBASE; + + writesw(pci_iobase + addr, buffer, count); } #endif @@ -732,7 +751,9 @@ static inline void outsw(unsigned long addr, const void *buffer, static inline void outsl(unsigned long addr, const void *buffer, unsigned int count) { - writesl(PCI_IOBASE + addr, buffer, count); + void *pci_iobase = PCI_IOBASE; + + writesl(pci_iobase + addr, buffer, count); } #endif From patchwork Mon Dec 5 08:30:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Chen X-Patchwork-Id: 29596 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2130914wrr; Mon, 5 Dec 2022 00:34:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf6d4zoPpGlWQjFF68p400rxWh/e560x/DaS0Yp4wJMYC+r4VtMkOcflLUeycniYLbwjqjMe X-Received: by 2002:a17:90a:4307:b0:213:9df5:43b2 with SMTP id q7-20020a17090a430700b002139df543b2mr92726465pjg.86.1670229278351; Mon, 05 Dec 2022 00:34:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670229278; cv=none; d=google.com; s=arc-20160816; b=Rh5SRd6z9HiUWJLRvJ5ZMfR+fOsG2X4tUcswSnv0scKb4Mdep0UwE5AJFQ/9wF89XV n2AifJsXLt5/A6iusSLiE0Y+ckg5lCZacVvaZ9ijy2neHh0O3RNkQ5nWg3f6OesfCYrY r4Ol44lO40XbCsgQLcl/G37pQBizcoLAZGN2YzfkoTREpPAXkXdiZQRwDj5yMWDnt0OW nWZ7pfr1ME71gnz2JBi/Pycfnr/XUbVAzgocJdSW0RnUfQd0KLP1YRraE2wzlHX6N6Pi F0o1i0zDssoxOrPb79egOr/nQO6grOcZDGU/N1BQb+NYCs23138rs3qKjn3HalnKGvtK mGpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from:sender :hmm_source_type:hmm_attache_num:hmm_source_ip; bh=O6Qp/a6d8Jk6n4Ypylia+vRDfqUkkjbud6/sqzz+LgA=; b=1LXo+k1/kKVk7/MwB5ESbTkMwzdtZjPa+0N24dYzG0MKIuY7xWmHNnHEk+RwsCF5iS XpsXlzWkN4UeH/SMmUB0JFdIh1BjeSY06nffxKtNmXsv3psHaDRn1f/I+X7so/5GKYoJ 0ZIL8yB4p0VufzVsYdbO8Y4b3eVSybNQ/es5505BlxyJdSY9CYJik11E+2V1q6sBGgMA wQaAuFH8VyB7UTpiUmFHc22I2Eq/tOl+V92qVtw+hd9bMbyFeD50EeJgEdv31DUMh4ow +ZK/RtKb/tzF6j1qtzgRu+vUq3zj7hn6rknDVSIZloMiyp+Dpz+yi9XuLBnm+nna3ajT +qww== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s2-20020a632c02000000b00477bfab5a83si14250089pgs.2.2022.12.05.00.34.25; Mon, 05 Dec 2022 00:34:38 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231829AbiLEIXl (ORCPT + 99 others); Mon, 5 Dec 2022 03:23:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232068AbiLEIXd (ORCPT ); Mon, 5 Dec 2022 03:23:33 -0500 Received: from 189.cn (ptr.189.cn [183.61.185.103]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 793A1165AD; Mon, 5 Dec 2022 00:23:30 -0800 (PST) HMM_SOURCE_IP: 10.64.8.41:59286.703431701 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-123.150.8.42 (unknown [10.64.8.41]) by 189.cn (HERMES) with SMTP id 6D6301002F0; Mon, 5 Dec 2022 16:23:28 +0800 (CST) Received: from ([123.150.8.42]) by gateway-153622-dep-6cffbd87dd-5n69v with ESMTP id 6754938087e943759d0a36285b07a169 for rostedt@goodmis.org; Mon, 05 Dec 2022 16:23:29 CST X-Transaction-ID: 6754938087e943759d0a36285b07a169 X-Real-From: chensong_2000@189.cn X-Receive-IP: 123.150.8.42 X-MEDUSA-Status: 0 Sender: chensong_2000@189.cn From: Song Chen To: rostedt@goodmis.org, mhiramat@kernel.org, arnd@arndb.de Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-arch@vger.kernel.org, Song Chen Subject: [PATCH v3 4/4] kernel/trace: remove calling regs_* when compiling HEXAGON Date: Mon, 5 Dec 2022 16:30:17 +0800 Message-Id: <1670229017-4106-1-git-send-email-chensong_2000@189.cn> X-Mailer: git-send-email 2.7.4 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,SPF_HELO_PASS,SPF_PASS autolearn=no 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?1751362335774491456?= X-GMAIL-MSGID: =?utf-8?q?1751362335774491456?= kernel test robot reports below errors: In file included from kernel/trace/trace_events_synth.c:22: >> kernel/trace/trace_probe_kernel.h:203:9: error: call to undeclared function 'regs_get_register'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] val = regs_get_register(regs, code->param); HEXAGON doesn't define and implement those reg_* functions underneath arch/hexagon as well as other archs. To remove those errors, i have to include those function calls in "CONFIG_HEXAGON" It looks ugly, but i don't know any other way to fix it, this patch can be reverted after reg_* have been in place in arch/hexagon. Signed-off-by: Song Chen Reported-by: kernel test robot --- kernel/trace/trace_probe_kernel.h | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/kernel/trace/trace_probe_kernel.h b/kernel/trace/trace_probe_kernel.h index 8c42abe0dacf..7e958b7f07e5 100644 --- a/kernel/trace/trace_probe_kernel.h +++ b/kernel/trace/trace_probe_kernel.h @@ -130,8 +130,7 @@ probe_mem_read(void *dest, void *src, size_t size) return copy_from_kernel_nofault(dest, src, size); } -static nokprobe_inline unsigned long -get_event_field(struct fetch_insn *code, void *rec) +static unsigned long get_event_field(struct fetch_insn *code, void *rec) { struct ftrace_event_field *field = code->data; unsigned long val; @@ -194,23 +193,41 @@ static int process_fetch_insn(struct fetch_insn *code, void *rec, void *dest, void *base) { +#ifndef CONFIG_HEXAGON struct pt_regs *regs = rec; +#endif unsigned long val; retry: /* 1st stage: get value from context */ switch (code->op) { case FETCH_OP_REG: +#ifdef CONFIG_HEXAGON + val = 0; +#else val = regs_get_register(regs, code->param); +#endif break; case FETCH_OP_STACK: +#ifdef CONFIG_HEXAGON + val = 0; +#else val = regs_get_kernel_stack_nth(regs, code->param); +#endif break; case FETCH_OP_STACKP: +#ifdef CONFIG_HEXAGON + val = 0; +#else val = kernel_stack_pointer(regs); +#endif break; case FETCH_OP_RETVAL: +#ifdef CONFIG_HEXAGON + val = 0; +#else val = regs_return_value(regs); +#endif break; case FETCH_OP_IMM: val = code->immediate;