[PATCH 16/17] sysfs: Provide write method for paravirt

Shrikanth Hegde posted 17 patches 1 week, 5 days ago
There is a newer version of this series
[PATCH 16/17] sysfs: Provide write method for paravirt
Posted by Shrikanth Hegde 1 week, 5 days ago
This is a debug 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 allows checking some corner cases by providing custom
cpumasks which isn't possible with arch method.

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>
---
This is currently not meant be merged, since paravirt sysfs file is meant
to be Read-Only. Hence the documentation hasn't changed. If this method is
really helpful, then can consider including it depending on the
discussion.

drivers/base/cpu.c | 47 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index c216e13c4e2d..766584c85051 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 paravirt_store(struct device *dev,
+			      struct device_attribute *attr,
+			      const char *buf, size_t count)
+{
+	cpumask_var_t temp_mask;
+	int retval = 0;
+	int cpu;
+
+	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 */
+		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 paravirt_show(struct device *dev,
 				   struct device_attribute *attr, char *buf)
 {
 	return sysfs_emit(buf, "%*pbl\n", cpumask_pr_args(cpu_paravirt_mask));
 }
-static DEVICE_ATTR_RO(paravirt);
+static DEVICE_ATTR_RW(paravirt);
 #endif
 
 const struct bus_type cpu_subsys = {
-- 
2.47.3
Re: [PATCH 16/17] sysfs: Provide write method for paravirt
Posted by Greg KH 1 week ago
On Wed, Nov 19, 2025 at 06:14:48PM +0530, Shrikanth Hegde wrote:
> This is a debug 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 allows checking some corner cases by providing custom
> cpumasks which isn't possible with arch method.
> 
> 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>
> ---
> This is currently not meant be merged, since paravirt sysfs file is meant
> to be Read-Only. Hence the documentation hasn't changed. If this method is
> really helpful, then can consider including it depending on the
> discussion.

As you added this to this series, if it is picked up, it WILL be merged
:(

Please try a "Nacked-by:" or something else to keep patches from being
applied.  Or better yet, send them as a totally separate series.

thanks,

greg k-h
Re: [PATCH 16/17] sysfs: Provide write method for paravirt
Posted by Steven Rostedt 1 week ago
On Mon, 24 Nov 2025 18:04:48 +0100
Greg KH <gregkh@linuxfoundation.org> wrote:

> As you added this to this series, if it is picked up, it WILL be merged
> :(
> 
> Please try a "Nacked-by:" or something else to keep patches from being
> applied.  Or better yet, send them as a totally separate series.

Agreed. But when I do this to a patch in a series, I usually add in subject:

  [PATCH 16/17][DO NOT APPLY!!!] sysfs: Provide write method for paravirt

in order to make it stand out, and not a footnote after the tags.

-- Steve
Re: [PATCH 16/17] sysfs: Provide write method for paravirt
Posted by Shrikanth Hegde 6 days, 23 hours ago

On 11/24/25 10:54 PM, Steven Rostedt wrote:
> On Mon, 24 Nov 2025 18:04:48 +0100
> Greg KH <gregkh@linuxfoundation.org> wrote:
> 
>> As you added this to this series, if it is picked up, it WILL be merged
>> :(
>>
>> Please try a "Nacked-by:" or something else to keep patches from being
>> applied.  Or better yet, send them as a totally separate series.
> 
> Agreed. But when I do this to a patch in a series, I usually add in subject:
> 
>    [PATCH 16/17][DO NOT APPLY!!!] sysfs: Provide write method for paravirt
> 
> in order to make it stand out, and not a footnote after the tags.
> 
> -- Steve
> 

I can follow this.

PS: I was skeptical after last series mistake.
Re: [PATCH 16/17] sysfs: Provide write method for paravirt
Posted by Steven Rostedt 6 days, 10 hours ago
On Tue, 25 Nov 2025 08:19:45 +0530
Shrikanth Hegde <sshegde@linux.ibm.com> wrote:

> >    [PATCH 16/17][DO NOT APPLY!!!] sysfs: Provide write method for paravirt
> > 
> > in order to make it stand out, and not a footnote after the tags.
> > 
> > -- Steve
> >   
> 
> I can follow this.
> 
> PS: I was skeptical after last series mistake.

You may also want remove the [ ] and use '--' instead:

  [PATCH 16/17] -- DO NOT APPLY!!! -- sysfs: Provide write method for paravirt

Because if someone were to do a b4 pull it would strip out the text within
the brackets. Using -- DO NOT APPLY!!! -- instead, would keep it in the
commit message. And then seeing that in the shortlog would be a really big
red flag ;-)

-- Steve

PS. I plan on changing my usages to use '--' instead of '[' ']'
Re: [PATCH 16/17] sysfs: Provide write method for paravirt
Posted by Konstantin Ryabitsev 6 days, 10 hours ago
On Tue, Nov 25, 2025 at 10:52:18AM -0500, Steven Rostedt wrote:
> You may also want remove the [ ] and use '--' instead:
> 
>   [PATCH 16/17] -- DO NOT APPLY!!! -- sysfs: Provide write method for paravirt
> 
> Because if someone were to do a b4 pull it would strip out the text within
> the brackets. Using -- DO NOT APPLY!!! -- instead, would keep it in the
> commit message. And then seeing that in the shortlog would be a really big
> red flag ;-)

Small correction -- it's git itself that strips all content inside [], not b4
specifically.

-K
Re: [PATCH 16/17] sysfs: Provide write method for paravirt
Posted by Steven Rostedt 6 days, 10 hours ago
On Tue, 25 Nov 2025 11:02:38 -0500
Konstantin Ryabitsev <konstantin@linuxfoundation.org> wrote:

> Small correction -- it's git itself that strips all content inside [], not b4
> specifically.

Yes of course. Sorry, I didn't want to blame b4. I actually download the
patch series from patchwork and then do git am which does the stripping. I
just wanted to state a more common workflow, which is usually b4 followed
by a blind execution of git am. Where it does the stripping isn't of
importance at that point.

-- Steve