Linux Framebuffer Layer development
 help / color / mirror / Atom feed
* Re: [PATCH 2/2] backlight: mp3309c: Initialize backlight properties without memset
From: Lee Jones @ 2025-09-02 10:36 UTC (permalink / raw)
  To: Daniel Thompson
  Cc: Uwe Kleine-König, Flavio Suligoi, Daniel Thompson,
	Jingoo Han, Helge Deller, dri-devel, linux-fbdev, linux-pwm
In-Reply-To: <aKLvaP55PIVhyFSc@aspen.lan>

On Mon, 18 Aug 2025, Daniel Thompson wrote:

> On Tue, Jul 01, 2025 at 11:22:37AM +0200, Uwe Kleine-König wrote:
> > Assigning values to a struct using a compound literal (since C99) also
> > guarantees that all unspecified struct members are empty-initialized, so
> > it properly replaces the memset to zero.
> >
> > The code looks a bit nicer and more idiomatic (though that might be
> > subjective?). The resulting binary is a bit smaller. On ARCH=arm with
> > an allnoconfig + minimal changes to enable the mp3309c driver the
> > difference is 12 bytes.
> >
> > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
> 
> Reviewed-by: Daniel Thompson (RISCstar) <danielt@kernel.org>

Looks like you cannot send tags from non-related email accounts:

NOTE: some trailers ignored due to from/email mismatches:
    ! Trailer: Reviewed-by: "Daniel Thompson (RISCstar)" <danielt@kernel.org>
     Msg From: Daniel Thompson <daniel@riscstar.com>

I'll add the tags manually this time.

-- 
Lee Jones [李琼斯]

^ permalink raw reply

* Re: [PATCH 0/2] backlight: mp3309c: Drop pwm_apply_args()
From: Lee Jones @ 2025-09-02 10:35 UTC (permalink / raw)
  To: Flavio Suligoi, Lee Jones, Daniel Thompson, Jingoo Han,
	Helge Deller, Uwe Kleine-König
  Cc: Daniel Thompson, dri-devel, linux-fbdev, linux-pwm
In-Reply-To: <cover.1751361465.git.u.kleine-koenig@baylibre.com>

