[HELPER PATCH 1] sysfs: Provide write method for paravirt

Shrikanth Hegde posted 1 patch 1 week, 5 days ago
drivers/base/cpu.c | 48 ++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 46 insertions(+), 2 deletions(-)
[HELPER PATCH 1] sysfs: Provide write method for paravirt
Posted by Shrikanth Hegde 1 week, 5 days ago
This is helper patch which could be used to set the range of CPUs as
paravirt. One could make use of this for quick testing of this infra
instead of writing arch specific code.

This is currently not meant be merged, since paravirt sysfs file is meant
to be Read-Only.

echo 100-200,600-700 >  /sys/devices/system/cpu/paravirt
cat /sys/devices/system/cpu/paravirt
100-200,600-700

echo > /sys/devices/system/cpu/paravirt
cat /sys/devices/system/cpu/paravirt

Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
---
 drivers/base/cpu.c | 48 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 46 insertions(+), 2 deletions(-)

diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 59ceae217b22..043e4f4ce1a9 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -375,12 +375,57 @@ static int cpu_uevent(const struct device *dev, struct kobj_uevent_env *env)
 #endif
 
 #ifdef CONFIG_PARAVIRT
+static ssize_t store_paravirt_cpus(struct device *dev,
+				   struct device_attribute *attr,
+				   const char *buf, size_t count)
+{
+	cpumask_var_t temp_mask;
+	int retval = 0;
+
+	if (!alloc_cpumask_var(&temp_mask, GFP_KERNEL))
+		return -ENOMEM;
+
+	retval = cpulist_parse(buf, temp_mask);
+	if (retval)
+		goto free_mask;
+
+	/* ALL cpus can't be marked as paravirt */
+	if (cpumask_equal(temp_mask, cpu_online_mask)) {
+		retval = -EINVAL;
+		goto free_mask;
+	}
+	if (cpumask_weight(temp_mask) > num_online_cpus()) {
+		retval = -EINVAL;
+		goto free_mask;
+	}
+
+	/* No more paravirt cpus */
+	if (cpumask_empty(temp_mask)) {
+		cpumask_copy((struct cpumask *)&__cpu_paravirt_mask, temp_mask);
+	} else {
+		cpumask_copy((struct cpumask *)&__cpu_paravirt_mask, temp_mask);
+
+		/* Enable tick on nohz_full cpu */
+		int cpu;
+		for_each_cpu(cpu, temp_mask) {
+			if (tick_nohz_full_cpu(cpu))
+				tick_nohz_dep_set_cpu(cpu, TICK_DEP_BIT_SCHED);
+		}
+	}
+
+	retval = count;
+
+free_mask:
+	free_cpumask_var(temp_mask);
+	return retval;
+}
+
 static ssize_t print_paravirt_cpus(struct device *dev,
 				   struct device_attribute *attr, char *buf)
 {
 	return sysfs_emit(buf, "%*pbl\n", cpumask_pr_args(cpu_paravirt_mask));
 }
-static DEVICE_ATTR(paravirt, 0444, print_paravirt_cpus, NULL);
+static DEVICE_ATTR(paravirt, 0644, print_paravirt_cpus, store_paravirt_cpus);
 #endif
 
 const struct bus_type cpu_subsys = {
@@ -675,7 +720,6 @@ static void __init cpu_register_vulnerabilities(void)
 		put_device(dev);
 	}
 }
-
 #else
 static inline void cpu_register_vulnerabilities(void) { }
 #endif
