Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2536692rdb; Mon, 20 Nov 2023 13:49:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IGMkBssO+K9Tz95DL4rA5wdFwbJgztWHlkIT6gOG56vyO9yUTU8SvtfFYGiTzAeqZ/LOBPn X-Received: by 2002:a17:902:c947:b0:1cf:569d:937b with SMTP id i7-20020a170902c94700b001cf569d937bmr5553886pla.52.1700516966688; Mon, 20 Nov 2023 13:49:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700516966; cv=none; d=google.com; s=arc-20160816; b=mZwQaAjQucWbRoYyVvlien3TpcAJX4GHlghKlBD8/FwyKmL2kZxER0cfLLl5dWCuKD zUtLmhTmA/DA48BkAq+FChi0uHl6R3O3O2Injp37LvB/Mftf9h9q0Ay8K5krnGw/w/6R mVWbMke64T+Ld2cxxrqldPFjpfTbtD6JiULK70z5cyL4w64/Kh4tOuxtYC3sZz7S3HNZ 8MtmndAB8WijqKMR6MMCioRCdqeHtUZnKbXvJ3iE0cS4tRfbKkDYEDDYHrvMomPOJ8/5 pUoTMPSRi/T2MdZwirbA4RsTJghcNskqoQAKfYaNy/O+ESoHNlk0cHTzpqjLRtbGbTo9 Yw5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=VbEEEvOKQiy4zEH0Fh29KF4UlqN9PFMjTOjddwVcuH0=; fh=Zil15qMcWU6SKSMFA3k+w+i+AIrKTkuGtEvSRY9DICA=; b=I2lINVSSdmQFUpj1faMXWP41guJunmkDIwqoHDdr5lmhwwNLxqcOeT7DRugKXpmB1h dscoIyeVCrys0iawI2px80rJpe7qrN+sBwABPA3fPwj2yohfwSz+SzUdZEppn4AOi0jR amAObJna9n1CgZqhe7zKL3sqc8MkEPwfS4lBeWCJak4PBgINVcUQFbJaHB/eLWNRYk6d ZNyEP8e4C2RTFLMFJJNtzmx/CqFsOjCYbaeBcGbFrrH8fwfGTXYpVQD191e20dOIP3C0 dAn1gz5KZ08sbqVLjrW7c0D+kV27uIRwRox+vgFuKoQwTqxNsBWoyo3pa3fG2wFjL6U9 dbWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=IpU6vftx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id m3-20020a170902bb8300b001c426636990si8141566pls.637.2023.11.20.13.49.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 13:49:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=IpU6vftx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 7C2AE807EA31; Mon, 20 Nov 2023 13:49:21 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232918AbjKTVsg (ORCPT + 99 others); Mon, 20 Nov 2023 16:48:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232902AbjKTVsX (ORCPT ); Mon, 20 Nov 2023 16:48:23 -0500 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D932626A9; Mon, 20 Nov 2023 13:47:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=VbEEEvOKQiy4zEH0Fh29KF4UlqN9PFMjTOjddwVcuH0=; b=IpU6vftxa1fXYJ78C8NKRyS+9l f7v4iA/kVSFpjbSWiu9akz5U9lxJc07AnqL9j2Objf4DHd6mnsNCRRxH737bJyhjFpFD1fKjFw0/E S9J40QiM4h0O8mWcRRQGHVEywvU6hWuYP1C8vNed/oLM1FqvKVEgZdTRLCM8IiHzBSbqTRIcRg60z tEW5D+sriSXR1wWbCcBt5UKy6tkB/ZrwxNpeZZMQwtquD+PdOhEiF5nvUf4VzCvQqvHqxin936pNf 8I1hnpVhmz4WbWMabaHjJfRcPHGqbQYR34Em/11cCC7yDHfXYCIArGDEVvZBcTmhti8NljgnrREK5 8mOBNh+Q==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1r5C6c-00B8ac-0k; Mon, 20 Nov 2023 21:46:58 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 1F2C33004E3; Mon, 20 Nov 2023 22:46:57 +0100 (CET) Date: Mon, 20 Nov 2023 22:46:57 +0100 From: Peter Zijlstra To: Mathieu Desnoyers Cc: Steven Rostedt , Masami Hiramatsu , linux-kernel@vger.kernel.org, Michael Jeanson , Alexei Starovoitov , Yonghong Song , "Paul E . McKenney" , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , bpf@vger.kernel.org, Joel Fernandes Subject: Re: [PATCH v4 5/5] tracing: convert sys_enter/exit to faultable tracepoints Message-ID: <20231120214657.GB8262@noisy.programming.kicks-ass.net> References: <20231120205418.334172-1-mathieu.desnoyers@efficios.com> <20231120205418.334172-6-mathieu.desnoyers@efficios.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231120205418.334172-6-mathieu.desnoyers@efficios.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 20 Nov 2023 13:49:21 -0800 (PST) On Mon, Nov 20, 2023 at 03:54:18PM -0500, Mathieu Desnoyers wrote: > diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c > index de753403cdaf..718a0723a0bc 100644 > --- a/kernel/trace/trace_syscalls.c > +++ b/kernel/trace/trace_syscalls.c > @@ -299,27 +299,33 @@ static void ftrace_syscall_enter(void *data, struct pt_regs *regs, long id) > int syscall_nr; > int size; > > + /* > + * Probe called with preemption enabled (may_fault), but ring buffer and > + * per-cpu data require preemption to be disabled. > + */ > + preempt_disable_notrace(); guard(preempt_notrace)(); and ditch all the goto crap. > + > syscall_nr = trace_get_syscall_nr(current, regs); > if (syscall_nr < 0 || syscall_nr >= NR_syscalls) > - return; > + goto end; > > /* Here we're inside tp handler's rcu_read_lock_sched (__DO_TRACE) */ > trace_file = rcu_dereference_sched(tr->enter_syscall_files[syscall_nr]); > if (!trace_file) > - return; > + goto end; > > if (trace_trigger_soft_disabled(trace_file)) > - return; > + goto end; > > sys_data = syscall_nr_to_meta(syscall_nr); > if (!sys_data) > - return; > + goto end; > > size = sizeof(*entry) + sizeof(unsigned long) * sys_data->nb_args; > > entry = trace_event_buffer_reserve(&fbuffer, trace_file, size); > if (!entry) > - return; > + goto end; > > entry = ring_buffer_event_data(fbuffer.event); > entry->nr = syscall_nr; > @@ -327,6 +333,8 @@ static void ftrace_syscall_enter(void *data, struct pt_regs *regs, long id) > memcpy(entry->args, args, sizeof(unsigned long) * sys_data->nb_args); > > trace_event_buffer_commit(&fbuffer); > +end: > + preempt_enable_notrace(); > } > > static void ftrace_syscall_exit(void *data, struct pt_regs *regs, long ret) > @@ -338,31 +346,39 @@ static void ftrace_syscall_exit(void *data, struct pt_regs *regs, long ret) > struct trace_event_buffer fbuffer; > int syscall_nr; > > + /* > + * Probe called with preemption enabled (may_fault), but ring buffer and > + * per-cpu data require preemption to be disabled. > + */ > + preempt_disable_notrace(); Idem. > + > syscall_nr = trace_get_syscall_nr(current, regs); > if (syscall_nr < 0 || syscall_nr >= NR_syscalls) > - return; > + goto end; > > /* Here we're inside tp handler's rcu_read_lock_sched (__DO_TRACE()) */ > trace_file = rcu_dereference_sched(tr->exit_syscall_files[syscall_nr]); > if (!trace_file) > - return; > + goto end; > > if (trace_trigger_soft_disabled(trace_file)) > - return; > + goto end; > > sys_data = syscall_nr_to_meta(syscall_nr); > if (!sys_data) > - return; > + goto end; > > entry = trace_event_buffer_reserve(&fbuffer, trace_file, sizeof(*entry)); > if (!entry) > - return; > + goto end; > > entry = ring_buffer_event_data(fbuffer.event); > entry->nr = syscall_nr; > entry->ret = syscall_get_return_value(current, regs); > > trace_event_buffer_commit(&fbuffer); > +end: > + preempt_enable_notrace(); > } > > static int reg_event_syscall_enter(struct trace_event_file *file, > @@ -377,7 +393,9 @@ static int reg_event_syscall_enter(struct trace_event_file *file, > return -ENOSYS; > mutex_lock(&syscall_trace_lock); > if (!tr->sys_refcount_enter) > - ret = register_trace_sys_enter(ftrace_syscall_enter, tr); > + ret = register_trace_prio_flags_sys_enter(ftrace_syscall_enter, tr, > + TRACEPOINT_DEFAULT_PRIO, > + TRACEPOINT_MAY_FAULT); > if (!ret) { > rcu_assign_pointer(tr->enter_syscall_files[num], file); > tr->sys_refcount_enter++; > @@ -415,7 +433,9 @@ static int reg_event_syscall_exit(struct trace_event_file *file, > return -ENOSYS; > mutex_lock(&syscall_trace_lock); > if (!tr->sys_refcount_exit) > - ret = register_trace_sys_exit(ftrace_syscall_exit, tr); > + ret = register_trace_prio_flags_sys_exit(ftrace_syscall_exit, tr, > + TRACEPOINT_DEFAULT_PRIO, > + TRACEPOINT_MAY_FAULT); > if (!ret) { > rcu_assign_pointer(tr->exit_syscall_files[num], file); > tr->sys_refcount_exit++; /me hands you a bucket of {}, free of charge. > @@ -582,20 +602,26 @@ static void perf_syscall_enter(void *ignore, struct pt_regs *regs, long id) > int rctx; > int size; > > + /* > + * Probe called with preemption enabled (may_fault), but ring buffer and > + * per-cpu data require preemption to be disabled. > + */ > + preempt_disable_notrace(); Again, guard(preempt_notrace)(); > + > syscall_nr = trace_get_syscall_nr(current, regs); > if (syscall_nr < 0 || syscall_nr >= NR_syscalls) > - return; > + goto end; > if (!test_bit(syscall_nr, enabled_perf_enter_syscalls)) > - return; > + goto end; > > sys_data = syscall_nr_to_meta(syscall_nr); > if (!sys_data) > - return; > + goto end; > > head = this_cpu_ptr(sys_data->enter_event->perf_events); > valid_prog_array = bpf_prog_array_valid(sys_data->enter_event); > if (!valid_prog_array && hlist_empty(head)) > - return; > + goto end; > > /* get the size after alignment with the u32 buffer size field */ > size = sizeof(unsigned long) * sys_data->nb_args + sizeof(*rec); > @@ -604,7 +630,7 @@ static void perf_syscall_enter(void *ignore, struct pt_regs *regs, long id) > > rec = perf_trace_buf_alloc(size, NULL, &rctx); > if (!rec) > - return; > + goto end; > > rec->nr = syscall_nr; > syscall_get_arguments(current, regs, args); > @@ -614,12 +640,14 @@ static void perf_syscall_enter(void *ignore, struct pt_regs *regs, long id) > !perf_call_bpf_enter(sys_data->enter_event, regs, sys_data, rec)) || > hlist_empty(head)) { > perf_swevent_put_recursion_context(rctx); > - return; > + goto end; > } > > perf_trace_buf_submit(rec, size, rctx, > sys_data->enter_event->event.type, 1, regs, > head, NULL); > +end: > + preempt_enable_notrace(); > } > > static int perf_sysenter_enable(struct trace_event_call *call) > @@ -631,7 +659,9 @@ static int perf_sysenter_enable(struct trace_event_call *call) > > mutex_lock(&syscall_trace_lock); > if (!sys_perf_refcount_enter) > - ret = register_trace_sys_enter(perf_syscall_enter, NULL); > + ret = register_trace_prio_flags_sys_enter(perf_syscall_enter, NULL, > + TRACEPOINT_DEFAULT_PRIO, > + TRACEPOINT_MAY_FAULT); More {} > if (ret) { > pr_info("event trace: Could not activate syscall entry trace point"); > } else { > @@ -682,20 +712,26 @@ static void perf_syscall_exit(void *ignore, struct pt_regs *regs, long ret) > int rctx; > int size; > > + /* > + * Probe called with preemption enabled (may_fault), but ring buffer and > + * per-cpu data require preemption to be disabled. > + */ > + preempt_disable_notrace(); Guess? > + > syscall_nr = trace_get_syscall_nr(current, regs); > if (syscall_nr < 0 || syscall_nr >= NR_syscalls) > - return; > + goto end; > if (!test_bit(syscall_nr, enabled_perf_exit_syscalls)) > - return; > + goto end; > > sys_data = syscall_nr_to_meta(syscall_nr); > if (!sys_data) > - return; > + goto end; > > head = this_cpu_ptr(sys_data->exit_event->perf_events); > valid_prog_array = bpf_prog_array_valid(sys_data->exit_event); > if (!valid_prog_array && hlist_empty(head)) > - return; > + goto end; > > /* We can probably do that at build time */ > size = ALIGN(sizeof(*rec) + sizeof(u32), sizeof(u64)); > @@ -703,7 +739,7 @@ static void perf_syscall_exit(void *ignore, struct pt_regs *regs, long ret) > > rec = perf_trace_buf_alloc(size, NULL, &rctx); > if (!rec) > - return; > + goto end; > > rec->nr = syscall_nr; > rec->ret = syscall_get_return_value(current, regs); > @@ -712,11 +748,13 @@ static void perf_syscall_exit(void *ignore, struct pt_regs *regs, long ret) > !perf_call_bpf_exit(sys_data->exit_event, regs, rec)) || > hlist_empty(head)) { > perf_swevent_put_recursion_context(rctx); > - return; > + goto end; > } > > perf_trace_buf_submit(rec, size, rctx, sys_data->exit_event->event.type, > 1, regs, head, NULL); > +end: > + preempt_enable_notrace(); > } > > static int perf_sysexit_enable(struct trace_event_call *call) > @@ -728,7 +766,9 @@ static int perf_sysexit_enable(struct trace_event_call *call) > > mutex_lock(&syscall_trace_lock); > if (!sys_perf_refcount_exit) > - ret = register_trace_sys_exit(perf_syscall_exit, NULL); > + ret = register_trace_prio_flags_sys_exit(perf_syscall_exit, NULL, > + TRACEPOINT_DEFAULT_PRIO, > + TRACEPOINT_MAY_FAULT); And yet more {} > if (ret) { > pr_info("event trace: Could not activate syscall exit trace point"); > } else { > -- > 2.25.1 >