From: "Roedel, Joerg" <Joerg.Roedel@amd.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Borislav Petkov <bp@alien8.de>,
Greg Kroah-Hartman <gregkh@suse.de>,
Sarah Sharp <sarah.a.sharp@linux.intel.com>,
"Xu, Andiry" <Andiry.Xu@amd.com>,
USB list <linux-usb@vger.kernel.org>,
Kernel development list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v5] USB host: Fix lockdep warning in AMD PLL quirk
Date: Mon, 11 Apr 2011 18:37:11 +0200 [thread overview]
Message-ID: <20110411163711.GA20607@amd.com> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1104111221000.1975-100000@iolanthe.rowland.org>
On Mon, Apr 11, 2011 at 12:25:07PM -0400, Alan Stern wrote:
> On Mon, 11 Apr 2011, Roedel, Joerg wrote:
>
> > > > +commit:
> > > > +
> > > > + spin_lock_irqsave(&amd_lock, flags);
> > > > + if (amd_chipset.probe_count > 0) {
> > > > + /* race - someone else was faster - drop devices */
> > > > +
> > > > + /* Mark that we where here */
> > > > + amd_chipset.probe_count++;
> > >
> > > This line should be moved above the "if" statement, since you always
> > > want to increment the count.
> >
> > No, probe_count can't be incremented here because the probe is not
> > finished yet.
>
> I don't follow you. Sure it is finished; this is the "commit" part of
> the probe.
Nevermind, I thought you were refering to the spin-locked part at the
beginning of the function.
> > If another thread jumps in after the lock is released and
> > detects probe_count > 0 while the probe hasn't happened the quirk will
> > fail. So we need to make sure that amd_chipset.probe_count does not
> > become > 0 before the probe is finished.
>
> I meant the increment should be done before the "if" statement but
> after the spin_lock_irqsave(). That way nobody else can jump in at the
> wrong time.
In the real commit case the
amd_chipset = info;
line will overwrite the increment if the probe is done before the
if-statement. So incrementing amd_chipset.probe_count directly only
matters for the case where we detected a race.
> > > > + ret = amd_chipset.probe_result;
> > > > +
> > > > + spin_unlock_irqrestore(&amd_lock, flags);
> > > > +
> > > > + if (info.nb_dev)
> > > > + pci_dev_put(info.nb_dev);
> > > > + if (info.smbus_dev)
> > > > + pci_dev_put(info.smbus_dev);
> > > > +
> > > > + } else {
> > > > + /* no race - commit the result */
> > > > + info.probe_count++;
> > >
> > > This isn't right, because info.probe_count was initialized to 0. Maybe
> > > amd_chipset.probe_count should be made into a separate variable, not a
> > > part of the structure, like amd_lock.
> >
> > The purpose of the struct is structuring of data. In theory all of its
> > members could be turned into global variables. The amd_lock is different
> > because it does not only protect the struct but also access to the
> > hardware while the quirk is applied/unapplied.
>
> Do it however you prefer. But as it stands now, the patch is wrong.
Hmm, I see how it can be done differently, but no real bug.
Joerg
--
AMD Operating System Research Center
Advanced Micro Devices GmbH Einsteinring 24 85609 Dornach
General Managers: Alberto Bozzo, Andrew Bowd
Registration: Dornach, Landkr. Muenchen; Registerger. Muenchen, HRB Nr. 43632
next prev parent reply other threads:[~2011-04-11 16:38 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-06 11:21 [PATCH] USB host: Fix lockdep warning in AMD PLL quirk Joerg Roedel
2011-04-06 15:16 ` Alan Stern
2011-04-06 15:25 ` Roedel, Joerg
2011-04-07 2:21 ` Xu, Andiry
2011-04-07 7:50 ` Roedel, Joerg
2011-04-07 9:01 ` Xu, Andiry
2011-04-07 13:00 ` Roedel, Joerg
2011-04-07 15:01 ` Alan Stern
2011-04-07 20:22 ` Joerg Roedel
2011-04-08 14:26 ` [PATCH v4] " Joerg Roedel
2011-04-08 14:52 ` Alan Stern
2011-04-08 15:09 ` Roedel, Joerg
2011-04-08 16:30 ` Alan Stern
2011-04-07 8:26 ` [PATCH] " Joerg Roedel
2011-04-07 9:58 ` Xu, Andiry
2011-04-07 12:52 ` Roedel, Joerg
2011-04-07 13:14 ` Joerg Roedel
2011-04-11 6:26 ` Borislav Petkov
2011-04-11 6:43 ` Roedel, Joerg
2011-04-11 6:59 ` [PATCH v5] " Roedel, Joerg
2011-04-11 10:00 ` Sergei Shtylyov
2011-04-11 15:49 ` Alan Stern
2011-04-11 16:16 ` Roedel, Joerg
2011-04-11 16:25 ` Alan Stern
2011-04-11 16:37 ` Roedel, Joerg [this message]
2011-04-11 17:05 ` Alan Stern
2011-04-12 6:41 ` [PATCH v6] " Roedel, Joerg
2011-04-12 10:59 ` Sergei Shtylyov
2011-04-12 11:13 ` Roedel, Joerg
2011-04-13 6:38 ` [PATCH v7] " Roedel, Joerg
2011-04-13 14:44 ` Alan Stern
2011-04-07 14:35 ` [PATCH] " Alan Stern
2011-04-07 15:00 ` Roedel, Joerg
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=20110411163711.GA20607@amd.com \
--to=joerg.roedel@amd.com \
--cc=Andiry.Xu@amd.com \
--cc=bp@alien8.de \
--cc=gregkh@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=sarah.a.sharp@linux.intel.com \
--cc=stern@rowland.harvard.edu \
/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.