-- 
2.47.3
Re: [HELPER PATCH 1] sysfs: Provide write method for paravirt
Posted by Greg KH 1 week, 5 days ago
On Wed, Nov 19, 2025 at 11:50:59AM +0530, Shrikanth Hegde wrote:
> This is helper patch which could be used to set the range of CPUs as
> paravirt. One could make use of this for quick testing of this infra
> instead of writing arch specific code.
> 
> This is currently not meant be merged, since paravirt sysfs file is meant
> to be Read-Only.
> 
> echo 100-200,600-700 >  /sys/devices/system/cpu/paravirt
> cat /sys/devices/system/cpu/paravirt
> 100-200,600-700
> 
> echo > /sys/devices/system/cpu/paravirt
> cat /sys/devices/system/cpu/paravirt
> 
> Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
> ---
>  drivers/base/cpu.c | 48 ++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 46 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
> index 59ceae217b22..043e4f4ce1a9 100644
> --- a/drivers/base/cpu.c
> +++ b/drivers/base/cpu.c
> @@ -375,12 +375,57 @@ static int cpu_uevent(const struct device *dev, struct kobj_uevent_env *env)
>  #endif
>  
>  #ifdef CONFIG_PARAVIRT
> +static ssize_t store_paravirt_cpus(struct device *dev,
> +				   struct device_attribute *attr,
> +				   const char *buf, size_t count)
> +{
> +	cpumask_var_t temp_mask;
> +	int retval = 0;
> +
> +	if (!alloc_cpumask_var(&temp_mask, GFP_KERNEL))
> +		return -ENOMEM;
> +
> +	retval = cpulist_parse(buf, temp_mask);
> +	if (retval)
> +		goto free_mask;
> +
> +	/* ALL cpus can't be marked as paravirt */
> +	if (cpumask_equal(temp_mask, cpu_online_mask)) {
> +		retval = -EINVAL;
> +		goto free_mask;
> +	}
> +	if (cpumask_weight(temp_mask) > num_online_cpus()) {
> +		retval = -EINVAL;
> +		goto free_mask;
> +	}
> +
> +	/* No more paravirt cpus */
> +	if (cpumask_empty(temp_mask)) {
> +		cpumask_copy((struct cpumask *)&__cpu_paravirt_mask, temp_mask);
> +	} else {
> +		cpumask_copy((struct cpumask *)&__cpu_paravirt_mask, temp_mask);
> +
> +		/* Enable tick on nohz_full cpu */
> +		int cpu;
> +		for_each_cpu(cpu, temp_mask) {
> +			if (tick_nohz_full_cpu(cpu))
> +				tick_nohz_dep_set_cpu(cpu, TICK_DEP_BIT_SCHED);
> +		}
> +	}
> +
> +	retval = count;
> +
> +free_mask:
> +	free_cpumask_var(temp_mask);
> +	return retval;
> +}
> +
>  static ssize_t print_paravirt_cpus(struct device *dev,
>  				   struct device_attribute *attr, char *buf)
>  {
>  	return sysfs_emit(buf, "%*pbl\n", cpumask_pr_args(cpu_paravirt_mask));
>  }
> -static DEVICE_ATTR(paravirt, 0444, print_paravirt_cpus, NULL);
> +static DEVICE_ATTR(paravirt, 0644, print_paravirt_cpus, store_paravirt_cpus);

DEVICE_ATTR_RW()?

And where is the documentation update for this sysfs file change?

>  #endif
>  
>  const struct bus_type cpu_subsys = {
> @@ -675,7 +720,6 @@ static void __init cpu_register_vulnerabilities(void)
>  		put_device(dev);
>  	}
>  }
> -
>  #else

Why is this change needed?

thanks,

greg k-h
Re: [HELPER PATCH 1] sysfs: Provide write method for paravirt
Posted by Shrikanth Hegde 1 week, 5 days ago
Hi Greg.

