Files
Thierry Strudel a73c81554f Merged linux-4.4.88 into android-msm-wahoo-4.4
Linux 4.4.88
    xfs: XFS_IS_REALTIME_INODE() should be false if no rt device present
    NFS: Fix 2 use after free issues in the I/O code
    ARM: 8692/1: mm: abort uaccess retries upon fatal signal
    Bluetooth: Properly check L2CAP config option output buffer length
    ALSA: msnd: Optimize / harden DSP and MIDI loops
    locktorture: Fix potential memory leak with rw lock test
    btrfs: resume qgroup rescan on rw remount
    drm/bridge: adv7511: Re-write the i2c address before EDID probing
    drm/bridge: adv7511: Switch to using drm_kms_helper_hotplug_event()
    drm/bridge: adv7511: Use work_struct to defer hotplug handing to out of irq context
    drm/bridge: adv7511: Fix mutex deadlock when interrupts are disabled
    drm: adv7511: really enable interrupts for EDID detection
    scsi: sg: recheck MMAP_IO request length with lock held
    scsi: sg: protect against races between mmap() and SG_SET_RESERVED_SIZE
    cs5536: add support for IDE controller variant
    workqueue: Fix flag collision
    drm/nouveau/pci/msi: disable MSI on big-endian platforms by default
    mwifiex: correct channel stat buffer overflows
    dlm: avoid double-free on error path in dlm_device_{register,unregister}
    Bluetooth: Add support of 13d3:3494 RTL8723BE device
    rtlwifi: rtl_pci_probe: Fix fail path of _rtl_pci_find_adapter
    Input: trackpoint - assume 3 buttons when buttons detection fails
    ath10k: fix memory leak in rx ring buffer allocation
    intel_th: pci: Add Cannon Lake PCH-LP support
    intel_th: pci: Add Cannon Lake PCH-H support
    driver core: bus: Fix a potential double free
    staging/rts5208: fix incorrect shift to extract upper nybble
    USB: core: Avoid race of async_completed() w/ usbdev_release()
    usb:xhci:Fix regression when ATI chipsets detected
    usb: Add device quirk for Logitech HD Pro Webcam C920-C
    USB: serial: option: add support for D-Link DWM-157 C1
    usb: quirks: add delay init quirk for Corsair Strafe RGB keyboard
Linux 4.4.87
    crypto: algif_skcipher - only call put_page on referenced and used pages
    epoll: fix race between ep_poll_callback(POLLFREE) and ep_free()/ep_remove()
    kvm: arm/arm64: Force reading uncached stage2 PGD
    kvm: arm/arm64: Fix race in resetting stage2 PGD
    drm/ttm: Fix accounting error when fail to get pages for pool
    xfrm: policy: check policy direction value
    wl1251: add a missing spin_lock_init()
    CIFS: remove endian related sparse warning
    CIFS: Fix maximum SMB2 header size
    alpha: uapi: Add support for __SANE_USERSPACE_TYPES__
    cpuset: Fix incorrect memory_pressure control file mapping
    cpumask: fix spurious cpumask_of_node() on non-NUMA multi-node configs
    ceph: fix readpage from fscache
    i2c: ismt: Return EMSGSIZE for block reads with bogus length
    i2c: ismt: Don't duplicate the receive length for block reads
    irqchip: mips-gic: SYNC after enabling GIC region
Linux 4.4.86
    drm/i915: fix compiler warning in drivers/gpu/drm/i915/intel_uncore.c
    scsi: sg: reset 'res_in_use' after unlinking reserved array
    scsi: sg: protect accesses to 'reserved' page array
    arm64: fpsimd: Prevent registers leaking across exec
    x86/io: Add "memory" clobber to insb/insw/insl/outsb/outsw/outsl
    arm64: mm: abort uaccess retries upon fatal signal
    lpfc: Fix Device discovery failures during switch reboot test.
    p54: memset(0) whole array
    lightnvm: initialize ppa_addr in dev_to_generic_addr()
    gcov: support GCC 7.1
    gcov: add support for gcc version >= 6
    i2c: jz4780: drop superfluous init
    btrfs: remove duplicate const specifier
    ALSA: au88x0: Fix zero clear of stream->resources
    scsi: isci: avoid array subscript warning