On Tue, 01 Jul 2025 11:22:35 +0200, Uwe Kleine-König wrote:
> the first patch of this series is what I really care about: There are
> hardly any drivers left that use pwm_apply_args(). When all of them are
> converted to not use it any more, I intend to drop that function.
> 
> The 2nd patch is just a change that I noticed while editing the driver
> that is IMHO nice. If you don't agree and only apply the first patch, I
> won't argue. It's an alternative approach to what Daniel Thompson did in
> commit 7ee6478d5aa9 ("backlight: mp3309c: Fully initialize
> backlight_properties during probe").
> 
> [...]

Applied, thanks!

[1/2] backlight: mp3309c: Drop pwm_apply_args()
      commit: d22caa15de3a11b503157aec079cad4bf305ff47
[2/2] backlight: mp3309c: Initialize backlight properties without memset
      commit: 71ca0594c11b4030c6dece9ba9b080d652a82473

--
Lee Jones [李琼斯]


^ permalink raw reply

* [PATCH] fbdev/simplefb: Fix use after free in simplefb_detach_genpds()
From: Janne Grunau @ 2025-09-01  9:12 UTC (permalink / raw)
  To: Hans de Goede, Helge Deller, Thierry Reding
  Cc: linux-fbdev, dri-devel, linux-kernel, Daniel Huhardeaux, stable,
	Janne Grunau

The pm_domain cleanup can not be devres managed as it uses struct
simplefb_par which is allocated within struct fb_info by
framebuffer_alloc(). This allocation is explicitly freed by
unregister_framebuffer() in simplefb_remove().
Devres managed cleanup runs after the device remove call and thus can no
longer access struct simplefb_par.
Call simplefb_detach_genpds() explicitly from simplefb_destroy() like
the cleanup functions for clocks and regulators.

Fixes an use after free on M2 Mac mini during
aperture_remove_conflicting_devices() using the downstream asahi kernel
with Debian's kernel config. For unknown reasons this started to
consistently dereference an invalid pointer in v6.16.3 based kernels.

[    6.736134] BUG: KASAN: slab-use-after-free in simplefb_detach_genpds+0x58/0x220
[    6.743545] Read of size 4 at addr ffff8000304743f0 by task (udev-worker)/227
[    6.750697]
[    6.752182] CPU: 6 UID: 0 PID: 227 Comm: (udev-worker) Tainted: G S                  6.16.3-asahi+ #16 PREEMPTLAZY
[    6.752186] Tainted: [S]=CPU_OUT_OF_SPEC
[    6.752187] Hardware name: Apple Mac mini (M2, 2023) (DT)
[    6.752189] Call trace:
[    6.752190]  show_stack+0x34/0x98 (C)
[    6.752194]  dump_stack_lvl+0x60/0x80
[    6.752197]  print_report+0x17c/0x4d8
[    6.752201]  kasan_report+0xb4/0x100
[    6.752206]  __asan_report_load4_noabort+0x20/0x30
[    6.752209]  simplefb_detach_genpds+0x58/0x220
[    6.752213]  devm_action_release+0x50/0x98
[    6.752216]  release_nodes+0xd0/0x2c8
[    6.752219]  devres_release_all+0xfc/0x178
[    6.752221]  device_unbind_cleanup+0x28/0x168
[    6.752224]  device_release_driver_internal+0x34c/0x470
[    6.752228]  device_release_driver+0x20/0x38
[    6.752231]  bus_remove_device+0x1b0/0x380
[    6.752234]  device_del+0x314/0x820
[    6.752238]  platform_device_del+0x3c/0x1e8
[    6.752242]  platform_device_unregister+0x20/0x50
[    6.752246]  aperture_detach_platform_device+0x1c/0x30
[    6.752250]  aperture_detach_devices+0x16c/0x290
[    6.752253]  aperture_remove_conflicting_devices+0x34/0x50
...
[    6.752343]
[    6.967409] Allocated by task 62:
[    6.970724]  kasan_save_stack+0x3c/0x70
[    6.974560]  kasan_save_track+0x20/0x40
[    6.978397]  kasan_save_alloc_info+0x40/0x58
[    6.982670]  __kasan_kmalloc+0xd4/0xd8
[    6.986420]  __kmalloc_noprof+0x194/0x540
[    6.990432]  framebuffer_alloc+0xc8/0x130
[    6.994444]  simplefb_probe+0x258/0x2378
...
[    7.054356]
[    7.055838] Freed by task 227:
[    7.058891]  kasan_save_stack+0x3c/0x70
[    7.062727]  kasan_save_track+0x20/0x40
[    7.066565]  kasan_save_free_info+0x4c/0x80
[    7.070751]  __kasan_slab_free+0x6c/0xa0
[    7.074675]  kfree+0x10c/0x380
[    7.077727]  framebuffer_release+0x5c/0x90
[    7.081826]  simplefb_destroy+0x1b4/0x2c0
[    7.085837]  put_fb_info+0x98/0x100
[    7.089326]  unregister_framebuffer+0x178/0x320
[    7.093861]  simplefb_remove+0x3c/0x60
[    7.097611]  platform_remove+0x60/0x98
[    7.101361]  device_remove+0xb8/0x160
[    7.105024]  device_release_driver_internal+0x2fc/0x470
[    7.110256]  device_release_driver+0x20/0x38
[    7.114529]  bus_remove_device+0x1b0/0x380
[    7.118628]  device_del+0x314/0x820
[    7.122116]  platform_device_del+0x3c/0x1e8
[    7.126302]  platform_device_unregister+0x20/0x50
[    7.131012]  aperture_detach_platform_device+0x1c/0x30
[    7.136157]  aperture_detach_devices+0x16c/0x290
[    7.140779]  aperture_remove_conflicting_devices+0x34/0x50
...

Reported-by: Daniel Huhardeaux <tech@tootai.net>
Cc: stable@vger.kernel.org
Fixes: 92a511a568e44 ("fbdev/simplefb: Add support for generic power-domains")
Signed-off-by: Janne Grunau <j@jannau.net>
---
 drivers/video/fbdev/simplefb.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/video/fbdev/simplefb.c b/drivers/video/fbdev/simplefb.c
index 1893815dc67f4c1403eea42c0e10a7ead4d96ba9..cd5193e704ffe1ccc178c13916a462446af9cb14 100644
--- a/drivers/video/fbdev/simplefb.c
+++ b/drivers/video/fbdev/simplefb.c
@@ -93,6 +93,7 @@ struct simplefb_par {
 
 static void simplefb_clocks_destroy(struct simplefb_par *par);
 static void simplefb_regulators_destroy(struct simplefb_par *par);
+static void simplefb_detach_genpds(void *res);
 
 /*
  * fb_ops.fb_destroy is called by the last put_fb_info() call at the end
@@ -105,6 +106,7 @@ static void simplefb_destroy(struct fb_info *info)
 
 	simplefb_regulators_destroy(info->par);
 	simplefb_clocks_destroy(info->par);
+	simplefb_detach_genpds(info->par);
 	if (info->screen_base)
 		iounmap(info->screen_base);
 
@@ -465,13 +467,11 @@ static int simplefb_attach_genpds(struct simplefb_par *par,
 		return err;
 	}
 
-	par->num_genpds = err;
-
 	/*
 	 * Single power-domain devices are handled by the driver core, so
 	 * nothing to do here.
 	 */
-	if (par->num_genpds <= 1)
+	if (err <= 1)
 		return 0;
 
 	par->genpds = devm_kcalloc(dev, par->num_genpds, sizeof(*par->genpds),
@@ -485,6 +485,12 @@ static int simplefb_attach_genpds(struct simplefb_par *par,
 	if (!par->genpd_links)
 		return -ENOMEM;
 
+	/*
+	 * Set num_genpds only after genpds and genpd_links are allocated to
+	 * exit early from simplefb_detach_genpds() without full initialisation.
+	 */
+	par->num_genpds = err;
+
 	for (i = 0; i < par->num_genpds; i++) {
 		par->genpds[i] = dev_pm_domain_attach_by_id(dev, i);
 		if (IS_ERR(par->genpds[i])) {
@@ -506,9 +512,10 @@ static int simplefb_attach_genpds(struct simplefb_par *par,
 			dev_warn(dev, "failed to link power-domain %u\n", i);
 	}
 
-	return devm_add_action_or_reset(dev, simplefb_detach_genpds, par);
+	return 0;
 }
 #else
+static void simplefb_detach_genpds(void *res) { }
 static int simplefb_attach_genpds(struct simplefb_par *par,
 				  struct platform_device *pdev)
 {

---
base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585
change-id: 20250901-simplefb-genpd-uaf-352704761a29

Best regards,
-- 
Janne Grunau <j@jannau.net>


^ permalink raw reply related

* [PATCH] fbdev: mb862xxfb: Use int type to store negative error codes
From: Qianfeng Rong @ 2025-08-30 12:47 UTC (permalink / raw)
  To: Helge Deller, Thomas Zimmermann, Qianfeng Rong,
	Uwe Kleine-König, linux-fbdev, dri-devel, linux-kernel

Change the 'ret' variable in of_platform_mb862xx_probe() from unsigned long
to int, as it needs to store either negative error codes or zero.

Storing the negative error codes in unsigned type, doesn't cause an issue
at runtime but can be confusing. Additionally, assigning negative error
codes to unsigned type may trigger a GCC warning when the -Wsign-conversion
flag is enabled.

No effect on runtime.

Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
---
 drivers/video/fbdev/mb862xx/mb862xxfbdrv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/mb862xx/mb862xxfbdrv.c b/drivers/video/fbdev/mb862xx/mb862xxfbdrv.c
index ade88e7bc760..676c6d3ccc12 100644
--- a/drivers/video/fbdev/mb862xx/mb862xxfbdrv.c
+++ b/drivers/video/fbdev/mb862xx/mb862xxfbdrv.c
@@ -674,7 +674,7 @@ static int of_platform_mb862xx_probe(struct platform_device *ofdev)
 	struct fb_info *info;
 	struct resource res;
 	resource_size_t res_size;
-	unsigned long ret = -ENODEV;
+	int ret = -ENODEV;
 
 	if (of_address_to_resource(np, 0, &res)) {
 		dev_err(dev, "Invalid address\n");
-- 
2.34.1


^ permalink raw reply related

* Re: [PATCH V0 1/2] hyper-v: Add CONFIG_HYPERV_VMBUS option
From: Mukesh R @ 2025-08-29 20:59 UTC (permalink / raw)
  To: Nuno Das Neves, dri-devel, linux-kernel, linux-input,
	linux-hyperv, netdev, linux-pci, linux-scsi, linux-fbdev,
	linux-arch, virtualization
  Cc: maarten.lankhorst, mripard, tzimmermann, airlied, simona, jikos,
	bentiss, kys, haiyangz, wei.liu, decui, dmitry.torokhov,
	andrew+netdev, davem, edumazet, kuba, pabeni, bhelgaas,
	James.Bottomley, martin.petersen, gregkh, deller, arnd, sgarzare,
	horms
In-Reply-To: <5003d5e8-a025-4827-b8a0-6fe11877421b@linux.microsoft.com>

On 8/28/25 17:29, Nuno Das Neves wrote:
> On 8/27/2025 5:59 PM, Mukesh Rathor wrote:
>> Somehow vmbus driver is hinged on CONFIG_HYPERV. It appears this is initial
>> code that did not get addressed when the scope of CONFIG_HYPERV went beyond
>> vmbus. This commit creates a fine grained HYPERV_VMBUS option and updates
>> drivers that depend on VMBUS.
>>
> 
> The commit message can be improved. The docs are helpful here:
> https://docs.kernel.org/process/submitting-patches.html#describe-your-changes
> 
> In particular, some clearer reasons for the change.
> e.g.
> - CONFIG_HYPERV encompasses too much right now. It's not always clear what
>   depends on builtin hyperv code and what depends on vmbus.
> 
> - Since there is so much builtin hyperv code, building CONFIG_HYPERV as a
>   module doesn't make intuitive sense. Building vmbus support as a module does.
> 
> - There are actually some real scenarios someone may want to compile with
>   CONFIG_HYPERV but without vmbus, like baremetal root partition.
> 
> FWIW I think it's a good idea, interested to hear what others think.

Sorry, you had mentioned it and I expanded the cover letter and forgot the
commit message here. You said it better than I could above, so I can just use
that in V1 next week if no other comments.

Thanks,
-Mukesh


> Nuno
> 
>> Signed-off-by: Mukesh Rathor <mrathor@linux.microsoft.com>
>> ---
>>  drivers/gpu/drm/Kconfig        |  2 +-
>>  drivers/hid/Kconfig            |  2 +-
>>  drivers/hv/Kconfig             | 12 +++++++++---
>>  drivers/hv/Makefile            |  2 +-
>>  drivers/input/serio/Kconfig    |  4 ++--
>>  drivers/net/hyperv/Kconfig     |  2 +-
>>  drivers/pci/Kconfig            |  2 +-
>>  drivers/scsi/Kconfig           |  2 +-
>>  drivers/uio/Kconfig            |  2 +-
>>  drivers/video/fbdev/Kconfig    |  2 +-
>>  include/asm-generic/mshyperv.h |  8 +++++---
>>  net/vmw_vsock/Kconfig          |  2 +-
>>  12 files changed, 25 insertions(+), 17 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
>> index f7ea8e895c0c..58f34da061c6 100644
>> --- a/drivers/gpu/drm/Kconfig
>> +++ b/drivers/gpu/drm/Kconfig
>> @@ -398,7 +398,7 @@ source "drivers/gpu/drm/imagination/Kconfig"
>>  
>>  config DRM_HYPERV
>>  	tristate "DRM Support for Hyper-V synthetic video device"
>> -	depends on DRM && PCI && HYPERV
>> +	depends on DRM && PCI && HYPERV_VMBUS
>>  	select DRM_CLIENT_SELECTION
>>  	select DRM_KMS_HELPER
>>  	select DRM_GEM_SHMEM_HELPER
>> diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
>> index a57901203aeb..fe3dc8c0db99 100644
>> --- a/drivers/hid/Kconfig
>> +++ b/drivers/hid/Kconfig
>> @@ -1162,7 +1162,7 @@ config GREENASIA_FF
>>  
>>  config HID_HYPERV_MOUSE
>>  	tristate "Microsoft Hyper-V mouse driver"
>> -	depends on HYPERV
>> +	depends on HYPERV_VMBUS
>>  	help
>>  	Select this option to enable the Hyper-V mouse driver.
>>  
>> diff --git a/drivers/hv/Kconfig b/drivers/hv/Kconfig
>> index 2e8df09db599..08c4ed005137 100644
>> --- a/drivers/hv/Kconfig
>> +++ b/drivers/hv/Kconfig
>> @@ -44,18 +44,24 @@ config HYPERV_TIMER
>>  
>>  config HYPERV_UTILS
>>  	tristate "Microsoft Hyper-V Utilities driver"
>> -	depends on HYPERV && CONNECTOR && NLS
>> +	depends on HYPERV_VMBUS && CONNECTOR && NLS
>>  	depends on PTP_1588_CLOCK_OPTIONAL
>>  	help
>>  	  Select this option to enable the Hyper-V Utilities.
>>  
>>  config HYPERV_BALLOON
>>  	tristate "Microsoft Hyper-V Balloon driver"
>> -	depends on HYPERV
>> +	depends on HYPERV_VMBUS
>>  	select PAGE_REPORTING
>>  	help
>>  	  Select this option to enable Hyper-V Balloon driver.
>>  
>> +config HYPERV_VMBUS
>> +	tristate "Microsoft Hyper-V Vmbus driver"
>> +	depends on HYPERV
>> +	help
>> +	  Select this option to enable Hyper-V Vmbus driver.
>> +
>>  config MSHV_ROOT
>>  	tristate "Microsoft Hyper-V root partition support"
>>  	depends on HYPERV && (X86_64 || ARM64)
>> @@ -75,7 +81,7 @@ config MSHV_ROOT
>>  
>>  config MSHV_VTL
>>  	tristate "Microsoft Hyper-V VTL driver"
>> -	depends on X86_64 && HYPERV_VTL_MODE
>> +	depends on X86_64 && HYPERV_VTL_MODE && HYPERV_VMBUS
>>  	# Mapping VTL0 memory to a userspace process in VTL2 is supported in OpenHCL.
>>  	# VTL2 for OpenHCL makes use of Huge Pages to improve performance on VMs,
>>  	# specially with large memory requirements.
>> diff --git a/drivers/hv/Makefile b/drivers/hv/Makefile
>> index c53a0df746b7..050517756a82 100644
>> --- a/drivers/hv/Makefile
>> +++ b/drivers/hv/Makefile
>> @@ -1,5 +1,5 @@
>>  # SPDX-License-Identifier: GPL-2.0
>> -obj-$(CONFIG_HYPERV)		+= hv_vmbus.o
>> +obj-$(CONFIG_HYPERV_VMBUS)	+= hv_vmbus.o
>>  obj-$(CONFIG_HYPERV_UTILS)	+= hv_utils.o
>>  obj-$(CONFIG_HYPERV_BALLOON)	+= hv_balloon.o
>>  obj-$(CONFIG_MSHV_ROOT)		+= mshv_root.o
>> diff --git a/drivers/input/serio/Kconfig b/drivers/input/serio/Kconfig
>> index 17edc1597446..c7ef347a4dff 100644
>> --- a/drivers/input/serio/Kconfig
>> +++ b/drivers/input/serio/Kconfig
>> @@ -276,8 +276,8 @@ config SERIO_OLPC_APSP
>>  
>>  config HYPERV_KEYBOARD
>>  	tristate "Microsoft Synthetic Keyboard driver"
>> -	depends on HYPERV
>> -	default HYPERV
>> +	depends on HYPERV_VMBUS
>> +	default HYPERV_VMBUS
>>  	help
>>  	  Select this option to enable the Hyper-V Keyboard driver.
>>  
>> diff --git a/drivers/net/hyperv/Kconfig b/drivers/net/hyperv/Kconfig
>> index c8cbd85adcf9..982964c1a9fb 100644
>> --- a/drivers/net/hyperv/Kconfig
>> +++ b/drivers/net/hyperv/Kconfig
>> @@ -1,7 +1,7 @@
>>  # SPDX-License-Identifier: GPL-2.0-only
>>  config HYPERV_NET
>>  	tristate "Microsoft Hyper-V virtual network driver"
>> -	depends on HYPERV
>> +	depends on HYPERV_VMBUS
>>  	select UCS2_STRING
>>  	select NLS
>>  	help
>> diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
>> index 9a249c65aedc..7065a8e5f9b1 100644
>> --- a/drivers/pci/Kconfig
>> +++ b/drivers/pci/Kconfig
>> @@ -221,7 +221,7 @@ config PCI_LABEL
>>  
>>  config PCI_HYPERV
>>  	tristate "Hyper-V PCI Frontend"
>> -	depends on ((X86 && X86_64) || ARM64) && HYPERV && PCI_MSI && SYSFS
>> +	depends on ((X86 && X86_64) || ARM64) && HYPERV_VMBUS && PCI_MSI && SYSFS
>>  	select PCI_HYPERV_INTERFACE
>>  	select IRQ_MSI_LIB
>>  	help
>> diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
>> index 5522310bab8d..19d0884479a2 100644
>> --- a/drivers/scsi/Kconfig
>> +++ b/drivers/scsi/Kconfig
>> @@ -589,7 +589,7 @@ config XEN_SCSI_FRONTEND
>>  
>>  config HYPERV_STORAGE
>>  	tristate "Microsoft Hyper-V virtual storage driver"
>> -	depends on SCSI && HYPERV
>> +	depends on SCSI && HYPERV_VMBUS
>>  	depends on m || SCSI_FC_ATTRS != m
>>  	default HYPERV
>>  	help
>> diff --git a/drivers/uio/Kconfig b/drivers/uio/Kconfig
>> index b060dcd7c635..6f86a61231e6 100644
>> --- a/drivers/uio/Kconfig
>> +++ b/drivers/uio/Kconfig
>> @@ -140,7 +140,7 @@ config UIO_MF624
>>  
>>  config UIO_HV_GENERIC
>>  	tristate "Generic driver for Hyper-V VMBus"
>> -	depends on HYPERV
>> +	depends on HYPERV_VMBUS
>>  	help
>>  	  Generic driver that you can bind, dynamically, to any
>>  	  Hyper-V VMBus device. It is useful to provide direct access
>> diff --git a/drivers/video/fbdev/Kconfig b/drivers/video/fbdev/Kconfig
>> index c21484d15f0c..72c63eaeb983 100644
>> --- a/drivers/video/fbdev/Kconfig
>> +++ b/drivers/video/fbdev/Kconfig
>> @@ -1774,7 +1774,7 @@ config FB_BROADSHEET
>>  
>>  config FB_HYPERV
>>  	tristate "Microsoft Hyper-V Synthetic Video support"
>> -	depends on FB && HYPERV
>> +	depends on FB && HYPERV_VMBUS
>>  	select DMA_CMA if HAVE_DMA_CONTIGUOUS && CMA
>>  	select FB_IOMEM_HELPERS_DEFERRED
>>  	help
>> diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
>> index 1d2ad1304ad4..66c58c91b530 100644
>> --- a/include/asm-generic/mshyperv.h
>> +++ b/include/asm-generic/mshyperv.h
>> @@ -165,6 +165,7 @@ static inline u64 hv_generate_guest_id(u64 kernel_version)
>>  
>>  void __init hv_mark_resources(void);
>>  
>> +#if IS_ENABLED(CONFIG_HYPERV_VMBUS)
>>  /* Free the message slot and signal end-of-message if required */
>>  static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type)
>>  {
>> @@ -200,6 +201,10 @@ static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type)
>>  	}
>>  }
>>  
>> +extern int vmbus_interrupt;
>> +extern int vmbus_irq;
>> +#endif /* CONFIG_HYPERV_VMBUS */
>> +
>>  int hv_get_hypervisor_version(union hv_hypervisor_version_info *info);
>>  
>>  void hv_setup_vmbus_handler(void (*handler)(void));
>> @@ -213,9 +218,6 @@ void hv_setup_crash_handler(void (*handler)(struct pt_regs *regs));
>>  void hv_remove_crash_handler(void);
>>  void hv_setup_mshv_handler(void (*handler)(void));
>>  
>> -extern int vmbus_interrupt;
>> -extern int vmbus_irq;
>> -
>>  #if IS_ENABLED(CONFIG_HYPERV)
>>  /*
>>   * Hypervisor's notion of virtual processor ID is different from
>> diff --git a/net/vmw_vsock/Kconfig b/net/vmw_vsock/Kconfig
>> index 56356d2980c8..8e803c4828c4 100644
>> --- a/net/vmw_vsock/Kconfig
>> +++ b/net/vmw_vsock/Kconfig
>> @@ -72,7 +72,7 @@ config VIRTIO_VSOCKETS_COMMON
>>  
>>  config HYPERV_VSOCKETS
>>  	tristate "Hyper-V transport for Virtual Sockets"
>> -	depends on VSOCKETS && HYPERV
>> +	depends on VSOCKETS && HYPERV_VMBUS
>>  	help
>>  	  This module implements a Hyper-V transport for Virtual Sockets.
>>  


^ permalink raw reply

* Re: [PATCH v2 3/9] crash_core: use panic_try_start() in crash_kexec()
From: Jinchao Wang @ 2025-08-29  4:39 UTC (permalink / raw)
  To: Qianqiang Liu
  Cc: Andrew Morton, Baoquan He, Yury Norov, Simona Vetter,
	Helge Deller, Petr Mladek, Steven Rostedt, John Ogness,
	Sergey Senozhatsky, Vivek Goyal, Dave Young, Kees Cook, Tony Luck,
	Guilherme G. Piccoli, Thomas Zimmermann, Ville Syrjälä,
	Shixiong Ou, Zsolt Kajtar, Ingo Molnar, Nam Cao, Jonathan Cameron,
	Joel Fernandes, Joel Granados, Jason Gunthorpe, Sohil Mehta,
	Feng Tang, Sravan Kumar Gundu, Douglas Anderson, Thomas Gleixner,
	Anna Schumaker, Darrick J. Wong, Max Kellermann, Yunhui Cui,
	Tejun Heo, Luo Gengkun, Li Huafei, Thorsten Blum, Yicong Yang,
	linux-fbdev, dri-devel, kexec, linux-hardening, linux-kernel
In-Reply-To: <aLEQy-srX89Rndch@debian.debian.local>

On 8/29/25 10:30, Qianqiang Liu wrote:
> On Mon, Aug 25, 2025 at 10:29:31AM +0800, Jinchao Wang wrote:
>> crash_kexec() had its own code to exclude parallel execution by setting
>> panic_cpu. This is already handled by panic_try_start(). Switch to
>> panic_try_start() to remove the duplication and keep the logic consistent.
>>
>> Signed-off-by: Jinchao Wang <wangjinchao600@gmail.com>
>> ---
>>   kernel/crash_core.c | 15 +++------------
>>   1 file changed, 3 insertions(+), 12 deletions(-)
>>
>> diff --git a/kernel/crash_core.c b/kernel/crash_core.c
>> index a4ef79591eb2..bb38bbaf3a26 100644
>> --- a/kernel/crash_core.c
>> +++ b/kernel/crash_core.c
>> @@ -4,6 +4,7 @@
>>    * Copyright (C) 2002-2004 Eric Biederman  <ebiederm@xmission.com>
>>    */
>>   
>> +#include "linux/panic.h"
> 
> Can you change this line of code to #include <linux/panic.h>?
Yes, I will.
Thanks for the feedback.>
>>   #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
>>   
>>   #include <linux/buildid.h>
>> @@ -143,17 +144,7 @@ STACK_FRAME_NON_STANDARD(__crash_kexec);
>>   
>>   __bpf_kfunc void crash_kexec(struct pt_regs *regs)
>>   {
>> -	int old_cpu, this_cpu;
>> -
>> -	/*
>> -	 * Only one CPU is allowed to execute the crash_kexec() code as with
>> -	 * panic().  Otherwise parallel calls of panic() and crash_kexec()
>> -	 * may stop each other.  To exclude them, we use panic_cpu here too.
>> -	 */
>> -	old_cpu = PANIC_CPU_INVALID;
>> -	this_cpu = raw_smp_processor_id();
>> -
>> -	if (atomic_try_cmpxchg(&panic_cpu, &old_cpu, this_cpu)) {
>> +	if (panic_try_start()) {
>>   		/* This is the 1st CPU which comes here, so go ahead. */
>>   		__crash_kexec(regs);
>>   
>> @@ -161,7 +152,7 @@ __bpf_kfunc void crash_kexec(struct pt_regs *regs)
>>   		 * Reset panic_cpu to allow another panic()/crash_kexec()
>>   		 * call.
>>   		 */
>> -		atomic_set(&panic_cpu, PANIC_CPU_INVALID);
>> +		panic_reset();
>>   	}
>>   }
>>   
>> -- 
>> 2.43.0
> 


-- 
Best regards,
Jinchao

^ permalink raw reply

* Re: [PATCH v2 3/9] crash_core: use panic_try_start() in crash_kexec()
From: Qianqiang Liu @ 2025-08-29  2:30 UTC (permalink / raw)
  To: Jinchao Wang
  Cc: Andrew Morton, Baoquan He, Yury Norov, Simona Vetter,
	Helge Deller, Petr Mladek, Steven Rostedt, John Ogness,
	Sergey Senozhatsky, Vivek Goyal, Dave Young, Kees Cook, Tony Luck,
	Guilherme G. Piccoli, Thomas Zimmermann, Ville Syrjälä,
	Shixiong Ou, Zsolt Kajtar, Ingo Molnar, Nam Cao, Jonathan Cameron,
	Joel Fernandes, Joel Granados, Jason Gunthorpe, Sohil Mehta,
	Feng Tang, Sravan Kumar Gundu, Douglas Anderson, Thomas Gleixner,
	Anna Schumaker, Darrick J. Wong, Max Kellermann, Yunhui Cui,
	Tejun Heo, Luo Gengkun, Li Huafei, Thorsten Blum, Yicong Yang,
	linux-fbdev, dri-devel, kexec, linux-hardening, linux-kernel
In-Reply-To: <20250825022947.1596226-4-wangjinchao600@gmail.com>

On Mon, Aug 25, 2025 at 10:29:31AM +0800, Jinchao Wang wrote:
> crash_kexec() had its own code to exclude parallel execution by setting
> panic_cpu. This is already handled by panic_try_start(). Switch to
> panic_try_start() to remove the duplication and keep the logic consistent.
> 
> Signed-off-by: Jinchao Wang <wangjinchao600@gmail.com>
> ---
>  kernel/crash_core.c | 15 +++------------
>  1 file changed, 3 insertions(+), 12 deletions(-)
> 
> diff --git a/kernel/crash_core.c b/kernel/crash_core.c
> index a4ef79591eb2..bb38bbaf3a26 100644
> --- a/kernel/crash_core.c
> +++ b/kernel/crash_core.c
> @@ -4,6 +4,7 @@
>   * Copyright (C) 2002-2004 Eric Biederman  <ebiederm@xmission.com>
>   */
>  
> +#include "linux/panic.h"

Can you change this line of code to #include <linux/panic.h>?

>  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
>  
>  #include <linux/buildid.h>
> @@ -143,17 +144,7 @@ STACK_FRAME_NON_STANDARD(__crash_kexec);
>  
>  __bpf_kfunc void crash_kexec(struct pt_regs *regs)
>  {
> -	int old_cpu, this_cpu;
> -
> -	/*
> -	 * Only one CPU is allowed to execute the crash_kexec() code as with
> -	 * panic().  Otherwise parallel calls of panic() and crash_kexec()
> -	 * may stop each other.  To exclude them, we use panic_cpu here too.
> -	 */
> -	old_cpu = PANIC_CPU_INVALID;
> -	this_cpu = raw_smp_processor_id();
> -
> -	if (atomic_try_cmpxchg(&panic_cpu, &old_cpu, this_cpu)) {
> +	if (panic_try_start()) {
>  		/* This is the 1st CPU which comes here, so go ahead. */
>  		__crash_kexec(regs);
>  
> @@ -161,7 +152,7 @@ __bpf_kfunc void crash_kexec(struct pt_regs *regs)
>  		 * Reset panic_cpu to allow another panic()/crash_kexec()
>  		 * call.
>  		 */
> -		atomic_set(&panic_cpu, PANIC_CPU_INVALID);
> +		panic_reset();
>  	}
>  }
>  
> -- 
> 2.43.0

-- 
Best,
Qianqiang Liu


^ permalink raw reply

* Re: [PATCH V0 1/2] hyper-v: Add CONFIG_HYPERV_VMBUS option
From: Nuno Das Neves @ 2025-08-29  0:29 UTC (permalink / raw)
  To: Mukesh Rathor, dri-devel, linux-kernel, linux-input, linux-hyperv,
	netdev, linux-pci, linux-scsi, linux-fbdev, linux-arch,
	virtualization
  Cc: maarten.lankhorst, mripard, tzimmermann, airlied, simona, jikos,
	bentiss, kys, haiyangz, wei.liu, decui, dmitry.torokhov,
	andrew+netdev, davem, edumazet, kuba, pabeni, bhelgaas,
	James.Bottomley, martin.petersen, gregkh, deller, arnd, sgarzare,
	horms
In-Reply-To: <20250828005952.884343-2-mrathor@linux.microsoft.com>

On 8/27/2025 5:59 PM, Mukesh Rathor wrote:
> Somehow vmbus driver is hinged on CONFIG_HYPERV. It appears this is initial
> code that did not get addressed when the scope of CONFIG_HYPERV went beyond
> vmbus. This commit creates a fine grained HYPERV_VMBUS option and updates
> drivers that depend on VMBUS.
> 

The commit message can be improved. The docs are helpful here:
https://docs.kernel.org/process/submitting-patches.html#describe-your-changes

In particular, some clearer reasons for the change.
e.g.
- CONFIG_HYPERV encompasses too much right now. It's not always clear what
  depends on builtin hyperv code and what depends on vmbus.

- Since there is so much builtin hyperv code, building CONFIG_HYPERV as a
  module doesn't make intuitive sense. Building vmbus support as a module does.

- There are actually some real scenarios someone may want to compile with
  CONFIG_HYPERV but without vmbus, like baremetal root partition.

FWIW I think it's a good idea, interested to hear what others think.

Nuno

> Signed-off-by: Mukesh Rathor <mrathor@linux.microsoft.com>
> ---
>  drivers/gpu/drm/Kconfig        |  2 +-
>  drivers/hid/Kconfig            |  2 +-
>  drivers/hv/Kconfig             | 12 +++++++++---
>  drivers/hv/Makefile            |  2 +-
>  drivers/input/serio/Kconfig    |  4 ++--
>  drivers/net/hyperv/Kconfig     |  2 +-
>  drivers/pci/Kconfig            |  2 +-
>  drivers/scsi/Kconfig           |  2 +-
>  drivers/uio/Kconfig            |  2 +-
>  drivers/video/fbdev/Kconfig    |  2 +-
>  include/asm-generic/mshyperv.h |  8 +++++---
>  net/vmw_vsock/Kconfig          |  2 +-
>  12 files changed, 25 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
> index f7ea8e895c0c..58f34da061c6 100644
> --- a/drivers/gpu/drm/Kconfig
> +++ b/drivers/gpu/drm/Kconfig
> @@ -398,7 +398,7 @@ source "drivers/gpu/drm/imagination/Kconfig"
>  
>  config DRM_HYPERV
>  	tristate "DRM Support for Hyper-V synthetic video device"
> -	depends on DRM && PCI && HYPERV
> +	depends on DRM && PCI && HYPERV_VMBUS
>  	select DRM_CLIENT_SELECTION
>  	select DRM_KMS_HELPER
>  	select DRM_GEM_SHMEM_HELPER
> diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
> index a57901203aeb..fe3dc8c0db99 100644
> --- a/drivers/hid/Kconfig
> +++ b/drivers/hid/Kconfig
> @@ -1162,7 +1162,7 @@ config GREENASIA_FF
>  
>  config HID_HYPERV_MOUSE
>  	tristate "Microsoft Hyper-V mouse driver"
> -	depends on HYPERV
> +	depends on HYPERV_VMBUS
>  	help
>  	Select this option to enable the Hyper-V mouse driver.
>  
> diff --git a/drivers/hv/Kconfig b/drivers/hv/Kconfig
> index 2e8df09db599..08c4ed005137 100644
> --- a/drivers/hv/Kconfig
> +++ b/drivers/hv/Kconfig
> @@ -44,18 +44,24 @@ config HYPERV_TIMER
>  
>  config HYPERV_UTILS
>  	tristate "Microsoft Hyper-V Utilities driver"
> -	depends on HYPERV && CONNECTOR && NLS
> +	depends on HYPERV_VMBUS && CONNECTOR && NLS
>  	depends on PTP_1588_CLOCK_OPTIONAL
>  	help
>  	  Select this option to enable the Hyper-V Utilities.
>  
>  config HYPERV_BALLOON
>  	tristate "Microsoft Hyper-V Balloon driver"
> -	depends on HYPERV
> +	depends on HYPERV_VMBUS
>  	select PAGE_REPORTING
>  	help
>  	  Select this option to enable Hyper-V Balloon driver.
>  
> +config HYPERV_VMBUS
> +	tristate "Microsoft Hyper-V Vmbus driver"
> +	depends on HYPERV
> +	help
> +	  Select this option to enable Hyper-V Vmbus driver.
> +
>  config MSHV_ROOT
>  	tristate "Microsoft Hyper-V root partition support"
>  	depends on HYPERV && (X86_64 || ARM64)
> @@ -75,7 +81,7 @@ config MSHV_ROOT
>  
>  config MSHV_VTL
>  	tristate "Microsoft Hyper-V VTL driver"
> -	depends on X86_64 && HYPERV_VTL_MODE
> +	depends on X86_64 && HYPERV_VTL_MODE && HYPERV_VMBUS
>  	# Mapping VTL0 memory to a userspace process in VTL2 is supported in OpenHCL.
>  	# VTL2 for OpenHCL makes use of Huge Pages to improve performance on VMs,
>  	# specially with large memory requirements.
> diff --git a/drivers/hv/Makefile b/drivers/hv/Makefile
> index c53a0df746b7..050517756a82 100644
> --- a/drivers/hv/Makefile
> +++ b/drivers/hv/Makefile
> @@ -1,5 +1,5 @@
>  # SPDX-License-Identifier: GPL-2.0
> -obj-$(CONFIG_HYPERV)		+= hv_vmbus.o
> +obj-$(CONFIG_HYPERV_VMBUS)	+= hv_vmbus.o
>  obj-$(CONFIG_HYPERV_UTILS)	+= hv_utils.o
>  obj-$(CONFIG_HYPERV_BALLOON)	+= hv_balloon.o
>  obj-$(CONFIG_MSHV_ROOT)		+= mshv_root.o
> diff --git a/drivers/input/serio/Kconfig b/drivers/input/serio/Kconfig
> index 17edc1597446..c7ef347a4dff 100644
> --- a/drivers/input/serio/Kconfig
> +++ b/drivers/input/serio/Kconfig
> @@ -276,8 +276,8 @@ config SERIO_OLPC_APSP
>  
>  config HYPERV_KEYBOARD
>  	tristate "Microsoft Synthetic Keyboard driver"
> -	depends on HYPERV
> -	default HYPERV
> +	depends on HYPERV_VMBUS
> +	default HYPERV_VMBUS
>  	help
>  	  Select this option to enable the Hyper-V Keyboard driver.
>  
> diff --git a/drivers/net/hyperv/Kconfig b/drivers/net/hyperv/Kconfig
> index c8cbd85adcf9..982964c1a9fb 100644
> --- a/drivers/net/hyperv/Kconfig
> +++ b/drivers/net/hyperv/Kconfig
> @@ -1,7 +1,7 @@
>  # SPDX-License-Identifier: GPL-2.0-only
>  config HYPERV_NET
>  	tristate "Microsoft Hyper-V virtual network driver"
> -	depends on HYPERV
> +	depends on HYPERV_VMBUS
>  	select UCS2_STRING
>  	select NLS
>  	help
> diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
> index 9a249c65aedc..7065a8e5f9b1 100644
> --- a/drivers/pci/Kconfig
> +++ b/drivers/pci/Kconfig
> @@ -221,7 +221,7 @@ config PCI_LABEL
>  
>  config PCI_HYPERV
>  	tristate "Hyper-V PCI Frontend"
> -	depends on ((X86 && X86_64) || ARM64) && HYPERV && PCI_MSI && SYSFS
> +	depends on ((X86 && X86_64) || ARM64) && HYPERV_VMBUS && PCI_MSI && SYSFS
>  	select PCI_HYPERV_INTERFACE
>  	select IRQ_MSI_LIB
>  	help
> diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
> index 5522310bab8d..19d0884479a2 100644
> --- a/drivers/scsi/Kconfig
> +++ b/drivers/scsi/Kconfig
> @@ -589,7 +589,7 @@ config XEN_SCSI_FRONTEND
>  
>  config HYPERV_STORAGE
>  	tristate "Microsoft Hyper-V virtual storage driver"
> -	depends on SCSI && HYPERV
> +	depends on SCSI && HYPERV_VMBUS
>  	depends on m || SCSI_FC_ATTRS != m
>  	default HYPERV
>  	help
> diff --git a/drivers/uio/Kconfig b/drivers/uio/Kconfig
> index b060dcd7c635..6f86a61231e6 100644
> --- a/drivers/uio/Kconfig
> +++ b/drivers/uio/Kconfig
> @@ -140,7 +140,7 @@ config UIO_MF624
>  
>  config UIO_HV_GENERIC
>  	tristate "Generic driver for Hyper-V VMBus"
> -	depends on HYPERV
> +	depends on HYPERV_VMBUS
>  	help
>  	  Generic driver that you can bind, dynamically, to any
>  	  Hyper-V VMBus device. It is useful to provide direct access
> diff --git a/drivers/video/fbdev/Kconfig b/drivers/video/fbdev/Kconfig
> index c21484d15f0c..72c63eaeb983 100644
> --- a/drivers/video/fbdev/Kconfig
> +++ b/drivers/video/fbdev/Kconfig
> @@ -1774,7 +1774,7 @@ config FB_BROADSHEET
>  
>  config FB_HYPERV
>  	tristate "Microsoft Hyper-V Synthetic Video support"
> -	depends on FB && HYPERV
> +	depends on FB && HYPERV_VMBUS
>  	select DMA_CMA if HAVE_DMA_CONTIGUOUS && CMA
>  	select FB_IOMEM_HELPERS_DEFERRED
>  	help
> diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
> index 1d2ad1304ad4..66c58c91b530 100644
> --- a/include/asm-generic/mshyperv.h
> +++ b/include/asm-generic/mshyperv.h
> @@ -165,6 +165,7 @@ static inline u64 hv_generate_guest_id(u64 kernel_version)
>  
>  void __init hv_mark_resources(void);
>  
> +#if IS_ENABLED(CONFIG_HYPERV_VMBUS)
>  /* Free the message slot and signal end-of-message if required */
>  static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type)
>  {
> @@ -200,6 +201,10 @@ static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type)
>  	}
>  }
>  
> +extern int vmbus_interrupt;
> +extern int vmbus_irq;
> +#endif /* CONFIG_HYPERV_VMBUS */
> +
>  int hv_get_hypervisor_version(union hv_hypervisor_version_info *info);
>  
>  void hv_setup_vmbus_handler(void (*handler)(void));
> @@ -213,9 +218,6 @@ void hv_setup_crash_handler(void (*handler)(struct pt_regs *regs));
>  void hv_remove_crash_handler(void);
>  void hv_setup_mshv_handler(void (*handler)(void));
>  
> -extern int vmbus_interrupt;
> -extern int vmbus_irq;
> -
>  #if IS_ENABLED(CONFIG_HYPERV)
>  /*
>   * Hypervisor's notion of virtual processor ID is different from
> diff --git a/net/vmw_vsock/Kconfig b/net/vmw_vsock/Kconfig
> index 56356d2980c8..8e803c4828c4 100644
> --- a/net/vmw_vsock/Kconfig
> +++ b/net/vmw_vsock/Kconfig
> @@ -72,7 +72,7 @@ config VIRTIO_VSOCKETS_COMMON
>  
>  config HYPERV_VSOCKETS
>  	tristate "Hyper-V transport for Virtual Sockets"
> -	depends on VSOCKETS && HYPERV
> +	depends on VSOCKETS && HYPERV_VMBUS
>  	help
>  	  This module implements a Hyper-V transport for Virtual Sockets.
>  


^ permalink raw reply

* [PATCH V0 2/2] hyper-v: Make CONFIG_HYPERV bool
From: Mukesh Rathor @ 2025-08-28  0:59 UTC (permalink / raw)
  To: dri-devel, linux-kernel, linux-input, linux-hyperv, netdev,
	linux-pci, linux-scsi, linux-fbdev, linux-arch, virtualization
  Cc: maarten.lankhorst, mripard, tzimmermann, airlied, simona, jikos,
	bentiss, kys, haiyangz, wei.liu, decui, dmitry.torokhov,
	andrew+netdev, davem, edumazet, kuba, pabeni, bhelgaas,
	James.Bottomley, martin.petersen, gregkh, deller, arnd, sgarzare,
	horms
In-Reply-To: <20250828005952.884343-1-mrathor@linux.microsoft.com>

CONFIG_HYPERV is an umbrella config option involved in enabling hyperv
support and build of modules like hyperv-balloon, hyperv-vmbus, etc.. As
such it should be bool and the hack in Makefile be removed.

Signed-off-by: Mukesh Rathor <mrathor@linux.microsoft.com>
---
 drivers/Makefile    | 2 +-
 drivers/hv/Kconfig  | 2 +-
 drivers/hv/Makefile | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/Makefile b/drivers/Makefile
index b5749cf67044..7ad5744db0b6 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -161,7 +161,7 @@ obj-$(CONFIG_SOUNDWIRE)		+= soundwire/
 
 # Virtualization drivers
 obj-$(CONFIG_VIRT_DRIVERS)	+= virt/
-obj-$(subst m,y,$(CONFIG_HYPERV))	+= hv/
+obj-$(CONFIG_HYPERV)		+= hv/
 
 obj-$(CONFIG_PM_DEVFREQ)	+= devfreq/
 obj-$(CONFIG_EXTCON)		+= extcon/
diff --git a/drivers/hv/Kconfig b/drivers/hv/Kconfig
index 08c4ed005137..b860bc1026b7 100644
--- a/drivers/hv/Kconfig
+++ b/drivers/hv/Kconfig
@@ -3,7 +3,7 @@
 menu "Microsoft Hyper-V guest support"
 
 config HYPERV
-	tristate "Microsoft Hyper-V client drivers"
+	bool "Microsoft Hyper-V client drivers"
 	depends on (X86 && X86_LOCAL_APIC && HYPERVISOR_GUEST) \
 		|| (ARM64 && !CPU_BIG_ENDIAN)
 	select PARAVIRT
diff --git a/drivers/hv/Makefile b/drivers/hv/Makefile
index 050517756a82..8b04a33e4dd8 100644
--- a/drivers/hv/Makefile
+++ b/drivers/hv/Makefile
@@ -18,7 +18,7 @@ mshv_root-y := mshv_root_main.o mshv_synic.o mshv_eventfd.o mshv_irq.o \
 mshv_vtl-y := mshv_vtl_main.o
 
 # Code that must be built-in
-obj-$(subst m,y,$(CONFIG_HYPERV)) += hv_common.o
+obj-$(CONFIG_HYPERV) += hv_common.o
 obj-$(subst m,y,$(CONFIG_MSHV_ROOT)) += hv_proc.o
 ifneq ($(CONFIG_MSHV_ROOT) $(CONFIG_MSHV_VTL),)
     obj-y += mshv_common.o
-- 
2.36.1.vfs.0.0


^ permalink raw reply related

* [PATCH V0 1/2] hyper-v: Add CONFIG_HYPERV_VMBUS option
From: Mukesh Rathor @ 2025-08-28  0:59 UTC (permalink / raw)
  To: dri-devel, linux-kernel, linux-input, linux-hyperv, netdev,
	linux-pci, linux-scsi, linux-fbdev, linux-arch, virtualization
  Cc: maarten.lankhorst, mripard, tzimmermann, airlied, simona, jikos,
	bentiss, kys, haiyangz, wei.liu, decui, dmitry.torokhov,
	andrew+netdev, davem, edumazet, kuba, pabeni, bhelgaas,
	James.Bottomley, martin.petersen, gregkh, deller, arnd, sgarzare,
	horms
In-Reply-To: <20250828005952.884343-1-mrathor@linux.microsoft.com>

Somehow vmbus driver is hinged on CONFIG_HYPERV. It appears this is initial
code that did not get addressed when the scope of CONFIG_HYPERV went beyond
vmbus. This commit creates a fine grained HYPERV_VMBUS option and updates
drivers that depend on VMBUS.

Signed-off-by: Mukesh Rathor <mrathor@linux.microsoft.com>
---
 drivers/gpu/drm/Kconfig        |  2 +-
 drivers/hid/Kconfig            |  2 +-
 drivers/hv/Kconfig             | 12 +++++++++---
 drivers/hv/Makefile            |  2 +-
 drivers/input/serio/Kconfig    |  4 ++--
 drivers/net/hyperv/Kconfig     |  2 +-
 drivers/pci/Kconfig            |  2 +-
 drivers/scsi/Kconfig           |  2 +-
 drivers/uio/Kconfig            |  2 +-
 drivers/video/fbdev/Kconfig    |  2 +-
 include/asm-generic/mshyperv.h |  8 +++++---
 net/vmw_vsock/Kconfig          |  2 +-
 12 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index f7ea8e895c0c..58f34da061c6 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -398,7 +398,7 @@ source "drivers/gpu/drm/imagination/Kconfig"
 
 config DRM_HYPERV
 	tristate "DRM Support for Hyper-V synthetic video device"
-	depends on DRM && PCI && HYPERV
+	depends on DRM && PCI && HYPERV_VMBUS
 	select DRM_CLIENT_SELECTION
 	select DRM_KMS_HELPER
 	select DRM_GEM_SHMEM_HELPER
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index a57901203aeb..fe3dc8c0db99 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -1162,7 +1162,7 @@ config GREENASIA_FF
 
 config HID_HYPERV_MOUSE
 	tristate "Microsoft Hyper-V mouse driver"
-	depends on HYPERV
+	depends on HYPERV_VMBUS
 	help
 	Select this option to enable the Hyper-V mouse driver.
 
diff --git a/drivers/hv/Kconfig b/drivers/hv/Kconfig
index 2e8df09db599..08c4ed005137 100644
--- a/drivers/hv/Kconfig
+++ b/drivers/hv/Kconfig
@@ -44,18 +44,24 @@ config HYPERV_TIMER
 
 config HYPERV_UTILS
 	tristate "Microsoft Hyper-V Utilities driver"
-	depends on HYPERV && CONNECTOR && NLS
+	depends on HYPERV_VMBUS && CONNECTOR && NLS
 	depends on PTP_1588_CLOCK_OPTIONAL
 	help
 	  Select this option to enable the Hyper-V Utilities.
 
 config HYPERV_BALLOON
 	tristate "Microsoft Hyper-V Balloon driver"
-	depends on HYPERV
+	depends on HYPERV_VMBUS
 	select PAGE_REPORTING
 	help
 	  Select this option to enable Hyper-V Balloon driver.
 
+config HYPERV_VMBUS
+	tristate "Microsoft Hyper-V Vmbus driver"
+	depends on HYPERV
+	help
+	  Select this option to enable Hyper-V Vmbus driver.
+
 config MSHV_ROOT
 	tristate "Microsoft Hyper-V root partition support"
 	depends on HYPERV && (X86_64 || ARM64)
@@ -75,7 +81,7 @@ config MSHV_ROOT
 
 config MSHV_VTL
 	tristate "Microsoft Hyper-V VTL driver"
-	depends on X86_64 && HYPERV_VTL_MODE
+	depends on X86_64 && HYPERV_VTL_MODE && HYPERV_VMBUS
 	# Mapping VTL0 memory to a userspace process in VTL2 is supported in OpenHCL.
 	# VTL2 for OpenHCL makes use of Huge Pages to improve performance on VMs,
 	# specially with large memory requirements.
diff --git a/drivers/hv/Makefile b/drivers/hv/Makefile
index c53a0df746b7..050517756a82 100644
--- a/drivers/hv/Makefile
+++ b/drivers/hv/Makefile
@@ -1,5 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
-obj-$(CONFIG_HYPERV)		+= hv_vmbus.o
+obj-$(CONFIG_HYPERV_VMBUS)	+= hv_vmbus.o
 obj-$(CONFIG_HYPERV_UTILS)	+= hv_utils.o
 obj-$(CONFIG_HYPERV_BALLOON)	+= hv_balloon.o
 obj-$(CONFIG_MSHV_ROOT)		+= mshv_root.o
diff --git a/drivers/input/serio/Kconfig b/drivers/input/serio/Kconfig
index 17edc1597446..c7ef347a4dff 100644
--- a/drivers/input/serio/Kconfig
+++ b/drivers/input/serio/Kconfig
@@ -276,8 +276,8 @@ config SERIO_OLPC_APSP
 
 config HYPERV_KEYBOARD
 	tristate "Microsoft Synthetic Keyboard driver"
-	depends on HYPERV
-	default HYPERV
+	depends on HYPERV_VMBUS
+	default HYPERV_VMBUS
 	help
 	  Select this option to enable the Hyper-V Keyboard driver.
 
diff --git a/drivers/net/hyperv/Kconfig b/drivers/net/hyperv/Kconfig
index c8cbd85adcf9..982964c1a9fb 100644
--- a/drivers/net/hyperv/Kconfig
+++ b/drivers/net/hyperv/Kconfig
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 config HYPERV_NET
 	tristate "Microsoft Hyper-V virtual network driver"
-	depends on HYPERV
+	depends on HYPERV_VMBUS
 	select UCS2_STRING
 	select NLS
 	help
diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index 9a249c65aedc..7065a8e5f9b1 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -221,7 +221,7 @@ config PCI_LABEL
 
 config PCI_HYPERV
 	tristate "Hyper-V PCI Frontend"
-	depends on ((X86 && X86_64) || ARM64) && HYPERV && PCI_MSI && SYSFS
+	depends on ((X86 && X86_64) || ARM64) && HYPERV_VMBUS && PCI_MSI && SYSFS
 	select PCI_HYPERV_INTERFACE
 	select IRQ_MSI_LIB
 	help
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 5522310bab8d..19d0884479a2 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -589,7 +589,7 @@ config XEN_SCSI_FRONTEND
 
 config HYPERV_STORAGE
 	tristate "Microsoft Hyper-V virtual storage driver"
-	depends on SCSI && HYPERV
+	depends on SCSI && HYPERV_VMBUS
 	depends on m || SCSI_FC_ATTRS != m
 	default HYPERV
 	help
diff --git a/drivers/uio/Kconfig b/drivers/uio/Kconfig
index b060dcd7c635..6f86a61231e6 100644
--- a/drivers/uio/Kconfig
+++ b/drivers/uio/Kconfig
@@ -140,7 +140,7 @@ config UIO_MF624
 
 config UIO_HV_GENERIC
 	tristate "Generic driver for Hyper-V VMBus"
-	depends on HYPERV
+	depends on HYPERV_VMBUS
 	help
 	  Generic driver that you can bind, dynamically, to any
 	  Hyper-V VMBus device. It is useful to provide direct access
diff --git a/drivers/video/fbdev/Kconfig b/drivers/video/fbdev/Kconfig
index c21484d15f0c..72c63eaeb983 100644
--- a/drivers/video/fbdev/Kconfig
+++ b/drivers/video/fbdev/Kconfig
@@ -1774,7 +1774,7 @@ config FB_BROADSHEET
 
 config FB_HYPERV
 	tristate "Microsoft Hyper-V Synthetic Video support"
-	depends on FB && HYPERV
+	depends on FB && HYPERV_VMBUS
 	select DMA_CMA if HAVE_DMA_CONTIGUOUS && CMA
 	select FB_IOMEM_HELPERS_DEFERRED
 	help
diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
index 1d2ad1304ad4..66c58c91b530 100644
--- a/include/asm-generic/mshyperv.h
+++ b/include/asm-generic/mshyperv.h
@@ -165,6 +165,7 @@ static inline u64 hv_generate_guest_id(u64 kernel_version)
 
 void __init hv_mark_resources(void);
 
+#if IS_ENABLED(CONFIG_HYPERV_VMBUS)
 /* Free the message slot and signal end-of-message if required */
 static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type)
 {
@@ -200,6 +201,10 @@ static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type)
 	}
 }
 