On 11/19/25 1:12 PM, Greg KH wrote:
> On Wed, Nov 19, 2025 at 11:50:59AM +0530, Shrikanth Hegde wrote:
>> This is helper patch which could be used to set the range of CPUs as
>> paravirt. One could make use of this for quick testing of this infra
>> instead of writing arch specific code.
>>
>> This is currently not meant be merged, since paravirt sysfs file is meant
>> to be Read-Only.
>>
>> echo 100-200,600-700 >  /sys/devices/system/cpu/paravirt
>> cat /sys/devices/system/cpu/paravirt
>> 100-200,600-700
>>
>> echo > /sys/devices/system/cpu/paravirt
>> cat /sys/devices/system/cpu/paravirt
>>
>> Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
>> ---
>>   drivers/base/cpu.c | 48 ++++++++++++++++++++++++++++++++++++++++++++--
>>   1 file changed, 46 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
>> index 59ceae217b22..043e4f4ce1a9 100644
>> --- a/drivers/base/cpu.c
>> +++ b/drivers/base/cpu.c
>> @@ -375,12 +375,57 @@ static int cpu_uevent(const struct device *dev, struct kobj_uevent_env *env)
>>   #endif
>>   
>>   #ifdef CONFIG_PARAVIRT
>> +static ssize_t store_paravirt_cpus(struct device *dev,
>> +				   struct device_attribute *attr,
>> +				   const char *buf, size_t count)
>> +{
>> +	cpumask_var_t temp_mask;
>> +	int retval = 0;
>> +
>> +	if (!alloc_cpumask_var(&temp_mask, GFP_KERNEL))
>> +		return -ENOMEM;
>> +
>> +	retval = cpulist_parse(buf, temp_mask);
>> +	if (retval)
>> +		goto free_mask;
>> +
>> +	/* ALL cpus can't be marked as paravirt */
>> +	if (cpumask_equal(temp_mask, cpu_online_mask)) {
>> +		retval = -EINVAL;
>> +		goto free_mask;
>> +	}
>> +	if (cpumask_weight(temp_mask) > num_online_cpus()) {
>> +		retval = -EINVAL;
>> +		goto free_mask;
>> +	}
>> +
>> +	/* No more paravirt cpus */
>> +	if (cpumask_empty(temp_mask)) {
>> +		cpumask_copy((struct cpumask *)&__cpu_paravirt_mask, temp_mask);
>> +	} else {
>> +		cpumask_copy((struct cpumask *)&__cpu_paravirt_mask, temp_mask);
>> +
>> +		/* Enable tick on nohz_full cpu */
>> +		int cpu;
>> +		for_each_cpu(cpu, temp_mask) {
>> +			if (tick_nohz_full_cpu(cpu))
>> +				tick_nohz_dep_set_cpu(cpu, TICK_DEP_BIT_SCHED);
>> +		}
>> +	}
>> +
>> +	retval = count;
>> +
>> +free_mask:
>> +	free_cpumask_var(temp_mask);
>> +	return retval;
>> +}
>> +
>>   static ssize_t print_paravirt_cpus(struct device *dev,
>>   				   struct device_attribute *attr, char *buf)
>>   {
>>   	return sysfs_emit(buf, "%*pbl\n", cpumask_pr_args(cpu_paravirt_mask));
>>   }
>> -static DEVICE_ATTR(paravirt, 0444, print_paravirt_cpus, NULL);
>> +static DEVICE_ATTR(paravirt, 0644, print_paravirt_cpus, store_paravirt_cpus);
> 
> DEVICE_ATTR_RW()?

ok.

> 
> And where is the documentation update for this sysfs file change?
> 

[RFC PATCH v4 11/17] has the documentation of this sysfs file.
https://lore.kernel.org/all/20251119062100.1112520-12-sshegde@linux.ibm.com/

>>   #endif
>>   
>>   const struct bus_type cpu_subsys = {
>> @@ -675,7 +720,6 @@ static void __init cpu_register_vulnerabilities(void)
>>   		put_device(dev);
>>   	}
>>   }
>> -
>>   #else
> 
> Why is this change needed?
> 
> thanks,
> 
> greg k-h

This is a helper patch. This helps to verify functionality of any combination
of CPUs being marked as paravirt which helped me to test some corner cases.

This is also helpful until the arch specific hint becomes better.

This is also useful for other archs which haven't implemented archs specific handling of
steal time, but want to play around with series for their usecase (ex: S390)

Once arch specific hint becomes better, we could decide to remove it or keep in more appropriate
place. It really is debugfs for infra which says I don't want to use these CPUs for now.
Re: [HELPER PATCH 1] sysfs: Provide write method for paravirt
Posted by Christophe Leroy 1 week, 5 days ago

