All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@gmail.com>
To: Suresh Thiagarajan <Suresh.Thiagarajan@pmcs.com>
Cc: Oleg Nesterov <oleg@redhat.com>, Ingo Molnar <mingo@kernel.org>,
	Jason Seba <jason.seba42@gmail.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Tomas Henzl <thenzl@redhat.com>, Jack Wang <xjtuwjp@gmail.com>,
	Viswas G <Viswas.G@pmcs.com>,
	"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
	"JBottomley@parallels.com" <JBottomley@parallels.com>,
	Vasanthalakshmi Tharmarajan 
	<Vasanthalakshmi.Tharmarajan@pmcs.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: spinlock_irqsave() && flags (Was: pm80xx: Spinlock fix)
Date: Fri, 3 Jan 2014 12:02:06 -0800	[thread overview]
Message-ID: <CAA9_cme0MZvz_6VXXpP3ATkR6p_OznHpVtyyNxA+HK2iBvb7Rg@mail.gmail.com> (raw)
In-Reply-To: <CE2C58F938F4C44EA74FFF880BAA7E5E1CD22E04@BBYEXM01.pmc-sierra.internal>

On Thu, Jan 2, 2014 at 2:31 AM, Suresh Thiagarajan
<Suresh.Thiagarajan@pmcs.com> wrote:
>
>
> On Fri, Dec 27, 2013 at 9:48 PM, Oleg Nesterov <oleg@redhat.com> wrote:
>> On 12/24, Suresh Thiagarajan wrote:
>>>
>>> Below is a small pseudo code on protecting/serializing the flag for global access.
>>> struct temp
>>> {
>>>       ...
>>>       spinlock_t lock;
>>>       unsigned long lock_flags;
>>> };
>>> void my_lock(struct temp *t)
>>> {
>>>                unsigned long flag; // thread-private variable as suggested
>>>                spin_lock_irqsave(&t->lock, flag);
>>>                t->lock_flags = flag; //updating inside critical section now to serialize the access to flag
>>> }
>>>
>>> void my_unlock(struct temp *t)
>>> {
>>>                unsigned long flag = t->lock_flags;
>>>                t->lock_flags = 0;  //clearing it before getting out of critical section
>>>                spin_unlock_irqrestore(&t->lock, flag);
>>> }
>>
>> Yes, this should work as a quick fix. And you do not need to clear ->lock_flags
>> in my_unlock().
>>
>> But when I look at original patch again, I no longer understand why do
>> you need pm8001_ha->lock_flags at all. Of course I do not understand this
>> code, I am sure I missed something, but at first glance it seems that only
>> this sequence
>>
>>         spin_unlock_irq(&pm8001_ha->lock);
>>         t->task_done(t);
>>         spin_lock_irq(&pm8001_ha->lock);
>>
>> should be fixed?
>>
>> If yes, why you can't simply do spin_unlock() + spin_lock() around
>> t->task_done() ? This won't enable irqs, but spin_unlock_irqrestore()
>> doesn't necessarily enables irqs too, so ->task_done() can run with
>> irqs disabled?
>>
>> And note that the pattern above has a lot of users, perhaps it makes
>> sense to start with something like the patch below?
>
> Thanks James, Oleg and all for your inputs.
> Will start with review and testing this patch and then work/investigate to keep shortest and clearest critical
> section so that we can have the lock and unlock within the same routine.
>

Fwiw we solved this in libsas a while back with a similar pattern
proposed by Oleg:

unsigned long flags;

local_irq_save(flags);
spin_unlock(lock);
...
spin_lock_lock(lock);
local_irq_restore(flags);

See commit 312d3e56119a "[SCSI] libsas: remove ata_port.lock
management duties from lldds"

--
Dan

  reply	other threads:[~2014-01-03 20:02 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-18 11:28 [PATCH] pm80xx: Spinlock fix Viswas G
2013-12-23 13:07 ` Tomas Henzl
2013-12-23 13:32   ` Jack Wang
2013-12-23 13:45     ` Suresh Thiagarajan
2013-12-23 14:55       ` Jason Seba
2013-12-23 15:06         ` Jack Wang
2013-12-23 15:28           ` Tomas Henzl
2013-12-23 15:33             ` Jason Seba
2013-12-23 15:36               ` Tomas Henzl
2013-12-23 16:34               ` Oleg Nesterov
2013-12-23 17:27                 ` spinlock_irqsave() && flags (Was: pm80xx: Spinlock fix) Oleg Nesterov
2013-12-23 17:27                   ` Oleg Nesterov
2013-12-23 18:12                   ` Linus Torvalds
2013-12-23 18:12                     ` Linus Torvalds
2013-12-23 18:24                     ` Oleg Nesterov
2013-12-23 18:24                       ` Oleg Nesterov
2013-12-23 18:43                       ` Linus Torvalds
2013-12-23 18:43                         ` Linus Torvalds
2013-12-23 18:23                   ` Ingo Molnar
2013-12-23 18:23                     ` Ingo Molnar
2013-12-23 18:33                     ` Oleg Nesterov
2013-12-23 18:33                       ` Oleg Nesterov
2013-12-24  8:29                       ` Ingo Molnar
2013-12-24  8:29                         ` Ingo Molnar
2013-12-24  9:13                         ` Suresh Thiagarajan
2013-12-24 17:29                           ` James Bottomley
2013-12-24 17:29                             ` James Bottomley
2013-12-27 16:18                           ` Oleg Nesterov
2013-12-27 16:18                             ` Oleg Nesterov
2014-01-02 10:31                             ` Suresh Thiagarajan
2014-01-03 20:02                               ` Dan Williams [this message]
2014-01-03 20:02                                 ` Dan Williams
2013-12-23 15:38             ` [PATCH] pm80xx: Spinlock fix Oleg Nesterov

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=CAA9_cme0MZvz_6VXXpP3ATkR6p_OznHpVtyyNxA+HK2iBvb7Rg@mail.gmail.com \
    --to=dan.j.williams@gmail.com \
    --cc=JBottomley@parallels.com \
    --cc=Suresh.Thiagarajan@pmcs.com \
    --cc=Vasanthalakshmi.Tharmarajan@pmcs.com \
    --cc=Viswas.G@pmcs.com \
    --cc=jason.seba42@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    --cc=thenzl@redhat.com \
    --cc=torvalds@linux-foundation.org \
    --cc=xjtuwjp@gmail.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.