7999a9a70d
-----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEZH8oZUiU471FcZm+ONu9yGCSaT4FAmVmG20ACgkQONu9yGCS aT6dzg/7BnCP2SpVmgEaD7FdPvGO/A6O5VrC9zu3sQE6g2gAwirZhdgE8NRn+ggm WSQ1kIA+HEcY23FKpq46pBED4P1irudiW7DkLw8nyOGp+XLb4wGkF5lBBP5z+B2P ga2RgwqKvYWeDaUW4n1Uy7m2Cz+wqCg/EvnITo40glSWPh20gM532/CSnA5akoje 9mjZYZ0rKHKTZGu65aNScNR7XnXHIivJU6C1jF6L9N1+Xn679nUHKQP4KM/RcjpX g1WQMWFC3mGIn5IX28W1wvKS320D5HLmTLnLqJvFpJN9+13DUnUoXcX469zvQoxJ GL3S94goWN/0BPOgr5KcKvTj00b4O+EWhQuQt+x8NLdydzRQuyFu2UpLNhIKKSou sT+BcxzeuqJhEh1tZItcZkZBptpLEkb0ezT11u5McnU5FjPzzzP8CtEetKKmEaBU AUoEP/lQQlVyk1I6xAeuzu53smncNQt6CqnXJxYXOBGgJ2txAM5kroMKXPin5C8k BCpUIqghhKmBd1hwuKyaOBKF99eLKKZsuvXppoPD0Yz7/Nq5TgdBw0qbNt2iLr05 XSM7WIIeCBROaV+ZiVxgtcXDR51FpMr7CLTbkBQ6IgLwircHeHSK7rQn7kFO3fCg OezhWAuh72qDZ2PCJ84fj21IhZ49a5oCLbUdBew+KzZervVpSo0= =eW67 -----END PGP SIGNATURE----- Merge 5.10.202 into android12-5.10-lts Changes in 5.10.202 locking/ww_mutex/test: Fix potential workqueue corruption perf/core: Bail out early if the request AUX area is out of bound clocksource/drivers/timer-imx-gpt: Fix potential memory leak clocksource/drivers/timer-atmel-tcb: Fix initialization on SAM9 hardware x86/mm: Drop the 4 MB restriction on minimal NUMA node memory size wifi: mac80211_hwsim: fix clang-specific fortify warning wifi: mac80211: don't return unset power in ieee80211_get_tx_power() bpf: Detect IP == ksym.end as part of BPF program wifi: ath9k: fix clang-specific fortify warnings wifi: ath10k: fix clang-specific fortify warning net: annotate data-races around sk->sk_tx_queue_mapping net: annotate data-races around sk->sk_dst_pending_confirm wifi: ath10k: Don't touch the CE interrupt registers after power up Bluetooth: btusb: Add date->evt_skb is NULL check Bluetooth: Fix double free in hci_conn_cleanup platform/x86: thinkpad_acpi: Add battery quirk for Thinkpad X120e drm/komeda: drop all currently held locks if deadlock happens drm/msm/dp: skip validity check for DP CTS EDID checksum drm/amd: Fix UBSAN array-index-out-of-bounds for SMU7 drm/amd: Fix UBSAN array-index-out-of-bounds for Polaris and Tonga drm/amdgpu: Fix potential null pointer derefernce drm/panel: fix a possible null pointer dereference drm/panel/panel-tpo-tpg110: fix a possible null pointer dereference drm/panel: st7703: Pick different reset sequence drm/amdgpu: Fix a null pointer access when the smc_rreg pointer is NULL selftests/efivarfs: create-read: fix a resource leak ASoC: soc-card: Add storage for PCI SSID crypto: pcrypt - Fix hungtask for PADATA_RESET RDMA/hfi1: Use FIELD_GET() to extract Link Width fs/jfs: Add check for negative db_l2nbperpage fs/jfs: Add validity check for db_maxag and db_agpref jfs: fix array-index-out-of-bounds in dbFindLeaf jfs: fix array-index-out-of-bounds in diAlloc HID: lenovo: Detect quirk-free fw on cptkbd and stop applying workaround ARM: 9320/1: fix stack depot IRQ stack filter ALSA: hda: Fix possible null-ptr-deref when assigning a stream PCI: tegra194: Use FIELD_GET()/FIELD_PREP() with Link Width fields atm: iphase: Do PCI error checks on own line scsi: libfc: Fix potential NULL pointer dereference in fc_lport_ptp_setup() misc: pci_endpoint_test: Add Device ID for R-Car S4-8 PCIe controller HID: Add quirk for Dell Pro Wireless Keyboard and Mouse KM5221W exfat: support handle zero-size directory tty: vcc: Add check for kstrdup() in vcc_probe() usb: gadget: f_ncm: Always set current gadget in ncm_bind() 9p/trans_fd: Annotate data-racy writes to file::f_flags i2c: sun6i-p2wi: Prevent potential division by zero media: gspca: cpia1: shift-out-of-bounds in set_flicker media: vivid: avoid integer overflow gfs2: ignore negated quota changes gfs2: fix an oops in gfs2_permission media: cobalt: Use FIELD_GET() to extract Link Width media: imon: fix access to invalid resource for the second interface drm/amd/display: Avoid NULL dereference of timing generator kgdb: Flush console before entering kgdb on panic ASoC: ti: omap-mcbsp: Fix runtime PM underflow warnings drm/amdgpu: fix software pci_unplug on some chips pwm: Fix double shift bug wifi: iwlwifi: Use FW rate for non-data frames xhci: turn cancelled td cleanup to its own function SUNRPC: ECONNRESET might require a rebind SUNRPC: Add an IS_ERR() check back to where it was NFSv4.1: fix SP4_MACH_CRED protection for pnfs IO SUNRPC: Fix RPC client cleaned up the freed pipefs dentries gfs2: Silence "suspicious RCU usage in gfs2_permission" warning ipvlan: add ipvlan_route_v6_outbound() helper tty: Fix uninit-value access in ppp_sync_receive() net: hns3: fix variable may not initialized problem in hns3_init_mac_addr() net: hns3: fix VF reset fail issue tipc: Fix kernel-infoleak due to uninitialized TLV value ppp: limit MRU to 64K xen/events: fix delayed eoi list handling ptp: annotate data-race around q->head and q->tail bonding: stop the device in bond_setup_by_slave() net: ethernet: cortina: Fix max RX frame define net: ethernet: cortina: Handle large frames net: ethernet: cortina: Fix MTU max setting netfilter: nf_conntrack_bridge: initialize err to 0 net: stmmac: fix rx budget limit check net/mlx5e: fix double free of encap_header net/mlx5_core: Clean driver version and name net/mlx5e: Check return value of snprintf writing to fw_version buffer for representors macvlan: Don't propagate promisc change to lower dev in passthru tools/power/turbostat: Fix a knl bug cifs: spnego: add ';' in HOST_KEY_LEN cifs: fix check of rc in function generate_smb3signingkey media: venus: hfi: add checks to perform sanity on queue pointers powerpc/perf: Fix disabling BHRB and instruction sampling randstruct: Fix gcc-plugin performance mode to stay in group bpf: Fix check_stack_write_fixed_off() to correctly spill imm bpf: Fix precision tracking for BPF_ALU | BPF_TO_BE | BPF_END scsi: mpt3sas: Fix loop logic scsi: megaraid_sas: Increase register read retry rount from 3 to 30 for selected registers x86/cpu/hygon: Fix the CPU topology evaluation for real KVM: x86: hyper-v: Don't auto-enable stimer on write from user-space KVM: x86: Ignore MSR_AMD64_TW_CFG access audit: don't take task_lock() in audit_exe_compare() code path audit: don't WARN_ON_ONCE(!current->mm) in audit_exe_compare() tty/sysrq: replace smp_processor_id() with get_cpu() hvc/xen: fix console unplug hvc/xen: fix error path in xen_hvc_init() to always register frontend driver PCI/sysfs: Protect driver's D3cold preference from user space watchdog: move softlockup_panic back to early_param ACPI: resource: Do IRQ override on TongFang GMxXGxx arm64: Restrict CPU_BIG_ENDIAN to GNU as or LLVM IAS 15.x or newer parisc/pdc: Add width field to struct pdc_model clk: qcom: ipq8074: drop the CLK_SET_RATE_PARENT flag from PLL clocks clk: qcom: ipq6018: drop the CLK_SET_RATE_PARENT flag from PLL clocks mmc: vub300: fix an error code mmc: sdhci_am654: fix start loop index for TAP value parsing PCI/ASPM: Fix L1 substate handling in aspm_attr_store_common() arm64: dts: qcom: ipq6018: Fix hwlock index for SMEM PM: hibernate: Use __get_safe_page() rather than touching the list PM: hibernate: Clean up sync_read handling in snapshot_write_next() rcu: kmemleak: Ignore kmemleak false positives when RCU-freeing objects btrfs: don't arbitrarily slow down delalloc if we're committing firmware: qcom_scm: use 64-bit calling convention only when client is 64-bit ima: detect changes to the backing overlay file wifi: ath11k: fix temperature event locking wifi: ath11k: fix dfs radar event locking wifi: ath11k: fix htt pktlog locking mmc: meson-gx: Remove setting of CMD_CFG_ERROR genirq/generic_chip: Make irq_remove_generic_chip() irqdomain aware PCI: keystone: Don't discard .remove() callback PCI: keystone: Don't discard .probe() callback jbd2: fix potential data lost in recovering journal raced with synchronizing fs bdev quota: explicitly forbid quota files from being encrypted kernel/reboot: emergency_restart: Set correct system_state i2c: core: Run atomic i2c xfer when !preemptible mcb: fix error handling for different scenarios when parsing dmaengine: stm32-mdma: correct desc prep when channel running mm/cma: use nth_page() in place of direct struct page manipulation mm/memory_hotplug: use pfn math in place of direct struct page manipulation mtd: cfi_cmdset_0001: Byte swap OTP info i3c: master: cdns: Fix reading status register parisc: Prevent booting 64-bit kernels on PA1.x machines parisc/pgtable: Do not drop upper 5 address bits of physical address xhci: Enable RPM on controllers that support low-power states ALSA: info: Fix potential deadlock at disconnection ALSA: hda/realtek - Add Dell ALC295 to pin fall back table ALSA: hda/realtek - Enable internal speaker of ASUS K6500ZC serial: meson: remove redundant initialization of variable id tty: serial: meson: retrieve port FIFO size from DT serial: meson: Use platform_get_irq() to get the interrupt tty: serial: meson: fix hard LOCKUP on crtscts mode cpufreq: stats: Fix buffer overflow detection in trans_stats() Bluetooth: btusb: Add Realtek RTL8852BE support ID 0x0cb8:0xc559 bluetooth: Add device 0bda:887b to device tables bluetooth: Add device 13d3:3571 to device tables Bluetooth: btusb: Add RTW8852BE device 13d3:3570 to device tables Bluetooth: btusb: Add 0bda:b85b for Fn-Link RTL8852BE PCI: exynos: Don't discard .remove() callback arm64: dts: qcom: ipq6018: switch TCSR mutex to MMIO arm64: dts: qcom: ipq6018: Fix tcsr_mutex register size Revert ncsi: Propagate carrier gain/loss events to the NCSI controller lsm: fix default return value for vm_enough_memory lsm: fix default return value for inode_getsecctx i2c: designware: Disable TX_EMPTY irq while waiting for block length byte net: dsa: lan9303: consequently nested-lock physical MDIO net: phylink: initialize carrier state at creation i2c: i801: fix potential race in i801_block_transaction_byte_by_byte f2fs: avoid format-overflow warning media: lirc: drop trailing space from scancode transmit media: sharp: fix sharp encoding media: venus: hfi_parser: Add check to keep the number of codecs within range media: venus: hfi: fix the check to handle session buffer requirement media: venus: hfi: add checks to handle capabilities from firmware nfsd: fix file memleak on client_opens_release mm: kmem: drop __GFP_NOFAIL when allocating objcg vectors media: qcom: camss: Fix vfe_get() error jump Revert "net: r8169: Disable multicast filter for RTL8168H and RTL8107E" ext4: apply umask if ACL support is disabled ext4: correct offset of gdb backup in non meta_bg group to update_backups ext4: correct return value of ext4_convert_meta_bg ext4: correct the start block of counting reserved clusters ext4: remove gdb backup copy for meta bg in setup_new_flex_group_blocks drm/amd/pm: Handle non-terminated overdrive commands. drm/amdgpu: fix error handling in amdgpu_bo_list_get() drm/amd/display: Change the DMCUB mailbox memory location from FB to inbox io_uring/fdinfo: lock SQ thread while retrieving thread cpu/pid tracing: Have trace_event_file have ref counters netfilter: nftables: update table flags from the commit phase netfilter: nf_tables: fix table flag updates netfilter: nf_tables: disable toggling dormant table state more than once interconnect: qcom: Add support for mask-based BCMs Linux 5.10.202 Change-Id: I762bcd4848d9b87cbb4efe4104fe1685999dc0f7 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
600 lines
14 KiB
C
600 lines
14 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* linux/kernel/reboot.c
|
|
*
|
|
* Copyright (C) 2013 Linus Torvalds
|
|
*/
|
|
|
|
#define pr_fmt(fmt) "reboot: " fmt
|
|
|
|
#include <linux/ctype.h>
|
|
#include <linux/export.h>
|
|
#include <linux/kexec.h>
|
|
#include <linux/kmod.h>
|
|
#include <linux/kmsg_dump.h>
|
|
#include <linux/reboot.h>
|
|
#include <linux/suspend.h>
|
|
#include <linux/syscalls.h>
|
|
#include <linux/syscore_ops.h>
|
|
#include <linux/uaccess.h>
|
|
|
|
/*
|
|
* this indicates whether you can reboot with ctrl-alt-del: the default is yes
|
|
*/
|
|
|
|
int C_A_D = 1;
|
|
struct pid *cad_pid;
|
|
EXPORT_SYMBOL(cad_pid);
|
|
|
|
#if defined(CONFIG_ARM)
|
|
#define DEFAULT_REBOOT_MODE = REBOOT_HARD
|
|
#else
|
|
#define DEFAULT_REBOOT_MODE
|
|
#endif
|
|
enum reboot_mode reboot_mode DEFAULT_REBOOT_MODE;
|
|
EXPORT_SYMBOL_GPL(reboot_mode);
|
|
enum reboot_mode panic_reboot_mode = REBOOT_UNDEFINED;
|
|
EXPORT_SYMBOL_GPL(panic_reboot_mode);
|
|
|
|
/*
|
|
* This variable is used privately to keep track of whether or not
|
|
* reboot_type is still set to its default value (i.e., reboot= hasn't
|
|
* been set on the command line). This is needed so that we can
|
|
* suppress DMI scanning for reboot quirks. Without it, it's
|
|
* impossible to override a faulty reboot quirk without recompiling.
|
|
*/
|
|
int reboot_default = 1;
|
|
int reboot_cpu;
|
|
enum reboot_type reboot_type = BOOT_ACPI;
|
|
int reboot_force;
|
|
|
|
/*
|
|
* If set, this is used for preparing the system to power off.
|
|
*/
|
|
|
|
void (*pm_power_off_prepare)(void);
|
|
EXPORT_SYMBOL_GPL(pm_power_off_prepare);
|
|
|
|
/**
|
|
* emergency_restart - reboot the system
|
|
*
|
|
* Without shutting down any hardware or taking any locks
|
|
* reboot the system. This is called when we know we are in
|
|
* trouble so this is our best effort to reboot. This is
|
|
* safe to call in interrupt context.
|
|
*/
|
|
void emergency_restart(void)
|
|
{
|
|
kmsg_dump(KMSG_DUMP_EMERG);
|
|
system_state = SYSTEM_RESTART;
|
|
machine_emergency_restart();
|
|
}
|
|
EXPORT_SYMBOL_GPL(emergency_restart);
|
|
|
|
void kernel_restart_prepare(char *cmd)
|
|
{
|
|
blocking_notifier_call_chain(&reboot_notifier_list, SYS_RESTART, cmd);
|
|
system_state = SYSTEM_RESTART;
|
|
usermodehelper_disable();
|
|
device_shutdown();
|
|
}
|
|
|
|
/**
|
|
* register_reboot_notifier - Register function to be called at reboot time
|
|
* @nb: Info about notifier function to be called
|
|
*
|
|
* Registers a function with the list of functions
|
|
* to be called at reboot time.
|
|
*
|
|
* Currently always returns zero, as blocking_notifier_chain_register()
|
|
* always returns zero.
|
|
*/
|
|
int register_reboot_notifier(struct notifier_block *nb)
|
|
{
|
|
return blocking_notifier_chain_register(&reboot_notifier_list, nb);
|
|
}
|
|
EXPORT_SYMBOL(register_reboot_notifier);
|
|
|
|
/**
|
|
* unregister_reboot_notifier - Unregister previously registered reboot notifier
|
|
* @nb: Hook to be unregistered
|
|
*
|
|
* Unregisters a previously registered reboot
|
|
* notifier function.
|
|
*
|
|
* Returns zero on success, or %-ENOENT on failure.
|
|
*/
|
|
int unregister_reboot_notifier(struct notifier_block *nb)
|
|
{
|
|
return blocking_notifier_chain_unregister(&reboot_notifier_list, nb);
|
|
}
|
|
EXPORT_SYMBOL(unregister_reboot_notifier);
|
|
|
|
static void devm_unregister_reboot_notifier(struct device *dev, void *res)
|
|
{
|
|
WARN_ON(unregister_reboot_notifier(*(struct notifier_block **)res));
|
|
}
|
|
|
|
int devm_register_reboot_notifier(struct device *dev, struct notifier_block *nb)
|
|
{
|
|
struct notifier_block **rcnb;
|
|
int ret;
|
|
|
|
rcnb = devres_alloc(devm_unregister_reboot_notifier,
|
|
sizeof(*rcnb), GFP_KERNEL);
|
|
if (!rcnb)
|
|
return -ENOMEM;
|
|
|
|
ret = register_reboot_notifier(nb);
|
|
if (!ret) {
|
|
*rcnb = nb;
|
|
devres_add(dev, rcnb);
|
|
} else {
|
|
devres_free(rcnb);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL(devm_register_reboot_notifier);
|
|
|
|
/*
|
|
* Notifier list for kernel code which wants to be called
|
|
* to restart the system.
|
|
*/
|
|
static ATOMIC_NOTIFIER_HEAD(restart_handler_list);
|
|
|
|
/**
|
|
* register_restart_handler - Register function to be called to reset
|
|
* the system
|
|
* @nb: Info about handler function to be called
|
|
* @nb->priority: Handler priority. Handlers should follow the
|
|
* following guidelines for setting priorities.
|
|
* 0: Restart handler of last resort,
|
|
* with limited restart capabilities
|
|
* 128: Default restart handler; use if no other
|
|
* restart handler is expected to be available,
|
|
* and/or if restart functionality is
|
|
* sufficient to restart the entire system
|
|
* 255: Highest priority restart handler, will
|
|
* preempt all other restart handlers
|
|
*
|
|
* Registers a function with code to be called to restart the
|
|
* system.
|
|
*
|
|
* Registered functions will be called from machine_restart as last
|
|
* step of the restart sequence (if the architecture specific
|
|
* machine_restart function calls do_kernel_restart - see below
|
|
* for details).
|
|
* Registered functions are expected to restart the system immediately.
|
|
* If more than one function is registered, the restart handler priority
|
|
* selects which function will be called first.
|
|
*
|
|
* Restart handlers are expected to be registered from non-architecture
|
|
* code, typically from drivers. A typical use case would be a system
|
|
* where restart functionality is provided through a watchdog. Multiple
|
|
* restart handlers may exist; for example, one restart handler might
|
|
* restart the entire system, while another only restarts the CPU.
|
|
* In such cases, the restart handler which only restarts part of the
|
|
* hardware is expected to register with low priority to ensure that
|
|
* it only runs if no other means to restart the system is available.
|
|
*
|
|
* Currently always returns zero, as atomic_notifier_chain_register()
|
|
* always returns zero.
|
|
*/
|
|
int register_restart_handler(struct notifier_block *nb)
|
|
{
|
|
return atomic_notifier_chain_register(&restart_handler_list, nb);
|
|
}
|
|
EXPORT_SYMBOL(register_restart_handler);
|
|
|
|
/**
|
|
* unregister_restart_handler - Unregister previously registered
|
|
* restart handler
|
|
* @nb: Hook to be unregistered
|
|
*
|
|
* Unregisters a previously registered restart handler function.
|
|
*
|
|
* Returns zero on success, or %-ENOENT on failure.
|
|
*/
|
|
int unregister_restart_handler(struct notifier_block *nb)
|
|
{
|
|
return atomic_notifier_chain_unregister(&restart_handler_list, nb);
|
|
}
|
|
EXPORT_SYMBOL(unregister_restart_handler);
|
|
|
|
/**
|
|
* do_kernel_restart - Execute kernel restart handler call chain
|
|
*
|
|
* Calls functions registered with register_restart_handler.
|
|
*
|
|
* Expected to be called from machine_restart as last step of the restart
|
|
* sequence.
|
|
*
|
|
* Restarts the system immediately if a restart handler function has been
|
|
* registered. Otherwise does nothing.
|
|
*/
|
|
void do_kernel_restart(char *cmd)
|
|
{
|
|
atomic_notifier_call_chain(&restart_handler_list, reboot_mode, cmd);
|
|
}
|
|
|
|
void migrate_to_reboot_cpu(void)
|
|
{
|
|
/* The boot cpu is always logical cpu 0 */
|
|
int cpu = reboot_cpu;
|
|
|
|
cpu_hotplug_disable();
|
|
|
|
/* Make certain the cpu I'm about to reboot on is online */
|
|
if (!cpu_online(cpu))
|
|
cpu = cpumask_first(cpu_online_mask);
|
|
|
|
/* Prevent races with other tasks migrating this task */
|
|
current->flags |= PF_NO_SETAFFINITY;
|
|
|
|
/* Make certain I only run on the appropriate processor */
|
|
set_cpus_allowed_ptr(current, cpumask_of(cpu));
|
|
}
|
|
|
|
/**
|
|
* kernel_restart - reboot the system
|
|
* @cmd: pointer to buffer containing command to execute for restart
|
|
* or %NULL
|
|
*
|
|
* Shutdown everything and perform a clean reboot.
|
|
* This is not safe to call in interrupt context.
|
|
*/
|
|
void kernel_restart(char *cmd)
|
|
{
|
|
kernel_restart_prepare(cmd);
|
|
migrate_to_reboot_cpu();
|
|
syscore_shutdown();
|
|
if (!cmd)
|
|
pr_emerg("Restarting system\n");
|
|
else
|
|
pr_emerg("Restarting system with command '%s'\n", cmd);
|
|
kmsg_dump(KMSG_DUMP_SHUTDOWN);
|
|
machine_restart(cmd);
|
|
}
|
|
EXPORT_SYMBOL_GPL(kernel_restart);
|
|
|
|
static void kernel_shutdown_prepare(enum system_states state)
|
|
{
|
|
blocking_notifier_call_chain(&reboot_notifier_list,
|
|
(state == SYSTEM_HALT) ? SYS_HALT : SYS_POWER_OFF, NULL);
|
|
system_state = state;
|
|
usermodehelper_disable();
|
|
device_shutdown();
|
|
}
|
|
/**
|
|
* kernel_halt - halt the system
|
|
*
|
|
* Shutdown everything and perform a clean system halt.
|
|
*/
|
|
void kernel_halt(void)
|
|
{
|
|
kernel_shutdown_prepare(SYSTEM_HALT);
|
|
migrate_to_reboot_cpu();
|
|
syscore_shutdown();
|
|
pr_emerg("System halted\n");
|
|
kmsg_dump(KMSG_DUMP_SHUTDOWN);
|
|
machine_halt();
|
|
}
|
|
EXPORT_SYMBOL_GPL(kernel_halt);
|
|
|
|
/**
|
|
* kernel_power_off - power_off the system
|
|
*
|
|
* Shutdown everything and perform a clean system power_off.
|
|
*/
|
|
void kernel_power_off(void)
|
|
{
|
|
kernel_shutdown_prepare(SYSTEM_POWER_OFF);
|
|
if (pm_power_off_prepare)
|
|
pm_power_off_prepare();
|
|
migrate_to_reboot_cpu();
|
|
syscore_shutdown();
|
|
pr_emerg("Power down\n");
|
|
kmsg_dump(KMSG_DUMP_SHUTDOWN);
|
|
machine_power_off();
|
|
}
|
|
EXPORT_SYMBOL_GPL(kernel_power_off);
|
|
|
|
DEFINE_MUTEX(system_transition_mutex);
|
|
|
|
/*
|
|
* Reboot system call: for obvious reasons only root may call it,
|
|
* and even root needs to set up some magic numbers in the registers
|
|
* so that some mistake won't make this reboot the whole machine.
|
|
* You can also set the meaning of the ctrl-alt-del-key here.
|
|
*
|
|
* reboot doesn't sync: do that yourself before calling this.
|
|
*/
|
|
SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
|
|
void __user *, arg)
|
|
{
|
|
struct pid_namespace *pid_ns = task_active_pid_ns(current);
|
|
char buffer[256];
|
|
int ret = 0;
|
|
|
|
/* We only trust the superuser with rebooting the system. */
|
|
if (!ns_capable(pid_ns->user_ns, CAP_SYS_BOOT))
|
|
return -EPERM;
|
|
|
|
/* For safety, we require "magic" arguments. */
|
|
if (magic1 != LINUX_REBOOT_MAGIC1 ||
|
|
(magic2 != LINUX_REBOOT_MAGIC2 &&
|
|
magic2 != LINUX_REBOOT_MAGIC2A &&
|
|
magic2 != LINUX_REBOOT_MAGIC2B &&
|
|
magic2 != LINUX_REBOOT_MAGIC2C))
|
|
return -EINVAL;
|
|
|
|
/*
|
|
* If pid namespaces are enabled and the current task is in a child
|
|
* pid_namespace, the command is handled by reboot_pid_ns() which will
|
|
* call do_exit().
|
|
*/
|
|
ret = reboot_pid_ns(pid_ns, cmd);
|
|
if (ret)
|
|
return ret;
|
|
|
|
/* Instead of trying to make the power_off code look like
|
|
* halt when pm_power_off is not set do it the easy way.
|
|
*/
|
|
if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
|
|
cmd = LINUX_REBOOT_CMD_HALT;
|
|
|
|
mutex_lock(&system_transition_mutex);
|
|
switch (cmd) {
|
|
case LINUX_REBOOT_CMD_RESTART:
|
|
kernel_restart(NULL);
|
|
break;
|
|
|
|
case LINUX_REBOOT_CMD_CAD_ON:
|
|
C_A_D = 1;
|
|
break;
|
|
|
|
case LINUX_REBOOT_CMD_CAD_OFF:
|
|
C_A_D = 0;
|
|
break;
|
|
|
|
case LINUX_REBOOT_CMD_HALT:
|
|
kernel_halt();
|
|
do_exit(0);
|
|
panic("cannot halt");
|
|
|
|
case LINUX_REBOOT_CMD_POWER_OFF:
|
|
kernel_power_off();
|
|
do_exit(0);
|
|
break;
|
|
|
|
case LINUX_REBOOT_CMD_RESTART2:
|
|
ret = strncpy_from_user(&buffer[0], arg, sizeof(buffer) - 1);
|
|
if (ret < 0) {
|
|
ret = -EFAULT;
|
|
break;
|
|
}
|
|
buffer[sizeof(buffer) - 1] = '\0';
|
|
|
|
kernel_restart(buffer);
|
|
break;
|
|
|
|
#ifdef CONFIG_KEXEC_CORE
|
|
case LINUX_REBOOT_CMD_KEXEC:
|
|
ret = kernel_kexec();
|
|
break;
|
|
#endif
|
|
|
|
#ifdef CONFIG_HIBERNATION
|
|
case LINUX_REBOOT_CMD_SW_SUSPEND:
|
|
ret = hibernate();
|
|
break;
|
|
#endif
|
|
|
|
default:
|
|
ret = -EINVAL;
|
|
break;
|
|
}
|
|
mutex_unlock(&system_transition_mutex);
|
|
return ret;
|
|
}
|
|
|
|
static void deferred_cad(struct work_struct *dummy)
|
|
{
|
|
kernel_restart(NULL);
|
|
}
|
|
|
|
/*
|
|
* This function gets called by ctrl-alt-del - ie the keyboard interrupt.
|
|
* As it's called within an interrupt, it may NOT sync: the only choice
|
|
* is whether to reboot at once, or just ignore the ctrl-alt-del.
|
|
*/
|
|
void ctrl_alt_del(void)
|
|
{
|
|
static DECLARE_WORK(cad_work, deferred_cad);
|
|
|
|
if (C_A_D)
|
|
schedule_work(&cad_work);
|
|
else
|
|
kill_cad_pid(SIGINT, 1);
|
|
}
|
|
|
|
char poweroff_cmd[POWEROFF_CMD_PATH_LEN] = "/sbin/poweroff";
|
|
static const char reboot_cmd[] = "/sbin/reboot";
|
|
|
|
static int run_cmd(const char *cmd)
|
|
{
|
|
char **argv;
|
|
static char *envp[] = {
|
|
"HOME=/",
|
|
"PATH=/sbin:/bin:/usr/sbin:/usr/bin",
|
|
NULL
|
|
};
|
|
int ret;
|
|
argv = argv_split(GFP_KERNEL, cmd, NULL);
|
|
if (argv) {
|
|
ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_EXEC);
|
|
argv_free(argv);
|
|
} else {
|
|
ret = -ENOMEM;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int __orderly_reboot(void)
|
|
{
|
|
int ret;
|
|
|
|
ret = run_cmd(reboot_cmd);
|
|
|
|
if (ret) {
|
|
pr_warn("Failed to start orderly reboot: forcing the issue\n");
|
|
emergency_sync();
|
|
kernel_restart(NULL);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int __orderly_poweroff(bool force)
|
|
{
|
|
int ret;
|
|
|
|
ret = run_cmd(poweroff_cmd);
|
|
|
|
if (ret && force) {
|
|
pr_warn("Failed to start orderly shutdown: forcing the issue\n");
|
|
|
|
/*
|
|
* I guess this should try to kick off some daemon to sync and
|
|
* poweroff asap. Or not even bother syncing if we're doing an
|
|
* emergency shutdown?
|
|
*/
|
|
emergency_sync();
|
|
kernel_power_off();
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
static bool poweroff_force;
|
|
|
|
static void poweroff_work_func(struct work_struct *work)
|
|
{
|
|
__orderly_poweroff(poweroff_force);
|
|
}
|
|
|
|
static DECLARE_WORK(poweroff_work, poweroff_work_func);
|
|
|
|
/**
|
|
* orderly_poweroff - Trigger an orderly system poweroff
|
|
* @force: force poweroff if command execution fails
|
|
*
|
|
* This may be called from any context to trigger a system shutdown.
|
|
* If the orderly shutdown fails, it will force an immediate shutdown.
|
|
*/
|
|
void orderly_poweroff(bool force)
|
|
{
|
|
if (force) /* do not override the pending "true" */
|
|
poweroff_force = true;
|
|
schedule_work(&poweroff_work);
|
|
}
|
|
EXPORT_SYMBOL_GPL(orderly_poweroff);
|
|
|
|
static void reboot_work_func(struct work_struct *work)
|
|
{
|
|
__orderly_reboot();
|
|
}
|
|
|
|
static DECLARE_WORK(reboot_work, reboot_work_func);
|
|
|
|
/**
|
|
* orderly_reboot - Trigger an orderly system reboot
|
|
*
|
|
* This may be called from any context to trigger a system reboot.
|
|
* If the orderly reboot fails, it will force an immediate reboot.
|
|
*/
|
|
void orderly_reboot(void)
|
|
{
|
|
schedule_work(&reboot_work);
|
|
}
|
|
EXPORT_SYMBOL_GPL(orderly_reboot);
|
|
|
|
static int __init reboot_setup(char *str)
|
|
{
|
|
for (;;) {
|
|
enum reboot_mode *mode;
|
|
|
|
/*
|
|
* Having anything passed on the command line via
|
|
* reboot= will cause us to disable DMI checking
|
|
* below.
|
|
*/
|
|
reboot_default = 0;
|
|
|
|
if (!strncmp(str, "panic_", 6)) {
|
|
mode = &panic_reboot_mode;
|
|
str += 6;
|
|
} else {
|
|
mode = &reboot_mode;
|
|
}
|
|
|
|
switch (*str) {
|
|
case 'w':
|
|
*mode = REBOOT_WARM;
|
|
break;
|
|
|
|
case 'c':
|
|
*mode = REBOOT_COLD;
|
|
break;
|
|
|
|
case 'h':
|
|
*mode = REBOOT_HARD;
|
|
break;
|
|
|
|
case 's':
|
|
if (isdigit(*(str+1)))
|
|
reboot_cpu = simple_strtoul(str+1, NULL, 0);
|
|
else if (str[1] == 'm' && str[2] == 'p' &&
|
|
isdigit(*(str+3)))
|
|
reboot_cpu = simple_strtoul(str+3, NULL, 0);
|
|
else
|
|
*mode = REBOOT_SOFT;
|
|
if (reboot_cpu >= num_possible_cpus()) {
|
|
pr_err("Ignoring the CPU number in reboot= option. "
|
|
"CPU %d exceeds possible cpu number %d\n",
|
|
reboot_cpu, num_possible_cpus());
|
|
reboot_cpu = 0;
|
|
break;
|
|
}
|
|
break;
|
|
|
|
case 'g':
|
|
*mode = REBOOT_GPIO;
|
|
break;
|
|
|
|
case 'b':
|
|
case 'a':
|
|
case 'k':
|
|
case 't':
|
|
case 'e':
|
|
case 'p':
|
|
reboot_type = *str;
|
|
break;
|
|
|
|
case 'f':
|
|
reboot_force = 1;
|
|
break;
|
|
}
|
|
|
|
str = strchr(str, ',');
|
|
if (str)
|
|
str++;
|
|
else
|
|
break;
|
|
}
|
|
return 1;
|
|
}
|
|
__setup("reboot=", reboot_setup);
|