Le 19/11/2025 à 09:08, Shrikanth Hegde a écrit :
> Hi Greg.
> 
> On 11/19/25 1:12 PM, Greg KH wrote:
>> On Wed, Nov 19, 2025 at 11:50:59AM +0530, Shrikanth Hegde wrote:
>>> This is helper patch which could be used to set the range of CPUs as
>>> paravirt. One could make use of this for quick testing of this infra
>>> instead of writing arch specific code.
>>>
>>> This is currently not meant be merged, since paravirt sysfs file is 
>>> meant
>>> to be Read-Only.
>>>
>>> echo 100-200,600-700 >  /sys/devices/system/cpu/paravirt
>>> cat /sys/devices/system/cpu/paravirt
>>> 100-200,600-700
>>>
>>> echo > /sys/devices/system/cpu/paravirt
>>> cat /sys/devices/system/cpu/paravirt
>>>
>>> Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
>>> ---
>>>   drivers/base/cpu.c | 48 ++++++++++++++++++++++++++++++++++++++++++++--
>>>   1 file changed, 46 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
>>> index 59ceae217b22..043e4f4ce1a9 100644
>>> --- a/drivers/base/cpu.c
>>> +++ b/drivers/base/cpu.c
>>> @@ -375,12 +375,57 @@ static int cpu_uevent(const struct device *dev, 
>>> struct kobj_uevent_env *env)
>>>   #endif
>>>   #ifdef CONFIG_PARAVIRT
>>> +static ssize_t store_paravirt_cpus(struct device *dev,
>>> +                   struct device_attribute *attr,
>>> +                   const char *buf, size_t count)
>>> +{
>>> +    cpumask_var_t temp_mask;
>>> +    int retval = 0;
>>> +
>>> +    if (!alloc_cpumask_var(&temp_mask, GFP_KERNEL))
>>> +        return -ENOMEM;
>>> +
>>> +    retval = cpulist_parse(buf, temp_mask);
>>> +    if (retval)
>>> +        goto free_mask;
>>> +
>>> +    /* ALL cpus can't be marked as paravirt */
>>> +    if (cpumask_equal(temp_mask, cpu_online_mask)) {
>>> +        retval = -EINVAL;
>>> +        goto free_mask;
>>> +    }
>>> +    if (cpumask_weight(temp_mask) > num_online_cpus()) {
>>> +        retval = -EINVAL;
>>> +        goto free_mask;
>>> +    }
>>> +
>>> +    /* No more paravirt cpus */
>>> +    if (cpumask_empty(temp_mask)) {
>>> +        cpumask_copy((struct cpumask *)&__cpu_paravirt_mask, 
>>> temp_mask);
>>> +    } else {
>>> +        cpumask_copy((struct cpumask *)&__cpu_paravirt_mask, 
>>> temp_mask);
>>> +
>>> +        /* Enable tick on nohz_full cpu */
>>> +        int cpu;
>>> +        for_each_cpu(cpu, temp_mask) {
>>> +            if (tick_nohz_full_cpu(cpu))
>>> +                tick_nohz_dep_set_cpu(cpu, TICK_DEP_BIT_SCHED);
>>> +        }
>>> +    }
>>> +
>>> +    retval = count;
>>> +
>>> +free_mask:
>>> +    free_cpumask_var(temp_mask);
>>> +    return retval;
>>> +}
>>> +
>>>   static ssize_t print_paravirt_cpus(struct device *dev,
>>>                      struct device_attribute *attr, char *buf)
>>>   {
>>>       return sysfs_emit(buf, "%*pbl\n", 
>>> cpumask_pr_args(cpu_paravirt_mask));
>>>   }
>>> -static DEVICE_ATTR(paravirt, 0444, print_paravirt_cpus, NULL);
>>> +static DEVICE_ATTR(paravirt, 0644, print_paravirt_cpus, 
>>> store_paravirt_cpus);
>>
>> DEVICE_ATTR_RW()?
> 
> ok.
> 
>>
>> And where is the documentation update for this sysfs file change?
>>
> 
> [RFC PATCH v4 11/17] has the documentation of this sysfs file.

There is a problem in the way you sent this patch and the other helper 
patch. They appear in the cover letter of your series are part of it but 
at the end the series is only sent with 15 patches over 17, and the last 
two patches appear as independent from the series:

Series at 
https://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=482680

Other patches are on their own: 
https://patchwork.ozlabs.org/project/linuxppc-dev/list/?submitter=87866

