Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'akpm' (updates from Andrew Morton)

Merge misc fixes from Andrew Morton:
"Bunch of fixes and one little addition to math64.h"

* emailed patches from Andrew Morton <akpm@linux-foundation.org>: (27 commits)
include/linux/math64.h: add div64_ul()
mm: memcontrol: fix lockless reclaim hierarchy iterator
frontswap: fix incorrect zeroing and allocation size for frontswap_map
kernel/audit_tree.c:audit_add_tree_rule(): protect `rule' from kill_rules()
mm: migration: add migrate_entry_wait_huge()
ocfs2: add missing lockres put in dlm_mig_lockres_handler
mm/page_alloc.c: fix watermark check in __zone_watermark_ok()
drivers/misc/sgi-gru/grufile.c: fix info leak in gru_get_config_info()
aio: fix io_destroy() regression by using call_rcu()
rtc-at91rm9200: use shadow IMR on at91sam9x5
rtc-at91rm9200: add shadow interrupt mask
rtc-at91rm9200: refactor interrupt-register handling
rtc-at91rm9200: add configuration support
rtc-at91rm9200: add match-table compile guard
fs/ocfs2/namei.c: remove unecessary ERROR when removing non-empty directory
swap: avoid read_swap_cache_async() race to deadlock while waiting on discard I/O completion
drivers/rtc/rtc-twl.c: fix missing device_init_wakeup() when booted with device tree
cciss: fix broken mutex usage in ioctl
audit: wait_for_auditd() should use TASK_UNINTERRUPTIBLE
drivers/rtc/rtc-cmos.c: fix accidentally enabling rtc channel
...

+321 -168
+1 -1
Documentation/devicetree/bindings/rtc/atmel,at91rm9200-rtc.txt
··· 1 1 Atmel AT91RM9200 Real Time Clock 2 2 3 3 Required properties: 4 - - compatible: should be: "atmel,at91rm9200-rtc" 4 + - compatible: should be: "atmel,at91rm9200-rtc" or "atmel,at91sam9x5-rtc" 5 5 - reg: physical base address of the controller and length of memory mapped 6 6 region. 7 7 - interrupts: rtc alarm/event interrupt
+16 -16
drivers/block/cciss.c
··· 168 168 static int cciss_open(struct block_device *bdev, fmode_t mode); 169 169 static int cciss_unlocked_open(struct block_device *bdev, fmode_t mode); 170 170 static void cciss_release(struct gendisk *disk, fmode_t mode); 171 - static int do_ioctl(struct block_device *bdev, fmode_t mode, 172 - unsigned int cmd, unsigned long arg); 173 171 static int cciss_ioctl(struct block_device *bdev, fmode_t mode, 174 172 unsigned int cmd, unsigned long arg); 175 173 static int cciss_getgeo(struct block_device *bdev, struct hd_geometry *geo); ··· 233 235 .owner = THIS_MODULE, 234 236 .open = cciss_unlocked_open, 235 237 .release = cciss_release, 236 - .ioctl = do_ioctl, 238 + .ioctl = cciss_ioctl, 237 239 .getgeo = cciss_getgeo, 238 240 #ifdef CONFIG_COMPAT 239 241 .compat_ioctl = cciss_compat_ioctl, ··· 1141 1143 mutex_unlock(&cciss_mutex); 1142 1144 } 1143 1145 1144 - static int do_ioctl(struct block_device *bdev, fmode_t mode, 1145 - unsigned cmd, unsigned long arg) 1146 - { 1147 - int ret; 1148 - mutex_lock(&cciss_mutex); 1149 - ret = cciss_ioctl(bdev, mode, cmd, arg); 1150 - mutex_unlock(&cciss_mutex); 1151 - return ret; 1152 - } 1153 - 1154 1146 #ifdef CONFIG_COMPAT 1155 1147 1156 1148 static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode, ··· 1167 1179 case CCISS_REGNEWD: 1168 1180 case CCISS_RESCANDISK: 1169 1181 case CCISS_GETLUNINFO: 1170 - return do_ioctl(bdev, mode, cmd, arg); 1182 + return cciss_ioctl(bdev, mode, cmd, arg); 1171 1183 1172 1184 case CCISS_PASSTHRU32: 1173 1185 return cciss_ioctl32_passthru(bdev, mode, cmd, arg); ··· 1207 1219 if (err) 1208 1220 return -EFAULT; 1209 1221 1210 - err = do_ioctl(bdev, mode, CCISS_PASSTHRU, (unsigned long)p); 1222 + err = cciss_ioctl(bdev, mode, CCISS_PASSTHRU, (unsigned long)p); 1211 1223 if (err) 1212 1224 return err; 1213 1225 err |= ··· 1249 1261 if (err) 1250 1262 return -EFAULT; 1251 1263 1252 - err = do_ioctl(bdev, mode, CCISS_BIG_PASSTHRU, (unsigned long)p); 1264 + err = cciss_ioctl(bdev, mode, CCISS_BIG_PASSTHRU, (unsigned long)p); 1253 1265 if (err) 1254 1266 return err; 1255 1267 err |= ··· 1299 1311 static int cciss_getintinfo(ctlr_info_t *h, void __user *argp) 1300 1312 { 1301 1313 cciss_coalint_struct intinfo; 1314 + unsigned long flags; 1302 1315 1303 1316 if (!argp) 1304 1317 return -EINVAL; 1318 + spin_lock_irqsave(&h->lock, flags); 1305 1319 intinfo.delay = readl(&h->cfgtable->HostWrite.CoalIntDelay); 1306 1320 intinfo.count = readl(&h->cfgtable->HostWrite.CoalIntCount); 1321 + spin_unlock_irqrestore(&h->lock, flags); 1307 1322 if (copy_to_user 1308 1323 (argp, &intinfo, sizeof(cciss_coalint_struct))) 1309 1324 return -EFAULT; ··· 1347 1356 static int cciss_getnodename(ctlr_info_t *h, void __user *argp) 1348 1357 { 1349 1358 NodeName_type NodeName; 1359 + unsigned long flags; 1350 1360 int i; 1351 1361 1352 1362 if (!argp) 1353 1363 return -EINVAL; 1364 + spin_lock_irqsave(&h->lock, flags); 1354 1365 for (i = 0; i < 16; i++) 1355 1366 NodeName[i] = readb(&h->cfgtable->ServerName[i]); 1367 + spin_unlock_irqrestore(&h->lock, flags); 1356 1368 if (copy_to_user(argp, NodeName, sizeof(NodeName_type))) 1357 1369 return -EFAULT; 1358 1370 return 0; ··· 1392 1398 static int cciss_getheartbeat(ctlr_info_t *h, void __user *argp) 1393 1399 { 1394 1400 Heartbeat_type heartbeat; 1401 + unsigned long flags; 1395 1402 1396 1403 if (!argp) 1397 1404 return -EINVAL; 1405 + spin_lock_irqsave(&h->lock, flags); 1398 1406 heartbeat = readl(&h->cfgtable->HeartBeat); 1407 + spin_unlock_irqrestore(&h->lock, flags); 1399 1408 if (copy_to_user(argp, &heartbeat, sizeof(Heartbeat_type))) 1400 1409 return -EFAULT; 1401 1410 return 0; ··· 1407 1410 static int cciss_getbustypes(ctlr_info_t *h, void __user *argp) 1408 1411 { 1409 1412 BusTypes_type BusTypes; 1413 + unsigned long flags; 1410 1414 1411 1415 if (!argp) 1412 1416 return -EINVAL; 1417 + spin_lock_irqsave(&h->lock, flags); 1413 1418 BusTypes = readl(&h->cfgtable->BusTypes); 1419 + spin_unlock_irqrestore(&h->lock, flags); 1414 1420 if (copy_to_user(argp, &BusTypes, sizeof(BusTypes_type))) 1415 1421 return -EFAULT; 1416 1422 return 0;
+1
drivers/misc/sgi-gru/grufile.c
··· 172 172 nodesperblade = 2; 173 173 else 174 174 nodesperblade = 1; 175 + memset(&info, 0, sizeof(info)); 175 176 info.cpus = num_online_cpus(); 176 177 info.nodes = num_online_nodes(); 177 178 info.blades = info.nodes / nodesperblade;
+111 -20
drivers/rtc/rtc-at91rm9200.c
··· 25 25 #include <linux/rtc.h> 26 26 #include <linux/bcd.h> 27 27 #include <linux/interrupt.h> 28 + #include <linux/spinlock.h> 28 29 #include <linux/ioctl.h> 29 30 #include <linux/completion.h> 30 31 #include <linux/io.h> ··· 43 42 44 43 #define AT91_RTC_EPOCH 1900UL /* just like arch/arm/common/rtctime.c */ 45 44 45 + struct at91_rtc_config { 46 + bool use_shadow_imr; 47 + }; 48 + 49 + static const struct at91_rtc_config *at91_rtc_config; 46 50 static DECLARE_COMPLETION(at91_rtc_updated); 47 51 static unsigned int at91_alarm_year = AT91_RTC_EPOCH; 48 52 static void __iomem *at91_rtc_regs; 49 53 static int irq; 54 + static DEFINE_SPINLOCK(at91_rtc_lock); 55 + static u32 at91_rtc_shadow_imr; 56 + 57 + static void at91_rtc_write_ier(u32 mask) 58 + { 59 + unsigned long flags; 60 + 61 + spin_lock_irqsave(&at91_rtc_lock, flags); 62 + at91_rtc_shadow_imr |= mask; 63 + at91_rtc_write(AT91_RTC_IER, mask); 64 + spin_unlock_irqrestore(&at91_rtc_lock, flags); 65 + } 66 + 67 + static void at91_rtc_write_idr(u32 mask) 68 + { 69 + unsigned long flags; 70 + 71 + spin_lock_irqsave(&at91_rtc_lock, flags); 72 + at91_rtc_write(AT91_RTC_IDR, mask); 73 + /* 74 + * Register read back (of any RTC-register) needed to make sure 75 + * IDR-register write has reached the peripheral before updating 76 + * shadow mask. 77 + * 78 + * Note that there is still a possibility that the mask is updated 79 + * before interrupts have actually been disabled in hardware. The only 80 + * way to be certain would be to poll the IMR-register, which is is 81 + * the very register we are trying to emulate. The register read back 82 + * is a reasonable heuristic. 83 + */ 84 + at91_rtc_read(AT91_RTC_SR); 85 + at91_rtc_shadow_imr &= ~mask; 86 + spin_unlock_irqrestore(&at91_rtc_lock, flags); 87 + } 88 + 89 + static u32 at91_rtc_read_imr(void) 90 + { 91 + unsigned long flags; 92 + u32 mask; 93 + 94 + if (at91_rtc_config->use_shadow_imr) { 95 + spin_lock_irqsave(&at91_rtc_lock, flags); 96 + mask = at91_rtc_shadow_imr; 97 + spin_unlock_irqrestore(&at91_rtc_lock, flags); 98 + } else { 99 + mask = at91_rtc_read(AT91_RTC_IMR); 100 + } 101 + 102 + return mask; 103 + } 50 104 51 105 /* 52 106 * Decode time/date into rtc_time structure ··· 166 110 cr = at91_rtc_read(AT91_RTC_CR); 167 111 at91_rtc_write(AT91_RTC_CR, cr | AT91_RTC_UPDCAL | AT91_RTC_UPDTIM); 168 112 169 - at91_rtc_write(AT91_RTC_IER, AT91_RTC_ACKUPD); 113 + at91_rtc_write_ier(AT91_RTC_ACKUPD); 170 114 wait_for_completion(&at91_rtc_updated); /* wait for ACKUPD interrupt */ 171 - at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ACKUPD); 115 + at91_rtc_write_idr(AT91_RTC_ACKUPD); 172 116 173 117 at91_rtc_write(AT91_RTC_TIMR, 174 118 bin2bcd(tm->tm_sec) << 0 ··· 200 144 tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year); 201 145 tm->tm_year = at91_alarm_year - 1900; 202 146 203 - alrm->enabled = (at91_rtc_read(AT91_RTC_IMR) & AT91_RTC_ALARM) 147 + alrm->enabled = (at91_rtc_read_imr() & AT91_RTC_ALARM) 204 148 ? 1 : 0; 205 149 206 150 dev_dbg(dev, "%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__, ··· 225 169 tm.tm_min = alrm->time.tm_min; 226 170 tm.tm_sec = alrm->time.tm_sec; 227 171 228 - at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ALARM); 172 + at91_rtc_write_idr(AT91_RTC_ALARM); 229 173 at91_rtc_write(AT91_RTC_TIMALR, 230 174 bin2bcd(tm.tm_sec) << 0 231 175 | bin2bcd(tm.tm_min) << 8 ··· 238 182 239 183 if (alrm->enabled) { 240 184 at91_rtc_write(AT91_RTC_SCCR, AT91_RTC_ALARM); 241 - at91_rtc_write(AT91_RTC_IER, AT91_RTC_ALARM); 185 + at91_rtc_write_ier(AT91_RTC_ALARM); 242 186 } 243 187 244 188 dev_dbg(dev, "%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__, ··· 254 198 255 199 if (enabled) { 256 200 at91_rtc_write(AT91_RTC_SCCR, AT91_RTC_ALARM); 257 - at91_rtc_write(AT91_RTC_IER, AT91_RTC_ALARM); 201 + at91_rtc_write_ier(AT91_RTC_ALARM); 258 202 } else 259 - at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ALARM); 203 + at91_rtc_write_idr(AT91_RTC_ALARM); 260 204 261 205 return 0; 262 206 } ··· 265 209 */ 266 210 static int at91_rtc_proc(struct device *dev, struct seq_file *seq) 267 211 { 268 - unsigned long imr = at91_rtc_read(AT91_RTC_IMR); 212 + unsigned long imr = at91_rtc_read_imr(); 269 213 270 214 seq_printf(seq, "update_IRQ\t: %s\n", 271 215 (imr & AT91_RTC_ACKUPD) ? "yes" : "no"); ··· 285 229 unsigned int rtsr; 286 230 unsigned long events = 0; 287 231 288 - rtsr = at91_rtc_read(AT91_RTC_SR) & at91_rtc_read(AT91_RTC_IMR); 232 + rtsr = at91_rtc_read(AT91_RTC_SR) & at91_rtc_read_imr(); 289 233 if (rtsr) { /* this interrupt is shared! Is it ours? */ 290 234 if (rtsr & AT91_RTC_ALARM) 291 235 events |= (RTC_AF | RTC_IRQF); ··· 306 250 return IRQ_NONE; /* not handled */ 307 251 } 308 252 253 + static const struct at91_rtc_config at91rm9200_config = { 254 + }; 255 + 256 + static const struct at91_rtc_config at91sam9x5_config = { 257 + .use_shadow_imr = true, 258 + }; 259 + 260 + #ifdef CONFIG_OF 261 + static const struct of_device_id at91_rtc_dt_ids[] = { 262 + { 263 + .compatible = "atmel,at91rm9200-rtc", 264 + .data = &at91rm9200_config, 265 + }, { 266 + .compatible = "atmel,at91sam9x5-rtc", 267 + .data = &at91sam9x5_config, 268 + }, { 269 + /* sentinel */ 270 + } 271 + }; 272 + MODULE_DEVICE_TABLE(of, at91_rtc_dt_ids); 273 + #endif 274 + 275 + static const struct at91_rtc_config * 276 + at91_rtc_get_config(struct platform_device *pdev) 277 + { 278 + const struct of_device_id *match; 279 + 280 + if (pdev->dev.of_node) { 281 + match = of_match_node(at91_rtc_dt_ids, pdev->dev.of_node); 282 + if (!match) 283 + return NULL; 284 + return (const struct at91_rtc_config *)match->data; 285 + } 286 + 287 + return &at91rm9200_config; 288 + } 289 + 309 290 static const struct rtc_class_ops at91_rtc_ops = { 310 291 .read_time = at91_rtc_readtime, 311 292 .set_time = at91_rtc_settime, ··· 360 267 struct rtc_device *rtc; 361 268 struct resource *regs; 362 269 int ret = 0; 270 + 271 + at91_rtc_config = at91_rtc_get_config(pdev); 272 + if (!at91_rtc_config) 273 + return -ENODEV; 363 274 364 275 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 365 276 if (!regs) { ··· 387 290 at91_rtc_write(AT91_RTC_MR, 0); /* 24 hour mode */ 388 291 389 292 /* Disable all interrupts */ 390 - at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ACKUPD | AT91_RTC_ALARM | 293 + at91_rtc_write_idr(AT91_RTC_ACKUPD | AT91_RTC_ALARM | 391 294 AT91_RTC_SECEV | AT91_RTC_TIMEV | 392 295 AT91_RTC_CALEV); 393 296 ··· 432 335 struct rtc_device *rtc = platform_get_drvdata(pdev); 433 336 434 337 /* Disable all interrupts */ 435 - at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ACKUPD | AT91_RTC_ALARM | 338 + at91_rtc_write_idr(AT91_RTC_ACKUPD | AT91_RTC_ALARM | 436 339 AT91_RTC_SECEV | AT91_RTC_TIMEV | 437 340 AT91_RTC_CALEV); 438 341 free_irq(irq, pdev); ··· 455 358 /* this IRQ is shared with DBGU and other hardware which isn't 456 359 * necessarily doing PM like we are... 457 360 */ 458 - at91_rtc_imr = at91_rtc_read(AT91_RTC_IMR) 361 + at91_rtc_imr = at91_rtc_read_imr() 459 362 & (AT91_RTC_ALARM|AT91_RTC_SECEV); 460 363 if (at91_rtc_imr) { 461 364 if (device_may_wakeup(dev)) 462 365 enable_irq_wake(irq); 463 366 else 464 - at91_rtc_write(AT91_RTC_IDR, at91_rtc_imr); 367 + at91_rtc_write_idr(at91_rtc_imr); 465 368 } 466 369 return 0; 467 370 } ··· 472 375 if (device_may_wakeup(dev)) 473 376 disable_irq_wake(irq); 474 377 else 475 - at91_rtc_write(AT91_RTC_IER, at91_rtc_imr); 378 + at91_rtc_write_ier(at91_rtc_imr); 476 379 } 477 380 return 0; 478 381 } 479 382 #endif 480 383 481 384 static SIMPLE_DEV_PM_OPS(at91_rtc_pm_ops, at91_rtc_suspend, at91_rtc_resume); 482 - 483 - static const struct of_device_id at91_rtc_dt_ids[] = { 484 - { .compatible = "atmel,at91rm9200-rtc" }, 485 - { /* sentinel */ } 486 - }; 487 - MODULE_DEVICE_TABLE(of, at91_rtc_dt_ids); 488 385 489 386 static struct platform_driver at91_rtc_driver = { 490 387 .remove = __exit_p(at91_rtc_remove),
+3 -1
drivers/rtc/rtc-cmos.c
··· 854 854 } 855 855 856 856 spin_lock_irq(&rtc_lock); 857 + if (device_may_wakeup(dev)) 858 + hpet_rtc_timer_init(); 859 + 857 860 do { 858 861 CMOS_WRITE(tmp, RTC_CONTROL); 859 862 hpet_set_rtc_irq_bit(tmp & RTC_IRQMASK); ··· 872 869 rtc_update_irq(cmos->rtc, 1, mask); 873 870 tmp &= ~RTC_AIE; 874 871 hpet_mask_rtc_irq_bit(RTC_AIE); 875 - hpet_rtc_timer_init(); 876 872 } while (mask & RTC_AIE); 877 873 spin_unlock_irq(&rtc_lock); 878 874 }
+2 -1
drivers/rtc/rtc-tps6586x.c
··· 273 273 return ret; 274 274 } 275 275 276 + device_init_wakeup(&pdev->dev, 1); 277 + 276 278 platform_set_drvdata(pdev, rtc); 277 279 rtc->rtc = devm_rtc_device_register(&pdev->dev, dev_name(&pdev->dev), 278 280 &tps6586x_rtc_ops, THIS_MODULE); ··· 294 292 goto fail_rtc_register; 295 293 } 296 294 disable_irq(rtc->irq); 297 - device_set_wakeup_capable(&pdev->dev, 1); 298 295 return 0; 299 296 300 297 fail_rtc_register:
+1
drivers/rtc/rtc-twl.c
··· 524 524 } 525 525 526 526 platform_set_drvdata(pdev, rtc); 527 + device_init_wakeup(&pdev->dev, 1); 527 528 return 0; 528 529 529 530 out2:
+16 -20
fs/aio.c
··· 141 141 for (i = 0; i < ctx->nr_pages; i++) 142 142 put_page(ctx->ring_pages[i]); 143 143 144 - if (ctx->mmap_size) 145 - vm_munmap(ctx->mmap_base, ctx->mmap_size); 146 - 147 144 if (ctx->ring_pages && ctx->ring_pages != ctx->internal_pages) 148 145 kfree(ctx->ring_pages); 149 146 } ··· 319 322 320 323 aio_free_ring(ctx); 321 324 322 - spin_lock(&aio_nr_lock); 323 - BUG_ON(aio_nr - ctx->max_reqs > aio_nr); 324 - aio_nr -= ctx->max_reqs; 325 - spin_unlock(&aio_nr_lock); 326 - 327 325 pr_debug("freeing %p\n", ctx); 328 326 329 327 /* ··· 427 435 { 428 436 if (!atomic_xchg(&ctx->dead, 1)) { 429 437 hlist_del_rcu(&ctx->list); 430 - /* Between hlist_del_rcu() and dropping the initial ref */ 431 - synchronize_rcu(); 432 438 433 439 /* 434 - * We can't punt to workqueue here because put_ioctx() -> 435 - * free_ioctx() will unmap the ringbuffer, and that has to be 436 - * done in the original process's context. kill_ioctx_rcu/work() 437 - * exist for exit_aio(), as in that path free_ioctx() won't do 438 - * the unmap. 440 + * It'd be more correct to do this in free_ioctx(), after all 441 + * the outstanding kiocbs have finished - but by then io_destroy 442 + * has already returned, so io_setup() could potentially return 443 + * -EAGAIN with no ioctxs actually in use (as far as userspace 444 + * could tell). 439 445 */ 440 - kill_ioctx_work(&ctx->rcu_work); 446 + spin_lock(&aio_nr_lock); 447 + BUG_ON(aio_nr - ctx->max_reqs > aio_nr); 448 + aio_nr -= ctx->max_reqs; 449 + spin_unlock(&aio_nr_lock); 450 + 451 + if (ctx->mmap_size) 452 + vm_munmap(ctx->mmap_base, ctx->mmap_size); 453 + 454 + /* Between hlist_del_rcu() and dropping the initial ref */ 455 + call_rcu(&ctx->rcu_head, kill_ioctx_rcu); 441 456 } 442 457 } 443 458 ··· 494 495 */ 495 496 ctx->mmap_size = 0; 496 497 497 - if (!atomic_xchg(&ctx->dead, 1)) { 498 - hlist_del_rcu(&ctx->list); 499 - call_rcu(&ctx->rcu_head, kill_ioctx_rcu); 500 - } 498 + kill_ioctx(ctx); 501 499 } 502 500 } 503 501
+1
fs/ocfs2/dlm/dlmrecovery.c
··· 1408 1408 mres->lockname_len, mres->lockname); 1409 1409 ret = -EFAULT; 1410 1410 spin_unlock(&res->spinlock); 1411 + dlm_lockres_put(res); 1411 1412 goto leave; 1412 1413 } 1413 1414 res->state |= DLM_LOCK_RES_MIGRATING;
+2 -2
fs/ocfs2/namei.c
··· 947 947 ocfs2_free_dir_lookup_result(&orphan_insert); 948 948 ocfs2_free_dir_lookup_result(&lookup); 949 949 950 - if (status) 950 + if (status && (status != -ENOTEMPTY)) 951 951 mlog_errno(status); 952 952 953 953 return status; ··· 2216 2216 2217 2217 brelse(orphan_dir_bh); 2218 2218 2219 - return 0; 2219 + return ret; 2220 2220 } 2221 2221 2222 2222 int ocfs2_create_inode_in_orphan(struct inode *dir,
+5 -5
fs/proc/kmsg.c
··· 21 21 22 22 static int kmsg_open(struct inode * inode, struct file * file) 23 23 { 24 - return do_syslog(SYSLOG_ACTION_OPEN, NULL, 0, SYSLOG_FROM_FILE); 24 + return do_syslog(SYSLOG_ACTION_OPEN, NULL, 0, SYSLOG_FROM_PROC); 25 25 } 26 26 27 27 static int kmsg_release(struct inode * inode, struct file * file) 28 28 { 29 - (void) do_syslog(SYSLOG_ACTION_CLOSE, NULL, 0, SYSLOG_FROM_FILE); 29 + (void) do_syslog(SYSLOG_ACTION_CLOSE, NULL, 0, SYSLOG_FROM_PROC); 30 30 return 0; 31 31 } 32 32 ··· 34 34 size_t count, loff_t *ppos) 35 35 { 36 36 if ((file->f_flags & O_NONBLOCK) && 37 - !do_syslog(SYSLOG_ACTION_SIZE_UNREAD, NULL, 0, SYSLOG_FROM_FILE)) 37 + !do_syslog(SYSLOG_ACTION_SIZE_UNREAD, NULL, 0, SYSLOG_FROM_PROC)) 38 38 return -EAGAIN; 39 - return do_syslog(SYSLOG_ACTION_READ, buf, count, SYSLOG_FROM_FILE); 39 + return do_syslog(SYSLOG_ACTION_READ, buf, count, SYSLOG_FROM_PROC); 40 40 } 41 41 42 42 static unsigned int kmsg_poll(struct file *file, poll_table *wait) 43 43 { 44 44 poll_wait(file, &log_wait, wait); 45 - if (do_syslog(SYSLOG_ACTION_SIZE_UNREAD, NULL, 0, SYSLOG_FROM_FILE)) 45 + if (do_syslog(SYSLOG_ACTION_SIZE_UNREAD, NULL, 0, SYSLOG_FROM_PROC)) 46 46 return POLLIN | POLLRDNORM; 47 47 return 0; 48 48 }
+4
include/linux/cpu.h
··· 175 175 176 176 extern void get_online_cpus(void); 177 177 extern void put_online_cpus(void); 178 + extern void cpu_hotplug_disable(void); 179 + extern void cpu_hotplug_enable(void); 178 180 #define hotcpu_notifier(fn, pri) cpu_notifier(fn, pri) 179 181 #define register_hotcpu_notifier(nb) register_cpu_notifier(nb) 180 182 #define unregister_hotcpu_notifier(nb) unregister_cpu_notifier(nb) ··· 200 198 201 199 #define get_online_cpus() do { } while (0) 202 200 #define put_online_cpus() do { } while (0) 201 + #define cpu_hotplug_disable() do { } while (0) 202 + #define cpu_hotplug_enable() do { } while (0) 203 203 #define hotcpu_notifier(fn, pri) do { (void)(fn); } while (0) 204 204 /* These aren't inline functions due to a GCC bug. */ 205 205 #define register_hotcpu_notifier(nb) ({ (void)(nb); 0; })
+4 -2
include/linux/math64.h
··· 6 6 7 7 #if BITS_PER_LONG == 64 8 8 9 - #define div64_long(x,y) div64_s64((x),(y)) 9 + #define div64_long(x, y) div64_s64((x), (y)) 10 + #define div64_ul(x, y) div64_u64((x), (y)) 10 11 11 12 /** 12 13 * div_u64_rem - unsigned 64bit divide with 32bit divisor with remainder ··· 48 47 49 48 #elif BITS_PER_LONG == 32 50 49 51 - #define div64_long(x,y) div_s64((x),(y)) 50 + #define div64_long(x, y) div_s64((x), (y)) 51 + #define div64_ul(x, y) div_u64((x), (y)) 52 52 53 53 #ifndef div_u64_rem 54 54 static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
+3
include/linux/swapops.h
··· 137 137 138 138 extern void migration_entry_wait(struct mm_struct *mm, pmd_t *pmd, 139 139 unsigned long address); 140 + extern void migration_entry_wait_huge(struct mm_struct *mm, pte_t *pte); 140 141 #else 141 142 142 143 #define make_migration_entry(page, write) swp_entry(0, 0) ··· 149 148 static inline void make_migration_entry_read(swp_entry_t *entryp) { } 150 149 static inline void migration_entry_wait(struct mm_struct *mm, pmd_t *pmd, 151 150 unsigned long address) { } 151 + static inline void migration_entry_wait_huge(struct mm_struct *mm, 152 + pte_t *pte) { } 152 153 static inline int is_write_migration_entry(swp_entry_t entry) 153 154 { 154 155 return 0;
+2 -2
include/linux/syslog.h
··· 44 44 /* Return size of the log buffer */ 45 45 #define SYSLOG_ACTION_SIZE_BUFFER 10 46 46 47 - #define SYSLOG_FROM_CALL 0 48 - #define SYSLOG_FROM_FILE 1 47 + #define SYSLOG_FROM_READER 0 48 + #define SYSLOG_FROM_PROC 1 49 49 50 50 int do_syslog(int type, char __user *buf, int count, bool from_file); 51 51
+1 -1
kernel/audit.c
··· 1056 1056 static void wait_for_auditd(unsigned long sleep_time) 1057 1057 { 1058 1058 DECLARE_WAITQUEUE(wait, current); 1059 - set_current_state(TASK_INTERRUPTIBLE); 1059 + set_current_state(TASK_UNINTERRUPTIBLE); 1060 1060 add_wait_queue(&audit_backlog_wait, &wait); 1061 1061 1062 1062 if (audit_backlog_limit &&
+1
kernel/audit_tree.c
··· 658 658 struct vfsmount *mnt; 659 659 int err; 660 660 661 + rule->tree = NULL; 661 662 list_for_each_entry(tree, &tree_list, list) { 662 663 if (!strcmp(seed->pathname, tree->pathname)) { 663 664 put_tree(seed);
+23 -32
kernel/cpu.c
··· 133 133 mutex_unlock(&cpu_hotplug.lock); 134 134 } 135 135 136 + /* 137 + * Wait for currently running CPU hotplug operations to complete (if any) and 138 + * disable future CPU hotplug (from sysfs). The 'cpu_add_remove_lock' protects 139 + * the 'cpu_hotplug_disabled' flag. The same lock is also acquired by the 140 + * hotplug path before performing hotplug operations. So acquiring that lock 141 + * guarantees mutual exclusion from any currently running hotplug operations. 142 + */ 143 + void cpu_hotplug_disable(void) 144 + { 145 + cpu_maps_update_begin(); 146 + cpu_hotplug_disabled = 1; 147 + cpu_maps_update_done(); 148 + } 149 + 150 + void cpu_hotplug_enable(void) 151 + { 152 + cpu_maps_update_begin(); 153 + cpu_hotplug_disabled = 0; 154 + cpu_maps_update_done(); 155 + } 156 + 136 157 #else /* #if CONFIG_HOTPLUG_CPU */ 137 158 static void cpu_hotplug_begin(void) {} 138 159 static void cpu_hotplug_done(void) {} ··· 562 541 core_initcall(alloc_frozen_cpus); 563 542 564 543 /* 565 - * Prevent regular CPU hotplug from racing with the freezer, by disabling CPU 566 - * hotplug when tasks are about to be frozen. Also, don't allow the freezer 567 - * to continue until any currently running CPU hotplug operation gets 568 - * completed. 569 - * To modify the 'cpu_hotplug_disabled' flag, we need to acquire the 570 - * 'cpu_add_remove_lock'. And this same lock is also taken by the regular 571 - * CPU hotplug path and released only after it is complete. Thus, we 572 - * (and hence the freezer) will block here until any currently running CPU 573 - * hotplug operation gets completed. 574 - */ 575 - void cpu_hotplug_disable_before_freeze(void) 576 - { 577 - cpu_maps_update_begin(); 578 - cpu_hotplug_disabled = 1; 579 - cpu_maps_update_done(); 580 - } 581 - 582 - 583 - /* 584 - * When tasks have been thawed, re-enable regular CPU hotplug (which had been 585 - * disabled while beginning to freeze tasks). 586 - */ 587 - void cpu_hotplug_enable_after_thaw(void) 588 - { 589 - cpu_maps_update_begin(); 590 - cpu_hotplug_disabled = 0; 591 - cpu_maps_update_done(); 592 - } 593 - 594 - /* 595 544 * When callbacks for CPU hotplug notifications are being executed, we must 596 545 * ensure that the state of the system with respect to the tasks being frozen 597 546 * or not, as reported by the notification, remains unchanged *throughout the ··· 580 589 581 590 case PM_SUSPEND_PREPARE: 582 591 case PM_HIBERNATION_PREPARE: 583 - cpu_hotplug_disable_before_freeze(); 592 + cpu_hotplug_disable(); 584 593 break; 585 594 586 595 case PM_POST_SUSPEND: 587 596 case PM_POST_HIBERNATION: 588 - cpu_hotplug_enable_after_thaw(); 597 + cpu_hotplug_enable(); 589 598 break; 590 599 591 600 default:
+50 -41
kernel/printk.c
··· 363 363 log_next_seq++; 364 364 } 365 365 366 + #ifdef CONFIG_SECURITY_DMESG_RESTRICT 367 + int dmesg_restrict = 1; 368 + #else 369 + int dmesg_restrict; 370 + #endif 371 + 372 + static int syslog_action_restricted(int type) 373 + { 374 + if (dmesg_restrict) 375 + return 1; 376 + /* 377 + * Unless restricted, we allow "read all" and "get buffer size" 378 + * for everybody. 379 + */ 380 + return type != SYSLOG_ACTION_READ_ALL && 381 + type != SYSLOG_ACTION_SIZE_BUFFER; 382 + } 383 + 384 + static int check_syslog_permissions(int type, bool from_file) 385 + { 386 + /* 387 + * If this is from /proc/kmsg and we've already opened it, then we've 388 + * already done the capabilities checks at open time. 389 + */ 390 + if (from_file && type != SYSLOG_ACTION_OPEN) 391 + return 0; 392 + 393 + if (syslog_action_restricted(type)) { 394 + if (capable(CAP_SYSLOG)) 395 + return 0; 396 + /* 397 + * For historical reasons, accept CAP_SYS_ADMIN too, with 398 + * a warning. 399 + */ 400 + if (capable(CAP_SYS_ADMIN)) { 401 + pr_warn_once("%s (%d): Attempt to access syslog with " 402 + "CAP_SYS_ADMIN but no CAP_SYSLOG " 403 + "(deprecated).\n", 404 + current->comm, task_pid_nr(current)); 405 + return 0; 406 + } 407 + return -EPERM; 408 + } 409 + return security_syslog(type); 410 + } 411 + 412 + 366 413 /* /dev/kmsg - userspace message inject/listen interface */ 367 414 struct devkmsg_user { 368 415 u64 seq; ··· 667 620 if ((file->f_flags & O_ACCMODE) == O_WRONLY) 668 621 return 0; 669 622 670 - err = security_syslog(SYSLOG_ACTION_READ_ALL); 623 + err = check_syslog_permissions(SYSLOG_ACTION_READ_ALL, 624 + SYSLOG_FROM_READER); 671 625 if (err) 672 626 return err; 673 627 ··· 860 812 { 861 813 } 862 814 #endif 863 - 864 - #ifdef CONFIG_SECURITY_DMESG_RESTRICT 865 - int dmesg_restrict = 1; 866 - #else 867 - int dmesg_restrict; 868 - #endif 869 - 870 - static int syslog_action_restricted(int type) 871 - { 872 - if (dmesg_restrict) 873 - return 1; 874 - /* Unless restricted, we allow "read all" and "get buffer size" for everybody */ 875 - return type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER; 876 - } 877 - 878 - static int check_syslog_permissions(int type, bool from_file) 879 - { 880 - /* 881 - * If this is from /proc/kmsg and we've already opened it, then we've 882 - * already done the capabilities checks at open time. 883 - */ 884 - if (from_file && type != SYSLOG_ACTION_OPEN) 885 - return 0; 886 - 887 - if (syslog_action_restricted(type)) { 888 - if (capable(CAP_SYSLOG)) 889 - return 0; 890 - /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */ 891 - if (capable(CAP_SYS_ADMIN)) { 892 - printk_once(KERN_WARNING "%s (%d): " 893 - "Attempt to access syslog with CAP_SYS_ADMIN " 894 - "but no CAP_SYSLOG (deprecated).\n", 895 - current->comm, task_pid_nr(current)); 896 - return 0; 897 - } 898 - return -EPERM; 899 - } 900 - return 0; 901 - } 902 815 903 816 #if defined(CONFIG_PRINTK_TIME) 904 817 static bool printk_time = 1; ··· 1258 1249 1259 1250 SYSCALL_DEFINE3(syslog, int, type, char __user *, buf, int, len) 1260 1251 { 1261 - return do_syslog(type, buf, len, SYSLOG_FROM_CALL); 1252 + return do_syslog(type, buf, len, SYSLOG_FROM_READER); 1262 1253 } 1263 1254 1264 1255 /*
+26 -3
kernel/sys.c
··· 362 362 } 363 363 EXPORT_SYMBOL(unregister_reboot_notifier); 364 364 365 + /* Add backwards compatibility for stable trees. */ 366 + #ifndef PF_NO_SETAFFINITY 367 + #define PF_NO_SETAFFINITY PF_THREAD_BOUND 368 + #endif 369 + 370 + static void migrate_to_reboot_cpu(void) 371 + { 372 + /* The boot cpu is always logical cpu 0 */ 373 + int cpu = 0; 374 + 375 + cpu_hotplug_disable(); 376 + 377 + /* Make certain the cpu I'm about to reboot on is online */ 378 + if (!cpu_online(cpu)) 379 + cpu = cpumask_first(cpu_online_mask); 380 + 381 + /* Prevent races with other tasks migrating this task */ 382 + current->flags |= PF_NO_SETAFFINITY; 383 + 384 + /* Make certain I only run on the appropriate processor */ 385 + set_cpus_allowed_ptr(current, cpumask_of(cpu)); 386 + } 387 + 365 388 /** 366 389 * kernel_restart - reboot the system 367 390 * @cmd: pointer to buffer containing command to execute for restart ··· 396 373 void kernel_restart(char *cmd) 397 374 { 398 375 kernel_restart_prepare(cmd); 399 - disable_nonboot_cpus(); 376 + migrate_to_reboot_cpu(); 400 377 syscore_shutdown(); 401 378 if (!cmd) 402 379 printk(KERN_EMERG "Restarting system.\n"); ··· 423 400 void kernel_halt(void) 424 401 { 425 402 kernel_shutdown_prepare(SYSTEM_HALT); 426 - disable_nonboot_cpus(); 403 + migrate_to_reboot_cpu(); 427 404 syscore_shutdown(); 428 405 printk(KERN_EMERG "System halted.\n"); 429 406 kmsg_dump(KMSG_DUMP_HALT); ··· 442 419 kernel_shutdown_prepare(SYSTEM_POWER_OFF); 443 420 if (pm_power_off_prepare) 444 421 pm_power_off_prepare(); 445 - disable_nonboot_cpus(); 422 + migrate_to_reboot_cpu(); 446 423 syscore_shutdown(); 447 424 printk(KERN_EMERG "Power down.\n"); 448 425 kmsg_dump(KMSG_DUMP_POWEROFF);
+1 -1
lib/mpi/mpicoder.c
··· 37 37 mpi_limb_t a; 38 38 MPI val = NULL; 39 39 40 - while (nbytes >= 0 && buffer[0] == 0) { 40 + while (nbytes > 0 && buffer[0] == 0) { 41 41 buffer++; 42 42 nbytes--; 43 43 }
+1 -1
mm/frontswap.c
··· 319 319 return; 320 320 frontswap_ops->invalidate_area(type); 321 321 atomic_set(&sis->frontswap_pages, 0); 322 - memset(sis->frontswap_map, 0, sis->max / sizeof(long)); 322 + bitmap_zero(sis->frontswap_map, sis->max); 323 323 } 324 324 clear_bit(type, need_init); 325 325 }
+1 -1
mm/hugetlb.c
··· 2839 2839 if (ptep) { 2840 2840 entry = huge_ptep_get(ptep); 2841 2841 if (unlikely(is_hugetlb_entry_migration(entry))) { 2842 - migration_entry_wait(mm, (pmd_t *)ptep, address); 2842 + migration_entry_wait_huge(mm, ptep); 2843 2843 return 0; 2844 2844 } else if (unlikely(is_hugetlb_entry_hwpoisoned(entry))) 2845 2845 return VM_FAULT_HWPOISON_LARGE |
+5 -9
mm/memcontrol.c
··· 1199 1199 1200 1200 mz = mem_cgroup_zoneinfo(root, nid, zid); 1201 1201 iter = &mz->reclaim_iter[reclaim->priority]; 1202 - last_visited = iter->last_visited; 1203 1202 if (prev && reclaim->generation != iter->generation) { 1204 1203 iter->last_visited = NULL; 1205 1204 goto out_unlock; ··· 1217 1218 * is alive. 1218 1219 */ 1219 1220 dead_count = atomic_read(&root->dead_count); 1220 - smp_rmb(); 1221 - last_visited = iter->last_visited; 1222 - if (last_visited) { 1223 - if ((dead_count != iter->last_dead_count) || 1224 - !css_tryget(&last_visited->css)) { 1221 + if (dead_count == iter->last_dead_count) { 1222 + smp_rmb(); 1223 + last_visited = iter->last_visited; 1224 + if (last_visited && 1225 + !css_tryget(&last_visited->css)) 1225 1226 last_visited = NULL; 1226 - } 1227 1227 } 1228 1228 } 1229 1229 ··· 3139 3141 return -ENOMEM; 3140 3142 } 3141 3143 3142 - INIT_WORK(&s->memcg_params->destroy, 3143 - kmem_cache_destroy_work_func); 3144 3144 s->memcg_params->is_root_cache = true; 3145 3145 3146 3146 /*
+18 -5
mm/migrate.c
··· 200 200 * get to the page and wait until migration is finished. 201 201 * When we return from this function the fault will be retried. 202 202 */ 203 - void migration_entry_wait(struct mm_struct *mm, pmd_t *pmd, 204 - unsigned long address) 203 + static void __migration_entry_wait(struct mm_struct *mm, pte_t *ptep, 204 + spinlock_t *ptl) 205 205 { 206 - pte_t *ptep, pte; 207 - spinlock_t *ptl; 206 + pte_t pte; 208 207 swp_entry_t entry; 209 208 struct page *page; 210 209 211 - ptep = pte_offset_map_lock(mm, pmd, address, &ptl); 210 + spin_lock(ptl); 212 211 pte = *ptep; 213 212 if (!is_swap_pte(pte)) 214 213 goto out; ··· 233 234 return; 234 235 out: 235 236 pte_unmap_unlock(ptep, ptl); 237 + } 238 + 239 + void migration_entry_wait(struct mm_struct *mm, pmd_t *pmd, 240 + unsigned long address) 241 + { 242 + spinlock_t *ptl = pte_lockptr(mm, pmd); 243 + pte_t *ptep = pte_offset_map(pmd, address); 244 + __migration_entry_wait(mm, ptep, ptl); 245 + } 246 + 247 + void migration_entry_wait_huge(struct mm_struct *mm, pte_t *pte) 248 + { 249 + spinlock_t *ptl = &(mm)->page_table_lock; 250 + __migration_entry_wait(mm, pte, ptl); 236 251 } 237 252 238 253 #ifdef CONFIG_BLOCK
+4 -2
mm/page_alloc.c
··· 1628 1628 long min = mark; 1629 1629 long lowmem_reserve = z->lowmem_reserve[classzone_idx]; 1630 1630 int o; 1631 + long free_cma = 0; 1631 1632 1632 1633 free_pages -= (1 << order) - 1; 1633 1634 if (alloc_flags & ALLOC_HIGH) ··· 1638 1637 #ifdef CONFIG_CMA 1639 1638 /* If allocation can't use CMA areas don't use free CMA pages */ 1640 1639 if (!(alloc_flags & ALLOC_CMA)) 1641 - free_pages -= zone_page_state(z, NR_FREE_CMA_PAGES); 1640 + free_cma = zone_page_state(z, NR_FREE_CMA_PAGES); 1642 1641 #endif 1643 - if (free_pages <= min + lowmem_reserve) 1642 + 1643 + if (free_pages - free_cma <= min + lowmem_reserve) 1644 1644 return false; 1645 1645 for (o = 0; o < order; o++) { 1646 1646 /* At the next order, this order's pages become unavailable */
+17 -1
mm/swap_state.c
··· 336 336 * Swap entry may have been freed since our caller observed it. 337 337 */ 338 338 err = swapcache_prepare(entry); 339 - if (err == -EEXIST) { /* seems racy */ 339 + if (err == -EEXIST) { 340 340 radix_tree_preload_end(); 341 + /* 342 + * We might race against get_swap_page() and stumble 343 + * across a SWAP_HAS_CACHE swap_map entry whose page 344 + * has not been brought into the swapcache yet, while 345 + * the other end is scheduled away waiting on discard 346 + * I/O completion at scan_swap_map(). 347 + * 348 + * In order to avoid turning this transitory state 349 + * into a permanent loop around this -EEXIST case 350 + * if !CONFIG_PREEMPT and the I/O completion happens 351 + * to be waiting on the CPU waitqueue where we are now 352 + * busy looping, we just conditionally invoke the 353 + * scheduler here, if there are some more important 354 + * tasks to run. 355 + */ 356 + cond_resched(); 341 357 continue; 342 358 } 343 359 if (err) { /* swp entry is obsolete ? */
+1 -1
mm/swapfile.c
··· 2116 2116 } 2117 2117 /* frontswap enabled? set up bit-per-page map for frontswap */ 2118 2118 if (frontswap_enabled) 2119 - frontswap_map = vzalloc(maxpages / sizeof(long)); 2119 + frontswap_map = vzalloc(BITS_TO_LONGS(maxpages) * sizeof(long)); 2120 2120 2121 2121 if (p->bdev) { 2122 2122 if (blk_queue_nonrot(bdev_get_queue(p->bdev))) {