lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 4 Mar 2022 12:42:45 -0800
From:   "Joseph, Jithu" <jithu.joseph@...el.com>
To:     "Williams, Dan J" <dan.j.williams@...el.com>,
        "hdegoede@...hat.com" <hdegoede@...hat.com>,
        "markgross@...nel.org" <markgross@...nel.org>
CC:     "corbet@....net" <corbet@....net>,
        "Raj, Ashok" <ashok.raj@...el.com>,
        "Luck, Tony" <tony.luck@...el.com>,
        "dave.hansen@...ux.intel.com" <dave.hansen@...ux.intel.com>,
        "patches@...ts.linux.dev" <patches@...ts.linux.dev>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "mingo@...hat.com" <mingo@...hat.com>,
        "rostedt@...dmis.org" <rostedt@...dmis.org>,
        "Shankar, Ravi V" <ravi.v.shankar@...el.com>,
        "tglx@...utronix.de" <tglx@...utronix.de>,
        "platform-driver-x86@...r.kernel.org" 
        <platform-driver-x86@...r.kernel.org>,
        "linux-doc@...r.kernel.org" <linux-doc@...r.kernel.org>,
        "hpa@...or.com" <hpa@...or.com>, "bp@...en8.de" <bp@...en8.de>,
        "gregkh@...uxfoundation.org" <gregkh@...uxfoundation.org>,
        "andriy.shevchenko@...ux.intel.com" 
        <andriy.shevchenko@...ux.intel.com>,
        "x86@...nel.org" <x86@...nel.org>
Subject: Re: [RFC 08/10] platform/x86/intel/ifs: Add IFS sysfs interface



On 3/3/2022 4:31 PM, Williams, Dan J wrote:
> On Tue, 2022-03-01 at 11:54 -0800, Jithu Joseph wrote:
>> Implement sysfs interface to trigger ifs test for a targeted core or
>> all cores. For all core testing, the kernel will start testing from core 0
>> and proceed to the next core one after another. After the ifs test on the
>> last core, the test stops until the administrator starts another round of

>> +
>> +/*
>> + * The sysfs interface to check the test status:
>> + * To check the result, for example, cpu0
>> + * cat /sys/devices/system/cpu/cpu0/ifs/details
>> + */
>> +static ssize_t details_show(struct device *dev,
>> +                           struct device_attribute *attr,
>> +                           char *buf)
>> +{
>> +       unsigned int cpu = dev->id;
>> +       int ret;
>> +
>> +       if (down_trylock(&ifs_sem))
>> +               return -EBUSY;
> 
> What is the ifs_sem protecting? This result is immediately invalid
> after the lock is dropped anyway, so why hold it over reading the
> value? You can't prevent 2 threads racing each other here.

percpu thread running scan_test_worker() will update per_cpu(ifs_state, cpu).scan_details. (before signalling this thread to run, this lock would be acquired)
This is to protect against the scenario where if the percpu thread is running a test and if at the same time a user is querying its status, they would see busy.

> 
>> +
>> +       ret = sprintf(buf, "%llx\n", per_cpu(ifs_state, cpu).scan_details);
> 
> Should be sysfs_emit() which includes the page buffer safety.

grep KH also pointed this out ... will replace this throughout

> 
> Also, you likely want that format string to be %#llx so that userspace
> knows explicitly that this is a hexadecimal value.

Agreed will do this


>> +
>> +/*
>> + * The sysfs interface for single core testing
>> + * To start test, for example, cpu0
>> + * echo 1 > /sys/devices/system/cpu/cpu0/ifs/run_test
>> + * To check the result:
>> + * cat /sys/devices/system/cpu/cpu0/ifs/result
(there is a typo in the comment result -> status)
> 
> Just have a CPU mask as an input parameter and avoid needing to hang
> ifs sysfs attributes underneath /sys/device/system/cpu/ifs.

The percpu sysfs has the additional function of providing percpu status and  details. 
The global interface is unable to provide the status and details for all the cores in the system. It does give a summary, which
guides the user to the appropriate percpu status/details

 
>> + */
>> +static ssize_t allcpu_run_test_store(struct device *dev,
>> +                                    struct device_attribute *attr,
>> +                                    const char *buf, size_t count)
>> +{
>> +       bool var;
>> +       int rc;
>> +
>> +       if (ifs_disabled)
>> +               return -ENXIO;
>> +
>> +       rc = kstrtobool(buf, &var);
>> +       if (rc < 0 || var != 1)
>> +               return -EINVAL;
> 
> You could just cut to the chase and do: sysfs_eq(buf, "1")

Thanks will use this

 

>> +
>> +/*
>> + * Percpu and allcpu ifs have attributes named "status".
>> + * Since the former is defined in this same file using DEVICE_ATTR_RO()
>> + * the latter is defined directly.
>> + */
>> +static struct device_attribute dev_attr_allcpu_status = {
>> +       .attr   = { .name = "status", .mode = 0444 },
>> +       .show   = allcpu_status_show,
>> +};
> 
> Can still do the one line declartion like this and skip the comment.
> 
> DEVICE_ATTR(status, 0444, allcpu_status_show, NULL);

Will change as per your suggestion above

> 
>> +
>> +/* global scan sysfs attributes */
>> +static struct attribute *cpu_ifs_attrs[] = {
>> +       &dev_attr_reload.attr,
>> +       &dev_attr_allcpu_run_test.attr,
>> +       &dev_attr_image_version.attr,
>> +       &dev_attr_cpu_fail_list.attr,
>> +       &dev_attr_cpu_untested_list.attr,
>> +       &dev_attr_cpu_pass_list.attr,
>> +       &dev_attr_allcpu_status.attr,
>> +       NULL
>> +};
>> +
>> +const struct attribute_group cpu_ifs_attr_group = {
> 
> static?

will do

Jithu

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