Re: [PATCH v6 06/11] printk: console: Introduce sysfs interface for per-console loglevels

From: John Ogness
Date: Wed Nov 20 2024 - 10:29:43 EST


On 2024-11-20, Petr Mladek <pmladek@xxxxxxxx> 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));
>
> Honestly, it seems that everyone agrees that the READ_ONCE() makes
> some sense. I do not understand why some many people wants to remove
> it. I personally prefer to be on the safe side.

OK, then please also annotate the data race to keep KCSAN happy:

data_race(READ_ONCE(con->level));

>From the data_race kerneldoc:

If the access must be atomic *and* KCSAN should ignore the access,
use both data_race() and READ_ONCE(), for example,
data_race(READ_ONCE(x)).

John