Linux 4.4.85
    ACPI / APEI: Add missing synchronize_rcu() on NOTIFY_SCI removal
    ACPI: ioapic: Clear on-stack resource before using it
    ntb_transport: fix bug calculating num_qps_mw
    ntb_transport: fix qp count bug
    ASoC: rsnd: don't call update callback if it was NULL
    ASoC: rsnd: ssi: 24bit data needs right-aligned settings
    ASoC: rsnd: Add missing initialization of ADG req_rate
    ASoC: rsnd: avoid pointless loop in rsnd_mod_interrupt()
    ASoC: rsnd: disable SRC.out only when stop timing
    ASoC: simple-card: don't fail if sysclk setting is not supported
    staging: rtl8188eu: add RNX-N150NUB support
    iio: hid-sensor-trigger: Fix the race with user space powering up sensors
    iio: imu: adis16480: Fix acceleration scale factor for adis16480
    ANDROID: binder: fix proc->tsk check.
    binder: Use wake up hint for synchronous transactions.
    binder: use group leader instead of open thread
    Bluetooth: bnep: fix possible might sleep error in bnep_session
    Bluetooth: cmtp: fix possible might sleep error in cmtp_session
    Bluetooth: hidp: fix possible might sleep error in hidp_session_thread
    perf/core: Fix group {cpu,task} validation
    nfsd: Limit end of page list when decoding NFSv4 WRITE
    cifs: return ENAMETOOLONG for overlong names in cifs_open()/cifs_lookup()
    cifs: Fix df output for users with quota limits
    tracing: Fix freeing of filter in create_filter() when set_str is false
    drm: rcar-du: Fix H/V sync signal polarity configuration
    drm: rcar-du: Fix display timing controller parameter
    drm: rcar-du: Fix crash in encoder failure error path
    drm: rcar-du: lvds: Rename PLLEN bit to PLLON
    drm: rcar-du: lvds: Fix PLL frequency-related configuration
    drm/atomic: If the atomic check fails, return its value first
    drm: Release driver tracking before making the object available again
    i2c: designware: Fix system suspend
    ARCv2: PAE40: Explicitly set MSB counterpart of SLC region ops addresses
    ALSA: hda - Add stereo mic quirk for Lenovo G50-70 (17aa:3978)
    ALSA: core: Fix unexpected error at replacing user TLV
    Input: elan_i2c - add ELAN0602 ACPI ID to support Lenovo Yoga310
    Input: trackpoint - add new trackpoint firmware ID
    mei: me: add lewisburg device ids
    mei: me: add broxton pci device ids
    net_sched: fix order of queue length updates in qdisc_replace()
    net: sched: fix NULL pointer dereference when action calls some targets
    irda: do not leak initialized list.dev to userspace
    tcp: when rearming RTO, if RTO time is in past then fire RTO ASAP
    ipv6: repair fib6 tree in failure case
    ipv6: reset fn->rr_ptr when replacing route
    tipc: fix use-after-free
    sctp: fully initialize the IPv6 address in sctp_v6_to_addr()
    ipv4: better IP_MAX_MTU enforcement
    net_sched/sfq: update hierarchical backlog when drop packet
    ipv4: fix NULL dereference in free_fib_info_rcu()
    dccp: defer ccid_hc_tx_delete() at dismantle time
    dccp: purge write queue in dccp_destroy_sock()
    af_key: do not use GFP_KERNEL in atomic contexts
Linux 4.4.84
    usb: qmi_wwan: add D-Link DWM-222 device ID
    usb: optimize acpi companion search for usb port devices
    perf/x86: Fix LBR related crashes on Intel Atom
    pids: make task_tgid_nr_ns() safe
    Sanitize 'move_pages()' permission checks
    irqchip/atmel-aic: Fix unbalanced refcount in aic_common_rtc_irq_fixup()
    irqchip/atmel-aic: Fix unbalanced of_node_put() in aic_common_irq_fixup()
    x86/asm/64: Clear AC on NMI entries
    xen: fix bio vec merging
    mm: revert x86_64 and arm64 ELF_ET_DYN_BASE base changes
    mm/mempolicy: fix use after free when calling get_mempolicy
    ALSA: usb-audio: Add mute TLV for playback volumes on C-Media devices
    ALSA: usb-audio: Apply sample rate quirk to Sennheiser headset
    ALSA: seq: 2nd attempt at fixing race creating a queue
    Input: elan_i2c - Add antoher Lenovo ACPI ID for upcoming Lenovo NB
    Input: elan_i2c - add ELAN0608 to the ACPI table
    crypto: x86/sha1 - Fix reads beyond the number of blocks passed
    parisc: pci memory bar assignment fails with 64bit kernels on dino/cujo
    audit: Fix use after free in audit_remove_watch_rule()
    netfilter: nf_ct_ext: fix possible panic after nf_ct_extend_unregister
