From: Lai Jiangshan <jiangshanlai@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Lai Jiangshan <jiangshan.ljs@antgroup.com>,
Marc Zyngier <maz@kernel.org>, Zenghui Yu <yuzenghui@huawei.com>,
Paolo Bonzini <pbonzini@redhat.com>,
kvm@vger.kernel.org
Subject: [PATCH] kvm: Simplify kvm_get_running_vcpu()
Date: Thu, 20 Jun 2024 16:11:14 +0800 [thread overview]
Message-ID: <20240620081114.70615-1-jiangshanlai@gmail.com> (raw)
From: Lai Jiangshan <jiangshan.ljs@antgroup.com>
this_cpu_read() is exactly the same behavior as "preempt_disable() +
__this_cpu_read() + preempt_enable()", and it uses less instructions
in X86.
Just use this_cpu_read() to simplify kvm_get_running_vcpu().
Cc: Marc Zyngier <maz@kernel.org>
Cc: Zenghui Yu <yuzenghui@huawei.com>
Link: https://lore.kernel.org/kvm/20200207163410.31276-1-maz@kernel.org/
Signed-off-by: Lai Jiangshan <jiangshan.ljs@antgroup.com>
---
virt/kvm/kvm_main.c | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 14841acb8b95..0d18e9b1017f 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -6306,21 +6306,14 @@ static void kvm_sched_out(struct preempt_notifier *pn,
/**
* kvm_get_running_vcpu - get the vcpu running on the current CPU.
*
- * We can disable preemption locally around accessing the per-CPU variable,
- * and use the resolved vcpu pointer after enabling preemption again,
+ * The result is either NULL or the vcpu running on the current thread
* because even if the current thread is migrated to another CPU, reading
* the per-CPU value later will give us the same value as we update the
* per-CPU variable in the preempt notifier handlers.
*/
struct kvm_vcpu *kvm_get_running_vcpu(void)
{
- struct kvm_vcpu *vcpu;
-
- preempt_disable();
- vcpu = __this_cpu_read(kvm_running_vcpu);
- preempt_enable();
-
- return vcpu;
+ return this_cpu_read(kvm_running_vcpu);
}
EXPORT_SYMBOL_GPL(kvm_get_running_vcpu);
--
2.19.1.6.gb485710b
next reply other threads:[~2024-06-20 8:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-20 8:11 Lai Jiangshan [this message]
2024-06-20 21:15 ` Paolo Bonzini
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=20240620081114.70615-1-jiangshanlai@gmail.com \
--to=jiangshanlai@gmail.com \
--cc=jiangshan.ljs@antgroup.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maz@kernel.org \
--cc=pbonzini@redhat.com \
--cc=yuzenghui@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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®