* [PATCH] Loongson: Lemote-2F: Fixup of _rdmsr and _wrmsr
@ 2010-03-10 15:41 Wu Zhangjin
2010-03-11 0:17 ` David Daney
0 siblings, 1 reply; 3+ messages in thread
From: Wu Zhangjin @ 2010-03-10 15:41 UTC (permalink / raw)
To: Ralf Baechle; +Cc: linux-mips, Wu Zhangjin
From: Wu Zhangjin <wuzhangjin@gmail.com>
The _rdmsr, _wrmsr operation must be atomic to ensure the accessing to msr
address is what we want.
Without this patch, in some cases, the reboot operation(fs2f_reboot) defined in
arch/mips/loongson/lemote-2f/reset.c may fail for it called _rdmsr, _wrmsr but
may be interrupted/preempted by the other related operations and make the
_rdmsr get the wrong value or make the _wrmsr write a wrong value to an
unexpected target.
Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
---
arch/mips/pci/ops-loongson2.c | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/arch/mips/pci/ops-loongson2.c b/arch/mips/pci/ops-loongson2.c
index 2bb4057..1f93dfb 100644
--- a/arch/mips/pci/ops-loongson2.c
+++ b/arch/mips/pci/ops-loongson2.c
@@ -180,15 +180,20 @@ struct pci_ops loongson_pci_ops = {
};
#ifdef CONFIG_CS5536
+DEFINE_SPINLOCK(msr_lock);
void _rdmsr(u32 msr, u32 *hi, u32 *lo)
{
struct pci_bus bus = {
.number = PCI_BUS_CS5536
};
u32 devfn = PCI_DEVFN(PCI_IDSEL_CS5536, 0);
+ unsigned long flags;
+
+ spin_lock_irqsave(&msr_lock, flags);
loongson_pcibios_write(&bus, devfn, PCI_MSR_ADDR, 4, msr);
loongson_pcibios_read(&bus, devfn, PCI_MSR_DATA_LO, 4, lo);
loongson_pcibios_read(&bus, devfn, PCI_MSR_DATA_HI, 4, hi);
+ spin_unlock_irqrestore(&msr_lock, flags);
}
EXPORT_SYMBOL(_rdmsr);
@@ -198,9 +203,13 @@ void _wrmsr(u32 msr, u32 hi, u32 lo)
.number = PCI_BUS_CS5536
};
u32 devfn = PCI_DEVFN(PCI_IDSEL_CS5536, 0);
+ unsigned long flags;
+
+ spin_lock_irqsave(&msr_lock, flags);
loongson_pcibios_write(&bus, devfn, PCI_MSR_ADDR, 4, msr);
loongson_pcibios_write(&bus, devfn, PCI_MSR_DATA_LO, 4, lo);
loongson_pcibios_write(&bus, devfn, PCI_MSR_DATA_HI, 4, hi);
+ spin_unlock_irqrestore(&msr_lock, flags);
}
EXPORT_SYMBOL(_wrmsr);
#endif
--
1.7.0.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Loongson: Lemote-2F: Fixup of _rdmsr and _wrmsr
2010-03-10 15:41 [PATCH] Loongson: Lemote-2F: Fixup of _rdmsr and _wrmsr Wu Zhangjin
@ 2010-03-11 0:17 ` David Daney
2010-03-11 1:15 ` Wu Zhangjin
0 siblings, 1 reply; 3+ messages in thread
From: David Daney @ 2010-03-11 0:17 UTC (permalink / raw)
To: Wu Zhangjin, Ralf Baechle; +Cc: linux-mips
On 03/10/2010 07:41 AM, Wu Zhangjin wrote:
> From: Wu Zhangjin<wuzhangjin@gmail.com>
>
> The _rdmsr, _wrmsr operation must be atomic to ensure the accessing to msr
> address is what we want.
>
> Without this patch, in some cases, the reboot operation(fs2f_reboot) defined in
> arch/mips/loongson/lemote-2f/reset.c may fail for it called _rdmsr, _wrmsr but
> may be interrupted/preempted by the other related operations and make the
> _rdmsr get the wrong value or make the _wrmsr write a wrong value to an
> unexpected target.
>
> Signed-off-by: Wu Zhangjin<wuzhangjin@gmail.com>
> ---
> arch/mips/pci/ops-loongson2.c | 9 +++++++++
> 1 files changed, 9 insertions(+), 0 deletions(-)
>
> diff --git a/arch/mips/pci/ops-loongson2.c b/arch/mips/pci/ops-loongson2.c
> index 2bb4057..1f93dfb 100644
> --- a/arch/mips/pci/ops-loongson2.c
> +++ b/arch/mips/pci/ops-loongson2.c
> @@ -180,15 +180,20 @@ struct pci_ops loongson_pci_ops = {
> };
>
> #ifdef CONFIG_CS5536
> +DEFINE_SPINLOCK(msr_lock);
Should this be DEFINE_RAW_SPINLOCK instead?
David Daney
> void _rdmsr(u32 msr, u32 *hi, u32 *lo)
> {
> struct pci_bus bus = {
> .number = PCI_BUS_CS5536
> };
> u32 devfn = PCI_DEVFN(PCI_IDSEL_CS5536, 0);
> + unsigned long flags;
> +
> + spin_lock_irqsave(&msr_lock, flags);
> loongson_pcibios_write(&bus, devfn, PCI_MSR_ADDR, 4, msr);
> loongson_pcibios_read(&bus, devfn, PCI_MSR_DATA_LO, 4, lo);
> loongson_pcibios_read(&bus, devfn, PCI_MSR_DATA_HI, 4, hi);
> + spin_unlock_irqrestore(&msr_lock, flags);
> }
> EXPORT_SYMBOL(_rdmsr);
>
> @@ -198,9 +203,13 @@ void _wrmsr(u32 msr, u32 hi, u32 lo)
> .number = PCI_BUS_CS5536
> };
> u32 devfn = PCI_DEVFN(PCI_IDSEL_CS5536, 0);
> + unsigned long flags;
> +
> + spin_lock_irqsave(&msr_lock, flags);
> loongson_pcibios_write(&bus, devfn, PCI_MSR_ADDR, 4, msr);
> loongson_pcibios_write(&bus, devfn, PCI_MSR_DATA_LO, 4, lo);
> loongson_pcibios_write(&bus, devfn, PCI_MSR_DATA_HI, 4, hi);
> + spin_unlock_irqrestore(&msr_lock, flags);
> }
> EXPORT_SYMBOL(_wrmsr);
> #endif
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Loongson: Lemote-2F: Fixup of _rdmsr and _wrmsr
2010-03-11 0:17 ` David Daney
@ 2010-03-11 1:15 ` Wu Zhangjin
0 siblings, 0 replies; 3+ messages in thread
From: Wu Zhangjin @ 2010-03-11 1:15 UTC (permalink / raw)
To: David Daney; +Cc: Ralf Baechle, linux-mips
On Wed, 2010-03-10 at 16:17 -0800, David Daney wrote:
> On 03/10/2010 07:41 AM, Wu Zhangjin wrote:
> > From: Wu Zhangjin<wuzhangjin@gmail.com>
> >
> > The _rdmsr, _wrmsr operation must be atomic to ensure the accessing to msr
> > address is what we want.
> >
> > Without this patch, in some cases, the reboot operation(fs2f_reboot) defined in
> > arch/mips/loongson/lemote-2f/reset.c may fail for it called _rdmsr, _wrmsr but
> > may be interrupted/preempted by the other related operations and make the
> > _rdmsr get the wrong value or make the _wrmsr write a wrong value to an
> > unexpected target.
> >
> > Signed-off-by: Wu Zhangjin<wuzhangjin@gmail.com>
> > ---
> > arch/mips/pci/ops-loongson2.c | 9 +++++++++
> > 1 files changed, 9 insertions(+), 0 deletions(-)
> >
> > diff --git a/arch/mips/pci/ops-loongson2.c b/arch/mips/pci/ops-loongson2.c
> > index 2bb4057..1f93dfb 100644
> > --- a/arch/mips/pci/ops-loongson2.c
> > +++ b/arch/mips/pci/ops-loongson2.c
> > @@ -180,15 +180,20 @@ struct pci_ops loongson_pci_ops = {
> > };
> >
> > #ifdef CONFIG_CS5536
> > +DEFINE_SPINLOCK(msr_lock);
>
>
> Should this be DEFINE_RAW_SPINLOCK instead?
>
It should be, thanks!
Regards,
Wu Zhangjin
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-03-11 1:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-10 15:41 [PATCH] Loongson: Lemote-2F: Fixup of _rdmsr and _wrmsr Wu Zhangjin
2010-03-11 0:17 ` David Daney
2010-03-11 1:15 ` Wu Zhangjin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).