-
Notifications
You must be signed in to change notification settings - Fork 4
/
kvm-for-linux-v5.2-rc4.patch
1302 lines (1203 loc) · 46.8 KB
/
kvm-for-linux-v5.2-rc4.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 2db9f5e0905b191322cccbd399b6d60212a11b2c Mon Sep 17 00:00:00 2001
From: Dongli Zhang <[email protected]>
Date: Mon, 24 Jun 2019 16:11:51 +0800
Subject: [PATCH 1/1] kvm for linux v5.2-rc4
Signed-off-by: Dongli Zhang <[email protected]>
---
arch/x86/include/asm/kvm_host.h | 6 ++
arch/x86/include/asm/msr-index.h | 7 ++
arch/x86/kernel/crash.c | 12 +++
arch/x86/kvm/cpuid.c | 5 ++
arch/x86/kvm/cpuid.h | 9 ++
arch/x86/kvm/i8254.c | 174 +++++++++++++++++++++++++++++++++++++++
arch/x86/kvm/i8254.h | 11 +++
arch/x86/kvm/irq.c | 4 +
arch/x86/kvm/irq_comm.c | 4 +
arch/x86/kvm/lapic.c | 27 ++++++
arch/x86/kvm/mmu.c | 9 ++
arch/x86/kvm/vmx/vmcs12.h | 1 +
arch/x86/kvm/vmx/vmx.c | 75 +++++++++++++++++
arch/x86/kvm/x86.c | 74 +++++++++++++++++
virt/kvm/async_pf.c | 13 +++
virt/kvm/eventfd.c | 4 +
virt/kvm/irqchip.c | 26 ++++++
virt/kvm/kvm_main.c | 103 +++++++++++++++++++++++
18 files changed, 564 insertions(+)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 450d69a..bad74a9 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1062,6 +1062,12 @@ struct kvm_x86_ops {
*/
void (*tlb_flush_gva)(struct kvm_vcpu *vcpu, gva_t addr);
+ /*
+ * called by:
+ * - arch/x86/kvm/x86.c|7996| <<vcpu_enter_guest>> kvm_x86_ops->run(vcpu);
+ *
+ * vmx: vmx_vcpu_run()
+ */
void (*run)(struct kvm_vcpu *vcpu);
int (*handle_exit)(struct kvm_vcpu *vcpu);
void (*skip_emulated_instruction)(struct kvm_vcpu *vcpu);
diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
index 979ef97..4531c70 100644
--- a/arch/x86/include/asm/msr-index.h
+++ b/arch/x86/include/asm/msr-index.h
@@ -536,6 +536,13 @@
#define FEATURE_CONTROL_LMCE (1<<20)
#define MSR_IA32_APICBASE 0x0000001b
+/*
+ * used by:
+ * - arch/x86/kvm/lapic.c|2137| <<kvm_lapic_set_base>> value |= MSR_IA32_APICBASE_BSP;
+ * - arch/x86/kvm/lapic.c|2228| <<kvm_lapic_reset>> vcpu->arch.apic_base | MSR_IA32_APICBASE_BSP);
+ * - arch/x86/kvm/vmx/vmx.c|4190| <<vmx_vcpu_reset>> apic_base_msr.data |= MSR_IA32_APICBASE_BSP;
+ * - arch/x86/kvm/x86.c|9199| <<kvm_vcpu_is_bsp>> return (vcpu->arch.apic_base & MSR_IA32_APICBASE_BSP) != 0;
+ */
#define MSR_IA32_APICBASE_BSP (1<<8)
#define MSR_IA32_APICBASE_ENABLE (1<<11)
#define MSR_IA32_APICBASE_BASE (0xfffff<<12)
diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
index 576b2e1..bbd3702 100644
--- a/arch/x86/kernel/crash.c
+++ b/arch/x86/kernel/crash.c
@@ -54,15 +54,27 @@ struct crash_memmap_data {
*
* protected by rcu.
*/
+/*
+ * called by:
+ * - arch/x86/kernel/crash.c|66| <<cpu_crash_vmclear_loaded_vmcss>> do_vmclear_operation = rcu_dereference(crash_vmclear_loaded_vmcss);
+ * - arch/x86/kvm/vmx/vmx.c|7748| <<vmx_exit>> RCU_INIT_POINTER(crash_vmclear_loaded_vmcss, NULL);
+ * - arch/x86/kvm/vmx/vmx.c|7834| <<vmx_init>> rcu_assign_pointer(crash_vmclear_loaded_vmcss,
+ */
crash_vmclear_fn __rcu *crash_vmclear_loaded_vmcss = NULL;
EXPORT_SYMBOL_GPL(crash_vmclear_loaded_vmcss);
unsigned long crash_zero_bytes;
+/*
+ * called by:
+ * - arch/x86/kernel/crash.c|89| <<kdump_nmi_callback>> cpu_crash_vmclear_loaded_vmcss();
+ * - arch/x86/kernel/crash.c|156| <<native_machine_crash_shutdown>> cpu_crash_vmclear_loaded_vmcss();
+ */
static inline void cpu_crash_vmclear_loaded_vmcss(void)
{
crash_vmclear_fn *do_vmclear_operation = NULL;
rcu_read_lock();
+ /* 在vmx_init()中设置为 crash_vmclear_local_loaded_vmcss() */
do_vmclear_operation = rcu_dereference(crash_vmclear_loaded_vmcss);
if (do_vmclear_operation)
do_vmclear_operation();
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index e18a9f9..e2af392 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -956,6 +956,11 @@ bool kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx,
}
EXPORT_SYMBOL_GPL(kvm_cpuid);
+/*
+ * called by:
+ * - arch/x86/kvm/svm.c|3904| <<cpuid_interception>> return kvm_emulate_cpuid(&svm->vcpu);
+ * - arch/x86/kvm/vmx/vmx.c|4832| <<handle_cpuid>> return kvm_emulate_cpuid(vcpu);
+ */
int kvm_emulate_cpuid(struct kvm_vcpu *vcpu)
{
u32 eax, ebx, ecx, edx;
diff --git a/arch/x86/kvm/cpuid.h b/arch/x86/kvm/cpuid.h
index 9a327d5..a4a71cd 100644
--- a/arch/x86/kvm/cpuid.h
+++ b/arch/x86/kvm/cpuid.h
@@ -156,11 +156,20 @@ static inline int guest_cpuid_stepping(struct kvm_vcpu *vcpu)
return x86_stepping(best->eax);
}
+/*
+ * called by:
+ * - arch/x86/kvm/x86.c|2695| <<kvm_set_msr_common>> !supports_cpuid_fault(vcpu)))
+ */
static inline bool supports_cpuid_fault(struct kvm_vcpu *vcpu)
{
return vcpu->arch.msr_platform_info & MSR_PLATFORM_INFO_CPUID_FAULT;
}
+/*
+ * called by:
+ * - arch/x86/kvm/cpuid.c|963| <<kvm_emulate_cpuid>> if (cpuid_fault_enabled(vcpu) && !kvm_require_cpl(vcpu, 0))
+ * - arch/x86/kvm/x86.c|2688| <<kvm_set_msr_common>> cpuid_fault_enabled(vcpu)))
+ */
static inline bool cpuid_fault_enabled(struct kvm_vcpu *vcpu)
{
return vcpu->arch.msr_misc_features_enables &
diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c
index 4a6dc54..b08614b 100644
--- a/arch/x86/kvm/i8254.c
+++ b/arch/x86/kvm/i8254.c
@@ -40,6 +40,24 @@
#include "i8254.h"
#include "x86.h"
+/*
+ * https://wiki.osdev.org/Programmable_Interval_Timer
+ *
+ * 在driver中设置periodic的例子:
+ * static int pit_set_periodic(struct clock_event_device *evt)
+ * {
+ * raw_spin_lock(&i8253_lock);
+ *
+ * // binary, mode 2, LSB/MSB, ch 0
+ * outb_p(0x34, PIT_MODE);
+ * outb_p(PIT_LATCH & 0xff, PIT_CH0); // LSB
+ * outb_p(PIT_LATCH >> 8, PIT_CH0); // MSB
+ *
+ * raw_spin_unlock(&i8253_lock);
+ * return 0;
+ * }
+ */
+
#ifndef CONFIG_X86_64
#define mod_64(x, y) ((x) - (y) * div64_u64(x, y))
#else
@@ -51,6 +69,25 @@
#define RW_STATE_WORD0 3
#define RW_STATE_WORD1 4
+/*
+ * static int pit_set_periodic(struct clock_event_device *evt)
+ * {
+ * raw_spin_lock(&i8253_lock);
+ *
+ * // binary, mode 2, LSB/MSB, ch 0
+ * outb_p(0x34, PIT_MODE);
+ * outb_p(PIT_LATCH & 0xff, PIT_CH0); // LSB
+ * outb_p(PIT_LATCH >> 8, PIT_CH0); // MSB
+ *
+ * raw_spin_unlock(&i8253_lock);
+ * return 0;
+ * }
+ */
+
+/*
+ * called by:
+ * - arch/x86/kvm/i8254.c|585| <<speaker_ioport_write>> pit_set_gate(pit, 2, val & 1);
+ */
static void pit_set_gate(struct kvm_pit *pit, int channel, u32 val)
{
struct kvm_kpit_channel_state *c = &pit->pit_state.channels[channel];
@@ -79,6 +116,10 @@ static int pit_get_gate(struct kvm_pit *pit, int channel)
return pit->pit_state.channels[channel].gate;
}
+/*
+ * called by:
+ * - arch/x86/kvm/i8254.c|123| <<kpit_elapsed>> return __kpit_elapsed(pit);
+ */
static s64 __kpit_elapsed(struct kvm_pit *pit)
{
s64 elapsed;
@@ -103,6 +144,11 @@ static s64 __kpit_elapsed(struct kvm_pit *pit)
return elapsed;
}
+/*
+ * called by:
+ * - arch/x86/kvm/i8254.c|133| <<pit_get_count>> t = kpit_elapsed(pit, c, channel);
+ * - arch/x86/kvm/i8254.c|160| <<pit_get_out>> t = kpit_elapsed(pit, c, channel);
+ */
static s64 kpit_elapsed(struct kvm_pit *pit, struct kvm_kpit_channel_state *c,
int channel)
{
@@ -112,6 +158,14 @@ static s64 kpit_elapsed(struct kvm_pit *pit, struct kvm_kpit_channel_state *c,
return ktime_to_ns(ktime_sub(ktime_get(), c->count_load_time));
}
+/*
+ * called by:
+ * - arch/x86/kvm/i8254.c|191| <<pit_latch_count>> c->latched_count = pit_get_count(pit, channel);
+ * - arch/x86/kvm/i8254.c|605| <<pit_ioport_read>> count = pit_get_count(pit, addr);
+ * - arch/x86/kvm/i8254.c|609| <<pit_ioport_read>> count = pit_get_count(pit, addr);
+ * - arch/x86/kvm/i8254.c|613| <<pit_ioport_read>> count = pit_get_count(pit, addr);
+ * - arch/x86/kvm/i8254.c|618| <<pit_ioport_read>> count = pit_get_count(pit, addr);
+ */
static int pit_get_count(struct kvm_pit *pit, int channel)
{
struct kvm_kpit_channel_state *c = &pit->pit_state.channels[channel];
@@ -139,6 +193,11 @@ static int pit_get_count(struct kvm_pit *pit, int channel)
return counter;
}
+/*
+ * called by:
+ * - arch/x86/kvm/i8254.c|202| <<pit_latch_status>> c->status = ((pit_get_out(pit, channel) << 7) |
+ * - arch/x86/kvm/i8254.c|666| <<speaker_ioport_read>> (pit_get_out(pit, 2) << 5) | (refresh_clock << 4));
+ */
static int pit_get_out(struct kvm_pit *pit, int channel)
{
struct kvm_kpit_channel_state *c = &pit->pit_state.channels[channel];
@@ -171,6 +230,11 @@ static int pit_get_out(struct kvm_pit *pit, int channel)
return out;
}
+/*
+ * called by:
+ * - arch/x86/kvm/i8254.c|530| <<pit_ioport_write>> pit_latch_count(pit, channel);
+ * - arch/x86/kvm/i8254.c|540| <<pit_ioport_write>> pit_latch_count(pit, channel);
+ */
static void pit_latch_count(struct kvm_pit *pit, int channel)
{
struct kvm_kpit_channel_state *c = &pit->pit_state.channels[channel];
@@ -181,6 +245,10 @@ static void pit_latch_count(struct kvm_pit *pit, int channel)
}
}
+/*
+ * called by:
+ * - arch/x86/kvm/i8254.c|532| <<pit_ioport_write>> pit_latch_status(pit, channel);
+ */
static void pit_latch_status(struct kvm_pit *pit, int channel)
{
struct kvm_kpit_channel_state *c = &pit->pit_state.channels[channel];
@@ -215,6 +283,10 @@ static void kvm_pit_ack_irq(struct kvm_irq_ack_notifier *kian)
kthread_queue_work(pit->worker, &pit->expired);
}
+/*
+ * called by:
+ * - arch/x86/kvm/irq.c|161| <<__kvm_migrate_timers>> __kvm_migrate_pit_timer(vcpu);
+ */
void __kvm_migrate_pit_timer(struct kvm_vcpu *vcpu)
{
struct kvm_pit *pit = vcpu->kvm->arch.vpit;
@@ -236,6 +308,17 @@ static void destroy_pit_timer(struct kvm_pit *pit)
kthread_flush_work(&pit->expired);
}
+/*
+ * used by:
+ * - arch/x86/kvm/i8254.c|707| <<kvm_create_pit>> kthread_init_work(&pit->expired, pit_do_work);
+ *
+ * 在以下使用pit->expired:
+ * - arch/x86/kvm/i8254.c|223| <<kvm_pit_ack_irq>> kthread_queue_work(pit->worker, &pit->expired);
+ * - arch/x86/kvm/i8254.c|244| <<destroy_pit_timer>> kthread_flush_work(&pit->expired);
+ * - arch/x86/kvm/i8254.c|287| <<pit_timer_fn>> kthread_queue_work(pt->worker, &pt->expired);
+ * - arch/x86/kvm/i8254.c|344| <<create_pit_timer>> kthread_flush_work(&pit->expired);
+ * - arch/x86/kvm/i8254.c|711| <<kvm_create_pit>> kthread_init_work(&pit->expired, pit_do_work);
+ */
static void pit_do_work(struct kthread_work *work)
{
struct kvm_pit *pit = container_of(work, struct kvm_pit, expired);
@@ -264,6 +347,10 @@ static void pit_do_work(struct kthread_work *work)
kvm_apic_nmi_wd_deliver(vcpu);
}
+/*
+ * called by:
+ * - arch/x86/kvm/i8254.c|781| <<kvm_create_pit>> pit_state->timer.function = pit_timer_fn;
+ */
static enum hrtimer_restart pit_timer_fn(struct hrtimer *data)
{
struct kvm_kpit_state *ps = container_of(data, struct kvm_kpit_state, timer);
@@ -275,18 +362,37 @@ static enum hrtimer_restart pit_timer_fn(struct hrtimer *data)
kthread_queue_work(pt->worker, &pt->expired);
if (ps->is_periodic) {
+ /*
+ * ps->period在以下设置:
+ * - arch/x86/kvm/i8254.c|397| <<create_pit_timer>> ps->period = interval;
+ * - arch/x86/kvm/i8254.c|415| <<create_pit_timer>> ps->period = min_period;
+ */
hrtimer_add_expires_ns(&ps->timer, ps->period);
return HRTIMER_RESTART;
} else
return HRTIMER_NORESTART;
}
+/*
+ * called by:
+ * - arch/x86/kvm/i8254.c|323| <<kvm_pit_set_reinject>> kvm_pit_reset_reinject(pit);
+ * - arch/x86/kvm/i8254.c|359| <<create_pit_timer>> kvm_pit_reset_reinject(pit);
+ * - arch/x86/kvm/i8254.c|669| <<kvm_pit_reset>> kvm_pit_reset_reinject(pit);
+ * - arch/x86/kvm/i8254.c|677| <<pit_mask_notifer>> kvm_pit_reset_reinject(pit);
+ */
static inline void kvm_pit_reset_reinject(struct kvm_pit *pit)
{
atomic_set(&pit->pit_state.pending, 0);
atomic_set(&pit->pit_state.irq_ack, 1);
}
+/*
+ * called by:
+ * - arch/x86/kvm/i8254.c|744| <<kvm_create_pit>> kvm_pit_set_reinject(pit, true);
+ * - arch/x86/kvm/i8254.c|777| <<kvm_create_pit>> kvm_pit_set_reinject(pit, false);
+ * - arch/x86/kvm/i8254.c|795| <<kvm_free_pit>> kvm_pit_set_reinject(pit, false);
+ * - arch/x86/kvm/x86.c|4481| <<kvm_vm_ioctl_reinject>> kvm_pit_set_reinject(pit, control->pit_reinject);
+ */
void kvm_pit_set_reinject(struct kvm_pit *pit, bool reinject)
{
struct kvm_kpit_state *ps = &pit->pit_state;
@@ -308,6 +414,11 @@ void kvm_pit_set_reinject(struct kvm_pit *pit, bool reinject)
atomic_set(&ps->reinject, reinject);
}
+/*
+ * called by:
+ * - arch/x86/kvm/i8254.c|381| <<pit_load_count>> create_pit_timer(pit, val, 0);
+ * - arch/x86/kvm/i8254.c|385| <<pit_load_count>> create_pit_timer(pit, val, 1);
+ */
static void create_pit_timer(struct kvm_pit *pit, u32 val, int is_period)
{
struct kvm_kpit_state *ps = &pit->pit_state;
@@ -351,6 +462,15 @@ static void create_pit_timer(struct kvm_pit *pit, u32 val, int is_period)
HRTIMER_MODE_ABS);
}
+/*
+ * called by:
+ * - arch/x86/kvm/i8254.c|404| <<kvm_pit_load_count>> pit_load_count(pit, channel, val);
+ * - arch/x86/kvm/i8254.c|407| <<kvm_pit_load_count>> pit_load_count(pit, channel, val);
+ * - arch/x86/kvm/i8254.c|483| <<pit_ioport_write>> pit_load_count(pit, addr, val);
+ * - arch/x86/kvm/i8254.c|486| <<pit_ioport_write>> pit_load_count(pit, addr, val << 8);
+ * - arch/x86/kvm/i8254.c|493| <<pit_ioport_write>> pit_load_count(pit, addr, s->write_latch | (val << 8));
+ * - arch/x86/kvm/i8254.c|624| <<kvm_pit_reset>> pit_load_count(pit, i, 0);
+ */
static void pit_load_count(struct kvm_pit *pit, int channel, u32 val)
{
struct kvm_kpit_state *ps = &pit->pit_state;
@@ -389,6 +509,11 @@ static void pit_load_count(struct kvm_pit *pit, int channel, u32 val)
}
}
+/*
+ * called by:
+ * - arch/x86/kvm/x86.c|4430| <<kvm_vm_ioctl_set_pit>> kvm_pit_load_count(pit, i, ps->channels[i].count, 0);
+ * - arch/x86/kvm/x86.c|4462| <<kvm_vm_ioctl_set_pit2>> kvm_pit_load_count(pit, i, pit->pit_state.channels[i].count,
+ */
void kvm_pit_load_count(struct kvm_pit *pit, int channel, u32 val,
int hpet_legacy_start)
{
@@ -418,12 +543,20 @@ static inline struct kvm_pit *speaker_to_pit(struct kvm_io_device *dev)
return container_of(dev, struct kvm_pit, speaker_dev);
}
+/*
+ * called by:
+ * - arch/x86/kvm/i8254.c|528| <<pit_ioport_write>> if (!pit_in_range(addr))
+ * - arch/x86/kvm/i8254.c|603| <<pit_ioport_read>> if (!pit_in_range(addr))
+ */
static inline int pit_in_range(gpa_t addr)
{
return ((addr >= KVM_PIT_BASE_ADDRESS) &&
(addr < KVM_PIT_BASE_ADDRESS + KVM_PIT_MEM_LENGTH));
}
+/*
+ * struct kvm_io_device_ops pit_dev_ops.write = pit_ioport_write()
+ */
static int pit_ioport_write(struct kvm_vcpu *vcpu,
struct kvm_io_device *this,
gpa_t addr, int len, const void *data)
@@ -500,6 +633,9 @@ static int pit_ioport_write(struct kvm_vcpu *vcpu,
return 0;
}
+/*
+ * struct kvm_io_device_ops pit_dev_ops.read = pit_ioport_read()
+ */
static int pit_ioport_read(struct kvm_vcpu *vcpu,
struct kvm_io_device *this,
gpa_t addr, int len, void *data)
@@ -611,6 +747,10 @@ static int speaker_ioport_read(struct kvm_vcpu *vcpu,
return 0;
}
+/*
+ * called by:
+ * - arch/x86/kvm/i8254.c|742| <<kvm_create_pit>> kvm_pit_reset(pit);
+ */
static void kvm_pit_reset(struct kvm_pit *pit)
{
int i;
@@ -627,6 +767,10 @@ static void kvm_pit_reset(struct kvm_pit *pit)
kvm_pit_reset_reinject(pit);
}
+/*
+ * used by:
+ * - arch/x86/kvm/i8254.c|794| <<kvm_create_pit>> pit->mask_notifier.func = pit_mask_notifer;
+ */
static void pit_mask_notifer(struct kvm_irq_mask_notifier *kimn, bool mask)
{
struct kvm_pit *pit = container_of(kimn, struct kvm_pit, mask_notifier);
@@ -635,6 +779,10 @@ static void pit_mask_notifer(struct kvm_irq_mask_notifier *kimn, bool mask)
kvm_pit_reset_reinject(pit);
}
+/*
+ * used by:
+ * - arch/x86/kvm/i8254.c|801| <<kvm_create_pit>> kvm_iodevice_init(&pit->dev, &pit_dev_ops);
+ */
static const struct kvm_io_device_ops pit_dev_ops = {
.read = pit_ioport_read,
.write = pit_ioport_write,
@@ -645,6 +793,12 @@ static const struct kvm_io_device_ops speaker_dev_ops = {
.write = speaker_ioport_write,
};
+/*
+ * called by:
+ * - arch/x86/kvm/x86.c|4738| <<kvm_arch_vm_ioctl>> kvm->arch.vpit = kvm_create_pit(kvm, u.pit_config.flags);
+ *
+ * vm的dev: kvm_vm_fops->kvm_vm_ioctl()-->kvm_arch_vm_ioctl()::KVM_CREATE_PIT(KVM_CREATE_PIT2)
+ */
struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags)
{
struct kvm_pit *pit;
@@ -671,6 +825,14 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags)
if (IS_ERR(pit->worker))
goto fail_kthread;
+ /*
+ * used by:
+ * - arch/x86/kvm/i8254.c|223| <<kvm_pit_ack_irq>> kthread_queue_work(pit->worker, &pit->expired);
+ * - arch/x86/kvm/i8254.c|244| <<destroy_pit_timer>> kthread_flush_work(&pit->expired);
+ * - arch/x86/kvm/i8254.c|287| <<pit_timer_fn>> kthread_queue_work(pt->worker, &pt->expired);
+ * - arch/x86/kvm/i8254.c|344| <<create_pit_timer>> kthread_flush_work(&pit->expired);
+ * - arch/x86/kvm/i8254.c|711| <<kvm_create_pit>> kthread_init_work(&pit->expired, pit_do_work);
+ */
kthread_init_work(&pit->expired, pit_do_work);
pit->kvm = kvm;
@@ -689,6 +851,14 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags)
mutex_lock(&kvm->slots_lock);
kvm_iodevice_init(&pit->dev, &pit_dev_ops);
+ /*
+ * KVM_PIT_BASE_ADDRESS是0x40
+ *
+ * 0x40 Channel 0 data port (read/write)
+ * 0x41 Channel 1 data port (read/write)
+ * 0x42 Channel 2 data port (read/write)
+ * 0x43 Mode/Command register (write only, a read is ignored)
+ */
ret = kvm_io_bus_register_dev(kvm, KVM_PIO_BUS, KVM_PIT_BASE_ADDRESS,
KVM_PIT_MEM_LENGTH, &pit->dev);
if (ret < 0)
@@ -719,6 +889,10 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags)
return NULL;
}
+/*
+ * called by only:
+ * - arch/x86/kvm/x86.c|9375| <<kvm_arch_sync_events>> kvm_free_pit(kvm);
+ */
void kvm_free_pit(struct kvm *kvm)
{
struct kvm_pit *pit = kvm->arch.vpit;
diff --git a/arch/x86/kvm/i8254.h b/arch/x86/kvm/i8254.h
index 394d952..f14af896 100644
--- a/arch/x86/kvm/i8254.h
+++ b/arch/x86/kvm/i8254.h
@@ -19,6 +19,12 @@ struct kvm_kpit_channel_state {
u8 mode;
u8 bcd; /* not supported */
u8 gate; /* timer start */
+ /*
+ * used by:
+ * - arch/x86/kvm/i8254.c|78| <<pit_set_gate>> c->count_load_time = ktime_get();
+ * - arch/x86/kvm/i8254.c|120| <<kpit_elapsed>> return ktime_to_ns(ktime_sub(ktime_get(), c->count_load_time));
+ * - arch/x86/kvm/i8254.c|421| <<pit_load_count>> ps->channels[channel].count_load_time = ktime_get();
+ */
ktime_t count_load_time;
};
@@ -27,6 +33,11 @@ struct kvm_kpit_state {
struct kvm_kpit_channel_state channels[3];
u32 flags;
bool is_periodic;
+ /*
+ * 在以下设置:
+ * - arch/x86/kvm/i8254.c|397| <<create_pit_timer>> ps->period = interval;
+ * - arch/x86/kvm/i8254.c|415| <<create_pit_timer>> ps->period = min_period;
+ */
s64 period; /* unit: ns */
struct hrtimer timer;
u32 speaker_data_on;
diff --git a/arch/x86/kvm/irq.c b/arch/x86/kvm/irq.c
index e330e7d..14cdce0 100644
--- a/arch/x86/kvm/irq.c
+++ b/arch/x86/kvm/irq.c
@@ -155,6 +155,10 @@ void kvm_inject_pending_timer_irqs(struct kvm_vcpu *vcpu)
}
EXPORT_SYMBOL_GPL(kvm_inject_pending_timer_irqs);
+/*
+ * called by:
+ * - arch/x86/kvm/x86.c|7803| <<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 924b3bd..b12ab89 100644
--- a/arch/x86/kvm/irq_comm.c
+++ b/arch/x86/kvm/irq_comm.c
@@ -186,6 +186,10 @@ int kvm_arch_set_irq_inatomic(struct kvm_kernel_irq_routing_entry *e,
return -EWOULDBLOCK;
}
+/*
+ * called only by:
+ * - arch/x86/kvm/i8254.c|708| <<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;
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 4924f83..06d27d5 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -102,7 +102,26 @@ static inline int __apic_test_and_clear_vector(int vec, void *bitmap)
return __test_and_clear_bit(VEC_POS(vec), (bitmap) + REG_POS(vec));
}
+/*
+ * used by:
+ * - arch/x86/kvm/lapic.c|2055| <<kvm_free_lapic>> static_key_slow_dec_deferred(&apic_hw_disabled);
+ * - arch/x86/kvm/lapic.c|2132| <<kvm_lapic_set_base>> static_key_slow_dec_deferred(&apic_hw_disabled);
+ * - arch/x86/kvm/lapic.c|2134| <<kvm_lapic_set_base>> static_key_slow_inc(&apic_hw_disabled.key);
+ * - arch/x86/kvm/lapic.c|2762| <<kvm_lapic_init>> jump_label_rate_limit(&apic_hw_disabled, HZ);
+ * - arch/x86/kvm/lapic.c|2768| <<kvm_lapic_exit>> static_key_deferred_flush(&apic_hw_disabled);
+ * - arch/x86/kvm/lapic.h|170| <<kvm_apic_hw_enabled>> if (static_key_false(&apic_hw_disabled.key))
+ */
struct static_key_deferred apic_hw_disabled __read_mostly;
+/*
+ * used by:
+ * - arch/x86/kvm/lapic.c|256| <<apic_set_spiv>> static_key_slow_dec_deferred(&apic_sw_disabled);
+ * - arch/x86/kvm/lapic.c|258| <<apic_set_spiv>> static_key_slow_inc(&apic_sw_disabled.key);
+ * - arch/x86/kvm/lapic.c|2058| <<kvm_free_lapic>> static_key_slow_dec_deferred(&apic_sw_disabled);
+ * - arch/x86/kvm/lapic.c|2329| <<kvm_create_lapic>> static_key_slow_inc(&apic_sw_disabled.key);
+ * - arch/x86/kvm/lapic.c|2763| <<kvm_lapic_init>> jump_label_rate_limit(&apic_sw_disabled, HZ);
+ * - arch/x86/kvm/lapic.c|2769| <<kvm_lapic_exit>> static_key_deferred_flush(&apic_sw_disabled);
+ * - arch/x86/kvm/lapic.h|179| <<kvm_apic_sw_enabled>> if (static_key_false(&apic_sw_disabled.key))
+ */
struct static_key_deferred apic_sw_disabled __read_mostly;
static inline int apic_enabled(struct kvm_lapic *apic)
@@ -2756,6 +2775,10 @@ void kvm_apic_accept_events(struct kvm_vcpu *vcpu)
}
}
+/*
+ * called by:
+ * - arch/x86/kvm/x86.c|7052| <<kvm_arch_init>> kvm_lapic_init();
+ */
void kvm_lapic_init(void)
{
/* do not patch jump label more than once per second */
@@ -2763,6 +2786,10 @@ void kvm_lapic_init(void)
jump_label_rate_limit(&apic_sw_disabled, HZ);
}
+/*
+ * called by:
+ * - arch/x86/kvm/x86.c|7076| <<kvm_arch_exit>> kvm_lapic_exit();
+ */
void kvm_lapic_exit(void)
{
static_key_deferred_flush(&apic_hw_disabled);
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 1e9ba81..da38b2c 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -452,6 +452,11 @@ static bool check_mmio_spte(struct kvm_vcpu *vcpu, u64 spte)
* - Setting either @accessed_mask or @dirty_mask requires setting both
* - At least one of @accessed_mask or @acc_track_mask must be set
*/
+/*
+ * called by:
+ * - arch/x86/kvm/vmx/vmx.c|5262| <<vmx_enable_tdp>> kvm_mmu_set_mask_ptes(VMX_EPT_READABLE_MASK,
+ * - arch/x86/kvm/x86.c|7046| <<kvm_arch_init>> kvm_mmu_set_mask_ptes(PT_USER_MASK, PT_ACCESSED_MASK,
+ */
void kvm_mmu_set_mask_ptes(u64 user_mask, u64 accessed_mask,
u64 dirty_mask, u64 nx_mask, u64 x_mask, u64 p_mask,
u64 acc_track_mask, u64 me_mask)
@@ -5998,6 +6003,10 @@ static void mmu_destroy_caches(void)
kmem_cache_destroy(mmu_page_header_cache);
}
+/*
+ * called by only:
+ * - arch/x86/kvm/x86.c|7034| <<kvm_arch_init>> r = kvm_mmu_module_init();
+ */
int kvm_mmu_module_init(void)
{
int ret = -ENOMEM;
diff --git a/arch/x86/kvm/vmx/vmcs12.h b/arch/x86/kvm/vmx/vmcs12.h
index 3a74242..350cb9e8 100644
--- a/arch/x86/kvm/vmx/vmcs12.h
+++ b/arch/x86/kvm/vmx/vmcs12.h
@@ -218,6 +218,7 @@ struct __packed vmcs12 {
BUILD_BUG_ON_MSG(offsetof(struct vmcs12, field) != (loc), \
"Offset of " #field " in struct vmcs12 has changed.")
+/* 只被vmx_init()调用 */
static inline void vmx_check_vmcs12_offsets(void)
{
CHECK_OFFSET(hdr, 0);
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index b93e36d..fa83b62 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -67,12 +67,37 @@
MODULE_AUTHOR("Qumranet");
MODULE_LICENSE("GPL");
+/*
+ * 进入的核心函数是vmx_vcpu_run()-->__vmx_vcpu_run()
+ *
+ * vcpu的dev: kvm_vcpu_fops->unlock_ioctl = kvm_vcpu_ioctl()
+ * -> KVM_RUN::kvm_arch_vcpu_ioctl_run()
+ * -> vcpu_run()
+ * -> vcpu_enter_guest()
+ * -> kvm_x86_ops->run = vmx_vcpu_run()
+ * -> arch/x86/kvm/vmx/vmenter.S:__vmx_vcpu_run()
+ * -> arch/x86/kvm/vmx/vmenter.S:vmx_vmenter
+ * -> 调用vmresume或者vmlaunch指令
+ * -> kvm_x86_ops->handle_exit = vmx_handle_exit()
+ * -> kvm_vmx_exit_handlers[exit_reason](vcpu)
+ * -> 比如EXIT_REASON_IO_INSTRUCTION是handle_io()
+ * 比如EXIT_REASON_EPT_MISCONFIG是handle_ept_misconfig()
+ * 比如EXIT_REASON_EPT_VIOLATION是handle_ept_violation()
+ */
+
static const struct x86_cpu_id vmx_cpu_id[] = {
X86_FEATURE_MATCH(X86_FEATURE_VMX),
{}
};
MODULE_DEVICE_TABLE(x86cpu, vmx_cpu_id);
+/*
+ * 不考虑nested vmx的情况下在以下使用:
+ * - arch/x86/kvm/vmx/vmx.c|3436| <<allocate_vpid>> if (!enable_vpid)
+ * - arch/x86/kvm/vmx/vmx.c|3450| <<free_vpid>> if (!enable_vpid || vpid == 0)
+ * - arch/x86/kvm/vmx/vmx.c|7475| <<hardware_setup>> enable_vpid = 0;
+ * - arch/x86/kvm/vmx/vmx.h|505| <<__vmx_flush_tlb>> if (enable_ept && (invalidate_gpa || !enable_vpid)) {
+ */
bool __read_mostly enable_vpid = 1;
module_param_named(vpid, enable_vpid, bool, 0444);
@@ -82,6 +107,10 @@ module_param_named(vnmi, enable_vnmi, bool, S_IRUGO);
bool __read_mostly flexpriority_enabled = 1;
module_param_named(flexpriority, flexpriority_enabled, bool, S_IRUGO);
+/*
+ * 只在一处可能修改:
+ * - arch/x86/kvm/vmx/vmx.c|7481| <<hardware_setup>> enable_ept = 0;
+ */
bool __read_mostly enable_ept = 1;
module_param_named(ept, enable_ept, bool, S_IRUGO);
@@ -89,15 +118,43 @@ bool __read_mostly enable_unrestricted_guest = 1;
module_param_named(unrestricted_guest,
enable_unrestricted_guest, bool, S_IRUGO);
+/*
+ * used by:
+ * - arch/x86/kvm/vmx/nested.c|5631| <<nested_vmx_setup_ctls_msrs>> if (enable_ept_ad_bits) {
+ * - arch/x86/kvm/vmx/vmx.c|2851| <<construct_eptp>> if (enable_ept_ad_bits &&
+ * - arch/x86/kvm/vmx/vmx.c|5267| <<vmx_enable_tdp>> enable_ept_ad_bits ? VMX_EPT_ACCESS_BIT : 0ull,
+ * - arch/x86/kvm/vmx/vmx.c|5268| <<vmx_enable_tdp>> enable_ept_ad_bits ? VMX_EPT_DIRTY_BIT : 0ull,
+ * - arch/x86/kvm/vmx/vmx.c|7484| <<hardware_setup>> enable_ept_ad_bits = 0;
+ * - arch/x86/kvm/vmx/vmx.c|7548| <<hardware_setup>> if (!enable_ept || !enable_ept_ad_bits || !cpu_has_vmx_pml())
+ */
bool __read_mostly enable_ept_ad_bits = 1;
module_param_named(eptad, enable_ept_ad_bits, bool, S_IRUGO);
+/*
+ * used by:
+ * - arch/x86/kvm/vmx/vmx.c|1370| <<emulation_required>> return emulate_invalid_guest_state && !guest_state_valid(vcpu);
+ * - arch/x86/kvm/vmx/vmx.c|2558| <<fix_pmode_seg>> if (!emulate_invalid_guest_state) {
+ * - arch/x86/kvm/vmx/vmx.c|2623| <<fix_rmode_seg>> if (!emulate_invalid_guest_state) {
+ * - arch/x86/kvm/vmx/vmx.c|6249| <<vmx_has_emulated_msr>> return enable_unrestricted_guest || emulate_invalid_guest_state;
+ */
static bool __read_mostly emulate_invalid_guest_state = true;
module_param(emulate_invalid_guest_state, bool, S_IRUGO);
+/*
+ * used only by:
+ * - arch/x86/kvm/vmx/vmx.c|5001| <<handle_apic_access>> if (likely(fasteoi)) {
+ */
static bool __read_mostly fasteoi = 1;
module_param(fasteoi, bool, S_IRUGO);
+/*
+ * used by:
+ * - arch/x86/kvm/vmx/vmx.c|3550| <<vmx_msr_bitmap_mode>> if (enable_apicv && kvm_vcpu_apicv_active(vcpu))
+ * - arch/x86/kvm/vmx/vmx.c|3622| <<vmx_get_enable_apicv>> return enable_apicv;
+ * - arch/x86/kvm/vmx/vmx.c|6764| <<vmx_check_processor_compat>> enable_apicv);
+ * - arch/x86/kvm/vmx/vmx.c|7527| <<hardware_setup>> enable_apicv = 0;
+ * - arch/x86/kvm/vmx/vmx.c|7583| <<hardware_setup>> vmx_capability.ept, enable_apicv);
+ */
static bool __read_mostly enable_apicv = 1;
module_param(enable_apicv, bool, S_IRUGO);
@@ -4827,6 +4884,9 @@ static void vmx_set_dr7(struct kvm_vcpu *vcpu, unsigned long val)
vmcs_writel(GUEST_DR7, val);
}
+/*
+ * kvm_vmx_exit_handlers[EXIT_REASON_CPUID] = handle_cpuid()
+ */
static int handle_cpuid(struct kvm_vcpu *vcpu)
{
return kvm_emulate_cpuid(vcpu);
@@ -5471,6 +5531,12 @@ static int handle_encls(struct kvm_vcpu *vcpu)
* may resume. Otherwise they set the kvm_run parameter to indicate what needs
* to be done to userspace and return 0.
*/
+/*
+ * used by:
+ * - arch/x86/kvm/vmx/vmx.c|5867| <<vmx_handle_exit>> && kvm_vmx_exit_handlers[exit_reason])
+ * - arch/x86/kvm/vmx/vmx.c|5868| <<vmx_handle_exit>> return kvm_vmx_exit_handlers[exit_reason](vcpu);
+ * - arch/x86/kvm/vmx/vmx.c|7576| <<hardware_setup>> r = nested_vmx_hardware_setup(kvm_vmx_exit_handlers);
+ */
static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = {
[EXIT_REASON_EXCEPTION_NMI] = handle_exception,
[EXIT_REASON_EXTERNAL_INTERRUPT] = handle_external_interrupt,
@@ -5771,6 +5837,9 @@ void dump_vmcs(void)
* The guest has exited. See if we can fix it or if we need userspace
* assistance.
*/
+/*
+ * struct kvm_x86_ops vmx_x86_ops.handle_exit = vmx_handle_exit()
+ */
static int vmx_handle_exit(struct kvm_vcpu *vcpu)
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
@@ -6384,6 +6453,12 @@ void vmx_update_host_rsp(struct vcpu_vmx *vmx, unsigned long host_rsp)
bool __vmx_vcpu_run(struct vcpu_vmx *vmx, unsigned long *regs, bool launched);
+/*
+ * called by:
+ * - arch/x86/kvm/x86.c|7996| <<vcpu_enter_guest>> kvm_x86_ops->run(vcpu);
+ *
+ * struct kvm_x86_ops vmx_x86_ops.run = vmx_vcpu_run()
+ */
static void vmx_vcpu_run(struct kvm_vcpu *vcpu)
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 83aefd7..170fa8f 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1531,6 +1531,13 @@ static atomic_t kvm_guest_has_master_clock = ATOMIC_INIT(0);
#endif
static DEFINE_PER_CPU(unsigned long, cpu_tsc_khz);
+/*
+ * used by:
+ * - arch/x86/kvm/x86.c|6846| <<kvm_timer_init>> max_tsc_khz = tsc_khz;
+ * - arch/x86/kvm/x86.c|6857| <<kvm_timer_init>> max_tsc_khz = policy.cpuinfo.max_freq;
+ * - arch/x86/kvm/x86.c|6863| <<kvm_timer_init>> pr_debug("kvm: max_tsc_khz = %ld\n", max_tsc_khz);
+ * - arch/x86/kvm/x86.c|9157| <<kvm_arch_vcpu_init>> kvm_set_tsc_khz(vcpu, max_tsc_khz);
+ */
static unsigned long max_tsc_khz;
static u32 adjust_tsc_khz(u32 khz, s32 ppm)
@@ -3151,6 +3158,12 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
}
+/*
+ * called by:
+ * - virt/kvm/kvm_main.c|3520| <<kvm_dev_ioctl>> return kvm_arch_dev_ioctl(filp, ioctl, arg);
+ *
+ * 处理kvm的dev的kvm_chardev_ops的kvm_dev_ioctl()的剩余的命令
+ */
long kvm_arch_dev_ioctl(struct file *filp,
unsigned int ioctl, unsigned long arg)
{
@@ -4632,6 +4645,12 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
return r;
}
+/*
+ * called by:
+ * - virt/kvm/kvm_main.c|3436| <<kvm_vm_ioctl>> r = kvm_arch_vm_ioctl(filp, ioctl, arg);
+ *
+ * vm的dev: kvm_vm_fops->kvm_vm_ioctl()-->kvm_arch_vm_ioctl()
+ */
long kvm_arch_vm_ioctl(struct file *filp,
unsigned int ioctl, unsigned long arg)
{
@@ -6841,6 +6860,10 @@ static int kvmclock_cpu_online(unsigned int cpu)
return 0;
}
+/*
+ * called only by:
+ * - arch/x86/kvm/x86.c|7049| <<kvm_arch_init>> kvm_timer_init();
+ */
static void kvm_timer_init(void)
{
max_tsc_khz = tsc_khz;
@@ -6983,6 +7006,10 @@ static struct notifier_block pvclock_gtod_notifier = {
};
#endif
+/*
+ * called by only:
+ * - virt/kvm/kvm_main.c|4233| <<kvm_init>> r = kvm_arch_init(opaque);
+ */
int kvm_arch_init(void *opaque)
{
int r;
@@ -7752,6 +7779,12 @@ EXPORT_SYMBOL_GPL(__kvm_request_immediate_exit);
* exiting to the userspace. Otherwise, the value will be returned to the
* userspace.
*/
+/*
+ * called by:
+ * - arch/x86/kvm/x86.c|8128| <<vcpu_run>> r = vcpu_enter_guest(vcpu);
+ *
+ * vcpu的dev: kvm_vcpu_fops->kvm_vcpu_ioctl()::KVM_RUN-->kvm_arch_vcpu_ioctl_run()-->vcpu_run()-->vcpu_enter_guest()
+ */
static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
{
int r;
@@ -7972,6 +8005,12 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
vcpu->arch.switch_db_regs &= ~KVM_DEBUGREG_RELOAD;
}
+ /*
+ * called only by:
+ * - arch/x86/kvm/x86.c|7996| <<vcpu_enter_guest>> kvm_x86_ops->run(vcpu);
+ *
+ * vmx: vmx_vcpu_run()
+ */
kvm_x86_ops->run(vcpu);
/*
@@ -8032,6 +8071,12 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
kvm_lapic_sync_from_vapic(vcpu);
vcpu->arch.gpa_available = false;
+ /*
+ * called only by:
+ * - arch/x86/kvm/x86.c|8060| <<vcpu_enter_guest>> r = kvm_x86_ops->handle_exit(vcpu);
+ *
+ * vmx: vmx_handle_exit()
+ */
r = kvm_x86_ops->handle_exit(vcpu);
return r;
@@ -8043,6 +8088,10 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
return r;
}
+/*
+ * called by:
+ * - arch/x86/kvm/x86.c|8122| <<vcpu_run>> r = vcpu_block(kvm, vcpu);
+ */
static inline int vcpu_block(struct kvm *kvm, struct kvm_vcpu *vcpu)
{
if (!kvm_arch_vcpu_runnable(vcpu) &&
@@ -8086,6 +8135,12 @@ static inline bool kvm_vcpu_running(struct kvm_vcpu *vcpu)
!vcpu->arch.apf.halted);
}
+/*
+ * called by:
+ * - arch/x86/kvm/x86.c|8328| <<kvm_arch_vcpu_ioctl_run>> r = vcpu_run(vcpu);
+ *
+ * vcpu的dev: kvm_vcpu_fops->kvm_vcpu_ioctl()::KVM_RUN-->kvm_arch_vcpu_ioctl_run()-->vcpu_run()
+ */
static int vcpu_run(struct kvm_vcpu *vcpu)
{
int r;
@@ -8248,6 +8303,12 @@ static void kvm_put_guest_fpu(struct kvm_vcpu *vcpu)
trace_kvm_fpu(0);
}
+/*
+ * called by:
+ * - virt/kvm/kvm_main.c|2814| <<kvm_vcpu_ioctl>> r = kvm_arch_vcpu_ioctl_run(vcpu, vcpu->run);
+ *
+ * vcpu的dev: kvm_vcpu_fops->kvm_vcpu_ioctl()::KVM_RUN-->kvm_arch_vcpu_ioctl_run()
+ */
int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
{
int r;
@@ -8835,6 +8896,12 @@ void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu)
free_cpumask_var(wbinvd_dirty_mask);
}
+/*
+ * called by:
+ * - virt/kvm/kvm_main.c|2691| <<kvm_vm_ioctl_create_vcpu>> vcpu = kvm_arch_vcpu_create(kvm, id);
+ *
+ * vm的dev: kvm_vm_fops->kvm_vm_ioctl()::KVM_CREATE_VCPU-->kvm_vm_ioctl_create_vcpu()-->kvm_arch_vcpu_create()
+ */
struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm,
unsigned int id)
{
@@ -8850,6 +8917,9 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm,
return vcpu;
}
+/*
+ * vm的dev: kvm_vm_fops->kvm_vm_ioctl()::KVM_CREATE_VCPU-->kvm_vm_ioctl_create_vcpu()-->kvm_arch_vcpu_setup()
+ */
int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
{
vcpu->arch.arch_capabilities = kvm_get_arch_capabilities();
@@ -9082,6 +9152,10 @@ int kvm_arch_hardware_setup(void)
{
int r;
+ /*
+ * vmx: hardware_setup()
+ * svm: svm_hardware_setup()
+ */
r = kvm_x86_ops->hardware_setup();
if (r != 0)
return r;
diff --git a/virt/kvm/async_pf.c b/virt/kvm/async_pf.c
index 110cbe3..29484a9 100644
--- a/virt/kvm/async_pf.c
+++ b/virt/kvm/async_pf.c
@@ -44,6 +44,19 @@ static inline void kvm_async_page_present_async(struct kvm_vcpu *vcpu,
#endif
}
+/*
+ * used by:
+ * - virt/kvm/async_pf.c|51| <<kvm_async_pf_init>> async_pf_cache = KMEM_CACHE(kvm_async_pf, 0);
+ * - virt/kvm/async_pf.c|53| <<kvm_async_pf_init>> if (!async_pf_cache)
+ * - virt/kvm/async_pf.c|61| <<kvm_async_pf_deinit>> kmem_cache_destroy(async_pf_cache);
+ * - virt/kvm/async_pf.c|62| <<kvm_async_pf_deinit>> async_pf_cache = NULL;
+ * - virt/kvm/async_pf.c|141| <<kvm_clear_async_pf_completion_queue>> kmem_cache_free(async_pf_cache, work);
+ * - virt/kvm/async_pf.c|152| <<kvm_clear_async_pf_completion_queue>> kmem_cache_free(async_pf_cache, work);
+ * - virt/kvm/async_pf.c|176| <<kvm_check_async_pf_completion>> kmem_cache_free(async_pf_cache, work);
+ * - virt/kvm/async_pf.c|194| <<kvm_setup_async_pf>> work = kmem_cache_zalloc(async_pf_cache, GFP_NOWAIT | __GFP_NOWARN);
+ * - virt/kvm/async_pf.c|223| <<kvm_setup_async_pf>> kmem_cache_free(async_pf_cache, work);
+ * - virt/kvm/async_pf.c|234| <<kvm_async_pf_wakeup_all>> work = kmem_cache_zalloc(async_pf_cache, GFP_ATOMIC);
+ */
static struct kmem_cache *async_pf_cache;
int kvm_async_pf_init(void)
diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c
index 3972a956..19e8965 100644
--- a/virt/kvm/eventfd.c
+++ b/virt/kvm/eventfd.c
@@ -642,6 +642,10 @@ void kvm_irq_routing_update(struct kvm *kvm)
* aggregated from all vm* instances. We need our own isolated
* queue to ease flushing work items when a VM exits.