From patchwork Wed Mar 30 04:36:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linyu Yuan X-Patchwork-Id: 555534 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33C9EC433F5 for ; Wed, 30 Mar 2022 04:36:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242625AbiC3EiX (ORCPT ); Wed, 30 Mar 2022 00:38:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242661AbiC3EiQ (ORCPT ); Wed, 30 Mar 2022 00:38:16 -0400 Received: from alexa-out-sd-01.qualcomm.com (alexa-out-sd-01.qualcomm.com [199.106.114.38]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 144FD22B00 for ; Tue, 29 Mar 2022 21:36:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1648614990; x=1680150990; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fBx4UZiCzCK1j+2CfVkFTu4yhrZbHawb5Ljq+4d0Rxc=; b=ls1RLkI0Xvw8y6CgD23eWGz57d1VjUaXCPok7CeN+3M6tIe9idWi5WFP NtknjGnSV5wBfRvcf/CDF5ilSL7dkQtM2jfraAbMUSkFfwIbpZ95hLmBK 9q8lUaE8t6E4ZLMT4QzOjYTgT/O01z6DW4MIEM4kfDidY+LxbFzfw41Lc k=; Received: from unknown (HELO ironmsg-SD-alpha.qualcomm.com) ([10.53.140.30]) by alexa-out-sd-01.qualcomm.com with ESMTP; 29 Mar 2022 21:36:29 -0700 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg-SD-alpha.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 21:36:29 -0700 Received: from nalasex01b.na.qualcomm.com (10.47.209.197) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Tue, 29 Mar 2022 21:36:29 -0700 Received: from linyyuan-gv.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Tue, 29 Mar 2022 21:36:27 -0700 From: Linyu Yuan To: Felipe Balbi , Greg Kroah-Hartman CC: , Jack Pham , "Linyu Yuan" Subject: [PATCH v3 1/5] usb: gadget: remove gadgets_type storage type 'static' Date: Wed, 30 Mar 2022 12:36:16 +0800 Message-ID: <1648614980-25024-2-git-send-email-quic_linyyuan@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1648614980-25024-1-git-send-email-quic_linyyuan@quicinc.com> References: <1648614980-25024-1-git-send-email-quic_linyyuan@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Prepare for new trace event function which will use gadgets_type variable. Signed-off-by: Linyu Yuan --- v3: first add this change drivers/usb/gadget/configfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index 1fb837d..b2beeda 100644 --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c @@ -1642,7 +1642,7 @@ static struct configfs_group_operations gadgets_ops = { .drop_item = &gadgets_drop, }; -static const struct config_item_type gadgets_type = { +const struct config_item_type gadgets_type = { .ct_group_ops = &gadgets_ops, .ct_owner = THIS_MODULE, }; From patchwork Wed Mar 30 04:36:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linyu Yuan X-Patchwork-Id: 555535 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2374C433FE for ; Wed, 30 Mar 2022 04:36:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242615AbiC3EiW (ORCPT ); Wed, 30 Mar 2022 00:38:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242660AbiC3EiQ (ORCPT ); Wed, 30 Mar 2022 00:38:16 -0400 Received: from alexa-out.qualcomm.com (alexa-out.qualcomm.com [129.46.98.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DA0C22B18 for ; Tue, 29 Mar 2022 21:36:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1648614992; x=1680150992; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oNyAYn2iRB9DghlnpbxutG5HqEHxLidQEAxBj35aa9A=; b=hBSQyf2nn+NBRdpmaaveugVL5dyrHZlY4TreZUvWTamtAjD9XGy29gk3 XIP5wETCfuC8wZvI/+DZ2xTD2+bpuBZHYz+Y+MDF+Qat9vxzn6Nm+BIe5 rC59/bN6MWCMq48Wn5kSx+mOaCfpORXGNQL0/1c70tydvl8TLrT2KBU0X E=; Received: from ironmsg07-lv.qualcomm.com ([10.47.202.151]) by alexa-out.qualcomm.com with ESMTP; 29 Mar 2022 21:36:32 -0700 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg07-lv.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 21:36:31 -0700 Received: from nalasex01b.na.qualcomm.com (10.47.209.197) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Tue, 29 Mar 2022 21:36:31 -0700 Received: from linyyuan-gv.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Tue, 29 Mar 2022 21:36:29 -0700 From: Linyu Yuan To: Felipe Balbi , Greg Kroah-Hartman CC: , Jack Pham , "Linyu Yuan" Subject: [PATCH v3 2/5] usb: gadget: add trace event of configfs operation Date: Wed, 30 Mar 2022 12:36:17 +0800 Message-ID: <1648614980-25024-3-git-send-email-quic_linyyuan@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1648614980-25024-1-git-send-email-quic_linyyuan@quicinc.com> References: <1648614980-25024-1-git-send-email-quic_linyyuan@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add a common trace event entry which have only one __string field, it allow create APIs base on it to add trace events for usb gadget and function layer, then it will cover all user input like make configfs group/item, drop item, write attribute, allow/drop link. Signed-off-by: Linyu Yuan --- v2: no change v3: add trace.c and configfs.c will not include trace.h drivers/usb/gadget/Makefile | 2 ++ drivers/usb/gadget/trace.c | 8 ++++++++ drivers/usb/gadget/trace.h | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 drivers/usb/gadget/trace.c create mode 100644 drivers/usb/gadget/trace.h diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index 33f1ef9..b426f5c 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile @@ -8,5 +8,7 @@ subdir-ccflags-$(CONFIG_USB_GADGET_VERBOSE) += -DVERBOSE_DEBUG obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o libcomposite-y := usbstring.o config.o epautoconf.o libcomposite-y += composite.o functions.o configfs.o u_f.o +CFLAGS_trace.o := -I$(src) +libcomposite-y += trace.o obj-$(CONFIG_USB_GADGET) += udc/ function/ legacy/ diff --git a/drivers/usb/gadget/trace.c b/drivers/usb/gadget/trace.c new file mode 100644 index 0000000..8b4b1db --- /dev/null +++ b/drivers/usb/gadget/trace.c @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#define CREATE_TRACE_POINTS +#include "trace.h" + diff --git a/drivers/usb/gadget/trace.h b/drivers/usb/gadget/trace.h new file mode 100644 index 0000000..d556580 --- /dev/null +++ b/drivers/usb/gadget/trace.h @@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#undef TRACE_SYSTEM +#define TRACE_SYSTEM gadget_configfs + + +#if !defined(_GADGET_TRACE_H) || defined(TRACE_HEADER_MULTI_READ) +#define _GADGET_TRACE_H + +#include + +TRACE_EVENT(gadget_configfs, + TP_PROTO(char *info), + TP_ARGS(info), + TP_STRUCT__entry( + __string(info, info) + ), + + TP_fast_assign( + __assign_str(info, info); + ), + + TP_printk("%s", __get_str(info)) +); + +#endif /* _GADGET_TRACE_H */ + +/* this part has to be here */ + +#undef TRACE_INCLUDE_PATH +#define TRACE_INCLUDE_PATH . + +#undef TRACE_INCLUDE_FILE +#define TRACE_INCLUDE_FILE trace + +#include From patchwork Wed Mar 30 04:36:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linyu Yuan X-Patchwork-Id: 555251 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82CC9C4332F for ; Wed, 30 Mar 2022 04:36:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242622AbiC3EiW (ORCPT ); Wed, 30 Mar 2022 00:38:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242666AbiC3EiS (ORCPT ); Wed, 30 Mar 2022 00:38:18 -0400 Received: from alexa-out-sd-01.qualcomm.com (alexa-out-sd-01.qualcomm.com [199.106.114.38]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A759322B22 for ; Tue, 29 Mar 2022 21:36:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1648614993; x=1680150993; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LxESVssURVT/NkMHo+yN3CMA+XiFeh54I6ETMqdmIeY=; b=kveCJhYPdWa+rAtwb53peajVZqwQo6VYAYluMyASdEW7nK2Apdf0+DDm NyoRqeu9HP3iqZ8WavHHrrJ5O3fxR14p9OJ7DR6dEn3RNWt9G2AmVYI5j U7QnuI+l4xetTkbpuWmWlqjrP8ugLF/I3pHv2sQNf1kJAFU0kVmucyOWo U=; Received: from unknown (HELO ironmsg02-sd.qualcomm.com) ([10.53.140.142]) by alexa-out-sd-01.qualcomm.com with ESMTP; 29 Mar 2022 21:36:33 -0700 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg02-sd.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 21:36:33 -0700 Received: from nalasex01b.na.qualcomm.com (10.47.209.197) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Tue, 29 Mar 2022 21:36:32 -0700 Received: from linyyuan-gv.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Tue, 29 Mar 2022 21:36:31 -0700 From: Linyu Yuan To: Felipe Balbi , Greg Kroah-Hartman CC: , Jack Pham , "Linyu Yuan" Subject: [PATCH v3 3/5] usb: gadget: add trace event of configfs group operation Date: Wed, 30 Mar 2022 12:36:18 +0800 Message-ID: <1648614980-25024-4-git-send-email-quic_linyyuan@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1648614980-25024-1-git-send-email-quic_linyyuan@quicinc.com> References: <1648614980-25024-1-git-send-email-quic_linyyuan@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add API trace_usb_configfs_make_group() and trace_usb_configfs_drop_group() to trace user create groups like gadget/function/configuration, it also trace group create in a specific function. Signed-off-by: Linyu Yuan --- v2: no change v3: add API in trace.c drivers/usb/gadget/configfs.c | 11 ++++ drivers/usb/gadget/function/f_mass_storage.c | 4 ++ drivers/usb/gadget/function/uvc_configfs.c | 12 +++++ drivers/usb/gadget/trace.c | 80 ++++++++++++++++++++++++++++ include/linux/usb/composite.h | 9 ++++ include/linux/usb/gadget_configfs.h | 2 + 6 files changed, 118 insertions(+) diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index b2beeda..a0599fb 100644 --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c @@ -621,6 +621,8 @@ static struct config_group *function_make( gi = container_of(group, struct gadget_info, functions_group); + trace_usb_configfs_make_group(&group->cg_item, &fi->group.cg_item); + mutex_lock(&gi->lock); list_add_tail(&fi->cfs_list, &gi->available_func); mutex_unlock(&gi->lock); @@ -634,6 +636,8 @@ static void function_drop( struct usb_function_instance *fi = to_usb_function_instance(item); struct gadget_info *gi; + trace_usb_configfs_drop_group(&group->cg_item, item); + gi = container_of(group, struct gadget_info, functions_group); mutex_lock(&gi->lock); @@ -729,6 +733,7 @@ static struct config_group *config_desc_make( if (ret) goto err; + trace_usb_configfs_make_group(&group->cg_item, &cfg->group.cg_item); return &cfg->group; err: kfree(cfg->c.label); @@ -740,6 +745,7 @@ static void config_desc_drop( struct config_group *group, struct config_item *item) { + trace_usb_configfs_drop_group(&group->cg_item, item); config_item_put(item); } @@ -1083,6 +1089,7 @@ static struct config_item *ext_prop_make( ext_prop_type->ct_owner = desc->owner; config_item_init_type_name(&ext_prop->item, name, ext_prop_type); + trace_usb_configfs_make_group(&group->cg_item, &ext_prop->item); ext_prop->name = kstrdup(name, GFP_KERNEL); if (!ext_prop->name) { @@ -1107,6 +1114,8 @@ static void ext_prop_drop(struct config_group *group, struct config_item *item) struct usb_os_desc_ext_prop *ext_prop = to_usb_os_desc_ext_prop(item); struct usb_os_desc *desc = to_usb_os_desc(&group->cg_item); + trace_usb_configfs_drop_group(&group->cg_item, item); + if (desc->opts_mutex) mutex_lock(desc->opts_mutex); list_del(&ext_prop->entry); @@ -1626,6 +1635,7 @@ static struct config_group *gadgets_make( if (!gi->composite.gadget_driver.function) goto err; + trace_usb_configfs_make_group(&group->cg_item, &gi->group.cg_item); return &gi->group; err: kfree(gi); @@ -1634,6 +1644,7 @@ static struct config_group *gadgets_make( static void gadgets_drop(struct config_group *group, struct config_item *item) { + trace_usb_configfs_drop_group(&group->cg_item, item); config_item_put(item); } diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c index 3a77bca..a96eca9 100644 --- a/drivers/usb/gadget/function/f_mass_storage.c +++ b/drivers/usb/gadget/function/f_mass_storage.c @@ -3289,6 +3289,8 @@ static struct config_group *fsg_lun_make(struct config_group *group, config_group_init_type_name(&opts->group, name, &fsg_lun_type); + trace_usb_configfs_make_group(&group->cg_item, &opts->group.cg_item); + return &opts->group; out: mutex_unlock(&fsg_opts->lock); @@ -3300,6 +3302,8 @@ static void fsg_lun_drop(struct config_group *group, struct config_item *item) struct fsg_lun_opts *lun_opts; struct fsg_opts *fsg_opts; + trace_usb_configfs_drop_group(&group->cg_item, item); + lun_opts = to_fsg_lun_opts(item); fsg_opts = to_fsg_opts(&group->cg_item); diff --git a/drivers/usb/gadget/function/uvc_configfs.c b/drivers/usb/gadget/function/uvc_configfs.c index 77d6403..cc0f2eb 100644 --- a/drivers/usb/gadget/function/uvc_configfs.c +++ b/drivers/usb/gadget/function/uvc_configfs.c @@ -236,6 +236,8 @@ static struct config_item *uvcg_control_header_make(struct config_group *group, config_item_init_type_name(&h->item, name, &uvcg_control_header_type); + trace_usb_configfs_make_group(&group->cg_item, &h->item); + return &h->item; } @@ -1039,6 +1041,8 @@ static struct config_item config_item_init_type_name(&h->item, name, &uvcg_streaming_header_type); + trace_usb_configfs_make_group(&group->cg_item, &h->item); + return &h->item; } @@ -1380,6 +1384,8 @@ static struct config_item *uvcg_frame_make(struct config_group *group, config_item_init_type_name(&h->item, name, &uvcg_frame_type); + trace_usb_configfs_make_group(&group->cg_item, &h->item); + return &h->item; } @@ -1389,6 +1395,8 @@ static void uvcg_frame_drop(struct config_group *group, struct config_item *item struct f_uvc_opts *opts; struct config_item *opts_item; + trace_usb_configfs_drop_group(&group->cg_item, item); + opts_item = group->cg_item.ci_parent->ci_parent->ci_parent; opts = to_f_uvc_opts(opts_item); @@ -1649,6 +1657,8 @@ static struct config_group *uvcg_uncompressed_make(struct config_group *group, config_group_init_type_name(&h->fmt.group, name, &uvcg_uncompressed_type); + trace_usb_configfs_make_group(&group->cg_item, &h->fmt.group.cg_item); + return &h->fmt.group; } @@ -1835,6 +1845,8 @@ static struct config_group *uvcg_mjpeg_make(struct config_group *group, config_group_init_type_name(&h->fmt.group, name, &uvcg_mjpeg_type); + trace_usb_configfs_make_group(&group->cg_item, &h->fmt.group.cg_item); + return &h->fmt.group; } diff --git a/drivers/usb/gadget/trace.c b/drivers/usb/gadget/trace.c index 8b4b1db..66a0762 100644 --- a/drivers/usb/gadget/trace.c +++ b/drivers/usb/gadget/trace.c @@ -6,3 +6,83 @@ #define CREATE_TRACE_POINTS #include "trace.h" +#include +#include + +extern const struct config_item_type gadgets_type; + +#ifdef CONFIG_TRACEPOINTS +#define GROUP_LEN 128 +static int gadget_configfs_group(char *group, struct config_item *item) +{ + struct config_item *parent; + char *tmpgroup; + + if (!item) + return -1; + + tmpgroup = kzalloc(GROUP_LEN, GFP_KERNEL); + if (!tmpgroup) + return -1; + + for (parent = item->ci_parent; parent; + item = parent,parent = item->ci_parent) { + if (item->ci_type == &gadgets_type) { + kfree(tmpgroup); + return 0; + } + + if (tmpgroup[0] == '\0') + snprintf(group, GROUP_LEN, "%s", + config_item_name(item)); + else + snprintf(group, GROUP_LEN, "%s/%s", + config_item_name(item), tmpgroup); + + strcpy(tmpgroup, group); + } + + return -1; +} + +static void trace_usb_configfs_make_drop_group(struct config_item *parent, + struct config_item *item, char *make_drop) +{ + char *group, *parent_group; + int ret; + + group = kzalloc(2 * GROUP_LEN, GFP_KERNEL); + if (!group) + return; + + parent_group = group + GROUP_LEN; + ret = gadget_configfs_group(parent_group, parent); + if (ret) { + kfree(group); + return; + } + + if (parent_group[0] == '\0') + snprintf(group, GROUP_LEN, "%s %s", make_drop, + config_item_name(item)); + else + snprintf(group, GROUP_LEN, "%s %s/%s", make_drop, parent_group, + config_item_name(item)); + + trace_gadget_configfs(group); +} + +void trace_usb_configfs_make_group(struct config_item *parent, + struct config_item *item) +{ + trace_usb_configfs_make_drop_group(parent, item, "mkdir"); +} +EXPORT_SYMBOL(trace_usb_configfs_make_group); + +void trace_usb_configfs_drop_group(struct config_item *parent, + struct config_item *item) +{ + trace_usb_configfs_make_drop_group(parent, item, "rmdir"); +} +EXPORT_SYMBOL(trace_usb_configfs_drop_group); +#endif diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h index 9d27622..e904527 100644 --- a/include/linux/usb/composite.h +++ b/include/linux/usb/composite.h @@ -603,6 +603,15 @@ void usb_put_function_instance(struct usb_function_instance *fi); void usb_put_function(struct usb_function *f); struct usb_function_instance *usb_get_function_instance(const char *name); struct usb_function *usb_get_function(struct usb_function_instance *fi); +#ifdef CONFIG_TRACEPOINTS +void trace_usb_configfs_make_group(struct config_item *parent, + struct config_item *item); +void trace_usb_configfs_drop_group(struct config_item *parent, + struct config_item *item); +#else +#define trace_usb_configfs_make_group(parent, item) do {} while(0) +#define trace_usb_configfs_drop_group(parent, item) do {} while(0) +#endif struct usb_configuration *usb_get_config(struct usb_composite_dev *cdev, int val); diff --git a/include/linux/usb/gadget_configfs.h b/include/linux/usb/gadget_configfs.h index d61aebd..a89f177 100644 --- a/include/linux/usb/gadget_configfs.h +++ b/include/linux/usb/gadget_configfs.h @@ -63,6 +63,7 @@ static struct config_item_type struct_in##_langid_type = { \ goto err; \ config_group_init_type_name(&new->group, name, \ &struct_in##_langid_type); \ + trace_usb_configfs_make_group(&group->cg_item, &new->group.cg_item); \ \ gi = container_of(group, struct struct_member, strings_group); \ ret = -EEXIST; \ @@ -86,6 +87,7 @@ static void struct_in##_strings_drop( \ struct config_group *group, \ struct config_item *item) \ { \ + trace_usb_configfs_drop_group(&group->cg_item, item); \ config_item_put(item); \ } \ \ From patchwork Wed Mar 30 04:36:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linyu Yuan X-Patchwork-Id: 555250 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACA72C433EF for ; Wed, 30 Mar 2022 04:36:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242633AbiC3Ei1 (ORCPT ); Wed, 30 Mar 2022 00:38:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242636AbiC3EiT (ORCPT ); Wed, 30 Mar 2022 00:38:19 -0400 Received: from alexa-out-sd-01.qualcomm.com (alexa-out-sd-01.qualcomm.com [199.106.114.38]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 512752253B for ; Tue, 29 Mar 2022 21:36:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1648614995; x=1680150995; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8fSR2rkcfoY2SPmLLrProyRiR5ZRmVTmoUhSPRIOFdI=; b=MsFHShCnTFU/rGtPwsovb2zVeNrlh1sTQ47gNmIrzb5uCNyHUpn1ASLi Fs3PYUmBp/YGn9C0QEOIUEPaKzNqqJS7rxPM7fvAS6OctNmCB2Ki5sbaK tetkh0PlBkmhH73egwaq3zILKKjjpdIXd0dtmrbJE5EcIJsSMWTttLXog E=; Received: from unknown (HELO ironmsg01-sd.qualcomm.com) ([10.53.140.141]) by alexa-out-sd-01.qualcomm.com with ESMTP; 29 Mar 2022 21:36:35 -0700 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg01-sd.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 21:36:34 -0700 Received: from nalasex01b.na.qualcomm.com (10.47.209.197) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Tue, 29 Mar 2022 21:36:34 -0700 Received: from linyyuan-gv.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Tue, 29 Mar 2022 21:36:32 -0700 From: Linyu Yuan To: Felipe Balbi , Greg Kroah-Hartman CC: , Jack Pham , "Linyu Yuan" Subject: [PATCH v3 4/5] usb: gadget: add trace event of configfs link/unlink operation Date: Wed, 30 Mar 2022 12:36:19 +0800 Message-ID: <1648614980-25024-5-git-send-email-quic_linyyuan@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1648614980-25024-1-git-send-email-quic_linyyuan@quicinc.com> References: <1648614980-25024-1-git-send-email-quic_linyyuan@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add API trace_usb_configfs_link_group() and trace_usb_configfs_unlink_group() to trace user link/unlink a group like add function to configuration or remove function from configuration. If a specific function need link/unlink, it also can be used. Signed-off-by: Linyu Yuan --- v2: no change v3: add API in trace.c drivers/usb/gadget/configfs.c | 8 ++++++ drivers/usb/gadget/function/uvc_configfs.c | 12 ++++++++ drivers/usb/gadget/trace.c | 44 ++++++++++++++++++++++++++++++ include/linux/usb/composite.h | 6 ++++ 4 files changed, 70 insertions(+) diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index a0599fb..a304d29 100644 --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c @@ -422,6 +422,8 @@ static int config_usb_cfg_link( struct usb_function *f; int ret; + trace_usb_configfs_link_group(usb_cfg_ci, usb_func_ci); + mutex_lock(&gi->lock); /* * Make sure this function is from within our _this_ gadget and not @@ -471,6 +473,8 @@ static void config_usb_cfg_unlink( to_usb_function_instance(usb_func_ci); struct usb_function *f; + trace_usb_configfs_unlink_group(usb_cfg_ci, usb_func_ci); + /* * ideally I would like to forbid to unlink functions while a gadget is * bound to an UDC. Since this isn't possible at the moment, we simply @@ -893,6 +897,8 @@ static int os_desc_link(struct config_item *os_desc_ci, struct usb_configuration *c = NULL, *iter; int ret; + trace_usb_configfs_link_group(os_desc_ci, usb_cfg_ci); + mutex_lock(&gi->lock); list_for_each_entry(iter, &cdev->configs, list) { if (iter != &c_target->c) @@ -924,6 +930,8 @@ static void os_desc_unlink(struct config_item *os_desc_ci, struct gadget_info *gi = os_desc_item_to_gadget_info(os_desc_ci); struct usb_composite_dev *cdev = &gi->cdev; + trace_usb_configfs_unlink_group(os_desc_ci, usb_cfg_ci); + mutex_lock(&gi->lock); if (gi->composite.gadget_driver.udc_name) unregister_gadget(gi); diff --git a/drivers/usb/gadget/function/uvc_configfs.c b/drivers/usb/gadget/function/uvc_configfs.c index cc0f2eb..fc139f3 100644 --- a/drivers/usb/gadget/function/uvc_configfs.c +++ b/drivers/usb/gadget/function/uvc_configfs.c @@ -598,6 +598,8 @@ static int uvcg_control_class_allow_link(struct config_item *src, struct uvcg_control_header *target_hdr; int ret = -EINVAL; + trace_usb_configfs_link_group(src, target); + mutex_lock(su_mutex); /* for navigating configfs hierarchy */ control = src->ci_parent->ci_parent; @@ -639,6 +641,8 @@ static void uvcg_control_class_drop_link(struct config_item *src, struct uvc_descriptor_header **class_array; struct uvcg_control_header *target_hdr; + trace_usb_configfs_unlink_group(src, target); + mutex_lock(su_mutex); /* for navigating configfs hierarchy */ control = src->ci_parent->ci_parent; @@ -883,6 +887,8 @@ static int uvcg_streaming_header_allow_link(struct config_item *src, struct uvcg_format_ptr *format_ptr; int i, ret = -EINVAL; + trace_usb_configfs_link_group(src, target); + src_hdr = to_uvcg_streaming_header(src); mutex_lock(su_mutex); /* for navigating configfs hierarchy */ @@ -946,6 +952,8 @@ static void uvcg_streaming_header_drop_link(struct config_item *src, struct uvcg_format *target_fmt = NULL; struct uvcg_format_ptr *format_ptr, *tmp; + trace_usb_configfs_unlink_group(src, target); + src_hdr = to_uvcg_streaming_header(src); mutex_lock(su_mutex); /* for navigating configfs hierarchy */ @@ -2171,6 +2179,8 @@ static int uvcg_streaming_class_allow_link(struct config_item *src, size_t size = 0, count = 0; int ret = -EINVAL; + trace_usb_configfs_link_group(src, target); + mutex_lock(su_mutex); /* for navigating configfs hierarchy */ streaming = src->ci_parent->ci_parent; @@ -2242,6 +2252,8 @@ static void uvcg_streaming_class_drop_link(struct config_item *src, struct uvc_descriptor_header ***class_array; struct uvcg_streaming_header *target_hdr; + trace_usb_configfs_unlink_group(src, target); + mutex_lock(su_mutex); /* for navigating configfs hierarchy */ streaming = src->ci_parent->ci_parent; diff --git a/drivers/usb/gadget/trace.c b/drivers/usb/gadget/trace.c index 66a0762..b39bf6f 100644 --- a/drivers/usb/gadget/trace.c +++ b/drivers/usb/gadget/trace.c @@ -85,4 +85,48 @@ void trace_usb_configfs_drop_group(struct config_item *parent, trace_usb_configfs_make_drop_group(parent, item, "rmdir"); } EXPORT_SYMBOL(trace_usb_configfs_drop_group); + +static void trace_usb_configfs_link_unlink_group(struct config_item *dest, + struct config_item *src, char *link_unlink) +{ + char *group, *dest_group, *src_group; + int ret; + + group = kzalloc(4 * GROUP_LEN, GFP_KERNEL); + if (!group) + return; + + dest_group = group + 2 * GROUP_LEN; + ret = gadget_configfs_group(dest_group, dest); + if (ret) { + kfree(group); + return; + } + + src_group = group + 3 * GROUP_LEN; + ret = gadget_configfs_group(src_group, src); + if (ret) { + kfree(group); + return; + } + + snprintf(group, 2 * GROUP_LEN, "%s %s %s", + link_unlink, dest_group, src_group); + + trace_gadget_configfs(group); +} + +void trace_usb_configfs_link_group(struct config_item *dest, + struct config_item *src) +{ + trace_usb_configfs_link_unlink_group(dest, src, "link"); +} +EXPORT_SYMBOL(trace_usb_configfs_link_group); + +void trace_usb_configfs_unlink_group(struct config_item *dest, + struct config_item *src) +{ + trace_usb_configfs_link_unlink_group(dest, src, "unlink"); +} +EXPORT_SYMBOL(trace_usb_configfs_unlink_group); #endif diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h index e904527..df74bd5 100644 --- a/include/linux/usb/composite.h +++ b/include/linux/usb/composite.h @@ -608,9 +608,15 @@ void trace_usb_configfs_make_group(struct config_item *parent, struct config_item *item); void trace_usb_configfs_drop_group(struct config_item *parent, struct config_item *item); +void trace_usb_configfs_link_group(struct config_item *dest, + struct config_item *src); +void trace_usb_configfs_unlink_group(struct config_item *dest, + struct config_item *src); #else #define trace_usb_configfs_make_group(parent, item) do {} while(0) #define trace_usb_configfs_drop_group(parent, item) do {} while(0) +#define trace_usb_configfs_link_group(dest, src) do {} while(0) +#define trace_usb_configfs_unlink_group(dest, src) do {} while(0) #endif struct usb_configuration *usb_get_config(struct usb_composite_dev *cdev, From patchwork Wed Mar 30 04:36:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linyu Yuan X-Patchwork-Id: 555533 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52D25C433F5 for ; Wed, 30 Mar 2022 04:36:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242635AbiC3Ei2 (ORCPT ); Wed, 30 Mar 2022 00:38:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242617AbiC3EiW (ORCPT ); Wed, 30 Mar 2022 00:38:22 -0400 Received: from alexa-out.qualcomm.com (alexa-out.qualcomm.com [129.46.98.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F314922B00 for ; Tue, 29 Mar 2022 21:36:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1648614997; x=1680150997; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZVSSV0XOQpNnR4T92tchagkZ85QpbJyLAuNDxzyGyCk=; b=oaILr8OKfJV79MDwsuFdocVt05pTDjo4+FWXcs0YULg2cyeiEavNq3Lo XEe8K+CkIRVAXW7EQzos4jaDzeate/800fWB6+ae7oLfpiuzZpxOWLUtu J2CntID9mhmPpom9L5VXgGfyby/Z5/SaKRu/NG9n8zldJo2IqQGAZDToX 8=; Received: from ironmsg08-lv.qualcomm.com ([10.47.202.152]) by alexa-out.qualcomm.com with ESMTP; 29 Mar 2022 21:36:36 -0700 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg08-lv.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 21:36:36 -0700 Received: from nalasex01b.na.qualcomm.com (10.47.209.197) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Tue, 29 Mar 2022 21:36:36 -0700 Received: from linyyuan-gv.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Tue, 29 Mar 2022 21:36:34 -0700 From: Linyu Yuan To: Felipe Balbi , Greg Kroah-Hartman CC: , Jack Pham , "Linyu Yuan" Subject: [PATCH v3 5/5] usb: gadget: add trace event of configfs write attributes operation Date: Wed, 30 Mar 2022 12:36:20 +0800 Message-ID: <1648614980-25024-6-git-send-email-quic_linyyuan@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1648614980-25024-1-git-send-email-quic_linyyuan@quicinc.com> References: <1648614980-25024-1-git-send-email-quic_linyyuan@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add API trace_usb_configfs_write_attr() to trace user change gadget or function attributes. Signed-off-by: Linyu Yuan --- v2: no change v3: add API in trace.c drivers/usb/gadget/configfs.c | 24 ++++++++++++++++++++++++ drivers/usb/gadget/function/f_acm.c | 1 + drivers/usb/gadget/function/f_hid.c | 4 ++++ drivers/usb/gadget/function/f_loopback.c | 4 ++++ drivers/usb/gadget/function/f_mass_storage.c | 16 ++++++++++++++++ drivers/usb/gadget/function/f_midi.c | 6 ++++++ drivers/usb/gadget/function/f_printer.c | 4 ++++ drivers/usb/gadget/function/f_serial.c | 1 + drivers/usb/gadget/function/f_sourcesink.c | 16 ++++++++++++++++ drivers/usb/gadget/function/f_uac1.c | 6 ++++++ drivers/usb/gadget/function/f_uac1_legacy.c | 4 ++++ drivers/usb/gadget/function/f_uac2.c | 8 ++++++++ drivers/usb/gadget/function/u_ether_configfs.h | 10 ++++++++++ drivers/usb/gadget/function/uvc_configfs.c | 18 ++++++++++++++++++ drivers/usb/gadget/trace.c | 24 ++++++++++++++++++++++++ include/linux/usb/composite.h | 3 +++ include/linux/usb/gadget_configfs.h | 2 ++ 17 files changed, 151 insertions(+) diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index a304d29..a9ea331 100644 --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c @@ -146,6 +146,8 @@ static ssize_t gadget_dev_desc_##_name##_store(struct config_item *item, \ { \ u8 val; \ int ret; \ + \ + trace_usb_configfs_write_attr(item, #_name, page); \ ret = kstrtou8(page, 0, &val); \ if (ret) \ return ret; \ @@ -159,6 +161,8 @@ static ssize_t gadget_dev_desc_##_name##_store(struct config_item *item, \ { \ u16 val; \ int ret; \ + \ + trace_usb_configfs_write_attr(item, #_name, page); \ ret = kstrtou16(page, 0, &val); \ if (ret) \ return ret; \ @@ -198,6 +202,8 @@ static ssize_t gadget_dev_desc_bcdDevice_store(struct config_item *item, u16 bcdDevice; int ret; + trace_usb_configfs_write_attr(item, "bcdDevice", page); + ret = kstrtou16(page, 0, &bcdDevice); if (ret) return ret; @@ -215,6 +221,8 @@ static ssize_t gadget_dev_desc_bcdUSB_store(struct config_item *item, u16 bcdUSB; int ret; + trace_usb_configfs_write_attr(item, "bcdUSB", page); + ret = kstrtou16(page, 0, &bcdUSB); if (ret) return ret; @@ -262,6 +270,8 @@ static ssize_t gadget_dev_desc_UDC_store(struct config_item *item, char *name; int ret; + trace_usb_configfs_write_attr(item, "UDC", page); + if (strlen(page) < len) return -EOVERFLOW; @@ -311,6 +321,8 @@ static ssize_t gadget_dev_desc_max_speed_store(struct config_item *item, { struct gadget_info *gi = to_gadget_info(item); + trace_usb_configfs_write_attr(item, "max_speed", page); + mutex_lock(&gi->lock); /* Prevent changing of max_speed after the driver is binded */ @@ -519,6 +531,9 @@ static ssize_t gadget_config_desc_MaxPower_store(struct config_item *item, struct config_usb_cfg *cfg = to_config_usb_cfg(item); u16 val; int ret; + + trace_usb_configfs_write_attr(item, "MaxPower", page); + ret = kstrtou16(page, 0, &val); if (ret) return ret; @@ -542,6 +557,9 @@ static ssize_t gadget_config_desc_bmAttributes_store(struct config_item *item, struct config_usb_cfg *cfg = to_config_usb_cfg(item); u8 val; int ret; + + trace_usb_configfs_write_attr(item, "bmAttributes", page); + ret = kstrtou8(page, 0, &val); if (ret) return ret; @@ -809,6 +827,8 @@ static ssize_t os_desc_use_store(struct config_item *item, const char *page, int ret; bool use; + trace_usb_configfs_write_attr(item, "use", page); + mutex_lock(&gi->lock); ret = strtobool(page, &use); if (!ret) { @@ -833,6 +853,8 @@ static ssize_t os_desc_b_vendor_code_store(struct config_item *item, int ret; u8 b_vendor_code; + trace_usb_configfs_write_attr(item, "b_vendor_code", page); + mutex_lock(&gi->lock); ret = kstrtou8(page, 0, &b_vendor_code); if (!ret) { @@ -862,6 +884,8 @@ static ssize_t os_desc_qw_sign_store(struct config_item *item, const char *page, struct gadget_info *gi = os_desc_item_to_gadget_info(item); int res, l; + trace_usb_configfs_write_attr(item, "qw_sign", page); + l = min((int)len, OS_STRING_QW_SIGN_LEN >> 1); if (page[l - 1] == '\n') --l; diff --git a/drivers/usb/gadget/function/f_acm.c b/drivers/usb/gadget/function/f_acm.c index 349945e..d48f666 100644 --- a/drivers/usb/gadget/function/f_acm.c +++ b/drivers/usb/gadget/function/f_acm.c @@ -794,6 +794,7 @@ static struct configfs_item_operations acm_item_ops = { static ssize_t f_acm_console_store(struct config_item *item, const char *page, size_t count) { + trace_usb_configfs_write_attr(item, "console", page); return gserial_set_console(to_f_serial_opts(item)->port_num, page, count); } diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c index ca0a7d9..c54af8d 100644 --- a/drivers/usb/gadget/function/f_hid.c +++ b/drivers/usb/gadget/function/f_hid.c @@ -1074,6 +1074,8 @@ static ssize_t f_hid_opts_##name##_store(struct config_item *item, \ int ret; \ u##prec num; \ \ + trace_usb_configfs_write_attr(item, #name, page); \ + \ mutex_lock(&opts->lock); \ if (opts->refcnt) { \ ret = -EBUSY; \ @@ -1123,6 +1125,8 @@ static ssize_t f_hid_opts_report_desc_store(struct config_item *item, int ret = -EBUSY; char *d; + trace_usb_configfs_write_attr(item, "report_desc", page); + mutex_lock(&opts->lock); if (opts->refcnt) diff --git a/drivers/usb/gadget/function/f_loopback.c b/drivers/usb/gadget/function/f_loopback.c index ae41f55..42f6061 100644 --- a/drivers/usb/gadget/function/f_loopback.c +++ b/drivers/usb/gadget/function/f_loopback.c @@ -489,6 +489,8 @@ static ssize_t f_lb_opts_qlen_store(struct config_item *item, int ret; u32 num; + trace_usb_configfs_write_attr(item, "qlen", page); + mutex_lock(&opts->lock); if (opts->refcnt) { ret = -EBUSY; @@ -527,6 +529,8 @@ static ssize_t f_lb_opts_bulk_buflen_store(struct config_item *item, int ret; u32 num; + trace_usb_configfs_write_attr(item, "bulk_buflen", page); + mutex_lock(&opts->lock); if (opts->refcnt) { ret = -EBUSY; diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c index a96eca9..295966b 100644 --- a/drivers/usb/gadget/function/f_mass_storage.c +++ b/drivers/usb/gadget/function/f_mass_storage.c @@ -3141,6 +3141,8 @@ static ssize_t fsg_lun_opts_file_store(struct config_item *item, struct fsg_lun_opts *opts = to_fsg_lun_opts(item); struct fsg_opts *fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent); + trace_usb_configfs_write_attr(item, "file", page); + return fsg_store_file(opts->lun, &fsg_opts->common->filesem, page, len); } @@ -3157,6 +3159,8 @@ static ssize_t fsg_lun_opts_ro_store(struct config_item *item, struct fsg_lun_opts *opts = to_fsg_lun_opts(item); struct fsg_opts *fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent); + trace_usb_configfs_write_attr(item, "ro", page); + return fsg_store_ro(opts->lun, &fsg_opts->common->filesem, page, len); } @@ -3171,6 +3175,8 @@ static ssize_t fsg_lun_opts_removable_show(struct config_item *item, static ssize_t fsg_lun_opts_removable_store(struct config_item *item, const char *page, size_t len) { + trace_usb_configfs_write_attr(item, "removable", page); + return fsg_store_removable(to_fsg_lun_opts(item)->lun, page, len); } @@ -3187,6 +3193,8 @@ static ssize_t fsg_lun_opts_cdrom_store(struct config_item *item, struct fsg_lun_opts *opts = to_fsg_lun_opts(item); struct fsg_opts *fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent); + trace_usb_configfs_write_attr(item, "cdrom", page); + return fsg_store_cdrom(opts->lun, &fsg_opts->common->filesem, page, len); } @@ -3201,6 +3209,8 @@ static ssize_t fsg_lun_opts_nofua_show(struct config_item *item, char *page) static ssize_t fsg_lun_opts_nofua_store(struct config_item *item, const char *page, size_t len) { + trace_usb_configfs_write_attr(item, "nofua", page); + return fsg_store_nofua(to_fsg_lun_opts(item)->lun, page, len); } @@ -3215,6 +3225,8 @@ static ssize_t fsg_lun_opts_inquiry_string_show(struct config_item *item, static ssize_t fsg_lun_opts_inquiry_string_store(struct config_item *item, const char *page, size_t len) { + trace_usb_configfs_write_attr(item, "inquiry_string", page); + return fsg_store_inquiry_string(to_fsg_lun_opts(item)->lun, page, len); } @@ -3353,6 +3365,8 @@ static ssize_t fsg_opts_stall_store(struct config_item *item, const char *page, int ret; bool stall; + trace_usb_configfs_write_attr(item, "stall", page); + mutex_lock(&opts->lock); if (opts->refcnt) { @@ -3393,6 +3407,8 @@ static ssize_t fsg_opts_num_buffers_store(struct config_item *item, int ret; u8 num; + trace_usb_configfs_write_attr(item, "num_buffers", page); + mutex_lock(&opts->lock); if (opts->refcnt) { ret = -EBUSY; diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c index fddf539..ebb2d7b 100644 --- a/drivers/usb/gadget/function/f_midi.c +++ b/drivers/usb/gadget/function/f_midi.c @@ -1110,6 +1110,8 @@ static ssize_t f_midi_opts_##name##_store(struct config_item *item, \ int ret; \ u32 num; \ \ + trace_usb_configfs_write_attr(item, #name, page); \ + \ mutex_lock(&opts->lock); \ if (opts->refcnt > 1) { \ ret = -EBUSY; \ @@ -1154,6 +1156,8 @@ static ssize_t f_midi_opts_##name##_store(struct config_item *item, \ int ret; \ s32 num; \ \ + trace_usb_configfs_write_attr(item, #name, page); \ + \ mutex_lock(&opts->lock); \ if (opts->refcnt > 1) { \ ret = -EBUSY; \ @@ -1209,6 +1213,8 @@ static ssize_t f_midi_opts_id_store(struct config_item *item, int ret; char *c; + trace_usb_configfs_write_attr(item, "id", page); + mutex_lock(&opts->lock); if (opts->refcnt > 1) { ret = -EBUSY; diff --git a/drivers/usb/gadget/function/f_printer.c b/drivers/usb/gadget/function/f_printer.c index abec5c5..c071574 100644 --- a/drivers/usb/gadget/function/f_printer.c +++ b/drivers/usb/gadget/function/f_printer.c @@ -1239,6 +1239,8 @@ static ssize_t f_printer_opts_pnp_string_store(struct config_item *item, char *new_pnp; int result; + trace_usb_configfs_write_attr(item, "pnp_string", page); + mutex_lock(&opts->lock); new_pnp = kstrndup(page, len, GFP_KERNEL); @@ -1281,6 +1283,8 @@ static ssize_t f_printer_opts_q_len_store(struct config_item *item, int ret; u16 num; + trace_usb_configfs_write_attr(item, "q_len", page); + mutex_lock(&opts->lock); if (opts->refcnt) { ret = -EBUSY; diff --git a/drivers/usb/gadget/function/f_serial.c b/drivers/usb/gadget/function/f_serial.c index a9480b9..58f69a7 100644 --- a/drivers/usb/gadget/function/f_serial.c +++ b/drivers/usb/gadget/function/f_serial.c @@ -271,6 +271,7 @@ static struct configfs_item_operations serial_item_ops = { static ssize_t f_serial_console_store(struct config_item *item, const char *page, size_t count) { + trace_usb_configfs_write_attr(item, "console", page); return gserial_set_console(to_f_serial_opts(item)->port_num, page, count); } diff --git a/drivers/usb/gadget/function/f_sourcesink.c b/drivers/usb/gadget/function/f_sourcesink.c index 6803cd6..4e6acd7 100644 --- a/drivers/usb/gadget/function/f_sourcesink.c +++ b/drivers/usb/gadget/function/f_sourcesink.c @@ -907,6 +907,8 @@ static ssize_t f_ss_opts_pattern_store(struct config_item *item, int ret; u8 num; + trace_usb_configfs_write_attr(item, "pattern", page); + mutex_lock(&opts->lock); if (opts->refcnt) { ret = -EBUSY; @@ -950,6 +952,8 @@ static ssize_t f_ss_opts_isoc_interval_store(struct config_item *item, int ret; u8 num; + trace_usb_configfs_write_attr(item, "isoc_interval", page); + mutex_lock(&opts->lock); if (opts->refcnt) { ret = -EBUSY; @@ -993,6 +997,8 @@ static ssize_t f_ss_opts_isoc_maxpacket_store(struct config_item *item, int ret; u16 num; + trace_usb_configfs_write_attr(item, "isoc_maxpacket", page); + mutex_lock(&opts->lock); if (opts->refcnt) { ret = -EBUSY; @@ -1036,6 +1042,8 @@ static ssize_t f_ss_opts_isoc_mult_store(struct config_item *item, int ret; u8 num; + trace_usb_configfs_write_attr(item, "isoc_mult", page); + mutex_lock(&opts->lock); if (opts->refcnt) { ret = -EBUSY; @@ -1079,6 +1087,8 @@ static ssize_t f_ss_opts_isoc_maxburst_store(struct config_item *item, int ret; u8 num; + trace_usb_configfs_write_attr(item, "isoc_maxburst", page); + mutex_lock(&opts->lock); if (opts->refcnt) { ret = -EBUSY; @@ -1122,6 +1132,8 @@ static ssize_t f_ss_opts_bulk_buflen_store(struct config_item *item, int ret; u32 num; + trace_usb_configfs_write_attr(item, "bulk_buflen", page); + mutex_lock(&opts->lock); if (opts->refcnt) { ret = -EBUSY; @@ -1160,6 +1172,8 @@ static ssize_t f_ss_opts_bulk_qlen_store(struct config_item *item, int ret; u32 num; + trace_usb_configfs_write_attr(item, "bulk_qlen", page); + mutex_lock(&opts->lock); if (opts->refcnt) { ret = -EBUSY; @@ -1198,6 +1212,8 @@ static ssize_t f_ss_opts_iso_qlen_store(struct config_item *item, int ret; u32 num; + trace_usb_configfs_write_attr(item, "iso_qlen", page); + mutex_lock(&opts->lock); if (opts->refcnt) { ret = -EBUSY; diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c index 6f0e1d8..efbf45f 100644 --- a/drivers/usb/gadget/function/f_uac1.c +++ b/drivers/usb/gadget/function/f_uac1.c @@ -1474,6 +1474,8 @@ static ssize_t f_uac1_opts_##name##_store( \ int ret; \ type num; \ \ + trace_usb_configfs_write_attr(item, #name, page); \ + \ mutex_lock(&opts->lock); \ if (opts->refcnt) { \ ret = -EBUSY; \ @@ -1527,6 +1529,8 @@ static ssize_t f_uac1_opts_##name##_store(struct config_item *item, \ u32 num; \ int i; \ \ + trace_usb_configfs_write_attr(item, #name, page); \ + \ mutex_lock(&opts->lock); \ if (opts->refcnt) { \ ret = -EBUSY; \ @@ -1573,6 +1577,8 @@ static ssize_t f_uac1_opts_##name##_store(struct config_item *item, \ struct f_uac1_opts *opts = to_f_uac1_opts(item); \ int ret = 0; \ \ + trace_usb_configfs_write_attr(item, #name, page); \ + \ mutex_lock(&opts->lock); \ if (opts->refcnt) { \ ret = -EBUSY; \ diff --git a/drivers/usb/gadget/function/f_uac1_legacy.c b/drivers/usb/gadget/function/f_uac1_legacy.c index e2d7f69..a65917b 100644 --- a/drivers/usb/gadget/function/f_uac1_legacy.c +++ b/drivers/usb/gadget/function/f_uac1_legacy.c @@ -837,6 +837,8 @@ static ssize_t f_uac1_opts_##name##_store(struct config_item *item, \ int ret; \ u32 num; \ \ + trace_usb_configfs_write_attr(item, #name, page); \ + \ mutex_lock(&opts->lock); \ if (opts->refcnt) { \ ret = -EBUSY; \ @@ -882,6 +884,8 @@ static ssize_t f_uac1_opts_##name##_store(struct config_item *item, \ int ret = -EBUSY; \ char *tmp; \ \ + trace_usb_configfs_write_attr(item, #name, page); \ + \ mutex_lock(&opts->lock); \ if (opts->refcnt) \ goto end; \ diff --git a/drivers/usb/gadget/function/f_uac2.c b/drivers/usb/gadget/function/f_uac2.c index 1905a8d..1849f3b 100644 --- a/drivers/usb/gadget/function/f_uac2.c +++ b/drivers/usb/gadget/function/f_uac2.c @@ -1886,6 +1886,8 @@ static ssize_t f_uac2_opts_##name##_store(struct config_item *item, \ int ret; \ type num; \ \ + trace_usb_configfs_write_attr(item, #name, page); \ + \ mutex_lock(&opts->lock); \ if (opts->refcnt) { \ ret = -EBUSY; \ @@ -1938,6 +1940,8 @@ static ssize_t f_uac2_opts_##name##_store(struct config_item *item, \ struct f_uac2_opts *opts = to_f_uac2_opts(item); \ int ret = 0; \ \ + trace_usb_configfs_write_attr(item, #name, page); \ + \ mutex_lock(&opts->lock); \ if (opts->refcnt) { \ ret = -EBUSY; \ @@ -1995,6 +1999,8 @@ static ssize_t f_uac2_opts_##name##_store(struct config_item *item, \ u32 num; \ int i; \ \ + trace_usb_configfs_write_attr(item, #name, page); \ + \ mutex_lock(&opts->lock); \ if (opts->refcnt) { \ ret = -EBUSY; \ @@ -2041,6 +2047,8 @@ static ssize_t f_uac2_opts_##name##_store(struct config_item *item, \ struct f_uac2_opts *opts = to_f_uac2_opts(item); \ int ret = 0; \ \ + trace_usb_configfs_write_attr(item, #name, page); \ + \ mutex_lock(&opts->lock); \ if (opts->refcnt) { \ ret = -EBUSY; \ diff --git a/drivers/usb/gadget/function/u_ether_configfs.h b/drivers/usb/gadget/function/u_ether_configfs.h index f558c31..05578be 100644 --- a/drivers/usb/gadget/function/u_ether_configfs.h +++ b/drivers/usb/gadget/function/u_ether_configfs.h @@ -45,6 +45,8 @@ struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ int ret; \ \ + trace_usb_configfs_write_attr(item, "dev_addr", page); \ + \ mutex_lock(&opts->lock); \ if (opts->refcnt) { \ mutex_unlock(&opts->lock); \ @@ -80,6 +82,8 @@ struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ int ret; \ \ + trace_usb_configfs_write_attr(item, "host_addr", page); \ + \ mutex_lock(&opts->lock); \ if (opts->refcnt) { \ mutex_unlock(&opts->lock); \ @@ -115,6 +119,8 @@ u8 val; \ int ret; \ \ + trace_usb_configfs_write_attr(item, "qmult", page); \ + \ mutex_lock(&opts->lock); \ if (opts->refcnt) { \ ret = -EBUSY; \ @@ -154,6 +160,8 @@ out: \ struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ int ret = -EBUSY; \ \ + trace_usb_configfs_write_attr(item, "ifname", page); \ + \ mutex_lock(&opts->lock); \ if (!opts->refcnt) \ ret = gether_set_ifname(opts->net, page, len); \ @@ -185,6 +193,8 @@ out: \ int ret = -EINVAL; \ u8 val; \ \ + trace_usb_configfs_write_attr(item, #_n_, page); \ + \ mutex_lock(&opts->lock); \ if (sscanf(page, "%02hhx", &val) > 0) { \ opts->_n_ = val; \ diff --git a/drivers/usb/gadget/function/uvc_configfs.c b/drivers/usb/gadget/function/uvc_configfs.c index fc139f3..6556e42 100644 --- a/drivers/usb/gadget/function/uvc_configfs.c +++ b/drivers/usb/gadget/function/uvc_configfs.c @@ -172,6 +172,8 @@ uvcg_control_header_##cname##_store(struct config_item *item, \ int ret; \ u##bits num; \ \ + trace_usb_configfs_write_attr(item, #cname, page); \ + \ mutex_lock(su_mutex); /* for navigating configfs hierarchy */ \ \ opts_item = ch->item.ci_parent->ci_parent->ci_parent; \ @@ -1129,6 +1131,8 @@ static ssize_t uvcg_frame_##cname##_store(struct config_item *item, \ typeof(f->frame.cname) num; \ int ret; \ \ + trace_usb_configfs_write_attr(item, #aname, page); \ + \ ret = kstrtou##bits(page, 0, &num); \ if (ret) \ return ret; \ @@ -1288,6 +1292,8 @@ static ssize_t uvcg_frame_dw_frame_interval_store(struct config_item *item, int ret = 0, n = 0; u32 *frm_intrv, *tmp; + trace_usb_configfs_write_attr(item, "dwFrameInterval", page); + mutex_lock(su_mutex); /* for navigating configfs hierarchy */ opts_item = ch->item.ci_parent->ci_parent->ci_parent->ci_parent; @@ -1484,6 +1490,8 @@ static ssize_t uvcg_uncompressed_guid_format_store(struct config_item *item, struct mutex *su_mutex = &ch->fmt.group.cg_subsys->su_mutex; int ret; + trace_usb_configfs_write_attr(item, "guidFormat", page); + mutex_lock(su_mutex); /* for navigating configfs hierarchy */ opts_item = ch->fmt.group.cg_item.ci_parent->ci_parent->ci_parent; @@ -1566,6 +1574,8 @@ uvcg_uncompressed_##cname##_store(struct config_item *item, \ int ret; \ u8 num; \ \ + trace_usb_configfs_write_attr(item, #aname, page); \ + \ mutex_lock(su_mutex); /* for navigating configfs hierarchy */ \ \ opts_item = u->fmt.group.cg_item.ci_parent->ci_parent->ci_parent;\ @@ -1613,6 +1623,8 @@ uvcg_uncompressed_bma_controls_store(struct config_item *item, const char *page, size_t len) { struct uvcg_uncompressed *unc = to_uvcg_uncompressed(item); + + trace_usb_configfs_write_attr(item, "bmaControls", page); return uvcg_format_bma_controls_store(&unc->fmt, page, len); } @@ -1761,6 +1773,8 @@ uvcg_mjpeg_##cname##_store(struct config_item *item, \ int ret; \ u8 num; \ \ + trace_usb_configfs_write_attr(item, #aname, page); \ + \ mutex_lock(su_mutex); /* for navigating configfs hierarchy */ \ \ opts_item = u->fmt.group.cg_item.ci_parent->ci_parent->ci_parent;\ @@ -1808,6 +1822,8 @@ uvcg_mjpeg_bma_controls_store(struct config_item *item, const char *page, size_t len) { struct uvcg_mjpeg *u = to_uvcg_mjpeg(item); + + trace_usb_configfs_write_attr(item, "bmaControls", page); return uvcg_format_bma_controls_store(&u->fmt, page, len); } @@ -2420,6 +2436,8 @@ f_uvc_opts_##cname##_store(struct config_item *item, \ unsigned int num; \ int ret; \ \ + trace_usb_configfs_write_attr(item, #aname, page); \ + \ mutex_lock(&opts->lock); \ if (opts->refcnt) { \ ret = -EBUSY; \ diff --git a/drivers/usb/gadget/trace.c b/drivers/usb/gadget/trace.c index b39bf6f..76f7c41 100644 --- a/drivers/usb/gadget/trace.c +++ b/drivers/usb/gadget/trace.c @@ -129,4 +129,28 @@ void trace_usb_configfs_unlink_group(struct config_item *dest, trace_usb_configfs_link_unlink_group(dest, src, "unlink"); } EXPORT_SYMBOL(trace_usb_configfs_unlink_group); + +void trace_usb_configfs_write_attr(struct config_item *item, + const char *attr, const char *page) +{ + char *info, *group; + int ret; + + info = kzalloc(2 * PAGE_SIZE, GFP_KERNEL); + if (!info) + return; + + group = info + 2 * PAGE_SIZE - GROUP_LEN; + ret = gadget_configfs_group(group, item); + if (ret) { + kfree(info); + return; + } + + snprintf(info, 2 * PAGE_SIZE - GROUP_LEN, + "echo %s/%s %s", group, attr, page); + + trace_gadget_configfs(info); +} +EXPORT_SYMBOL(trace_usb_configfs_write_attr); #endif diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h index df74bd5..5326871 100644 --- a/include/linux/usb/composite.h +++ b/include/linux/usb/composite.h @@ -612,11 +612,14 @@ void trace_usb_configfs_link_group(struct config_item *dest, struct config_item *src); void trace_usb_configfs_unlink_group(struct config_item *dest, struct config_item *src); +void trace_usb_configfs_write_attr(struct config_item *item, + const char *attr, const char *page); #else #define trace_usb_configfs_make_group(parent, item) do {} while(0) #define trace_usb_configfs_drop_group(parent, item) do {} while(0) #define trace_usb_configfs_link_group(dest, src) do {} while(0) #define trace_usb_configfs_unlink_group(dest, src) do {} while(0) +#define trace_usb_configfs_write_attr(item, attr, page) do {} while(0) #endif struct usb_configuration *usb_get_config(struct usb_composite_dev *cdev, diff --git a/include/linux/usb/gadget_configfs.h b/include/linux/usb/gadget_configfs.h index a89f177..2c0663e 100644 --- a/include/linux/usb/gadget_configfs.h +++ b/include/linux/usb/gadget_configfs.h @@ -14,6 +14,8 @@ static ssize_t __struct##_##__name##_store(struct config_item *item, \ struct __struct *gs = to_##__struct(item); \ int ret; \ \ + trace_usb_configfs_write_attr(item, #__name, page); \ + \ ret = usb_string_copy(page, &gs->__name); \ if (ret) \ return ret; \