提交 f94e5b1a 编写于 作者: X Xunlei Pang 提交者: Caspar Zhang

alinux: hotfix: Add Cloud Kernel hotfix enhancement

We reserve some fields beforehand for core structures prone to change,
so that we won't hurt when extra fields have to be added for hotfix,
thereby inceasing the success rate, we even can hot add features with
this enhancement.

After reserving, normally cache does not matter as the reserved fields
(usually at tail) are not accessed at all.

Currently involve the following structures:
    MM:
    struct zone
    struct pglist_data
    struct mm_struct
    struct vm_area_struct
    struct mem_cgroup
    struct writeback_control

    Block:
    struct gendisk
    struct backing_dev_info
    struct bio
    struct queue_limits
    struct request_queue
    struct blkcg
    struct blkcg_policy
    struct blk_mq_hw_ctx
    struct blk_mq_tag_set
    struct blk_mq_queue_data
    struct blk_mq_ops
    struct elevator_mq_ops
    struct inode
    struct dentry
    struct address_space
    struct block_device
    struct hd_struct
    struct bio_set

    Network:
    struct sk_buff
    struct sock
    struct net_device_ops
    struct xt_target
    struct dst_entry
    struct dst_ops
    struct fib_rule

    Scheduler:
    struct task_struct
    struct cfs_rq
    struct rq
    struct sched_statistics
    struct sched_entity
    struct signal_struct
    struct task_group
    struct cpuacct

    cgroup:
    struct cgroup_root
    struct cgroup_subsys_state
    struct cgroup_subsys
    struct css_set