> https://eur01.safelinks.protection.outlook.com/? 
> url=https%3A%2F%2Flore.kernel.org%2Fall%2F20251119062100.1112520-12- 
> sshegde%40linux.ibm.com%2F&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7Ce78250c7fb3647ca116608de2742daa2%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638991365240852443%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=RxgUm4gnzXXVnTq0cGQ41Zf1wj83PBEfZm3k%2FPC9Abw%3D&reserved=0
> 
>>>   #endif
>>>   const struct bus_type cpu_subsys = {
>>> @@ -675,7 +720,6 @@ static void __init 
>>> cpu_register_vulnerabilities(void)
>>>           put_device(dev);
>>>       }
>>>   }
>>> -
>>>   #else
>>
>> Why is this change needed?
>>
>> thanks,
>>
>> greg k-h
> 
> This is a helper patch. This helps to verify functionality of any 
> combination
> of CPUs being marked as paravirt which helped me to test some corner cases.
> 
> This is also helpful until the arch specific hint becomes better.
> 
> This is also useful for other archs which haven't implemented archs 
> specific handling of
> steal time, but want to play around with series for their usecase (ex: 
> S390)
> 
> Once arch specific hint becomes better, we could decide to remove it or 
> keep in more appropriate
> place. It really is debugfs for infra which says I don't want to use 
> these CPUs for now.

Re: [HELPER PATCH 1] sysfs: Provide write method for paravirt
Posted by Shrikanth Hegde 1 week, 5 days ago

On 11/19/25 1:50 PM, Christophe Leroy wrote:
> 
> 
> Le 19/11/2025 à 09:08, Shrikanth Hegde a écrit :
>> Hi Greg.
>>
>> On 11/19/25 1:12 PM, Greg KH wrote:
>>> On Wed, Nov 19, 2025 at 11:50:59AM +0530, Shrikanth Hegde wrote:
>>>> This is helper patch which could be used to set the range of CPUs as
>>>> paravirt. One could make use of this for quick testing of this infra
>>>> instead of writing arch specific code.
>>>>
>>>> This is currently not meant be merged, since paravirt sysfs file is 
>>>> meant
>>>> to be Read-Only.
>>>>
>>>> echo 100-200,600-700 >  /sys/devices/system/cpu/paravirt
>>>> cat /sys/devices/system/cpu/paravirt
>>>> 100-200,600-700
>>>>
>>>> echo > /sys/devices/system/cpu/paravirt
>>>> cat /sys/devices/system/cpu/paravirt
>>>>
>>>> Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
>>>> ---
>>>>   drivers/base/cpu.c | 48 ++++++++++++++++++++++++++++++++++++++++++ 
>>>> ++--
>>>>   1 file changed, 46 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
>>>> index 59ceae217b22..043e4f4ce1a9 100644
>>>> --- a/drivers/base/cpu.c
>>>> +++ b/drivers/base/cpu.c
>>>> @@ -375,12 +375,57 @@ static int cpu_uevent(const struct device 
>>>> *dev, struct kobj_uevent_env *env)
>>>>   #endif
>>>>   #ifdef CONFIG_PARAVIRT
>>>> +static ssize_t store_paravirt_cpus(struct device *dev,
>>>> +                   struct device_attribute *attr,
>>>> +                   const char *buf, size_t count)
>>>> +{
>>>> +    cpumask_var_t temp_mask;
>>>> +    int retval = 0;
>>>> +
>>>> +    if (!alloc_cpumask_var(&temp_mask, GFP_KERNEL))
>>>> +        return -ENOMEM;
>>>> +
>>>> +    retval = cpulist_parse(buf, temp_mask);
>>>> +    if (retval)
>>>> +        goto free_mask;
>>>> +
>>>> +    /* ALL cpus can't be marked as paravirt */
>>>> +    if (cpumask_equal(temp_mask, cpu_online_mask)) {
>>>> +        retval = -EINVAL;
>>>> +        goto free_mask;
>>>> +    }
>>>> +    if (cpumask_weight(temp_mask) > num_online_cpus()) {
>>>> +        retval = -EINVAL;
>>>> +        goto free_mask;
>>>> +    }
>>>> +
>>>> +    /* No more paravirt cpus */
>>>> +    if (cpumask_empty(temp_mask)) {
>>>> +        cpumask_copy((struct cpumask *)&__cpu_paravirt_mask, 
>>>> temp_mask);
>>>> +    } else {
>>>> +        cpumask_copy((struct cpumask *)&__cpu_paravirt_mask, 
>>>> temp_mask);
>>>> +
>>>> +        /* Enable tick on nohz_full cpu */
>>>> +        int cpu;
>>>> +        for_each_cpu(cpu, temp_mask) {
>>>> +            if (tick_nohz_full_cpu(cpu))
>>>> +                tick_nohz_dep_set_cpu(cpu, TICK_DEP_BIT_SCHED);
>>>> +        }
>>>> +    }
>>>> +
>>>> +    retval = count;
>>>> +
>>>> +free_mask:
>>>> +    free_cpumask_var(temp_mask);
>>>> +    return retval;
>>>> +}
>>>> +
>>>>   static ssize_t print_paravirt_cpus(struct device *dev,
>>>>                      struct device_attribute *attr, char *buf)
>>>>   {
>>>>       return sysfs_emit(buf, "%*pbl\n", 
>>>> cpumask_pr_args(cpu_paravirt_mask));
>>>>   }
>>>> -static DEVICE_ATTR(paravirt, 0444, print_paravirt_cpus, NULL);
>>>> +static DEVICE_ATTR(paravirt, 0644, print_paravirt_cpus, 
>>>> store_paravirt_cpus);
>>>
>>> DEVICE_ATTR_RW()?
>>
>> ok.
>>
>>>
>>> And where is the documentation update for this sysfs file change?
>>>
>>
>> [RFC PATCH v4 11/17] has the documentation of this sysfs file.
> 
> There is a problem in the way you sent this patch and the other helper 
> patch. They appear in the cover letter of your series are part of it but 
> at the end the series is only sent with 15 patches over 17, and the last 
> two patches appear as independent from the series:
> 
> Series at https://patchwork.ozlabs.org/project/linuxppc-dev/list/? 
> series=482680
> 
> Other patches are on their own: https://patchwork.ozlabs.org/project/ 
> linuxppc-dev/list/?submitter=87866
> 

