mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Segher Boessenkool <segher@kernel.crashing.org>
To: "Ahmed S. Darwish" <darwish.07@gmail.com>
Cc: x86@kernel.org, Rusty Russell <rusty@rustcorp.com.au>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	linux-kernel@vger.kernel.org
Subject: Re: x86: Is 'volatile' necessary for readb/writeb and friends?
Date: Fri, 4 Dec 2009 15:39:06 +0100	[thread overview]
Message-ID: <8B1FEF0C-5D71-4D64-ADC3-1EE60F50779F@kernel.crashing.org> (raw)
In-Reply-To: <20091204092119.GA9707@laptop>

> x86 memory-mapped IO register accessors cast the memory mapped address
> parameter to a one with the 'volatile' type qualifier. For example,  
> here
> is readb() after cpp processing
>
> --> arch/x86/include/asm/io.h:
>
> static inline unsigned char readb(const volatile void __iomem *addr) {

This "volatile" is meaningless.

> 	unsigned char ret;
> 	asm volatile("movb %1, %0"

This "volatile" is required; without it, if "ret" isn't used (or can
be optimised away), the asm() could be optimised away.

> 		     :"=q" (ret)
> 		     :"m" (*(volatile unsigned char __force *)addr)

This "volatile" has no effect, since the asm has a "memory" clobber.
Without that clobber, this "volatile" would prevent moving the asm
over other memory accesses.

If you want to get all language-lawyery, if the object pointed to by
"addr" is volatile, the volatile here _is_ needed: accessing volatile
objects via a not volatile-qualified lvalue is undefined.  But since
this is GCC-specific code anyway, do you care?  :-)

> 		     :"memory");
>         return ret;
> }


Segher


  reply	other threads:[~2009-12-04 14:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-04  9:21 Ahmed S. Darwish
2009-12-04 14:39 ` Segher Boessenkool [this message]
2009-12-04 16:00   ` Arnd Bergmann
2009-12-04 17:30   ` H. Peter Anvin
2009-12-04 19:54     ` Segher Boessenkool

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=8B1FEF0C-5D71-4D64-ADC3-1EE60F50779F@kernel.crashing.org \
    --to=segher@kernel.crashing.org \
    --cc=darwish.07@gmail.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=rusty@rustcorp.com.au \
    --cc=x86@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®