Reviewed-by: NJoseph Qi <joseph.qi@linux.alibaba.com>
Signed-off-by: NXunlei Pang <xlpang@linux.alibaba.com>
[ caspar: use SPDX-License-Identifier ]
Signed-off-by: NCaspar Zhang <caspar@linux.alibaba.com>
上级 cea84490
/* SPDX-License-Identifier: GPL-2.0
*
* Copyright (c) 2019 Xunlei Pang <xlpang@linux.alibaba.com>
*/
#ifndef _LINUX_ALI_HOTFIX_H
#define _LINUX_ALI_HOTFIX_H
#include <linux/compiler.h>
/*
* ALI_HOTFIX_RESERVE* - reserve fields for core structures prone to change
* ALI_HOTFIX_USE* - use the reserved field in your hotfix
* ALI_HOTFIX_REPLACE - replacement of _orig with a union of _orig and _new
*/
#define _ALI_HOTFIX_REPLACE(_orig, _new) \
union { \
_new; \
struct { \
_orig; \
} __UNIQUE_ID(ali_hotfix_hide); \
}
#define ALI_HOTFIX_REPLACE(_orig, _new) _ALI_HOTFIX_REPLACE(_orig, _new);
/*
* We tried to standardize on alikernel reserved names. These wrappers leverage
* those common names making it easier to read and find in the code.
*/
#define _ALI_HOTFIX_RESERVE(n) unsigned long ali_reserved##n
#define _ALI_HOTFIX_RESERVE_P(n) void (*ali_reserved##n)(void)
#define ALI_HOTFIX_RESERVE(n) _ALI_HOTFIX_RESERVE(n);
#define ALI_HOTFIX_RESERVE_P(n) _ALI_HOTFIX_RESERVE_P(n);
/*
* Wrappers to replace standard alikernel reserved elements.
*/
#define ALI_HOTFIX_USE(n, _new) \
ALI_HOTFIX_REPLACE(_ALI_HOTFIX_RESERVE(n), _new)
#define ALI_HOTFIX_USE_P(n, _new) \
ALI_HOTFIX_REPLACE(_ALI_HOTFIX_RESERVE_P(n), _new)
/*
* Macros for breaking up a reserved element into two smaller chunks using an
* anonymous struct inside an anonymous union.
*/
#define ALI_HOTFIX_USE2(n, _new1, _new2) \
ALI_HOTFIX_REPLACE(_ALI_HOTFIX_RESERVE(n), struct{ _new1; _new2; })
#define ALI_HOTFIX_USE2_P(n, _new1, _new2) \
ALI_HOTFIX_REPLACE(_ALI_HOTFIX_RESERVE_P(n), struct{ _new1; _new2; })
#endif /* _LINUX_ALI_HOTFIX_H */
......@@ -162,6 +162,9 @@ struct bdi_writeback {
struct rcu_head rcu;
};
#endif
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
};
struct backing_dev_info {
......@@ -205,6 +208,9 @@ struct backing_dev_info {
struct dentry *debug_dir;
struct dentry *debug_stats;
#endif
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
};
enum {
......
......@@ -775,6 +775,9 @@ struct bio_set {
struct bio_list rescue_list;
struct work_struct rescue_work;
struct workqueue_struct *rescue_workqueue;
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
};
struct biovec_slab {
......
......@@ -58,6 +58,11 @@ struct blkcg {
struct list_head cgwb_list;
refcount_t cgwb_refcnt;
#endif
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
ALI_HOTFIX_RESERVE(3)
ALI_HOTFIX_RESERVE(4)
};
/*
......@@ -178,6 +183,9 @@ struct blkcg_policy {
blkcg_pol_free_pd_fn *pd_free_fn;
blkcg_pol_reset_pd_stats_fn *pd_reset_stats_fn;
blkcg_pol_stat_pd_fn *pd_stat_fn;
ALI_HOTFIX_RESERVE_P(1)
ALI_HOTFIX_RESERVE_P(2)
};
extern struct blkcg blkcg_root;
......
......@@ -70,6 +70,11 @@ struct blk_mq_hw_ctx {
struct dentry *sched_debugfs_dir;
#endif
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
ALI_HOTFIX_RESERVE(3)
ALI_HOTFIX_RESERVE(4)
/* Must be the last member - see also blk_mq_hw_ctx_size(). */
struct srcu_struct srcu[0];
};
......@@ -90,11 +95,18 @@ struct blk_mq_tag_set {
struct mutex tag_list_lock;
struct list_head tag_list;
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
ALI_HOTFIX_RESERVE(3)
ALI_HOTFIX_RESERVE(4)
};
struct blk_mq_queue_data {
struct request *rq;
bool last;
ALI_HOTFIX_RESERVE(1)
};
typedef blk_status_t (queue_rq_fn)(struct blk_mq_hw_ctx *,
......@@ -181,6 +193,9 @@ struct blk_mq_ops {
*/
void (*show_rq)(struct seq_file *m, struct request *rq);
#endif
ALI_HOTFIX_RESERVE_P(1)
ALI_HOTFIX_RESERVE_P(2)
};
enum {
......
......@@ -11,6 +11,8 @@
#include <linux/ktime.h>
#include <linux/sched/clock.h>
#include <linux/ali_hotfix.h>
struct bio_set;
struct bio;
struct bio_integrity_payload;
......@@ -212,6 +214,9 @@ struct bio {
struct bio_set *bi_pool;
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
/*
* We can inline a number of vecs at the end of the bio, to avoid
* double allocations for a small number of bio_vecs. This member
......
......@@ -396,6 +396,9 @@ struct queue_limits {
unsigned char cluster;
unsigned char raid_partial_stripes_expensive;
enum blk_zoned_model zoned;
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
};
#ifdef CONFIG_BLK_DEV_ZONED
......@@ -677,6 +680,11 @@ struct request_queue {
#define BLK_MAX_WRITE_HINTS 5
u64 write_hints[BLK_MAX_WRITE_HINTS];
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
ALI_HOTFIX_RESERVE(3)
ALI_HOTFIX_RESERVE(4)
};
#define QUEUE_FLAG_QUEUED 0 /* uses generic tag queueing */
......
......@@ -161,6 +161,9 @@ struct cgroup_subsys_state {
struct work_struct destroy_work;
struct rcu_work destroy_rwork;
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
/*
* PI: the parent css. Placed here for cache proximity to following
* fields of the containing structure.
......@@ -262,6 +265,9 @@ struct css_set {
/* For RCU-protected deletion */
struct rcu_head rcu_head;
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
};
struct cgroup_base_stat {
......@@ -489,6 +495,9 @@ struct cgroup_root {
/* IDs for cgroups in this hierarchy */
struct idr cgroup_idr;
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
/* The path to use for release notifications. */
char release_agent_path[PATH_MAX];
......@@ -614,6 +623,9 @@ struct cgroup_subsys {
void (*release)(struct task_struct *task);
void (*bind)(struct cgroup_subsys_state *root_css);
ALI_HOTFIX_RESERVE_P(1)
ALI_HOTFIX_RESERVE_P(2)
bool early_init:1;
/*
......
......@@ -14,6 +14,8 @@
#include <linux/stringhash.h>
#include <linux/wait.h>
#include <linux/ali_hotfix.h>
struct path;
struct vfsmount;
......@@ -117,6 +119,9 @@ struct dentry {
struct hlist_bl_node d_in_lookup_hash; /* only for in-lookup ones */
struct rcu_head d_rcu;
} d_u;
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
} __randomize_layout;
/*
......
......@@ -119,6 +119,9 @@ struct elevator_mq_ops {
struct request *(*next_request)(struct request_queue *, struct request *);
void (*init_icq)(struct io_cq *);
void (*exit_icq)(struct io_cq *);
ALI_HOTFIX_RESERVE_P(1)
ALI_HOTFIX_RESERVE_P(2)
};
#define ELV_NAME_MAX (16)
......
......@@ -431,6 +431,9 @@ struct address_space {
struct list_head private_list; /* for use by the address_space */
void *private_data; /* ditto */
errseq_t wb_err;
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
} __attribute__((aligned(sizeof(long)))) __randomize_layout;
/*
* On most architectures that alignment is already the case; but
......@@ -475,6 +478,9 @@ struct block_device {
int bd_fsfreeze_count;
/* Mutex for freeze */
struct mutex bd_fsfreeze_mutex;
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
} __randomize_layout;
/*
......@@ -694,6 +700,9 @@ struct inode {
#endif
void *i_private; /* fs or device private pointer */
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
} __randomize_layout;
static inline unsigned int i_blocksize(const struct inode *node)
......
......@@ -131,6 +131,9 @@ struct hd_struct {
#endif
struct percpu_ref ref;
struct rcu_work rcu_work;
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
};
#define GENHD_FL_REMOVABLE 1
......@@ -212,6 +215,9 @@ struct gendisk {
int node_id;
struct badblocks *bb;
struct lockdep_map lockdep_map;
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
};
static inline struct gendisk *part_to_disk(struct hd_struct *part)
......
......@@ -329,6 +329,11 @@ struct mem_cgroup {
struct idle_page_stats idle_stats[KIDLED_STATS_NR_TYPE];
#endif
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
ALI_HOTFIX_RESERVE(3)
ALI_HOTFIX_RESERVE(4)
struct mem_cgroup_per_node *nodeinfo[0];
/* WARNING: nodeinfo must be the last member here */
};
......
......@@ -450,6 +450,9 @@ struct vm_operations_struct {
*/
struct page *(*find_special_page)(struct vm_area_struct *vma,
unsigned long addr);
ALI_HOTFIX_RESERVE_P(1)
ALI_HOTFIX_RESERVE_P(2)
};
static inline void vma_init(struct vm_area_struct *vma, struct mm_struct *mm)
......
......@@ -17,6 +17,8 @@
#include <asm/mmu.h>
#include <linux/ali_hotfix.h>
#ifndef AT_VECTOR_SIZE_ARCH
#define AT_VECTOR_SIZE_ARCH 0
#endif
......@@ -329,6 +331,11 @@ struct vm_area_struct {
struct mempolicy *vm_policy; /* NUMA policy for the VMA */
#endif
struct vm_userfaultfd_ctx vm_userfaultfd_ctx;
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
ALI_HOTFIX_RESERVE(3)
ALI_HOTFIX_RESERVE(4)
} __randomize_layout;
struct core_thread {
......@@ -499,6 +506,9 @@ struct mm_struct {
#endif
} __randomize_layout;
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
/*
* The mm_cpumask needs to be at the end of mm_struct, because it
* is dynamically sized based on nr_cpu_ids.
......
......@@ -20,6 +20,8 @@
#include <linux/atomic.h>
#include <asm/page.h>
#include <linux/ali_hotfix.h>
/* Free memory management - zoned buddy allocator. */
#ifndef CONFIG_FORCE_MAX_ZONEORDER
#define MAX_ORDER 11
......@@ -507,6 +509,9 @@ struct zone {
/* Zone statistics */
atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
atomic_long_t vm_numa_stat[NR_VM_NUMA_STAT_ITEMS];
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
} ____cacheline_internodealigned_in_smp;
enum pgdat_flags {
......@@ -724,6 +729,9 @@ typedef struct pglist_data {
/* Per-node vmstats */
struct per_cpu_nodestat __percpu *per_cpu_nodestats;
atomic_long_t vm_stat[NR_VM_NODE_STAT_ITEMS];
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
} pg_data_t;
#define node_present_pages(nid) (NODE_DATA(nid)->node_present_pages)
......
......@@ -53,6 +53,8 @@
#include <uapi/linux/pkt_cls.h>
#include <linux/hashtable.h>
#include <linux/ali_hotfix.h>
struct netpoll_info;
struct device;
struct phy_device;
......@@ -1410,6 +1412,9 @@ struct net_device_ops {
u32 flags);
int (*ndo_xsk_async_xmit)(struct net_device *dev,
u32 queue_id);
ALI_HOTFIX_RESERVE_P(1)
ALI_HOTFIX_RESERVE_P(2)
};
/**
......
......@@ -8,6 +8,8 @@
#include <linux/netfilter.h>
#include <uapi/linux/netfilter/x_tables.h>
#include <linux/ali_hotfix.h>
/* Test a struct->invflags and a boolean for inequality */
#define NF_INVF(ptr, flag, boolean) \
((boolean) ^ !!((ptr)->invflags & (flag)))
......@@ -217,6 +219,9 @@ struct xt_target {
unsigned short proto;
unsigned short family;
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
};
/* Furniture shopping... */
......
......@@ -29,6 +29,8 @@
#include <linux/task_io_accounting.h>
#include <linux/rseq.h>
#include <linux/ali_hotfix.h>
/* task_struct member predeclarations (sorted alphabetically): */
struct audit_context;
struct backing_dev_info;
......@@ -440,6 +442,9 @@ struct sched_statistics {
u64 nr_wakeups_affine_attempts;
u64 nr_wakeups_passive;
u64 nr_wakeups_idle;
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
#endif
};
......@@ -478,6 +483,9 @@ struct sched_entity {
*/
struct sched_avg avg;
#endif
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
};
struct sched_rt_entity {
......@@ -1209,6 +1217,15 @@ struct task_struct {
void *security;
#endif
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
ALI_HOTFIX_RESERVE(3)
ALI_HOTFIX_RESERVE(4)
ALI_HOTFIX_RESERVE(5)
ALI_HOTFIX_RESERVE(6)
ALI_HOTFIX_RESERVE(7)
ALI_HOTFIX_RESERVE(8)
/*
* New fields for task_struct should be added above here, so that
* they are included in the randomized portion of task_struct.
......
......@@ -232,6 +232,9 @@ struct signal_struct {
struct mutex cred_guard_mutex; /* guard against foreign influences on
* credential calculations
* (notably. ptrace) */
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
} __randomize_layout;
/*
......
......@@ -849,6 +849,9 @@ struct sk_buff {
__u32 headers_end[0];
/* public: */
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
/* These elements must be at the end, see alloc_skb() for details. */
sk_buff_data_t tail;
sk_buff_data_t end;
......
......@@ -8,6 +8,8 @@
#include <linux/debugobjects.h>
#include <linux/stringify.h>
#include <linux/ali_hotfix.h>
struct timer_list {
/*
* All fields that change during normal runtime grouped to the
......@@ -21,6 +23,9 @@ struct timer_list {
#ifdef CONFIG_LOCKDEP
struct lockdep_map lockdep_map;
#endif
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
};
#ifdef CONFIG_LOCKDEP
......
......@@ -80,6 +80,9 @@ struct writeback_control {
size_t wb_lcand_bytes; /* bytes written by last candidate */
size_t wb_tcand_bytes; /* bytes written by this candidate */
#endif
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
};
static inline int wbc_to_write_flags(struct writeback_control *wbc)
......
......@@ -88,6 +88,11 @@ struct dst_entry {
#ifndef CONFIG_64BIT
atomic_t __refcnt; /* 32-bit offset 64 */
#endif
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
ALI_HOTFIX_RESERVE(3)
ALI_HOTFIX_RESERVE(4)
};
struct dst_metrics {
......
......@@ -39,6 +39,9 @@ struct dst_ops {
struct kmem_cache *kmem_cachep;
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
struct percpu_counter pcpuc_entries ____cacheline_aligned_in_smp;
};
......
......@@ -43,6 +43,8 @@ struct fib_rule {
struct fib_rule_port_range sport_range;
struct fib_rule_port_range dport_range;
struct rcu_head rcu;
ALI_HOTFIX_RESERVE(1)
};
struct fib_lookup_arg {
......
......@@ -511,6 +511,9 @@ struct sock {
struct sock_reuseport __rcu *sk_reuseport_cb;
__be32 sk_toa_data[16];
struct rcu_head sk_rcu;
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
};
enum sk_pacing {
......
......@@ -30,6 +30,11 @@ struct cpuacct {
/* cpuusage holds pointer to a u64-type object on every CPU */
struct cpuacct_usage __percpu *cpuusage;
struct kernel_cpustat __percpu *cpustat;
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
ALI_HOTFIX_RESERVE(3)
ALI_HOTFIX_RESERVE(4)
};
static inline struct cpuacct *css_ca(struct cgroup_subsys_state *css)
......
......@@ -392,6 +392,9 @@ struct task_group {
#endif
struct cfs_bandwidth cfs_bandwidth;
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
};
#ifdef CONFIG_FAIR_GROUP_SCHED
......@@ -565,6 +568,11 @@ struct cfs_rq {
struct list_head throttled_list;
#endif /* CONFIG_CFS_BANDWIDTH */
#endif /* CONFIG_FAIR_GROUP_SCHED */
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
ALI_HOTFIX_RESERVE(3)
ALI_HOTFIX_RESERVE(4)
};
static inline int rt_bandwidth_enabled(void)
......@@ -915,6 +923,11 @@ struct rq {
/* Must be inspected within a rcu lock section */
struct cpuidle_state *idle_state;
#endif
ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2)
ALI_HOTFIX_RESERVE(3)
ALI_HOTFIX_RESERVE(4)
};
static inline int cpu_of(struct rq *rq)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册