aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Marciniszyn <mike.marciniszyn@intel.com>2016-08-31 10:24:46 -0400
committerDoug Ledford <dledford@redhat.com>2016-09-02 14:26:55 -0400
commit16170d9c102764f76c58aad244e947f4e3f44590 (patch)
tree717586260a4fa59c6fee4fae4400e082207f43cd
parent429b6a721727d49d8565b50a6bc0dc42432383a9 (diff)
IB/hfi1: Rework debugfs to use SRCU
The debugfs RCU trips many debug kernel warnings because of potential sleeps with an RCU read lock held. This includes both user copy calls and slab allocations throughout the file. This patch switches the RCU to use SRCU for file remove/access race protection. In one case, the SRCU is implicit in the use of the raw debugfs file object and just works. In the seq_file case, a wrapper around seq_read() and seq_lseek() is used to enforce the SRCU using the debugfs supplied functions debugfs_use_file_start() and debugfs_use_file_stop(). The sychronize_rcu() is deleted since the SRCU prevents the remove access race. The RCU locking is kept for qp_stats since the QP hash list is protected using the non-sleepable RCU. Reviewed-by: Sebastian Sanchez <sebastian.sanchez@intel.com> Signed-off-by: Mike Marciniszyn <mike.marciniszyn@intel.com> Signed-off-by: Dennis Dalessandro <dennis.dalessandro@intel.com> Signed-off-by: Doug Ledford <dledford@redhat.com>
-rw-r--r--drivers/infiniband/hw/hfi1/debugfs.c132
1 files changed, 52 insertions, 80 deletions
diff --git a/drivers/infiniband/hw/hfi1/debugfs.c b/drivers/infiniband/hw/hfi1/debugfs.c
index a49cc88f08a2..5e9be16f6cd3 100644
--- a/drivers/infiniband/hw/hfi1/debugfs.c
+++ b/drivers/infiniband/hw/hfi1/debugfs.c
@@ -59,6 +59,40 @@
59 59
60static struct dentry *hfi1_dbg_root; 60static struct dentry *hfi1_dbg_root;
61 61
62/* wrappers to enforce srcu in seq file */
63static ssize_t hfi1_seq_read(
64 struct file *file,
65 char __user *buf,
66 size_t size,
67 loff_t *ppos)
68{
69 struct dentry *d = file->f_path.dentry;
70 int srcu_idx;
71 ssize_t r;
72
73 r = debugfs_use_file_start(d, &srcu_idx);
74 if (likely(!r))
75 r = seq_read(file, buf, size, ppos);
76 debugfs_use_file_finish(srcu_idx);
77 return r;
78}
79
80static loff_t hfi1_seq_lseek(
81 struct file *file,
82 loff_t offset,
83 int whence)
84{
85 struct dentry *d = file->f_path.dentry;
86 int srcu_idx;
87 loff_t r;
88
89 r = debugfs_use_file_start(d, &srcu_idx);
90 if (likely(!r))
91 r = seq_lseek(file, offset, whence);
92 debugfs_use_file_finish(srcu_idx);
93 return r;
94}
95
62#define private2dd(file) (file_inode(file)->i_private) 96#define private2dd(file) (file_inode(file)->i_private)
63#define private2ppd(file) (file_inode(file)->i_private) 97#define private2ppd(file) (file_inode(file)->i_private)
64 98
@@ -87,8 +121,8 @@ static int _##name##_open(struct inode *inode, struct file *s) \
87static const struct file_operations _##name##_file_ops = { \ 121static const struct file_operations _##name##_file_ops = { \
88 .owner = THIS_MODULE, \ 122 .owner = THIS_MODULE, \
89 .open = _##name##_open, \ 123 .open = _##name##_open, \
90 .read = seq_read, \ 124 .read = hfi1_seq_read, \
91 .llseek = seq_lseek, \ 125 .llseek = hfi1_seq_lseek, \
92 .release = seq_release \ 126 .release = seq_release \
93} 127}
94 128
@@ -105,11 +139,9 @@ do { \
105 DEBUGFS_FILE_CREATE(#name, parent, data, &_##name##_file_ops, S_IRUGO) 139 DEBUGFS_FILE_CREATE(#name, parent, data, &_##name##_file_ops, S_IRUGO)
106 140
107static void *_opcode_stats_seq_start(struct seq_file *s, loff_t *pos) 141static void *_opcode_stats_seq_start(struct seq_file *s, loff_t *pos)
108__acquires(RCU)
109{ 142{
110 struct hfi1_opcode_stats_perctx *opstats; 143 struct hfi1_opcode_stats_perctx *opstats;
111 144
112 rcu_read_lock();
113 if (*pos >= ARRAY_SIZE(opstats->stats)) 145 if (*pos >= ARRAY_SIZE(opstats->stats))
114 return NULL; 146 return NULL;
115 return pos; 147 return pos;
@@ -126,9 +158,7 @@ static void *_opcode_stats_seq_next(struct seq_file *s, void *v, loff_t *pos)
126} 158}
127 159
128static void _opcode_stats_seq_stop(struct seq_file *s, void *v) 160static void _opcode_stats_seq_stop(struct seq_file *s, void *v)
129__releases(RCU)
130{ 161{
131 rcu_read_unlock();
132} 162}
133 163
134static int _opcode_stats_seq_show(struct seq_file *s, void *v) 164static int _opcode_stats_seq_show(struct seq_file *s, void *v)
@@ -285,12 +315,10 @@ DEBUGFS_SEQ_FILE_OPEN(qp_stats)
285DEBUGFS_FILE_OPS(qp_stats); 315DEBUGFS_FILE_OPS(qp_stats);
286 316
287static void *_sdes_seq_start(struct seq_file *s, loff_t *pos) 317static void *_sdes_seq_start(struct seq_file *s, loff_t *pos)
288__acquires(RCU)
289{ 318{
290 struct hfi1_ibdev *ibd; 319 struct hfi1_ibdev *ibd;
291 struct hfi1_devdata *dd; 320 struct hfi1_devdata *dd;
292 321
293 rcu_read_lock();
294 ibd = (struct hfi1_ibdev *)s->private; 322 ibd = (struct hfi1_ibdev *)s->private;
295 dd = dd_from_dev(ibd); 323 dd = dd_from_dev(ibd);
296 if (!dd->per_sdma || *pos >= dd->num_sdma) 324 if (!dd->per_sdma || *pos >= dd->num_sdma)
@@ -310,9 +338,7 @@ static void *_sdes_seq_next(struct seq_file *s, void *v, loff_t *pos)
310} 338}
311 339
312static void _sdes_seq_stop(struct seq_file *s, void *v) 340static void _sdes_seq_stop(struct seq_file *s, void *v)
313__releases(RCU)
314{ 341{
315 rcu_read_unlock();
316} 342}
317 343
318static int _sdes_seq_show(struct seq_file *s, void *v) 344static int _sdes_seq_show(struct seq_file *s, void *v)
@@ -339,11 +365,9 @@ static ssize_t dev_counters_read(struct file *file, char __user *buf,
339 struct hfi1_devdata *dd; 365 struct hfi1_devdata *dd;
340 ssize_t rval; 366 ssize_t rval;
341 367
342 rcu_read_lock();
343 dd = private2dd(file); 368 dd = private2dd(file);
344 avail = hfi1_read_cntrs(dd, NULL, &counters); 369 avail = hfi1_read_cntrs(dd, NULL, &counters);
345 rval = simple_read_from_buffer(buf, count, ppos, counters, avail); 370 rval = simple_read_from_buffer(buf, count, ppos, counters, avail);
346 rcu_read_unlock();
347 return rval; 371 return rval;
348} 372}
349 373
@@ -356,11 +380,9 @@ static ssize_t dev_names_read(struct file *file, char __user *buf,
356 struct hfi1_devdata *dd; 380 struct hfi1_devdata *dd;
357 ssize_t rval; 381 ssize_t rval;
358 382
359 rcu_read_lock();
360 dd = private2dd(file); 383 dd = private2dd(file);
361 avail = hfi1_read_cntrs(dd, &names, NULL); 384 avail = hfi1_read_cntrs(dd, &names, NULL);
362 rval = simple_read_from_buffer(buf, count, ppos, names, avail); 385 rval = simple_read_from_buffer(buf, count, ppos, names, avail);
363 rcu_read_unlock();
364 return rval; 386 return rval;
365} 387}
366 388
@@ -383,11 +405,9 @@ static ssize_t portnames_read(struct file *file, char __user *buf,
383 struct hfi1_devdata *dd; 405 struct hfi1_devdata *dd;
384 ssize_t rval; 406 ssize_t rval;
385 407
386 rcu_read_lock();
387 dd = private2dd(file); 408 dd = private2dd(file);
388 avail = hfi1_read_portcntrs(dd->pport, &names, NULL); 409 avail = hfi1_read_portcntrs(dd->pport, &names, NULL);
389 rval = simple_read_from_buffer(buf, count, ppos, names, avail); 410 rval = simple_read_from_buffer(buf, count, ppos, names, avail);
390 rcu_read_unlock();
391 return rval; 411 return rval;
392} 412}
393 413
@@ -400,11 +420,9 @@ static ssize_t portcntrs_debugfs_read(struct file *file, char __user *buf,
400 struct hfi1_pportdata *ppd; 420 struct hfi1_pportdata *ppd;
401 ssize_t rval; 421 ssize_t rval;
402 422
403 rcu_read_lock();
404 ppd = private2ppd(file); 423 ppd = private2ppd(file);
405 avail = hfi1_read_portcntrs(ppd, NULL, &counters); 424 avail = hfi1_read_portcntrs(ppd, NULL, &counters);
406 rval = simple_read_from_buffer(buf, count, ppos, counters, avail); 425 rval = simple_read_from_buffer(buf, count, ppos, counters, avail);
407 rcu_read_unlock();
408 return rval; 426 return rval;
409} 427}
410 428
@@ -434,16 +452,13 @@ static ssize_t asic_flags_read(struct file *file, char __user *buf,
434 int used; 452 int used;
435 int i; 453 int i;
436 454
437 rcu_read_lock();
438 ppd = private2ppd(file); 455 ppd = private2ppd(file);
439 dd = ppd->dd; 456 dd = ppd->dd;
440 size = PAGE_SIZE; 457 size = PAGE_SIZE;
441 used = 0; 458 used = 0;
442 tmp = kmalloc(size, GFP_KERNEL); 459 tmp = kmalloc(size, GFP_KERNEL);
443 if (!tmp) { 460 if (!tmp)
444 rcu_read_unlock();
445 return -ENOMEM; 461 return -ENOMEM;
446 }
447 462
448 scratch0 = read_csr(dd, ASIC_CFG_SCRATCH); 463 scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
449 used += scnprintf(tmp + used, size - used, 464 used += scnprintf(tmp + used, size - used,
@@ -470,7 +485,6 @@ static ssize_t asic_flags_read(struct file *file, char __user *buf,
470 used += scnprintf(tmp + used, size - used, "Write bits to clear\n"); 485 used += scnprintf(tmp + used, size - used, "Write bits to clear\n");
471 486
472 ret = simple_read_from_buffer(buf, count, ppos, tmp, used); 487 ret = simple_read_from_buffer(buf, count, ppos, tmp, used);
473 rcu_read_unlock();
474 kfree(tmp); 488 kfree(tmp);
475 return ret; 489 return ret;
476} 490}
@@ -486,15 +500,12 @@ static ssize_t asic_flags_write(struct file *file, const char __user *buf,
486 u64 scratch0; 500 u64 scratch0;
487 u64 clear; 501 u64 clear;
488 502
489 rcu_read_lock();
490 ppd = private2ppd(file); 503 ppd = private2ppd(file);
491 dd = ppd->dd; 504 dd = ppd->dd;
492 505
493 buff = kmalloc(count + 1, GFP_KERNEL); 506 buff = kmalloc(count + 1, GFP_KERNEL);
494 if (!buff) { 507 if (!buff)
495 ret = -ENOMEM; 508 return -ENOMEM;
496 goto do_return;
497 }
498 509
499 ret = copy_from_user(buff, buf, count); 510 ret = copy_from_user(buff, buf, count);
500 if (ret > 0) { 511 if (ret > 0) {
@@ -527,8 +538,6 @@ static ssize_t asic_flags_write(struct file *file, const char __user *buf,
527 538
528 do_free: 539 do_free:
529 kfree(buff); 540 kfree(buff);
530 do_return:
531 rcu_read_unlock();
532 return ret; 541 return ret;
533} 542}
534 543
@@ -542,18 +551,14 @@ static ssize_t qsfp_debugfs_dump(struct file *file, char __user *buf,
542 char *tmp; 551 char *tmp;
543 int ret; 552 int ret;
544 553
545 rcu_read_lock();
546 ppd = private2ppd(file); 554 ppd = private2ppd(file);
547 tmp = kmalloc(PAGE_SIZE, GFP_KERNEL); 555 tmp = kmalloc(PAGE_SIZE, GFP_KERNEL);
548 if (!tmp) { 556 if (!tmp)
549 rcu_read_unlock();
550 return -ENOMEM; 557 return -ENOMEM;
551 }
552 558
553 ret = qsfp_dump(ppd, tmp, PAGE_SIZE); 559 ret = qsfp_dump(ppd, tmp, PAGE_SIZE);
554 if (ret > 0) 560 if (ret > 0)
555 ret = simple_read_from_buffer(buf, count, ppos, tmp, ret); 561 ret = simple_read_from_buffer(buf, count, ppos, tmp, ret);
556 rcu_read_unlock();
557 kfree(tmp); 562 kfree(tmp);
558 return ret; 563 return ret;
559} 564}
@@ -569,7 +574,6 @@ static ssize_t __i2c_debugfs_write(struct file *file, const char __user *buf,
569 int offset; 574 int offset;
570 int total_written; 575 int total_written;
571 576
572 rcu_read_lock();
573 ppd = private2ppd(file); 577 ppd = private2ppd(file);
574 578
575 /* byte offset format: [offsetSize][i2cAddr][offsetHigh][offsetLow] */ 579 /* byte offset format: [offsetSize][i2cAddr][offsetHigh][offsetLow] */
@@ -577,16 +581,12 @@ static ssize_t __i2c_debugfs_write(struct file *file, const char __user *buf,
577 offset = *ppos & 0xffff; 581 offset = *ppos & 0xffff;
578 582
579 /* explicitly reject invalid address 0 to catch cp and cat */ 583 /* explicitly reject invalid address 0 to catch cp and cat */
580 if (i2c_addr == 0) { 584 if (i2c_addr == 0)
581 ret = -EINVAL; 585 return -EINVAL;
582 goto _return;
583 }
584 586
585 buff = kmalloc(count, GFP_KERNEL); 587 buff = kmalloc(count, GFP_KERNEL);
586 if (!buff) { 588 if (!buff)
587 ret = -ENOMEM; 589 return -ENOMEM;
588 goto _return;
589 }
590 590
591 ret = copy_from_user(buff, buf, count); 591 ret = copy_from_user(buff, buf, count);
592 if (ret > 0) { 592 if (ret > 0) {
@@ -606,8 +606,6 @@ static ssize_t __i2c_debugfs_write(struct file *file, const char __user *buf,
606 606
607 _free: 607 _free:
608 kfree(buff); 608 kfree(buff);
609 _return:
610 rcu_read_unlock();
611 return ret; 609 return ret;
612} 610}
613 611
@@ -636,7 +634,6 @@ static ssize_t __i2c_debugfs_read(struct file *file, char __user *buf,
636 int offset; 634 int offset;
637 int total_read; 635 int total_read;
638 636
639 rcu_read_lock();
640 ppd = private2ppd(file); 637 ppd = private2ppd(file);
641 638
642 /* byte offset format: [offsetSize][i2cAddr][offsetHigh][offsetLow] */ 639 /* byte offset format: [offsetSize][i2cAddr][offsetHigh][offsetLow] */
@@ -644,16 +641,12 @@ static ssize_t __i2c_debugfs_read(struct file *file, char __user *buf,
644 offset = *ppos & 0xffff; 641 offset = *ppos & 0xffff;
645 642
646 /* explicitly reject invalid address 0 to catch cp and cat */ 643 /* explicitly reject invalid address 0 to catch cp and cat */
647 if (i2c_addr == 0) { 644 if (i2c_addr == 0)
648 ret = -EINVAL; 645 return -EINVAL;
649 goto _return;
650 }
651 646
652 buff = kmalloc(count, GFP_KERNEL); 647 buff = kmalloc(count, GFP_KERNEL);
653 if (!buff) { 648 if (!buff)
654 ret = -ENOMEM; 649 return -ENOMEM;
655 goto _return;
656 }
657 650
658 total_read = i2c_read(ppd, target, i2c_addr, offset, buff, count); 651 total_read = i2c_read(ppd, target, i2c_addr, offset, buff, count);
659 if (total_read < 0) { 652 if (total_read < 0) {
@@ -673,8 +666,6 @@ static ssize_t __i2c_debugfs_read(struct file *file, char __user *buf,
673 666
674 _free: 667 _free:
675 kfree(buff); 668 kfree(buff);
676 _return:
677 rcu_read_unlock();
678 return ret; 669 return ret;
679} 670}
680 671
@@ -701,26 +692,20 @@ static ssize_t __qsfp_debugfs_write(struct file *file, const char __user *buf,
701 int ret; 692 int ret;
702 int total_written; 693 int total_written;
703 694
704 rcu_read_lock(); 695 if (*ppos + count > QSFP_PAGESIZE * 4) /* base page + page00-page03 */
705 if (*ppos + count > QSFP_PAGESIZE * 4) { /* base page + page00-page03 */ 696 return -EINVAL;
706 ret = -EINVAL;
707 goto _return;
708 }
709 697
710 ppd = private2ppd(file); 698 ppd = private2ppd(file);
711 699
712 buff = kmalloc(count, GFP_KERNEL); 700 buff = kmalloc(count, GFP_KERNEL);
713 if (!buff) { 701 if (!buff)
714 ret = -ENOMEM; 702 return -ENOMEM;
715 goto _return;
716 }
717 703
718 ret = copy_from_user(buff, buf, count); 704 ret = copy_from_user(buff, buf, count);
719 if (ret > 0) { 705 if (ret > 0) {
720 ret = -EFAULT; 706 ret = -EFAULT;
721 goto _free; 707 goto _free;
722 } 708 }
723
724 total_written = qsfp_write(ppd, target, *ppos, buff, count); 709 total_written = qsfp_write(ppd, target, *ppos, buff, count);
725 if (total_written < 0) { 710 if (total_written < 0) {
726 ret = total_written; 711 ret = total_written;
@@ -733,8 +718,6 @@ static ssize_t __qsfp_debugfs_write(struct file *file, const char __user *buf,
733 718
734 _free: 719 _free:
735 kfree(buff); 720 kfree(buff);
736 _return:
737 rcu_read_unlock();
738 return ret; 721 return ret;
739} 722}
740 723
@@ -761,7 +744,6 @@ static ssize_t __qsfp_debugfs_read(struct file *file, char __user *buf,
761 int ret; 744 int ret;
762 int total_read; 745 int total_read;
763 746
764 rcu_read_lock();
765 if (*ppos + count > QSFP_PAGESIZE * 4) { /* base page + page00-page03 */ 747 if (*ppos + count > QSFP_PAGESIZE * 4) { /* base page + page00-page03 */
766 ret = -EINVAL; 748 ret = -EINVAL;
767 goto _return; 749 goto _return;
@@ -794,7 +776,6 @@ static ssize_t __qsfp_debugfs_read(struct file *file, char __user *buf,
794 _free: 776 _free:
795 kfree(buff); 777 kfree(buff);
796 _return: 778 _return:
797 rcu_read_unlock();
798 return ret; 779 return ret;
799} 780}
800 781
@@ -1010,7 +991,6 @@ void hfi1_dbg_ibdev_exit(struct hfi1_ibdev *ibd)
1010 debugfs_remove_recursive(ibd->hfi1_ibdev_dbg); 991 debugfs_remove_recursive(ibd->hfi1_ibdev_dbg);
1011out: 992out:
1012 ibd->hfi1_ibdev_dbg = NULL; 993 ibd->hfi1_ibdev_dbg = NULL;
1013 synchronize_rcu();
1014} 994}
1015 995
1016/* 996/*
@@ -1035,9 +1015,7 @@ static const char * const hfi1_statnames[] = {
1035}; 1015};
1036 1016
1037static void *_driver_stats_names_seq_start(struct seq_file *s, loff_t *pos) 1017static void *_driver_stats_names_seq_start(struct seq_file *s, loff_t *pos)
1038__acquires(RCU)
1039{ 1018{
1040 rcu_read_lock();
1041 if (*pos >= ARRAY_SIZE(hfi1_statnames)) 1019 if (*pos >= ARRAY_SIZE(hfi1_statnames))
1042 return NULL; 1020 return NULL;
1043 return pos; 1021 return pos;
@@ -1055,9 +1033,7 @@ static void *_driver_stats_names_seq_next(
1055} 1033}
1056 1034
1057static void _driver_stats_names_seq_stop(struct seq_file *s, void *v) 1035static void _driver_stats_names_seq_stop(struct seq_file *s, void *v)
1058__releases(RCU)
1059{ 1036{
1060 rcu_read_unlock();
1061} 1037}
1062 1038
1063static int _driver_stats_names_seq_show(struct seq_file *s, void *v) 1039static int _driver_stats_names_seq_show(struct seq_file *s, void *v)
@@ -1073,9 +1049,7 @@ DEBUGFS_SEQ_FILE_OPEN(driver_stats_names)
1073DEBUGFS_FILE_OPS(driver_stats_names); 1049DEBUGFS_FILE_OPS(driver_stats_names);
1074 1050
1075static void *_driver_stats_seq_start(struct seq_file *s, loff_t *pos) 1051static void *_driver_stats_seq_start(struct seq_file *s, loff_t *pos)
1076__acquires(RCU)
1077{ 1052{
1078 rcu_read_lock();
1079 if (*pos >= ARRAY_SIZE(hfi1_statnames)) 1053 if (*pos >= ARRAY_SIZE(hfi1_statnames))
1080 return NULL; 1054 return NULL;
1081 return pos; 1055 return pos;
@@ -1090,9 +1064,7 @@ static void *_driver_stats_seq_next(struct seq_file *s, void *v, loff_t *pos)
1090} 1064}
1091 1065
1092static void _driver_stats_seq_stop(struct seq_file *s, void *v) 1066static void _driver_stats_seq_stop(struct seq_file *s, void *v)
1093__releases(RCU)
1094{ 1067{
1095 rcu_read_unlock();
1096} 1068}
1097 1069
1098static u64 hfi1_sps_ints(void) 1070static u64 hfi1_sps_ints(void)