-
Notifications
You must be signed in to change notification settings - Fork 4
/
io_uring-comment-for-linux-5.7.patch
1572 lines (1457 loc) · 57.6 KB
/
io_uring-comment-for-linux-5.7.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From 5afda9bbe2173b71204eca8745666bc6ceab7cd8 Mon Sep 17 00:00:00 2001
From: Dongli Zhang <[email protected]>
Date: Sun, 14 Jun 2020 11:34:19 -0700
Subject: [PATCH 1/1] io_uring comment for linux-5.7
Signed-off-by: Dongli Zhang <[email protected]>
---
fs/io_uring.c | 691 ++++++++++++++++++++++++++++++++++
include/uapi/linux/io_uring.h | 48 +++
2 files changed, 739 insertions(+)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index bb25e3997d41..ca5e660a4e3e 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -88,7 +88,30 @@
#include "internal.h"
#include "io-wq.h"
+/*
+ * root 5808 0.0 0.0 0 0 ? S 10:00 0:00 [io_wq_manager]
+ * root 5809 0.0 0.0 0 0 ? S 10:00 0:00 [io_wqe_worker-0]
+ * root 5810 0.0 0.0 0 0 ? S 10:00 0:00 [io_wqe_worker-0]
+ * root 5811 0.0 0.0 0 0 ? S 10:00 0:00 [io_wq_manager]
+ * root 5812 0.0 0.0 0 0 ? S 10:00 0:00 [io_wqe_worker-0]
+ * root 5813 0.0 0.0 0 0 ? S 10:00 0:00 [io_wqe_worker-0]
+ * root 5815 0.0 0.0 0 0 ? S 10:00 0:00 [io_wq_manager]
+ * root 5816 0.0 0.0 0 0 ? S 10:00 0:00 [io_wqe_worker-0]
+ * root 5817 0.0 0.0 0 0 ? S 10:00 0:00 [io_wqe_worker-0]
+ */
+
+/*
+ * 在以下使用IORING_MAX_ENTRIES:
+ * - fs/io_uring.c|92| <<IORING_MAX_CQ_ENTRIES>> #define IORING_MAX_CQ_ENTRIES (2 * IORING_MAX_ENTRIES)
+ * - fs/io_uring.c|7937| <<io_uring_create>> if (entries > IORING_MAX_ENTRIES) {
+ * - fs/io_uring.c|7940| <<io_uring_create>> entries = IORING_MAX_ENTRIES;
+ */
#define IORING_MAX_ENTRIES 32768
+/*
+ * 在以下使用IORING_MAX_CQ_ENTRIES:
+ * - fs/io_uring.c|7960| <<io_uring_create>> if (p->cq_entries > IORING_MAX_CQ_ENTRIES) {
+ * - fs/io_uring.c|7963| <<io_uring_create>> p->cq_entries = IORING_MAX_CQ_ENTRIES;
+ */
#define IORING_MAX_CQ_ENTRIES (2 * IORING_MAX_ENTRIES)
/*
@@ -97,6 +120,10 @@
#define IORING_FILE_TABLE_SHIFT 9
#define IORING_MAX_FILES_TABLE (1U << IORING_FILE_TABLE_SHIFT)
#define IORING_FILE_TABLE_MASK (IORING_MAX_FILES_TABLE - 1)
+/*
+ * 在以下使用IORING_MAX_FIXED_FILES:
+ * - fs/io_uring.c|6597| <<io_sqe_files_register>> if (nr_args > IORING_MAX_FIXED_FILES)
+ */
#define IORING_MAX_FIXED_FILES (64 * IORING_MAX_FILES_TABLE)
struct io_uring {
@@ -246,6 +273,16 @@ struct io_ring_ctx {
unsigned long sq_check_overflow;
struct list_head defer_list;
+ /*
+ * 在以下使用io_ring_ctx->timeout_list:
+ * - fs/io_uring.c|985| <<io_ring_ctx_alloc>> INIT_LIST_HEAD(&ctx->timeout_list);
+ * - fs/io_uring.c|1055| <<io_get_timeout_req>> req = list_first_entry_or_null(&ctx->timeout_list, struct io_kiocb, list);
+ * - fs/io_uring.c|1182| <<io_kill_timeouts>> list_for_each_entry_safe(req, tmp, &ctx->timeout_list, list)
+ * - fs/io_uring.c|4677| <<io_timeout_fn>> list_for_each_entry_continue_reverse(prev, &ctx->timeout_list, list)
+ * - fs/io_uring.c|4697| <<io_timeout_cancel>> list_for_each_entry(req, &ctx->timeout_list, list) {
+ * - fs/io_uring.c|4815| <<io_timeout>> entry = ctx->timeout_list.prev;
+ * - fs/io_uring.c|4826| <<io_timeout>> list_for_each_prev(entry, &ctx->timeout_list) {
+ */
struct list_head timeout_list;
struct list_head cq_overflow_list;
@@ -259,6 +296,22 @@ struct io_ring_ctx {
struct io_wq *io_wq;
struct task_struct *sqo_thread; /* if using sq thread polling */
struct mm_struct *sqo_mm;
+ /*
+ * 在以下使用io_ring_ctx->sqo_wait:
+ * - fs/io_uring.c|995| <<io_ring_ctx_alloc>> init_waitqueue_head(&ctx->sqo_wait);
+ * - fs/io_uring.c|1318| <<io_cqring_ev_posted>> if (waitqueue_active(&ctx->sqo_wait))
+ * - fs/io_uring.c|1319| <<io_cqring_ev_posted>> wake_up(&ctx->sqo_wait);
+ * - fs/io_uring.c|2151| <<io_iopoll_req_issued>> wq_has_sleeper(&ctx->sqo_wait))
+ * - fs/io_uring.c|2152| <<io_iopoll_req_issued>> wake_up(&ctx->sqo_wait);
+ * - fs/io_uring.c|6273| <<io_sq_thread>> prepare_to_wait(&ctx->sqo_wait, &wait,
+ * - fs/io_uring.c|6285| <<io_sq_thread>> finish_wait(&ctx->sqo_wait, &wait);
+ * - fs/io_uring.c|6297| <<io_sq_thread>> finish_wait(&ctx->sqo_wait, &wait);
+ * - fs/io_uring.c|6302| <<io_sq_thread>> finish_wait(&ctx->sqo_wait, &wait);
+ * - fs/io_uring.c|6308| <<io_sq_thread>> finish_wait(&ctx->sqo_wait, &wait);
+ * - fs/io_uring.c|6314| <<io_sq_thread>> finish_wait(&ctx->sqo_wait, &wait);
+ * - fs/io_uring.c|7740| <<io_ring_ctx_wait_and_kill>> while (ctx->sqo_thread && !wq_has_sleeper(&ctx->sqo_wait))
+ * - fs/io_uring.c|7972| <<SYSCALL_DEFINE6(io_uring_enter)>> wake_up(&ctx->sqo_wait);
+ */
wait_queue_head_t sqo_wait;
/*
@@ -299,8 +352,29 @@ struct io_ring_ctx {
unsigned cq_mask;
atomic_t cq_timeouts;
unsigned long cq_check_overflow;
+ /*
+ * 在以下使用io_ring_ctx->io_ring_ctx:
+ * - fs/io_uring.c|989| <<io_ring_ctx_alloc>> init_waitqueue_head(&ctx->cq_wait);
+ * - fs/io_uring.c|1094| <<__io_commit_cqring>> if (wq_has_sleeper(&ctx->cq_wait)) {
+ * - fs/io_uring.c|1095| <<__io_commit_cqring>> wake_up_interruptible(&ctx->cq_wait);
+ * - fs/io_uring.c|7649| <<io_uring_poll>> poll_wait(file, &ctx->cq_wait, wait);
+ */
struct wait_queue_head cq_wait;
struct fasync_struct *cq_fasync;
+ /*
+ * 在以下使用io_ring_ctx->cq_ev_fd:
+ * - fs/io_uring.c|1308| <<io_should_trigger_evfd>> if (!ctx->cq_ev_fd)
+ * - fs/io_uring.c|1337| <<io_cqring_ev_posted>> eventfd_signal(ctx->cq_ev_fd, 1);
+ * - fs/io_uring.c|7599| <<io_eventfd_register>> if (ctx->cq_ev_fd)
+ * - fs/io_uring.c|7605| <<io_eventfd_register>> ctx->cq_ev_fd = eventfd_ctx_fdget(fd);
+ * - fs/io_uring.c|7606| <<io_eventfd_register>> if (IS_ERR(ctx->cq_ev_fd)) {
+ * - fs/io_uring.c|7607| <<io_eventfd_register>> int ret = PTR_ERR(ctx->cq_ev_fd);
+ * - fs/io_uring.c|7608| <<io_eventfd_register>> ctx->cq_ev_fd = NULL;
+ * - fs/io_uring.c|7622| <<io_eventfd_unregister>> if (ctx->cq_ev_fd) {
+ * - fs/io_uring.c|7623| <<io_eventfd_unregister>> eventfd_ctx_put(ctx->cq_ev_fd);
+ * - fs/io_uring.c|7624| <<io_eventfd_unregister>> ctx->cq_ev_fd = NULL;
+ * - fs/io_uring.c|8735| <<SYSCALL_DEFINE4>> ctx->cq_ev_fd != NULL, ret);
+ */
struct eventfd_ctx *cq_ev_fd;
} ____cacheline_aligned_in_smp;
@@ -869,12 +943,33 @@ static struct kmem_cache *req_cachep;
static const struct file_operations io_uring_fops;
+/*
+ * called by:
+ * - net/unix/scm.c|38| <<unix_get_socket>> u_sock = io_uring_get_socket(filp);
+ */
struct sock *io_uring_get_socket(struct file *file)
{
#if defined(CONFIG_UNIX)
+ /*
+ * 在以下使用io_uring_fops:
+ * - fs/io_uring.c|875| <<io_uring_get_socket>> if (file->f_op == &io_uring_fops) {
+ * - fs/io_uring.c|2038| <<io_file_supports_async>> if (S_ISREG(mode) && file->f_op != &io_uring_fops)
+ * - fs/io_uring.c|3399| <<io_close_prep>> if (req->file->f_op == &io_uring_fops ||
+ * - fs/io_uring.c|6582| <<io_sqe_files_register>> if (file->f_op == &io_uring_fops) {
+ * - fs/io_uring.c|6745| <<__io_sqe_files_update>> if (file->f_op == &io_uring_fops) {
+ * - fs/io_uring.c|6826| <<io_init_wq_offload>> if (f.file->f_op != &io_uring_fops) {
+ * - fs/io_uring.c|7511| <<SYSCALL_DEFINE6(io_uring_enter)>> if (f.file->f_op != &io_uring_fops)
+ * - fs/io_uring.c|7731| <<io_uring_get_fd>> file = anon_inode_getfile("[io_uring]", &io_uring_fops, ctx,
+ * - fs/io_uring.c|8098| <<SYSCALL_DEFINE4(io_uring_register)>> if (f.file->f_op != &io_uring_fops)
+ */
if (file->f_op == &io_uring_fops) {
struct io_ring_ctx *ctx = file->private_data;
+ /*
+ * struct io_ring_ctx:
+ * -> struct socket *ring_sock;
+ * -> struct sock *sk;
+ */
return ctx->ring_sock->sk;
}
#endif
@@ -882,6 +977,10 @@ struct sock *io_uring_get_socket(struct file *file)
}
EXPORT_SYMBOL(io_uring_get_socket);
+/*
+ * 在以下使用io_ring_ctx_ref_free():
+ * - fs/io_uring.c|928| <<io_ring_ctx_alloc>> if (percpu_ref_init(&ctx->refs, io_ring_ctx_ref_free,
+ */
static void io_ring_ctx_ref_free(struct percpu_ref *ref)
{
struct io_ring_ctx *ctx = container_of(ref, struct io_ring_ctx, refs);
@@ -889,6 +988,15 @@ static void io_ring_ctx_ref_free(struct percpu_ref *ref)
complete(&ctx->completions[0]);
}
+/*
+ * called by:
+ * - fs/io_uring.c|7930| <<io_uring_create>> ctx = io_ring_ctx_alloc(p);
+ *
+ * SYSCALL_DEFINE2(io_uring_setup)
+ * -> io_uring_setup()
+ * -> io_uring_create()
+ * -> io_ring_ctx_alloc()
+ */
static struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
{
struct io_ring_ctx *ctx;
@@ -927,6 +1035,13 @@ static struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
ctx->flags = p->flags;
init_waitqueue_head(&ctx->sqo_wait);
+ /*
+ * 在以下使用io_ring_ctx:
+ * - fs/io_uring.c|989| <<io_ring_ctx_alloc>> init_waitqueue_head(&ctx->cq_wait);
+ * - fs/io_uring.c|1094| <<__io_commit_cqring>> if (wq_has_sleeper(&ctx->cq_wait)) {
+ * - fs/io_uring.c|1095| <<__io_commit_cqring>> wake_up_interruptible(&ctx->cq_wait);
+ * - fs/io_uring.c|7649| <<io_uring_poll>> poll_wait(file, &ctx->cq_wait, wait);
+ */
init_waitqueue_head(&ctx->cq_wait);
INIT_LIST_HEAD(&ctx->cq_overflow_list);
init_completion(&ctx->completions[0]);
@@ -952,14 +1067,29 @@ static struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
return NULL;
}
+/*
+ * called by:
+ * - fs/io_uring.c|978| <<req_need_defer>> return __req_need_defer(req);
+ * - fs/io_uring.c|1004| <<io_get_timeout_req>> if (!__req_need_defer(req)) {
+ */
static inline bool __req_need_defer(struct io_kiocb *req)
{
+ /*
+ * struct io_kiocb:
+ * -> struct io_ring_ctx *ctx;
+ */
struct io_ring_ctx *ctx = req->ctx;
return req->sequence != ctx->cached_cq_tail
+ atomic_read(&ctx->cached_cq_overflow);
}
+/*
+ * called by:
+ * - fs/io_uring.c|988| <<io_get_deferred_req>> if (req && !req_need_defer(req)) {
+ * - fs/io_uring.c|5046| <<io_req_defer>> if (!req_need_defer(req) && list_empty_careful(&ctx->defer_list))
+ * - fs/io_uring.c|5058| <<io_req_defer>> if (!req_need_defer(req) && list_empty(&ctx->defer_list)) {
+ */
static inline bool req_need_defer(struct io_kiocb *req)
{
if (unlikely(req->flags & REQ_F_IO_DRAIN))
@@ -968,6 +1098,10 @@ static inline bool req_need_defer(struct io_kiocb *req)
return false;
}
+/*
+ * called by:
+ * - fs/io_uring.c|1137| <<io_commit_cqring>> while ((req = io_get_deferred_req(ctx)) != NULL)
+ */
static struct io_kiocb *io_get_deferred_req(struct io_ring_ctx *ctx)
{
struct io_kiocb *req;
@@ -981,6 +1115,10 @@ static struct io_kiocb *io_get_deferred_req(struct io_ring_ctx *ctx)
return NULL;
}
+/*
+ * called by:
+ * - fs/io_uring.c|1132| <<io_commit_cqring>> while ((req = io_get_timeout_req(ctx)) != NULL)
+ */
static struct io_kiocb *io_get_timeout_req(struct io_ring_ctx *ctx)
{
struct io_kiocb *req;
@@ -998,6 +1136,10 @@ static struct io_kiocb *io_get_timeout_req(struct io_ring_ctx *ctx)
return NULL;
}
+/*
+ * called by:
+ * - fs/io_uring.c|1135| <<io_commit_cqring>> __io_commit_cqring(ctx);
+ */
static void __io_commit_cqring(struct io_ring_ctx *ctx)
{
struct io_rings *rings = ctx->rings;
@@ -1005,6 +1147,13 @@ static void __io_commit_cqring(struct io_ring_ctx *ctx)
/* order cqe stores with ring update */
smp_store_release(&rings->cq.tail, ctx->cached_cq_tail);
+ /*
+ * 在以下使用io_ring_ctx:
+ * - fs/io_uring.c|989| <<io_ring_ctx_alloc>> init_waitqueue_head(&ctx->cq_wait);
+ * - fs/io_uring.c|1094| <<__io_commit_cqring>> if (wq_has_sleeper(&ctx->cq_wait)) {
+ * - fs/io_uring.c|1095| <<__io_commit_cqring>> wake_up_interruptible(&ctx->cq_wait);
+ * - fs/io_uring.c|7649| <<io_uring_poll>> poll_wait(file, &ctx->cq_wait, wait);
+ */
if (wq_has_sleeper(&ctx->cq_wait)) {
wake_up_interruptible(&ctx->cq_wait);
kill_fasync(&ctx->cq_fasync, SIGIO, POLL_IN);
@@ -1056,6 +1205,10 @@ static inline void io_req_work_drop_env(struct io_kiocb *req)
}
}
+/*
+ * called by:
+ * - fs/io_uring.c|1153| <<io_queue_async_work>> io_prep_async_work(req, &link);
+ */
static inline void io_prep_async_work(struct io_kiocb *req,
struct io_kiocb **link)
{
@@ -1074,6 +1227,15 @@ static inline void io_prep_async_work(struct io_kiocb *req,
*link = io_prep_linked_timeout(req);
}
+/*
+ * called by:
+ * - fs/io_uring.c|1197| <<io_commit_cqring>> io_queue_async_work(req);
+ * - fs/io_uring.c|1625| <<io_free_req>> io_queue_async_work(nxt);
+ * - fs/io_uring.c|1806| <<io_iopoll_queue>> io_queue_async_work(req);
+ * - fs/io_uring.c|3532| <<io_close>> io_queue_async_work(req);
+ * - fs/io_uring.c|5666| <<__io_queue_sqe>> io_queue_async_work(req);
+ * - fs/io_uring.c|5727| <<io_queue_sqe>> io_queue_async_work(req);
+ */
static inline void io_queue_async_work(struct io_kiocb *req)
{
struct io_ring_ctx *ctx = req->ctx;
@@ -1089,6 +1251,11 @@ static inline void io_queue_async_work(struct io_kiocb *req)
io_queue_linked_timeout(link);
}
+/*
+ * called by:
+ * - fs/io_uring.c|1183| <<io_kill_timeouts>> io_kill_timeout(req);
+ * - fs/io_uring.c|1192| <<io_commit_cqring>> io_kill_timeout(req);
+ */
static void io_kill_timeout(struct io_kiocb *req)
{
int ret;
@@ -1103,6 +1270,10 @@ static void io_kill_timeout(struct io_kiocb *req)
}
}
+/*
+ * called by:
+ * - fs/io_uring.c|7496| <<io_ring_ctx_wait_and_kill>> io_kill_timeouts(ctx);
+ */
static void io_kill_timeouts(struct io_ring_ctx *ctx)
{
struct io_kiocb *req, *tmp;
@@ -1113,6 +1284,20 @@ static void io_kill_timeouts(struct io_ring_ctx *ctx)
spin_unlock_irq(&ctx->completion_lock);
}
+/*
+ * called by:
+ * - fs/io_uring.c|1280| <<io_cqring_overflow_flush>> io_commit_cqring(ctx);
+ * - fs/io_uring.c|1342| <<__io_cqring_add_event>> io_commit_cqring(ctx);
+ * - fs/io_uring.c|1507| <<io_link_cancel_timeout>> io_commit_cqring(ctx);
+ * - fs/io_uring.c|1581| <<io_fail_links>> io_commit_cqring(ctx);
+ * - fs/io_uring.c|1792| <<io_iopoll_complete>> io_commit_cqring(ctx);
+ * - fs/io_uring.c|4277| <<io_async_task_func>> io_commit_cqring(ctx);
+ * - fs/io_uring.c|4461| <<io_poll_remove_one>> io_commit_cqring(req->ctx);
+ * - fs/io_uring.c|4547| <<io_poll_complete>> io_commit_cqring(ctx);
+ * - fs/io_uring.c|4683| <<io_timeout_fn>> io_commit_cqring(ctx);
+ * - fs/io_uring.c|4746| <<io_timeout_remove>> io_commit_cqring(ctx);
+ * - fs/io_uring.c|4919| <<io_async_find_and_cancel>> io_commit_cqring(ctx);
+ */
static void io_commit_cqring(struct io_ring_ctx *ctx)
{
struct io_kiocb *req;
@@ -1144,6 +1329,10 @@ static struct io_uring_cqe *io_get_cqring(struct io_ring_ctx *ctx)
return &rings->cqes[tail & ctx->cq_mask];
}
+/*
+ * called by:
+ * - fs/io_uring.c|1336| <<io_cqring_ev_posted>> if (io_should_trigger_evfd(ctx))
+ */
static inline bool io_should_trigger_evfd(struct io_ring_ctx *ctx)
{
if (!ctx->cq_ev_fd)
@@ -1153,6 +1342,21 @@ static inline bool io_should_trigger_evfd(struct io_ring_ctx *ctx)
return io_wq_current_is_worker();
}
+/*
+ * called by:
+ * - fs/io_uring.c|1286| <<io_cqring_overflow_flush>> io_cqring_ev_posted(ctx);
+ * - fs/io_uring.c|1345| <<__io_cqring_add_event>> io_cqring_ev_posted(ctx);
+ * - fs/io_uring.c|1551| <<io_req_link_next>> io_cqring_ev_posted(ctx);
+ * - fs/io_uring.c|1583| <<io_fail_links>> io_cqring_ev_posted(ctx);
+ * - fs/io_uring.c|1794| <<io_iopoll_complete>> io_cqring_ev_posted(ctx);
+ * - fs/io_uring.c|4287| <<io_async_task_func>> io_cqring_ev_posted(ctx);
+ * - fs/io_uring.c|4486| <<io_poll_remove_all>> io_cqring_ev_posted(ctx);
+ * - fs/io_uring.c|4566| <<io_poll_task_handler>> io_cqring_ev_posted(ctx);
+ * - fs/io_uring.c|4646| <<io_poll_add>> io_cqring_ev_posted(ctx);
+ * - fs/io_uring.c|4686| <<io_timeout_fn>> io_cqring_ev_posted(ctx);
+ * - fs/io_uring.c|4748| <<io_timeout_remove>> io_cqring_ev_posted(ctx);
+ * - fs/io_uring.c|4921| <<io_async_find_and_cancel>> io_cqring_ev_posted(ctx);
+ */
static void io_cqring_ev_posted(struct io_ring_ctx *ctx)
{
if (waitqueue_active(&ctx->wait))
@@ -1358,6 +1562,12 @@ static void __io_req_aux_free(struct io_kiocb *req)
io_req_work_drop_env(req);
}
+/*
+ * called by:
+ * - fs/io_uring.c|1683| <<io_free_req>> __io_free_req(req);
+ * - fs/io_uring.c|1722| <<io_put_req_find_next>> __io_free_req(req);
+ * - fs/io_uring.c|1760| <<__io_double_put_req>> __io_free_req(req);
+ */
static void __io_free_req(struct io_kiocb *req)
{
__io_req_aux_free(req);
@@ -1837,6 +2047,10 @@ static void io_iopoll_reap_events(struct io_ring_ctx *ctx)
mutex_unlock(&ctx->uring_lock);
}
+/*
+ * called by:
+ * - fs/io_uring.c|7617| <<SYSCALL_DEFINE6(io_uring_enter)>> ret = io_iopoll_check(ctx, &nr_events, min_complete);
+ */
static int io_iopoll_check(struct io_ring_ctx *ctx, unsigned *nr_events,
long min)
{
@@ -2415,6 +2629,11 @@ static ssize_t io_import_iovec(int rw, struct io_kiocb *req,
* For files that don't have ->read_iter() and ->write_iter(), handle them
* by looping over ->read() or ->write() manually.
*/
+/*
+ * called by:
+ * - fs/io_uring.c|2592| <<io_read>> ret2 = loop_rw_iter(READ, req->file, kiocb, &iter);
+ * - fs/io_uring.c|2707| <<io_write>> ret2 = loop_rw_iter(WRITE, req->file, kiocb, &iter);
+ */
static ssize_t loop_rw_iter(int rw, struct file *file, struct kiocb *kiocb,
struct iov_iter *iter)
{
@@ -2500,6 +2719,11 @@ static int io_alloc_async_ctx(struct io_kiocb *req)
return __io_alloc_async_ctx(req);
}
+/*
+ * called by:
+ * - fs/io_uring.c|2743| <<io_read>> ret = io_setup_async_rw(req, io_size, iovec,
+ * - fs/io_uring.c|2866| <<io_write>> ret = io_setup_async_rw(req, io_size, iovec,
+ */
static int io_setup_async_rw(struct io_kiocb *req, ssize_t io_size,
struct iovec *iovec, struct iovec *fast_iov,
struct iov_iter *iter)
@@ -2637,6 +2861,10 @@ static int io_write_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe,
return 0;
}
+/*
+ * 处理IORING_OP_WRITEV/IORING_OP_WRITE_FIXED/IORING_OP_WRITE:
+ * - fs/io_uring.c|5276| <<io_issue_sqe>> ret = io_write(req, force_nonblock);
+ */
static int io_write(struct io_kiocb *req, bool force_nonblock)
{
struct iovec inline_vecs[UIO_FASTIOV], *iovec = inline_vecs;
@@ -3127,6 +3355,10 @@ static int io_provide_buffers_prep(struct io_kiocb *req,
return 0;
}
+/*
+ * called by:
+ * - fs/io_uring.c|3178| <<io_provide_buffers>> ret = io_add_buffers(p, &head);
+ */
static int io_add_buffers(struct io_provide_buf *pbuf, struct io_buffer **head)
{
struct io_buffer *buf;
@@ -4534,6 +4766,10 @@ static int io_poll_add_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe
return 0;
}
+/*
+ * called by:
+ * - fs/io_uring.c|5131| <<io_issue_sqe>> ret = io_poll_add(req);
+ */
static int io_poll_add(struct io_kiocb *req)
{
struct io_poll_iocb *poll = &req->poll;
@@ -4701,6 +4937,10 @@ static int io_timeout_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe,
return 0;
}
+/*
+ * 在以下使用io_timeout():
+ * - fs/io_uring.c|5179| <<io_issue_sqe>> ret = io_timeout(req);
+ */
static int io_timeout(struct io_kiocb *req)
{
struct io_ring_ctx *ctx = req->ctx;
@@ -5076,6 +5316,11 @@ static void io_cleanup_req(struct io_kiocb *req)
req->flags &= ~REQ_F_NEED_CLEANUP;
}
+/*
+ * called by:
+ * - fs/io_uring.c|5351| <<io_wq_submit_work>> ret = io_issue_sqe(req, NULL, false);
+ * - fs/io_uring.c|5548| <<__io_queue_sqe>> ret = io_issue_sqe(req, sqe, true);
+ */
static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
bool force_nonblock)
{
@@ -5370,6 +5615,11 @@ static inline struct file *io_file_from_index(struct io_ring_ctx *ctx,
return table->files[index & IORING_FILE_TABLE_MASK];;
}
+/*
+ * called by:
+ * - fs/io_uring.c|2756| <<io_splice_prep>> ret = io_file_get(NULL, req, READ_ONCE(sqe->splice_fd_in), &sp->file_in,
+ * - fs/io_uring.c|5417| <<io_req_set_file>> return io_file_get(state, req, fd, &req->file, fixed);
+ */
static int io_file_get(struct io_submit_state *state, struct io_kiocb *req,
int fd, struct file **out_file, bool fixed)
{
@@ -5477,6 +5727,13 @@ static enum hrtimer_restart io_link_timeout_fn(struct hrtimer *timer)
return HRTIMER_NORESTART;
}
+/*
+ * called by:
+ * - fs/io_uring.c|1183| <<io_queue_async_work>> io_queue_linked_timeout(link);
+ * - fs/io_uring.c|1695| <<io_link_work_cb>> io_queue_linked_timeout(link);
+ * - fs/io_uring.c|5713| <<__io_queue_sqe>> io_queue_linked_timeout(linked_timeout);
+ * - fs/io_uring.c|5738| <<__io_queue_sqe>> io_queue_linked_timeout(linked_timeout);
+ */
static void io_queue_linked_timeout(struct io_kiocb *req)
{
struct io_ring_ctx *ctx = req->ctx;
@@ -5518,6 +5775,12 @@ static struct io_kiocb *io_prep_linked_timeout(struct io_kiocb *req)
return nxt;
}
+/*
+ * called by:
+ * - fs/io_uring.c|4356| <<io_async_task_func>> __io_queue_sqe(req, NULL);
+ * - fs/io_uring.c|4640| <<io_poll_task_func>> __io_queue_sqe(nxt, NULL);
+ * - fs/io_uring.c|5790| <<io_queue_sqe>> __io_queue_sqe(req, sqe);
+ */
static void __io_queue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe)
{
struct io_kiocb *linked_timeout;
@@ -5595,6 +5858,11 @@ static void __io_queue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe)
revert_creds(old_creds);
}
+/*
+ * called by:
+ * - fs/io_uring.c|5800| <<io_queue_link_head>> io_queue_sqe(req, NULL);
+ * - fs/io_uring.c|5868| <<io_submit_sqe>> io_queue_sqe(req, sqe);
+ */
static void io_queue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe)
{
int ret;
@@ -5628,6 +5896,11 @@ static void io_queue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe)
}
}
+/*
+ * called by:
+ * - fs/io_uring.c|5848| <<io_submit_sqe>> io_queue_link_head(head);
+ * - fs/io_uring.c|6100| <<io_submit_sqes>> io_queue_link_head(link);
+ */
static inline void io_queue_link_head(struct io_kiocb *req)
{
if (unlikely(req->flags & REQ_F_FAIL_LINK)) {
@@ -5637,6 +5910,10 @@ static inline void io_queue_link_head(struct io_kiocb *req)
io_queue_sqe(req, NULL);
}
+/*
+ * called by:
+ * - fs/io_uring.c|5905| <<io_submit_sqes>> err = io_submit_sqe(req, sqe, statep, &link);
+ */
static int io_submit_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
struct io_submit_state *state, struct io_kiocb **link)
{
@@ -5719,6 +5996,10 @@ static void io_submit_state_end(struct io_submit_state *state)
/*
* Start submission side cache.
*/
+/*
+ * called by:
+ * - fs/io_uring.c|6085| <<io_submit_sqes>> io_submit_state_start(&state, nr);
+ */
static void io_submit_state_start(struct io_submit_state *state,
unsigned int max_ios)
{
@@ -5728,6 +6009,10 @@ static void io_submit_state_start(struct io_submit_state *state,
state->ios_left = max_ios;
}
+/*
+ * called by:
+ * - fs/io_uring.c|6101| <<io_submit_sqes>> io_commit_sqring(ctx);
+ */
static void io_commit_sqring(struct io_ring_ctx *ctx)
{
struct io_rings *rings = ctx->rings;
@@ -5748,6 +6033,10 @@ static void io_commit_sqring(struct io_ring_ctx *ctx)
* used, it's important that those reads are done through READ_ONCE() to
* prevent a re-load down the line.
*/
+/*
+ * called by:
+ * - fs/io_uring.c|5900| <<io_submit_sqes>> sqe = io_get_sqe(ctx);
+ */
static const struct io_uring_sqe *io_get_sqe(struct io_ring_ctx *ctx)
{
u32 *sq_array = ctx->sq_array;
@@ -5771,6 +6060,11 @@ static const struct io_uring_sqe *io_get_sqe(struct io_ring_ctx *ctx)
return NULL;
}
+/*
+ * called by:
+ * - fs/io_uring.c|6099| <<io_submit_sqes>> io_consume_sqe(ctx);
+ * - fs/io_uring.c|6110| <<io_submit_sqes>> io_consume_sqe(ctx);
+ */
static inline void io_consume_sqe(struct io_ring_ctx *ctx)
{
ctx->cached_sq_head++;
@@ -5780,6 +6074,10 @@ static inline void io_consume_sqe(struct io_ring_ctx *ctx)
IOSQE_IO_HARDLINK | IOSQE_ASYNC | \
IOSQE_BUFFER_SELECT)
+/*
+ * called by:
+ * - fs/io_uring.c|5899| <<io_submit_sqes>> err = io_init_req(ctx, req, sqe, statep, async);
+ */
static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
const struct io_uring_sqe *sqe,
struct io_submit_state *state, bool async)
@@ -5833,6 +6131,11 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
}
/* same numerical values with corresponding REQ_F_*, safe to copy */
+ /*
+ * 在以下使用IOSQE_IO_LINK:
+ * - fs/io_uring.c|6061| <<SQE_VALID_FLAGS>> #define SQE_VALID_FLAGS (IOSQE_FIXED_FILE|IOSQE_IO_DRAIN|IOSQE_IO_LINK| \
+ * - fs/io_uring.c|6124| <<io_init_req>> IOSQE_BUFFER_SELECT | IOSQE_IO_LINK);
+ */
req->flags |= sqe_flags & (IOSQE_IO_DRAIN | IOSQE_IO_HARDLINK |
IOSQE_ASYNC | IOSQE_FIXED_FILE |
IOSQE_BUFFER_SELECT | IOSQE_IO_LINK);
@@ -5843,6 +6146,11 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
return io_req_set_file(state, req, READ_ONCE(sqe->fd));
}
+/*
+ * called by:
+ * - fs/io_uring.c|6052| <<io_sq_thread>> ret = io_submit_sqes(ctx, to_submit, NULL, -1, true);
+ * - fs/io_uring.c|7555| <<SYSCALL_DEFINE6(io_uring_enter)>> submitted = io_submit_sqes(ctx, to_submit, f.file, fd, false);
+ */
static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr,
struct file *ring_file, int ring_fd, bool async)
{
@@ -5858,6 +6166,9 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr,
}
/* make sure SQ entry isn't read before tail */
+ /*
+ * unsigned sq_entries;
+ */
nr = min3(nr, ctx->sq_entries, io_sqring_entries(ctx));
if (!percpu_ref_tryget_many(&ctx->refs, nr))
@@ -5876,11 +6187,22 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr,
struct io_kiocb *req;
int err;
+ /*
+ * Fetch an sqe, if one is available. Note that sqe_ptr will point to memory
+ * that is mapped by userspace. This means that care needs to be taken to
+ * ensure that reads are stable, as we cannot rely on userspace always
+ * being a good citizen. If members of the sqe are validated and then later
+ * used, it's important that those reads are done through READ_ONCE() to
+ * prevent a re-load down the line.
+ */
sqe = io_get_sqe(ctx);
if (unlikely(!sqe)) {
io_consume_sqe(ctx);
break;
}
+ /*
+ * struct io_kiocb *req;
+ */
req = io_alloc_req(ctx, statep);
if (unlikely(!req)) {
if (!submitted)
@@ -5933,6 +6255,11 @@ static inline void io_sq_thread_drop_mm(struct io_ring_ctx *ctx)
}
}
+/*
+ * 在以下使用io_sq_thread():
+ * - fs/io_uring.c|6910| <<io_sq_offload_start>> ctx->sqo_thread = kthread_create_on_cpu(io_sq_thread,
+ * - fs/io_uring.c|6914| <<io_sq_offload_start>> ctx->sqo_thread = kthread_create(io_sq_thread, ctx,
+ */
static int io_sq_thread(void *data)
{
struct io_ring_ctx *ctx = data;
@@ -6065,6 +6392,11 @@ struct io_wait_queue {
unsigned nr_timeouts;
};
+/*
+ * called by:
+ * - fs/io_uring.c|6273| <<io_wake_function>> if (!io_should_wake(iowq, true))
+ * - fs/io_uring.c|6330| <<io_cqring_wait>> if (io_should_wake(&iowq, false))
+ */
static inline bool io_should_wake(struct io_wait_queue *iowq, bool noflush)
{
struct io_ring_ctx *ctx = iowq->ctx;
@@ -6078,6 +6410,10 @@ static inline bool io_should_wake(struct io_wait_queue *iowq, bool noflush)
atomic_read(&ctx->cq_timeouts) != iowq->nr_timeouts;
}
+/*
+ * 在以下使用io_wake_function():
+ * - fs/io_uring.c|6293| <<io_cqring_wait>> .func = io_wake_function,
+ */
static int io_wake_function(struct wait_queue_entry *curr, unsigned int mode,
int wake_flags, void *key)
{
@@ -6095,6 +6431,10 @@ static int io_wake_function(struct wait_queue_entry *curr, unsigned int mode,
* Wait until events become available, if we don't already have some. The
* application must reap them itself, as they reside on the shared cq ring.
*/
+/*
+ * called by:
+ * - fs/io_uring.c|7619| <<SYSCALL_DEFINE6(io_uring_enter)>> ret = io_cqring_wait(ctx, min_complete, sig, sigsz);
+ */
static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
const sigset_t __user *sig, size_t sigsz)
{
@@ -6153,6 +6493,10 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
return READ_ONCE(rings->cq.head) == READ_ONCE(rings->cq.tail) ? ret : 0;
}
+/*
+ * called by:
+ * - fs/io_uring.c|6406| <<io_sqe_files_unregister>> __io_sqe_files_unregister(ctx);
+ */
static void __io_sqe_files_unregister(struct io_ring_ctx *ctx)
{
#if defined(CONFIG_UNIX)
@@ -6176,6 +6520,10 @@ static void __io_sqe_files_unregister(struct io_ring_ctx *ctx)
#endif
}
+/*
+ * called by:
+ * - fs/io_uring.c|6738| <<io_sqe_files_register>> if (percpu_ref_init(&ctx->file_data->refs, io_file_ref_kill,
+ */
static void io_file_ref_kill(struct percpu_ref *ref)
{
struct fixed_file_data *data;
@@ -6184,6 +6532,13 @@ static void io_file_ref_kill(struct percpu_ref *ref)
complete(&data->done);
}
+/*
+ * called by:
+ * - fs/io_uring.c|6625| <<io_sqe_files_register>> io_sqe_files_unregister(ctx);
+ * - fs/io_uring.c|6631| <<io_sqe_files_register>> io_sqe_files_unregister(ctx);
+ * - fs/io_uring.c|7253| <<io_ring_ctx_free>> io_sqe_files_unregister(ctx);
+ * - fs/io_uring.c|8123| <<__io_uring_register(处理IORING_UNREGISTER_FILES)>> ret = io_sqe_files_unregister(ctx);
+ */
static int io_sqe_files_unregister(struct io_ring_ctx *ctx)
{
struct fixed_file_data *data = ctx->file_data;
@@ -6219,6 +6574,10 @@ static int io_sqe_files_unregister(struct io_ring_ctx *ctx)
return 0;
}
+/*
+ * called by:
+ * - fs/io_uring.c|6435| <<io_finish_async>> io_sq_thread_stop(ctx);
+ */
static void io_sq_thread_stop(struct io_ring_ctx *ctx)
{
if (ctx->sqo_thread) {
@@ -6234,6 +6593,11 @@ static void io_sq_thread_stop(struct io_ring_ctx *ctx)
}
}
+/*
+ * called by:
+ * - fs/io_uring.c|7178| <<io_sq_offload_start>> io_finish_async(ctx);
+ * - fs/io_uring.c|7528| <<io_ring_ctx_free>> io_finish_async(ctx);
+ */
static void io_finish_async(struct io_ring_ctx *ctx)
{
io_sq_thread_stop(ctx);
@@ -6499,6 +6863,10 @@ static void destroy_fixed_file_ref_node(struct fixed_file_ref_node *ref_node)
kfree(ref_node);
}
+/*
+ * 处理IORING_REGISTER_FILES:
+ * - fs/io_uring.c|8117| <<__io_uring_register>> ret = io_sqe_files_register(ctx, arg, nr_args);
+ */
static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
unsigned nr_args)
{
@@ -6623,6 +6991,10 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
return ret;
}
+/*
+ * called by:
+ * - fs/io_uring.c|6787| <<__io_sqe_files_update>> err = io_sqe_file_register(ctx, file, i);
+ */
static int io_sqe_file_register(struct io_ring_ctx *ctx, struct file *file,
int index)
{
@@ -6666,6 +7038,10 @@ static int io_sqe_file_register(struct io_ring_ctx *ctx, struct file *file,
#endif
}
+/*
+ * called by:
+ * - fs/io_uring.c|6929| <<__io_sqe_files_update>> err = io_queue_file_removal(data, file);
+ */
static int io_queue_file_removal(struct fixed_file_data *data,
struct file *file)
{
@@ -6684,6 +7060,11 @@ static int io_queue_file_removal(struct fixed_file_data *data,
return 0;
}
+/*
+ * called by:
+ * - fs/io_uring.c|5037| <<io_files_update>> ret = __io_sqe_files_update(ctx, &up, req->files_update.nr_args);
+ * - fs/io_uring.c|6995| <<io_sqe_files_update>> return __io_sqe_files_update(ctx, &up, nr_args);
+ */
static int __io_sqe_files_update(struct io_ring_ctx *ctx,
struct io_uring_files_update *up,
unsigned nr_args)
@@ -6770,6 +7151,10 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
return done ? done : err;
}
+/*
+ * 处理IORING_REGISTER_FILES_UPDATE:
+ * - fs/io_uring.c|8143| <<__io_uring_register>> ret = io_sqe_files_update(ctx, arg, nr_args);
+ */
static int io_sqe_files_update(struct io_ring_ctx *ctx, void __user *arg,
unsigned nr_args)
{
@@ -6787,6 +7172,10 @@ static int io_sqe_files_update(struct io_ring_ctx *ctx, void __user *arg,
return __io_sqe_files_update(ctx, &up, nr_args);
}
+/*
+ * 在以下使用io_free_work():
+ * - fs/io_uring.c|7016| <<io_init_wq_offload>> data.free_work = io_free_work;
+ */
static void io_free_work(struct io_wq_work *work)
{
struct io_kiocb *req = container_of(work, struct io_kiocb, work);
@@ -6795,6 +7184,16 @@ static void io_free_work(struct io_wq_work *work)
io_put_req(req);
}
+/*
+ * called by:
+ * - fs/io_uring.c|7097| <<io_sq_offload_start>> ret = io_init_wq_offload(ctx, p);
+ *
+ * SYSCALL_DEFINE2(io_uring_setup)
+ * -> io_uring_setup()
+ * -> io_uring_create()
+ * -> io_sq_offload_start()
+ * -> io_init_wq_offload()
+ */
static int io_init_wq_offload(struct io_ring_ctx *ctx,
struct io_uring_params *p)
{
@@ -6841,6 +7240,15 @@ static int io_init_wq_offload(struct io_ring_ctx *ctx,
return ret;
}
+/*
+ * called by:
+ * - fs/io_uring.c|8119| <<io_uring_create>> ret = io_sq_offload_start(ctx, p);
+ *
+ * SYSCALL_DEFINE2(io_uring_setup)
+ * -> io_uring_setup()
+ * -> io_uring_create()
+ * -> io_sq_offload_start()
+ */
static int io_sq_offload_start(struct io_ring_ctx *ctx,
struct io_uring_params *p)
{
@@ -6849,6 +7257,7 @@ static int io_sq_offload_start(struct io_ring_ctx *ctx,
mmgrab(current->mm);
ctx->sqo_mm = current->mm;
+ /* SQ poll thread */
if (ctx->flags & IORING_SETUP_SQPOLL) {
ret = -EPERM;
if (!capable(CAP_SYS_ADMIN))
@@ -6858,6 +7267,9 @@ static int io_sq_offload_start(struct io_ring_ctx *ctx,
if (!ctx->sq_thread_idle)
ctx->sq_thread_idle = HZ;
+ /*
+ * sq_thread_cpu is valid
+ */
if (p->flags & IORING_SETUP_SQ_AFF) {
int cpu = p->sq_thread_cpu;
@@ -6898,11 +7310,25 @@ static int io_sq_offload_start(struct io_ring_ctx *ctx,
return ret;
}
+/*
+ * called by:
+ * - fs/io_uring.c|7288| <<io_sqe_buffer_unregister>> io_unaccount_mem(ctx->user, imu->nr_bvecs);
+ * - fs/io_uring.c|7393| <<io_sqe_buffer_register>> io_unaccount_mem(ctx->user, nr_pages);
+ * - fs/io_uring.c|7404| <<io_sqe_buffer_register>> io_unaccount_mem(ctx->user, nr_pages);
+ * - fs/io_uring.c|7436| <<io_sqe_buffer_register>> io_unaccount_mem(ctx->user, nr_pages);
+ * - fs/io_uring.c|7551| <<io_ring_ctx_free>> io_unaccount_mem(ctx->user,
+ * - fs/io_uring.c|8180| <<io_uring_create>> io_unaccount_mem(user, ring_pages(p->sq_entries,
+ */
static void io_unaccount_mem(struct user_struct *user, unsigned long nr_pages)
{
atomic_long_sub(nr_pages, &user->locked_vm);
}
+/*
+ * called by:
+ * - fs/io_uring.c|7376| <<io_sqe_buffer_register>> ret = io_account_mem(ctx->user, nr_pages);
+ * - fs/io_uring.c|8169| <<io_uring_create>> ret = io_account_mem(user,
+ */
static int io_account_mem(struct user_struct *user, unsigned long nr_pages)
{
unsigned long page_limit, cur_pages, new_pages;
@@ -6921,6 +7347,13 @@ static int io_account_mem(struct user_struct *user, unsigned long nr_pages)
return 0;
}
+/*
+ * called by:
+ * - fs/io_uring.c|7546| <<io_ring_ctx_free>> io_mem_free(ctx->rings);
+ * - fs/io_uring.c|7547| <<io_ring_ctx_free>> io_mem_free(ctx->sq_sqes);
+ * - fs/io_uring.c|8050| <<io_allocate_scq_urings>> io_mem_free(ctx->rings);
+ * - fs/io_uring.c|8057| <<io_allocate_scq_urings>> io_mem_free(ctx->rings);
+ */
static void io_mem_free(void *ptr)
{
struct page *page;
@@ -6933,6 +7366,11 @@ static void io_mem_free(void *ptr)
free_compound_page(page);
}
+/*
+ * called by:
+ * - fs/io_uring.c|8033| <<io_allocate_scq_urings>> rings = io_mem_alloc(size);
+ * - fs/io_uring.c|8055| <<io_allocate_scq_urings>> ctx->sq_sqes = io_mem_alloc(size);
+ */
static void *io_mem_alloc(size_t size)
{
gfp_t gfp_flags = GFP_KERNEL | __GFP_ZERO | __GFP_NOWARN | __GFP_COMP |
@@ -6982,6 +7420,12 @@ static unsigned long ring_pages(unsigned sq_entries, unsigned cq_entries)
return pages;
}
+/*
+ * called by:
+ * - fs/io_uring.c|7194| <<io_sqe_buffer_register>> io_sqe_buffer_unregister(ctx);
+ * - fs/io_uring.c|7252| <<io_ring_ctx_free>> io_sqe_buffer_unregister(ctx);
+ * - fs/io_uring.c|8114| <<__io_uring_register(处理IORING_UNREGISTER_BUFFERS)>> ret = io_sqe_buffer_unregister(ctx);
+ */
static int io_sqe_buffer_unregister(struct io_ring_ctx *ctx)
{
int i, j;
@@ -7032,6 +7476,10 @@ static int io_copy_iov(struct io_ring_ctx *ctx, struct iovec *dst,
return 0;
}
+/*
+ * 处理IORING_REGISTER_BUFFERS:
+ * - fs/io_uring.c|8079| <<__io_uring_register>> ret = io_sqe_buffer_register(ctx, arg, nr_args);
+ */
static int io_sqe_buffer_register(struct io_ring_ctx *ctx, void __user *arg,
unsigned nr_args)
{
@@ -7174,6 +7622,10 @@ static int io_sqe_buffer_register(struct io_ring_ctx *ctx, void __user *arg,
return ret;
}
+/*
+ * 处理IORING_REGISTER_EVENTFD或者IORING_REGISTER_EVENTFD_ASYNC:
+ * - fs/io_uring.c|8150| <<__io_uring_register>> ret = io_eventfd_register(ctx, arg);
+ */
static int io_eventfd_register(struct io_ring_ctx *ctx, void __user *arg)
{
__s32 __user *fds = arg;
@@ -7195,6 +7647,11 @@ static int io_eventfd_register(struct io_ring_ctx *ctx, void __user *arg)
return 0;
}
+/*
+ * called by:
+ * - fs/io_uring.c|7271| <<io_ring_ctx_free>> io_eventfd_unregister(ctx);
+ * - fs/io_uring.c|8162| <<__io_uring_register(处理IORING_UNREGISTER_EVENTFD)>> ret = io_eventfd_unregister(ctx);
+ */
static int io_eventfd_unregister(struct io_ring_ctx *ctx)
{
if (ctx->cq_ev_fd) {
@@ -7261,6 +7718,13 @@ static __poll_t io_uring_poll(struct file *file, poll_table *wait)
struct io_ring_ctx *ctx = file->private_data;
__poll_t mask = 0;