I edited the patch header before sending. Wanted to say they are debug patches.
Thought "helper" maybe a name. My bad.

I didn't realize that it could seen an separate patches :(
So sorry. I thought it would come up as thread of the series. Like it showed up in
https://lore.kernel.org/all/20251119062100.1112520-12-sshegde@linux.ibm.com/#r

Should I resend the series?
Re: [HELPER PATCH 1] sysfs: Provide write method for paravirt
Posted by Greg KH 1 week, 5 days ago
On Wed, Nov 19, 2025 at 01:38:24PM +0530, Shrikanth Hegde wrote:
> Hi Greg.
> 
> On 11/19/25 1:12 PM, Greg KH wrote:
> > On Wed, Nov 19, 2025 at 11:50:59AM +0530, Shrikanth Hegde wrote:
> > > This is helper patch which could be used to set the range of CPUs as
> > > paravirt. One could make use of this for quick testing of this infra
> > > instead of writing arch specific code.
> > > 
> > > This is currently not meant be merged, since paravirt sysfs file is meant
> > > to be Read-Only.
> > > 
> > > echo 100-200,600-700 >  /sys/devices/system/cpu/paravirt
> > > cat /sys/devices/system/cpu/paravirt
> > > 100-200,600-700
> > > 
> > > echo > /sys/devices/system/cpu/paravirt
> > > cat /sys/devices/system/cpu/paravirt
> > > 
> > > Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
> > > ---
> > >   drivers/base/cpu.c | 48 ++++++++++++++++++++++++++++++++++++++++++++--
> > >   1 file changed, 46 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
> > > index 59ceae217b22..043e4f4ce1a9 100644
> > > --- a/drivers/base/cpu.c
> > > +++ b/drivers/base/cpu.c
> > > @@ -375,12 +375,57 @@ static int cpu_uevent(const struct device *dev, struct kobj_uevent_env *env)
> > >   #endif
> > >   #ifdef CONFIG_PARAVIRT
> > > +static ssize_t store_paravirt_cpus(struct device *dev,
> > > +				   struct device_attribute *attr,
> > > +				   const char *buf, size_t count)
> > > +{
> > > +	cpumask_var_t temp_mask;
> > > +	int retval = 0;
> > > +
> > > +	if (!alloc_cpumask_var(&temp_mask, GFP_KERNEL))
> > > +		return -ENOMEM;
> > > +
> > > +	retval = cpulist_parse(buf, temp_mask);
> > > +	if (retval)
> > > +		goto free_mask;
> > > +
> > > +	/* ALL cpus can't be marked as paravirt */
> > > +	if (cpumask_equal(temp_mask, cpu_online_mask)) {
> > > +		retval = -EINVAL;
> > > +		goto free_mask;
> > > +	}
> > > +	if (cpumask_weight(temp_mask) > num_online_cpus()) {
> > > +		retval = -EINVAL;
> > > +		goto free_mask;
> > > +	}
> > > +
> > > +	/* No more paravirt cpus */
> > > +	if (cpumask_empty(temp_mask)) {
> > > +		cpumask_copy((struct cpumask *)&__cpu_paravirt_mask, temp_mask);
> > > +	} else {
> > > +		cpumask_copy((struct cpumask *)&__cpu_paravirt_mask, temp_mask);
> > > +
> > > +		/* Enable tick on nohz_full cpu */
> > > +		int cpu;
> > > +		for_each_cpu(cpu, temp_mask) {
> > > +			if (tick_nohz_full_cpu(cpu))
> > > +				tick_nohz_dep_set_cpu(cpu, TICK_DEP_BIT_SCHED);
> > > +		}
> > > +	}
> > > +
> > > +	retval = count;
> > > +
> > > +free_mask:
> > > +	free_cpumask_var(temp_mask);
> > > +	return retval;
> > > +}
> > > +
> > >   static ssize_t print_paravirt_cpus(struct device *dev,
> > >   				   struct device_attribute *attr, char *buf)
> > >   {
> > >   	return sysfs_emit(buf, "%*pbl\n", cpumask_pr_args(cpu_paravirt_mask));
> > >   }
> > > -static DEVICE_ATTR(paravirt, 0444, print_paravirt_cpus, NULL);
> > > +static DEVICE_ATTR(paravirt, 0644, print_paravirt_cpus, store_paravirt_cpus);
> > 
> > DEVICE_ATTR_RW()?
> 
> ok.
> 
> > 
> > And where is the documentation update for this sysfs file change?
> > 
> 
> [RFC PATCH v4 11/17] has the documentation of this sysfs file.
> https://lore.kernel.org/all/20251119062100.1112520-12-sshegde@linux.ibm.com/

