diff options
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/audit.c | 2 | ||||
| -rw-r--r-- | kernel/cgroup.c | 23 | ||||
| -rw-r--r-- | kernel/cpuset.c | 2 | ||||
| -rw-r--r-- | kernel/cred.c | 25 | ||||
| -rw-r--r-- | kernel/debug/debug_core.c | 6 | ||||
| -rw-r--r-- | kernel/debug/gdbstub.c | 200 | ||||
| -rw-r--r-- | kernel/debug/kdb/kdb_main.c | 139 | ||||
| -rw-r--r-- | kernel/debug/kdb/kdb_private.h | 2 | ||||
| -rw-r--r-- | kernel/early_res.c | 6 | ||||
| -rw-r--r-- | kernel/hw_breakpoint.c | 12 | ||||
| -rw-r--r-- | kernel/module.c | 1092 | ||||
| -rw-r--r-- | kernel/padata.c | 755 | ||||
| -rw-r--r-- | kernel/pm_qos_params.c | 215 | ||||
| -rw-r--r-- | kernel/power/hibernate.c | 26 | ||||
| -rw-r--r-- | kernel/power/main.c | 55 | ||||
| -rw-r--r-- | kernel/power/snapshot.c | 2 | ||||
| -rw-r--r-- | kernel/power/suspend.c | 13 | ||||
| -rw-r--r-- | kernel/power/swap.c | 6 | ||||
| -rw-r--r-- | kernel/printk.c | 33 | ||||
| -rw-r--r-- | kernel/signal.c | 9 | ||||
| -rw-r--r-- | kernel/time/tick-broadcast.c | 2 | ||||
| -rw-r--r-- | kernel/timer.c | 13 | ||||
| -rw-r--r-- | kernel/trace/Makefile | 3 | ||||
| -rw-r--r-- | kernel/trace/trace.c | 43 | ||||
| -rw-r--r-- | kernel/trace/trace.h | 19 | ||||
| -rw-r--r-- | kernel/trace/trace_kdb.c | 136 | ||||
| -rw-r--r-- | kernel/user_namespace.c | 44 |
27 files changed, 1950 insertions, 933 deletions
diff --git a/kernel/audit.c b/kernel/audit.c index c71bd26631a2..8296aa516c5a 100644 --- a/kernel/audit.c +++ b/kernel/audit.c | |||
| @@ -407,7 +407,7 @@ static void kauditd_send_skb(struct sk_buff *skb) | |||
| 407 | audit_hold_skb(skb); | 407 | audit_hold_skb(skb); |
| 408 | } else | 408 | } else |
| 409 | /* drop the extra reference if sent ok */ | 409 | /* drop the extra reference if sent ok */ |
| 410 | kfree_skb(skb); | 410 | consume_skb(skb); |
| 411 | } | 411 | } |
| 412 | 412 | ||
| 413 | static int kauditd_thread(void *dummy) | 413 | static int kauditd_thread(void *dummy) |
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 3ac6f5b0a64b..a8ce09954404 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
| @@ -1788,6 +1788,29 @@ out: | |||
| 1788 | return retval; | 1788 | return retval; |
| 1789 | } | 1789 | } |
| 1790 | 1790 | ||
| 1791 | /** | ||
| 1792 | * cgroup_attach_task_current_cg - attach task 'tsk' to current task's cgroup | ||
| 1793 | * @tsk: the task to be attached | ||
| 1794 | */ | ||
| 1795 | int cgroup_attach_task_current_cg(struct task_struct *tsk) | ||
| 1796 | { | ||
| 1797 | struct cgroupfs_root *root; | ||
| 1798 | struct cgroup *cur_cg; | ||
| 1799 | int retval = 0; | ||
| 1800 | |||
| 1801 | cgroup_lock(); | ||
| 1802 | for_each_active_root(root) { | ||
| 1803 | cur_cg = task_cgroup_from_root(current, root); | ||
| 1804 | retval = cgroup_attach_task(cur_cg, tsk); | ||
| 1805 | if (retval) | ||
| 1806 | break; | ||
| 1807 | } | ||
| 1808 | cgroup_unlock(); | ||
| 1809 | |||
| 1810 | return retval; | ||
| 1811 | } | ||
| 1812 | EXPORT_SYMBOL_GPL(cgroup_attach_task_current_cg); | ||
| 1813 | |||
| 1791 | /* | 1814 | /* |
| 1792 | * Attach task with pid 'pid' to cgroup 'cgrp'. Call with cgroup_mutex | 1815 | * Attach task with pid 'pid' to cgroup 'cgrp'. Call with cgroup_mutex |
| 1793 | * held. May take task_lock of task | 1816 | * held. May take task_lock of task |
diff --git a/kernel/cpuset.c b/kernel/cpuset.c index 02b9611eadde..7cb37d86a005 100644 --- a/kernel/cpuset.c +++ b/kernel/cpuset.c | |||
| @@ -105,7 +105,7 @@ struct cpuset { | |||
| 105 | /* for custom sched domain */ | 105 | /* for custom sched domain */ |
| 106 | int relax_domain_level; | 106 | int relax_domain_level; |
| 107 | 107 | ||
| 108 | /* used for walking a cpuset heirarchy */ | 108 | /* used for walking a cpuset hierarchy */ |
| 109 | struct list_head stack_list; | 109 | struct list_head stack_list; |
| 110 | }; | 110 | }; |
| 111 | 111 | ||
diff --git a/kernel/cred.c b/kernel/cred.c index a2d5504fbcc2..60bc8b1e32e6 100644 --- a/kernel/cred.c +++ b/kernel/cred.c | |||
| @@ -209,6 +209,31 @@ void exit_creds(struct task_struct *tsk) | |||
| 209 | } | 209 | } |
| 210 | } | 210 | } |
| 211 | 211 | ||
| 212 | /** | ||
| 213 | * get_task_cred - Get another task's objective credentials | ||
| 214 | * @task: The task to query | ||
| 215 | * | ||
| 216 | * Get the objective credentials of a task, pinning them so that they can't go | ||
| 217 | * away. Accessing a task's credentials directly is not permitted. | ||
| 218 | * | ||
| 219 | * The caller must also make sure task doesn't get deleted, either by holding a | ||
| 220 | * ref on task or by holding tasklist_lock to prevent it from being unlinked. | ||
| 221 | */ | ||
| 222 | const struct cred *get_task_cred(struct task_struct *task) | ||
| 223 | { | ||
| 224 | const struct cred *cred; | ||
| 225 | |||
| 226 | rcu_read_lock(); | ||
| 227 | |||
| 228 | do { | ||
| 229 | cred = __task_cred((task)); | ||
| 230 | BUG_ON(!cred); | ||
| 231 | } while (!atomic_inc_not_zero(&((struct cred *)cred)->usage)); | ||
| 232 | |||
| 233 | rcu_read_unlock(); | ||
| 234 | return cred; | ||
| 235 | } | ||
| 236 | |||
| 212 | /* | 237 | /* |
| 213 | * Allocate blank credentials, such that the credentials can be filled in at a | 238 | * Allocate blank credentials, such that the credentials can be filled in at a |
| 214 | * later date without risk of ENOMEM. | 239 | * later date without risk of ENOMEM. |
diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c index 5cb7cd1de10c..3c2d4972d235 100644 --- a/kernel/debug/debug_core.c +++ b/kernel/debug/debug_core.c | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | * Copyright (C) 2000-2001 VERITAS Software Corporation. | 6 | * Copyright (C) 2000-2001 VERITAS Software Corporation. |
| 7 | * Copyright (C) 2002-2004 Timesys Corporation | 7 | * Copyright (C) 2002-2004 Timesys Corporation |
| 8 | * Copyright (C) 2003-2004 Amit S. Kale <amitkale@linsyssoft.com> | 8 | * Copyright (C) 2003-2004 Amit S. Kale <amitkale@linsyssoft.com> |
| 9 | * Copyright (C) 2004 Pavel Machek <pavel@suse.cz> | 9 | * Copyright (C) 2004 Pavel Machek <pavel@ucw.cz> |
| 10 | * Copyright (C) 2004-2006 Tom Rini <trini@kernel.crashing.org> | 10 | * Copyright (C) 2004-2006 Tom Rini <trini@kernel.crashing.org> |
| 11 | * Copyright (C) 2004-2006 LinSysSoft Technologies Pvt. Ltd. | 11 | * Copyright (C) 2004-2006 LinSysSoft Technologies Pvt. Ltd. |
| 12 | * Copyright (C) 2005-2009 Wind River Systems, Inc. | 12 | * Copyright (C) 2005-2009 Wind River Systems, Inc. |
| @@ -605,13 +605,15 @@ cpu_master_loop: | |||
| 605 | if (dbg_kdb_mode) { | 605 | if (dbg_kdb_mode) { |
| 606 | kgdb_connected = 1; | 606 | kgdb_connected = 1; |
| 607 | error = kdb_stub(ks); | 607 | error = kdb_stub(ks); |
| 608 | if (error == -1) | ||
| 609 | continue; | ||
| 610 | kgdb_connected = 0; | ||
| 608 | } else { | 611 | } else { |
| 609 | error = gdb_serial_stub(ks); | 612 | error = gdb_serial_stub(ks); |
| 610 | } | 613 | } |
| 611 | 614 | ||
| 612 | if (error == DBG_PASS_EVENT) { | 615 | if (error == DBG_PASS_EVENT) { |
| 613 | dbg_kdb_mode = !dbg_kdb_mode; | 616 | dbg_kdb_mode = !dbg_kdb_mode; |
| 614 | kgdb_connected = 0; | ||
| 615 | } else if (error == DBG_SWITCH_CPU_EVENT) { | 617 | } else if (error == DBG_SWITCH_CPU_EVENT) { |
| 616 | dbg_cpu_switch(cpu, dbg_switch_cpu); | 618 | dbg_cpu_switch(cpu, dbg_switch_cpu); |
| 617 | goto cpu_loop; | 619 | goto cpu_loop; |
diff --git a/kernel/debug/gdbstub.c b/kernel/debug/gdbstub.c index 4b17b3269525..481a7bd2dfe7 100644 --- a/kernel/debug/gdbstub.c +++ b/kernel/debug/gdbstub.c | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | * Copyright (C) 2000-2001 VERITAS Software Corporation. | 6 | * Copyright (C) 2000-2001 VERITAS Software Corporation. |
| 7 | * Copyright (C) 2002-2004 Timesys Corporation | 7 | * Copyright (C) 2002-2004 Timesys Corporation |
| 8 | * Copyright (C) 2003-2004 Amit S. Kale <amitkale@linsyssoft.com> | 8 | * Copyright (C) 2003-2004 Amit S. Kale <amitkale@linsyssoft.com> |
| 9 | * Copyright (C) 2004 Pavel Machek <pavel@suse.cz> | 9 | * Copyright (C) 2004 Pavel Machek <pavel@ucw.cz> |
| 10 | * Copyright (C) 2004-2006 Tom Rini <trini@kernel.crashing.org> | 10 | * Copyright (C) 2004-2006 Tom Rini <trini@kernel.crashing.org> |
| 11 | * Copyright (C) 2004-2006 LinSysSoft Technologies Pvt. Ltd. | 11 | * Copyright (C) 2004-2006 LinSysSoft Technologies Pvt. Ltd. |
| 12 | * Copyright (C) 2005-2009 Wind River Systems, Inc. | 12 | * Copyright (C) 2005-2009 Wind River Systems, Inc. |
| @@ -52,17 +52,6 @@ static unsigned long gdb_regs[(NUMREGBYTES + | |||
| 52 | * GDB remote protocol parser: | 52 | * GDB remote protocol parser: |
| 53 | */ | 53 | */ |
| 54 | 54 | ||
| 55 | static int hex(char ch) | ||
| 56 | { | ||
| 57 | if ((ch >= 'a') && (ch <= 'f')) | ||
| 58 | return ch - 'a' + 10; | ||
| 59 | if ((ch >= '0') && (ch <= '9')) | ||
| 60 | return ch - '0'; | ||
| 61 | if ((ch >= 'A') && (ch <= 'F')) | ||
| 62 | return ch - 'A' + 10; | ||
| 63 | return -1; | ||
| 64 | } | ||
| 65 | |||
| 66 | #ifdef CONFIG_KGDB_KDB | 55 | #ifdef CONFIG_KGDB_KDB |
| 67 | static int gdbstub_read_wait(void) | 56 | static int gdbstub_read_wait(void) |
| 68 | { | 57 | { |
| @@ -123,8 +112,8 @@ static void get_packet(char *buffer) | |||
| 123 | buffer[count] = 0; | 112 | buffer[count] = 0; |
| 124 | 113 | ||
| 125 | if (ch == '#') { | 114 | if (ch == '#') { |
| 126 | xmitcsum = hex(gdbstub_read_wait()) << 4; | 115 | xmitcsum = hex_to_bin(gdbstub_read_wait()) << 4; |
| 127 | xmitcsum += hex(gdbstub_read_wait()); | 116 | xmitcsum += hex_to_bin(gdbstub_read_wait()); |
| 128 | 117 | ||
| 129 | if (checksum != xmitcsum) | 118 | if (checksum != xmitcsum) |
| 130 | /* failed checksum */ | 119 | /* failed checksum */ |
| @@ -236,7 +225,7 @@ void gdbstub_msg_write(const char *s, int len) | |||
| 236 | * buf. Return a pointer to the last char put in buf (null). May | 225 | * buf. Return a pointer to the last char put in buf (null). May |
| 237 | * return an error. | 226 | * return an error. |
| 238 | */ | 227 | */ |
| 239 | int kgdb_mem2hex(char *mem, char *buf, int count) | 228 | char *kgdb_mem2hex(char *mem, char *buf, int count) |
| 240 | { | 229 | { |
| 241 | char *tmp; | 230 | char *tmp; |
| 242 | int err; | 231 | int err; |
| @@ -248,17 +237,16 @@ int kgdb_mem2hex(char *mem, char *buf, int count) | |||
| 248 | tmp = buf + count; | 237 | tmp = buf + count; |
| 249 | 238 | ||
| 250 | err = probe_kernel_read(tmp, mem, count); | 239 | err = probe_kernel_read(tmp, mem, count); |
| 251 | if (!err) { | 240 | if (err) |
| 252 | while (count > 0) { | 241 | return NULL; |
| 253 | buf = pack_hex_byte(buf, *tmp); | 242 | while (count > 0) { |
| 254 | tmp++; | 243 | buf = pack_hex_byte(buf, *tmp); |
| 255 | count--; | 244 | tmp++; |
| 256 | } | 245 | count--; |
| 257 | |||
| 258 | *buf = 0; | ||
| 259 | } | 246 | } |
| 247 | *buf = 0; | ||
| 260 | 248 | ||
| 261 | return err; | 249 | return buf; |
| 262 | } | 250 | } |
| 263 | 251 | ||
| 264 | /* | 252 | /* |
| @@ -280,8 +268,8 @@ int kgdb_hex2mem(char *buf, char *mem, int count) | |||
| 280 | tmp_hex = tmp_raw - 1; | 268 | tmp_hex = tmp_raw - 1; |
| 281 | while (tmp_hex >= buf) { | 269 | while (tmp_hex >= buf) { |
| 282 | tmp_raw--; | 270 | tmp_raw--; |
| 283 | *tmp_raw = hex(*tmp_hex--); | 271 | *tmp_raw = hex_to_bin(*tmp_hex--); |
| 284 | *tmp_raw |= hex(*tmp_hex--) << 4; | 272 | *tmp_raw |= hex_to_bin(*tmp_hex--) << 4; |
| 285 | } | 273 | } |
| 286 | 274 | ||
| 287 | return probe_kernel_write(mem, tmp_raw, count); | 275 | return probe_kernel_write(mem, tmp_raw, count); |
| @@ -304,7 +292,7 @@ int kgdb_hex2long(char **ptr, unsigned long *long_val) | |||
| 304 | (*ptr)++; | 292 | (*ptr)++; |
| 305 | } | 293 | } |
| 306 | while (**ptr) { | 294 | while (**ptr) { |
| 307 | hex_val = hex(**ptr); | 295 | hex_val = hex_to_bin(**ptr); |
| 308 | if (hex_val < 0) | 296 | if (hex_val < 0) |
| 309 | break; | 297 | break; |
| 310 | 298 | ||
| @@ -339,6 +327,32 @@ static int kgdb_ebin2mem(char *buf, char *mem, int count) | |||
| 339 | return probe_kernel_write(mem, c, size); | 327 | return probe_kernel_write(mem, c, size); |
| 340 | } | 328 | } |
| 341 | 329 | ||
| 330 | #if DBG_MAX_REG_NUM > 0 | ||
| 331 | void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs) | ||
| 332 | { | ||
| 333 | int i; | ||
| 334 | int idx = 0; | ||
| 335 | char *ptr = (char *)gdb_regs; | ||
| 336 | |||
| 337 | for (i = 0; i < DBG_MAX_REG_NUM; i++) { | ||
| 338 | dbg_get_reg(i, ptr + idx, regs); | ||
| 339 | idx += dbg_reg_def[i].size; | ||
| 340 | } | ||
| 341 | } | ||
| 342 | |||
| 343 | void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs) | ||
| 344 | { | ||
| 345 | int i; | ||
| 346 | int idx = 0; | ||
| 347 | char *ptr = (char *)gdb_regs; | ||
| 348 | |||
| 349 | for (i = 0; i < DBG_MAX_REG_NUM; i++) { | ||
| 350 | dbg_set_reg(i, ptr + idx, regs); | ||
| 351 | idx += dbg_reg_def[i].size; | ||
| 352 | } | ||
| 353 | } | ||
| 354 | #endif /* DBG_MAX_REG_NUM > 0 */ | ||
| 355 | |||
| 342 | /* Write memory due to an 'M' or 'X' packet. */ | 356 | /* Write memory due to an 'M' or 'X' packet. */ |
| 343 | static int write_mem_msg(int binary) | 357 | static int write_mem_msg(int binary) |
| 344 | { | 358 | { |
| @@ -378,28 +392,31 @@ static void error_packet(char *pkt, int error) | |||
| 378 | * remapped to negative TIDs. | 392 | * remapped to negative TIDs. |
| 379 | */ | 393 | */ |
| 380 | 394 | ||
| 381 | #define BUF_THREAD_ID_SIZE 16 | 395 | #define BUF_THREAD_ID_SIZE 8 |
| 382 | 396 | ||
| 383 | static char *pack_threadid(char *pkt, unsigned char *id) | 397 | static char *pack_threadid(char *pkt, unsigned char *id) |
| 384 | { | 398 | { |
| 385 | char *limit; | 399 | unsigned char *limit; |
| 400 | int lzero = 1; | ||
| 401 | |||
| 402 | limit = id + (BUF_THREAD_ID_SIZE / 2); | ||
| 403 | while (id < limit) { | ||
| 404 | if (!lzero || *id != 0) { | ||
| 405 | pkt = pack_hex_byte(pkt, *id); | ||
| 406 | lzero = 0; | ||
| 407 | } | ||
| 408 | id++; | ||
| 409 | } | ||
| 386 | 410 | ||
| 387 | limit = pkt + BUF_THREAD_ID_SIZE; | 411 | if (lzero) |
| 388 | while (pkt < limit) | 412 | pkt = pack_hex_byte(pkt, 0); |
| 389 | pkt = pack_hex_byte(pkt, *id++); | ||
| 390 | 413 | ||
| 391 | return pkt; | 414 | return pkt; |
| 392 | } | 415 | } |
| 393 | 416 | ||
| 394 | static void int_to_threadref(unsigned char *id, int value) | 417 | static void int_to_threadref(unsigned char *id, int value) |
| 395 | { | 418 | { |
| 396 | unsigned char *scan; | 419 | put_unaligned_be32(value, id); |
| 397 | int i = 4; | ||
| 398 | |||
| 399 | scan = (unsigned char *)id; | ||
| 400 | while (i--) | ||
| 401 | *scan++ = 0; | ||
| 402 | put_unaligned_be32(value, scan); | ||
| 403 | } | 420 | } |
| 404 | 421 | ||
| 405 | static struct task_struct *getthread(struct pt_regs *regs, int tid) | 422 | static struct task_struct *getthread(struct pt_regs *regs, int tid) |
| @@ -463,8 +480,7 @@ static void gdb_cmd_status(struct kgdb_state *ks) | |||
| 463 | pack_hex_byte(&remcom_out_buffer[1], ks->signo); | 480 | pack_hex_byte(&remcom_out_buffer[1], ks->signo); |
| 464 | } | 481 | } |
| 465 | 482 | ||
| 466 | /* Handle the 'g' get registers request */ | 483 | static void gdb_get_regs_helper(struct kgdb_state *ks) |
| 467 | static void gdb_cmd_getregs(struct kgdb_state *ks) | ||
| 468 | { | 484 | { |
| 469 | struct task_struct *thread; | 485 | struct task_struct *thread; |
| 470 | void *local_debuggerinfo; | 486 | void *local_debuggerinfo; |
| @@ -505,6 +521,12 @@ static void gdb_cmd_getregs(struct kgdb_state *ks) | |||
| 505 | */ | 521 | */ |
| 506 | sleeping_thread_to_gdb_regs(gdb_regs, thread); | 522 | sleeping_thread_to_gdb_regs(gdb_regs, thread); |
| 507 | } | 523 | } |
| 524 | } | ||
| 525 | |||
| 526 | /* Handle the 'g' get registers request */ | ||
| 527 | static void gdb_cmd_getregs(struct kgdb_state *ks) | ||
| 528 | { | ||
| 529 | gdb_get_regs_helper(ks); | ||
| 508 | kgdb_mem2hex((char *)gdb_regs, remcom_out_buffer, NUMREGBYTES); | 530 | kgdb_mem2hex((char *)gdb_regs, remcom_out_buffer, NUMREGBYTES); |
| 509 | } | 531 | } |
| 510 | 532 | ||
| @@ -527,13 +549,13 @@ static void gdb_cmd_memread(struct kgdb_state *ks) | |||
| 527 | char *ptr = &remcom_in_buffer[1]; | 549 | char *ptr = &remcom_in_buffer[1]; |
| 528 | unsigned long length; | 550 | unsigned long length; |
| 529 | unsigned long addr; | 551 | unsigned long addr; |
| 530 | int err; | 552 | char *err; |
| 531 | 553 | ||
| 532 | if (kgdb_hex2long(&ptr, &addr) > 0 && *ptr++ == ',' && | 554 | if (kgdb_hex2long(&ptr, &addr) > 0 && *ptr++ == ',' && |
| 533 | kgdb_hex2long(&ptr, &length) > 0) { | 555 | kgdb_hex2long(&ptr, &length) > 0) { |
| 534 | err = kgdb_mem2hex((char *)addr, remcom_out_buffer, length); | 556 | err = kgdb_mem2hex((char *)addr, remcom_out_buffer, length); |
| 535 | if (err) | 557 | if (!err) |
| 536 | error_packet(remcom_out_buffer, err); | 558 | error_packet(remcom_out_buffer, -EINVAL); |
| 537 | } else { | 559 | } else { |
| 538 | error_packet(remcom_out_buffer, -EINVAL); | 560 | error_packet(remcom_out_buffer, -EINVAL); |
| 539 | } | 561 | } |
| @@ -550,6 +572,60 @@ static void gdb_cmd_memwrite(struct kgdb_state *ks) | |||
| 550 | strcpy(remcom_out_buffer, "OK"); | 572 | strcpy(remcom_out_buffer, "OK"); |
| 551 | } | 573 | } |
| 552 | 574 | ||
| 575 | #if DBG_MAX_REG_NUM > 0 | ||
| 576 | static char *gdb_hex_reg_helper(int regnum, char *out) | ||
| 577 | { | ||
| 578 | int i; | ||
| 579 | int offset = 0; | ||
| 580 | |||
| 581 | for (i = 0; i < regnum; i++) | ||
| 582 | offset += dbg_reg_def[i].size; | ||
| 583 | return kgdb_mem2hex((char *)gdb_regs + offset, out, | ||
| 584 | dbg_reg_def[i].size); | ||
| 585 | } | ||
| 586 | |||
| 587 | /* Handle the 'p' individual regster get */ | ||
| 588 | static void gdb_cmd_reg_get(struct kgdb_state *ks) | ||
| 589 | { | ||
| 590 | unsigned long regnum; | ||
| 591 | char *ptr = &remcom_in_buffer[1]; | ||
| 592 | |||
| 593 | kgdb_hex2long(&ptr, ®num); | ||
| 594 | if (regnum >= DBG_MAX_REG_NUM) { | ||
| 595 | error_packet(remcom_out_buffer, -EINVAL); | ||
| 596 | return; | ||
| 597 | } | ||
| 598 | gdb_get_regs_helper(ks); | ||
| 599 | gdb_hex_reg_helper(regnum, remcom_out_buffer); | ||
| 600 | } | ||
| 601 | |||
| 602 | /* Handle the 'P' individual regster set */ | ||
| 603 | static void gdb_cmd_reg_set(struct kgdb_state *ks) | ||
| 604 | { | ||
| 605 | unsigned long regnum; | ||
| 606 | char *ptr = &remcom_in_buffer[1]; | ||
| 607 | int i = 0; | ||
| 608 | |||
| 609 | kgdb_hex2long(&ptr, ®num); | ||
| 610 | if (*ptr++ != '=' || | ||
| 611 | !(!kgdb_usethread || kgdb_usethread == current) || | ||
| 612 | !dbg_get_reg(regnum, gdb_regs, ks->linux_regs)) { | ||
| 613 | error_packet(remcom_out_buffer, -EINVAL); | ||
| 614 | return; | ||
| 615 | } | ||
| 616 | memset(gdb_regs, 0, sizeof(gdb_regs)); | ||
| 617 | while (i < sizeof(gdb_regs) * 2) | ||
| 618 | if (hex_to_bin(ptr[i]) >= 0) | ||
| 619 | i++; | ||
| 620 | else | ||
| 621 | break; | ||
| 622 | i = i / 2; | ||
| 623 | kgdb_hex2mem(ptr, (char *)gdb_regs, i); | ||
| 624 | dbg_set_reg(regnum, gdb_regs, ks->linux_regs); | ||
| 625 | strcpy(remcom_out_buffer, "OK"); | ||
| 626 | } | ||
| 627 | #endif /* DBG_MAX_REG_NUM > 0 */ | ||
| 628 | |||
| 553 | /* Handle the 'X' memory binary write bytes */ | 629 | /* Handle the 'X' memory binary write bytes */ |
| 554 | static void gdb_cmd_binwrite(struct kgdb_state *ks) | 630 | static void gdb_cmd_binwrite(struct kgdb_state *ks) |
| 555 | { | 631 | { |
| @@ -612,7 +688,7 @@ static void gdb_cmd_query(struct kgdb_state *ks) | |||
| 612 | { | 688 | { |
| 613 | struct task_struct *g; | 689 | struct task_struct *g; |
| 614 | struct task_struct *p; | 690 | struct task_struct *p; |
| 615 | unsigned char thref[8]; | 691 | unsigned char thref[BUF_THREAD_ID_SIZE]; |
| 616 | char *ptr; | 692 | char *ptr; |
| 617 | int i; | 693 | int i; |
| 618 | int cpu; | 694 | int cpu; |
| @@ -621,10 +697,8 @@ static void gdb_cmd_query(struct kgdb_state *ks) | |||
| 621 | switch (remcom_in_buffer[1]) { | 697 | switch (remcom_in_buffer[1]) { |
| 622 | case 's': | 698 | case 's': |
| 623 | case 'f': | 699 | case 'f': |
| 624 | if (memcmp(remcom_in_buffer + 2, "ThreadInfo", 10)) { | 700 | if (memcmp(remcom_in_buffer + 2, "ThreadInfo", 10)) |
| 625 | error_packet(remcom_out_buffer, -EINVAL); | ||
| 626 | break; | 701 | break; |
| 627 | } | ||
| 628 | 702 | ||
| 629 | i = 0; | 703 | i = 0; |
| 630 | remcom_out_buffer[0] = 'm'; | 704 | remcom_out_buffer[0] = 'm'; |
| @@ -634,8 +708,7 @@ static void gdb_cmd_query(struct kgdb_state *ks) | |||
| 634 | for_each_online_cpu(cpu) { | 708 | for_each_online_cpu(cpu) { |
| 635 | ks->thr_query = 0; | 709 | ks->thr_query = 0; |
| 636 | int_to_threadref(thref, -cpu - 2); | 710 | int_to_threadref(thref, -cpu - 2); |
| 637 | pack_threadid(ptr, thref); | 711 | ptr = pack_threadid(ptr, thref); |
| 638 | ptr += BUF_THREAD_ID_SIZE; | ||
| 639 | *(ptr++) = ','; | 712 | *(ptr++) = ','; |
| 640 | i++; | 713 | i++; |
| 641 | } | 714 | } |
| @@ -644,8 +717,7 @@ static void gdb_cmd_query(struct kgdb_state *ks) | |||
| 644 | do_each_thread(g, p) { | 717 | do_each_thread(g, p) { |
| 645 | if (i >= ks->thr_query && !finished) { | 718 | if (i >= ks->thr_query && !finished) { |
| 646 | int_to_threadref(thref, p->pid); | 719 | int_to_threadref(thref, p->pid); |
| 647 | pack_threadid(ptr, thref); | 720 | ptr = pack_threadid(ptr, thref); |
| 648 | ptr += BUF_THREAD_ID_SIZE; | ||
| 649 | *(ptr++) = ','; | 721 | *(ptr++) = ','; |
| 650 | ks->thr_query++; | 722 | ks->thr_query++; |
| 651 | if (ks->thr_query % KGDB_MAX_THREAD_QUERY == 0) | 723 | if (ks->thr_query % KGDB_MAX_THREAD_QUERY == 0) |
| @@ -665,10 +737,9 @@ static void gdb_cmd_query(struct kgdb_state *ks) | |||
| 665 | pack_threadid(remcom_out_buffer + 2, thref); | 737 | pack_threadid(remcom_out_buffer + 2, thref); |
| 666 | break; | 738 | break; |
| 667 | case 'T': | 739 | case 'T': |
| 668 | if (memcmp(remcom_in_buffer + 1, "ThreadExtraInfo,", 16)) { | 740 | if (memcmp(remcom_in_buffer + 1, "ThreadExtraInfo,", 16)) |
| 669 | error_packet(remcom_out_buffer, -EINVAL); | ||
| 670 | break; | 741 | break; |
| 671 | } | 742 | |
| 672 | ks->threadid = 0; | 743 | ks->threadid = 0; |
| 673 | ptr = remcom_in_buffer + 17; | 744 | ptr = remcom_in_buffer + 17; |
| 674 | kgdb_hex2long(&ptr, &ks->threadid); | 745 | kgdb_hex2long(&ptr, &ks->threadid); |
| @@ -861,11 +932,14 @@ int gdb_serial_stub(struct kgdb_state *ks) | |||
| 861 | int error = 0; | 932 | int error = 0; |
| 862 | int tmp; | 933 | int tmp; |
| 863 | 934 | ||
| 864 | /* Clear the out buffer. */ | 935 | /* Initialize comm buffer and globals. */ |
| 865 | memset(remcom_out_buffer, 0, sizeof(remcom_out_buffer)); | 936 | memset(remcom_out_buffer, 0, sizeof(remcom_out_buffer)); |
| 937 | kgdb_usethread = kgdb_info[ks->cpu].task; | ||
| 938 | ks->kgdb_usethreadid = shadow_pid(kgdb_info[ks->cpu].task->pid); | ||
| 939 | ks->pass_exception = 0; | ||
| 866 | 940 | ||
| 867 | if (kgdb_connected) { | 941 | if (kgdb_connected) { |
| 868 | unsigned char thref[8]; | 942 | unsigned char thref[BUF_THREAD_ID_SIZE]; |
| 869 | char *ptr; | 943 | char *ptr; |
| 870 | 944 | ||
| 871 | /* Reply to host that an exception has occurred */ | 945 | /* Reply to host that an exception has occurred */ |
| @@ -879,10 +953,6 @@ int gdb_serial_stub(struct kgdb_state *ks) | |||
| 879 | put_packet(remcom_out_buffer); | 953 | put_packet(remcom_out_buffer); |
| 880 | } | 954 | } |
| 881 | 955 | ||
| 882 | kgdb_usethread = kgdb_info[ks->cpu].task; | ||
| 883 | ks->kgdb_usethreadid = shadow_pid(kgdb_info[ks->cpu].task->pid); | ||
| 884 | ks->pass_exception = 0; | ||
| 885 | |||
| 886 | while (1) { | 956 | while (1) { |
| 887 | error = 0; | 957 | error = 0; |
| 888 | 958 | ||
| @@ -907,6 +977,14 @@ int gdb_serial_stub(struct kgdb_state *ks) | |||
| 907 | case 'M': /* MAA..AA,LLLL: Write LLLL bytes at address AA..AA */ | 977 | case 'M': /* MAA..AA,LLLL: Write LLLL bytes at address AA..AA */ |
| 908 | gdb_cmd_memwrite(ks); | 978 | gdb_cmd_memwrite(ks); |
| 909 | break; | 979 | break; |
| 980 | #if DBG_MAX_REG_NUM > 0 | ||
| 981 | case 'p': /* pXX Return gdb register XX (in hex) */ | ||
| 982 | gdb_cmd_reg_get(ks); | ||
| 983 | break; | ||
| 984 | case 'P': /* PXX=aaaa Set gdb register XX to aaaa (in hex) */ | ||
| 985 | gdb_cmd_reg_set(ks); | ||
| 986 | break; | ||
| 987 | #endif /* DBG_MAX_REG_NUM > 0 */ | ||
| 910 | case 'X': /* XAA..AA,LLLL: Write LLLL bytes at address AA..AA */ | 988 | case 'X': /* XAA..AA,LLLL: Write LLLL bytes at address AA..AA */ |
| 911 | gdb_cmd_binwrite(ks); | 989 | gdb_cmd_binwrite(ks); |
| 912 | break; | 990 | break; |
diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c index 184cd8209c36..8577e45a9a58 100644 --- a/kernel/debug/kdb/kdb_main.c +++ b/kernel/debug/kdb/kdb_main.c | |||
| @@ -312,7 +312,7 @@ int kdbgetularg(const char *arg, unsigned long *value) | |||
| 312 | 312 | ||
| 313 | if (endp == arg) { | 313 | if (endp == arg) { |
| 314 | /* | 314 | /* |
| 315 | * Try base 16, for us folks too lazy to type the | 315 | * Also try base 16, for us folks too lazy to type the |
| 316 | * leading 0x... | 316 | * leading 0x... |
| 317 | */ | 317 | */ |
| 318 | val = simple_strtoul(arg, &endp, 16); | 318 | val = simple_strtoul(arg, &endp, 16); |
| @@ -325,6 +325,25 @@ int kdbgetularg(const char *arg, unsigned long *value) | |||
| 325 | return 0; | 325 | return 0; |
| 326 | } | 326 | } |
| 327 | 327 | ||
| 328 | int kdbgetu64arg(const char *arg, u64 *value) | ||
| 329 | { | ||
| 330 | char *endp; | ||
| 331 | u64 val; | ||
| 332 | |||
| 333 | val = simple_strtoull(arg, &endp, 0); | ||
| 334 | |||
| 335 | if (endp == arg) { | ||
| 336 | |||
| 337 | val = simple_strtoull(arg, &endp, 16); | ||
| 338 | if (endp == arg) | ||
| 339 | return KDB_BADINT; | ||
| 340 | } | ||
| 341 | |||
| 342 | *value = val; | ||
| 343 | |||
| 344 | return 0; | ||
| 345 | } | ||
| 346 | |||
| 328 | /* | 347 | /* |
| 329 | * kdb_set - This function implements the 'set' command. Alter an | 348 | * kdb_set - This function implements the 'set' command. Alter an |
| 330 | * existing environment variable or create a new one. | 349 | * existing environment variable or create a new one. |
| @@ -1770,11 +1789,65 @@ static int kdb_go(int argc, const char **argv) | |||
| 1770 | */ | 1789 | */ |
| 1771 | static int kdb_rd(int argc, const char **argv) | 1790 | static int kdb_rd(int argc, const char **argv) |
| 1772 | { | 1791 | { |
| 1773 | int diag = kdb_check_regs(); | 1792 | int len = kdb_check_regs(); |
| 1774 | if (diag) | 1793 | #if DBG_MAX_REG_NUM > 0 |
| 1775 | return diag; | 1794 | int i; |
| 1795 | char *rname; | ||
| 1796 | int rsize; | ||
| 1797 | u64 reg64; | ||
| 1798 | u32 reg32; | ||
| 1799 | u16 reg16; | ||
| 1800 | u8 reg8; | ||
| 1801 | |||
| 1802 | if (len) | ||
| 1803 | return len; | ||
| 1804 | |||
| 1805 | for (i = 0; i < DBG_MAX_REG_NUM; i++) { | ||
| 1806 | rsize = dbg_reg_def[i].size * 2; | ||
| 1807 | if (rsize > 16) | ||
| 1808 | rsize = 2; | ||
| 1809 | if (len + strlen(dbg_reg_def[i].name) + 4 + rsize > 80) { | ||
| 1810 | len = 0; | ||
| 1811 | kdb_printf("\n"); | ||
| 1812 | } | ||
| 1813 | if (len) | ||
| 1814 | len += kdb_printf(" "); | ||
| 1815 | switch(dbg_reg_def[i].size * 8) { | ||
| 1816 | case 8: | ||
| 1817 | rname = dbg_get_reg(i, ®8, kdb_current_regs); | ||
| 1818 | if (!rname) | ||
| 1819 | break; | ||
| 1820 | len += kdb_printf("%s: %02x", rname, reg8); | ||
| 1821 | break; | ||
| 1822 | case 16: | ||
| 1823 | rname = dbg_get_reg(i, ®16, kdb_current_regs); | ||
| 1824 | if (!rname) | ||
| 1825 | break; | ||
| 1826 | len += kdb_printf("%s: %04x", rname, reg16); | ||
| 1827 | break; | ||
| 1828 | case 32: | ||
| 1829 | rname = dbg_get_reg(i, ®32, kdb_current_regs); | ||
| 1830 | if (!rname) | ||
| 1831 | break; | ||
| 1832 | len += kdb_printf("%s: %08x", rname, reg32); | ||
| 1833 | break; | ||
| 1834 | case 64: | ||
| 1835 | rname = dbg_get_reg(i, ®64, kdb_current_regs); | ||
| 1836 | if (!rname) | ||
| 1837 | break; | ||
| 1838 | len += kdb_printf("%s: %016llx", rname, reg64); | ||
| 1839 | break; | ||
| 1840 | default: | ||
| 1841 | len += kdb_printf("%s: ??", dbg_reg_def[i].name); | ||
| 1842 | } | ||
| 1843 | } | ||
| 1844 | kdb_printf("\n"); | ||
| 1845 | #else | ||
| 1846 | if (len) | ||
| 1847 | return len; | ||
| 1776 | 1848 | ||
| 1777 | kdb_dumpregs(kdb_current_regs); | 1849 | kdb_dumpregs(kdb_current_regs); |
| 1850 | #endif | ||
| 1778 | return 0; | 1851 | return 0; |
| 1779 | } | 1852 | } |
| 1780 | 1853 | ||
| @@ -1782,32 +1855,67 @@ static int kdb_rd(int argc, const char **argv) | |||
| 1782 | * kdb_rm - This function implements the 'rm' (register modify) command. | 1855 | * kdb_rm - This function implements the 'rm' (register modify) command. |
| 1783 | * rm register-name new-contents | 1856 | * rm register-name new-contents |
| 1784 | * Remarks: | 1857 | * Remarks: |
| 1785 | * Currently doesn't allow modification of control or | 1858 | * Allows register modification with the same restrictions as gdb |
| 1786 | * debug registers. | ||
| 1787 | */ | 1859 | */ |
| 1788 | static int kdb_rm(int argc, const char **argv) | 1860 | static int kdb_rm(int argc, const char **argv) |
| 1789 | { | 1861 | { |
| 1862 | #if DBG_MAX_REG_NUM > 0 | ||
| 1790 | int diag; | 1863 | int diag; |
| 1791 | int ind = 0; | 1864 | const char *rname; |
| 1792 | unsigned long contents; | 1865 | int i; |
| 1866 | u64 reg64; | ||
| 1867 | u32 reg32; | ||
| 1868 | u16 reg16; | ||
| 1869 | u8 reg8; | ||
| 1793 | 1870 | ||
| 1794 | if (argc != 2) | 1871 | if (argc != 2) |
| 1795 | return KDB_ARGCOUNT; | 1872 | return KDB_ARGCOUNT; |
| 1796 | /* | 1873 | /* |
| 1797 | * Allow presence or absence of leading '%' symbol. | 1874 | * Allow presence or absence of leading '%' symbol. |
| 1798 | */ | 1875 | */ |
| 1799 | if (argv[1][0] == '%') | 1876 | rname = argv[1]; |
| 1800 | ind = 1; | 1877 | if (*rname == '%') |
| 1878 | rname++; | ||
| 1801 | 1879 | ||
| 1802 | diag = kdbgetularg(argv[2], &contents); | 1880 | diag = kdbgetu64arg(argv[2], ®64); |
| 1803 | if (diag) | 1881 | if (diag) |
| 1804 | return diag; | 1882 | return diag; |
| 1805 | 1883 | ||
| 1806 | diag = kdb_check_regs(); | 1884 | diag = kdb_check_regs(); |
| 1807 | if (diag) | 1885 | if (diag) |
| 1808 | return diag; | 1886 | return diag; |
| 1887 | |||
| 1888 | diag = KDB_BADREG; | ||
| 1889 | for (i = 0; i < DBG_MAX_REG_NUM; i++) { | ||
| 1890 | if (strcmp(rname, dbg_reg_def[i].name) == 0) { | ||
| 1891 | diag = 0; | ||
| 1892 | break; | ||
| 1893 | } | ||
| 1894 | } | ||
| 1895 | if (!diag) { | ||
| 1896 | switch(dbg_reg_def[i].size * 8) { | ||
| 1897 | case 8: | ||
| 1898 | reg8 = reg64; | ||
| 1899 | dbg_set_reg(i, ®8, kdb_current_regs); | ||
| 1900 | break; | ||
| 1901 | case 16: | ||
| 1902 | reg16 = reg64; | ||
| 1903 | dbg_set_reg(i, ®16, kdb_current_regs); | ||
| 1904 | break; | ||
| 1905 | case 32: | ||
| 1906 | reg32 = reg64; | ||
| 1907 | dbg_set_reg(i, ®32, kdb_current_regs); | ||
| 1908 | break; | ||
| 1909 | case 64: | ||
| 1910 | dbg_set_reg(i, ®64, kdb_current_regs); | ||
| 1911 | break; | ||
| 1912 | } | ||
| 1913 | } | ||
| 1914 | return diag; | ||
| 1915 | #else | ||
| 1809 | kdb_printf("ERROR: Register set currently not implemented\n"); | 1916 | kdb_printf("ERROR: Register set currently not implemented\n"); |
| 1810 | return 0; | 1917 | return 0; |
| 1918 | #endif | ||
| 1811 | } | 1919 | } |
| 1812 | 1920 | ||
| 1813 | #if defined(CONFIG_MAGIC_SYSRQ) | 1921 | #if defined(CONFIG_MAGIC_SYSRQ) |
| @@ -1820,9 +1928,8 @@ static int kdb_sr(int argc, const char **argv) | |||
| 1820 | { | 1928 | { |
| 1821 | if (argc != 1) | 1929 | if (argc != 1) |
| 1822 | return KDB_ARGCOUNT; | 1930 | return KDB_ARGCOUNT; |
| 1823 | sysrq_toggle_support(1); | ||
| 1824 | kdb_trap_printk++; | 1931 | kdb_trap_printk++; |
| 1825 | handle_sysrq(*argv[1], NULL); | 1932 | __handle_sysrq(*argv[1], NULL, 0); |
| 1826 | kdb_trap_printk--; | 1933 | kdb_trap_printk--; |
| 1827 | 1934 | ||
| 1828 | return 0; | 1935 | return 0; |
| @@ -1883,6 +1990,7 @@ static int kdb_lsmod(int argc, const char **argv) | |||
| 1883 | kdb_printf(" (Loading)"); | 1990 | kdb_printf(" (Loading)"); |
| 1884 | else | 1991 | else |
| 1885 | kdb_printf(" (Live)"); | 1992 | kdb_printf(" (Live)"); |
| 1993 | kdb_printf(" 0x%p", mod->module_core); | ||
| 1886 | 1994 | ||
| 1887 | #ifdef CONFIG_MODULE_UNLOAD | 1995 | #ifdef CONFIG_MODULE_UNLOAD |
| 1888 | { | 1996 | { |
| @@ -2291,6 +2399,9 @@ static int kdb_ll(int argc, const char **argv) | |||
| 2291 | while (va) { | 2399 | while (va) { |
| 2292 | char buf[80]; | 2400 | char buf[80]; |
| 2293 | 2401 | ||
| 2402 | if (KDB_FLAG(CMD_INTERRUPT)) | ||
| 2403 | return 0; | ||
| 2404 | |||
| 2294 | sprintf(buf, "%s " kdb_machreg_fmt "\n", command, va); | 2405 | sprintf(buf, "%s " kdb_machreg_fmt "\n", command, va); |
| 2295 | diag = kdb_parse(buf); | 2406 | diag = kdb_parse(buf); |
| 2296 | if (diag) | 2407 | if (diag) |
diff --git a/kernel/debug/kdb/kdb_private.h b/kernel/debug/kdb/kdb_private.h index 97d3ba69775d..c438f545a321 100644 --- a/kernel/debug/kdb/kdb_private.h +++ b/kernel/debug/kdb/kdb_private.h | |||
| @@ -144,9 +144,7 @@ extern int kdb_getword(unsigned long *, unsigned long, size_t); | |||
| 144 | extern int kdb_putword(unsigned long, unsigned long, size_t); | 144 | extern int kdb_putword(unsigned long, unsigned long, size_t); |
| 145 | 145 | ||
| 146 | extern int kdbgetularg(const char *, unsigned long *); | 146 | extern int kdbgetularg(const char *, unsigned long *); |
| 147 | extern int kdb_set(int, const char **); | ||
| 148 | extern char *kdbgetenv(const char *); | 147 | extern char *kdbgetenv(const char *); |
| 149 | extern int kdbgetintenv(const char *, int *); | ||
| 150 | extern int kdbgetaddrarg(int, const char **, int*, unsigned long *, | 148 | extern int kdbgetaddrarg(int, const char **, int*, unsigned long *, |
| 151 | long *, char **); | 149 | long *, char **); |
| 152 | extern int kdbgetsymval(const char *, kdb_symtab_t *); | 150 | extern int kdbgetsymval(const char *, kdb_symtab_t *); |
diff --git a/kernel/early_res.c b/kernel/early_res.c index 31aa9332ef3f..7bfae887f211 100644 --- a/kernel/early_res.c +++ b/kernel/early_res.c | |||
| @@ -7,6 +7,8 @@ | |||
| 7 | #include <linux/bootmem.h> | 7 | #include <linux/bootmem.h> |
| 8 | #include <linux/mm.h> | 8 | #include <linux/mm.h> |
| 9 | #include <linux/early_res.h> | 9 | #include <linux/early_res.h> |
| 10 | #include <linux/slab.h> | ||
| 11 | #include <linux/kmemleak.h> | ||
| 10 | 12 | ||
| 11 | /* | 13 | /* |
| 12 | * Early reserved memory areas. | 14 | * Early reserved memory areas. |
| @@ -319,6 +321,8 @@ void __init free_early(u64 start, u64 end) | |||
| 319 | struct early_res *r; | 321 | struct early_res *r; |
| 320 | int i; | 322 | int i; |
| 321 | 323 | ||
| 324 | kmemleak_free_part(__va(start), end - start); | ||
| 325 | |||
| 322 | i = find_overlapped_early(start, end); | 326 | i = find_overlapped_early(start, end); |
| 323 | r = &early_res[i]; | 327 | r = &early_res[i]; |
| 324 | if (i >= max_early_res || r->end != end || r->start != start) | 328 | if (i >= max_early_res || r->end != end || r->start != start) |
| @@ -333,6 +337,8 @@ void __init free_early_partial(u64 start, u64 end) | |||
| 333 | struct early_res *r; | 337 | struct early_res *r; |
| 334 | int i; | 338 | int i; |
| 335 | 339 | ||
| 340 | kmemleak_free_part(__va(start), end - start); | ||
| 341 | |||
| 336 | if (start == end) | 342 | if (start == end) |
| 337 | return; | 343 | return; |
| 338 | 344 | ||
diff --git a/kernel/hw_breakpoint.c b/kernel/hw_breakpoint.c index 7a56b22e0602..71ed3ce29e12 100644 --- a/kernel/hw_breakpoint.c +++ b/kernel/hw_breakpoint.c | |||
| @@ -242,6 +242,17 @@ toggle_bp_slot(struct perf_event *bp, bool enable, enum bp_type_idx type, | |||
| 242 | } | 242 | } |
| 243 | 243 | ||
| 244 | /* | 244 | /* |
| 245 | * Function to perform processor-specific cleanup during unregistration | ||
| 246 | */ | ||
| 247 | __weak void arch_unregister_hw_breakpoint(struct perf_event *bp) | ||
| 248 | { | ||
| 249 | /* | ||
| 250 | * A weak stub function here for those archs that don't define | ||
| 251 | * it inside arch/.../kernel/hw_breakpoint.c | ||
| 252 | */ | ||
| 253 | } | ||
| 254 | |||
| 255 | /* | ||
| 245 | * Contraints to check before allowing this new breakpoint counter: | 256 | * Contraints to check before allowing this new breakpoint counter: |
| 246 | * | 257 | * |
| 247 | * == Non-pinned counter == (Considered as pinned for now) | 258 | * == Non-pinned counter == (Considered as pinned for now) |
| @@ -339,6 +350,7 @@ void release_bp_slot(struct perf_event *bp) | |||
| 339 | { | 350 | { |
| 340 | mutex_lock(&nr_bp_mutex); | 351 | mutex_lock(&nr_bp_mutex); |
| 341 | 352 | ||
| 353 | arch_unregister_hw_breakpoint(bp); | ||
| 342 | __release_bp_slot(bp); | 354 | __release_bp_slot(bp); |
| 343 | 355 | ||
| 344 | mutex_unlock(&nr_bp_mutex); | 356 | mutex_unlock(&nr_bp_mutex); |
diff --git a/kernel/module.c b/kernel/module.c index 5d2d28197c82..d0b5f8db11b4 100644 --- a/kernel/module.c +++ b/kernel/module.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* | 1 | /* |
| 2 | Copyright (C) 2002 Richard Henderson | 2 | Copyright (C) 2002 Richard Henderson |
| 3 | Copyright (C) 2001 Rusty Russell, 2002 Rusty Russell IBM. | 3 | Copyright (C) 2001 Rusty Russell, 2002, 2010 Rusty Russell IBM. |
| 4 | 4 | ||
| 5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
| @@ -110,6 +110,20 @@ int unregister_module_notifier(struct notifier_block * nb) | |||
| 110 | } | 110 | } |
| 111 | EXPORT_SYMBOL(unregister_module_notifier); | 111 | EXPORT_SYMBOL(unregister_module_notifier); |
| 112 | 112 | ||
| 113 | struct load_info { | ||
| 114 | Elf_Ehdr *hdr; | ||
| 115 | unsigned long len; | ||
| 116 | Elf_Shdr *sechdrs; | ||
| 117 | char *secstrings, *strtab; | ||
| 118 | unsigned long *strmap; | ||
| 119 | unsigned long symoffs, stroffs; | ||
| 120 | struct _ddebug *debug; | ||
| 121 | unsigned int num_debug; | ||
| 122 | struct { | ||
| 123 | unsigned int sym, str, mod, vers, info, pcpu; | ||
| 124 | } index; | ||
| 125 | }; | ||
| 126 | |||
| 113 | /* We require a truly strong try_module_get(): 0 means failure due to | 127 | /* We require a truly strong try_module_get(): 0 means failure due to |
| 114 | ongoing or failed initialization etc. */ | 128 | ongoing or failed initialization etc. */ |
| 115 | static inline int strong_try_module_get(struct module *mod) | 129 | static inline int strong_try_module_get(struct module *mod) |
| @@ -140,42 +154,38 @@ void __module_put_and_exit(struct module *mod, long code) | |||
| 140 | EXPORT_SYMBOL(__module_put_and_exit); | 154 | EXPORT_SYMBOL(__module_put_and_exit); |
| 141 | 155 | ||
| 142 | /* Find a module section: 0 means not found. */ | 156 | /* Find a module section: 0 means not found. */ |
| 143 | static unsigned int find_sec(Elf_Ehdr *hdr, | 157 | static unsigned int find_sec(const struct load_info *info, const char *name) |
| 144 | Elf_Shdr *sechdrs, | ||
| 145 | const char *secstrings, | ||
| 146 | const char *name) | ||
| 147 | { | 158 | { |
| 148 | unsigned int i; | 159 | unsigned int i; |
| 149 | 160 | ||
| 150 | for (i = 1; i < hdr->e_shnum; i++) | 161 | for (i = 1; i < info->hdr->e_shnum; i++) { |
| 162 | Elf_Shdr *shdr = &info->sechdrs[i]; | ||
| 151 | /* Alloc bit cleared means "ignore it." */ | 163 | /* Alloc bit cleared means "ignore it." */ |
| 152 | if ((sechdrs[i].sh_flags & SHF_ALLOC) | 164 | if ((shdr->sh_flags & SHF_ALLOC) |
| 153 | && strcmp(secstrings+sechdrs[i].sh_name, name) == 0) | 165 | && strcmp(info->secstrings + shdr->sh_name, name) == 0) |
| 154 | return i; | 166 | return i; |
| 167 | } | ||
| 155 | return 0; | 168 | return 0; |
| 156 | } | 169 | } |
| 157 | 170 | ||
| 158 | /* Find a module section, or NULL. */ | 171 | /* Find a module section, or NULL. */ |
| 159 | static void *section_addr(Elf_Ehdr *hdr, Elf_Shdr *shdrs, | 172 | static void *section_addr(const struct load_info *info, const char *name) |
| 160 | const char *secstrings, const char *name) | ||
| 161 | { | 173 | { |
| 162 | /* Section 0 has sh_addr 0. */ | 174 | /* Section 0 has sh_addr 0. */ |
| 163 | return (void *)shdrs[find_sec(hdr, shdrs, secstrings, name)].sh_addr; | 175 | return (void *)info->sechdrs[find_sec(info, name)].sh_addr; |
| 164 | } | 176 | } |
| 165 | 177 | ||
| 166 | /* Find a module section, or NULL. Fill in number of "objects" in section. */ | 178 | /* Find a module section, or NULL. Fill in number of "objects" in section. */ |
| 167 | static void *section_objs(Elf_Ehdr *hdr, | 179 | static void *section_objs(const struct load_info *info, |
| 168 | Elf_Shdr *sechdrs, | ||
| 169 | const char *secstrings, | ||
| 170 | const char *name, | 180 | const char *name, |
| 171 | size_t object_size, | 181 | size_t object_size, |
| 172 | unsigned int *num) | 182 | unsigned int *num) |
| 173 | { | 183 | { |
| 174 | unsigned int sec = find_sec(hdr, sechdrs, secstrings, name); | 184 | unsigned int sec = find_sec(info, name); |
| 175 | 185 | ||
| 176 | /* Section 0 has sh_addr 0 and sh_size 0. */ | 186 | /* Section 0 has sh_addr 0 and sh_size 0. */ |
| 177 | *num = sechdrs[sec].sh_size / object_size; | 187 | *num = info->sechdrs[sec].sh_size / object_size; |
| 178 | return (void *)sechdrs[sec].sh_addr; | 188 | return (void *)info->sechdrs[sec].sh_addr; |
| 179 | } | 189 | } |
| 180 | 190 | ||
| 181 | /* Provided by the linker */ | 191 | /* Provided by the linker */ |
| @@ -227,7 +237,7 @@ bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner, | |||
| 227 | unsigned int symnum, void *data), void *data) | 237 | unsigned int symnum, void *data), void *data) |
| 228 | { | 238 | { |
| 229 | struct module *mod; | 239 | struct module *mod; |
| 230 | const struct symsearch arr[] = { | 240 | static const struct symsearch arr[] = { |
| 231 | { __start___ksymtab, __stop___ksymtab, __start___kcrctab, | 241 | { __start___ksymtab, __stop___ksymtab, __start___kcrctab, |
| 232 | NOT_GPL_ONLY, false }, | 242 | NOT_GPL_ONLY, false }, |
| 233 | { __start___ksymtab_gpl, __stop___ksymtab_gpl, | 243 | { __start___ksymtab_gpl, __stop___ksymtab_gpl, |
| @@ -392,7 +402,8 @@ static int percpu_modalloc(struct module *mod, | |||
| 392 | mod->percpu = __alloc_reserved_percpu(size, align); | 402 | mod->percpu = __alloc_reserved_percpu(size, align); |
| 393 | if (!mod->percpu) { | 403 | if (!mod->percpu) { |
| 394 | printk(KERN_WARNING | 404 | printk(KERN_WARNING |
| 395 | "Could not allocate %lu bytes percpu data\n", size); | 405 | "%s: Could not allocate %lu bytes percpu data\n", |
| 406 | mod->name, size); | ||
| 396 | return -ENOMEM; | 407 | return -ENOMEM; |
| 397 | } | 408 | } |
| 398 | mod->percpu_size = size; | 409 | mod->percpu_size = size; |
| @@ -404,11 +415,9 @@ static void percpu_modfree(struct module *mod) | |||
| 404 | free_percpu(mod->percpu); | 415 | free_percpu(mod->percpu); |
| 405 | } | 416 | } |
| 406 | 417 | ||
| 407 | static unsigned int find_pcpusec(Elf_Ehdr *hdr, | 418 | static unsigned int find_pcpusec(struct load_info *info) |
| 408 | Elf_Shdr *sechdrs, | ||
| 409 | const char *secstrings) | ||
| 410 | { | 419 | { |
| 411 | return find_sec(hdr, sechdrs, secstrings, ".data..percpu"); | 420 | return find_sec(info, ".data..percpu"); |
| 412 | } | 421 | } |
| 413 | 422 | ||
| 414 | static void percpu_modcopy(struct module *mod, | 423 | static void percpu_modcopy(struct module *mod, |
| @@ -468,9 +477,7 @@ static inline int percpu_modalloc(struct module *mod, | |||
| 468 | static inline void percpu_modfree(struct module *mod) | 477 | static inline void percpu_modfree(struct module *mod) |
| 469 | { | 478 | { |
| 470 | } | 479 | } |
| 471 | static inline unsigned int find_pcpusec(Elf_Ehdr *hdr, | 480 | static unsigned int find_pcpusec(struct load_info *info) |
| 472 | Elf_Shdr *sechdrs, | ||
| 473 | const char *secstrings) | ||
| 474 | { | 481 | { |
| 475 | return 0; | 482 | return 0; |
| 476 | } | 483 | } |
| @@ -524,21 +531,21 @@ static char last_unloaded_module[MODULE_NAME_LEN+1]; | |||
| 524 | EXPORT_TRACEPOINT_SYMBOL(module_get); | 531 | EXPORT_TRACEPOINT_SYMBOL(module_get); |
| 525 | 532 | ||
| 526 | /* Init the unload section of the module. */ | 533 | /* Init the unload section of the module. */ |
| 527 | static void module_unload_init(struct module *mod) | 534 | static int module_unload_init(struct module *mod) |
| 528 | { | 535 | { |
| 529 | int cpu; | 536 | mod->refptr = alloc_percpu(struct module_ref); |
| 537 | if (!mod->refptr) | ||
| 538 | return -ENOMEM; | ||
| 530 | 539 | ||
| 531 | INIT_LIST_HEAD(&mod->source_list); | 540 | INIT_LIST_HEAD(&mod->source_list); |
| 532 | INIT_LIST_HEAD(&mod->target_list); | 541 | INIT_LIST_HEAD(&mod->target_list); |
| 533 | for_each_possible_cpu(cpu) { | ||
| 534 | per_cpu_ptr(mod->refptr, cpu)->incs = 0; | ||
| 535 | per_cpu_ptr(mod->refptr, cpu)->decs = 0; | ||
| 536 | } | ||
| 537 | 542 | ||
| 538 | /* Hold reference count during initialization. */ | 543 | /* Hold reference count during initialization. */ |
| 539 | __this_cpu_write(mod->refptr->incs, 1); | 544 | __this_cpu_write(mod->refptr->incs, 1); |
| 540 | /* Backwards compatibility macros put refcount during init. */ | 545 | /* Backwards compatibility macros put refcount during init. */ |
| 541 | mod->waiter = current; | 546 | mod->waiter = current; |
| 547 | |||
| 548 | return 0; | ||
| 542 | } | 549 | } |
| 543 | 550 | ||
| 544 | /* Does a already use b? */ | 551 | /* Does a already use b? */ |
| @@ -618,6 +625,8 @@ static void module_unload_free(struct module *mod) | |||
| 618 | kfree(use); | 625 | kfree(use); |
| 619 | } | 626 | } |
| 620 | mutex_unlock(&module_mutex); | 627 | mutex_unlock(&module_mutex); |
| 628 | |||
| 629 | free_percpu(mod->refptr); | ||
| 621 | } | 630 | } |
| 622 | 631 | ||
| 623 | #ifdef CONFIG_MODULE_FORCE_UNLOAD | 632 | #ifdef CONFIG_MODULE_FORCE_UNLOAD |
| @@ -787,7 +796,6 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user, | |||
| 787 | 796 | ||
| 788 | /* Store the name of the last unloaded module for diagnostic purposes */ | 797 | /* Store the name of the last unloaded module for diagnostic purposes */ |
| 789 | strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module)); | 798 | strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module)); |
| 790 | ddebug_remove_module(mod->name); | ||
| 791 | 799 | ||
| 792 | free_module(mod); | 800 | free_module(mod); |
| 793 | return 0; | 801 | return 0; |
| @@ -892,8 +900,9 @@ int ref_module(struct module *a, struct module *b) | |||
| 892 | } | 900 | } |
| 893 | EXPORT_SYMBOL_GPL(ref_module); | 901 | EXPORT_SYMBOL_GPL(ref_module); |
| 894 | 902 | ||
| 895 | static inline void module_unload_init(struct module *mod) | 903 | static inline int module_unload_init(struct module *mod) |
| 896 | { | 904 | { |
| 905 | return 0; | ||
| 897 | } | 906 | } |
| 898 | #endif /* CONFIG_MODULE_UNLOAD */ | 907 | #endif /* CONFIG_MODULE_UNLOAD */ |
| 899 | 908 | ||
| @@ -1052,10 +1061,9 @@ static inline int same_magic(const char *amagic, const char *bmagic, | |||
| 1052 | #endif /* CONFIG_MODVERSIONS */ | 1061 | #endif /* CONFIG_MODVERSIONS */ |
| 1053 | 1062 | ||
| 1054 | /* Resolve a symbol for this module. I.e. if we find one, record usage. */ | 1063 | /* Resolve a symbol for this module. I.e. if we find one, record usage. */ |
| 1055 | static const struct kernel_symbol *resolve_symbol(Elf_Shdr *sechdrs, | 1064 | static const struct kernel_symbol *resolve_symbol(struct module *mod, |
| 1056 | unsigned int versindex, | 1065 | const struct load_info *info, |
| 1057 | const char *name, | 1066 | const char *name, |
| 1058 | struct module *mod, | ||
| 1059 | char ownername[]) | 1067 | char ownername[]) |
| 1060 | { | 1068 | { |
| 1061 | struct module *owner; | 1069 | struct module *owner; |
| @@ -1069,7 +1077,8 @@ static const struct kernel_symbol *resolve_symbol(Elf_Shdr *sechdrs, | |||
| 1069 | if (!sym) | 1077 | if (!sym) |
| 1070 | goto unlock; | 1078 | goto unlock; |
| 1071 | 1079 | ||
| 1072 | if (!check_version(sechdrs, versindex, name, mod, crc, owner)) { | 1080 | if (!check_version(info->sechdrs, info->index.vers, name, mod, crc, |
| 1081 | owner)) { | ||
| 1073 | sym = ERR_PTR(-EINVAL); | 1082 | sym = ERR_PTR(-EINVAL); |
| 1074 | goto getname; | 1083 | goto getname; |
| 1075 | } | 1084 | } |
| @@ -1088,21 +1097,20 @@ unlock: | |||
| 1088 | return sym; | 1097 | return sym; |
| 1089 | } | 1098 | } |
| 1090 | 1099 | ||
| 1091 | static const struct kernel_symbol *resolve_symbol_wait(Elf_Shdr *sechdrs, | 1100 | static const struct kernel_symbol * |
| 1092 | unsigned int versindex, | 1101 | resolve_symbol_wait(struct module *mod, |
| 1093 | const char *name, | 1102 | const struct load_info *info, |
| 1094 | struct module *mod) | 1103 | const char *name) |
| 1095 | { | 1104 | { |
| 1096 | const struct kernel_symbol *ksym; | 1105 | const struct kernel_symbol *ksym; |
| 1097 | char ownername[MODULE_NAME_LEN]; | 1106 | char owner[MODULE_NAME_LEN]; |
| 1098 | 1107 | ||
| 1099 | if (wait_event_interruptible_timeout(module_wq, | 1108 | if (wait_event_interruptible_timeout(module_wq, |
| 1100 | !IS_ERR(ksym = resolve_symbol(sechdrs, versindex, name, | 1109 | !IS_ERR(ksym = resolve_symbol(mod, info, name, owner)) |
| 1101 | mod, ownername)) || | 1110 | || PTR_ERR(ksym) != -EBUSY, |
| 1102 | PTR_ERR(ksym) != -EBUSY, | ||
| 1103 | 30 * HZ) <= 0) { | 1111 | 30 * HZ) <= 0) { |
| 1104 | printk(KERN_WARNING "%s: gave up waiting for init of module %s.\n", | 1112 | printk(KERN_WARNING "%s: gave up waiting for init of module %s.\n", |
| 1105 | mod->name, ownername); | 1113 | mod->name, owner); |
| 1106 | } | 1114 | } |
| 1107 | return ksym; | 1115 | return ksym; |
| 1108 | } | 1116 | } |
| @@ -1111,8 +1119,9 @@ static const struct kernel_symbol *resolve_symbol_wait(Elf_Shdr *sechdrs, | |||
| 1111 | * /sys/module/foo/sections stuff | 1119 | * /sys/module/foo/sections stuff |
| 1112 | * J. Corbet <corbet@lwn.net> | 1120 | * J. Corbet <corbet@lwn.net> |
| 1113 | */ | 1121 | */ |
| 1114 | #if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS) | 1122 | #ifdef CONFIG_SYSFS |
| 1115 | 1123 | ||
| 1124 | #ifdef CONFIG_KALLSYMS | ||
| 1116 | static inline bool sect_empty(const Elf_Shdr *sect) | 1125 | static inline bool sect_empty(const Elf_Shdr *sect) |
| 1117 | { | 1126 | { |
| 1118 | return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0; | 1127 | return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0; |
| @@ -1149,8 +1158,7 @@ static void free_sect_attrs(struct module_sect_attrs *sect_attrs) | |||
| 1149 | kfree(sect_attrs); | 1158 | kfree(sect_attrs); |
| 1150 | } | 1159 | } |
| 1151 | 1160 | ||
| 1152 | static void add_sect_attrs(struct module *mod, unsigned int nsect, | 1161 | static void add_sect_attrs(struct module *mod, const struct load_info *info) |
| 1153 | char *secstrings, Elf_Shdr *sechdrs) | ||
| 1154 | { | 1162 | { |
| 1155 | unsigned int nloaded = 0, i, size[2]; | 1163 | unsigned int nloaded = 0, i, size[2]; |
| 1156 | struct module_sect_attrs *sect_attrs; | 1164 | struct module_sect_attrs *sect_attrs; |
| @@ -1158,8 +1166,8 @@ static void add_sect_attrs(struct module *mod, unsigned int nsect, | |||
| 1158 | struct attribute **gattr; | 1166 | struct attribute **gattr; |
| 1159 | 1167 | ||
| 1160 | /* Count loaded sections and allocate structures */ | 1168 | /* Count loaded sections and allocate structures */ |
| 1161 | for (i = 0; i < nsect; i++) | 1169 | for (i = 0; i < info->hdr->e_shnum; i++) |
| 1162 | if (!sect_empty(&sechdrs[i])) | 1170 | if (!sect_empty(&info->sechdrs[i])) |
| 1163 | nloaded++; | 1171 | nloaded++; |
| 1164 | size[0] = ALIGN(sizeof(*sect_attrs) | 1172 | size[0] = ALIGN(sizeof(*sect_attrs) |
| 1165 | + nloaded * sizeof(sect_attrs->attrs[0]), | 1173 | + nloaded * sizeof(sect_attrs->attrs[0]), |
| @@ -1176,11 +1184,12 @@ static void add_sect_attrs(struct module *mod, unsigned int nsect, | |||
| 1176 | sect_attrs->nsections = 0; | 1184 | sect_attrs->nsections = 0; |
| 1177 | sattr = §_attrs->attrs[0]; | 1185 | sattr = §_attrs->attrs[0]; |
| 1178 | gattr = §_attrs->grp.attrs[0]; | 1186 | gattr = §_attrs->grp.attrs[0]; |
| 1179 | for (i = 0; i < nsect; i++) { | 1187 | for (i = 0; i < info->hdr->e_shnum; i++) { |
| 1180 | if (sect_empty(&sechdrs[i])) | 1188 | Elf_Shdr *sec = &info->sechdrs[i]; |
| 1189 | if (sect_empty(sec)) | ||
| 1181 | continue; | 1190 | continue; |
| 1182 | sattr->address = sechdrs[i].sh_addr; | 1191 | sattr->address = sec->sh_addr; |
| 1183 | sattr->name = kstrdup(secstrings + sechdrs[i].sh_name, | 1192 | sattr->name = kstrdup(info->secstrings + sec->sh_name, |
| 1184 | GFP_KERNEL); | 1193 | GFP_KERNEL); |
| 1185 | if (sattr->name == NULL) | 1194 | if (sattr->name == NULL) |
| 1186 | goto out; | 1195 | goto out; |
| @@ -1248,8 +1257,7 @@ static void free_notes_attrs(struct module_notes_attrs *notes_attrs, | |||
| 1248 | kfree(notes_attrs); | 1257 | kfree(notes_attrs); |
| 1249 | } | 1258 | } |
| 1250 | 1259 | ||
| 1251 | static void add_notes_attrs(struct module *mod, unsigned int nsect, | 1260 | static void add_notes_attrs(struct module *mod, const struct load_info *info) |
| 1252 | char *secstrings, Elf_Shdr *sechdrs) | ||
| 1253 | { | 1261 | { |
| 1254 | unsigned int notes, loaded, i; | 1262 | unsigned int notes, loaded, i; |
| 1255 | struct module_notes_attrs *notes_attrs; | 1263 | struct module_notes_attrs *notes_attrs; |
| @@ -1261,9 +1269,9 @@ static void add_notes_attrs(struct module *mod, unsigned int nsect, | |||
| 1261 | 1269 | ||
| 1262 | /* Count notes sections and allocate structures. */ | 1270 | /* Count notes sections and allocate structures. */ |
| 1263 | notes = 0; | 1271 | notes = 0; |
| 1264 | for (i = 0; i < nsect; i++) | 1272 | for (i = 0; i < info->hdr->e_shnum; i++) |
| 1265 | if (!sect_empty(&sechdrs[i]) && | 1273 | if (!sect_empty(&info->sechdrs[i]) && |
| 1266 | (sechdrs[i].sh_type == SHT_NOTE)) | 1274 | (info->sechdrs[i].sh_type == SHT_NOTE)) |
| 1267 | ++notes; | 1275 | ++notes; |
| 1268 | 1276 | ||
| 1269 | if (notes == 0) | 1277 | if (notes == 0) |
| @@ -1277,15 +1285,15 @@ static void add_notes_attrs(struct module *mod, unsigned int nsect, | |||
| 1277 | 1285 | ||
| 1278 | notes_attrs->notes = notes; | 1286 | notes_attrs->notes = notes; |
| 1279 | nattr = ¬es_attrs->attrs[0]; | 1287 | nattr = ¬es_attrs->attrs[0]; |
| 1280 | for (loaded = i = 0; i < nsect; ++i) { | 1288 | for (loaded = i = 0; i < info->hdr->e_shnum; ++i) { |
| 1281 | if (sect_empty(&sechdrs[i])) | 1289 | if (sect_empty(&info->sechdrs[i])) |
| 1282 | continue; | 1290 | continue; |
| 1283 | if (sechdrs[i].sh_type == SHT_NOTE) { | 1291 | if (info->sechdrs[i].sh_type == SHT_NOTE) { |
| 1284 | sysfs_bin_attr_init(nattr); | 1292 | sysfs_bin_attr_init(nattr); |
| 1285 | nattr->attr.name = mod->sect_attrs->attrs[loaded].name; | 1293 | nattr->attr.name = mod->sect_attrs->attrs[loaded].name; |
| 1286 | nattr->attr.mode = S_IRUGO; | 1294 | nattr->attr.mode = S_IRUGO; |
| 1287 | nattr->size = sechdrs[i].sh_size; | 1295 | nattr->size = info->sechdrs[i].sh_size; |
| 1288 | nattr->private = (void *) sechdrs[i].sh_addr; | 1296 | nattr->private = (void *) info->sechdrs[i].sh_addr; |
| 1289 | nattr->read = module_notes_read; | 1297 | nattr->read = module_notes_read; |
| 1290 | ++nattr; | 1298 | ++nattr; |
| 1291 | } | 1299 | } |
| @@ -1316,8 +1324,8 @@ static void remove_notes_attrs(struct module *mod) | |||
| 1316 | 1324 | ||
| 1317 | #else | 1325 | #else |
| 1318 | 1326 | ||
| 1319 | static inline void add_sect_attrs(struct module *mod, unsigned int nsect, | 1327 | static inline void add_sect_attrs(struct module *mod, |
| 1320 | char *sectstrings, Elf_Shdr *sechdrs) | 1328 | const struct load_info *info) |
| 1321 | { | 1329 | { |
| 1322 | } | 1330 | } |
| 1323 | 1331 | ||
| @@ -1325,17 +1333,16 @@ static inline void remove_sect_attrs(struct module *mod) | |||
| 1325 | { | 1333 | { |
| 1326 | } | 1334 | } |
| 1327 | 1335 | ||
| 1328 | static inline void add_notes_attrs(struct module *mod, unsigned int nsect, | 1336 | static inline void add_notes_attrs(struct module *mod, |
| 1329 | char *sectstrings, Elf_Shdr *sechdrs) | 1337 | const struct load_info *info) |
| 1330 | { | 1338 | { |
| 1331 | } | 1339 | } |
| 1332 | 1340 | ||
| 1333 | static inline void remove_notes_attrs(struct module *mod) | 1341 | static inline void remove_notes_attrs(struct module *mod) |
| 1334 | { | 1342 | { |
| 1335 | } | 1343 | } |
| 1336 | #endif | 1344 | #endif /* CONFIG_KALLSYMS */ |
| 1337 | 1345 | ||
| 1338 | #ifdef CONFIG_SYSFS | ||
| 1339 | static void add_usage_links(struct module *mod) | 1346 | static void add_usage_links(struct module *mod) |
| 1340 | { | 1347 | { |
| 1341 | #ifdef CONFIG_MODULE_UNLOAD | 1348 | #ifdef CONFIG_MODULE_UNLOAD |
| @@ -1440,6 +1447,7 @@ out: | |||
| 1440 | } | 1447 | } |
| 1441 | 1448 | ||
| 1442 | static int mod_sysfs_setup(struct module *mod, | 1449 | static int mod_sysfs_setup(struct module *mod, |
| 1450 | const struct load_info *info, | ||
| 1443 | struct kernel_param *kparam, | 1451 | struct kernel_param *kparam, |
| 1444 | unsigned int num_params) | 1452 | unsigned int num_params) |
| 1445 | { | 1453 | { |
| @@ -1464,6 +1472,8 @@ static int mod_sysfs_setup(struct module *mod, | |||
| 1464 | goto out_unreg_param; | 1472 | goto out_unreg_param; |
| 1465 | 1473 | ||
| 1466 | add_usage_links(mod); | 1474 | add_usage_links(mod); |
| 1475 | add_sect_attrs(mod, info); | ||
| 1476 | add_notes_attrs(mod, info); | ||
| 1467 | 1477 | ||
| 1468 | kobject_uevent(&mod->mkobj.kobj, KOBJ_ADD); | 1478 | kobject_uevent(&mod->mkobj.kobj, KOBJ_ADD); |
| 1469 | return 0; | 1479 | return 0; |
| @@ -1480,33 +1490,26 @@ out: | |||
| 1480 | 1490 | ||
| 1481 | static void mod_sysfs_fini(struct module *mod) | 1491 | static void mod_sysfs_fini(struct module *mod) |
| 1482 | { | 1492 | { |
| 1493 | remove_notes_attrs(mod); | ||
| 1494 | remove_sect_attrs(mod); | ||
| 1483 | kobject_put(&mod->mkobj.kobj); | 1495 | kobject_put(&mod->mkobj.kobj); |
| 1484 | } | 1496 | } |
| 1485 | 1497 | ||
| 1486 | #else /* CONFIG_SYSFS */ | 1498 | #else /* !CONFIG_SYSFS */ |
| 1487 | |||
| 1488 | static inline int mod_sysfs_init(struct module *mod) | ||
| 1489 | { | ||
| 1490 | return 0; | ||
| 1491 | } | ||
| 1492 | 1499 | ||
| 1493 | static inline int mod_sysfs_setup(struct module *mod, | 1500 | static int mod_sysfs_setup(struct module *mod, |
| 1501 | const struct load_info *info, | ||
| 1494 | struct kernel_param *kparam, | 1502 | struct kernel_param *kparam, |
| 1495 | unsigned int num_params) | 1503 | unsigned int num_params) |
| 1496 | { | 1504 | { |
| 1497 | return 0; | 1505 | return 0; |
| 1498 | } | 1506 | } |
| 1499 | 1507 | ||
| 1500 | static inline int module_add_modinfo_attrs(struct module *mod) | 1508 | static void mod_sysfs_fini(struct module *mod) |
| 1501 | { | ||
| 1502 | return 0; | ||
| 1503 | } | ||
| 1504 | |||
| 1505 | static inline void module_remove_modinfo_attrs(struct module *mod) | ||
| 1506 | { | 1509 | { |
| 1507 | } | 1510 | } |
| 1508 | 1511 | ||
| 1509 | static void mod_sysfs_fini(struct module *mod) | 1512 | static void module_remove_modinfo_attrs(struct module *mod) |
| 1510 | { | 1513 | { |
| 1511 | } | 1514 | } |
| 1512 | 1515 | ||
| @@ -1516,7 +1519,7 @@ static void del_usage_links(struct module *mod) | |||
| 1516 | 1519 | ||
| 1517 | #endif /* CONFIG_SYSFS */ | 1520 | #endif /* CONFIG_SYSFS */ |
| 1518 | 1521 | ||
| 1519 | static void mod_kobject_remove(struct module *mod) | 1522 | static void mod_sysfs_teardown(struct module *mod) |
| 1520 | { | 1523 | { |
| 1521 | del_usage_links(mod); | 1524 | del_usage_links(mod); |
| 1522 | module_remove_modinfo_attrs(mod); | 1525 | module_remove_modinfo_attrs(mod); |
| @@ -1546,9 +1549,10 @@ static void free_module(struct module *mod) | |||
| 1546 | mutex_lock(&module_mutex); | 1549 | mutex_lock(&module_mutex); |
| 1547 | stop_machine(__unlink_module, mod, NULL); | 1550 | stop_machine(__unlink_module, mod, NULL); |
| 1548 | mutex_unlock(&module_mutex); | 1551 | mutex_unlock(&module_mutex); |
| 1549 | remove_notes_attrs(mod); | 1552 | mod_sysfs_teardown(mod); |
| 1550 | remove_sect_attrs(mod); | 1553 | |
| 1551 | mod_kobject_remove(mod); | 1554 | /* Remove dynamic debug info */ |
| 1555 | ddebug_remove_module(mod->name); | ||
| 1552 | 1556 | ||
| 1553 | /* Arch-specific cleanup. */ | 1557 | /* Arch-specific cleanup. */ |
| 1554 | module_arch_cleanup(mod); | 1558 | module_arch_cleanup(mod); |
| @@ -1563,10 +1567,7 @@ static void free_module(struct module *mod) | |||
| 1563 | module_free(mod, mod->module_init); | 1567 | module_free(mod, mod->module_init); |
| 1564 | kfree(mod->args); | 1568 | kfree(mod->args); |
| 1565 | percpu_modfree(mod); | 1569 | percpu_modfree(mod); |
| 1566 | #if defined(CONFIG_MODULE_UNLOAD) | 1570 | |
| 1567 | if (mod->refptr) | ||
| 1568 | free_percpu(mod->refptr); | ||
| 1569 | #endif | ||
| 1570 | /* Free lock-classes: */ | 1571 | /* Free lock-classes: */ |
| 1571 | lockdep_free_key_range(mod->module_core, mod->core_size); | 1572 | lockdep_free_key_range(mod->module_core, mod->core_size); |
| 1572 | 1573 | ||
| @@ -1632,25 +1633,23 @@ static int verify_export_symbols(struct module *mod) | |||
| 1632 | } | 1633 | } |
| 1633 | 1634 | ||
| 1634 | /* Change all symbols so that st_value encodes the pointer directly. */ | 1635 | /* Change all symbols so that st_value encodes the pointer directly. */ |
| 1635 | static int simplify_symbols(Elf_Shdr *sechdrs, | 1636 | static int simplify_symbols(struct module *mod, const struct load_info *info) |
| 1636 | unsigned int symindex, | 1637 | { |
| 1637 | const char *strtab, | 1638 | Elf_Shdr *symsec = &info->sechdrs[info->index.sym]; |
| 1638 | unsigned int versindex, | 1639 | Elf_Sym *sym = (void *)symsec->sh_addr; |
| 1639 | unsigned int pcpuindex, | ||
| 1640 | struct module *mod) | ||
| 1641 | { | ||
| 1642 | Elf_Sym *sym = (void *)sechdrs[symindex].sh_addr; | ||
| 1643 | unsigned long secbase; | 1640 | unsigned long secbase; |
| 1644 | unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym); | 1641 | unsigned int i; |
| 1645 | int ret = 0; | 1642 | int ret = 0; |
| 1646 | const struct kernel_symbol *ksym; | 1643 | const struct kernel_symbol *ksym; |
| 1647 | 1644 | ||
| 1648 | for (i = 1; i < n; i++) { | 1645 | for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) { |
| 1646 | const char *name = info->strtab + sym[i].st_name; | ||
| 1647 | |||
| 1649 | switch (sym[i].st_shndx) { | 1648 | switch (sym[i].st_shndx) { |
| 1650 | case SHN_COMMON: | 1649 | case SHN_COMMON: |
| 1651 | /* We compiled with -fno-common. These are not | 1650 | /* We compiled with -fno-common. These are not |
| 1652 | supposed to happen. */ | 1651 | supposed to happen. */ |
| 1653 | DEBUGP("Common symbol: %s\n", strtab + sym[i].st_name); | 1652 | DEBUGP("Common symbol: %s\n", name); |
| 1654 | printk("%s: please compile with -fno-common\n", | 1653 | printk("%s: please compile with -fno-common\n", |
| 1655 | mod->name); | 1654 | mod->name); |
| 1656 | ret = -ENOEXEC; | 1655 | ret = -ENOEXEC; |
| @@ -1663,9 +1662,7 @@ static int simplify_symbols(Elf_Shdr *sechdrs, | |||
| 1663 | break; | 1662 | break; |
| 1664 | 1663 | ||
| 1665 | case SHN_UNDEF: | 1664 | case SHN_UNDEF: |
| 1666 | ksym = resolve_symbol_wait(sechdrs, versindex, | 1665 | ksym = resolve_symbol_wait(mod, info, name); |
| 1667 | strtab + sym[i].st_name, | ||
| 1668 | mod); | ||
| 1669 | /* Ok if resolved. */ | 1666 | /* Ok if resolved. */ |
| 1670 | if (ksym && !IS_ERR(ksym)) { | 1667 | if (ksym && !IS_ERR(ksym)) { |
| 1671 | sym[i].st_value = ksym->value; | 1668 | sym[i].st_value = ksym->value; |
| @@ -1677,17 +1674,16 @@ static int simplify_symbols(Elf_Shdr *sechdrs, | |||
| 1677 | break; | 1674 | break; |
| 1678 | 1675 | ||
| 1679 | printk(KERN_WARNING "%s: Unknown symbol %s (err %li)\n", | 1676 | printk(KERN_WARNING "%s: Unknown symbol %s (err %li)\n", |
| 1680 | mod->name, strtab + sym[i].st_name, | 1677 | mod->name, name, PTR_ERR(ksym)); |
| 1681 | PTR_ERR(ksym)); | ||
| 1682 | ret = PTR_ERR(ksym) ?: -ENOENT; | 1678 | ret = PTR_ERR(ksym) ?: -ENOENT; |
| 1683 | break; | 1679 | break; |
| 1684 | 1680 | ||
| 1685 | default: | 1681 | default: |
| 1686 | /* Divert to percpu allocation if a percpu var. */ | 1682 | /* Divert to percpu allocation if a percpu var. */ |
| 1687 | if (sym[i].st_shndx == pcpuindex) | 1683 | if (sym[i].st_shndx == info->index.pcpu) |
| 1688 | secbase = (unsigned long)mod_percpu(mod); | 1684 | secbase = (unsigned long)mod_percpu(mod); |
| 1689 | else | 1685 | else |
| 1690 | secbase = sechdrs[sym[i].st_shndx].sh_addr; | 1686 | secbase = info->sechdrs[sym[i].st_shndx].sh_addr; |
| 1691 | sym[i].st_value += secbase; | 1687 | sym[i].st_value += secbase; |
| 1692 | break; | 1688 | break; |
| 1693 | } | 1689 | } |
| @@ -1696,6 +1692,35 @@ static int simplify_symbols(Elf_Shdr *sechdrs, | |||
| 1696 | return ret; | 1692 | return ret; |
| 1697 | } | 1693 | } |
| 1698 | 1694 | ||
| 1695 | static int apply_relocations(struct module *mod, const struct load_info *info) | ||
| 1696 | { | ||
| 1697 | unsigned int i; | ||
| 1698 | int err = 0; | ||
| 1699 | |||
| 1700 | /* Now do relocations. */ | ||
| 1701 | for (i = 1; i < info->hdr->e_shnum; i++) { | ||
| 1702 | unsigned int infosec = info->sechdrs[i].sh_info; | ||
| 1703 | |||
| 1704 | /* Not a valid relocation section? */ | ||
| 1705 | if (infosec >= info->hdr->e_shnum) | ||
| 1706 | continue; | ||
| 1707 | |||
| 1708 | /* Don't bother with non-allocated sections */ | ||
| 1709 | if (!(info->sechdrs[infosec].sh_flags & SHF_ALLOC)) | ||
| 1710 | continue; | ||
| 1711 | |||
| 1712 | if (info->sechdrs[i].sh_type == SHT_REL) | ||
| 1713 | err = apply_relocate(info->sechdrs, info->strtab, | ||
| 1714 | info->index.sym, i, mod); | ||
| 1715 | else if (info->sechdrs[i].sh_type == SHT_RELA) | ||
| 1716 | err = apply_relocate_add(info->sechdrs, info->strtab, | ||
| 1717 | info->index.sym, i, mod); | ||
| 1718 | if (err < 0) | ||
| 1719 | break; | ||
| 1720 | } | ||
| 1721 | return err; | ||
| 1722 | } | ||
| 1723 | |||
| 1699 | /* Additional bytes needed by arch in front of individual sections */ | 1724 | /* Additional bytes needed by arch in front of individual sections */ |
| 1700 | unsigned int __weak arch_mod_section_prepend(struct module *mod, | 1725 | unsigned int __weak arch_mod_section_prepend(struct module *mod, |
| 1701 | unsigned int section) | 1726 | unsigned int section) |
| @@ -1720,10 +1745,7 @@ static long get_offset(struct module *mod, unsigned int *size, | |||
| 1720 | might -- code, read-only data, read-write data, small data. Tally | 1745 | might -- code, read-only data, read-write data, small data. Tally |
| 1721 | sizes, and place the offsets into sh_entsize fields: high bit means it | 1746 | sizes, and place the offsets into sh_entsize fields: high bit means it |
| 1722 | belongs in init. */ | 1747 | belongs in init. */ |
| 1723 | static void layout_sections(struct module *mod, | 1748 | static void layout_sections(struct module *mod, struct load_info *info) |
| 1724 | const Elf_Ehdr *hdr, | ||
| 1725 | Elf_Shdr *sechdrs, | ||
| 1726 | const char *secstrings) | ||
| 1727 | { | 1749 | { |
| 1728 | static unsigned long const masks[][2] = { | 1750 | static unsigned long const masks[][2] = { |
| 1729 | /* NOTE: all executable code must be the first section | 1751 | /* NOTE: all executable code must be the first section |
| @@ -1736,21 +1758,22 @@ static void layout_sections(struct module *mod, | |||
| 1736 | }; | 1758 | }; |
| 1737 | unsigned int m, i; | 1759 | unsigned int m, i; |
| 1738 | 1760 | ||
| 1739 | for (i = 0; i < hdr->e_shnum; i++) | 1761 | for (i = 0; i < info->hdr->e_shnum; i++) |
| 1740 | sechdrs[i].sh_entsize = ~0UL; | 1762 | info->sechdrs[i].sh_entsize = ~0UL; |
| 1741 | 1763 | ||
| 1742 | DEBUGP("Core section allocation order:\n"); | 1764 | DEBUGP("Core section allocation order:\n"); |
| 1743 | for (m = 0; m < ARRAY_SIZE(masks); ++m) { | 1765 | for (m = 0; m < ARRAY_SIZE(masks); ++m) { |
| 1744 | for (i = 0; i < hdr->e_shnum; ++i) { | 1766 | for (i = 0; i < info->hdr->e_shnum; ++i) { |
| 1745 | Elf_Shdr *s = &sechdrs[i]; | 1767 | Elf_Shdr *s = &info->sechdrs[i]; |
| 1768 | const char *sname = info->secstrings + s->sh_name; | ||
| 1746 | 1769 | ||
| 1747 | if ((s->sh_flags & masks[m][0]) != masks[m][0] | 1770 | if ((s->sh_flags & masks[m][0]) != masks[m][0] |
| 1748 | || (s->sh_flags & masks[m][1]) | 1771 | || (s->sh_flags & masks[m][1]) |
| 1749 | || s->sh_entsize != ~0UL | 1772 | || s->sh_entsize != ~0UL |
| 1750 | || strstarts(secstrings + s->sh_name, ".init")) | 1773 | || strstarts(sname, ".init")) |
| 1751 | continue; | 1774 | continue; |
| 1752 | s->sh_entsize = get_offset(mod, &mod->core_size, s, i); | 1775 | s->sh_entsize = get_offset(mod, &mod->core_size, s, i); |
| 1753 | DEBUGP("\t%s\n", secstrings + s->sh_name); | 1776 | DEBUGP("\t%s\n", name); |
| 1754 | } | 1777 | } |
| 1755 | if (m == 0) | 1778 | if (m == 0) |
| 1756 | mod->core_text_size = mod->core_size; | 1779 | mod->core_text_size = mod->core_size; |
| @@ -1758,17 +1781,18 @@ static void layout_sections(struct module *mod, | |||
| 1758 | 1781 | ||
| 1759 | DEBUGP("Init section allocation order:\n"); | 1782 | DEBUGP("Init section allocation order:\n"); |
| 1760 | for (m = 0; m < ARRAY_SIZE(masks); ++m) { | 1783 | for (m = 0; m < ARRAY_SIZE(masks); ++m) { |
| 1761 | for (i = 0; i < hdr->e_shnum; ++i) { | 1784 | for (i = 0; i < info->hdr->e_shnum; ++i) { |
| 1762 | Elf_Shdr *s = &sechdrs[i]; | 1785 | Elf_Shdr *s = &info->sechdrs[i]; |
| 1786 | const char *sname = info->secstrings + s->sh_name; | ||
| 1763 | 1787 | ||
| 1764 | if ((s->sh_flags & masks[m][0]) != masks[m][0] | 1788 | if ((s->sh_flags & masks[m][0]) != masks[m][0] |
| 1765 | || (s->sh_flags & masks[m][1]) | 1789 | || (s->sh_flags & masks[m][1]) |
| 1766 | || s->sh_entsize != ~0UL | 1790 | || s->sh_entsize != ~0UL |
| 1767 | || !strstarts(secstrings + s->sh_name, ".init")) | 1791 | || !strstarts(sname, ".init")) |
| 1768 | continue; | 1792 | continue; |
| 1769 | s->sh_entsize = (get_offset(mod, &mod->init_size, s, i) | 1793 | s->sh_entsize = (get_offset(mod, &mod->init_size, s, i) |
| 1770 | | INIT_OFFSET_MASK); | 1794 | | INIT_OFFSET_MASK); |
| 1771 | DEBUGP("\t%s\n", secstrings + s->sh_name); | 1795 | DEBUGP("\t%s\n", sname); |
| 1772 | } | 1796 | } |
| 1773 | if (m == 0) | 1797 | if (m == 0) |
| 1774 | mod->init_text_size = mod->init_size; | 1798 | mod->init_text_size = mod->init_size; |
| @@ -1807,33 +1831,28 @@ static char *next_string(char *string, unsigned long *secsize) | |||
| 1807 | return string; | 1831 | return string; |
| 1808 | } | 1832 | } |
| 1809 | 1833 | ||
| 1810 | static char *get_modinfo(Elf_Shdr *sechdrs, | 1834 | static char *get_modinfo(struct load_info *info, const char *tag) |
| 1811 | unsigned int info, | ||
| 1812 | const char *tag) | ||
| 1813 | { | 1835 | { |
| 1814 | char *p; | 1836 | char *p; |
| 1815 | unsigned int taglen = strlen(tag); | 1837 | unsigned int taglen = strlen(tag); |
| 1816 | unsigned long size = sechdrs[info].sh_size; | 1838 | Elf_Shdr *infosec = &info->sechdrs[info->index.info]; |
| 1839 | unsigned long size = infosec->sh_size; | ||
| 1817 | 1840 | ||
| 1818 | for (p = (char *)sechdrs[info].sh_addr; p; p = next_string(p, &size)) { | 1841 | for (p = (char *)infosec->sh_addr; p; p = next_string(p, &size)) { |
| 1819 | if (strncmp(p, tag, taglen) == 0 && p[taglen] == '=') | 1842 | if (strncmp(p, tag, taglen) == 0 && p[taglen] == '=') |
| 1820 | return p + taglen + 1; | 1843 | return p + taglen + 1; |
| 1821 | } | 1844 | } |
| 1822 | return NULL; | 1845 | return NULL; |
| 1823 | } | 1846 | } |
| 1824 | 1847 | ||
| 1825 | static void setup_modinfo(struct module *mod, Elf_Shdr *sechdrs, | 1848 | static void setup_modinfo(struct module *mod, struct load_info *info) |
| 1826 | unsigned int infoindex) | ||
| 1827 | { | 1849 | { |
| 1828 | struct module_attribute *attr; | 1850 | struct module_attribute *attr; |
| 1829 | int i; | 1851 | int i; |
| 1830 | 1852 | ||
| 1831 | for (i = 0; (attr = modinfo_attrs[i]); i++) { | 1853 | for (i = 0; (attr = modinfo_attrs[i]); i++) { |
| 1832 | if (attr->setup) | 1854 | if (attr->setup) |
| 1833 | attr->setup(mod, | 1855 | attr->setup(mod, get_modinfo(info, attr->attr.name)); |
| 1834 | get_modinfo(sechdrs, | ||
| 1835 | infoindex, | ||
| 1836 | attr->attr.name)); | ||
| 1837 | } | 1856 | } |
| 1838 | } | 1857 | } |
| 1839 | 1858 | ||
| @@ -1874,11 +1893,10 @@ static int is_exported(const char *name, unsigned long value, | |||
| 1874 | } | 1893 | } |
| 1875 | 1894 | ||
| 1876 | /* As per nm */ | 1895 | /* As per nm */ |
| 1877 | static char elf_type(const Elf_Sym *sym, | 1896 | static char elf_type(const Elf_Sym *sym, const struct load_info *info) |
| 1878 | Elf_Shdr *sechdrs, | ||
| 1879 | const char *secstrings, | ||
| 1880 | struct module *mod) | ||
| 1881 | { | 1897 | { |
| 1898 | const Elf_Shdr *sechdrs = info->sechdrs; | ||
| 1899 | |||
| 1882 | if (ELF_ST_BIND(sym->st_info) == STB_WEAK) { | 1900 | if (ELF_ST_BIND(sym->st_info) == STB_WEAK) { |
| 1883 | if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT) | 1901 | if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT) |
| 1884 | return 'v'; | 1902 | return 'v'; |
| @@ -1908,8 +1926,10 @@ static char elf_type(const Elf_Sym *sym, | |||
| 1908 | else | 1926 | else |
| 1909 | return 'b'; | 1927 | return 'b'; |
| 1910 | } | 1928 | } |
| 1911 | if (strstarts(secstrings + sechdrs[sym->st_shndx].sh_name, ".debug")) | 1929 | if (strstarts(info->secstrings + sechdrs[sym->st_shndx].sh_name, |
| 1930 | ".debug")) { | ||
| 1912 | return 'n'; | 1931 | return 'n'; |
| 1932 | } | ||
| 1913 | return '?'; | 1933 | return '?'; |
| 1914 | } | 1934 | } |
| 1915 | 1935 | ||
| @@ -1934,127 +1954,96 @@ static bool is_core_symbol(const Elf_Sym *src, const Elf_Shdr *sechdrs, | |||
| 1934 | return true; | 1954 | return true; |
| 1935 | } | 1955 | } |
| 1936 | 1956 | ||
| 1937 | static unsigned long layout_symtab(struct module *mod, | 1957 | static void layout_symtab(struct module *mod, struct load_info *info) |
| 1938 | Elf_Shdr *sechdrs, | ||
| 1939 | unsigned int symindex, | ||
| 1940 | unsigned int strindex, | ||
| 1941 | const Elf_Ehdr *hdr, | ||
| 1942 | const char *secstrings, | ||
| 1943 | unsigned long *pstroffs, | ||
| 1944 | unsigned long *strmap) | ||
| 1945 | { | 1958 | { |
| 1946 | unsigned long symoffs; | 1959 | Elf_Shdr *symsect = info->sechdrs + info->index.sym; |
| 1947 | Elf_Shdr *symsect = sechdrs + symindex; | 1960 | Elf_Shdr *strsect = info->sechdrs + info->index.str; |
| 1948 | Elf_Shdr *strsect = sechdrs + strindex; | ||
| 1949 | const Elf_Sym *src; | 1961 | const Elf_Sym *src; |
| 1950 | const char *strtab; | ||
| 1951 | unsigned int i, nsrc, ndst; | 1962 | unsigned int i, nsrc, ndst; |
| 1952 | 1963 | ||
| 1953 | /* Put symbol section at end of init part of module. */ | 1964 | /* Put symbol section at end of init part of module. */ |
| 1954 | symsect->sh_flags |= SHF_ALLOC; | 1965 | symsect->sh_flags |= SHF_ALLOC; |
| 1955 | symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect, | 1966 | symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect, |
| 1956 | symindex) | INIT_OFFSET_MASK; | 1967 | info->index.sym) | INIT_OFFSET_MASK; |
| 1957 | DEBUGP("\t%s\n", secstrings + symsect->sh_name); | 1968 | DEBUGP("\t%s\n", info->secstrings + symsect->sh_name); |
| 1958 | 1969 | ||
| 1959 | src = (void *)hdr + symsect->sh_offset; | 1970 | src = (void *)info->hdr + symsect->sh_offset; |
| 1960 | nsrc = symsect->sh_size / sizeof(*src); | 1971 | nsrc = symsect->sh_size / sizeof(*src); |
| 1961 | strtab = (void *)hdr + strsect->sh_offset; | ||
| 1962 | for (ndst = i = 1; i < nsrc; ++i, ++src) | 1972 | for (ndst = i = 1; i < nsrc; ++i, ++src) |
| 1963 | if (is_core_symbol(src, sechdrs, hdr->e_shnum)) { | 1973 | if (is_core_symbol(src, info->sechdrs, info->hdr->e_shnum)) { |
| 1964 | unsigned int j = src->st_name; | 1974 | unsigned int j = src->st_name; |
| 1965 | 1975 | ||
| 1966 | while(!__test_and_set_bit(j, strmap) && strtab[j]) | 1976 | while (!__test_and_set_bit(j, info->strmap) |
| 1977 | && info->strtab[j]) | ||
| 1967 | ++j; | 1978 | ++j; |
| 1968 | ++ndst; | 1979 | ++ndst; |
| 1969 | } | 1980 | } |
| 1970 | 1981 | ||
| 1971 | /* Append room for core symbols at end of core part. */ | 1982 | /* Append room for core symbols at end of core part. */ |
| 1972 | symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1); | 1983 | info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1); |
| 1973 | mod->core_size = symoffs + ndst * sizeof(Elf_Sym); | 1984 | mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym); |
| 1974 | 1985 | ||
| 1975 | /* Put string table section at end of init part of module. */ | 1986 | /* Put string table section at end of init part of module. */ |
| 1976 | strsect->sh_flags |= SHF_ALLOC; | 1987 | strsect->sh_flags |= SHF_ALLOC; |
| 1977 | strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect, | 1988 | strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect, |
| 1978 | strindex) | INIT_OFFSET_MASK; | 1989 | info->index.str) | INIT_OFFSET_MASK; |
| 1979 | DEBUGP("\t%s\n", secstrings + strsect->sh_name); | 1990 | DEBUGP("\t%s\n", info->secstrings + strsect->sh_name); |
| 1980 | 1991 | ||
| 1981 | /* Append room for core symbols' strings at end of core part. */ | 1992 | /* Append room for core symbols' strings at end of core part. */ |
| 1982 | *pstroffs = mod->core_size; | 1993 | info->stroffs = mod->core_size; |
| 1983 | __set_bit(0, strmap); | 1994 | __set_bit(0, info->strmap); |
| 1984 | mod->core_size += bitmap_weight(strmap, strsect->sh_size); | 1995 | mod->core_size += bitmap_weight(info->strmap, strsect->sh_size); |
| 1985 | |||
| 1986 | return symoffs; | ||
| 1987 | } | 1996 | } |
| 1988 | 1997 | ||
| 1989 | static void add_kallsyms(struct module *mod, | 1998 | static void add_kallsyms(struct module *mod, const struct load_info *info) |
| 1990 | Elf_Shdr *sechdrs, | ||
| 1991 | unsigned int shnum, | ||
| 1992 | unsigned int symindex, | ||
| 1993 | unsigned int strindex, | ||
| 1994 | unsigned long symoffs, | ||
| 1995 | unsigned long stroffs, | ||
| 1996 | const char *secstrings, | ||
| 1997 | unsigned long *strmap) | ||
| 1998 | { | 1999 | { |
| 1999 | unsigned int i, ndst; | 2000 | unsigned int i, ndst; |
| 2000 | const Elf_Sym *src; | 2001 | const Elf_Sym *src; |
| 2001 | Elf_Sym *dst; | 2002 | Elf_Sym *dst; |
| 2002 | char *s; | 2003 | char *s; |
| 2004 | Elf_Shdr *symsec = &info->sechdrs[info->index.sym]; | ||
| 2003 | 2005 | ||
| 2004 | mod->symtab = (void *)sechdrs[symindex].sh_addr; | 2006 | mod->symtab = (void *)symsec->sh_addr; |
| 2005 | mod->num_symtab = sechdrs[symindex].sh_size / sizeof(Elf_Sym); | 2007 | mod->num_symtab = symsec->sh_size / sizeof(Elf_Sym); |
| 2006 | mod->strtab = (void *)sechdrs[strindex].sh_addr; | 2008 | /* Make sure we get permanent strtab: don't use info->strtab. */ |
| 2009 | mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr; | ||
| 2007 | 2010 | ||
| 2008 | /* Set types up while we still have access to sections. */ | 2011 | /* Set types up while we still have access to sections. */ |
| 2009 | for (i = 0; i < mod->num_symtab; i++) | 2012 | for (i = 0; i < mod->num_symtab; i++) |
| 2010 | mod->symtab[i].st_info | 2013 | mod->symtab[i].st_info = elf_type(&mod->symtab[i], info); |
| 2011 | = elf_type(&mod->symtab[i], sechdrs, secstrings, mod); | ||
| 2012 | 2014 | ||
| 2013 | mod->core_symtab = dst = mod->module_core + symoffs; | 2015 | mod->core_symtab = dst = mod->module_core + info->symoffs; |
| 2014 | src = mod->symtab; | 2016 | src = mod->symtab; |
| 2015 | *dst = *src; | 2017 | *dst = *src; |
| 2016 | for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) { | 2018 | for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) { |
| 2017 | if (!is_core_symbol(src, sechdrs, shnum)) | 2019 | if (!is_core_symbol(src, info->sechdrs, info->hdr->e_shnum)) |
| 2018 | continue; | 2020 | continue; |
| 2019 | dst[ndst] = *src; | 2021 | dst[ndst] = *src; |
| 2020 | dst[ndst].st_name = bitmap_weight(strmap, dst[ndst].st_name); | 2022 | dst[ndst].st_name = bitmap_weight(info->strmap, |
| 2023 | dst[ndst].st_name); | ||
| 2021 | ++ndst; | 2024 | ++ndst; |
| 2022 | } | 2025 | } |
| 2023 | mod->core_num_syms = ndst; | 2026 | mod->core_num_syms = ndst; |
| 2024 | 2027 | ||
| 2025 | mod->core_strtab = s = mod->module_core + stroffs; | 2028 | mod->core_strtab = s = mod->module_core + info->stroffs; |
| 2026 | for (*s = 0, i = 1; i < sechdrs[strindex].sh_size; ++i) | 2029 | for (*s = 0, i = 1; i < info->sechdrs[info->index.str].sh_size; ++i) |
| 2027 | if (test_bit(i, strmap)) | 2030 | if (test_bit(i, info->strmap)) |
| 2028 | *++s = mod->strtab[i]; | 2031 | *++s = mod->strtab[i]; |
| 2029 | } | 2032 | } |
| 2030 | #else | 2033 | #else |
| 2031 | static inline unsigned long layout_symtab(struct module *mod, | 2034 | static inline void layout_symtab(struct module *mod, struct load_info *info) |
| 2032 | Elf_Shdr *sechdrs, | ||
| 2033 | unsigned int symindex, | ||
| 2034 | unsigned int strindex, | ||
| 2035 | const Elf_Ehdr *hdr, | ||
| 2036 | const char *secstrings, | ||
| 2037 | unsigned long *pstroffs, | ||
| 2038 | unsigned long *strmap) | ||
| 2039 | { | 2035 | { |
| 2040 | return 0; | ||
| 2041 | } | 2036 | } |
| 2042 | 2037 | ||
| 2043 | static inline void add_kallsyms(struct module *mod, | 2038 | static void add_kallsyms(struct module *mod, struct load_info *info) |
| 2044 | Elf_Shdr *sechdrs, | ||
| 2045 | unsigned int shnum, | ||
| 2046 | unsigned int symindex, | ||
| 2047 | unsigned int strindex, | ||
| 2048 | unsigned long symoffs, | ||
| 2049 | unsigned long stroffs, | ||
| 2050 | const char *secstrings, | ||
| 2051 | const unsigned long *strmap) | ||
| 2052 | { | 2039 | { |
| 2053 | } | 2040 | } |
| 2054 | #endif /* CONFIG_KALLSYMS */ | 2041 | #endif /* CONFIG_KALLSYMS */ |
| 2055 | 2042 | ||
| 2056 | static void dynamic_debug_setup(struct _ddebug *debug, unsigned int num) | 2043 | static void dynamic_debug_setup(struct _ddebug *debug, unsigned int num) |
| 2057 | { | 2044 | { |
| 2045 | if (!debug) | ||
| 2046 | return; | ||
| 2058 | #ifdef CONFIG_DYNAMIC_DEBUG | 2047 | #ifdef CONFIG_DYNAMIC_DEBUG |
| 2059 | if (ddebug_add_module(debug, num, debug->modname)) | 2048 | if (ddebug_add_module(debug, num, debug->modname)) |
| 2060 | printk(KERN_ERR "dynamic debug error adding module: %s\n", | 2049 | printk(KERN_ERR "dynamic debug error adding module: %s\n", |
| @@ -2085,65 +2074,47 @@ static void *module_alloc_update_bounds(unsigned long size) | |||
| 2085 | } | 2074 | } |
| 2086 | 2075 | ||
| 2087 | #ifdef CONFIG_DEBUG_KMEMLEAK | 2076 | #ifdef CONFIG_DEBUG_KMEMLEAK |
| 2088 | static void kmemleak_load_module(struct module *mod, Elf_Ehdr *hdr, | 2077 | static void kmemleak_load_module(const struct module *mod, |
| 2089 | Elf_Shdr *sechdrs, char *secstrings) | 2078 | const struct load_info *info) |
| 2090 | { | 2079 | { |
| 2091 | unsigned int i; | 2080 | unsigned int i; |
| 2092 | 2081 | ||
| 2093 | /* only scan the sections containing data */ | 2082 | /* only scan the sections containing data */ |
| 2094 | kmemleak_scan_area(mod, sizeof(struct module), GFP_KERNEL); | 2083 | kmemleak_scan_area(mod, sizeof(struct module), GFP_KERNEL); |
| 2095 | 2084 | ||
| 2096 | for (i = 1; i < hdr->e_shnum; i++) { | 2085 | for (i = 1; i < info->hdr->e_shnum; i++) { |
| 2097 | if (!(sechdrs[i].sh_flags & SHF_ALLOC)) | 2086 | const char *name = info->secstrings + info->sechdrs[i].sh_name; |
| 2087 | if (!(info->sechdrs[i].sh_flags & SHF_ALLOC)) | ||
| 2098 | continue; | 2088 | continue; |
| 2099 | if (strncmp(secstrings + sechdrs[i].sh_name, ".data", 5) != 0 | 2089 | if (!strstarts(name, ".data") && !strstarts(name, ".bss")) |
| 2100 | && strncmp(secstrings + sechdrs[i].sh_name, ".bss", 4) != 0) | ||
| 2101 | continue; | 2090 | continue; |
| 2102 | 2091 | ||
| 2103 | kmemleak_scan_area((void *)sechdrs[i].sh_addr, | 2092 | kmemleak_scan_area((void *)info->sechdrs[i].sh_addr, |
| 2104 | sechdrs[i].sh_size, GFP_KERNEL); | 2093 | info->sechdrs[i].sh_size, GFP_KERNEL); |
| 2105 | } | 2094 | } |
| 2106 | } | 2095 | } |
| 2107 | #else | 2096 | #else |
| 2108 | static inline void kmemleak_load_module(struct module *mod, Elf_Ehdr *hdr, | 2097 | static inline void kmemleak_load_module(const struct module *mod, |
| 2109 | Elf_Shdr *sechdrs, char *secstrings) | 2098 | const struct load_info *info) |
| 2110 | { | 2099 | { |
| 2111 | } | 2100 | } |
| 2112 | #endif | 2101 | #endif |
| 2113 | 2102 | ||
| 2114 | /* Allocate and load the module: note that size of section 0 is always | 2103 | /* Sets info->hdr and info->len. */ |
| 2115 | zero, and we rely on this for optional sections. */ | 2104 | static int copy_and_check(struct load_info *info, |
| 2116 | static noinline struct module *load_module(void __user *umod, | 2105 | const void __user *umod, unsigned long len, |
| 2117 | unsigned long len, | 2106 | const char __user *uargs) |
| 2118 | const char __user *uargs) | ||
| 2119 | { | 2107 | { |
| 2108 | int err; | ||
| 2120 | Elf_Ehdr *hdr; | 2109 | Elf_Ehdr *hdr; |
| 2121 | Elf_Shdr *sechdrs; | ||
| 2122 | char *secstrings, *args, *modmagic, *strtab = NULL; | ||
| 2123 | char *staging; | ||
| 2124 | unsigned int i; | ||
| 2125 | unsigned int symindex = 0; | ||
| 2126 | unsigned int strindex = 0; | ||
| 2127 | unsigned int modindex, versindex, infoindex, pcpuindex; | ||
| 2128 | struct module *mod; | ||
| 2129 | long err = 0; | ||
| 2130 | void *ptr = NULL; /* Stops spurious gcc warning */ | ||
| 2131 | unsigned long symoffs, stroffs, *strmap; | ||
| 2132 | void __percpu *percpu; | ||
| 2133 | struct _ddebug *debug = NULL; | ||
| 2134 | unsigned int num_debug = 0; | ||
| 2135 | |||
| 2136 | mm_segment_t old_fs; | ||
| 2137 | 2110 | ||
| 2138 | DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n", | ||
| 2139 | umod, len, uargs); | ||
| 2140 | if (len < sizeof(*hdr)) | 2111 | if (len < sizeof(*hdr)) |
| 2141 | return ERR_PTR(-ENOEXEC); | 2112 | return -ENOEXEC; |
| 2142 | 2113 | ||
| 2143 | /* Suck in entire file: we'll want most of it. */ | 2114 | /* Suck in entire file: we'll want most of it. */ |
| 2144 | /* vmalloc barfs on "unusual" numbers. Check here */ | 2115 | /* vmalloc barfs on "unusual" numbers. Check here */ |
| 2145 | if (len > 64 * 1024 * 1024 || (hdr = vmalloc(len)) == NULL) | 2116 | if (len > 64 * 1024 * 1024 || (hdr = vmalloc(len)) == NULL) |
| 2146 | return ERR_PTR(-ENOMEM); | 2117 | return -ENOMEM; |
| 2147 | 2118 | ||
| 2148 | if (copy_from_user(hdr, umod, len) != 0) { | 2119 | if (copy_from_user(hdr, umod, len) != 0) { |
| 2149 | err = -EFAULT; | 2120 | err = -EFAULT; |
| @@ -2151,135 +2122,225 @@ static noinline struct module *load_module(void __user *umod, | |||
| 2151 | } | 2122 | } |
| 2152 | 2123 | ||
| 2153 | /* Sanity checks against insmoding binaries or wrong arch, | 2124 | /* Sanity checks against insmoding binaries or wrong arch, |
| 2154 | weird elf version */ | 2125 | weird elf version */ |
| 2155 | if (memcmp(hdr->e_ident, ELFMAG, SELFMAG) != 0 | 2126 | if (memcmp(hdr->e_ident, ELFMAG, SELFMAG) != 0 |
| 2156 | || hdr->e_type != ET_REL | 2127 | || hdr->e_type != ET_REL |
| 2157 | || !elf_check_arch(hdr) | 2128 | || !elf_check_arch(hdr) |
| 2158 | || hdr->e_shentsize != sizeof(*sechdrs)) { | 2129 | || hdr->e_shentsize != sizeof(Elf_Shdr)) { |
| 2130 | err = -ENOEXEC; | ||
| 2131 | goto free_hdr; | ||
| 2132 | } | ||
| 2133 | |||
| 2134 | if (len < hdr->e_shoff + hdr->e_shnum * sizeof(Elf_Shdr)) { | ||
| 2159 | err = -ENOEXEC; | 2135 | err = -ENOEXEC; |
| 2160 | goto free_hdr; | 2136 | goto free_hdr; |
| 2161 | } | 2137 | } |
| 2162 | 2138 | ||
| 2163 | if (len < hdr->e_shoff + hdr->e_shnum * sizeof(Elf_Shdr)) | 2139 | info->hdr = hdr; |
| 2164 | goto truncated; | 2140 | info->len = len; |
| 2141 | return 0; | ||
| 2142 | |||
| 2143 | free_hdr: | ||
| 2144 | vfree(hdr); | ||
| 2145 | return err; | ||
| 2146 | } | ||
| 2147 | |||
| 2148 | static void free_copy(struct load_info *info) | ||
| 2149 | { | ||
| 2150 | vfree(info->hdr); | ||
| 2151 | } | ||
| 2152 | |||
| 2153 | static int rewrite_section_headers(struct load_info *info) | ||
| 2154 | { | ||
| 2155 | unsigned int i; | ||
| 2165 | 2156 | ||
| 2166 | /* Convenience variables */ | 2157 | /* This should always be true, but let's be sure. */ |
| 2167 | sechdrs = (void *)hdr + hdr->e_shoff; | 2158 | info->sechdrs[0].sh_addr = 0; |
| 2168 | secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset; | ||
| 2169 | sechdrs[0].sh_addr = 0; | ||
| 2170 | 2159 | ||
| 2171 | for (i = 1; i < hdr->e_shnum; i++) { | 2160 | for (i = 1; i < info->hdr->e_shnum; i++) { |
| 2172 | if (sechdrs[i].sh_type != SHT_NOBITS | 2161 | Elf_Shdr *shdr = &info->sechdrs[i]; |
| 2173 | && len < sechdrs[i].sh_offset + sechdrs[i].sh_size) | 2162 | if (shdr->sh_type != SHT_NOBITS |
| 2174 | goto truncated; | 2163 | && info->len < shdr->sh_offset + shdr->sh_size) { |
| 2164 | printk(KERN_ERR "Module len %lu truncated\n", | ||
| 2165 | info->len); | ||
| 2166 | return -ENOEXEC; | ||
| 2167 | } | ||
| 2175 | 2168 | ||
| 2176 | /* Mark all sections sh_addr with their address in the | 2169 | /* Mark all sections sh_addr with their address in the |
| 2177 | temporary image. */ | 2170 | temporary image. */ |
| 2178 | sechdrs[i].sh_addr = (size_t)hdr + sechdrs[i].sh_offset; | 2171 | shdr->sh_addr = (size_t)info->hdr + shdr->sh_offset; |
| 2179 | 2172 | ||
| 2180 | /* Internal symbols and strings. */ | ||
| 2181 | if (sechdrs[i].sh_type == SHT_SYMTAB) { | ||
| 2182 | symindex = i; | ||
| 2183 | strindex = sechdrs[i].sh_link; | ||
| 2184 | strtab = (char *)hdr + sechdrs[strindex].sh_offset; | ||
| 2185 | } | ||
| 2186 | #ifndef CONFIG_MODULE_UNLOAD | 2173 | #ifndef CONFIG_MODULE_UNLOAD |
| 2187 | /* Don't load .exit sections */ | 2174 | /* Don't load .exit sections */ |
| 2188 | if (strstarts(secstrings+sechdrs[i].sh_name, ".exit")) | 2175 | if (strstarts(info->secstrings+shdr->sh_name, ".exit")) |
| 2189 | sechdrs[i].sh_flags &= ~(unsigned long)SHF_ALLOC; | 2176 | shdr->sh_flags &= ~(unsigned long)SHF_ALLOC; |
| 2190 | #endif | 2177 | #endif |
| 2191 | } | 2178 | } |
| 2192 | 2179 | ||
| 2193 | modindex = find_sec(hdr, sechdrs, secstrings, | 2180 | /* Track but don't keep modinfo and version sections. */ |
| 2194 | ".gnu.linkonce.this_module"); | 2181 | info->index.vers = find_sec(info, "__versions"); |
| 2195 | if (!modindex) { | 2182 | info->index.info = find_sec(info, ".modinfo"); |
| 2183 | info->sechdrs[info->index.info].sh_flags &= ~(unsigned long)SHF_ALLOC; | ||
| 2184 | info->sechdrs[info->index.vers].sh_flags &= ~(unsigned long)SHF_ALLOC; | ||
| 2185 | return 0; | ||
| 2186 | } | ||
| 2187 | |||
| 2188 | /* | ||
| 2189 | * Set up our basic convenience variables (pointers to section headers, | ||
| 2190 | * search for module section index etc), and do some basic section | ||
| 2191 | * verification. | ||
| 2192 | * | ||
| 2193 | * Return the temporary module pointer (we'll replace it with the final | ||
| 2194 | * one when we move the module sections around). | ||
| 2195 | */ | ||
| 2196 | static struct module *setup_load_info(struct load_info *info) | ||
| 2197 | { | ||
| 2198 | unsigned int i; | ||
| 2199 | int err; | ||
| 2200 | struct module *mod; | ||
| 2201 | |||
| 2202 | /* Set up the convenience variables */ | ||
| 2203 | info->sechdrs = (void *)info->hdr + info->hdr->e_shoff; | ||
| 2204 | info->secstrings = (void *)info->hdr | ||
| 2205 | + info->sechdrs[info->hdr->e_shstrndx].sh_offset; | ||
| 2206 | |||
| 2207 | err = rewrite_section_headers(info); | ||
| 2208 | if (err) | ||
| 2209 | return ERR_PTR(err); | ||
| 2210 | |||
| 2211 | /* Find internal symbols and strings. */ | ||
| 2212 | for (i = 1; i < info->hdr->e_shnum; i++) { | ||
| 2213 | if (info->sechdrs[i].sh_type == SHT_SYMTAB) { | ||
| 2214 | info->index.sym = i; | ||
| 2215 | info->index.str = info->sechdrs[i].sh_link; | ||
| 2216 | info->strtab = (char *)info->hdr | ||
| 2217 | + info->sechdrs[info->index.str].sh_offset; | ||
| 2218 | break; | ||
| 2219 | } | ||
| 2220 | } | ||
| 2221 | |||
| 2222 | info->index.mod = find_sec(info, ".gnu.linkonce.this_module"); | ||
| 2223 | if (!info->index.mod) { | ||
| 2196 | printk(KERN_WARNING "No module found in object\n"); | 2224 | printk(KERN_WARNING "No module found in object\n"); |
| 2197 | err = -ENOEXEC; | 2225 | return ERR_PTR(-ENOEXEC); |
| 2198 | goto free_hdr; | ||
| 2199 | } | 2226 | } |
| 2200 | /* This is temporary: point mod into copy of data. */ | 2227 | /* This is temporary: point mod into copy of data. */ |
| 2201 | mod = (void *)sechdrs[modindex].sh_addr; | 2228 | mod = (void *)info->sechdrs[info->index.mod].sh_addr; |
| 2202 | 2229 | ||
| 2203 | if (symindex == 0) { | 2230 | if (info->index.sym == 0) { |
| 2204 | printk(KERN_WARNING "%s: module has no symbols (stripped?)\n", | 2231 | printk(KERN_WARNING "%s: module has no symbols (stripped?)\n", |
| 2205 | mod->name); | 2232 | mod->name); |
| 2206 | err = -ENOEXEC; | 2233 | return ERR_PTR(-ENOEXEC); |
| 2207 | goto free_hdr; | ||
| 2208 | } | 2234 | } |
| 2209 | 2235 | ||
| 2210 | versindex = find_sec(hdr, sechdrs, secstrings, "__versions"); | 2236 | info->index.pcpu = find_pcpusec(info); |
| 2211 | infoindex = find_sec(hdr, sechdrs, secstrings, ".modinfo"); | ||
| 2212 | pcpuindex = find_pcpusec(hdr, sechdrs, secstrings); | ||
| 2213 | |||
| 2214 | /* Don't keep modinfo and version sections. */ | ||
| 2215 | sechdrs[infoindex].sh_flags &= ~(unsigned long)SHF_ALLOC; | ||
| 2216 | sechdrs[versindex].sh_flags &= ~(unsigned long)SHF_ALLOC; | ||
| 2217 | 2237 | ||
| 2218 | /* Check module struct version now, before we try to use module. */ | 2238 | /* Check module struct version now, before we try to use module. */ |
| 2219 | if (!check_modstruct_version(sechdrs, versindex, mod)) { | 2239 | if (!check_modstruct_version(info->sechdrs, info->index.vers, mod)) |
| 2220 | err = -ENOEXEC; | 2240 | return ERR_PTR(-ENOEXEC); |
| 2221 | goto free_hdr; | 2241 | |
| 2222 | } | 2242 | return mod; |
| 2243 | } | ||
| 2244 | |||
| 2245 | static int check_modinfo(struct module *mod, struct load_info *info) | ||
| 2246 | { | ||
| 2247 | const char *modmagic = get_modinfo(info, "vermagic"); | ||
| 2248 | int err; | ||
| 2223 | 2249 | ||
| 2224 | modmagic = get_modinfo(sechdrs, infoindex, "vermagic"); | ||
| 2225 | /* This is allowed: modprobe --force will invalidate it. */ | 2250 | /* This is allowed: modprobe --force will invalidate it. */ |
| 2226 | if (!modmagic) { | 2251 | if (!modmagic) { |
| 2227 | err = try_to_force_load(mod, "bad vermagic"); | 2252 | err = try_to_force_load(mod, "bad vermagic"); |
| 2228 | if (err) | 2253 | if (err) |
| 2229 | goto free_hdr; | 2254 | return err; |
| 2230 | } else if (!same_magic(modmagic, vermagic, versindex)) { | 2255 | } else if (!same_magic(modmagic, vermagic, info->index.vers)) { |
| 2231 | printk(KERN_ERR "%s: version magic '%s' should be '%s'\n", | 2256 | printk(KERN_ERR "%s: version magic '%s' should be '%s'\n", |
| 2232 | mod->name, modmagic, vermagic); | 2257 | mod->name, modmagic, vermagic); |
| 2233 | err = -ENOEXEC; | 2258 | return -ENOEXEC; |
| 2234 | goto free_hdr; | ||
| 2235 | } | 2259 | } |
| 2236 | 2260 | ||
| 2237 | staging = get_modinfo(sechdrs, infoindex, "staging"); | 2261 | if (get_modinfo(info, "staging")) { |
| 2238 | if (staging) { | ||
| 2239 | add_taint_module(mod, TAINT_CRAP); | 2262 | add_taint_module(mod, TAINT_CRAP); |
| 2240 | printk(KERN_WARNING "%s: module is from the staging directory," | 2263 | printk(KERN_WARNING "%s: module is from the staging directory," |
| 2241 | " the quality is unknown, you have been warned.\n", | 2264 | " the quality is unknown, you have been warned.\n", |
| 2242 | mod->name); | 2265 | mod->name); |
| 2243 | } | 2266 | } |
| 2244 | 2267 | ||
| 2245 | /* Now copy in args */ | 2268 | /* Set up license info based on the info section */ |
| 2246 | args = strndup_user(uargs, ~0UL >> 1); | 2269 | set_license(mod, get_modinfo(info, "license")); |
| 2247 | if (IS_ERR(args)) { | ||
| 2248 | err = PTR_ERR(args); | ||
| 2249 | goto free_hdr; | ||
| 2250 | } | ||
| 2251 | 2270 | ||
| 2252 | strmap = kzalloc(BITS_TO_LONGS(sechdrs[strindex].sh_size) | 2271 | return 0; |
| 2253 | * sizeof(long), GFP_KERNEL); | 2272 | } |
| 2254 | if (!strmap) { | ||
| 2255 | err = -ENOMEM; | ||
| 2256 | goto free_mod; | ||
| 2257 | } | ||
| 2258 | 2273 | ||
| 2259 | mod->state = MODULE_STATE_COMING; | 2274 | static void find_module_sections(struct module *mod, struct load_info *info) |
| 2275 | { | ||
| 2276 | mod->kp = section_objs(info, "__param", | ||
| 2277 | sizeof(*mod->kp), &mod->num_kp); | ||
| 2278 | mod->syms = section_objs(info, "__ksymtab", | ||
| 2279 | sizeof(*mod->syms), &mod->num_syms); | ||
| 2280 | mod->crcs = section_addr(info, "__kcrctab"); | ||
| 2281 | mod->gpl_syms = section_objs(info, "__ksymtab_gpl", | ||
| 2282 | sizeof(*mod->gpl_syms), | ||
| 2283 | &mod->num_gpl_syms); | ||
| 2284 | mod->gpl_crcs = section_addr(info, "__kcrctab_gpl"); | ||
| 2285 | mod->gpl_future_syms = section_objs(info, | ||
| 2286 | "__ksymtab_gpl_future", | ||
| 2287 | sizeof(*mod->gpl_future_syms), | ||
| 2288 | &mod->num_gpl_future_syms); | ||
| 2289 | mod->gpl_future_crcs = section_addr(info, "__kcrctab_gpl_future"); | ||
| 2260 | 2290 | ||
| 2261 | /* Allow arches to frob section contents and sizes. */ | 2291 | #ifdef CONFIG_UNUSED_SYMBOLS |
| 2262 | err = module_frob_arch_sections(hdr, sechdrs, secstrings, mod); | 2292 | mod->unused_syms = section_objs(info, "__ksymtab_unused", |
| 2263 | if (err < 0) | 2293 | sizeof(*mod->unused_syms), |
| 2264 | goto free_mod; | 2294 | &mod->num_unused_syms); |
| 2295 | mod->unused_crcs = section_addr(info, "__kcrctab_unused"); | ||
| 2296 | mod->unused_gpl_syms = section_objs(info, "__ksymtab_unused_gpl", | ||
| 2297 | sizeof(*mod->unused_gpl_syms), | ||
| 2298 | &mod->num_unused_gpl_syms); | ||
| 2299 | mod->unused_gpl_crcs = section_addr(info, "__kcrctab_unused_gpl"); | ||
| 2300 | #endif | ||
| 2301 | #ifdef CONFIG_CONSTRUCTORS | ||
| 2302 | mod->ctors = section_objs(info, ".ctors", | ||
| 2303 | sizeof(*mod->ctors), &mod->num_ctors); | ||
| 2304 | #endif | ||
| 2265 | 2305 | ||
| 2266 | if (pcpuindex) { | 2306 | #ifdef CONFIG_TRACEPOINTS |
| 2267 | /* We have a special allocation for this section. */ | 2307 | mod->tracepoints = section_objs(info, "__tracepoints", |
| 2268 | err = percpu_modalloc(mod, sechdrs[pcpuindex].sh_size, | 2308 | sizeof(*mod->tracepoints), |
| 2269 | sechdrs[pcpuindex].sh_addralign); | 2309 | &mod->num_tracepoints); |
| 2270 | if (err) | 2310 | #endif |
| 2271 | goto free_mod; | 2311 | #ifdef CONFIG_EVENT_TRACING |
| 2272 | sechdrs[pcpuindex].sh_flags &= ~(unsigned long)SHF_ALLOC; | 2312 | mod->trace_events = section_objs(info, "_ftrace_events", |
| 2273 | } | 2313 | sizeof(*mod->trace_events), |
| 2274 | /* Keep this around for failure path. */ | 2314 | &mod->num_trace_events); |
| 2275 | percpu = mod_percpu(mod); | 2315 | /* |
| 2316 | * This section contains pointers to allocated objects in the trace | ||
| 2317 | * code and not scanning it leads to false positives. | ||
| 2318 | */ | ||
| 2319 | kmemleak_scan_area(mod->trace_events, sizeof(*mod->trace_events) * | ||
| 2320 | mod->num_trace_events, GFP_KERNEL); | ||
| 2321 | #endif | ||
| 2322 | #ifdef CONFIG_FTRACE_MCOUNT_RECORD | ||
| 2323 | /* sechdrs[0].sh_size is always zero */ | ||
| 2324 | mod->ftrace_callsites = section_objs(info, "__mcount_loc", | ||
| 2325 | sizeof(*mod->ftrace_callsites), | ||
| 2326 | &mod->num_ftrace_callsites); | ||
| 2327 | #endif | ||
| 2276 | 2328 | ||
| 2277 | /* Determine total sizes, and put offsets in sh_entsize. For now | 2329 | mod->extable = section_objs(info, "__ex_table", |
| 2278 | this is done generically; there doesn't appear to be any | 2330 | sizeof(*mod->extable), &mod->num_exentries); |
| 2279 | special cases for the architectures. */ | 2331 | |
| 2280 | layout_sections(mod, hdr, sechdrs, secstrings); | 2332 | if (section_addr(info, "__obsparm")) |
| 2281 | symoffs = layout_symtab(mod, sechdrs, symindex, strindex, hdr, | 2333 | printk(KERN_WARNING "%s: Ignoring obsolete parameters\n", |
| 2282 | secstrings, &stroffs, strmap); | 2334 | mod->name); |
| 2335 | |||
| 2336 | info->debug = section_objs(info, "__verbose", | ||
| 2337 | sizeof(*info->debug), &info->num_debug); | ||
| 2338 | } | ||
| 2339 | |||
| 2340 | static int move_module(struct module *mod, struct load_info *info) | ||
| 2341 | { | ||
| 2342 | int i; | ||
| 2343 | void *ptr; | ||
| 2283 | 2344 | ||
| 2284 | /* Do the allocs. */ | 2345 | /* Do the allocs. */ |
| 2285 | ptr = module_alloc_update_bounds(mod->core_size); | 2346 | ptr = module_alloc_update_bounds(mod->core_size); |
| @@ -2289,10 +2350,9 @@ static noinline struct module *load_module(void __user *umod, | |||
| 2289 | * leak. | 2350 | * leak. |
| 2290 | */ | 2351 | */ |
| 2291 | kmemleak_not_leak(ptr); | 2352 | kmemleak_not_leak(ptr); |
| 2292 | if (!ptr) { | 2353 | if (!ptr) |
| 2293 | err = -ENOMEM; | 2354 | return -ENOMEM; |
| 2294 | goto free_percpu; | 2355 | |
| 2295 | } | ||
| 2296 | memset(ptr, 0, mod->core_size); | 2356 | memset(ptr, 0, mod->core_size); |
| 2297 | mod->module_core = ptr; | 2357 | mod->module_core = ptr; |
| 2298 | 2358 | ||
| @@ -2305,50 +2365,40 @@ static noinline struct module *load_module(void __user *umod, | |||
| 2305 | */ | 2365 | */ |
| 2306 | kmemleak_ignore(ptr); | 2366 | kmemleak_ignore(ptr); |
| 2307 | if (!ptr && mod->init_size) { | 2367 | if (!ptr && mod->init_size) { |
| 2308 | err = -ENOMEM; | 2368 | module_free(mod, mod->module_core); |
| 2309 | goto free_core; | 2369 | return -ENOMEM; |
| 2310 | } | 2370 | } |
| 2311 | memset(ptr, 0, mod->init_size); | 2371 | memset(ptr, 0, mod->init_size); |
| 2312 | mod->module_init = ptr; | 2372 | mod->module_init = ptr; |
| 2313 | 2373 | ||
| 2314 | /* Transfer each section which specifies SHF_ALLOC */ | 2374 | /* Transfer each section which specifies SHF_ALLOC */ |
| 2315 | DEBUGP("final section addresses:\n"); | 2375 | DEBUGP("final section addresses:\n"); |
| 2316 | for (i = 0; i < hdr->e_shnum; i++) { | 2376 | for (i = 0; i < info->hdr->e_shnum; i++) { |
| 2317 | void *dest; | 2377 | void *dest; |
| 2378 | Elf_Shdr *shdr = &info->sechdrs[i]; | ||
| 2318 | 2379 | ||
| 2319 | if (!(sechdrs[i].sh_flags & SHF_ALLOC)) | 2380 | if (!(shdr->sh_flags & SHF_ALLOC)) |
| 2320 | continue; | 2381 | continue; |
| 2321 | 2382 | ||
| 2322 | if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK) | 2383 | if (shdr->sh_entsize & INIT_OFFSET_MASK) |
| 2323 | dest = mod->module_init | 2384 | dest = mod->module_init |
| 2324 | + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK); | 2385 | + (shdr->sh_entsize & ~INIT_OFFSET_MASK); |
| 2325 | else | 2386 | else |
| 2326 | dest = mod->module_core + sechdrs[i].sh_entsize; | 2387 | dest = mod->module_core + shdr->sh_entsize; |
| 2327 | 2388 | ||
| 2328 | if (sechdrs[i].sh_type != SHT_NOBITS) | 2389 | if (shdr->sh_type != SHT_NOBITS) |
| 2329 | memcpy(dest, (void *)sechdrs[i].sh_addr, | 2390 | memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size); |
| 2330 | sechdrs[i].sh_size); | ||
| 2331 | /* Update sh_addr to point to copy in image. */ | 2391 | /* Update sh_addr to point to copy in image. */ |
| 2332 | sechdrs[i].sh_addr = (unsigned long)dest; | 2392 | shdr->sh_addr = (unsigned long)dest; |
| 2333 | DEBUGP("\t0x%lx %s\n", sechdrs[i].sh_addr, secstrings + sechdrs[i].sh_name); | 2393 | DEBUGP("\t0x%lx %s\n", |
| 2394 | shdr->sh_addr, info->secstrings + shdr->sh_name); | ||
| 2334 | } | 2395 | } |
| 2335 | /* Module has been moved. */ | ||
| 2336 | mod = (void *)sechdrs[modindex].sh_addr; | ||
| 2337 | kmemleak_load_module(mod, hdr, sechdrs, secstrings); | ||
| 2338 | 2396 | ||
| 2339 | #if defined(CONFIG_MODULE_UNLOAD) | 2397 | return 0; |
| 2340 | mod->refptr = alloc_percpu(struct module_ref); | 2398 | } |
| 2341 | if (!mod->refptr) { | ||
| 2342 | err = -ENOMEM; | ||
| 2343 | goto free_init; | ||
| 2344 | } | ||
| 2345 | #endif | ||
| 2346 | /* Now we've moved module, initialize linked lists, etc. */ | ||
| 2347 | module_unload_init(mod); | ||
| 2348 | |||
| 2349 | /* Set up license info based on the info section */ | ||
| 2350 | set_license(mod, get_modinfo(sechdrs, infoindex, "license")); | ||
| 2351 | 2399 | ||
| 2400 | static int check_module_license_and_versions(struct module *mod) | ||
| 2401 | { | ||
| 2352 | /* | 2402 | /* |
| 2353 | * ndiswrapper is under GPL by itself, but loads proprietary modules. | 2403 | * ndiswrapper is under GPL by itself, but loads proprietary modules. |
| 2354 | * Don't use add_taint_module(), as it would prevent ndiswrapper from | 2404 | * Don't use add_taint_module(), as it would prevent ndiswrapper from |
| @@ -2361,77 +2411,6 @@ static noinline struct module *load_module(void __user *umod, | |||
| 2361 | if (strcmp(mod->name, "driverloader") == 0) | 2411 | if (strcmp(mod->name, "driverloader") == 0) |
| 2362 | add_taint_module(mod, TAINT_PROPRIETARY_MODULE); | 2412 | add_taint_module(mod, TAINT_PROPRIETARY_MODULE); |
| 2363 | 2413 | ||
| 2364 | /* Set up MODINFO_ATTR fields */ | ||
| 2365 | setup_modinfo(mod, sechdrs, infoindex); | ||
| 2366 | |||
| 2367 | /* Fix up syms, so that st_value is a pointer to location. */ | ||
| 2368 | err = simplify_symbols(sechdrs, symindex, strtab, versindex, pcpuindex, | ||
| 2369 | mod); | ||
| 2370 | if (err < 0) | ||
| 2371 | goto cleanup; | ||
| 2372 | |||
| 2373 | /* Now we've got everything in the final locations, we can | ||
| 2374 | * find optional sections. */ | ||
| 2375 | mod->kp = section_objs(hdr, sechdrs, secstrings, "__param", | ||
| 2376 | sizeof(*mod->kp), &mod->num_kp); | ||
| 2377 | mod->syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab", | ||
| 2378 | sizeof(*mod->syms), &mod->num_syms); | ||
| 2379 | mod->crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab"); | ||
| 2380 | mod->gpl_syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab_gpl", | ||
| 2381 | sizeof(*mod->gpl_syms), | ||
| 2382 | &mod->num_gpl_syms); | ||
| 2383 | mod->gpl_crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab_gpl"); | ||
| 2384 | mod->gpl_future_syms = section_objs(hdr, sechdrs, secstrings, | ||
| 2385 | "__ksymtab_gpl_future", | ||
| 2386 | sizeof(*mod->gpl_future_syms), | ||
| 2387 | &mod->num_gpl_future_syms); | ||
| 2388 | mod->gpl_future_crcs = section_addr(hdr, sechdrs, secstrings, | ||
| 2389 | "__kcrctab_gpl_future"); | ||
| 2390 | |||
| 2391 | #ifdef CONFIG_UNUSED_SYMBOLS | ||
| 2392 | mod->unused_syms = section_objs(hdr, sechdrs, secstrings, | ||
| 2393 | "__ksymtab_unused", | ||
| 2394 | sizeof(*mod->unused_syms), | ||
| 2395 | &mod->num_unused_syms); | ||
| 2396 | mod->unused_crcs = section_addr(hdr, sechdrs, secstrings, | ||
| 2397 | "__kcrctab_unused"); | ||
| 2398 | mod->unused_gpl_syms = section_objs(hdr, sechdrs, secstrings, | ||
| 2399 | "__ksymtab_unused_gpl", | ||
| 2400 | sizeof(*mod->unused_gpl_syms), | ||
| 2401 | &mod->num_unused_gpl_syms); | ||
| 2402 | mod->unused_gpl_crcs = section_addr(hdr, sechdrs, secstrings, | ||
| 2403 | "__kcrctab_unused_gpl"); | ||
| 2404 | #endif | ||
| 2405 | #ifdef CONFIG_CONSTRUCTORS | ||
| 2406 | mod->ctors = section_objs(hdr, sechdrs, secstrings, ".ctors", | ||
| 2407 | sizeof(*mod->ctors), &mod->num_ctors); | ||
| 2408 | #endif | ||
| 2409 | |||
| 2410 | #ifdef CONFIG_TRACEPOINTS | ||
| 2411 | mod->tracepoints = section_objs(hdr, sechdrs, secstrings, | ||
| 2412 | "__tracepoints", | ||
| 2413 | sizeof(*mod->tracepoints), | ||
| 2414 | &mod->num_tracepoints); | ||
| 2415 | #endif | ||
| 2416 | #ifdef CONFIG_EVENT_TRACING | ||
| 2417 | mod->trace_events = section_objs(hdr, sechdrs, secstrings, | ||
| 2418 | "_ftrace_events", | ||
| 2419 | sizeof(*mod->trace_events), | ||
| 2420 | &mod->num_trace_events); | ||
| 2421 | /* | ||
| 2422 | * This section contains pointers to allocated objects in the trace | ||
| 2423 | * code and not scanning it leads to false positives. | ||
| 2424 | */ | ||
| 2425 | kmemleak_scan_area(mod->trace_events, sizeof(*mod->trace_events) * | ||
| 2426 | mod->num_trace_events, GFP_KERNEL); | ||
| 2427 | #endif | ||
| 2428 | #ifdef CONFIG_FTRACE_MCOUNT_RECORD | ||
| 2429 | /* sechdrs[0].sh_size is always zero */ | ||
| 2430 | mod->ftrace_callsites = section_objs(hdr, sechdrs, secstrings, | ||
| 2431 | "__mcount_loc", | ||
| 2432 | sizeof(*mod->ftrace_callsites), | ||
| 2433 | &mod->num_ftrace_callsites); | ||
| 2434 | #endif | ||
| 2435 | #ifdef CONFIG_MODVERSIONS | 2414 | #ifdef CONFIG_MODVERSIONS |
| 2436 | if ((mod->num_syms && !mod->crcs) | 2415 | if ((mod->num_syms && !mod->crcs) |
| 2437 | || (mod->num_gpl_syms && !mod->gpl_crcs) | 2416 | || (mod->num_gpl_syms && !mod->gpl_crcs) |
| @@ -2441,56 +2420,16 @@ static noinline struct module *load_module(void __user *umod, | |||
| 2441 | || (mod->num_unused_gpl_syms && !mod->unused_gpl_crcs) | 2420 | || (mod->num_unused_gpl_syms && !mod->unused_gpl_crcs) |
| 2442 | #endif | 2421 | #endif |
| 2443 | ) { | 2422 | ) { |
| 2444 | err = try_to_force_load(mod, | 2423 | return try_to_force_load(mod, |
| 2445 | "no versions for exported symbols"); | 2424 | "no versions for exported symbols"); |
| 2446 | if (err) | ||
| 2447 | goto cleanup; | ||
| 2448 | } | 2425 | } |
| 2449 | #endif | 2426 | #endif |
| 2427 | return 0; | ||
| 2428 | } | ||
| 2450 | 2429 | ||
| 2451 | /* Now do relocations. */ | 2430 | static void flush_module_icache(const struct module *mod) |
| 2452 | for (i = 1; i < hdr->e_shnum; i++) { | 2431 | { |
| 2453 | const char *strtab = (char *)sechdrs[strindex].sh_addr; | 2432 | mm_segment_t old_fs; |
| 2454 | unsigned int info = sechdrs[i].sh_info; | ||
| 2455 | |||
| 2456 | /* Not a valid relocation section? */ | ||
| 2457 | if (info >= hdr->e_shnum) | ||
| 2458 | continue; | ||
| 2459 | |||
| 2460 | /* Don't bother with non-allocated sections */ | ||
| 2461 | if (!(sechdrs[info].sh_flags & SHF_ALLOC)) | ||
| 2462 | continue; | ||
| 2463 | |||
| 2464 | if (sechdrs[i].sh_type == SHT_REL) | ||
| 2465 | err = apply_relocate(sechdrs, strtab, symindex, i,mod); | ||
| 2466 | else if (sechdrs[i].sh_type == SHT_RELA) | ||
| 2467 | err = apply_relocate_add(sechdrs, strtab, symindex, i, | ||
| 2468 | mod); | ||
| 2469 | if (err < 0) | ||
| 2470 | goto cleanup; | ||
| 2471 | } | ||
| 2472 | |||
| 2473 | /* Set up and sort exception table */ | ||
| 2474 | mod->extable = section_objs(hdr, sechdrs, secstrings, "__ex_table", | ||
| 2475 | sizeof(*mod->extable), &mod->num_exentries); | ||
| 2476 | sort_extable(mod->extable, mod->extable + mod->num_exentries); | ||
| 2477 | |||
| 2478 | /* Finally, copy percpu area over. */ | ||
| 2479 | percpu_modcopy(mod, (void *)sechdrs[pcpuindex].sh_addr, | ||
| 2480 | sechdrs[pcpuindex].sh_size); | ||
| 2481 | |||
| 2482 | add_kallsyms(mod, sechdrs, hdr->e_shnum, symindex, strindex, | ||
| 2483 | symoffs, stroffs, secstrings, strmap); | ||
| 2484 | kfree(strmap); | ||
| 2485 | strmap = NULL; | ||
| 2486 | |||
| 2487 | if (!mod->taints) | ||
| 2488 | debug = section_objs(hdr, sechdrs, secstrings, "__verbose", | ||
| 2489 | sizeof(*debug), &num_debug); | ||
| 2490 | |||
| 2491 | err = module_finalize(hdr, sechdrs, mod); | ||
| 2492 | if (err < 0) | ||
| 2493 | goto cleanup; | ||
| 2494 | 2433 | ||
| 2495 | /* flush the icache in correct context */ | 2434 | /* flush the icache in correct context */ |
| 2496 | old_fs = get_fs(); | 2435 | old_fs = get_fs(); |
| @@ -2509,11 +2448,160 @@ static noinline struct module *load_module(void __user *umod, | |||
| 2509 | (unsigned long)mod->module_core + mod->core_size); | 2448 | (unsigned long)mod->module_core + mod->core_size); |
| 2510 | 2449 | ||
| 2511 | set_fs(old_fs); | 2450 | set_fs(old_fs); |
| 2451 | } | ||
| 2512 | 2452 | ||
| 2513 | mod->args = args; | 2453 | static struct module *layout_and_allocate(struct load_info *info) |
| 2514 | if (section_addr(hdr, sechdrs, secstrings, "__obsparm")) | 2454 | { |
| 2515 | printk(KERN_WARNING "%s: Ignoring obsolete parameters\n", | 2455 | /* Module within temporary copy. */ |
| 2516 | mod->name); | 2456 | struct module *mod; |
| 2457 | Elf_Shdr *pcpusec; | ||
| 2458 | int err; | ||
| 2459 | |||
| 2460 | mod = setup_load_info(info); | ||
| 2461 | if (IS_ERR(mod)) | ||
| 2462 | return mod; | ||
| 2463 | |||
| 2464 | err = check_modinfo(mod, info); | ||
| 2465 | if (err) | ||
| 2466 | return ERR_PTR(err); | ||
| 2467 | |||
| 2468 | /* Allow arches to frob section contents and sizes. */ | ||
| 2469 | err = module_frob_arch_sections(info->hdr, info->sechdrs, | ||
| 2470 | info->secstrings, mod); | ||
| 2471 | if (err < 0) | ||
| 2472 | goto out; | ||
| 2473 | |||
| 2474 | pcpusec = &info->sechdrs[info->index.pcpu]; | ||
| 2475 | if (pcpusec->sh_size) { | ||
| 2476 | /* We have a special allocation for this section. */ | ||
| 2477 | err = percpu_modalloc(mod, | ||
| 2478 | pcpusec->sh_size, pcpusec->sh_addralign); | ||
| 2479 | if (err) | ||
| 2480 | goto out; | ||
| 2481 | pcpusec->sh_flags &= ~(unsigned long)SHF_ALLOC; | ||
| 2482 | } | ||
| 2483 | |||
| 2484 | /* Determine total sizes, and put offsets in sh_entsize. For now | ||
| 2485 | this is done generically; there doesn't appear to be any | ||
| 2486 | special cases for the architectures. */ | ||
| 2487 | layout_sections(mod, info); | ||
| 2488 | |||
| 2489 | info->strmap = kzalloc(BITS_TO_LONGS(info->sechdrs[info->index.str].sh_size) | ||
| 2490 | * sizeof(long), GFP_KERNEL); | ||
| 2491 | if (!info->strmap) { | ||
| 2492 | err = -ENOMEM; | ||
| 2493 | goto free_percpu; | ||
| 2494 | } | ||
| 2495 | layout_symtab(mod, info); | ||
| 2496 | |||
| 2497 | /* Allocate and move to the final place */ | ||
| 2498 | err = move_module(mod, info); | ||
| 2499 | if (err) | ||
| 2500 | goto free_strmap; | ||
| 2501 | |||
| 2502 | /* Module has been copied to its final place now: return it. */ | ||
| 2503 | mod = (void *)info->sechdrs[info->index.mod].sh_addr; | ||
| 2504 | kmemleak_load_module(mod, info); | ||
| 2505 | return mod; | ||
| 2506 | |||
| 2507 | free_strmap: | ||
| 2508 | kfree(info->strmap); | ||
| 2509 | free_percpu: | ||
| 2510 | percpu_modfree(mod); | ||
| 2511 | out: | ||
| 2512 | return ERR_PTR(err); | ||
| 2513 | } | ||
| 2514 | |||
| 2515 | /* mod is no longer valid after this! */ | ||
| 2516 | static void module_deallocate(struct module *mod, struct load_info *info) | ||
| 2517 | { | ||
| 2518 | kfree(info->strmap); | ||
| 2519 | percpu_modfree(mod); | ||
| 2520 | module_free(mod, mod->module_init); | ||
| 2521 | module_free(mod, mod->module_core); | ||
| 2522 | } | ||
| 2523 | |||
| 2524 | static int post_relocation(struct module *mod, const struct load_info *info) | ||
| 2525 | { | ||
| 2526 | /* Sort exception table now relocations are done. */ | ||
| 2527 | sort_extable(mod->extable, mod->extable + mod->num_exentries); | ||
| 2528 | |||
| 2529 | /* Copy relocated percpu area over. */ | ||
| 2530 | percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr, | ||
| 2531 | info->sechdrs[info->index.pcpu].sh_size); | ||
| 2532 | |||
| 2533 | /* Setup kallsyms-specific fields. */ | ||
| 2534 | add_kallsyms(mod, info); | ||
| 2535 | |||
| 2536 | /* Arch-specific module finalizing. */ | ||
| 2537 | return module_finalize(info->hdr, info->sechdrs, mod); | ||
| 2538 | } | ||
| 2539 | |||
| 2540 | /* Allocate and load the module: note that size of section 0 is always | ||
| 2541 | zero, and we rely on this for optional sections. */ | ||
| 2542 | static struct module *load_module(void __user *umod, | ||
| 2543 | unsigned long len, | ||
| 2544 | const char __user *uargs) | ||
| 2545 | { | ||
| 2546 | struct load_info info = { NULL, }; | ||
| 2547 | struct module *mod; | ||
| 2548 | long err; | ||
| 2549 | |||
| 2550 | DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n", | ||
| 2551 | umod, len, uargs); | ||
| 2552 | |||
| 2553 | /* Copy in the blobs from userspace, check they are vaguely sane. */ | ||
| 2554 | err = copy_and_check(&info, umod, len, uargs); | ||
| 2555 | if (err) | ||
| 2556 | return ERR_PTR(err); | ||
| 2557 | |||
| 2558 | /* Figure out module layout, and allocate all the memory. */ | ||
| 2559 | mod = layout_and_allocate(&info); | ||
| 2560 | if (IS_ERR(mod)) { | ||
| 2561 | err = PTR_ERR(mod); | ||
| 2562 | goto free_copy; | ||
| 2563 | } | ||
| 2564 | |||
| 2565 | /* Now module is in final location, initialize linked lists, etc. */ | ||
| 2566 | err = module_unload_init(mod); | ||
| 2567 | if (err) | ||
| 2568 | goto free_module; | ||
| 2569 | |||
| 2570 | /* Now we've got everything in the final locations, we can | ||
| 2571 | * find optional sections. */ | ||
| 2572 | find_module_sections(mod, &info); | ||
| 2573 | |||
| 2574 | err = check_module_license_and_versions(mod); | ||
| 2575 | if (err) | ||
| 2576 | goto free_unload; | ||
| 2577 | |||
| 2578 | /* Set up MODINFO_ATTR fields */ | ||
| 2579 | setup_modinfo(mod, &info); | ||
| 2580 | |||
| 2581 | /* Fix up syms, so that st_value is a pointer to location. */ | ||
| 2582 | err = simplify_symbols(mod, &info); | ||
| 2583 | if (err < 0) | ||
| 2584 | goto free_modinfo; | ||
| 2585 | |||
| 2586 | err = apply_relocations(mod, &info); | ||
| 2587 | if (err < 0) | ||
| 2588 | goto free_modinfo; | ||
| 2589 | |||
| 2590 | err = post_relocation(mod, &info); | ||
| 2591 | if (err < 0) | ||
| 2592 | goto free_modinfo; | ||
| 2593 | |||
| 2594 | flush_module_icache(mod); | ||
| 2595 | |||
| 2596 | /* Now copy in args */ | ||
| 2597 | mod->args = strndup_user(uargs, ~0UL >> 1); | ||
| 2598 | if (IS_ERR(mod->args)) { | ||
| 2599 | err = PTR_ERR(mod->args); | ||
| 2600 | goto free_arch_cleanup; | ||
| 2601 | } | ||
| 2602 | |||
| 2603 | /* Mark state as coming so strong_try_module_get() ignores us. */ | ||
| 2604 | mod->state = MODULE_STATE_COMING; | ||
| 2517 | 2605 | ||
| 2518 | /* Now sew it into the lists so we can get lockdep and oops | 2606 | /* Now sew it into the lists so we can get lockdep and oops |
| 2519 | * info during argument parsing. Noone should access us, since | 2607 | * info during argument parsing. Noone should access us, since |
| @@ -2528,8 +2616,9 @@ static noinline struct module *load_module(void __user *umod, | |||
| 2528 | goto unlock; | 2616 | goto unlock; |
| 2529 | } | 2617 | } |
| 2530 | 2618 | ||
| 2531 | if (debug) | 2619 | /* This has to be done once we're sure module name is unique. */ |
| 2532 | dynamic_debug_setup(debug, num_debug); | 2620 | if (!mod->taints) |
| 2621 | dynamic_debug_setup(info.debug, info.num_debug); | ||
| 2533 | 2622 | ||
| 2534 | /* Find duplicate symbols */ | 2623 | /* Find duplicate symbols */ |
| 2535 | err = verify_export_symbols(mod); | 2624 | err = verify_export_symbols(mod); |
| @@ -2539,23 +2628,22 @@ static noinline struct module *load_module(void __user *umod, | |||
| 2539 | list_add_rcu(&mod->list, &modules); | 2628 | list_add_rcu(&mod->list, &modules); |
| 2540 | mutex_unlock(&module_mutex); | 2629 | mutex_unlock(&module_mutex); |
| 2541 | 2630 | ||
| 2631 | /* Module is ready to execute: parsing args may do that. */ | ||
| 2542 | err = parse_args(mod->name, mod->args, mod->kp, mod->num_kp, NULL); | 2632 | err = parse_args(mod->name, mod->args, mod->kp, mod->num_kp, NULL); |
| 2543 | if (err < 0) | 2633 | if (err < 0) |
| 2544 | goto unlink; | 2634 | goto unlink; |
| 2545 | 2635 | ||
| 2546 | err = mod_sysfs_setup(mod, mod->kp, mod->num_kp); | 2636 | /* Link in to syfs. */ |
| 2637 | err = mod_sysfs_setup(mod, &info, mod->kp, mod->num_kp); | ||
| 2547 | if (err < 0) | 2638 | if (err < 0) |
| 2548 | goto unlink; | 2639 | goto unlink; |
| 2549 | 2640 | ||
| 2550 | add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs); | 2641 | /* Get rid of temporary copy and strmap. */ |
| 2551 | add_notes_attrs(mod, hdr->e_shnum, secstrings, sechdrs); | 2642 | kfree(info.strmap); |
| 2552 | 2643 | free_copy(&info); | |
| 2553 | /* Get rid of temporary copy */ | ||
| 2554 | vfree(hdr); | ||
| 2555 | |||
| 2556 | trace_module_load(mod); | ||
| 2557 | 2644 | ||
| 2558 | /* Done! */ | 2645 | /* Done! */ |
| 2646 | trace_module_load(mod); | ||
| 2559 | return mod; | 2647 | return mod; |
| 2560 | 2648 | ||
| 2561 | unlink: | 2649 | unlink: |
| @@ -2563,35 +2651,23 @@ static noinline struct module *load_module(void __user *umod, | |||
| 2563 | /* Unlink carefully: kallsyms could be walking list. */ | 2651 | /* Unlink carefully: kallsyms could be walking list. */ |
| 2564 | list_del_rcu(&mod->list); | 2652 | list_del_rcu(&mod->list); |
| 2565 | ddebug: | 2653 | ddebug: |
| 2566 | dynamic_debug_remove(debug); | 2654 | if (!mod->taints) |
| 2655 | dynamic_debug_remove(info.debug); | ||
| 2567 | unlock: | 2656 | unlock: |
| 2568 | mutex_unlock(&module_mutex); | 2657 | mutex_unlock(&module_mutex); |
| 2569 | synchronize_sched(); | 2658 | synchronize_sched(); |
| 2659 | kfree(mod->args); | ||
| 2660 | free_arch_cleanup: | ||
| 2570 | module_arch_cleanup(mod); | 2661 | module_arch_cleanup(mod); |
| 2571 | cleanup: | 2662 | free_modinfo: |
| 2572 | free_modinfo(mod); | 2663 | free_modinfo(mod); |
| 2664 | free_unload: | ||
| 2573 | module_unload_free(mod); | 2665 | module_unload_free(mod); |
| 2574 | #if defined(CONFIG_MODULE_UNLOAD) | 2666 | free_module: |
| 2575 | free_percpu(mod->refptr); | 2667 | module_deallocate(mod, &info); |
| 2576 | free_init: | 2668 | free_copy: |
| 2577 | #endif | 2669 | free_copy(&info); |
| 2578 | module_free(mod, mod->module_init); | ||
| 2579 | free_core: | ||
| 2580 | module_free(mod, mod->module_core); | ||
| 2581 | /* mod will be freed with core. Don't access it beyond this line! */ | ||
| 2582 | free_percpu: | ||
| 2583 | free_percpu(percpu); | ||
| 2584 | free_mod: | ||
| 2585 | kfree(args); | ||
| 2586 | kfree(strmap); | ||
| 2587 | free_hdr: | ||
| 2588 | vfree(hdr); | ||
| 2589 | return ERR_PTR(err); | 2670 | return ERR_PTR(err); |
| 2590 | |||
| 2591 | truncated: | ||
| 2592 | printk(KERN_ERR "Module len %lu truncated\n", len); | ||
| 2593 | err = -ENOEXEC; | ||
| 2594 | goto free_hdr; | ||
| 2595 | } | 2671 | } |
| 2596 | 2672 | ||
| 2597 | /* Call module constructors. */ | 2673 | /* Call module constructors. */ |
diff --git a/kernel/padata.c b/kernel/padata.c index fdd8ae609ce3..751019415d23 100644 --- a/kernel/padata.c +++ b/kernel/padata.c | |||
| @@ -26,18 +26,19 @@ | |||
| 26 | #include <linux/mutex.h> | 26 | #include <linux/mutex.h> |
| 27 | #include <linux/sched.h> | 27 | #include <linux/sched.h> |
| 28 | #include <linux/slab.h> | 28 | #include <linux/slab.h> |
| 29 | #include <linux/sysfs.h> | ||
| 29 | #include <linux/rcupdate.h> | 30 | #include <linux/rcupdate.h> |
| 30 | 31 | ||
| 31 | #define MAX_SEQ_NR INT_MAX - NR_CPUS | 32 | #define MAX_SEQ_NR (INT_MAX - NR_CPUS) |
| 32 | #define MAX_OBJ_NUM 1000 | 33 | #define MAX_OBJ_NUM 1000 |
| 33 | 34 | ||
| 34 | static int padata_index_to_cpu(struct parallel_data *pd, int cpu_index) | 35 | static int padata_index_to_cpu(struct parallel_data *pd, int cpu_index) |
| 35 | { | 36 | { |
| 36 | int cpu, target_cpu; | 37 | int cpu, target_cpu; |
| 37 | 38 | ||
| 38 | target_cpu = cpumask_first(pd->cpumask); | 39 | target_cpu = cpumask_first(pd->cpumask.pcpu); |
| 39 | for (cpu = 0; cpu < cpu_index; cpu++) | 40 | for (cpu = 0; cpu < cpu_index; cpu++) |
| 40 | target_cpu = cpumask_next(target_cpu, pd->cpumask); | 41 | target_cpu = cpumask_next(target_cpu, pd->cpumask.pcpu); |
| 41 | 42 | ||
| 42 | return target_cpu; | 43 | return target_cpu; |
| 43 | } | 44 | } |
| @@ -53,26 +54,27 @@ static int padata_cpu_hash(struct padata_priv *padata) | |||
| 53 | * Hash the sequence numbers to the cpus by taking | 54 | * Hash the sequence numbers to the cpus by taking |
| 54 | * seq_nr mod. number of cpus in use. | 55 | * seq_nr mod. number of cpus in use. |
| 55 | */ | 56 | */ |
| 56 | cpu_index = padata->seq_nr % cpumask_weight(pd->cpumask); | 57 | cpu_index = padata->seq_nr % cpumask_weight(pd->cpumask.pcpu); |
| 57 | 58 | ||
| 58 | return padata_index_to_cpu(pd, cpu_index); | 59 | return padata_index_to_cpu(pd, cpu_index); |
| 59 | } | 60 | } |
| 60 | 61 | ||
| 61 | static void padata_parallel_worker(struct work_struct *work) | 62 | static void padata_parallel_worker(struct work_struct *parallel_work) |
| 62 | { | 63 | { |
| 63 | struct padata_queue *queue; | 64 | struct padata_parallel_queue *pqueue; |
| 64 | struct parallel_data *pd; | 65 | struct parallel_data *pd; |
| 65 | struct padata_instance *pinst; | 66 | struct padata_instance *pinst; |
| 66 | LIST_HEAD(local_list); | 67 | LIST_HEAD(local_list); |
| 67 | 68 | ||
| 68 | local_bh_disable(); | 69 | local_bh_disable(); |
| 69 | queue = container_of(work, struct padata_queue, pwork); | 70 | pqueue = container_of(parallel_work, |
| 70 | pd = queue->pd; | 71 | struct padata_parallel_queue, work); |
| 72 | pd = pqueue->pd; | ||
| 71 | pinst = pd->pinst; | 73 | pinst = pd->pinst; |
| 72 | 74 | ||
| 73 | spin_lock(&queue->parallel.lock); | 75 | spin_lock(&pqueue->parallel.lock); |
| 74 | list_replace_init(&queue->parallel.list, &local_list); | 76 | list_replace_init(&pqueue->parallel.list, &local_list); |
| 75 | spin_unlock(&queue->parallel.lock); | 77 | spin_unlock(&pqueue->parallel.lock); |
| 76 | 78 | ||
| 77 | while (!list_empty(&local_list)) { | 79 | while (!list_empty(&local_list)) { |
| 78 | struct padata_priv *padata; | 80 | struct padata_priv *padata; |
| @@ -94,7 +96,7 @@ static void padata_parallel_worker(struct work_struct *work) | |||
| 94 | * @pinst: padata instance | 96 | * @pinst: padata instance |
| 95 | * @padata: object to be parallelized | 97 | * @padata: object to be parallelized |
| 96 | * @cb_cpu: cpu the serialization callback function will run on, | 98 | * @cb_cpu: cpu the serialization callback function will run on, |
| 97 | * must be in the cpumask of padata. | 99 | * must be in the serial cpumask of padata(i.e. cpumask.cbcpu). |
| 98 | * | 100 | * |
| 99 | * The parallelization callback function will run with BHs off. | 101 | * The parallelization callback function will run with BHs off. |
| 100 | * Note: Every object which is parallelized by padata_do_parallel | 102 | * Note: Every object which is parallelized by padata_do_parallel |
| @@ -104,15 +106,18 @@ int padata_do_parallel(struct padata_instance *pinst, | |||
| 104 | struct padata_priv *padata, int cb_cpu) | 106 | struct padata_priv *padata, int cb_cpu) |
| 105 | { | 107 | { |
| 106 | int target_cpu, err; | 108 | int target_cpu, err; |
| 107 | struct padata_queue *queue; | 109 | struct padata_parallel_queue *queue; |
| 108 | struct parallel_data *pd; | 110 | struct parallel_data *pd; |
| 109 | 111 | ||
| 110 | rcu_read_lock_bh(); | 112 | rcu_read_lock_bh(); |
| 111 | 113 | ||
| 112 | pd = rcu_dereference(pinst->pd); | 114 | pd = rcu_dereference(pinst->pd); |
| 113 | 115 | ||
| 114 | err = 0; | 116 | err = -EINVAL; |
| 115 | if (!(pinst->flags & PADATA_INIT)) | 117 | if (!(pinst->flags & PADATA_INIT) || pinst->flags & PADATA_INVALID) |
| 118 | goto out; | ||
| 119 | |||
| 120 | if (!cpumask_test_cpu(cb_cpu, pd->cpumask.cbcpu)) | ||
| 116 | goto out; | 121 | goto out; |
| 117 | 122 | ||
| 118 | err = -EBUSY; | 123 | err = -EBUSY; |
| @@ -122,11 +127,7 @@ int padata_do_parallel(struct padata_instance *pinst, | |||
| 122 | if (atomic_read(&pd->refcnt) >= MAX_OBJ_NUM) | 127 | if (atomic_read(&pd->refcnt) >= MAX_OBJ_NUM) |
| 123 | goto out; | 128 | goto out; |
| 124 | 129 | ||
| 125 | err = -EINVAL; | 130 | err = 0; |
| 126 | if (!cpumask_test_cpu(cb_cpu, pd->cpumask)) | ||
| 127 | goto out; | ||
| 128 | |||
| 129 | err = -EINPROGRESS; | ||
| 130 | atomic_inc(&pd->refcnt); | 131 | atomic_inc(&pd->refcnt); |
| 131 | padata->pd = pd; | 132 | padata->pd = pd; |
| 132 | padata->cb_cpu = cb_cpu; | 133 | padata->cb_cpu = cb_cpu; |
| @@ -137,13 +138,13 @@ int padata_do_parallel(struct padata_instance *pinst, | |||
| 137 | padata->seq_nr = atomic_inc_return(&pd->seq_nr); | 138 | padata->seq_nr = atomic_inc_return(&pd->seq_nr); |
| 138 | 139 | ||
| 139 | target_cpu = padata_cpu_hash(padata); | 140 | target_cpu = padata_cpu_hash(padata); |
| 140 | queue = per_cpu_ptr(pd->queue, target_cpu); | 141 | queue = per_cpu_ptr(pd->pqueue, target_cpu); |
| 141 | 142 | ||
| 142 | spin_lock(&queue->parallel.lock); | 143 | spin_lock(&queue->parallel.lock); |
| 143 | list_add_tail(&padata->list, &queue->parallel.list); | 144 | list_add_tail(&padata->list, &queue->parallel.list); |
| 144 | spin_unlock(&queue->parallel.lock); | 145 | spin_unlock(&queue->parallel.lock); |
| 145 | 146 | ||
| 146 | queue_work_on(target_cpu, pinst->wq, &queue->pwork); | 147 | queue_work_on(target_cpu, pinst->wq, &queue->work); |
| 147 | 148 | ||
| 148 | out: | 149 | out: |
| 149 | rcu_read_unlock_bh(); | 150 | rcu_read_unlock_bh(); |
| @@ -171,84 +172,52 @@ EXPORT_SYMBOL(padata_do_parallel); | |||
| 171 | */ | 172 | */ |
| 172 | static struct padata_priv *padata_get_next(struct parallel_data *pd) | 173 | static struct padata_priv *padata_get_next(struct parallel_data *pd) |
| 173 | { | 174 | { |
| 174 | int cpu, num_cpus, empty, calc_seq_nr; | 175 | int cpu, num_cpus; |
| 175 | int seq_nr, next_nr, overrun, next_overrun; | 176 | int next_nr, next_index; |
| 176 | struct padata_queue *queue, *next_queue; | 177 | struct padata_parallel_queue *queue, *next_queue; |
| 177 | struct padata_priv *padata; | 178 | struct padata_priv *padata; |
| 178 | struct padata_list *reorder; | 179 | struct padata_list *reorder; |
| 179 | 180 | ||
| 180 | empty = 0; | 181 | num_cpus = cpumask_weight(pd->cpumask.pcpu); |
| 181 | next_nr = -1; | ||
| 182 | next_overrun = 0; | ||
| 183 | next_queue = NULL; | ||
| 184 | |||
| 185 | num_cpus = cpumask_weight(pd->cpumask); | ||
| 186 | |||
| 187 | for_each_cpu(cpu, pd->cpumask) { | ||
| 188 | queue = per_cpu_ptr(pd->queue, cpu); | ||
| 189 | reorder = &queue->reorder; | ||
| 190 | |||
| 191 | /* | ||
| 192 | * Calculate the seq_nr of the object that should be | ||
| 193 | * next in this reorder queue. | ||
| 194 | */ | ||
| 195 | overrun = 0; | ||
| 196 | calc_seq_nr = (atomic_read(&queue->num_obj) * num_cpus) | ||
| 197 | + queue->cpu_index; | ||
| 198 | 182 | ||
| 199 | if (unlikely(calc_seq_nr > pd->max_seq_nr)) { | 183 | /* |
| 200 | calc_seq_nr = calc_seq_nr - pd->max_seq_nr - 1; | 184 | * Calculate the percpu reorder queue and the sequence |
| 201 | overrun = 1; | 185 | * number of the next object. |
| 202 | } | 186 | */ |
| 203 | 187 | next_nr = pd->processed; | |
| 204 | if (!list_empty(&reorder->list)) { | 188 | next_index = next_nr % num_cpus; |
| 205 | padata = list_entry(reorder->list.next, | 189 | cpu = padata_index_to_cpu(pd, next_index); |
| 206 | struct padata_priv, list); | 190 | next_queue = per_cpu_ptr(pd->pqueue, cpu); |
| 207 | 191 | ||
| 208 | seq_nr = padata->seq_nr; | 192 | if (unlikely(next_nr > pd->max_seq_nr)) { |
| 209 | BUG_ON(calc_seq_nr != seq_nr); | 193 | next_nr = next_nr - pd->max_seq_nr - 1; |
| 210 | } else { | 194 | next_index = next_nr % num_cpus; |
| 211 | seq_nr = calc_seq_nr; | 195 | cpu = padata_index_to_cpu(pd, next_index); |
| 212 | empty++; | 196 | next_queue = per_cpu_ptr(pd->pqueue, cpu); |
| 213 | } | 197 | pd->processed = 0; |
| 214 | |||
| 215 | if (next_nr < 0 || seq_nr < next_nr | ||
| 216 | || (next_overrun && !overrun)) { | ||
| 217 | next_nr = seq_nr; | ||
| 218 | next_overrun = overrun; | ||
| 219 | next_queue = queue; | ||
| 220 | } | ||
| 221 | } | 198 | } |
| 222 | 199 | ||
| 223 | padata = NULL; | 200 | padata = NULL; |
| 224 | 201 | ||
| 225 | if (empty == num_cpus) | ||
| 226 | goto out; | ||
| 227 | |||
| 228 | reorder = &next_queue->reorder; | 202 | reorder = &next_queue->reorder; |
| 229 | 203 | ||
| 230 | if (!list_empty(&reorder->list)) { | 204 | if (!list_empty(&reorder->list)) { |
| 231 | padata = list_entry(reorder->list.next, | 205 | padata = list_entry(reorder->list.next, |
| 232 | struct padata_priv, list); | 206 | struct padata_priv, list); |
| 233 | 207 | ||
| 234 | if (unlikely(next_overrun)) { | 208 | BUG_ON(next_nr != padata->seq_nr); |
| 235 | for_each_cpu(cpu, pd->cpumask) { | ||
| 236 | queue = per_cpu_ptr(pd->queue, cpu); | ||
| 237 | atomic_set(&queue->num_obj, 0); | ||
| 238 | } | ||
| 239 | } | ||
| 240 | 209 | ||
| 241 | spin_lock(&reorder->lock); | 210 | spin_lock(&reorder->lock); |
| 242 | list_del_init(&padata->list); | 211 | list_del_init(&padata->list); |
| 243 | atomic_dec(&pd->reorder_objects); | 212 | atomic_dec(&pd->reorder_objects); |
| 244 | spin_unlock(&reorder->lock); | 213 | spin_unlock(&reorder->lock); |
| 245 | 214 | ||
| 246 | atomic_inc(&next_queue->num_obj); | 215 | pd->processed++; |
| 247 | 216 | ||
| 248 | goto out; | 217 | goto out; |
| 249 | } | 218 | } |
| 250 | 219 | ||
| 251 | queue = per_cpu_ptr(pd->queue, smp_processor_id()); | 220 | queue = per_cpu_ptr(pd->pqueue, smp_processor_id()); |
| 252 | if (queue->cpu_index == next_queue->cpu_index) { | 221 | if (queue->cpu_index == next_queue->cpu_index) { |
| 253 | padata = ERR_PTR(-ENODATA); | 222 | padata = ERR_PTR(-ENODATA); |
| 254 | goto out; | 223 | goto out; |
| @@ -262,7 +231,7 @@ out: | |||
| 262 | static void padata_reorder(struct parallel_data *pd) | 231 | static void padata_reorder(struct parallel_data *pd) |
| 263 | { | 232 | { |
| 264 | struct padata_priv *padata; | 233 | struct padata_priv *padata; |
| 265 | struct padata_queue *queue; | 234 | struct padata_serial_queue *squeue; |
| 266 | struct padata_instance *pinst = pd->pinst; | 235 | struct padata_instance *pinst = pd->pinst; |
| 267 | 236 | ||
| 268 | /* | 237 | /* |
| @@ -301,13 +270,13 @@ static void padata_reorder(struct parallel_data *pd) | |||
| 301 | return; | 270 | return; |
| 302 | } | 271 | } |
| 303 | 272 | ||
| 304 | queue = per_cpu_ptr(pd->queue, padata->cb_cpu); | 273 | squeue = per_cpu_ptr(pd->squeue, padata->cb_cpu); |
| 305 | 274 | ||
| 306 | spin_lock(&queue->serial.lock); | 275 | spin_lock(&squeue->serial.lock); |
| 307 | list_add_tail(&padata->list, &queue->serial.list); | 276 | list_add_tail(&padata->list, &squeue->serial.list); |
| 308 | spin_unlock(&queue->serial.lock); | 277 | spin_unlock(&squeue->serial.lock); |
| 309 | 278 | ||
| 310 | queue_work_on(padata->cb_cpu, pinst->wq, &queue->swork); | 279 | queue_work_on(padata->cb_cpu, pinst->wq, &squeue->work); |
| 311 | } | 280 | } |
| 312 | 281 | ||
| 313 | spin_unlock_bh(&pd->lock); | 282 | spin_unlock_bh(&pd->lock); |
| @@ -333,19 +302,19 @@ static void padata_reorder_timer(unsigned long arg) | |||
| 333 | padata_reorder(pd); | 302 | padata_reorder(pd); |
| 334 | } | 303 | } |
| 335 | 304 | ||
| 336 | static void padata_serial_worker(struct work_struct *work) | 305 | static void padata_serial_worker(struct work_struct *serial_work) |
| 337 | { | 306 | { |
| 338 | struct padata_queue *queue; | 307 | struct padata_serial_queue *squeue; |
| 339 | struct parallel_data *pd; | 308 | struct parallel_data *pd; |
| 340 | LIST_HEAD(local_list); | 309 | LIST_HEAD(local_list); |
| 341 | 310 | ||
| 342 | local_bh_disable(); | 311 | local_bh_disable(); |
| 343 | queue = container_of(work, struct padata_queue, swork); | 312 | squeue = container_of(serial_work, struct padata_serial_queue, work); |
| 344 | pd = queue->pd; | 313 | pd = squeue->pd; |
| 345 | 314 | ||
| 346 | spin_lock(&queue->serial.lock); | 315 | spin_lock(&squeue->serial.lock); |
| 347 | list_replace_init(&queue->serial.list, &local_list); | 316 | list_replace_init(&squeue->serial.list, &local_list); |
| 348 | spin_unlock(&queue->serial.lock); | 317 | spin_unlock(&squeue->serial.lock); |
| 349 | 318 | ||
| 350 | while (!list_empty(&local_list)) { | 319 | while (!list_empty(&local_list)) { |
| 351 | struct padata_priv *padata; | 320 | struct padata_priv *padata; |
| @@ -372,18 +341,18 @@ static void padata_serial_worker(struct work_struct *work) | |||
| 372 | void padata_do_serial(struct padata_priv *padata) | 341 | void padata_do_serial(struct padata_priv *padata) |
| 373 | { | 342 | { |
| 374 | int cpu; | 343 | int cpu; |
| 375 | struct padata_queue *queue; | 344 | struct padata_parallel_queue *pqueue; |
| 376 | struct parallel_data *pd; | 345 | struct parallel_data *pd; |
| 377 | 346 | ||
| 378 | pd = padata->pd; | 347 | pd = padata->pd; |
| 379 | 348 | ||
| 380 | cpu = get_cpu(); | 349 | cpu = get_cpu(); |
| 381 | queue = per_cpu_ptr(pd->queue, cpu); | 350 | pqueue = per_cpu_ptr(pd->pqueue, cpu); |
| 382 | 351 | ||
| 383 | spin_lock(&queue->reorder.lock); | 352 | spin_lock(&pqueue->reorder.lock); |
| 384 | atomic_inc(&pd->reorder_objects); | 353 | atomic_inc(&pd->reorder_objects); |
| 385 | list_add_tail(&padata->list, &queue->reorder.list); | 354 | list_add_tail(&padata->list, &pqueue->reorder.list); |
| 386 | spin_unlock(&queue->reorder.lock); | 355 | spin_unlock(&pqueue->reorder.lock); |
| 387 | 356 | ||
| 388 | put_cpu(); | 357 | put_cpu(); |
| 389 | 358 | ||
| @@ -391,52 +360,89 @@ void padata_do_serial(struct padata_priv *padata) | |||
| 391 | } | 360 | } |
| 392 | EXPORT_SYMBOL(padata_do_serial); | 361 | EXPORT_SYMBOL(padata_do_serial); |
| 393 | 362 | ||
| 394 | /* Allocate and initialize the internal cpumask dependend resources. */ | 363 | static int padata_setup_cpumasks(struct parallel_data *pd, |
| 395 | static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst, | 364 | const struct cpumask *pcpumask, |
| 396 | const struct cpumask *cpumask) | 365 | const struct cpumask *cbcpumask) |
| 397 | { | 366 | { |
| 398 | int cpu, cpu_index, num_cpus; | 367 | if (!alloc_cpumask_var(&pd->cpumask.pcpu, GFP_KERNEL)) |
| 399 | struct padata_queue *queue; | 368 | return -ENOMEM; |
| 400 | struct parallel_data *pd; | ||
| 401 | |||
| 402 | cpu_index = 0; | ||
| 403 | 369 | ||
| 404 | pd = kzalloc(sizeof(struct parallel_data), GFP_KERNEL); | 370 | cpumask_and(pd->cpumask.pcpu, pcpumask, cpu_active_mask); |
| 405 | if (!pd) | 371 | if (!alloc_cpumask_var(&pd->cpumask.cbcpu, GFP_KERNEL)) { |
| 406 | goto err; | 372 | free_cpumask_var(pd->cpumask.cbcpu); |
| 373 | return -ENOMEM; | ||
| 374 | } | ||
| 407 | 375 | ||
| 408 | pd->queue = alloc_percpu(struct padata_queue); | 376 | cpumask_and(pd->cpumask.cbcpu, cbcpumask, cpu_active_mask); |
| 409 | if (!pd->queue) | 377 | return 0; |
| 410 | goto err_free_pd; | 378 | } |
| 411 | 379 | ||
| 412 | if (!alloc_cpumask_var(&pd->cpumask, GFP_KERNEL)) | 380 | static void __padata_list_init(struct padata_list *pd_list) |
| 413 | goto err_free_queue; | 381 | { |
| 382 | INIT_LIST_HEAD(&pd_list->list); | ||
| 383 | spin_lock_init(&pd_list->lock); | ||
| 384 | } | ||
| 414 | 385 | ||
| 415 | cpumask_and(pd->cpumask, cpumask, cpu_active_mask); | 386 | /* Initialize all percpu queues used by serial workers */ |
| 387 | static void padata_init_squeues(struct parallel_data *pd) | ||
| 388 | { | ||
| 389 | int cpu; | ||
| 390 | struct padata_serial_queue *squeue; | ||
| 416 | 391 | ||
| 417 | for_each_cpu(cpu, pd->cpumask) { | 392 | for_each_cpu(cpu, pd->cpumask.cbcpu) { |
| 418 | queue = per_cpu_ptr(pd->queue, cpu); | 393 | squeue = per_cpu_ptr(pd->squeue, cpu); |
| 394 | squeue->pd = pd; | ||
| 395 | __padata_list_init(&squeue->serial); | ||
| 396 | INIT_WORK(&squeue->work, padata_serial_worker); | ||
| 397 | } | ||
| 398 | } | ||
| 419 | 399 | ||
| 420 | queue->pd = pd; | 400 | /* Initialize all percpu queues used by parallel workers */ |
| 401 | static void padata_init_pqueues(struct parallel_data *pd) | ||
| 402 | { | ||
| 403 | int cpu_index, num_cpus, cpu; | ||
| 404 | struct padata_parallel_queue *pqueue; | ||
| 421 | 405 | ||
| 422 | queue->cpu_index = cpu_index; | 406 | cpu_index = 0; |
| 407 | for_each_cpu(cpu, pd->cpumask.pcpu) { | ||
| 408 | pqueue = per_cpu_ptr(pd->pqueue, cpu); | ||
| 409 | pqueue->pd = pd; | ||
| 410 | pqueue->cpu_index = cpu_index; | ||
| 423 | cpu_index++; | 411 | cpu_index++; |
| 424 | 412 | ||
| 425 | INIT_LIST_HEAD(&queue->reorder.list); | 413 | __padata_list_init(&pqueue->reorder); |
| 426 | INIT_LIST_HEAD(&queue->parallel.list); | 414 | __padata_list_init(&pqueue->parallel); |
| 427 | INIT_LIST_HEAD(&queue->serial.list); | 415 | INIT_WORK(&pqueue->work, padata_parallel_worker); |
| 428 | spin_lock_init(&queue->reorder.lock); | 416 | atomic_set(&pqueue->num_obj, 0); |
| 429 | spin_lock_init(&queue->parallel.lock); | ||
| 430 | spin_lock_init(&queue->serial.lock); | ||
| 431 | |||
| 432 | INIT_WORK(&queue->pwork, padata_parallel_worker); | ||
| 433 | INIT_WORK(&queue->swork, padata_serial_worker); | ||
| 434 | atomic_set(&queue->num_obj, 0); | ||
| 435 | } | 417 | } |
| 436 | 418 | ||
| 437 | num_cpus = cpumask_weight(pd->cpumask); | 419 | num_cpus = cpumask_weight(pd->cpumask.pcpu); |
| 438 | pd->max_seq_nr = (MAX_SEQ_NR / num_cpus) * num_cpus - 1; | 420 | pd->max_seq_nr = num_cpus ? (MAX_SEQ_NR / num_cpus) * num_cpus - 1 : 0; |
| 421 | } | ||
| 422 | |||
| 423 | /* Allocate and initialize the internal cpumask dependend resources. */ | ||
| 424 | static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst, | ||
| 425 | const struct cpumask *pcpumask, | ||
| 426 | const struct cpumask *cbcpumask) | ||
| 427 | { | ||
| 428 | struct parallel_data *pd; | ||
| 439 | 429 | ||
| 430 | pd = kzalloc(sizeof(struct parallel_data), GFP_KERNEL); | ||
| 431 | if (!pd) | ||
| 432 | goto err; | ||
| 433 | |||
| 434 | pd->pqueue = alloc_percpu(struct padata_parallel_queue); | ||
| 435 | if (!pd->pqueue) | ||
| 436 | goto err_free_pd; | ||
| 437 | |||
| 438 | pd->squeue = alloc_percpu(struct padata_serial_queue); | ||
| 439 | if (!pd->squeue) | ||
| 440 | goto err_free_pqueue; | ||
| 441 | if (padata_setup_cpumasks(pd, pcpumask, cbcpumask) < 0) | ||
| 442 | goto err_free_squeue; | ||
| 443 | |||
| 444 | padata_init_pqueues(pd); | ||
| 445 | padata_init_squeues(pd); | ||
| 440 | setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd); | 446 | setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd); |
| 441 | atomic_set(&pd->seq_nr, -1); | 447 | atomic_set(&pd->seq_nr, -1); |
| 442 | atomic_set(&pd->reorder_objects, 0); | 448 | atomic_set(&pd->reorder_objects, 0); |
| @@ -446,8 +452,10 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst, | |||
| 446 | 452 | ||
| 447 | return pd; | 453 | return pd; |
| 448 | 454 | ||
| 449 | err_free_queue: | 455 | err_free_squeue: |
| 450 | free_percpu(pd->queue); | 456 | free_percpu(pd->squeue); |
| 457 | err_free_pqueue: | ||
| 458 | free_percpu(pd->pqueue); | ||
| 451 | err_free_pd: | 459 | err_free_pd: |
| 452 | kfree(pd); | 460 | kfree(pd); |
| 453 | err: | 461 | err: |
| @@ -456,8 +464,10 @@ err: | |||
| 456 | 464 | ||
| 457 | static void padata_free_pd(struct parallel_data *pd) | 465 | static void padata_free_pd(struct parallel_data *pd) |
| 458 | { | 466 | { |
| 459 | free_cpumask_var(pd->cpumask); | 467 | free_cpumask_var(pd->cpumask.pcpu); |
| 460 | free_percpu(pd->queue); | 468 | free_cpumask_var(pd->cpumask.cbcpu); |
| 469 | free_percpu(pd->pqueue); | ||
| 470 | free_percpu(pd->squeue); | ||
| 461 | kfree(pd); | 471 | kfree(pd); |
| 462 | } | 472 | } |
| 463 | 473 | ||
| @@ -465,11 +475,12 @@ static void padata_free_pd(struct parallel_data *pd) | |||
| 465 | static void padata_flush_queues(struct parallel_data *pd) | 475 | static void padata_flush_queues(struct parallel_data *pd) |
| 466 | { | 476 | { |
| 467 | int cpu; | 477 | int cpu; |
| 468 | struct padata_queue *queue; | 478 | struct padata_parallel_queue *pqueue; |
| 479 | struct padata_serial_queue *squeue; | ||
| 469 | 480 | ||
| 470 | for_each_cpu(cpu, pd->cpumask) { | 481 | for_each_cpu(cpu, pd->cpumask.pcpu) { |
| 471 | queue = per_cpu_ptr(pd->queue, cpu); | 482 | pqueue = per_cpu_ptr(pd->pqueue, cpu); |
| 472 | flush_work(&queue->pwork); | 483 | flush_work(&pqueue->work); |
| 473 | } | 484 | } |
| 474 | 485 | ||
| 475 | del_timer_sync(&pd->timer); | 486 | del_timer_sync(&pd->timer); |
| @@ -477,19 +488,39 @@ static void padata_flush_queues(struct parallel_data *pd) | |||
| 477 | if (atomic_read(&pd->reorder_objects)) | 488 | if (atomic_read(&pd->reorder_objects)) |
| 478 | padata_reorder(pd); | 489 | padata_reorder(pd); |
| 479 | 490 | ||
| 480 | for_each_cpu(cpu, pd->cpumask) { | 491 | for_each_cpu(cpu, pd->cpumask.cbcpu) { |
| 481 | queue = per_cpu_ptr(pd->queue, cpu); | 492 | squeue = per_cpu_ptr(pd->squeue, cpu); |
| 482 | flush_work(&queue->swork); | 493 | flush_work(&squeue->work); |
| 483 | } | 494 | } |
| 484 | 495 | ||
| 485 | BUG_ON(atomic_read(&pd->refcnt) != 0); | 496 | BUG_ON(atomic_read(&pd->refcnt) != 0); |
| 486 | } | 497 | } |
| 487 | 498 | ||
| 499 | static void __padata_start(struct padata_instance *pinst) | ||
| 500 | { | ||
| 501 | pinst->flags |= PADATA_INIT; | ||
| 502 | } | ||
| 503 | |||
| 504 | static void __padata_stop(struct padata_instance *pinst) | ||
| 505 | { | ||
| 506 | if (!(pinst->flags & PADATA_INIT)) | ||
| 507 | return; | ||
| 508 | |||
| 509 | pinst->flags &= ~PADATA_INIT; | ||
| 510 | |||
| 511 | synchronize_rcu(); | ||
| 512 | |||
| 513 | get_online_cpus(); | ||
| 514 | padata_flush_queues(pinst->pd); | ||
| 515 | put_online_cpus(); | ||
| 516 | } | ||
| 517 | |||
| 488 | /* Replace the internal control stucture with a new one. */ | 518 | /* Replace the internal control stucture with a new one. */ |
| 489 | static void padata_replace(struct padata_instance *pinst, | 519 | static void padata_replace(struct padata_instance *pinst, |
| 490 | struct parallel_data *pd_new) | 520 | struct parallel_data *pd_new) |
| 491 | { | 521 | { |
| 492 | struct parallel_data *pd_old = pinst->pd; | 522 | struct parallel_data *pd_old = pinst->pd; |
| 523 | int notification_mask = 0; | ||
| 493 | 524 | ||
| 494 | pinst->flags |= PADATA_RESET; | 525 | pinst->flags |= PADATA_RESET; |
| 495 | 526 | ||
| @@ -497,41 +528,162 @@ static void padata_replace(struct padata_instance *pinst, | |||
| 497 | 528 | ||
| 498 | synchronize_rcu(); | 529 | synchronize_rcu(); |
| 499 | 530 | ||
| 531 | if (!cpumask_equal(pd_old->cpumask.pcpu, pd_new->cpumask.pcpu)) | ||
| 532 | notification_mask |= PADATA_CPU_PARALLEL; | ||
| 533 | if (!cpumask_equal(pd_old->cpumask.cbcpu, pd_new->cpumask.cbcpu)) | ||
| 534 | notification_mask |= PADATA_CPU_SERIAL; | ||
| 535 | |||
| 500 | padata_flush_queues(pd_old); | 536 | padata_flush_queues(pd_old); |
| 501 | padata_free_pd(pd_old); | 537 | padata_free_pd(pd_old); |
| 502 | 538 | ||
| 539 | if (notification_mask) | ||
| 540 | blocking_notifier_call_chain(&pinst->cpumask_change_notifier, | ||
| 541 | notification_mask, | ||
| 542 | &pd_new->cpumask); | ||
| 543 | |||
| 503 | pinst->flags &= ~PADATA_RESET; | 544 | pinst->flags &= ~PADATA_RESET; |
| 504 | } | 545 | } |
| 505 | 546 | ||
| 506 | /** | 547 | /** |
| 507 | * padata_set_cpumask - set the cpumask that padata should use | 548 | * padata_register_cpumask_notifier - Registers a notifier that will be called |
| 549 | * if either pcpu or cbcpu or both cpumasks change. | ||
| 508 | * | 550 | * |
| 509 | * @pinst: padata instance | 551 | * @pinst: A poineter to padata instance |
| 510 | * @cpumask: the cpumask to use | 552 | * @nblock: A pointer to notifier block. |
| 511 | */ | 553 | */ |
| 512 | int padata_set_cpumask(struct padata_instance *pinst, | 554 | int padata_register_cpumask_notifier(struct padata_instance *pinst, |
| 513 | cpumask_var_t cpumask) | 555 | struct notifier_block *nblock) |
| 514 | { | 556 | { |
| 557 | return blocking_notifier_chain_register(&pinst->cpumask_change_notifier, | ||
| 558 | nblock); | ||
| 559 | } | ||
| 560 | EXPORT_SYMBOL(padata_register_cpumask_notifier); | ||
| 561 | |||
| 562 | /** | ||
| 563 | * padata_unregister_cpumask_notifier - Unregisters cpumask notifier | ||
| 564 | * registered earlier using padata_register_cpumask_notifier | ||
| 565 | * | ||
| 566 | * @pinst: A pointer to data instance. | ||
| 567 | * @nlock: A pointer to notifier block. | ||
| 568 | */ | ||
| 569 | int padata_unregister_cpumask_notifier(struct padata_instance *pinst, | ||
| 570 | struct notifier_block *nblock) | ||
| 571 | { | ||
| 572 | return blocking_notifier_chain_unregister( | ||
| 573 | &pinst->cpumask_change_notifier, | ||
| 574 | nblock); | ||
| 575 | } | ||
| 576 | EXPORT_SYMBOL(padata_unregister_cpumask_notifier); | ||
| 577 | |||
| 578 | |||
| 579 | /* If cpumask contains no active cpu, we mark the instance as invalid. */ | ||
| 580 | static bool padata_validate_cpumask(struct padata_instance *pinst, | ||
| 581 | const struct cpumask *cpumask) | ||
| 582 | { | ||
| 583 | if (!cpumask_intersects(cpumask, cpu_active_mask)) { | ||
| 584 | pinst->flags |= PADATA_INVALID; | ||
| 585 | return false; | ||
| 586 | } | ||
| 587 | |||
| 588 | pinst->flags &= ~PADATA_INVALID; | ||
| 589 | return true; | ||
| 590 | } | ||
| 591 | |||
| 592 | static int __padata_set_cpumasks(struct padata_instance *pinst, | ||
| 593 | cpumask_var_t pcpumask, | ||
| 594 | cpumask_var_t cbcpumask) | ||
| 595 | { | ||
| 596 | int valid; | ||
| 515 | struct parallel_data *pd; | 597 | struct parallel_data *pd; |
| 516 | int err = 0; | 598 | |
| 599 | valid = padata_validate_cpumask(pinst, pcpumask); | ||
| 600 | if (!valid) { | ||
| 601 | __padata_stop(pinst); | ||
| 602 | goto out_replace; | ||
| 603 | } | ||
| 604 | |||
| 605 | valid = padata_validate_cpumask(pinst, cbcpumask); | ||
| 606 | if (!valid) | ||
| 607 | __padata_stop(pinst); | ||
| 608 | |||
| 609 | out_replace: | ||
| 610 | pd = padata_alloc_pd(pinst, pcpumask, cbcpumask); | ||
| 611 | if (!pd) | ||
| 612 | return -ENOMEM; | ||
| 613 | |||
| 614 | cpumask_copy(pinst->cpumask.pcpu, pcpumask); | ||
| 615 | cpumask_copy(pinst->cpumask.cbcpu, cbcpumask); | ||
| 616 | |||
| 617 | padata_replace(pinst, pd); | ||
| 618 | |||
| 619 | if (valid) | ||
| 620 | __padata_start(pinst); | ||
| 621 | |||
| 622 | return 0; | ||
| 623 | } | ||
| 624 | |||
| 625 | /** | ||
| 626 | * padata_set_cpumasks - Set both parallel and serial cpumasks. The first | ||
| 627 | * one is used by parallel workers and the second one | ||
| 628 | * by the wokers doing serialization. | ||
| 629 | * | ||
| 630 | * @pinst: padata instance | ||
| 631 | * @pcpumask: the cpumask to use for parallel workers | ||
| 632 | * @cbcpumask: the cpumsak to use for serial workers | ||
| 633 | */ | ||
| 634 | int padata_set_cpumasks(struct padata_instance *pinst, cpumask_var_t pcpumask, | ||
| 635 | cpumask_var_t cbcpumask) | ||
| 636 | { | ||
| 637 | int err; | ||
| 517 | 638 | ||
| 518 | mutex_lock(&pinst->lock); | 639 | mutex_lock(&pinst->lock); |
| 640 | get_online_cpus(); | ||
| 519 | 641 | ||
| 642 | err = __padata_set_cpumasks(pinst, pcpumask, cbcpumask); | ||
| 643 | |||
| 644 | put_online_cpus(); | ||
| 645 | mutex_unlock(&pinst->lock); | ||
| 646 | |||
| 647 | return err; | ||
| 648 | |||
| 649 | } | ||
| 650 | EXPORT_SYMBOL(padata_set_cpumasks); | ||
| 651 | |||
| 652 | /** | ||
| 653 | * padata_set_cpumask: Sets specified by @cpumask_type cpumask to the value | ||
| 654 | * equivalent to @cpumask. | ||
| 655 | * | ||
| 656 | * @pinst: padata instance | ||
| 657 | * @cpumask_type: PADATA_CPU_SERIAL or PADATA_CPU_PARALLEL corresponding | ||
| 658 | * to parallel and serial cpumasks respectively. | ||
| 659 | * @cpumask: the cpumask to use | ||
| 660 | */ | ||
| 661 | int padata_set_cpumask(struct padata_instance *pinst, int cpumask_type, | ||
| 662 | cpumask_var_t cpumask) | ||
| 663 | { | ||
| 664 | struct cpumask *serial_mask, *parallel_mask; | ||
| 665 | int err = -EINVAL; | ||
| 666 | |||
| 667 | mutex_lock(&pinst->lock); | ||
| 520 | get_online_cpus(); | 668 | get_online_cpus(); |
| 521 | 669 | ||
| 522 | pd = padata_alloc_pd(pinst, cpumask); | 670 | switch (cpumask_type) { |
| 523 | if (!pd) { | 671 | case PADATA_CPU_PARALLEL: |
| 524 | err = -ENOMEM; | 672 | serial_mask = pinst->cpumask.cbcpu; |
| 525 | goto out; | 673 | parallel_mask = cpumask; |
| 674 | break; | ||
| 675 | case PADATA_CPU_SERIAL: | ||
| 676 | parallel_mask = pinst->cpumask.pcpu; | ||
| 677 | serial_mask = cpumask; | ||
| 678 | break; | ||
| 679 | default: | ||
| 680 | goto out; | ||
| 526 | } | 681 | } |
| 527 | 682 | ||
| 528 | cpumask_copy(pinst->cpumask, cpumask); | 683 | err = __padata_set_cpumasks(pinst, parallel_mask, serial_mask); |
| 529 | |||
| 530 | padata_replace(pinst, pd); | ||
| 531 | 684 | ||
| 532 | out: | 685 | out: |
| 533 | put_online_cpus(); | 686 | put_online_cpus(); |
| 534 | |||
| 535 | mutex_unlock(&pinst->lock); | 687 | mutex_unlock(&pinst->lock); |
| 536 | 688 | ||
| 537 | return err; | 689 | return err; |
| @@ -543,30 +695,48 @@ static int __padata_add_cpu(struct padata_instance *pinst, int cpu) | |||
| 543 | struct parallel_data *pd; | 695 | struct parallel_data *pd; |
| 544 | 696 | ||
| 545 | if (cpumask_test_cpu(cpu, cpu_active_mask)) { | 697 | if (cpumask_test_cpu(cpu, cpu_active_mask)) { |
| 546 | pd = padata_alloc_pd(pinst, pinst->cpumask); | 698 | pd = padata_alloc_pd(pinst, pinst->cpumask.pcpu, |
| 699 | pinst->cpumask.cbcpu); | ||
| 547 | if (!pd) | 700 | if (!pd) |
| 548 | return -ENOMEM; | 701 | return -ENOMEM; |
| 549 | 702 | ||
| 550 | padata_replace(pinst, pd); | 703 | padata_replace(pinst, pd); |
| 704 | |||
| 705 | if (padata_validate_cpumask(pinst, pinst->cpumask.pcpu) && | ||
| 706 | padata_validate_cpumask(pinst, pinst->cpumask.cbcpu)) | ||
| 707 | __padata_start(pinst); | ||
| 551 | } | 708 | } |
| 552 | 709 | ||
| 553 | return 0; | 710 | return 0; |
| 554 | } | 711 | } |
| 555 | 712 | ||
| 556 | /** | 713 | /** |
| 557 | * padata_add_cpu - add a cpu to the padata cpumask | 714 | * padata_add_cpu - add a cpu to one or both(parallel and serial) |
| 715 | * padata cpumasks. | ||
| 558 | * | 716 | * |
| 559 | * @pinst: padata instance | 717 | * @pinst: padata instance |
| 560 | * @cpu: cpu to add | 718 | * @cpu: cpu to add |
| 719 | * @mask: bitmask of flags specifying to which cpumask @cpu shuld be added. | ||
| 720 | * The @mask may be any combination of the following flags: | ||
| 721 | * PADATA_CPU_SERIAL - serial cpumask | ||
| 722 | * PADATA_CPU_PARALLEL - parallel cpumask | ||
| 561 | */ | 723 | */ |
| 562 | int padata_add_cpu(struct padata_instance *pinst, int cpu) | 724 | |
| 725 | int padata_add_cpu(struct padata_instance *pinst, int cpu, int mask) | ||
| 563 | { | 726 | { |
| 564 | int err; | 727 | int err; |
| 565 | 728 | ||
| 729 | if (!(mask & (PADATA_CPU_SERIAL | PADATA_CPU_PARALLEL))) | ||
| 730 | return -EINVAL; | ||
| 731 | |||
| 566 | mutex_lock(&pinst->lock); | 732 | mutex_lock(&pinst->lock); |
| 567 | 733 | ||
| 568 | get_online_cpus(); | 734 | get_online_cpus(); |
| 569 | cpumask_set_cpu(cpu, pinst->cpumask); | 735 | if (mask & PADATA_CPU_SERIAL) |
| 736 | cpumask_set_cpu(cpu, pinst->cpumask.cbcpu); | ||
| 737 | if (mask & PADATA_CPU_PARALLEL) | ||
| 738 | cpumask_set_cpu(cpu, pinst->cpumask.pcpu); | ||
| 739 | |||
| 570 | err = __padata_add_cpu(pinst, cpu); | 740 | err = __padata_add_cpu(pinst, cpu); |
| 571 | put_online_cpus(); | 741 | put_online_cpus(); |
| 572 | 742 | ||
| @@ -578,10 +748,16 @@ EXPORT_SYMBOL(padata_add_cpu); | |||
| 578 | 748 | ||
| 579 | static int __padata_remove_cpu(struct padata_instance *pinst, int cpu) | 749 | static int __padata_remove_cpu(struct padata_instance *pinst, int cpu) |
| 580 | { | 750 | { |
| 581 | struct parallel_data *pd; | 751 | struct parallel_data *pd = NULL; |
| 582 | 752 | ||
| 583 | if (cpumask_test_cpu(cpu, cpu_online_mask)) { | 753 | if (cpumask_test_cpu(cpu, cpu_online_mask)) { |
| 584 | pd = padata_alloc_pd(pinst, pinst->cpumask); | 754 | |
| 755 | if (!padata_validate_cpumask(pinst, pinst->cpumask.pcpu) || | ||
| 756 | !padata_validate_cpumask(pinst, pinst->cpumask.cbcpu)) | ||
| 757 | __padata_stop(pinst); | ||
| 758 | |||
| 759 | pd = padata_alloc_pd(pinst, pinst->cpumask.pcpu, | ||
| 760 | pinst->cpumask.cbcpu); | ||
| 585 | if (!pd) | 761 | if (!pd) |
| 586 | return -ENOMEM; | 762 | return -ENOMEM; |
| 587 | 763 | ||
| @@ -591,20 +767,32 @@ static int __padata_remove_cpu(struct padata_instance *pinst, int cpu) | |||
| 591 | return 0; | 767 | return 0; |
| 592 | } | 768 | } |
| 593 | 769 | ||
| 594 | /** | 770 | /** |
| 595 | * padata_remove_cpu - remove a cpu from the padata cpumask | 771 | * padata_remove_cpu - remove a cpu from the one or both(serial and paralell) |
| 772 | * padata cpumasks. | ||
| 596 | * | 773 | * |
| 597 | * @pinst: padata instance | 774 | * @pinst: padata instance |
| 598 | * @cpu: cpu to remove | 775 | * @cpu: cpu to remove |
| 776 | * @mask: bitmask specifying from which cpumask @cpu should be removed | ||
| 777 | * The @mask may be any combination of the following flags: | ||
| 778 | * PADATA_CPU_SERIAL - serial cpumask | ||
| 779 | * PADATA_CPU_PARALLEL - parallel cpumask | ||
| 599 | */ | 780 | */ |
| 600 | int padata_remove_cpu(struct padata_instance *pinst, int cpu) | 781 | int padata_remove_cpu(struct padata_instance *pinst, int cpu, int mask) |
| 601 | { | 782 | { |
| 602 | int err; | 783 | int err; |
| 603 | 784 | ||
| 785 | if (!(mask & (PADATA_CPU_SERIAL | PADATA_CPU_PARALLEL))) | ||
| 786 | return -EINVAL; | ||
| 787 | |||
| 604 | mutex_lock(&pinst->lock); | 788 | mutex_lock(&pinst->lock); |
| 605 | 789 | ||
| 606 | get_online_cpus(); | 790 | get_online_cpus(); |
| 607 | cpumask_clear_cpu(cpu, pinst->cpumask); | 791 | if (mask & PADATA_CPU_SERIAL) |
| 792 | cpumask_clear_cpu(cpu, pinst->cpumask.cbcpu); | ||
| 793 | if (mask & PADATA_CPU_PARALLEL) | ||
| 794 | cpumask_clear_cpu(cpu, pinst->cpumask.pcpu); | ||
| 795 | |||
| 608 | err = __padata_remove_cpu(pinst, cpu); | 796 | err = __padata_remove_cpu(pinst, cpu); |
| 609 | put_online_cpus(); | 797 | put_online_cpus(); |
| 610 | 798 | ||
| @@ -619,11 +807,20 @@ EXPORT_SYMBOL(padata_remove_cpu); | |||
| 619 | * | 807 | * |
| 620 | * @pinst: padata instance to start | 808 | * @pinst: padata instance to start |
| 621 | */ | 809 | */ |
| 622 | void padata_start(struct padata_instance *pinst) | 810 | int padata_start(struct padata_instance *pinst) |
| 623 | { | 811 | { |
| 812 | int err = 0; | ||
| 813 | |||
| 624 | mutex_lock(&pinst->lock); | 814 | mutex_lock(&pinst->lock); |
| 625 | pinst->flags |= PADATA_INIT; | 815 | |
| 816 | if (pinst->flags & PADATA_INVALID) | ||
| 817 | err =-EINVAL; | ||
| 818 | |||
| 819 | __padata_start(pinst); | ||
| 820 | |||
| 626 | mutex_unlock(&pinst->lock); | 821 | mutex_unlock(&pinst->lock); |
| 822 | |||
| 823 | return err; | ||
| 627 | } | 824 | } |
| 628 | EXPORT_SYMBOL(padata_start); | 825 | EXPORT_SYMBOL(padata_start); |
| 629 | 826 | ||
| @@ -635,12 +832,20 @@ EXPORT_SYMBOL(padata_start); | |||
| 635 | void padata_stop(struct padata_instance *pinst) | 832 | void padata_stop(struct padata_instance *pinst) |
| 636 | { | 833 | { |
| 637 | mutex_lock(&pinst->lock); | 834 | mutex_lock(&pinst->lock); |
| 638 | pinst->flags &= ~PADATA_INIT; | 835 | __padata_stop(pinst); |
| 639 | mutex_unlock(&pinst->lock); | 836 | mutex_unlock(&pinst->lock); |
| 640 | } | 837 | } |
| 641 | EXPORT_SYMBOL(padata_stop); | 838 | EXPORT_SYMBOL(padata_stop); |
| 642 | 839 | ||
| 643 | #ifdef CONFIG_HOTPLUG_CPU | 840 | #ifdef CONFIG_HOTPLUG_CPU |
| 841 | |||
| 842 | static inline int pinst_has_cpu(struct padata_instance *pinst, int cpu) | ||
| 843 | { | ||
| 844 | return cpumask_test_cpu(cpu, pinst->cpumask.pcpu) || | ||
| 845 | cpumask_test_cpu(cpu, pinst->cpumask.cbcpu); | ||
| 846 | } | ||
| 847 | |||
| 848 | |||
| 644 | static int padata_cpu_callback(struct notifier_block *nfb, | 849 | static int padata_cpu_callback(struct notifier_block *nfb, |
| 645 | unsigned long action, void *hcpu) | 850 | unsigned long action, void *hcpu) |
| 646 | { | 851 | { |
| @@ -653,7 +858,7 @@ static int padata_cpu_callback(struct notifier_block *nfb, | |||
| 653 | switch (action) { | 858 | switch (action) { |
| 654 | case CPU_ONLINE: | 859 | case CPU_ONLINE: |
| 655 | case CPU_ONLINE_FROZEN: | 860 | case CPU_ONLINE_FROZEN: |
| 656 | if (!cpumask_test_cpu(cpu, pinst->cpumask)) | 861 | if (!pinst_has_cpu(pinst, cpu)) |
| 657 | break; | 862 | break; |
| 658 | mutex_lock(&pinst->lock); | 863 | mutex_lock(&pinst->lock); |
| 659 | err = __padata_add_cpu(pinst, cpu); | 864 | err = __padata_add_cpu(pinst, cpu); |
| @@ -664,7 +869,7 @@ static int padata_cpu_callback(struct notifier_block *nfb, | |||
| 664 | 869 | ||
| 665 | case CPU_DOWN_PREPARE: | 870 | case CPU_DOWN_PREPARE: |
| 666 | case CPU_DOWN_PREPARE_FROZEN: | 871 | case CPU_DOWN_PREPARE_FROZEN: |
| 667 | if (!cpumask_test_cpu(cpu, pinst->cpumask)) | 872 | if (!pinst_has_cpu(pinst, cpu)) |
| 668 | break; | 873 | break; |
| 669 | mutex_lock(&pinst->lock); | 874 | mutex_lock(&pinst->lock); |
| 670 | err = __padata_remove_cpu(pinst, cpu); | 875 | err = __padata_remove_cpu(pinst, cpu); |
| @@ -675,7 +880,7 @@ static int padata_cpu_callback(struct notifier_block *nfb, | |||
| 675 | 880 | ||
| 676 | case CPU_UP_CANCELED: | 881 | case CPU_UP_CANCELED: |
| 677 | case CPU_UP_CANCELED_FROZEN: | 882 | case CPU_UP_CANCELED_FROZEN: |
| 678 | if (!cpumask_test_cpu(cpu, pinst->cpumask)) | 883 | if (!pinst_has_cpu(pinst, cpu)) |
| 679 | break; | 884 | break; |
| 680 | mutex_lock(&pinst->lock); | 885 | mutex_lock(&pinst->lock); |
| 681 | __padata_remove_cpu(pinst, cpu); | 886 | __padata_remove_cpu(pinst, cpu); |
| @@ -683,7 +888,7 @@ static int padata_cpu_callback(struct notifier_block *nfb, | |||
| 683 | 888 | ||
| 684 | case CPU_DOWN_FAILED: | 889 | case CPU_DOWN_FAILED: |
| 685 | case CPU_DOWN_FAILED_FROZEN: | 890 | case CPU_DOWN_FAILED_FROZEN: |
| 686 | if (!cpumask_test_cpu(cpu, pinst->cpumask)) | 891 | if (!pinst_has_cpu(pinst, cpu)) |
| 687 | break; | 892 | break; |
| 688 | mutex_lock(&pinst->lock); | 893 | mutex_lock(&pinst->lock); |
| 689 | __padata_add_cpu(pinst, cpu); | 894 | __padata_add_cpu(pinst, cpu); |
| @@ -694,36 +899,202 @@ static int padata_cpu_callback(struct notifier_block *nfb, | |||
| 694 | } | 899 | } |
| 695 | #endif | 900 | #endif |
| 696 | 901 | ||
| 902 | static void __padata_free(struct padata_instance *pinst) | ||
| 903 | { | ||
| 904 | #ifdef CONFIG_HOTPLUG_CPU | ||
| 905 | unregister_hotcpu_notifier(&pinst->cpu_notifier); | ||
| 906 | #endif | ||
| 907 | |||
| 908 | padata_stop(pinst); | ||
| 909 | padata_free_pd(pinst->pd); | ||
| 910 | free_cpumask_var(pinst->cpumask.pcpu); | ||
| 911 | free_cpumask_var(pinst->cpumask.cbcpu); | ||
| 912 | kfree(pinst); | ||
| 913 | } | ||
| 914 | |||
| 915 | #define kobj2pinst(_kobj) \ | ||
| 916 | container_of(_kobj, struct padata_instance, kobj) | ||
| 917 | #define attr2pentry(_attr) \ | ||
| 918 | container_of(_attr, struct padata_sysfs_entry, attr) | ||
| 919 | |||
| 920 | static void padata_sysfs_release(struct kobject *kobj) | ||
| 921 | { | ||
| 922 | struct padata_instance *pinst = kobj2pinst(kobj); | ||
| 923 | __padata_free(pinst); | ||
| 924 | } | ||
| 925 | |||
| 926 | struct padata_sysfs_entry { | ||
| 927 | struct attribute attr; | ||
| 928 | ssize_t (*show)(struct padata_instance *, struct attribute *, char *); | ||
| 929 | ssize_t (*store)(struct padata_instance *, struct attribute *, | ||
| 930 | const char *, size_t); | ||
| 931 | }; | ||
| 932 | |||
| 933 | static ssize_t show_cpumask(struct padata_instance *pinst, | ||
| 934 | struct attribute *attr, char *buf) | ||
| 935 | { | ||
| 936 | struct cpumask *cpumask; | ||
| 937 | ssize_t len; | ||
| 938 | |||
| 939 | mutex_lock(&pinst->lock); | ||
| 940 | if (!strcmp(attr->name, "serial_cpumask")) | ||
| 941 | cpumask = pinst->cpumask.cbcpu; | ||
| 942 | else | ||
| 943 | cpumask = pinst->cpumask.pcpu; | ||
| 944 | |||
| 945 | len = bitmap_scnprintf(buf, PAGE_SIZE, cpumask_bits(cpumask), | ||
| 946 | nr_cpu_ids); | ||
| 947 | if (PAGE_SIZE - len < 2) | ||
| 948 | len = -EINVAL; | ||
| 949 | else | ||
| 950 | len += sprintf(buf + len, "\n"); | ||
| 951 | |||
| 952 | mutex_unlock(&pinst->lock); | ||
| 953 | return len; | ||
| 954 | } | ||
| 955 | |||
| 956 | static ssize_t store_cpumask(struct padata_instance *pinst, | ||
| 957 | struct attribute *attr, | ||
| 958 | const char *buf, size_t count) | ||
| 959 | { | ||
| 960 | cpumask_var_t new_cpumask; | ||
| 961 | ssize_t ret; | ||
| 962 | int mask_type; | ||
| 963 | |||
| 964 | if (!alloc_cpumask_var(&new_cpumask, GFP_KERNEL)) | ||
| 965 | return -ENOMEM; | ||
| 966 | |||
| 967 | ret = bitmap_parse(buf, count, cpumask_bits(new_cpumask), | ||
| 968 | nr_cpumask_bits); | ||
| 969 | if (ret < 0) | ||
| 970 | goto out; | ||
| 971 | |||
| 972 | mask_type = !strcmp(attr->name, "serial_cpumask") ? | ||
| 973 | PADATA_CPU_SERIAL : PADATA_CPU_PARALLEL; | ||
| 974 | ret = padata_set_cpumask(pinst, mask_type, new_cpumask); | ||
| 975 | if (!ret) | ||
| 976 | ret = count; | ||
| 977 | |||
| 978 | out: | ||
| 979 | free_cpumask_var(new_cpumask); | ||
| 980 | return ret; | ||
| 981 | } | ||
| 982 | |||
| 983 | #define PADATA_ATTR_RW(_name, _show_name, _store_name) \ | ||
| 984 | static struct padata_sysfs_entry _name##_attr = \ | ||
| 985 | __ATTR(_name, 0644, _show_name, _store_name) | ||
| 986 | #define PADATA_ATTR_RO(_name, _show_name) \ | ||
| 987 | static struct padata_sysfs_entry _name##_attr = \ | ||
| 988 | __ATTR(_name, 0400, _show_name, NULL) | ||
| 989 | |||
| 990 | PADATA_ATTR_RW(serial_cpumask, show_cpumask, store_cpumask); | ||
| 991 | PADATA_ATTR_RW(parallel_cpumask, show_cpumask, store_cpumask); | ||
| 992 | |||
| 993 | /* | ||
| 994 | * Padata sysfs provides the following objects: | ||
| 995 | * serial_cpumask [RW] - cpumask for serial workers | ||
| 996 | * parallel_cpumask [RW] - cpumask for parallel workers | ||
| 997 | */ | ||
| 998 | static struct attribute *padata_default_attrs[] = { | ||
| 999 | &serial_cpumask_attr.attr, | ||
| 1000 | ¶llel_cpumask_attr.attr, | ||
| 1001 | NULL, | ||
| 1002 | }; | ||
| 1003 | |||
| 1004 | static ssize_t padata_sysfs_show(struct kobject *kobj, | ||
| 1005 | struct attribute *attr, char *buf) | ||
| 1006 | { | ||
| 1007 | struct padata_instance *pinst; | ||
| 1008 | struct padata_sysfs_entry *pentry; | ||
| 1009 | ssize_t ret = -EIO; | ||
| 1010 | |||
| 1011 | pinst = kobj2pinst(kobj); | ||
| 1012 | pentry = attr2pentry(attr); | ||
| 1013 | if (pentry->show) | ||
| 1014 | ret = pentry->show(pinst, attr, buf); | ||
| 1015 | |||
| 1016 | return ret; | ||
| 1017 | } | ||
| 1018 | |||
| 1019 | static ssize_t padata_sysfs_store(struct kobject *kobj, struct attribute *attr, | ||
| 1020 | const char *buf, size_t count) | ||
| 1021 | { | ||
| 1022 | struct padata_instance *pinst; | ||
| 1023 | struct padata_sysfs_entry *pentry; | ||
| 1024 | ssize_t ret = -EIO; | ||
| 1025 | |||
| 1026 | pinst = kobj2pinst(kobj); | ||
| 1027 | pentry = attr2pentry(attr); | ||
| 1028 | if (pentry->show) | ||
| 1029 | ret = pentry->store(pinst, attr, buf, count); | ||
| 1030 | |||
| 1031 | return ret; | ||
| 1032 | } | ||
| 1033 | |||
| 1034 | static const struct sysfs_ops padata_sysfs_ops = { | ||
| 1035 | .show = padata_sysfs_show, | ||
| 1036 | .store = padata_sysfs_store, | ||
| 1037 | }; | ||
| 1038 | |||
| 1039 | static struct kobj_type padata_attr_type = { | ||
| 1040 | .sysfs_ops = &padata_sysfs_ops, | ||
| 1041 | .default_attrs = padata_default_attrs, | ||
| 1042 | .release = padata_sysfs_release, | ||
| 1043 | }; | ||
| 1044 | |||
| 697 | /** | 1045 | /** |
| 698 | * padata_alloc - allocate and initialize a padata instance | 1046 | * padata_alloc_possible - Allocate and initialize padata instance. |
| 1047 | * Use the cpu_possible_mask for serial and | ||
| 1048 | * parallel workers. | ||
| 699 | * | 1049 | * |
| 700 | * @cpumask: cpumask that padata uses for parallelization | ||
| 701 | * @wq: workqueue to use for the allocated padata instance | 1050 | * @wq: workqueue to use for the allocated padata instance |
| 702 | */ | 1051 | */ |
| 703 | struct padata_instance *padata_alloc(const struct cpumask *cpumask, | 1052 | struct padata_instance *padata_alloc_possible(struct workqueue_struct *wq) |
| 704 | struct workqueue_struct *wq) | 1053 | { |
| 1054 | return padata_alloc(wq, cpu_possible_mask, cpu_possible_mask); | ||
| 1055 | } | ||
| 1056 | EXPORT_SYMBOL(padata_alloc_possible); | ||
| 1057 | |||
| 1058 | /** | ||
| 1059 | * padata_alloc - allocate and initialize a padata instance and specify | ||
| 1060 | * cpumasks for serial and parallel workers. | ||
| 1061 | * | ||
| 1062 | * @wq: workqueue to use for the allocated padata instance | ||
| 1063 | * @pcpumask: cpumask that will be used for padata parallelization | ||
| 1064 | * @cbcpumask: cpumask that will be used for padata serialization | ||
| 1065 | */ | ||
| 1066 | struct padata_instance *padata_alloc(struct workqueue_struct *wq, | ||
| 1067 | const struct cpumask *pcpumask, | ||
| 1068 | const struct cpumask *cbcpumask) | ||
| 705 | { | 1069 | { |
| 706 | struct padata_instance *pinst; | 1070 | struct padata_instance *pinst; |
| 707 | struct parallel_data *pd; | 1071 | struct parallel_data *pd = NULL; |
| 708 | 1072 | ||
| 709 | pinst = kzalloc(sizeof(struct padata_instance), GFP_KERNEL); | 1073 | pinst = kzalloc(sizeof(struct padata_instance), GFP_KERNEL); |
| 710 | if (!pinst) | 1074 | if (!pinst) |
| 711 | goto err; | 1075 | goto err; |
| 712 | 1076 | ||
| 713 | get_online_cpus(); | 1077 | get_online_cpus(); |
| 714 | 1078 | if (!alloc_cpumask_var(&pinst->cpumask.pcpu, GFP_KERNEL)) | |
| 715 | pd = padata_alloc_pd(pinst, cpumask); | ||
| 716 | if (!pd) | ||
| 717 | goto err_free_inst; | 1079 | goto err_free_inst; |
| 1080 | if (!alloc_cpumask_var(&pinst->cpumask.cbcpu, GFP_KERNEL)) { | ||
| 1081 | free_cpumask_var(pinst->cpumask.pcpu); | ||
| 1082 | goto err_free_inst; | ||
| 1083 | } | ||
| 1084 | if (!padata_validate_cpumask(pinst, pcpumask) || | ||
| 1085 | !padata_validate_cpumask(pinst, cbcpumask)) | ||
| 1086 | goto err_free_masks; | ||
| 718 | 1087 | ||
| 719 | if (!alloc_cpumask_var(&pinst->cpumask, GFP_KERNEL)) | 1088 | pd = padata_alloc_pd(pinst, pcpumask, cbcpumask); |
| 720 | goto err_free_pd; | 1089 | if (!pd) |
| 1090 | goto err_free_masks; | ||
| 721 | 1091 | ||
| 722 | rcu_assign_pointer(pinst->pd, pd); | 1092 | rcu_assign_pointer(pinst->pd, pd); |
| 723 | 1093 | ||
| 724 | pinst->wq = wq; | 1094 | pinst->wq = wq; |
| 725 | 1095 | ||
| 726 | cpumask_copy(pinst->cpumask, cpumask); | 1096 | cpumask_copy(pinst->cpumask.pcpu, pcpumask); |
| 1097 | cpumask_copy(pinst->cpumask.cbcpu, cbcpumask); | ||
| 727 | 1098 | ||
| 728 | pinst->flags = 0; | 1099 | pinst->flags = 0; |
| 729 | 1100 | ||
| @@ -735,12 +1106,15 @@ struct padata_instance *padata_alloc(const struct cpumask *cpumask, | |||
| 735 | 1106 | ||
| 736 | put_online_cpus(); | 1107 | put_online_cpus(); |
| 737 | 1108 | ||
| 1109 | BLOCKING_INIT_NOTIFIER_HEAD(&pinst->cpumask_change_notifier); | ||
| 1110 | kobject_init(&pinst->kobj, &padata_attr_type); | ||
| 738 | mutex_init(&pinst->lock); | 1111 | mutex_init(&pinst->lock); |
| 739 | 1112 | ||
| 740 | return pinst; | 1113 | return pinst; |
| 741 | 1114 | ||
| 742 | err_free_pd: | 1115 | err_free_masks: |
| 743 | padata_free_pd(pd); | 1116 | free_cpumask_var(pinst->cpumask.pcpu); |
| 1117 | free_cpumask_var(pinst->cpumask.cbcpu); | ||
| 744 | err_free_inst: | 1118 | err_free_inst: |
| 745 | kfree(pinst); | 1119 | kfree(pinst); |
| 746 | put_online_cpus(); | 1120 | put_online_cpus(); |
| @@ -756,19 +1130,6 @@ EXPORT_SYMBOL(padata_alloc); | |||
| 756 | */ | 1130 | */ |
| 757 | void padata_free(struct padata_instance *pinst) | 1131 | void padata_free(struct padata_instance *pinst) |
| 758 | { | 1132 | { |
| 759 | padata_stop(pinst); | 1133 | kobject_put(&pinst->kobj); |
| 760 | |||
| 761 | synchronize_rcu(); | ||
| 762 | |||
| 763 | #ifdef CONFIG_HOTPLUG_CPU | ||
| 764 | unregister_hotcpu_notifier(&pinst->cpu_notifier); | ||
| 765 | #endif | ||
| 766 | get_online_cpus(); | ||
| 767 | padata_flush_queues(pinst->pd); | ||
| 768 | put_online_cpus(); | ||
| 769 | |||
| 770 | padata_free_pd(pinst->pd); | ||
| 771 | free_cpumask_var(pinst->cpumask); | ||
| 772 | kfree(pinst); | ||
| 773 | } | 1134 | } |
| 774 | EXPORT_SYMBOL(padata_free); | 1135 | EXPORT_SYMBOL(padata_free); |
diff --git a/kernel/pm_qos_params.c b/kernel/pm_qos_params.c index f42d3f737a33..996a4dec5f96 100644 --- a/kernel/pm_qos_params.c +++ b/kernel/pm_qos_params.c | |||
| @@ -48,59 +48,49 @@ | |||
| 48 | * or pm_qos_object list and pm_qos_objects need to happen with pm_qos_lock | 48 | * or pm_qos_object list and pm_qos_objects need to happen with pm_qos_lock |
| 49 | * held, taken with _irqsave. One lock to rule them all | 49 | * held, taken with _irqsave. One lock to rule them all |
| 50 | */ | 50 | */ |
| 51 | struct pm_qos_request_list { | 51 | enum pm_qos_type { |
| 52 | struct list_head list; | 52 | PM_QOS_MAX, /* return the largest value */ |
| 53 | union { | 53 | PM_QOS_MIN /* return the smallest value */ |
| 54 | s32 value; | ||
| 55 | s32 usec; | ||
| 56 | s32 kbps; | ||
| 57 | }; | ||
| 58 | int pm_qos_class; | ||
| 59 | }; | 54 | }; |
| 60 | 55 | ||
| 61 | static s32 max_compare(s32 v1, s32 v2); | ||
| 62 | static s32 min_compare(s32 v1, s32 v2); | ||
| 63 | |||
| 64 | struct pm_qos_object { | 56 | struct pm_qos_object { |
| 65 | struct pm_qos_request_list requests; | 57 | struct plist_head requests; |
| 66 | struct blocking_notifier_head *notifiers; | 58 | struct blocking_notifier_head *notifiers; |
| 67 | struct miscdevice pm_qos_power_miscdev; | 59 | struct miscdevice pm_qos_power_miscdev; |
| 68 | char *name; | 60 | char *name; |
| 69 | s32 default_value; | 61 | s32 default_value; |
| 70 | atomic_t target_value; | 62 | enum pm_qos_type type; |
| 71 | s32 (*comparitor)(s32, s32); | ||
| 72 | }; | 63 | }; |
| 73 | 64 | ||
| 65 | static DEFINE_SPINLOCK(pm_qos_lock); | ||
| 66 | |||
| 74 | static struct pm_qos_object null_pm_qos; | 67 | static struct pm_qos_object null_pm_qos; |
| 75 | static BLOCKING_NOTIFIER_HEAD(cpu_dma_lat_notifier); | 68 | static BLOCKING_NOTIFIER_HEAD(cpu_dma_lat_notifier); |
| 76 | static struct pm_qos_object cpu_dma_pm_qos = { | 69 | static struct pm_qos_object cpu_dma_pm_qos = { |
| 77 | .requests = {LIST_HEAD_INIT(cpu_dma_pm_qos.requests.list)}, | 70 | .requests = PLIST_HEAD_INIT(cpu_dma_pm_qos.requests, pm_qos_lock), |
| 78 | .notifiers = &cpu_dma_lat_notifier, | 71 | .notifiers = &cpu_dma_lat_notifier, |
| 79 | .name = "cpu_dma_latency", | 72 | .name = "cpu_dma_latency", |
| 80 | .default_value = 2000 * USEC_PER_SEC, | 73 | .default_value = 2000 * USEC_PER_SEC, |
| 81 | .target_value = ATOMIC_INIT(2000 * USEC_PER_SEC), | 74 | .type = PM_QOS_MIN, |
| 82 | .comparitor = min_compare | ||
| 83 | }; | 75 | }; |
| 84 | 76 | ||
| 85 | static BLOCKING_NOTIFIER_HEAD(network_lat_notifier); | 77 | static BLOCKING_NOTIFIER_HEAD(network_lat_notifier); |
| 86 | static struct pm_qos_object network_lat_pm_qos = { | 78 | static struct pm_qos_object network_lat_pm_qos = { |
| 87 | .requests = {LIST_HEAD_INIT(network_lat_pm_qos.requests.list)}, | 79 | .requests = PLIST_HEAD_INIT(network_lat_pm_qos.requests, pm_qos_lock), |
| 88 | .notifiers = &network_lat_notifier, | 80 | .notifiers = &network_lat_notifier, |
| 89 | .name = "network_latency", | 81 | .name = "network_latency", |
| 90 | .default_value = 2000 * USEC_PER_SEC, | 82 | .default_value = 2000 * USEC_PER_SEC, |
| 91 | .target_value = ATOMIC_INIT(2000 * USEC_PER_SEC), | 83 | .type = PM_QOS_MIN |
| 92 | .comparitor = min_compare | ||
| 93 | }; | 84 | }; |
| 94 | 85 | ||
| 95 | 86 | ||
| 96 | static BLOCKING_NOTIFIER_HEAD(network_throughput_notifier); | 87 | static BLOCKING_NOTIFIER_HEAD(network_throughput_notifier); |
| 97 | static struct pm_qos_object network_throughput_pm_qos = { | 88 | static struct pm_qos_object network_throughput_pm_qos = { |
| 98 | .requests = {LIST_HEAD_INIT(network_throughput_pm_qos.requests.list)}, | 89 | .requests = PLIST_HEAD_INIT(network_throughput_pm_qos.requests, pm_qos_lock), |
| 99 | .notifiers = &network_throughput_notifier, | 90 | .notifiers = &network_throughput_notifier, |
| 100 | .name = "network_throughput", | 91 | .name = "network_throughput", |
| 101 | .default_value = 0, | 92 | .default_value = 0, |
| 102 | .target_value = ATOMIC_INIT(0), | 93 | .type = PM_QOS_MAX, |
| 103 | .comparitor = max_compare | ||
| 104 | }; | 94 | }; |
| 105 | 95 | ||
| 106 | 96 | ||
| @@ -111,8 +101,6 @@ static struct pm_qos_object *pm_qos_array[] = { | |||
| 111 | &network_throughput_pm_qos | 101 | &network_throughput_pm_qos |
| 112 | }; | 102 | }; |
| 113 | 103 | ||
| 114 | static DEFINE_SPINLOCK(pm_qos_lock); | ||
| 115 | |||
| 116 | static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf, | 104 | static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf, |
| 117 | size_t count, loff_t *f_pos); | 105 | size_t count, loff_t *f_pos); |
| 118 | static int pm_qos_power_open(struct inode *inode, struct file *filp); | 106 | static int pm_qos_power_open(struct inode *inode, struct file *filp); |
| @@ -124,46 +112,55 @@ static const struct file_operations pm_qos_power_fops = { | |||
| 124 | .release = pm_qos_power_release, | 112 | .release = pm_qos_power_release, |
| 125 | }; | 113 | }; |
| 126 | 114 | ||
| 127 | /* static helper functions */ | 115 | /* unlocked internal variant */ |
| 128 | static s32 max_compare(s32 v1, s32 v2) | 116 | static inline int pm_qos_get_value(struct pm_qos_object *o) |
| 129 | { | 117 | { |
| 130 | return max(v1, v2); | 118 | if (plist_head_empty(&o->requests)) |
| 131 | } | 119 | return o->default_value; |
| 132 | 120 | ||
| 133 | static s32 min_compare(s32 v1, s32 v2) | 121 | switch (o->type) { |
| 134 | { | 122 | case PM_QOS_MIN: |
| 135 | return min(v1, v2); | 123 | return plist_last(&o->requests)->prio; |
| 136 | } | ||
| 137 | 124 | ||
| 125 | case PM_QOS_MAX: | ||
| 126 | return plist_first(&o->requests)->prio; | ||
| 138 | 127 | ||
| 139 | static void update_target(int pm_qos_class) | 128 | default: |
| 129 | /* runtime check for not using enum */ | ||
| 130 | BUG(); | ||
| 131 | } | ||
| 132 | } | ||
| 133 | |||
| 134 | static void update_target(struct pm_qos_object *o, struct plist_node *node, | ||
| 135 | int del, int value) | ||
| 140 | { | 136 | { |
| 141 | s32 extreme_value; | ||
| 142 | struct pm_qos_request_list *node; | ||
| 143 | unsigned long flags; | 137 | unsigned long flags; |
| 144 | int call_notifier = 0; | 138 | int prev_value, curr_value; |
| 145 | 139 | ||
| 146 | spin_lock_irqsave(&pm_qos_lock, flags); | 140 | spin_lock_irqsave(&pm_qos_lock, flags); |
| 147 | extreme_value = pm_qos_array[pm_qos_class]->default_value; | 141 | prev_value = pm_qos_get_value(o); |
| 148 | list_for_each_entry(node, | 142 | /* PM_QOS_DEFAULT_VALUE is a signal that the value is unchanged */ |
| 149 | &pm_qos_array[pm_qos_class]->requests.list, list) { | 143 | if (value != PM_QOS_DEFAULT_VALUE) { |
| 150 | extreme_value = pm_qos_array[pm_qos_class]->comparitor( | 144 | /* |
| 151 | extreme_value, node->value); | 145 | * to change the list, we atomically remove, reinit |
| 152 | } | 146 | * with new value and add, then see if the extremal |
| 153 | if (atomic_read(&pm_qos_array[pm_qos_class]->target_value) != | 147 | * changed |
| 154 | extreme_value) { | 148 | */ |
| 155 | call_notifier = 1; | 149 | plist_del(node, &o->requests); |
| 156 | atomic_set(&pm_qos_array[pm_qos_class]->target_value, | 150 | plist_node_init(node, value); |
| 157 | extreme_value); | 151 | plist_add(node, &o->requests); |
| 158 | pr_debug(KERN_ERR "new target for qos %d is %d\n", pm_qos_class, | 152 | } else if (del) { |
| 159 | atomic_read(&pm_qos_array[pm_qos_class]->target_value)); | 153 | plist_del(node, &o->requests); |
| 154 | } else { | ||
| 155 | plist_add(node, &o->requests); | ||
| 160 | } | 156 | } |
| 157 | curr_value = pm_qos_get_value(o); | ||
| 161 | spin_unlock_irqrestore(&pm_qos_lock, flags); | 158 | spin_unlock_irqrestore(&pm_qos_lock, flags); |
| 162 | 159 | ||
| 163 | if (call_notifier) | 160 | if (prev_value != curr_value) |
| 164 | blocking_notifier_call_chain( | 161 | blocking_notifier_call_chain(o->notifiers, |
| 165 | pm_qos_array[pm_qos_class]->notifiers, | 162 | (unsigned long)curr_value, |
| 166 | (unsigned long) extreme_value, NULL); | 163 | NULL); |
| 167 | } | 164 | } |
| 168 | 165 | ||
| 169 | static int register_pm_qos_misc(struct pm_qos_object *qos) | 166 | static int register_pm_qos_misc(struct pm_qos_object *qos) |
| @@ -196,10 +193,23 @@ static int find_pm_qos_object_by_minor(int minor) | |||
| 196 | */ | 193 | */ |
| 197 | int pm_qos_request(int pm_qos_class) | 194 | int pm_qos_request(int pm_qos_class) |
| 198 | { | 195 | { |
| 199 | return atomic_read(&pm_qos_array[pm_qos_class]->target_value); | 196 | unsigned long flags; |
| 197 | int value; | ||
| 198 | |||
| 199 | spin_lock_irqsave(&pm_qos_lock, flags); | ||
| 200 | value = pm_qos_get_value(pm_qos_array[pm_qos_class]); | ||
| 201 | spin_unlock_irqrestore(&pm_qos_lock, flags); | ||
| 202 | |||
| 203 | return value; | ||
| 200 | } | 204 | } |
| 201 | EXPORT_SYMBOL_GPL(pm_qos_request); | 205 | EXPORT_SYMBOL_GPL(pm_qos_request); |
| 202 | 206 | ||
| 207 | int pm_qos_request_active(struct pm_qos_request_list *req) | ||
| 208 | { | ||
| 209 | return req->pm_qos_class != 0; | ||
| 210 | } | ||
| 211 | EXPORT_SYMBOL_GPL(pm_qos_request_active); | ||
| 212 | |||
| 203 | /** | 213 | /** |
| 204 | * pm_qos_add_request - inserts new qos request into the list | 214 | * pm_qos_add_request - inserts new qos request into the list |
| 205 | * @pm_qos_class: identifies which list of qos request to us | 215 | * @pm_qos_class: identifies which list of qos request to us |
| @@ -211,27 +221,23 @@ EXPORT_SYMBOL_GPL(pm_qos_request); | |||
| 211 | * element as a handle for use in updating and removal. Call needs to save | 221 | * element as a handle for use in updating and removal. Call needs to save |
| 212 | * this handle for later use. | 222 | * this handle for later use. |
| 213 | */ | 223 | */ |
| 214 | struct pm_qos_request_list *pm_qos_add_request(int pm_qos_class, s32 value) | 224 | void pm_qos_add_request(struct pm_qos_request_list *dep, |
| 225 | int pm_qos_class, s32 value) | ||
| 215 | { | 226 | { |
| 216 | struct pm_qos_request_list *dep; | 227 | struct pm_qos_object *o = pm_qos_array[pm_qos_class]; |
| 217 | unsigned long flags; | 228 | int new_value; |
| 218 | 229 | ||
| 219 | dep = kzalloc(sizeof(struct pm_qos_request_list), GFP_KERNEL); | 230 | if (pm_qos_request_active(dep)) { |
| 220 | if (dep) { | 231 | WARN(1, KERN_ERR "pm_qos_add_request() called for already added request\n"); |
| 221 | if (value == PM_QOS_DEFAULT_VALUE) | 232 | return; |
| 222 | dep->value = pm_qos_array[pm_qos_class]->default_value; | ||
| 223 | else | ||
| 224 | dep->value = value; | ||
| 225 | dep->pm_qos_class = pm_qos_class; | ||
| 226 | |||
| 227 | spin_lock_irqsave(&pm_qos_lock, flags); | ||
| 228 | list_add(&dep->list, | ||
| 229 | &pm_qos_array[pm_qos_class]->requests.list); | ||
| 230 | spin_unlock_irqrestore(&pm_qos_lock, flags); | ||
| 231 | update_target(pm_qos_class); | ||
| 232 | } | 233 | } |
| 233 | 234 | if (value == PM_QOS_DEFAULT_VALUE) | |
| 234 | return dep; | 235 | new_value = o->default_value; |
| 236 | else | ||
| 237 | new_value = value; | ||
| 238 | plist_node_init(&dep->list, new_value); | ||
| 239 | dep->pm_qos_class = pm_qos_class; | ||
| 240 | update_target(o, &dep->list, 0, PM_QOS_DEFAULT_VALUE); | ||
| 235 | } | 241 | } |
| 236 | EXPORT_SYMBOL_GPL(pm_qos_add_request); | 242 | EXPORT_SYMBOL_GPL(pm_qos_add_request); |
| 237 | 243 | ||
| @@ -246,27 +252,28 @@ EXPORT_SYMBOL_GPL(pm_qos_add_request); | |||
| 246 | * Attempts are made to make this code callable on hot code paths. | 252 | * Attempts are made to make this code callable on hot code paths. |
| 247 | */ | 253 | */ |
| 248 | void pm_qos_update_request(struct pm_qos_request_list *pm_qos_req, | 254 | void pm_qos_update_request(struct pm_qos_request_list *pm_qos_req, |
| 249 | s32 new_value) | 255 | s32 new_value) |
| 250 | { | 256 | { |
| 251 | unsigned long flags; | ||
| 252 | int pending_update = 0; | ||
| 253 | s32 temp; | 257 | s32 temp; |
| 258 | struct pm_qos_object *o; | ||
| 259 | |||
| 260 | if (!pm_qos_req) /*guard against callers passing in null */ | ||
| 261 | return; | ||
| 254 | 262 | ||
| 255 | if (pm_qos_req) { /*guard against callers passing in null */ | 263 | if (!pm_qos_request_active(pm_qos_req)) { |
| 256 | spin_lock_irqsave(&pm_qos_lock, flags); | 264 | WARN(1, KERN_ERR "pm_qos_update_request() called for unknown object\n"); |
| 257 | if (new_value == PM_QOS_DEFAULT_VALUE) | 265 | return; |
| 258 | temp = pm_qos_array[pm_qos_req->pm_qos_class]->default_value; | ||
| 259 | else | ||
| 260 | temp = new_value; | ||
| 261 | |||
| 262 | if (temp != pm_qos_req->value) { | ||
| 263 | pending_update = 1; | ||
| 264 | pm_qos_req->value = temp; | ||
| 265 | } | ||
| 266 | spin_unlock_irqrestore(&pm_qos_lock, flags); | ||
| 267 | if (pending_update) | ||
| 268 | update_target(pm_qos_req->pm_qos_class); | ||
| 269 | } | 266 | } |
| 267 | |||
| 268 | o = pm_qos_array[pm_qos_req->pm_qos_class]; | ||
| 269 | |||
| 270 | if (new_value == PM_QOS_DEFAULT_VALUE) | ||
| 271 | temp = o->default_value; | ||
| 272 | else | ||
| 273 | temp = new_value; | ||
| 274 | |||
| 275 | if (temp != pm_qos_req->list.prio) | ||
| 276 | update_target(o, &pm_qos_req->list, 0, temp); | ||
| 270 | } | 277 | } |
| 271 | EXPORT_SYMBOL_GPL(pm_qos_update_request); | 278 | EXPORT_SYMBOL_GPL(pm_qos_update_request); |
| 272 | 279 | ||
| @@ -280,19 +287,20 @@ EXPORT_SYMBOL_GPL(pm_qos_update_request); | |||
| 280 | */ | 287 | */ |
| 281 | void pm_qos_remove_request(struct pm_qos_request_list *pm_qos_req) | 288 | void pm_qos_remove_request(struct pm_qos_request_list *pm_qos_req) |
| 282 | { | 289 | { |
| 283 | unsigned long flags; | 290 | struct pm_qos_object *o; |
| 284 | int qos_class; | ||
| 285 | 291 | ||
| 286 | if (pm_qos_req == NULL) | 292 | if (pm_qos_req == NULL) |
| 287 | return; | 293 | return; |
| 288 | /* silent return to keep pcm code cleaner */ | 294 | /* silent return to keep pcm code cleaner */ |
| 289 | 295 | ||
| 290 | qos_class = pm_qos_req->pm_qos_class; | 296 | if (!pm_qos_request_active(pm_qos_req)) { |
| 291 | spin_lock_irqsave(&pm_qos_lock, flags); | 297 | WARN(1, KERN_ERR "pm_qos_remove_request() called for unknown object\n"); |
| 292 | list_del(&pm_qos_req->list); | 298 | return; |
| 293 | kfree(pm_qos_req); | 299 | } |
| 294 | spin_unlock_irqrestore(&pm_qos_lock, flags); | 300 | |
| 295 | update_target(qos_class); | 301 | o = pm_qos_array[pm_qos_req->pm_qos_class]; |
| 302 | update_target(o, &pm_qos_req->list, 1, PM_QOS_DEFAULT_VALUE); | ||
| 303 | memset(pm_qos_req, 0, sizeof(*pm_qos_req)); | ||
| 296 | } | 304 | } |
| 297 | EXPORT_SYMBOL_GPL(pm_qos_remove_request); | 305 | EXPORT_SYMBOL_GPL(pm_qos_remove_request); |
| 298 | 306 | ||
| @@ -340,8 +348,12 @@ static int pm_qos_power_open(struct inode *inode, struct file *filp) | |||
| 340 | 348 | ||
| 341 | pm_qos_class = find_pm_qos_object_by_minor(iminor(inode)); | 349 | pm_qos_class = find_pm_qos_object_by_minor(iminor(inode)); |
| 342 | if (pm_qos_class >= 0) { | 350 | if (pm_qos_class >= 0) { |
| 343 | filp->private_data = (void *) pm_qos_add_request(pm_qos_class, | 351 | struct pm_qos_request_list *req = kzalloc(GFP_KERNEL, sizeof(*req)); |
| 344 | PM_QOS_DEFAULT_VALUE); | 352 | if (!req) |
| 353 | return -ENOMEM; | ||
| 354 | |||
| 355 | pm_qos_add_request(req, pm_qos_class, PM_QOS_DEFAULT_VALUE); | ||
| 356 | filp->private_data = req; | ||
| 345 | 357 | ||
| 346 | if (filp->private_data) | 358 | if (filp->private_data) |
| 347 | return 0; | 359 | return 0; |
| @@ -353,8 +365,9 @@ static int pm_qos_power_release(struct inode *inode, struct file *filp) | |||
| 353 | { | 365 | { |
| 354 | struct pm_qos_request_list *req; | 366 | struct pm_qos_request_list *req; |
| 355 | 367 | ||
| 356 | req = (struct pm_qos_request_list *)filp->private_data; | 368 | req = filp->private_data; |
| 357 | pm_qos_remove_request(req); | 369 | pm_qos_remove_request(req); |
| 370 | kfree(req); | ||
| 358 | 371 | ||
| 359 | return 0; | 372 | return 0; |
| 360 | } | 373 | } |
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index aa9e916da4d5..8dc31e02ae12 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | * | 3 | * |
| 4 | * Copyright (c) 2003 Patrick Mochel | 4 | * Copyright (c) 2003 Patrick Mochel |
| 5 | * Copyright (c) 2003 Open Source Development Lab | 5 | * Copyright (c) 2003 Open Source Development Lab |
| 6 | * Copyright (c) 2004 Pavel Machek <pavel@suse.cz> | 6 | * Copyright (c) 2004 Pavel Machek <pavel@ucw.cz> |
| 7 | * Copyright (c) 2009 Rafael J. Wysocki, Novell Inc. | 7 | * Copyright (c) 2009 Rafael J. Wysocki, Novell Inc. |
| 8 | * | 8 | * |
| 9 | * This file is released under the GPLv2. | 9 | * This file is released under the GPLv2. |
| @@ -277,7 +277,7 @@ static int create_image(int platform_mode) | |||
| 277 | goto Enable_irqs; | 277 | goto Enable_irqs; |
| 278 | } | 278 | } |
| 279 | 279 | ||
| 280 | if (hibernation_test(TEST_CORE)) | 280 | if (hibernation_test(TEST_CORE) || !pm_check_wakeup_events()) |
| 281 | goto Power_up; | 281 | goto Power_up; |
| 282 | 282 | ||
| 283 | in_suspend = 1; | 283 | in_suspend = 1; |
| @@ -288,8 +288,10 @@ static int create_image(int platform_mode) | |||
| 288 | error); | 288 | error); |
| 289 | /* Restore control flow magically appears here */ | 289 | /* Restore control flow magically appears here */ |
| 290 | restore_processor_state(); | 290 | restore_processor_state(); |
| 291 | if (!in_suspend) | 291 | if (!in_suspend) { |
| 292 | events_check_enabled = false; | ||
| 292 | platform_leave(platform_mode); | 293 | platform_leave(platform_mode); |
| 294 | } | ||
| 293 | 295 | ||
| 294 | Power_up: | 296 | Power_up: |
| 295 | sysdev_resume(); | 297 | sysdev_resume(); |
| @@ -328,7 +330,7 @@ int hibernation_snapshot(int platform_mode) | |||
| 328 | 330 | ||
| 329 | error = platform_begin(platform_mode); | 331 | error = platform_begin(platform_mode); |
| 330 | if (error) | 332 | if (error) |
| 331 | return error; | 333 | goto Close; |
| 332 | 334 | ||
| 333 | /* Preallocate image memory before shutting down devices. */ | 335 | /* Preallocate image memory before shutting down devices. */ |
| 334 | error = hibernate_preallocate_memory(); | 336 | error = hibernate_preallocate_memory(); |
| @@ -511,18 +513,24 @@ int hibernation_platform_enter(void) | |||
| 511 | 513 | ||
| 512 | local_irq_disable(); | 514 | local_irq_disable(); |
| 513 | sysdev_suspend(PMSG_HIBERNATE); | 515 | sysdev_suspend(PMSG_HIBERNATE); |
| 516 | if (!pm_check_wakeup_events()) { | ||
| 517 | error = -EAGAIN; | ||
| 518 | goto Power_up; | ||
| 519 | } | ||
| 520 | |||
| 514 | hibernation_ops->enter(); | 521 | hibernation_ops->enter(); |
| 515 | /* We should never get here */ | 522 | /* We should never get here */ |
| 516 | while (1); | 523 | while (1); |
| 517 | 524 | ||
| 518 | /* | 525 | Power_up: |
| 519 | * We don't need to reenable the nonboot CPUs or resume consoles, since | 526 | sysdev_resume(); |
| 520 | * the system is going to be halted anyway. | 527 | local_irq_enable(); |
| 521 | */ | 528 | enable_nonboot_cpus(); |
| 529 | |||
| 522 | Platform_finish: | 530 | Platform_finish: |
| 523 | hibernation_ops->finish(); | 531 | hibernation_ops->finish(); |
| 524 | 532 | ||
| 525 | dpm_suspend_noirq(PMSG_RESTORE); | 533 | dpm_resume_noirq(PMSG_RESTORE); |
| 526 | 534 | ||
| 527 | Resume_devices: | 535 | Resume_devices: |
| 528 | entering_platform_hibernation = false; | 536 | entering_platform_hibernation = false; |
diff --git a/kernel/power/main.c b/kernel/power/main.c index b58800b21fc0..62b0bc6e4983 100644 --- a/kernel/power/main.c +++ b/kernel/power/main.c | |||
| @@ -204,6 +204,60 @@ static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, | |||
| 204 | 204 | ||
| 205 | power_attr(state); | 205 | power_attr(state); |
| 206 | 206 | ||
| 207 | #ifdef CONFIG_PM_SLEEP | ||
| 208 | /* | ||
| 209 | * The 'wakeup_count' attribute, along with the functions defined in | ||
| 210 | * drivers/base/power/wakeup.c, provides a means by which wakeup events can be | ||
| 211 | * handled in a non-racy way. | ||
| 212 | * | ||
| 213 | * If a wakeup event occurs when the system is in a sleep state, it simply is | ||
| 214 | * woken up. In turn, if an event that would wake the system up from a sleep | ||
| 215 | * state occurs when it is undergoing a transition to that sleep state, the | ||
| 216 | * transition should be aborted. Moreover, if such an event occurs when the | ||
| 217 | * system is in the working state, an attempt to start a transition to the | ||
| 218 | * given sleep state should fail during certain period after the detection of | ||
| 219 | * the event. Using the 'state' attribute alone is not sufficient to satisfy | ||
| 220 | * these requirements, because a wakeup event may occur exactly when 'state' | ||
| 221 | * is being written to and may be delivered to user space right before it is | ||
| 222 | * frozen, so the event will remain only partially processed until the system is | ||
| 223 | * woken up by another event. In particular, it won't cause the transition to | ||
| 224 | * a sleep state to be aborted. | ||
| 225 | * | ||
| 226 | * This difficulty may be overcome if user space uses 'wakeup_count' before | ||
| 227 | * writing to 'state'. It first should read from 'wakeup_count' and store | ||
| 228 | * the read value. Then, after carrying out its own preparations for the system | ||
| 229 | * transition to a sleep state, it should write the stored value to | ||
| 230 | * 'wakeup_count'. If that fails, at least one wakeup event has occured since | ||
| 231 | * 'wakeup_count' was read and 'state' should not be written to. Otherwise, it | ||
| 232 | * is allowed to write to 'state', but the transition will be aborted if there | ||
| 233 | * are any wakeup events detected after 'wakeup_count' was written to. | ||
| 234 | */ | ||
| 235 | |||
| 236 | static ssize_t wakeup_count_show(struct kobject *kobj, | ||
| 237 | struct kobj_attribute *attr, | ||
| 238 | char *buf) | ||
| 239 | { | ||
| 240 | unsigned long val; | ||
| 241 | |||
| 242 | return pm_get_wakeup_count(&val) ? sprintf(buf, "%lu\n", val) : -EINTR; | ||
| 243 | } | ||
| 244 | |||
| 245 | static ssize_t wakeup_count_store(struct kobject *kobj, | ||
| 246 | struct kobj_attribute *attr, | ||
| 247 | const char *buf, size_t n) | ||
| 248 | { | ||
| 249 | unsigned long val; | ||
| 250 | |||
| 251 | if (sscanf(buf, "%lu", &val) == 1) { | ||
| 252 | if (pm_save_wakeup_count(val)) | ||
| 253 | return n; | ||
| 254 | } | ||
| 255 | return -EINVAL; | ||
| 256 | } | ||
| 257 | |||
| 258 | power_attr(wakeup_count); | ||
| 259 | #endif /* CONFIG_PM_SLEEP */ | ||
| 260 | |||
| 207 | #ifdef CONFIG_PM_TRACE | 261 | #ifdef CONFIG_PM_TRACE |
| 208 | int pm_trace_enabled; | 262 | int pm_trace_enabled; |
| 209 | 263 | ||
| @@ -236,6 +290,7 @@ static struct attribute * g[] = { | |||
| 236 | #endif | 290 | #endif |
| 237 | #ifdef CONFIG_PM_SLEEP | 291 | #ifdef CONFIG_PM_SLEEP |
| 238 | &pm_async_attr.attr, | 292 | &pm_async_attr.attr, |
| 293 | &wakeup_count_attr.attr, | ||
| 239 | #ifdef CONFIG_PM_DEBUG | 294 | #ifdef CONFIG_PM_DEBUG |
| 240 | &pm_test_attr.attr, | 295 | &pm_test_attr.attr, |
| 241 | #endif | 296 | #endif |
diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c index 25ce010e9f8b..f6cd6faf84fd 100644 --- a/kernel/power/snapshot.c +++ b/kernel/power/snapshot.c | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | * | 3 | * |
| 4 | * This file provides system snapshot/restore functionality for swsusp. | 4 | * This file provides system snapshot/restore functionality for swsusp. |
| 5 | * | 5 | * |
| 6 | * Copyright (C) 1998-2005 Pavel Machek <pavel@suse.cz> | 6 | * Copyright (C) 1998-2005 Pavel Machek <pavel@ucw.cz> |
| 7 | * Copyright (C) 2006 Rafael J. Wysocki <rjw@sisk.pl> | 7 | * Copyright (C) 2006 Rafael J. Wysocki <rjw@sisk.pl> |
| 8 | * | 8 | * |
| 9 | * This file is released under the GPLv2. | 9 | * This file is released under the GPLv2. |
diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c index f37cb7dd4402..7335952ee473 100644 --- a/kernel/power/suspend.c +++ b/kernel/power/suspend.c | |||
| @@ -136,19 +136,19 @@ static int suspend_enter(suspend_state_t state) | |||
| 136 | if (suspend_ops->prepare) { | 136 | if (suspend_ops->prepare) { |
| 137 | error = suspend_ops->prepare(); | 137 | error = suspend_ops->prepare(); |
| 138 | if (error) | 138 | if (error) |
| 139 | return error; | 139 | goto Platform_finish; |
| 140 | } | 140 | } |
| 141 | 141 | ||
| 142 | error = dpm_suspend_noirq(PMSG_SUSPEND); | 142 | error = dpm_suspend_noirq(PMSG_SUSPEND); |
| 143 | if (error) { | 143 | if (error) { |
| 144 | printk(KERN_ERR "PM: Some devices failed to power down\n"); | 144 | printk(KERN_ERR "PM: Some devices failed to power down\n"); |
| 145 | goto Platfrom_finish; | 145 | goto Platform_finish; |
| 146 | } | 146 | } |
| 147 | 147 | ||
| 148 | if (suspend_ops->prepare_late) { | 148 | if (suspend_ops->prepare_late) { |
| 149 | error = suspend_ops->prepare_late(); | 149 | error = suspend_ops->prepare_late(); |
| 150 | if (error) | 150 | if (error) |
| 151 | goto Power_up_devices; | 151 | goto Platform_wake; |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | if (suspend_test(TEST_PLATFORM)) | 154 | if (suspend_test(TEST_PLATFORM)) |
| @@ -163,8 +163,10 @@ static int suspend_enter(suspend_state_t state) | |||
| 163 | 163 | ||
| 164 | error = sysdev_suspend(PMSG_SUSPEND); | 164 | error = sysdev_suspend(PMSG_SUSPEND); |
| 165 | if (!error) { | 165 | if (!error) { |
| 166 | if (!suspend_test(TEST_CORE)) | 166 | if (!suspend_test(TEST_CORE) && pm_check_wakeup_events()) { |
| 167 | error = suspend_ops->enter(state); | 167 | error = suspend_ops->enter(state); |
| 168 | events_check_enabled = false; | ||
| 169 | } | ||
| 168 | sysdev_resume(); | 170 | sysdev_resume(); |
| 169 | } | 171 | } |
| 170 | 172 | ||
| @@ -178,10 +180,9 @@ static int suspend_enter(suspend_state_t state) | |||
| 178 | if (suspend_ops->wake) | 180 | if (suspend_ops->wake) |
| 179 | suspend_ops->wake(); | 181 | suspend_ops->wake(); |
| 180 | 182 | ||
| 181 | Power_up_devices: | ||
| 182 | dpm_resume_noirq(PMSG_RESUME); | 183 | dpm_resume_noirq(PMSG_RESUME); |
| 183 | 184 | ||
| 184 | Platfrom_finish: | 185 | Platform_finish: |
| 185 | if (suspend_ops->finish) | 186 | if (suspend_ops->finish) |
| 186 | suspend_ops->finish(); | 187 | suspend_ops->finish(); |
| 187 | 188 | ||
diff --git a/kernel/power/swap.c b/kernel/power/swap.c index b0bb21778391..e6a5bdf61a37 100644 --- a/kernel/power/swap.c +++ b/kernel/power/swap.c | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | * This file provides functions for reading the suspend image from | 4 | * This file provides functions for reading the suspend image from |
| 5 | * and writing it to a swap partition. | 5 | * and writing it to a swap partition. |
| 6 | * | 6 | * |
| 7 | * Copyright (C) 1998,2001-2005 Pavel Machek <pavel@suse.cz> | 7 | * Copyright (C) 1998,2001-2005 Pavel Machek <pavel@ucw.cz> |
| 8 | * Copyright (C) 2006 Rafael J. Wysocki <rjw@sisk.pl> | 8 | * Copyright (C) 2006 Rafael J. Wysocki <rjw@sisk.pl> |
| 9 | * | 9 | * |
| 10 | * This file is released under the GPLv2. | 10 | * This file is released under the GPLv2. |
| @@ -32,7 +32,7 @@ | |||
| 32 | /* | 32 | /* |
| 33 | * The swap map is a data structure used for keeping track of each page | 33 | * The swap map is a data structure used for keeping track of each page |
| 34 | * written to a swap partition. It consists of many swap_map_page | 34 | * written to a swap partition. It consists of many swap_map_page |
| 35 | * structures that contain each an array of MAP_PAGE_SIZE swap entries. | 35 | * structures that contain each an array of MAP_PAGE_ENTRIES swap entries. |
| 36 | * These structures are stored on the swap and linked together with the | 36 | * These structures are stored on the swap and linked together with the |
| 37 | * help of the .next_swap member. | 37 | * help of the .next_swap member. |
| 38 | * | 38 | * |
| @@ -148,7 +148,7 @@ sector_t alloc_swapdev_block(int swap) | |||
| 148 | 148 | ||
| 149 | /** | 149 | /** |
| 150 | * free_all_swap_pages - free swap pages allocated for saving image data. | 150 | * free_all_swap_pages - free swap pages allocated for saving image data. |
| 151 | * It also frees the extents used to register which swap entres had been | 151 | * It also frees the extents used to register which swap entries had been |
| 152 | * allocated. | 152 | * allocated. |
| 153 | */ | 153 | */ |
| 154 | 154 | ||
diff --git a/kernel/printk.c b/kernel/printk.c index 444b770c9595..4ab0164bcf84 100644 --- a/kernel/printk.c +++ b/kernel/printk.c | |||
| @@ -37,6 +37,8 @@ | |||
| 37 | #include <linux/ratelimit.h> | 37 | #include <linux/ratelimit.h> |
| 38 | #include <linux/kmsg_dump.h> | 38 | #include <linux/kmsg_dump.h> |
| 39 | #include <linux/syslog.h> | 39 | #include <linux/syslog.h> |
| 40 | #include <linux/cpu.h> | ||
| 41 | #include <linux/notifier.h> | ||
| 40 | 42 | ||
| 41 | #include <asm/uaccess.h> | 43 | #include <asm/uaccess.h> |
| 42 | 44 | ||
| @@ -985,6 +987,32 @@ void resume_console(void) | |||
| 985 | } | 987 | } |
| 986 | 988 | ||
| 987 | /** | 989 | /** |
| 990 | * console_cpu_notify - print deferred console messages after CPU hotplug | ||
| 991 | * @self: notifier struct | ||
| 992 | * @action: CPU hotplug event | ||
| 993 | * @hcpu: unused | ||
| 994 | * | ||
| 995 | * If printk() is called from a CPU that is not online yet, the messages | ||
| 996 | * will be spooled but will not show up on the console. This function is | ||
| 997 | * called when a new CPU comes online (or fails to come up), and ensures | ||
| 998 | * that any such output gets printed. | ||
| 999 | */ | ||
| 1000 | static int __cpuinit console_cpu_notify(struct notifier_block *self, | ||
| 1001 | unsigned long action, void *hcpu) | ||
| 1002 | { | ||
| 1003 | switch (action) { | ||
| 1004 | case CPU_ONLINE: | ||
| 1005 | case CPU_DEAD: | ||
| 1006 | case CPU_DYING: | ||
| 1007 | case CPU_DOWN_FAILED: | ||
| 1008 | case CPU_UP_CANCELED: | ||
| 1009 | acquire_console_sem(); | ||
| 1010 | release_console_sem(); | ||
| 1011 | } | ||
| 1012 | return NOTIFY_OK; | ||
| 1013 | } | ||
| 1014 | |||
| 1015 | /** | ||
| 988 | * acquire_console_sem - lock the console system for exclusive use. | 1016 | * acquire_console_sem - lock the console system for exclusive use. |
| 989 | * | 1017 | * |
| 990 | * Acquires a semaphore which guarantees that the caller has | 1018 | * Acquires a semaphore which guarantees that the caller has |
| @@ -1371,7 +1399,7 @@ int unregister_console(struct console *console) | |||
| 1371 | } | 1399 | } |
| 1372 | EXPORT_SYMBOL(unregister_console); | 1400 | EXPORT_SYMBOL(unregister_console); |
| 1373 | 1401 | ||
| 1374 | static int __init disable_boot_consoles(void) | 1402 | static int __init printk_late_init(void) |
| 1375 | { | 1403 | { |
| 1376 | struct console *con; | 1404 | struct console *con; |
| 1377 | 1405 | ||
| @@ -1382,9 +1410,10 @@ static int __init disable_boot_consoles(void) | |||
| 1382 | unregister_console(con); | 1410 | unregister_console(con); |
| 1383 | } | 1411 | } |
| 1384 | } | 1412 | } |
| 1413 | hotcpu_notifier(console_cpu_notify, 0); | ||
| 1385 | return 0; | 1414 | return 0; |
| 1386 | } | 1415 | } |
| 1387 | late_initcall(disable_boot_consoles); | 1416 | late_initcall(printk_late_init); |
| 1388 | 1417 | ||
| 1389 | #if defined CONFIG_PRINTK | 1418 | #if defined CONFIG_PRINTK |
| 1390 | 1419 | ||
diff --git a/kernel/signal.c b/kernel/signal.c index 906ae5a1779c..bded65187780 100644 --- a/kernel/signal.c +++ b/kernel/signal.c | |||
| @@ -637,7 +637,7 @@ static inline bool si_fromuser(const struct siginfo *info) | |||
| 637 | 637 | ||
| 638 | /* | 638 | /* |
| 639 | * Bad permissions for sending the signal | 639 | * Bad permissions for sending the signal |
| 640 | * - the caller must hold at least the RCU read lock | 640 | * - the caller must hold the RCU read lock |
| 641 | */ | 641 | */ |
| 642 | static int check_kill_permission(int sig, struct siginfo *info, | 642 | static int check_kill_permission(int sig, struct siginfo *info, |
| 643 | struct task_struct *t) | 643 | struct task_struct *t) |
| @@ -1127,11 +1127,14 @@ struct sighand_struct *lock_task_sighand(struct task_struct *tsk, unsigned long | |||
| 1127 | 1127 | ||
| 1128 | /* | 1128 | /* |
| 1129 | * send signal info to all the members of a group | 1129 | * send signal info to all the members of a group |
| 1130 | * - the caller must hold the RCU read lock at least | ||
| 1131 | */ | 1130 | */ |
| 1132 | int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p) | 1131 | int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p) |
| 1133 | { | 1132 | { |
| 1134 | int ret = check_kill_permission(sig, info, p); | 1133 | int ret; |
| 1134 | |||
| 1135 | rcu_read_lock(); | ||
| 1136 | ret = check_kill_permission(sig, info, p); | ||
| 1137 | rcu_read_unlock(); | ||
| 1135 | 1138 | ||
| 1136 | if (!ret && sig) | 1139 | if (!ret && sig) |
| 1137 | ret = do_send_sig_info(sig, info, p, true); | 1140 | ret = do_send_sig_info(sig, info, p, true); |
diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c index b3bafd5fc66d..48b2761b5668 100644 --- a/kernel/time/tick-broadcast.c +++ b/kernel/time/tick-broadcast.c | |||
| @@ -188,7 +188,7 @@ static void tick_handle_periodic_broadcast(struct clock_event_device *dev) | |||
| 188 | /* | 188 | /* |
| 189 | * Setup the next period for devices, which do not have | 189 | * Setup the next period for devices, which do not have |
| 190 | * periodic mode. We read dev->next_event first and add to it | 190 | * periodic mode. We read dev->next_event first and add to it |
| 191 | * when the event alrady expired. clockevents_program_event() | 191 | * when the event already expired. clockevents_program_event() |
| 192 | * sets dev->next_event only when the event is really | 192 | * sets dev->next_event only when the event is really |
| 193 | * programmed to the device. | 193 | * programmed to the device. |
| 194 | */ | 194 | */ |
diff --git a/kernel/timer.c b/kernel/timer.c index ee305c8d4e18..efde11e197c4 100644 --- a/kernel/timer.c +++ b/kernel/timer.c | |||
| @@ -577,6 +577,19 @@ static void __init_timer(struct timer_list *timer, | |||
| 577 | lockdep_init_map(&timer->lockdep_map, name, key, 0); | 577 | lockdep_init_map(&timer->lockdep_map, name, key, 0); |
| 578 | } | 578 | } |
| 579 | 579 | ||
| 580 | void setup_deferrable_timer_on_stack_key(struct timer_list *timer, | ||
| 581 | const char *name, | ||
| 582 | struct lock_class_key *key, | ||
| 583 | void (*function)(unsigned long), | ||
| 584 | unsigned long data) | ||
| 585 | { | ||
| 586 | timer->function = function; | ||
| 587 | timer->data = data; | ||
| 588 | init_timer_on_stack_key(timer, name, key); | ||
| 589 | timer_set_deferrable(timer); | ||
| 590 | } | ||
| 591 | EXPORT_SYMBOL_GPL(setup_deferrable_timer_on_stack_key); | ||
| 592 | |||
| 580 | /** | 593 | /** |
| 581 | * init_timer_key - initialize a timer | 594 | * init_timer_key - initialize a timer |
| 582 | * @timer: the timer to be initialized | 595 | * @timer: the timer to be initialized |
diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile index ffb1a5b0550e..4215530b490b 100644 --- a/kernel/trace/Makefile +++ b/kernel/trace/Makefile | |||
| @@ -57,5 +57,8 @@ obj-$(CONFIG_EVENT_TRACING) += trace_events_filter.o | |||
| 57 | obj-$(CONFIG_KPROBE_EVENT) += trace_kprobe.o | 57 | obj-$(CONFIG_KPROBE_EVENT) += trace_kprobe.o |
| 58 | obj-$(CONFIG_KSYM_TRACER) += trace_ksym.o | 58 | obj-$(CONFIG_KSYM_TRACER) += trace_ksym.o |
| 59 | obj-$(CONFIG_EVENT_TRACING) += power-traces.o | 59 | obj-$(CONFIG_EVENT_TRACING) += power-traces.o |
| 60 | ifeq ($(CONFIG_TRACING),y) | ||
| 61 | obj-$(CONFIG_KGDB_KDB) += trace_kdb.o | ||
| 62 | endif | ||
| 60 | 63 | ||
| 61 | libftrace-y := ftrace.o | 64 | libftrace-y := ftrace.o |
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 086d36316805..d6736b93dc2a 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c | |||
| @@ -101,10 +101,7 @@ static inline void ftrace_enable_cpu(void) | |||
| 101 | preempt_enable(); | 101 | preempt_enable(); |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | static cpumask_var_t __read_mostly tracing_buffer_mask; | 104 | cpumask_var_t __read_mostly tracing_buffer_mask; |
| 105 | |||
| 106 | #define for_each_tracing_cpu(cpu) \ | ||
| 107 | for_each_cpu(cpu, tracing_buffer_mask) | ||
| 108 | 105 | ||
| 109 | /* | 106 | /* |
| 110 | * ftrace_dump_on_oops - variable to dump ftrace buffer on oops | 107 | * ftrace_dump_on_oops - variable to dump ftrace buffer on oops |
| @@ -1539,11 +1536,6 @@ int trace_vprintk(unsigned long ip, const char *fmt, va_list args) | |||
| 1539 | } | 1536 | } |
| 1540 | EXPORT_SYMBOL_GPL(trace_vprintk); | 1537 | EXPORT_SYMBOL_GPL(trace_vprintk); |
| 1541 | 1538 | ||
| 1542 | enum trace_file_type { | ||
| 1543 | TRACE_FILE_LAT_FMT = 1, | ||
| 1544 | TRACE_FILE_ANNOTATE = 2, | ||
| 1545 | }; | ||
| 1546 | |||
| 1547 | static void trace_iterator_increment(struct trace_iterator *iter) | 1539 | static void trace_iterator_increment(struct trace_iterator *iter) |
| 1548 | { | 1540 | { |
| 1549 | /* Don't allow ftrace to trace into the ring buffers */ | 1541 | /* Don't allow ftrace to trace into the ring buffers */ |
| @@ -1641,7 +1633,7 @@ struct trace_entry *trace_find_next_entry(struct trace_iterator *iter, | |||
| 1641 | } | 1633 | } |
| 1642 | 1634 | ||
| 1643 | /* Find the next real entry, and increment the iterator to the next entry */ | 1635 | /* Find the next real entry, and increment the iterator to the next entry */ |
| 1644 | static void *find_next_entry_inc(struct trace_iterator *iter) | 1636 | void *trace_find_next_entry_inc(struct trace_iterator *iter) |
| 1645 | { | 1637 | { |
| 1646 | iter->ent = __find_next_entry(iter, &iter->cpu, | 1638 | iter->ent = __find_next_entry(iter, &iter->cpu, |
| 1647 | &iter->lost_events, &iter->ts); | 1639 | &iter->lost_events, &iter->ts); |
| @@ -1676,19 +1668,19 @@ static void *s_next(struct seq_file *m, void *v, loff_t *pos) | |||
| 1676 | return NULL; | 1668 | return NULL; |
| 1677 | 1669 | ||
| 1678 | if (iter->idx < 0) | 1670 | if (iter->idx < 0) |
| 1679 | ent = find_next_entry_inc(iter); | 1671 | ent = trace_find_next_entry_inc(iter); |
| 1680 | else | 1672 | else |
| 1681 | ent = iter; | 1673 | ent = iter; |
| 1682 | 1674 | ||
| 1683 | while (ent && iter->idx < i) | 1675 | while (ent && iter->idx < i) |
| 1684 | ent = find_next_entry_inc(iter); | 1676 | ent = trace_find_next_entry_inc(iter); |
| 1685 | 1677 | ||
| 1686 | iter->pos = *pos; | 1678 | iter->pos = *pos; |
| 1687 | 1679 | ||
| 1688 | return ent; | 1680 | return ent; |
| 1689 | } | 1681 | } |
| 1690 | 1682 | ||
| 1691 | static void tracing_iter_reset(struct trace_iterator *iter, int cpu) | 1683 | void tracing_iter_reset(struct trace_iterator *iter, int cpu) |
| 1692 | { | 1684 | { |
| 1693 | struct trace_array *tr = iter->tr; | 1685 | struct trace_array *tr = iter->tr; |
| 1694 | struct ring_buffer_event *event; | 1686 | struct ring_buffer_event *event; |
| @@ -2049,7 +2041,7 @@ int trace_empty(struct trace_iterator *iter) | |||
| 2049 | } | 2041 | } |
| 2050 | 2042 | ||
| 2051 | /* Called with trace_event_read_lock() held. */ | 2043 | /* Called with trace_event_read_lock() held. */ |
| 2052 | static enum print_line_t print_trace_line(struct trace_iterator *iter) | 2044 | enum print_line_t print_trace_line(struct trace_iterator *iter) |
| 2053 | { | 2045 | { |
| 2054 | enum print_line_t ret; | 2046 | enum print_line_t ret; |
| 2055 | 2047 | ||
| @@ -3211,7 +3203,7 @@ waitagain: | |||
| 3211 | 3203 | ||
| 3212 | trace_event_read_lock(); | 3204 | trace_event_read_lock(); |
| 3213 | trace_access_lock(iter->cpu_file); | 3205 | trace_access_lock(iter->cpu_file); |
| 3214 | while (find_next_entry_inc(iter) != NULL) { | 3206 | while (trace_find_next_entry_inc(iter) != NULL) { |
| 3215 | enum print_line_t ret; | 3207 | enum print_line_t ret; |
| 3216 | int len = iter->seq.len; | 3208 | int len = iter->seq.len; |
| 3217 | 3209 | ||
| @@ -3294,7 +3286,7 @@ tracing_fill_pipe_page(size_t rem, struct trace_iterator *iter) | |||
| 3294 | if (ret != TRACE_TYPE_NO_CONSUME) | 3286 | if (ret != TRACE_TYPE_NO_CONSUME) |
| 3295 | trace_consume(iter); | 3287 | trace_consume(iter); |
| 3296 | rem -= count; | 3288 | rem -= count; |
| 3297 | if (!find_next_entry_inc(iter)) { | 3289 | if (!trace_find_next_entry_inc(iter)) { |
| 3298 | rem = 0; | 3290 | rem = 0; |
| 3299 | iter->ent = NULL; | 3291 | iter->ent = NULL; |
| 3300 | break; | 3292 | break; |
| @@ -3350,7 +3342,7 @@ static ssize_t tracing_splice_read_pipe(struct file *filp, | |||
| 3350 | if (ret <= 0) | 3342 | if (ret <= 0) |
| 3351 | goto out_err; | 3343 | goto out_err; |
| 3352 | 3344 | ||
| 3353 | if (!iter->ent && !find_next_entry_inc(iter)) { | 3345 | if (!iter->ent && !trace_find_next_entry_inc(iter)) { |
| 3354 | ret = -EFAULT; | 3346 | ret = -EFAULT; |
| 3355 | goto out_err; | 3347 | goto out_err; |
| 3356 | } | 3348 | } |
| @@ -4414,7 +4406,7 @@ static struct notifier_block trace_die_notifier = { | |||
| 4414 | */ | 4406 | */ |
| 4415 | #define KERN_TRACE KERN_EMERG | 4407 | #define KERN_TRACE KERN_EMERG |
| 4416 | 4408 | ||
| 4417 | static void | 4409 | void |
| 4418 | trace_printk_seq(struct trace_seq *s) | 4410 | trace_printk_seq(struct trace_seq *s) |
| 4419 | { | 4411 | { |
| 4420 | /* Probably should print a warning here. */ | 4412 | /* Probably should print a warning here. */ |
| @@ -4429,6 +4421,13 @@ trace_printk_seq(struct trace_seq *s) | |||
| 4429 | trace_seq_init(s); | 4421 | trace_seq_init(s); |
| 4430 | } | 4422 | } |
| 4431 | 4423 | ||
| 4424 | void trace_init_global_iter(struct trace_iterator *iter) | ||
| 4425 | { | ||
| 4426 | iter->tr = &global_trace; | ||
| 4427 | iter->trace = current_trace; | ||
| 4428 | iter->cpu_file = TRACE_PIPE_ALL_CPU; | ||
| 4429 | } | ||
| 4430 | |||
| 4432 | static void | 4431 | static void |
| 4433 | __ftrace_dump(bool disable_tracing, enum ftrace_dump_mode oops_dump_mode) | 4432 | __ftrace_dump(bool disable_tracing, enum ftrace_dump_mode oops_dump_mode) |
| 4434 | { | 4433 | { |
| @@ -4454,8 +4453,10 @@ __ftrace_dump(bool disable_tracing, enum ftrace_dump_mode oops_dump_mode) | |||
| 4454 | if (disable_tracing) | 4453 | if (disable_tracing) |
| 4455 | ftrace_kill(); | 4454 | ftrace_kill(); |
| 4456 | 4455 | ||
| 4456 | trace_init_global_iter(&iter); | ||
| 4457 | |||
| 4457 | for_each_tracing_cpu(cpu) { | 4458 | for_each_tracing_cpu(cpu) { |
| 4458 | atomic_inc(&global_trace.data[cpu]->disabled); | 4459 | atomic_inc(&iter.tr->data[cpu]->disabled); |
| 4459 | } | 4460 | } |
| 4460 | 4461 | ||
| 4461 | old_userobj = trace_flags & TRACE_ITER_SYM_USEROBJ; | 4462 | old_userobj = trace_flags & TRACE_ITER_SYM_USEROBJ; |
| @@ -4504,7 +4505,7 @@ __ftrace_dump(bool disable_tracing, enum ftrace_dump_mode oops_dump_mode) | |||
| 4504 | iter.iter_flags |= TRACE_FILE_LAT_FMT; | 4505 | iter.iter_flags |= TRACE_FILE_LAT_FMT; |
| 4505 | iter.pos = -1; | 4506 | iter.pos = -1; |
| 4506 | 4507 | ||
| 4507 | if (find_next_entry_inc(&iter) != NULL) { | 4508 | if (trace_find_next_entry_inc(&iter) != NULL) { |
| 4508 | int ret; | 4509 | int ret; |
| 4509 | 4510 | ||
| 4510 | ret = print_trace_line(&iter); | 4511 | ret = print_trace_line(&iter); |
| @@ -4526,7 +4527,7 @@ __ftrace_dump(bool disable_tracing, enum ftrace_dump_mode oops_dump_mode) | |||
| 4526 | trace_flags |= old_userobj; | 4527 | trace_flags |= old_userobj; |
| 4527 | 4528 | ||
| 4528 | for_each_tracing_cpu(cpu) { | 4529 | for_each_tracing_cpu(cpu) { |
| 4529 | atomic_dec(&global_trace.data[cpu]->disabled); | 4530 | atomic_dec(&iter.tr->data[cpu]->disabled); |
| 4530 | } | 4531 | } |
| 4531 | tracing_on(); | 4532 | tracing_on(); |
| 4532 | } | 4533 | } |
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 2cd96399463f..0605fc00c176 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h | |||
| @@ -338,6 +338,14 @@ struct trace_entry *tracing_get_trace_entry(struct trace_array *tr, | |||
| 338 | struct trace_entry *trace_find_next_entry(struct trace_iterator *iter, | 338 | struct trace_entry *trace_find_next_entry(struct trace_iterator *iter, |
| 339 | int *ent_cpu, u64 *ent_ts); | 339 | int *ent_cpu, u64 *ent_ts); |
| 340 | 340 | ||
| 341 | int trace_empty(struct trace_iterator *iter); | ||
| 342 | |||
| 343 | void *trace_find_next_entry_inc(struct trace_iterator *iter); | ||
| 344 | |||
| 345 | void trace_init_global_iter(struct trace_iterator *iter); | ||
| 346 | |||
| 347 | void tracing_iter_reset(struct trace_iterator *iter, int cpu); | ||
| 348 | |||
| 341 | void default_wait_pipe(struct trace_iterator *iter); | 349 | void default_wait_pipe(struct trace_iterator *iter); |
| 342 | void poll_wait_pipe(struct trace_iterator *iter); | 350 | void poll_wait_pipe(struct trace_iterator *iter); |
| 343 | 351 | ||
| @@ -380,6 +388,15 @@ void tracing_start_sched_switch_record(void); | |||
| 380 | int register_tracer(struct tracer *type); | 388 | int register_tracer(struct tracer *type); |
| 381 | void unregister_tracer(struct tracer *type); | 389 | void unregister_tracer(struct tracer *type); |
| 382 | int is_tracing_stopped(void); | 390 | int is_tracing_stopped(void); |
| 391 | enum trace_file_type { | ||
| 392 | TRACE_FILE_LAT_FMT = 1, | ||
| 393 | TRACE_FILE_ANNOTATE = 2, | ||
| 394 | }; | ||
| 395 | |||
| 396 | extern cpumask_var_t __read_mostly tracing_buffer_mask; | ||
| 397 | |||
| 398 | #define for_each_tracing_cpu(cpu) \ | ||
| 399 | for_each_cpu(cpu, tracing_buffer_mask) | ||
| 383 | 400 | ||
| 384 | extern int process_new_ksym_entry(char *ksymname, int op, unsigned long addr); | 401 | extern int process_new_ksym_entry(char *ksymname, int op, unsigned long addr); |
| 385 | 402 | ||
| @@ -471,6 +488,8 @@ trace_array_vprintk(struct trace_array *tr, | |||
| 471 | unsigned long ip, const char *fmt, va_list args); | 488 | unsigned long ip, const char *fmt, va_list args); |
| 472 | int trace_array_printk(struct trace_array *tr, | 489 | int trace_array_printk(struct trace_array *tr, |
| 473 | unsigned long ip, const char *fmt, ...); | 490 | unsigned long ip, const char *fmt, ...); |
| 491 | void trace_printk_seq(struct trace_seq *s); | ||
| 492 | enum print_line_t print_trace_line(struct trace_iterator *iter); | ||
| 474 | 493 | ||
| 475 | extern unsigned long trace_flags; | 494 | extern unsigned long trace_flags; |
| 476 | 495 | ||
diff --git a/kernel/trace/trace_kdb.c b/kernel/trace/trace_kdb.c new file mode 100644 index 000000000000..7b8ecd751d93 --- /dev/null +++ b/kernel/trace/trace_kdb.c | |||
| @@ -0,0 +1,136 @@ | |||
| 1 | /* | ||
| 2 | * kdb helper for dumping the ftrace buffer | ||
| 3 | * | ||
| 4 | * Copyright (C) 2010 Jason Wessel <jason.wessel@windriver.com> | ||
| 5 | * | ||
| 6 | * ftrace_dump_buf based on ftrace_dump: | ||
| 7 | * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com> | ||
| 8 | * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com> | ||
| 9 | * | ||
| 10 | */ | ||
| 11 | #include <linux/init.h> | ||
| 12 | #include <linux/kgdb.h> | ||
| 13 | #include <linux/kdb.h> | ||
| 14 | #include <linux/ftrace.h> | ||
| 15 | |||
| 16 | #include "../debug/kdb/kdb_private.h" | ||
| 17 | #include "trace.h" | ||
| 18 | #include "trace_output.h" | ||
| 19 | |||
| 20 | static void ftrace_dump_buf(int skip_lines, long cpu_file) | ||
| 21 | { | ||
| 22 | /* use static because iter can be a bit big for the stack */ | ||
| 23 | static struct trace_iterator iter; | ||
| 24 | unsigned int old_userobj; | ||
| 25 | int cnt = 0, cpu; | ||
| 26 | |||
| 27 | trace_init_global_iter(&iter); | ||
| 28 | |||
| 29 | for_each_tracing_cpu(cpu) { | ||
| 30 | atomic_inc(&iter.tr->data[cpu]->disabled); | ||
| 31 | } | ||
| 32 | |||
| 33 | old_userobj = trace_flags; | ||
| 34 | |||
| 35 | /* don't look at user memory in panic mode */ | ||
| 36 | trace_flags &= ~TRACE_ITER_SYM_USEROBJ; | ||
| 37 | |||
| 38 | kdb_printf("Dumping ftrace buffer:\n"); | ||
| 39 | |||
| 40 | /* reset all but tr, trace, and overruns */ | ||
| 41 | memset(&iter.seq, 0, | ||
| 42 | sizeof(struct trace_iterator) - | ||
| 43 | offsetof(struct trace_iterator, seq)); | ||
| 44 | iter.iter_flags |= TRACE_FILE_LAT_FMT; | ||
| 45 | iter.pos = -1; | ||
| 46 | |||
| 47 | if (cpu_file == TRACE_PIPE_ALL_CPU) { | ||
| 48 | for_each_tracing_cpu(cpu) { | ||
| 49 | iter.buffer_iter[cpu] = | ||
| 50 | ring_buffer_read_prepare(iter.tr->buffer, cpu); | ||
| 51 | ring_buffer_read_start(iter.buffer_iter[cpu]); | ||
| 52 | tracing_iter_reset(&iter, cpu); | ||
| 53 | } | ||
| 54 | } else { | ||
| 55 | iter.cpu_file = cpu_file; | ||
| 56 | iter.buffer_iter[cpu_file] = | ||
| 57 | ring_buffer_read_prepare(iter.tr->buffer, cpu_file); | ||
| 58 | ring_buffer_read_start(iter.buffer_iter[cpu_file]); | ||
| 59 | tracing_iter_reset(&iter, cpu_file); | ||
| 60 | } | ||
| 61 | if (!trace_empty(&iter)) | ||
| 62 | trace_find_next_entry_inc(&iter); | ||
| 63 | while (!trace_empty(&iter)) { | ||
| 64 | if (!cnt) | ||
| 65 | kdb_printf("---------------------------------\n"); | ||
| 66 | cnt++; | ||
| 67 | |||
| 68 | if (trace_find_next_entry_inc(&iter) != NULL && !skip_lines) | ||
| 69 | print_trace_line(&iter); | ||
| 70 | if (!skip_lines) | ||
| 71 | trace_printk_seq(&iter.seq); | ||
| 72 | else | ||
| 73 | skip_lines--; | ||
| 74 | if (KDB_FLAG(CMD_INTERRUPT)) | ||
| 75 | goto out; | ||
| 76 | } | ||
| 77 | |||
| 78 | if (!cnt) | ||
| 79 | kdb_printf(" (ftrace buffer empty)\n"); | ||
| 80 | else | ||
| 81 | kdb_printf("---------------------------------\n"); | ||
| 82 | |||
| 83 | out: | ||
| 84 | trace_flags = old_userobj; | ||
| 85 | |||
| 86 | for_each_tracing_cpu(cpu) { | ||
| 87 | atomic_dec(&iter.tr->data[cpu]->disabled); | ||
| 88 | } | ||
| 89 | |||
| 90 | for_each_tracing_cpu(cpu) | ||
| 91 | if (iter.buffer_iter[cpu]) | ||
| 92 | ring_buffer_read_finish(iter.buffer_iter[cpu]); | ||
| 93 | } | ||
| 94 | |||
| 95 | /* | ||
| 96 | * kdb_ftdump - Dump the ftrace log buffer | ||
| 97 | */ | ||
| 98 | static int kdb_ftdump(int argc, const char **argv) | ||
| 99 | { | ||
| 100 | int skip_lines = 0; | ||
| 101 | long cpu_file; | ||
| 102 | char *cp; | ||
| 103 | |||
| 104 | if (argc > 2) | ||
| 105 | return KDB_ARGCOUNT; | ||
| 106 | |||
| 107 | if (argc) { | ||
| 108 | skip_lines = simple_strtol(argv[1], &cp, 0); | ||
| 109 | if (*cp) | ||
| 110 | skip_lines = 0; | ||
| 111 | } | ||
| 112 | |||
| 113 | if (argc == 2) { | ||
| 114 | cpu_file = simple_strtol(argv[2], &cp, 0); | ||
| 115 | if (*cp || cpu_file >= NR_CPUS || cpu_file < 0 || | ||
| 116 | !cpu_online(cpu_file)) | ||
| 117 | return KDB_BADINT; | ||
| 118 | } else { | ||
| 119 | cpu_file = TRACE_PIPE_ALL_CPU; | ||
| 120 | } | ||
| 121 | |||
| 122 | kdb_trap_printk++; | ||
| 123 | ftrace_dump_buf(skip_lines, cpu_file); | ||
| 124 | kdb_trap_printk--; | ||
| 125 | |||
| 126 | return 0; | ||
| 127 | } | ||
| 128 | |||
| 129 | static __init int kdb_ftrace_register(void) | ||
| 130 | { | ||
| 131 | kdb_register_repeat("ftdump", kdb_ftdump, "[skip_#lines] [cpu]", | ||
| 132 | "Dump ftrace log", 0, KDB_REPEAT_NONE); | ||
| 133 | return 0; | ||
| 134 | } | ||
| 135 | |||
| 136 | late_initcall(kdb_ftrace_register); | ||
diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c index b2d70d38dff4..25915832291a 100644 --- a/kernel/user_namespace.c +++ b/kernel/user_namespace.c | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #include <linux/nsproxy.h> | 9 | #include <linux/nsproxy.h> |
| 10 | #include <linux/slab.h> | 10 | #include <linux/slab.h> |
| 11 | #include <linux/user_namespace.h> | 11 | #include <linux/user_namespace.h> |
| 12 | #include <linux/highuid.h> | ||
| 12 | #include <linux/cred.h> | 13 | #include <linux/cred.h> |
| 13 | 14 | ||
| 14 | /* | 15 | /* |
| @@ -82,3 +83,46 @@ void free_user_ns(struct kref *kref) | |||
| 82 | schedule_work(&ns->destroyer); | 83 | schedule_work(&ns->destroyer); |
| 83 | } | 84 | } |
| 84 | EXPORT_SYMBOL(free_user_ns); | 85 | EXPORT_SYMBOL(free_user_ns); |
| 86 | |||
| 87 | uid_t user_ns_map_uid(struct user_namespace *to, const struct cred *cred, uid_t uid) | ||
| 88 | { | ||
| 89 | struct user_namespace *tmp; | ||
| 90 | |||
| 91 | if (likely(to == cred->user->user_ns)) | ||
| 92 | return uid; | ||
| 93 | |||
| 94 | |||
| 95 | /* Is cred->user the creator of the target user_ns | ||
| 96 | * or the creator of one of it's parents? | ||
| 97 | */ | ||
| 98 | for ( tmp = to; tmp != &init_user_ns; | ||
| 99 | tmp = tmp->creator->user_ns ) { | ||
| 100 | if (cred->user == tmp->creator) { | ||
| 101 | return (uid_t)0; | ||
| 102 | } | ||
| 103 | } | ||
| 104 | |||
| 105 | /* No useful relationship so no mapping */ | ||
| 106 | return overflowuid; | ||
| 107 | } | ||
| 108 | |||
| 109 | gid_t user_ns_map_gid(struct user_namespace *to, const struct cred *cred, gid_t gid) | ||
| 110 | { | ||
| 111 | struct user_namespace *tmp; | ||
| 112 | |||
| 113 | if (likely(to == cred->user->user_ns)) | ||
| 114 | return gid; | ||
| 115 | |||
| 116 | /* Is cred->user the creator of the target user_ns | ||
| 117 | * or the creator of one of it's parents? | ||
| 118 | */ | ||
| 119 | for ( tmp = to; tmp != &init_user_ns; | ||
| 120 | tmp = tmp->creator->user_ns ) { | ||
| 121 | if (cred->user == tmp->creator) { | ||
| 122 | return (gid_t)0; | ||
| 123 | } | ||
| 124 | } | ||
| 125 | |||
| 126 | /* No useful relationship so no mapping */ | ||
| 127 | return overflowgid; | ||
| 128 | } | ||
