From: Marc Zyngier <maz@kernel.org>
To: Reiji Watanabe <reijiw@google.com>
Cc: Oliver Upton <oliver.upton@linux.dev>,
kvmarm@lists.linux.dev, kvm@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
James Morse <james.morse@arm.com>,
Alexandru Elisei <alexandru.elisei@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Ricardo Koller <ricarkol@google.com>,
Jing Zhang <jingzhangos@google.com>,
Raghavendra Rao Anata <rananta@google.com>,
Will Deacon <will@kernel.org>
Subject: Re: [PATCH v1 1/2] KVM: arm64: Acquire mp_state_lock in kvm_arch_vcpu_ioctl_vcpu_init()
Date: Thu, 20 Apr 2023 09:16:43 +0100 [thread overview]
Message-ID: <86y1mnj7dg.wl-maz@kernel.org> (raw)
In-Reply-To: <20230420021302.iyl3pqo3lg6lpabv@google.com>
On Thu, 20 Apr 2023 03:13:02 +0100,
Reiji Watanabe <reijiw@google.com> wrote:
>
> Hi Marc,
>
> On Wed, Apr 19, 2023 at 08:12:45AM +0100, Marc Zyngier wrote:
> > On Wed, 19 Apr 2023 03:18:51 +0100,
> > Reiji Watanabe <reijiw@google.com> wrote:
> > > kvm_arch_vcpu_ioctl_vcpu_init() doesn't acquire mp_state_lock
> > > when setting the mp_state to KVM_MP_STATE_RUNNABLE. Fix the
> > > code to acquire the lock.
> > >
> > > Signed-off-by: Reiji Watanabe <reijiw@google.com>
> > > ---
> > > arch/arm64/kvm/arm.c | 5 ++++-
> > > 1 file changed, 4 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
> > > index fbafcbbcc463..388aa4f18f21 100644
> > > --- a/arch/arm64/kvm/arm.c
> > > +++ b/arch/arm64/kvm/arm.c
> > > @@ -1244,8 +1244,11 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu,
> > > */
> > > if (test_bit(KVM_ARM_VCPU_POWER_OFF, vcpu->arch.features))
> > > kvm_arm_vcpu_power_off(vcpu);
> > > - else
> > > + else {
> > > + spin_lock(&vcpu->arch.mp_state_lock);
> > > WRITE_ONCE(vcpu->arch.mp_state.mp_state, KVM_MP_STATE_RUNNABLE);
> > > + spin_unlock(&vcpu->arch.mp_state_lock);
> > > + }
> > >
> > > return 0;
> > > }
> >
> > I'm not entirely convinced that this fixes anything. What does the
> > lock hazard against given that the write is atomic? But maybe a
>
> It appears that kvm_psci_vcpu_on() expects the vCPU's mp_state
> to not be changed by holding the lock. Although I don't think this
> code practically causes any real issues now, I am a little concerned
> about leaving one instance that updates mpstate without acquiring the
> lock, in terms of future maintenance, as holding the lock won't prevent
> mp_state from being updated.
>
> What do you think ?
Right, fair enough. It is probably better to take the lock and not
have to think of this sort of things... I'm becoming more lazy by the
minute!
>
> > slightly more readable of this would be to expand the critical section
> > this way:
> >
> > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
> > index 4ec888fdd4f7..bb21d0c25de7 100644
> > --- a/arch/arm64/kvm/arm.c
> > +++ b/arch/arm64/kvm/arm.c
> > @@ -1246,11 +1246,15 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu,
> > /*
> > * Handle the "start in power-off" case.
> > */
> > + spin_lock(&vcpu->arch.mp_state_lock);
> > +
> > if (test_bit(KVM_ARM_VCPU_POWER_OFF, vcpu->arch.features))
> > - kvm_arm_vcpu_power_off(vcpu);
> > + __kvm_arm_vcpu_power_off(vcpu);
> > else
> > WRITE_ONCE(vcpu->arch.mp_state.mp_state, KVM_MP_STATE_RUNNABLE);
> >
> > + spin_unlock(&vcpu->arch.mp_state_lock);
> > +
> > return 0;
> > }
> >
> > Thoughts?
>
> Yes, it looks better!
Cool. I've applied this change to your patch, applied the series to
the lock inversion branch, and remerged the branch in -next.
We're getting there! ;-)
M.
--
Without deviation from the norm, progress is not possible.
WARNING: multiple messages have this Message-ID (diff)
From: Marc Zyngier <maz@kernel.org>
To: Reiji Watanabe <reijiw@google.com>
Cc: Oliver Upton <oliver.upton@linux.dev>,
kvmarm@lists.linux.dev, kvm@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
James Morse <james.morse@arm.com>,
Alexandru Elisei <alexandru.elisei@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Ricardo Koller <ricarkol@google.com>,
Jing Zhang <jingzhangos@google.com>,
Raghavendra Rao Anata <rananta@google.com>,
Will Deacon <will@kernel.org>
Subject: Re: [PATCH v1 1/2] KVM: arm64: Acquire mp_state_lock in kvm_arch_vcpu_ioctl_vcpu_init()
Date: Thu, 20 Apr 2023 09:16:43 +0100 [thread overview]
Message-ID: <86y1mnj7dg.wl-maz@kernel.org> (raw)
In-Reply-To: <20230420021302.iyl3pqo3lg6lpabv@google.com>
On Thu, 20 Apr 2023 03:13:02 +0100,
Reiji Watanabe <reijiw@google.com> wrote:
>
> Hi Marc,
>
> On Wed, Apr 19, 2023 at 08:12:45AM +0100, Marc Zyngier wrote:
> > On Wed, 19 Apr 2023 03:18:51 +0100,
> > Reiji Watanabe <reijiw@google.com> wrote:
> > > kvm_arch_vcpu_ioctl_vcpu_init() doesn't acquire mp_state_lock
> > > when setting the mp_state to KVM_MP_STATE_RUNNABLE. Fix the
> > > code to acquire the lock.
> > >
> > > Signed-off-by: Reiji Watanabe <reijiw@google.com>
> > > ---
> > > arch/arm64/kvm/arm.c | 5 ++++-
> > > 1 file changed, 4 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
> > > index fbafcbbcc463..388aa4f18f21 100644
> > > --- a/arch/arm64/kvm/arm.c
> > > +++ b/arch/arm64/kvm/arm.c
> > > @@ -1244,8 +1244,11 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu,
> > > */
> > > if (test_bit(KVM_ARM_VCPU_POWER_OFF, vcpu->arch.features))
> > > kvm_arm_vcpu_power_off(vcpu);
> > > - else
> > > + else {
> > > + spin_lock(&vcpu->arch.mp_state_lock);
> > > WRITE_ONCE(vcpu->arch.mp_state.mp_state, KVM_MP_STATE_RUNNABLE);
> > > + spin_unlock(&vcpu->arch.mp_state_lock);
> > > + }
> > >
> > > return 0;
> > > }
> >
> > I'm not entirely convinced that this fixes anything. What does the
> > lock hazard against given that the write is atomic? But maybe a
>
> It appears that kvm_psci_vcpu_on() expects the vCPU's mp_state
> to not be changed by holding the lock. Although I don't think this
> code practically causes any real issues now, I am a little concerned
> about leaving one instance that updates mpstate without acquiring the
> lock, in terms of future maintenance, as holding the lock won't prevent
> mp_state from being updated.
>
> What do you think ?
Right, fair enough. It is probably better to take the lock and not
have to think of this sort of things... I'm becoming more lazy by the
minute!
>
> > slightly more readable of this would be to expand the critical section
> > this way:
> >
> > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
> > index 4ec888fdd4f7..bb21d0c25de7 100644
> > --- a/arch/arm64/kvm/arm.c
> > +++ b/arch/arm64/kvm/arm.c
> > @@ -1246,11 +1246,15 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu,
> > /*
> > * Handle the "start in power-off" case.
> > */
> > + spin_lock(&vcpu->arch.mp_state_lock);
> > +
> > if (test_bit(KVM_ARM_VCPU_POWER_OFF, vcpu->arch.features))
> > - kvm_arm_vcpu_power_off(vcpu);
> > + __kvm_arm_vcpu_power_off(vcpu);
> > else
> > WRITE_ONCE(vcpu->arch.mp_state.mp_state, KVM_MP_STATE_RUNNABLE);
> >
> > + spin_unlock(&vcpu->arch.mp_state_lock);
> > +
> > return 0;
> > }
> >
> > Thoughts?
>
> Yes, it looks better!
Cool. I've applied this change to your patch, applied the series to
the lock inversion branch, and remerged the branch in -next.
We're getting there! ;-)
M.
--
Without deviation from the norm, progress is not possible.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2023-04-20 8:16 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-19 2:18 [PATCH v1 0/2] KVM: arm64: Fix bugs related to mp_state updates Reiji Watanabe
2023-04-19 2:18 ` Reiji Watanabe
2023-04-19 2:18 ` [PATCH v1 1/2] KVM: arm64: Acquire mp_state_lock in kvm_arch_vcpu_ioctl_vcpu_init() Reiji Watanabe
2023-04-19 2:18 ` Reiji Watanabe
2023-04-19 7:12 ` Marc Zyngier
2023-04-19 7:12 ` Marc Zyngier
2023-04-20 2:13 ` Reiji Watanabe
2023-04-20 2:13 ` Reiji Watanabe
2023-04-20 8:16 ` Marc Zyngier [this message]
2023-04-20 8:16 ` Marc Zyngier
2023-04-21 3:27 ` Reiji Watanabe
2023-04-21 3:27 ` Reiji Watanabe
2023-04-19 2:18 ` [PATCH v1 2/2] KVM: arm64: Have kvm_psci_vcpu_on() use WRITE_ONCE() to update mp_state Reiji Watanabe
2023-04-19 2:18 ` Reiji Watanabe
2023-04-20 8:08 ` [PATCH v1 0/2] KVM: arm64: Fix bugs related to mp_state updates Marc Zyngier
2023-04-20 8:08 ` 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=86y1mnj7dg.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=alexandru.elisei@arm.com \
--cc=james.morse@arm.com \
--cc=jingzhangos@google.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=oliver.upton@linux.dev \
--cc=pbonzini@redhat.com \
--cc=rananta@google.com \
--cc=reijiw@google.com \
--cc=ricarkol@google.com \
--cc=suzuki.poulose@arm.com \
--cc=will@kernel.org \
--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 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.