So a rfc patch has the documentation for a change that you don't want to
have applied?  This is an odd series, how are we supposed to review
this?

> This is a helper patch. This helps to verify functionality of any combination
> of CPUs being marked as paravirt which helped me to test some corner cases.

I don't think I have ever seen a "helper patch" to know what to do with
it :(

thanks,

greg k-h
Re: [HELPER PATCH 1] sysfs: Provide write method for paravirt
Posted by Shrikanth Hegde 1 week, 5 days ago

On 11/19/25 1:53 PM, Greg KH wrote:
> On Wed, Nov 19, 2025 at 01:38:24PM +0530, Shrikanth Hegde wrote:
>> Hi Greg.
>>
>> On 11/19/25 1:12 PM, Greg KH wrote:
>>> On Wed, Nov 19, 2025 at 11:50:59AM +0530, Shrikanth Hegde wrote:
>>>> This is helper patch which could be used to set the range of CPUs as
>>>> paravirt. One could make use of this for quick testing of this infra
>>>> instead of writing arch specific code.
>>>>
>>>> This is currently not meant be merged, since paravirt sysfs file is meant
>>>> to be Read-Only.
>>>>
>>>> echo 100-200,600-700 >  /sys/devices/system/cpu/paravirt
>>>> cat /sys/devices/system/cpu/paravirt
>>>> 100-200,600-700
>>>>
>>>> echo > /sys/devices/system/cpu/paravirt
>>>> cat /sys/devices/system/cpu/paravirt
>>>>
>>>> Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
>>>> ---
>>>>    drivers/base/cpu.c | 48 ++++++++++++++++++++++++++++++++++++++++++++--
>>>>    1 file changed, 46 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
>>>> index 59ceae217b22..043e4f4ce1a9 100644
>>>> --- a/drivers/base/cpu.c
>>>> +++ b/drivers/base/cpu.c
>>>> @@ -375,12 +375,57 @@ static int cpu_uevent(const struct device *dev, struct kobj_uevent_env *env)
>>>>    #endif
>>>>    #ifdef CONFIG_PARAVIRT
>>>> +static ssize_t store_paravirt_cpus(struct device *dev,
>>>> +				   struct device_attribute *attr,
>>>> +				   const char *buf, size_t count)
>>>> +{
>>>> +	cpumask_var_t temp_mask;
>>>> +	int retval = 0;
>>>> +
>>>> +	if (!alloc_cpumask_var(&temp_mask, GFP_KERNEL))
>>>> +		return -ENOMEM;
>>>> +
>>>> +	retval = cpulist_parse(buf, temp_mask);
>>>> +	if (retval)
>>>> +		goto free_mask;
>>>> +
>>>> +	/* ALL cpus can't be marked as paravirt */
>>>> +	if (cpumask_equal(temp_mask, cpu_online_mask)) {
>>>> +		retval = -EINVAL;
>>>> +		goto free_mask;
>>>> +	}
>>>> +	if (cpumask_weight(temp_mask) > num_online_cpus()) {
>>>> +		retval = -EINVAL;
>>>> +		goto free_mask;
>>>> +	}
>>>> +
>>>> +	/* No more paravirt cpus */
>>>> +	if (cpumask_empty(temp_mask)) {
>>>> +		cpumask_copy((struct cpumask *)&__cpu_paravirt_mask, temp_mask);
>>>> +	} else {
>>>> +		cpumask_copy((struct cpumask *)&__cpu_paravirt_mask, temp_mask);
>>>> +
>>>> +		/* Enable tick on nohz_full cpu */
>>>> +		int cpu;
>>>> +		for_each_cpu(cpu, temp_mask) {
>>>> +			if (tick_nohz_full_cpu(cpu))
>>>> +				tick_nohz_dep_set_cpu(cpu, TICK_DEP_BIT_SCHED);
>>>> +		}
>>>> +	}
>>>> +
>>>> +	retval = count;
>>>> +
>>>> +free_mask:
>>>> +	free_cpumask_var(temp_mask);
>>>> +	return retval;
>>>> +}
>>>> +
>>>>    static ssize_t print_paravirt_cpus(struct device *dev,
>>>>    				   struct device_attribute *attr, char *buf)
>>>>    {
>>>>    	return sysfs_emit(buf, "%*pbl\n", cpumask_pr_args(cpu_paravirt_mask));
>>>>    }
>>>> -static DEVICE_ATTR(paravirt, 0444, print_paravirt_cpus, NULL);
>>>> +static DEVICE_ATTR(paravirt, 0644, print_paravirt_cpus, store_paravirt_cpus);
>>>
>>> DEVICE_ATTR_RW()?
>>
>> ok.
>>
>>>
>>> And where is the documentation update for this sysfs file change?
>>>
>>
>> [RFC PATCH v4 11/17] has the documentation of this sysfs file.
>> https://lore.kernel.org/all/20251119062100.1112520-12-sshegde@linux.ibm.com/
> 
> So a rfc patch has the documentation for a change that you don't want to
> have applied?  This is an odd series, how are we supposed to review
> this?

I added the documentation for sysfs file as the file is read only. The last two
patch are debug patches. So i didn't update the documentation saying it can be written
too. I hope this clears the doubts.

> 
>> This is a helper patch. This helps to verify functionality of any combination
>> of CPUs being marked as paravirt which helped me to test some corner cases.
> 
> I don't think I have ever seen a "helper patch" to know what to do with
> it :(
> 

Sorry for confusion with the name.

All I wanted to say there was it is debug patch one could use.
Would [RFC PATCH 16/17][DEBUG] would have been a better name?