Re: [PATCH v6 06/11] printk: console: Introduce sysfs interface for per-console loglevels
From: John Ogness
Date: Wed Nov 20 2024 - 03:43:20 EST
On 2024-11-20, Chris Down <chris@xxxxxxxxxxxxxx> wrote:
>>> +static ssize_t loglevel_show(struct device *dev, struct device_attribute *attr,
>>> + char *buf)
>>> +{
>>> + struct console *con = dev_get_drvdata(dev);
>>> +
>>> + return sysfs_emit(buf, "%d\n", READ_ONCE(con->level));
>>
>>While I admire the use of READ_ONCE() properly, it really doesn't matter
>>for sysfs as it could change right afterwards and no one cares. So no
>>need for that here, right?
>
> From my reading of the code it looks like we need this to avoid
> tearing.
I cannot imagine that any compiler would perform multiple reads to read
an aligned field of 4-bytes. Particularly since this function only reads
this one field.
At most it is kind of annotating lockless access to con->level. But
since it is not using data_race(), it would still trigger KCSAN with a
warning. I recommend removing it.
John Ogness