1
2
3
4
5
6
7
8
9#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10
11#include <linux/cache.h>
12#include <linux/fs.h>
13#include <linux/export.h>
14#include <linux/seq_file.h>
15#include <linux/vmalloc.h>
16#include <linux/slab.h>
17#include <linux/cred.h>
18#include <linux/mm.h>
19#include <linux/printk.h>
20#include <linux/string_helpers.h>
21#include <linux/uio.h>
22
23#include <linux/uaccess.h>
24#include <asm/page.h>
25
26static struct kmem_cache *seq_file_cache __ro_after_init;
27
28static void seq_set_overflow(struct seq_file *m)
29{
30 m->count = m->size;
31}
32
33static void *seq_buf_alloc(unsigned long size)
34{
35 if (unlikely(size > MAX_RW_COUNT))
36 return NULL;
37
38 return kvmalloc(size, GFP_KERNEL_ACCOUNT);
39}
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57int seq_open(struct file *file, const struct seq_operations *op)
58{
59 struct seq_file *p;
60
61 WARN_ON(file->private_data);
62
63 p = kmem_cache_zalloc(seq_file_cache, GFP_KERNEL);
64 if (!p)
65 return -ENOMEM;
66
67 file->private_data = p;
68
69 mutex_init(&p->lock);
70 p->op = op;
71
72
73
74 p->file = file;
75
76
77
78
79
80
81
82
83
84
85 file->f_mode &= ~FMODE_PWRITE;
86 return 0;
87}
88EXPORT_SYMBOL(seq_open);
89
90static int traverse(struct seq_file *m, loff_t offset)
91{
92 loff_t pos = 0;
93 int error = 0;
94 void *p;
95
96 m->index = 0;
97 m->count = m->from = 0;
98 if (!offset)
99 return 0;
100
101 if (!m->buf) {
102 m->buf = seq_buf_alloc(m->size = PAGE_SIZE);
103 if (!m->buf)
104 return -ENOMEM;
105 }
106 p = m->op->start(m, &m->index);
107 while (p) {
108 error = PTR_ERR(p);
109 if (IS_ERR(p))
110 break;
111 error = m->op->show(m, p);
112 if (error < 0)
113 break;
114 if (unlikely(error)) {
115 error = 0;
116 m->count = 0;
117 }
118 if (seq_has_overflowed(m))
119 goto Eoverflow;
120 p = m->op->next(m, p, &m->index);
121 if (pos + m->count > offset) {
122 m->from = offset - pos;
123 m->count -= m->from;
124 break;
125 }
126 pos += m->count;
127 m->count = 0;
128 if (pos == offset)
129 break;
130 }
131 m->op->stop(m, p);
132 return error;
133
134Eoverflow:
135 m->op->stop(m, p);
136 kvfree(m->buf);
137 m->count = 0;
138 m->buf = seq_buf_alloc(m->size <<= 1);
139 return !m->buf ? -ENOMEM : -EAGAIN;
140}
141
142
143
144
145
146
147
148
149
150
151ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
152{
153 struct iovec iov = { .iov_base = buf, .iov_len = size};
154 struct kiocb kiocb;
155 struct iov_iter iter;
156 ssize_t ret;
157
158 init_sync_kiocb(&kiocb, file);
159 iov_iter_init(&iter, READ, &iov, 1, size);
160
161 kiocb.ki_pos = *ppos;
162 ret = seq_read_iter(&kiocb, &iter);
163 *ppos = kiocb.ki_pos;
164 return ret;
165}
166EXPORT_SYMBOL(seq_read);
167
168
169
170
171ssize_t seq_read_iter(struct kiocb *iocb, struct iov_iter *iter)
172{
173 struct seq_file *m = iocb->ki_filp->private_data;
174 size_t copied = 0;
175 size_t n;
176 void *p;
177 int err = 0;
178
179 if (!iov_iter_count(iter))
180 return 0;
181
182 mutex_lock(&m->lock);
183
184
185
186
187
188 if (iocb->ki_pos == 0) {
189 m->index = 0;
190 m->count = 0;
191 }
192
193
194 if (unlikely(iocb->ki_pos != m->read_pos)) {
195 while ((err = traverse(m, iocb->ki_pos)) == -EAGAIN)
196 ;
197 if (err) {
198
199 m->read_pos = 0;
200 m->index = 0;
201 m->count = 0;
202 goto Done;
203 } else {
204 m->read_pos = iocb->ki_pos;
205 }
206 }
207
208
209 if (!m->buf) {
210 m->buf = seq_buf_alloc(m->size = PAGE_SIZE);
211 if (!m->buf)
212 goto Enomem;
213 }
214
215 if (m->count) {
216 n = copy_to_iter(m->buf + m->from, m->count, iter);
217 m->count -= n;
218 m->from += n;
219 copied += n;
220 if (m->count)
221 goto Done;
222 }
223
224 m->from = 0;
225 p = m->op->start(m, &m->index);
226 while (1) {
227 err = PTR_ERR(p);
228 if (!p || IS_ERR(p))
229 break;
230 err = m->op->show(m, p);
231 if (err < 0)
232 break;
233 if (unlikely(err))
234 m->count = 0;
235 if (unlikely(!m->count)) {
236 p = m->op->next(m, p, &m->index);
237 continue;
238 }
239 if (!seq_has_overflowed(m))
240 goto Fill;
241
242 m->op->stop(m, p);
243 kvfree(m->buf);
244 m->count = 0;
245 m->buf = seq_buf_alloc(m->size <<= 1);
246 if (!m->buf)
247 goto Enomem;
248 p = m->op->start(m, &m->index);
249 }
250
251 m->op->stop(m, p);
252 m->count = 0;
253 goto Done;
254Fill:
255
256
257
258 while (1) {
259 size_t offs = m->count;
260 loff_t pos = m->index;
261
262 p = m->op->next(m, p, &m->index);
263 if (pos == m->index) {
264 pr_info_ratelimited("buggy .next function %ps did not update position index\n",
265 m->op->next);
266 m->index++;
267 }
268 if (!p || IS_ERR(p))
269 break;
270 if (m->count >= iov_iter_count(iter))
271 break;
272 err = m->op->show(m, p);
273 if (err > 0) {
274 m->count = offs;
275 } else if (err || seq_has_overflowed(m)) {
276 m->count = offs;
277 break;
278 }
279 }
280 m->op->stop(m, p);
281 n = copy_to_iter(m->buf, m->count, iter);
282 copied += n;
283 m->count -= n;
284 m->from = n;
285Done:
286 if (unlikely(!copied)) {
287 copied = m->count ? -EFAULT : err;
288 } else {
289 iocb->ki_pos += copied;
290 m->read_pos += copied;
291 }
292 mutex_unlock(&m->lock);
293 return copied;
294Enomem:
295 err = -ENOMEM;
296 goto Done;
297}
298EXPORT_SYMBOL(seq_read_iter);
299
300
301
302
303
304
305
306
307
308loff_t seq_lseek(struct file *file, loff_t offset, int whence)
309{
310 struct seq_file *m = file->private_data;
311 loff_t retval = -EINVAL;
312
313 mutex_lock(&m->lock);
314 switch (whence) {
315 case SEEK_CUR:
316 offset += file->f_pos;
317 fallthrough;
318 case SEEK_SET:
319 if (offset < 0)
320 break;
321 retval = offset;
322 if (offset != m->read_pos) {
323 while ((retval = traverse(m, offset)) == -EAGAIN)
324 ;
325 if (retval) {
326
327 file->f_pos = 0;
328 m->read_pos = 0;
329 m->index = 0;
330 m->count = 0;
331 } else {
332 m->read_pos = offset;
333 retval = file->f_pos = offset;
334 }
335 } else {
336 file->f_pos = offset;
337 }
338 }
339 mutex_unlock(&m->lock);
340 return retval;
341}
342EXPORT_SYMBOL(seq_lseek);
343
344
345
346
347
348
349
350
351
352int seq_release(struct inode *inode, struct file *file)
353{
354 struct seq_file *m = file->private_data;
355 kvfree(m->buf);
356 kmem_cache_free(seq_file_cache, m);
357 return 0;
358}
359EXPORT_SYMBOL(seq_release);
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374void seq_escape_mem(struct seq_file *m, const char *src, size_t len,
375 unsigned int flags, const char *esc)
376{
377 char *buf;
378 size_t size = seq_get_buf(m, &buf);
379 int ret;
380
381 ret = string_escape_mem(src, len, buf, size, flags, esc);
382 seq_commit(m, ret < size ? ret : -1);
383}
384EXPORT_SYMBOL(seq_escape_mem);
385
386void seq_vprintf(struct seq_file *m, const char *f, va_list args)
387{
388 int len;
389
390 if (m->count < m->size) {
391 len = vsnprintf(m->buf + m->count, m->size - m->count, f, args);
392 if (m->count + len < m->size) {
393 m->count += len;
394 return;
395 }
396 }
397 seq_set_overflow(m);
398}
399EXPORT_SYMBOL(seq_vprintf);
400
401void seq_printf(struct seq_file *m, const char *f, ...)
402{
403 va_list args;
404
405 va_start(args, f);
406 seq_vprintf(m, f, args);
407 va_end(args);
408}
409EXPORT_SYMBOL(seq_printf);
410
411#ifdef CONFIG_BINARY_PRINTF
412void seq_bprintf(struct seq_file *m, const char *f, const u32 *binary)
413{
414 int len;
415
416 if (m->count < m->size) {
417 len = bstr_printf(m->buf + m->count, m->size - m->count, f,
418 binary);
419 if (m->count + len < m->size) {
420 m->count += len;
421 return;
422 }
423 }
424 seq_set_overflow(m);
425}
426EXPORT_SYMBOL(seq_bprintf);
427#endif
428
429
430
431
432
433
434
435
436
437
438
439
440char *mangle_path(char *s, const char *p, const char *esc)
441{
442 while (s <= p) {
443 char c = *p++;
444 if (!c) {
445 return s;
446 } else if (!strchr(esc, c)) {
447 *s++ = c;
448 } else if (s + 4 > p) {
449 break;
450 } else {
451 *s++ = '\\';
452 *s++ = '0' + ((c & 0300) >> 6);
453 *s++ = '0' + ((c & 070) >> 3);
454 *s++ = '0' + (c & 07);
455 }
456 }
457 return NULL;
458}
459EXPORT_SYMBOL(mangle_path);
460
461
462
463
464
465
466
467
468
469
470int seq_path(struct seq_file *m, const struct path *path, const char *esc)
471{
472 char *buf;
473 size_t size = seq_get_buf(m, &buf);
474 int res = -1;
475
476 if (size) {
477 char *p = d_path(path, buf, size);
478 if (!IS_ERR(p)) {
479 char *end = mangle_path(buf, p, esc);
480 if (end)
481 res = end - buf;
482 }
483 }
484 seq_commit(m, res);
485
486 return res;
487}
488EXPORT_SYMBOL(seq_path);
489
490
491
492
493
494
495
496
497
498int seq_file_path(struct seq_file *m, struct file *file, const char *esc)
499{
500 return seq_path(m, &file->f_path, esc);
501}
502EXPORT_SYMBOL(seq_file_path);
503
504
505
506
507int seq_path_root(struct seq_file *m, const struct path *path,
508 const struct path *root, const char *esc)
509{
510 char *buf;
511 size_t size = seq_get_buf(m, &buf);
512 int res = -ENAMETOOLONG;
513
514 if (size) {
515 char *p;
516
517 p = __d_path(path, root, buf, size);
518 if (!p)
519 return SEQ_SKIP;
520 res = PTR_ERR(p);
521 if (!IS_ERR(p)) {
522 char *end = mangle_path(buf, p, esc);
523 if (end)
524 res = end - buf;
525 else
526 res = -ENAMETOOLONG;
527 }
528 }
529 seq_commit(m, res);
530
531 return res < 0 && res != -ENAMETOOLONG ? res : 0;
532}
533
534
535
536
537int seq_dentry(struct seq_file *m, struct dentry *dentry, const char *esc)
538{
539 char *buf;
540 size_t size = seq_get_buf(m, &buf);
541 int res = -1;
542
543 if (size) {
544 char *p = dentry_path(dentry, buf, size);
545 if (!IS_ERR(p)) {
546 char *end = mangle_path(buf, p, esc);
547 if (end)
548 res = end - buf;
549 }
550 }
551 seq_commit(m, res);
552
553 return res;
554}
555EXPORT_SYMBOL(seq_dentry);
556
557static void *single_start(struct seq_file *p, loff_t *pos)
558{
559 return NULL + (*pos == 0);
560}
561
562static void *single_next(struct seq_file *p, void *v, loff_t *pos)
563{
564 ++*pos;
565 return NULL;
566}
567
568static void single_stop(struct seq_file *p, void *v)
569{
570}
571
572int single_open(struct file *file, int (*show)(struct seq_file *, void *),
573 void *data)
574{
575 struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL_ACCOUNT);
576 int res = -ENOMEM;
577
578 if (op) {
579 op->start = single_start;
580 op->next = single_next;
581 op->stop = single_stop;
582 op->show = show;
583 res = seq_open(file, op);
584 if (!res)
585 ((struct seq_file *)file->private_data)->private = data;
586 else
587 kfree(op);
588 }
589 return res;
590}
591EXPORT_SYMBOL(single_open);
592
593int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
594 void *data, size_t size)
595{
596 char *buf = seq_buf_alloc(size);
597 int ret;
598 if (!buf)
599 return -ENOMEM;
600 ret = single_open(file, show, data);
601 if (ret) {
602 kvfree(buf);
603 return ret;
604 }
605 ((struct seq_file *)file->private_data)->buf = buf;
606 ((struct seq_file *)file->private_data)->size = size;
607 return 0;
608}
609EXPORT_SYMBOL(single_open_size);
610
611int single_release(struct inode *inode, struct file *file)
612{
613 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
614 int res = seq_release(inode, file);
615 kfree(op);
616 return res;
617}
618EXPORT_SYMBOL(single_release);
619
620int seq_release_private(struct inode *inode, struct file *file)
621{
622 struct seq_file *seq = file->private_data;
623
624 kfree(seq->private);
625 seq->private = NULL;
626 return seq_release(inode, file);
627}
628EXPORT_SYMBOL(seq_release_private);
629
630void *__seq_open_private(struct file *f, const struct seq_operations *ops,
631 int psize)
632{
633 int rc;
634 void *private;
635 struct seq_file *seq;
636
637 private = kzalloc(psize, GFP_KERNEL_ACCOUNT);
638 if (private == NULL)
639 goto out;
640
641 rc = seq_open(f, ops);
642 if (rc < 0)
643 goto out_free;
644
645 seq = f->private_data;
646 seq->private = private;
647 return private;
648
649out_free:
650 kfree(private);
651out:
652 return NULL;
653}
654EXPORT_SYMBOL(__seq_open_private);
655
656int seq_open_private(struct file *filp, const struct seq_operations *ops,
657 int psize)
658{
659 return __seq_open_private(filp, ops, psize) ? 0 : -ENOMEM;
660}
661EXPORT_SYMBOL(seq_open_private);
662
663void seq_putc(struct seq_file *m, char c)
664{
665 if (m->count >= m->size)
666 return;
667
668 m->buf[m->count++] = c;
669}
670EXPORT_SYMBOL(seq_putc);
671
672void seq_puts(struct seq_file *m, const char *s)
673{
674 int len = strlen(s);
675
676 if (m->count + len >= m->size) {
677 seq_set_overflow(m);
678 return;
679 }
680 memcpy(m->buf + m->count, s, len);
681 m->count += len;
682}
683EXPORT_SYMBOL(seq_puts);
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698void seq_put_decimal_ull_width(struct seq_file *m, const char *delimiter,
699 unsigned long long num, unsigned int width)
700{
701 int len;
702
703 if (m->count + 2 >= m->size)
704 goto overflow;
705
706 if (delimiter && delimiter[0]) {
707 if (delimiter[1] == 0)
708 seq_putc(m, delimiter[0]);
709 else
710 seq_puts(m, delimiter);
711 }
712
713 if (!width)
714 width = 1;
715
716 if (m->count + width >= m->size)
717 goto overflow;
718
719 len = num_to_str(m->buf + m->count, m->size - m->count, num, width);
720 if (!len)
721 goto overflow;
722
723 m->count += len;
724 return;
725
726overflow:
727 seq_set_overflow(m);
728}
729
730void seq_put_decimal_ull(struct seq_file *m, const char *delimiter,
731 unsigned long long num)
732{
733 return seq_put_decimal_ull_width(m, delimiter, num, 0);
734}
735EXPORT_SYMBOL(seq_put_decimal_ull);
736
737
738
739
740
741
742
743
744
745
746
747
748
749void seq_put_hex_ll(struct seq_file *m, const char *delimiter,
750 unsigned long long v, unsigned int width)
751{
752 unsigned int len;
753 int i;
754
755 if (delimiter && delimiter[0]) {
756 if (delimiter[1] == 0)
757 seq_putc(m, delimiter[0]);
758 else
759 seq_puts(m, delimiter);
760 }
761
762
763 if (v == 0)
764 len = 1;
765 else
766 len = (sizeof(v) * 8 - __builtin_clzll(v) + 3) / 4;
767
768 if (len < width)
769 len = width;
770
771 if (m->count + len > m->size) {
772 seq_set_overflow(m);
773 return;
774 }
775
776 for (i = len - 1; i >= 0; i--) {
777 m->buf[m->count + i] = hex_asc[0xf & v];
778 v = v >> 4;
779 }
780 m->count += len;
781}
782
783void seq_put_decimal_ll(struct seq_file *m, const char *delimiter, long long num)
784{
785 int len;
786
787 if (m->count + 3 >= m->size)
788 goto overflow;
789
790 if (delimiter && delimiter[0]) {
791 if (delimiter[1] == 0)
792 seq_putc(m, delimiter[0]);
793 else
794 seq_puts(m, delimiter);
795 }
796
797 if (m->count + 2 >= m->size)
798 goto overflow;
799
800 if (num < 0) {
801 m->buf[m->count++] = '-';
802 num = -num;
803 }
804
805 if (num < 10) {
806 m->buf[m->count++] = num + '0';
807 return;
808 }
809
810 len = num_to_str(m->buf + m->count, m->size - m->count, num, 0);
811 if (!len)
812 goto overflow;
813
814 m->count += len;
815 return;
816
817overflow:
818 seq_set_overflow(m);
819}
820EXPORT_SYMBOL(seq_put_decimal_ll);
821
822
823
824
825
826
827
828
829
830int seq_write(struct seq_file *seq, const void *data, size_t len)
831{
832 if (seq->count + len < seq->size) {
833 memcpy(seq->buf + seq->count, data, len);
834 seq->count += len;
835 return 0;
836 }
837 seq_set_overflow(seq);
838 return -1;
839}
840EXPORT_SYMBOL(seq_write);
841
842
843
844
845
846
847void seq_pad(struct seq_file *m, char c)
848{
849 int size = m->pad_until - m->count;
850 if (size > 0) {
851 if (size + m->count > m->size) {
852 seq_set_overflow(m);
853 return;
854 }
855 memset(m->buf + m->count, ' ', size);
856 m->count += size;
857 }
858 if (c)
859 seq_putc(m, c);
860}
861EXPORT_SYMBOL(seq_pad);
862
863
864void seq_hex_dump(struct seq_file *m, const char *prefix_str, int prefix_type,
865 int rowsize, int groupsize, const void *buf, size_t len,
866 bool ascii)
867{
868 const u8 *ptr = buf;
869 int i, linelen, remaining = len;
870 char *buffer;
871 size_t size;
872 int ret;
873
874 if (rowsize != 16 && rowsize != 32)
875 rowsize = 16;
876
877 for (i = 0; i < len && !seq_has_overflowed(m); i += rowsize) {
878 linelen = min(remaining, rowsize);
879 remaining -= rowsize;
880
881 switch (prefix_type) {
882 case DUMP_PREFIX_ADDRESS:
883 seq_printf(m, "%s%p: ", prefix_str, ptr + i);
884 break;
885 case DUMP_PREFIX_OFFSET:
886 seq_printf(m, "%s%.8x: ", prefix_str, i);
887 break;
888 default:
889 seq_printf(m, "%s", prefix_str);
890 break;
891 }
892
893 size = seq_get_buf(m, &buffer);
894 ret = hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize,
895 buffer, size, ascii);
896 seq_commit(m, ret < size ? ret : -1);
897
898 seq_putc(m, '\n');
899 }
900}
901EXPORT_SYMBOL(seq_hex_dump);
902
903struct list_head *seq_list_start(struct list_head *head, loff_t pos)
904{
905 struct list_head *lh;
906
907 list_for_each(lh, head)
908 if (pos-- == 0)
909 return lh;
910
911 return NULL;
912}
913EXPORT_SYMBOL(seq_list_start);
914
915struct list_head *seq_list_start_head(struct list_head *head, loff_t pos)
916{
917 if (!pos)
918 return head;
919
920 return seq_list_start(head, pos - 1);
921}
922EXPORT_SYMBOL(seq_list_start_head);
923
924struct list_head *seq_list_next(void *v, struct list_head *head, loff_t *ppos)
925{
926 struct list_head *lh;
927
928 lh = ((struct list_head *)v)->next;
929 ++*ppos;
930 return lh == head ? NULL : lh;
931}
932EXPORT_SYMBOL(seq_list_next);
933
934
935
936
937
938
939
940
941struct hlist_node *seq_hlist_start(struct hlist_head *head, loff_t pos)
942{
943 struct hlist_node *node;
944
945 hlist_for_each(node, head)
946 if (pos-- == 0)
947 return node;
948 return NULL;
949}
950EXPORT_SYMBOL(seq_hlist_start);
951
952
953
954
955
956
957
958
959
960struct hlist_node *seq_hlist_start_head(struct hlist_head *head, loff_t pos)
961{
962 if (!pos)
963 return SEQ_START_TOKEN;
964
965 return seq_hlist_start(head, pos - 1);
966}
967EXPORT_SYMBOL(seq_hlist_start_head);
968
969
970
971
972
973
974
975
976
977struct hlist_node *seq_hlist_next(void *v, struct hlist_head *head,
978 loff_t *ppos)
979{
980 struct hlist_node *node = v;
981
982 ++*ppos;
983 if (v == SEQ_START_TOKEN)
984 return head->first;
985 else
986 return node->next;
987}
988EXPORT_SYMBOL(seq_hlist_next);
989
990
991
992
993
994
995
996
997
998
999
1000
1001struct hlist_node *seq_hlist_start_rcu(struct hlist_head *head,
1002 loff_t pos)
1003{
1004 struct hlist_node *node;
1005
1006 __hlist_for_each_rcu(node, head)
1007 if (pos-- == 0)
1008 return node;
1009 return NULL;
1010}
1011EXPORT_SYMBOL(seq_hlist_start_rcu);
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025struct hlist_node *seq_hlist_start_head_rcu(struct hlist_head *head,
1026 loff_t pos)
1027{
1028 if (!pos)
1029 return SEQ_START_TOKEN;
1030
1031 return seq_hlist_start_rcu(head, pos - 1);
1032}
1033EXPORT_SYMBOL(seq_hlist_start_head_rcu);
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047struct hlist_node *seq_hlist_next_rcu(void *v,
1048 struct hlist_head *head,
1049 loff_t *ppos)
1050{
1051 struct hlist_node *node = v;
1052
1053 ++*ppos;
1054 if (v == SEQ_START_TOKEN)
1055 return rcu_dereference(head->first);
1056 else
1057 return rcu_dereference(node->next);
1058}
1059EXPORT_SYMBOL(seq_hlist_next_rcu);
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069struct hlist_node *
1070seq_hlist_start_percpu(struct hlist_head __percpu *head, int *cpu, loff_t pos)
1071{
1072 struct hlist_node *node;
1073
1074 for_each_possible_cpu(*cpu) {
1075 hlist_for_each(node, per_cpu_ptr(head, *cpu)) {
1076 if (pos-- == 0)
1077 return node;
1078 }
1079 }
1080 return NULL;
1081}
1082EXPORT_SYMBOL(seq_hlist_start_percpu);
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093struct hlist_node *
1094seq_hlist_next_percpu(void *v, struct hlist_head __percpu *head,
1095 int *cpu, loff_t *pos)
1096{
1097 struct hlist_node *node = v;
1098
1099 ++*pos;
1100
1101 if (node->next)
1102 return node->next;
1103
1104 for (*cpu = cpumask_next(*cpu, cpu_possible_mask); *cpu < nr_cpu_ids;
1105 *cpu = cpumask_next(*cpu, cpu_possible_mask)) {
1106 struct hlist_head *bucket = per_cpu_ptr(head, *cpu);
1107
1108 if (!hlist_empty(bucket))
1109 return bucket->first;
1110 }
1111 return NULL;
1112}
1113EXPORT_SYMBOL(seq_hlist_next_percpu);
1114
1115void __init seq_file_init(void)
1116{
1117 seq_file_cache = KMEM_CACHE(seq_file, SLAB_ACCOUNT|SLAB_PANIC);
1118}
1119