From: Sean Christopherson <seanjc@google.com> To: Atish Patra <Atish.Patra@wdc.com> Cc: "linux-riscv@lists.infradead.org" <linux-riscv@lists.infradead.org>, Anup Patel <Anup.Patel@wdc.com>, "vincent.chen@sifive.com" <vincent.chen@sifive.com>, "kvm-riscv@lists.infradead.org" <kvm-riscv@lists.infradead.org>, "paul.walmsley@sifive.com" <paul.walmsley@sifive.com>, "palmer@dabbelt.com" <palmer@dabbelt.com>, "wangkefeng.wang@huawei.com" <wangkefeng.wang@huawei.com>, "kvm@vger.kernel.org" <kvm@vger.kernel.org>, "pbonzini@redhat.com" <pbonzini@redhat.com>, "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org> Subject: Re: [PATCH v3 5/5] RISC-V: Add SBI HSM extension in KVM Date: Mon, 11 Oct 2021 14:32:38 +0000 [thread overview] Message-ID: <YWRLBknWXjzPnF1w@google.com> (raw) In-Reply-To: <0383b5cacb25e9dc293d891284df9f4cbc06ee3a.camel@wdc.com> On Mon, Oct 11, 2021, Atish Patra wrote: > On Fri, 2021-10-08 at 15:02 +0000, Sean Christopherson wrote: > > On Thu, Oct 07, 2021, Atish Patra wrote: > > > + preempt_disable(); > > > + loaded = (vcpu->cpu != -1); > > > + if (loaded) > > > + kvm_arch_vcpu_put(vcpu); > > > > Oof. Looks like this pattern was taken from arm64. > > Yes. This part is similar to arm64 because the same race condition can > happen in riscv due to save/restore of CSRs during reset. > > > > Is there really no better approach to handling this? I don't see anything > > in kvm_riscv_reset_vcpu() that will obviously break if the vCPU is > > loaded. If the goal is purely to effect a CSR reset via > > kvm_arch_vcpu_load(), then why not just factor out a helper to do exactly > > that? What about the question here? > > > > > > > > memcpy(csr, reset_csr, sizeof(*csr)); > > > > > > @@ -144,6 +151,11 @@ static void kvm_riscv_reset_vcpu(struct > > > kvm_vcpu *vcpu) > > > > > > WRITE_ONCE(vcpu->arch.irqs_pending, 0); > > > WRITE_ONCE(vcpu->arch.irqs_pending_mask, 0); > > > + > > > + /* Reset the guest CSRs for hotplug usecase */ > > > + if (loaded) > > > + kvm_arch_vcpu_load(vcpu, smp_processor_id()); > > > > If the preempt shenanigans really have to stay, at least use > > get_cpu()/put_cpu(). > > > > Is there any specific advantage to that ? get_cpu/put_cpu are just > macros which calls preempt_disable/preempt_enable. > > The only advantage of get_cpu is that it returns the current cpu. > vcpu_load function uses get_cpu because it requires the current cpu id. > > However, we don't need that in this case. I am not against changing it > to get_cpu/put_cpu. Just wanted to understand the reasoning behind your > suggestion. It would make the code a bit self-documenting, because AFAICT it doesn't truly care about being preempted, it cares about keeping the vCPU on the correct pCPU. > > > + preempt_enable(); > > > } > > > > > > int kvm_arch_vcpu_precreate(struct kvm *kvm, unsigned int id) > > > @@ -180,6 +192,13 @@ int kvm_arch_vcpu_create(struct kvm_vcpu > > > *vcpu) > > > > > > void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu) > > > { > > > + /** > > > + * vcpu with id 0 is the designated boot cpu. > > > + * Keep all vcpus with non-zero cpu id in power-off state > > > so that they > > > + * can brought to online using SBI HSM extension. > > > + */ > > > + if (vcpu->vcpu_idx != 0) > > > + kvm_riscv_vcpu_power_off(vcpu); > > > > Why do this in postcreate? > > > > Because we need to absolutely sure that the vcpu is created. It is > cleaner in this way rather than doing this here at the end of > kvm_arch_vcpu_create. create_vcpu can also fail after > kvm_arch_vcpu_create returns. But kvm_riscv_vcpu_power_off() doesn't doesn't anything outside of the vCPU. It clears vcpu->arch.power_off, makes a request, and kicks the vCPU. None of that has side effects to anything else in KVM. If the vCPU isn't created successfully, it gets deleted and nothing ever sees that state change.
WARNING: multiple messages have this Message-ID (diff)
From: Sean Christopherson <seanjc@google.com> To: Atish Patra <Atish.Patra@wdc.com> Cc: "linux-riscv@lists.infradead.org" <linux-riscv@lists.infradead.org>, Anup Patel <Anup.Patel@wdc.com>, "vincent.chen@sifive.com" <vincent.chen@sifive.com>, "kvm-riscv@lists.infradead.org" <kvm-riscv@lists.infradead.org>, "paul.walmsley@sifive.com" <paul.walmsley@sifive.com>, "palmer@dabbelt.com" <palmer@dabbelt.com>, "wangkefeng.wang@huawei.com" <wangkefeng.wang@huawei.com>, "kvm@vger.kernel.org" <kvm@vger.kernel.org>, "pbonzini@redhat.com" <pbonzini@redhat.com>, "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org> Subject: Re: [PATCH v3 5/5] RISC-V: Add SBI HSM extension in KVM Date: Mon, 11 Oct 2021 14:32:38 +0000 [thread overview] Message-ID: <YWRLBknWXjzPnF1w@google.com> (raw) In-Reply-To: <0383b5cacb25e9dc293d891284df9f4cbc06ee3a.camel@wdc.com> On Mon, Oct 11, 2021, Atish Patra wrote: > On Fri, 2021-10-08 at 15:02 +0000, Sean Christopherson wrote: > > On Thu, Oct 07, 2021, Atish Patra wrote: > > > + preempt_disable(); > > > + loaded = (vcpu->cpu != -1); > > > + if (loaded) > > > + kvm_arch_vcpu_put(vcpu); > > > > Oof. Looks like this pattern was taken from arm64. > > Yes. This part is similar to arm64 because the same race condition can > happen in riscv due to save/restore of CSRs during reset. > > > > Is there really no better approach to handling this? I don't see anything > > in kvm_riscv_reset_vcpu() that will obviously break if the vCPU is > > loaded. If the goal is purely to effect a CSR reset via > > kvm_arch_vcpu_load(), then why not just factor out a helper to do exactly > > that? What about the question here? > > > > > > > > memcpy(csr, reset_csr, sizeof(*csr)); > > > > > > @@ -144,6 +151,11 @@ static void kvm_riscv_reset_vcpu(struct > > > kvm_vcpu *vcpu) > > > > > > WRITE_ONCE(vcpu->arch.irqs_pending, 0); > > > WRITE_ONCE(vcpu->arch.irqs_pending_mask, 0); > > > + > > > + /* Reset the guest CSRs for hotplug usecase */ > > > + if (loaded) > > > + kvm_arch_vcpu_load(vcpu, smp_processor_id()); > > > > If the preempt shenanigans really have to stay, at least use > > get_cpu()/put_cpu(). > > > > Is there any specific advantage to that ? get_cpu/put_cpu are just > macros which calls preempt_disable/preempt_enable. > > The only advantage of get_cpu is that it returns the current cpu. > vcpu_load function uses get_cpu because it requires the current cpu id. > > However, we don't need that in this case. I am not against changing it > to get_cpu/put_cpu. Just wanted to understand the reasoning behind your > suggestion. It would make the code a bit self-documenting, because AFAICT it doesn't truly care about being preempted, it cares about keeping the vCPU on the correct pCPU. > > > + preempt_enable(); > > > } > > > > > > int kvm_arch_vcpu_precreate(struct kvm *kvm, unsigned int id) > > > @@ -180,6 +192,13 @@ int kvm_arch_vcpu_create(struct kvm_vcpu > > > *vcpu) > > > > > > void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu) > > > { > > > + /** > > > + * vcpu with id 0 is the designated boot cpu. > > > + * Keep all vcpus with non-zero cpu id in power-off state > > > so that they > > > + * can brought to online using SBI HSM extension. > > > + */ > > > + if (vcpu->vcpu_idx != 0) > > > + kvm_riscv_vcpu_power_off(vcpu); > > > > Why do this in postcreate? > > > > Because we need to absolutely sure that the vcpu is created. It is > cleaner in this way rather than doing this here at the end of > kvm_arch_vcpu_create. create_vcpu can also fail after > kvm_arch_vcpu_create returns. But kvm_riscv_vcpu_power_off() doesn't doesn't anything outside of the vCPU. It clears vcpu->arch.power_off, makes a request, and kicks the vCPU. None of that has side effects to anything else in KVM. If the vCPU isn't created successfully, it gets deleted and nothing ever sees that state change. _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2021-10-11 14:32 UTC|newest] Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-10-08 3:20 [PATCH v3 0/5] Add SBI v0.2 support for KVM Atish Patra 2021-10-08 3:20 ` Atish Patra 2021-10-08 3:20 ` [PATCH v3 1/5] RISC-V: Mark the existing SBI v0.1 implementation as legacy Atish Patra 2021-10-08 3:20 ` Atish Patra 2021-10-08 7:24 ` Paolo Bonzini 2021-10-08 7:24 ` Paolo Bonzini 2021-10-25 7:53 ` Anup Patel 2021-10-25 7:53 ` Anup Patel 2021-10-08 3:20 ` [PATCH v3 2/5] RISC-V: Reorganize SBI code by moving legacy SBI to its own file Atish Patra 2021-10-08 3:20 ` Atish Patra 2021-10-08 3:20 ` [PATCH v3 3/5] RISC-V: Add SBI v0.2 base extension Atish Patra 2021-10-08 3:20 ` Atish Patra 2021-10-08 3:20 ` [PATCH v3 4/5] RISC-V: Add v0.1 replacement SBI extensions defined in v02 Atish Patra 2021-10-08 3:20 ` Atish Patra 2021-10-08 3:20 ` [PATCH v3 5/5] RISC-V: Add SBI HSM extension in KVM Atish Patra 2021-10-08 3:20 ` Atish Patra 2021-10-08 15:02 ` Sean Christopherson 2021-10-08 15:02 ` Sean Christopherson 2021-10-11 8:02 ` Atish Patra 2021-10-11 8:02 ` Atish Patra 2021-10-11 14:32 ` Sean Christopherson [this message] 2021-10-11 14:32 ` Sean Christopherson 2021-10-11 22:50 ` Atish Patra 2021-10-11 22:50 ` Atish Patra 2021-10-12 16:46 ` Sean Christopherson 2021-10-12 16:46 ` Sean Christopherson 2021-10-10 9:34 ` [PATCH v3 0/5] Add SBI v0.2 support for KVM Guo Ren 2021-10-10 9:34 ` Guo Ren
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=YWRLBknWXjzPnF1w@google.com \ --to=seanjc@google.com \ --cc=Anup.Patel@wdc.com \ --cc=Atish.Patra@wdc.com \ --cc=kvm-riscv@lists.infradead.org \ --cc=kvm@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-riscv@lists.infradead.org \ --cc=palmer@dabbelt.com \ --cc=paul.walmsley@sifive.com \ --cc=pbonzini@redhat.com \ --cc=vincent.chen@sifive.com \ --cc=wangkefeng.wang@huawei.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.