+extern int vmbus_interrupt;
+extern int vmbus_irq;
+#endif /* CONFIG_HYPERV_VMBUS */
+
 int hv_get_hypervisor_version(union hv_hypervisor_version_info *info);
 
 void hv_setup_vmbus_handler(void (*handler)(void));
@@ -213,9 +218,6 @@ void hv_setup_crash_handler(void (*handler)(struct pt_regs *regs));
 void hv_remove_crash_handler(void);
 void hv_setup_mshv_handler(void (*handler)(void));
 
-extern int vmbus_interrupt;
-extern int vmbus_irq;
-
 #if IS_ENABLED(CONFIG_HYPERV)
 /*
  * Hypervisor's notion of virtual processor ID is different from
diff --git a/net/vmw_vsock/Kconfig b/net/vmw_vsock/Kconfig
index 56356d2980c8..8e803c4828c4 100644
--- a/net/vmw_vsock/Kconfig
+++ b/net/vmw_vsock/Kconfig
@@ -72,7 +72,7 @@ config VIRTIO_VSOCKETS_COMMON
 
 config HYPERV_VSOCKETS
 	tristate "Hyper-V transport for Virtual Sockets"
-	depends on VSOCKETS && HYPERV
+	depends on VSOCKETS && HYPERV_VMBUS
 	help
 	  This module implements a Hyper-V transport for Virtual Sockets.
 
-- 
2.36.1.vfs.0.0


^ permalink raw reply related

* [PATCH V0 0/2] Fix CONFIG_HYPERV and vmbus related anamoly
From: Mukesh Rathor @ 2025-08-28  0:59 UTC (permalink / raw)
  To: dri-devel, linux-kernel, linux-input, linux-hyperv, netdev,
	linux-pci, linux-scsi, linux-fbdev, linux-arch, virtualization
  Cc: maarten.lankhorst, mripard, tzimmermann, airlied, simona, jikos,
	bentiss, kys, haiyangz, wei.liu, decui, dmitry.torokhov,
	andrew+netdev, davem, edumazet, kuba, pabeni, bhelgaas,
	James.Bottomley, martin.petersen, gregkh, deller, arnd, sgarzare,
	horms

At present, drivers/Makefile will subst =m to =y for CONFIG_HYPERV for hv
subdir. Also, drivers/hv/Makefile replaces =m to =y to build in
hv_common.c that is needed for the drivers. Moreover, vmbus driver is
built if CONFIG_HYPER is set, either loadable or builtin.

This is not a good approach. CONFIG_HYPERV is really an umbrella config that
encompasses builtin code and various other things and not a dedicated config
option for VMBUS. Vmbus should really have a config option just like
CONFIG_HYPERV_BALLOON etc. This small series introduces CONFIG_HYPERV_VMBUS
to build VMBUS driver and make that distinction explicit. With that
CONFIG_HYPERV could be changed to bool.

For now, hv_common.c is left as is to reduce conflicts for upcoming patches,
but once merges are mostly done, that and some others should be moved to
virt/hyperv directory.

Mukesh Rathor (2):
  hyper-v: Add CONFIG_HYPERV_VMBUS option
  hyper-v: Make CONFIG_HYPERV bool

 drivers/Makefile               |  2 +-
 drivers/gpu/drm/Kconfig        |  2 +-
 drivers/hid/Kconfig            |  2 +-
 drivers/hv/Kconfig             | 14 ++++++++++----
 drivers/hv/Makefile            |  4 ++--
 drivers/input/serio/Kconfig    |  4 ++--
 drivers/net/hyperv/Kconfig     |  2 +-
 drivers/pci/Kconfig            |  2 +-
 drivers/scsi/Kconfig           |  2 +-
 drivers/uio/Kconfig            |  2 +-
 drivers/video/fbdev/Kconfig    |  2 +-
 include/asm-generic/mshyperv.h |  8 +++++---
 net/vmw_vsock/Kconfig          |  2 +-
 13 files changed, 28 insertions(+), 20 deletions(-)

-- 
2.36.1.vfs.0.0


^ permalink raw reply

* Re: [PATCH v2 3/5] drm/sysfb: simpledrm: Add support for interconnect paths
From: Luca Weiss @ 2025-08-27  8:42 UTC (permalink / raw)
  To: Javier Martinez Canillas, Hans de Goede, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Helge Deller
  Cc: linux-fbdev, dri-devel, devicetree, linux-kernel
In-Reply-To: <874ivjf5gn.fsf@minerva.mail-host-address-is-not-set>

Hi Javier,

On Fri Jul 11, 2025 at 11:21 AM CEST, Javier Martinez Canillas wrote:
> "Luca Weiss" <luca.weiss@fairphone.com> writes:
>
> Hello Luca,
>
>> Hi Javier,
>>
>> On Fri Jun 27, 2025 at 9:51 AM CEST, Javier Martinez Canillas wrote:
>
> [...]
>
>>>> +static int simpledrm_device_attach_icc(struct simpledrm_device *sdev)
>>>> +{
>>>> +	struct device *dev = sdev->sysfb.dev.dev;
>>>> +	int ret, count, i;
>>>> +
>>>> +	count = of_count_phandle_with_args(dev->of_node, "interconnects",
>>>> +							 "#interconnect-cells");
>>>> +	if (count < 0)
>>>> +		return 0;
>>>> +
>
> You are already checking here the number of interconnects phandlers. IIUC
> this should return -ENOENT if there's no "interconects" property and your
> logic returns success in that case.

We shouldn't error out in case there's no interconnects defined for this
simple-framebuffer though? That'd break all other usages of it?

>
> [...]
>
>>>
>>> You could use dev_err_probe() instead that already handles the -EPROBE_DEFER
>>> case and also will get this message in the /sys/kernel/debug/devices_deferred
>>> debugfs entry, as the reason why the probe deferral happened.
>>
>> Not quite sure how to implement dev_err_probe, but I think this should
>> be quite okay?
>>
>
> And of_icc_get_by_index() should only return NULL if CONFIG_INTERCONNECT
> is disabled but you have ifdef guards already for this so it should not
> happen.
>
>> 		if (IS_ERR_OR_NULL(sdev->icc_paths[i])) {
>
> Then here you could just do a IS_ERR() check and not care about being NULL.

But checking also for NULL shouldn't hurt either, in case the compile
guards get removed in the future or something?

Quote:
> * Return: icc_path pointer on success or ERR_PTR() on error. NULL is returned
> * when the API is disabled or the "interconnects" DT property is missing.



>
>> 			ret = dev_err_probe(dev, PTR_ERR(sdev->icc_paths[i]),
>> 				      "failed to get interconnect path %u\n", i);
>> 			if (ret == -EPROBE_DEFER)
>> 				goto err;
>
> Why you only want to put the icc_paths get for the probe deferral case? I
> think that you want to do it for any error?

This is the same logic as e.g. for the regulator code in simpledrm. The
idea seems to be that in case some regulator (or here interconnect)
doesn't probe correctly, we still try anyways. Just for EPROBE_DEFER we
defer and wait until the supplier is available.

So defer -> defer simpledrm probe
So error -> ignore error and continue probe

>
>> 			continue;
>
> I'm not sure why you need this?

For the above behavior.

I guess there were some original design decisions behind handling it
this way, so I don't see a reason to handle it differently for
interconnects.

>
>> 		}
>>
>> That would still keep the current behavior for defer vs permanent error
>> while printing when necessary and having it for devices_deferred for the
>> defer case.
>>
>
> As mentioned I still don't understand why you want the error path to only
> be called for probe deferral. I would had thought that any failure to get
> an interconnect would led to an error and cleanup.

See above.

Regards
Luca

>
>> Not sure what the difference between drm_err and dev_err are, but I
>> trust you on that.
>>
>
> The drm_err() adds DRM specific info but IMO the dev_err_probe() is better
> to avoid printing errors in case of probe deferral and also to have it in
> the devices_deferred debugfs entry.


^ permalink raw reply

* [PATCH v2 9/9] watchdog: skip checks when panic is in progress
From: Jinchao Wang @ 2025-08-25  2:29 UTC (permalink / raw)
  To: Andrew Morton, Baoquan He, Yury Norov, Qianqiang Liu,
	Simona Vetter, Helge Deller, Petr Mladek, Steven Rostedt,
	John Ogness, Sergey Senozhatsky, Vivek Goyal, Dave Young,
	Kees Cook, Tony Luck, Guilherme G. Piccoli, Thomas Zimmermann,
	Ville Syrjälä, Shixiong Ou, Jinchao Wang, Zsolt Kajtar,
	Ingo Molnar, Nam Cao, Jonathan Cameron, Joel Fernandes,
	Joel Granados, Jason Gunthorpe, Sohil Mehta, Feng Tang,
	Sravan Kumar Gundu, Douglas Anderson, Thomas Gleixner,
	Anna Schumaker, Darrick J. Wong, Max Kellermann, Yunhui Cui,
	Tejun Heo, Luo Gengkun, Li Huafei, Thorsten Blum, Yicong Yang,
	linux-fbdev, dri-devel, kexec, linux-hardening, linux-kernel
In-Reply-To: <20250825022947.1596226-1-wangjinchao600@gmail.com>

This issue was found when an EFI pstore was configured for kdump
logging with the NMI hard lockup detector enabled. The efi-pstore
write operation was slow, and with a large number of logs, the
pstore dump callback within kmsg_dump() took a long time.

This delay triggered the NMI watchdog, leading to a nested panic.
The call flow demonstrates how the secondary panic caused an
emergency_restart() to be triggered before the initial pstore
operation could finish, leading to a failure to dump the logs:

  real panic() {
	kmsg_dump() {
		...
		pstore_dump() {
			start_dump();
			... // long time operation triggers NMI watchdog
			nmi panic() {
				...
				emergency_restart(); // pstore unfinished
			}
			...
			finish_dump(); // never reached
		}
	}
  }

Both watchdog_buddy_check_hardlockup() and watchdog_overflow_callback() may
trigger during a panic. This can lead to recursive panic handling.

Add panic_in_progress() checks so watchdog activity is skipped once a panic
has begun.

This prevents recursive panic and keeps the panic path more reliable.

Signed-off-by: Jinchao Wang <wangjinchao600@gmail.com>
Reviewed-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
---
 kernel/watchdog.c      | 6 ++++++
 kernel/watchdog_perf.c | 4 ++++
 2 files changed, 10 insertions(+)

diff --git a/kernel/watchdog.c b/kernel/watchdog.c
index 80b56c002c7f..597c0d947c93 100644
--- a/kernel/watchdog.c
+++ b/kernel/watchdog.c
@@ -740,6 +740,12 @@ static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer)
 	if (!watchdog_enabled)
 		return HRTIMER_NORESTART;
 
+	/*
+	 * pass the buddy check if a panic is in process
+	 */
+	if (panic_in_progress())
+		return HRTIMER_NORESTART;
+
 	watchdog_hardlockup_kick();
 
 	/* kick the softlockup detector */
