[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <0fa9c062-d3fc-61e5-4d54-6bc29f7c64cf@loongson.cn>
Date: Tue, 21 Feb 2023 14:59:52 +0800
From: maobibo <maobibo@...ngson.cn>
To: Paolo Bonzini <pbonzini@...hat.com>,
Tianrui Zhao <zhaotianrui@...ngson.cn>
Cc: Huacai Chen <chenhuacai@...nel.org>,
WANG Xuerui <kernel@...0n.name>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
loongarch@...ts.linux.dev, linux-kernel@...r.kernel.org,
kvm@...r.kernel.org, Jens Axboe <axboe@...nel.dk>,
Mark Brown <broonie@...nel.org>,
Alex Deucher <alexander.deucher@....com>,
Oliver Upton <oliver.upton@...ux.dev>
Subject: Re: [PATCH v2 02/29] LoongArch: KVM: Implement kvm module related
interface
在 2023/2/21 01:46, Paolo Bonzini 写道:
> On 2/20/23 07:57, Tianrui Zhao wrote:
>> + order = get_order(kvm_vector_size + kvm_enter_guest_size);
>> + addr = (void *)__get_free_pages(GFP_KERNEL, order);
>> + if (!addr) {
>> + free_percpu(vmcs);
>> + return -ENOMEM;
>> + }
>> +
>> + memcpy(addr, kvm_vector_entry, kvm_vector_size);
>> + memcpy(addr + kvm_vector_size, kvm_enter_guest, kvm_enter_guest_size);
>> + flush_icache_range((unsigned long)addr, (unsigned long)addr +
>> + kvm_vector_size + kvm_enter_guest_size);
>> +
>> + vpid_mask = read_csr_gstat();
>> + vpid_mask = (vpid_mask & CSR_GSTAT_GIDBIT) >> CSR_GSTAT_GIDBIT_SHIFT;
>> + if (vpid_mask)
>> + vpid_mask = GENMASK(vpid_mask - 1, 0);
>> +
>> + for_each_possible_cpu(cpu) {
>> + context = per_cpu_ptr(vmcs, cpu);
>> + context->vpid_mask = vpid_mask;
>> + context->vpid_cache = context->vpid_mask + 1;
>> + context->last_vcpu = NULL;
>> + context->kvm_eentry = addr;
>> + context->kvm_enter_guest = addr + kvm_vector_size;
>> + context->page_order = order;
>> + }
>
> A lot of these variables are constant across all pCPUs, any reason to have them in a per-CPU variable? Likewise, since they are all the same as the constant global vmcs variable, why make them part of struct kvm_context instead of just making them globals?
>
Paolo,
Thanks for reviewing these patches.
Originally we think that global variables make c files depending with
each other, and global variables is not faster than percpu, so that
we removes global variables. we are ok to make them globals.
> Also, why does the world switch code need a copy?
There will be problem in world switch code if there is page fault reenter,
since pgd register is shared between root kernel and kvm hypervisor.
World switch entry need be unmapped area, cannot be tlb mapped area.
In future if hw pagetable walking is supported, or there is separate pgd
registers between root kernel and kvm hypervisor, copying about world switch
code will not be used.
Regards
Bibo, Mao
>
> Paolo
Powered by blists - more mailing lists