From: Greg KH <gregkh@linuxfoundation.org>
To: speck@linutronix.de
Subject: [MODERATED] Re: [PATCH v4 04/10] TAAv4 4
Date: Fri, 27 Sep 2019 09:01:53 +0200 [thread overview]
Message-ID: <20190927070153.GA1790199@kroah.com> (raw)
In-Reply-To: <20190924232503.GE2473@guptapadev.amr>
On Tue, Sep 24, 2019 at 04:25:03PM -0700, speck for Pawan Gupta wrote:
> On Tue, Sep 24, 2019 at 07:04:59AM +0200, speck for Greg KH wrote:
> > Either way, my original comment of "do not use sysfs_create_group() when
> > you have a 'struct device'" still stands, that needs to be fixed up no
> > matter what here.
>
> Thanks for your inputs. As we have the 'struct device' are you
> suggesting to use device_create_file()?
You should never use sysfs_create_file() if you have a 'struct device'
so yes, that's at least one thing that needs to be fixed.
> Approach 1 - sysfs_create_file() => device_create_file()
>
> -----------------
> diff --git a/arch/x86/kernel/cpu/tsx.c b/arch/x86/kernel/cpu/tsx.c
> index 40fec8ab82b1..4799c081198c 100644
> --- a/arch/x86/kernel/cpu/tsx.c
> +++ b/arch/x86/kernel/cpu/tsx.c
> @@ -162,7 +162,7 @@ static void tsx_update_on_each_cpu(bool val)
> put_online_cpus();
> }
>
> -static ssize_t tsx_show(struct device *cdev,
> +static ssize_t htm_show(struct device *cdev,
> struct device_attribute *attr,
> char *buf)
> {
> @@ -171,7 +171,7 @@ static ssize_t tsx_show(struct device *cdev,
>
> static DEFINE_MUTEX(tsx_mutex);
>
> -static ssize_t tsx_store(struct device *cdev,
> +static ssize_t htm_store(struct device *cdev,
> struct device_attribute *attr,
> const char *buf, size_t count)
> {
> @@ -197,15 +197,14 @@ static ssize_t tsx_store(struct device *cdev,
> return count;
> }
>
> -static DEVICE_ATTR_RW(tsx);
> +static const DEVICE_ATTR_RW(htm);
>
> static int __init tsx_sysfs_init(void)
> {
> if (tsx_ctrl_state == TSX_CTRL_NOT_SUPPORTED)
> return -ENODEV;
>
> - return sysfs_create_file(&cpu_subsys.dev_root->kobj,
> - &dev_attr_tsx.attr);
> + return device_create_file(cpu_subsys.dev_root, &dev_attr_htm);
> }
>
> -late_initcall(tsx_sysfs_init);
> +device_initcall(tsx_sysfs_init);
You are renaming the file here too, but that's fine, it's not my file :)
> -------------------------------------------------------------------
>
> If the first approach is not what you are expecting, is the below
> patch to add the attribute to the cpu_root_attrs list okay?
>
> Approach 2 - Add tsx attribute to cpu_root_attrs in drivers/base/cpu.c
>
> --------------------
> diff --git a/arch/x86/kernel/cpu/tsx.c b/arch/x86/kernel/cpu/tsx.c
> index da75021daa1d..631996e129d5 100644
> --- a/arch/x86/kernel/cpu/tsx.c
> +++ b/arch/x86/kernel/cpu/tsx.c
> @@ -158,17 +158,15 @@ static void tsx_update_on_each_cpu(bool val)
> put_online_cpus();
> }
>
> -static ssize_t tsx_show(struct device *cdev,
> - struct device_attribute *attr,
> - char *buf)
> +ssize_t htm_show(struct device *dev, struct device_attribute *attr, char *buf)
> {
> return sprintf(buf, "%d\n", tsx_ctrl_state == TSX_CTRL_ENABLE ? 1 : 0);
> }
>
> static DEFINE_MUTEX(tsx_mutex);
>
> -static ssize_t tsx_store(struct device *cdev, struct device_attribute *attr,
> - const char *buf, size_t count)
> +ssize_t htm_store(struct device *dev, struct device_attribute *attr,
> + const char *buf, size_t count)
> {
> enum tsx_ctrl_states requested_state;
> ssize_t ret;
> @@ -229,32 +227,10 @@ static ssize_t tsx_store(struct device *cdev, struct device_attribute *attr,
> return count;
> }
>
> -static DEVICE_ATTR_RW(tsx);
> -
> -static struct attribute *tsx_ctrl_attrs[] = {
> - &dev_attr_tsx.attr,
> - NULL
> -};
> -
> -static umode_t tsx_ctrl_attr_is_visible(struct kobject *kobj,
> - struct attribute *attr, int index)
> +umode_t htm_is_visible(void)
> {
> - if ((attr == &dev_attr_tsx.attr) &&
> - (tsx_ctrl_state == TSX_CTRL_NOT_SUPPORTED))
> + if (tsx_ctrl_state == TSX_CTRL_NOT_SUPPORTED)
> return 0;
>
> - return attr->mode;
> + return 0644;
> }
> -
> -static struct attribute_group tsx_ctrl_attr_group = {
> - .attrs = tsx_ctrl_attrs,
> - .is_visible = tsx_ctrl_attr_is_visible,
> -};
> -
> -static int __init tsx_sysfs_init(void)
> -{
> - return sysfs_create_group(&cpu_subsys.dev_root->kobj,
> - &tsx_ctrl_attr_group);
> -}
> -
> -late_initcall(tsx_sysfs_init);
> diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
> index 80d43ff9a7ec..2b1579c7f22d 100644
> --- a/drivers/base/cpu.c
> +++ b/drivers/base/cpu.c
> @@ -460,6 +460,34 @@ struct device *cpu_device_create(struct device *parent, void *drvdata,
> }
> EXPORT_SYMBOL_GPL(cpu_device_create);
>
> +ssize_t __weak htm_show(struct device *dev, struct device_attribute *attr,
> + char *buf)
> +{
> + return -ENODEV;
> +}
> +
> +ssize_t __weak htm_store(struct device *dev, struct device_attribute *attr,
> + const char *buf, size_t count)
> +{
> + return -ENODEV;
> +}
> +
> +DEVICE_ATTR_RW(htm);
> +
> +umode_t __weak htm_is_visible(void)
> +{
> + return 0;
> +}
> +
> +static umode_t cpu_root_attrs_is_visible(struct kobject *kobj,
> + struct attribute *attr, int index)
> +{
> + if (attr == &dev_attr_htm.attr)
> + return htm_is_visible();
> +
> + return attr->mode;
> +}
> +
> #ifdef CONFIG_GENERIC_CPU_AUTOPROBE
> static DEVICE_ATTR(modalias, 0444, print_cpu_modalias, NULL);
> #endif
> @@ -481,11 +509,13 @@ static struct attribute *cpu_root_attrs[] = {
> #ifdef CONFIG_GENERIC_CPU_AUTOPROBE
> &dev_attr_modalias.attr,
> #endif
> + &dev_attr_htm.attr,
> NULL
> };
>
> static struct attribute_group cpu_root_attr_group = {
> - .attrs = cpu_root_attrs,
> + .attrs = cpu_root_attrs,
> + .is_visible = cpu_root_attrs_is_visible,
> };
>
> static const struct attribute_group *cpu_root_attr_groups[] = {
I like this second one a _lot_ better. You are creating the file at the
correct time, in the correct location, and handling if you should expose
the file or not to userspace correctly. Nice work!
thanks,
greg k-h
next prev parent reply other threads:[~2019-09-27 7:02 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1567543894.git.pawan.kumar.gupta@linux.intel.com>
2019-09-23 12:47 ` [MODERATED] Re: [PATCH v4 01/10] TAAv4 1 Borislav Petkov
[not found] ` <20190904060028.GD7212@kroah.com>
[not found] ` <20190906072835.GD13480@guptapadev.amr>
[not found] ` <20190906092727.GA16843@kroah.com>
[not found] ` <20190910184223.GA7543@guptapadev.amr>
[not found] ` <20190910223334.GA21301@kroah.com>
[not found] ` <20190910233449.GA10041@agluck-desk2.amr.corp.intel.com>
2019-09-23 19:10 ` [MODERATED] Re: [PATCH v4 04/10] TAAv4 4 Greg KH
[not found] ` <20190911023223.GA8305@guptapadev.amr>
2019-09-23 19:13 ` Greg KH
2019-09-23 22:25 ` Pawan Gupta
2019-09-24 5:04 ` Greg KH
2019-09-24 10:48 ` Jiri Kosina
2019-09-24 13:31 ` Greg KH
2019-09-24 13:38 ` Jiri Kosina
2019-09-24 13:47 ` Greg KH
2019-09-24 23:25 ` Pawan Gupta
2019-09-27 7:01 ` Greg KH [this message]
2019-09-25 21:10 ` [MODERATED] Re: [PATCH v4 06/10] TAAv4 6 Kanth Ghatraju
2019-09-25 21:11 ` [MODERATED] [AUTOREPLY] [AUTOREPLY] Automatic reply: " Hatle, Mark
2019-09-26 1:15 ` [MODERATED] " Pawan Gupta
[not found] ` <20190904055711.GC7212@kroah.com>
[not found] ` <nycvar.YFH.7.76.1909040759580.31470@cbobk.fhfr.pm>
[not found] ` <20190904061155.GI7212@kroah.com>
[not found] ` <20190904075846.GD1321@guptapadev.amr>
[not found] ` <20190904084306.GA4925@kroah.com>
[not found] ` <20190904112758.GP3838@dhcp22.suse.cz>
2019-09-25 22:05 ` [MODERATED] Re: ***UNCHECKED*** Re: [PATCH v4 03/10] TAAv4 3 Josh Poimboeuf
2019-10-01 0:20 ` [MODERATED] " Pawan Gupta
2019-10-02 14:55 ` Borislav Petkov
2019-10-05 5:16 ` Pawan Gupta
2019-10-08 2:59 ` Josh Poimboeuf
2019-10-08 6:15 ` Pawan Gupta
2019-10-08 18:06 ` Dave Hansen
2019-10-08 18:36 ` [MODERATED] Re: ***UNCHECKED*** " Jiri Kosina
[not found] ` <20190904055406.GA7212@kroah.com>
[not found] ` <20190904074326.GB1321@guptapadev.amr>
[not found] ` <bfe6f7e0-22db-ce4d-ac3a-875482b43489@intel.com>
2019-09-25 22:13 ` [MODERATED] Re: [PATCH v4 02/10] TAAv4 2 Josh Poimboeuf
2019-09-26 0:46 ` Pawan Gupta
2019-09-25 22:30 ` Josh Poimboeuf
2019-09-30 23:26 ` Pawan Gupta
2019-09-30 23:32 ` [MODERATED] [AUTOREPLY] [MODERATED] [AUTOREPLY] Automatic reply: " James, Hengameh M
[not found] ` <5b6df5ee-a5b7-c281-de29-af6544b8abb6@intel.com>
[not found] ` <20190906074645.GE13480@guptapadev.amr>
2019-09-25 22:48 ` [MODERATED] Re: [PATCH v4 03/10] TAAv4 3 Josh Poimboeuf
2019-09-25 23:12 ` Dave Hansen
2019-09-25 23:22 ` Andrew Cooper
2019-09-26 1:13 ` Pawan Gupta
2019-09-26 2:34 ` Josh Poimboeuf
2019-09-26 7:15 ` Pawan Gupta
2019-09-26 13:54 ` Josh Poimboeuf
2019-09-26 17:57 ` Pawan Gupta
[not found] ` <d6fd9ad7-79f7-aab9-db31-a9a2ca03aa10@intel.com>
[not found] ` <20190906080828.GF13480@guptapadev.amr>
[not found] ` <00170736-0d97-4a48-2141-ffba4bb67199@intel.com>
2019-09-25 22:58 ` [MODERATED] Re: [PATCH v4 04/10] TAAv4 4 Josh Poimboeuf
2019-09-26 0:48 ` Pawan Gupta
2019-09-25 23:06 ` [MODERATED] Re: [PATCH v4 06/10] TAAv4 6 Josh Poimboeuf
2019-09-30 23:00 ` Pawan Gupta
2019-10-01 18:26 ` [MODERATED] Re: [PATCH v4 05/10] TAAv4 5 Pawan Gupta
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190927070153.GA1790199@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=speck@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.