Linux 4.4.83
    pinctrl: samsung: Remove bogus irq_[un]mask from resource management
    pinctrl: sunxi: add a missing function of A10/A20 pinctrl driver
    pnfs/blocklayout: require 64-bit sector_t
    iio: adc: vf610_adc: Fix VALT selection value for REFSEL bits
    usb:xhci:Add quirk for Certain failing HP keyboard on reset after resume
    usb: quirks: Add no-lpm quirk for Moshi USB to Ethernet Adapter
    usb: core: unlink urbs from the tail of the endpoint's urb_list
    USB: Check for dropped connection before switching to full speed
    uas: Add US_FL_IGNORE_RESIDUE for Initio Corporation INIC-3069
    iio: light: tsl2563: use correct event code
    iio: accel: bmc150: Always restore device to normal mode after suspend-resume
    staging:iio:resolver:ad2s1210 fix negative IIO_ANGL_VEL read
    USB: hcd: Mark secondary HCD as dead if the primary one died
    usb: musb: fix tx fifo flush handling again
    USB: serial: pl2303: add new ATEN device id
    USB: serial: cp210x: add support for Qivicon USB ZigBee dongle
    USB: serial: option: add D-Link DWM-222 device ID
    nfs/flexfiles: fix leak of nfs4_ff_ds_version arrays
    fuse: initialize the flock flag in fuse_file on allocation
    iscsi-target: Fix iscsi_np reset hung task during parallel delete
    iscsi-target: fix memory leak in iscsit_setup_text_cmd()
    mm: ratelimit PFNs busy info message
    cpuset: fix a deadlock due to incomplete patching of cpusets_enabled()
Linux 4.4.82
    net: account for current skb length when deciding about UFO
    ipv4: Should use consistent conditional judgement for ip fragment in __ip_append_data and ip_finish_output
    mm/mempool: avoid KASAN marking mempool poison checks as use-after-free
    KVM: arm/arm64: Handle hva aging while destroying the vm
    sparc64: Prevent perf from running during super critical sections
    udp: consistently apply ufo or fragmentation
    revert "ipv4: Should use consistent conditional judgement for ip fragment in __ip_append_data and ip_finish_output"
    revert "net: account for current skb length when deciding about UFO"
    packet: fix tp_reserve race in packet_set_ring
    net: avoid skb_warn_bad_offload false positives on UFO
    tcp: fastopen: tcp_connect() must refresh the route
    net: sched: set xt_tgchk_param par.nft_compat as 0 in ipt_init_target
    bpf, s390: fix jit branch offset related to ldimm64
    net: fix keepalive code vs TCP_FASTOPEN_CONNECT
    tcp: avoid setting cwnd to invalid ssthresh after cwnd reduction states
Linux 4.4.81
    workqueue: implicit ordered attribute should be overridable
    net: account for current skb length when deciding about UFO
    ipv4: Should use consistent conditional judgement for ip fragment in __ip_append_data and ip_finish_output
    mm: don't dereference struct page fields of invalid pages
    signal: protect SIGNAL_UNKILLABLE from unintentional clearing.
    lib/Kconfig.debug: fix frv build failure
    mm, slab: make sure that KMALLOC_MAX_SIZE will fit into MAX_ORDER
    ARM: 8632/1: ftrace: fix syscall name matching
    virtio_blk: fix panic in initialization error path
    drm/virtio: fix framebuffer sparse warning
    scsi: qla2xxx: Get mutex lock before checking optrom_state
    phy state machine: failsafe leave invalid RUNNING state
    x86/boot: Add missing declaration of string functions
    tg3: Fix race condition in tg3_get_stats64().
    net: phy: dp83867: fix irq generation
    sh_eth: R8A7740 supports packet shecksumming
    wext: handle NULL extra data in iwe_stream_add_point better
    sparc64: Measure receiver forward progress to avoid send mondo timeout
    xen-netback: correctly schedule rate-limited queues
    net: phy: Fix PHY unbind crash
    net: phy: Correctly process PHY_HALTED in phy_stop_machine()
    net/mlx5: Fix command bad flow on command entry allocation failure
    sctp: fix the check for _sctp_walk_params and _sctp_walk_errors
    sctp: don't dereference ptr before leaving _sctp_walk_{params, errors}()
    dccp: fix a memleak for dccp_feat_init err process
    dccp: fix a memleak that dccp_ipv4 doesn't put reqsk properly
    dccp: fix a memleak that dccp_ipv6 doesn't put reqsk properly
    net: ethernet: nb8800: Handle all 4 RGMII modes identically
    ipv6: Don't increase IPSTATS_MIB_FRAGFAILS twice in ip6_fragment()
    packet: fix use-after-free in prb_retire_rx_blk_timer_expired()
    openvswitch: fix potential out of bound access in parse_ct
    mcs7780: Fix initialization when CONFIG_VMAP_STACK is enabled
    rtnetlink: allocate more memory for dev_set_mac_address()
    ipv4: initialize fib_trie prior to register_netdev_notifier call.
    ipv6: avoid overflow of offset in ip6_find_1stfragopt
    net: Zero terminate ifr_name in dev_ifname().
    ipv4: ipv6: initialize treq->txhash in cookie_v[46]_check()
    saa7164: fix double fetch PCIe access condition
    drm: rcar-du: fix backport bug
    f2fs: sanity check checkpoint segno and blkoff
    media: lirc: LIRC_GET_REC_RESOLUTION should return microseconds
    mm, mprotect: flush TLB if potentially racing with a parallel reclaim leaving stale TLB entries
    iser-target: Avoid isert_conn->cm_id dereference in isert_login_recv_done
    iscsi-target: Fix delayed logout processing greater than SECONDS_FOR_LOGOUT_COMP
    iscsi-target: Fix initial login PDU asynchronous socket close OOPs
    iscsi-target: Fix early sk_data_ready LOGIN_FLAGS_READY race
    iscsi-target: Always wait for kthread_should_stop() before kthread exit
    target: Avoid mappedlun symlink creation during lun shutdown
    media: platform: davinci: return -EINVAL for VPFE_CMD_S_CCDC_RAW_PARAMS ioctl
    ARM: dts: armada-38x: Fix irq type for pca955
    ext4: fix overflow caused by missing cast in ext4_resize_fs()
    ext4: fix SEEK_HOLE/SEEK_DATA for blocksize < pagesize
    mm/page_alloc: Remove kernel address exposure in free_reserved_area()
    KVM: async_pf: make rcu irq exit if not triggered from idle task
    ASoC: do not close shared backend dailink
    ALSA: hda - Fix speaker output from VAIO VPCL14M1R
    workqueue: restore WQ_UNBOUND/max_active==1 to be ordered
    libata: array underflow in ata_find_dev()

