cpu/hotplug: Fix build error of using {add,remove}_cpu() with !CONFIG_SMP
Subsystems (3)
PATCH RESEND v2 1/2 cpu/hotplug: Fix build error of using {add,remove}_cpu() with !CONFIG_SMP
From: Shuo Liu <[email protected]>
279dcf693ac7 ("virt: acrn: Introduce an interface for Service VM to control vCPU") introduced {add,remove}_cpu() usage and it hit below error with !CONFIG_SMP:
../drivers/virt/acrn/hsm.c: In function ‘remove_cpu_store’:../drivers/virt/acrn/hsm.c:389:3: error: implicit declaration of function ‘remove_cpu’; [-Werror=implicit-function-declaration]
remove_cpu(cpu);
../drivers/virt/acrn/hsm.c:402:2: error: implicit declaration of function ‘add_cpu’; [-Werror=implicit-function-declaration]
add_cpu(cpu);
Add add_cpu() function prototypes with !CONFIG_SMP and remove_cpu() with !CONFIG_HOTPLUG_CPU for such usage.
--- include/linux/cpu.h | 3 +++ 1 file changed, 3 insertions(+)
include/linux/cpu.h +3 -0
@@ -108,6 +108,8 @@ static inline void cpu_maps_update_done(void) { } +static inline int add_cpu (unsigned int cpu) {return 0 ;} +#endif /* CONFIG_SMP */ extern struct bus_type cpu_subsys;
@@ -137,6 +139,7 @@ static inline int cpus_read_trylock(void) { return true; }static inline void lockdep_assert_cpus_held (void ) { }static inline void cpu_hotplug_disable (void ) { }static inline void cpu_hotplug_enable (void ) { } +static inline int remove_cpu (unsigned int cpu) {return -EPERM ; }static inline void smp_shutdown_nonboot_cpus (unsigned int primary_cpu) { }#endif /* !CONFIG_HOTPLUG_CPU */
base-commit: abaf6f60176f1ae9d946d63e4db63164600b7b1a
Signature · 1 line
2.28.0
PATCH RESEND v2 2/2 virt: acrn: Make remove_cpu sysfs invisible with !CONFIG_HOTPLUG_CPU
From: Shuo Liu <[email protected]>
Without cpu hotplug support, vCPU cannot be removed from a Service VM. Don't expose remove_cpu sysfs when CONFIG_HOTPLUG_CPU disabled.
--- drivers/virt/acrn/hsm.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/virt/acrn/hsm.c +9 -0
@@ -404,6 +404,14 @@ static ssize_t remove_cpu_store(struct device *dev, }static DEVICE_ATTR_WO (remove_cpu); +static umode_t acrn_attr_visible (struct kobject *kobj,struct attribute *a,int n) +{ +if (a == &dev_attr_remove_cpu.attr) +return IS_ENABLED (CONFIG_HOTPLUG_CPU ) ? a->mode :0 ; + +return a->mode; +} +static struct attribute *acrn_attrs[] = { &dev_attr_remove_cpu.attr,NULL
@@ -411,6 +419,7 @@ static struct attribute *acrn_attrs[] = {static struct attribute_group acrn_attr_group = { .attrs = acrn_attrs, + .is_visible = acrn_attr_visible, };static const struct attribute_group *acrn_attr_groups[] = {
Signature · 1 line
2.28.0
Re: [PATCH RESEND v2 2/2] virt: acrn: Make remove_cpu sysfs invisible with !CONFIG_HOTPLUG_CPU
Quoted 21 lines · On 02/21/21 21:43, [email protected] wrote:
From: Shuo Liu <[email protected]>
Without cpu hotplug support, vCPU cannot be removed from a Service VM. Don't expose
remove_cpusysfs whenCONFIG_HOTPLUG_CPUdisabled.Signed-off-by Shuo Liu <[email protected]>Cc Stephen Rothwell <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Qais Yousef <[email protected]>--- drivers/virt/acrn/hsm.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/virt/acrn/hsm.c +0
-0@@ -404,6 +404,14 @@ static ssize_t remove_cpu_store(struct device *dev, }
drivers/virt/acrn/hsm.c static ssize_t remove_cpu_store(struct device *dev, · line 414
Quoted 10 lines
drivers/virt/acrn/hsm.c +8
-0static DEVICE_ATTR_WO (remove_cpu); +static umode_t acrn_attr_visible (struct kobject *kobj,struct attribute *a,int n) +{ +if (a == &dev_attr_remove_cpu.attr) +return IS_ENABLED (CONFIG_HOTPLUG_CPU ) ? a->mode :0 ; + +return a->mode; +} +
I can't find this code in Linus' master. But this looks fine from my narrow PoV. Protecting the attribute with ifdef CONFIG_HOTPLUG_CPU is easier to read for me, but this doesn't mean this approach is not fine.
Thanks
--
Qais Yousef
Quoted 14 lines
drivers/virt/acrn/hsm.c +1
-0static struct attribute *acrn_attrs[] = { &dev_attr_remove_cpu.attr,NULL @@ -411,6 +419,7 @@ static struct attribute *acrn_attrs[] = {static struct attribute_group acrn_attr_group = { .attrs = acrn_attrs, + .is_visible = acrn_attr_visible, };static const struct attribute_group *acrn_attr_groups[] = {Signature · 1 line
2.28.0
Re: [PATCH RESEND v2 2/2] virt: acrn: Make remove_cpu sysfs invisible with !CONFIG_HOTPLUG_CPU
Hi,
Quoted 24 lines · Qais Yousef
Quoted 23 lines · On 02/21/21 21:43, [email protected] wrote:
From: Shuo Liu <[email protected]>
Without cpu hotplug support, vCPU cannot be removed from a Service VM. Don't expose
remove_cpusysfs whenCONFIG_HOTPLUG_CPUdisabled.Signed-off-by Shuo Liu <[email protected]>Cc Stephen Rothwell <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Qais Yousef <[email protected]>--- drivers/virt/acrn/hsm.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/virt/acrn/hsm.c +0
-0@@ -404,6 +404,14 @@ static ssize_t remove_cpu_store(struct device *dev, }static DEVICE_ATTR_WO (remove_cpu);
Quoted 10 lines
drivers/virt/acrn/hsm.c static ssize_t remove_cpu_store(struct device *dev, · line 414
Quoted 8 lines
drivers/virt/acrn/hsm.c +8
-0+static umode_t acrn_attr_visible (struct kobject *kobj,struct attribute *a,int n) +{ +if (a == &dev_attr_remove_cpu.attr) +return IS_ENABLED (CONFIG_HOTPLUG_CPU ) ? a->mode :0 ; + +return a->mode; +} +I can't find this code in Linus' master. But this looks fine from my narrow
Now, the code is still in linux-next tree only.
Quoted 2 lines
PoV. Protecting the attribute with ifdef
CONFIG_HOTPLUG_CPUis easier to read for me, but this doesn't mean this approach is not fine.
Just FYI, Greg prefers this solution.
https://lore.kernel.org/lkml/[email protected]/
Thanks
shuo
Quoted 24 lines · On 02/21/21 21:43, [email protected] wrote:
From: Shuo Liu <[email protected]>
279dcf693ac7("virt: acrn: Introduce an interface for Service VM to control vCPU") introduced {add,remove}_cpu() usage and it hit below error with !CONFIG_SMP:
../drivers/virt/acrn/hsm.c: In function ‘remove_cpu_store’:../drivers/virt/acrn/hsm.c:389:3: error: implicit declaration of function ‘remove_cpu’; [-Werror=implicit-function-declaration]
remove_cpu(cpu);
../drivers/virt/acrn/hsm.c:402:2: error: implicit declaration of function ‘add_cpu’; [-Werror=implicit-function-declaration]
add_cpu(cpu);Add
add_cpu()function prototypes with !CONFIG_SMP andremove_cpu()with !CONFIG_HOTPLUG_CPU for such usage.Fixes 279dcf693ac7 ("virt: acrn: Introduce an interface for Service VM to control vCPU")Reported-by Randy Dunlap <[email protected]>Signed-off-by Shuo Liu <[email protected]>Cc Stephen Rothwell <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Qais Yousef <[email protected]>
Quoted 1 line
---
Thanks!
--
Qais Yousef
Quoted 29 lines
include/linux/cpu.h | 3 +++ 1 file changed, 3 insertions(+)include/linux/cpu.h +3
-0@@ -108,6 +108,8 @@ static inline void cpu_maps_update_done(void) { } +static inline int add_cpu (unsigned int cpu) {return 0 ;} +#endif /* CONFIG_SMP */ extern struct bus_type cpu_subsys;@@ -137,6 +139,7 @@ static inline int cpus_read_trylock(void) { return true; }static inline void lockdep_assert_cpus_held (void ) { }static inline void cpu_hotplug_disable (void ) { }static inline void cpu_hotplug_enable (void ) { } +static inline int remove_cpu (unsigned int cpu) {return -EPERM ; }static inline void smp_shutdown_nonboot_cpus (unsigned int primary_cpu) { }#endif /* !CONFIG_HOTPLUG_CPU */ base-commit:
abaf6f60176f1ae9d946d63e4db63164600b7b1aSignature · 1 line
2.28.0