-
Notifications
You must be signed in to change notification settings - Fork 4
/
linux-uek5-v4.14.35-2047.502.4.1.patch
8292 lines (7778 loc) · 361 KB
/
linux-uek5-v4.14.35-2047.502.4.1.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 a3f59d0d518ccd5ad54f37c5bed642aa6052f2ab Mon Sep 17 00:00:00 2001
From: Dongli Zhang <[email protected]>
Date: Mon, 26 Jul 2021 09:19:41 -0700
Subject: [PATCH 1/1] linux uek5 v4.14.35-2047.502.4.1
Signed-off-by: Dongli Zhang <[email protected]>
---
arch/x86/include/asm/apic.h | 19 +
arch/x86/include/asm/kvm_host.h | 69 ++
arch/x86/include/asm/pvclock-abi.h | 14 +
arch/x86/include/asm/x2apic.h | 7 +
arch/x86/include/uapi/asm/kvm_para.h | 11 +
arch/x86/kernel/apic/apic.c | 111 ++++
arch/x86/kernel/apic/probe_64.c | 22 +
arch/x86/kernel/apic/x2apic_cluster.c | 19 +
arch/x86/kernel/apic/x2apic_phys.c | 40 ++
arch/x86/kernel/kvm.c | 36 +
arch/x86/kvm/debugfs.c | 15 +
arch/x86/kvm/ioapic.c | 32 +
arch/x86/kvm/irq.c | 32 +
arch/x86/kvm/irq_comm.c | 62 ++
arch/x86/kvm/kvm_cache_regs.h | 5 +
arch/x86/kvm/lapic.c | 474 ++++++++++++++
arch/x86/kvm/lapic.h | 87 +++
arch/x86/kvm/mmu.c | 8 +
arch/x86/kvm/pmu.c | 62 ++
arch/x86/kvm/vmx/capabilities.h | 85 +++
arch/x86/kvm/vmx/ops.h | 8 +
arch/x86/kvm/vmx/pmu_intel.c | 12 +
arch/x86/kvm/vmx/vmcs.h | 22 +
arch/x86/kvm/vmx/vmx.c | 901 ++++++++++++++++++++++++++
arch/x86/kvm/vmx/vmx.h | 40 ++
arch/x86/kvm/x86.c | 297 +++++++++
arch/x86/kvm/x86.h | 5 +
drivers/net/virtio_net.c | 318 +++++++++
drivers/vhost/net.c | 86 +++
drivers/vhost/vhost.c | 276 ++++++++
drivers/vhost/vhost.h | 43 ++
drivers/virtio/virtio_ring.c | 316 +++++++++
include/linux/hrtimer.h | 38 ++
include/linux/kvm_host.h | 27 +-
include/uapi/linux/kvm.h | 9 +
include/uapi/linux/kvm_para.h | 6 +
include/uapi/linux/vhost.h | 25 +
include/uapi/linux/virtio_ring.h | 82 +++
kernel/events/core.c | 10 +
kernel/sched/core.c | 18 +
kernel/sched/cputime.c | 9 +
kernel/sched/sched.h | 5 +
kernel/sched/stats.h | 8 +
kernel/smp.c | 4 +
kernel/time/clockevents.c | 29 +
kernel/time/hrtimer.c | 50 ++
kernel/time/tick-oneshot.c | 13 +
kernel/time/tick-sched.c | 4 +
virt/kvm/async_pf.c | 26 +
virt/kvm/coalesced_mmio.c | 23 +
virt/kvm/eventfd.c | 25 +
virt/kvm/irqchip.c | 43 ++
virt/kvm/kvm_main.c | 346 ++++++++++
virt/kvm/vfio.c | 19 +
54 files changed, 4352 insertions(+), 1 deletion(-)
diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
index 97d686b821b5..f4fa1da4b794 100644
--- a/arch/x86/include/asm/apic.h
+++ b/arch/x86/include/asm/apic.h
@@ -280,6 +280,25 @@ struct apic {
int (*apic_id_registered)(void);
u32 irq_delivery_mode;
+ /*
+ * 在以下使用apic->irq_dest_mode:
+ * - arch/x86/kernel/apic/apic_flat_64.c|155| <<global>> .irq_dest_mode = 1,
+ * - arch/x86/kernel/apic/apic_flat_64.c|250| <<global>> .irq_dest_mode = 0,
+ * - arch/x86/kernel/apic/apic_noop.c|122| <<global>> .irq_dest_mode = 1,
+ * - arch/x86/kernel/apic/apic_numachip.c|250| <<global>> .irq_dest_mode = 0,
+ * - arch/x86/kernel/apic/apic_numachip.c|301| <<global>> .irq_dest_mode = 0,
+ * - arch/x86/kernel/apic/bigsmp_32.c|136| <<global>> .irq_dest_mode = 0,
+ * - arch/x86/kernel/apic/probe_32.c|85| <<global>> .irq_dest_mode = 1,
+ * - arch/x86/kernel/apic/x2apic_cluster.c|243| <<global>> .irq_dest_mode = 1,
+ * - arch/x86/kernel/apic/x2apic_phys.c|133| <<global>> .irq_dest_mode = 0,
+ * - arch/x86/kernel/apic/x2apic_uv_x.c|725| <<global>> .irq_dest_mode = 0,
+ * - arch/x86/kernel/apic/io_apic.c|2906| <<mp_setup_entry>> entry->dest_mode = apic->irq_dest_mode;
+ * - arch/x86/kernel/apic/msi.c|38| <<__irq_msi_compose_msg>> ((apic->irq_dest_mode == 0) ?
+ * - arch/x86/platform/uv/uv_irq.c|39| <<uv_program_mmr>> entry->dest_mode = apic->irq_dest_mode;
+ * - drivers/iommu/amd_iommu.c|4125| <<irq_remapping_prepare_irte>> apic->irq_dest_mode, irq_cfg->vector,
+ * - drivers/iommu/amd_iommu.c|4377| <<amd_ir_set_vcpu_affinity>> irte->lo.fields_remap.dm = apic->irq_dest_mode;
+ * - drivers/iommu/intel_irq_remapping.c|1067| <<prepare_irte>> irte->dst_mode = apic->irq_dest_mode;
+ */
u32 irq_dest_mode;
const struct cpumask *(*target_cpus)(void);
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 826fbad70c56..9bc52b12f2d9 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -556,7 +556,27 @@ struct kvm_vcpu_arch {
bool apicv_active;
bool load_eoi_exitmap_pending;
DECLARE_BITMAP(ioapic_handled_vectors, 256);
+ /*
+ * 在以下使用kvm_vcpu_arch->apic_attention:
+ * - arch/x86/kvm/lapic.c|742| <<pv_eoi_set_pending>> __set_bit(KVM_APIC_PV_EOI_PENDING, &vcpu->arch.apic_attention);
+ * - arch/x86/kvm/lapic.c|752| <<pv_eoi_clr_pending>> __clear_bit(KVM_APIC_PV_EOI_PENDING, &vcpu->arch.apic_attention);
+ * - arch/x86/kvm/lapic.c|2538| <<kvm_lapic_reset>> vcpu->arch.apic_attention = 0;
+ * - arch/x86/kvm/lapic.c|2886| <<kvm_lapic_sync_from_vapic>> if (test_bit(KVM_APIC_PV_EOI_PENDING, &vcpu->arch.apic_attention))
+ * - arch/x86/kvm/lapic.c|2889| <<kvm_lapic_sync_from_vapic>> if (!test_bit(KVM_APIC_CHECK_VAPIC, &vcpu->arch.apic_attention))
+ * - arch/x86/kvm/lapic.c|2933| <<kvm_lapic_sync_to_vapic>> if (!test_bit(KVM_APIC_CHECK_VAPIC, &vcpu->arch.apic_attention))
+ * - arch/x86/kvm/lapic.c|2956| <<kvm_lapic_set_vapic_addr>> __set_bit(KVM_APIC_CHECK_VAPIC, &vcpu->arch.apic_attention);
+ * - arch/x86/kvm/lapic.c|2958| <<kvm_lapic_set_vapic_addr>> __clear_bit(KVM_APIC_CHECK_VAPIC, &vcpu->arch.apic_attention);
+ * - arch/x86/kvm/x86.c|8053| <<vcpu_enter_guest>> if (vcpu->arch.apic_attention)
+ * - arch/x86/kvm/x86.c|8062| <<vcpu_enter_guest>> if (unlikely(vcpu->arch.apic_attention))
+ */
unsigned long apic_attention;
+ /*
+ * 在以下使用kvm_vcpu_arch->apic_arb_prio:
+ * - arch/x86/kvm/lapic.c|1088| <<__apic_accept_irq>> vcpu->arch.apic_arb_prio++;
+ * - arch/x86/kvm/lapic.c|1187| <<kvm_apic_compare_prio>> return vcpu1->arch.apic_arb_prio - vcpu2->arch.apic_arb_prio;
+ * - arch/x86/kvm/lapic.c|2480| <<kvm_lapic_reset>> vcpu->arch.apic_arb_prio = 0;
+ * - arch/x86/kvm/lapic.c|2771| <<kvm_apic_set_state>> vcpu->arch.apic_arb_prio = 0;
+ */
int32_t apic_arb_prio;
int mp_state;
u64 ia32_misc_enable_msr;
@@ -683,8 +703,28 @@ struct kvm_vcpu_arch {
u32 virtual_tsc_mult;
u32 virtual_tsc_khz;
s64 ia32_tsc_adjust_msr;
+ /*
+ * 在以下使用kvm_vcpu_arch->tsc_scaling_ratio:
+ * - arch/x86/kvm/debugfs.c|37| <<vcpu_get_tsc_scaling_ratio>> *val = vcpu->arch.tsc_scaling_ratio;
+ * - arch/x86/kvm/svm.c|2304| <<svm_vcpu_load>> u64 tsc_ratio = vcpu->arch.tsc_scaling_ratio;
+ * - arch/x86/kvm/vmx/vmx.c|1297| <<vmx_vcpu_load>> vmx->current_tsc_ratio != vcpu->arch.tsc_scaling_ratio)
+ * - arch/x86/kvm/vmx/vmx.c|7421| <<vmx_set_hv_timer>> if (vcpu->arch.tsc_scaling_ratio != kvm_default_tsc_scaling_ratio &&
+ * - arch/x86/kvm/vmx/vmx.c|7424| <<vmx_set_hv_timer>> vcpu->arch.tsc_scaling_ratio,
+ * - arch/x86/kvm/vmx/vmx.h|541| <<decache_tsc_multiplier>> vmx->current_tsc_ratio = vmx->vcpu.arch.tsc_scaling_ratio;
+ * - arch/x86/kvm/x86.c|1593| <<set_tsc_khz>> vcpu->arch.tsc_scaling_ratio = kvm_default_tsc_scaling_ratio;
+ * - arch/x86/kvm/x86.c|1619| <<set_tsc_khz>> vcpu->arch.tsc_scaling_ratio = ratio;
+ * - arch/x86/kvm/x86.c|1631| <<kvm_set_tsc_khz>> vcpu->arch.tsc_scaling_ratio = kvm_default_tsc_scaling_ratio;
+ * - arch/x86/kvm/x86.c|1722| <<kvm_scale_tsc>> u64 ratio = vcpu->arch.tsc_scaling_ratio;
+ * - arch/x86/kvm/x86.c|1884| <<adjust_tsc_offset_host>> if (vcpu->arch.tsc_scaling_ratio != kvm_default_tsc_scaling_ratio)
+ */
u64 tsc_scaling_ratio;
+ /*
+ * 在以下使用kvm_vcpu_arch->nmi_queued:
+ * - arch/x86/kvm/x86.c|615| <<kvm_inject_nmi>> atomic_inc(&vcpu->arch.nmi_queued);
+ * - arch/x86/kvm/x86.c|7403| <<process_nmi>> vcpu->arch.nmi_pending += atomic_xchg(&vcpu->arch.nmi_queued, 0);
+ * - arch/x86/kvm/x86.c|8916| <<kvm_vcpu_reset>> atomic_set(&vcpu->arch.nmi_queued, 0);
+ */
atomic_t nmi_queued; /* unprocessed asynchronous NMIs */
unsigned nmi_pending; /* NMI queued after currently running handler */
bool nmi_injected; /* Trying to inject an NMI this entry */
@@ -727,6 +767,14 @@ struct kvm_vcpu_arch {
unsigned long last_retry_addr;
struct {
+ /*
+ * 在以下使用kvm_vcpu_arch->apf.halted:
+ * - arch/x86/kvm/x86.c|7781| <<vcpu_enter_guest>> vcpu->arch.apf.halted = true;
+ * - arch/x86/kvm/x86.c|8056| <<vcpu_block>> vcpu->arch.apf.halted = false;
+ * - arch/x86/kvm/x86.c|8073| <<kvm_vcpu_running>> !vcpu->arch.apf.halted);
+ * - arch/x86/kvm/x86.c|8925| <<kvm_vcpu_reset>> vcpu->arch.apf.halted = false;
+ * - arch/x86/kvm/x86.c|9890| <<kvm_arch_async_page_present>> vcpu->arch.apf.halted = false;
+ */
bool halted;
gfn_t gfns[roundup_pow_of_two(ASYNC_PF_PER_VCPU)];
struct gfn_to_hva_cache data;
@@ -875,8 +923,24 @@ struct kvm_arch {
gpa_t wall_clock;
+ /*
+ * 在以下使用kvm_arch->mwait_in_guest:
+ * - arch/x86/kvm/x86.c|4662| <<kvm_vm_ioctl_enable_cap(KVM_CAP_X86_DISABLE_EXITS)>> kvm->arch.mwait_in_guest = true;
+ * - arch/x86/kvm/x86.h|330| <<kvm_mwait_in_guest>> return kvm->arch.mwait_in_guest;
+ */
bool mwait_in_guest;
+ /*
+ * 在以下使用hlt_in_guest:
+ * - arch/x86/kvm/x86.c|4664| <<kvm_vm_ioctl_enable_cap>> kvm->arch.hlt_in_guest = true;
+ * - arch/x86/kvm/x86.h|340| <<kvm_hlt_in_guest>> return kvm->arch.hlt_in_guest;
+ */
bool hlt_in_guest;
+ /*
+ * 在以下使用kvm_arch->pause_in_guest:
+ * - arch/x86/kvm/vmx/vmx.c|6874| <<vmx_vm_init>> kvm->arch.pause_in_guest = true;
+ * - arch/x86/kvm/x86.c|4666| <<kvm_vm_ioctl_enable_cap>> kvm->arch.pause_in_guest = true;
+ * - arch/x86/kvm/x86.h|340| <<kvm_pause_in_guest>> return kvm->arch.pause_in_guest;
+ */
bool pause_in_guest;
unsigned long irq_sources_bitmap;
@@ -1366,6 +1430,11 @@ int kvm_read_guest_page_mmu(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu,
bool kvm_require_cpl(struct kvm_vcpu *vcpu, int required_cpl);
bool kvm_require_dr(struct kvm_vcpu *vcpu, int dr);
+/*
+ * called by:
+ * - arch/x86/kvm/i8259.c|193| <<kvm_pic_set_irq>> irq_level = __kvm_irq_line_state(&s->irq_states[irq],
+ * - arch/x86/kvm/ioapic.c|395| <<kvm_ioapic_set_irq>> irq_level = __kvm_irq_line_state(&ioapic->irq_states[irq],
+ */
static inline int __kvm_irq_line_state(unsigned long *irq_state,
int irq_source_id, int level)
{
diff --git a/arch/x86/include/asm/pvclock-abi.h b/arch/x86/include/asm/pvclock-abi.h
index 1436226efe3e..03cd41bd4cb2 100644
--- a/arch/x86/include/asm/pvclock-abi.h
+++ b/arch/x86/include/asm/pvclock-abi.h
@@ -40,6 +40,20 @@ struct pvclock_wall_clock {
u32 nsec;
} __attribute__((__packed__));
+/*
+ * 在以下使用PVCLOCK_TSC_STABLE_BIT:
+ * - arch/x86/entry/vdso/vclock_gettime.c|135| <<vread_pvclock>> if (unlikely(!(pvti->flags & PVCLOCK_TSC_STABLE_BIT))) {
+ * - arch/x86/kernel/kvmclock.c|289| <<kvm_setup_vsyscall_timeinfo>> if (!(flags & PVCLOCK_TSC_STABLE_BIT))
+ * - arch/x86/kernel/kvmclock.c|351| <<kvmclock_init>> pvclock_set_flags(PVCLOCK_TSC_STABLE_BIT);
+ * - arch/x86/kernel/kvmclock.c|354| <<kvmclock_init>> kvm_sched_clock_init(flags & PVCLOCK_TSC_STABLE_BIT);
+ * - arch/x86/kernel/pvclock.c|96| <<pvclock_clocksource_read>> if ((valid_flags & PVCLOCK_TSC_STABLE_BIT) &&
+ * - arch/x86/kernel/pvclock.c|97| <<pvclock_clocksource_read>> (flags & PVCLOCK_TSC_STABLE_BIT))
+ * - arch/x86/kvm/hyperv.c|913| <<compute_tsc_page_parameters>> if (!(hv_clock->flags & PVCLOCK_TSC_STABLE_BIT))
+ * - arch/x86/kvm/x86.c|2351| <<kvm_guest_time_update>> pvclock_flags |= PVCLOCK_TSC_STABLE_BIT;
+ * - arch/x86/xen/time.c|456| <<xen_setup_vsyscall_time_info>> if (!(ti->pvti.flags & PVCLOCK_TSC_STABLE_BIT)) {
+ * - arch/x86/xen/time.c|504| <<xen_time_init>> if (pvti->flags & PVCLOCK_TSC_STABLE_BIT) {
+ * - arch/x86/xen/time.c|505| <<xen_time_init>> pvclock_set_flags(PVCLOCK_TSC_STABLE_BIT);
+ */
#define PVCLOCK_TSC_STABLE_BIT (1 << 0)
#define PVCLOCK_GUEST_STOPPED (1 << 1)
/* PVCLOCK_COUNTS_FROM_ZERO broke ABI and can't be used anymore. */
diff --git a/arch/x86/include/asm/x2apic.h b/arch/x86/include/asm/x2apic.h
index 78ccf28d17db..320d5e53d11a 100644
--- a/arch/x86/include/asm/x2apic.h
+++ b/arch/x86/include/asm/x2apic.h
@@ -20,6 +20,13 @@ static int x2apic_apic_id_registered(void)
return 1;
}
+/*
+ * called by:
+ * - arch/x86/kernel/apic/x2apic_cluster.c|33| <<x2apic_send_IPI>> __x2apic_send_IPI_dest(dest, vector, APIC_DEST_LOGICAL);
+ * - arch/x86/kernel/apic/x2apic_cluster.c|76| <<__x2apic_send_IPI_mask>> __x2apic_send_IPI_dest(dest, vector, apic->dest_logical);
+ * - arch/x86/kernel/apic/x2apic_phys.c|45| <<x2apic_send_IPI>> __x2apic_send_IPI_dest(dest, vector, APIC_DEST_PHYSICAL);
+ * - arch/x86/kernel/apic/x2apic_phys.c|63| <<__x2apic_send_IPI_mask>> __x2apic_send_IPI_dest(per_cpu(x86_cpu_to_apicid, query_cpu),
+ */
static void
__x2apic_send_IPI_dest(unsigned int apicid, int vector, unsigned int dest)
{
diff --git a/arch/x86/include/uapi/asm/kvm_para.h b/arch/x86/include/uapi/asm/kvm_para.h
index 21d5f0240595..aef2f287d653 100644
--- a/arch/x86/include/uapi/asm/kvm_para.h
+++ b/arch/x86/include/uapi/asm/kvm_para.h
@@ -59,7 +59,18 @@ struct kvm_steal_time {
__u32 pad[11];
};
+/*
+ * 在以下使用KVM_VCPU_PREEMPTED:
+ * - arch/x86/kernel/kvm.c|621| <<kvm_flush_tlb_others>> if ((state & KVM_VCPU_PREEMPTED)) {
+ * - arch/x86/kernel/kvm.c|819| <<__kvm_vcpu_is_preempted>> return !!(src->preempted & KVM_VCPU_PREEMPTED);
+ * - arch/x86/kvm/x86.c|3345| <<kvm_steal_time_set_preempted>> st->preempted = vcpu->arch.st.preempted = KVM_VCPU_PREEMPTED;
+ */
#define KVM_VCPU_PREEMPTED (1 << 0)
+/*
+ * 在以下使用KVM_VCPU_FLUSH_TLB:
+ * - arch/x86/kernel/kvm.c|623| <<kvm_flush_tlb_others>> state | KVM_VCPU_FLUSH_TLB))
+ * - arch/x86/kvm/x86.c|2457| <<record_steal_time>> if (xchg(&st->preempted, 0) & KVM_VCPU_FLUSH_TLB)
+ */
#define KVM_VCPU_FLUSH_TLB (1 << 1)
#define KVM_CLOCK_PAIRING_WALLCLOCK 0
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index ee33f0951322..218c4609de72 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -59,6 +59,18 @@
#include <asm/intel-family.h>
#include <asm/irq_regs.h>
+/*
+ * https://tcbbd.moe/ref-and-spec/intel-sdm/sdm-basic-ch10/
+ *
+ * 通过LINT0和LINT1这两个引脚接收的本地中断
+ * 通过IOAPIC接收的外部中断,以及通过MSI方式收到的外部中断
+ * 其他CPU(甚至自己)发来的IPI
+ * APIC Timer产生的中断
+ * Performance Monitoring Counter产生的中断
+ * 温度传感器产生的中断
+ * APIC内部错误引发的中断
+ */
+
unsigned int num_processors;
unsigned disabled_cpus;
@@ -90,6 +102,15 @@ static unsigned int disabled_cpu_apicid __read_mostly = BAD_APICID;
* This variable controls which CPUs receive external NMIs. By default,
* external NMIs are delivered only to the BSP.
*/
+/*
+ * 在以下使用apic_extnmi:
+ * - arch/x86/kernel/apic/apic.c|1319| <<init_bsp_APIC>> if (apic_extnmi == APIC_EXTNMI_NONE)
+ * - arch/x86/kernel/apic/apic.c|1560| <<setup_local_APIC>> if ((!cpu && apic_extnmi != APIC_EXTNMI_NONE) ||
+ * - arch/x86/kernel/apic/apic.c|1561| <<setup_local_APIC>> apic_extnmi == APIC_EXTNMI_ALL)
+ * - arch/x86/kernel/apic/apic.c|2795| <<apic_set_extnmi>> apic_extnmi = APIC_EXTNMI_ALL;
+ * - arch/x86/kernel/apic/apic.c|2797| <<apic_set_extnmi>> apic_extnmi = APIC_EXTNMI_NONE;
+ * - arch/x86/kernel/apic/apic.c|2799| <<apic_set_extnmi>> apic_extnmi = APIC_EXTNMI_BSP;
+ */
static int apic_extnmi = APIC_EXTNMI_BSP;
/*
@@ -328,6 +349,11 @@ int lapic_get_maxlvt(void)
* We do reads before writes even if unnecessary, to get around the
* P5 APIC double write bug.
*/
+/*
+ * called by:
+ * - arch/x86/kernel/apic/apic.c|524| <<lapic_timer_set_periodic_oneshot>> __setup_APIC_LVTT(lapic_timer_frequency, oneshot, 1);
+ * - arch/x86/kernel/apic/apic.c|874| <<calibrate_APIC_clock>> __setup_APIC_LVTT(0xffffffff, 0, 0);
+ */
static void __setup_APIC_LVTT(unsigned int clocks, int oneshot, int irqen)
{
unsigned int lvtt_value, tmp_value;
@@ -468,6 +494,24 @@ static int lapic_next_event(unsigned long delta,
return 0;
}
+/*
+ * 一个例子
+ * lapic_next_deadline
+ * tick_program_event
+ * hrtimer_interrupt
+ * smp_apic_timer_interrupt
+ * apic_timer_interrupt
+ * cpuidle_enter_state
+ * cpuidle_enter
+ * call_cpuidle
+ * do_idle
+ * cpu_startup_entry
+ * start_secondary
+ * secondary_startup_64
+ *
+ * 在以下使用lapic_next_deadline():
+ * - arch/x86/kernel/apic/apic.c|685| <<setup_APIC_timer>> levt->set_next_event = lapic_next_deadline;
+ */
static int lapic_next_deadline(unsigned long delta,
struct clock_event_device *evt)
{
@@ -493,6 +537,11 @@ static int lapic_timer_shutdown(struct clock_event_device *evt)
return 0;
}
+/*
+ * called by:
+ * - arch/x86/kernel/apic/apic.c|553| <<lapic_timer_set_periodic>> return lapic_timer_set_periodic_oneshot(evt, false);
+ * - arch/x86/kernel/apic/apic.c|558| <<lapic_timer_set_oneshot>> return lapic_timer_set_periodic_oneshot(evt, true);
+ */
static inline int
lapic_timer_set_periodic_oneshot(struct clock_event_device *evt, bool oneshot)
{
@@ -644,6 +693,13 @@ static __init bool apic_validate_deadline_timer(void)
* Setup the local APIC timer for this CPU. Copy the initialized values
* of the boot CPU and register the clock event in the framework.
*/
+/*
+ * called by:
+ * - arch/x86/kernel/apic/apic.c|1035| <<setup_boot_APIC_clock>> setup_APIC_timer();
+ * - arch/x86/kernel/apic/apic.c|1043| <<setup_boot_APIC_clock>> setup_APIC_timer();
+ * - arch/x86/kernel/apic/apic.c|1055| <<setup_boot_APIC_clock>> setup_APIC_timer();
+ * - arch/x86/kernel/apic/apic.c|1061| <<setup_secondary_APIC_clock>> setup_APIC_timer();
+ */
static void setup_APIC_timer(void)
{
struct clock_event_device *levt = this_cpu_ptr(&lapic_events);
@@ -654,9 +710,31 @@ static void setup_APIC_timer(void)
lapic_clockevent.rating = 150;
}
+ /*
+ * 580 static struct clock_event_device lapic_clockevent = {
+ * 581 .name = "lapic",
+ * 582 .features = CLOCK_EVT_FEAT_PERIODIC |
+ * 583 CLOCK_EVT_FEAT_ONESHOT | CLOCK_EVT_FEAT_C3STOP
+ * 584 | CLOCK_EVT_FEAT_DUMMY,
+ * 585 .shift = 32,
+ * 586 .set_state_shutdown = lapic_timer_shutdown,
+ * 587 .set_state_periodic = lapic_timer_set_periodic,
+ * 588 .set_state_oneshot = lapic_timer_set_oneshot,
+ * 589 .set_state_oneshot_stopped = lapic_timer_shutdown,
+ * 590 .set_next_event = lapic_next_event,
+ * 591 .broadcast = lapic_timer_broadcast,
+ * 592 .rating = 100,
+ * 593 .irq = -1,
+ * 594 };
+ * 595 static DEFINE_PER_CPU(struct clock_event_device, lapic_events);
+ */
memcpy(levt, &lapic_clockevent, sizeof(*levt));
levt->cpumask = cpumask_of(smp_processor_id());
+ /*
+ * # cat /sys/devices/system/clockevents/clockevent0/current_device
+ * lapic-deadline
+ */
if (this_cpu_has(X86_FEATURE_TSC_DEADLINE_TIMER)) {
levt->name = "lapic-deadline";
levt->features &= ~(CLOCK_EVT_FEAT_PERIODIC |
@@ -1072,6 +1150,9 @@ static void local_apic_timer_interrupt(void)
*/
inc_irq_stat(apic_timer_irqs);
+ /*
+ * hrtimer_interrupt()
+ */
evt->event_handler(evt);
}
@@ -1418,6 +1499,11 @@ static void apic_pending_intr_clear(void)
* Used to setup local APIC while initializing BSP or bringing up APs.
* Always called with preemption disabled.
*/
+/*
+ * called by:
+ * - arch/x86/kernel/apic/apic.c|1598| <<apic_ap_setup>> setup_local_APIC();
+ * - arch/x86/kernel/apic/apic.c|2413| <<apic_bsp_setup>> setup_local_APIC();
+ */
void setup_local_APIC(void)
{
int cpu = smp_processor_id();
@@ -1434,6 +1520,10 @@ void setup_local_APIC(void)
* SPIV. Soft disable it before doing further initialization.
*/
value = apic_read(APIC_SPIV);
+ /*
+ * Allows software to temporarily enable or disable the local APIC.
+ * 第8位控制
+ */
value &= ~APIC_SPIV_APIC_ENABLED;
apic_write(APIC_SPIV, value);
@@ -1698,6 +1788,10 @@ static __init void x2apic_enable(void)
__x2apic_enable();
}
+/*
+ * called by:
+ * - arch/x86/kernel/apic/apic.c|1802| <<enable_IR_x2apic>> try_to_enable_x2apic(ir_stat);
+ */
static __init void try_to_enable_x2apic(int remap_mode)
{
if (x2apic_state == X2APIC_DISABLED)
@@ -1749,6 +1843,10 @@ static inline void try_to_enable_x2apic(int remap_mode) { }
static inline void __x2apic_enable(void) { }
#endif /* !CONFIG_X86_X2APIC */
+/*
+ * called by:
+ * - arch/x86/kernel/apic/probe_64.c|32| <<default_setup_apic_routing>> enable_IR_x2apic();
+ */
void __init enable_IR_x2apic(void)
{
unsigned long flags;
@@ -2430,6 +2528,11 @@ int __init apic_bsp_setup(bool upmode)
* This initializes the IO-APIC and APIC hardware if this is
* a UP kernel.
*/
+/*
+ * called by:
+ * - arch/x86/kernel/apic/apic.c|2471| <<up_late_init>> APIC_init_uniprocessor();
+ * - arch/x86/kernel/smpboot.c|1338| <<native_smp_prepare_cpus>> if (APIC_init_uniprocessor())
+ */
int __init APIC_init_uniprocessor(void)
{
if (disable_apic) {
@@ -2791,6 +2894,14 @@ static int __init apic_set_extnmi(char *arg)
if (!arg)
return -EINVAL;
+ /*
+ * bsp: External NMI is delivered only to CPU 0
+ * all: External NMIs are broadcast to all CPUs as a
+ * backup of CPU 0
+ * none: External NMI is masked for all CPUs. This is
+ * useful so that a dump capture kernel won't be
+ * shot down by NMI
+ */
if (!strncmp("all", arg, 3))
apic_extnmi = APIC_EXTNMI_ALL;
else if (!strncmp("none", arg, 4))
diff --git a/arch/x86/kernel/apic/probe_64.c b/arch/x86/kernel/apic/probe_64.c
index c303054b90b5..111ff55e70fc 100644
--- a/arch/x86/kernel/apic/probe_64.c
+++ b/arch/x86/kernel/apic/probe_64.c
@@ -25,12 +25,30 @@
/*
* Check the APIC IDs in bios_cpu_apicid and choose the APIC mode.
*/
+/*
+ * called by:
+ * - arch/x86/kernel/smpboot.c|1358| <<native_smp_prepare_cpus>> default_setup_apic_routing();
+ */
void __init default_setup_apic_routing(void)
{
struct apic **drv;
enable_IR_x2apic();
+ /*
+ * 在以下使用apic_driver():
+ * - arch/x86/kernel/apic/apic_numachip.c|291| <<global>> apic_driver(apic_numachip1);
+ * - arch/x86/kernel/apic/apic_numachip.c|342| <<global>> apic_driver(apic_numachip2);
+ * - arch/x86/kernel/apic/bigsmp_32.c|198| <<global>> apic_driver(apic_bigsmp);
+ * - arch/x86/kernel/apic/probe_32.c|127| <<global>> apic_driver(apic_default);
+ * - arch/x86/kernel/apic/x2apic_cluster.c|283| <<global>> apic_driver(apic_x2apic_cluster);
+ * - arch/x86/kernel/apic/x2apic_phys.c|173| <<global>> apic_driver(apic_x2apic_phys);
+ * - arch/x86/kernel/apic/x2apic_uv_x.c|1759| <<global>> apic_driver(apic_x2apic_uv_x);
+ * - arch/x86/xen/apic.c|228| <<global>> apic_driver(xen_pv_apic);
+ *
+ * [ 0.045605] x2apic enabled
+ * [ 0.046007] Switched APIC routing to physical x2apic.
+ */
for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
if ((*drv)->probe && (*drv)->probe()) {
if (apic != *drv) {
@@ -53,6 +71,10 @@ void apic_send_IPI_self(int vector)
__default_send_IPI_shortcut(APIC_DEST_SELF, vector, APIC_DEST_PHYSICAL);
}
+/*
+ * called by:
+ * - arch/x86/kernel/acpi/boot.c|159| <<acpi_parse_madt>> default_acpi_madt_oem_check(madt->header.oem_id,
+ */
int __init default_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
{
struct apic **drv;
diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
index ec6a004b0f55..08d42d292084 100644
--- a/arch/x86/kernel/apic/x2apic_cluster.c
+++ b/arch/x86/kernel/apic/x2apic_cluster.c
@@ -12,7 +12,26 @@
#include <asm/x2apic.h>
static DEFINE_PER_CPU(u32, x86_cpu_to_logical_apicid);
+/*
+ * 在以下使用cpus_in_cluster:
+ * - arch/x86/kernel/apic/x2apic_cluster.c|64| <<__x2apic_send_IPI_mask>> cpus_in_cluster_ptr = per_cpu(cpus_in_cluster, cpu);
+ * - arch/x86/kernel/apic/x2apic_cluster.c|143| <<init_x2apic_ldr>> cpumask_set_cpu(this_cpu, per_cpu(cpus_in_cluster, this_cpu));
+ * - arch/x86/kernel/apic/x2apic_cluster.c|147| <<init_x2apic_ldr>> cpumask_set_cpu(this_cpu, per_cpu(cpus_in_cluster, cpu));
+ * - arch/x86/kernel/apic/x2apic_cluster.c|148| <<init_x2apic_ldr>> cpumask_set_cpu(cpu, per_cpu(cpus_in_cluster, this_cpu));
+ * - arch/x86/kernel/apic/x2apic_cluster.c|157| <<x2apic_prepare_cpu>> if (!zalloc_cpumask_var(&per_cpu(cpus_in_cluster, cpu), GFP_KERNEL))
+ * - arch/x86/kernel/apic/x2apic_cluster.c|161| <<x2apic_prepare_cpu>> free_cpumask_var(per_cpu(cpus_in_cluster, cpu));
+ * - arch/x86/kernel/apic/x2apic_cluster.c|175| <<x2apic_dead_cpu>> cpumask_clear_cpu(this_cpu, per_cpu(cpus_in_cluster, cpu));
+ * - arch/x86/kernel/apic/x2apic_cluster.c|176| <<x2apic_dead_cpu>> cpumask_clear_cpu(cpu, per_cpu(cpus_in_cluster, this_cpu));
+ * - arch/x86/kernel/apic/x2apic_cluster.c|178| <<x2apic_dead_cpu>> free_cpumask_var(per_cpu(cpus_in_cluster, this_cpu));
+ * - arch/x86/kernel/apic/x2apic_cluster.c|197| <<x2apic_cluster_probe>> cpumask_set_cpu(cpu, per_cpu(cpus_in_cluster, cpu));
+ */
static DEFINE_PER_CPU(cpumask_var_t, cpus_in_cluster);
+/*
+ * 在以下使用ipi_mask:
+ * - arch/x86/kernel/apic/x2apic_cluster.c|55| <<__x2apic_send_IPI_mask>> ipi_mask_ptr = this_cpu_cpumask_var_ptr(ipi_mask);
+ * - arch/x86/kernel/apic/x2apic_cluster.c|160| <<x2apic_prepare_cpu>> if (!zalloc_cpumask_var(&per_cpu(ipi_mask, cpu), GFP_KERNEL)) {
+ * - arch/x86/kernel/apic/x2apic_cluster.c|179| <<x2apic_dead_cpu>> free_cpumask_var(per_cpu(ipi_mask, this_cpu));
+ */
static DEFINE_PER_CPU(cpumask_var_t, ipi_mask);
static int x2apic_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
index b94d35320f85..18a575f62240 100644
--- a/arch/x86/kernel/apic/x2apic_phys.c
+++ b/arch/x86/kernel/apic/x2apic_phys.c
@@ -9,6 +9,14 @@
#include <asm/smp.h>
#include <asm/x2apic.h>
+/*
+ * 在以下使用x2apic_phys:
+ * - arch/x86/kernel/apic/apic.c|1739| <<try_to_enable_x2apic>> x2apic_phys = 1;
+ * - arch/x86/kernel/apic/x2apic_phys.c|18| <<set_x2apic_phys_mode>> x2apic_phys = 1;
+ * - arch/x86/kernel/apic/x2apic_phys.c|37| <<x2apic_acpi_madt_oem_check>> return x2apic_enabled() && (x2apic_phys || x2apic_fadt_phys());
+ * - arch/x86/kernel/apic/x2apic_phys.c|96| <<x2apic_phys_probe>> if (x2apic_mode && (x2apic_phys || x2apic_fadt_phys()))
+ * - arch/x86/kernel/cpu/mshyperv.c|340| <<ms_hyperv_init_platform>> x2apic_phys = 1;
+ */
int x2apic_phys;
static struct apic apic_x2apic_phys;
@@ -82,6 +90,13 @@ static void x2apic_send_IPI_allbutself(int vector)
__x2apic_send_IPI_mask(cpu_online_mask, vector, APIC_DEST_ALLBUT);
}
+/*
+ * kvm会修改为以下:
+ * apic->send_IPI_mask = kvm_send_ipi_mask;
+ * apic->send_IPI_mask_allbutself = kvm_send_ipi_mask_allbutself;
+ * apic->send_IPI_allbutself = kvm_send_ipi_allbutself;
+ * apic->send_IPI_all = kvm_send_ipi_all;
+ */
static void x2apic_send_IPI_all(int vector)
{
__x2apic_send_IPI_mask(cpu_online_mask, vector, APIC_DEST_ALLINC);
@@ -99,6 +114,31 @@ static int x2apic_phys_probe(void)
return apic == &apic_x2apic_phys;
}
+/*
+ * 在以下使用apic->irq_dest_mode:
+ * - arch/x86/kernel/apic/apic_flat_64.c|155| <<global>> .irq_dest_mode = 1,
+ * - arch/x86/kernel/apic/apic_flat_64.c|250| <<global>> .irq_dest_mode = 0,
+ * - arch/x86/kernel/apic/apic_noop.c|122| <<global>> .irq_dest_mode = 1,
+ * - arch/x86/kernel/apic/apic_numachip.c|250| <<global>> .irq_dest_mode = 0,
+ * - arch/x86/kernel/apic/apic_numachip.c|301| <<global>> .irq_dest_mode = 0,
+ * - arch/x86/kernel/apic/bigsmp_32.c|136| <<global>> .irq_dest_mode = 0,
+ * - arch/x86/kernel/apic/probe_32.c|85| <<global>> .irq_dest_mode = 1,
+ * - arch/x86/kernel/apic/x2apic_cluster.c|243| <<global>> .irq_dest_mode = 1,
+ * - arch/x86/kernel/apic/x2apic_phys.c|133| <<global>> .irq_dest_mode = 0,
+ * - arch/x86/kernel/apic/x2apic_uv_x.c|725| <<global>> .irq_dest_mode = 0,
+ * - arch/x86/kernel/apic/io_apic.c|2906| <<mp_setup_entry>> entry->dest_mode = apic->irq_dest_mode;
+ * - arch/x86/kernel/apic/msi.c|38| <<__irq_msi_compose_msg>> ((apic->irq_dest_mode == 0) ?
+ * - arch/x86/platform/uv/uv_irq.c|39| <<uv_program_mmr>> entry->dest_mode = apic->irq_dest_mode;
+ * - drivers/iommu/amd_iommu.c|4125| <<irq_remapping_prepare_irte>> apic->irq_dest_mode, irq_cfg->vector,
+ * - drivers/iommu/amd_iommu.c|4377| <<amd_ir_set_vcpu_affinity>> irte->lo.fields_remap.dm = apic->irq_dest_mode;
+ * - drivers/iommu/intel_irq_remapping.c|1067| <<prepare_irte>> irte->dst_mode = apic->irq_dest_mode;
+ *
+ * kvm会修改为以下:
+ * apic->send_IPI_mask = kvm_send_ipi_mask;
+ * apic->send_IPI_mask_allbutself = kvm_send_ipi_mask_allbutself;
+ * apic->send_IPI_allbutself = kvm_send_ipi_allbutself;
+ * apic->send_IPI_all = kvm_send_ipi_all;
+ */
static struct apic apic_x2apic_phys __ro_after_init = {
.name = "physical x2apic",
diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index d41230f9c67f..7d6c7f6fb3b2 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -449,6 +449,12 @@ static void __init sev_map_percpu_data(void)
#ifdef CONFIG_SMP
#define KVM_IPI_CLUSTER_SIZE (2 * BITS_PER_LONG)
+/*
+ * called by:
+ * - arch/x86/kernel/kvm.c|505| <<kvm_send_ipi_mask>> __send_ipi_mask(mask, vector);
+ * - arch/x86/kernel/kvm.c|517| <<kvm_send_ipi_mask_allbutself>> __send_ipi_mask(local_mask, vector);
+ * - arch/x86/kernel/kvm.c|527| <<kvm_send_ipi_all>> __send_ipi_mask(cpu_online_mask, vector);
+ */
static void __send_ipi_mask(const struct cpumask *mask, int vector)
{
unsigned long flags;
@@ -590,16 +596,33 @@ static void __init kvm_apf_trap_init(void)
update_intr_gate(X86_TRAP_PF, async_page_fault);
}
+/*
+ * 在以下使用__pv_tlb_mask:
+ * - arch/x86/kernel/kvm.c|611| <<kvm_flush_tlb_others>> struct cpumask *flushmask = this_cpu_cpumask_var_ptr(__pv_tlb_mask);
+ * - arch/x86/kernel/kvm.c|764| <<kvm_setup_pv_tlb_flush>> zalloc_cpumask_var_node(per_cpu_ptr(&__pv_tlb_mask, cpu),
+ */
static DEFINE_PER_CPU(cpumask_var_t, __pv_tlb_mask);
+/*
+ * 在以下使用kvm_flush_tlb_others():
+ * - arch/x86/kernel/kvm.c|643| <<kvm_guest_init>> pv_mmu_ops.flush_tlb_others = kvm_flush_tlb_others;
+ */
static void kvm_flush_tlb_others(const struct cpumask *cpumask,
const struct flush_tlb_info *info)
{
u8 state;
int cpu;
struct kvm_steal_time *src;
+ /*
+ * 在以下使用__pv_tlb_mask:
+ * - arch/x86/kernel/kvm.c|611| <<kvm_flush_tlb_others>> struct cpumask *flushmask = this_cpu_cpumask_var_ptr(__pv_tlb_mask);
+ * - arch/x86/kernel/kvm.c|764| <<kvm_setup_pv_tlb_flush>> zalloc_cpumask_var_node(per_cpu_ptr(&__pv_tlb_mask, cpu),
+ */
struct cpumask *flushmask = this_cpu_cpumask_var_ptr(__pv_tlb_mask);
+ /*
+ * 从cpumask copy到 flushmask
+ */
cpumask_copy(flushmask, cpumask);
/*
* We have to call flush only on online vCPUs. And
@@ -608,6 +631,19 @@ static void kvm_flush_tlb_others(const struct cpumask *cpumask,
for_each_cpu(cpu, flushmask) {
src = &per_cpu(steal_time, cpu);
state = READ_ONCE(src->preempted);
+ /*
+ * 在以下使用KVM_VCPU_PREEMPTED:
+ * - arch/x86/kernel/kvm.c|621| <<kvm_flush_tlb_others>> if ((state & KVM_VCPU_PREEMPTED)) {
+ * - arch/x86/kernel/kvm.c|819| <<__kvm_vcpu_is_preempted>> return !!(src->preempted & KVM_VCPU_PREEMPTED);
+ * - arch/x86/kvm/x86.c|3345| <<kvm_steal_time_set_preempted>> st->preempted = vcpu->arch.st.preempted = KVM_VCPU_PREEMPTED;
+ *
+ * 在以下使用KVM_VCPU_FLUSH_TLB:
+ * - arch/x86/kernel/kvm.c|623| <<kvm_flush_tlb_others>> state | KVM_VCPU_FLUSH_TLB))
+ * - arch/x86/kvm/x86.c|2457| <<record_steal_time>> if (xchg(&st->preempted, 0) & KVM_VCPU_FLUSH_TLB)
+ *
+ * #define KVM_VCPU_PREEMPTED (1 << 0)
+ * #define KVM_VCPU_FLUSH_TLB (1 << 1)
+ */
if ((state & KVM_VCPU_PREEMPTED)) {
if (try_cmpxchg(&src->preempted, &state,
state | KVM_VCPU_FLUSH_TLB))
diff --git a/arch/x86/kvm/debugfs.c b/arch/x86/kvm/debugfs.c
index c19c7ede9bd6..ce5e49932d75 100644
--- a/arch/x86/kvm/debugfs.c
+++ b/arch/x86/kvm/debugfs.c
@@ -10,6 +10,10 @@
#include <linux/kvm_host.h>
#include <linux/debugfs.h>
+/*
+ * called by:
+ * - virt/kvm/kvm_main.c|2787| <<kvm_create_vcpu_debugfs>> if (!kvm_arch_has_vcpu_debugfs())
+ */
bool kvm_arch_has_vcpu_debugfs(void)
{
return true;
@@ -18,6 +22,13 @@ bool kvm_arch_has_vcpu_debugfs(void)
static int vcpu_get_tsc_offset(void *data, u64 *val)
{
struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data;
+ /*
+ * struct kvm_vcpu *vcpu:
+ * -> struct kvm_vcpu_arch arch;
+ * -> struct kvm_lapic *apic;
+ * -> struct kvm_timer lapic_timer;
+ * -> u64 tsc_offset;
+ */
*val = vcpu->arch.tsc_offset;
return 0;
}
@@ -41,6 +52,10 @@ static int vcpu_get_tsc_scaling_frac_bits(void *data, u64 *val)
DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_scaling_frac_fops, vcpu_get_tsc_scaling_frac_bits, NULL, "%llu\n");
+/*
+ * called by:
+ * - virt/kvm/kvm_main.c|2787| <<kvm_create_vcpu_debugfs>> ret = kvm_arch_create_vcpu_debugfs(vcpu);
+ */
int kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu)
{
struct dentry *ret;
diff --git a/arch/x86/kvm/ioapic.c b/arch/x86/kvm/ioapic.c
index bac2ec9b4443..168171a72b82 100644
--- a/arch/x86/kvm/ioapic.c
+++ b/arch/x86/kvm/ioapic.c
@@ -335,6 +335,13 @@ static void ioapic_write_indirect(struct kvm_ioapic *ioapic, u32 val)
}
}
+/*
+ * called by:
+ * - arch/x86/kvm/ioapic.c|222| <<ioapic_set_irq>> ret = ioapic_service(ioapic, irq, line_status);
+ * - arch/x86/kvm/ioapic.c|332| <<ioapic_write_indirect>> ioapic_service(ioapic, index, false);
+ * - arch/x86/kvm/ioapic.c|427| <<kvm_ioapic_eoi_inject_work>> ioapic_service(ioapic, i, false);
+ * - arch/x86/kvm/ioapic.c|485| <<__kvm_ioapic_update_eoi>> ioapic_service(ioapic, i, false);
+ */
static int ioapic_service(struct kvm_ioapic *ioapic, int irq, bool line_status)
{
union kvm_ioapic_redirect_entry *entry = &ioapic->redirtbl[irq];
@@ -364,6 +371,15 @@ static int ioapic_service(struct kvm_ioapic *ioapic, int irq, bool line_status)
if (irqe.trig_mode == IOAPIC_EDGE_TRIG)
ioapic->irr_delivered |= 1 << irq;
+ /*
+ * called by:
+ * - arch/x86/kvm/hyperv.c|331| <<synic_set_irq>> ret = kvm_irq_delivery_to_apic(vcpu->kvm, vcpu->arch.apic, &irq, NULL);
+ * - arch/x86/kvm/ioapic.c|375| <<ioapic_service>> ret = kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe,
+ * - arch/x86/kvm/ioapic.c|379| <<ioapic_service>> ret = kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe, NULL);
+ * - arch/x86/kvm/irq_comm.c|192| <<kvm_set_msi>> return kvm_irq_delivery_to_apic(kvm, NULL, &irq, NULL);
+ * - arch/x86/kvm/lapic.c|1249| <<apic_send_ipi>> kvm_irq_delivery_to_apic(apic->vcpu->kvm, apic, &irq, NULL);
+ * - arch/x86/kvm/x86.c|7133| <<kvm_pv_kick_cpu_op>> kvm_irq_delivery_to_apic(kvm, NULL, &lapic_irq, NULL);
+ */
if (irq == RTC_GSI && line_status) {
/*
* pending_eoi cannot ever become negative (see
@@ -384,6 +400,10 @@ static int ioapic_service(struct kvm_ioapic *ioapic, int irq, bool line_status)
return ret;
}
+/*
+ * called by:
+ * - arch/x86/kvm/irq_comm.c|54| <<kvm_set_ioapic_irq>> return kvm_ioapic_set_irq(ioapic, e->irqchip.pin, irq_source_id, level,
+ */
int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int irq_source_id,
int level, bool line_status)
{
@@ -411,6 +431,10 @@ void kvm_ioapic_clear_all(struct kvm_ioapic *ioapic, int irq_source_id)
spin_unlock(&ioapic->lock);
}
+/*
+ * 在以下使用kvm_ioapic_eoi_inject_work:
+ * - arch/x86/kvm/ioapic.c|632| <<kvm_ioapic_init>> INIT_DELAYED_WORK(&ioapic->eoi_inject, kvm_ioapic_eoi_inject_work);
+ */
static void kvm_ioapic_eoi_inject_work(struct work_struct *work)
{
int i;
@@ -661,6 +685,10 @@ void kvm_ioapic_destroy(struct kvm *kvm)
kfree(ioapic);
}
+/*
+ * 处理KVM_IRQCHIP_IOAPIC:
+ * - arch/x86/kvm/x86.c|4407| <<kvm_vm_ioctl_get_irqchip>> kvm_get_ioapic(kvm, &chip->chip.ioapic);
+ */
void kvm_get_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state)
{
struct kvm_ioapic *ioapic = kvm->arch.vioapic;
@@ -671,6 +699,10 @@ void kvm_get_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state)
spin_unlock(&ioapic->lock);
}
+/*
+ * 处理KVM_IRQCHIP_IOAPIC:
+ * - arch/x86/kvm/x86.c|4436| <<kvm_vm_ioctl_set_irqchip>> kvm_set_ioapic(kvm, &chip->chip.ioapic);
+ */
void kvm_set_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state)
{
struct kvm_ioapic *ioapic = kvm->arch.vioapic;
diff --git a/arch/x86/kvm/irq.c b/arch/x86/kvm/irq.c
index faa264822cee..289cd28191bb 100644
--- a/arch/x86/kvm/irq.c
+++ b/arch/x86/kvm/irq.c
@@ -31,6 +31,11 @@
* check if there are pending timer events
* to be processed.
*/
+/*
+ * called by:
+ * - arch/x86/kvm/x86.c|8088| <<vcpu_run>> if (kvm_cpu_has_pending_timer(vcpu))
+ * - virt/kvm/kvm_main.c|2444| <<kvm_vcpu_check_block>> if (kvm_cpu_has_pending_timer(vcpu))
+ */
int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu)
{
if (lapic_in_kernel(vcpu))
@@ -100,6 +105,13 @@ int kvm_cpu_has_injectable_intr(struct kvm_vcpu *v)
* check if there is pending interrupt without
* intack.
*/
+/*
+ * called by:
+ * - arch/x86/kvm/irq.c|129| <<global>> EXPORT_SYMBOL_GPL(kvm_cpu_has_interrupt);
+ * - arch/x86/kvm/vmx/nested.c|3481| <<vmx_check_nested_events>> if (kvm_cpu_has_interrupt(vcpu) && nested_exit_on_intr(vcpu)) {
+ * - arch/x86/kvm/x86.c|3462| <<kvm_vcpu_ready_for_interrupt_injection>> !kvm_cpu_has_interrupt(vcpu) &&
+ * - arch/x86/kvm/x86.c|9724| <<kvm_vcpu_has_events>> (kvm_cpu_has_interrupt(vcpu) ||
+ */
int kvm_cpu_has_interrupt(struct kvm_vcpu *v)
{
/*
@@ -144,6 +156,11 @@ static int kvm_cpu_get_extint(struct kvm_vcpu *v)
/*
* Read pending interrupt vector and intack.
*/
+/*
+ * called by:
+ * - arch/x86/kvm/vmx/nested.c|4063| <<nested_vmx_vmexit>> int irq = kvm_cpu_get_interrupt(vcpu);
+ * - arch/x86/kvm/x86.c|7397| <<inject_pending_event>> kvm_queue_interrupt(vcpu, kvm_cpu_get_interrupt(vcpu),
+ */
int kvm_cpu_get_interrupt(struct kvm_vcpu *v)
{
int vector;
@@ -160,6 +177,17 @@ int kvm_cpu_get_interrupt(struct kvm_vcpu *v)
}
EXPORT_SYMBOL_GPL(kvm_cpu_get_interrupt);
+/*
+ * kvm_inject_pending_timer_irqs
+ * kvm_vcpu_ioctl
+ * do_vfs_ioctl
+ * sys_ioctl
+ * do_syscall_64
+ * entry_SYSCALL_64_after_hwframe
+ *
+ * called by(处理kvm_cpu_has_pending_timer()):
+ * - arch/x86/kvm/x86.c|8074| <<vcpu_run>> kvm_inject_pending_timer_irqs(vcpu);
+ */
void kvm_inject_pending_timer_irqs(struct kvm_vcpu *vcpu)
{
if (lapic_in_kernel(vcpu))
@@ -167,6 +195,10 @@ void kvm_inject_pending_timer_irqs(struct kvm_vcpu *vcpu)
}
EXPORT_SYMBOL_GPL(kvm_inject_pending_timer_irqs);
+/*
+ * called by(处理KVM_REQ_MIGRATE_TIMER):
+ * - arch/x86/kvm/x86.c|7779| <<vcpu_enter_guest>> __kvm_migrate_timers(vcpu);
+ */
void __kvm_migrate_timers(struct kvm_vcpu *vcpu)
{
__kvm_migrate_apic_timer(vcpu);
diff --git a/arch/x86/kvm/irq_comm.c b/arch/x86/kvm/irq_comm.c
index 4d000aea05e0..79e7ae956489 100644
--- a/arch/x86/kvm/irq_comm.c
+++ b/arch/x86/kvm/irq_comm.c
@@ -55,6 +55,15 @@ static int kvm_set_ioapic_irq(struct kvm_kernel_irq_routing_entry *e,
line_status);
}
+/*
+ * called by:
+ * - arch/x86/kvm/hyperv.c|331| <<synic_set_irq>> ret = kvm_irq_delivery_to_apic(vcpu->kvm, vcpu->arch.apic, &irq, NULL);
+ * - arch/x86/kvm/ioapic.c|375| <<ioapic_service>> ret = kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe,
+ * - arch/x86/kvm/ioapic.c|379| <<ioapic_service>> ret = kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe, NULL);
+ * - arch/x86/kvm/irq_comm.c|192| <<kvm_set_msi>> return kvm_irq_delivery_to_apic(kvm, NULL, &irq, NULL);
+ * - arch/x86/kvm/lapic.c|1249| <<apic_send_ipi>> kvm_irq_delivery_to_apic(apic->vcpu->kvm, apic, &irq, NULL);
+ * - arch/x86/kvm/x86.c|7133| <<kvm_pv_kick_cpu_op>> kvm_irq_delivery_to_apic(kvm, NULL, &lapic_irq, NULL);
+ */
int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
struct kvm_lapic_irq *irq, struct dest_map *dest_map)
{
@@ -112,6 +121,41 @@ int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
return r;
}
+/*
+ * # sudo /usr/share/bcc/tools/trace -t -C 'kvm_set_msi_irq'
+ * TIME CPU PID TID COMM FUNC
+ * 1.409018 4 23372 23372 vhost-23357 kvm_set_msi_irq
+ * 1.430408 4 23372 23372 vhost-23357 kvm_set_msi_irq
+ * 1.557921 1 23372 23372 vhost-23357 kvm_set_msi_irq
+ * 1.594878 5 23372 23372 vhost-23357 kvm_set_msi_irq
+ * 1.624964 4 23372 23372 vhost-23357 kvm_set_msi_irq
+ *
+ * 9.586209 17 23357 23357 qemu-system-x86 kvm_set_msi_irq
+ * 9.586283 17 23357 23357 qemu-system-x86 kvm_set_msi_irq
+ * 9.586399 5 23372 23372 vhost-23357 kvm_set_msi_irq
+ * 9.586470 17 23357 23357 qemu-system-x86 kvm_set_msi_irq
+ * 9.586482 17 23357 23357 qemu-system-x86 kvm_set_msi_irq
+ *
+ * kvm_set_msi_irq
+ * irqfd_wakeup
+ * __wake_up_common
+ * __wake_up_locked_key
+ * eventfd_signal
+ * vhost_signal
+ * vhost_add_used_and_signal_n
+ * handle_rx
+ * handle_rx_net
+ * vhost_worker
+ * kthread
+ * ret_from_fork
+ *
+ * called by:
+ * - arch/x86/kvm/irq_comm.c|155| <<kvm_set_msi>> kvm_set_msi_irq(kvm, e, &irq);
+ * - arch/x86/kvm/irq_comm.c|187| <<kvm_arch_set_irq_inatomic>> kvm_set_msi_irq(kvm, e, &irq);
+ * - arch/x86/kvm/irq_comm.c|428| <<kvm_scan_ioapic_routes>> kvm_set_msi_irq(vcpu->kvm, entry, &irq);
+ * - arch/x86/kvm/svm.c|5309| <<get_pi_vcpu_info>> kvm_set_msi_irq(kvm, e, &irq);
+ * - arch/x86/kvm/vmx/vmx.c|7543| <<vmx_update_pi_irte>> kvm_set_msi_irq(kvm, e, &irq);
+ */
void kvm_set_msi_irq(struct kvm *kvm, struct kvm_kernel_irq_routing_entry *e,
struct kvm_lapic_irq *irq)
{
@@ -141,6 +185,11 @@ static inline bool kvm_msi_route_invalid(struct kvm *kvm,
return kvm->arch.x2apic_format && (e->msi.address_hi & 0xff);
}
+/*
+ * called by
+ * - arch/x86/kvm/irq_comm.c|359| <<kvm_set_routing_entry>> e->set = kvm_set_msi;
+ * - virt/kvm/irqchip.c|78| <<kvm_send_userspace_msi>> return kvm_set_msi(&route, kvm, KVM_USERSPACE_IRQ_SOURCE_ID, 1, false);
+ */
int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e,
struct kvm *kvm, int irq_source_id, int level, bool line_status)
{
@@ -168,6 +217,11 @@ static int kvm_hv_set_sint(struct kvm_kernel_irq_routing_entry *e,
return kvm_hv_synic_set_irq(kvm, e->hv_sint.vcpu, e->hv_sint.sint);
}
+/*
+ * called by:
+ * - virt/kvm/eventfd.c|178| <<kvm_arch_set_irq_inatomic>> int __attribute__((weak)) kvm_arch_set_irq_inatomic(
+ * - virt/kvm/eventfd.c|212| <<irqfd_wakeup>> if (kvm_arch_set_irq_inatomic(&irq, kvm,
+ */
int kvm_arch_set_irq_inatomic(struct kvm_kernel_irq_routing_entry *e,
struct kvm *kvm, int irq_source_id, int level,
bool line_status)
@@ -197,6 +251,10 @@ int kvm_arch_set_irq_inatomic(struct kvm_kernel_irq_routing_entry *e,
return -EWOULDBLOCK;
}
+/*
+ * called by:
+ * - arch/x86/kvm/i8254.c|660| <<kvm_create_pit>> pit->irq_source_id = kvm_request_irq_source_id(kvm);
+ */
int kvm_request_irq_source_id(struct kvm *kvm)
{
unsigned long *bitmap = &kvm->arch.irq_sources_bitmap;
@@ -279,6 +337,10 @@ bool kvm_arch_can_set_irq_routing(struct kvm *kvm)
return irqchip_in_kernel(kvm);
}
+/*
+ * called by:
+ * - virt/kvm/irqchip.c|180| <<setup_routing_entry>> r = kvm_set_routing_entry(kvm, e, ue);
+ */
int kvm_set_routing_entry(struct kvm *kvm,
struct kvm_kernel_irq_routing_entry *e,
const struct kvm_irq_routing_entry *ue)
diff --git a/arch/x86/kvm/kvm_cache_regs.h b/arch/x86/kvm/kvm_cache_regs.h
index 4fa133a69df7..21a49848b9fd 100644