From patchwork Thu Nov 4 06:09:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 12602465 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6316DC433F5 for ; Thu, 4 Nov 2021 06:10:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 40ACB611AE for ; Thu, 4 Nov 2021 06:10:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230087AbhKDGMr (ORCPT ); Thu, 4 Nov 2021 02:12:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229912AbhKDGMq (ORCPT ); Thu, 4 Nov 2021 02:12:46 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 964C9C061714 for ; Wed, 3 Nov 2021 23:10:08 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id d12so6325305lfv.6 for ; Wed, 03 Nov 2021 23:10:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to:cc; bh=KJt7w9HUtwqjLGuVfMWXu6W69sayYk8QAjyyDHSwDdA=; b=qzXxdMbz9w1B77l9kZyfLjD89q2J67SsY3fNFvY3xQrogmQ+disCqfeqoUQxL/8Ges 0gnnoVYeHBYPQbDwaoIEiFKUAaBHBO2Cgt2gUxE2Oujr3Z1AvjKLOggaZD/GE6qeazrB s6s8eL8a/uptlnY7l3kVA+LaR0SjzliL+kTmQWx6UPr8T+zWJtm6la78+YDgErmc3x8c flYvQK4G2OTeMMwPghXfbv6xM0g3/4xFVsjwusyndx/0KIxZQco+KykfvacDTIcXCIlY anUVRI9fFkHcHa8ejv88jEUd5IMYxEwRndm8YDnDtxfezWgM0yymPqZPsvgZYz5TuK+T J/tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=KJt7w9HUtwqjLGuVfMWXu6W69sayYk8QAjyyDHSwDdA=; b=k9Stgm7Zc9gYMYrJOWLAn1HavLDa+dyPgGa3cC4ePEhdTlH+Tr9/P1uFGpAddx6YF2 3ZHuV152HAMb/vY+UbdR4TToSO4l5CYIbnQUY0Ytx3VuRhOjR+hXjKKPlcwlzxKcFOSC WZhjMTelNo6MPjpyUPkl1/MuZDCTMUYOZeK8pVCvQVvrgSnOF4TjRGq+sz0P3o0mGCHQ SY9AdnSTJM5AcfJEuFBtxk5hAsvyJToVKdJ679L0aWowXeJkHvM8D8wjXwtqZPD1qWi3 C5LBnxUXJjfNOK+tg3MVtMH+ezb14izafuzthm9SSoMY0iqOQ5m+jCXBpCJo/s5gmQw0 6dBg== X-Gm-Message-State: AOAM533iI8Yb+69juqdZNj20AiMBtlYNXaacgkUyKDny79tUtAZcLYx2 Z0OFuI358t+A9WsYSpYP2ko7sCfXjxD8z/J2v63tpz0Ql1k= X-Google-Smtp-Source: ABdhPJwrOBxhWkWlWLelbG49J55727xA1pIMtQsLfk7d9n+7HHaumkWF+SiWRfBIww+G7GA3XSJ/YMI8bE0KFWEYaew= X-Received: by 2002:ac2:4309:: with SMTP id l9mr44988461lfh.667.1636006206655; Wed, 03 Nov 2021 23:10:06 -0700 (PDT) MIME-Version: 1.0 From: Steve French Date: Thu, 4 Nov 2021 01:09:55 -0500 Message-ID: Subject: trace point to print ip address we are trying to connect to To: CIFS Cc: Shyam Prasad N , Paulo Alcantara Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org It wasn't obvious to me the best way to pass in a pointer to the ipv4 (and ipv6 address) to a dynamic trace point (unless I create a temp string first in generic_ip_connect and do the conversion (via "%pI4" and "%pI6" with sprintf) e.g. sprintf(ses->ip_addr, "%pI4", &addr->sin_addr); The approach I tried passing in the pointer to sin_addr (the ipv4_address) caused an oops on loading it the first time and the warning: [14928.818532] event smb3_ipv4_connect has unsafe dereference of argument 3 [14928.818534] print_fmt: "conn_id=0x%llx server=%s addr=%pI4:%d", REC->conn_id, __get_str(hostname), REC->ipaddr, REC->port What I tried was the following (also see attached diff) to print the ipv4 address that we were trying to connect to DECLARE_EVENT_CLASS(smb3_connect_class, TP_PROTO(char *hostname, __u64 conn_id, __u16 port, struct in_addr *ipaddr), TP_ARGS(hostname, conn_id, port, ipaddr), TP_STRUCT__entry( __string(hostname, hostname) __field(__u64, conn_id) __field(__u16, port) __field(const void *, ipaddr) ), TP_fast_assign( __entry->port = port; __entry->conn_id = conn_id; __entry->ipaddr = ipaddr; __assign_str(hostname, hostname); ), TP_printk("conn_id=0x%llx server=%s addr=%pI4:%d", __entry->conn_id, __get_str(hostname), __entry->ipaddr, __entry->port) ) #define DEFINE_SMB3_CONNECT_EVENT(name) \ DEFINE_EVENT(smb3_connect_class, smb3_##name, \ TP_PROTO(char *hostname, \ __u64 conn_id, \ __u16 port, \ struct in_addr *ipaddr), \ TP_ARGS(hostname, conn_id, port, ipaddr)) DEFINE_SMB3_CONNECT_EVENT(ipv4_connect); Any ideas how to pass in the ipv4 address - or is it better to convert it to a string before we call the trace point (which seems wasteful to me but there must be examples of how to pass in structs to printks in trace in Linux) diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index e6e261dfd107..4cbfca90a47c 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -2590,6 +2590,8 @@ generic_ip_connect(struct TCP_Server_Info *server) sfamily = AF_INET; cifs_dbg(FYI, "%s: connecting to %pI4:%d\n", __func__, &ipv4->sin_addr, ntohs(sport)); + trace_smb3_ipv4_connect(server->hostname, server->conn_id, + ntohs(sport), &ipv4->sin_addr); } if (socket == NULL) { diff --git a/fs/cifs/trace.h b/fs/cifs/trace.h index dafcb6ab050d..3162f484fb85 100644 --- a/fs/cifs/trace.h +++ b/fs/cifs/trace.h @@ -11,7 +11,7 @@ #define _CIFS_TRACE_H #include - +#include /* * Please use this 3-part article as a reference for writing new tracepoints: * https://lwn.net/Articles/379903/ @@ -854,6 +854,41 @@ DEFINE_EVENT(smb3_lease_err_class, smb3_##name, \ DEFINE_SMB3_LEASE_ERR_EVENT(lease_err); +DECLARE_EVENT_CLASS(smb3_connect_class, + TP_PROTO(char *hostname, + __u64 conn_id, + __u16 port, + struct in_addr *ipaddr), + TP_ARGS(hostname, conn_id, port, ipaddr), + TP_STRUCT__entry( + __string(hostname, hostname) + __field(__u64, conn_id) + __field(__u16, port) + __field(const void *, ipaddr) + ), + TP_fast_assign( + __entry->port = port; + __entry->conn_id = conn_id; + __entry->ipaddr = ipaddr; + __assign_str(hostname, hostname); + ), + TP_printk("conn_id=0x%llx server=%s addr=%pI4:%d", + __entry->conn_id, + __get_str(hostname), + __entry->ipaddr, + __entry->port) +) + +#define DEFINE_SMB3_CONNECT_EVENT(name) \ +DEFINE_EVENT(smb3_connect_class, smb3_##name, \ + TP_PROTO(char *hostname, \ + __u64 conn_id, \ + __u16 port, \ + struct in_addr *ipaddr), \ + TP_ARGS(hostname, conn_id, port, ipaddr)) + +DEFINE_SMB3_CONNECT_EVENT(ipv4_connect); + DECLARE_EVENT_CLASS(smb3_reconnect_class, TP_PROTO(__u64 currmid, __u64 conn_id,