Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp6421260rwl; Mon, 9 Jan 2023 08:08:41 -0800 (PST) X-Google-Smtp-Source: AMrXdXsplJLRQTxtN/aygdK/0At5e9As8nmON+ANTuuE61DJ3YUQfoIUkDUv78M6yxf9slKYPQj/ X-Received: by 2002:a05:6a00:18a3:b0:582:197e:f6c1 with SMTP id x35-20020a056a0018a300b00582197ef6c1mr48971736pfh.4.1673280521059; Mon, 09 Jan 2023 08:08:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673280521; cv=none; d=google.com; s=arc-20160816; b=n+FwoDwAcbeeqSS70UtL6luG6TmK69rFo+1fmhfY4Y6gWh7Ed8FKY8OtVycL6Efoxn 1pSfKmSYi0/XtAfJH2NMqGRz8C6DQgA+e8JmDsMY+MfLslgL8wZRvU21+VfSTXcynPFG THnSacbMaDOFJJ+AoRq5LJpxWEmqY++uKyD+pu1O3BW3ZWnyL+N/rnlXeNtr2/uleJvd vwZv1miCRhjIP2amp1rn+65fSydYKA41r6N1UQrjED6Ul0uWIv8H/h/k8gl7ux8nc22I 1g6Z/cQhsC43b11Gx34hicEni6HaT0Y2VNZ/CgpgDCS6eLZAAV7J9kqpmmfUSEbjrKtd /ECg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=5aVQsmC4CXYrfVLoZKxVbVq0RUkZDRsh5TxThuMCMmU=; b=0Fg12VMuIdEqbI8xvIyJvl07VCZwXpdDrsieWrgWSPJb9lgwKTHtYwIbWbPv3N1P65 NiBOqafmkmKADUeqhP6xHRSvar2v6r0NwQXfma9JSQbQBv1nd+TQpw2vaJteWWtMBp6A HPpnej2WJG0q9VyPey6LWiXaJ1O8j9wLBaZ/9awgXNGKskZkm/CZBbsKjUjYthXqnJ1g JYkyAr49zxHNir+hE4J1G2TdtWtPw3ZQQ51+hfO6+O6U2UH31BIBT5urtZdhnvDcOc4f UuqXNnpb9IHMleH5PIsxKZ8ba6s6IdrSebYLlCyQi4PM6lK/bJqVrlaR2JEPC7sKjMcv 0lvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="k9tk/TmH"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j7-20020a056a00174700b0056e3c566bfasi9669159pfc.201.2023.01.09.08.08.33; Mon, 09 Jan 2023 08:08:41 -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; dkim=pass header.i=@google.com header.s=20210112 header.b="k9tk/TmH"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237119AbjAIPW2 (ORCPT + 53 others); Mon, 9 Jan 2023 10:22:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237062AbjAIPWK (ORCPT ); Mon, 9 Jan 2023 10:22:10 -0500 Received: from mail-yw1-x112d.google.com (mail-yw1-x112d.google.com [IPv6:2607:f8b0:4864:20::112d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 738051C12F for ; Mon, 9 Jan 2023 07:21:11 -0800 (PST) Received: by mail-yw1-x112d.google.com with SMTP id 00721157ae682-4b718cab0e4so117004357b3.9 for ; Mon, 09 Jan 2023 07:21:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=5aVQsmC4CXYrfVLoZKxVbVq0RUkZDRsh5TxThuMCMmU=; b=k9tk/TmHq0DhEW6Qi9fIk4cVJeag11W69L7khvrCZJ1Q2diWkv9jOy/aCGFsvPZtqp waK2jBW0khYv0eb8tLpUJlMkD+iRaz8kI3US8UyGyvTBNO+YbF7BGzwT3TVMA+Htt36m 48rVVqvcryLQGi/BKwkRrX/+Mgyrqe06eGYD8FtCh/kBei8AqhODpoyaNwDnETAtoUga PinmJmWCf9bjoweT1hXszTZ2/rx2w0U2inuOD3i9MB1gMJz3TXs3P0LLxU7UesDw2xp0 xMT5O6cVrl2JjRZo9d95sJtn4huV2LR9D8lBVCQDHf547PzTIQCYCueY7U/Qxa4lQ47d dAxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5aVQsmC4CXYrfVLoZKxVbVq0RUkZDRsh5TxThuMCMmU=; b=vxL7hr9MYYxxNkTMdJzrNJAeJ+emEp8NsRMTEobRF0TPYiXUUfVOD9iDSYwVkYNcif iX0t1TxKYNDUDiZ75WD+oUQdo8w4MLH5qQZjEbjJmTpplyGf788+qv109/q3Lz6OK/H5 ORwOaWyWIEhgmI9QKR1xmqNo+ycicUwC4r6QVw3pjbaSPK2dnGpWopwUIeH3SBUIrhu0 cHSSS0uhPuPai/Vilofs3Jdlx0dRCO8v6DtYH5bisCGZCePLJ/QhCHyIQEvu620OlrrY 5EicYZ4/teX3zG5hOV8gTmOsxnlpywUe80pbWzjXRgMBJWllTJzW/e3PqKrkYxgclGsp ncRg== X-Gm-Message-State: AFqh2kqWtX7TRT8ECMv5/bkfXdfVArwibnTyGI5HshqleOY38qrlyAbZ kqm3z/nX/v9PVXb/RrKI+qJB4ivigL2WZfdswSvqmQ== X-Received: by 2002:a81:6d85:0:b0:3f2:e8b7:a6ec with SMTP id i127-20020a816d85000000b003f2e8b7a6ecmr862462ywc.332.1673277670464; Mon, 09 Jan 2023 07:21:10 -0800 (PST) MIME-Version: 1.0 References: <20230108025545.338-1-cuiyunhui@bytedance.com> <20230109100833.03f4d4b1@gandalf.local.home> In-Reply-To: <20230109100833.03f4d4b1@gandalf.local.home> From: Eric Dumazet Date: Mon, 9 Jan 2023 16:20:58 +0100 Message-ID: Subject: Re: [External] Re: [PATCH v4] sock: add tracepoint for send recv length To: Steven Rostedt Cc: =?UTF-8?B?6L+Q6L6J5bSU?= , mhiramat@kernel.org, davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, kuniyu@amazon.com, xiyou.wangcong@gmail.com, duanxiongchun@bytedance.com, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, netdev@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 On Mon, Jan 9, 2023 at 4:08 PM Steven Rostedt wrote: > > On Mon, 9 Jan 2023 15:54:38 +0100 > Eric Dumazet wrote: > > > > static inline int sock_sendmsg_nosec(struct socket *sock, struct msghdr *msg) > > > { > > > int ret = INDIRECT_CALL_INET(sock->ops->sendmsg, inet6_sendmsg, > > > inet_sendmsg, sock, msg, > > > msg_data_left(msg)); > > > BUG_ON(ret == -EIOCBQUEUED); > > > > > > if (trace_sock_send_length_enabled()) { > > > > A barrier() is needed here, with the current state of affairs. > > > > IMO, ftrace/x86 experts should take care of this generic issue ? > > trace_*_enabled() is a static_branch() (aka. jump label). > > It's a nop, where the if block is in the out-of-line code and skipped. When > the tracepoint is enabled, it gets turned into a jump to the if block > (which returns back to this location). > This is not a nop, as shown in the generated assembly, I copied in this thread earlier. Compiler does all sorts of things before the point the static branch is looked at. Let's add the extract again with <<*>> tags on added instructions/dereferences. sock_recvmsg_nosec: pushq %r12 # movl %edx, %r12d # tmp123, flags pushq %rbp # # net/socket.c:999: int ret = INDIRECT_CALL_INET(sock->ops->recvmsg, inet6_recvmsg, movl %r12d, %ecx # flags, # net/socket.c:998: { movq %rdi, %rbp # tmp121, sock pushq %rbx # # net/socket.c:999: int ret = INDIRECT_CALL_INET(sock->ops->recvmsg, inet6_recvmsg, movq 32(%rdi), %rax # sock_19(D)->ops, sock_19(D)->ops # ./include/linux/uio.h:270: return i->count; movq 32(%rsi), %rdx # MEM[(const struct iov_iter *)msg_20(D) + 16B].count, pretmp_48 # net/socket.c:999: int ret = INDIRECT_CALL_INET(sock->ops->recvmsg, inet6_recvmsg, movq 144(%rax), %rax # _1->recvmsg, _2 cmpq $inet6_recvmsg, %rax #, _2 jne .L107 #, call inet6_recvmsg # <<*>> movl %eax, %ebx # tmp124, .L108: # net/socket.c:1003: trace_sock_recv_length(sock->sk, sock->sk->sk_family, <<*>> xorl %r8d, %r8d # tmp127 <<*>> testl %ebx, %ebx # # net/socket.c:1004: sock->sk->sk_protocol, <<*>> movq 24(%rbp), %rsi # sock_19(D)->sk, _10 # net/socket.c:1003: trace_sock_recv_length(sock->sk, sock->sk->sk_family, <<*>> cmovle %ebx, %r8d # ,, tmp119 <<*>> testb $2, %r12b #, flags # net/socket.c:1004: sock->sk->sk_protocol, <<*>> movzwl 516(%rsi), %ecx # _10->sk_protocol, # net/socket.c:1003: trace_sock_recv_length(sock->sk, sock->sk->sk_family, <<*>> movzwl 16(%rsi), %edx # _10->__sk_common.skc_family, # net/socket.c:1003: trace_sock_recv_length(sock->sk, sock->sk->sk_family, <<*>> cmove %ebx, %r8d # tmp119,, , iftmp.54_16 # ./arch/x86/include/asm/jump_label.h:27: asm_volatile_goto("1:" #APP # 27 "./arch/x86/include/asm/jump_label.h" 1 1:jmp .L111 # objtool NOPs this # .pushsection __jump_table, "aw" .balign 8 .long 1b - . .long .L111 - . # .quad __tracepoint_sock_recv_length+8 + 2 - . #, .popsection # 0 "" 2 #NO_APP .L106: # net/socket.c:1008: } <<*>> movl %ebx, %eax # , popq %rbx # popq %rbp # popq %r12 # ret .L111: # ./include/trace/events/sock.h:308: DEFINE_EVENT(sock_msg_length, sock_recv_length, > That is, when the tracepoint in the block gets enabled so does the above > branch. Sure, there could be a race between the two being enabled, but I > don't see any issue if there is. But the process to modify the jump labels, > does a bunch of synchronization between the CPUs. > > What barrier are you expecting? Something preventing the compiler being 'smart', forcing expression evaluations before TP_fast_assign() is eventually called. > > -- Steve > > > > > > > > > > call_trace_sock_send_length(sock->sk, sock->sk->sk_family, > > > sock->sk->sk_protocol, ret, 0); > > > } > > > return ret; > > > } > > > > > > What do you think?