All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zenghui Yu <yuzenghui@huawei.com>
To: Marc Zyngier <maz@kernel.org>
Cc: <kvm@vger.kernel.org>, <kvmarm@lists.cs.columbia.edu>,
	<pbonzini@redhat.com>, <peterx@redhat.com>
Subject: Re: BUG: using __this_cpu_read() in preemptible [00000000] code
Date: Fri, 7 Feb 2020 18:19:17 +0800	[thread overview]
Message-ID: <3e90c020-e7f3-61f1-3731-a489df0b1d9c@huawei.com> (raw)
In-Reply-To: <828d3b538b7258f692f782b6798277cf@kernel.org>

Hi Marc,

On 2020/2/7 17:19, Marc Zyngier wrote:
> Hi Zenghui,
> 
> On 2020-02-07 09:00, Zenghui Yu wrote:
>> Hi,
>>
>> Running a latest preemptible kernel and some guests on it,
>> I got the following message,
>>
>> ---8<---
>>
>> [  630.031870] BUG: using __this_cpu_read() in preemptible [00000000]
>> code: qemu-system-aar/37270
>> [  630.031872] caller is kvm_get_running_vcpu+0x1c/0x38
>> [  630.031874] CPU: 32 PID: 37270 Comm: qemu-system-aar Kdump: loaded
>> Not tainted 5.5.0+
>> [  630.031876] Hardware name: Huawei TaiShan 2280 /BC11SPCD, BIOS 1.58
>> 10/29/2018
>> [  630.031876] Call trace:
>> [  630.031878]  dump_backtrace+0x0/0x200
>> [  630.031880]  show_stack+0x24/0x30
>> [  630.031882]  dump_stack+0xb0/0xf4
>> [  630.031884]  __this_cpu_preempt_check+0xc8/0xd0
>> [  630.031886]  kvm_get_running_vcpu+0x1c/0x38
>> [  630.031888]  vgic_mmio_change_active.isra.4+0x2c/0xe0
>> [  630.031890]  __vgic_mmio_write_cactive+0x80/0xc8
>> [  630.031892]  vgic_mmio_uaccess_write_cactive+0x3c/0x50
>> [  630.031894]  vgic_uaccess+0xcc/0x138
>> [  630.031896]  vgic_v3_redist_uaccess+0x7c/0xa8
>> [  630.031898]  vgic_v3_attr_regs_access+0x1a8/0x230
>> [  630.031901]  vgic_v3_set_attr+0x1b4/0x290
>> [  630.031903]  kvm_device_ioctl_attr+0xbc/0x110
>> [  630.031905]  kvm_device_ioctl+0xc4/0x108
>> [  630.031907]  ksys_ioctl+0xb4/0xd0
>> [  630.031909]  __arm64_sys_ioctl+0x28/0x38
>> [  630.031911]  el0_svc_common.constprop.1+0x7c/0x1a0
>> [  630.031913]  do_el0_svc+0x34/0xa0
>> [  630.031915]  el0_sync_handler+0x124/0x274
>> [  630.031916]  el0_sync+0x140/0x180
>>
>> ---8<---
>>
>> I'm now at commit 90568ecf561540fa330511e21fcd823b0c3829c6.
>>
>> And it looks like vgic_get_mmio_requester_vcpu() was broken by
>> 7495e22bb165 ("KVM: Move running VCPU from ARM to common code").
>>
>> Could anyone please have a look?
> 
> Here you go:
> 
> diff --git a/virt/kvm/arm/vgic/vgic-mmio.c b/virt/kvm/arm/vgic/vgic-mmio.c
> index d656ebd5f9d4..e1735f19c924 100644
> --- a/virt/kvm/arm/vgic/vgic-mmio.c
> +++ b/virt/kvm/arm/vgic/vgic-mmio.c
> @@ -190,6 +190,15 @@ unsigned long vgic_mmio_read_pending(struct 
> kvm_vcpu *vcpu,
>    * value later will give us the same value as we update the per-CPU 
> variable
>    * in the preempt notifier handlers.
>    */
> +static struct kvm_vcpu *vgic_get_mmio_requester_vcpu(void)
> +{
> +    struct kvm_vcpu *vcpu;
> +
> +    preempt_disable();
> +    vcpu = kvm_get_running_vcpu();
> +    preempt_enable();
> +    return vcpu;
> +}
> 
>   /* Must be called with irq->irq_lock held */
>   static void vgic_hw_irq_spending(struct kvm_vcpu *vcpu, struct 
> vgic_irq *irq,
> @@ -212,7 +221,7 @@ void vgic_mmio_write_spending(struct kvm_vcpu *vcpu,
>                     gpa_t addr, unsigned int len,
>                     unsigned long val)
>   {
> -    bool is_uaccess = !kvm_get_running_vcpu();
> +    bool is_uaccess = !vgic_get_mmio_requester_vcpu();
>       u32 intid = VGIC_ADDR_TO_INTID(addr, 1);
>       int i;
>       unsigned long flags;
> @@ -265,7 +274,7 @@ void vgic_mmio_write_cpending(struct kvm_vcpu *vcpu,
>                     gpa_t addr, unsigned int len,
>                     unsigned long val)
>   {
> -    bool is_uaccess = !kvm_get_running_vcpu();
> +    bool is_uaccess = !vgic_get_mmio_requester_vcpu();
>       u32 intid = VGIC_ADDR_TO_INTID(addr, 1);
>       int i;
>       unsigned long flags;
> @@ -326,7 +335,7 @@ static void vgic_mmio_change_active(struct kvm_vcpu 
> *vcpu, struct vgic_irq *irq,
>                       bool active)
>   {
>       unsigned long flags;
> -    struct kvm_vcpu *requester_vcpu = kvm_get_running_vcpu();
> +    struct kvm_vcpu *requester_vcpu = vgic_get_mmio_requester_vcpu();
> 
>       raw_spin_lock_irqsave(&irq->irq_lock, flags);
> 
> 
> That's basically a revert of the offending code. The comment right above
> vgic_get_mmio_requester_vcpu() explains *why* this is valid, and why
> preempt_disable() is needed.

I see, thanks!

> 
> Can you please give it a shot?

Yes, it works for me:

Tested-by: Zenghui Yu <yuzenghui@huawei.com>


WARNING: multiple messages have this Message-ID (diff)
From: Zenghui Yu <yuzenghui@huawei.com>
To: Marc Zyngier <maz@kernel.org>
Cc: pbonzini@redhat.com, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org
Subject: Re: BUG: using __this_cpu_read() in preemptible [00000000] code
Date: Fri, 7 Feb 2020 18:19:17 +0800	[thread overview]
Message-ID: <3e90c020-e7f3-61f1-3731-a489df0b1d9c@huawei.com> (raw)
In-Reply-To: <828d3b538b7258f692f782b6798277cf@kernel.org>

Hi Marc,

On 2020/2/7 17:19, Marc Zyngier wrote:
> Hi Zenghui,
> 
> On 2020-02-07 09:00, Zenghui Yu wrote:
>> Hi,
>>
>> Running a latest preemptible kernel and some guests on it,
>> I got the following message,
>>
>> ---8<---
>>
>> [  630.031870] BUG: using __this_cpu_read() in preemptible [00000000]
>> code: qemu-system-aar/37270
>> [  630.031872] caller is kvm_get_running_vcpu+0x1c/0x38
>> [  630.031874] CPU: 32 PID: 37270 Comm: qemu-system-aar Kdump: loaded
>> Not tainted 5.5.0+
>> [  630.031876] Hardware name: Huawei TaiShan 2280 /BC11SPCD, BIOS 1.58
>> 10/29/2018
>> [  630.031876] Call trace:
>> [  630.031878]  dump_backtrace+0x0/0x200
>> [  630.031880]  show_stack+0x24/0x30
>> [  630.031882]  dump_stack+0xb0/0xf4
>> [  630.031884]  __this_cpu_preempt_check+0xc8/0xd0
>> [  630.031886]  kvm_get_running_vcpu+0x1c/0x38
>> [  630.031888]  vgic_mmio_change_active.isra.4+0x2c/0xe0
>> [  630.031890]  __vgic_mmio_write_cactive+0x80/0xc8
>> [  630.031892]  vgic_mmio_uaccess_write_cactive+0x3c/0x50
>> [  630.031894]  vgic_uaccess+0xcc/0x138
>> [  630.031896]  vgic_v3_redist_uaccess+0x7c/0xa8
>> [  630.031898]  vgic_v3_attr_regs_access+0x1a8/0x230
>> [  630.031901]  vgic_v3_set_attr+0x1b4/0x290
>> [  630.031903]  kvm_device_ioctl_attr+0xbc/0x110
>> [  630.031905]  kvm_device_ioctl+0xc4/0x108
>> [  630.031907]  ksys_ioctl+0xb4/0xd0
>> [  630.031909]  __arm64_sys_ioctl+0x28/0x38
>> [  630.031911]  el0_svc_common.constprop.1+0x7c/0x1a0
>> [  630.031913]  do_el0_svc+0x34/0xa0
>> [  630.031915]  el0_sync_handler+0x124/0x274
>> [  630.031916]  el0_sync+0x140/0x180
>>
>> ---8<---
>>
>> I'm now at commit 90568ecf561540fa330511e21fcd823b0c3829c6.
>>
>> And it looks like vgic_get_mmio_requester_vcpu() was broken by
>> 7495e22bb165 ("KVM: Move running VCPU from ARM to common code").
>>
>> Could anyone please have a look?
> 
> Here you go:
> 
> diff --git a/virt/kvm/arm/vgic/vgic-mmio.c b/virt/kvm/arm/vgic/vgic-mmio.c
> index d656ebd5f9d4..e1735f19c924 100644
> --- a/virt/kvm/arm/vgic/vgic-mmio.c
> +++ b/virt/kvm/arm/vgic/vgic-mmio.c
> @@ -190,6 +190,15 @@ unsigned long vgic_mmio_read_pending(struct 
> kvm_vcpu *vcpu,
>    * value later will give us the same value as we update the per-CPU 
> variable
>    * in the preempt notifier handlers.
>    */
> +static struct kvm_vcpu *vgic_get_mmio_requester_vcpu(void)
> +{
> +    struct kvm_vcpu *vcpu;
> +
> +    preempt_disable();
> +    vcpu = kvm_get_running_vcpu();
> +    preempt_enable();
> +    return vcpu;
> +}
> 
>   /* Must be called with irq->irq_lock held */
>   static void vgic_hw_irq_spending(struct kvm_vcpu *vcpu, struct 
> vgic_irq *irq,
> @@ -212,7 +221,7 @@ void vgic_mmio_write_spending(struct kvm_vcpu *vcpu,
>                     gpa_t addr, unsigned int len,
>                     unsigned long val)
>   {
> -    bool is_uaccess = !kvm_get_running_vcpu();
> +    bool is_uaccess = !vgic_get_mmio_requester_vcpu();
>       u32 intid = VGIC_ADDR_TO_INTID(addr, 1);
>       int i;
>       unsigned long flags;
> @@ -265,7 +274,7 @@ void vgic_mmio_write_cpending(struct kvm_vcpu *vcpu,
>                     gpa_t addr, unsigned int len,
>                     unsigned long val)
>   {
> -    bool is_uaccess = !kvm_get_running_vcpu();
> +    bool is_uaccess = !vgic_get_mmio_requester_vcpu();
>       u32 intid = VGIC_ADDR_TO_INTID(addr, 1);
>       int i;
>       unsigned long flags;
> @@ -326,7 +335,7 @@ static void vgic_mmio_change_active(struct kvm_vcpu 
> *vcpu, struct vgic_irq *irq,
>                       bool active)
>   {
>       unsigned long flags;
> -    struct kvm_vcpu *requester_vcpu = kvm_get_running_vcpu();
> +    struct kvm_vcpu *requester_vcpu = vgic_get_mmio_requester_vcpu();
> 
>       raw_spin_lock_irqsave(&irq->irq_lock, flags);
> 
> 
> That's basically a revert of the offending code. The comment right above
> vgic_get_mmio_requester_vcpu() explains *why* this is valid, and why
> preempt_disable() is needed.

I see, thanks!

> 
> Can you please give it a shot?

Yes, it works for me:

Tested-by: Zenghui Yu <yuzenghui@huawei.com>

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

  reply	other threads:[~2020-02-07 10:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-07  9:00 BUG: using __this_cpu_read() in preemptible [00000000] code Zenghui Yu
2020-02-07  9:00 ` Zenghui Yu
2020-02-07  9:19 ` Marc Zyngier
2020-02-07  9:19   ` Marc Zyngier
2020-02-07 10:19   ` Zenghui Yu [this message]
2020-02-07 10:19     ` Zenghui Yu
2020-02-07 10:25     ` Marc Zyngier
2020-02-07 10:25       ` Marc Zyngier
2020-02-07 16:18       ` Peter Xu
2020-02-07 16:18         ` Peter Xu
2020-02-07 16:25         ` Marc Zyngier
2020-02-07 16:25           ` Marc Zyngier

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=3e90c020-e7f3-61f1-3731-a489df0b1d9c@huawei.com \
    --to=yuzenghui@huawei.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=maz@kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.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 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.