public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: ebiederman@lnxi.com (Eric W. Biederman)
To: Roland Dreier <roland@topspin.com>
Cc: ebiederm@xmission.com (Eric W. Biederman),
	Jeff Garzik <jgarzik@pobox.com>, Andrew Morton <akpm@osdl.org>,
	Robert.Picco@hp.com, linux-kernel@vger.kernel.org,
	venkatesh.pallipadi@intel.com, Greg KH <greg@kroah.com>
Subject: Re: readq/writeq on 32bit machines
Date: 18 May 2004 17:01:14 -0600	[thread overview]
Message-ID: <m3hdudtk5h.fsf@maxwell.lnxi.com> (raw)
In-Reply-To: <52fz9xpp5l.fsf@topspin.com>

Roland Dreier <roland@topspin.com> writes:

> Thanks for posting this Eric... I sent a less detailed reply yesterday
> (pointing out that atomic writeq is needed sometimes) but it seems to
> have gotten eaten.
> 
>     Eric> This issue came last night on the openib list.  The driver
>     Eric> currently rolls it's own version of writeq and in the case
>     Eric> where there is not an atomic 64bit write it needs to a
>     Eric> spinlock to make certain things don't get out of order.  The
>     Eric> driver fails with the current 2 writel() version.
> 
>     Eric> Here is an SSE version, that should not be to intrusive.
>     Eric> According to intel's docs a 64bit aligned 64bit write is
>     Eric> atomic all of the way back to the Pentium.  If
>     Eric> kernel_fpu_begin/kernel_fpu_end are safe in interrupt
>     Eric> context we can do an atomic/correct version of writeq for
>     Eric> x86 processors that don't support sse as well.  Although I
>     Eric> don't know if we want to.
> 
> 	static inline void __raw_writeq(u64 val, unsigned long dest)
> 	{
> 		unsigned long cr0;
> 		u64 xmmsave __attribute__((aligned(8));
> 		preempt_disable();
> 	        cr0 = read_cr0();
> 		clts();
> 	        asm volatile (
> 			"movlps %%xmm0,(%0); \n\t"
> 			"movlps (%2),%%xmm0; \n\t"
> 			"movlps %%xmm0,(%1); \n\t"
> 			"movlps (%0),%%xmm0; \n\t"
> 			: =m (&xmmsave), "=m" ((void *)dest)
> 			: "m" (&val)
> 			);
> 		write_cr0(cr0);
> 		preempt_enable();
> 	}
> 
> This is pretty much what I wrote in the above-mentioned openib
> driver.  However I'm worried about using 
> 
>         u64 xmmsave __attribute__((aligned(8));
> 
> for a stack variable.  I don't think gcc respects the alignment
> attribute for stack variables (I've had a problem in the past using
> movdqa to a stack variable, even if I do __attribute__((aligned(16))).
> If we're sure gcc aligns xmmsave properly, stick a comment in and
> leave out the __attribute__; if not then I think we have to do

I picked that up out of xor.h where the raid code does something similar,
so if there is a problem it needs to be fixed there as well.

> 
>         u8 xmmsave[8 + 7];
> 
> and then use ~7 & (xmmsave + 7).
> 
>     Eric> Thinking about this a little more we might be able to get
>     Eric> away with.
> 
> 	static inline void __raw_writeq(u64 val, unsigned long dest)
> 	{
> 		unsigned long flags;
> 	        local_irq_save(flags);
> 		writel(val & 0xffffffff, addr);
> 		writel(val >> 32, addr + 4);
> 	        irq_restore(flags);
> 	}
> 
> I don't think this is good enough on SMP.  In the openib case, it's
> entirely possible for one CPU to be ringing a (64-bit) work queue
> doorbell at the same time as another CPU is ringing a (64-bit)
> completion queue doorbell, and if the 32-bit halves of those doorbells
> get interleaved, the hardware gets confused.  Maybe there's some magic
> aspect of the PC hardware that ensures this can't happen but I'd hate
> to count on it without some very good documentation.

Right.  It does make the window incredibly small though.  I am even
nervous that the version with a spinlock might break, if something really
needs an atomic guarantee.  


Eric

  parent reply	other threads:[~2004-05-18 23:01 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-13 22:34 [PATCH] HPET driver Robert Picco
2004-05-13 23:17 ` Jeff Garzik
2004-05-13 23:42   ` Andrew Morton
2004-05-13 23:46     ` Andrew Morton
2004-05-13 23:53       ` HPET docs Jeff Garzik
2004-05-13 23:49     ` [PATCH] HPET driver Jeff Garzik
2004-05-14 11:19       ` Vojtech Pavlik
2004-05-14 16:59         ` Jeff Garzik
2004-05-17 22:33   ` Robert Picco
2004-05-17 22:39     ` Jeff Garzik
2004-05-17 22:43     ` Jeff Garzik
2004-05-17 23:05     ` Andrew Morton
2004-05-17 23:06       ` Jeff Garzik
2004-05-17 23:12       ` Andrew Morton
2004-05-17 23:18         ` Jeff Garzik
2004-05-17 23:25           ` Russell King
2004-05-17 23:41             ` Jeff Garzik
2004-05-17 23:33           ` Andrew Morton
2004-05-17 23:42             ` Jeff Garzik
2004-05-18  1:46               ` Andrew Morton
2004-05-18  1:59                 ` Jeff Garzik
     [not found]                   ` <m1vfit3939.fsf_-_@ebiederm.dsl.xmission.com>
     [not found]                     ` <52fz9xpp5l.fsf@topspin.com>
2004-05-18 23:01                       ` Eric W. Biederman [this message]
2004-05-19  0:58                         ` readq/writeq on 32bit machines Roland Dreier
2004-05-19  3:14                           ` Eric W. Biederman
     [not found]                   ` <16553.28862.590897.171478@napali.hpl.hp.com>
2004-05-20  2:01                     ` [PATCH] HPET driver Jeff Garzik
2004-05-13 23:18 ` Andrew Morton

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=m3hdudtk5h.fsf@maxwell.lnxi.com \
    --to=ebiederman@lnxi.com \
    --cc=Robert.Picco@hp.com \
    --cc=akpm@osdl.org \
    --cc=ebiederm@xmission.com \
    --cc=greg@kroah.com \
    --cc=jgarzik@pobox.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=roland@topspin.com \
    --cc=venkatesh.pallipadi@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox