From: Paul Mackerras <paulus@samba.org>
To: Liu ping fan <kernelfans@gmail.com>
Cc: linuxppc-dev@lists.ozlabs.org, Alexander Graf <agraf@suse.de>,
kvm-ppc@vger.kernel.org
Subject: Re: [PATCH 2/3] powerpc/kvm: fix rare but potential deadlock scene
Date: Wed, 06 Nov 2013 11:18:41 +0000 [thread overview]
Message-ID: <20131106111841.GA22605@iris.ozlabs.ibm.com> (raw)
In-Reply-To: <CAFgQCTsxEAqMDt=zfFMhEG2CZ6G=QpH+OsPvJkvjFU7GkDOcXQ@mail.gmail.com>
On Wed, Nov 06, 2013 at 02:02:07PM +0800, Liu ping fan wrote:
> On Wed, Nov 6, 2013 at 1:04 PM, Paul Mackerras <paulus@samba.org> wrote:
> > On Tue, Nov 05, 2013 at 03:42:43PM +0800, Liu Ping Fan wrote:
> >> Since kvmppc_hv_find_lock_hpte() is called from both virtmode and
> >> realmode, so it can trigger the deadlock.
> >
> > Good catch, we should have preemption disabled while ever we have a
> > HPTE locked.
> >
> >> @@ -474,8 +474,10 @@ static int kvmppc_mmu_book3s_64_hv_xlate(struct kvm_vcpu *vcpu, gva_t eaddr,
> >> }
> >>
> >> /* Find the HPTE in the hash table */
> >> + preempt_disable();
> >> index = kvmppc_hv_find_lock_hpte(kvm, eaddr, slb_v,
> >> HPTE_V_VALID | HPTE_V_ABSENT);
> >> + preempt_enable();
> >
> > Which means we need to add the preempt_enable after unlocking the
> > HPTE, not here.
> >
> Yes. Sorry, but I am not sure about whether we can call
> preempt_disable/enable() in realmode. I think since thread_info is
> allocated with linear address, so we can use preempt_disable/enable()
> inside kvmppc_hv_find_lock_hpte(), right?
Your analysis correctly pointed out that we can get a deadlock if we
can be preempted while holding a lock on a HPTE. That means that we
have to disable preemption before taking an HPTE lock and keep it
disabled until after we unlock the HPTE. Since the point of
kvmppc_hv_find_lock_hpte() is to lock the HPTE and return with it
locked, we can't have the preempt_enable() inside it. The
preempt_enable() has to come after we have unlocked the HPTE. That is
also why we can't have the preempt_enable() where your patch put it;
it needs to be about 9 lines further down, after the statement
hptep[0] = v. (We also need to make sure to re-enable preemption in
the index < 0 case.)
Regards,
Paul.
WARNING: multiple messages have this Message-ID (diff)
From: Paul Mackerras <paulus@samba.org>
To: Liu ping fan <kernelfans@gmail.com>
Cc: linuxppc-dev@lists.ozlabs.org, Alexander Graf <agraf@suse.de>,
kvm-ppc@vger.kernel.org
Subject: Re: [PATCH 2/3] powerpc/kvm: fix rare but potential deadlock scene
Date: Wed, 6 Nov 2013 22:18:41 +1100 [thread overview]
Message-ID: <20131106111841.GA22605@iris.ozlabs.ibm.com> (raw)
In-Reply-To: <CAFgQCTsxEAqMDt=zfFMhEG2CZ6G=QpH+OsPvJkvjFU7GkDOcXQ@mail.gmail.com>
On Wed, Nov 06, 2013 at 02:02:07PM +0800, Liu ping fan wrote:
> On Wed, Nov 6, 2013 at 1:04 PM, Paul Mackerras <paulus@samba.org> wrote:
> > On Tue, Nov 05, 2013 at 03:42:43PM +0800, Liu Ping Fan wrote:
> >> Since kvmppc_hv_find_lock_hpte() is called from both virtmode and
> >> realmode, so it can trigger the deadlock.
> >
> > Good catch, we should have preemption disabled while ever we have a
> > HPTE locked.
> >
> >> @@ -474,8 +474,10 @@ static int kvmppc_mmu_book3s_64_hv_xlate(struct kvm_vcpu *vcpu, gva_t eaddr,
> >> }
> >>
> >> /* Find the HPTE in the hash table */
> >> + preempt_disable();
> >> index = kvmppc_hv_find_lock_hpte(kvm, eaddr, slb_v,
> >> HPTE_V_VALID | HPTE_V_ABSENT);
> >> + preempt_enable();
> >
> > Which means we need to add the preempt_enable after unlocking the
> > HPTE, not here.
> >
> Yes. Sorry, but I am not sure about whether we can call
> preempt_disable/enable() in realmode. I think since thread_info is
> allocated with linear address, so we can use preempt_disable/enable()
> inside kvmppc_hv_find_lock_hpte(), right?
Your analysis correctly pointed out that we can get a deadlock if we
can be preempted while holding a lock on a HPTE. That means that we
have to disable preemption before taking an HPTE lock and keep it
disabled until after we unlock the HPTE. Since the point of
kvmppc_hv_find_lock_hpte() is to lock the HPTE and return with it
locked, we can't have the preempt_enable() inside it. The
preempt_enable() has to come after we have unlocked the HPTE. That is
also why we can't have the preempt_enable() where your patch put it;
it needs to be about 9 lines further down, after the statement
hptep[0] = v. (We also need to make sure to re-enable preemption in
the index < 0 case.)
Regards,
Paul.
next prev parent reply other threads:[~2013-11-06 11:18 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-05 7:42 [PATCH 1/3] powerpc/kvm: simplify the entering logic for secondary thread Liu Ping Fan
2013-11-05 7:42 ` Liu Ping Fan
2013-11-05 7:42 ` [PATCH 2/3] powerpc/kvm: fix rare but potential deadlock scene Liu Ping Fan
2013-11-05 7:42 ` Liu Ping Fan
2013-11-06 5:04 ` Paul Mackerras
2013-11-06 5:04 ` Paul Mackerras
2013-11-06 6:02 ` Liu ping fan
2013-11-06 6:02 ` Liu ping fan
2013-11-06 11:18 ` Paul Mackerras [this message]
2013-11-06 11:18 ` Paul Mackerras
2013-11-07 2:36 ` Liu ping fan
2013-11-07 2:36 ` Liu ping fan
2013-11-05 7:42 ` [PATCH 3/3] powerpc/kvm: remove redundant assignment Liu Ping Fan
2013-11-05 7:42 ` Liu Ping Fan
2013-11-06 5:04 ` Paul Mackerras
2013-11-06 5:04 ` Paul Mackerras
2013-11-06 11:24 ` Alexander Graf
2013-11-06 11:24 ` Alexander Graf
2013-11-06 19:58 ` Benjamin Herrenschmidt
2013-11-06 19:58 ` Benjamin Herrenschmidt
2013-11-07 7:52 ` Alexander Graf
2013-11-07 7:52 ` Alexander Graf
2013-11-07 7:55 ` Benjamin Herrenschmidt
2013-11-07 7:55 ` Benjamin Herrenschmidt
2013-11-07 8:14 ` Alexander Graf
2013-11-07 8:14 ` Alexander Graf
2013-11-07 8:36 ` Benjamin Herrenschmidt
2013-11-07 8:36 ` Benjamin Herrenschmidt
2013-11-06 5:01 ` [PATCH 1/3] powerpc/kvm: simplify the entering logic for secondary thread Paul Mackerras
2013-11-06 5:01 ` Paul Mackerras
2013-11-06 7:26 ` Liu ping fan
2013-11-06 7:26 ` Liu ping fan
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=20131106111841.GA22605@iris.ozlabs.ibm.com \
--to=paulus@samba.org \
--cc=agraf@suse.de \
--cc=kernelfans@gmail.com \
--cc=kvm-ppc@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
/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.