Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp592018pxj; Thu, 3 Jun 2021 14:25:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYEl5f8Uf929CIwsIu9/06FSdjua6PYyYJ34em4QBa6qCBvYPWezmBF9GnC2houKfi6pgO X-Received: by 2002:aa7:cad4:: with SMTP id l20mr1350252edt.382.1622755515323; Thu, 03 Jun 2021 14:25:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622755515; cv=none; d=google.com; s=arc-20160816; b=Z16T6L0GyHRSA/iM8Yh/tBViIzKfQGoD5QgkeeJc1dZm8CluNxXymMnxfDaqNNqvyD oM1Z+wX/EOiOJuIBFDxusCeYl5BwzrOaK1fSwTl86Hj7cjHkJlfUzVIsABD2Ycx8P6/F lKW5FVnAr7NAuk2DVGJMfPI3lPAne6OqzQWWjXFw5I0MrGyHZkO25HDmct1KOivQRmPz VaDydSsGYKp339t7XBmiphRyEBoA4bFSFvkGlIhSHT2EriZw2cvjIm3oRiDEsryQfq6S r4GIoRWfkhi+KKwmQxRR67N+yBsgR1LL6L2qpWGqG0psHzuI7ZvoMK1Z3wgIT+uKGuWL MXOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=JYZ5h4zcR9XLMiZgqplePv6U7xus5BSDNb9afEynN7g=; b=o/zSCnlvSotGf/bc/3HkvsEDbqFgafJjk3hfcqSh2XEWxnvMLkZKL23puHgT5td5o6 w7sORdXSN85nZJn5qoDGyJMGY+yeechuHNhw/MNABr0gQqa1uqsZ4vFgr3EyCA8mMjhE w4wAZywFcuJj745CKkWpoKdIZTjMZf5w1hcqk0OUbX+6O60Gx1OFEWVJEdG0R/mkfOCX GR6PtHq/GL6zQhP+sAAEmRvTMBFxXu/NcqcVUMmtmthEDB81Fe10ApDZWd2T6c60jsVo P7hmxCiMeIr0fBve7oA4JsBsPflNBpkh7FhyJ9KC43PMOBie0ArWUokSlz6mH/nzYuSp u8sQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z7si3272528edc.522.2021.06.03.14.24.51; Thu, 03 Jun 2021 14:25:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230158AbhFCVYd (ORCPT + 99 others); Thu, 3 Jun 2021 17:24:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:49460 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229924AbhFCVYc (ORCPT ); Thu, 3 Jun 2021 17:24:32 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5B872613FF; Thu, 3 Jun 2021 21:22:46 +0000 (UTC) Date: Thu, 3 Jun 2021 17:22:44 -0400 From: Steven Rostedt To: Daniel Bristot de Oliveira Cc: linux-kernel@vger.kernel.org, Phil Auld , Sebastian Andrzej Siewior , Kate Carcia , Jonathan Corbet , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , Alexandre Chartre , Clark Willaims , John Kacur , Juri Lelli , linux-doc@vger.kernel.org Subject: Re: [PATCH V3 5/9] tracing/trace: Add a generic function to read/write u64 values from tracefs Message-ID: <20210603172244.6d2a6059@gandalf.local.home> In-Reply-To: References: X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 14 May 2021 22:51:14 +0200 Daniel Bristot de Oliveira wrote: > Provides a generic read and write implementation to save/read u64 values > from a file on tracefs. The trace_ull_config structure defines where to > read/write the value, the min and the max acceptable values, and a lock > to protect the write. This states what the patch is doing, but does not say why it is doing it. > > Cc: Jonathan Corbet > Cc: Steven Rostedt > Cc: Ingo Molnar > Cc: Peter Zijlstra > Cc: Thomas Gleixner > Cc: Alexandre Chartre > Cc: Clark Willaims > Cc: John Kacur > Cc: Juri Lelli > Cc: linux-doc@vger.kernel.org > Cc: linux-kernel@vger.kernel.org > Signed-off-by: Daniel Bristot de Oliveira > --- > kernel/trace/trace.c | 87 ++++++++++++++++++++++++++++++++++++++++++++ > kernel/trace/trace.h | 19 ++++++++++ > 2 files changed, 106 insertions(+) > > diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c > index 560e4c8d3825..b4cd89010813 100644 > --- a/kernel/trace/trace.c > +++ b/kernel/trace/trace.c > @@ -7516,6 +7516,93 @@ static const struct file_operations snapshot_raw_fops = { > > #endif /* CONFIG_TRACER_SNAPSHOT */ > > +/* > + * trace_ull_config_write - Generic write function to save u64 value That is a horrible name. What the hell is the "config"? > + * @filp: The active open file structure > + * @ubuf: The userspace provided buffer to read value into > + * @cnt: The maximum number of bytes to read > + * @ppos: The current "file" position > + * > + * This function provides a generic write implementation to save u64 values > + * from a file on tracefs. The filp->private_data must point to a > + * trace_ull_config structure that defines where to write the value, the > + * min and the max acceptable values, and a lock to protect the write. This doesn't seem to be a generic way to save 64 bit values (which I still don't understand, because unsigned long long should work too). But it looks like the rational is for having some kind of generic way to read 64 bit values giving them a min and a max. I see this is used later, but this patch needs to be rewritten. It makes no sense. -- Steve > + */ > +static ssize_t > +trace_ull_config_write(struct file *filp, const char __user *ubuf, size_t cnt, > + loff_t *ppos) > +{ > + struct trace_ull_config *config = filp->private_data; > + u64 val; > + int err; > + > + if (!config) > + return -EFAULT; > + > + err = kstrtoull_from_user(ubuf, cnt, 10, &val); > + if (err) > + return err; > + > + if (config->lock) > + mutex_lock(config->lock); > + > + if (config->min && val < *config->min) > + err = -EINVAL; > + > + if (config->max && val > *config->max) > + err = -EINVAL; > + > + if (!err) > + *config->val = val; > + > + if (config->lock) > + mutex_unlock(config->lock); > + > + if (err) > + return err; > + > + return cnt; > +} > + > +/* > + * trace_ull_config_read - Generic write function to read u64 value via tracefs > + * @filp: The active open file structure > + * @ubuf: The userspace provided buffer to read value into > + * @cnt: The maximum number of bytes to read > + * @ppos: The current "file" position > + * > + * This function provides a generic read implementation to read a u64 value > + * from a file on tracefs. The filp->private_data must point to a > + * trace_ull_config structure with valid data. > + */ > +static ssize_t > +trace_ull_config_read(struct file *filp, char __user *ubuf, size_t cnt, > + loff_t *ppos) > +{ > + struct trace_ull_config *config = filp->private_data; > + char buf[ULL_STR_SIZE]; > + u64 val; > + int len; > + > + if (!config) > + return -EFAULT; > + > + val = *config->val; > + > + if (cnt > sizeof(buf)) > + cnt = sizeof(buf); > + > + len = snprintf(buf, sizeof(buf), "%llu\n", val); > + > + return simple_read_from_buffer(ubuf, cnt, ppos, buf, len); > +} > + > +const struct file_operations trace_ull_config_fops = { > + .open = tracing_open_generic, > + .read = trace_ull_config_read, > + .write = trace_ull_config_write, > +}; > + > #define TRACING_LOG_ERRS_MAX 8 > #define TRACING_LOG_LOC_MAX 128 > > diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h > index cd80d046c7a5..44fa25c1264a 100644 > --- a/kernel/trace/trace.h > +++ b/kernel/trace/trace.h > @@ -1952,4 +1952,23 @@ static inline bool is_good_name(const char *name) > return true; > } > > +/* > + * This is a generic way to read and write a u64 config value from a file > + * in tracefs. > + * > + * The value is stored on the variable pointed by *val. The value needs > + * to be at least *min and at most *max. The write is protected by an > + * existing *lock. > + */ > +struct trace_ull_config { > + struct mutex *lock; > + u64 *val; > + u64 *min; > + u64 *max; > +}; > + > +#define ULL_STR_SIZE 22 /* 20 digits max */ > + > +extern const struct file_operations trace_ull_config_fops; > + > #endif /* _LINUX_KERNEL_TRACE_H */