diff --git a/kernel/watchdog_perf.c b/kernel/watchdog_perf.c
index 9c58f5b4381d..d3ca70e3c256 100644
--- a/kernel/watchdog_perf.c
+++ b/kernel/watchdog_perf.c
@@ -12,6 +12,7 @@
 
 #define pr_fmt(fmt) "NMI watchdog: " fmt
 
+#include <linux/panic.h>
 #include <linux/nmi.h>
 #include <linux/atomic.h>
 #include <linux/module.h>
@@ -108,6 +109,9 @@ static void watchdog_overflow_callback(struct perf_event *event,
 	/* Ensure the watchdog never gets throttled */
 	event->hw.interrupts = 0;
 
+	if (panic_in_progress())
+		return;
+
 	if (!watchdog_check_timestamp())
 		return;
 
-- 
2.43.0


^ permalink raw reply related

* [PATCH v2 8/9] panic/printk: replace other_cpu_in_panic() with panic_on_other_cpu()
From: Jinchao Wang @ 2025-08-25  2:29 UTC (permalink / raw)
  To: Andrew Morton, Baoquan He, Yury Norov, Qianqiang Liu,
	Simona Vetter, Helge Deller, Petr Mladek, Steven Rostedt,
	John Ogness, Sergey Senozhatsky, Vivek Goyal, Dave Young,
	Kees Cook, Tony Luck, Guilherme G. Piccoli, Thomas Zimmermann,
	Ville Syrjälä, Shixiong Ou, Jinchao Wang, Zsolt Kajtar,
	Ingo Molnar, Nam Cao, Jonathan Cameron, Joel Fernandes,
	Joel Granados, Jason Gunthorpe, Sohil Mehta, Feng Tang,
	Sravan Kumar Gundu, Douglas Anderson, Thomas Gleixner,
	Anna Schumaker, Darrick J. Wong, Max Kellermann, Yunhui Cui,
	Tejun Heo, Luo Gengkun, Li Huafei, Thorsten Blum, Yicong Yang,
	linux-fbdev, dri-devel, kexec, linux-hardening, linux-kernel
In-Reply-To: <20250825022947.1596226-1-wangjinchao600@gmail.com>

The helper other_cpu_in_panic() duplicated logic already provided by
panic_on_other_cpu().

Remove other_cpu_in_panic() and update all users to call
panic_on_other_cpu() instead.

This removes redundant code and makes panic handling consistent.

Signed-off-by: Jinchao Wang <wangjinchao600@gmail.com>
---
 kernel/printk/internal.h |  1 -
 kernel/printk/nbcon.c    |  8 ++++----
 kernel/printk/printk.c   | 19 ++++---------------
 3 files changed, 8 insertions(+), 20 deletions(-)

diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h
index ef282001f200..f72bbfa266d6 100644
--- a/kernel/printk/internal.h
+++ b/kernel/printk/internal.h
@@ -332,7 +332,6 @@ struct printk_message {
 	unsigned long		dropped;
 };
 
-bool other_cpu_in_panic(void);
 bool printk_get_next_message(struct printk_message *pmsg, u64 seq,
 			     bool is_extended, bool may_supress);
 
diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
index c6d1a4a747e9..171480135830 100644
--- a/kernel/printk/nbcon.c
+++ b/kernel/printk/nbcon.c
@@ -255,7 +255,7 @@ static int nbcon_context_try_acquire_direct(struct nbcon_context *ctxt,
 		 * opportunity to perform any necessary cleanup if they were
 		 * interrupted by the panic CPU while printing.
 		 */
-		if (other_cpu_in_panic() &&
+		if (panic_on_other_cpu() &&
 		    (!is_reacquire || cur->unsafe_takeover)) {
 			return -EPERM;
 		}
@@ -310,7 +310,7 @@ static bool nbcon_waiter_matches(struct nbcon_state *cur, int expected_prio)
 	 * Event #2 implies the new context is PANIC.
 	 * Event #3 occurs when panic() has flushed the console.
 	 * Event #4 occurs when a non-panic CPU reacquires.
-	 * Event #5 is not possible due to the other_cpu_in_panic() check
+	 * Event #5 is not possible due to the panic_on_other_cpu() check
 	 *          in nbcon_context_try_acquire_handover().
 	 */
 
@@ -349,7 +349,7 @@ static int nbcon_context_try_acquire_requested(struct nbcon_context *ctxt,
 	struct nbcon_state new;
 
 	/* Note that the caller must still remove the request! */
-	if (other_cpu_in_panic())
+	if (panic_on_other_cpu())
 		return -EPERM;
 
 	/*
@@ -447,7 +447,7 @@ static int nbcon_context_try_acquire_handover(struct nbcon_context *ctxt,
 	 * nbcon_waiter_matches(). In particular, the assumption that
 	 * lower priorities are ignored during panic.
 	 */
-	if (other_cpu_in_panic())
+	if (panic_on_other_cpu())
 		return -EPERM;
 
 	/* Handover is not possible on the same CPU. */
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index faa8b1f0585b..236f03937107 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -346,17 +346,6 @@ static void __up_console_sem(unsigned long ip)
 }
 #define up_console_sem() __up_console_sem(_RET_IP_)
 
-/*
- * Return true if a panic is in progress on a remote CPU.
- *
- * On true, the local CPU should immediately release any printing resources
- * that may be needed by the panic CPU.
- */
-bool other_cpu_in_panic(void)
-{
-	return (panic_in_progress() && !panic_on_this_cpu());
-}
-
 /*
  * This is used for debugging the mess that is the VT code by
  * keeping track if we have the console semaphore held. It's
@@ -2391,7 +2380,7 @@ asmlinkage int vprintk_emit(int facility, int level,
 	 * non-panic CPUs are generating any messages, they will be
 	 * silently dropped.
 	 */
-	if (other_cpu_in_panic() &&
+	if (panic_on_other_cpu() &&
 	    !debug_non_panic_cpus &&
 	    !panic_triggering_all_cpu_backtrace)
 		return 0;
@@ -2827,7 +2816,7 @@ void console_lock(void)
 	might_sleep();
 
 	/* On panic, the console_lock must be left to the panic cpu. */
-	while (other_cpu_in_panic())
+	while (panic_on_other_cpu())
 		msleep(1000);
 
 	down_console_sem();
@@ -2847,7 +2836,7 @@ EXPORT_SYMBOL(console_lock);
 int console_trylock(void)
 {
 	/* On panic, the console_lock must be left to the panic cpu. */
-	if (other_cpu_in_panic())
+	if (panic_on_other_cpu())
 		return 0;
 	if (down_trylock_console_sem())
 		return 0;
@@ -3227,7 +3216,7 @@ static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handove
 			any_progress = true;
 
 			/* Allow panic_cpu to take over the consoles safely. */
-			if (other_cpu_in_panic())
+			if (panic_on_other_cpu())
 				goto abandon;
 
 			if (do_cond_resched)
-- 
2.43.0


^ permalink raw reply related

* [PATCH v2 7/9] panic/printk: replace this_cpu_in_panic() with panic_on_this_cpu()
From: Jinchao Wang @ 2025-08-25  2:29 UTC (permalink / raw)
  To: Andrew Morton, Baoquan He, Yury Norov, Qianqiang Liu,
	Simona Vetter, Helge Deller, Petr Mladek, Steven Rostedt,
	John Ogness, Sergey Senozhatsky, Vivek Goyal, Dave Young,
	Kees Cook, Tony Luck, Guilherme G. Piccoli, Thomas Zimmermann,
	Ville Syrjälä, Shixiong Ou, Jinchao Wang, Zsolt Kajtar,
	Ingo Molnar, Nam Cao, Jonathan Cameron, Joel Fernandes,
	Joel Granados, Jason Gunthorpe, Sohil Mehta, Feng Tang,
	Sravan Kumar Gundu, Douglas Anderson, Thomas Gleixner,
	Anna Schumaker, Darrick J. Wong, Max Kellermann, Yunhui Cui,
	Tejun Heo, Luo Gengkun, Li Huafei, Thorsten Blum, Yicong Yang,
	linux-fbdev, dri-devel, kexec, linux-hardening, linux-kernel
In-Reply-To: <20250825022947.1596226-1-wangjinchao600@gmail.com>

The helper this_cpu_in_panic() duplicated logic already provided by
panic_on_this_cpu().

Remove this_cpu_in_panic() and switch all users to panic_on_this_cpu().

This simplifies the code and avoids having two helpers for the same check.

Signed-off-by: Jinchao Wang <wangjinchao600@gmail.com>
---
 include/linux/printk.h            |  2 --
 kernel/panic.c                    |  2 +-
 kernel/printk/nbcon.c             |  2 +-
 kernel/printk/printk.c            | 15 ++-------------
 kernel/printk/printk_ringbuffer.c |  2 +-
 lib/dump_stack.c                  |  2 +-
 6 files changed, 6 insertions(+), 19 deletions(-)

diff --git a/include/linux/printk.h b/include/linux/printk.h
index 5d22b803f51e..45c663124c9b 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -330,8 +330,6 @@ static inline bool pr_flush(int timeout_ms, bool reset_on_progress)
 
 #endif
 
-bool this_cpu_in_panic(void);
-
 #ifdef CONFIG_SMP
 extern int __printk_cpu_sync_try_get(void);
 extern void __printk_cpu_sync_wait(void);
diff --git a/kernel/panic.c b/kernel/panic.c
index 5266e195f5ac..8415e4073da1 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -343,7 +343,7 @@ EXPORT_SYMBOL(panic_on_this_cpu);
  */
 bool panic_on_other_cpu(void)
 {
-	return (panic_in_progress() && !this_cpu_in_panic());
+	return (panic_in_progress() && !panic_on_this_cpu());
 }
 EXPORT_SYMBOL(panic_on_other_cpu);
 
diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
index 7490865e2f44..c6d1a4a747e9 100644
--- a/kernel/printk/nbcon.c
+++ b/kernel/printk/nbcon.c
@@ -1394,7 +1394,7 @@ enum nbcon_prio nbcon_get_default_prio(void)
 {
 	unsigned int *cpu_emergency_nesting;
 
-	if (this_cpu_in_panic())
+	if (panic_on_this_cpu())
 		return NBCON_PRIO_PANIC;
 
 	cpu_emergency_nesting = nbcon_get_cpu_emergency_nesting();
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 5fe35f377b79..faa8b1f0585b 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -17,6 +17,7 @@
  *	01Mar01 Andrew Morton
  */
 
+#include "linux/panic.h"
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
 #include <linux/kernel.h>
@@ -345,18 +346,6 @@ static void __up_console_sem(unsigned long ip)
 }
 #define up_console_sem() __up_console_sem(_RET_IP_)
 
-/* Return true if a panic is in progress on the current CPU. */
-bool this_cpu_in_panic(void)
-{
-	/*
-	 * We can use raw_smp_processor_id() here because it is impossible for
-	 * the task to be migrated to the panic_cpu, or away from it. If
-	 * panic_cpu has already been set, and we're not currently executing on
-	 * that CPU, then we never will be.
-	 */
-	return unlikely(atomic_read(&panic_cpu) == raw_smp_processor_id());
-}
-
 /*
  * Return true if a panic is in progress on a remote CPU.
  *
@@ -365,7 +354,7 @@ bool this_cpu_in_panic(void)
  */
 bool other_cpu_in_panic(void)
 {
-	return (panic_in_progress() && !this_cpu_in_panic());
+	return (panic_in_progress() && !panic_on_this_cpu());
 }
 
 /*
diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c
index d9fb053cff67..e2a1b2d34d2b 100644
--- a/kernel/printk/printk_ringbuffer.c
+++ b/kernel/printk/printk_ringbuffer.c
@@ -2143,7 +2143,7 @@ static bool _prb_read_valid(struct printk_ringbuffer *rb, u64 *seq,
 			 * But it would have the sequence number returned
 			 * by "prb_next_reserve_seq() - 1".
 			 */
-			if (this_cpu_in_panic() &&
+			if (panic_on_this_cpu() &&
 			    (!debug_non_panic_cpus || legacy_allow_panic_sync) &&
 			    ((*seq + 1) < prb_next_reserve_seq(rb))) {
 				(*seq)++;
diff --git a/lib/dump_stack.c b/lib/dump_stack.c
index b3a85fe8b673..f0c78b5b5324 100644
--- a/lib/dump_stack.c
+++ b/lib/dump_stack.c
@@ -102,7 +102,7 @@ static void __dump_stack(const char *log_lvl)
  */
 asmlinkage __visible void dump_stack_lvl(const char *log_lvl)
 {
-	bool in_panic = this_cpu_in_panic();
+	bool in_panic = panic_on_this_cpu();
 	unsigned long flags;
 
 	/*
-- 
2.43.0


^ permalink raw reply related

* [PATCH v2 6/9] printk/nbcon: use panic_on_this_cpu() helper
From: Jinchao Wang @ 2025-08-25  2:29 UTC (permalink / raw)
  To: Andrew Morton, Baoquan He, Yury Norov, Qianqiang Liu,
	Simona Vetter, Helge Deller, Petr Mladek, Steven Rostedt,
	John Ogness, Sergey Senozhatsky, Vivek Goyal, Dave Young,
	Kees Cook, Tony Luck, Guilherme G. Piccoli, Thomas Zimmermann,
	Ville Syrjälä, Shixiong Ou, Jinchao Wang, Zsolt Kajtar,
	Ingo Molnar, Nam Cao, Jonathan Cameron, Joel Fernandes,
	Joel Granados, Jason Gunthorpe, Sohil Mehta, Feng Tang,
	Sravan Kumar Gundu, Douglas Anderson, Thomas Gleixner,
	Anna Schumaker, Darrick J. Wong, Max Kellermann, Yunhui Cui,
	Tejun Heo, Luo Gengkun, Li Huafei, Thorsten Blum, Yicong Yang,
	linux-fbdev, dri-devel, kexec, linux-hardening, linux-kernel
In-Reply-To: <20250825022947.1596226-1-wangjinchao600@gmail.com>

nbcon_context_try_acquire() compared panic_cpu directly with
smp_processor_id().  This open-coded check is now provided by
panic_on_this_cpu().

Switch to panic_on_this_cpu() to simplify the code and improve readability.

Signed-off-by: Jinchao Wang <wangjinchao600@gmail.com>
---
 kernel/printk/nbcon.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
index 646801813415..7490865e2f44 100644
--- a/kernel/printk/nbcon.c
+++ b/kernel/printk/nbcon.c
@@ -2,6 +2,7 @@
 // Copyright (C) 2022 Linutronix GmbH, John Ogness
 // Copyright (C) 2022 Intel, Thomas Gleixner
 
+#include "linux/panic.h"
 #include <linux/atomic.h>
 #include <linux/bug.h>
 #include <linux/console.h>
@@ -589,7 +590,6 @@ static struct printk_buffers panic_nbcon_pbufs;
  */
 static bool nbcon_context_try_acquire(struct nbcon_context *ctxt, bool is_reacquire)
 {
-	unsigned int cpu = smp_processor_id();
 	struct console *con = ctxt->console;
 	struct nbcon_state cur;
 	int err;
@@ -614,7 +614,7 @@ static bool nbcon_context_try_acquire(struct nbcon_context *ctxt, bool is_reacqu
 	/* Acquire succeeded. */
 
 	/* Assign the appropriate buffer for this context. */
-	if (atomic_read(&panic_cpu) == cpu)
+	if (panic_on_this_cpu())
 		ctxt->pbufs = &panic_nbcon_pbufs;
 	else
 		ctxt->pbufs = con->pbufs;
-- 
2.43.0


^ permalink raw reply related

* [PATCH v2 5/9] panic: use panic_try_start() in vpanic()
From: Jinchao Wang @ 2025-08-25  2:29 UTC (permalink / raw)
  To: Andrew Morton, Baoquan He, Yury Norov, Qianqiang Liu,
	Simona Vetter, Helge Deller, Petr Mladek, Steven Rostedt,
	John Ogness, Sergey Senozhatsky, Vivek Goyal, Dave Young,
	Kees Cook, Tony Luck, Guilherme G. Piccoli, Thomas Zimmermann,
	Ville Syrjälä, Shixiong Ou, Jinchao Wang, Zsolt Kajtar,
	Ingo Molnar, Nam Cao, Jonathan Cameron, Joel Fernandes,
	Joel Granados, Jason Gunthorpe, Sohil Mehta, Feng Tang,
	Sravan Kumar Gundu, Douglas Anderson, Thomas Gleixner,
	Anna Schumaker, Darrick J. Wong, Max Kellermann, Yunhui Cui,
	Tejun Heo, Luo Gengkun, Li Huafei, Thorsten Blum, Yicong Yang,
	linux-fbdev, dri-devel, kexec, linux-hardening, linux-kernel
In-Reply-To: <20250825022947.1596226-1-wangjinchao600@gmail.com>

vpanic() had open-coded logic to claim panic_cpu with atomic_try_cmpxchg.
This is already handled by panic_try_start().

Switch to panic_try_start() and use panic_on_other_cpu() for the fallback
path.

This removes duplicate code and makes panic handling consistent across
functions.

Signed-off-by: Jinchao Wang <wangjinchao600@gmail.com>
---
 kernel/panic.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/kernel/panic.c b/kernel/panic.c
index cd86d37d124c..5266e195f5ac 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -415,7 +415,6 @@ void vpanic(const char *fmt, va_list args)
 	static char buf[1024];
 	long i, i_next = 0, len;
 	int state = 0;
-	int old_cpu, this_cpu;
 	bool _crash_kexec_post_notifiers = crash_kexec_post_notifiers;
 
 	if (panic_on_warn) {
@@ -452,13 +451,10 @@ void vpanic(const char *fmt, va_list args)
 	 * `old_cpu == this_cpu' means we came from nmi_panic() which sets
 	 * panic_cpu to this CPU.  In this case, this is also the 1st CPU.
 	 */
-	old_cpu = PANIC_CPU_INVALID;
-	this_cpu = raw_smp_processor_id();
-
 	/* atomic_try_cmpxchg updates old_cpu on failure */
-	if (atomic_try_cmpxchg(&panic_cpu, &old_cpu, this_cpu)) {
+	if (panic_try_start()) {
 		/* go ahead */
-	} else if (old_cpu != this_cpu)
+	} else if (panic_on_other_cpu())
 		panic_smp_self_stop();
 
 	console_verbose();
-- 
2.43.0


^ permalink raw reply related

* [PATCH v2 4/9] panic: use panic_try_start() in nmi_panic()
From: Jinchao Wang @ 2025-08-25  2:29 UTC (permalink / raw)
  To: Andrew Morton, Baoquan He, Yury Norov, Qianqiang Liu,
	Simona Vetter, Helge Deller, Petr Mladek, Steven Rostedt,
	John Ogness, Sergey Senozhatsky, Vivek Goyal, Dave Young,
	Kees Cook, Tony Luck, Guilherme G. Piccoli, Thomas Zimmermann,
	Ville Syrjälä, Shixiong Ou, Jinchao Wang, Zsolt Kajtar,
	Ingo Molnar, Nam Cao, Jonathan Cameron, Joel Fernandes,
	Joel Granados, Jason Gunthorpe, Sohil Mehta, Feng Tang,
	Sravan Kumar Gundu, Douglas Anderson, Thomas Gleixner,
	Anna Schumaker, Darrick J. Wong, Max Kellermann, Yunhui Cui,
	Tejun Heo, Luo Gengkun, Li Huafei, Thorsten Blum, Yicong Yang,
	linux-fbdev, dri-devel, kexec, linux-hardening, linux-kernel
In-Reply-To: <20250825022947.1596226-1-wangjinchao600@gmail.com>

nmi_panic() duplicated the logic to claim panic_cpu with atomic_try_cmpxchg.
This is already wrapped in panic_try_start().

Replace the open-coded logic with panic_try_start(), and use
panic_on_other_cpu() for the fallback path.

This removes duplication and keeps panic handling code consistent.

Signed-off-by: Jinchao Wang <wangjinchao600@gmail.com>
---
 kernel/panic.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/kernel/panic.c b/kernel/panic.c
index eacb0c972110..cd86d37d124c 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -355,15 +355,9 @@ EXPORT_SYMBOL(panic_on_other_cpu);
  */
 void nmi_panic(struct pt_regs *regs, const char *msg)
 {
-	int old_cpu, this_cpu;
-
-	old_cpu = PANIC_CPU_INVALID;
-	this_cpu = raw_smp_processor_id();
-
-	/* atomic_try_cmpxchg updates old_cpu on failure */
-	if (atomic_try_cmpxchg(&panic_cpu, &old_cpu, this_cpu))
+	if (panic_try_start())
 		panic("%s", msg);
-	else if (old_cpu != this_cpu)
+	else if (panic_on_other_cpu())
 		nmi_panic_self_stop(regs);
 }
 EXPORT_SYMBOL(nmi_panic);
-- 
2.43.0


^ permalink raw reply related

* [PATCH v2 3/9] crash_core: use panic_try_start() in crash_kexec()
From: Jinchao Wang @ 2025-08-25  2:29 UTC (permalink / raw)
  To: Andrew Morton, Baoquan He, Yury Norov, Qianqiang Liu,
	Simona Vetter, Helge Deller, Petr Mladek, Steven Rostedt,
	John Ogness, Sergey Senozhatsky, Vivek Goyal, Dave Young,
	Kees Cook, Tony Luck, Guilherme G. Piccoli, Thomas Zimmermann,
	Ville Syrjälä, Shixiong Ou, Jinchao Wang, Zsolt Kajtar,
	Ingo Molnar, Nam Cao, Jonathan Cameron, Joel Fernandes,
	Joel Granados, Jason Gunthorpe, Sohil Mehta, Feng Tang,
	Sravan Kumar Gundu, Douglas Anderson, Thomas Gleixner,
	Anna Schumaker, Darrick J. Wong, Max Kellermann, Yunhui Cui,
	Tejun Heo, Luo Gengkun, Li Huafei, Thorsten Blum, Yicong Yang,
	linux-fbdev, dri-devel, kexec, linux-hardening, linux-kernel
In-Reply-To: <20250825022947.1596226-1-wangjinchao600@gmail.com>

crash_kexec() had its own code to exclude parallel execution by setting
panic_cpu. This is already handled by panic_try_start(). Switch to
panic_try_start() to remove the duplication and keep the logic consistent.

Signed-off-by: Jinchao Wang <wangjinchao600@gmail.com>
---
 kernel/crash_core.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/kernel/crash_core.c b/kernel/crash_core.c
index a4ef79591eb2..bb38bbaf3a26 100644
--- a/kernel/crash_core.c
+++ b/kernel/crash_core.c
@@ -4,6 +4,7 @@
  * Copyright (C) 2002-2004 Eric Biederman  <ebiederm@xmission.com>
  */
 
+#include "linux/panic.h"
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
 #include <linux/buildid.h>
@@ -143,17 +144,7 @@ STACK_FRAME_NON_STANDARD(__crash_kexec);
 
 __bpf_kfunc void crash_kexec(struct pt_regs *regs)
 {
-	int old_cpu, this_cpu;
-
-	/*
-	 * Only one CPU is allowed to execute the crash_kexec() code as with
-	 * panic().  Otherwise parallel calls of panic() and crash_kexec()
-	 * may stop each other.  To exclude them, we use panic_cpu here too.
-	 */
-	old_cpu = PANIC_CPU_INVALID;
-	this_cpu = raw_smp_processor_id();
-
-	if (atomic_try_cmpxchg(&panic_cpu, &old_cpu, this_cpu)) {
+	if (panic_try_start()) {
 		/* This is the 1st CPU which comes here, so go ahead. */
 		__crash_kexec(regs);
 
@@ -161,7 +152,7 @@ __bpf_kfunc void crash_kexec(struct pt_regs *regs)
 		 * Reset panic_cpu to allow another panic()/crash_kexec()
 		 * call.
 		 */
-		atomic_set(&panic_cpu, PANIC_CPU_INVALID);
+		panic_reset();
 	}
 }
 
-- 
2.43.0


^ permalink raw reply related

* [PATCH v2 2/9] fbdev: Use panic_in_progress() helper
From: Jinchao Wang @ 2025-08-25  2:29 UTC (permalink / raw)
  To: Andrew Morton, Baoquan He, Yury Norov, Qianqiang Liu,
	Simona Vetter, Helge Deller, Petr Mladek, Steven Rostedt,
	John Ogness, Sergey Senozhatsky, Vivek Goyal, Dave Young,
	Kees Cook, Tony Luck, Guilherme G. Piccoli, Thomas Zimmermann,
	Ville Syrjälä, Shixiong Ou, Jinchao Wang, Zsolt Kajtar,
	Ingo Molnar, Nam Cao, Jonathan Cameron, Joel Fernandes,
	Joel Granados, Jason Gunthorpe, Sohil Mehta, Feng Tang,
	Sravan Kumar Gundu, Douglas Anderson, Thomas Gleixner,
	Anna Schumaker, Darrick J. Wong, Max Kellermann, Yunhui Cui,
	Tejun Heo, Luo Gengkun, Li Huafei, Thorsten Blum, Yicong Yang,
	linux-fbdev, dri-devel, kexec, linux-hardening, linux-kernel
In-Reply-To: <20250825022947.1596226-1-wangjinchao600@gmail.com>

This patch updates the fbcon_skip_panic() function to use the
panic_in_progress() helper.

The previous direct access to panic_cpu is less readable and is being
replaced by a dedicated function that more clearly expresses the intent.

This change is part of a series to refactor the kernel's panic handling
logic for better clarity and robustness.

Signed-off-by: Jinchao Wang <wangjinchao600@gmail.com>
Acked-by Qianqiang Liu <qianqiang.liu@163.com>
---
 drivers/video/fbdev/core/fbcon.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c
index 55f5731e94c3..b062b05f4128 100644
--- a/drivers/video/fbdev/core/fbcon.c
+++ b/drivers/video/fbdev/core/fbcon.c
@@ -279,14 +279,7 @@ static int fbcon_get_rotate(struct fb_info *info)
 
 static bool fbcon_skip_panic(struct fb_info *info)
 {
-/* panic_cpu is not exported, and can't be used if built as module. Use
- * oops_in_progress instead, but non-fatal oops won't be printed.
- */
-#if defined(MODULE)
-	return (info->skip_panic && unlikely(oops_in_progress));
-#else
-	return (info->skip_panic && unlikely(atomic_read(&panic_cpu) != PANIC_CPU_INVALID));
-#endif
+	return (info->skip_panic && unlikely(panic_in_progress()));
 }
 
 static inline bool fbcon_is_active(struct vc_data *vc, struct fb_info *info)
-- 
2.43.0


^ permalink raw reply related

* [PATCH v2 1/9] panic: Introduce helper functions for panic state
From: Jinchao Wang @ 2025-08-25  2:29 UTC (permalink / raw)
  To: Andrew Morton, Baoquan He, Yury Norov, Qianqiang Liu,
	Simona Vetter, Helge Deller, Petr Mladek, Steven Rostedt,
	John Ogness, Sergey Senozhatsky, Vivek Goyal, Dave Young,
	Kees Cook, Tony Luck, Guilherme G. Piccoli, Thomas Zimmermann,
	Ville Syrjälä, Shixiong Ou, Jinchao Wang, Zsolt Kajtar,
	Ingo Molnar, Nam Cao, Jonathan Cameron, Joel Fernandes,
	Joel Granados, Jason Gunthorpe, Sohil Mehta, Feng Tang,
	Sravan Kumar Gundu, Douglas Anderson, Thomas Gleixner,
	Anna Schumaker, Darrick J. Wong, Max Kellermann, Yunhui Cui,
	Tejun Heo, Luo Gengkun, Li Huafei, Thorsten Blum, Yicong Yang,
	linux-fbdev, dri-devel, kexec, linux-hardening, linux-kernel
In-Reply-To: <20250825022947.1596226-1-wangjinchao600@gmail.com>

This patch introduces four new helper functions to abstract the
management of the panic_cpu variable. These functions will be used in
subsequent patches to refactor existing code.

The direct use of panic_cpu can be error-prone and ambiguous, as it
requires manual checks to determine which CPU is handling the panic.
The new helpers clarify intent:

panic_try_start():
Atomically sets the current CPU as the panicking CPU.

panic_reset():
Reset panic_cpu to PANIC_CPU_INVALID.

panic_in_progress():
Checks if a panic has been triggered.

panic_on_this_cpu():
Returns true if the current CPU is the panic originator.

panic_on_other_cpu():
Returns true if a panic is on another CPU.

This change lays the groundwork for improved code readability
and robustness in the panic handling subsystem.

Signed-off-by: Jinchao Wang <wangjinchao600@gmail.com>
---
 include/linux/panic.h  |  6 +++++
 kernel/panic.c         | 53 ++++++++++++++++++++++++++++++++++++++++++
 kernel/printk/printk.c |  5 ----
 3 files changed, 59 insertions(+), 5 deletions(-)

diff --git a/include/linux/panic.h b/include/linux/panic.h
index 7be742628c25..6f972a66c13e 100644
--- a/include/linux/panic.h
+++ b/include/linux/panic.h
@@ -43,6 +43,12 @@ void abort(void);
 extern atomic_t panic_cpu;
 #define PANIC_CPU_INVALID	-1
 
+bool panic_try_start(void);
+void panic_reset(void);
+bool panic_in_progress(void);
+bool panic_on_this_cpu(void);
+bool panic_on_other_cpu(void);
+
 /*
  * Only to be used by arch init code. If the user over-wrote the default
  * CONFIG_PANIC_TIMEOUT, honor it.
diff --git a/kernel/panic.c b/kernel/panic.c
index 72fcbb5a071b..eacb0c972110 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -294,6 +294,59 @@ void __weak crash_smp_send_stop(void)
 
 atomic_t panic_cpu = ATOMIC_INIT(PANIC_CPU_INVALID);
 
+bool panic_try_start(void)
+{
+	int old_cpu, this_cpu;
+
+	/*
+	 * Only one CPU is allowed to execute the crash_kexec() code as with
+	 * panic().  Otherwise parallel calls of panic() and crash_kexec()
+	 * may stop each other.  To exclude them, we use panic_cpu here too.
+	 */
+	old_cpu = PANIC_CPU_INVALID;
+	this_cpu = raw_smp_processor_id();
+
+	return atomic_try_cmpxchg(&panic_cpu, &old_cpu, this_cpu);
+}
+EXPORT_SYMBOL(panic_try_start);
+
+void panic_reset(void)
+{
+	atomic_set(&panic_cpu, PANIC_CPU_INVALID);
+}
+EXPORT_SYMBOL(panic_reset);
+
+bool panic_in_progress(void)
+{
+	return unlikely(atomic_read(&panic_cpu) != PANIC_CPU_INVALID);
+}
+EXPORT_SYMBOL(panic_in_progress);
+
+/* Return true if a panic is in progress on the current CPU. */
+bool panic_on_this_cpu(void)
+{
+	/*
+	 * We can use raw_smp_processor_id() here because it is impossible for
+	 * the task to be migrated to the panic_cpu, or away from it. If
+	 * panic_cpu has already been set, and we're not currently executing on
+	 * that CPU, then we never will be.
+	 */
+	return unlikely(atomic_read(&panic_cpu) == raw_smp_processor_id());
+}
+EXPORT_SYMBOL(panic_on_this_cpu);
+
+/*
+ * Return true if a panic is in progress on a remote CPU.
+ *
+ * On true, the local CPU should immediately release any printing resources
+ * that may be needed by the panic CPU.
+ */
+bool panic_on_other_cpu(void)
+{
+	return (panic_in_progress() && !this_cpu_in_panic());
+}
+EXPORT_SYMBOL(panic_on_other_cpu);
+
 /*
  * A variant of panic() called from NMI context. We return if we've already
  * panicked on this CPU. If another CPU already panicked, loop in
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 0efbcdda9aab..5fe35f377b79 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -345,11 +345,6 @@ static void __up_console_sem(unsigned long ip)
 }
 #define up_console_sem() __up_console_sem(_RET_IP_)
 
-static bool panic_in_progress(void)
-{
-	return unlikely(atomic_read(&panic_cpu) != PANIC_CPU_INVALID);
-}
-
 /* Return true if a panic is in progress on the current CPU. */
 bool this_cpu_in_panic(void)
 {
-- 
2.43.0


^ permalink raw reply related

* [PATCH v2 0/9] panic: introduce panic status function family
From: Jinchao Wang @ 2025-08-25  2:29 UTC (permalink / raw)
  To: Andrew Morton, Baoquan He, Yury Norov, Qianqiang Liu,
	Simona Vetter, Helge Deller, Petr Mladek, Steven Rostedt,
	John Ogness, Sergey Senozhatsky, Vivek Goyal, Dave Young,
	Kees Cook, Tony Luck, Guilherme G. Piccoli, Thomas Zimmermann,
	Ville Syrjälä, Shixiong Ou, Jinchao Wang, Zsolt Kajtar,
	Ingo Molnar, Nam Cao, Jonathan Cameron, Joel Fernandes,
	Joel Granados, Jason Gunthorpe, Sohil Mehta, Feng Tang,
	Sravan Kumar Gundu, Douglas Anderson, Thomas Gleixner,
	Anna Schumaker, Darrick J. Wong, Max Kellermann, Yunhui Cui,
	Tejun Heo, Luo Gengkun, Li Huafei, Thorsten Blum, Yicong Yang,
	linux-fbdev, dri-devel, kexec, linux-hardening, linux-kernel

This series introduces a family of helper functions to manage panic state and
updates existing code to use them.

Before this series, panic state helpers were scattered and inconsistent. For
example, panic_in_progress() was defined in printk/printk.c, not in panic.c or
panic.h. As a result, developers had to look in unexpected places to understand
or re-use panic state logic. Other checks were open- coded, duplicating logic
across panic, crash, and watchdog paths.

The new helpers centralize the functionality in panic.c/panic.h:
  - panic_try_start()
  - panic_reset()
  - panic_in_progress()
  - panic_on_this_cpu()
  - panic_on_other_cpu()

Patches 1–8 add the helpers and convert panic/crash and printk/nbcon code to
use them.

Patch 9 fixes a bug in the watchdog subsystem by skipping checks when a panic
is in progress, avoiding interference with the panic CPU.

Together, this makes panic state handling simpler, more discoverable, and more
robust.

-- 

Changes from v1:

  - The commit messages have been re-formatted based on Baoquan He's suggestions.
  - The panic_in_progress() check has been moved to be the first check in
    watchdog_overflow_callback(), as suggested by Yury Norov.

Link to v1:
https://lore.kernel.org/all/20250820091702.512524-1-wangjinchao600@gmail.com/

Jinchao Wang (9):
  panic: Introduce helper functions for panic state
  fbdev: Use panic_in_progress() helper
  crash_core: use panic_try_start() in crash_kexec()
  panic: use panic_try_start() in nmi_panic()
  panic: use panic_try_start() in vpanic()
  printk/nbcon: use panic_on_this_cpu() helper
  panic/printk: replace this_cpu_in_panic() with panic_on_this_cpu()
  panic/printk: replace other_cpu_in_panic() with panic_on_other_cpu()
  watchdog: skip checks when panic is in progress

 drivers/video/fbdev/core/fbcon.c  |  9 +---
 include/linux/panic.h             |  6 +++
 include/linux/printk.h            |  2 -
 kernel/crash_core.c               | 15 ++-----
 kernel/panic.c                    | 71 +++++++++++++++++++++++++------
 kernel/printk/internal.h          |  1 -
 kernel/printk/nbcon.c             | 14 +++---
 kernel/printk/printk.c            | 37 +++-------------
 kernel/printk/printk_ringbuffer.c |  2 +-
 kernel/watchdog.c                 |  6 +++
 kernel/watchdog_perf.c            |  4 ++
 lib/dump_stack.c                  |  2 +-
 12 files changed, 91 insertions(+), 78 deletions(-)

-- 
2.43.0


^ permalink raw reply

* Re: [PATCH] fbdev: s3fb: Implement 1 and 2 BPP modes, improve 4 BPP
From: Helge Deller @ 2025-08-24 15:40 UTC (permalink / raw)
  To: Zsolt Kajtar, linux-fbdev
In-Reply-To: <20250818204426.32115-1-soci@c64.rulez.org>

On 8/18/25 22:44, Zsolt Kajtar wrote:
> With the right setup S3 cards can display 1 and 2 BPP packed pixel
> modes, even in high resolutions. So this patch makes them available.
> 
> The 4 BPP packed pixel mode had one pixel column of garbage on the
> left side due to how the shift register works, this is fixed now.
> 
> There was a limitation that only 8 pixel wide fonts could be used at 4
> BPP. Since the CFB routines were updated to handle reverse pixel
> ordering correctly that limitation doesn't exists and was removed now.
> 
> In 4 BPP interleaved planes mode font widths of multiply of 8 are
> accepted now, not just 8 pixels.
> 
> The horizontal screen position will not move as much between modes as it
> used to. That was caused by the various amount of pipeline delay which
> is compensated now as much as possible.
> 
> While adjusting the code direct port access of PEL registers was
> corrected. Should work now on systems where these are memory mapped.
> 
> I've noticed that when in 1 BPP mode the console is used with Unicode
> fonts erasing might be done with non-blanks. That's a bug in the VT code
> and so not part of this patch.
> 
> Signed-off-by: Zsolt Kajtar <soci@c64.rulez.org>
> ---
>   drivers/video/fbdev/Kconfig |   1 +
>   drivers/video/fbdev/s3fb.c  | 140 ++++++++++++++++++++++++++----------
>   2 files changed, 105 insertions(+), 36 deletions(-)

Nice to see enhancements here!
Applied to fbdev git tree.

Thanks!
Helge

^ permalink raw reply

* Re: [PATCH] fbdev: core: fix ubsan warning in pixel_to_pat
From: Helge Deller @ 2025-08-24 15:38 UTC (permalink / raw)
  To: Zsolt Kajtar, linux-fbdev, dri-devel
In-Reply-To: <20250821024248.7458-1-soci@c64.rulez.org>

On 8/21/25 04:42, Zsolt Kajtar wrote:
> It could be triggered on 32 bit big endian machines at 32 bpp in the
> pattern realignment. In this case just return early as the result is
> an identity.
> 
> Signed-off-by: Zsolt Kajtar <soci@c64.rulez.org>
> ---
>   drivers/video/fbdev/core/fb_fillrect.h | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)

applied.

Thanks!
Helge

^ permalink raw reply

* Re: [PATCH] fbdev: Use string choices helpers
From: Helge Deller @ 2025-08-24 15:38 UTC (permalink / raw)
  To: Chelsy Ratnawat; +Cc: linux-fbdev, dri-devel
In-Reply-To: <20250824152327.2390717-1-chelsyratnawat2001@gmail.com>

On 8/24/25 17:23, Chelsy Ratnawat wrote:
> Use string_choices.h helpers instead of hard-coded strings.
> 
> Signed-off-by: Chelsy Ratnawat <chelsyratnawat2001@gmail.com>
> ---
>   drivers/video/fbdev/core/fbmon.c    | 7 ++++---
>   drivers/video/fbdev/nvidia/nvidia.c | 3 ++-
>   drivers/video/fbdev/pxafb.c         | 3 ++-
>   3 files changed, 8 insertions(+), 5 deletions(-)

applied.

Thanks!
Helge

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox