Skip to content

Commit 0d2abe6

Browse files
bibo-maochenhuacai
authored andcommitted
LoongArch: KVM: Allow to access HW timer CSR registers always
Currently HW timer CSR registers are allowed to access before entering to vm and disabled if switch to SW timer in host mode, instead it is not necessary to do so. HW timer CSR registers can be accessed always, it is nothing to do with whether it is in vm mode or host mode. This patch removes the limitation. Signed-off-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent 1612673 commit 0d2abe6

2 files changed

Lines changed: 6 additions & 22 deletions

File tree

arch/loongarch/kvm/main.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,6 @@ int kvm_arch_hardware_enable(void)
287287
if (env & CSR_GCFG_MATC_ROOT)
288288
gcfg |= CSR_GCFG_MATC_ROOT;
289289

290-
gcfg |= CSR_GCFG_TIT;
291290
write_csr_gcfg(gcfg);
292291

293292
kvm_flush_tlb_all();

arch/loongarch/kvm/timer.c

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,6 @@ void kvm_init_timer(struct kvm_vcpu *vcpu, unsigned long timer_hz)
7070
*/
7171
void kvm_acquire_timer(struct kvm_vcpu *vcpu)
7272
{
73-
unsigned long cfg;
74-
75-
cfg = read_csr_gcfg();
76-
if (!(cfg & CSR_GCFG_TIT))
77-
return;
78-
79-
/* Enable guest access to hard timer */
80-
write_csr_gcfg(cfg & ~CSR_GCFG_TIT);
81-
8273
/*
8374
* Freeze the soft-timer and sync the guest stable timer with it. We do
8475
* this with interrupts disabled to avoid latency.
@@ -174,21 +165,15 @@ static void _kvm_save_timer(struct kvm_vcpu *vcpu)
174165
*/
175166
void kvm_save_timer(struct kvm_vcpu *vcpu)
176167
{
177-
unsigned long cfg;
178168
struct loongarch_csrs *csr = vcpu->arch.csr;
179169

180170
preempt_disable();
181-
cfg = read_csr_gcfg();
182-
if (!(cfg & CSR_GCFG_TIT)) {
183-
/* Disable guest use of hard timer */
184-
write_csr_gcfg(cfg | CSR_GCFG_TIT);
185-
186-
/* Save hard timer state */
187-
kvm_save_hw_gcsr(csr, LOONGARCH_CSR_TCFG);
188-
kvm_save_hw_gcsr(csr, LOONGARCH_CSR_TVAL);
189-
if (kvm_read_sw_gcsr(csr, LOONGARCH_CSR_TCFG) & CSR_TCFG_EN)
190-
_kvm_save_timer(vcpu);
191-
}
171+
172+
/* Save hard timer state */
173+
kvm_save_hw_gcsr(csr, LOONGARCH_CSR_TCFG);
174+
kvm_save_hw_gcsr(csr, LOONGARCH_CSR_TVAL);
175+
if (kvm_read_sw_gcsr(csr, LOONGARCH_CSR_TCFG) & CSR_TCFG_EN)
176+
_kvm_save_timer(vcpu);
192177

193178
/* Save timer-related state to vCPU context */
194179
kvm_save_hw_gcsr(csr, LOONGARCH_CSR_ESTAT);

0 commit comments

Comments
 (0)