From patchwork Sun Mar 20 04:35:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linyu Yuan X-Patchwork-Id: 12786411 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 579D1C433F5 for ; Sun, 20 Mar 2022 04:35:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244699AbiCTEgm (ORCPT ); Sun, 20 Mar 2022 00:36:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235846AbiCTEgi (ORCPT ); Sun, 20 Mar 2022 00:36:38 -0400 Received: from alexa-out.qualcomm.com (alexa-out.qualcomm.com [129.46.98.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99D7AE0A3 for ; Sat, 19 Mar 2022 21:35:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1647750914; x=1679286914; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qlJGwixuBamASEt+ES5RBWBibSXNH3GVmGQuEGVYlr4=; b=jVEXA8zayupfwzED6R4RQA/wDDnZQBm18m44eJ/B8p+s9H5ax8Pogn5G KcSklaJCHfatIPak6toqG3burTvqESuVdTGwgTA0dV1+ajkroLraDRG9N 6YdC0A/iCEwvdWcKci0+Dcs7G3JgHml3kHFYqxg0Hh/y7OYFJ+Fv0/p9s w=; Received: from ironmsg07-lv.qualcomm.com ([10.47.202.151]) by alexa-out.qualcomm.com with ESMTP; 19 Mar 2022 21:35:13 -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; 19 Mar 2022 21:35:13 -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; Sat, 19 Mar 2022 21:35:13 -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; Sat, 19 Mar 2022 21:35:11 -0700 From: Linyu Yuan To: Greg Kroah-Hartman CC: , Jack Pham , "Linyu Yuan" Subject: [PATCH 1/4] usb: gadget: add trace event of configfs operation Date: Sun, 20 Mar 2022 12:35:01 +0800 Message-ID: <1647750904-6524-2-git-send-email-quic_linyyuan@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1647750904-6524-1-git-send-email-quic_linyyuan@quicinc.com> References: <1647750904-6524-1-git-send-email-quic_linyyuan@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) 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, the following patch will add global function base on it to allow usb gadget and function layer use them, it will cover all user input like make configfs group/item, drop item, write attribute, allow/drop link. Signed-off-by: Linyu Yuan --- drivers/usb/gadget/Makefile | 1 + drivers/usb/gadget/configfs.c | 3 +++ drivers/usb/gadget/trace.h | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 drivers/usb/gadget/trace.h diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index 33f1ef9..e072a11 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile @@ -5,6 +5,7 @@ subdir-ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG subdir-ccflags-$(CONFIG_USB_GADGET_VERBOSE) += -DVERBOSE_DEBUG +CFLAGS_configfs.o := -I$(src) 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 diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index 1fb837d..f35a226 100644 --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c @@ -123,6 +123,9 @@ static int usb_string_copy(const char *s, char **s_copy) return 0; } +#define CREATE_TRACE_POINTS +#include "trace.h" + #define GI_DEVICE_DESC_SIMPLE_R_u8(__name) \ static ssize_t gadget_dev_desc_##__name##_show(struct config_item *item, \ char *page) \ 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 Sun Mar 20 04:35:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linyu Yuan X-Patchwork-Id: 12786413 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 85F07C433FE for ; Sun, 20 Mar 2022 04:35:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244703AbiCTEgn (ORCPT ); Sun, 20 Mar 2022 00:36:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244696AbiCTEgi (ORCPT ); Sun, 20 Mar 2022 00:36:38 -0400 Received: from alexa-out-sd-02.qualcomm.com (alexa-out-sd-02.qualcomm.com [199.106.114.39]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B853113E3A for ; Sat, 19 Mar 2022 21:35:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1647750915; x=1679286915; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5THFDHVrFdjakTnkLRoEPwbHIiD2c8eFREUGLOz+adY=; b=ET2lqQeFWGPhNqVA5K0EEcWexqj9f3Wfv7DezMxr3iq5c3iZTiWON/bm GU80Bse5A38DJjOpa4Z7GvNXJP8u/T/3QyttMUP9gOzfPSpPPsyCRrJIJ iLRU7yyMvQQHX5pEZKuCFp6NOyf04PaLdK2AnmTAY+js/6qW/ALaZWq6q I=; Received: from unknown (HELO ironmsg04-sd.qualcomm.com) ([10.53.140.144]) by alexa-out-sd-02.qualcomm.com with ESMTP; 19 Mar 2022 21:35:15 -0700 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg04-sd.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Mar 2022 21:35:15 -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; Sat, 19 Mar 2022 21:35:14 -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; Sat, 19 Mar 2022 21:35:13 -0700 From: Linyu Yuan To: Greg Kroah-Hartman CC: , Jack Pham , "Linyu Yuan" Subject: [PATCH 2/4] usb: gadget: add trace event of configfs group operation Date: Sun, 20 Mar 2022 12:35:02 +0800 Message-ID: <1647750904-6524-3-git-send-email-quic_linyyuan@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1647750904-6524-1-git-send-email-quic_linyyuan@quicinc.com> References: <1647750904-6524-1-git-send-email-quic_linyyuan@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) 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 gadget/function/configuration... groups, it also trace group create in a specific function. Signed-off-by: Linyu Yuan --- drivers/usb/gadget/configfs.c | 88 ++++++++++++++++++++++++++++ drivers/usb/gadget/function/f_mass_storage.c | 4 ++ drivers/usb/gadget/function/uvc_configfs.c | 12 ++++ include/linux/usb/composite.h | 9 +++ include/linux/usb/gadget_configfs.h | 2 + 5 files changed, 115 insertions(+) diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index f35a226..be9e70a 100644 --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c @@ -624,6 +624,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); @@ -637,6 +639,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); @@ -732,6 +736,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); @@ -743,6 +748,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); } @@ -1086,6 +1092,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) { @@ -1110,6 +1117,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); @@ -1629,6 +1638,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); @@ -1637,6 +1647,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); } @@ -1670,6 +1681,83 @@ void unregister_gadget_item(struct config_item *item) } EXPORT_SYMBOL_GPL(unregister_gadget_item); +#ifdef CONFIG_TRACEPOINTS +#define GROUP_LEN 128 +static int gadget_configfs_group(char *group, struct config_item *item) +{ + char *tmpgroup = kzalloc(GROUP_LEN, GFP_KERNEL); + + if (!tmpgroup) + return -1; + + for (;;) { + 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); + + item = item->ci_parent; + if (item->ci_type == &gadgets_type) { + kfree(tmpgroup); + return 0; + } + + strcpy(tmpgroup, group); + } + + return 0; +} + +static void trace_usb_configfs_make_drop_group(struct config_item *pitem, + struct config_item *item, char *make_drop) +{ + char *group = kzalloc(2 * GROUP_LEN, GFP_KERNEL); + char *tmpgroup; + int ret; + + if (!group) + goto out; + + tmpgroup = group + GROUP_LEN; + ret = gadget_configfs_group(tmpgroup, pitem); + if (ret) + goto out; + + if (tmpgroup[0] == '\0') + snprintf(group, GROUP_LEN, "%s %s", make_drop, + config_item_name(item)); + else + snprintf(group, GROUP_LEN, "%s %s/%s", make_drop, tmpgroup, + config_item_name(item)); + + trace_gadget_configfs(group); + +out: + kfree(group); +} + +void trace_usb_configfs_make_group(struct config_item *pitem, + struct config_item *item) +{ + trace_usb_configfs_make_drop_group(pitem, item, "mkdir"); +} +EXPORT_SYMBOL(trace_usb_configfs_make_group); + +void trace_usb_configfs_drop_group(struct config_item *pitem, + struct config_item *item) +{ + trace_usb_configfs_make_drop_group(pitem, item, "rmdir"); +} +EXPORT_SYMBOL(trace_usb_configfs_drop_group); +#endif + static int __init gadget_cfs_init(void) { int ret; diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c index ba899ca..8bf1f37 100644 --- a/drivers/usb/gadget/function/f_mass_storage.c +++ b/drivers/usb/gadget/function/f_mass_storage.c @@ -3288,6 +3288,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); @@ -3299,6 +3301,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/include/linux/usb/composite.h b/include/linux/usb/composite.h index 9d27622..611029d 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 *pitem, + struct config_item *item); +void trace_usb_configfs_drop_group(struct config_item *pitem, + struct config_item *item); +#else +#define trace_usb_configfs_make_group(pitem, item) do {} while(0) +#define trace_usb_configfs_drop_group(pitem, 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 Sun Mar 20 04:35:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linyu Yuan X-Patchwork-Id: 12786412 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 6768FC433EF for ; Sun, 20 Mar 2022 04:35:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244700AbiCTEgn (ORCPT ); Sun, 20 Mar 2022 00:36:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244697AbiCTEgj (ORCPT ); Sun, 20 Mar 2022 00:36:39 -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 70FFB47AE3 for ; Sat, 19 Mar 2022 21:35:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1647750917; x=1679286917; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WIkUobeuKjo9dCJeepOW7jT+K9eFKjzOT9xmxgseI/Y=; b=qLlwtg3J8iCArpd7IcTOWMGjaNMvHAvcVwvTzEp1WUnpByJJxberoC1p 9cCQBz0MkYZwiPk8My/MzZQDKnYuhqcbd7WTw9xbFsCLu5KmkBu6/1iwp /GkSxlHlJ9ptWykxb6aMk2lbLv+93eb6UPguDd943R1rbuE9IjXPN9sY1 8=; Received: from unknown (HELO ironmsg01-sd.qualcomm.com) ([10.53.140.141]) by alexa-out-sd-01.qualcomm.com with ESMTP; 19 Mar 2022 21:35:17 -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; 19 Mar 2022 21:35:16 -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; Sat, 19 Mar 2022 21:35:16 -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; Sat, 19 Mar 2022 21:35:14 -0700 From: Linyu Yuan To: Greg Kroah-Hartman CC: , Jack Pham , "Linyu Yuan" Subject: [PATCH 3/4] usb: gadget: add trace event of configfs link/unlink operation Date: Sun, 20 Mar 2022 12:35:03 +0800 Message-ID: <1647750904-6524-4-git-send-email-quic_linyyuan@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1647750904-6524-1-git-send-email-quic_linyyuan@quicinc.com> References: <1647750904-6524-1-git-send-email-quic_linyyuan@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) 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 function to gadget configuration, if a specific function need link/unlink, it also can be used. Signed-off-by: Linyu Yuan --- drivers/usb/gadget/configfs.c | 50 ++++++++++++++++++++++++++++++ drivers/usb/gadget/function/uvc_configfs.c | 12 +++++++ include/linux/usb/composite.h | 6 ++++ 3 files changed, 68 insertions(+) diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index be9e70a..0f85290 100644 --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c @@ -425,6 +425,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 @@ -474,6 +476,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 @@ -896,6 +900,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) @@ -927,6 +933,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); @@ -1756,6 +1764,48 @@ void trace_usb_configfs_drop_group(struct config_item *pitem, trace_usb_configfs_make_drop_group(pitem, 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 = kzalloc(4 * GROUP_LEN, GFP_KERNEL); + char *group1, *group2; + int ret; + + if (!group) + goto out; + + group1 = group + 2 * GROUP_LEN; + ret = gadget_configfs_group(group1, dest); + if (ret) + goto out; + + group2 = group + 3 * GROUP_LEN; + ret = gadget_configfs_group(group2, src); + if (ret) + goto out; + + snprintf(group, 2 * GROUP_LEN, "%s %s %s", link_unlink, group1, group2); + + trace_gadget_configfs(group); + +out: + kfree(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 static int __init gadget_cfs_init(void) 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/include/linux/usb/composite.h b/include/linux/usb/composite.h index 611029d..a90e626 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 *pitem, struct config_item *item); void trace_usb_configfs_drop_group(struct config_item *pitem, struct config_item *item); +void trace_usb_configfs_link_group(struct config_item *pitem, + struct config_item *item); +void trace_usb_configfs_unlink_group(struct config_item *pitem, + struct config_item *item); #else #define trace_usb_configfs_make_group(pitem, item) do {} while(0) #define trace_usb_configfs_drop_group(pitem, item) do {} while(0) +#define trace_usb_configfs_link_group(pitem, item) do {} while(0) +#define trace_usb_configfs_unlink_group(pitem, item) do {} while(0) #endif struct usb_configuration *usb_get_config(struct usb_composite_dev *cdev, From patchwork Sun Mar 20 04:35:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linyu Yuan X-Patchwork-Id: 12786414 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 867A5C433EF for ; Sun, 20 Mar 2022 04:35:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244697AbiCTEgo (ORCPT ); Sun, 20 Mar 2022 00:36:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244704AbiCTEgn (ORCPT ); Sun, 20 Mar 2022 00:36:43 -0400 Received: from alexa-out.qualcomm.com (alexa-out.qualcomm.com [129.46.98.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F438488B7 for ; Sat, 19 Mar 2022 21:35:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1647750918; x=1679286918; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JrZ2nii7nVu9Bc6KwXuyOVbX4empWBto7na5Rp+3JM8=; b=wQjJ2AxnA98TW9eBWrxAPvBvc0rtDet4//+hi9Ce/x0eWhXre3hsCvDm +CqfXbdZLuUfZDGRnYoam7GjIOwfOM+qNaACLlYJ6itaPEuTRzuF5q9rj Wct4rrTEPeLmtASGMjofrWYSfjeuCaya9ByrJCqWebi7UN4BowcKaqXVL 0=; Received: from ironmsg07-lv.qualcomm.com ([10.47.202.151]) by alexa-out.qualcomm.com with ESMTP; 19 Mar 2022 21:35:18 -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; 19 Mar 2022 21:35:18 -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; Sat, 19 Mar 2022 21:35:18 -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; Sat, 19 Mar 2022 21:35:16 -0700 From: Linyu Yuan To: Greg Kroah-Hartman CC: , Jack Pham , "Linyu Yuan" Subject: [PATCH 4/4] usb: gadget: add trace event of configfs write attributes operation Date: Sun, 20 Mar 2022 12:35:04 +0800 Message-ID: <1647750904-6524-5-git-send-email-quic_linyyuan@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1647750904-6524-1-git-send-email-quic_linyyuan@quicinc.com> References: <1647750904-6524-1-git-send-email-quic_linyyuan@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) 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 --- drivers/usb/gadget/configfs.c | 47 ++++++++++++++++++++++++++ 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 ++++++++++ include/linux/usb/composite.h | 3 ++ include/linux/usb/gadget_configfs.h | 2 ++ 16 files changed, 150 insertions(+) diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index 0f85290..c35ad0a 100644 --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c @@ -149,6 +149,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; \ @@ -162,6 +164,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; \ @@ -201,6 +205,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; @@ -218,6 +224,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; @@ -265,6 +273,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; @@ -314,6 +324,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 */ @@ -522,6 +534,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; @@ -545,6 +560,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; @@ -812,6 +830,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) { @@ -836,6 +856,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) { @@ -865,6 +887,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; @@ -1806,6 +1830,29 @@ 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 = kzalloc(2 * PAGE_SIZE, GFP_KERNEL); + char *group = kzalloc(GROUP_LEN, GFP_KERNEL); + int ret; + + if (!info || !group) + goto out; + + ret = gadget_configfs_group(group, item); + if (ret) + goto out; + + snprintf(info, 2 * PAGE_SIZE, "echo %s/%s %s", group, attr, page); + + trace_gadget_configfs(info); + +out: + kfree(info); +} +EXPORT_SYMBOL(trace_usb_configfs_write_attr); #endif static int __init gadget_cfs_init(void) 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 8bf1f37..edece4f 100644 --- a/drivers/usb/gadget/function/f_mass_storage.c +++ b/drivers/usb/gadget/function/f_mass_storage.c @@ -3140,6 +3140,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); } @@ -3156,6 +3158,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); } @@ -3170,6 +3174,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); } @@ -3186,6 +3192,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); } @@ -3200,6 +3208,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); } @@ -3214,6 +3224,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); } @@ -3352,6 +3364,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) { @@ -3392,6 +3406,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/include/linux/usb/composite.h b/include/linux/usb/composite.h index a90e626..491e693 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 *pitem, struct config_item *item); void trace_usb_configfs_unlink_group(struct config_item *pitem, struct config_item *item); +void trace_usb_configfs_write_attr(struct config_item *item, + const char *attr, const char *page); #else #define trace_usb_configfs_make_group(pitem, item) do {} while(0) #define trace_usb_configfs_drop_group(pitem, item) do {} while(0) #define trace_usb_configfs_link_group(pitem, item) do {} while(0) #define trace_usb_configfs_unlink_group(pitem, item) 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; \