linux-hyperv.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ricardo Ribalda <ribalda@chromium.org>
To: Juergen Gross <jgross@suse.com>, Mark Brown <broonie@kernel.org>,
	Chromeos Kdump <chromeos-kdump@google.com>,
	Daniel Baluta <daniel.baluta@nxp.com>,
	Christophe Leroy <christophe.leroy@csgroup.eu>,
	Len Brown <len.brown@intel.com>, Ard Biesheuvel <ardb@kernel.org>,
	Ranjani Sridharan <ranjani.sridharan@linux.intel.com>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	Nicholas Piggin <npiggin@gmail.com>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Eric Biederman <ebiederm@xmission.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Jaroslav Kysela <perex@perex.cz>,
	Joel Fernandes <joel@joelfernandes.org>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Peter Ujfalusi <peter.ujfalusi@linux.intel.com>,
	Pavel Machek <pavel@ucw.cz>,
	Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>,
	Kai Vehmanen <kai.vehmanen@linux.intel.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	"K. Y. Srinivasan" <kys@microsoft.com>,
	Ingo Molnar <mingo@redhat.com>,
	Bjorn Helgaas <bhelgaas@google.com>,
	Dexuan Cui <decui@microsoft.com>, Takashi Iwai <tiwai@suse.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Bard Liao <yung-chuan.liao@linux.intel.com>,
	Haiyang Zhang <haiyangz@microsoft.com>,
	Wei Liu <wei.liu@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Borislav Petkov <bp@alien8.de>,
	x86@kernel.org
Cc: kexec@lists.infradead.org, alsa-devel@alsa-project.org,
	Ricardo Ribalda <ribalda@chromium.org>,
	stable@vger.kernel.org, sound-open-firmware@alsa-project.org,
	linuxppc-dev@lists.ozlabs.org, linux-hyperv@vger.kernel.org,
	linux-pci@vger.kernel.org, linux-pm@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org,
	xen-devel@lists.xenproject.org
Subject: [PATCH v8 1/3] kexec: Refactor kexec_in_progress into a function
Date: Thu, 01 Dec 2022 12:08:21 +0100	[thread overview]
Message-ID: <20221127-snd-freeze-v8-1-3bc02d09f2ce@chromium.org> (raw)
In-Reply-To: <20221127-snd-freeze-v8-0-3bc02d09f2ce@chromium.org>

Drivers running .shutdown() might want to behave differently during
kexec.

Convert kexec_in_progress into a function and export it, so it can be
used by drivers that are either built-in or modules.

Cc: stable@vger.kernel.org
Fixes: 83bfc7e793b5 ("ASoC: SOF: core: unregister clients and machine drivers in .shutdown")
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
 arch/powerpc/platforms/pseries/vio.c |  2 +-
 arch/x86/kernel/cpu/mshyperv.c       |  6 +++---
 arch/x86/xen/enlighten_hvm.c         |  2 +-
 drivers/firmware/efi/efi.c           |  2 +-
 drivers/pci/pci-driver.c             |  2 +-
 include/linux/kexec.h                |  5 ++---
 kernel/kexec_core.c                  | 12 ++++++++++--
 7 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/vio.c b/arch/powerpc/platforms/pseries/vio.c
index 00ecac2c205b..923f9a36b992 100644
--- a/arch/powerpc/platforms/pseries/vio.c
+++ b/arch/powerpc/platforms/pseries/vio.c
@@ -1289,7 +1289,7 @@ static void vio_bus_shutdown(struct device *dev)
 		viodrv = to_vio_driver(dev->driver);
 		if (viodrv->shutdown)
 			viodrv->shutdown(viodev);
-		else if (kexec_in_progress)
+		else if (kexec_in_progress())
 			vio_bus_remove(dev);
 	}
 }
diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index 831613959a92..f91f35206489 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -122,21 +122,21 @@ void hv_remove_crash_handler(void)
 #ifdef CONFIG_KEXEC_CORE
 static void hv_machine_shutdown(void)
 {
-	if (kexec_in_progress && hv_kexec_handler)
+	if (kexec_in_progress() && hv_kexec_handler)
 		hv_kexec_handler();
 
 	/*
 	 * Call hv_cpu_die() on all the CPUs, otherwise later the hypervisor
 	 * corrupts the old VP Assist Pages and can crash the kexec kernel.
 	 */
-	if (kexec_in_progress && hyperv_init_cpuhp > 0)
+	if (kexec_in_progress() && hyperv_init_cpuhp > 0)
 		cpuhp_remove_state(hyperv_init_cpuhp);
 
 	/* The function calls stop_other_cpus(). */
 	native_machine_shutdown();
 
 	/* Disable the hypercall page when there is only 1 active CPU. */
-	if (kexec_in_progress)
+	if (kexec_in_progress())
 		hyperv_cleanup();
 }
 
diff --git a/arch/x86/xen/enlighten_hvm.c b/arch/x86/xen/enlighten_hvm.c
index c1cd28e915a3..769163833ffc 100644
--- a/arch/x86/xen/enlighten_hvm.c
+++ b/arch/x86/xen/enlighten_hvm.c
@@ -145,7 +145,7 @@ DEFINE_IDTENTRY_SYSVEC(sysvec_xen_hvm_callback)
 static void xen_hvm_shutdown(void)
 {
 	native_machine_shutdown();
-	if (kexec_in_progress)
+	if (kexec_in_progress())
 		xen_reboot(SHUTDOWN_soft_reset);
 }
 
diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index a46df5d1d094..608bc2146802 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -1040,7 +1040,7 @@ static int update_efi_random_seed(struct notifier_block *nb,
 	struct linux_efi_random_seed *seed;
 	u32 size = 0;
 
-	if (!kexec_in_progress)
+	if (!kexec_in_progress())
 		return NOTIFY_DONE;
 
 	seed = memremap(efi_rng_seed, sizeof(*seed), MEMREMAP_WB);
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 107d77f3c846..23eeb7538b03 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -519,7 +519,7 @@ static void pci_device_shutdown(struct device *dev)
 	 * If it is not a kexec reboot, firmware will hit the PCI
 	 * devices with big hammer and stop their DMA any way.
 	 */
-	if (kexec_in_progress && (pci_dev->current_state <= PCI_D3hot))
+	if (kexec_in_progress() && pci_dev->current_state <= PCI_D3hot)
 		pci_clear_master(pci_dev);
 }
 
diff --git a/include/linux/kexec.h b/include/linux/kexec.h
index 41a686996aaa..2ec0aec1a0de 100644
--- a/include/linux/kexec.h
+++ b/include/linux/kexec.h
@@ -423,8 +423,7 @@ extern int kexec_load_disabled;
 #define KEXEC_FILE_FLAGS	(KEXEC_FILE_UNLOAD | KEXEC_FILE_ON_CRASH | \
 				 KEXEC_FILE_NO_INITRAMFS)
 
-/* flag to track if kexec reboot is in progress */
-extern bool kexec_in_progress;
+bool kexec_in_progress(void);
 
 int crash_shrink_memory(unsigned long new_size);
 ssize_t crash_get_memory_size(void);
@@ -507,7 +506,7 @@ static inline void __crash_kexec(struct pt_regs *regs) { }
 static inline void crash_kexec(struct pt_regs *regs) { }
 static inline int kexec_should_crash(struct task_struct *p) { return 0; }
 static inline int kexec_crash_loaded(void) { return 0; }
-#define kexec_in_progress false
+static inline bool kexec_in_progress(void) { return false; }
 #endif /* CONFIG_KEXEC_CORE */
 
 #ifdef CONFIG_KEXEC_SIG
diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
index ca2743f9c634..4495d0fc28ae 100644
--- a/kernel/kexec_core.c
+++ b/kernel/kexec_core.c
@@ -52,8 +52,16 @@ atomic_t __kexec_lock = ATOMIC_INIT(0);
 note_buf_t __percpu *crash_notes;
 
 /* Flag to indicate we are going to kexec a new kernel */
-bool kexec_in_progress = false;
+static bool kexec_in_progress_internal;
 
+/**
+ * kexec_in_progress - Check if the system is going to kexec
+ */
+bool kexec_in_progress(void)
+{
+	return kexec_in_progress_internal;
+}
+EXPORT_SYMBOL(kexec_in_progress);
 
 /* Location of the reserved area for the crash kernel */
 struct resource crashk_res = {
@@ -1175,7 +1183,7 @@ int kernel_kexec(void)
 	} else
 #endif
 	{
-		kexec_in_progress = true;
+		kexec_in_progress_internal = true;
 		kernel_restart_prepare("kexec reboot");
 		migrate_to_reboot_cpu();
 

-- 
2.39.0.rc0.267.gcb52ba06e7-goog-b4-0.11.0-dev-696ae

  reply	other threads:[~2022-12-01 11:15 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-01 11:08 [PATCH v8 0/3] ASoC: SOF: Fix deadlock when shutdown a frozen userspace Ricardo Ribalda
2022-12-01 11:08 ` Ricardo Ribalda [this message]
2022-12-01 11:08 ` [PATCH v8 2/3] freezer: refactor pm_freezing into a function Ricardo Ribalda
2022-12-02 17:47   ` Rafael J. Wysocki
2022-12-05 12:05     ` Ricardo Ribalda
2022-12-01 11:08 ` [PATCH v8 3/3] ASoC: SOF: Fix deadlock when shutdown a frozen userspace Ricardo Ribalda
2022-12-01 12:28   ` Oliver Neukum
2022-12-01 13:03     ` Ricardo Ribalda
2022-12-01 13:22       ` Oliver Neukum
2022-12-01 13:34         ` Ricardo Ribalda
2022-12-09 11:53           ` Kai Vehmanen
2022-12-01 13:38         ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221127-snd-freeze-v8-1-3bc02d09f2ce@chromium.org \
    --to=ribalda@chromium.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=ardb@kernel.org \
    --cc=bhelgaas@google.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=bp@alien8.de \
    --cc=broonie@kernel.org \
    --cc=christophe.leroy@csgroup.eu \
    --cc=chromeos-kdump@google.com \
    --cc=daniel.baluta@nxp.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=decui@microsoft.com \
    --cc=ebiederm@xmission.com \
    --cc=haiyangz@microsoft.com \
    --cc=hpa@zytor.com \
    --cc=jgross@suse.com \
    --cc=joel@joelfernandes.org \
    --cc=kai.vehmanen@linux.intel.com \
    --cc=kexec@lists.infradead.org \
    --cc=kys@microsoft.com \
    --cc=len.brown@intel.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mingo@redhat.com \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=pavel@ucw.cz \
    --cc=perex@perex.cz \
    --cc=peter.ujfalusi@linux.intel.com \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=rafael@kernel.org \
    --cc=ranjani.sridharan@linux.intel.com \
    --cc=rostedt@goodmis.org \
    --cc=sound-open-firmware@alsa-project.org \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=tiwai@suse.com \
    --cc=wei.liu@kernel.org \
    --cc=x86@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    --cc=yung-chuan.liao@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).