mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chuck Ebbert <76306.1226@compuserve.com>
To: Richard Henderson <rth@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>, Andrew Morton <akpm@osdl.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Linus Torvalds <torvalds@osdl.org>, Andi Kleen <ak@suse.de>
Subject: Re: [patch] i386: make bitops safe
Date: Tue, 28 Feb 2006 01:04:01 -0500	[thread overview]
Message-ID: <200602280106_MC3-1-B974-9231@compuserve.com> (raw)

In-Reply-To: <20060228005436.GA24895@redhat.com>

On Mon, 27 Feb 2006 at 16:54:36 -0800, Richard Henderson wrote:

> On Tue, Feb 28, 2006 at 12:47:22AM +0100, Andi Kleen wrote:
> > I remember asking rth about this at some point and IIRC
> > he expressed doubts if it would actually do what expected. Richard?
> 
> It's a bit dicey to be sure.  GCC may or may not be able to look
> through the size of the array and not kill things beyond it.  If
> one could be *sure* of some actual maximum index, this would be
> fine, but I don't think you can.
> 

In theory the bit offset could be from -2**31 to 2**31 - 1

> One could reasonably argue that if you used a structure with a
> flexible array member, that GCC could not look through that.  But
> again I'm not 100% positive this is handled properly.

This seems to work but causes more problems than it solves:

#define vaddr ((volatile long *) addr)
static inline void set_bit(int nr, volatile unsigned long * addr)
{
        __asm__ __volatile__( "lock ; "
                "btsl %2,%1"
                :"+m" (*(vaddr + (nr>>5)))
                :"m" (*vaddr),"Ir" (nr)
                );
}

First, it generates the byte offset nr>>5 and puts it in a register
even though it will never be used in the asm.  I can't find a constraint
that says "I'll be accessing this address but I don't need you to generate
it for me."  Second, the compiler thinks *vaddr will be read when it
really won't (unless nr>>5 == 0 in which case constraint 0 takes care
of it.)

Generated code when nr is a variable:

        movl nr,%edx
        movl %edx,%eax
        sarl $5,%eax
        sall $2,%eax
        lock ; btsl %edx,addr

This causes a register reload afterward (assuming all regs are busy) and
can cause a function to use more stack space.  That plus the three extra
instructions made me go with the full memory clobber instead.

-- 
Chuck
"Equations are the Devil's sentences."  --Stephen Colbert


             reply	other threads:[~2006-02-28  6:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-28  6:04 Chuck Ebbert [this message]
2006-02-28 21:25 ` Richard Henderson
  -- strict thread matches above, loose matches on Subject: below --
2006-02-27 21:57 Chuck Ebbert
2006-02-27 23:06 ` Linus Torvalds
2006-02-27 23:47   ` Andi Kleen
2006-02-28  0:54     ` Richard Henderson
2006-02-28  1:24       ` Andi Kleen

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=200602280106_MC3-1-B974-9231@compuserve.com \
    --to=76306.1226@compuserve.com \
    --cc=ak@suse.de \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=rth@redhat.com \
    --cc=torvalds@osdl.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

Powered by JetHome