Changes in 4.9.318 USB: new quirk for Dell Gen 2 devices ptrace/xtensa: Replace PT_SINGLESTEP with TIF_SINGLESTEP ptrace: Reimplement PTRACE_KILL by always sending SIGKILL btrfs: add "0x" prefix for unsupported optional features drm/virtio: fix NULL pointer dereference in virtio_gpu_conn_get_modes mwifiex: add mutex lock for call in mwifiex_dfs_chan_sw_work_queue b43legacy: Fix assigning negative value to unsigned variable b43: Fix assigning negative value to unsigned variable ipw2x00: Fix potential NULL dereference in libipw_xmit() ACPICA: Avoid cache flush inside virtual machines ALSA: jack: Access input_dev under mutex drm/amd/pm: fix double free in si_parse_power_table() ath9k: fix QCA9561 PA bias level media: cx25821: Fix the warning when removing the module scsi: megaraid: Fix error check return value of register_chrdev() drm/amd/pm: fix the compile warning ipv6: Don't send rs packets to the interface of ARPHRD_TUNNEL ASoC: dapm: Don't fold register value changes into notifications dma-debug: change allocation mode from GFP_NOWAIT to GFP_ATIOMIC ipmi:ssif: Check for NULL msg when handling events and messages openrisc: start CPU timer early in boot nvme-pci: fix a NULL pointer dereference in nvme_alloc_admin_tags ASoC: rt5645: Fix errorenous cleanup order media: exynos4-is: Fix compile warning rxrpc: Return an error to sendmsg if call failed eth: tg3: silence the GCC 12 array-bounds warning fs: jfs: fix possible NULL pointer dereference in dbFree() ARM: OMAP1: clock: Fix UART rate reporting algorithm fat: add ratelimit to fat*_ent_bread() ARM: versatile: Add missing of_node_put in dcscb_init ARM: dts: exynos: add atmel,24c128 fallback to Samsung EEPROM ARM: hisi: Add missing of_node_put after of_find_compatible_node PCI: Avoid pci_dev_lock() AB/BA deadlock with sriov_numvfs_store() powerpc/xics: fix refcount leak in icp_opal_init() macintosh/via-pmu: Fix build failure when CONFIG_INPUT is disabled drm: fix EDID struct for old ARM OABI format ASoC: mediatek: Fix error handling in mt8173_max98090_dev_probe x86/delay: Fix the wrong asm constraint in delay_loop() drm/mediatek: Fix mtk_cec_mask() spi: spi-ti-qspi: Fix return value handling of wait_for_completion_timeout NFC: NULL out the dev->rfkill to prevent UAF HID: hid-led: fix maximum brightness for Dream Cheeky spi: img-spfi: Fix pm_runtime_get_sync() error checking ath9k_htc: fix potential out of bounds access with invalid rxstatus->rs_keyix inotify: show inotify mask flags in proc fdinfo x86/pm: Fix false positive kmemleak report in msr_build_context() drm/msm/dsi: fix error checks and return values for DSI xmit functions drm/msm/hdmi: check return value after calling platform_get_resource_byname() drm/rockchip: vop: fix possible null-ptr-deref in vop_bind() x86/mm: Cleanup the control_va_addr_alignment() __setup handler drm/msm: return an error pointer in msm_gem_prime_get_sg_table() media: uvcvideo: Fix missing check to determine if element is found in list ASoC: mxs-saif: Fix refcount leak in mxs_saif_probe regulator: pfuze100: Fix refcount leak in pfuze_parse_regulators_dt media: exynos4-is: Change clk_disable to clk_disable_unprepare media: pvrusb2: fix array-index-out-of-bounds in pvr2_i2c_core_init Bluetooth: fix dangling sco_conn and use-after-free in sco_sock_timeout m68k: math-emu: Fix dependencies of math emulation support sctp: read sk->sk_bound_dev_if once in sctp_rcv() ASoC: wm2000: fix missing clk_disable_unprepare() on error in wm2000_anc_transition() rxrpc: Fix listen() setting the bar too high for the prealloc rings rxrpc: Don't try to resend the request if we're receiving the reply soc: qcom: smp2p: Fix missing of_node_put() in smp2p_parse_ipc soc: qcom: smsm: Fix missing of_node_put() in smsm_parse_ipc mfd: ipaq-micro: Fix error check return value of platform_get_irq() scsi: fcoe: Fix Wstringop-overflow warnings in fcoe_wwn_from_mac() drivers/base/node.c: fix compaction sysfs file leak powerpc/8xx: export 'cpm_setbrg' for modules powerpc/idle: Fix return value of __setup() handler powerpc/4xx/cpm: Fix return value of __setup() handler tty: fix deadlock caused by calling printk() under tty_port->lock Input: sparcspkr - fix refcount leak in bbc_beep_probe video: fbdev: clcdfb: Fix refcount leak in clcdfb_of_vram_setup iommu/amd: Increase timeout waiting for GA log enablement wifi: mac80211: fix use-after-free in chanctx code iwlwifi: mvm: fix assert 1F04 upon reconfig fs-writeback: writeback_sb_inodes:Recalculate 'wrote' according skipped pages ext4: fix use-after-free in ext4_rename_dir_prepare ext4: fix bug_on in ext4_writepages ext4: verify dir block before splitting it dlm: fix plock invalid read dlm: fix missing lkb refcount handling ocfs2: dlmfs: fix error handling of user_dlm_destroy_lock scsi: dc395x: Fix a missing check on list iterator scsi: ufs: qcom: Add a readl() to make sure ref_clk gets enabled drm/amdgpu/cs: make commands with 0 chunks illegal behaviour. drm/bridge: analogix_dp: Grab runtime PM reference for DP-AUX md: fix an incorrect NULL check in does_sb_need_changing md: fix an incorrect NULL check in md_reload_sb RDMA/hfi1: Fix potential integer multiplication overflow errors irqchip/armada-370-xp: Do not touch Performance Counter Overflow on A375, A38x, A39x irqchip: irq-xtensa-mx: fix initial IRQ affinity mac80211: upgrade passive scan to active scan on DFS channels after beacon rx um: chan_user: Fix winch_tramp() return value um: Fix out-of-bounds read in LDT setup iommu/msm: Fix an incorrect NULL check on list iterator nodemask.h: fix compilation error with GCC12 hugetlb: fix huge_pmd_unshare address update rtl818x: Prevent using not initialized queues ASoC: rt5514: Fix event generation for "DSP Voice Wake Up" control carl9170: tx: fix an incorrect use of list iterator gma500: fix an incorrect NULL check on list iterator docs/conf.py: Cope with removal of language=None in Sphinx 5.0.0 dt-bindings: gpio: altera: correct interrupt-cells RDMA/rxe: Generate a completion for unsupported/invalid opcode MIPS: IP27: Remove incorrect `cpu_has_fpu' override netfilter: nf_tables: disallow non-stateful expression in sets earlier pcmcia: db1xxx_ss: restrict to MIPS_DB1XXX boards staging: greybus: codecs: fix type confusion of list iterator variable usb: usbip: fix a refcount leak in stub_probe() usb: usbip: add missing device lock on tweak configuration cmd USB: storage: karma: fix rio_karma_init return pwm: lp3943: Fix duty calculation in case period was clamped rpmsg: qcom_smd: Fix irq_of_parse_and_map() return value rtc: mt6397: check return value after calling platform_get_resource() serial: meson: acquire port->lock in startup() serial: digicolor-usart: Don't allow CS5-6 serial: txx9: Don't allow CS5-6 serial: sh-sci: Don't allow CS5-6 serial: st-asc: Sanitize CSIZE and correct PARENB for CS7 firmware: dmi-sysfs: Fix memory leak in dmi_sysfs_register_handle clocksource/drivers/oxnas-rps: Fix irq_of_parse_and_map() return value net: ethernet: mtk_eth_soc: out of bounds read in mtk_hwlro_get_fdir_entry() modpost: fix removing numeric suffixes jffs2: fix memory leak in jffs2_do_fill_super tcp: tcp_rtx_synack() can be called from process context tracing: Avoid adding tracer option before update_tracer_options i2c: cadence: Increase timeout per message if necessary m68knommu: set ZERO_PAGE() to the allocated zeroed page m68knommu: fix undefined reference to `_init_sp' video: fbdev: pxa3xx-gcu: release the resources correctly in pxa3xx_gcu_probe/remove() net: fix nla_strcmp to handle more then one trailing null character ata: pata_octeon_cf: Fix refcount leak in octeon_cf_probe net/mlx4_en: Fix wrong return value on ioctl EEPROM query failure SUNRPC: Fix the calculation of xdr->end in xdr_get_next_encode_buffer() net: xfrm: unexport __init-annotated xfrm4_protocol_init() net: altera: Fix refcount leak in altera_tse_mdio_create iio: dummy: iio_simple_dummy: check the return value of kstrdup() lkdtm/usercopy: Expand size of "out of frame" object tty: synclink_gt: Fix null-pointer-dereference in slgt_clean() tty: Fix a possible resource leak in icom_probe drivers: staging: rtl8192e: Fix deadlock in rtllib_beacons_stop() USB: host: isp116x: check return value after calling platform_get_resource() drivers: tty: serial: Fix deadlock in sa1100_set_termios() drivers: usb: host: Fix deadlock in oxu_bus_suspend() USB: hcd-pci: Fully suspend across freeze/thaw cycle usb: dwc2: gadget: don't reset gadget's driver->bus misc: rtsx: set NULL intfdata when probe fails clocksource/drivers/sp804: Avoid error on multiple instances staging: rtl8712: fix uninit-value in r871xu_drv_init() serial: msm_serial: disable interrupts in __msm_console_write() md: protect md_unregister_thread from reentrancy Revert "net: af_key: add check for pfkey_broadcast in function pfkey_process" drm/radeon: fix a possible null pointer dereference modpost: fix undefined behavior of is_arm_mapping_symbol() nodemask: Fix return values to be unsigned vringh: Fix loop descriptors check in the indirect cases ALSA: hda/conexant - Fix loopback issue with CX20632 cifs: return errors during session setup during reconnects ata: libata-transport: fix {dma|pio|xfer}_mode sysfs files nfc: st21nfca: fix incorrect validating logic in EVT_TRANSACTION nfc: st21nfca: fix memory leaks in EVT_TRANSACTION handling Input: bcm5974 - set missing URB_NO_TRANSFER_DMA_MAP urb flag powerpc/32: Fix overread/overwrite of thread_struct via ptrace mtd: cfi_cmdset_0002: Move and rename chip_check/chip_ready/chip_good_for_write mtd: cfi_cmdset_0002: Use chip_ready() for write on S29GL064N PCI: qcom: Fix unbalanced PHY init on probe errors tcp: fix tcp_mtup_probe_success vs wrong snd_cwnd Linux 4.9.318 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: I2028f3dcd422886bf997ec7e1d2ae86515f1bfb9
714 lines
19 KiB
C
714 lines
19 KiB
C
/*
|
|
* Basic Node interface support
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/init.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/memory.h>
|
|
#include <linux/vmstat.h>
|
|
#include <linux/notifier.h>
|
|
#include <linux/node.h>
|
|
#include <linux/hugetlb.h>
|
|
#include <linux/compaction.h>
|
|
#include <linux/cpumask.h>
|
|
#include <linux/topology.h>
|
|
#include <linux/nodemask.h>
|
|
#include <linux/cpu.h>
|
|
#include <linux/device.h>
|
|
#include <linux/swap.h>
|
|
#include <linux/slab.h>
|
|
|
|
static struct bus_type node_subsys = {
|
|
.name = "node",
|
|
.dev_name = "node",
|
|
};
|
|
|
|
|
|
static ssize_t node_read_cpumap(struct device *dev, bool list, char *buf)
|
|
{
|
|
struct node *node_dev = to_node(dev);
|
|
const struct cpumask *mask = cpumask_of_node(node_dev->dev.id);
|
|
|
|
/* 2008/04/07: buf currently PAGE_SIZE, need 9 chars per 32 bits. */
|
|
BUILD_BUG_ON((NR_CPUS/32 * 9) > (PAGE_SIZE-1));
|
|
|
|
return cpumap_print_to_pagebuf(list, buf, mask);
|
|
}
|
|
|
|
static inline ssize_t node_read_cpumask(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
return node_read_cpumap(dev, false, buf);
|
|
}
|
|
static inline ssize_t node_read_cpulist(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
return node_read_cpumap(dev, true, buf);
|
|
}
|
|
|
|
static DEVICE_ATTR(cpumap, S_IRUGO, node_read_cpumask, NULL);
|
|
static DEVICE_ATTR(cpulist, S_IRUGO, node_read_cpulist, NULL);
|
|
|
|
#define K(x) ((x) << (PAGE_SHIFT - 10))
|
|
static ssize_t node_read_meminfo(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
int n;
|
|
int nid = dev->id;
|
|
struct pglist_data *pgdat = NODE_DATA(nid);
|
|
struct sysinfo i;
|
|
|
|
si_meminfo_node(&i, nid);
|
|
n = sprintf(buf,
|
|
"Node %d MemTotal: %8lu kB\n"
|
|
"Node %d MemFree: %8lu kB\n"
|
|
"Node %d MemUsed: %8lu kB\n"
|
|
"Node %d Active: %8lu kB\n"
|
|
"Node %d Inactive: %8lu kB\n"
|
|
"Node %d Active(anon): %8lu kB\n"
|
|
"Node %d Inactive(anon): %8lu kB\n"
|
|
"Node %d Active(file): %8lu kB\n"
|
|
"Node %d Inactive(file): %8lu kB\n"
|
|
"Node %d Unevictable: %8lu kB\n"
|
|
"Node %d Mlocked: %8lu kB\n",
|
|
nid, K(i.totalram),
|
|
nid, K(i.freeram),
|
|
nid, K(i.totalram - i.freeram),
|
|
nid, K(node_page_state(pgdat, NR_ACTIVE_ANON) +
|
|
node_page_state(pgdat, NR_ACTIVE_FILE)),
|
|
nid, K(node_page_state(pgdat, NR_INACTIVE_ANON) +
|
|
node_page_state(pgdat, NR_INACTIVE_FILE)),
|
|
nid, K(node_page_state(pgdat, NR_ACTIVE_ANON)),
|
|
nid, K(node_page_state(pgdat, NR_INACTIVE_ANON)),
|
|
nid, K(node_page_state(pgdat, NR_ACTIVE_FILE)),
|
|
nid, K(node_page_state(pgdat, NR_INACTIVE_FILE)),
|
|
nid, K(node_page_state(pgdat, NR_UNEVICTABLE)),
|
|
nid, K(sum_zone_node_page_state(nid, NR_MLOCK)));
|
|
|
|
#ifdef CONFIG_HIGHMEM
|
|
n += sprintf(buf + n,
|
|
"Node %d HighTotal: %8lu kB\n"
|
|
"Node %d HighFree: %8lu kB\n"
|
|
"Node %d LowTotal: %8lu kB\n"
|
|
"Node %d LowFree: %8lu kB\n",
|
|
nid, K(i.totalhigh),
|
|
nid, K(i.freehigh),
|
|
nid, K(i.totalram - i.totalhigh),
|
|
nid, K(i.freeram - i.freehigh));
|
|
#endif
|
|
n += sprintf(buf + n,
|
|
"Node %d Dirty: %8lu kB\n"
|
|
"Node %d Writeback: %8lu kB\n"
|
|
"Node %d FilePages: %8lu kB\n"
|
|
"Node %d Mapped: %8lu kB\n"
|
|
"Node %d AnonPages: %8lu kB\n"
|
|
"Node %d Shmem: %8lu kB\n"
|
|
"Node %d KernelStack: %8lu kB\n"
|
|
"Node %d PageTables: %8lu kB\n"
|
|
"Node %d NFS_Unstable: %8lu kB\n"
|
|
"Node %d Bounce: %8lu kB\n"
|
|
"Node %d WritebackTmp: %8lu kB\n"
|
|
"Node %d Slab: %8lu kB\n"
|
|
"Node %d SReclaimable: %8lu kB\n"
|
|
"Node %d SUnreclaim: %8lu kB\n"
|
|
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
|
|
"Node %d AnonHugePages: %8lu kB\n"
|
|
"Node %d ShmemHugePages: %8lu kB\n"
|
|
"Node %d ShmemPmdMapped: %8lu kB\n"
|
|
#endif
|
|
,
|
|
nid, K(node_page_state(pgdat, NR_FILE_DIRTY)),
|
|
nid, K(node_page_state(pgdat, NR_WRITEBACK)),
|
|
nid, K(node_page_state(pgdat, NR_FILE_PAGES)),
|
|
nid, K(node_page_state(pgdat, NR_FILE_MAPPED)),
|
|
nid, K(node_page_state(pgdat, NR_ANON_MAPPED)),
|
|
nid, K(i.sharedram),
|
|
nid, sum_zone_node_page_state(nid, NR_KERNEL_STACK_KB),
|
|
nid, K(sum_zone_node_page_state(nid, NR_PAGETABLE)),
|
|
nid, K(node_page_state(pgdat, NR_UNSTABLE_NFS)),
|
|
nid, K(sum_zone_node_page_state(nid, NR_BOUNCE)),
|
|
nid, K(node_page_state(pgdat, NR_WRITEBACK_TEMP)),
|
|
nid, K(sum_zone_node_page_state(nid, NR_SLAB_RECLAIMABLE) +
|
|
sum_zone_node_page_state(nid, NR_SLAB_UNRECLAIMABLE)),
|
|
nid, K(sum_zone_node_page_state(nid, NR_SLAB_RECLAIMABLE)),
|
|
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
|
|
nid, K(sum_zone_node_page_state(nid, NR_SLAB_UNRECLAIMABLE)),
|
|
nid, K(node_page_state(pgdat, NR_ANON_THPS) *
|
|
HPAGE_PMD_NR),
|
|
nid, K(node_page_state(pgdat, NR_SHMEM_THPS) *
|
|
HPAGE_PMD_NR),
|
|
nid, K(node_page_state(pgdat, NR_SHMEM_PMDMAPPED) *
|
|
HPAGE_PMD_NR));
|
|
#else
|
|
nid, K(sum_zone_node_page_state(nid, NR_SLAB_UNRECLAIMABLE)));
|
|
#endif
|
|
n += hugetlb_report_node_meminfo(nid, buf + n);
|
|
return n;
|
|
}
|
|
|
|
#undef K
|
|
static DEVICE_ATTR(meminfo, S_IRUGO, node_read_meminfo, NULL);
|
|
|
|
static ssize_t node_read_numastat(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
return sprintf(buf,
|
|
"numa_hit %lu\n"
|
|
"numa_miss %lu\n"
|
|
"numa_foreign %lu\n"
|
|
"interleave_hit %lu\n"
|
|
"local_node %lu\n"
|
|
"other_node %lu\n",
|
|
sum_zone_node_page_state(dev->id, NUMA_HIT),
|
|
sum_zone_node_page_state(dev->id, NUMA_MISS),
|
|
sum_zone_node_page_state(dev->id, NUMA_FOREIGN),
|
|
sum_zone_node_page_state(dev->id, NUMA_INTERLEAVE_HIT),
|
|
sum_zone_node_page_state(dev->id, NUMA_LOCAL),
|
|
sum_zone_node_page_state(dev->id, NUMA_OTHER));
|
|
}
|
|
static DEVICE_ATTR(numastat, S_IRUGO, node_read_numastat, NULL);
|
|
|
|
static ssize_t node_read_vmstat(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
int nid = dev->id;
|
|
struct pglist_data *pgdat = NODE_DATA(nid);
|
|
int i;
|
|
int n = 0;
|
|
|
|
for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
|
|
n += sprintf(buf+n, "%s %lu\n", vmstat_text[i],
|
|
sum_zone_node_page_state(nid, i));
|
|
|
|
for (i = 0; i < NR_VM_NODE_STAT_ITEMS; i++)
|
|
n += sprintf(buf+n, "%s %lu\n",
|
|
vmstat_text[i + NR_VM_ZONE_STAT_ITEMS],
|
|
node_page_state(pgdat, i));
|
|
|
|
return n;
|
|
}
|
|
static DEVICE_ATTR(vmstat, S_IRUGO, node_read_vmstat, NULL);
|
|
|
|
static ssize_t node_read_distance(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
int nid = dev->id;
|
|
int len = 0;
|
|
int i;
|
|
|
|
/*
|
|
* buf is currently PAGE_SIZE in length and each node needs 4 chars
|
|
* at the most (distance + space or newline).
|
|
*/
|
|
BUILD_BUG_ON(MAX_NUMNODES * 4 > PAGE_SIZE);
|
|
|
|
for_each_online_node(i)
|
|
len += sprintf(buf + len, "%s%d", i ? " " : "", node_distance(nid, i));
|
|
|
|
len += sprintf(buf + len, "\n");
|
|
return len;
|
|
}
|
|
static DEVICE_ATTR(distance, S_IRUGO, node_read_distance, NULL);
|
|
|
|
static struct attribute *node_dev_attrs[] = {
|
|
&dev_attr_cpumap.attr,
|
|
&dev_attr_cpulist.attr,
|
|
&dev_attr_meminfo.attr,
|
|
&dev_attr_numastat.attr,
|
|
&dev_attr_distance.attr,
|
|
&dev_attr_vmstat.attr,
|
|
NULL
|
|
};
|
|
ATTRIBUTE_GROUPS(node_dev);
|
|
|
|
#ifdef CONFIG_HUGETLBFS
|
|
/*
|
|
* hugetlbfs per node attributes registration interface:
|
|
* When/if hugetlb[fs] subsystem initializes [sometime after this module],
|
|
* it will register its per node attributes for all online nodes with
|
|
* memory. It will also call register_hugetlbfs_with_node(), below, to
|
|
* register its attribute registration functions with this node driver.
|
|
* Once these hooks have been initialized, the node driver will call into
|
|
* the hugetlb module to [un]register attributes for hot-plugged nodes.
|
|
*/
|
|
static node_registration_func_t __hugetlb_register_node;
|
|
static node_registration_func_t __hugetlb_unregister_node;
|
|
|
|
static inline bool hugetlb_register_node(struct node *node)
|
|
{
|
|
if (__hugetlb_register_node &&
|
|
node_state(node->dev.id, N_MEMORY)) {
|
|
__hugetlb_register_node(node);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
static inline void hugetlb_unregister_node(struct node *node)
|
|
{
|
|
if (__hugetlb_unregister_node)
|
|
__hugetlb_unregister_node(node);
|
|
}
|
|
|
|
void register_hugetlbfs_with_node(node_registration_func_t doregister,
|
|
node_registration_func_t unregister)
|
|
{
|
|
__hugetlb_register_node = doregister;
|
|
__hugetlb_unregister_node = unregister;
|
|
}
|
|
#else
|
|
static inline void hugetlb_register_node(struct node *node) {}
|
|
|
|
static inline void hugetlb_unregister_node(struct node *node) {}
|
|
#endif
|
|
|
|
static void node_device_release(struct device *dev)
|
|
{
|
|
struct node *node = to_node(dev);
|
|
|
|
#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_HUGETLBFS)
|
|
/*
|
|
* We schedule the work only when a memory section is
|
|
* onlined/offlined on this node. When we come here,
|
|
* all the memory on this node has been offlined,
|
|
* so we won't enqueue new work to this work.
|
|
*
|
|
* The work is using node->node_work, so we should
|
|
* flush work before freeing the memory.
|
|
*/
|
|
flush_work(&node->node_work);
|
|
#endif
|
|
kfree(node);
|
|
}
|
|
|
|
/*
|
|
* register_node - Setup a sysfs device for a node.
|
|
* @num - Node number to use when creating the device.
|
|
*
|
|
* Initialize and register the node device.
|
|
*/
|
|
static int register_node(struct node *node, int num, struct node *parent)
|
|
{
|
|
int error;
|
|
|
|
node->dev.id = num;
|
|
node->dev.bus = &node_subsys;
|
|
node->dev.release = node_device_release;
|
|
node->dev.groups = node_dev_groups;
|
|
error = device_register(&node->dev);
|
|
|
|
if (!error){
|
|
hugetlb_register_node(node);
|
|
|
|
compaction_register_node(node);
|
|
}
|
|
return error;
|
|
}
|
|
|
|
/**
|
|
* unregister_node - unregister a node device
|
|
* @node: node going away
|
|
*
|
|
* Unregisters a node device @node. All the devices on the node must be
|
|
* unregistered before calling this function.
|
|
*/
|
|
void unregister_node(struct node *node)
|
|
{
|
|
compaction_unregister_node(node);
|
|
hugetlb_unregister_node(node); /* no-op, if memoryless node */
|
|
|
|
device_unregister(&node->dev);
|
|
}
|
|
|
|
struct node *node_devices[MAX_NUMNODES];
|
|
|
|
/*
|
|
* register cpu under node
|
|
*/
|
|
int register_cpu_under_node(unsigned int cpu, unsigned int nid)
|
|
{
|
|
int ret;
|
|
struct device *obj;
|
|
|
|
if (!node_online(nid))
|
|
return 0;
|
|
|
|
obj = get_cpu_device(cpu);
|
|
if (!obj)
|
|
return 0;
|
|
|
|
ret = sysfs_create_link(&node_devices[nid]->dev.kobj,
|
|
&obj->kobj,
|
|
kobject_name(&obj->kobj));
|
|
if (ret)
|
|
return ret;
|
|
|
|
return sysfs_create_link(&obj->kobj,
|
|
&node_devices[nid]->dev.kobj,
|
|
kobject_name(&node_devices[nid]->dev.kobj));
|
|
}
|
|
|
|
int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
|
|
{
|
|
struct device *obj;
|
|
|
|
if (!node_online(nid))
|
|
return 0;
|
|
|
|
obj = get_cpu_device(cpu);
|
|
if (!obj)
|
|
return 0;
|
|
|
|
sysfs_remove_link(&node_devices[nid]->dev.kobj,
|
|
kobject_name(&obj->kobj));
|
|
sysfs_remove_link(&obj->kobj,
|
|
kobject_name(&node_devices[nid]->dev.kobj));
|
|
|
|
return 0;
|
|
}
|
|
|
|
#ifdef CONFIG_MEMORY_HOTPLUG_SPARSE
|
|
#define page_initialized(page) (page->lru.next)
|
|
|
|
static int __ref get_nid_for_pfn(unsigned long pfn)
|
|
{
|
|
struct page *page;
|
|
|
|
if (!pfn_valid_within(pfn))
|
|
return -1;
|
|
#ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT
|
|
if (system_state == SYSTEM_BOOTING)
|
|
return early_pfn_to_nid(pfn);
|
|
#endif
|
|
page = pfn_to_page(pfn);
|
|
if (!page_initialized(page))
|
|
return -1;
|
|
return pfn_to_nid(pfn);
|
|
}
|
|
|
|
/* register memory section under specified node if it spans that node */
|
|
int register_mem_sect_under_node(struct memory_block *mem_blk, int nid)
|
|
{
|
|
int ret;
|
|
unsigned long pfn, sect_start_pfn, sect_end_pfn;
|
|
|
|
if (!mem_blk)
|
|
return -EFAULT;
|
|
if (!node_online(nid))
|
|
return 0;
|
|
|
|
sect_start_pfn = section_nr_to_pfn(mem_blk->start_section_nr);
|
|
sect_end_pfn = section_nr_to_pfn(mem_blk->end_section_nr);
|
|
sect_end_pfn += PAGES_PER_SECTION - 1;
|
|
for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) {
|
|
int page_nid;
|
|
|
|
/*
|
|
* memory block could have several absent sections from start.
|
|
* skip pfn range from absent section
|
|
*/
|
|
if (!pfn_present(pfn)) {
|
|
pfn = round_down(pfn + PAGES_PER_SECTION,
|
|
PAGES_PER_SECTION) - 1;
|
|
continue;
|
|
}
|
|
|
|
page_nid = get_nid_for_pfn(pfn);
|
|
if (page_nid < 0)
|
|
continue;
|
|
if (page_nid != nid)
|
|
continue;
|
|
ret = sysfs_create_link_nowarn(&node_devices[nid]->dev.kobj,
|
|
&mem_blk->dev.kobj,
|
|
kobject_name(&mem_blk->dev.kobj));
|
|
if (ret)
|
|
return ret;
|
|
|
|
return sysfs_create_link_nowarn(&mem_blk->dev.kobj,
|
|
&node_devices[nid]->dev.kobj,
|
|
kobject_name(&node_devices[nid]->dev.kobj));
|
|
}
|
|
/* mem section does not span the specified node */
|
|
return 0;
|
|
}
|
|
|
|
/* unregister memory section under all nodes that it spans */
|
|
int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
|
|
unsigned long phys_index)
|
|
{
|
|
NODEMASK_ALLOC(nodemask_t, unlinked_nodes, GFP_KERNEL);
|
|
unsigned long pfn, sect_start_pfn, sect_end_pfn;
|
|
|
|
if (!mem_blk) {
|
|
NODEMASK_FREE(unlinked_nodes);
|
|
return -EFAULT;
|
|
}
|
|
if (!unlinked_nodes)
|
|
return -ENOMEM;
|
|
nodes_clear(*unlinked_nodes);
|
|
|
|
sect_start_pfn = section_nr_to_pfn(phys_index);
|
|
sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1;
|
|
for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) {
|
|
int nid;
|
|
|
|
nid = get_nid_for_pfn(pfn);
|
|
if (nid < 0)
|
|
continue;
|
|
if (!node_online(nid))
|
|
continue;
|
|
if (node_test_and_set(nid, *unlinked_nodes))
|
|
continue;
|
|
sysfs_remove_link(&node_devices[nid]->dev.kobj,
|
|
kobject_name(&mem_blk->dev.kobj));
|
|
sysfs_remove_link(&mem_blk->dev.kobj,
|
|
kobject_name(&node_devices[nid]->dev.kobj));
|
|
}
|
|
NODEMASK_FREE(unlinked_nodes);
|
|
return 0;
|
|
}
|
|
|
|
static int link_mem_sections(int nid)
|
|
{
|
|
unsigned long start_pfn = NODE_DATA(nid)->node_start_pfn;
|
|
unsigned long end_pfn = start_pfn + NODE_DATA(nid)->node_spanned_pages;
|
|
unsigned long pfn;
|
|
struct memory_block *mem_blk = NULL;
|
|
int err = 0;
|
|
|
|
for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) {
|
|
unsigned long section_nr = pfn_to_section_nr(pfn);
|
|
struct mem_section *mem_sect;
|
|
int ret;
|
|
|
|
if (!present_section_nr(section_nr))
|
|
continue;
|
|
mem_sect = __nr_to_section(section_nr);
|
|
|
|
/* same memblock ? */
|
|
if (mem_blk)
|
|
if ((section_nr >= mem_blk->start_section_nr) &&
|
|
(section_nr <= mem_blk->end_section_nr))
|
|
continue;
|
|
|
|
mem_blk = find_memory_block_hinted(mem_sect, mem_blk);
|
|
|
|
ret = register_mem_sect_under_node(mem_blk, nid);
|
|
if (!err)
|
|
err = ret;
|
|
|
|
/* discard ref obtained in find_memory_block() */
|
|
}
|
|
|
|
if (mem_blk)
|
|
kobject_put(&mem_blk->dev.kobj);
|
|
return err;
|
|
}
|
|
|
|
#ifdef CONFIG_HUGETLBFS
|
|
/*
|
|
* Handle per node hstate attribute [un]registration on transistions
|
|
* to/from memoryless state.
|
|
*/
|
|
static void node_hugetlb_work(struct work_struct *work)
|
|
{
|
|
struct node *node = container_of(work, struct node, node_work);
|
|
|
|
/*
|
|
* We only get here when a node transitions to/from memoryless state.
|
|
* We can detect which transition occurred by examining whether the
|
|
* node has memory now. hugetlb_register_node() already check this
|
|
* so we try to register the attributes. If that fails, then the
|
|
* node has transitioned to memoryless, try to unregister the
|
|
* attributes.
|
|
*/
|
|
if (!hugetlb_register_node(node))
|
|
hugetlb_unregister_node(node);
|
|
}
|
|
|
|
static void init_node_hugetlb_work(int nid)
|
|
{
|
|
INIT_WORK(&node_devices[nid]->node_work, node_hugetlb_work);
|
|
}
|
|
|
|
static int node_memory_callback(struct notifier_block *self,
|
|
unsigned long action, void *arg)
|
|
{
|
|
struct memory_notify *mnb = arg;
|
|
int nid = mnb->status_change_nid;
|
|
|
|
switch (action) {
|
|
case MEM_ONLINE:
|
|
case MEM_OFFLINE:
|
|
/*
|
|
* offload per node hstate [un]registration to a work thread
|
|
* when transitioning to/from memoryless state.
|
|
*/
|
|
if (nid != NUMA_NO_NODE)
|
|
schedule_work(&node_devices[nid]->node_work);
|
|
break;
|
|
|
|
case MEM_GOING_ONLINE:
|
|
case MEM_GOING_OFFLINE:
|
|
case MEM_CANCEL_ONLINE:
|
|
case MEM_CANCEL_OFFLINE:
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return NOTIFY_OK;
|
|
}
|
|
#endif /* CONFIG_HUGETLBFS */
|
|
#else /* !CONFIG_MEMORY_HOTPLUG_SPARSE */
|
|
|
|
static int link_mem_sections(int nid) { return 0; }
|
|
#endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */
|
|
|
|
#if !defined(CONFIG_MEMORY_HOTPLUG_SPARSE) || \
|
|
!defined(CONFIG_HUGETLBFS)
|
|
static inline int node_memory_callback(struct notifier_block *self,
|
|
unsigned long action, void *arg)
|
|
{
|
|
return NOTIFY_OK;
|
|
}
|
|
|
|
static void init_node_hugetlb_work(int nid) { }
|
|
|
|
#endif
|
|
|
|
int register_one_node(int nid)
|
|
{
|
|
int error = 0;
|
|
int cpu;
|
|
|
|
if (node_online(nid)) {
|
|
int p_node = parent_node(nid);
|
|
struct node *parent = NULL;
|
|
|
|
if (p_node != nid)
|
|
parent = node_devices[p_node];
|
|
|
|
node_devices[nid] = kzalloc(sizeof(struct node), GFP_KERNEL);
|
|
if (!node_devices[nid])
|
|
return -ENOMEM;
|
|
|
|
error = register_node(node_devices[nid], nid, parent);
|
|
|
|
/* link cpu under this node */
|
|
for_each_present_cpu(cpu) {
|
|
if (cpu_to_node(cpu) == nid)
|
|
register_cpu_under_node(cpu, nid);
|
|
}
|
|
|
|
/* link memory sections under this node */
|
|
error = link_mem_sections(nid);
|
|
|
|
/* initialize work queue for memory hot plug */
|
|
init_node_hugetlb_work(nid);
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
void unregister_one_node(int nid)
|
|
{
|
|
if (!node_devices[nid])
|
|
return;
|
|
|
|
unregister_node(node_devices[nid]);
|
|
node_devices[nid] = NULL;
|
|
}
|
|
|
|
/*
|
|
* node states attributes
|
|
*/
|
|
|
|
static ssize_t print_nodes_state(enum node_states state, char *buf)
|
|
{
|
|
int n;
|
|
|
|
n = scnprintf(buf, PAGE_SIZE - 1, "%*pbl",
|
|
nodemask_pr_args(&node_states[state]));
|
|
buf[n++] = '\n';
|
|
buf[n] = '\0';
|
|
return n;
|
|
}
|
|
|
|
struct node_attr {
|
|
struct device_attribute attr;
|
|
enum node_states state;
|
|
};
|
|
|
|
static ssize_t show_node_state(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct node_attr *na = container_of(attr, struct node_attr, attr);
|
|
return print_nodes_state(na->state, buf);
|
|
}
|
|
|
|
#define _NODE_ATTR(name, state) \
|
|
{ __ATTR(name, 0444, show_node_state, NULL), state }
|
|
|
|
static struct node_attr node_state_attr[] = {
|
|
[N_POSSIBLE] = _NODE_ATTR(possible, N_POSSIBLE),
|
|
[N_ONLINE] = _NODE_ATTR(online, N_ONLINE),
|
|
[N_NORMAL_MEMORY] = _NODE_ATTR(has_normal_memory, N_NORMAL_MEMORY),
|
|
#ifdef CONFIG_HIGHMEM
|
|
[N_HIGH_MEMORY] = _NODE_ATTR(has_high_memory, N_HIGH_MEMORY),
|
|
#endif
|
|
#ifdef CONFIG_MOVABLE_NODE
|
|
[N_MEMORY] = _NODE_ATTR(has_memory, N_MEMORY),
|
|
#endif
|
|
[N_CPU] = _NODE_ATTR(has_cpu, N_CPU),
|
|
};
|
|
|
|
static struct attribute *node_state_attrs[] = {
|
|
&node_state_attr[N_POSSIBLE].attr.attr,
|
|
&node_state_attr[N_ONLINE].attr.attr,
|
|
&node_state_attr[N_NORMAL_MEMORY].attr.attr,
|
|
#ifdef CONFIG_HIGHMEM
|
|
&node_state_attr[N_HIGH_MEMORY].attr.attr,
|
|
#endif
|
|
#ifdef CONFIG_MOVABLE_NODE
|
|
&node_state_attr[N_MEMORY].attr.attr,
|
|
#endif
|
|
&node_state_attr[N_CPU].attr.attr,
|
|
NULL
|
|
};
|
|
|
|
static struct attribute_group memory_root_attr_group = {
|
|
.attrs = node_state_attrs,
|
|
};
|
|
|
|
static const struct attribute_group *cpu_root_attr_groups[] = {
|
|
&memory_root_attr_group,
|
|
NULL,
|
|
};
|
|
|
|
#define NODE_CALLBACK_PRI 2 /* lower than SLAB */
|
|
static int __init register_node_type(void)
|
|
{
|
|
int ret;
|
|
|
|
BUILD_BUG_ON(ARRAY_SIZE(node_state_attr) != NR_NODE_STATES);
|
|
BUILD_BUG_ON(ARRAY_SIZE(node_state_attrs)-1 != NR_NODE_STATES);
|
|
|
|
ret = subsys_system_register(&node_subsys, cpu_root_attr_groups);
|
|
if (!ret) {
|
|
static struct notifier_block node_memory_callback_nb = {
|
|
.notifier_call = node_memory_callback,
|
|
.priority = NODE_CALLBACK_PRI,
|
|
};
|
|
register_hotmemory_notifier(&node_memory_callback_nb);
|
|
}
|
|
|
|
/*
|
|
* Note: we're not going to unregister the node class if we fail
|
|
* to register the node state class attribute files.
|
|
*/
|
|
return ret;
|
|
}
|
|
postcore_initcall(register_node_type);
|