Linux-Next Archive on lore.kernel.org
 help / color / Atom feed
* linux-next: build warning after merge of the tip tree
@ 2014-07-18  5:00 Stephen Rothwell
  2014-07-18 17:21 ` [PATCH] x86, vdso: Fix vdso2c's special_pages error checking Andy Lutomirski
  2014-07-18 19:16 ` linux-next: build warning after merge of the tip tree H. Peter Anvin
  0 siblings, 2 replies; 9+ messages in thread
From: Stephen Rothwell @ 2014-07-18  5:00 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Peter Zijlstra
  Cc: linux-next, linux-kernel, Andy Lutomirski


[-- Attachment #1: Type: text/plain, Size: 737 bytes --]

Hi all,

After merging the tip tree, today's linux-next build (x86_64 allmodconfig)
produced these warnings:

In file included from arch/x86/vdso/vdso2c.c:161:0:
arch/x86/vdso/vdso2c.c: In function 'main':
arch/x86/vdso/vdso2c.h:118:6: warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false [-Wstrict-overflow]
In file included from arch/x86/vdso/vdso2c.c:165:0:
arch/x86/vdso/vdso2c.h:118:6: warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false [-Wstrict-overflow]

Probably introduced by commit e6577a7ce99a ("x86, vdso: Move the vvar
area before the vdso text").

-- 
Cheers,
Stephen Rothwell                    sfr@canb.auug.org.au

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH] x86, vdso: Fix vdso2c's special_pages error checking
  2014-07-18  5:00 linux-next: build warning after merge of the tip tree Stephen Rothwell
@ 2014-07-18 17:21 ` Andy Lutomirski
  2014-07-18 19:16 ` linux-next: build warning after merge of the tip tree H. Peter Anvin
  1 sibling, 0 replies; 9+ messages in thread
From: Andy Lutomirski @ 2014-07-18 17:21 UTC (permalink / raw)
  To: Stephen Rothwell, H. Peter Anvin
  Cc: Thomas Gleixner, Ingo Molnar, Peter Zijlstra, linux-next,
	linux-kernel, Andy Lutomirski

Stephen Rothwell's compiler did something amazing: it unrolled a
loop, discovered that one iteration of that loop contained an
always-true test, and emitted a warning that will IMO only serve to
convince people to disable the warning.

That bogus warning caused me to wonder what prompted such an
absurdity from his compiler, and I discovered that the code in
question was, in fact, completely wrong -- I was looking things up
in the wrong array.

This affects 3.16 as well, but the only effect is to screw up the
error checking a bit.  vdso2c's output is unaffected.

Signed-off-by: Andy Lutomirski <luto@amacapital.net>
---
 arch/x86/vdso/vdso2c.h | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/arch/x86/vdso/vdso2c.h b/arch/x86/vdso/vdso2c.h
index fd57829..0224987 100644
--- a/arch/x86/vdso/vdso2c.h
+++ b/arch/x86/vdso/vdso2c.h
@@ -109,16 +109,18 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
 
 	/* Validate mapping addresses. */
 	for (i = 0; i < sizeof(special_pages) / sizeof(special_pages[0]); i++) {
-		if (!syms[i])
+		INT_BITS symval = syms[special_pages[i]];
+
+		if (!symval)
 			continue;  /* The mapping isn't used; ignore it. */
 
-		if (syms[i] % 4096)
+		if (symval % 4096)
 			fail("%s must be a multiple of 4096\n",
 			     required_syms[i].name);
-		if (syms[sym_vvar_start] > syms[i] + 4096)
-			fail("%s underruns begin_vvar\n",
+		if (symval + 4096 < syms[sym_vvar_start])
+			fail("%s underruns vvar_start\n",
 			     required_syms[i].name);
-		if (syms[i] + 4096 > 0)
+		if (symval + 4096 > 0)
 			fail("%s is on the wrong side of the vdso text\n",
 			     required_syms[i].name);
 	}
-- 
1.9.3

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: linux-next: build warning after merge of the tip tree
  2014-07-18  5:00 linux-next: build warning after merge of the tip tree Stephen Rothwell
  2014-07-18 17:21 ` [PATCH] x86, vdso: Fix vdso2c's special_pages error checking Andy Lutomirski
@ 2014-07-18 19:16 ` H. Peter Anvin
  2014-07-18 19:57   ` Andy Lutomirski
  1 sibling, 1 reply; 9+ messages in thread
From: H. Peter Anvin @ 2014-07-18 19:16 UTC (permalink / raw)
  To: Stephen Rothwell, Thomas Gleixner, Ingo Molnar, Peter Zijlstra
  Cc: linux-next, linux-kernel, Andy Lutomirski, Linus Torvalds

On 07/17/2014 10:00 PM, Stephen Rothwell wrote:
> Hi all,
> 
> After merging the tip tree, today's linux-next build (x86_64
> allmodconfig) produced these warnings:
> 
> In file included from arch/x86/vdso/vdso2c.c:161:0: 
> arch/x86/vdso/vdso2c.c: In function 'main': 
> arch/x86/vdso/vdso2c.h:118:6: warning: assuming signed overflow
> does not occur when assuming that (X + c) < X is always false
> [-Wstrict-overflow] In file included from
> arch/x86/vdso/vdso2c.c:165:0: arch/x86/vdso/vdso2c.h:118:6:
> warning: assuming signed overflow does not occur when assuming that
> (X + c) < X is always false [-Wstrict-overflow]
> 
> Probably introduced by commit e6577a7ce99a ("x86, vdso: Move the
> vvar area before the vdso text").
> 

This seems toxic.

I always wonder if we shouldn't use -fwrapv for the kernel...

	-hpa

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: linux-next: build warning after merge of the tip tree
  2014-07-18 19:16 ` linux-next: build warning after merge of the tip tree H. Peter Anvin
@ 2014-07-18 19:57   ` Andy Lutomirski
  2014-07-18 20:05     ` H. Peter Anvin
  0 siblings, 1 reply; 9+ messages in thread
From: Andy Lutomirski @ 2014-07-18 19:57 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Stephen Rothwell, Thomas Gleixner, Ingo Molnar, Peter Zijlstra,
	linux-next, linux-kernel, Linus Torvalds

On Fri, Jul 18, 2014 at 12:16 PM, H. Peter Anvin <hpa@zytor.com> wrote:
> On 07/17/2014 10:00 PM, Stephen Rothwell wrote:
>> Hi all,
>>
>> After merging the tip tree, today's linux-next build (x86_64
>> allmodconfig) produced these warnings:
>>
>> In file included from arch/x86/vdso/vdso2c.c:161:0:
>> arch/x86/vdso/vdso2c.c: In function 'main':
>> arch/x86/vdso/vdso2c.h:118:6: warning: assuming signed overflow
>> does not occur when assuming that (X + c) < X is always false
>> [-Wstrict-overflow] In file included from
>> arch/x86/vdso/vdso2c.c:165:0: arch/x86/vdso/vdso2c.h:118:6:
>> warning: assuming signed overflow does not occur when assuming that
>> (X + c) < X is always false [-Wstrict-overflow]
>>
>> Probably introduced by commit e6577a7ce99a ("x86, vdso: Move the
>> vvar area before the vdso text").
>>
>
> This seems toxic.
>
> I always wonder if we shouldn't use -fwrapv for the kernel...

This particular warning is IMO in a particularly dumb category: GCC
optimizes some code and then warns about a construct that wasn't there
in the original code.  In this case, I think it unrolled a loop and
discovered that one iteration contained a test that was always true.
Big deal.

(OTOH, the code in question was buggy, but not all for the reason that
GCC thought it was.)

--Andy

>
>         -hpa
>



-- 
Andy Lutomirski
AMA Capital Management, LLC

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: linux-next: build warning after merge of the tip tree
  2014-07-18 19:57   ` Andy Lutomirski
@ 2014-07-18 20:05     ` H. Peter Anvin
  2014-07-18 20:08       ` Andy Lutomirski
  0 siblings, 1 reply; 9+ messages in thread
From: H. Peter Anvin @ 2014-07-18 20:05 UTC (permalink / raw)
  To: Andy Lutomirski
  Cc: Stephen Rothwell, Thomas Gleixner, Ingo Molnar, Peter Zijlstra,
	linux-next, linux-kernel, Linus Torvalds

On 07/18/2014 12:57 PM, Andy Lutomirski wrote:
> 
> This particular warning is IMO in a particularly dumb category: GCC
> optimizes some code and then warns about a construct that wasn't there
> in the original code.  In this case, I think it unrolled a loop and
> discovered that one iteration contained a test that was always true.
> Big deal.
> 
> (OTOH, the code in question was buggy, but not all for the reason that
> GCC thought it was.)
> 

		if (syms[sym_vvar_start] > syms[i] + 4096)
			fail("%s underruns begin_vvar\n",
			     required_syms[i].name);

if i == sym_vvar_start then this is at least a valid warning.  It could
easily be quieted by chaning syms[] to an unsigned array.

	-hpa

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: linux-next: build warning after merge of the tip tree
  2014-07-18 20:05     ` H. Peter Anvin
@ 2014-07-18 20:08       ` Andy Lutomirski
  2014-07-18 20:15         ` H. Peter Anvin
  0 siblings, 1 reply; 9+ messages in thread
From: Andy Lutomirski @ 2014-07-18 20:08 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Stephen Rothwell, Thomas Gleixner, Ingo Molnar, Peter Zijlstra,
	linux-next, linux-kernel, Linus Torvalds

On Fri, Jul 18, 2014 at 1:05 PM, H. Peter Anvin <hpa@zytor.com> wrote:
> On 07/18/2014 12:57 PM, Andy Lutomirski wrote:
>>
>> This particular warning is IMO in a particularly dumb category: GCC
>> optimizes some code and then warns about a construct that wasn't there
>> in the original code.  In this case, I think it unrolled a loop and
>> discovered that one iteration contained a test that was always true.
>> Big deal.
>>
>> (OTOH, the code in question was buggy, but not all for the reason that
>> GCC thought it was.)
>>
>
>                 if (syms[sym_vvar_start] > syms[i] + 4096)
>                         fail("%s underruns begin_vvar\n",
>                              required_syms[i].name);
>
> if i == sym_vvar_start then this is at least a valid warning.  It could
> easily be quieted by chaning syms[] to an unsigned array.

Hah -- fooled you, too :)

i isn't an index in to the syms array at all.  This code is completely
wrong.  See the patch I sent in reply to Stephen's original email.

But, to your earlier point, presumably this could warn:

for (int i = 0; i < 10; i++)
  if (array[i] > array[5] + 1)
    fail();

I think that's absurd.  There's nothing wrong with that code.  A given
test should have to be always true or always false on *all* loop
iterations to be flagged, I think.

--Andy

>
>         -hpa
>



-- 
Andy Lutomirski
AMA Capital Management, LLC

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: linux-next: build warning after merge of the tip tree
  2014-07-18 20:08       ` Andy Lutomirski
@ 2014-07-18 20:15         ` H. Peter Anvin
  2014-07-18 20:20           ` Andy Lutomirski
  0 siblings, 1 reply; 9+ messages in thread
From: H. Peter Anvin @ 2014-07-18 20:15 UTC (permalink / raw)
  To: Andy Lutomirski
  Cc: Stephen Rothwell, Thomas Gleixner, Ingo Molnar, Peter Zijlstra,
	linux-next, linux-kernel, Linus Torvalds

On 07/18/2014 01:08 PM, Andy Lutomirski wrote:
> 
> i isn't an index in to the syms array at all.  This code is completely
> wrong.  See the patch I sent in reply to Stephen's original email.
> 
> But, to your earlier point, presumably this could warn:
> 
> for (int i = 0; i < 10; i++)
>   if (array[i] > array[5] + 1)
>     fail();
> 
> I think that's absurd.  There's nothing wrong with that code.  A given
> test should have to be always true or always false on *all* loop
> iterations to be flagged, I think.
> 

No, the issue is that gcc is telling you that the code will do the wrong
thing in this case.  Yes, only for one iteration, but still.

The reason this is a concern is that: (x > x + n) and its variants is
often used to mean (x > INT_MAX - n) without the type knowledge, but
that is actually invalid standard C because signed types are not
guaranteed to wrap.

	-hpa

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: linux-next: build warning after merge of the tip tree
  2014-07-18 20:15         ` H. Peter Anvin
@ 2014-07-18 20:20           ` Andy Lutomirski
  2014-07-18 20:50             ` H. Peter Anvin
  0 siblings, 1 reply; 9+ messages in thread
From: Andy Lutomirski @ 2014-07-18 20:20 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Stephen Rothwell, Thomas Gleixner, Ingo Molnar, Peter Zijlstra,
	linux-next, linux-kernel, Linus Torvalds

On Fri, Jul 18, 2014 at 1:15 PM, H. Peter Anvin <hpa@zytor.com> wrote:
> On 07/18/2014 01:08 PM, Andy Lutomirski wrote:
>>
>> i isn't an index in to the syms array at all.  This code is completely
>> wrong.  See the patch I sent in reply to Stephen's original email.
>>
>> But, to your earlier point, presumably this could warn:
>>
>> for (int i = 0; i < 10; i++)
>>   if (array[i] > array[5] + 1)
>>     fail();
>>
>> I think that's absurd.  There's nothing wrong with that code.  A given
>> test should have to be always true or always false on *all* loop
>> iterations to be flagged, I think.
>>
>
> No, the issue is that gcc is telling you that the code will do the wrong
> thing in this case.  Yes, only for one iteration, but still.
>
> The reason this is a concern is that: (x > x + n) and its variants is
> often used to mean (x > INT_MAX - n) without the type knowledge, but
> that is actually invalid standard C because signed types are not
> guaranteed to wrap.

Right, but the constant in this case is *much* less than INT_MAX.
Anyway, this is moot.

I do wonder whether the kind of people who build hardened kernels
should enable -fwrapv, though.

--Andy

>
>         -hpa
>



-- 
Andy Lutomirski
AMA Capital Management, LLC

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: linux-next: build warning after merge of the tip tree
  2014-07-18 20:20           ` Andy Lutomirski
@ 2014-07-18 20:50             ` H. Peter Anvin
  0 siblings, 0 replies; 9+ messages in thread
From: H. Peter Anvin @ 2014-07-18 20:50 UTC (permalink / raw)
  To: Andy Lutomirski
  Cc: Stephen Rothwell, Thomas Gleixner, Ingo Molnar, Peter Zijlstra,
	linux-next, linux-kernel, Linus Torvalds

On 07/18/2014 01:20 PM, Andy Lutomirski wrote:
>>
>> The reason this is a concern is that: (x > x + n) and its variants is
>> often used to mean (x > INT_MAX - n) without the type knowledge, but
>> that is actually invalid standard C because signed types are not
>> guaranteed to wrap.
> 
> Right, but the constant in this case is *much* less than INT_MAX.
> Anyway, this is moot.

It isn't about the constant (n) at all, it is about the value of x.

> I do wonder whether the kind of people who build hardened kernels
> should enable -fwrapv, though.

-fwrapv in gcc makes signed arithmetic strict 2's-complement, which is
what I think we want in the kernel.  Someone would just have to make
sure there isn't some key codepath in the kernel which gets pessimized.

	-hpa

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, back to index

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-18  5:00 linux-next: build warning after merge of the tip tree Stephen Rothwell
2014-07-18 17:21 ` [PATCH] x86, vdso: Fix vdso2c's special_pages error checking Andy Lutomirski
2014-07-18 19:16 ` linux-next: build warning after merge of the tip tree H. Peter Anvin
2014-07-18 19:57   ` Andy Lutomirski
2014-07-18 20:05     ` H. Peter Anvin
2014-07-18 20:08       ` Andy Lutomirski
2014-07-18 20:15         ` H. Peter Anvin
2014-07-18 20:20           ` Andy Lutomirski
2014-07-18 20:50             ` H. Peter Anvin

Linux-Next Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-next/0 linux-next/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-next linux-next/ https://lore.kernel.org/linux-next \
		linux-next@vger.kernel.org
	public-inbox-index linux-next

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-next


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git