Bug: 62730977
Change-Id: I08905b35c8abf614055051b789f2114c2157dab9
Signed-off-by: Thierry Strudel <tstrudel@google.com>
2017-09-21 13:31:24 -07:00

638 lines
19 KiB
C

/*
* Written by Mark Hemment, 1996 (markhe@nextd.demon.co.uk).
*
* (C) SGI 2006, Christoph Lameter
* Cleaned up and restructured to ease the addition of alternative
* implementations of SLAB allocators.
* (C) Linux Foundation 2008-2013
* Unified interface for all slab allocators
*/
#ifndef _LINUX_SLAB_H
#define _LINUX_SLAB_H
#include <linux/gfp.h>
#include <linux/types.h>
#include <linux/workqueue.h>
/*
* Flags to pass to kmem_cache_create().
* The ones marked DEBUG are only valid if CONFIG_DEBUG_SLAB is set.
*/
#define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
#define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
#define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
#define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
#define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
#define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
#define SLAB_PANIC 0x00040000UL /* Panic if kmem_cache_create() fails */
/*
* SLAB_DESTROY_BY_RCU - **WARNING** READ THIS!
*
* This delays freeing the SLAB page by a grace period, it does _NOT_
* delay object freeing. This means that if you do kmem_cache_free()
* that memory location is free to be reused at any time. Thus it may
* be possible to see another object there in the same RCU grace period.
*
* This feature only ensures the memory location backing the object
* stays valid, the trick to using this is relying on an independent
* object validation pass. Something like:
*
* rcu_read_lock()
* again:
* obj = lockless_lookup(key);
* if (obj) {
* if (!try_get_ref(obj)) // might fail for free objects
* goto again;
*
* if (obj->key != key) { // not the object we expected
* put_ref(obj);
* goto again;
* }
* }
* rcu_read_unlock();
*
* This is useful if we need to approach a kernel structure obliquely,
* from its address obtained without the usual locking. We can lock
* the structure to stabilize it and check it's still at the given address,
* only if we can be sure that the memory has not been meanwhile reused
* for some other kind of object (which our subsystem's lock might corrupt).
*
* rcu_read_lock before reading the address, then rcu_read_unlock after
* taking the spinlock within the structure expected at that address.
*/
#define SLAB_DESTROY_BY_RCU 0x00080000UL /* Defer freeing slabs to RCU */
#define SLAB_MEM_SPREAD 0x00100000UL /* Spread some memory over cpuset */
#define SLAB_TRACE 0x00200000UL /* Trace allocations and frees */
/* Flag to prevent checks on free */
#ifdef CONFIG_DEBUG_OBJECTS
# define SLAB_DEBUG_OBJECTS 0x00400000UL
#else
# define SLAB_DEBUG_OBJECTS 0x00000000UL
#endif
#define SLAB_NOLEAKTRACE 0x00800000UL /* Avoid kmemleak tracing */
/* Don't track use of uninitialized memory */
#ifdef CONFIG_KMEMCHECK
# define SLAB_NOTRACK 0x01000000UL
#else
# define SLAB_NOTRACK 0x00000000UL
#endif
#ifdef CONFIG_FAILSLAB
# define SLAB_FAILSLAB 0x02000000UL /* Fault injection mark */
#else
# define SLAB_FAILSLAB 0x00000000UL
#endif
#ifdef CONFIG_KASAN
#define SLAB_KASAN 0x08000000UL
#else
#define SLAB_KASAN 0x00000000UL
#endif
/* The following flags affect the page allocator grouping pages by mobility */
#define SLAB_RECLAIM_ACCOUNT 0x00020000UL /* Objects are reclaimable */
#define SLAB_TEMPORARY SLAB_RECLAIM_ACCOUNT /* Objects are short-lived */
/*
* ZERO_SIZE_PTR will be returned for zero sized kmalloc requests.
*
* Dereferencing ZERO_SIZE_PTR will lead to a distinct access fault.
*
* ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
* Both make kfree a no-op.
*/
#define ZERO_SIZE_PTR ((void *)16)
#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
(unsigned long)ZERO_SIZE_PTR)
#include <linux/kmemleak.h>
#include <linux/kasan.h>
struct mem_cgroup;
/*
* struct kmem_cache related prototypes
*/
void __init kmem_cache_init(void);
bool slab_is_available(void);
struct kmem_cache *kmem_cache_create(const char *, size_t, size_t,
unsigned long,
void (*)(void *));
void kmem_cache_destroy(struct kmem_cache *);
int kmem_cache_shrink(struct kmem_cache *);
void memcg_create_kmem_cache(struct mem_cgroup *, struct kmem_cache *);
void memcg_deactivate_kmem_caches(struct mem_cgroup *);
void memcg_destroy_kmem_caches(struct mem_cgroup *);
/*
* Please use this macro to create slab caches. Simply specify the
* name of the structure and maybe some flags that are listed above.
*
* The alignment of the struct determines object alignment. If you
* f.e. add ____cacheline_aligned_in_smp to the struct declaration
* then the objects will be properly aligned in SMP configurations.
*/
#define KMEM_CACHE(__struct, __flags) kmem_cache_create(#__struct,\
sizeof(struct __struct), __alignof__(struct __struct),\
(__flags), NULL)
/*
* Common kmalloc functions provided by all allocators
*/
void * __must_check __krealloc(const void *, size_t, gfp_t);
void * __must_check krealloc(const void *, size_t, gfp_t);
void kfree(const void *);
void kzfree(const void *);
size_t ksize(const void *);
#ifdef CONFIG_HAVE_HARDENED_USERCOPY_ALLOCATOR
const char *__check_heap_object(const void *ptr, unsigned long n,
struct page *page);
#else
static inline const char *__check_heap_object(const void *ptr,
unsigned long n,
struct page *page)
{
return NULL;
}
#endif
/*
* Some archs want to perform DMA into kmalloc caches and need a guaranteed
* alignment larger than the alignment of a 64-bit integer.
* Setting ARCH_KMALLOC_MINALIGN in arch headers allows that.
*/
#if defined(ARCH_DMA_MINALIGN) && ARCH_DMA_MINALIGN > 8
#define ARCH_KMALLOC_MINALIGN ARCH_DMA_MINALIGN
#define KMALLOC_MIN_SIZE ARCH_DMA_MINALIGN
#define KMALLOC_SHIFT_LOW ilog2(ARCH_DMA_MINALIGN)
#else
#define ARCH_KMALLOC_MINALIGN __alignof__(unsigned long long)
#endif
/*
* Setting ARCH_SLAB_MINALIGN in arch headers allows a different alignment.
* Intended for arches that get misalignment faults even for 64 bit integer
* aligned buffers.
*/
#ifndef ARCH_SLAB_MINALIGN
#define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
#endif
/*
* kmalloc and friends return ARCH_KMALLOC_MINALIGN aligned
* pointers. kmem_cache_alloc and friends return ARCH_SLAB_MINALIGN
* aligned pointers.
*/
#define __assume_kmalloc_alignment __assume_aligned(ARCH_KMALLOC_MINALIGN)
#define __assume_slab_alignment __assume_aligned(ARCH_SLAB_MINALIGN)
#define __assume_page_alignment __assume_aligned(PAGE_SIZE)
/*
* Kmalloc array related definitions
*/
#ifdef CONFIG_SLAB
/*
* The largest kmalloc size supported by the SLAB allocators is
* 32 megabyte (2^25) or the maximum allocatable page order if that is
* less than 32 MB.
*
* WARNING: Its not easy to increase this value since the allocators have
* to do various tricks to work around compiler limitations in order to
* ensure proper constant folding.
*/
#define KMALLOC_SHIFT_HIGH ((MAX_ORDER + PAGE_SHIFT - 1) <= 25 ? \
(MAX_ORDER + PAGE_SHIFT - 1) : 25)
#define KMALLOC_SHIFT_MAX KMALLOC_SHIFT_HIGH
#ifndef KMALLOC_SHIFT_LOW
#define KMALLOC_SHIFT_LOW 5
#endif
#endif
#ifdef CONFIG_SLUB
/*
* SLUB directly allocates requests fitting in to an order-1 page
* (PAGE_SIZE*2). Larger requests are passed to the page allocator.
*/
#define KMALLOC_SHIFT_HIGH (PAGE_SHIFT + 1)
#define KMALLOC_SHIFT_MAX (MAX_ORDER + PAGE_SHIFT - 1)
#ifndef KMALLOC_SHIFT_LOW
#define KMALLOC_SHIFT_LOW 3
#endif
#endif
#ifdef CONFIG_SLOB
/*
* SLOB passes all requests larger than one page to the page allocator.
* No kmalloc array is necessary since objects of different sizes can
* be allocated from the same page.
*/
#define KMALLOC_SHIFT_HIGH PAGE_SHIFT
#define KMALLOC_SHIFT_MAX (MAX_ORDER + PAGE_SHIFT - 1)
#ifndef KMALLOC_SHIFT_LOW
#define KMALLOC_SHIFT_LOW 3
#endif
#endif
/* Maximum allocatable size */
#define KMALLOC_MAX_SIZE (1UL << KMALLOC_SHIFT_MAX)
/* Maximum size for which we actually use a slab cache */
#define KMALLOC_MAX_CACHE_SIZE (1UL << KMALLOC_SHIFT_HIGH)
/* Maximum order allocatable via the slab allocagtor */
#define KMALLOC_MAX_ORDER (KMALLOC_SHIFT_MAX - PAGE_SHIFT)
/*
* Kmalloc subsystem.
*/
#ifndef KMALLOC_MIN_SIZE
#define KMALLOC_MIN_SIZE (1 << KMALLOC_SHIFT_LOW)
#endif
/*
* This restriction comes from byte sized index implementation.
* Page size is normally 2^12 bytes and, in this case, if we want to use
* byte sized index which can represent 2^8 entries, the size of the object
* should be equal or greater to 2^12 / 2^8 = 2^4 = 16.
* If minimum size of kmalloc is less than 16, we use it as minimum object
* size and give up to use byte sized index.
*/
#define SLAB_OBJ_MIN_SIZE (KMALLOC_MIN_SIZE < 16 ? \
(KMALLOC_MIN_SIZE) : 16)
#ifndef CONFIG_SLOB
extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
#ifdef CONFIG_ZONE_DMA
extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
#endif
/*
* Figure out which kmalloc slab an allocation of a certain size
* belongs to.
* 0 = zero alloc
* 1 = 65 .. 96 bytes
* 2 = 129 .. 192 bytes
* n = 2^(n-1)+1 .. 2^n
*/
static __always_inline int kmalloc_index(size_t size)
{
if (!size)
return 0;
if (size <= KMALLOC_MIN_SIZE)
return KMALLOC_SHIFT_LOW;
if (KMALLOC_MIN_SIZE <= 32 && size > 64 && size <= 96)
return 1;
if (KMALLOC_MIN_SIZE <= 64 && size > 128 && size <= 192)
return 2;
if (size <= 8) return 3;
if (size <= 16) return 4;
if (size <= 32) return 5;
if (size <= 64) return 6;
if (size <= 128) return 7;
if (size <= 256) return 8;
if (size <= 512) return 9;
if (size <= 1024) return 10;
if (size <= 2 * 1024) return 11;
if (size <= 4 * 1024) return 12;
if (size <= 8 * 1024) return 13;
if (size <= 16 * 1024) return 14;
if (size <= 32 * 1024) return 15;
if (size <= 64 * 1024) return 16;
if (size <= 128 * 1024) return 17;
if (size <= 256 * 1024) return 18;
if (size <= 512 * 1024) return 19;
if (size <= 1024 * 1024) return 20;
if (size <= 2 * 1024 * 1024) return 21;
if (size <= 4 * 1024 * 1024) return 22;
if (size <= 8 * 1024 * 1024) return 23;
if (size <= 16 * 1024 * 1024) return 24;
if (size <= 32 * 1024 * 1024) return 25;
if (size <= 64 * 1024 * 1024) return 26;
BUG();
/* Will never be reached. Needed because the compiler may complain */
return -1;
}
#endif /* !CONFIG_SLOB */
void *__kmalloc(size_t size, gfp_t flags) __assume_kmalloc_alignment;
void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags) __assume_slab_alignment;
void kmem_cache_free(struct kmem_cache *, void *);
/*
* Bulk allocation and freeing operations. These are accellerated in an
* allocator specific way to avoid taking locks repeatedly or building
* metadata structures unnecessarily.
*
* Note that interrupts must be enabled when calling these functions.
*/
void kmem_cache_free_bulk(struct kmem_cache *, size_t, void **);
int kmem_cache_alloc_bulk(struct kmem_cache *, gfp_t, size_t, void **);
#ifdef CONFIG_NUMA
void *__kmalloc_node(size_t size, gfp_t flags, int node) __assume_kmalloc_alignment;
void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node) __assume_slab_alignment;
#else
static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
{
return __kmalloc(size, flags);
}
static __always_inline void *kmem_cache_alloc_node(struct kmem_cache *s, gfp_t flags, int node)
{
return kmem_cache_alloc(s, flags);
}
#endif
#ifdef CONFIG_TRACING
extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t) __assume_slab_alignment;
#ifdef CONFIG_NUMA
extern void *kmem_cache_alloc_node_trace(struct kmem_cache *s,
gfp_t gfpflags,
int node, size_t size) __assume_slab_alignment;
#else
static __always_inline void *
kmem_cache_alloc_node_trace(struct kmem_cache *s,
gfp_t gfpflags,
int node, size_t size)
{
return kmem_cache_alloc_trace(s, gfpflags, size);
}
#endif /* CONFIG_NUMA */
#else /* CONFIG_TRACING */
static __always_inline void *kmem_cache_alloc_trace(struct kmem_cache *s,
gfp_t flags, size_t size)
{
void *ret = kmem_cache_alloc(s, flags);
kasan_kmalloc(s, ret, size, flags);
return ret;
}
static __always_inline void *
kmem_cache_alloc_node_trace(struct kmem_cache *s,
gfp_t gfpflags,
int node, size_t size)
{
void *ret = kmem_cache_alloc_node(s, gfpflags, node);
kasan_kmalloc(s, ret, size, gfpflags);
return ret;
}
#endif /* CONFIG_TRACING */
extern void *kmalloc_order(size_t size, gfp_t flags, unsigned int order) __assume_page_alignment;
#ifdef CONFIG_TRACING
extern void *kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order) __assume_page_alignment;
#else
static __always_inline void *
kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
{
return kmalloc_order(size, flags, order);
}
#endif
static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
{
unsigned int order = get_order(size);
return kmalloc_order_trace(size, flags, order);
}
/**
* kmalloc - allocate memory
* @size: how many bytes of memory are required.
* @flags: the type of memory to allocate.
*
* kmalloc is the normal method of allocating memory
* for objects smaller than page size in the kernel.
*
* The @flags argument may be one of:
*
* %GFP_USER - Allocate memory on behalf of user. May sleep.
*
* %GFP_KERNEL - Allocate normal kernel ram. May sleep.
*
* %GFP_ATOMIC - Allocation will not sleep. May use emergency pools.
* For example, use this inside interrupt handlers.
*
* %GFP_HIGHUSER - Allocate pages from high memory.
*
* %GFP_NOIO - Do not do any I/O at all while trying to get memory.
*
* %GFP_NOFS - Do not make any fs calls while trying to get memory.
*
* %GFP_NOWAIT - Allocation will not sleep.
*
* %__GFP_THISNODE - Allocate node-local memory only.
*
* %GFP_DMA - Allocation suitable for DMA.
* Should only be used for kmalloc() caches. Otherwise, use a
* slab created with SLAB_DMA.
*
* Also it is possible to set different flags by OR'ing
* in one or more of the following additional @flags:
*
* %__GFP_COLD - Request cache-cold pages instead of
* trying to return cache-warm pages.
*
* %__GFP_HIGH - This allocation has high priority and may use emergency pools.
*
* %__GFP_NOFAIL - Indicate that this allocation is in no way allowed to fail
* (think twice before using).
*
* %__GFP_NORETRY - If memory is not immediately available,
* then give up at once.
*
* %__GFP_NOWARN - If allocation fails, don't issue any warnings.
*
* %__GFP_REPEAT - If allocation fails initially, try once more before failing.
*
* There are other flags available as well, but these are not intended
* for general use, and so are not documented here. For a full list of
* potential flags, always refer to linux/gfp.h.
*/
static __always_inline void *kmalloc(size_t size, gfp_t flags)
{
if (__builtin_constant_p(size)) {
if (size > KMALLOC_MAX_CACHE_SIZE)
return kmalloc_large(size, flags);
#ifndef CONFIG_SLOB
if (!(flags & GFP_DMA)) {
int index = kmalloc_index(size);
if (!index)
return ZERO_SIZE_PTR;
return kmem_cache_alloc_trace(kmalloc_caches[index],
flags, size);
}
#endif
}
return __kmalloc(size, flags);
}
/*
* Determine size used for the nth kmalloc cache.
* return size or 0 if a kmalloc cache for that
* size does not exist
*/
static __always_inline int kmalloc_size(int n)
{
#ifndef CONFIG_SLOB
if (n > 2)
return 1 << n;
if (n == 1 && KMALLOC_MIN_SIZE <= 32)
return 96;
if (n == 2 && KMALLOC_MIN_SIZE <= 64)
return 192;
#endif
return 0;
}
static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
{
#ifndef CONFIG_SLOB
if (__builtin_constant_p(size) &&
size <= KMALLOC_MAX_CACHE_SIZE && !(flags & GFP_DMA)) {
int i = kmalloc_index(size);
if (!i)
return ZERO_SIZE_PTR;
return kmem_cache_alloc_node_trace(kmalloc_caches[i],
flags, node, size);
}
#endif
return __kmalloc_node(size, flags, node);
}
struct memcg_cache_array {
struct rcu_head rcu;
struct kmem_cache *entries[0];
};
/*
* This is the main placeholder for memcg-related information in kmem caches.
* Both the root cache and the child caches will have it. For the root cache,
* this will hold a dynamically allocated array large enough to hold
* information about the currently limited memcgs in the system. To allow the
* array to be accessed without taking any locks, on relocation we free the old
* version only after a grace period.
*
* Child caches will hold extra metadata needed for its operation. Fields are:
*
* @memcg: pointer to the memcg this cache belongs to
* @root_cache: pointer to the global, root cache, this cache was derived from
*
* Both root and child caches of the same kind are linked into a list chained
* through @list.
*/
struct memcg_cache_params {
bool is_root_cache;
struct list_head list;
union {
struct memcg_cache_array __rcu *memcg_caches;
struct {
struct mem_cgroup *memcg;
struct kmem_cache *root_cache;
};
};
};
int memcg_update_all_caches(int num_memcgs);
/**
* kmalloc_array - allocate memory for an array.
* @n: number of elements.
* @size: element size.
* @flags: the type of memory to allocate (see kmalloc).
*/
static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
{
if (size != 0 && n > SIZE_MAX / size)
return NULL;
return __kmalloc(n * size, flags);
}
/**
* kcalloc - allocate memory for an array. The memory is set to zero.
* @n: number of elements.
* @size: element size.
* @flags: the type of memory to allocate (see kmalloc).
*/
static inline void *kcalloc(size_t n, size_t size, gfp_t flags)
{
return kmalloc_array(n, size, flags | __GFP_ZERO);
}
/*
* kmalloc_track_caller is a special version of kmalloc that records the
* calling function of the routine calling it for slab leak tracking instead
* of just the calling function (confusing, eh?).
* It's useful when the call to kmalloc comes from a widely-used standard
* allocator where we care about the real place the memory allocation
* request comes from.
*/
extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
#define kmalloc_track_caller(size, flags) \
__kmalloc_track_caller(size, flags, _RET_IP_)
#ifdef CONFIG_NUMA
extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
#define kmalloc_node_track_caller(size, flags, node) \
__kmalloc_node_track_caller(size, flags, node, \
_RET_IP_)
#else /* CONFIG_NUMA */
#define kmalloc_node_track_caller(size, flags, node) \
kmalloc_track_caller(size, flags)
#endif /* CONFIG_NUMA */
/*
* Shortcuts
*/
static inline void *kmem_cache_zalloc(struct kmem_cache *k, gfp_t flags)
{
return kmem_cache_alloc(k, flags | __GFP_ZERO);
}
/**
* kzalloc - allocate memory. The memory is set to zero.
* @size: how many bytes of memory are required.
* @flags: the type of memory to allocate (see kmalloc).
*/
static inline void *kzalloc(size_t size, gfp_t flags)
{
return kmalloc(size, flags | __GFP_ZERO);
}
/**
* kzalloc_node - allocate zeroed memory from a particular memory node.
* @size: how many bytes of memory are required.
* @flags: the type of memory to allocate (see kmalloc).
* @node: memory node from which to allocate
*/
static inline void *kzalloc_node(size_t size, gfp_t flags, int node)
{
return kmalloc_node(size, flags | __GFP_ZERO, node);
}
unsigned int kmem_cache_size(struct kmem_cache *s);
void __init kmem_cache_init_late(void);
#endif /* _LINUX_SLAB_H */