From: Andrew Sharp <andy.sharp@onstor.com>
To: Ulrich Eckhardt <eckhardt@satorlaser.com>
Cc: linux-mips <linux-mips@linux-mips.org>
Subject: Re: [PATCH] Put cast inside macro instead of all the callers
Date: Thu, 1 Nov 2007 10:23:00 -0700 [thread overview]
Message-ID: <20071101102300.1db4ff6a@ripper.onstor.net> (raw)
In-Reply-To: <200711011704.01079.eckhardt@satorlaser.com>
On Thu, 1 Nov 2007 17:04:01 +0100 Ulrich Eckhardt
<eckhardt@satorlaser.com> wrote:
> I'm by far not a MIPS expert, but I'm puzzled by the code and how it
> uses signed integers for addresses. I just added some comments below,
> but I'm not sure if they are valid. Thank you for any clarification!
>
> On Wednesday 31 October 2007, Andrew Sharp wrote:
> > Since all the callers of the PHYS_TO_XKPHYS macro call with a
> > constant, put the cast to LL inside the macro where it really
> > should be rather than in all the callers. This makes macros like
> > PHYS_TO_XKSEG_UNCACHED work without gcc whining.
>
> I'm not sure if this is always a compile-time constant so that you
> can adorn it with a LL. However, note that this is not a cast, a cast
> is at runtime.
It is always a constant.
> > if (sp >= (long)CKSEG0 && sp < (long)CKSEG2)
> > usp = CKSEG1ADDR(sp);
> > #ifdef CONFIG_64BIT
> > - else if ((long long)sp >= (long long)PHYS_TO_XKPHYS(0LL,
> > 0) &&
> > - (long long)sp < (long long)PHYS_TO_XKPHYS(8LL, 0))
> > - usp = PHYS_TO_XKPHYS((long long)K_CALG_UNCACHED,
> > + else if ((long long)sp >= (long long)PHYS_TO_XKPHYS(0, 0)
> > &&
> > + (long long)sp < (long long)PHYS_TO_XKPHYS(8, 0))
> > + usp = PHYS_TO_XKPHYS(K_CALG_UNCACHED,
> > XKPHYS_TO_PHYS((long
> > long)sp));
>
> I'd say this code is broken in way too many aspects:
> 1. A plethora of casts. PHYS_TO_XKPHYS() should return a physical
> address (i.e. 32 or 64 bits unsigned integer) already, so casting its
> result should not be necessary.
> 2. Using a signed integer of undefined size for an address. At least
> use an explicit 64 bit unsigned integer (__u64).
> 3. The use of signed types makes me wonder about intended overflow
> semantics. Just for the record, signed overflow in C causes undefined
> behaviour, no diagnostic required, and recent GCC even assume that no
> overflow occurs as an optimisation!
>
> > #define PHYS_TO_XKSEG_CACHED(p)
> > PHYS_TO_XKPHYS(K_CALG_COH_SHAREABLE,(p)) #define
> > XKPHYS_TO_PHYS(p) ((p) & TO_PHYS_MASK) #define
> > PHYS_TO_XKPHYS(cm,a) (_CONST64_(0x8000000000000000)
> > | \
> > - ((cm)<<59) | (a))
> > + (_CONST64_(cm)<<59) | (a))
>
> This macro will always(!!!) generate a negative number, is that
> intended?
Well, it's an address, not a number. Does that help? The point of the
macro is to convert physical addresses to a selectable type of virtual
address, of which mips has several.
Cheers,
a
next prev parent reply other threads:[~2007-11-01 17:23 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-31 21:11 [PATCH] Put cast inside macro instead of all the callers Andrew Sharp
2007-11-01 16:04 ` Ulrich Eckhardt
2007-11-01 17:23 ` Andrew Sharp [this message]
2007-11-01 17:47 ` Ralf Baechle
2007-11-08 15:26 ` Maciej W. Rozycki
2007-11-02 8:06 ` Ulrich Eckhardt
2007-11-01 17:16 ` Ralf Baechle
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=20071101102300.1db4ff6a@ripper.onstor.net \
--to=andy.sharp@onstor.com \
--cc=eckhardt@satorlaser.com \
--cc=linux-mips@linux-mips.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