Re: ILP32 for ARM64: testing with glibc testsuite

2016-12-05 Thread Zhangjian (Bamvor)



On 2016/12/5 18:07, Andreas Schwab wrote:

On Dez 05 2016, "Zhangjian (Bamvor)" <bamvor.zhangj...@huawei.com> wrote:


Is there some progresses on it? We could collabrate to fix those issues.


All the elf/nptl/rt fails should be fixed by the recent binutils fixes.

Cool. How about the conform and other failures?

Regards

Bamvor


Andreas.





Re: ILP32 for ARM64: testing with glibc testsuite

2016-12-05 Thread Zhangjian (Bamvor)



On 2016/12/5 18:07, Andreas Schwab wrote:

On Dez 05 2016, "Zhangjian (Bamvor)"  wrote:


Is there some progresses on it? We could collabrate to fix those issues.


All the elf/nptl/rt fails should be fixed by the recent binutils fixes.

Cool. How about the conform and other failures?

Regards

Bamvor


Andreas.





Re: ILP32 for ARM64 - testing with lmbench

2016-12-05 Thread Zhangjian (Bamvor)

Hi, Catalin, Guys

Do you have suggestion of next move of upstreaming ILP32?
There are already the test results of lmbench and specint. Do you they are ok 
or need more data to prove no regression?
I have also noticed that there are ILP32 failures in glibc testsuite. Is it the 
only blocker for merge ILP32(in technology part)?

We appreciate any feedback/suggestion and hope could collaborate to improve the 
upstream progress.

(cc libc-alpha to get more input).

Thanks

Bamvor

On 2016/11/17 15:48, Zhangjian (Bamvor) wrote:

Hi, Maxim

On 2016/11/17 13:02, Maxim Kuvyrkov wrote:

Hi Bamvor,

I'm surprised that you see this much difference from ILP32 patches on SPEC 
CPU2006int at all.  The SPEC CPU2006 benchmarks spend almost no time in the 
kernel syscalls.  I can imagine memory, TLB,
and cache handling in the kernel could affect CPU2006 benchmarks.  Do ILP32 
patches touch code in those areas?

Other than that, it would be interesting to check what the variance is between 
the 3 iterations of benchmark runs.  Could you check what relative standard 
deviation is between the 3 iterations --
(STDEV(RUN1, RUN2, RUN3) / RUNselected)?

For reference, in my [non-ILP32] benchmarking I see 1.1% for 401.bzip2,  0.8% 
for 429.mcf, 0.2% for 456.hmmer, and 0.1% for 462.libquantum.

Here is my result:
ILP32_mergedILP32_unmerged
  401.bzip20.31%0.26%
  429.mcf  1.61%1.36%
  456.hmmer1.37%1.57%
  462.libquantum   0.29%0.28%

Regards

Bamvor



--
Maxim Kuvyrkov
www.linaro.org




On Nov 17, 2016, at 7:28 AM, Zhangjian (Bamvor) <bamvor.zhangj...@huawei.com> 
wrote:

Hi, all

I test specint of aarch64 LP64 when aarch32 el0 disable/enabled respectively
and compare with ILP32 unmerged kernel(4.8-rc6) in our arm64 board. I found
that difference(ILP32 disabled/ILP32 unmerged) is bigger when aarch32 el0 is
enabled, compare with aarch32 el0 disabled kernel. And bzip2, mcg, hmmer,
libquantum are the top four differences[1]. Note that bigger is better in
specint test.

In order to make sure the above results, I retest these four testcases in
reportable way(reference the command in the end). The result[2] show that
libquantum decrease -2.09% after ILP32 enabled and aarch32 on. I think it is in
significant.

The result of lmbench is not stable in my board. I plan to dig it later.

[1] The following test result is tested through --size=ref --iterations=3.
1.1 Test when aarch32_el0 is enabled.
   ILP32 disabledbase line
 400.perlbench100.00% 100%
 401.bzip2 99.35% 100%
 403.gcc  100.26% 100%
 429.mcf  102.75% 100%
 445.gobmk100.00% 100%
 456.hmmer 95.66% 100%
 458.sjeng100.00% 100%
 462.libquantum   100.00% 100%
 471.omnetpp  100.59% 100%
 473.astar 99.66% 100%
 483.xalancbmk 99.10% 100%

1.2 Test when aarch32_el0 is disabled
   ILP32 disabled base line
 400.perlbench100.22%  100%
 401.bzip2100.95%  100%
 403.gcc  100.20%  100%
 429.mcf  100.76%  100%
 445.gobmk100.36%  100%
 456.hmmer 97.94%  100%
 458.sjeng 99.73%  100%
 462.libquantum98.72%  100%
 471.omnetpp  100.86%  100%
 473.astar 99.15%  100%
 483.xalancbmk100.08%  100%

[2] The following test result is tested through: runspec --config=my.cfg 
--size=test,train,ref --noreportable --tune=base,peak --iterations=3 bzip2 mcf 
hmmer libquantum
2.1 Test when aarch32_el0 is enabled.
ILP32_enabled base line
 401.bzip2100.82%  100%
 429.mcf  100.18%  100%
 456.hmmer 99.64%  100%
 462.libquantum97.91%  100%

Regards

Bamvor

On 2016/10/28 20:46, Yury Norov wrote:

[Add Steve Ellcey, thanks for testing on ThunderX]

Lmbench-3.0-a9 testing is performed on ThunderX machine to check that
ILP32 series does not add performance regressions for LP64. Test
summary is in the table below. Our measurements doesn't show
significant performance regression of LP64 if ILP32 code is merged,
both enabled or disabled.

  ILP32 enabled   ILP32  disabled   Standard Kernel
null syscall   0.1066  0.11210.1121
  95.09%  100.00%

stat   1.3947  

Re: ILP32 for ARM64 - testing with lmbench

2016-12-05 Thread Zhangjian (Bamvor)

Hi, Catalin, Guys

Do you have suggestion of next move of upstreaming ILP32?
There are already the test results of lmbench and specint. Do you they are ok 
or need more data to prove no regression?
I have also noticed that there are ILP32 failures in glibc testsuite. Is it the 
only blocker for merge ILP32(in technology part)?

We appreciate any feedback/suggestion and hope could collaborate to improve the 
upstream progress.

(cc libc-alpha to get more input).

Thanks

Bamvor

On 2016/11/17 15:48, Zhangjian (Bamvor) wrote:

Hi, Maxim

On 2016/11/17 13:02, Maxim Kuvyrkov wrote:

Hi Bamvor,

I'm surprised that you see this much difference from ILP32 patches on SPEC 
CPU2006int at all.  The SPEC CPU2006 benchmarks spend almost no time in the 
kernel syscalls.  I can imagine memory, TLB,
and cache handling in the kernel could affect CPU2006 benchmarks.  Do ILP32 
patches touch code in those areas?

Other than that, it would be interesting to check what the variance is between 
the 3 iterations of benchmark runs.  Could you check what relative standard 
deviation is between the 3 iterations --
(STDEV(RUN1, RUN2, RUN3) / RUNselected)?

For reference, in my [non-ILP32] benchmarking I see 1.1% for 401.bzip2,  0.8% 
for 429.mcf, 0.2% for 456.hmmer, and 0.1% for 462.libquantum.

Here is my result:
ILP32_mergedILP32_unmerged
  401.bzip20.31%0.26%
  429.mcf  1.61%1.36%
  456.hmmer1.37%1.57%
  462.libquantum   0.29%0.28%

Regards

Bamvor



--
Maxim Kuvyrkov
www.linaro.org




On Nov 17, 2016, at 7:28 AM, Zhangjian (Bamvor)  
wrote:

Hi, all

I test specint of aarch64 LP64 when aarch32 el0 disable/enabled respectively
and compare with ILP32 unmerged kernel(4.8-rc6) in our arm64 board. I found
that difference(ILP32 disabled/ILP32 unmerged) is bigger when aarch32 el0 is
enabled, compare with aarch32 el0 disabled kernel. And bzip2, mcg, hmmer,
libquantum are the top four differences[1]. Note that bigger is better in
specint test.

In order to make sure the above results, I retest these four testcases in
reportable way(reference the command in the end). The result[2] show that
libquantum decrease -2.09% after ILP32 enabled and aarch32 on. I think it is in
significant.

The result of lmbench is not stable in my board. I plan to dig it later.

[1] The following test result is tested through --size=ref --iterations=3.
1.1 Test when aarch32_el0 is enabled.
   ILP32 disabledbase line
 400.perlbench100.00% 100%
 401.bzip2 99.35% 100%
 403.gcc  100.26% 100%
 429.mcf  102.75% 100%
 445.gobmk100.00% 100%
 456.hmmer 95.66% 100%
 458.sjeng100.00% 100%
 462.libquantum   100.00% 100%
 471.omnetpp  100.59% 100%
 473.astar 99.66% 100%
 483.xalancbmk 99.10% 100%

1.2 Test when aarch32_el0 is disabled
   ILP32 disabled base line
 400.perlbench100.22%  100%
 401.bzip2100.95%  100%
 403.gcc  100.20%  100%
 429.mcf  100.76%  100%
 445.gobmk100.36%  100%
 456.hmmer 97.94%  100%
 458.sjeng 99.73%  100%
 462.libquantum98.72%  100%
 471.omnetpp  100.86%  100%
 473.astar 99.15%  100%
 483.xalancbmk100.08%  100%

[2] The following test result is tested through: runspec --config=my.cfg 
--size=test,train,ref --noreportable --tune=base,peak --iterations=3 bzip2 mcf 
hmmer libquantum
2.1 Test when aarch32_el0 is enabled.
ILP32_enabled base line
 401.bzip2100.82%  100%
 429.mcf  100.18%  100%
 456.hmmer 99.64%  100%
 462.libquantum97.91%  100%

Regards

Bamvor

On 2016/10/28 20:46, Yury Norov wrote:

[Add Steve Ellcey, thanks for testing on ThunderX]

Lmbench-3.0-a9 testing is performed on ThunderX machine to check that
ILP32 series does not add performance regressions for LP64. Test
summary is in the table below. Our measurements doesn't show
significant performance regression of LP64 if ILP32 code is merged,
both enabled or disabled.

  ILP32 enabled   ILP32  disabled   Standard Kernel
null syscall   0.1066  0.11210.1121
  95.09%  100.00%

stat   1.3947  1.38141.3864

Re: ILP32 for ARM64: testing with glibc testsuite

2016-12-05 Thread Zhangjian (Bamvor)

Hi, Steve

On 2016/11/18 5:45, Steve Ellcey wrote:

On Wed, 2016-11-16 at 15:22 +0400, Maxim Kuvyrkov wrote:


On Nov 9, 2016, at 1:56 PM, Yury Norov 
wrote:



Below is the results of glibc testsuite run for aarch64/lp64


I have been running the glibc testsuite as well.  I have only run it on
an ILP32 enabled kernel.  Using that kernel, top-of-tree glibc, and the
ILP32 glibc patches I have no LP64 regressions.  There are 5 failures
in LP64 mode but I get them with vanilla top-of-tree glibc sources too.
They are:
nptl/eintr1 (I actually don't run this because it kills the 'make 
check')
debug/tst-backtrace5
debug/tst-backtrace6
nptl/tst-stack4
nptl/tst-thread_local1

In ILP32 mode I get 33 failures, they include the above failures (minus
nptl/tst-thread_local1) plus:

c++-types-check
conform/ISO11/inttypes.h/conform
conform/ISO11/stdint.h/conform
conform/ISO99/inttypes.h/conform
conform/ISO99/stdint.h/conform
conform/POSIX2008/inttypes.h/conform
conform/POSIX2008/stdint.h/conform
conform/XOPEN2K/inttypes.h/conform
conform/XOPEN2K/stdint.h/conform
conform/XOPEN2K8/inttypes.h/conform
conform/XOPEN2K8/stdint.h/conform
elf/tst-tls1
elf/tst-tls1-static
elf/tst-tls2
elf/tst-tls2-static
elf/tst-tls3
math/check-abi-libm
math/test-double
math/test-double-finite
math/test-float
math/test-float-finite
misc/tst-sync_file_range
nptl/tst-cancel26
nptl/tst-cancel27
nptl/tst-sem3
rt/tst-mqueue1
rt/tst-mqueue2
rt/tst-mqueue4
rt/tst-mqueue7
stdlib/tst-makecontext3

I am currently looking at these ILP32 regressions (starting with the
tls failures) to see if I can figure out what is happening with them.

Is there some progresses on it? We could collabrate to fix those issues.

Regards

Bamvor


Steve Ellcey
sell...@caviumnetworks.com





Re: ILP32 for ARM64: testing with glibc testsuite

2016-12-05 Thread Zhangjian (Bamvor)

Hi, Steve

On 2016/11/18 5:45, Steve Ellcey wrote:

On Wed, 2016-11-16 at 15:22 +0400, Maxim Kuvyrkov wrote:


On Nov 9, 2016, at 1:56 PM, Yury Norov 
wrote:



Below is the results of glibc testsuite run for aarch64/lp64


I have been running the glibc testsuite as well.  I have only run it on
an ILP32 enabled kernel.  Using that kernel, top-of-tree glibc, and the
ILP32 glibc patches I have no LP64 regressions.  There are 5 failures
in LP64 mode but I get them with vanilla top-of-tree glibc sources too.
They are:
nptl/eintr1 (I actually don't run this because it kills the 'make 
check')
debug/tst-backtrace5
debug/tst-backtrace6
nptl/tst-stack4
nptl/tst-thread_local1

In ILP32 mode I get 33 failures, they include the above failures (minus
nptl/tst-thread_local1) plus:

c++-types-check
conform/ISO11/inttypes.h/conform
conform/ISO11/stdint.h/conform
conform/ISO99/inttypes.h/conform
conform/ISO99/stdint.h/conform
conform/POSIX2008/inttypes.h/conform
conform/POSIX2008/stdint.h/conform
conform/XOPEN2K/inttypes.h/conform
conform/XOPEN2K/stdint.h/conform
conform/XOPEN2K8/inttypes.h/conform
conform/XOPEN2K8/stdint.h/conform
elf/tst-tls1
elf/tst-tls1-static
elf/tst-tls2
elf/tst-tls2-static
elf/tst-tls3
math/check-abi-libm
math/test-double
math/test-double-finite
math/test-float
math/test-float-finite
misc/tst-sync_file_range
nptl/tst-cancel26
nptl/tst-cancel27
nptl/tst-sem3
rt/tst-mqueue1
rt/tst-mqueue2
rt/tst-mqueue4
rt/tst-mqueue7
stdlib/tst-makecontext3

I am currently looking at these ILP32 regressions (starting with the
tls failures) to see if I can figure out what is happening with them.

Is there some progresses on it? We could collabrate to fix those issues.

Regards

Bamvor


Steve Ellcey
sell...@caviumnetworks.com





Re: [PATCH RFC 6/6] selftests: enable O and KBUILD_OUTPUT

2016-11-18 Thread Zhangjian (Bamvor)

Hi, Macheal

Thanks your reply.

On 2016/11/18 19:29, Michael Ellerman wrote:
>> From: Bamvor Jian Zhang 
>>
>> Enable O and KBUILD_OUTPUT for kselftest. User could compile kselftest
>> to another directory by passing O or KBUILD_OUTPUT. And O is high
>> priority than KBUILD_OUTPUT.
>
>We end up saying $(OUTPUT) a lot, kbuild uses $(obj), which is shorter
>and less shouty and reads nicer I think ?
I agree that we need a clearly name. Meanwhile the $(obj) sounds like
compile objects. But it is actually a directory which we put objs to
there. I am wondering if people may confuse about he name. Given that
kbuild make KBUILD_OUTPUT work by defining the srctree. How about pick
up dst (means dsttree) instead of OUTPUT?
>
>> diff --git a/tools/testing/selftests/Makefile 
b/tools/testing/selftests/Makefile
>> index a3144a3..79c5e97 100644
>> --- a/tools/testing/selftests/Makefile
>> +++ b/tools/testing/selftests/Makefile
>> @@ -47,29 +47,47 @@ override LDFLAGS =
>>  override MAKEFLAGS =
>>  endif
>>
>> +ifeq ($(O)$(KBUILD_OUTPUT),)
>> +BUILD :=$(shell pwd)
>> +else
>> +ifneq ($(O),)
>> +BUILD := $(O)
>> +else
>> +ifneq ($(KBUILD_OUTPUT),)
>> +BUILD := $(KBUILD_OUTPUT)
>> +endif
>> +endif
>> +endif
>
>That should be equivalent to:
>
>BUILD := $(O)
>ifndef BUILD
>  BUILD := $(KBUILD_OUTPUT)
>endif
>ifndef BUILD
>  BUILD := $(shell pwd)
>endif
Thanks. It works for me. I will update in my next version.
>
>> diff --git a/tools/testing/selftests/exec/Makefile 
b/tools/testing/selftests/exec/Makefile
>> index 48d1f86..fe5cdec 100644
>> --- a/tools/testing/selftests/exec/Makefile
>> +++ b/tools/testing/selftests/exec/Makefile
>> @@ -5,18 +5,19 @@ TEST_GEN_FILES := execveat.symlink execveat.denatured 
script subdir
>>  # Makefile is a run-time dependency, since it's accessed by the execveat 
test
>>  TEST_FILES := Makefile
>>
>> -EXTRA_CLEAN := subdir.moved execveat.moved x*
>> +EXTRA_CLEAN := $(OUTPUT)subdir.moved $(OUTPUT)execveat.moved $(OUTPUT)x*
>
>It reads strangely to not have a slash after the output I think it would
>be better if you used a slash everywhere you use it, like:
>
>EXTRA_CLEAN := $(OUTPUT)/subdir.moved $(OUTPUT)/execveat.moved $(OUTPUT)/x*
>
>That makes it clear that it's a directory, and not some other prefix.
Oh, yes. The origin code is not work if remove the slash. I eventually
found that it is because I do the wrong replacement in TEST_GEN_PROGS
and TEST_GEN_FILES. They should be:
TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS))
TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES))
>
>
>Having said that, I think for EXTRA_CLEAN it should just be defined that
>the contents are in $(OUTPUT), and so we can just do that in lib.mk, eg:
>
>EXTRA_CLEAN := $(addprefix $(OUTPUT)/,$(EXTRA_CLEAN))
>
>clean:
>$(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) 
$(EXTRA_CLEAN)
The OUTPUT is the directory we build. It may be not be not the
directory we run the test. For example, pstore do not need compile.
It could run in the source directory.
>
>
>>  include ../lib.mk
>>
>> -subdir:
>> +$(OUTPUT)subdir:
>>   mkdir -p $@
>> -script:
>> +$(OUTPUT)script:
>>   echo '#!/bin/sh' > $@
>>   echo 'exit $$*' >> $@
>>   chmod +x $@
>> -execveat.symlink: execveat
>> - ln -s -f $< $@
>> -execveat.denatured: execveat
>> +$(OUTPUT)execveat.symlink: execveat
>> + cd $(OUTPUT) && ln -s -f $< `basename $@`
>> +$(OUTPUT)execveat.denatured: execveat
>>   cp $< $@
>>   chmod -x $@
>
>Do those work? I would have thought you'd need $(OUTPUT) on the right
>hand side also?
It works because execveat will generate twice which is wrong. I will
fix in next version.
>
>> diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk
>> index 0f7a371..fa87f98 100644
>> --- a/tools/testing/selftests/lib.mk
>> +++ b/tools/testing/selftests/lib.mk
>> @@ -33,19 +34,29 @@ endif
>>
>>  define EMIT_TESTS
>>   @for TEST in $(TEST_GEN_PROGS) $(TEST_PROGS); do \
>> - echo "(./$$TEST && echo \"selftests: $$TEST [PASS]\") || echo \"selftests: 
$$TEST [FAIL]\""; \
>> + BASENAME_TEST=`basename $$TEST`;\
>> + echo "(./$$BASENAME_TEST && echo \"selftests: $$BASENAME_TEST [PASS]\") || echo 
\"selftests: $$BASENAME_TEST [FAIL]\""; \
>>   done;
>>  endef
>>
>>  emit_tests:
>>   $(EMIT_TESTS)
>>
>> +TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)%,$(TEST_GEN_PROGS))
>> +TEST_GEN_FILES := $(patsubst %,$(OUTPUT)%,$(TEST_GEN_FILES))
>
>You should just be able to use addprefix there.
Yes.
>
>> +
>>  all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
>>
>>  clean:
>>   $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) 
$(EXTRA_CLEAN)
>>
>> -%: %.c
>> - $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ $^
>> +$(OUTPUT)%:%.c
>> + $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) $< -o $@
>
>I think it reads better with a space after the 

Re: [PATCH RFC 6/6] selftests: enable O and KBUILD_OUTPUT

2016-11-18 Thread Zhangjian (Bamvor)

Hi, Macheal

Thanks your reply.

On 2016/11/18 19:29, Michael Ellerman wrote:
>> From: Bamvor Jian Zhang 
>>
>> Enable O and KBUILD_OUTPUT for kselftest. User could compile kselftest
>> to another directory by passing O or KBUILD_OUTPUT. And O is high
>> priority than KBUILD_OUTPUT.
>
>We end up saying $(OUTPUT) a lot, kbuild uses $(obj), which is shorter
>and less shouty and reads nicer I think ?
I agree that we need a clearly name. Meanwhile the $(obj) sounds like
compile objects. But it is actually a directory which we put objs to
there. I am wondering if people may confuse about he name. Given that
kbuild make KBUILD_OUTPUT work by defining the srctree. How about pick
up dst (means dsttree) instead of OUTPUT?
>
>> diff --git a/tools/testing/selftests/Makefile 
b/tools/testing/selftests/Makefile
>> index a3144a3..79c5e97 100644
>> --- a/tools/testing/selftests/Makefile
>> +++ b/tools/testing/selftests/Makefile
>> @@ -47,29 +47,47 @@ override LDFLAGS =
>>  override MAKEFLAGS =
>>  endif
>>
>> +ifeq ($(O)$(KBUILD_OUTPUT),)
>> +BUILD :=$(shell pwd)
>> +else
>> +ifneq ($(O),)
>> +BUILD := $(O)
>> +else
>> +ifneq ($(KBUILD_OUTPUT),)
>> +BUILD := $(KBUILD_OUTPUT)
>> +endif
>> +endif
>> +endif
>
>That should be equivalent to:
>
>BUILD := $(O)
>ifndef BUILD
>  BUILD := $(KBUILD_OUTPUT)
>endif
>ifndef BUILD
>  BUILD := $(shell pwd)
>endif
Thanks. It works for me. I will update in my next version.
>
>> diff --git a/tools/testing/selftests/exec/Makefile 
b/tools/testing/selftests/exec/Makefile
>> index 48d1f86..fe5cdec 100644
>> --- a/tools/testing/selftests/exec/Makefile
>> +++ b/tools/testing/selftests/exec/Makefile
>> @@ -5,18 +5,19 @@ TEST_GEN_FILES := execveat.symlink execveat.denatured 
script subdir
>>  # Makefile is a run-time dependency, since it's accessed by the execveat 
test
>>  TEST_FILES := Makefile
>>
>> -EXTRA_CLEAN := subdir.moved execveat.moved x*
>> +EXTRA_CLEAN := $(OUTPUT)subdir.moved $(OUTPUT)execveat.moved $(OUTPUT)x*
>
>It reads strangely to not have a slash after the output I think it would
>be better if you used a slash everywhere you use it, like:
>
>EXTRA_CLEAN := $(OUTPUT)/subdir.moved $(OUTPUT)/execveat.moved $(OUTPUT)/x*
>
>That makes it clear that it's a directory, and not some other prefix.
Oh, yes. The origin code is not work if remove the slash. I eventually
found that it is because I do the wrong replacement in TEST_GEN_PROGS
and TEST_GEN_FILES. They should be:
TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS))
TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES))
>
>
>Having said that, I think for EXTRA_CLEAN it should just be defined that
>the contents are in $(OUTPUT), and so we can just do that in lib.mk, eg:
>
>EXTRA_CLEAN := $(addprefix $(OUTPUT)/,$(EXTRA_CLEAN))
>
>clean:
>$(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) 
$(EXTRA_CLEAN)
The OUTPUT is the directory we build. It may be not be not the
directory we run the test. For example, pstore do not need compile.
It could run in the source directory.
>
>
>>  include ../lib.mk
>>
>> -subdir:
>> +$(OUTPUT)subdir:
>>   mkdir -p $@
>> -script:
>> +$(OUTPUT)script:
>>   echo '#!/bin/sh' > $@
>>   echo 'exit $$*' >> $@
>>   chmod +x $@
>> -execveat.symlink: execveat
>> - ln -s -f $< $@
>> -execveat.denatured: execveat
>> +$(OUTPUT)execveat.symlink: execveat
>> + cd $(OUTPUT) && ln -s -f $< `basename $@`
>> +$(OUTPUT)execveat.denatured: execveat
>>   cp $< $@
>>   chmod -x $@
>
>Do those work? I would have thought you'd need $(OUTPUT) on the right
>hand side also?
It works because execveat will generate twice which is wrong. I will
fix in next version.
>
>> diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk
>> index 0f7a371..fa87f98 100644
>> --- a/tools/testing/selftests/lib.mk
>> +++ b/tools/testing/selftests/lib.mk
>> @@ -33,19 +34,29 @@ endif
>>
>>  define EMIT_TESTS
>>   @for TEST in $(TEST_GEN_PROGS) $(TEST_PROGS); do \
>> - echo "(./$$TEST && echo \"selftests: $$TEST [PASS]\") || echo \"selftests: 
$$TEST [FAIL]\""; \
>> + BASENAME_TEST=`basename $$TEST`;\
>> + echo "(./$$BASENAME_TEST && echo \"selftests: $$BASENAME_TEST [PASS]\") || echo 
\"selftests: $$BASENAME_TEST [FAIL]\""; \
>>   done;
>>  endef
>>
>>  emit_tests:
>>   $(EMIT_TESTS)
>>
>> +TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)%,$(TEST_GEN_PROGS))
>> +TEST_GEN_FILES := $(patsubst %,$(OUTPUT)%,$(TEST_GEN_FILES))
>
>You should just be able to use addprefix there.
Yes.
>
>> +
>>  all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
>>
>>  clean:
>>   $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) 
$(EXTRA_CLEAN)
>>
>> -%: %.c
>> - $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ $^
>> +$(OUTPUT)%:%.c
>> + $(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) $< -o $@
>
>I think it reads better with a space after the ":"
Sure

Regards

Bamvor

>

Re: [PATCH RFC 1/6] selftests: remove duplicated all and clean target

2016-11-18 Thread Zhangjian (Bamvor)

Hi, Michael

On 2016/11/18 18:31, Michael Ellerman wrote:
>Hi Bamvor,
>
>bamvor.zhangj...@huawei.com writes:
>
>> From: Bamvor Jian Zhang 
>>
>> Currently, kselftest use TEST_PROGS, TEST_PROGS_EXTENDED, TEST_FILES to
>> indicate the default test program, extended test program and test files.
>> These lead to duplicated all and clean targets.
>>
>> In order to remove them, introduce TEST_GEN_PROGS,
>> TEST_GEN_PROGS_EXTENDED, TEST_GEN_FILES to indicate the compiled
>> objected.
>
>It's nice to be able to drop the clean rules, but renaming all those
>variables causes a lot of churn.
>
>I think it would be better if we add a new variable, maybe NO_CLEAN,
>which can be used to specify anything in TEST_PROGS/EXTENDED which
>should *not* be cleaned.
>
>And then the default clean rule will just do:
>
>clean:
>$(RM) -fr $(filter-out $(NO_CLEAN),$(TEST_PROGS))
Maybe I lost somewhere. I add these variable for all and
clean target. They will be used to output the objects to OUTPUT
directory. Could you please explain in details how should I do it for
"all" target if I do not introduce TEST_GEN_PROGS,
TEST_GEN_PROGS_EXTENDED and TEST_GEN_FILES?

Regards

Bamvor
>
>
>I think that would require less changes overall, because most tests just
>want to build some files, run them, and then clean them. The tests that
>need to do more elaborate things are the exception.
>
>cheers



Re: [PATCH RFC 1/6] selftests: remove duplicated all and clean target

2016-11-18 Thread Zhangjian (Bamvor)

Hi, Michael

On 2016/11/18 18:31, Michael Ellerman wrote:
>Hi Bamvor,
>
>bamvor.zhangj...@huawei.com writes:
>
>> From: Bamvor Jian Zhang 
>>
>> Currently, kselftest use TEST_PROGS, TEST_PROGS_EXTENDED, TEST_FILES to
>> indicate the default test program, extended test program and test files.
>> These lead to duplicated all and clean targets.
>>
>> In order to remove them, introduce TEST_GEN_PROGS,
>> TEST_GEN_PROGS_EXTENDED, TEST_GEN_FILES to indicate the compiled
>> objected.
>
>It's nice to be able to drop the clean rules, but renaming all those
>variables causes a lot of churn.
>
>I think it would be better if we add a new variable, maybe NO_CLEAN,
>which can be used to specify anything in TEST_PROGS/EXTENDED which
>should *not* be cleaned.
>
>And then the default clean rule will just do:
>
>clean:
>$(RM) -fr $(filter-out $(NO_CLEAN),$(TEST_PROGS))
Maybe I lost somewhere. I add these variable for all and
clean target. They will be used to output the objects to OUTPUT
directory. Could you please explain in details how should I do it for
"all" target if I do not introduce TEST_GEN_PROGS,
TEST_GEN_PROGS_EXTENDED and TEST_GEN_FILES?

Regards

Bamvor
>
>
>I think that would require less changes overall, because most tests just
>want to build some files, run them, and then clean them. The tests that
>need to do more elaborate things are the exception.
>
>cheers



Re: [PATCH RFC 5/6] selftests: add EXTRA_CLEAN for clean target

2016-11-18 Thread Zhangjian (Bamvor)

Hi, Micheal

On 2016/11/18 19:01, Michael Ellerman wrote:

bamvor.zhangj...@huawei.com writes:


From: Bamvor Jian Zhang 

Some testcases need the clean extra data after running. This patch
introduce the "EXTRA_CLEAN" variable to address this requirement.


The idea here is fine I think. But this will need reworking if you
follow my suggestions for patch 1.


After KOUTPUT_BUILD is enabled in later patch, it will be easy to
decide to if we need do the cleanup in the KOUTPUT_BUILD path, if the
testcase ran immediately after compiled.

Signed-off-by: Bamvor Jian Zhang 


All of these:


 tools/testing/selftests/powerpc/benchmarks/Makefile   |  5 ++---
 tools/testing/selftests/powerpc/copyloops/Makefile|  3 +--
 tools/testing/selftests/powerpc/dscr/Makefile |  4 ++--
 tools/testing/selftests/powerpc/math/Makefile |  5 ++---
 tools/testing/selftests/powerpc/primitives/Makefile   |  5 ++---
 tools/testing/selftests/powerpc/stringloops/Makefile  |  5 ++---
 tools/testing/selftests/powerpc/syscalls/Makefile |  5 ++---
 tools/testing/selftests/powerpc/tm/Makefile   |  5 ++---


are just cleaning *.o, and I'm pretty sure none of them need to. So for
those you can just drop the custom clean rule.

Sorry I do not check these. Because I define the fake target for
testing for ppc. Then I could remove *.o directly in above files.

Regards

Bamvor


This one does need a custom rule:


 .../testing/selftests/powerpc/switch_endian/Makefile  |  5 ++---



cheers





Re: [PATCH RFC 5/6] selftests: add EXTRA_CLEAN for clean target

2016-11-18 Thread Zhangjian (Bamvor)

Hi, Micheal

On 2016/11/18 19:01, Michael Ellerman wrote:

bamvor.zhangj...@huawei.com writes:


From: Bamvor Jian Zhang 

Some testcases need the clean extra data after running. This patch
introduce the "EXTRA_CLEAN" variable to address this requirement.


The idea here is fine I think. But this will need reworking if you
follow my suggestions for patch 1.


After KOUTPUT_BUILD is enabled in later patch, it will be easy to
decide to if we need do the cleanup in the KOUTPUT_BUILD path, if the
testcase ran immediately after compiled.

Signed-off-by: Bamvor Jian Zhang 


All of these:


 tools/testing/selftests/powerpc/benchmarks/Makefile   |  5 ++---
 tools/testing/selftests/powerpc/copyloops/Makefile|  3 +--
 tools/testing/selftests/powerpc/dscr/Makefile |  4 ++--
 tools/testing/selftests/powerpc/math/Makefile |  5 ++---
 tools/testing/selftests/powerpc/primitives/Makefile   |  5 ++---
 tools/testing/selftests/powerpc/stringloops/Makefile  |  5 ++---
 tools/testing/selftests/powerpc/syscalls/Makefile |  5 ++---
 tools/testing/selftests/powerpc/tm/Makefile   |  5 ++---


are just cleaning *.o, and I'm pretty sure none of them need to. So for
those you can just drop the custom clean rule.

Sorry I do not check these. Because I define the fake target for
testing for ppc. Then I could remove *.o directly in above files.

Regards

Bamvor


This one does need a custom rule:


 .../testing/selftests/powerpc/switch_endian/Makefile  |  5 ++---



cheers





Re: ILP32 for ARM64 - testing with lmbench

2016-11-16 Thread Zhangjian (Bamvor)

Hi, Maxim

On 2016/11/17 13:02, Maxim Kuvyrkov wrote:

Hi Bamvor,

I'm surprised that you see this much difference from ILP32 patches on SPEC 
CPU2006int at all.  The SPEC CPU2006 benchmarks spend almost no time in the 
kernel syscalls.  I can imagine memory, TLB, and cache handling in the kernel 
could affect CPU2006 benchmarks.  Do ILP32 patches touch code in those areas?

Other than that, it would be interesting to check what the variance is between 
the 3 iterations of benchmark runs.  Could you check what relative standard 
deviation is between the 3 iterations -- (STDEV(RUN1, RUN2, RUN3) / 
RUNselected)?

For reference, in my [non-ILP32] benchmarking I see 1.1% for 401.bzip2,  0.8% 
for 429.mcf, 0.2% for 456.hmmer, and 0.1% for 462.libquantum.

Here is my result:
ILP32_mergedILP32_unmerged
  401.bzip20.31%0.26%
  429.mcf  1.61%1.36%
  456.hmmer1.37%1.57%
  462.libquantum   0.29%0.28%

Regards

Bamvor



--
Maxim Kuvyrkov
www.linaro.org




On Nov 17, 2016, at 7:28 AM, Zhangjian (Bamvor) <bamvor.zhangj...@huawei.com> 
wrote:

Hi, all

I test specint of aarch64 LP64 when aarch32 el0 disable/enabled respectively
and compare with ILP32 unmerged kernel(4.8-rc6) in our arm64 board. I found
that difference(ILP32 disabled/ILP32 unmerged) is bigger when aarch32 el0 is
enabled, compare with aarch32 el0 disabled kernel. And bzip2, mcg, hmmer,
libquantum are the top four differences[1]. Note that bigger is better in
specint test.

In order to make sure the above results, I retest these four testcases in
reportable way(reference the command in the end). The result[2] show that
libquantum decrease -2.09% after ILP32 enabled and aarch32 on. I think it is in
significant.

The result of lmbench is not stable in my board. I plan to dig it later.

[1] The following test result is tested through --size=ref --iterations=3.
1.1 Test when aarch32_el0 is enabled.
   ILP32 disabledbase line
 400.perlbench100.00% 100%
 401.bzip2 99.35% 100%
 403.gcc  100.26% 100%
 429.mcf  102.75% 100%
 445.gobmk100.00% 100%
 456.hmmer 95.66% 100%
 458.sjeng100.00% 100%
 462.libquantum   100.00% 100%
 471.omnetpp  100.59% 100%
 473.astar 99.66% 100%
 483.xalancbmk 99.10% 100%

1.2 Test when aarch32_el0 is disabled
   ILP32 disabled base line
 400.perlbench100.22%  100%
 401.bzip2100.95%  100%
 403.gcc  100.20%  100%
 429.mcf  100.76%  100%
 445.gobmk100.36%  100%
 456.hmmer 97.94%  100%
 458.sjeng 99.73%  100%
 462.libquantum98.72%  100%
 471.omnetpp  100.86%  100%
 473.astar 99.15%  100%
 483.xalancbmk100.08%  100%

[2] The following test result is tested through: runspec --config=my.cfg 
--size=test,train,ref --noreportable --tune=base,peak --iterations=3 bzip2 mcf 
hmmer libquantum
2.1 Test when aarch32_el0 is enabled.
ILP32_enabled base line
 401.bzip2100.82%  100%
 429.mcf  100.18%  100%
 456.hmmer 99.64%  100%
 462.libquantum97.91%  100%

Regards

Bamvor

On 2016/10/28 20:46, Yury Norov wrote:

[Add Steve Ellcey, thanks for testing on ThunderX]

Lmbench-3.0-a9 testing is performed on ThunderX machine to check that
ILP32 series does not add performance regressions for LP64. Test
summary is in the table below. Our measurements doesn't show
significant performance regression of LP64 if ILP32 code is merged,
both enabled or disabled.

  ILP32 enabled   ILP32  disabled   Standard Kernel
null syscall   0.1066  0.11210.1121
  95.09%  100.00%

stat   1.3947  1.38141.3864
  100.60% 99.64%

fstat  0.4459  0.43440.4524
  98.56%  96.02%

open/close 4.0606  4.04114.0453
  100.38% 99.90%

read   0.4819  0.50140.5014
  96.11%  100.00%

Tested with linux 4.8 because 4.9-rc1 is not fixed yet for ThunderX.
Other system details below.

Yury.

ubuntu@crb6:~$ uname -a
Linux crb6 4.8.0+ #3 SMP Thu Oct 27 11:01:32 PDT 2016 a

Re: ILP32 for ARM64 - testing with lmbench

2016-11-16 Thread Zhangjian (Bamvor)

Hi, Maxim

On 2016/11/17 13:02, Maxim Kuvyrkov wrote:

Hi Bamvor,

I'm surprised that you see this much difference from ILP32 patches on SPEC 
CPU2006int at all.  The SPEC CPU2006 benchmarks spend almost no time in the 
kernel syscalls.  I can imagine memory, TLB, and cache handling in the kernel 
could affect CPU2006 benchmarks.  Do ILP32 patches touch code in those areas?

Other than that, it would be interesting to check what the variance is between 
the 3 iterations of benchmark runs.  Could you check what relative standard 
deviation is between the 3 iterations -- (STDEV(RUN1, RUN2, RUN3) / 
RUNselected)?

For reference, in my [non-ILP32] benchmarking I see 1.1% for 401.bzip2,  0.8% 
for 429.mcf, 0.2% for 456.hmmer, and 0.1% for 462.libquantum.

Here is my result:
ILP32_mergedILP32_unmerged
  401.bzip20.31%0.26%
  429.mcf  1.61%1.36%
  456.hmmer1.37%1.57%
  462.libquantum   0.29%0.28%

Regards

Bamvor



--
Maxim Kuvyrkov
www.linaro.org




On Nov 17, 2016, at 7:28 AM, Zhangjian (Bamvor)  
wrote:

Hi, all

I test specint of aarch64 LP64 when aarch32 el0 disable/enabled respectively
and compare with ILP32 unmerged kernel(4.8-rc6) in our arm64 board. I found
that difference(ILP32 disabled/ILP32 unmerged) is bigger when aarch32 el0 is
enabled, compare with aarch32 el0 disabled kernel. And bzip2, mcg, hmmer,
libquantum are the top four differences[1]. Note that bigger is better in
specint test.

In order to make sure the above results, I retest these four testcases in
reportable way(reference the command in the end). The result[2] show that
libquantum decrease -2.09% after ILP32 enabled and aarch32 on. I think it is in
significant.

The result of lmbench is not stable in my board. I plan to dig it later.

[1] The following test result is tested through --size=ref --iterations=3.
1.1 Test when aarch32_el0 is enabled.
   ILP32 disabledbase line
 400.perlbench100.00% 100%
 401.bzip2 99.35% 100%
 403.gcc  100.26% 100%
 429.mcf  102.75% 100%
 445.gobmk100.00% 100%
 456.hmmer 95.66% 100%
 458.sjeng100.00% 100%
 462.libquantum   100.00% 100%
 471.omnetpp  100.59% 100%
 473.astar 99.66% 100%
 483.xalancbmk 99.10% 100%

1.2 Test when aarch32_el0 is disabled
   ILP32 disabled base line
 400.perlbench100.22%  100%
 401.bzip2100.95%  100%
 403.gcc  100.20%  100%
 429.mcf  100.76%  100%
 445.gobmk100.36%  100%
 456.hmmer 97.94%  100%
 458.sjeng 99.73%  100%
 462.libquantum98.72%  100%
 471.omnetpp  100.86%  100%
 473.astar 99.15%  100%
 483.xalancbmk100.08%  100%

[2] The following test result is tested through: runspec --config=my.cfg 
--size=test,train,ref --noreportable --tune=base,peak --iterations=3 bzip2 mcf 
hmmer libquantum
2.1 Test when aarch32_el0 is enabled.
ILP32_enabled base line
 401.bzip2100.82%  100%
 429.mcf  100.18%  100%
 456.hmmer 99.64%  100%
 462.libquantum97.91%  100%

Regards

Bamvor

On 2016/10/28 20:46, Yury Norov wrote:

[Add Steve Ellcey, thanks for testing on ThunderX]

Lmbench-3.0-a9 testing is performed on ThunderX machine to check that
ILP32 series does not add performance regressions for LP64. Test
summary is in the table below. Our measurements doesn't show
significant performance regression of LP64 if ILP32 code is merged,
both enabled or disabled.

  ILP32 enabled   ILP32  disabled   Standard Kernel
null syscall   0.1066  0.11210.1121
  95.09%  100.00%

stat   1.3947  1.38141.3864
  100.60% 99.64%

fstat  0.4459  0.43440.4524
  98.56%  96.02%

open/close 4.0606  4.04114.0453
  100.38% 99.90%

read   0.4819  0.50140.5014
  96.11%  100.00%

Tested with linux 4.8 because 4.9-rc1 is not fixed yet for ThunderX.
Other system details below.

Yury.

ubuntu@crb6:~$ uname -a
Linux crb6 4.8.0+ #3 SMP Thu Oct 27 11:01:32 PDT 2016 aarch64 aarch64 aarch64 
GNU/Linux

Re: ILP32 for ARM64 - testing with lmbench

2016-11-16 Thread Zhangjian (Bamvor)

Hi, all

I test specint of aarch64 LP64 when aarch32 el0 disable/enabled respectively
and compare with ILP32 unmerged kernel(4.8-rc6) in our arm64 board. I found
that difference(ILP32 disabled/ILP32 unmerged) is bigger when aarch32 el0 is
enabled, compare with aarch32 el0 disabled kernel. And bzip2, mcg, hmmer,
libquantum are the top four differences[1]. Note that bigger is better in
specint test.

In order to make sure the above results, I retest these four testcases in
reportable way(reference the command in the end). The result[2] show that
libquantum decrease -2.09% after ILP32 enabled and aarch32 on. I think it is in
significant.

The result of lmbench is not stable in my board. I plan to dig it later.

[1] The following test result is tested through --size=ref --iterations=3.
1.1 Test when aarch32_el0 is enabled.
ILP32 disabledbase line
  400.perlbench100.00% 100%
  401.bzip2 99.35% 100%
  403.gcc  100.26% 100%
  429.mcf  102.75% 100%
  445.gobmk100.00% 100%
  456.hmmer 95.66% 100%
  458.sjeng100.00% 100%
  462.libquantum   100.00% 100%
  471.omnetpp  100.59% 100%
  473.astar 99.66% 100%
  483.xalancbmk 99.10% 100%

1.2 Test when aarch32_el0 is disabled
ILP32 disabled base line
  400.perlbench100.22%  100%
  401.bzip2100.95%  100%
  403.gcc  100.20%  100%
  429.mcf  100.76%  100%
  445.gobmk100.36%  100%
  456.hmmer 97.94%  100%
  458.sjeng 99.73%  100%
  462.libquantum98.72%  100%
  471.omnetpp  100.86%  100%
  473.astar 99.15%  100%
  483.xalancbmk100.08%  100%

[2] The following test result is tested through: runspec --config=my.cfg 
--size=test,train,ref --noreportable --tune=base,peak --iterations=3 bzip2 mcf 
hmmer libquantum
2.1 Test when aarch32_el0 is enabled.
 ILP32_enabled base line
  401.bzip2100.82%  100%
  429.mcf  100.18%  100%
  456.hmmer 99.64%  100%
  462.libquantum97.91%  100%

Regards

Bamvor

On 2016/10/28 20:46, Yury Norov wrote:

[Add Steve Ellcey, thanks for testing on ThunderX]

Lmbench-3.0-a9 testing is performed on ThunderX machine to check that
ILP32 series does not add performance regressions for LP64. Test
summary is in the table below. Our measurements doesn't show
significant performance regression of LP64 if ILP32 code is merged,
both enabled or disabled.

   ILP32 enabled   ILP32  disabled   Standard Kernel
null syscall   0.1066  0.11210.1121
   95.09%  100.00%

stat   1.3947  1.38141.3864
   100.60% 99.64%

fstat  0.4459  0.43440.4524
   98.56%  96.02%

open/close 4.0606  4.04114.0453
   100.38% 99.90%

read   0.4819  0.50140.5014
   96.11%  100.00%

Tested with linux 4.8 because 4.9-rc1 is not fixed yet for ThunderX.
Other system details below.

Yury.

ubuntu@crb6:~$ uname -a
Linux crb6 4.8.0+ #3 SMP Thu Oct 27 11:01:32 PDT 2016 aarch64 aarch64 aarch64 
GNU/Linux

ubuntu@crb6:~$ cat /proc/meminfo
MemTotal:   132011948 kB
MemFree:131442672 kB
MemAvailable:   130695764 kB
Buffers:   15696 kB
Cached:88088 kB
SwapCached:0 kB
Active:82760 kB
Inactive:  41336 kB
Active(anon):  20880 kB
Inactive(anon): 8576 kB
Active(file):  61880 kB
Inactive(file):32760 kB
Unevictable:   0 kB
Mlocked:   0 kB
SwapTotal:  128920572 kB
SwapFree:   128920572 kB
Dirty: 0 kB
Writeback: 0 kB
AnonPages: 20544 kB
Mapped:19780 kB
Shmem:  9060 kB
Slab:  78804 kB
SReclaimable:  27372 kB
SUnreclaim:51432 kB
KernelStack:8336 kB
PageTables:  820 kB
NFS_Unstable:  0 kB
Bounce:0 kB
WritebackTmp:  0 kB
CommitLimit:194926544 kB
Committed_AS: 256324 kB
VmallocTotal:   135290290112 kB
VmallocUsed:   0 kB
VmallocChunk:  0 kB
AnonHugePages: 0 kB
ShmemHugePages:0 kB
ShmemPmdMapped:0 kB
CmaTotal:  0 kB

Re: ILP32 for ARM64 - testing with lmbench

2016-11-16 Thread Zhangjian (Bamvor)

Hi, all

I test specint of aarch64 LP64 when aarch32 el0 disable/enabled respectively
and compare with ILP32 unmerged kernel(4.8-rc6) in our arm64 board. I found
that difference(ILP32 disabled/ILP32 unmerged) is bigger when aarch32 el0 is
enabled, compare with aarch32 el0 disabled kernel. And bzip2, mcg, hmmer,
libquantum are the top four differences[1]. Note that bigger is better in
specint test.

In order to make sure the above results, I retest these four testcases in
reportable way(reference the command in the end). The result[2] show that
libquantum decrease -2.09% after ILP32 enabled and aarch32 on. I think it is in
significant.

The result of lmbench is not stable in my board. I plan to dig it later.

[1] The following test result is tested through --size=ref --iterations=3.
1.1 Test when aarch32_el0 is enabled.
ILP32 disabledbase line
  400.perlbench100.00% 100%
  401.bzip2 99.35% 100%
  403.gcc  100.26% 100%
  429.mcf  102.75% 100%
  445.gobmk100.00% 100%
  456.hmmer 95.66% 100%
  458.sjeng100.00% 100%
  462.libquantum   100.00% 100%
  471.omnetpp  100.59% 100%
  473.astar 99.66% 100%
  483.xalancbmk 99.10% 100%

1.2 Test when aarch32_el0 is disabled
ILP32 disabled base line
  400.perlbench100.22%  100%
  401.bzip2100.95%  100%
  403.gcc  100.20%  100%
  429.mcf  100.76%  100%
  445.gobmk100.36%  100%
  456.hmmer 97.94%  100%
  458.sjeng 99.73%  100%
  462.libquantum98.72%  100%
  471.omnetpp  100.86%  100%
  473.astar 99.15%  100%
  483.xalancbmk100.08%  100%

[2] The following test result is tested through: runspec --config=my.cfg 
--size=test,train,ref --noreportable --tune=base,peak --iterations=3 bzip2 mcf 
hmmer libquantum
2.1 Test when aarch32_el0 is enabled.
 ILP32_enabled base line
  401.bzip2100.82%  100%
  429.mcf  100.18%  100%
  456.hmmer 99.64%  100%
  462.libquantum97.91%  100%

Regards

Bamvor

On 2016/10/28 20:46, Yury Norov wrote:

[Add Steve Ellcey, thanks for testing on ThunderX]

Lmbench-3.0-a9 testing is performed on ThunderX machine to check that
ILP32 series does not add performance regressions for LP64. Test
summary is in the table below. Our measurements doesn't show
significant performance regression of LP64 if ILP32 code is merged,
both enabled or disabled.

   ILP32 enabled   ILP32  disabled   Standard Kernel
null syscall   0.1066  0.11210.1121
   95.09%  100.00%

stat   1.3947  1.38141.3864
   100.60% 99.64%

fstat  0.4459  0.43440.4524
   98.56%  96.02%

open/close 4.0606  4.04114.0453
   100.38% 99.90%

read   0.4819  0.50140.5014
   96.11%  100.00%

Tested with linux 4.8 because 4.9-rc1 is not fixed yet for ThunderX.
Other system details below.

Yury.

ubuntu@crb6:~$ uname -a
Linux crb6 4.8.0+ #3 SMP Thu Oct 27 11:01:32 PDT 2016 aarch64 aarch64 aarch64 
GNU/Linux

ubuntu@crb6:~$ cat /proc/meminfo
MemTotal:   132011948 kB
MemFree:131442672 kB
MemAvailable:   130695764 kB
Buffers:   15696 kB
Cached:88088 kB
SwapCached:0 kB
Active:82760 kB
Inactive:  41336 kB
Active(anon):  20880 kB
Inactive(anon): 8576 kB
Active(file):  61880 kB
Inactive(file):32760 kB
Unevictable:   0 kB
Mlocked:   0 kB
SwapTotal:  128920572 kB
SwapFree:   128920572 kB
Dirty: 0 kB
Writeback: 0 kB
AnonPages: 20544 kB
Mapped:19780 kB
Shmem:  9060 kB
Slab:  78804 kB
SReclaimable:  27372 kB
SUnreclaim:51432 kB
KernelStack:8336 kB
PageTables:  820 kB
NFS_Unstable:  0 kB
Bounce:0 kB
WritebackTmp:  0 kB
CommitLimit:194926544 kB
Committed_AS: 256324 kB
VmallocTotal:   135290290112 kB
VmallocUsed:   0 kB
VmallocChunk:  0 kB
AnonHugePages: 0 kB
ShmemHugePages:0 kB
ShmemPmdMapped:0 kB
CmaTotal:  0 kB

Re: [RFC2 PATCH 00/23] ARM64: support ILP32

2016-09-08 Thread Zhangjian (Bamvor)

Hi, Yury

On 2016/9/8 19:37, Yury Norov wrote:

On Thu, Sep 08, 2016 at 12:25:27PM +0800, Zhangjian (Bamvor) wrote:

Hi, Guys

There was a discussion about bump vdso version of kernel. We need
update the vdso version in glibc correspondingly otherwise the
application could not make use of the vdso.

Is it make sense to you?

Regards

Bamvor


Hi Bamvor,

Is this the source of performance loss you've discovered?

Not yet.
There are mmmapstress03和vma03 failed in our kernel. I plan to
investigatet those bugs firstly. Do you encounter those failures?

Regards

Bamvor




commit 3ffc1d798fc25ccb02e7cc325fe5fb3890c085e3
Author: Bamvor Jian Zhang <bamvor.zhangj...@linaro.org>
Date:   Thu Sep 8 12:21:16 2016 +0800

[AARCH64] ILP32: bump vdso version consistent with kernel

Signed-off-by: Jun Ji <jij...@huawei.com>
Signed-off-by: Bamvor Jian Zhang <bamvor.zhangj...@linaro.org>

diff --git a/sysdeps/unix/sysv/linux/aarch64/init-first.c 
b/sysdeps/unix/sysv/linux/aarch64/init-first.c
index f7224a2..3e4eaad 100644
--- a/sysdeps/unix/sysv/linux/aarch64/init-first.c
+++ b/sysdeps/unix/sysv/linux/aarch64/init-first.c
@@ -27,17 +27,21 @@ int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct 
timespec *);
 static inline void
 _libc_vdso_platform_setup (void)
 {
-  PREPARE_VERSION (linux2639, "LINUX_2.6.39", 123718537);
+#ifndef __ILP32__
+  PREPARE_VERSION (linux, "LINUX_2.6.39", 123718537);
+#else
+  PREPARE_VERSION (linux, "LINUX_4.8", 61765624);
+#endif /* #ifndef __ILP32__ */

-  void *p = _dl_vdso_vsym ("__kernel_gettimeofday", );
+  void *p = _dl_vdso_vsym ("__kernel_gettimeofday", );
   PTR_MANGLE (p);
   VDSO_SYMBOL(gettimeofday) = p;

-  p = _dl_vdso_vsym ("__kernel_clock_gettime", );
+  p = _dl_vdso_vsym ("__kernel_clock_gettime", );
   PTR_MANGLE (p);
   VDSO_SYMBOL(clock_gettime) = p;

-  p = _dl_vdso_vsym ("__kernel_clock_getres", );
+  p = _dl_vdso_vsym ("__kernel_clock_getres", );
   PTR_MANGLE (p);
   VDSO_SYMBOL(clock_getres) = p;
 }


On 2016/6/29 0:39, Yury Norov wrote:

This series enables aarch64 port with ilp32 mode.

ABI details:
- types are taken from AARCH32, next types turned to 64-bit,
  as modern requirement for new APIs tells:
ino_t  is  u64 type
off_t  is  s64 type
blkcnt_t   is  s64 type
fsblkcnt_t is  u64 type
fsfilcnt_t is  u64 type
- 64-bit arguments are passed in syscall as register pair,
  as kernel internally clears top halves for all input regs;
- standard syscall table is used;
- 32-bit time_t is used. AARCH64/ILP32 is waiting for general
  fix of Y2038 problem just like other 32-bit arches;
- stat{64}, statfs{64} structures are of the identical layout
  with LP64. Corresponding syscalls are taken from 64-bit code
- struct utmp, utmpx layouts are the same.

v1: https://sourceware.org/ml/libc-alpha/2016-06/msg00730.html
v2:
- rebased on master;
- dropped unneeded/unrelated patches;
- pread family platform implementation removed;
- addressed v1 comments (I'm really sorry if I missed something,
  there are a lot of them, and I am really thankfull for detailed review);

Tested with LTP. Regressions are like this:
abort01FAIL   2
kill11 FAIL   2
mmap16 FAIL   6
open12 FAIL   2
rename11   FAIL   2
rmdir02FAIL   2
umount2_01 FAIL   2
umount2_02 FAIL   2
umount2_03 FAIL   2
utime06FAIL   2

It's better than v1, and there are ~5 additional regressions comparing to
aarch64, all are related to filesystem.

Andrew Pinski (17):
 [AARCH64] define word size for lp64 and ilp32
 [AARCH64] Add header guards to sysdep.h headers.
 Add dynamic ILP32 AARCH64 relocations to elf.h
 [AARCH64] Add PTR_REG, PTR_LOG_SIZE, and PTR_SIZE.  Use it in
   LDST_PCREL and LDST_GLOBAL.
 [AARCH64] Use PTR_REG in crti.S.
 [AARCH64] Use PTR_REG/PTR_SIZE/PTR_SIZE_LOG in dl-tlsesc.S
 [AARCH64] Use PTR_* macros in dl-trampoline.S
 [AARCH64] Use PTR_* in start.S
 [AARCH64] Use PTR_REG in getcontext.S.
 [AARCH64] Detect ILP32 in configure scripts.
 [AARCH64] Add ILP32 support to elf_machine_load_address.
 [AARCH64] Add ILP32 to makefiles
 [AARCH64] Add support to ldconfig for ILP32 and libilp32
 [AARCH64] Add ILP32 ld.so to the known interpreter names.
 [AARCH64] Add ldd-rewrite.sed so that ilp32 ld.so can be found
 [AARCH64] Make lp64 and ilp32 directories.
 [AARCH64] Fix ILP32 warning

Yury Norov (6):
 [AARCH64] ILP32: introduce syscalls that pass off_t
 [AARCH64] ILP32: support stat syscall family
 [AARCH64] delouse input arguments in system functions
 [AARCH64] Make __SIZEOF_SEM_T 16 for ILP32
 off_t: fix register pair calculation for 64-bit case
 [AARCH64] Take utmp{,x}.h from s390 port

elf/cac

Re: [RFC2 PATCH 00/23] ARM64: support ILP32

2016-09-08 Thread Zhangjian (Bamvor)

Hi, Yury

On 2016/9/8 19:37, Yury Norov wrote:

On Thu, Sep 08, 2016 at 12:25:27PM +0800, Zhangjian (Bamvor) wrote:

Hi, Guys

There was a discussion about bump vdso version of kernel. We need
update the vdso version in glibc correspondingly otherwise the
application could not make use of the vdso.

Is it make sense to you?

Regards

Bamvor


Hi Bamvor,

Is this the source of performance loss you've discovered?

Not yet.
There are mmmapstress03和vma03 failed in our kernel. I plan to
investigatet those bugs firstly. Do you encounter those failures?

Regards

Bamvor




commit 3ffc1d798fc25ccb02e7cc325fe5fb3890c085e3
Author: Bamvor Jian Zhang 
Date:   Thu Sep 8 12:21:16 2016 +0800

[AARCH64] ILP32: bump vdso version consistent with kernel

Signed-off-by: Jun Ji 
Signed-off-by: Bamvor Jian Zhang 

diff --git a/sysdeps/unix/sysv/linux/aarch64/init-first.c 
b/sysdeps/unix/sysv/linux/aarch64/init-first.c
index f7224a2..3e4eaad 100644
--- a/sysdeps/unix/sysv/linux/aarch64/init-first.c
+++ b/sysdeps/unix/sysv/linux/aarch64/init-first.c
@@ -27,17 +27,21 @@ int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct 
timespec *);
 static inline void
 _libc_vdso_platform_setup (void)
 {
-  PREPARE_VERSION (linux2639, "LINUX_2.6.39", 123718537);
+#ifndef __ILP32__
+  PREPARE_VERSION (linux, "LINUX_2.6.39", 123718537);
+#else
+  PREPARE_VERSION (linux, "LINUX_4.8", 61765624);
+#endif /* #ifndef __ILP32__ */

-  void *p = _dl_vdso_vsym ("__kernel_gettimeofday", );
+  void *p = _dl_vdso_vsym ("__kernel_gettimeofday", );
   PTR_MANGLE (p);
   VDSO_SYMBOL(gettimeofday) = p;

-  p = _dl_vdso_vsym ("__kernel_clock_gettime", );
+  p = _dl_vdso_vsym ("__kernel_clock_gettime", );
   PTR_MANGLE (p);
   VDSO_SYMBOL(clock_gettime) = p;

-  p = _dl_vdso_vsym ("__kernel_clock_getres", );
+  p = _dl_vdso_vsym ("__kernel_clock_getres", );
   PTR_MANGLE (p);
   VDSO_SYMBOL(clock_getres) = p;
 }


On 2016/6/29 0:39, Yury Norov wrote:

This series enables aarch64 port with ilp32 mode.

ABI details:
- types are taken from AARCH32, next types turned to 64-bit,
  as modern requirement for new APIs tells:
ino_t  is  u64 type
off_t  is  s64 type
blkcnt_t   is  s64 type
fsblkcnt_t is  u64 type
fsfilcnt_t is  u64 type
- 64-bit arguments are passed in syscall as register pair,
  as kernel internally clears top halves for all input regs;
- standard syscall table is used;
- 32-bit time_t is used. AARCH64/ILP32 is waiting for general
  fix of Y2038 problem just like other 32-bit arches;
- stat{64}, statfs{64} structures are of the identical layout
  with LP64. Corresponding syscalls are taken from 64-bit code
- struct utmp, utmpx layouts are the same.

v1: https://sourceware.org/ml/libc-alpha/2016-06/msg00730.html
v2:
- rebased on master;
- dropped unneeded/unrelated patches;
- pread family platform implementation removed;
- addressed v1 comments (I'm really sorry if I missed something,
  there are a lot of them, and I am really thankfull for detailed review);

Tested with LTP. Regressions are like this:
abort01FAIL   2
kill11 FAIL   2
mmap16 FAIL   6
open12 FAIL   2
rename11   FAIL   2
rmdir02FAIL   2
umount2_01 FAIL   2
umount2_02 FAIL   2
umount2_03 FAIL   2
utime06FAIL   2

It's better than v1, and there are ~5 additional regressions comparing to
aarch64, all are related to filesystem.

Andrew Pinski (17):
 [AARCH64] define word size for lp64 and ilp32
 [AARCH64] Add header guards to sysdep.h headers.
 Add dynamic ILP32 AARCH64 relocations to elf.h
 [AARCH64] Add PTR_REG, PTR_LOG_SIZE, and PTR_SIZE.  Use it in
   LDST_PCREL and LDST_GLOBAL.
 [AARCH64] Use PTR_REG in crti.S.
 [AARCH64] Use PTR_REG/PTR_SIZE/PTR_SIZE_LOG in dl-tlsesc.S
 [AARCH64] Use PTR_* macros in dl-trampoline.S
 [AARCH64] Use PTR_* in start.S
 [AARCH64] Use PTR_REG in getcontext.S.
 [AARCH64] Detect ILP32 in configure scripts.
 [AARCH64] Add ILP32 support to elf_machine_load_address.
 [AARCH64] Add ILP32 to makefiles
 [AARCH64] Add support to ldconfig for ILP32 and libilp32
 [AARCH64] Add ILP32 ld.so to the known interpreter names.
 [AARCH64] Add ldd-rewrite.sed so that ilp32 ld.so can be found
 [AARCH64] Make lp64 and ilp32 directories.
 [AARCH64] Fix ILP32 warning

Yury Norov (6):
 [AARCH64] ILP32: introduce syscalls that pass off_t
 [AARCH64] ILP32: support stat syscall family
 [AARCH64] delouse input arguments in system functions
 [AARCH64] Make __SIZEOF_SEM_T 16 for ILP32
 off_t: fix register pair calculation for 64-bit case
 [AARCH64] Take utmp{,x}.h from s390 port

elf/cache.c|   3 +
sysdeps/aarch64/Implies 

Re: [RFC2 PATCH 00/23] ARM64: support ILP32

2016-09-07 Thread Zhangjian (Bamvor)

Hi, Guys

There was a discussion about bump vdso version of kernel. We need
update the vdso version in glibc correspondingly otherwise the
application could not make use of the vdso.

Is it make sense to you?

Regards

Bamvor

commit 3ffc1d798fc25ccb02e7cc325fe5fb3890c085e3
Author: Bamvor Jian Zhang 
Date:   Thu Sep 8 12:21:16 2016 +0800

[AARCH64] ILP32: bump vdso version consistent with kernel

Signed-off-by: Jun Ji 
Signed-off-by: Bamvor Jian Zhang 

diff --git a/sysdeps/unix/sysv/linux/aarch64/init-first.c 
b/sysdeps/unix/sysv/linux/aarch64/init-first.c
index f7224a2..3e4eaad 100644
--- a/sysdeps/unix/sysv/linux/aarch64/init-first.c
+++ b/sysdeps/unix/sysv/linux/aarch64/init-first.c
@@ -27,17 +27,21 @@ int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct 
timespec *);
 static inline void
 _libc_vdso_platform_setup (void)
 {
-  PREPARE_VERSION (linux2639, "LINUX_2.6.39", 123718537);
+#ifndef __ILP32__
+  PREPARE_VERSION (linux, "LINUX_2.6.39", 123718537);
+#else
+  PREPARE_VERSION (linux, "LINUX_4.8", 61765624);
+#endif /* #ifndef __ILP32__ */

-  void *p = _dl_vdso_vsym ("__kernel_gettimeofday", );
+  void *p = _dl_vdso_vsym ("__kernel_gettimeofday", );
   PTR_MANGLE (p);
   VDSO_SYMBOL(gettimeofday) = p;

-  p = _dl_vdso_vsym ("__kernel_clock_gettime", );
+  p = _dl_vdso_vsym ("__kernel_clock_gettime", );
   PTR_MANGLE (p);
   VDSO_SYMBOL(clock_gettime) = p;

-  p = _dl_vdso_vsym ("__kernel_clock_getres", );
+  p = _dl_vdso_vsym ("__kernel_clock_getres", );
   PTR_MANGLE (p);
   VDSO_SYMBOL(clock_getres) = p;
 }


On 2016/6/29 0:39, Yury Norov wrote:

This series enables aarch64 port with ilp32 mode.

ABI details:
 - types are taken from AARCH32, next types turned to 64-bit,
   as modern requirement for new APIs tells:
ino_t  is  u64 type
off_t  is  s64 type
blkcnt_t   is  s64 type
fsblkcnt_t is  u64 type
fsfilcnt_t is  u64 type
 - 64-bit arguments are passed in syscall as register pair,
   as kernel internally clears top halves for all input regs;
 - standard syscall table is used;
 - 32-bit time_t is used. AARCH64/ILP32 is waiting for general
   fix of Y2038 problem just like other 32-bit arches;
 - stat{64}, statfs{64} structures are of the identical layout
   with LP64. Corresponding syscalls are taken from 64-bit code
 - struct utmp, utmpx layouts are the same.

v1: https://sourceware.org/ml/libc-alpha/2016-06/msg00730.html
v2:
 - rebased on master;
 - dropped unneeded/unrelated patches;
 - pread family platform implementation removed;
 - addressed v1 comments (I'm really sorry if I missed something,
   there are a lot of them, and I am really thankfull for detailed review);

Tested with LTP. Regressions are like this:
abort01FAIL   2
kill11 FAIL   2
mmap16 FAIL   6
open12 FAIL   2
rename11   FAIL   2
rmdir02FAIL   2
umount2_01 FAIL   2
umount2_02 FAIL   2
umount2_03 FAIL   2
utime06FAIL   2

It's better than v1, and there are ~5 additional regressions comparing to
aarch64, all are related to filesystem.

Andrew Pinski (17):
  [AARCH64] define word size for lp64 and ilp32
  [AARCH64] Add header guards to sysdep.h headers.
  Add dynamic ILP32 AARCH64 relocations to elf.h
  [AARCH64] Add PTR_REG, PTR_LOG_SIZE, and PTR_SIZE.  Use it in
LDST_PCREL and LDST_GLOBAL.
  [AARCH64] Use PTR_REG in crti.S.
  [AARCH64] Use PTR_REG/PTR_SIZE/PTR_SIZE_LOG in dl-tlsesc.S
  [AARCH64] Use PTR_* macros in dl-trampoline.S
  [AARCH64] Use PTR_* in start.S
  [AARCH64] Use PTR_REG in getcontext.S.
  [AARCH64] Detect ILP32 in configure scripts.
  [AARCH64] Add ILP32 support to elf_machine_load_address.
  [AARCH64] Add ILP32 to makefiles
  [AARCH64] Add support to ldconfig for ILP32 and libilp32
  [AARCH64] Add ILP32 ld.so to the known interpreter names.
  [AARCH64] Add ldd-rewrite.sed so that ilp32 ld.so can be found
  [AARCH64] Make lp64 and ilp32 directories.
  [AARCH64] Fix ILP32 warning

Yury Norov (6):
  [AARCH64] ILP32: introduce syscalls that pass off_t
  [AARCH64] ILP32: support stat syscall family
  [AARCH64] delouse input arguments in system functions
  [AARCH64] Make __SIZEOF_SEM_T 16 for ILP32
  off_t: fix register pair calculation for 64-bit case
  [AARCH64] Take utmp{,x}.h from s390 port

 elf/cache.c|   3 +
 sysdeps/aarch64/Implies|   6 -
 sysdeps/aarch64/__longjmp.S|   6 +-
 sysdeps/aarch64/bits/wordsize.h|  25 +++
 sysdeps/aarch64/configure  |  15 +-
 sysdeps/aarch64/configure.ac   |  11 +-
 sysdeps/aarch64/crti.S |   3 +-
 

Re: [RFC2 PATCH 00/23] ARM64: support ILP32

2016-09-07 Thread Zhangjian (Bamvor)

Hi, Guys

There was a discussion about bump vdso version of kernel. We need
update the vdso version in glibc correspondingly otherwise the
application could not make use of the vdso.

Is it make sense to you?

Regards

Bamvor

commit 3ffc1d798fc25ccb02e7cc325fe5fb3890c085e3
Author: Bamvor Jian Zhang 
Date:   Thu Sep 8 12:21:16 2016 +0800

[AARCH64] ILP32: bump vdso version consistent with kernel

Signed-off-by: Jun Ji 
Signed-off-by: Bamvor Jian Zhang 

diff --git a/sysdeps/unix/sysv/linux/aarch64/init-first.c 
b/sysdeps/unix/sysv/linux/aarch64/init-first.c
index f7224a2..3e4eaad 100644
--- a/sysdeps/unix/sysv/linux/aarch64/init-first.c
+++ b/sysdeps/unix/sysv/linux/aarch64/init-first.c
@@ -27,17 +27,21 @@ int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct 
timespec *);
 static inline void
 _libc_vdso_platform_setup (void)
 {
-  PREPARE_VERSION (linux2639, "LINUX_2.6.39", 123718537);
+#ifndef __ILP32__
+  PREPARE_VERSION (linux, "LINUX_2.6.39", 123718537);
+#else
+  PREPARE_VERSION (linux, "LINUX_4.8", 61765624);
+#endif /* #ifndef __ILP32__ */

-  void *p = _dl_vdso_vsym ("__kernel_gettimeofday", );
+  void *p = _dl_vdso_vsym ("__kernel_gettimeofday", );
   PTR_MANGLE (p);
   VDSO_SYMBOL(gettimeofday) = p;

-  p = _dl_vdso_vsym ("__kernel_clock_gettime", );
+  p = _dl_vdso_vsym ("__kernel_clock_gettime", );
   PTR_MANGLE (p);
   VDSO_SYMBOL(clock_gettime) = p;

-  p = _dl_vdso_vsym ("__kernel_clock_getres", );
+  p = _dl_vdso_vsym ("__kernel_clock_getres", );
   PTR_MANGLE (p);
   VDSO_SYMBOL(clock_getres) = p;
 }


On 2016/6/29 0:39, Yury Norov wrote:

This series enables aarch64 port with ilp32 mode.

ABI details:
 - types are taken from AARCH32, next types turned to 64-bit,
   as modern requirement for new APIs tells:
ino_t  is  u64 type
off_t  is  s64 type
blkcnt_t   is  s64 type
fsblkcnt_t is  u64 type
fsfilcnt_t is  u64 type
 - 64-bit arguments are passed in syscall as register pair,
   as kernel internally clears top halves for all input regs;
 - standard syscall table is used;
 - 32-bit time_t is used. AARCH64/ILP32 is waiting for general
   fix of Y2038 problem just like other 32-bit arches;
 - stat{64}, statfs{64} structures are of the identical layout
   with LP64. Corresponding syscalls are taken from 64-bit code
 - struct utmp, utmpx layouts are the same.

v1: https://sourceware.org/ml/libc-alpha/2016-06/msg00730.html
v2:
 - rebased on master;
 - dropped unneeded/unrelated patches;
 - pread family platform implementation removed;
 - addressed v1 comments (I'm really sorry if I missed something,
   there are a lot of them, and I am really thankfull for detailed review);

Tested with LTP. Regressions are like this:
abort01FAIL   2
kill11 FAIL   2
mmap16 FAIL   6
open12 FAIL   2
rename11   FAIL   2
rmdir02FAIL   2
umount2_01 FAIL   2
umount2_02 FAIL   2
umount2_03 FAIL   2
utime06FAIL   2

It's better than v1, and there are ~5 additional regressions comparing to
aarch64, all are related to filesystem.

Andrew Pinski (17):
  [AARCH64] define word size for lp64 and ilp32
  [AARCH64] Add header guards to sysdep.h headers.
  Add dynamic ILP32 AARCH64 relocations to elf.h
  [AARCH64] Add PTR_REG, PTR_LOG_SIZE, and PTR_SIZE.  Use it in
LDST_PCREL and LDST_GLOBAL.
  [AARCH64] Use PTR_REG in crti.S.
  [AARCH64] Use PTR_REG/PTR_SIZE/PTR_SIZE_LOG in dl-tlsesc.S
  [AARCH64] Use PTR_* macros in dl-trampoline.S
  [AARCH64] Use PTR_* in start.S
  [AARCH64] Use PTR_REG in getcontext.S.
  [AARCH64] Detect ILP32 in configure scripts.
  [AARCH64] Add ILP32 support to elf_machine_load_address.
  [AARCH64] Add ILP32 to makefiles
  [AARCH64] Add support to ldconfig for ILP32 and libilp32
  [AARCH64] Add ILP32 ld.so to the known interpreter names.
  [AARCH64] Add ldd-rewrite.sed so that ilp32 ld.so can be found
  [AARCH64] Make lp64 and ilp32 directories.
  [AARCH64] Fix ILP32 warning

Yury Norov (6):
  [AARCH64] ILP32: introduce syscalls that pass off_t
  [AARCH64] ILP32: support stat syscall family
  [AARCH64] delouse input arguments in system functions
  [AARCH64] Make __SIZEOF_SEM_T 16 for ILP32
  off_t: fix register pair calculation for 64-bit case
  [AARCH64] Take utmp{,x}.h from s390 port

 elf/cache.c|   3 +
 sysdeps/aarch64/Implies|   6 -
 sysdeps/aarch64/__longjmp.S|   6 +-
 sysdeps/aarch64/bits/wordsize.h|  25 +++
 sysdeps/aarch64/configure  |  15 +-
 sysdeps/aarch64/configure.ac   |  11 +-
 sysdeps/aarch64/crti.S |   3 +-
 sysdeps/aarch64/dl-irel.h  |   3 +-
 

Re: [PATCH 05/19] arm64: rename COMPAT to AARCH32_EL0 in Kconfig

2016-08-11 Thread Zhangjian (Bamvor)

Hi, Yury

On 2016/6/18 7:54, Yury Norov wrote:

From: Andrew Pinski 

In this patchset  ILP32 ABI support is added. Additionally to AARCH32,
which is binary-compatible with ARM, ILP32 is (mostly) ABI-compatible.

 From now, AARCH32_EL0 (former COMPAT) config option means the support of
AARCH32 userspace, ARM64_ILP32 - support of ILP32 ABI (see next patches),
and COMPAT indicates that one of them, or both, is enabled.

Where needed, CONFIG_COMPAT is changed over to use CONFIG_AARCH32_EL0 instead

Reviewed-by: David Daney 
Signed-off-by: Andrew Pinski 
Signed-off-by: Philipp Tomsich 
Signed-off-by: Christoph Muellner 
Signed-off-by: Bamvor Jian Zhang 
Signed-off-by: Yury Norov 

...

diff --git a/arch/arm64/kernel/cpuinfo.c b/arch/arm64/kernel/cpuinfo.c
index c173d32..af200a8 100644
--- a/arch/arm64/kernel/cpuinfo.c
+++ b/arch/arm64/kernel/cpuinfo.c
@@ -134,15 +134,17 @@ static int c_show(struct seq_file *m, void *v)
 */
seq_puts(m, "Features\t:");
if (compat) {
-#ifdef CONFIG_COMPAT
-   for (j = 0; compat_hwcap_str[j]; j++)
-   if (compat_elf_hwcap & (1 << j))
-   seq_printf(m, " %s", 
compat_hwcap_str[j]);
-
-   for (j = 0; compat_hwcap2_str[j]; j++)
-   if (compat_elf_hwcap2 & (1 << j))
-   seq_printf(m, " %s", 
compat_hwcap2_str[j]);
-#endif /* CONFIG_COMPAT */
+#ifdef CONFIG_AARCH32_EL0

I saw that compat_hwcap_str and compat_hwcap2_str is defined when
"CONFIG_COMPAT" is true. Why we only change it to CONFIG_AARCH32_EL0
in c show()?

+   if (personality(current->personality) == PER_LINUX32) {

And "compat" is "personality(current->personality) == PER_LINUX32;",
it seems that there is no need to add this twice.

Regards

Bamvor

+   for (j = 0; compat_hwcap_str[j]; j++)
+   if (compat_elf_hwcap & (1 << j))
+   seq_printf(m, " %s", 
compat_hwcap_str[j]);
+
+   for (j = 0; compat_hwcap2_str[j]; j++)
+   if (compat_elf_hwcap2 & (1 << j))
+   seq_printf(m, " %s", 
compat_hwcap2_str[j]);
+   }
+#endif /* CONFIG_AARCH32_EL0 */
} else {
for (j = 0; hwcap_str[j]; j++)
if (elf_hwcap & (1 << j))




Re: [PATCH 05/19] arm64: rename COMPAT to AARCH32_EL0 in Kconfig

2016-08-11 Thread Zhangjian (Bamvor)

Hi, Yury

On 2016/6/18 7:54, Yury Norov wrote:

From: Andrew Pinski 

In this patchset  ILP32 ABI support is added. Additionally to AARCH32,
which is binary-compatible with ARM, ILP32 is (mostly) ABI-compatible.

 From now, AARCH32_EL0 (former COMPAT) config option means the support of
AARCH32 userspace, ARM64_ILP32 - support of ILP32 ABI (see next patches),
and COMPAT indicates that one of them, or both, is enabled.

Where needed, CONFIG_COMPAT is changed over to use CONFIG_AARCH32_EL0 instead

Reviewed-by: David Daney 
Signed-off-by: Andrew Pinski 
Signed-off-by: Philipp Tomsich 
Signed-off-by: Christoph Muellner 
Signed-off-by: Bamvor Jian Zhang 
Signed-off-by: Yury Norov 

...

diff --git a/arch/arm64/kernel/cpuinfo.c b/arch/arm64/kernel/cpuinfo.c
index c173d32..af200a8 100644
--- a/arch/arm64/kernel/cpuinfo.c
+++ b/arch/arm64/kernel/cpuinfo.c
@@ -134,15 +134,17 @@ static int c_show(struct seq_file *m, void *v)
 */
seq_puts(m, "Features\t:");
if (compat) {
-#ifdef CONFIG_COMPAT
-   for (j = 0; compat_hwcap_str[j]; j++)
-   if (compat_elf_hwcap & (1 << j))
-   seq_printf(m, " %s", 
compat_hwcap_str[j]);
-
-   for (j = 0; compat_hwcap2_str[j]; j++)
-   if (compat_elf_hwcap2 & (1 << j))
-   seq_printf(m, " %s", 
compat_hwcap2_str[j]);
-#endif /* CONFIG_COMPAT */
+#ifdef CONFIG_AARCH32_EL0

I saw that compat_hwcap_str and compat_hwcap2_str is defined when
"CONFIG_COMPAT" is true. Why we only change it to CONFIG_AARCH32_EL0
in c show()?

+   if (personality(current->personality) == PER_LINUX32) {

And "compat" is "personality(current->personality) == PER_LINUX32;",
it seems that there is no need to add this twice.

Regards

Bamvor

+   for (j = 0; compat_hwcap_str[j]; j++)
+   if (compat_elf_hwcap & (1 << j))
+   seq_printf(m, " %s", 
compat_hwcap_str[j]);
+
+   for (j = 0; compat_hwcap2_str[j]; j++)
+   if (compat_elf_hwcap2 & (1 << j))
+   seq_printf(m, " %s", 
compat_hwcap2_str[j]);
+   }
+#endif /* CONFIG_AARCH32_EL0 */
} else {
for (j = 0; hwcap_str[j]; j++)
if (elf_hwcap & (1 << j))




Re: [RFD] Efficient unit test and fuzz tools for kernel/libc porting

2016-07-21 Thread Zhangjian (Bamvor)

Hi, Joseph

On 2016/7/20 23:47, Joseph Myers wrote:

On Wed, 6 Jul 2016, Zhangjian (Bamvor) wrote:


correct or not. After learn and compare some fuzz tools, I feel that there is
no such fuzz tools could help me. So, I wrote a new fuzz tools base on the
trinity and it found several wrapper issues in glibc. I will first explain the
different with existing fuzz tools and paste my propsosal in the end.


I'm not at all clear on whether any of the people working on AArch64 ILP32
glibc have run the glibc testsuite and investigated the results in detail
(the patch submissions have failed to include glibc testsuite results and
 have included bugs that would have been detected by the glibc testsuite).

I run test glibc testsuite in previous glibc version with v6 kernel patch
backport to kernel-4.1, without regression. I usually run glibc testsuite
after ltp test result looks good. So, maybe it hard to find a issue by
glibc testsuite in this case.

But, if you've found bugs in a new glibc port that were not detected by
the existing testsuite, then tests for those bugs should be contributed to
glibc (even if no existing port has those bugs, improving the test
coverage is still a good idea).

It is good idea. I will review the fixed issues(such as wrong context in
signal, wrong parameter in off_t/stat relative syscalls) and check if it is
suitable to add it to glibc testsuite. (Actually, I do not know which
test suite (ltp or glibc) I should improve for a specific issue).
I hope our tools could help on improving the coverage of syscall relative
code at least.

Thanks.

Bamvor



Re: [RFD] Efficient unit test and fuzz tools for kernel/libc porting

2016-07-21 Thread Zhangjian (Bamvor)

Hi, Joseph

On 2016/7/20 23:47, Joseph Myers wrote:

On Wed, 6 Jul 2016, Zhangjian (Bamvor) wrote:


correct or not. After learn and compare some fuzz tools, I feel that there is
no such fuzz tools could help me. So, I wrote a new fuzz tools base on the
trinity and it found several wrapper issues in glibc. I will first explain the
different with existing fuzz tools and paste my propsosal in the end.


I'm not at all clear on whether any of the people working on AArch64 ILP32
glibc have run the glibc testsuite and investigated the results in detail
(the patch submissions have failed to include glibc testsuite results and
 have included bugs that would have been detected by the glibc testsuite).

I run test glibc testsuite in previous glibc version with v6 kernel patch
backport to kernel-4.1, without regression. I usually run glibc testsuite
after ltp test result looks good. So, maybe it hard to find a issue by
glibc testsuite in this case.

But, if you've found bugs in a new glibc port that were not detected by
the existing testsuite, then tests for those bugs should be contributed to
glibc (even if no existing port has those bugs, improving the test
coverage is still a good idea).

It is good idea. I will review the fixed issues(such as wrong context in
signal, wrong parameter in off_t/stat relative syscalls) and check if it is
suitable to add it to glibc testsuite. (Actually, I do not know which
test suite (ltp or glibc) I should improve for a specific issue).
I hope our tools could help on improving the coverage of syscall relative
code at least.

Thanks.

Bamvor



Re: [RFD] Efficient unit test and fuzz tools for kernel/libc porting

2016-07-06 Thread Zhangjian (Bamvor)

Hi, Dmitry

On 2016/7/6 17:09, Dmitry Vyukov wrote:

On Wed, Jul 6, 2016 at 10:24 AM, Zhangjian (Bamvor)
<bamvor.zhangj...@huawei.com> wrote:

Hi, Dmitry



Hi Bamvor,

Nice work!

Coverage should be easy to do with CONFIG_KCOV, but do you need
fuzzing/coverage? It seems that testing a predefined set of special
values for each arg should be enough for your use case. Namely special
values that can detect endianess/truncation/sign extension/etc issues.


Yes. We are trying to cover endianess/truncation/sign extension at this
moment.
For coverage, there are some code path in syscall wrapper in both glibc
and kernel. E.g. overflow check in glibc. I am thinking if coverage
could help on this.


Ah, you mean user-space coverage. You may try AFL in binary
instrumentation mode for this.

Good idea. AFL seems a wonderful tools. I saw some discussion about use AFL
to do kernel fuzz(triforce). If AFL support arm64, I could try it my
aarch64 ILP32 works.

Regards

Bamvor




I think there is also a number of glibc functions that don't directly
map to syscalls. Most notably wrappers around various ioctl's (e.g.
ptsname). Do you test them?


No. Currently, our tools only focus on the syscall function in glibc. In
these syscall level, we could compare the parameter and return value
directly. As you said, there are only several type of issues. It is easy
to handle by tools.

I do not know how to test these complex cases. E.g. the ptsname may call
ioctl, *stat* syscall. Compare the original parameter is meaningless. But
it seems a good type of testcase to show how the user use the syscalls.
Do you have some ideas?


I don't have any ideas for automated testing. One could write a model,
of course
--
To unsubscribe from this list: send the line "unsubscribe linux-arch" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html





Re: [RFD] Efficient unit test and fuzz tools for kernel/libc porting

2016-07-06 Thread Zhangjian (Bamvor)

Hi, Dmitry

On 2016/7/6 17:09, Dmitry Vyukov wrote:

On Wed, Jul 6, 2016 at 10:24 AM, Zhangjian (Bamvor)
 wrote:

Hi, Dmitry



Hi Bamvor,

Nice work!

Coverage should be easy to do with CONFIG_KCOV, but do you need
fuzzing/coverage? It seems that testing a predefined set of special
values for each arg should be enough for your use case. Namely special
values that can detect endianess/truncation/sign extension/etc issues.


Yes. We are trying to cover endianess/truncation/sign extension at this
moment.
For coverage, there are some code path in syscall wrapper in both glibc
and kernel. E.g. overflow check in glibc. I am thinking if coverage
could help on this.


Ah, you mean user-space coverage. You may try AFL in binary
instrumentation mode for this.

Good idea. AFL seems a wonderful tools. I saw some discussion about use AFL
to do kernel fuzz(triforce). If AFL support arm64, I could try it my
aarch64 ILP32 works.

Regards

Bamvor




I think there is also a number of glibc functions that don't directly
map to syscalls. Most notably wrappers around various ioctl's (e.g.
ptsname). Do you test them?


No. Currently, our tools only focus on the syscall function in glibc. In
these syscall level, we could compare the parameter and return value
directly. As you said, there are only several type of issues. It is easy
to handle by tools.

I do not know how to test these complex cases. E.g. the ptsname may call
ioctl, *stat* syscall. Compare the original parameter is meaningless. But
it seems a good type of testcase to show how the user use the syscalls.
Do you have some ideas?


I don't have any ideas for automated testing. One could write a model,
of course
--
To unsubscribe from this list: send the line "unsubscribe linux-arch" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html





Re: [RFD] Efficient unit test and fuzz tools for kernel/libc porting

2016-07-06 Thread Zhangjian (Bamvor)

Hi, Dmitry

On 2016/7/6 16:00, Dmitry Vyukov wrote:

On Wed, Jul 6, 2016 at 9:39 AM, Zhangjian (Bamvor)
<bamvor.zhangj...@huawei.com> wrote:

HI,

When I working on the ILP32 ABI for ARMv8 in last two years, I has
encountered lots of syscall issues such as wrong number of arguments,
different data type in binary interface. I realized that the correctness of
argument passing between the C library and core kernel code is a common
problem when bringing up new architecture or ABI to kernel and libc.
Existing fuzz testing tools such as trinity[1], syzkaller[2] and triforce[3]
only generate random or boundary values for syscall parameters and then
inject them into kernel, but those tools won't validate if the results of
those syscalls are correct or not. Thus they can not act as an unit test for
ILP32. In this year, considering the abi of ILP32 is changes during
discussion, I am thinking if I could use some sort of automatically tools to
check whether the wrapper is correct or not. After learn and compare some
fuzz tools, I feel that there is no such fuzz tools could help me. So, I
wrote a new fuzz tools base on the trinity and it found several wrapper
issues in glibc. I will first explain the different with existing fuzz tools
and paste my propsosal in the end.

Trinity is developed in a long time. It could randomize the parameter of
syscall and run individual syscall standalone or parallel. When I do the
long time parallel test(not for ILP32), it could report some bug, e.g. hang,
panic. It is useful but it is indeed hard to debug because it usually fail
after a long time running. I do not know what does it exactly do.

Compare with Trinity, syzkaller is quite different. Here is the comparision
between syzkaller and our tools:
1.  Syzkaller could recursively randomize base date type in syscall which
means it is possible generate more meaningfull syscall test. But it only
test the syscall through syscall() function. It assume that the c library is
correct and stable. But it is wrong if we are porting new abi(such as ILP32)
or architecture to glibc and kernel. We need to take c library into account.
This is what my tools could do.

2.  Syzkaller could generate the readable short testcases. Our tools could
only test individual syscall and check the correctness of parameter and
return value. I think it is enough for the unit test which tests syscall one
by one.

3.  Syzkaller could do the coverage. Our tools could not. I think it is
useful for me. I plan to add the coverage later.

In my ILP32 works, my tools reported several off_t endian issues in glibc.
Our tools work like this:

Dump the function Dump the function
prototype fromprototype from c
vmlinux from the  library from the
sys_call_tablegiven list(posix
array in kernel.  interfaces or user
|  defined).
| |
| |
   \|/   \|/
` `
Generate jprobeModity Trinity to  Generate struct
hook according to  support run syscallfuzz generator
prototype whichsyscall from c from the prototype.
will recursively   libray instead And add them of
print the syscall  syscall() function to trinity. Trinity
value.   |will recursively
\ |print the function
 \|parameter.
  \   |   /
   ---
  |
 \|/
  `
   Run the trinity each syscall once
   and compare the function parameter
   printed in kernel and userspace
   If inconsistent, print specific
   information, such endian issue,
   32<->64bit conversion issue and
   so on.

Tools of function dump and hook generator based on the abi-dumper[4]. Other
functions base on trinity. Return value test is similar except generating
the kretprobe hook instead jprobe hook.

There are some hacks and the original funtion of trinity may be broken. The
main changes in trinity are as follows:
1.  Call syscall through c library via call_glibc_syscalls() instead of
direct syscall via syscall().
2.  Add new file generate-struct.c including the missing data type mentioned
in syscall. This file is generated by ./struct_extract.py with a little
modification. It should be fully auto generated in future.
3.  Add more date types in fill_arg()(gen

Re: [RFD] Efficient unit test and fuzz tools for kernel/libc porting

2016-07-06 Thread Zhangjian (Bamvor)

Hi, Dmitry

On 2016/7/6 16:00, Dmitry Vyukov wrote:

On Wed, Jul 6, 2016 at 9:39 AM, Zhangjian (Bamvor)
 wrote:

HI,

When I working on the ILP32 ABI for ARMv8 in last two years, I has
encountered lots of syscall issues such as wrong number of arguments,
different data type in binary interface. I realized that the correctness of
argument passing between the C library and core kernel code is a common
problem when bringing up new architecture or ABI to kernel and libc.
Existing fuzz testing tools such as trinity[1], syzkaller[2] and triforce[3]
only generate random or boundary values for syscall parameters and then
inject them into kernel, but those tools won't validate if the results of
those syscalls are correct or not. Thus they can not act as an unit test for
ILP32. In this year, considering the abi of ILP32 is changes during
discussion, I am thinking if I could use some sort of automatically tools to
check whether the wrapper is correct or not. After learn and compare some
fuzz tools, I feel that there is no such fuzz tools could help me. So, I
wrote a new fuzz tools base on the trinity and it found several wrapper
issues in glibc. I will first explain the different with existing fuzz tools
and paste my propsosal in the end.

Trinity is developed in a long time. It could randomize the parameter of
syscall and run individual syscall standalone or parallel. When I do the
long time parallel test(not for ILP32), it could report some bug, e.g. hang,
panic. It is useful but it is indeed hard to debug because it usually fail
after a long time running. I do not know what does it exactly do.

Compare with Trinity, syzkaller is quite different. Here is the comparision
between syzkaller and our tools:
1.  Syzkaller could recursively randomize base date type in syscall which
means it is possible generate more meaningfull syscall test. But it only
test the syscall through syscall() function. It assume that the c library is
correct and stable. But it is wrong if we are porting new abi(such as ILP32)
or architecture to glibc and kernel. We need to take c library into account.
This is what my tools could do.

2.  Syzkaller could generate the readable short testcases. Our tools could
only test individual syscall and check the correctness of parameter and
return value. I think it is enough for the unit test which tests syscall one
by one.

3.  Syzkaller could do the coverage. Our tools could not. I think it is
useful for me. I plan to add the coverage later.

In my ILP32 works, my tools reported several off_t endian issues in glibc.
Our tools work like this:

Dump the function Dump the function
prototype fromprototype from c
vmlinux from the  library from the
sys_call_tablegiven list(posix
array in kernel.  interfaces or user
|  defined).
| |
| |
   \|/   \|/
` `
Generate jprobeModity Trinity to  Generate struct
hook according to  support run syscallfuzz generator
prototype whichsyscall from c from the prototype.
will recursively   libray instead And add them of
print the syscall  syscall() function to trinity. Trinity
value.   |will recursively
\ |print the function
 \|parameter.
  \   |   /
   ---
  |
 \|/
  `
   Run the trinity each syscall once
   and compare the function parameter
   printed in kernel and userspace
   If inconsistent, print specific
   information, such endian issue,
   32<->64bit conversion issue and
   so on.

Tools of function dump and hook generator based on the abi-dumper[4]. Other
functions base on trinity. Return value test is similar except generating
the kretprobe hook instead jprobe hook.

There are some hacks and the original funtion of trinity may be broken. The
main changes in trinity are as follows:
1.  Call syscall through c library via call_glibc_syscalls() instead of
direct syscall via syscall().
2.  Add new file generate-struct.c including the missing data type mentioned
in syscall. This file is generated by ./struct_extract.py with a little
modification. It should be fully auto generated in future.
3.  Add more date types in fill_arg()(generate-args.c) and
include/syscal

Re: [RFD] Efficient unit test and fuzz tools for kernel/libc porting

2016-07-06 Thread Zhangjian (Bamvor)

Fix the wrong email address for Arnd. Sorry for the noise.

On 2016/7/6 15:39, Zhangjian (Bamvor) wrote:

HI,

When I working on the ILP32 ABI for ARMv8 in last two years, I has encountered 
lots of syscall issues such as wrong number of arguments, different data type 
in binary interface. I realized that the correctness of argument passing 
between the C library and core kernel code is a common problem when bringing up 
new architecture or ABI to kernel and libc. Existing fuzz testing tools such as 
trinity[1], syzkaller[2] and triforce[3] only generate random or boundary 
values for syscall parameters and then inject them into kernel, but those tools 
won't validate if the results of those syscalls are correct or not. Thus they 
can not act as an unit test for ILP32. In this year, considering the abi of 
ILP32 is changes during discussion, I am thinking if I could use some sort of 
automatically tools to check whether the wrapper is correct or not. After learn 
and compare some fuzz tools, I feel that there is no such fuzz tools could help 
me. So, I wrote a new fuzz tools base on the trinity a
nd it found several wrapper issues in glibc. I will first explain the different 
with existing fuzz tools and paste my propsosal in the end.

Trinity is developed in a long time. It could randomize the parameter of 
syscall and run individual syscall standalone or parallel. When I do the long 
time parallel test(not for ILP32), it could report some bug, e.g. hang, panic. 
It is useful but it is indeed hard to debug because it usually fail after a 
long time running. I do not know what does it exactly do.

Compare with Trinity, syzkaller is quite different. Here is the comparision 
between syzkaller and our tools:
1.  Syzkaller could recursively randomize base date type in syscall which means 
it is possible generate more meaningfull syscall test. But it only test the 
syscall through syscall() function. It assume that the c library is correct and 
stable. But it is wrong if we are porting new abi(such as ILP32) or 
architecture to glibc and kernel. We need to take c library into account. This 
is what my tools could do.

2.  Syzkaller could generate the readable short testcases. Our tools could only 
test individual syscall and check the correctness of parameter and return 
value. I think it is enough for the unit test which tests syscall one by one.

3.  Syzkaller could do the coverage. Our tools could not. I think it is useful 
for me. I plan to add the coverage later.

In my ILP32 works, my tools reported several off_t endian issues in glibc. Our 
tools work like this:

Dump the function Dump the function
prototype fromprototype from c
vmlinux from the  library from the
sys_call_tablegiven list(posix
array in kernel.  interfaces or user
|  defined).
| |
| |
   \|/   \|/
` `
Generate jprobeModity Trinity to  Generate struct
hook according to  support run syscallfuzz generator
prototype whichsyscall from c from the prototype.
will recursively   libray instead And add them of
print the syscall  syscall() function to trinity. Trinity
value.   |will recursively
\ |print the function
 \|parameter.
  \   |   /
   ---
  |
 \|/
  `
   Run the trinity each syscall once
   and compare the function parameter
   printed in kernel and userspace
   If inconsistent, print specific
   information, such endian issue,
   32<->64bit conversion issue and
   so on.

Tools of function dump and hook generator based on the abi-dumper[4]. Other 
functions base on trinity. Return value test is similar except generating the 
kretprobe hook instead jprobe hook.

There are some hacks and the original funtion of trinity may be broken. The 
main changes in trinity are as follows:
1.  Call syscall through c library via call_glibc_syscalls() instead of direct 
syscall via syscall().
2.  Add new file generate-struct.c including the missing data type mentioned in 
syscall. This file is generated by ./struct_extract.py with a little 
modification. It should be fully auto generated in future.
3.  Add more date types in fill_arg()(generate-

Re: [RFD] Efficient unit test and fuzz tools for kernel/libc porting

2016-07-06 Thread Zhangjian (Bamvor)

Fix the wrong email address for Arnd. Sorry for the noise.

On 2016/7/6 15:39, Zhangjian (Bamvor) wrote:

HI,

When I working on the ILP32 ABI for ARMv8 in last two years, I has encountered 
lots of syscall issues such as wrong number of arguments, different data type 
in binary interface. I realized that the correctness of argument passing 
between the C library and core kernel code is a common problem when bringing up 
new architecture or ABI to kernel and libc. Existing fuzz testing tools such as 
trinity[1], syzkaller[2] and triforce[3] only generate random or boundary 
values for syscall parameters and then inject them into kernel, but those tools 
won't validate if the results of those syscalls are correct or not. Thus they 
can not act as an unit test for ILP32. In this year, considering the abi of 
ILP32 is changes during discussion, I am thinking if I could use some sort of 
automatically tools to check whether the wrapper is correct or not. After learn 
and compare some fuzz tools, I feel that there is no such fuzz tools could help 
me. So, I wrote a new fuzz tools base on the trinity a
nd it found several wrapper issues in glibc. I will first explain the different 
with existing fuzz tools and paste my propsosal in the end.

Trinity is developed in a long time. It could randomize the parameter of 
syscall and run individual syscall standalone or parallel. When I do the long 
time parallel test(not for ILP32), it could report some bug, e.g. hang, panic. 
It is useful but it is indeed hard to debug because it usually fail after a 
long time running. I do not know what does it exactly do.

Compare with Trinity, syzkaller is quite different. Here is the comparision 
between syzkaller and our tools:
1.  Syzkaller could recursively randomize base date type in syscall which means 
it is possible generate more meaningfull syscall test. But it only test the 
syscall through syscall() function. It assume that the c library is correct and 
stable. But it is wrong if we are porting new abi(such as ILP32) or 
architecture to glibc and kernel. We need to take c library into account. This 
is what my tools could do.

2.  Syzkaller could generate the readable short testcases. Our tools could only 
test individual syscall and check the correctness of parameter and return 
value. I think it is enough for the unit test which tests syscall one by one.

3.  Syzkaller could do the coverage. Our tools could not. I think it is useful 
for me. I plan to add the coverage later.

In my ILP32 works, my tools reported several off_t endian issues in glibc. Our 
tools work like this:

Dump the function Dump the function
prototype fromprototype from c
vmlinux from the  library from the
sys_call_tablegiven list(posix
array in kernel.  interfaces or user
|  defined).
| |
| |
   \|/   \|/
` `
Generate jprobeModity Trinity to  Generate struct
hook according to  support run syscallfuzz generator
prototype whichsyscall from c from the prototype.
will recursively   libray instead And add them of
print the syscall  syscall() function to trinity. Trinity
value.   |will recursively
\ |print the function
 \|parameter.
  \   |   /
   ---
  |
 \|/
  `
   Run the trinity each syscall once
   and compare the function parameter
   printed in kernel and userspace
   If inconsistent, print specific
   information, such endian issue,
   32<->64bit conversion issue and
   so on.

Tools of function dump and hook generator based on the abi-dumper[4]. Other 
functions base on trinity. Return value test is similar except generating the 
kretprobe hook instead jprobe hook.

There are some hacks and the original funtion of trinity may be broken. The 
main changes in trinity are as follows:
1.  Call syscall through c library via call_glibc_syscalls() instead of direct 
syscall via syscall().
2.  Add new file generate-struct.c including the missing data type mentioned in 
syscall. This file is generated by ./struct_extract.py with a little 
modification. It should be fully auto generated in future.
3.  Add more date types in fill_arg()(generate-

[RFD] Efficient unit test and fuzz tools for kernel/libc porting

2016-07-06 Thread Zhangjian (Bamvor)

HI,

When I working on the ILP32 ABI for ARMv8 in last two years, I has encountered lots of syscall issues such as wrong number of arguments, different data type in binary interface. I realized that the correctness of argument passing between the C library and core kernel code is a common problem when bringing up new architecture or ABI to kernel and libc. Existing fuzz testing tools such as trinity[1], syzkaller[2] and triforce[3] only generate random or boundary values for syscall parameters and then inject them into kernel, but those tools won't validate if the results of those syscalls are correct or not. Thus they can not act as an unit test for ILP32. In this year, considering the abi of ILP32 is changes during discussion, I am thinking if I could use some sort of automatically tools to check whether the wrapper is correct or not. After learn and compare some fuzz tools, I feel that there is no such fuzz tools could help me. So, I wrote a new fuzz tools base on the trinity and it 
found several wrapper issues in glibc. I will first explain the different with existing fuzz tools and paste my propsosal in the end.


Trinity is developed in a long time. It could randomize the parameter of 
syscall and run individual syscall standalone or parallel. When I do the long 
time parallel test(not for ILP32), it could report some bug, e.g. hang, panic. 
It is useful but it is indeed hard to debug because it usually fail after a 
long time running. I do not know what does it exactly do.

Compare with Trinity, syzkaller is quite different. Here is the comparision 
between syzkaller and our tools:
1.  Syzkaller could recursively randomize base date type in syscall which means 
it is possible generate more meaningfull syscall test. But it only test the 
syscall through syscall() function. It assume that the c library is correct and 
stable. But it is wrong if we are porting new abi(such as ILP32) or 
architecture to glibc and kernel. We need to take c library into account. This 
is what my tools could do.

2.  Syzkaller could generate the readable short testcases. Our tools could only 
test individual syscall and check the correctness of parameter and return 
value. I think it is enough for the unit test which tests syscall one by one.

3.  Syzkaller could do the coverage. Our tools could not. I think it is useful 
for me. I plan to add the coverage later.

In my ILP32 works, my tools reported several off_t endian issues in glibc. Our 
tools work like this:

Dump the function Dump the function
prototype fromprototype from c
vmlinux from the  library from the
sys_call_tablegiven list(posix
array in kernel.  interfaces or user
   |  defined).
   | |
   | |
  \|/   \|/
   ` `
Generate jprobeModity Trinity to  Generate struct
hook according to  support run syscallfuzz generator
prototype whichsyscall from c from the prototype.
will recursively   libray instead And add them of
print the syscall  syscall() function to trinity. Trinity
value.   |will recursively
   \ |print the function
\|parameter.
 \   |   /
  ---
 |
\|/
 `
  Run the trinity each syscall once
  and compare the function parameter
  printed in kernel and userspace
  If inconsistent, print specific
  information, such endian issue,
  32<->64bit conversion issue and
  so on.

Tools of function dump and hook generator based on the abi-dumper[4]. Other 
functions base on trinity. Return value test is similar except generating the 
kretprobe hook instead jprobe hook.

There are some hacks and the original funtion of trinity may be broken. The 
main changes in trinity are as follows:
1.  Call syscall through c library via call_glibc_syscalls() instead of direct 
syscall via syscall().
2.  Add new file generate-struct.c including the missing data type mentioned in 
syscall. This file is generated by ./struct_extract.py with a little 
modification. It should be fully auto generated in future.
3.  Add more date types in fill_arg()(generate-args.c) and include/syscall.h.
4.  Modify the syscallentry struct in syscalls directory according to the newly 
added data types.
5.  Add or Change 

[RFD] Efficient unit test and fuzz tools for kernel/libc porting

2016-07-06 Thread Zhangjian (Bamvor)

HI,

When I working on the ILP32 ABI for ARMv8 in last two years, I has encountered lots of syscall issues such as wrong number of arguments, different data type in binary interface. I realized that the correctness of argument passing between the C library and core kernel code is a common problem when bringing up new architecture or ABI to kernel and libc. Existing fuzz testing tools such as trinity[1], syzkaller[2] and triforce[3] only generate random or boundary values for syscall parameters and then inject them into kernel, but those tools won't validate if the results of those syscalls are correct or not. Thus they can not act as an unit test for ILP32. In this year, considering the abi of ILP32 is changes during discussion, I am thinking if I could use some sort of automatically tools to check whether the wrapper is correct or not. After learn and compare some fuzz tools, I feel that there is no such fuzz tools could help me. So, I wrote a new fuzz tools base on the trinity and it 
found several wrapper issues in glibc. I will first explain the different with existing fuzz tools and paste my propsosal in the end.


Trinity is developed in a long time. It could randomize the parameter of 
syscall and run individual syscall standalone or parallel. When I do the long 
time parallel test(not for ILP32), it could report some bug, e.g. hang, panic. 
It is useful but it is indeed hard to debug because it usually fail after a 
long time running. I do not know what does it exactly do.

Compare with Trinity, syzkaller is quite different. Here is the comparision 
between syzkaller and our tools:
1.  Syzkaller could recursively randomize base date type in syscall which means 
it is possible generate more meaningfull syscall test. But it only test the 
syscall through syscall() function. It assume that the c library is correct and 
stable. But it is wrong if we are porting new abi(such as ILP32) or 
architecture to glibc and kernel. We need to take c library into account. This 
is what my tools could do.

2.  Syzkaller could generate the readable short testcases. Our tools could only 
test individual syscall and check the correctness of parameter and return 
value. I think it is enough for the unit test which tests syscall one by one.

3.  Syzkaller could do the coverage. Our tools could not. I think it is useful 
for me. I plan to add the coverage later.

In my ILP32 works, my tools reported several off_t endian issues in glibc. Our 
tools work like this:

Dump the function Dump the function
prototype fromprototype from c
vmlinux from the  library from the
sys_call_tablegiven list(posix
array in kernel.  interfaces or user
   |  defined).
   | |
   | |
  \|/   \|/
   ` `
Generate jprobeModity Trinity to  Generate struct
hook according to  support run syscallfuzz generator
prototype whichsyscall from c from the prototype.
will recursively   libray instead And add them of
print the syscall  syscall() function to trinity. Trinity
value.   |will recursively
   \ |print the function
\|parameter.
 \   |   /
  ---
 |
\|/
 `
  Run the trinity each syscall once
  and compare the function parameter
  printed in kernel and userspace
  If inconsistent, print specific
  information, such endian issue,
  32<->64bit conversion issue and
  so on.

Tools of function dump and hook generator based on the abi-dumper[4]. Other 
functions base on trinity. Return value test is similar except generating the 
kretprobe hook instead jprobe hook.

There are some hacks and the original funtion of trinity may be broken. The 
main changes in trinity are as follows:
1.  Call syscall through c library via call_glibc_syscalls() instead of direct 
syscall via syscall().
2.  Add new file generate-struct.c including the missing data type mentioned in 
syscall. This file is generated by ./struct_extract.py with a little 
modification. It should be fully auto generated in future.
3.  Add more date types in fill_arg()(generate-args.c) and include/syscall.h.
4.  Modify the syscallentry struct in syscalls directory according to the newly 
added data types.
5.  Add or Change 

Re: [RFC PATCH 00/27] ARM64: support ILP32

2016-06-21 Thread Zhangjian (Bamvor)

Hi,


In our test, we need to fix stack pointer in makecontext. Not sure
if it should be a standalone patch:

From 1d51ca34034ef83ea602874a93e26fd158ddd214 Mon Sep 17 00:00:00 2001
From: Jun Ji 
Date: Fri, 29 Apr 2016 17:20:23 +0800
Subject: [PATCH] fix for makecontext error

Signed-off-by: Jun Ji 

---
 sysdeps/unix/sysv/linux/aarch64/makecontext.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/aarch64/makecontext.c 
b/sysdeps/unix/sysv/linux/aarch64/makecontext.c
index 34f91a3..55a26a3 100644
--- a/sysdeps/unix/sysv/linux/aarch64/makecontext.c
+++ b/sysdeps/unix/sysv/linux/aarch64/makecontext.c
@@ -42,18 +42,18 @@ void
 __makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...)
 {
   extern void __startcontext (void);
-  unsigned long int *sp;
+  unsigned long long *sp;
   va_list ap;
   int i;

-  sp = (unsigned long int *)
+  sp = (unsigned long long *)
 ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);

   /* Allocate stack arguments.  */
   sp -= argc < 8 ? 0 : argc - 8;

   /* Keep the stack aligned.  */
-  sp = (unsigned long int *) (((uintptr_t) sp) & -16L);
+  sp = (unsigned long long *) (((uintptr_t) sp) & -16L);

   ucp->uc_mcontext.regs[19] = (uintptr_t) ucp->uc_link;
   ucp->uc_mcontext.sp = (uintptr_t) sp;
@@ -64,9 +64,9 @@ __makecontext (ucontext_t *ucp, void (*func) (void), int 
argc, ...)
   va_start (ap, argc);
   for (i = 0; i < argc; ++i)
 if (i < 8)
-  ucp->uc_mcontext.regs[i] = va_arg (ap, unsigned long int);
+  ucp->uc_mcontext.regs[i] = va_arg (ap, unsigned long long);
 else
-  sp[i - 8] = va_arg (ap, unsigned long int);
+  sp[i - 8] = va_arg (ap, unsigned long long);

   va_end (ap);
 }
--
1.8.4.5

Regards

Bamvor

On 2016/6/21 13:06, Yury Norov wrote:

This series enables aarch64 port with ilp32 mode.

After long discussions in kernel list, we finally got
consensus on how ABI should look. This patchset adds
support for the ABI in GLIBC. It is tested with LTP
with no big regressions comparing to LP64 and AARCH32.

Though it's very raw. Please be patient reviewing it.

ABI details:
  - types are taken from AARCH32, next types turned to 64-bit,
as modern requirement for new APIs tells:
ino_t  is  u64 type
off_t  is  s64 type
blkcnt_t   is  s64 type
fsblkcnt_t is  u64 type
fsfilcnt_t is  u64 type
  - 64-bit arguments are passed in syscall as register pair,
as kernel internally clears top halves for all input regs;
  - standard syscall table is used;
  - 32-bit time_t is used. AARCH64/ILP32 is waiting for general
fix of Y2038 problem just like other 32-bit arches;
  - stat{64}, statfs{64} structures are of the identical layout
with LP64. Corresponding syscalls are taken from 64-bit code.

Links:
This series: https://github.com/norov/glibc/commits/ilp32-2.23
Kernel series: https://github.com/norov/linux/commits/ilp32-nowrap
Kernel in LKML: https://lkml.org/lkml/2016/6/17/990

Please review it. Any comments appreciated.

Yury.

Andrew Pinski (24):
   [AARCH64] Fix utmp struct for compatibility reasons.
   [AARCH64] Add header guards to sysdep.h headers.
   Add dynamic ILP32 AARCH64 relocations to elf.h
   [AARCH64] Add PTR_REG, PTR_LOG_SIZE, and PTR_SIZE.  Use it in
 LDST_PCREL and LDST_GLOBAL.
   [AARCH64] Use PTR_REG in crti.S.
   [AARCH64] Use PTR_REG/PTR_SIZE/PTR_SIZE_LOG in dl-tlsesc.S
   [AARCH64] Use PTR_* macros in dl-trampoline.S
   [AARCH64] Use PTR_* in start.S
   [AARCH64] Use PTR_REG in getcontext.S.
   [AARCH64] Detect ILP32 in configure scripts.
   [AARCH64] Syscalls for ILP32 are passed always via 64bit values.
   [AARCH64] Add ILP32 support to elf_machine_load_address.
   [AARCH64] Set up wordsize for ILP32.
   [AARCH64] Add ILP32 to makefiles
   [AARCH64] Add support to ldconfig for ILP32 and libilp32
   [AARCH64] Add ILP32 ld.so to the known interpreter names.
   [AARCH64] Add ldd-rewrite.sed so that ilp32 ld.so can be found
   [AARCH64] Add kernel_sigaction.h for AARCH64 ILP32
   [AARCH64] Add typesizes.h for ILP32
   [AARCH64] Make lp64 and ilp32 directories.
   Add support for AT_ARM64_MIDR.
   [AARCH64] Fix ILP32 warning
   [AARCH64] Change type of __align to long long
   Fix PTRDIFF_MIN/PTRDIFF_MIN and PTRDIFF_MIN for ILP32.

Yury Norov (3):
   [AARCH64] ILP32: introduce syscalls that pass off_t
   [AARCH64] ILP32: support stat syscall family
   [AARCH64] delouse input arguments in system functions

  elf/cache.c|   2 +
  elf/dl-sysdep.c|   1 +
  elf/elf.h  |   3 +
  sysdeps/aarch64/Implies|   6 -
  sysdeps/aarch64/__longjmp.S|   6 +-
  sysdeps/aarch64/bits/wordsize.h|  28 +++
  sysdeps/aarch64/configure  |  15 +-
  sysdeps/aarch64/configure.ac  

Re: [RFC PATCH 00/27] ARM64: support ILP32

2016-06-21 Thread Zhangjian (Bamvor)

Hi,


In our test, we need to fix stack pointer in makecontext. Not sure
if it should be a standalone patch:

From 1d51ca34034ef83ea602874a93e26fd158ddd214 Mon Sep 17 00:00:00 2001
From: Jun Ji 
Date: Fri, 29 Apr 2016 17:20:23 +0800
Subject: [PATCH] fix for makecontext error

Signed-off-by: Jun Ji 

---
 sysdeps/unix/sysv/linux/aarch64/makecontext.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/aarch64/makecontext.c 
b/sysdeps/unix/sysv/linux/aarch64/makecontext.c
index 34f91a3..55a26a3 100644
--- a/sysdeps/unix/sysv/linux/aarch64/makecontext.c
+++ b/sysdeps/unix/sysv/linux/aarch64/makecontext.c
@@ -42,18 +42,18 @@ void
 __makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...)
 {
   extern void __startcontext (void);
-  unsigned long int *sp;
+  unsigned long long *sp;
   va_list ap;
   int i;

-  sp = (unsigned long int *)
+  sp = (unsigned long long *)
 ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);

   /* Allocate stack arguments.  */
   sp -= argc < 8 ? 0 : argc - 8;

   /* Keep the stack aligned.  */
-  sp = (unsigned long int *) (((uintptr_t) sp) & -16L);
+  sp = (unsigned long long *) (((uintptr_t) sp) & -16L);

   ucp->uc_mcontext.regs[19] = (uintptr_t) ucp->uc_link;
   ucp->uc_mcontext.sp = (uintptr_t) sp;
@@ -64,9 +64,9 @@ __makecontext (ucontext_t *ucp, void (*func) (void), int 
argc, ...)
   va_start (ap, argc);
   for (i = 0; i < argc; ++i)
 if (i < 8)
-  ucp->uc_mcontext.regs[i] = va_arg (ap, unsigned long int);
+  ucp->uc_mcontext.regs[i] = va_arg (ap, unsigned long long);
 else
-  sp[i - 8] = va_arg (ap, unsigned long int);
+  sp[i - 8] = va_arg (ap, unsigned long long);

   va_end (ap);
 }
--
1.8.4.5

Regards

Bamvor

On 2016/6/21 13:06, Yury Norov wrote:

This series enables aarch64 port with ilp32 mode.

After long discussions in kernel list, we finally got
consensus on how ABI should look. This patchset adds
support for the ABI in GLIBC. It is tested with LTP
with no big regressions comparing to LP64 and AARCH32.

Though it's very raw. Please be patient reviewing it.

ABI details:
  - types are taken from AARCH32, next types turned to 64-bit,
as modern requirement for new APIs tells:
ino_t  is  u64 type
off_t  is  s64 type
blkcnt_t   is  s64 type
fsblkcnt_t is  u64 type
fsfilcnt_t is  u64 type
  - 64-bit arguments are passed in syscall as register pair,
as kernel internally clears top halves for all input regs;
  - standard syscall table is used;
  - 32-bit time_t is used. AARCH64/ILP32 is waiting for general
fix of Y2038 problem just like other 32-bit arches;
  - stat{64}, statfs{64} structures are of the identical layout
with LP64. Corresponding syscalls are taken from 64-bit code.

Links:
This series: https://github.com/norov/glibc/commits/ilp32-2.23
Kernel series: https://github.com/norov/linux/commits/ilp32-nowrap
Kernel in LKML: https://lkml.org/lkml/2016/6/17/990

Please review it. Any comments appreciated.

Yury.

Andrew Pinski (24):
   [AARCH64] Fix utmp struct for compatibility reasons.
   [AARCH64] Add header guards to sysdep.h headers.
   Add dynamic ILP32 AARCH64 relocations to elf.h
   [AARCH64] Add PTR_REG, PTR_LOG_SIZE, and PTR_SIZE.  Use it in
 LDST_PCREL and LDST_GLOBAL.
   [AARCH64] Use PTR_REG in crti.S.
   [AARCH64] Use PTR_REG/PTR_SIZE/PTR_SIZE_LOG in dl-tlsesc.S
   [AARCH64] Use PTR_* macros in dl-trampoline.S
   [AARCH64] Use PTR_* in start.S
   [AARCH64] Use PTR_REG in getcontext.S.
   [AARCH64] Detect ILP32 in configure scripts.
   [AARCH64] Syscalls for ILP32 are passed always via 64bit values.
   [AARCH64] Add ILP32 support to elf_machine_load_address.
   [AARCH64] Set up wordsize for ILP32.
   [AARCH64] Add ILP32 to makefiles
   [AARCH64] Add support to ldconfig for ILP32 and libilp32
   [AARCH64] Add ILP32 ld.so to the known interpreter names.
   [AARCH64] Add ldd-rewrite.sed so that ilp32 ld.so can be found
   [AARCH64] Add kernel_sigaction.h for AARCH64 ILP32
   [AARCH64] Add typesizes.h for ILP32
   [AARCH64] Make lp64 and ilp32 directories.
   Add support for AT_ARM64_MIDR.
   [AARCH64] Fix ILP32 warning
   [AARCH64] Change type of __align to long long
   Fix PTRDIFF_MIN/PTRDIFF_MIN and PTRDIFF_MIN for ILP32.

Yury Norov (3):
   [AARCH64] ILP32: introduce syscalls that pass off_t
   [AARCH64] ILP32: support stat syscall family
   [AARCH64] delouse input arguments in system functions

  elf/cache.c|   2 +
  elf/dl-sysdep.c|   1 +
  elf/elf.h  |   3 +
  sysdeps/aarch64/Implies|   6 -
  sysdeps/aarch64/__longjmp.S|   6 +-
  sysdeps/aarch64/bits/wordsize.h|  28 +++
  sysdeps/aarch64/configure  |  15 +-
  sysdeps/aarch64/configure.ac   |  11 +-
  

Re: [PATCH 19/27] [AARCH64] Add typesizes.h for ILP32

2016-06-21 Thread Zhangjian (Bamvor)

Hi,

On 2016/6/21 15:58, Andreas Schwab wrote:

Yury Norov  writes:


diff --git a/sysdeps/unix/sysv/linux/sysdep-vdso.h 
b/sysdeps/unix/sysv/linux/sysdep-vdso.h
index e8c4a7b..351d6bb 100644
--- a/sysdeps/unix/sysv/linux/sysdep-vdso.h
+++ b/sysdeps/unix/sysv/linux/sysdep-vdso.h
@@ -37,7 +37,7 @@
  __label__ out;  \
  __label__ iserr;\
  INTERNAL_SYSCALL_DECL (sc_err); \
-long int sc_ret; \
+__syscall_slong_t sc_ret;\
  \
  __typeof (__vdso_##name) vdsop = __vdso_##name; \
  PTR_DEMANGLE (vdsop);   \
@@ -64,7 +64,7 @@
  #  define INTERNAL_VSYSCALL(name, err, nr, args...) \
({\
  __label__ out;  \
-long v_ret;
  \
+__syscall_slong_t v_ret; \
  \
  __typeof (__vdso_##name) vdsop = __vdso_##name; \
  PTR_DEMANGLE (vdsop);   \


That part should have no effect now that __SYSCALL_SLONG_TYPE remains to
be long.

Agree. According to the discussion in "[PATCH 11/27] [AARCH64] Syscalls for 
ILP32 are passed
always via 64bit values.". We should update this to long long too.

Regard

Bamvor


Andreas.





Re: [PATCH 19/27] [AARCH64] Add typesizes.h for ILP32

2016-06-21 Thread Zhangjian (Bamvor)

Hi,

On 2016/6/21 15:58, Andreas Schwab wrote:

Yury Norov  writes:


diff --git a/sysdeps/unix/sysv/linux/sysdep-vdso.h 
b/sysdeps/unix/sysv/linux/sysdep-vdso.h
index e8c4a7b..351d6bb 100644
--- a/sysdeps/unix/sysv/linux/sysdep-vdso.h
+++ b/sysdeps/unix/sysv/linux/sysdep-vdso.h
@@ -37,7 +37,7 @@
  __label__ out;  \
  __label__ iserr;\
  INTERNAL_SYSCALL_DECL (sc_err); \
-long int sc_ret; \
+__syscall_slong_t sc_ret;\
  \
  __typeof (__vdso_##name) vdsop = __vdso_##name; \
  PTR_DEMANGLE (vdsop);   \
@@ -64,7 +64,7 @@
  #  define INTERNAL_VSYSCALL(name, err, nr, args...) \
({\
  __label__ out;  \
-long v_ret;
  \
+__syscall_slong_t v_ret; \
  \
  __typeof (__vdso_##name) vdsop = __vdso_##name; \
  PTR_DEMANGLE (vdsop);   \


That part should have no effect now that __SYSCALL_SLONG_TYPE remains to
be long.

Agree. According to the discussion in "[PATCH 11/27] [AARCH64] Syscalls for 
ILP32 are passed
always via 64bit values.". We should update this to long long too.

Regard

Bamvor


Andreas.





Re: [PATCH 11/27] [AARCH64] Syscalls for ILP32 are passed always via 64bit values.

2016-06-21 Thread Zhangjian (Bamvor)

Hi,

On 2016/6/21 19:42, Zhangjian (Bamvor) wrote:

Hi,

On 2016/6/21 15:56, Andreas Schwab wrote:

Yury Norov <yno...@caviumnetworks.com> writes:


diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.h 
b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
index 1ffabc2..42f89c8 100644
--- a/sysdeps/unix/sysv/linux/aarch64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
@@ -161,11 +161,11 @@
 call.  */
  # undef INLINE_SYSCALL
  # define INLINE_SYSCALL(name, nr, args...)\
-  ({ unsigned long _sys_result = INTERNAL_SYSCALL (name, , nr, args);\
+  ({ unsigned long long _sys_result = INTERNAL_SYSCALL (name, , nr, args);\
   if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_sys_result, ), 0))\
 {\
   __set_errno (INTERNAL_SYSCALL_ERRNO (_sys_result, ));\
- _sys_result = (unsigned long) -1;\
+ _sys_result = (unsigned long long) -1;\
 }\
   (long) _sys_result; })


The cast should be (long long).

My understanding that we need more conversion, reference the follow patch:

Sorry, I used the wrong version of patch, here is the version could apply on 
yury'.
For vdso part, maybe we should fix in this patch instead of "[PATCH 19/27]
[AARCH64] Add typesizes.h for ILP32".

From 8c5f27c19407ba3ba8c400f0645cb51f91a5b379 Mon Sep 17 00:00:00 2001
From: gaoyongliang <gaoyongli...@huawei.com>
Date: Thu, 19 May 2016 18:19:05 +0800
Subject: [PATCH] ilp32 fix syscall return value to use long long

Signed-off-by: Yongliang Gao <gaoyongli...@huawei.com>
Signed-off-by: Bamvor Jian Zhang <bamvor.zhangj...@huawei.com>
---
 sysdeps/unix/sysdep.h| 2 +-
 sysdeps/unix/sysv/linux/aarch64/sysdep.h | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/sysdeps/unix/sysdep.h b/sysdeps/unix/sysdep.h
index 94a2ce0..a12456b 100644
--- a/sysdeps/unix/sysdep.h
+++ b/sysdeps/unix/sysdep.h
@@ -53,7 +53,7 @@

 #define SYSCALL_CANCEL(...) \
   ({\
-long int sc_ret;\
+long long sc_ret;   \
 if (SINGLE_THREAD_P)\
   sc_ret = __SYSCALL_CALL (__VA_ARGS__);   
 \
 else\
diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.h 
b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
index 42f89c8..82de012 100644
--- a/sysdeps/unix/sysv/linux/aarch64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
@@ -167,7 +167,7 @@
 __set_errno (INTERNAL_SYSCALL_ERRNO (_sys_result, ));  \
 _sys_result = (unsigned long long) -1; \
}   \
- (long) _sys_result; })
+ (long long) _sys_result; })

 # undef INTERNAL_SYSCALL_DECL
 # define INTERNAL_SYSCALL_DECL(err) do { } while (0)
@@ -194,7 +194,7 @@

 # undef INTERNAL_SYSCALL_ERROR_P
 # define INTERNAL_SYSCALL_ERROR_P(val, err) \
-  ((unsigned long) (val) >= (unsigned long) -4095)
+  ((unsigned long long) (val) >= (unsigned long long) -4095)

 # undef INTERNAL_SYSCALL_ERRNO
 # define INTERNAL_SYSCALL_ERRNO(val, err)  (-(val))
--
1.8.4.5



 From a0780d286277bf70bacfc0b20fe909a46b990f6e Mon Sep 17 00:00:00 2001
From: gaoyongliang <gaoyongli...@huawei.com>
Date: Thu, 19 May 2016 18:19:05 +0800
Subject: [PATCH] ilp32 fix syscall return value to use long long

Signed-off-by: Yongliang Gao <gaoyongli...@huawei.com>
Signed-off-by: Bamvor Jian Zhang <bamvor.zhangj...@huawei.com>

---
  sysdeps/unix/sysdep.h| 2 +-
  sysdeps/unix/sysv/linux/aarch64/sysdep.h | 8 
  2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/sysdeps/unix/sysdep.h b/sysdeps/unix/sysdep.h
index 71db7f8..09b6e75 100644
--- a/sysdeps/unix/sysdep.h
+++ b/sysdeps/unix/sysdep.h
@@ -31,7 +31,7 @@

  #define SYSCALL_CANCEL(name, ...) \
({ \
-long int sc_ret; \
+long long sc_ret; \
  if (SINGLE_THREAD_P) \
sc_ret = INLINE_SYSCALL (name, __SYSCALL_NARGS(__VA_ARGS__),   \
 __VA_ARGS__); \
diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.h 
b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
index fbf76c1..a696cc2 100644
--- a/sysdeps/unix/sysv/linux/aarch64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
@@ -173,7 +173,7 @@

Re: [PATCH 11/27] [AARCH64] Syscalls for ILP32 are passed always via 64bit values.

2016-06-21 Thread Zhangjian (Bamvor)

Hi,

On 2016/6/21 19:42, Zhangjian (Bamvor) wrote:

Hi,

On 2016/6/21 15:56, Andreas Schwab wrote:

Yury Norov  writes:


diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.h 
b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
index 1ffabc2..42f89c8 100644
--- a/sysdeps/unix/sysv/linux/aarch64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
@@ -161,11 +161,11 @@
 call.  */
  # undef INLINE_SYSCALL
  # define INLINE_SYSCALL(name, nr, args...)\
-  ({ unsigned long _sys_result = INTERNAL_SYSCALL (name, , nr, args);\
+  ({ unsigned long long _sys_result = INTERNAL_SYSCALL (name, , nr, args);\
   if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_sys_result, ), 0))\
 {\
   __set_errno (INTERNAL_SYSCALL_ERRNO (_sys_result, ));\
- _sys_result = (unsigned long) -1;\
+ _sys_result = (unsigned long long) -1;\
 }\
   (long) _sys_result; })


The cast should be (long long).

My understanding that we need more conversion, reference the follow patch:

Sorry, I used the wrong version of patch, here is the version could apply on 
yury'.
For vdso part, maybe we should fix in this patch instead of "[PATCH 19/27]
[AARCH64] Add typesizes.h for ILP32".

From 8c5f27c19407ba3ba8c400f0645cb51f91a5b379 Mon Sep 17 00:00:00 2001
From: gaoyongliang 
Date: Thu, 19 May 2016 18:19:05 +0800
Subject: [PATCH] ilp32 fix syscall return value to use long long

Signed-off-by: Yongliang Gao 
Signed-off-by: Bamvor Jian Zhang 
---
 sysdeps/unix/sysdep.h| 2 +-
 sysdeps/unix/sysv/linux/aarch64/sysdep.h | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/sysdeps/unix/sysdep.h b/sysdeps/unix/sysdep.h
index 94a2ce0..a12456b 100644
--- a/sysdeps/unix/sysdep.h
+++ b/sysdeps/unix/sysdep.h
@@ -53,7 +53,7 @@

 #define SYSCALL_CANCEL(...) \
   ({\
-long int sc_ret;\
+long long sc_ret;   \
 if (SINGLE_THREAD_P)\
   sc_ret = __SYSCALL_CALL (__VA_ARGS__);   
 \
 else\
diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.h 
b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
index 42f89c8..82de012 100644
--- a/sysdeps/unix/sysv/linux/aarch64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
@@ -167,7 +167,7 @@
 __set_errno (INTERNAL_SYSCALL_ERRNO (_sys_result, ));  \
 _sys_result = (unsigned long long) -1; \
}   \
- (long) _sys_result; })
+ (long long) _sys_result; })

 # undef INTERNAL_SYSCALL_DECL
 # define INTERNAL_SYSCALL_DECL(err) do { } while (0)
@@ -194,7 +194,7 @@

 # undef INTERNAL_SYSCALL_ERROR_P
 # define INTERNAL_SYSCALL_ERROR_P(val, err) \
-  ((unsigned long) (val) >= (unsigned long) -4095)
+  ((unsigned long long) (val) >= (unsigned long long) -4095)

 # undef INTERNAL_SYSCALL_ERRNO
 # define INTERNAL_SYSCALL_ERRNO(val, err)  (-(val))
--
1.8.4.5



 From a0780d286277bf70bacfc0b20fe909a46b990f6e Mon Sep 17 00:00:00 2001
From: gaoyongliang 
Date: Thu, 19 May 2016 18:19:05 +0800
Subject: [PATCH] ilp32 fix syscall return value to use long long

Signed-off-by: Yongliang Gao 
Signed-off-by: Bamvor Jian Zhang 

---
  sysdeps/unix/sysdep.h| 2 +-
  sysdeps/unix/sysv/linux/aarch64/sysdep.h | 8 
  2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/sysdeps/unix/sysdep.h b/sysdeps/unix/sysdep.h
index 71db7f8..09b6e75 100644
--- a/sysdeps/unix/sysdep.h
+++ b/sysdeps/unix/sysdep.h
@@ -31,7 +31,7 @@

  #define SYSCALL_CANCEL(name, ...) \
({ \
-long int sc_ret; \
+long long sc_ret; \
  if (SINGLE_THREAD_P) \
sc_ret = INLINE_SYSCALL (name, __SYSCALL_NARGS(__VA_ARGS__),   \
 __VA_ARGS__); \
diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.h 
b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
index fbf76c1..a696cc2 100644
--- a/sysdeps/unix/sysv/linux/aarch64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
@@ -173,7 +173,7 @@
{  \
iserr:  \
  __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err));  \
-sc_ret = -1L;  \
+ 

Re: [PATCH 11/27] [AARCH64] Syscalls for ILP32 are passed always via 64bit values.

2016-06-21 Thread Zhangjian (Bamvor)

Hi,

On 2016/6/21 15:56, Andreas Schwab wrote:

Yury Norov  writes:


diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.h 
b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
index 1ffabc2..42f89c8 100644
--- a/sysdeps/unix/sysv/linux/aarch64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
@@ -161,11 +161,11 @@
 call.  */
  # undef INLINE_SYSCALL
  # define INLINE_SYSCALL(name, nr, args...)\
-  ({ unsigned long _sys_result = INTERNAL_SYSCALL (name, , nr, args);  \
+  ({ unsigned long long _sys_result = INTERNAL_SYSCALL (name, , nr, args); 
\
   if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_sys_result, ), 0))\
 {  \
 __set_errno (INTERNAL_SYSCALL_ERRNO (_sys_result, ));  \
-_sys_result = (unsigned long) -1;  \
+_sys_result = (unsigned long long) -1; \
 }  \
   (long) _sys_result; })


The cast should be (long long).

My understanding that we need more conversion, reference the follow patch:

From a0780d286277bf70bacfc0b20fe909a46b990f6e Mon Sep 17 00:00:00 2001
From: gaoyongliang 
Date: Thu, 19 May 2016 18:19:05 +0800
Subject: [PATCH] ilp32 fix syscall return value to use long long

Signed-off-by: Yongliang Gao 
Signed-off-by: Bamvor Jian Zhang 

---
 sysdeps/unix/sysdep.h| 2 +-
 sysdeps/unix/sysv/linux/aarch64/sysdep.h | 8 
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/sysdeps/unix/sysdep.h b/sysdeps/unix/sysdep.h
index 71db7f8..09b6e75 100644
--- a/sysdeps/unix/sysdep.h
+++ b/sysdeps/unix/sysdep.h
@@ -31,7 +31,7 @@

 #define SYSCALL_CANCEL(name, ...) \
   ({ \
-long int sc_ret; \
+long long sc_ret; \
 if (SINGLE_THREAD_P) \
   sc_ret = INLINE_SYSCALL (name, __SYSCALL_NARGS(__VA_ARGS__),   \
__VA_ARGS__); \
diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.h 
b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
index fbf76c1..a696cc2 100644
--- a/sysdeps/unix/sysv/linux/aarch64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
@@ -173,7 +173,7 @@
   {
  \
   iserr: \
 __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err));   \
-sc_ret = -1L;\
+sc_ret = -1LL;   \
   }
  \
   out:   \
 sc_ret;  \
@@ -216,7 +216,7 @@
  : "=r" (_x0)\
  : "r" (funcptr) ASM_ARGS_##nr   \
  : "x30", "memory");   \
-(long) _x0;\
+(long long) _x0;   \
   })


@@ -230,7 +230,7 @@
 __set_errno (INTERNAL_SYSCALL_ERRNO (_sys_result, ));  \
 _sys_result = (unsigned long long) -1; \
}   \
- (long) _sys_result; })
+ (long long) _sys_result; })

 # undef INTERNAL_SYSCALL_DECL
 # define INTERNAL_SYSCALL_DECL(err) do { } while (0)
@@ -257,7 +257,7 @@

 # undef INTERNAL_SYSCALL_ERROR_P
 # define INTERNAL_SYSCALL_ERROR_P(val, err) \
-  ((unsigned long) (val) >= (unsigned long) -4095)
+  ((unsigned long long) (val) >= (unsigned long long) -4095)

 # undef INTERNAL_SYSCALL_ERRNO
 # define INTERNAL_SYSCALL_ERRNO(val, err)  (-(val))
--
1.8.4.5



Andreas.





Re: [PATCH 11/27] [AARCH64] Syscalls for ILP32 are passed always via 64bit values.

2016-06-21 Thread Zhangjian (Bamvor)

Hi,

On 2016/6/21 15:56, Andreas Schwab wrote:

Yury Norov  writes:


diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.h 
b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
index 1ffabc2..42f89c8 100644
--- a/sysdeps/unix/sysv/linux/aarch64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
@@ -161,11 +161,11 @@
 call.  */
  # undef INLINE_SYSCALL
  # define INLINE_SYSCALL(name, nr, args...)\
-  ({ unsigned long _sys_result = INTERNAL_SYSCALL (name, , nr, args);  \
+  ({ unsigned long long _sys_result = INTERNAL_SYSCALL (name, , nr, args); 
\
   if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_sys_result, ), 0))\
 {  \
 __set_errno (INTERNAL_SYSCALL_ERRNO (_sys_result, ));  \
-_sys_result = (unsigned long) -1;  \
+_sys_result = (unsigned long long) -1; \
 }  \
   (long) _sys_result; })


The cast should be (long long).

My understanding that we need more conversion, reference the follow patch:

From a0780d286277bf70bacfc0b20fe909a46b990f6e Mon Sep 17 00:00:00 2001
From: gaoyongliang 
Date: Thu, 19 May 2016 18:19:05 +0800
Subject: [PATCH] ilp32 fix syscall return value to use long long

Signed-off-by: Yongliang Gao 
Signed-off-by: Bamvor Jian Zhang 

---
 sysdeps/unix/sysdep.h| 2 +-
 sysdeps/unix/sysv/linux/aarch64/sysdep.h | 8 
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/sysdeps/unix/sysdep.h b/sysdeps/unix/sysdep.h
index 71db7f8..09b6e75 100644
--- a/sysdeps/unix/sysdep.h
+++ b/sysdeps/unix/sysdep.h
@@ -31,7 +31,7 @@

 #define SYSCALL_CANCEL(name, ...) \
   ({ \
-long int sc_ret; \
+long long sc_ret; \
 if (SINGLE_THREAD_P) \
   sc_ret = INLINE_SYSCALL (name, __SYSCALL_NARGS(__VA_ARGS__),   \
__VA_ARGS__); \
diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.h 
b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
index fbf76c1..a696cc2 100644
--- a/sysdeps/unix/sysv/linux/aarch64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
@@ -173,7 +173,7 @@
   {
  \
   iserr: \
 __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err));   \
-sc_ret = -1L;\
+sc_ret = -1LL;   \
   }
  \
   out:   \
 sc_ret;  \
@@ -216,7 +216,7 @@
  : "=r" (_x0)\
  : "r" (funcptr) ASM_ARGS_##nr   \
  : "x30", "memory");   \
-(long) _x0;\
+(long long) _x0;   \
   })


@@ -230,7 +230,7 @@
 __set_errno (INTERNAL_SYSCALL_ERRNO (_sys_result, ));  \
 _sys_result = (unsigned long long) -1; \
}   \
- (long) _sys_result; })
+ (long long) _sys_result; })

 # undef INTERNAL_SYSCALL_DECL
 # define INTERNAL_SYSCALL_DECL(err) do { } while (0)
@@ -257,7 +257,7 @@

 # undef INTERNAL_SYSCALL_ERROR_P
 # define INTERNAL_SYSCALL_ERROR_P(val, err) \
-  ((unsigned long) (val) >= (unsigned long) -4095)
+  ((unsigned long long) (val) >= (unsigned long long) -4095)

 # undef INTERNAL_SYSCALL_ERRNO
 # define INTERNAL_SYSCALL_ERRNO(val, err)  (-(val))
--
1.8.4.5



Andreas.





Re: [PATCH 26/27] [AARCH64] Change type of __align to long long

2016-06-21 Thread Zhangjian (Bamvor)

Hi, Yury

On 2016/6/21 13:07, Yury Norov wrote:

From: Andrew Pinski 

So that ILP32 is aligned to 64bits.

Signed-off-by: Yury Norov 
---
  sysdeps/aarch64/nptl/bits/semaphore.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sysdeps/aarch64/nptl/bits/semaphore.h 
b/sysdeps/aarch64/nptl/bits/semaphore.h
index 3cc5b37..3fe6047 100644
--- a/sysdeps/aarch64/nptl/bits/semaphore.h
+++ b/sysdeps/aarch64/nptl/bits/semaphore.h
@@ -31,5 +31,5 @@
  typedef union
  {
char __size[__SIZEOF_SEM_T];
-  long int __align;
+  long long int __align;

Why we need align to 64bit?

Regard

Bamvor

  } sem_t;





Re: [PATCH 26/27] [AARCH64] Change type of __align to long long

2016-06-21 Thread Zhangjian (Bamvor)

Hi, Yury

On 2016/6/21 13:07, Yury Norov wrote:

From: Andrew Pinski 

So that ILP32 is aligned to 64bits.

Signed-off-by: Yury Norov 
---
  sysdeps/aarch64/nptl/bits/semaphore.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sysdeps/aarch64/nptl/bits/semaphore.h 
b/sysdeps/aarch64/nptl/bits/semaphore.h
index 3cc5b37..3fe6047 100644
--- a/sysdeps/aarch64/nptl/bits/semaphore.h
+++ b/sysdeps/aarch64/nptl/bits/semaphore.h
@@ -31,5 +31,5 @@
  typedef union
  {
char __size[__SIZEOF_SEM_T];
-  long int __align;
+  long long int __align;

Why we need align to 64bit?

Regard

Bamvor

  } sem_t;





Re: [PATCH 08/19] arm64: introduce is_a32_task and is_a32_thread (for AArch32 compat)

2016-06-21 Thread Zhangjian (Bamvor)

Hi,

On 2016/6/18 7:54, Yury Norov wrote:

Based on patch of Andrew Pinski.

This patch introduces is_a32_compat_task and is_a32_thread so it is
easier to say this is a a32 specific thread or a generic compat thread/task.
Corresponding functions are located in  to avoid mess in
headers.

Some files include both  and ,
and this is wrong because  has  already
included. It was fixed too.

Signed-off-by: Yury Norov 
Signed-off-by: Philipp Tomsich 
Signed-off-by: Christoph Muellner 
Signed-off-by: Andrew Pinski 
Reviewed-by: David Daney 
---
  arch/arm64/include/asm/compat.h  | 19 ++-
  arch/arm64/include/asm/elf.h | 10 +++---
  arch/arm64/include/asm/ftrace.h  |  2 +-
  arch/arm64/include/asm/is_compat.h   | 64 
  arch/arm64/include/asm/memory.h  |  5 +--
  arch/arm64/include/asm/processor.h   |  5 +--
  arch/arm64/include/asm/syscall.h |  2 +-
  arch/arm64/include/asm/thread_info.h |  2 +-
  arch/arm64/kernel/hw_breakpoint.c| 10 +++---
  arch/arm64/kernel/perf_regs.c|  2 +-
  arch/arm64/kernel/process.c  |  7 ++--
  arch/arm64/kernel/ptrace.c   | 11 +++
  arch/arm64/kernel/signal.c   |  4 +--
  arch/arm64/kernel/traps.c|  3 +-
  14 files changed, 98 insertions(+), 48 deletions(-)
  create mode 100644 arch/arm64/include/asm/is_compat.h

diff --git a/arch/arm64/include/asm/compat.h b/arch/arm64/include/asm/compat.h
index eb8432b..df2f72d 100644
--- a/arch/arm64/include/asm/compat.h
+++ b/arch/arm64/include/asm/compat.h
@@ -24,6 +24,8 @@
  #include 
  #include 

+#include 
+
  #define COMPAT_USER_HZ100
  #ifdef __AARCH64EB__
  #define COMPAT_UTS_MACHINE"armv8b\0\0"
@@ -298,23 +300,6 @@ struct compat_shmid64_ds {
compat_ulong_t __unused5;
  };

-static inline int is_compat_task(void)
-{
-   return test_thread_flag(TIF_32BIT);
-}
-
-static inline int is_compat_thread(struct thread_info *thread)
-{
-   return test_ti_thread_flag(thread, TIF_32BIT);
-}
-
-#else /* !CONFIG_COMPAT */
-
-static inline int is_compat_thread(struct thread_info *thread)
-{
-   return 0;
-}
-
  #endif /* CONFIG_COMPAT */
  #endif /* __KERNEL__ */
  #endif /* __ASM_COMPAT_H */
diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h
index 579b6e6..bef2d90 100644
--- a/arch/arm64/include/asm/elf.h
+++ b/arch/arm64/include/asm/elf.h
@@ -16,6 +16,10 @@
  #ifndef __ASM_ELF_H
  #define __ASM_ELF_H

+#ifndef __ASSEMBLY__
+#include 
+#endif
+
  #include 

  /*
@@ -152,13 +156,9 @@ extern int arch_setup_additional_pages(struct linux_binprm 
*bprm,
   int uses_interp);

  /* 1GB of VA */
-#ifdef CONFIG_COMPAT
-#define STACK_RND_MASK (test_thread_flag(TIF_32BIT) ? \
+#define STACK_RND_MASK (is_compat_task() ? \
0x7ff >> (PAGE_SHIFT - 12) : \
0x3 >> (PAGE_SHIFT - 12))
-#else
-#define STACK_RND_MASK (0x3 >> (PAGE_SHIFT - 12))
-#endif

  #ifdef __AARCH64EB__
  #define COMPAT_ELF_PLATFORM   ("v8b")
diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h
index caa955f..0feb28a 100644
--- a/arch/arm64/include/asm/ftrace.h
+++ b/arch/arm64/include/asm/ftrace.h
@@ -54,7 +54,7 @@ static inline unsigned long ftrace_call_adjust(unsigned long 
addr)
  #define ARCH_TRACE_IGNORE_COMPAT_SYSCALLS
  static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs)
  {
-   return is_compat_task();
+   return is_a32_compat_task();
  }
  #endif /* ifndef __ASSEMBLY__ */

diff --git a/arch/arm64/include/asm/is_compat.h 
b/arch/arm64/include/asm/is_compat.h
new file mode 100644
index 000..8dba5ca
--- /dev/null
+++ b/arch/arm64/include/asm/is_compat.h
@@ -0,0 +1,64 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef __ASM_IS_COMPAT_H
+#define __ASM_IS_COMPAT_H
+#ifndef __ASSEMBLY__
+
+#include 
+
+#ifdef CONFIG_AARCH32_EL0
+
+static inline int is_a32_compat_task(void)
+{
+   return test_thread_flag(TIF_32BIT);
+}
+
+static inline int is_a32_compat_thread(struct thread_info *thread)
+{
+   return test_ti_thread_flag(thread, TIF_32BIT);
+}
+

Re: [PATCH 08/19] arm64: introduce is_a32_task and is_a32_thread (for AArch32 compat)

2016-06-21 Thread Zhangjian (Bamvor)

Hi,

On 2016/6/18 7:54, Yury Norov wrote:

Based on patch of Andrew Pinski.

This patch introduces is_a32_compat_task and is_a32_thread so it is
easier to say this is a a32 specific thread or a generic compat thread/task.
Corresponding functions are located in  to avoid mess in
headers.

Some files include both  and ,
and this is wrong because  has  already
included. It was fixed too.

Signed-off-by: Yury Norov 
Signed-off-by: Philipp Tomsich 
Signed-off-by: Christoph Muellner 
Signed-off-by: Andrew Pinski 
Reviewed-by: David Daney 
---
  arch/arm64/include/asm/compat.h  | 19 ++-
  arch/arm64/include/asm/elf.h | 10 +++---
  arch/arm64/include/asm/ftrace.h  |  2 +-
  arch/arm64/include/asm/is_compat.h   | 64 
  arch/arm64/include/asm/memory.h  |  5 +--
  arch/arm64/include/asm/processor.h   |  5 +--
  arch/arm64/include/asm/syscall.h |  2 +-
  arch/arm64/include/asm/thread_info.h |  2 +-
  arch/arm64/kernel/hw_breakpoint.c| 10 +++---
  arch/arm64/kernel/perf_regs.c|  2 +-
  arch/arm64/kernel/process.c  |  7 ++--
  arch/arm64/kernel/ptrace.c   | 11 +++
  arch/arm64/kernel/signal.c   |  4 +--
  arch/arm64/kernel/traps.c|  3 +-
  14 files changed, 98 insertions(+), 48 deletions(-)
  create mode 100644 arch/arm64/include/asm/is_compat.h

diff --git a/arch/arm64/include/asm/compat.h b/arch/arm64/include/asm/compat.h
index eb8432b..df2f72d 100644
--- a/arch/arm64/include/asm/compat.h
+++ b/arch/arm64/include/asm/compat.h
@@ -24,6 +24,8 @@
  #include 
  #include 

+#include 
+
  #define COMPAT_USER_HZ100
  #ifdef __AARCH64EB__
  #define COMPAT_UTS_MACHINE"armv8b\0\0"
@@ -298,23 +300,6 @@ struct compat_shmid64_ds {
compat_ulong_t __unused5;
  };

-static inline int is_compat_task(void)
-{
-   return test_thread_flag(TIF_32BIT);
-}
-
-static inline int is_compat_thread(struct thread_info *thread)
-{
-   return test_ti_thread_flag(thread, TIF_32BIT);
-}
-
-#else /* !CONFIG_COMPAT */
-
-static inline int is_compat_thread(struct thread_info *thread)
-{
-   return 0;
-}
-
  #endif /* CONFIG_COMPAT */
  #endif /* __KERNEL__ */
  #endif /* __ASM_COMPAT_H */
diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h
index 579b6e6..bef2d90 100644
--- a/arch/arm64/include/asm/elf.h
+++ b/arch/arm64/include/asm/elf.h
@@ -16,6 +16,10 @@
  #ifndef __ASM_ELF_H
  #define __ASM_ELF_H

+#ifndef __ASSEMBLY__
+#include 
+#endif
+
  #include 

  /*
@@ -152,13 +156,9 @@ extern int arch_setup_additional_pages(struct linux_binprm 
*bprm,
   int uses_interp);

  /* 1GB of VA */
-#ifdef CONFIG_COMPAT
-#define STACK_RND_MASK (test_thread_flag(TIF_32BIT) ? \
+#define STACK_RND_MASK (is_compat_task() ? \
0x7ff >> (PAGE_SHIFT - 12) : \
0x3 >> (PAGE_SHIFT - 12))
-#else
-#define STACK_RND_MASK (0x3 >> (PAGE_SHIFT - 12))
-#endif

  #ifdef __AARCH64EB__
  #define COMPAT_ELF_PLATFORM   ("v8b")
diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h
index caa955f..0feb28a 100644
--- a/arch/arm64/include/asm/ftrace.h
+++ b/arch/arm64/include/asm/ftrace.h
@@ -54,7 +54,7 @@ static inline unsigned long ftrace_call_adjust(unsigned long 
addr)
  #define ARCH_TRACE_IGNORE_COMPAT_SYSCALLS
  static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs)
  {
-   return is_compat_task();
+   return is_a32_compat_task();
  }
  #endif /* ifndef __ASSEMBLY__ */

diff --git a/arch/arm64/include/asm/is_compat.h 
b/arch/arm64/include/asm/is_compat.h
new file mode 100644
index 000..8dba5ca
--- /dev/null
+++ b/arch/arm64/include/asm/is_compat.h
@@ -0,0 +1,64 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef __ASM_IS_COMPAT_H
+#define __ASM_IS_COMPAT_H
+#ifndef __ASSEMBLY__
+
+#include 
+
+#ifdef CONFIG_AARCH32_EL0
+
+static inline int is_a32_compat_task(void)
+{
+   return test_thread_flag(TIF_32BIT);
+}
+
+static inline int is_a32_compat_thread(struct thread_info *thread)
+{
+   return test_ti_thread_flag(thread, TIF_32BIT);
+}
+
+#else
+
+static inline int is_a32_compat_task(void)
+
+{
+   return 0;
+}
+
+static inline int is_a32_compat_thread(struct thread_info *thread)
+{
+   return 0;
+}

Re: [PATCH 18/27] [AARCH64] Add kernel_sigaction.h for AARCH64 ILP32

2016-06-21 Thread Zhangjian (Bamvor)

Hi,

On 2016/6/21 15:45, Andreas Schwab wrote:

Yury Norov  writes:


In ILP32, the sigaction struct is the same as AARCH64


Isn't sys_ilp32.c using the compat calls for sigaction?

Yes. It is an old patch for v3 of ilp32 patches of kernel which wrote
in 2014. We should remove it completely.

Regards

Bamvor


Andreas.





Re: [PATCH 18/27] [AARCH64] Add kernel_sigaction.h for AARCH64 ILP32

2016-06-21 Thread Zhangjian (Bamvor)

Hi,

On 2016/6/21 15:45, Andreas Schwab wrote:

Yury Norov  writes:


In ILP32, the sigaction struct is the same as AARCH64


Isn't sys_ilp32.c using the compat calls for sigaction?

Yes. It is an old patch for v3 of ilp32 patches of kernel which wrote
in 2014. We should remove it completely.

Regards

Bamvor


Andreas.





Re: [PATCH 21/23] arm64: ilp32: introduce ilp32-specific handlers for sigframe and ucontext

2016-06-16 Thread Zhangjian (Bamvor)

Hi,

On 2016/6/13 1:44, Yury Norov wrote:

Hi Bamvor,

Sorry, I missed this patch.

On Sat, Jun 04, 2016 at 07:34:32PM +0800, Zhangjian (Bamvor) wrote:

Hi,

I found an issue of unwind with the following code. The correct backtrace
should be:
(gdb) where
#0 0x004004d0 in my_sig (sig=11) at test_force3.c:16
#1 
#2 func2 (num=0) at test_force3.c:22
#3 0x00400540 in func1 (num=1) at test_force3.c:28
#4 0x00400574 in main (argc=1, argv=0xffd7bc04) at test_force3.c:33

Without my patch, the backtrace is:
(gdb) where
#0 0x00400490 in my_sig (sig=11) at test_force3.c:16
#1 
#2 0x004004e4 in main (argc=1, argv=0xffe6f8f4) at test_force3.c:33

With my patch which fix the wrong frame pointer(setup_return calculate the 
offset
of fp through ilp32_sigframe instead of sigfreame), the backtrace is:
(gdb) where
#0 0x00400490 in my_sig (sig=11) at test_force3.c:16
#1 
#2 func1 () at test_force3.c:28
#3 0x004004e4 in main (argc=1, argv=0xffe6f8f4) at test_force3.c:33

I am not sure there is still some issue in kernel. But it seem that the gdb of 
ilp32
does not work correctly when unwind without framepointer.

The test code is:

 From 7e364a765097f57aed2d73f94c1688c2e7343e79 Mon Sep 17 00:00:00 2001
From: Bamvor Jian Zhang <bamvor.zhangj...@huawei.com>
Date: Sat, 4 Jun 2016 14:30:05 +0800
Subject: [PATCH] arm64: ilp32: fix for wrong fp offset when calculate the
  new fp

ILP32 define its own sigframe(ilp32_sigframe) because of the
difference uc_context. setup_return do not use ilp32 specific
sigframe to calculate the new offset of fp which lead to wrong
fp in signal handler. At this circumstance, gdb backtrace will miss
one item:
(gdb) where

It should be:
(gdb) where

The test code is as follows:

void my_sig(int sig)
{
 printf("sig=%d\n", sig);
 *(int *)0 = 0x0;
}

void func2(int num)
{
 printf("%s: %d\n", __FUNCTION__, num);
 *(int *)0 = 0x0;
 func2(num-1);
}

void func1(int num)
{
 printf("%s\n", __FUNCTION__);
 func2(num - 1);
}

int main(int argc, char **argv)
{
 signal(11, my_sig);
 func1(argc);
 return 0;
}

This patch fix this by passing the correct offset of fp to
setup_return.
Test pass on both ILP32 and LP64 in aarch64 EE.

Signed-off-by: Bamvor Jian Zhang <bamvor.zhangj...@huawei.com>
---
  arch/arm64/include/asm/signal_common.h | 3 ++-
  arch/arm64/kernel/signal.c | 9 +
  arch/arm64/kernel/signal_ilp32.c   | 4 ++--
  3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/arch/arm64/include/asm/signal_common.h 
b/arch/arm64/include/asm/signal_common.h
index de93c71..a5d7b63 100644
--- a/arch/arm64/include/asm/signal_common.h
+++ b/arch/arm64/include/asm/signal_common.h
@@ -29,6 +29,7 @@ int setup_sigcontex(struct sigcontext __user *uc_mcontext,
struct pt_regs *regs);
  int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sf);
  void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
-   void __user *frame, off_t sigframe_off, int usig);
+   void __user *frame, off_t sigframe_off, off_t fp_off,
+   int usig);

  #endif /* __ASM_SIGNAL_COMMON_H */
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
index 038bebe..e66a6e9 100644
--- a/arch/arm64/kernel/signal.c
+++ b/arch/arm64/kernel/signal.c
@@ -256,14 +256,14 @@ static struct rt_sigframe __user *get_sigframe(struct 
ksignal *ksig,
  }

  void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
-void __user *frame, off_t sigframe_off, int usig)
+void __user *frame, off_t sigframe_off, off_t fp_off,
+int usig)
  {
__sigrestore_t sigtramp;

regs->regs[0] = usig;
regs->sp = (unsigned long)frame;
-   regs->regs[29] = regs->sp + sigframe_off +
-   offsetof(struct sigframe, fp);
+   regs->regs[29] = regs->sp + sigframe_off + fp_off;


I think you are right here. The only nitpick is what for we send 2
offsets just to add one to another inside setup_return()?
We can do like this:

 void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
 void __user *frame, off_t fp_off, int usig)
 {
__sigrestore_t sigtramp;

regs->regs[0] = usig;
regs->sp = (unsigned long)frame;
regs->regs[29] = regs->sp + fp_off;
 [...]
 }

Where fp_off calculation is done by caller.

setup_return(regs, >ka, frame,
offsetof(struct rt_sigframe, sig) + offsetof(struct sigframe, 
fp),
 usig);

For me it's more clear to understand what happens with this approach.
I don't think struct rt_sigframe will grow, but we can even introduce
some helper for it:
 #define RT_SIGFRAM

Re: [PATCH 21/23] arm64: ilp32: introduce ilp32-specific handlers for sigframe and ucontext

2016-06-16 Thread Zhangjian (Bamvor)

Hi,

On 2016/6/13 1:44, Yury Norov wrote:

Hi Bamvor,

Sorry, I missed this patch.

On Sat, Jun 04, 2016 at 07:34:32PM +0800, Zhangjian (Bamvor) wrote:

Hi,

I found an issue of unwind with the following code. The correct backtrace
should be:
(gdb) where
#0 0x004004d0 in my_sig (sig=11) at test_force3.c:16
#1 
#2 func2 (num=0) at test_force3.c:22
#3 0x00400540 in func1 (num=1) at test_force3.c:28
#4 0x00400574 in main (argc=1, argv=0xffd7bc04) at test_force3.c:33

Without my patch, the backtrace is:
(gdb) where
#0 0x00400490 in my_sig (sig=11) at test_force3.c:16
#1 
#2 0x004004e4 in main (argc=1, argv=0xffe6f8f4) at test_force3.c:33

With my patch which fix the wrong frame pointer(setup_return calculate the 
offset
of fp through ilp32_sigframe instead of sigfreame), the backtrace is:
(gdb) where
#0 0x00400490 in my_sig (sig=11) at test_force3.c:16
#1 
#2 func1 () at test_force3.c:28
#3 0x004004e4 in main (argc=1, argv=0xffe6f8f4) at test_force3.c:33

I am not sure there is still some issue in kernel. But it seem that the gdb of 
ilp32
does not work correctly when unwind without framepointer.

The test code is:

 From 7e364a765097f57aed2d73f94c1688c2e7343e79 Mon Sep 17 00:00:00 2001
From: Bamvor Jian Zhang 
Date: Sat, 4 Jun 2016 14:30:05 +0800
Subject: [PATCH] arm64: ilp32: fix for wrong fp offset when calculate the
  new fp

ILP32 define its own sigframe(ilp32_sigframe) because of the
difference uc_context. setup_return do not use ilp32 specific
sigframe to calculate the new offset of fp which lead to wrong
fp in signal handler. At this circumstance, gdb backtrace will miss
one item:
(gdb) where

It should be:
(gdb) where

The test code is as follows:

void my_sig(int sig)
{
 printf("sig=%d\n", sig);
 *(int *)0 = 0x0;
}

void func2(int num)
{
 printf("%s: %d\n", __FUNCTION__, num);
 *(int *)0 = 0x0;
 func2(num-1);
}

void func1(int num)
{
 printf("%s\n", __FUNCTION__);
 func2(num - 1);
}

int main(int argc, char **argv)
{
 signal(11, my_sig);
 func1(argc);
 return 0;
}

This patch fix this by passing the correct offset of fp to
setup_return.
Test pass on both ILP32 and LP64 in aarch64 EE.

Signed-off-by: Bamvor Jian Zhang 
---
  arch/arm64/include/asm/signal_common.h | 3 ++-
  arch/arm64/kernel/signal.c | 9 +
  arch/arm64/kernel/signal_ilp32.c   | 4 ++--
  3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/arch/arm64/include/asm/signal_common.h 
b/arch/arm64/include/asm/signal_common.h
index de93c71..a5d7b63 100644
--- a/arch/arm64/include/asm/signal_common.h
+++ b/arch/arm64/include/asm/signal_common.h
@@ -29,6 +29,7 @@ int setup_sigcontex(struct sigcontext __user *uc_mcontext,
struct pt_regs *regs);
  int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sf);
  void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
-   void __user *frame, off_t sigframe_off, int usig);
+   void __user *frame, off_t sigframe_off, off_t fp_off,
+   int usig);

  #endif /* __ASM_SIGNAL_COMMON_H */
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
index 038bebe..e66a6e9 100644
--- a/arch/arm64/kernel/signal.c
+++ b/arch/arm64/kernel/signal.c
@@ -256,14 +256,14 @@ static struct rt_sigframe __user *get_sigframe(struct 
ksignal *ksig,
  }

  void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
-void __user *frame, off_t sigframe_off, int usig)
+void __user *frame, off_t sigframe_off, off_t fp_off,
+int usig)
  {
__sigrestore_t sigtramp;

regs->regs[0] = usig;
regs->sp = (unsigned long)frame;
-   regs->regs[29] = regs->sp + sigframe_off +
-   offsetof(struct sigframe, fp);
+   regs->regs[29] = regs->sp + sigframe_off + fp_off;


I think you are right here. The only nitpick is what for we send 2
offsets just to add one to another inside setup_return()?
We can do like this:

 void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
 void __user *frame, off_t fp_off, int usig)
 {
__sigrestore_t sigtramp;

regs->regs[0] = usig;
regs->sp = (unsigned long)frame;
regs->regs[29] = regs->sp + fp_off;
 [...]
 }

Where fp_off calculation is done by caller.

setup_return(regs, >ka, frame,
offsetof(struct rt_sigframe, sig) + offsetof(struct sigframe, 
fp),
 usig);

For me it's more clear to understand what happens with this approach.
I don't think struct rt_sigframe will grow, but we can even introduce
some helper for it:
 #define RT_SIGFRAME_FP_POS (offsetof(struct rt_sigframe, sig) + 
offsetof(struct sigframe, fp))

If no obje

Re: [PATCH 16/23] arm64: ilp32: introduce binfmt_ilp32.c

2016-06-13 Thread Zhangjian (Bamvor)

Hi, again

I found another issue in binfmt_ilp32.c. We are using the ELF_ET_DYN_BASE
for ilp32 application. The default ELF_ET_DYN_BASE is calculated by
TASK_SIZE_64. IIUC, we should define the following things in binfmt_ilp32.c
which is the same value as aarch32:

+#undef ELF_ET_DYN_BASE
+#define ELF_ET_DYN_BASE COMPAT_ELF_ET_DYN_BASE

Note that the ilp32 library works without this patch. After read code and
debug, the address is corrected in get_unmapped_area. I suspect find_vma
fix this wrong address.

Ideas?

Regards

Bamvor

On 2016/6/13 11:05, Zhangjian (Bamvor) wrote:

Hi, Yury

On 2016/5/24 8:04, Yury Norov wrote:

to handle ILP32 binaries

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
  arch/arm64/kernel/Makefile   |  1 +
  arch/arm64/kernel/binfmt_ilp32.c | 91 
  2 files changed, 92 insertions(+)
  create mode 100644 arch/arm64/kernel/binfmt_ilp32.c

diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 6bc9738..9dfdf86 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -28,6 +28,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
  arm64-obj-$(CONFIG_AARCH32_EL0)+= sys32.o kuser32.o signal32.o \
 sys_compat.o entry32.o\
 ../../arm/kernel/opcodes.o binfmt_elf32.o
+arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o
  arm64-obj-$(CONFIG_FUNCTION_TRACER)+= ftrace.o entry-ftrace.o
  arm64-obj-$(CONFIG_MODULES)+= arm64ksyms.o module.o
  arm64-obj-$(CONFIG_ARM64_MODULE_PLTS)+= module-plts.o
diff --git a/arch/arm64/kernel/binfmt_ilp32.c b/arch/arm64/kernel/binfmt_ilp32.c
new file mode 100644
index 000..a934fd4
--- /dev/null
+++ b/arch/arm64/kernel/binfmt_ilp32.c
@@ -0,0 +1,91 @@
+/*
+ * Support for ILP32 Linux/aarch64 ELF binaries.
+ */
+
+#include 
+#include 
+
+#undefELF_CLASS
+#define ELF_CLASSELFCLASS32
+
+#undefelfhdr
+#undefelf_phdr
+#undefelf_shdr
+#undefelf_note
+#undefelf_addr_t
+#define elfhdrelf32_hdr
+#define elf_phdrelf32_phdr
+#define elf_shdrelf32_shdr
+#define elf_noteelf32_note
+#define elf_addr_tElf32_Addr
+
+/*
+ * Some data types as stored in coredump.
+ */
+#define user_long_tcompat_long_t
+#define user_siginfo_tcompat_siginfo_t
+#define copy_siginfo_to_usercopy_siginfo_to_user32
+
+/*
+ * The machine-dependent core note format types are defined in 
elfcore-compat.h,
+ * which requires asm/elf.h to define compat_elf_gregset_t et al.
+ */
+#define elf_prstatuscompat_elf_prstatus
+#define elf_prpsinfocompat_elf_prpsinfo
+
+/*
+ * Compat version of cputime_to_compat_timeval, perhaps this
+ * should be an inline in .
+ */
+static void cputime_to_compat_timeval(const cputime_t cputime,
+  struct compat_timeval *value)
+{
+struct timeval tv;
+cputime_to_timeval(cputime, );
+value->tv_sec = tv.tv_sec;
+value->tv_usec = tv.tv_usec;
+}
+
+#undef cputime_to_timeval
+#define cputime_to_timeval cputime_to_compat_timeval
+
+/* AARCH64 ILP32 EABI. */
+#undef elf_check_arch
+#define elf_check_arch(x)(((x)->e_machine == EM_AARCH64)\
+&& (x)->e_ident[EI_CLASS] == ELFCLASS32)
+
+#undef SET_PERSONALITY
+#define SET_PERSONALITY(ex)\
+do {\
+set_thread_flag(TIF_32BIT_AARCH64);\
+clear_thread_flag(TIF_32BIT);\
+} while (0)
+
+#undef ARCH_DLINFO
+#define ARCH_DLINFO\
+do {\
+NEW_AUX_ENT(AT_SYSINFO_EHDR,\
+(elf_addr_t)(long)current->mm->context.vdso);\
+} while (0)
+
+#ifdef __AARCH64EB__
+#define COMPAT_ELF_PLATFORM("aarch64_be:ilp32")
+#else
+#define COMPAT_ELF_PLATFORM("aarch64:ilp32")
+#endif

fs/binfmt_elf.c use ELF_PLATFORM instead of the COMPAT one. Should we define
ELF_PLATFORM directly?
#undef ELF_PLATFORM
#ifdef __AARCH64EB__
#define ELF_PLATFORM("aarch64_be:ilp32")
#else
#define ELF_PLATFORM("aarch64:ilp32")
#endif

Regards

Bamvor

+
+#undef ELF_HWCAP
+#undef ELF_HWCAP2
+#define ELF_HWCAP((u32) elf_hwcap)
+#define ELF_HWCAP2((u32) (elf_hwcap >> 32))
+
+/*
+ * Rename a few of the symbols that binfmt_elf.c will define.
+ * These are all local so the names don't really matter, but it
+ * might make some debugging less confusing not to duplicate them.
+ */
+#define elf_formatcompat_elf_format
+#define init_elf_binfmtinit_compat_elf_binfmt
+#define exit_elf_binfmtexit_compat_elf_binfmt
+
+#include "../../../fs/binfmt_elf.c"







Re: [PATCH 16/23] arm64: ilp32: introduce binfmt_ilp32.c

2016-06-13 Thread Zhangjian (Bamvor)

Hi, again

I found another issue in binfmt_ilp32.c. We are using the ELF_ET_DYN_BASE
for ilp32 application. The default ELF_ET_DYN_BASE is calculated by
TASK_SIZE_64. IIUC, we should define the following things in binfmt_ilp32.c
which is the same value as aarch32:

+#undef ELF_ET_DYN_BASE
+#define ELF_ET_DYN_BASE COMPAT_ELF_ET_DYN_BASE

Note that the ilp32 library works without this patch. After read code and
debug, the address is corrected in get_unmapped_area. I suspect find_vma
fix this wrong address.

Ideas?

Regards

Bamvor

On 2016/6/13 11:05, Zhangjian (Bamvor) wrote:

Hi, Yury

On 2016/5/24 8:04, Yury Norov wrote:

to handle ILP32 binaries

Signed-off-by: Yury Norov 
---
  arch/arm64/kernel/Makefile   |  1 +
  arch/arm64/kernel/binfmt_ilp32.c | 91 
  2 files changed, 92 insertions(+)
  create mode 100644 arch/arm64/kernel/binfmt_ilp32.c

diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 6bc9738..9dfdf86 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -28,6 +28,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
  arm64-obj-$(CONFIG_AARCH32_EL0)+= sys32.o kuser32.o signal32.o \
 sys_compat.o entry32.o\
 ../../arm/kernel/opcodes.o binfmt_elf32.o
+arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o
  arm64-obj-$(CONFIG_FUNCTION_TRACER)+= ftrace.o entry-ftrace.o
  arm64-obj-$(CONFIG_MODULES)+= arm64ksyms.o module.o
  arm64-obj-$(CONFIG_ARM64_MODULE_PLTS)+= module-plts.o
diff --git a/arch/arm64/kernel/binfmt_ilp32.c b/arch/arm64/kernel/binfmt_ilp32.c
new file mode 100644
index 000..a934fd4
--- /dev/null
+++ b/arch/arm64/kernel/binfmt_ilp32.c
@@ -0,0 +1,91 @@
+/*
+ * Support for ILP32 Linux/aarch64 ELF binaries.
+ */
+
+#include 
+#include 
+
+#undefELF_CLASS
+#define ELF_CLASSELFCLASS32
+
+#undefelfhdr
+#undefelf_phdr
+#undefelf_shdr
+#undefelf_note
+#undefelf_addr_t
+#define elfhdrelf32_hdr
+#define elf_phdrelf32_phdr
+#define elf_shdrelf32_shdr
+#define elf_noteelf32_note
+#define elf_addr_tElf32_Addr
+
+/*
+ * Some data types as stored in coredump.
+ */
+#define user_long_tcompat_long_t
+#define user_siginfo_tcompat_siginfo_t
+#define copy_siginfo_to_usercopy_siginfo_to_user32
+
+/*
+ * The machine-dependent core note format types are defined in 
elfcore-compat.h,
+ * which requires asm/elf.h to define compat_elf_gregset_t et al.
+ */
+#define elf_prstatuscompat_elf_prstatus
+#define elf_prpsinfocompat_elf_prpsinfo
+
+/*
+ * Compat version of cputime_to_compat_timeval, perhaps this
+ * should be an inline in .
+ */
+static void cputime_to_compat_timeval(const cputime_t cputime,
+  struct compat_timeval *value)
+{
+struct timeval tv;
+cputime_to_timeval(cputime, );
+value->tv_sec = tv.tv_sec;
+value->tv_usec = tv.tv_usec;
+}
+
+#undef cputime_to_timeval
+#define cputime_to_timeval cputime_to_compat_timeval
+
+/* AARCH64 ILP32 EABI. */
+#undef elf_check_arch
+#define elf_check_arch(x)(((x)->e_machine == EM_AARCH64)\
+&& (x)->e_ident[EI_CLASS] == ELFCLASS32)
+
+#undef SET_PERSONALITY
+#define SET_PERSONALITY(ex)\
+do {\
+set_thread_flag(TIF_32BIT_AARCH64);\
+clear_thread_flag(TIF_32BIT);\
+} while (0)
+
+#undef ARCH_DLINFO
+#define ARCH_DLINFO\
+do {\
+NEW_AUX_ENT(AT_SYSINFO_EHDR,\
+(elf_addr_t)(long)current->mm->context.vdso);\
+} while (0)
+
+#ifdef __AARCH64EB__
+#define COMPAT_ELF_PLATFORM("aarch64_be:ilp32")
+#else
+#define COMPAT_ELF_PLATFORM("aarch64:ilp32")
+#endif

fs/binfmt_elf.c use ELF_PLATFORM instead of the COMPAT one. Should we define
ELF_PLATFORM directly?
#undef ELF_PLATFORM
#ifdef __AARCH64EB__
#define ELF_PLATFORM("aarch64_be:ilp32")
#else
#define ELF_PLATFORM("aarch64:ilp32")
#endif

Regards

Bamvor

+
+#undef ELF_HWCAP
+#undef ELF_HWCAP2
+#define ELF_HWCAP((u32) elf_hwcap)
+#define ELF_HWCAP2((u32) (elf_hwcap >> 32))
+
+/*
+ * Rename a few of the symbols that binfmt_elf.c will define.
+ * These are all local so the names don't really matter, but it
+ * might make some debugging less confusing not to duplicate them.
+ */
+#define elf_formatcompat_elf_format
+#define init_elf_binfmtinit_compat_elf_binfmt
+#define exit_elf_binfmtexit_compat_elf_binfmt
+
+#include "../../../fs/binfmt_elf.c"







Re: [PATCH 16/23] arm64: ilp32: introduce binfmt_ilp32.c

2016-06-12 Thread Zhangjian (Bamvor)

Hi, Yury

On 2016/5/24 8:04, Yury Norov wrote:

to handle ILP32 binaries

Signed-off-by: Yury Norov 
---
  arch/arm64/kernel/Makefile   |  1 +
  arch/arm64/kernel/binfmt_ilp32.c | 91 
  2 files changed, 92 insertions(+)
  create mode 100644 arch/arm64/kernel/binfmt_ilp32.c

diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 6bc9738..9dfdf86 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -28,6 +28,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
  arm64-obj-$(CONFIG_AARCH32_EL0)   += sys32.o kuser32.o signal32.o 
\
   sys_compat.o entry32.o   
\
   ../../arm/kernel/opcodes.o 
binfmt_elf32.o
+arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o
  arm64-obj-$(CONFIG_FUNCTION_TRACER)   += ftrace.o entry-ftrace.o
  arm64-obj-$(CONFIG_MODULES)   += arm64ksyms.o module.o
  arm64-obj-$(CONFIG_ARM64_MODULE_PLTS) += module-plts.o
diff --git a/arch/arm64/kernel/binfmt_ilp32.c b/arch/arm64/kernel/binfmt_ilp32.c
new file mode 100644
index 000..a934fd4
--- /dev/null
+++ b/arch/arm64/kernel/binfmt_ilp32.c
@@ -0,0 +1,91 @@
+/*
+ * Support for ILP32 Linux/aarch64 ELF binaries.
+ */
+
+#include 
+#include 
+
+#undef ELF_CLASS
+#define ELF_CLASS  ELFCLASS32
+
+#undef elfhdr
+#undef elf_phdr
+#undef elf_shdr
+#undef elf_note
+#undef elf_addr_t
+#define elfhdr elf32_hdr
+#define elf_phdr   elf32_phdr
+#define elf_shdr   elf32_shdr
+#define elf_note   elf32_note
+#define elf_addr_t Elf32_Addr
+
+/*
+ * Some data types as stored in coredump.
+ */
+#define user_long_tcompat_long_t
+#define user_siginfo_t compat_siginfo_t
+#define copy_siginfo_to_user   copy_siginfo_to_user32
+
+/*
+ * The machine-dependent core note format types are defined in 
elfcore-compat.h,
+ * which requires asm/elf.h to define compat_elf_gregset_t et al.
+ */
+#define elf_prstatus   compat_elf_prstatus
+#define elf_prpsinfo   compat_elf_prpsinfo
+
+/*
+ * Compat version of cputime_to_compat_timeval, perhaps this
+ * should be an inline in .
+ */
+static void cputime_to_compat_timeval(const cputime_t cputime,
+ struct compat_timeval *value)
+{
+   struct timeval tv;
+   cputime_to_timeval(cputime, );
+   value->tv_sec = tv.tv_sec;
+   value->tv_usec = tv.tv_usec;
+}
+
+#undef cputime_to_timeval
+#define cputime_to_timeval cputime_to_compat_timeval
+
+/* AARCH64 ILP32 EABI. */
+#undef elf_check_arch
+#define elf_check_arch(x)  (((x)->e_machine == EM_AARCH64)  \
+   && (x)->e_ident[EI_CLASS] == ELFCLASS32)
+
+#undef SET_PERSONALITY
+#define SET_PERSONALITY(ex)\
+do {   \
+   set_thread_flag(TIF_32BIT_AARCH64); \
+   clear_thread_flag(TIF_32BIT);   \
+} while (0)
+
+#undef ARCH_DLINFO
+#define ARCH_DLINFO\
+do {   \
+   NEW_AUX_ENT(AT_SYSINFO_EHDR,\
+   (elf_addr_t)(long)current->mm->context.vdso); \
+} while (0)
+
+#ifdef __AARCH64EB__
+#define COMPAT_ELF_PLATFORM("aarch64_be:ilp32")
+#else
+#define COMPAT_ELF_PLATFORM("aarch64:ilp32")
+#endif

fs/binfmt_elf.c use ELF_PLATFORM instead of the COMPAT one. Should we define
ELF_PLATFORM directly?
#undef ELF_PLATFORM
#ifdef __AARCH64EB__
#define ELF_PLATFORM("aarch64_be:ilp32")
#else
#define ELF_PLATFORM("aarch64:ilp32")
#endif

Regards

Bamvor

+
+#undef ELF_HWCAP
+#undef ELF_HWCAP2
+#define ELF_HWCAP  ((u32) elf_hwcap)
+#define ELF_HWCAP2 ((u32) (elf_hwcap >> 32))
+
+/*
+ * Rename a few of the symbols that binfmt_elf.c will define.
+ * These are all local so the names don't really matter, but it
+ * might make some debugging less confusing not to duplicate them.
+ */
+#define elf_format compat_elf_format
+#define init_elf_binfmtinit_compat_elf_binfmt
+#define exit_elf_binfmtexit_compat_elf_binfmt
+
+#include "../../../fs/binfmt_elf.c"





Re: [PATCH 16/23] arm64: ilp32: introduce binfmt_ilp32.c

2016-06-12 Thread Zhangjian (Bamvor)

Hi, Yury

On 2016/5/24 8:04, Yury Norov wrote:

to handle ILP32 binaries

Signed-off-by: Yury Norov 
---
  arch/arm64/kernel/Makefile   |  1 +
  arch/arm64/kernel/binfmt_ilp32.c | 91 
  2 files changed, 92 insertions(+)
  create mode 100644 arch/arm64/kernel/binfmt_ilp32.c

diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 6bc9738..9dfdf86 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -28,6 +28,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
  arm64-obj-$(CONFIG_AARCH32_EL0)   += sys32.o kuser32.o signal32.o 
\
   sys_compat.o entry32.o   
\
   ../../arm/kernel/opcodes.o 
binfmt_elf32.o
+arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o
  arm64-obj-$(CONFIG_FUNCTION_TRACER)   += ftrace.o entry-ftrace.o
  arm64-obj-$(CONFIG_MODULES)   += arm64ksyms.o module.o
  arm64-obj-$(CONFIG_ARM64_MODULE_PLTS) += module-plts.o
diff --git a/arch/arm64/kernel/binfmt_ilp32.c b/arch/arm64/kernel/binfmt_ilp32.c
new file mode 100644
index 000..a934fd4
--- /dev/null
+++ b/arch/arm64/kernel/binfmt_ilp32.c
@@ -0,0 +1,91 @@
+/*
+ * Support for ILP32 Linux/aarch64 ELF binaries.
+ */
+
+#include 
+#include 
+
+#undef ELF_CLASS
+#define ELF_CLASS  ELFCLASS32
+
+#undef elfhdr
+#undef elf_phdr
+#undef elf_shdr
+#undef elf_note
+#undef elf_addr_t
+#define elfhdr elf32_hdr
+#define elf_phdr   elf32_phdr
+#define elf_shdr   elf32_shdr
+#define elf_note   elf32_note
+#define elf_addr_t Elf32_Addr
+
+/*
+ * Some data types as stored in coredump.
+ */
+#define user_long_tcompat_long_t
+#define user_siginfo_t compat_siginfo_t
+#define copy_siginfo_to_user   copy_siginfo_to_user32
+
+/*
+ * The machine-dependent core note format types are defined in 
elfcore-compat.h,
+ * which requires asm/elf.h to define compat_elf_gregset_t et al.
+ */
+#define elf_prstatus   compat_elf_prstatus
+#define elf_prpsinfo   compat_elf_prpsinfo
+
+/*
+ * Compat version of cputime_to_compat_timeval, perhaps this
+ * should be an inline in .
+ */
+static void cputime_to_compat_timeval(const cputime_t cputime,
+ struct compat_timeval *value)
+{
+   struct timeval tv;
+   cputime_to_timeval(cputime, );
+   value->tv_sec = tv.tv_sec;
+   value->tv_usec = tv.tv_usec;
+}
+
+#undef cputime_to_timeval
+#define cputime_to_timeval cputime_to_compat_timeval
+
+/* AARCH64 ILP32 EABI. */
+#undef elf_check_arch
+#define elf_check_arch(x)  (((x)->e_machine == EM_AARCH64)  \
+   && (x)->e_ident[EI_CLASS] == ELFCLASS32)
+
+#undef SET_PERSONALITY
+#define SET_PERSONALITY(ex)\
+do {   \
+   set_thread_flag(TIF_32BIT_AARCH64); \
+   clear_thread_flag(TIF_32BIT);   \
+} while (0)
+
+#undef ARCH_DLINFO
+#define ARCH_DLINFO\
+do {   \
+   NEW_AUX_ENT(AT_SYSINFO_EHDR,\
+   (elf_addr_t)(long)current->mm->context.vdso); \
+} while (0)
+
+#ifdef __AARCH64EB__
+#define COMPAT_ELF_PLATFORM("aarch64_be:ilp32")
+#else
+#define COMPAT_ELF_PLATFORM("aarch64:ilp32")
+#endif

fs/binfmt_elf.c use ELF_PLATFORM instead of the COMPAT one. Should we define
ELF_PLATFORM directly?
#undef ELF_PLATFORM
#ifdef __AARCH64EB__
#define ELF_PLATFORM("aarch64_be:ilp32")
#else
#define ELF_PLATFORM("aarch64:ilp32")
#endif

Regards

Bamvor

+
+#undef ELF_HWCAP
+#undef ELF_HWCAP2
+#define ELF_HWCAP  ((u32) elf_hwcap)
+#define ELF_HWCAP2 ((u32) (elf_hwcap >> 32))
+
+/*
+ * Rename a few of the symbols that binfmt_elf.c will define.
+ * These are all local so the names don't really matter, but it
+ * might make some debugging less confusing not to duplicate them.
+ */
+#define elf_format compat_elf_format
+#define init_elf_binfmtinit_compat_elf_binfmt
+#define exit_elf_binfmtexit_compat_elf_binfmt
+
+#include "../../../fs/binfmt_elf.c"





Re: [PATCH 21/23] arm64: ilp32: introduce ilp32-specific handlers for sigframe and ucontext

2016-06-12 Thread Zhangjian (Bamvor)

Hi,

On 2016/6/4 19:34, Zhangjian (Bamvor) wrote:

Hi,

I found an issue of unwind with the following code. The correct backtrace
should be:
(gdb) where
#0 0x004004d0 in my_sig (sig=11) at test_force3.c:16
#1 
#2 func2 (num=0) at test_force3.c:22
#3 0x00400540 in func1 (num=1) at test_force3.c:28
#4 0x00400574 in main (argc=1, argv=0xffd7bc04) at test_force3.c:33

Without my patch, the backtrace is:
(gdb) where
#0 0x00400490 in my_sig (sig=11) at test_force3.c:16
#1 
#2 0x004004e4 in main (argc=1, argv=0xffe6f8f4) at test_force3.c:33

With my patch which fix the wrong frame pointer(setup_return calculate the 
offset
of fp through ilp32_sigframe instead of sigfreame), the backtrace is:
(gdb) where
#0 0x00400490 in my_sig (sig=11) at test_force3.c:16
#1 
#2 func1 () at test_force3.c:28
#3 0x004004e4 in main (argc=1, argv=0xffe6f8f4) at test_force3.c:33

I am not sure there is still some issue in kernel. But it seem that the gdb of 
ilp32
does not work correctly when unwind without framepointer.

I confirm that the reason why gdb could not unwind the func2 is gdb do not get 
the
correct offset of uc_mcontext.
And it seems that the kernel part is a reasonable fix for me.

Regards

Bamvor


The test code is:

#include 
#include 
#include 
#include 

void my_sig(int sig)
{
 printf("sig=%d\n", sig);
 *(int *)0 = 0x0;
}


void func2()
{
 *(int *)0 = 0x0;
}

void func1()
{
 func2();
}

int main(int argc, char **argv)
{
 signal(11, my_sig);
 func1();
 return 0;
}


The full patch is as follows:

 From 7e364a765097f57aed2d73f94c1688c2e7343e79 Mon Sep 17 00:00:00 2001
From: Bamvor Jian Zhang <bamvor.zhangj...@huawei.com>
Date: Sat, 4 Jun 2016 14:30:05 +0800
Subject: [PATCH] arm64: ilp32: fix for wrong fp offset when calculate the
  new fp

ILP32 define its own sigframe(ilp32_sigframe) because of the
difference uc_context. setup_return do not use ilp32 specific
sigframe to calculate the new offset of fp which lead to wrong
fp in signal handler. At this circumstance, gdb backtrace will miss
one item:
(gdb) where

It should be:
(gdb) where

The test code is as follows:

void my_sig(int sig)
{
 printf("sig=%d\n", sig);
 *(int *)0 = 0x0;
}

void func2(int num)
{
 printf("%s: %d\n", __FUNCTION__, num);
 *(int *)0 = 0x0;
 func2(num-1);
}

void func1(int num)
{
 printf("%s\n", __FUNCTION__);
 func2(num - 1);
}

int main(int argc, char **argv)
{
 signal(11, my_sig);
 func1(argc);
 return 0;
}

This patch fix this by passing the correct offset of fp to
setup_return.
Test pass on both ILP32 and LP64 in aarch64 EE.

Signed-off-by: Bamvor Jian Zhang <bamvor.zhangj...@huawei.com>
---
  arch/arm64/include/asm/signal_common.h | 3 ++-
  arch/arm64/kernel/signal.c | 9 +
  arch/arm64/kernel/signal_ilp32.c   | 4 ++--
  3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/arch/arm64/include/asm/signal_common.h 
b/arch/arm64/include/asm/signal_common.h
index de93c71..a5d7b63 100644
--- a/arch/arm64/include/asm/signal_common.h
+++ b/arch/arm64/include/asm/signal_common.h
@@ -29,6 +29,7 @@ int setup_sigcontex(struct sigcontext __user *uc_mcontext,
  struct pt_regs *regs);
  int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sf);
  void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
-void __user *frame, off_t sigframe_off, int usig);
+void __user *frame, off_t sigframe_off, off_t fp_off,
+int usig);

  #endif /* __ASM_SIGNAL_COMMON_H */
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
index 038bebe..e66a6e9 100644
--- a/arch/arm64/kernel/signal.c
+++ b/arch/arm64/kernel/signal.c
@@ -256,14 +256,14 @@ static struct rt_sigframe __user *get_sigframe(struct 
ksignal *ksig,
  }

  void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
- void __user *frame, off_t sigframe_off, int usig)
+ void __user *frame, off_t sigframe_off, off_t fp_off,
+ int usig)
  {
  __sigrestore_t sigtramp;

  regs->regs[0] = usig;
  regs->sp = (unsigned long)frame;
-regs->regs[29] = regs->sp + sigframe_off +
-offsetof(struct sigframe, fp);
+regs->regs[29] = regs->sp + sigframe_off + fp_off;
  regs->pc = (unsigned long)ka->sa.sa_handler;

  if (ka->sa.sa_flags & SA_RESTORER)
@@ -294,7 +294,8 @@ static int setup_rt_frame(int usig, struct ksignal *ksig, 
sigset_t *set,
  err |= setup_sigframe(>sig, regs, set);
  if (err == 0) {
  setup_return(regs, >ka, frame,
-offsetof(struct rt_sigframe, sig), usig);
+offsetof(struct rt_sigframe, sig),
+offsetof(struct sigframe, fp), usig);
  if (ksig->ka.sa.sa_flags & SA_SIGINFO) {
  err |= copy_siginfo_to_user(>info, >info);
  r

Re: [PATCH 21/23] arm64: ilp32: introduce ilp32-specific handlers for sigframe and ucontext

2016-06-12 Thread Zhangjian (Bamvor)

Hi,

On 2016/6/4 19:34, Zhangjian (Bamvor) wrote:

Hi,

I found an issue of unwind with the following code. The correct backtrace
should be:
(gdb) where
#0 0x004004d0 in my_sig (sig=11) at test_force3.c:16
#1 
#2 func2 (num=0) at test_force3.c:22
#3 0x00400540 in func1 (num=1) at test_force3.c:28
#4 0x00400574 in main (argc=1, argv=0xffd7bc04) at test_force3.c:33

Without my patch, the backtrace is:
(gdb) where
#0 0x00400490 in my_sig (sig=11) at test_force3.c:16
#1 
#2 0x004004e4 in main (argc=1, argv=0xffe6f8f4) at test_force3.c:33

With my patch which fix the wrong frame pointer(setup_return calculate the 
offset
of fp through ilp32_sigframe instead of sigfreame), the backtrace is:
(gdb) where
#0 0x00400490 in my_sig (sig=11) at test_force3.c:16
#1 
#2 func1 () at test_force3.c:28
#3 0x004004e4 in main (argc=1, argv=0xffe6f8f4) at test_force3.c:33

I am not sure there is still some issue in kernel. But it seem that the gdb of 
ilp32
does not work correctly when unwind without framepointer.

I confirm that the reason why gdb could not unwind the func2 is gdb do not get 
the
correct offset of uc_mcontext.
And it seems that the kernel part is a reasonable fix for me.

Regards

Bamvor


The test code is:

#include 
#include 
#include 
#include 

void my_sig(int sig)
{
 printf("sig=%d\n", sig);
 *(int *)0 = 0x0;
}


void func2()
{
 *(int *)0 = 0x0;
}

void func1()
{
 func2();
}

int main(int argc, char **argv)
{
 signal(11, my_sig);
 func1();
 return 0;
}


The full patch is as follows:

 From 7e364a765097f57aed2d73f94c1688c2e7343e79 Mon Sep 17 00:00:00 2001
From: Bamvor Jian Zhang 
Date: Sat, 4 Jun 2016 14:30:05 +0800
Subject: [PATCH] arm64: ilp32: fix for wrong fp offset when calculate the
  new fp

ILP32 define its own sigframe(ilp32_sigframe) because of the
difference uc_context. setup_return do not use ilp32 specific
sigframe to calculate the new offset of fp which lead to wrong
fp in signal handler. At this circumstance, gdb backtrace will miss
one item:
(gdb) where

It should be:
(gdb) where

The test code is as follows:

void my_sig(int sig)
{
 printf("sig=%d\n", sig);
 *(int *)0 = 0x0;
}

void func2(int num)
{
 printf("%s: %d\n", __FUNCTION__, num);
 *(int *)0 = 0x0;
 func2(num-1);
}

void func1(int num)
{
 printf("%s\n", __FUNCTION__);
 func2(num - 1);
}

int main(int argc, char **argv)
{
 signal(11, my_sig);
 func1(argc);
 return 0;
}

This patch fix this by passing the correct offset of fp to
setup_return.
Test pass on both ILP32 and LP64 in aarch64 EE.

Signed-off-by: Bamvor Jian Zhang 
---
  arch/arm64/include/asm/signal_common.h | 3 ++-
  arch/arm64/kernel/signal.c | 9 +
  arch/arm64/kernel/signal_ilp32.c   | 4 ++--
  3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/arch/arm64/include/asm/signal_common.h 
b/arch/arm64/include/asm/signal_common.h
index de93c71..a5d7b63 100644
--- a/arch/arm64/include/asm/signal_common.h
+++ b/arch/arm64/include/asm/signal_common.h
@@ -29,6 +29,7 @@ int setup_sigcontex(struct sigcontext __user *uc_mcontext,
  struct pt_regs *regs);
  int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sf);
  void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
-void __user *frame, off_t sigframe_off, int usig);
+void __user *frame, off_t sigframe_off, off_t fp_off,
+int usig);

  #endif /* __ASM_SIGNAL_COMMON_H */
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
index 038bebe..e66a6e9 100644
--- a/arch/arm64/kernel/signal.c
+++ b/arch/arm64/kernel/signal.c
@@ -256,14 +256,14 @@ static struct rt_sigframe __user *get_sigframe(struct 
ksignal *ksig,
  }

  void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
- void __user *frame, off_t sigframe_off, int usig)
+ void __user *frame, off_t sigframe_off, off_t fp_off,
+ int usig)
  {
  __sigrestore_t sigtramp;

  regs->regs[0] = usig;
  regs->sp = (unsigned long)frame;
-regs->regs[29] = regs->sp + sigframe_off +
-offsetof(struct sigframe, fp);
+regs->regs[29] = regs->sp + sigframe_off + fp_off;
  regs->pc = (unsigned long)ka->sa.sa_handler;

  if (ka->sa.sa_flags & SA_RESTORER)
@@ -294,7 +294,8 @@ static int setup_rt_frame(int usig, struct ksignal *ksig, 
sigset_t *set,
  err |= setup_sigframe(>sig, regs, set);
  if (err == 0) {
  setup_return(regs, >ka, frame,
-offsetof(struct rt_sigframe, sig), usig);
+offsetof(struct rt_sigframe, sig),
+offsetof(struct sigframe, fp), usig);
  if (ksig->ka.sa.sa_flags & SA_SIGINFO) {
  err |= copy_siginfo_to_user(>info, >info);
  regs->regs[1] = (unsigned long)>info;
diff --git a/arch/arm64/kernel/

Re: [PATCH 13/23] arm64: introduce is_a32_task and is_a32_thread (for AArch32 compat)

2016-06-12 Thread Zhangjian (Bamvor)



On 2016/6/12 20:21, Zhangjian (Bamvor) wrote:

Hi, Yury

On 2016/5/24 8:04, Yury Norov wrote:

Based on patch of Andrew Pinski.

This patch introduces is_a32_compat_task and is_a32_thread so it is
easier to say this is a a32 specific thread or a generic compat thread/task.
Corresponding functions are located in  to avoid mess in
headers.

Some files include both  and ,
and this is wrong because  has  already
included. It was fixed too.

Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
Signed-off-by: Philipp Tomsich <philipp.toms...@theobroma-systems.com>
Signed-off-by: Christoph Muellner <christoph.muell...@theobroma-systems.com>
Signed-off-by: Andrew Pinski <andrew.pin...@caviumnetworks.com>
Reviewed-by: David Daney <dda...@caviumnetworks.com>
---
  arch/arm64/include/asm/compat.h  | 19 ++--
  arch/arm64/include/asm/elf.h | 10 +++
  arch/arm64/include/asm/ftrace.h  |  2 +-
  arch/arm64/include/asm/is_compat.h   | 58 
  arch/arm64/include/asm/memory.h  |  3 +-
  arch/arm64/include/asm/processor.h   |  5 ++--
  arch/arm64/include/asm/syscall.h |  2 +-
  arch/arm64/include/asm/thread_info.h |  2 +-
  arch/arm64/kernel/hw_breakpoint.c| 10 +++
  arch/arm64/kernel/perf_regs.c|  2 +-
  arch/arm64/kernel/process.c  |  7 ++---
  arch/arm64/kernel/ptrace.c   | 11 ---
  arch/arm64/kernel/signal.c   |  4 +--
  arch/arm64/kernel/traps.c|  3 +-
  14 files changed, 91 insertions(+), 47 deletions(-)
  create mode 100644 arch/arm64/include/asm/is_compat.h


[...]

diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h
index 12f8a00..a66a0f7 100644
--- a/arch/arm64/include/asm/memory.h
+++ b/arch/arm64/include/asm/memory.h
@@ -26,6 +26,7 @@
  #include 
  #include 
  #include 
+#include 

  /*
   * Allow for constants defined here to be used from assembly code
@@ -61,7 +62,7 @@

  #ifdef CONFIG_COMPAT
  #define TASK_SIZE_32UL(0x1)
-#define TASK_SIZE(test_thread_flag(TIF_32BIT) ? \
+#define TASK_SIZE(is_compat_task() ?\
  TASK_SIZE_32 : TASK_SIZE_64)
  #define TASK_SIZE_OF(tsk)(test_tsk_thread_flag(tsk, TIF_32BIT) ? \
  TASK_SIZE_32 : TASK_SIZE_64)

Should we update or delete this macro?
  #define TASK_SIZE_OF(tsk) (is_compat_task() ? \
TASK_SIZE_32 : TASK_SIZE_64)

Sorry it should be:
#define TASK_SIZE_OF(tsk)   ((is_a32_compat_thread(task_thread_info(tsk)) \
  || 
is_ilp32_compat_thread(task_thread_info(tsk))) ? \
TASK_SIZE_32 : TASK_SIZE_64)


x86, sparc, mips, ppc, parisc, s390 define its own version. But
"include/linux/sched.h" will define it if
TASK_SIZE_OF does not exist:
#ifndef TASK_SIZE_OF
#define TASK_SIZE_OF(tsk)   TASK_SIZE
#endif


Regards

Bamvor





Re: [PATCH 13/23] arm64: introduce is_a32_task and is_a32_thread (for AArch32 compat)

2016-06-12 Thread Zhangjian (Bamvor)



On 2016/6/12 20:21, Zhangjian (Bamvor) wrote:

Hi, Yury

On 2016/5/24 8:04, Yury Norov wrote:

Based on patch of Andrew Pinski.

This patch introduces is_a32_compat_task and is_a32_thread so it is
easier to say this is a a32 specific thread or a generic compat thread/task.
Corresponding functions are located in  to avoid mess in
headers.

Some files include both  and ,
and this is wrong because  has  already
included. It was fixed too.

Signed-off-by: Yury Norov 
Signed-off-by: Philipp Tomsich 
Signed-off-by: Christoph Muellner 
Signed-off-by: Andrew Pinski 
Reviewed-by: David Daney 
---
  arch/arm64/include/asm/compat.h  | 19 ++--
  arch/arm64/include/asm/elf.h | 10 +++
  arch/arm64/include/asm/ftrace.h  |  2 +-
  arch/arm64/include/asm/is_compat.h   | 58 
  arch/arm64/include/asm/memory.h  |  3 +-
  arch/arm64/include/asm/processor.h   |  5 ++--
  arch/arm64/include/asm/syscall.h |  2 +-
  arch/arm64/include/asm/thread_info.h |  2 +-
  arch/arm64/kernel/hw_breakpoint.c| 10 +++
  arch/arm64/kernel/perf_regs.c|  2 +-
  arch/arm64/kernel/process.c  |  7 ++---
  arch/arm64/kernel/ptrace.c   | 11 ---
  arch/arm64/kernel/signal.c   |  4 +--
  arch/arm64/kernel/traps.c|  3 +-
  14 files changed, 91 insertions(+), 47 deletions(-)
  create mode 100644 arch/arm64/include/asm/is_compat.h


[...]

diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h
index 12f8a00..a66a0f7 100644
--- a/arch/arm64/include/asm/memory.h
+++ b/arch/arm64/include/asm/memory.h
@@ -26,6 +26,7 @@
  #include 
  #include 
  #include 
+#include 

  /*
   * Allow for constants defined here to be used from assembly code
@@ -61,7 +62,7 @@

  #ifdef CONFIG_COMPAT
  #define TASK_SIZE_32UL(0x1)
-#define TASK_SIZE(test_thread_flag(TIF_32BIT) ? \
+#define TASK_SIZE(is_compat_task() ?\
  TASK_SIZE_32 : TASK_SIZE_64)
  #define TASK_SIZE_OF(tsk)(test_tsk_thread_flag(tsk, TIF_32BIT) ? \
  TASK_SIZE_32 : TASK_SIZE_64)

Should we update or delete this macro?
  #define TASK_SIZE_OF(tsk) (is_compat_task() ? \
TASK_SIZE_32 : TASK_SIZE_64)

Sorry it should be:
#define TASK_SIZE_OF(tsk)   ((is_a32_compat_thread(task_thread_info(tsk)) \
  || 
is_ilp32_compat_thread(task_thread_info(tsk))) ? \
TASK_SIZE_32 : TASK_SIZE_64)


x86, sparc, mips, ppc, parisc, s390 define its own version. But
"include/linux/sched.h" will define it if
TASK_SIZE_OF does not exist:
#ifndef TASK_SIZE_OF
#define TASK_SIZE_OF(tsk)   TASK_SIZE
#endif


Regards

Bamvor





Re: [PATCH 21/23] arm64: ilp32: introduce ilp32-specific handlers for sigframe and ucontext

2016-06-12 Thread Zhangjian (Bamvor)

Hi, Yury


Here is another print issue in this patch:

On 2016/5/24 8:04, Yury Norov wrote:

From: Andrew Pinski 

ILP32 uses AARCH32 compat structures and syscall handlers for signals.
But ILP32 struct rt_sigframe  and ucontext differs from both LP64 and
AARCH32. So some specific mechanism is needed to take care of it.


[...]

diff --git a/arch/arm64/kernel/signal_ilp32.c b/arch/arm64/kernel/signal_ilp32.c
new file mode 100644
index 000..841e8f8
--- /dev/null
+++ b/arch/arm64/kernel/signal_ilp32.c
@@ -0,0 +1,192 @@
+/*

[...]

+asmlinkage long ilp32_sys_rt_sigreturn(struct pt_regs *regs)
+{
+   struct ilp32_rt_sigframe __user *frame;
+
+   /* Always make any pending restarted system calls return -EINTR */
+   current->restart_block.fn = do_no_restart_syscall;
+
+   /*
+* Since we stacked the signal on a 128-bit boundary,
+* then 'sp' should be word aligned here.  If it's
+* not, then the user is trying to mess with us.
+*/
+   if (regs->sp & 15)
+   goto badframe;
+
+   frame = (struct ilp32_rt_sigframe __user *)regs->sp;
+
+   if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
+   goto badframe;
+
+   if (restore_ilp32_sigframe(regs, >sig))
+   goto badframe;
+
+   if (compat_restore_altstack(>sig.uc.uc_stack))
+   goto badframe;
+
+   return regs->regs[0];
+
+badframe:
+   if (show_unhandled_signals)
+   pr_info_ratelimited("%s[%d]: bad frame in %s: pc=%08llx 
sp=%08llx\n",
+   current->comm, task_pid_nr(current), 
__func__,
+   regs->pc, regs->compat_sp);

It should be sp instead of compat_sp. The latter one is used by aarch32 EE.

Regards

Bamvor

+   force_sig(SIGSEGV, current);
+   return 0;
+}
+




Re: [PATCH 21/23] arm64: ilp32: introduce ilp32-specific handlers for sigframe and ucontext

2016-06-12 Thread Zhangjian (Bamvor)

Hi, Yury


Here is another print issue in this patch:

On 2016/5/24 8:04, Yury Norov wrote:

From: Andrew Pinski 

ILP32 uses AARCH32 compat structures and syscall handlers for signals.
But ILP32 struct rt_sigframe  and ucontext differs from both LP64 and
AARCH32. So some specific mechanism is needed to take care of it.


[...]

diff --git a/arch/arm64/kernel/signal_ilp32.c b/arch/arm64/kernel/signal_ilp32.c
new file mode 100644
index 000..841e8f8
--- /dev/null
+++ b/arch/arm64/kernel/signal_ilp32.c
@@ -0,0 +1,192 @@
+/*

[...]

+asmlinkage long ilp32_sys_rt_sigreturn(struct pt_regs *regs)
+{
+   struct ilp32_rt_sigframe __user *frame;
+
+   /* Always make any pending restarted system calls return -EINTR */
+   current->restart_block.fn = do_no_restart_syscall;
+
+   /*
+* Since we stacked the signal on a 128-bit boundary,
+* then 'sp' should be word aligned here.  If it's
+* not, then the user is trying to mess with us.
+*/
+   if (regs->sp & 15)
+   goto badframe;
+
+   frame = (struct ilp32_rt_sigframe __user *)regs->sp;
+
+   if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
+   goto badframe;
+
+   if (restore_ilp32_sigframe(regs, >sig))
+   goto badframe;
+
+   if (compat_restore_altstack(>sig.uc.uc_stack))
+   goto badframe;
+
+   return regs->regs[0];
+
+badframe:
+   if (show_unhandled_signals)
+   pr_info_ratelimited("%s[%d]: bad frame in %s: pc=%08llx 
sp=%08llx\n",
+   current->comm, task_pid_nr(current), 
__func__,
+   regs->pc, regs->compat_sp);

It should be sp instead of compat_sp. The latter one is used by aarch32 EE.

Regards

Bamvor

+   force_sig(SIGSEGV, current);
+   return 0;
+}
+




Re: [PATCH 21/23] arm64: ilp32: introduce ilp32-specific handlers for sigframe and ucontext

2016-06-12 Thread Zhangjian (Bamvor)

ping

On 2016/6/4 19:34, Zhangjian (Bamvor) wrote:

Hi,

I found an issue of unwind with the following code. The correct backtrace
should be:
(gdb) where
#0 0x004004d0 in my_sig (sig=11) at test_force3.c:16
#1 
#2 func2 (num=0) at test_force3.c:22
#3 0x00400540 in func1 (num=1) at test_force3.c:28
#4 0x00400574 in main (argc=1, argv=0xffd7bc04) at test_force3.c:33

Without my patch, the backtrace is:
(gdb) where
#0 0x00400490 in my_sig (sig=11) at test_force3.c:16
#1 
#2 0x004004e4 in main (argc=1, argv=0xffe6f8f4) at test_force3.c:33

With my patch which fix the wrong frame pointer(setup_return calculate the 
offset
of fp through ilp32_sigframe instead of sigfreame), the backtrace is:
(gdb) where
#0 0x00400490 in my_sig (sig=11) at test_force3.c:16
#1 
#2 func1 () at test_force3.c:28
#3 0x004004e4 in main (argc=1, argv=0xffe6f8f4) at test_force3.c:33

I am not sure there is still some issue in kernel. But it seem that the gdb of 
ilp32
does not work correctly when unwind without framepointer.

The test code is:

#include 
#include 
#include 
#include 

void my_sig(int sig)
{
 printf("sig=%d\n", sig);
 *(int *)0 = 0x0;
}


void func2()
{
 *(int *)0 = 0x0;
}

void func1()
{
 func2();
}

int main(int argc, char **argv)
{
 signal(11, my_sig);
 func1();
 return 0;
}


The full patch is as follows:

 From 7e364a765097f57aed2d73f94c1688c2e7343e79 Mon Sep 17 00:00:00 2001
From: Bamvor Jian Zhang <bamvor.zhangj...@huawei.com>
Date: Sat, 4 Jun 2016 14:30:05 +0800
Subject: [PATCH] arm64: ilp32: fix for wrong fp offset when calculate the
  new fp

ILP32 define its own sigframe(ilp32_sigframe) because of the
difference uc_context. setup_return do not use ilp32 specific
sigframe to calculate the new offset of fp which lead to wrong
fp in signal handler. At this circumstance, gdb backtrace will miss
one item:
(gdb) where

It should be:
(gdb) where

The test code is as follows:

void my_sig(int sig)
{
 printf("sig=%d\n", sig);
 *(int *)0 = 0x0;
}

void func2(int num)
{
 printf("%s: %d\n", __FUNCTION__, num);
 *(int *)0 = 0x0;
 func2(num-1);
}

void func1(int num)
{
 printf("%s\n", __FUNCTION__);
 func2(num - 1);
}

int main(int argc, char **argv)
{
 signal(11, my_sig);
 func1(argc);
 return 0;
}

This patch fix this by passing the correct offset of fp to
setup_return.
Test pass on both ILP32 and LP64 in aarch64 EE.

Signed-off-by: Bamvor Jian Zhang <bamvor.zhangj...@huawei.com>
---
  arch/arm64/include/asm/signal_common.h | 3 ++-
  arch/arm64/kernel/signal.c | 9 +
  arch/arm64/kernel/signal_ilp32.c   | 4 ++--
  3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/arch/arm64/include/asm/signal_common.h 
b/arch/arm64/include/asm/signal_common.h
index de93c71..a5d7b63 100644
--- a/arch/arm64/include/asm/signal_common.h
+++ b/arch/arm64/include/asm/signal_common.h
@@ -29,6 +29,7 @@ int setup_sigcontex(struct sigcontext __user *uc_mcontext,
  struct pt_regs *regs);
  int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sf);
  void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
-void __user *frame, off_t sigframe_off, int usig);
+void __user *frame, off_t sigframe_off, off_t fp_off,
+int usig);

  #endif /* __ASM_SIGNAL_COMMON_H */
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
index 038bebe..e66a6e9 100644
--- a/arch/arm64/kernel/signal.c
+++ b/arch/arm64/kernel/signal.c
@@ -256,14 +256,14 @@ static struct rt_sigframe __user *get_sigframe(struct 
ksignal *ksig,
  }

  void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
- void __user *frame, off_t sigframe_off, int usig)
+ void __user *frame, off_t sigframe_off, off_t fp_off,
+ int usig)
  {
  __sigrestore_t sigtramp;

  regs->regs[0] = usig;
  regs->sp = (unsigned long)frame;
-regs->regs[29] = regs->sp + sigframe_off +
-offsetof(struct sigframe, fp);
+regs->regs[29] = regs->sp + sigframe_off + fp_off;
  regs->pc = (unsigned long)ka->sa.sa_handler;

  if (ka->sa.sa_flags & SA_RESTORER)
@@ -294,7 +294,8 @@ static int setup_rt_frame(int usig, struct ksignal *ksig, 
sigset_t *set,
  err |= setup_sigframe(>sig, regs, set);
  if (err == 0) {
  setup_return(regs, >ka, frame,
-offsetof(struct rt_sigframe, sig), usig);
+offsetof(struct rt_sigframe, sig),
+offsetof(struct sigframe, fp), usig);
  if (ksig->ka.sa.sa_flags & SA_SIGINFO) {
  err |= copy_siginfo_to_user(>info, >info);
  regs->regs[1] = (unsigned long)>info;
diff --git a/arch/arm64/kernel/signal_ilp32.c b/arch/arm64/kernel/signal_ilp32.c
index a8ea73e..9030f14 100644
--- a/arch/arm64/kernel/sign

Re: [PATCH 21/23] arm64: ilp32: introduce ilp32-specific handlers for sigframe and ucontext

2016-06-12 Thread Zhangjian (Bamvor)

ping

On 2016/6/4 19:34, Zhangjian (Bamvor) wrote:

Hi,

I found an issue of unwind with the following code. The correct backtrace
should be:
(gdb) where
#0 0x004004d0 in my_sig (sig=11) at test_force3.c:16
#1 
#2 func2 (num=0) at test_force3.c:22
#3 0x00400540 in func1 (num=1) at test_force3.c:28
#4 0x00400574 in main (argc=1, argv=0xffd7bc04) at test_force3.c:33

Without my patch, the backtrace is:
(gdb) where
#0 0x00400490 in my_sig (sig=11) at test_force3.c:16
#1 
#2 0x004004e4 in main (argc=1, argv=0xffe6f8f4) at test_force3.c:33

With my patch which fix the wrong frame pointer(setup_return calculate the 
offset
of fp through ilp32_sigframe instead of sigfreame), the backtrace is:
(gdb) where
#0 0x00400490 in my_sig (sig=11) at test_force3.c:16
#1 
#2 func1 () at test_force3.c:28
#3 0x004004e4 in main (argc=1, argv=0xffe6f8f4) at test_force3.c:33

I am not sure there is still some issue in kernel. But it seem that the gdb of 
ilp32
does not work correctly when unwind without framepointer.

The test code is:

#include 
#include 
#include 
#include 

void my_sig(int sig)
{
 printf("sig=%d\n", sig);
 *(int *)0 = 0x0;
}


void func2()
{
 *(int *)0 = 0x0;
}

void func1()
{
 func2();
}

int main(int argc, char **argv)
{
 signal(11, my_sig);
 func1();
 return 0;
}


The full patch is as follows:

 From 7e364a765097f57aed2d73f94c1688c2e7343e79 Mon Sep 17 00:00:00 2001
From: Bamvor Jian Zhang 
Date: Sat, 4 Jun 2016 14:30:05 +0800
Subject: [PATCH] arm64: ilp32: fix for wrong fp offset when calculate the
  new fp

ILP32 define its own sigframe(ilp32_sigframe) because of the
difference uc_context. setup_return do not use ilp32 specific
sigframe to calculate the new offset of fp which lead to wrong
fp in signal handler. At this circumstance, gdb backtrace will miss
one item:
(gdb) where

It should be:
(gdb) where

The test code is as follows:

void my_sig(int sig)
{
 printf("sig=%d\n", sig);
 *(int *)0 = 0x0;
}

void func2(int num)
{
 printf("%s: %d\n", __FUNCTION__, num);
 *(int *)0 = 0x0;
 func2(num-1);
}

void func1(int num)
{
 printf("%s\n", __FUNCTION__);
 func2(num - 1);
}

int main(int argc, char **argv)
{
 signal(11, my_sig);
 func1(argc);
 return 0;
}

This patch fix this by passing the correct offset of fp to
setup_return.
Test pass on both ILP32 and LP64 in aarch64 EE.

Signed-off-by: Bamvor Jian Zhang 
---
  arch/arm64/include/asm/signal_common.h | 3 ++-
  arch/arm64/kernel/signal.c | 9 +
  arch/arm64/kernel/signal_ilp32.c   | 4 ++--
  3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/arch/arm64/include/asm/signal_common.h 
b/arch/arm64/include/asm/signal_common.h
index de93c71..a5d7b63 100644
--- a/arch/arm64/include/asm/signal_common.h
+++ b/arch/arm64/include/asm/signal_common.h
@@ -29,6 +29,7 @@ int setup_sigcontex(struct sigcontext __user *uc_mcontext,
  struct pt_regs *regs);
  int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sf);
  void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
-void __user *frame, off_t sigframe_off, int usig);
+void __user *frame, off_t sigframe_off, off_t fp_off,
+int usig);

  #endif /* __ASM_SIGNAL_COMMON_H */
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
index 038bebe..e66a6e9 100644
--- a/arch/arm64/kernel/signal.c
+++ b/arch/arm64/kernel/signal.c
@@ -256,14 +256,14 @@ static struct rt_sigframe __user *get_sigframe(struct 
ksignal *ksig,
  }

  void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
- void __user *frame, off_t sigframe_off, int usig)
+ void __user *frame, off_t sigframe_off, off_t fp_off,
+ int usig)
  {
  __sigrestore_t sigtramp;

  regs->regs[0] = usig;
  regs->sp = (unsigned long)frame;
-regs->regs[29] = regs->sp + sigframe_off +
-offsetof(struct sigframe, fp);
+regs->regs[29] = regs->sp + sigframe_off + fp_off;
  regs->pc = (unsigned long)ka->sa.sa_handler;

  if (ka->sa.sa_flags & SA_RESTORER)
@@ -294,7 +294,8 @@ static int setup_rt_frame(int usig, struct ksignal *ksig, 
sigset_t *set,
  err |= setup_sigframe(>sig, regs, set);
  if (err == 0) {
  setup_return(regs, >ka, frame,
-offsetof(struct rt_sigframe, sig), usig);
+offsetof(struct rt_sigframe, sig),
+offsetof(struct sigframe, fp), usig);
  if (ksig->ka.sa.sa_flags & SA_SIGINFO) {
  err |= copy_siginfo_to_user(>info, >info);
  regs->regs[1] = (unsigned long)>info;
diff --git a/arch/arm64/kernel/signal_ilp32.c b/arch/arm64/kernel/signal_ilp32.c
index a8ea73e..9030f14 100644
--- a/arch/arm64/kernel/signal_ilp32.c
+++ b/arch/arm64/kernel/signal_ilp32.c
@@ -147,7 +147,6 @@ static struct il

Re: [PATCH 13/23] arm64: introduce is_a32_task and is_a32_thread (for AArch32 compat)

2016-06-12 Thread Zhangjian (Bamvor)

Hi, Yury

On 2016/5/24 8:04, Yury Norov wrote:

Based on patch of Andrew Pinski.

This patch introduces is_a32_compat_task and is_a32_thread so it is
easier to say this is a a32 specific thread or a generic compat thread/task.
Corresponding functions are located in  to avoid mess in
headers.

Some files include both  and ,
and this is wrong because  has  already
included. It was fixed too.

Signed-off-by: Yury Norov 
Signed-off-by: Philipp Tomsich 
Signed-off-by: Christoph Muellner 
Signed-off-by: Andrew Pinski 
Reviewed-by: David Daney 
---
  arch/arm64/include/asm/compat.h  | 19 ++--
  arch/arm64/include/asm/elf.h | 10 +++
  arch/arm64/include/asm/ftrace.h  |  2 +-
  arch/arm64/include/asm/is_compat.h   | 58 
  arch/arm64/include/asm/memory.h  |  3 +-
  arch/arm64/include/asm/processor.h   |  5 ++--
  arch/arm64/include/asm/syscall.h |  2 +-
  arch/arm64/include/asm/thread_info.h |  2 +-
  arch/arm64/kernel/hw_breakpoint.c| 10 +++
  arch/arm64/kernel/perf_regs.c|  2 +-
  arch/arm64/kernel/process.c  |  7 ++---
  arch/arm64/kernel/ptrace.c   | 11 ---
  arch/arm64/kernel/signal.c   |  4 +--
  arch/arm64/kernel/traps.c|  3 +-
  14 files changed, 91 insertions(+), 47 deletions(-)
  create mode 100644 arch/arm64/include/asm/is_compat.h


[...]

diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h
index 12f8a00..a66a0f7 100644
--- a/arch/arm64/include/asm/memory.h
+++ b/arch/arm64/include/asm/memory.h
@@ -26,6 +26,7 @@
  #include 
  #include 
  #include 
+#include 

  /*
   * Allow for constants defined here to be used from assembly code
@@ -61,7 +62,7 @@

  #ifdef CONFIG_COMPAT
  #define TASK_SIZE_32  UL(0x1)
-#define TASK_SIZE  (test_thread_flag(TIF_32BIT) ? \
+#define TASK_SIZE  (is_compat_task() ? \
TASK_SIZE_32 : TASK_SIZE_64)
  #define TASK_SIZE_OF(tsk) (test_tsk_thread_flag(tsk, TIF_32BIT) ? \
TASK_SIZE_32 : TASK_SIZE_64)

Should we update or delete this macro?
 #define TASK_SIZE_OF(tsk) (is_compat_task() ? \
TASK_SIZE_32 : TASK_SIZE_64)

x86, sparc, mips, ppc, parisc, s390 define its own version. But
"include/linux/sched.h" will define it if
TASK_SIZE_OF does not exist:
#ifndef TASK_SIZE_OF
#define TASK_SIZE_OF(tsk)   TASK_SIZE
#endif


Regards

Bamvor



Re: [PATCH 13/23] arm64: introduce is_a32_task and is_a32_thread (for AArch32 compat)

2016-06-12 Thread Zhangjian (Bamvor)

Hi, Yury

On 2016/5/24 8:04, Yury Norov wrote:

Based on patch of Andrew Pinski.

This patch introduces is_a32_compat_task and is_a32_thread so it is
easier to say this is a a32 specific thread or a generic compat thread/task.
Corresponding functions are located in  to avoid mess in
headers.

Some files include both  and ,
and this is wrong because  has  already
included. It was fixed too.

Signed-off-by: Yury Norov 
Signed-off-by: Philipp Tomsich 
Signed-off-by: Christoph Muellner 
Signed-off-by: Andrew Pinski 
Reviewed-by: David Daney 
---
  arch/arm64/include/asm/compat.h  | 19 ++--
  arch/arm64/include/asm/elf.h | 10 +++
  arch/arm64/include/asm/ftrace.h  |  2 +-
  arch/arm64/include/asm/is_compat.h   | 58 
  arch/arm64/include/asm/memory.h  |  3 +-
  arch/arm64/include/asm/processor.h   |  5 ++--
  arch/arm64/include/asm/syscall.h |  2 +-
  arch/arm64/include/asm/thread_info.h |  2 +-
  arch/arm64/kernel/hw_breakpoint.c| 10 +++
  arch/arm64/kernel/perf_regs.c|  2 +-
  arch/arm64/kernel/process.c  |  7 ++---
  arch/arm64/kernel/ptrace.c   | 11 ---
  arch/arm64/kernel/signal.c   |  4 +--
  arch/arm64/kernel/traps.c|  3 +-
  14 files changed, 91 insertions(+), 47 deletions(-)
  create mode 100644 arch/arm64/include/asm/is_compat.h


[...]

diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h
index 12f8a00..a66a0f7 100644
--- a/arch/arm64/include/asm/memory.h
+++ b/arch/arm64/include/asm/memory.h
@@ -26,6 +26,7 @@
  #include 
  #include 
  #include 
+#include 

  /*
   * Allow for constants defined here to be used from assembly code
@@ -61,7 +62,7 @@

  #ifdef CONFIG_COMPAT
  #define TASK_SIZE_32  UL(0x1)
-#define TASK_SIZE  (test_thread_flag(TIF_32BIT) ? \
+#define TASK_SIZE  (is_compat_task() ? \
TASK_SIZE_32 : TASK_SIZE_64)
  #define TASK_SIZE_OF(tsk) (test_tsk_thread_flag(tsk, TIF_32BIT) ? \
TASK_SIZE_32 : TASK_SIZE_64)

Should we update or delete this macro?
 #define TASK_SIZE_OF(tsk) (is_compat_task() ? \
TASK_SIZE_32 : TASK_SIZE_64)

x86, sparc, mips, ppc, parisc, s390 define its own version. But
"include/linux/sched.h" will define it if
TASK_SIZE_OF does not exist:
#ifndef TASK_SIZE_OF
#define TASK_SIZE_OF(tsk)   TASK_SIZE
#endif


Regards

Bamvor



Re: [RFC PATCH] sys_read: add a compat_sys_read for 64bit system

2016-06-08 Thread Zhangjian (Bamvor)

Hi, Peter

On 2016/6/8 15:33, H. Peter Anvin wrote:

On June 7, 2016 7:14:41 PM PDT, "Zhangjian (Bamvor)" 
<bamvor.zhangj...@huawei.com> wrote:

Hi,

On 2016/6/8 9:33, Weidong Wang wrote:

Test 32 progress and 64 progress on the 64bit system with
this progress:

int main(int argc, char **argv)
{
  int fd = 0;
  int i, ret = 0;
  char buf[512];
  unsigned long count = -1;

  fd = open("/tmp", O_RDONLY);
  if (fd < -1) {
  printf("Pls check the directory is exist?\n");
  return -1;
  }
  errno = 0;
  ret = read(fd, NULL, count);
  printf("Ret is %d errno %d\n", ret, errno);
  close(fd);

  return 0;
}

we get the different errno. The 64 progress we get errno is -14 while
the 32 progress is -21.

The reason is that, the user progress would use a 32bit count, while
the sys_read size_t in kernel is 64bit.  When the uesrspace count is
-1(0x), it goes to the sys_read, it would be change to a

positive

number.

So I think we should add a compat_sys_read for the read syscall. I

test it

on x86 or arm64 platform. The patch works well.

As weidong said, we tested on x86, x86_64, aarch64 ilp32, aarch64 lp64.
We do not familiar with other architecture, cc linux-api, hope could
get more
input.

Regards

Bamvor


As well this patch may do work for the 'tile' 64 system.
I think it may enter the same result on mips/parisc/powerpc/sparc.
The s390 do the compat_sys_s390_read for the compat sys_read.

Signed-off-by: Weidong Wang <wangweido...@huawei.com>
---
   arch/x86/entry/syscalls/syscall_32.tbl | 2 +-
   fs/read_write.c| 8 
   include/linux/compat.h | 2 ++
   include/uapi/asm-generic/unistd.h  | 2 +-
   4 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/arch/x86/entry/syscalls/syscall_32.tbl

b/arch/x86/entry/syscalls/syscall_32.tbl

index 4cddd17..ebc24e3 100644
--- a/arch/x86/entry/syscalls/syscall_32.tbl
+++ b/arch/x86/entry/syscalls/syscall_32.tbl
@@ -9,7 +9,7 @@
   0i386restart_syscall sys_restart_syscall
   1i386exitsys_exit
   2i386forksys_forksys_fork
-3  i386readsys_read
+3  i386readsys_read
compat_sys_read
   4i386write   sys_write
   5i386opensys_open
compat_sys_open
   6i386close   sys_close
diff --git a/fs/read_write.c b/fs/read_write.c
index 933b53a..d244848 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -613,6 +613,14 @@ SYSCALL_DEFINE3(write, unsigned int, fd, const

char __user *, buf,

return ret;
   }

+#ifdef CONFIG_COMPAT
+COMPAT_SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf,
+   compat_size_t, count)
+{
+return sys_read(fd, buf, (compat_ssize_t)count);
+}
+#endif
+
   SYSCALL_DEFINE4(pread64, unsigned int, fd, char __user *, buf,
size_t, count, loff_t, pos)
   {
diff --git a/include/linux/compat.h b/include/linux/compat.h
index f964ef7..d88ccad 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -332,6 +332,8 @@ asmlinkage long compat_sys_keyctl(u32 option,
  u32 arg2, u32 arg3, u32 arg4, u32 arg5);
   asmlinkage long compat_sys_ustat(unsigned dev, struct compat_ustat

__user *u32);


+asmlinkage ssize_t compat_sys_read(unsigned int fd,
+   char __user * buf, compat_size_t count);
   asmlinkage ssize_t compat_sys_readv(compat_ulong_t fd,
const struct compat_iovec __user *vec, compat_ulong_t vlen);
   asmlinkage ssize_t compat_sys_writev(compat_ulong_t fd,
diff --git a/include/uapi/asm-generic/unistd.h

b/include/uapi/asm-generic/unistd.h

index a26415b..745818a 100644
--- a/include/uapi/asm-generic/unistd.h
+++ b/include/uapi/asm-generic/unistd.h
@@ -201,7 +201,7 @@ __SC_COMP(__NR_getdents64, sys_getdents64,

compat_sys_getdents64)

   #define __NR3264_lseek 62
   __SC_3264(__NR3264_lseek, sys_llseek, sys_lseek)
   #define __NR_read 63
-__SYSCALL(__NR_read, sys_read)
+__SC_COMP(__NR_read, sys_read, compat_sys_read)
   #define __NR_write 64
   __SYSCALL(__NR_write, sys_write)
   #define __NR_readv 65



Does this cause any actual problems?  Also, it seems extremely unlikely read() 
would be the only system call so affected.

It do not cause any actual problems. And write may be affected too.
Without this patch, the errno is different when 32 application migrate
from 32bit kernel to 64bit kernel.

Regards

Bamvor







Re: [RFC PATCH] sys_read: add a compat_sys_read for 64bit system

2016-06-08 Thread Zhangjian (Bamvor)

Hi, Peter

On 2016/6/8 15:33, H. Peter Anvin wrote:

On June 7, 2016 7:14:41 PM PDT, "Zhangjian (Bamvor)" 
 wrote:

Hi,

On 2016/6/8 9:33, Weidong Wang wrote:

Test 32 progress and 64 progress on the 64bit system with
this progress:

int main(int argc, char **argv)
{
  int fd = 0;
  int i, ret = 0;
  char buf[512];
  unsigned long count = -1;

  fd = open("/tmp", O_RDONLY);
  if (fd < -1) {
  printf("Pls check the directory is exist?\n");
  return -1;
  }
  errno = 0;
  ret = read(fd, NULL, count);
  printf("Ret is %d errno %d\n", ret, errno);
  close(fd);

  return 0;
}

we get the different errno. The 64 progress we get errno is -14 while
the 32 progress is -21.

The reason is that, the user progress would use a 32bit count, while
the sys_read size_t in kernel is 64bit.  When the uesrspace count is
-1(0x), it goes to the sys_read, it would be change to a

positive

number.

So I think we should add a compat_sys_read for the read syscall. I

test it

on x86 or arm64 platform. The patch works well.

As weidong said, we tested on x86, x86_64, aarch64 ilp32, aarch64 lp64.
We do not familiar with other architecture, cc linux-api, hope could
get more
input.

Regards

Bamvor


As well this patch may do work for the 'tile' 64 system.
I think it may enter the same result on mips/parisc/powerpc/sparc.
The s390 do the compat_sys_s390_read for the compat sys_read.

Signed-off-by: Weidong Wang 
---
   arch/x86/entry/syscalls/syscall_32.tbl | 2 +-
   fs/read_write.c| 8 
   include/linux/compat.h | 2 ++
   include/uapi/asm-generic/unistd.h  | 2 +-
   4 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/arch/x86/entry/syscalls/syscall_32.tbl

b/arch/x86/entry/syscalls/syscall_32.tbl

index 4cddd17..ebc24e3 100644
--- a/arch/x86/entry/syscalls/syscall_32.tbl
+++ b/arch/x86/entry/syscalls/syscall_32.tbl
@@ -9,7 +9,7 @@
   0i386restart_syscall sys_restart_syscall
   1i386exitsys_exit
   2i386forksys_forksys_fork
-3  i386readsys_read
+3  i386readsys_read
compat_sys_read
   4i386write   sys_write
   5i386opensys_open
compat_sys_open
   6i386close   sys_close
diff --git a/fs/read_write.c b/fs/read_write.c
index 933b53a..d244848 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -613,6 +613,14 @@ SYSCALL_DEFINE3(write, unsigned int, fd, const

char __user *, buf,

return ret;
   }

+#ifdef CONFIG_COMPAT
+COMPAT_SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf,
+   compat_size_t, count)
+{
+return sys_read(fd, buf, (compat_ssize_t)count);
+}
+#endif
+
   SYSCALL_DEFINE4(pread64, unsigned int, fd, char __user *, buf,
size_t, count, loff_t, pos)
   {
diff --git a/include/linux/compat.h b/include/linux/compat.h
index f964ef7..d88ccad 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -332,6 +332,8 @@ asmlinkage long compat_sys_keyctl(u32 option,
  u32 arg2, u32 arg3, u32 arg4, u32 arg5);
   asmlinkage long compat_sys_ustat(unsigned dev, struct compat_ustat

__user *u32);


+asmlinkage ssize_t compat_sys_read(unsigned int fd,
+   char __user * buf, compat_size_t count);
   asmlinkage ssize_t compat_sys_readv(compat_ulong_t fd,
const struct compat_iovec __user *vec, compat_ulong_t vlen);
   asmlinkage ssize_t compat_sys_writev(compat_ulong_t fd,
diff --git a/include/uapi/asm-generic/unistd.h

b/include/uapi/asm-generic/unistd.h

index a26415b..745818a 100644
--- a/include/uapi/asm-generic/unistd.h
+++ b/include/uapi/asm-generic/unistd.h
@@ -201,7 +201,7 @@ __SC_COMP(__NR_getdents64, sys_getdents64,

compat_sys_getdents64)

   #define __NR3264_lseek 62
   __SC_3264(__NR3264_lseek, sys_llseek, sys_lseek)
   #define __NR_read 63
-__SYSCALL(__NR_read, sys_read)
+__SC_COMP(__NR_read, sys_read, compat_sys_read)
   #define __NR_write 64
   __SYSCALL(__NR_write, sys_write)
   #define __NR_readv 65



Does this cause any actual problems?  Also, it seems extremely unlikely read() 
would be the only system call so affected.

It do not cause any actual problems. And write may be affected too.
Without this patch, the errno is different when 32 application migrate
from 32bit kernel to 64bit kernel.

Regards

Bamvor







Re: [RFC PATCH] sys_read: add a compat_sys_read for 64bit system

2016-06-07 Thread Zhangjian (Bamvor)

Hi,

On 2016/6/8 9:33, Weidong Wang wrote:

Test 32 progress and 64 progress on the 64bit system with
this progress:

int main(int argc, char **argv)
{
 int fd = 0;
 int i, ret = 0;
 char buf[512];
 unsigned long count = -1;

 fd = open("/tmp", O_RDONLY);
 if (fd < -1) {
 printf("Pls check the directory is exist?\n");
 return -1;
 }
 errno = 0;
 ret = read(fd, NULL, count);
 printf("Ret is %d errno %d\n", ret, errno);
 close(fd);

 return 0;
}

we get the different errno. The 64 progress we get errno is -14 while
the 32 progress is -21.

The reason is that, the user progress would use a 32bit count, while
the sys_read size_t in kernel is 64bit.  When the uesrspace count is
-1(0x), it goes to the sys_read, it would be change to a positive
number.

So I think we should add a compat_sys_read for the read syscall. I test it
on x86 or arm64 platform. The patch works well.

As weidong said, we tested on x86, x86_64, aarch64 ilp32, aarch64 lp64.
We do not familiar with other architecture, cc linux-api, hope could get more
input.

Regards

Bamvor


As well this patch may do work for the 'tile' 64 system.
I think it may enter the same result on mips/parisc/powerpc/sparc.
The s390 do the compat_sys_s390_read for the compat sys_read.

Signed-off-by: Weidong Wang 
---
  arch/x86/entry/syscalls/syscall_32.tbl | 2 +-
  fs/read_write.c| 8 
  include/linux/compat.h | 2 ++
  include/uapi/asm-generic/unistd.h  | 2 +-
  4 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/arch/x86/entry/syscalls/syscall_32.tbl 
b/arch/x86/entry/syscalls/syscall_32.tbl
index 4cddd17..ebc24e3 100644
--- a/arch/x86/entry/syscalls/syscall_32.tbl
+++ b/arch/x86/entry/syscalls/syscall_32.tbl
@@ -9,7 +9,7 @@
  0 i386restart_syscall sys_restart_syscall
  1 i386exitsys_exit
  2 i386forksys_forksys_fork
-3  i386readsys_read
+3  i386readsys_read
compat_sys_read
  4 i386write   sys_write
  5 i386opensys_open
compat_sys_open
  6 i386close   sys_close
diff --git a/fs/read_write.c b/fs/read_write.c
index 933b53a..d244848 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -613,6 +613,14 @@ SYSCALL_DEFINE3(write, unsigned int, fd, const char __user 
*, buf,
return ret;
  }

+#ifdef CONFIG_COMPAT
+COMPAT_SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf,
+   compat_size_t, count)
+{
+return sys_read(fd, buf, (compat_ssize_t)count);
+}
+#endif
+
  SYSCALL_DEFINE4(pread64, unsigned int, fd, char __user *, buf,
size_t, count, loff_t, pos)
  {
diff --git a/include/linux/compat.h b/include/linux/compat.h
index f964ef7..d88ccad 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -332,6 +332,8 @@ asmlinkage long compat_sys_keyctl(u32 option,
  u32 arg2, u32 arg3, u32 arg4, u32 arg5);
  asmlinkage long compat_sys_ustat(unsigned dev, struct compat_ustat __user 
*u32);

+asmlinkage ssize_t compat_sys_read(unsigned int fd,
+   char __user * buf, compat_size_t count);
  asmlinkage ssize_t compat_sys_readv(compat_ulong_t fd,
const struct compat_iovec __user *vec, compat_ulong_t vlen);
  asmlinkage ssize_t compat_sys_writev(compat_ulong_t fd,
diff --git a/include/uapi/asm-generic/unistd.h 
b/include/uapi/asm-generic/unistd.h
index a26415b..745818a 100644
--- a/include/uapi/asm-generic/unistd.h
+++ b/include/uapi/asm-generic/unistd.h
@@ -201,7 +201,7 @@ __SC_COMP(__NR_getdents64, sys_getdents64, 
compat_sys_getdents64)
  #define __NR3264_lseek 62
  __SC_3264(__NR3264_lseek, sys_llseek, sys_lseek)
  #define __NR_read 63
-__SYSCALL(__NR_read, sys_read)
+__SC_COMP(__NR_read, sys_read, compat_sys_read)
  #define __NR_write 64
  __SYSCALL(__NR_write, sys_write)
  #define __NR_readv 65





Re: [RFC PATCH] sys_read: add a compat_sys_read for 64bit system

2016-06-07 Thread Zhangjian (Bamvor)

Hi,

On 2016/6/8 9:33, Weidong Wang wrote:

Test 32 progress and 64 progress on the 64bit system with
this progress:

int main(int argc, char **argv)
{
 int fd = 0;
 int i, ret = 0;
 char buf[512];
 unsigned long count = -1;

 fd = open("/tmp", O_RDONLY);
 if (fd < -1) {
 printf("Pls check the directory is exist?\n");
 return -1;
 }
 errno = 0;
 ret = read(fd, NULL, count);
 printf("Ret is %d errno %d\n", ret, errno);
 close(fd);

 return 0;
}

we get the different errno. The 64 progress we get errno is -14 while
the 32 progress is -21.

The reason is that, the user progress would use a 32bit count, while
the sys_read size_t in kernel is 64bit.  When the uesrspace count is
-1(0x), it goes to the sys_read, it would be change to a positive
number.

So I think we should add a compat_sys_read for the read syscall. I test it
on x86 or arm64 platform. The patch works well.

As weidong said, we tested on x86, x86_64, aarch64 ilp32, aarch64 lp64.
We do not familiar with other architecture, cc linux-api, hope could get more
input.

Regards

Bamvor


As well this patch may do work for the 'tile' 64 system.
I think it may enter the same result on mips/parisc/powerpc/sparc.
The s390 do the compat_sys_s390_read for the compat sys_read.

Signed-off-by: Weidong Wang 
---
  arch/x86/entry/syscalls/syscall_32.tbl | 2 +-
  fs/read_write.c| 8 
  include/linux/compat.h | 2 ++
  include/uapi/asm-generic/unistd.h  | 2 +-
  4 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/arch/x86/entry/syscalls/syscall_32.tbl 
b/arch/x86/entry/syscalls/syscall_32.tbl
index 4cddd17..ebc24e3 100644
--- a/arch/x86/entry/syscalls/syscall_32.tbl
+++ b/arch/x86/entry/syscalls/syscall_32.tbl
@@ -9,7 +9,7 @@
  0 i386restart_syscall sys_restart_syscall
  1 i386exitsys_exit
  2 i386forksys_forksys_fork
-3  i386readsys_read
+3  i386readsys_read
compat_sys_read
  4 i386write   sys_write
  5 i386opensys_open
compat_sys_open
  6 i386close   sys_close
diff --git a/fs/read_write.c b/fs/read_write.c
index 933b53a..d244848 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -613,6 +613,14 @@ SYSCALL_DEFINE3(write, unsigned int, fd, const char __user 
*, buf,
return ret;
  }

+#ifdef CONFIG_COMPAT
+COMPAT_SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf,
+   compat_size_t, count)
+{
+return sys_read(fd, buf, (compat_ssize_t)count);
+}
+#endif
+
  SYSCALL_DEFINE4(pread64, unsigned int, fd, char __user *, buf,
size_t, count, loff_t, pos)
  {
diff --git a/include/linux/compat.h b/include/linux/compat.h
index f964ef7..d88ccad 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -332,6 +332,8 @@ asmlinkage long compat_sys_keyctl(u32 option,
  u32 arg2, u32 arg3, u32 arg4, u32 arg5);
  asmlinkage long compat_sys_ustat(unsigned dev, struct compat_ustat __user 
*u32);

+asmlinkage ssize_t compat_sys_read(unsigned int fd,
+   char __user * buf, compat_size_t count);
  asmlinkage ssize_t compat_sys_readv(compat_ulong_t fd,
const struct compat_iovec __user *vec, compat_ulong_t vlen);
  asmlinkage ssize_t compat_sys_writev(compat_ulong_t fd,
diff --git a/include/uapi/asm-generic/unistd.h 
b/include/uapi/asm-generic/unistd.h
index a26415b..745818a 100644
--- a/include/uapi/asm-generic/unistd.h
+++ b/include/uapi/asm-generic/unistd.h
@@ -201,7 +201,7 @@ __SC_COMP(__NR_getdents64, sys_getdents64, 
compat_sys_getdents64)
  #define __NR3264_lseek 62
  __SC_3264(__NR3264_lseek, sys_llseek, sys_lseek)
  #define __NR_read 63
-__SYSCALL(__NR_read, sys_read)
+__SC_COMP(__NR_read, sys_read, compat_sys_read)
  #define __NR_write 64
  __SYSCALL(__NR_write, sys_write)
  #define __NR_readv 65





Re: [PATCH 21/23] arm64: ilp32: introduce ilp32-specific handlers for sigframe and ucontext

2016-06-04 Thread Zhangjian (Bamvor)

Hi,

I found an issue of unwind with the following code. The correct backtrace
should be:
(gdb) where
#0 0x004004d0 in my_sig (sig=11) at test_force3.c:16
#1 
#2 func2 (num=0) at test_force3.c:22
#3 0x00400540 in func1 (num=1) at test_force3.c:28
#4 0x00400574 in main (argc=1, argv=0xffd7bc04) at test_force3.c:33

Without my patch, the backtrace is:
(gdb) where
#0 0x00400490 in my_sig (sig=11) at test_force3.c:16
#1 
#2 0x004004e4 in main (argc=1, argv=0xffe6f8f4) at test_force3.c:33

With my patch which fix the wrong frame pointer(setup_return calculate the 
offset
of fp through ilp32_sigframe instead of sigfreame), the backtrace is:
(gdb) where
#0 0x00400490 in my_sig (sig=11) at test_force3.c:16
#1 
#2 func1 () at test_force3.c:28
#3 0x004004e4 in main (argc=1, argv=0xffe6f8f4) at test_force3.c:33

I am not sure there is still some issue in kernel. But it seem that the gdb of 
ilp32
does not work correctly when unwind without framepointer.

The test code is:

#include 
#include 
#include 
#include 

void my_sig(int sig)
{
printf("sig=%d\n", sig);
*(int *)0 = 0x0;
}


void func2()
{
*(int *)0 = 0x0;
}

void func1()
{
func2();
}

int main(int argc, char **argv)
{
signal(11, my_sig);
func1();
return 0;
}


The full patch is as follows:

From 7e364a765097f57aed2d73f94c1688c2e7343e79 Mon Sep 17 00:00:00 2001
From: Bamvor Jian Zhang 
Date: Sat, 4 Jun 2016 14:30:05 +0800
Subject: [PATCH] arm64: ilp32: fix for wrong fp offset when calculate the
 new fp

ILP32 define its own sigframe(ilp32_sigframe) because of the
difference uc_context. setup_return do not use ilp32 specific
sigframe to calculate the new offset of fp which lead to wrong
fp in signal handler. At this circumstance, gdb backtrace will miss
one item:
(gdb) where

It should be:
(gdb) where

The test code is as follows:

void my_sig(int sig)
{
printf("sig=%d\n", sig);
*(int *)0 = 0x0;
}

void func2(int num)
{
printf("%s: %d\n", __FUNCTION__, num);
*(int *)0 = 0x0;
func2(num-1);
}

void func1(int num)
{
printf("%s\n", __FUNCTION__);
func2(num - 1);
}

int main(int argc, char **argv)
{
signal(11, my_sig);
func1(argc);
return 0;
}

This patch fix this by passing the correct offset of fp to
setup_return.
Test pass on both ILP32 and LP64 in aarch64 EE.

Signed-off-by: Bamvor Jian Zhang 
---
 arch/arm64/include/asm/signal_common.h | 3 ++-
 arch/arm64/kernel/signal.c | 9 +
 arch/arm64/kernel/signal_ilp32.c   | 4 ++--
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/arch/arm64/include/asm/signal_common.h 
b/arch/arm64/include/asm/signal_common.h
index de93c71..a5d7b63 100644
--- a/arch/arm64/include/asm/signal_common.h
+++ b/arch/arm64/include/asm/signal_common.h
@@ -29,6 +29,7 @@ int setup_sigcontex(struct sigcontext __user *uc_mcontext,
struct pt_regs *regs);
 int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sf);
 void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
-   void __user *frame, off_t sigframe_off, int usig);
+   void __user *frame, off_t sigframe_off, off_t fp_off,
+   int usig);

 #endif /* __ASM_SIGNAL_COMMON_H */
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
index 038bebe..e66a6e9 100644
--- a/arch/arm64/kernel/signal.c
+++ b/arch/arm64/kernel/signal.c
@@ -256,14 +256,14 @@ static struct rt_sigframe __user *get_sigframe(struct 
ksignal *ksig,
 }

 void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
-void __user *frame, off_t sigframe_off, int usig)
+void __user *frame, off_t sigframe_off, off_t fp_off,
+int usig)
 {
__sigrestore_t sigtramp;

regs->regs[0] = usig;
regs->sp = (unsigned long)frame;
-   regs->regs[29] = regs->sp + sigframe_off +
-   offsetof(struct sigframe, fp);
+   regs->regs[29] = regs->sp + sigframe_off + fp_off;
regs->pc = (unsigned long)ka->sa.sa_handler;

if (ka->sa.sa_flags & SA_RESTORER)
@@ -294,7 +294,8 @@ static int setup_rt_frame(int usig, struct ksignal *ksig, 
sigset_t *set,
err |= setup_sigframe(>sig, regs, set);
if (err == 0) {
setup_return(regs, >ka, frame,
-   offsetof(struct rt_sigframe, sig), usig);
+   offsetof(struct rt_sigframe, sig),
+   offsetof(struct sigframe, fp), usig);
if (ksig->ka.sa.sa_flags & SA_SIGINFO) {
err |= copy_siginfo_to_user(>info, >info);
regs->regs[1] = (unsigned long)>info;
diff --git a/arch/arm64/kernel/signal_ilp32.c b/arch/arm64/kernel/signal_ilp32.c
index a8ea73e..9030f14 100644
--- a/arch/arm64/kernel/signal_ilp32.c
+++ 

Re: [PATCH 21/23] arm64: ilp32: introduce ilp32-specific handlers for sigframe and ucontext

2016-06-04 Thread Zhangjian (Bamvor)

Hi,

I found an issue of unwind with the following code. The correct backtrace
should be:
(gdb) where
#0 0x004004d0 in my_sig (sig=11) at test_force3.c:16
#1 
#2 func2 (num=0) at test_force3.c:22
#3 0x00400540 in func1 (num=1) at test_force3.c:28
#4 0x00400574 in main (argc=1, argv=0xffd7bc04) at test_force3.c:33

Without my patch, the backtrace is:
(gdb) where
#0 0x00400490 in my_sig (sig=11) at test_force3.c:16
#1 
#2 0x004004e4 in main (argc=1, argv=0xffe6f8f4) at test_force3.c:33

With my patch which fix the wrong frame pointer(setup_return calculate the 
offset
of fp through ilp32_sigframe instead of sigfreame), the backtrace is:
(gdb) where
#0 0x00400490 in my_sig (sig=11) at test_force3.c:16
#1 
#2 func1 () at test_force3.c:28
#3 0x004004e4 in main (argc=1, argv=0xffe6f8f4) at test_force3.c:33

I am not sure there is still some issue in kernel. But it seem that the gdb of 
ilp32
does not work correctly when unwind without framepointer.

The test code is:

#include 
#include 
#include 
#include 

void my_sig(int sig)
{
printf("sig=%d\n", sig);
*(int *)0 = 0x0;
}


void func2()
{
*(int *)0 = 0x0;
}

void func1()
{
func2();
}

int main(int argc, char **argv)
{
signal(11, my_sig);
func1();
return 0;
}


The full patch is as follows:

From 7e364a765097f57aed2d73f94c1688c2e7343e79 Mon Sep 17 00:00:00 2001
From: Bamvor Jian Zhang 
Date: Sat, 4 Jun 2016 14:30:05 +0800
Subject: [PATCH] arm64: ilp32: fix for wrong fp offset when calculate the
 new fp

ILP32 define its own sigframe(ilp32_sigframe) because of the
difference uc_context. setup_return do not use ilp32 specific
sigframe to calculate the new offset of fp which lead to wrong
fp in signal handler. At this circumstance, gdb backtrace will miss
one item:
(gdb) where

It should be:
(gdb) where

The test code is as follows:

void my_sig(int sig)
{
printf("sig=%d\n", sig);
*(int *)0 = 0x0;
}

void func2(int num)
{
printf("%s: %d\n", __FUNCTION__, num);
*(int *)0 = 0x0;
func2(num-1);
}

void func1(int num)
{
printf("%s\n", __FUNCTION__);
func2(num - 1);
}

int main(int argc, char **argv)
{
signal(11, my_sig);
func1(argc);
return 0;
}

This patch fix this by passing the correct offset of fp to
setup_return.
Test pass on both ILP32 and LP64 in aarch64 EE.

Signed-off-by: Bamvor Jian Zhang 
---
 arch/arm64/include/asm/signal_common.h | 3 ++-
 arch/arm64/kernel/signal.c | 9 +
 arch/arm64/kernel/signal_ilp32.c   | 4 ++--
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/arch/arm64/include/asm/signal_common.h 
b/arch/arm64/include/asm/signal_common.h
index de93c71..a5d7b63 100644
--- a/arch/arm64/include/asm/signal_common.h
+++ b/arch/arm64/include/asm/signal_common.h
@@ -29,6 +29,7 @@ int setup_sigcontex(struct sigcontext __user *uc_mcontext,
struct pt_regs *regs);
 int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sf);
 void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
-   void __user *frame, off_t sigframe_off, int usig);
+   void __user *frame, off_t sigframe_off, off_t fp_off,
+   int usig);

 #endif /* __ASM_SIGNAL_COMMON_H */
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
index 038bebe..e66a6e9 100644
--- a/arch/arm64/kernel/signal.c
+++ b/arch/arm64/kernel/signal.c
@@ -256,14 +256,14 @@ static struct rt_sigframe __user *get_sigframe(struct 
ksignal *ksig,
 }

 void setup_return(struct pt_regs *regs, struct k_sigaction *ka,
-void __user *frame, off_t sigframe_off, int usig)
+void __user *frame, off_t sigframe_off, off_t fp_off,
+int usig)
 {
__sigrestore_t sigtramp;

regs->regs[0] = usig;
regs->sp = (unsigned long)frame;
-   regs->regs[29] = regs->sp + sigframe_off +
-   offsetof(struct sigframe, fp);
+   regs->regs[29] = regs->sp + sigframe_off + fp_off;
regs->pc = (unsigned long)ka->sa.sa_handler;

if (ka->sa.sa_flags & SA_RESTORER)
@@ -294,7 +294,8 @@ static int setup_rt_frame(int usig, struct ksignal *ksig, 
sigset_t *set,
err |= setup_sigframe(>sig, regs, set);
if (err == 0) {
setup_return(regs, >ka, frame,
-   offsetof(struct rt_sigframe, sig), usig);
+   offsetof(struct rt_sigframe, sig),
+   offsetof(struct sigframe, fp), usig);
if (ksig->ka.sa.sa_flags & SA_SIGINFO) {
err |= copy_siginfo_to_user(>info, >info);
regs->regs[1] = (unsigned long)>info;
diff --git a/arch/arm64/kernel/signal_ilp32.c b/arch/arm64/kernel/signal_ilp32.c
index a8ea73e..9030f14 100644
--- a/arch/arm64/kernel/signal_ilp32.c
+++ b/arch/arm64/kernel/signal_ilp32.c
@@ -147,7 +147,6 @@ 

Re: [PATCH 16/23] arm64: ilp32: introduce binfmt_ilp32.c

2016-05-26 Thread Zhangjian (Bamvor)

Hi, yury

The coredump is usable in our platform. It miss the following definition:
+#define compat_elf_greg_t  elf_greg_t
+#define compat_elf_gregset_t   elf_gregset_t

And it leads to the wrong register save in core dump. After apply this patch,
gdb could debug core dump files.

Here is the full patch:
From 102624840aa5dacdd1bbfe3b390290f52f530ea2 Mon Sep 17 00:00:00 2001
From: Bamvor Jian Zhang 
Date: Thu, 26 May 2016 21:00:16 +0800
Subject: [PATCH hulk-4.1-next] arm64: ilp32: fix coredump issue

ILP32 use aarch64 register and 32bit signal struct which means it
could not make use of the existing compat_elf_prstatus/elf_prstatus
and compat_elf_prpsinfo/elf_prpsinfo.

This patch fix this issue by introducing the different
compat_elf_greg_t, compat_elf_gregset_t for aarch64 ilp32 and aarch32
el0.

Tested pass on huawei's hardware in bigendian.

Signed-off-by: Bamvor Jian Zhang 
---
 arch/arm64/include/asm/elf.h | 14 +++---
 arch/arm64/kernel/binfmt_elf32.c |  3 +++
 arch/arm64/kernel/binfmt_ilp32.c |  8 +++-
 arch/arm64/kernel/ptrace.c   | 20 ++--
 4 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h
index 0106d18..9019441 100644
--- a/arch/arm64/include/asm/elf.h
+++ b/arch/arm64/include/asm/elf.h
@@ -154,18 +154,18 @@ extern int arch_setup_additional_pages(struct 
linux_binprm *bprm,
   int uses_interp);

 /* 1GB of VA */
-#define STACK_RND_MASK (is_compat_task() ? \
-   0x7ff >> (PAGE_SHIFT - 12) : \
-   0x3 >> (PAGE_SHIFT - 12))
+#define STACK_RND_MASK (is_compat_task() ? \
+   0x7ff >> (PAGE_SHIFT - 12) : \
+   0x3 >> (PAGE_SHIFT - 12))

 #ifdef CONFIG_COMPAT

-#define COMPAT_ELF_ET_DYN_BASE (2 * TASK_SIZE_32 / 3)
+#define COMPAT_ELF_ET_DYN_BASE (2 * TASK_SIZE_32 / 3)

 /* AArch32 registers. */
-#define COMPAT_ELF_NGREG   18
-typedef unsigned int   compat_elf_greg_t;
-typedef compat_elf_greg_t  compat_elf_gregset_t[COMPAT_ELF_NGREG];
+#define COMPAT_ELF_NGREG   18
+typedef unsigned int   compat_a32_elf_greg_t;
+typedef compat_a32_elf_greg_t  compat_a32_elf_gregset_t[COMPAT_ELF_NGREG];

 #endif /* CONFIG_COMPAT */

diff --git a/arch/arm64/kernel/binfmt_elf32.c b/arch/arm64/kernel/binfmt_elf32.c
index 7b9b445..f75253c 100644
--- a/arch/arm64/kernel/binfmt_elf32.c
+++ b/arch/arm64/kernel/binfmt_elf32.c
@@ -31,4 +31,7 @@ struct linux_binprm;
 extern int aarch32_setup_vectors_page(struct linux_binprm *bprm,
  int uses_interp);

+#define compat_elf_greg_t  compat_a32_elf_greg_t
+#define compat_elf_gregset_t   compat_a32_elf_gregset_t
+
 #include "../../../fs/compat_binfmt_elf.c"
diff --git a/arch/arm64/kernel/binfmt_ilp32.c b/arch/arm64/kernel/binfmt_ilp32.c
index b827a9a..01baf83 100644
--- a/arch/arm64/kernel/binfmt_ilp32.c
+++ b/arch/arm64/kernel/binfmt_ilp32.c
@@ -2,7 +2,9 @@
  * Support for ILP32 Linux/aarch64 ELF binaries.
  */

-#include 
+#include 
+#include 
+#include 
 #include 

 #undef ELF_CLASS
@@ -30,9 +32,13 @@
  * The machine-dependent core note format types are defined in 
elfcore-compat.h,
  * which requires asm/elf.h to define compat_elf_gregset_t et al.
  */
+#define compat_elf_greg_t  elf_greg_t
+#define compat_elf_gregset_t   elf_gregset_t
 #define elf_prstatus   compat_elf_prstatus
 #define elf_prpsinfo   compat_elf_prpsinfo

+#include 
+
 /*
  * Compat version of cputime_to_compat_timeval, perhaps this
  * should be an inline in .
diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c
index 5c86135..9784c77 100644
--- a/arch/arm64/kernel/ptrace.c
+++ b/arch/arm64/kernel/ptrace.c
@@ -913,8 +913,8 @@ static const struct user_regset aarch32_regsets[] = {
[REGSET_COMPAT_GPR] = {
.core_note_type = NT_PRSTATUS,
.n = COMPAT_ELF_NGREG,
-   .size = sizeof(compat_elf_greg_t),
-   .align = sizeof(compat_elf_greg_t),
+   .size = sizeof(compat_a32_elf_greg_t),
+   .align = sizeof(compat_a32_elf_greg_t),
.get = compat_gpr_get,
.set = compat_gpr_set
},
@@ -947,7 +947,7 @@ static int compat_ptrace_read_user(struct task_struct *tsk, 
compat_ulong_t off,
tmp = tsk->mm->start_data;
else if (off == COMPAT_PT_TEXT_END_ADDR)
tmp = tsk->mm->end_code;
-   else if (off < sizeof(compat_elf_gregset_t))
+   else if (off < sizeof(compat_a32_elf_gregset_t))
return copy_regset_to_user(tsk, _aarch32_view,
   REGSET_COMPAT_GPR, off,
   

Re: [PATCH 16/23] arm64: ilp32: introduce binfmt_ilp32.c

2016-05-26 Thread Zhangjian (Bamvor)

Hi, yury

The coredump is usable in our platform. It miss the following definition:
+#define compat_elf_greg_t  elf_greg_t
+#define compat_elf_gregset_t   elf_gregset_t

And it leads to the wrong register save in core dump. After apply this patch,
gdb could debug core dump files.

Here is the full patch:
From 102624840aa5dacdd1bbfe3b390290f52f530ea2 Mon Sep 17 00:00:00 2001
From: Bamvor Jian Zhang 
Date: Thu, 26 May 2016 21:00:16 +0800
Subject: [PATCH hulk-4.1-next] arm64: ilp32: fix coredump issue

ILP32 use aarch64 register and 32bit signal struct which means it
could not make use of the existing compat_elf_prstatus/elf_prstatus
and compat_elf_prpsinfo/elf_prpsinfo.

This patch fix this issue by introducing the different
compat_elf_greg_t, compat_elf_gregset_t for aarch64 ilp32 and aarch32
el0.

Tested pass on huawei's hardware in bigendian.

Signed-off-by: Bamvor Jian Zhang 
---
 arch/arm64/include/asm/elf.h | 14 +++---
 arch/arm64/kernel/binfmt_elf32.c |  3 +++
 arch/arm64/kernel/binfmt_ilp32.c |  8 +++-
 arch/arm64/kernel/ptrace.c   | 20 ++--
 4 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h
index 0106d18..9019441 100644
--- a/arch/arm64/include/asm/elf.h
+++ b/arch/arm64/include/asm/elf.h
@@ -154,18 +154,18 @@ extern int arch_setup_additional_pages(struct 
linux_binprm *bprm,
   int uses_interp);

 /* 1GB of VA */
-#define STACK_RND_MASK (is_compat_task() ? \
-   0x7ff >> (PAGE_SHIFT - 12) : \
-   0x3 >> (PAGE_SHIFT - 12))
+#define STACK_RND_MASK (is_compat_task() ? \
+   0x7ff >> (PAGE_SHIFT - 12) : \
+   0x3 >> (PAGE_SHIFT - 12))

 #ifdef CONFIG_COMPAT

-#define COMPAT_ELF_ET_DYN_BASE (2 * TASK_SIZE_32 / 3)
+#define COMPAT_ELF_ET_DYN_BASE (2 * TASK_SIZE_32 / 3)

 /* AArch32 registers. */
-#define COMPAT_ELF_NGREG   18
-typedef unsigned int   compat_elf_greg_t;
-typedef compat_elf_greg_t  compat_elf_gregset_t[COMPAT_ELF_NGREG];
+#define COMPAT_ELF_NGREG   18
+typedef unsigned int   compat_a32_elf_greg_t;
+typedef compat_a32_elf_greg_t  compat_a32_elf_gregset_t[COMPAT_ELF_NGREG];

 #endif /* CONFIG_COMPAT */

diff --git a/arch/arm64/kernel/binfmt_elf32.c b/arch/arm64/kernel/binfmt_elf32.c
index 7b9b445..f75253c 100644
--- a/arch/arm64/kernel/binfmt_elf32.c
+++ b/arch/arm64/kernel/binfmt_elf32.c
@@ -31,4 +31,7 @@ struct linux_binprm;
 extern int aarch32_setup_vectors_page(struct linux_binprm *bprm,
  int uses_interp);

+#define compat_elf_greg_t  compat_a32_elf_greg_t
+#define compat_elf_gregset_t   compat_a32_elf_gregset_t
+
 #include "../../../fs/compat_binfmt_elf.c"
diff --git a/arch/arm64/kernel/binfmt_ilp32.c b/arch/arm64/kernel/binfmt_ilp32.c
index b827a9a..01baf83 100644
--- a/arch/arm64/kernel/binfmt_ilp32.c
+++ b/arch/arm64/kernel/binfmt_ilp32.c
@@ -2,7 +2,9 @@
  * Support for ILP32 Linux/aarch64 ELF binaries.
  */

-#include 
+#include 
+#include 
+#include 
 #include 

 #undef ELF_CLASS
@@ -30,9 +32,13 @@
  * The machine-dependent core note format types are defined in 
elfcore-compat.h,
  * which requires asm/elf.h to define compat_elf_gregset_t et al.
  */
+#define compat_elf_greg_t  elf_greg_t
+#define compat_elf_gregset_t   elf_gregset_t
 #define elf_prstatus   compat_elf_prstatus
 #define elf_prpsinfo   compat_elf_prpsinfo

+#include 
+
 /*
  * Compat version of cputime_to_compat_timeval, perhaps this
  * should be an inline in .
diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c
index 5c86135..9784c77 100644
--- a/arch/arm64/kernel/ptrace.c
+++ b/arch/arm64/kernel/ptrace.c
@@ -913,8 +913,8 @@ static const struct user_regset aarch32_regsets[] = {
[REGSET_COMPAT_GPR] = {
.core_note_type = NT_PRSTATUS,
.n = COMPAT_ELF_NGREG,
-   .size = sizeof(compat_elf_greg_t),
-   .align = sizeof(compat_elf_greg_t),
+   .size = sizeof(compat_a32_elf_greg_t),
+   .align = sizeof(compat_a32_elf_greg_t),
.get = compat_gpr_get,
.set = compat_gpr_set
},
@@ -947,7 +947,7 @@ static int compat_ptrace_read_user(struct task_struct *tsk, 
compat_ulong_t off,
tmp = tsk->mm->start_data;
else if (off == COMPAT_PT_TEXT_END_ADDR)
tmp = tsk->mm->end_code;
-   else if (off < sizeof(compat_elf_gregset_t))
+   else if (off < sizeof(compat_a32_elf_gregset_t))
return copy_regset_to_user(tsk, _aarch32_view,
   REGSET_COMPAT_GPR, off,
   sizeof(compat_ulong_t), ret);
@@ -968,7 +968,7 @@ static int 

Re: [RFC6 PATCH v6 00/21] ILP32 for ARM64

2016-05-13 Thread Zhangjian (Bamvor)

Hi,

On 2016/5/12 23:28, Catalin Marinas wrote:

On Thu, May 12, 2016 at 05:24:57PM +0300, Yury Norov wrote:

On Thu, May 12, 2016 at 03:07:35PM +0100, Catalin Marinas wrote:

On Thu, May 12, 2016 at 04:44:31PM +0300, Yury Norov wrote:

On Thu, May 12, 2016 at 02:35:34PM +0100, Catalin Marinas wrote:

On Thu, May 12, 2016 at 03:20:00AM +0300, Yury Norov wrote:

I debugged preadv02 and pwritev02 failures and found very weird bug.
Test passes {iovec_base = 0x, iovec_len = 64} as one element
of vector, and kernel reports successful read/write.

There are 2 problems:
1. How kernel allows such address to be passed to fs subsystem;
2. How fs successes to read/write at non-mapped, and in fact non-user
address.

I don't know the answer on 2'nd question, and it might be something
generic. But I investigated first problem.

The problem is that compat_rw_copy_check_uvector() uses access_ok() to
validate user address, and on arm64 it ends up with checking buffer
end against current_thread_info()->addr_limit.

current_thread_info()->addr_limit for ilp32, and most probably for
aarch32 is equal to aarch64 one, and so adress_ok() doesn't fail.
It happens because on thread creation we call flush_old_exec() to set
addr_limit, and completely ignore compat mode there.


[...]


--- a/arch/arm64/kernel/binfmt_elf32.c
+++ b/arch/arm64/kernel/binfmt_elf32.c
@@ -12,6 +12,7 @@
  do {  \
clear_thread_flag(TIF_32BIT_AARCH64);   \
set_thread_flag(TIF_32BIT); \
+   set_fs(TASK_SIZE_32);   \
  } while (0)

  #define COMPAT_ARCH_DLINFO
diff --git a/arch/arm64/kernel/binfmt_ilp32.c b/arch/arm64/kernel/binfmt_ilp32.c
index a934fd4..a8599c6 100644
--- a/arch/arm64/kernel/binfmt_ilp32.c
+++ b/arch/arm64/kernel/binfmt_ilp32.c
@@ -59,6 +59,7 @@ static void cputime_to_compat_timeval(const cputime_t cputime,
  do {  \
set_thread_flag(TIF_32BIT_AARCH64); \
clear_thread_flag(TIF_32BIT);   \
+   set_fs(TASK_SIZE_32);   \
  } while (0)


I don't think we need these two. AFAICT, flush_old_exec() takes care of
setting the USER_DS for the new thread.


That's true, but USER_DS depends on personality which is not set yet
for new thread, as I wrote above. In fact, I tried correct USER_DS
only, and it doesn't work


Ah, it looks like load_elf_binary() sets the personality after
flush_old_exec(). Looking at powerpc and x86, they set USER_DS to the
maximum 64-bit task value, so they should have a similar issue with
native 32-bit vs compat behaviour.


Hmmm. If so, it means we'd introduce generic fix. It would be removing
set_fs() from flush_old_exec() and appending it to load_elf_binary()
after SET_PERSONALITY(). But I think it should be agreed with other
arches developers.


The set_fs() in flush_old_exec() is probably fine, it may be meant to
re-set the USER_DS for the old thread.

It appears that at least powerpc and x86 don't have different USER_DS
setting for native and compat, so moving the set_fs() call further down
would not make any difference for them, nor will it fix the preadv02 LTP
test (if it fails for them, I haven't checked).


I've sent standalone patch for aarch64 (you in CC) so let's move
discussion there.


I've seen the patch but we would lose some discussion history here. I
think we should continue this thread and just summarise the conclusion
in reply to the other patch. This thread is also available on
linux-arch, in case other architecture maintainers follow it.


So what exactly is LTP complaining about? Is different error (like
EFAULT vs EINVAL) or not getting an error at all.


It should be EINVAL, but it succeed. The other problem is that
following fs routines does not complain on wrong address.


I see. The test asks the kernel to write a single byte (out of maximum
64) to the user address 0x.

What address We should set for this limitation, TASK_SIZE or STACK_TOP?
It is same for 64bit application. But STACK_TOP(0x) is below
TASK_SIZE in 32bit application. The address above STACK_TOP is preserved
for 32bit application.

Regards

Bamvor

> In the absence of the access_ok()

check, this operation succeeds. If the preadv syscall gets 2 bytes as
the count, then it would fail with EFAULT.

While it's not really a bug, I agree that for matching the native 32-bit
behavior (basically for other syscalls like those involving vfs_read()),
the simplest fix would be to have a dynamic USER_DS.










Re: [RFC6 PATCH v6 00/21] ILP32 for ARM64

2016-05-13 Thread Zhangjian (Bamvor)

Hi,

On 2016/5/12 23:28, Catalin Marinas wrote:

On Thu, May 12, 2016 at 05:24:57PM +0300, Yury Norov wrote:

On Thu, May 12, 2016 at 03:07:35PM +0100, Catalin Marinas wrote:

On Thu, May 12, 2016 at 04:44:31PM +0300, Yury Norov wrote:

On Thu, May 12, 2016 at 02:35:34PM +0100, Catalin Marinas wrote:

On Thu, May 12, 2016 at 03:20:00AM +0300, Yury Norov wrote:

I debugged preadv02 and pwritev02 failures and found very weird bug.
Test passes {iovec_base = 0x, iovec_len = 64} as one element
of vector, and kernel reports successful read/write.

There are 2 problems:
1. How kernel allows such address to be passed to fs subsystem;
2. How fs successes to read/write at non-mapped, and in fact non-user
address.

I don't know the answer on 2'nd question, and it might be something
generic. But I investigated first problem.

The problem is that compat_rw_copy_check_uvector() uses access_ok() to
validate user address, and on arm64 it ends up with checking buffer
end against current_thread_info()->addr_limit.

current_thread_info()->addr_limit for ilp32, and most probably for
aarch32 is equal to aarch64 one, and so adress_ok() doesn't fail.
It happens because on thread creation we call flush_old_exec() to set
addr_limit, and completely ignore compat mode there.


[...]


--- a/arch/arm64/kernel/binfmt_elf32.c
+++ b/arch/arm64/kernel/binfmt_elf32.c
@@ -12,6 +12,7 @@
  do {  \
clear_thread_flag(TIF_32BIT_AARCH64);   \
set_thread_flag(TIF_32BIT); \
+   set_fs(TASK_SIZE_32);   \
  } while (0)

  #define COMPAT_ARCH_DLINFO
diff --git a/arch/arm64/kernel/binfmt_ilp32.c b/arch/arm64/kernel/binfmt_ilp32.c
index a934fd4..a8599c6 100644
--- a/arch/arm64/kernel/binfmt_ilp32.c
+++ b/arch/arm64/kernel/binfmt_ilp32.c
@@ -59,6 +59,7 @@ static void cputime_to_compat_timeval(const cputime_t cputime,
  do {  \
set_thread_flag(TIF_32BIT_AARCH64); \
clear_thread_flag(TIF_32BIT);   \
+   set_fs(TASK_SIZE_32);   \
  } while (0)


I don't think we need these two. AFAICT, flush_old_exec() takes care of
setting the USER_DS for the new thread.


That's true, but USER_DS depends on personality which is not set yet
for new thread, as I wrote above. In fact, I tried correct USER_DS
only, and it doesn't work


Ah, it looks like load_elf_binary() sets the personality after
flush_old_exec(). Looking at powerpc and x86, they set USER_DS to the
maximum 64-bit task value, so they should have a similar issue with
native 32-bit vs compat behaviour.


Hmmm. If so, it means we'd introduce generic fix. It would be removing
set_fs() from flush_old_exec() and appending it to load_elf_binary()
after SET_PERSONALITY(). But I think it should be agreed with other
arches developers.


The set_fs() in flush_old_exec() is probably fine, it may be meant to
re-set the USER_DS for the old thread.

It appears that at least powerpc and x86 don't have different USER_DS
setting for native and compat, so moving the set_fs() call further down
would not make any difference for them, nor will it fix the preadv02 LTP
test (if it fails for them, I haven't checked).


I've sent standalone patch for aarch64 (you in CC) so let's move
discussion there.


I've seen the patch but we would lose some discussion history here. I
think we should continue this thread and just summarise the conclusion
in reply to the other patch. This thread is also available on
linux-arch, in case other architecture maintainers follow it.


So what exactly is LTP complaining about? Is different error (like
EFAULT vs EINVAL) or not getting an error at all.


It should be EINVAL, but it succeed. The other problem is that
following fs routines does not complain on wrong address.


I see. The test asks the kernel to write a single byte (out of maximum
64) to the user address 0x.

What address We should set for this limitation, TASK_SIZE or STACK_TOP?
It is same for 64bit application. But STACK_TOP(0x) is below
TASK_SIZE in 32bit application. The address above STACK_TOP is preserved
for 32bit application.

Regards

Bamvor

> In the absence of the access_ok()

check, this operation succeeds. If the preadv syscall gets 2 bytes as
the count, then it would fail with EFAULT.

While it's not really a bug, I agree that for matching the native 32-bit
behavior (basically for other syscalls like those involving vfs_read()),
the simplest fix would be to have a dynamic USER_DS.










Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-12 Thread Zhangjian (Bamvor)

Hi,

On 2016/5/12 16:24, Yury Norov wrote:

On Thu, May 12, 2016 at 11:45:53AM +0800, Zhangjian (Bamvor) wrote:

[...]


Hmm, that is indeed tricky. I think COMPAT_SYSCALL_WRAP4 rightfully
refuses the loff_t argument here, as the common case is that this is
not possible.

It works if I apply the following patch, I defined the wrong `__TYPE_IS_xxx`
yesterday. Should we merge this into ILP32 series or send the compat.h
and syscalls.h individually? The current series of ILP32 is a little bit
long and hard to review.
diff --git a/include/linux/compat.h b/include/linux/compat.h
index ba6ebe0..22a9565 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -747,7 +747,8 @@ asmlinkage long compat_sys_fanotify_mark(int, unsigned int, 
__u32, __u32,
  #ifndef __SC_COMPAT_CAST
  #define __SC_COMPAT_CAST(t, a) ({  \
 BUILD_BUG_ON((sizeof(t) > 4) && !__TYPE_IS_L(t) &&  \
-!__TYPE_IS_UL(t) && !__TYPE_IS_PTR(t));\
+!__TYPE_IS_UL(t) && !__TYPE_IS_PTR(t) &&   \
+!__TYPE_IS_LOFFT(t));  \


I think it's wrong, as loff_t is 64-bit in 32-bit userspace, and this
will clear meaningful data in top halve.

Yes. It is my fault. The original thoughts is clear the up 32bit for size_t.
How should we skip the loff_t?

Regards

Bamvor



Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-12 Thread Zhangjian (Bamvor)

Hi,

On 2016/5/12 16:24, Yury Norov wrote:

On Thu, May 12, 2016 at 11:45:53AM +0800, Zhangjian (Bamvor) wrote:

[...]


Hmm, that is indeed tricky. I think COMPAT_SYSCALL_WRAP4 rightfully
refuses the loff_t argument here, as the common case is that this is
not possible.

It works if I apply the following patch, I defined the wrong `__TYPE_IS_xxx`
yesterday. Should we merge this into ILP32 series or send the compat.h
and syscalls.h individually? The current series of ILP32 is a little bit
long and hard to review.
diff --git a/include/linux/compat.h b/include/linux/compat.h
index ba6ebe0..22a9565 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -747,7 +747,8 @@ asmlinkage long compat_sys_fanotify_mark(int, unsigned int, 
__u32, __u32,
  #ifndef __SC_COMPAT_CAST
  #define __SC_COMPAT_CAST(t, a) ({  \
 BUILD_BUG_ON((sizeof(t) > 4) && !__TYPE_IS_L(t) &&  \
-!__TYPE_IS_UL(t) && !__TYPE_IS_PTR(t));\
+!__TYPE_IS_UL(t) && !__TYPE_IS_PTR(t) &&   \
+!__TYPE_IS_LOFFT(t));  \


I think it's wrong, as loff_t is 64-bit in 32-bit userspace, and this
will clear meaningful data in top halve.

Yes. It is my fault. The original thoughts is clear the up 32bit for size_t.
How should we skip the loff_t?

Regards

Bamvor



Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-12 Thread Zhangjian (Bamvor)

Hi,

On 2016/5/12 17:21, Arnd Bergmann wrote:

On Thursday 12 May 2016 10:17:58 Catalin Marinas wrote:

On Wed, May 11, 2016 at 09:30:07PM +0200, Arnd Bergmann wrote:

On Wednesday 11 May 2016 17:59:01 Catalin Marinas wrote:

I don't think the shifts are a problem, the main downside would be
the limit to 44 bits of file offsets (16TB files), but it's also
unclear if that is a practical problem at all. If it is, we run
into the same problem on all other 32-bit architectures too.


I hope people are seriously thinking of moving to an LP64 ABI if they
have such large file offset needs.


Good point. 44 bits of file size is certainly enough for mmap()
on a 32-bit task: you would only be able to map a very small fraction
of the file anyway, and if you want to map larger files, and should
move to 64-bit tasks long before this becomes a limitation.

Hi,

I apply the following patch in order to make use of the REAL mmmap2. LTP
test pass in litle endian. mmap16 successful with segfault in big endian.

BTW, I saw the similar code in tile, mips, microblaze and s390 compat. Should
we merge these code into a common syscall wrapper?

kernel:
diff --git a/arch/arm64/kernel/sys_ilp32.c b/arch/arm64/kernel/sys_ilp32.c
index d85fe94..2cd72eb 100644
--- a/arch/arm64/kernel/sys_ilp32.c
+++ b/arch/arm64/kernel/sys_ilp32.c
@@ -41,7 +41,16 @@
 #define compat_sys_sync_file_range sys_sync_file_range
 #define compat_sys_truncate64  sys_truncate
 #define sys_llseek sys_lseek
-#define sys_mmap2 sys_mmap
+
+SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
+   unsigned long, prot, unsigned long, flags, unsigned long, fd,
+   unsigned long, pgoff)
+{
+   if (pgoff & (~PAGE_MASK >> 12))
+   return -EINVAL;
+
+   return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff >> 
(PAGE_SHIFT-12));
+}

 asmlinkage long ilp32_sys_rt_sigreturn_wrapper(void);
 #define compat_sys_rt_sigreturnilp32_sys_rt_sigreturn_wrapper

glibc:
diff --git a/sysdeps/unix/sysv/linux/aarch64/ilp32/mmap.c 
b/sysdeps/unix/sysv/linux/aarch64/ilp32/mmap.c
index e69de29..f75e251 100644
--- a/sysdeps/unix/sysv/linux/aarch64/ilp32/mmap.c
+++ b/sysdeps/unix/sysv/linux/aarch64/ilp32/mmap.c
@@ -0,0 +1,2 @@
+#include 
+
diff --git a/sysdeps/unix/sysv/linux/aarch64/ilp32/mmap64.c 
b/sysdeps/unix/sysv/linux/aarch64/ilp32/mmap64.c
index c6c7f1d..6f1a141 100644
--- a/sysdeps/unix/sysv/linux/aarch64/ilp32/mmap64.c
+++ b/sysdeps/unix/sysv/linux/aarch64/ilp32/mmap64.c
@@ -1,29 +1 @@
-#include 
-#include 
-#include 
-#include 
-
-#include 
-#include 
-
-/* mmap is provided by mmap as they are the same. */
-void *__mmap (void *__addr, size_t __len, int __prot,
-int __flags, int __fd, __off_t __offset)
-{
-   void *result;
-   result = (void *) INLINE_SYSCALL (mmap2, 6, __addr, __len, __prot, __flags,
-   return result;
-}
-/* mmap64 is provided by mmap as they are the same. */
-void *__mmap64 (void *__addr, size_t __len, int __prot,
-int __flags, int __fd, __off64_t __offset)
-{
-   void *result;
-   result = (void *)
- INLINE_SYSCALL (mmap2, 6, __addr,
- __len, __prot, __flags, __fd, __offset);
-   return result;
-}
-weak_alias (__mmap, mmap)
-weak_alias (__mmap64, mmap64)
+#include 

Regards

Bamvor

Arnd





Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-12 Thread Zhangjian (Bamvor)

Hi,

On 2016/5/12 17:21, Arnd Bergmann wrote:

On Thursday 12 May 2016 10:17:58 Catalin Marinas wrote:

On Wed, May 11, 2016 at 09:30:07PM +0200, Arnd Bergmann wrote:

On Wednesday 11 May 2016 17:59:01 Catalin Marinas wrote:

I don't think the shifts are a problem, the main downside would be
the limit to 44 bits of file offsets (16TB files), but it's also
unclear if that is a practical problem at all. If it is, we run
into the same problem on all other 32-bit architectures too.


I hope people are seriously thinking of moving to an LP64 ABI if they
have such large file offset needs.


Good point. 44 bits of file size is certainly enough for mmap()
on a 32-bit task: you would only be able to map a very small fraction
of the file anyway, and if you want to map larger files, and should
move to 64-bit tasks long before this becomes a limitation.

Hi,

I apply the following patch in order to make use of the REAL mmmap2. LTP
test pass in litle endian. mmap16 successful with segfault in big endian.

BTW, I saw the similar code in tile, mips, microblaze and s390 compat. Should
we merge these code into a common syscall wrapper?

kernel:
diff --git a/arch/arm64/kernel/sys_ilp32.c b/arch/arm64/kernel/sys_ilp32.c
index d85fe94..2cd72eb 100644
--- a/arch/arm64/kernel/sys_ilp32.c
+++ b/arch/arm64/kernel/sys_ilp32.c
@@ -41,7 +41,16 @@
 #define compat_sys_sync_file_range sys_sync_file_range
 #define compat_sys_truncate64  sys_truncate
 #define sys_llseek sys_lseek
-#define sys_mmap2 sys_mmap
+
+SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
+   unsigned long, prot, unsigned long, flags, unsigned long, fd,
+   unsigned long, pgoff)
+{
+   if (pgoff & (~PAGE_MASK >> 12))
+   return -EINVAL;
+
+   return sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff >> 
(PAGE_SHIFT-12));
+}

 asmlinkage long ilp32_sys_rt_sigreturn_wrapper(void);
 #define compat_sys_rt_sigreturnilp32_sys_rt_sigreturn_wrapper

glibc:
diff --git a/sysdeps/unix/sysv/linux/aarch64/ilp32/mmap.c 
b/sysdeps/unix/sysv/linux/aarch64/ilp32/mmap.c
index e69de29..f75e251 100644
--- a/sysdeps/unix/sysv/linux/aarch64/ilp32/mmap.c
+++ b/sysdeps/unix/sysv/linux/aarch64/ilp32/mmap.c
@@ -0,0 +1,2 @@
+#include 
+
diff --git a/sysdeps/unix/sysv/linux/aarch64/ilp32/mmap64.c 
b/sysdeps/unix/sysv/linux/aarch64/ilp32/mmap64.c
index c6c7f1d..6f1a141 100644
--- a/sysdeps/unix/sysv/linux/aarch64/ilp32/mmap64.c
+++ b/sysdeps/unix/sysv/linux/aarch64/ilp32/mmap64.c
@@ -1,29 +1 @@
-#include 
-#include 
-#include 
-#include 
-
-#include 
-#include 
-
-/* mmap is provided by mmap as they are the same. */
-void *__mmap (void *__addr, size_t __len, int __prot,
-int __flags, int __fd, __off_t __offset)
-{
-   void *result;
-   result = (void *) INLINE_SYSCALL (mmap2, 6, __addr, __len, __prot, __flags,
-   return result;
-}
-/* mmap64 is provided by mmap as they are the same. */
-void *__mmap64 (void *__addr, size_t __len, int __prot,
-int __flags, int __fd, __off64_t __offset)
-{
-   void *result;
-   result = (void *)
- INLINE_SYSCALL (mmap2, 6, __addr,
- __len, __prot, __flags, __fd, __offset);
-   return result;
-}
-weak_alias (__mmap, mmap)
-weak_alias (__mmap64, mmap64)
+#include 

Regards

Bamvor

Arnd





Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-11 Thread Zhangjian (Bamvor)

Hi, Arnd

On 2016/5/11 22:50, Arnd Bergmann wrote:

On Wednesday 11 May 2016 19:16:44 Zhangjian wrote:

Hi,

On 2016/5/11 18:12, Zhangjian (Bamvor) wrote:

Hi, Arnd

On 2016/5/11 16:09, Arnd Bergmann wrote:
  > On Wednesday 11 May 2016 10:04:16 Zhangjian wrote:
  >>> I don't remember. It's probably not important whether we have the shift
  >>> in there, as long as it's independent of the actual kernel page size and
  >>> user space and kernel agree on the calling conventions.
  >> Well. I am ok with where to shift the pages size because we get the same
  >> result. I was just thinking if we should get rid of the name of mmap2 in 
our
  >> ILP32 porting. Actually, it is mmap but we name it as mmap2. User may 
confused
  >> if they do not know the implementations.
  >
  > That is a good point: If the implementation matches the mmap() behavior 
rather than
  > mmap2(), we should rename the macro by doing
  >
  > #undef __NR_mmap2
  > #define __NR_mmap 222
  >
  > in the uapi/asm/unistd.h file for ilp32 mode.
Do you mean define the following things in kernel:
```
diff --git a/arch/arm64/include/uapi/asm/unistd.h 
b/arch/arm64/include/uapi/asm/unistd.h
index 1caadc2..3f79640 100644
--- a/arch/arm64/include/uapi/asm/unistd.h
+++ b/arch/arm64/include/uapi/asm/unistd.h
@@ -14,3 +14,9 @@
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
   #include 
+
+#ifdef __ILP32__
+#undef __NR_mmap2
+#define __NR_mmap 222
+#endif /* #ifdef __ILP32__ */
+
```
Then glibc could call mmap instead of mmap2.
I could not try it now. Because after change off_t to 64bit in glibc, stat
is fail. I may need to revert the stat relative patch.

After revert stat relative patch in glibc, mmap01-mmap14 success. But mmap16
success with segfault. I will investigate it later.

There is pointer and size_t in mmap, so, IIUC, we need to clear the top halves
of register by using COMPAT_SYSCALL_WRAP6.


Correct, good catch!


And after check the function in
arch/s390/kernel/compat_linux.c, I feel that we need to do the same thing for
pread64 and pwrite64.




But I got following error when I try to add
COMPAT_SYSCALL_WRAP4(pread64, unsigned int, fd, char __user *, buf,
size_t, count, loff_t, pos);
COMPAT_SYSCALL_WRAP4(pwrite64, unsigned int, fd, const char __user *, buf,
size_t, count, loff_t, pos);



Hmm, that is indeed tricky. I think COMPAT_SYSCALL_WRAP4 rightfully
refuses the loff_t argument here, as the common case is that this is
not possible.

It works if I apply the following patch, I defined the wrong `__TYPE_IS_xxx`
yesterday. Should we merge this into ILP32 series or send the compat.h
and syscalls.h individually? The current series of ILP32 is a little bit
long and hard to review.
diff --git a/include/linux/compat.h b/include/linux/compat.h
index ba6ebe0..22a9565 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -747,7 +747,8 @@ asmlinkage long compat_sys_fanotify_mark(int, unsigned int, 
__u32, __u32,
 #ifndef __SC_COMPAT_CAST
 #define __SC_COMPAT_CAST(t, a) ({  \
BUILD_BUG_ON((sizeof(t) > 4) && !__TYPE_IS_L(t) &&  \
-!__TYPE_IS_UL(t) && !__TYPE_IS_PTR(t));\
+!__TYPE_IS_UL(t) && !__TYPE_IS_PTR(t) &&   \
+!__TYPE_IS_LOFFT(t));  \
((t) ((t)(-1) < 0 ? (s64)(s32)(a) : (u64)(u32)(a)));\
 })
 #endif
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 6e57d9c..66eb85d 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -47,6 +47,7 @@
 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
 #define __TYPE_IS_UL(t)(__same_type((t)0, 0UL))
 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
+#define __TYPE_IS_LOFFT(t) (__same_type((t)0, (loff_t)0))
 #define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 
0L)) a
 #define __SC_CAST(t, a)(t) a
 #define __SC_ARGS(t, a)a
diff --git a/kernel/compat_wrapper.c b/kernel/compat_wrapper.c
index 98b68b8..28f02d0 100644
--- a/kernel/compat_wrapper.c
+++ b/kernel/compat_wrapper.c
@@ -304,3 +304,7 @@ COMPAT_SYSCALL_WRAP3(getpeername, int, fd, struct sockaddr 
__user *, usockaddr,
 COMPAT_SYSCALL_WRAP6(sendto, int, fd, void __user *, buff, size_t, len,
 unsigned int, flags, struct sockaddr __user *, addr,
 int, addr_len);
+COMPAT_SYSCALL_WRAP4(pread64, unsigned int, fd, char __user *, buf,
+   size_t, count, loff_t, pos);
+COMPAT_SYSCALL_WRAP4(pwrite64, unsigned int, fd, const char __user *, buf,
+size_t, count, loff_t, pos);
>
> Can you open-code this using a COMPAT_SYSCALL4 definition similar to what
> arch/tile has, but without the merging of the t

Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-11 Thread Zhangjian (Bamvor)

Hi, Arnd

On 2016/5/11 22:50, Arnd Bergmann wrote:

On Wednesday 11 May 2016 19:16:44 Zhangjian wrote:

Hi,

On 2016/5/11 18:12, Zhangjian (Bamvor) wrote:

Hi, Arnd

On 2016/5/11 16:09, Arnd Bergmann wrote:
  > On Wednesday 11 May 2016 10:04:16 Zhangjian wrote:
  >>> I don't remember. It's probably not important whether we have the shift
  >>> in there, as long as it's independent of the actual kernel page size and
  >>> user space and kernel agree on the calling conventions.
  >> Well. I am ok with where to shift the pages size because we get the same
  >> result. I was just thinking if we should get rid of the name of mmap2 in 
our
  >> ILP32 porting. Actually, it is mmap but we name it as mmap2. User may 
confused
  >> if they do not know the implementations.
  >
  > That is a good point: If the implementation matches the mmap() behavior 
rather than
  > mmap2(), we should rename the macro by doing
  >
  > #undef __NR_mmap2
  > #define __NR_mmap 222
  >
  > in the uapi/asm/unistd.h file for ilp32 mode.
Do you mean define the following things in kernel:
```
diff --git a/arch/arm64/include/uapi/asm/unistd.h 
b/arch/arm64/include/uapi/asm/unistd.h
index 1caadc2..3f79640 100644
--- a/arch/arm64/include/uapi/asm/unistd.h
+++ b/arch/arm64/include/uapi/asm/unistd.h
@@ -14,3 +14,9 @@
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
   #include 
+
+#ifdef __ILP32__
+#undef __NR_mmap2
+#define __NR_mmap 222
+#endif /* #ifdef __ILP32__ */
+
```
Then glibc could call mmap instead of mmap2.
I could not try it now. Because after change off_t to 64bit in glibc, stat
is fail. I may need to revert the stat relative patch.

After revert stat relative patch in glibc, mmap01-mmap14 success. But mmap16
success with segfault. I will investigate it later.

There is pointer and size_t in mmap, so, IIUC, we need to clear the top halves
of register by using COMPAT_SYSCALL_WRAP6.


Correct, good catch!


And after check the function in
arch/s390/kernel/compat_linux.c, I feel that we need to do the same thing for
pread64 and pwrite64.




But I got following error when I try to add
COMPAT_SYSCALL_WRAP4(pread64, unsigned int, fd, char __user *, buf,
size_t, count, loff_t, pos);
COMPAT_SYSCALL_WRAP4(pwrite64, unsigned int, fd, const char __user *, buf,
size_t, count, loff_t, pos);



Hmm, that is indeed tricky. I think COMPAT_SYSCALL_WRAP4 rightfully
refuses the loff_t argument here, as the common case is that this is
not possible.

It works if I apply the following patch, I defined the wrong `__TYPE_IS_xxx`
yesterday. Should we merge this into ILP32 series or send the compat.h
and syscalls.h individually? The current series of ILP32 is a little bit
long and hard to review.
diff --git a/include/linux/compat.h b/include/linux/compat.h
index ba6ebe0..22a9565 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -747,7 +747,8 @@ asmlinkage long compat_sys_fanotify_mark(int, unsigned int, 
__u32, __u32,
 #ifndef __SC_COMPAT_CAST
 #define __SC_COMPAT_CAST(t, a) ({  \
BUILD_BUG_ON((sizeof(t) > 4) && !__TYPE_IS_L(t) &&  \
-!__TYPE_IS_UL(t) && !__TYPE_IS_PTR(t));\
+!__TYPE_IS_UL(t) && !__TYPE_IS_PTR(t) &&   \
+!__TYPE_IS_LOFFT(t));  \
((t) ((t)(-1) < 0 ? (s64)(s32)(a) : (u64)(u32)(a)));\
 })
 #endif
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 6e57d9c..66eb85d 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -47,6 +47,7 @@
 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
 #define __TYPE_IS_UL(t)(__same_type((t)0, 0UL))
 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
+#define __TYPE_IS_LOFFT(t) (__same_type((t)0, (loff_t)0))
 #define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 
0L)) a
 #define __SC_CAST(t, a)(t) a
 #define __SC_ARGS(t, a)a
diff --git a/kernel/compat_wrapper.c b/kernel/compat_wrapper.c
index 98b68b8..28f02d0 100644
--- a/kernel/compat_wrapper.c
+++ b/kernel/compat_wrapper.c
@@ -304,3 +304,7 @@ COMPAT_SYSCALL_WRAP3(getpeername, int, fd, struct sockaddr 
__user *, usockaddr,
 COMPAT_SYSCALL_WRAP6(sendto, int, fd, void __user *, buff, size_t, len,
 unsigned int, flags, struct sockaddr __user *, addr,
 int, addr_len);
+COMPAT_SYSCALL_WRAP4(pread64, unsigned int, fd, char __user *, buf,
+   size_t, count, loff_t, pos);
+COMPAT_SYSCALL_WRAP4(pwrite64, unsigned int, fd, const char __user *, buf,
+size_t, count, loff_t, pos);
>
> Can you open-code this using a COMPAT_SYSCALL4 definition similar to what
> arch/tile has, but without the merging of the t

Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-11 Thread Zhangjian (Bamvor)

Hi,

On 2016/5/11 18:12, Zhangjian (Bamvor) wrote:

Hi, Arnd

On 2016/5/11 16:09, Arnd Bergmann wrote:
 > On Wednesday 11 May 2016 10:04:16 Zhangjian wrote:
 >>> I don't remember. It's probably not important whether we have the shift
 >>> in there, as long as it's independent of the actual kernel page size and
 >>> user space and kernel agree on the calling conventions.
 >> Well. I am ok with where to shift the pages size because we get the same
 >> result. I was just thinking if we should get rid of the name of mmap2 in our
 >> ILP32 porting. Actually, it is mmap but we name it as mmap2. User may 
confused
 >> if they do not know the implementations.
 >
 > That is a good point: If the implementation matches the mmap() behavior 
rather than
 > mmap2(), we should rename the macro by doing
 >
 > #undef __NR_mmap2
 > #define __NR_mmap 222
 >
 > in the uapi/asm/unistd.h file for ilp32 mode.
Do you mean define the following things in kernel:
```
diff --git a/arch/arm64/include/uapi/asm/unistd.h 
b/arch/arm64/include/uapi/asm/unistd.h
index 1caadc2..3f79640 100644
--- a/arch/arm64/include/uapi/asm/unistd.h
+++ b/arch/arm64/include/uapi/asm/unistd.h
@@ -14,3 +14,9 @@
   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   */
  #include 
+
+#ifdef __ILP32__
+#undef __NR_mmap2
+#define __NR_mmap 222
+#endif /* #ifdef __ILP32__ */
+
```
Then glibc could call mmap instead of mmap2.
I could not try it now. Because after change off_t to 64bit in glibc, stat
is fail. I may need to revert the stat relative patch.

After revert stat relative patch in glibc, mmap01-mmap14 success. But mmap16
success with segfault. I will investigate it later.

There is pointer and size_t in mmap, so, IIUC, we need to clear the top halves
of register by using COMPAT_SYSCALL_WRAP6. And after check the function in
arch/s390/kernel/compat_linux.c, I feel that we need to do the same thing for
pread64 and pwrite64.

But I got following error when I try to add
COMPAT_SYSCALL_WRAP4(pread64, unsigned int, fd, char __user *, buf,
size_t, count, loff_t, pos);
COMPAT_SYSCALL_WRAP4(pwrite64, unsigned int, fd, const char __user *, buf,
size_t, count, loff_t, pos);

The error message:
kernel/compat_wrapper.c: In function 'compat_SyS_pread64':
include/linux/compiler.h:429:38: error: call to '__compiletime_assert_308' declared with attribute error: 
BUILD_BUG_ON failed: (sizeof(loff_t) > 4) && !__TYPE_IS_L(loff_t) && 
!__TYPE_IS_UL(loff_t) && !__TYPE_IS_PTR(loff_t)
_compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
^
include/linux/compiler.h:412:4: note: in definition of macro 
'__compiletime_assert'
prefix ## suffix(); \
^
include/linux/compiler.h:429:2: note: in expansion of macro 
'_compiletime_assert'
_compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
^
include/linux/bug.h:50:37: note: in expansion of macro 'compiletime_assert'
#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
^
include/linux/bug.h:74:2: note: in expansion of macro 'BUILD_BUG_ON_MSG'
BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
^
include/linux/compat.h:749:2: note: in expansion of macro 'BUILD_BUG_ON'
BUILD_BUG_ON((sizeof(t) > 4) && !__TYPE_IS_L(t) && \
^
include/linux/syscalls.h:38:23: note: in expansion of macro '__SC_COMPAT_CAST'
#define __MAP1(m,t,a) m(t,a)
^
include/linux/syscalls.h:39:35: note: in expansion of macro '__MAP1'
#define __MAP2(m,t,a,...) m(t,a), __MAP1(m,__VA_ARGS__)
^
include/linux/syscalls.h:40:35: note: in expansion of macro '__MAP2'
#define __MAP3(m,t,a,...) m(t,a), __MAP2(m,__VA_ARGS__)
^
include/linux/syscalls.h:41:35: note: in expansion of macro '__MAP3'
#define __MAP4(m,t,a,...) m(t,a), __MAP3(m,__VA_ARGS__)
^
include/linux/syscalls.h:44:22: note: in expansion of macro '__MAP4'
#define __MAP(n,...) __MAP##n(__VA_ARGS__)
^
include/linux/compat.h:777:19: note: in expansion of macro '__MAP'
return sys##name(__MAP(x, __SC_COMPAT_CAST, __VA_ARGS__)); \
^
include/linux/compat.h:735:41: note: in expansion of macro 
'COMPAT_SYSCALL_WRAPx'
#define COMPAT_SYSCALL_WRAP4(name, ...) COMPAT_SYSCALL_WRAPx(4, _##name,\
^
kernel/compat_wrapper.c:307:1: note: in expansion of macro 
'COMPAT_SYSCALL_WRAP4'
COMPAT_SYSCALL_WRAP4(pread64, unsigned int, fd, char __user *, buf,
^

Because the loff_t is not the long, unsigned long or pointer.

Regards

Bamvor

 > Alternatively we can keep the
 > __NR_mmap2 definition but then we need to pass the pgoff (value shifted by
 > 12 bits) argument rather than the size in bytes.
It means that we could reuse the existing code of mmap2 in kernel and glibc.
But we need to shift twice when kernel is 64k page.
It seems that the first method is more clear. Suggestion?

Regards

Bamvor
 >
 >   Arnd
 >





Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-11 Thread Zhangjian (Bamvor)

Hi,

On 2016/5/11 18:12, Zhangjian (Bamvor) wrote:

Hi, Arnd

On 2016/5/11 16:09, Arnd Bergmann wrote:
 > On Wednesday 11 May 2016 10:04:16 Zhangjian wrote:
 >>> I don't remember. It's probably not important whether we have the shift
 >>> in there, as long as it's independent of the actual kernel page size and
 >>> user space and kernel agree on the calling conventions.
 >> Well. I am ok with where to shift the pages size because we get the same
 >> result. I was just thinking if we should get rid of the name of mmap2 in our
 >> ILP32 porting. Actually, it is mmap but we name it as mmap2. User may 
confused
 >> if they do not know the implementations.
 >
 > That is a good point: If the implementation matches the mmap() behavior 
rather than
 > mmap2(), we should rename the macro by doing
 >
 > #undef __NR_mmap2
 > #define __NR_mmap 222
 >
 > in the uapi/asm/unistd.h file for ilp32 mode.
Do you mean define the following things in kernel:
```
diff --git a/arch/arm64/include/uapi/asm/unistd.h 
b/arch/arm64/include/uapi/asm/unistd.h
index 1caadc2..3f79640 100644
--- a/arch/arm64/include/uapi/asm/unistd.h
+++ b/arch/arm64/include/uapi/asm/unistd.h
@@ -14,3 +14,9 @@
   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   */
  #include 
+
+#ifdef __ILP32__
+#undef __NR_mmap2
+#define __NR_mmap 222
+#endif /* #ifdef __ILP32__ */
+
```
Then glibc could call mmap instead of mmap2.
I could not try it now. Because after change off_t to 64bit in glibc, stat
is fail. I may need to revert the stat relative patch.

After revert stat relative patch in glibc, mmap01-mmap14 success. But mmap16
success with segfault. I will investigate it later.

There is pointer and size_t in mmap, so, IIUC, we need to clear the top halves
of register by using COMPAT_SYSCALL_WRAP6. And after check the function in
arch/s390/kernel/compat_linux.c, I feel that we need to do the same thing for
pread64 and pwrite64.

But I got following error when I try to add
COMPAT_SYSCALL_WRAP4(pread64, unsigned int, fd, char __user *, buf,
size_t, count, loff_t, pos);
COMPAT_SYSCALL_WRAP4(pwrite64, unsigned int, fd, const char __user *, buf,
size_t, count, loff_t, pos);

The error message:
kernel/compat_wrapper.c: In function 'compat_SyS_pread64':
include/linux/compiler.h:429:38: error: call to '__compiletime_assert_308' declared with attribute error: 
BUILD_BUG_ON failed: (sizeof(loff_t) > 4) && !__TYPE_IS_L(loff_t) && 
!__TYPE_IS_UL(loff_t) && !__TYPE_IS_PTR(loff_t)
_compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
^
include/linux/compiler.h:412:4: note: in definition of macro 
'__compiletime_assert'
prefix ## suffix(); \
^
include/linux/compiler.h:429:2: note: in expansion of macro 
'_compiletime_assert'
_compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
^
include/linux/bug.h:50:37: note: in expansion of macro 'compiletime_assert'
#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
^
include/linux/bug.h:74:2: note: in expansion of macro 'BUILD_BUG_ON_MSG'
BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
^
include/linux/compat.h:749:2: note: in expansion of macro 'BUILD_BUG_ON'
BUILD_BUG_ON((sizeof(t) > 4) && !__TYPE_IS_L(t) && \
^
include/linux/syscalls.h:38:23: note: in expansion of macro '__SC_COMPAT_CAST'
#define __MAP1(m,t,a) m(t,a)
^
include/linux/syscalls.h:39:35: note: in expansion of macro '__MAP1'
#define __MAP2(m,t,a,...) m(t,a), __MAP1(m,__VA_ARGS__)
^
include/linux/syscalls.h:40:35: note: in expansion of macro '__MAP2'
#define __MAP3(m,t,a,...) m(t,a), __MAP2(m,__VA_ARGS__)
^
include/linux/syscalls.h:41:35: note: in expansion of macro '__MAP3'
#define __MAP4(m,t,a,...) m(t,a), __MAP3(m,__VA_ARGS__)
^
include/linux/syscalls.h:44:22: note: in expansion of macro '__MAP4'
#define __MAP(n,...) __MAP##n(__VA_ARGS__)
^
include/linux/compat.h:777:19: note: in expansion of macro '__MAP'
return sys##name(__MAP(x, __SC_COMPAT_CAST, __VA_ARGS__)); \
^
include/linux/compat.h:735:41: note: in expansion of macro 
'COMPAT_SYSCALL_WRAPx'
#define COMPAT_SYSCALL_WRAP4(name, ...) COMPAT_SYSCALL_WRAPx(4, _##name,\
^
kernel/compat_wrapper.c:307:1: note: in expansion of macro 
'COMPAT_SYSCALL_WRAP4'
COMPAT_SYSCALL_WRAP4(pread64, unsigned int, fd, char __user *, buf,
^

Because the loff_t is not the long, unsigned long or pointer.

Regards

Bamvor

 > Alternatively we can keep the
 > __NR_mmap2 definition but then we need to pass the pgoff (value shifted by
 > 12 bits) argument rather than the size in bytes.
It means that we could reuse the existing code of mmap2 in kernel and glibc.
But we need to shift twice when kernel is 64k page.
It seems that the first method is more clear. Suggestion?

Regards

Bamvor
 >
 >   Arnd
 >





Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-11 Thread Zhangjian (Bamvor)

Hi, Arnd

On 2016/5/11 16:09, Arnd Bergmann wrote:
> On Wednesday 11 May 2016 10:04:16 Zhangjian wrote:
>>> I don't remember. It's probably not important whether we have the shift
>>> in there, as long as it's independent of the actual kernel page size and
>>> user space and kernel agree on the calling conventions.
>> Well. I am ok with where to shift the pages size because we get the same
>> result. I was just thinking if we should get rid of the name of mmap2 in our
>> ILP32 porting. Actually, it is mmap but we name it as mmap2. User may 
confused
>> if they do not know the implementations.
>
> That is a good point: If the implementation matches the mmap() behavior 
rather than
> mmap2(), we should rename the macro by doing
>
> #undef __NR_mmap2
> #define __NR_mmap 222
>
> in the uapi/asm/unistd.h file for ilp32 mode.
Do you mean define the following things in kernel:
```
diff --git a/arch/arm64/include/uapi/asm/unistd.h 
b/arch/arm64/include/uapi/asm/unistd.h
index 1caadc2..3f79640 100644
--- a/arch/arm64/include/uapi/asm/unistd.h
+++ b/arch/arm64/include/uapi/asm/unistd.h
@@ -14,3 +14,9 @@
  * along with this program.  If not, see .
  */
 #include 
+
+#ifdef __ILP32__
+#undef __NR_mmap2
+#define __NR_mmap 222
+#endif /* #ifdef __ILP32__ */
+
```
Then glibc could call mmap instead of mmap2.
I could not try it now. Because after change off_t to 64bit in glibc, stat
is fail. I may need to revert the stat relative patch.

> Alternatively we can keep the
> __NR_mmap2 definition but then we need to pass the pgoff (value shifted by
> 12 bits) argument rather than the size in bytes.
It means that we could reuse the existing code of mmap2 in kernel and glibc.
But we need to shift twice when kernel is 64k page.
It seems that the first method is more clear. Suggestion?

Regards

Bamvor
>
>   Arnd
>



Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-11 Thread Zhangjian (Bamvor)

Hi, Arnd

On 2016/5/11 16:09, Arnd Bergmann wrote:
> On Wednesday 11 May 2016 10:04:16 Zhangjian wrote:
>>> I don't remember. It's probably not important whether we have the shift
>>> in there, as long as it's independent of the actual kernel page size and
>>> user space and kernel agree on the calling conventions.
>> Well. I am ok with where to shift the pages size because we get the same
>> result. I was just thinking if we should get rid of the name of mmap2 in our
>> ILP32 porting. Actually, it is mmap but we name it as mmap2. User may 
confused
>> if they do not know the implementations.
>
> That is a good point: If the implementation matches the mmap() behavior 
rather than
> mmap2(), we should rename the macro by doing
>
> #undef __NR_mmap2
> #define __NR_mmap 222
>
> in the uapi/asm/unistd.h file for ilp32 mode.
Do you mean define the following things in kernel:
```
diff --git a/arch/arm64/include/uapi/asm/unistd.h 
b/arch/arm64/include/uapi/asm/unistd.h
index 1caadc2..3f79640 100644
--- a/arch/arm64/include/uapi/asm/unistd.h
+++ b/arch/arm64/include/uapi/asm/unistd.h
@@ -14,3 +14,9 @@
  * along with this program.  If not, see .
  */
 #include 
+
+#ifdef __ILP32__
+#undef __NR_mmap2
+#define __NR_mmap 222
+#endif /* #ifdef __ILP32__ */
+
```
Then glibc could call mmap instead of mmap2.
I could not try it now. Because after change off_t to 64bit in glibc, stat
is fail. I may need to revert the stat relative patch.

> Alternatively we can keep the
> __NR_mmap2 definition but then we need to pass the pgoff (value shifted by
> 12 bits) argument rather than the size in bytes.
It means that we could reuse the existing code of mmap2 in kernel and glibc.
But we need to shift twice when kernel is 64k page.
It seems that the first method is more clear. Suggestion?

Regards

Bamvor
>
>   Arnd
>



Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-10 Thread Zhangjian (Bamvor)

Hi,

On 2016/5/10 20:50, Arnd Bergmann wrote:

On Tuesday 10 May 2016 20:39:41 Zhangjian wrote:

Hi,

On 2016/5/10 19:48, Arnd Bergmann wrote:

On Tuesday 10 May 2016 17:47:26 Zhangjian wrote:

On 2016/5/10 16:36, Arnd Bergmann wrote:

On Tuesday 10 May 2016 15:42:07 Zhangjian wrote:

On 2016/5/6 20:37, Yury Norov wrote:


"include/uapi/asm-generic/posix_types.h" is uapi, we could not check
"ARCH_32BIT_OFF_T" here. Besides, the `__kernel_long_t` is long which
mean it is 32bit in ILP32. should we define something like x32?
   ```
   diff --git a/arch/arm64/include/uapi/asm/posix_types.h 
b/arch/arm64/include/uapi/asm/posix_types.h
   index 7985ff6..9baa8d3 100644
   --- a/arch/arm64/include/uapi/asm/posix_types.h
   +++ b/arch/arm64/include/uapi/asm/posix_types.h


glibc does not use the definition of __kernel_off_t, it has its own
copy, so changing the kernel headers would do nothing.

Yes, I think so. I am puzzle that how do we ensure that all the new
32bit architecture will define off_t as 64bit after introduce
ARCH_32BIT_OFF_T and do not change any other code?


This is for historic reasons: we have two sets of system calls passing
file offsets: the original ones passing a 'long' are named e.g. lseek,
pread, pwrite, fadvise, ...

The replacement syscalls that pass a 'long long' __kernel_loff_t are only
available on 32-bit architectures and have different names, e.g. llseek,
pread64, pwrite64, fadvise64, ...

On 64-bit architectures, we only provide the first set, because
__kernel_off_t was already wide enough. On old 32-bit architectures
we have both, and on new 32-bit architectures we only have the second
set, which lets us use the same definitions on all 32-bit architectures.


   @@ -5,6 +5,9 @@ typedef unsigned short __kernel_old_uid_t;
typedef unsigned short __kernel_old_gid_t;
 #define __kernel_old_uid_t __kernel_old_uid_t

+typedef long long __kernel_long_t;
+typedef unsigned long long __kernel_ulong_t;
+
 #include 

 #endif /*  __ASM_POSIX_TYPES_H */u
   ```


This would break all sorts of things, because __kernel_long_t/__kernel_ulong_t
are not just used for off_t but also other things.

Yes. But if we do not change __kernel_long_t and __kernel_ulong_t, the
application of ilp32 will think size of long in kernel is 32bit. Is that
correct?


No, __kernel_long_t refers to the definition of 'long' in the kernel/user
ABI, not in the kernel (except on the x86-64 "x32" ABI, which is weird).

Thanks, that is answer my question. I ask this because I saw the posix_types.h
for x32.

A 32-bit user space application must not care about how 'long' is defined
in the kernel, it should run on either 32-bit kernels or 64-bit kernels.
We don't have any plans to do an ilp32-mode kernel, but if we ever want
one, it must use the exact same ABI as the 64-bit kernel when running
ilp32 user space.



On the other hand, glibc define it own off_t in "bits/types.h":
   __STD_TYPE __OFF_T_TYPE __off_t;/* Type of file sizes and 
offsets.  */
   __STD_TYPE __OFF64_T_TYPE __off64_t;/* Type of file sizes and 
offsets (LFS).  */

in "sysdeps/unix/sysv/linux/aarch64/bits/typesizes.h":
   #define __OFF_T_TYPE__SLONGWORD_TYPE
   #define __OFF64_T_TYPE  __SQUAD_TYPE

If we define off_t as 64bit in glibc:
   #define __OFF_T_TYPE   __SQUAD_TYPE

Should We need to align all the off_t syscall to 64bit syscall in
kernel?



Yes, this is the change that I think we need to make, along with
the same change for __INO_T_TYPE and

#define __OFF_T_MATCHES_OFF64_T1
#define __INO_T_MATCHES_INO64_T1

If I read the rest of the glibc headers right, that should be all we need
to ensure that both off_t and off64_t match the __kernel_loff_t based
syscalls.

Ok, I will test the ltp syscall test.
With this changes, the issue I mentioned should be fixed. But we still
use mmap2 syscall for ILP32 application when we pass the offset instead
of page offset. Is it correct?


I don't remember. It's probably not important whether we have the shift
in there, as long as it's independent of the actual kernel page size and
user space and kernel agree on the calling conventions.

Well. I am ok with where to shift the pages size because we get the same
result. I was just thinking if we should get rid of the name of mmap2 in our
ILP32 porting. Actually, it is mmap but we name it as mmap2. User may confused
if they do not know the implementations.

Regards

Bamvor



Arnd





Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-10 Thread Zhangjian (Bamvor)

Hi,

On 2016/5/10 20:50, Arnd Bergmann wrote:

On Tuesday 10 May 2016 20:39:41 Zhangjian wrote:

Hi,

On 2016/5/10 19:48, Arnd Bergmann wrote:

On Tuesday 10 May 2016 17:47:26 Zhangjian wrote:

On 2016/5/10 16:36, Arnd Bergmann wrote:

On Tuesday 10 May 2016 15:42:07 Zhangjian wrote:

On 2016/5/6 20:37, Yury Norov wrote:


"include/uapi/asm-generic/posix_types.h" is uapi, we could not check
"ARCH_32BIT_OFF_T" here. Besides, the `__kernel_long_t` is long which
mean it is 32bit in ILP32. should we define something like x32?
   ```
   diff --git a/arch/arm64/include/uapi/asm/posix_types.h 
b/arch/arm64/include/uapi/asm/posix_types.h
   index 7985ff6..9baa8d3 100644
   --- a/arch/arm64/include/uapi/asm/posix_types.h
   +++ b/arch/arm64/include/uapi/asm/posix_types.h


glibc does not use the definition of __kernel_off_t, it has its own
copy, so changing the kernel headers would do nothing.

Yes, I think so. I am puzzle that how do we ensure that all the new
32bit architecture will define off_t as 64bit after introduce
ARCH_32BIT_OFF_T and do not change any other code?


This is for historic reasons: we have two sets of system calls passing
file offsets: the original ones passing a 'long' are named e.g. lseek,
pread, pwrite, fadvise, ...

The replacement syscalls that pass a 'long long' __kernel_loff_t are only
available on 32-bit architectures and have different names, e.g. llseek,
pread64, pwrite64, fadvise64, ...

On 64-bit architectures, we only provide the first set, because
__kernel_off_t was already wide enough. On old 32-bit architectures
we have both, and on new 32-bit architectures we only have the second
set, which lets us use the same definitions on all 32-bit architectures.


   @@ -5,6 +5,9 @@ typedef unsigned short __kernel_old_uid_t;
typedef unsigned short __kernel_old_gid_t;
 #define __kernel_old_uid_t __kernel_old_uid_t

+typedef long long __kernel_long_t;
+typedef unsigned long long __kernel_ulong_t;
+
 #include 

 #endif /*  __ASM_POSIX_TYPES_H */u
   ```


This would break all sorts of things, because __kernel_long_t/__kernel_ulong_t
are not just used for off_t but also other things.

Yes. But if we do not change __kernel_long_t and __kernel_ulong_t, the
application of ilp32 will think size of long in kernel is 32bit. Is that
correct?


No, __kernel_long_t refers to the definition of 'long' in the kernel/user
ABI, not in the kernel (except on the x86-64 "x32" ABI, which is weird).

Thanks, that is answer my question. I ask this because I saw the posix_types.h
for x32.

A 32-bit user space application must not care about how 'long' is defined
in the kernel, it should run on either 32-bit kernels or 64-bit kernels.
We don't have any plans to do an ilp32-mode kernel, but if we ever want
one, it must use the exact same ABI as the 64-bit kernel when running
ilp32 user space.



On the other hand, glibc define it own off_t in "bits/types.h":
   __STD_TYPE __OFF_T_TYPE __off_t;/* Type of file sizes and 
offsets.  */
   __STD_TYPE __OFF64_T_TYPE __off64_t;/* Type of file sizes and 
offsets (LFS).  */

in "sysdeps/unix/sysv/linux/aarch64/bits/typesizes.h":
   #define __OFF_T_TYPE__SLONGWORD_TYPE
   #define __OFF64_T_TYPE  __SQUAD_TYPE

If we define off_t as 64bit in glibc:
   #define __OFF_T_TYPE   __SQUAD_TYPE

Should We need to align all the off_t syscall to 64bit syscall in
kernel?



Yes, this is the change that I think we need to make, along with
the same change for __INO_T_TYPE and

#define __OFF_T_MATCHES_OFF64_T1
#define __INO_T_MATCHES_INO64_T1

If I read the rest of the glibc headers right, that should be all we need
to ensure that both off_t and off64_t match the __kernel_loff_t based
syscalls.

Ok, I will test the ltp syscall test.
With this changes, the issue I mentioned should be fixed. But we still
use mmap2 syscall for ILP32 application when we pass the offset instead
of page offset. Is it correct?


I don't remember. It's probably not important whether we have the shift
in there, as long as it's independent of the actual kernel page size and
user space and kernel agree on the calling conventions.

Well. I am ok with where to shift the pages size because we get the same
result. I was just thinking if we should get rid of the name of mmap2 in our
ILP32 porting. Actually, it is mmap but we name it as mmap2. User may confused
if they do not know the implementations.

Regards

Bamvor



Arnd





Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-10 Thread Zhangjian (Bamvor)

Hi,

On 2016/5/10 19:48, Arnd Bergmann wrote:

On Tuesday 10 May 2016 17:47:26 Zhangjian wrote:

On 2016/5/10 16:36, Arnd Bergmann wrote:

On Tuesday 10 May 2016 15:42:07 Zhangjian wrote:

On 2016/5/6 20:37, Yury Norov wrote:


"include/uapi/asm-generic/posix_types.h" is uapi, we could not check
"ARCH_32BIT_OFF_T" here. Besides, the `__kernel_long_t` is long which
mean it is 32bit in ILP32. should we define something like x32?
  ```
  diff --git a/arch/arm64/include/uapi/asm/posix_types.h 
b/arch/arm64/include/uapi/asm/posix_types.h
  index 7985ff6..9baa8d3 100644
  --- a/arch/arm64/include/uapi/asm/posix_types.h
  +++ b/arch/arm64/include/uapi/asm/posix_types.h


glibc does not use the definition of __kernel_off_t, it has its own
copy, so changing the kernel headers would do nothing.

Yes, I think so. I am puzzle that how do we ensure that all the new
32bit architecture will define off_t as 64bit after introduce
ARCH_32BIT_OFF_T and do not change any other code?



  @@ -5,6 +5,9 @@ typedef unsigned short __kernel_old_uid_t;
   typedef unsigned short __kernel_old_gid_t;
#define __kernel_old_uid_t __kernel_old_uid_t

   +typedef long long __kernel_long_t;
   +typedef unsigned long long __kernel_ulong_t;
   +
#include 

#endif /*  __ASM_POSIX_TYPES_H */u
  ```


This would break all sorts of things, because __kernel_long_t/__kernel_ulong_t
are not just used for off_t but also other things.

Yes. But if we do not change __kernel_long_t and __kernel_ulong_t, the
application of ilp32 will think size of long in kernel is 32bit. Is that
correct?




On the other hand, glibc define it own off_t in "bits/types.h":
  __STD_TYPE __OFF_T_TYPE __off_t;/* Type of file sizes and 
offsets.  */
  __STD_TYPE __OFF64_T_TYPE __off64_t;/* Type of file sizes and offsets 
(LFS).  */

in "sysdeps/unix/sysv/linux/aarch64/bits/typesizes.h":
  #define __OFF_T_TYPE__SLONGWORD_TYPE
  #define __OFF64_T_TYPE  __SQUAD_TYPE

If we define off_t as 64bit in glibc:
  #define __OFF_T_TYPE   __SQUAD_TYPE

Should We need to align all the off_t syscall to 64bit syscall in
kernel?



Yes, this is the change that I think we need to make, along with
the same change for __INO_T_TYPE and

#define __OFF_T_MATCHES_OFF64_T1
#define __INO_T_MATCHES_INO64_T1

If I read the rest of the glibc headers right, that should be all we need
to ensure that both off_t and off64_t match the __kernel_loff_t based
syscalls.

Ok, I will test the ltp syscall test.
With this changes, the issue I mentioned should be fixed. But we still
use mmap2 syscall for ILP32 application when we pass the offset instead
of page offset. Is it correct?

Regards

Bamvor



Arnd





Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-10 Thread Zhangjian (Bamvor)

Hi,

On 2016/5/10 19:48, Arnd Bergmann wrote:

On Tuesday 10 May 2016 17:47:26 Zhangjian wrote:

On 2016/5/10 16:36, Arnd Bergmann wrote:

On Tuesday 10 May 2016 15:42:07 Zhangjian wrote:

On 2016/5/6 20:37, Yury Norov wrote:


"include/uapi/asm-generic/posix_types.h" is uapi, we could not check
"ARCH_32BIT_OFF_T" here. Besides, the `__kernel_long_t` is long which
mean it is 32bit in ILP32. should we define something like x32?
  ```
  diff --git a/arch/arm64/include/uapi/asm/posix_types.h 
b/arch/arm64/include/uapi/asm/posix_types.h
  index 7985ff6..9baa8d3 100644
  --- a/arch/arm64/include/uapi/asm/posix_types.h
  +++ b/arch/arm64/include/uapi/asm/posix_types.h


glibc does not use the definition of __kernel_off_t, it has its own
copy, so changing the kernel headers would do nothing.

Yes, I think so. I am puzzle that how do we ensure that all the new
32bit architecture will define off_t as 64bit after introduce
ARCH_32BIT_OFF_T and do not change any other code?



  @@ -5,6 +5,9 @@ typedef unsigned short __kernel_old_uid_t;
   typedef unsigned short __kernel_old_gid_t;
#define __kernel_old_uid_t __kernel_old_uid_t

   +typedef long long __kernel_long_t;
   +typedef unsigned long long __kernel_ulong_t;
   +
#include 

#endif /*  __ASM_POSIX_TYPES_H */u
  ```


This would break all sorts of things, because __kernel_long_t/__kernel_ulong_t
are not just used for off_t but also other things.

Yes. But if we do not change __kernel_long_t and __kernel_ulong_t, the
application of ilp32 will think size of long in kernel is 32bit. Is that
correct?




On the other hand, glibc define it own off_t in "bits/types.h":
  __STD_TYPE __OFF_T_TYPE __off_t;/* Type of file sizes and 
offsets.  */
  __STD_TYPE __OFF64_T_TYPE __off64_t;/* Type of file sizes and offsets 
(LFS).  */

in "sysdeps/unix/sysv/linux/aarch64/bits/typesizes.h":
  #define __OFF_T_TYPE__SLONGWORD_TYPE
  #define __OFF64_T_TYPE  __SQUAD_TYPE

If we define off_t as 64bit in glibc:
  #define __OFF_T_TYPE   __SQUAD_TYPE

Should We need to align all the off_t syscall to 64bit syscall in
kernel?



Yes, this is the change that I think we need to make, along with
the same change for __INO_T_TYPE and

#define __OFF_T_MATCHES_OFF64_T1
#define __INO_T_MATCHES_INO64_T1

If I read the rest of the glibc headers right, that should be all we need
to ensure that both off_t and off64_t match the __kernel_loff_t based
syscalls.

Ok, I will test the ltp syscall test.
With this changes, the issue I mentioned should be fixed. But we still
use mmap2 syscall for ILP32 application when we pass the offset instead
of page offset. Is it correct?

Regards

Bamvor



Arnd





Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-10 Thread Zhangjian (Bamvor)

Hi, Arnd

On 2016/5/10 16:36, Arnd Bergmann wrote:

On Tuesday 10 May 2016 15:42:07 Zhangjian wrote:

On 2016/5/6 20:37, Yury Norov wrote:

On Fri, May 06, 2016 at 08:16:48PM +0800, Zhangjian (Bamvor) wrote:

AFAIR, here we don't shift offset, as it's 64-bit both in user-
and kernel-space,

In your ilp32-2.22 branch, you wrapper mmap to mmap2 in which type of
offset is off_t. And off_t is 32bit in ilp32, correct?
"sysdeps/unix/sysv/linux/aarch64/ilp32/mmap64.c"
/* mmap is provided by mmap as they are the same. */
void *__mmap (void *__addr, size_t __len, int __prot,
   int __flags, int __fd, __off_t __offset)
{
 void *result;
 result = (void *)
   INLINE_SYSCALL (mmap2, 6, __addr,
   __len, __prot, __flags, __fd, __offset);
 return result;
}


__off_t should be 'long long' on new architectures, and map
to __kernel_loff_t.

Can you see how it is defined?

For kernel part, in "include/uapi/asm-generic/posix_types.h":
#ifndef __kernel_long_t
typedef long__kernel_long_t;
typedef unsigned long   __kernel_ulong_t;
#endif
typedef __kernel_long_t __kernel_off_t;
in "include/linux/types.h":
typedef __kernel_off_t  off_t;

"include/uapi/asm-generic/posix_types.h" is uapi, we could not check
"ARCH_32BIT_OFF_T" here. Besides, the `__kernel_long_t` is long which
mean it is 32bit in ILP32. should we define something like x32?
```
diff --git a/arch/arm64/include/uapi/asm/posix_types.h 
b/arch/arm64/include/uapi/asm/posix_types.h
index 7985ff6..9baa8d3 100644
--- a/arch/arm64/include/uapi/asm/posix_types.h
+++ b/arch/arm64/include/uapi/asm/posix_types.h
@@ -5,6 +5,9 @@ typedef unsigned short __kernel_old_uid_t;
 typedef unsigned short __kernel_old_gid_t;
  #define __kernel_old_uid_t __kernel_old_uid_t

 +typedef long long __kernel_long_t;
 +typedef unsigned long long __kernel_ulong_t;
 +
  #include 

  #endif /*  __ASM_POSIX_TYPES_H */u
```
After this definition, the following kernel types is 64bit in ILP32:
typedef __kernel_long_t __kernel_suseconds_t;
typedef __kernel_long_t __kernel_ssize_t;
typedef __kernel_long_t __kernel_ptrdiff_t;
typedef __kernel_long_t __kernel_off_t;
typedef __kernel_long_t __kernel_time_t;
typedef __kernel_long_t __kernel_clock_t;
typedef __kernel_ulong_t __kernel_ino_t;
typedef __kernel_ulong_t __kernel_size_t;

But it is not a generic way to define off_t to 64bit if
ARCH_32BIT_OFF_T is not defined. How about this one? We need to
define `__kernel_off_t` on all the old 32bit architecture like
arm:
```
diff --git a/arch/arm/include/uapi/asm/posix_types.h 
b/arch/arm/include/uapi/asm/posix_types.h
index d2de9cb..f9d065c 100644
--- a/arch/arm/include/uapi/asm/posix_types.h
+++ b/arch/arm/include/uapi/asm/posix_types.h
@@ -32,6 +32,9 @@ typedef unsigned short__kernel_gid_t;
 typedef unsigned short __kernel_old_dev_t;
 #define __kernel_old_dev_t __kernel_old_dev_t

+typedef __kernel_long_t__kernel_off_t;
+#define __kernel_off_t
+
 #include 

 #endif
```
And We could change the generic posix_types.h a little bit:
```
diff --git a/include/uapi/asm-generic/posix_types.h 
b/include/uapi/asm-generic/posix_types.h
index fe74fcc..7bbaf04 100644
--- a/include/uapi/asm-generic/posix_types.h
+++ b/include/uapi/asm-generic/posix_types.h
@@ -80,10 +80,13 @@ typedef struct {
 } __kernel_fsid_t;
 #endif

+#ifndef __kernel_off_t
+typedef long long __kernel_off_t;
+#endif
+
 /*
  * anything below here should be completely generic
  */
-typedef __kernel_long_t__kernel_off_t;
 typedef long long  __kernel_loff_t;
 typedef __kernel_long_t__kernel_time_t;
 typedef __kernel_long_t__kernel_clock_t;
```

On the other hand, glibc define it own off_t in "bits/types.h":
__STD_TYPE __OFF_T_TYPE __off_t;/* Type of file sizes and offsets.  
*/
__STD_TYPE __OFF64_T_TYPE __off64_t;/* Type of file sizes and offsets 
(LFS).  */

in "sysdeps/unix/sysv/linux/aarch64/bits/typesizes.h":
#define __OFF_T_TYPE__SLONGWORD_TYPE
#define __OFF64_T_TYPE  __SQUAD_TYPE

If we define off_t as 64bit in glibc:
#define __OFF_T_TYPE   __SQUAD_TYPE

Should We need to align all the off_t syscall to 64bit syscall in
kernel?

Regards

Bamvor



Arnd





Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-10 Thread Zhangjian (Bamvor)

Hi, Arnd

On 2016/5/10 16:36, Arnd Bergmann wrote:

On Tuesday 10 May 2016 15:42:07 Zhangjian wrote:

On 2016/5/6 20:37, Yury Norov wrote:

On Fri, May 06, 2016 at 08:16:48PM +0800, Zhangjian (Bamvor) wrote:

AFAIR, here we don't shift offset, as it's 64-bit both in user-
and kernel-space,

In your ilp32-2.22 branch, you wrapper mmap to mmap2 in which type of
offset is off_t. And off_t is 32bit in ilp32, correct?
"sysdeps/unix/sysv/linux/aarch64/ilp32/mmap64.c"
/* mmap is provided by mmap as they are the same. */
void *__mmap (void *__addr, size_t __len, int __prot,
   int __flags, int __fd, __off_t __offset)
{
 void *result;
 result = (void *)
   INLINE_SYSCALL (mmap2, 6, __addr,
   __len, __prot, __flags, __fd, __offset);
 return result;
}


__off_t should be 'long long' on new architectures, and map
to __kernel_loff_t.

Can you see how it is defined?

For kernel part, in "include/uapi/asm-generic/posix_types.h":
#ifndef __kernel_long_t
typedef long__kernel_long_t;
typedef unsigned long   __kernel_ulong_t;
#endif
typedef __kernel_long_t __kernel_off_t;
in "include/linux/types.h":
typedef __kernel_off_t  off_t;

"include/uapi/asm-generic/posix_types.h" is uapi, we could not check
"ARCH_32BIT_OFF_T" here. Besides, the `__kernel_long_t` is long which
mean it is 32bit in ILP32. should we define something like x32?
```
diff --git a/arch/arm64/include/uapi/asm/posix_types.h 
b/arch/arm64/include/uapi/asm/posix_types.h
index 7985ff6..9baa8d3 100644
--- a/arch/arm64/include/uapi/asm/posix_types.h
+++ b/arch/arm64/include/uapi/asm/posix_types.h
@@ -5,6 +5,9 @@ typedef unsigned short __kernel_old_uid_t;
 typedef unsigned short __kernel_old_gid_t;
  #define __kernel_old_uid_t __kernel_old_uid_t

 +typedef long long __kernel_long_t;
 +typedef unsigned long long __kernel_ulong_t;
 +
  #include 

  #endif /*  __ASM_POSIX_TYPES_H */u
```
After this definition, the following kernel types is 64bit in ILP32:
typedef __kernel_long_t __kernel_suseconds_t;
typedef __kernel_long_t __kernel_ssize_t;
typedef __kernel_long_t __kernel_ptrdiff_t;
typedef __kernel_long_t __kernel_off_t;
typedef __kernel_long_t __kernel_time_t;
typedef __kernel_long_t __kernel_clock_t;
typedef __kernel_ulong_t __kernel_ino_t;
typedef __kernel_ulong_t __kernel_size_t;

But it is not a generic way to define off_t to 64bit if
ARCH_32BIT_OFF_T is not defined. How about this one? We need to
define `__kernel_off_t` on all the old 32bit architecture like
arm:
```
diff --git a/arch/arm/include/uapi/asm/posix_types.h 
b/arch/arm/include/uapi/asm/posix_types.h
index d2de9cb..f9d065c 100644
--- a/arch/arm/include/uapi/asm/posix_types.h
+++ b/arch/arm/include/uapi/asm/posix_types.h
@@ -32,6 +32,9 @@ typedef unsigned short__kernel_gid_t;
 typedef unsigned short __kernel_old_dev_t;
 #define __kernel_old_dev_t __kernel_old_dev_t

+typedef __kernel_long_t__kernel_off_t;
+#define __kernel_off_t
+
 #include 

 #endif
```
And We could change the generic posix_types.h a little bit:
```
diff --git a/include/uapi/asm-generic/posix_types.h 
b/include/uapi/asm-generic/posix_types.h
index fe74fcc..7bbaf04 100644
--- a/include/uapi/asm-generic/posix_types.h
+++ b/include/uapi/asm-generic/posix_types.h
@@ -80,10 +80,13 @@ typedef struct {
 } __kernel_fsid_t;
 #endif

+#ifndef __kernel_off_t
+typedef long long __kernel_off_t;
+#endif
+
 /*
  * anything below here should be completely generic
  */
-typedef __kernel_long_t__kernel_off_t;
 typedef long long  __kernel_loff_t;
 typedef __kernel_long_t__kernel_time_t;
 typedef __kernel_long_t__kernel_clock_t;
```

On the other hand, glibc define it own off_t in "bits/types.h":
__STD_TYPE __OFF_T_TYPE __off_t;/* Type of file sizes and offsets.  
*/
__STD_TYPE __OFF64_T_TYPE __off64_t;/* Type of file sizes and offsets 
(LFS).  */

in "sysdeps/unix/sysv/linux/aarch64/bits/typesizes.h":
#define __OFF_T_TYPE__SLONGWORD_TYPE
#define __OFF64_T_TYPE  __SQUAD_TYPE

If we define off_t as 64bit in glibc:
#define __OFF_T_TYPE   __SQUAD_TYPE

Should We need to align all the off_t syscall to 64bit syscall in
kernel?

Regards

Bamvor



Arnd





Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-10 Thread Zhangjian (Bamvor)

Hi,

Sorry I forget to paste my test code:

#include 
#include 
#include 
#include 

#define TEMPFILE "mmapfile"

int main(int argc, char *argv[])
{
int fd;
void *addr;
unsigned long offset;
unsigned long size;

if (argc == 3) {
if (argv[1][0] == '0' && argv[1][1] == 'x')
offset = strtoll([1][2], NULL, 16);
else
offset = atoi(argv[1]);

if (argv[2][0] == '0' && argv[2][1] == 'x')
size = strtoll([2][2], NULL, 16);
else
size = atoi(argv[2]);
} else {
exit(2);
}

printf("page size<0x%x>, offset is <0x%x>\n", size, offset);
//  if ((fd = open(TEMPFILE, O_RDWR | O_CREAT, 0666)) < 0) {
//  fprintf(stderr, "opening %s failed\n", TEMPFILE);
//  exit(2);
//  }
fd = open("/dev/mem", O_RDWR | O_SYNC);
if (-1 == fd)
{
printf( "open /dev/mem fail!\n" );
return 1;
}

//addr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, 
fd, offset);
addr = mmap(0, size, PROT_READ, MAP_FILE | MAP_SHARED, fd, offset);
if(addr == MAP_FAILED) {
fprintf(stderr, "mmap of %s failed\n", TEMPFILE);
exit(2);
}
printf("addr: <0x%x>\n", addr);

return 0;
}

Regards

Bamvor

On 2016/5/10 15:42, Zhangjian (Bamvor) wrote:

Hi, Yury

On 2016/5/6 20:37, Yury Norov wrote:

On Fri, May 06, 2016 at 08:16:48PM +0800, Zhangjian (Bamvor) wrote:

Hi,

On 2016/4/6 6:08, Yury Norov wrote:

From: Andrew Pinski <apin...@cavium.com>

Add a separate syscall-table for ILP32, which dispatches either to native
LP64 system call implementation or to compat-syscalls, as appropriate.

Signed-off-by: Andrew Pinski <andrew.pin...@caviumnetworks.com>
Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
  arch/arm64/include/asm/unistd.h | 11 ++-
  arch/arm64/kernel/Makefile  |  2 +-
  arch/arm64/kernel/entry.S   | 12 +++-
  arch/arm64/kernel/sys_ilp32.c   | 65 +
  4 files changed, 87 insertions(+), 3 deletions(-)
  create mode 100644 arch/arm64/kernel/sys_ilp32.c

diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h
index 2971dea..5ea18ef 100644
--- a/arch/arm64/include/asm/unistd.h
+++ b/arch/arm64/include/asm/unistd.h
@@ -13,9 +13,18 @@
   * You should have received a copy of the GNU General Public License
   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   */
+
+#ifdef CONFIG_COMPAT
+#define __ARCH_WANT_COMPAT_STAT64
+#endif
+
+#ifdef CONFIG_ARM64_ILP32
+#define __ARCH_WANT_COMPAT_SYS_PREADV64
+#define __ARCH_WANT_COMPAT_SYS_PWRITEV64
+#endif
+
  #ifdef CONFIG_AARCH32_EL0
  #define __ARCH_WANT_COMPAT_SYS_GETDENTS64
-#define __ARCH_WANT_COMPAT_STAT64
  #define __ARCH_WANT_SYS_GETHOSTNAME
  #define __ARCH_WANT_SYS_PAUSE
  #define __ARCH_WANT_SYS_GETPGRP
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 9dfdf86..7aa65ea 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -28,7 +28,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
  arm64-obj-$(CONFIG_AARCH32_EL0)+= sys32.o kuser32.o signal32.o \
 sys_compat.o entry32.o\
 ../../arm/kernel/opcodes.o binfmt_elf32.o
-arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o
+arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o sys_ilp32.o
  arm64-obj-$(CONFIG_FUNCTION_TRACER)+= ftrace.o entry-ftrace.o
  arm64-obj-$(CONFIG_MODULES)+= arm64ksyms.o module.o
  arm64-obj-$(CONFIG_ARM64_MODULE_PLTS)+= module-plts.o
diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
index cf4d1ae..1f7a145 100644
--- a/arch/arm64/kernel/entry.S
+++ b/arch/arm64/kernel/entry.S
@@ -715,9 +715,13 @@ ENDPROC(ret_from_fork)
   */
  .align6
  el0_svc:
-adrpstbl, sys_call_table// load syscall table pointer
  uxtwscno, w8// syscall number in w8
  movsc_nr, #__NR_syscalls
+#ifdef CONFIG_ARM64_ILP32
+ldrx16, [tsk, #TI_FLAGS]
+tbnzx16, #TIF_32BIT_AARCH64, el0_ilp32_svc // We are using ILP32
+#endif
+adrpstbl, sys_call_table// load syscall table pointer
  el0_svc_naked:// compat entry point
  stpx0, scno, [sp, #S_ORIG_X0]// save the original x0 and syscall 
number
  enable_dbg_and_irq
@@ -737,6 +741,12 @@ ni_sys:
  bret_fast_syscall
  ENDPROC(el0_svc)

+#ifdef CONFIG_ARM64_ILP32
+el0_ilp32_svc:
+adrpstbl, sys_call_ilp32_table // load syscall table pointer
+b el0_svc_naked
+#endif
+
  /*
   * This is the really s

Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-10 Thread Zhangjian (Bamvor)

Hi,

Sorry I forget to paste my test code:

#include 
#include 
#include 
#include 

#define TEMPFILE "mmapfile"

int main(int argc, char *argv[])
{
int fd;
void *addr;
unsigned long offset;
unsigned long size;

if (argc == 3) {
if (argv[1][0] == '0' && argv[1][1] == 'x')
offset = strtoll([1][2], NULL, 16);
else
offset = atoi(argv[1]);

if (argv[2][0] == '0' && argv[2][1] == 'x')
size = strtoll([2][2], NULL, 16);
else
size = atoi(argv[2]);
} else {
exit(2);
}

printf("page size<0x%x>, offset is <0x%x>\n", size, offset);
//  if ((fd = open(TEMPFILE, O_RDWR | O_CREAT, 0666)) < 0) {
//  fprintf(stderr, "opening %s failed\n", TEMPFILE);
//  exit(2);
//  }
fd = open("/dev/mem", O_RDWR | O_SYNC);
if (-1 == fd)
{
printf( "open /dev/mem fail!\n" );
return 1;
}

//addr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, 
fd, offset);
addr = mmap(0, size, PROT_READ, MAP_FILE | MAP_SHARED, fd, offset);
if(addr == MAP_FAILED) {
fprintf(stderr, "mmap of %s failed\n", TEMPFILE);
exit(2);
}
printf("addr: <0x%x>\n", addr);

return 0;
}

Regards

Bamvor

On 2016/5/10 15:42, Zhangjian (Bamvor) wrote:

Hi, Yury

On 2016/5/6 20:37, Yury Norov wrote:

On Fri, May 06, 2016 at 08:16:48PM +0800, Zhangjian (Bamvor) wrote:

Hi,

On 2016/4/6 6:08, Yury Norov wrote:

From: Andrew Pinski 

Add a separate syscall-table for ILP32, which dispatches either to native
LP64 system call implementation or to compat-syscalls, as appropriate.

Signed-off-by: Andrew Pinski 
Signed-off-by: Yury Norov 
---
  arch/arm64/include/asm/unistd.h | 11 ++-
  arch/arm64/kernel/Makefile  |  2 +-
  arch/arm64/kernel/entry.S   | 12 +++-
  arch/arm64/kernel/sys_ilp32.c   | 65 +
  4 files changed, 87 insertions(+), 3 deletions(-)
  create mode 100644 arch/arm64/kernel/sys_ilp32.c

diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h
index 2971dea..5ea18ef 100644
--- a/arch/arm64/include/asm/unistd.h
+++ b/arch/arm64/include/asm/unistd.h
@@ -13,9 +13,18 @@
   * You should have received a copy of the GNU General Public License
   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   */
+
+#ifdef CONFIG_COMPAT
+#define __ARCH_WANT_COMPAT_STAT64
+#endif
+
+#ifdef CONFIG_ARM64_ILP32
+#define __ARCH_WANT_COMPAT_SYS_PREADV64
+#define __ARCH_WANT_COMPAT_SYS_PWRITEV64
+#endif
+
  #ifdef CONFIG_AARCH32_EL0
  #define __ARCH_WANT_COMPAT_SYS_GETDENTS64
-#define __ARCH_WANT_COMPAT_STAT64
  #define __ARCH_WANT_SYS_GETHOSTNAME
  #define __ARCH_WANT_SYS_PAUSE
  #define __ARCH_WANT_SYS_GETPGRP
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 9dfdf86..7aa65ea 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -28,7 +28,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
  arm64-obj-$(CONFIG_AARCH32_EL0)+= sys32.o kuser32.o signal32.o \
 sys_compat.o entry32.o\
 ../../arm/kernel/opcodes.o binfmt_elf32.o
-arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o
+arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o sys_ilp32.o
  arm64-obj-$(CONFIG_FUNCTION_TRACER)+= ftrace.o entry-ftrace.o
  arm64-obj-$(CONFIG_MODULES)+= arm64ksyms.o module.o
  arm64-obj-$(CONFIG_ARM64_MODULE_PLTS)+= module-plts.o
diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
index cf4d1ae..1f7a145 100644
--- a/arch/arm64/kernel/entry.S
+++ b/arch/arm64/kernel/entry.S
@@ -715,9 +715,13 @@ ENDPROC(ret_from_fork)
   */
  .align6
  el0_svc:
-adrpstbl, sys_call_table// load syscall table pointer
  uxtwscno, w8// syscall number in w8
  movsc_nr, #__NR_syscalls
+#ifdef CONFIG_ARM64_ILP32
+ldrx16, [tsk, #TI_FLAGS]
+tbnzx16, #TIF_32BIT_AARCH64, el0_ilp32_svc // We are using ILP32
+#endif
+adrpstbl, sys_call_table// load syscall table pointer
  el0_svc_naked:// compat entry point
  stpx0, scno, [sp, #S_ORIG_X0]// save the original x0 and syscall 
number
  enable_dbg_and_irq
@@ -737,6 +741,12 @@ ni_sys:
  bret_fast_syscall
  ENDPROC(el0_svc)

+#ifdef CONFIG_ARM64_ILP32
+el0_ilp32_svc:
+adrpstbl, sys_call_ilp32_table // load syscall table pointer
+b el0_svc_naked
+#endif
+
  /*
   * This is the really slow path.  We're going to be doing context
   * switches, and waiting for our parent to respo

Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-10 Thread Zhangjian (Bamvor)

Hi, Yury

On 2016/5/6 20:37, Yury Norov wrote:

On Fri, May 06, 2016 at 08:16:48PM +0800, Zhangjian (Bamvor) wrote:

Hi,

On 2016/4/6 6:08, Yury Norov wrote:

From: Andrew Pinski <apin...@cavium.com>

Add a separate syscall-table for ILP32, which dispatches either to native
LP64 system call implementation or to compat-syscalls, as appropriate.

Signed-off-by: Andrew Pinski <andrew.pin...@caviumnetworks.com>
Signed-off-by: Yury Norov <yno...@caviumnetworks.com>
---
  arch/arm64/include/asm/unistd.h | 11 ++-
  arch/arm64/kernel/Makefile  |  2 +-
  arch/arm64/kernel/entry.S   | 12 +++-
  arch/arm64/kernel/sys_ilp32.c   | 65 +
  4 files changed, 87 insertions(+), 3 deletions(-)
  create mode 100644 arch/arm64/kernel/sys_ilp32.c

diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h
index 2971dea..5ea18ef 100644
--- a/arch/arm64/include/asm/unistd.h
+++ b/arch/arm64/include/asm/unistd.h
@@ -13,9 +13,18 @@
   * You should have received a copy of the GNU General Public License
   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   */
+
+#ifdef CONFIG_COMPAT
+#define __ARCH_WANT_COMPAT_STAT64
+#endif
+
+#ifdef CONFIG_ARM64_ILP32
+#define __ARCH_WANT_COMPAT_SYS_PREADV64
+#define __ARCH_WANT_COMPAT_SYS_PWRITEV64
+#endif
+
  #ifdef CONFIG_AARCH32_EL0
  #define __ARCH_WANT_COMPAT_SYS_GETDENTS64
-#define __ARCH_WANT_COMPAT_STAT64
  #define __ARCH_WANT_SYS_GETHOSTNAME
  #define __ARCH_WANT_SYS_PAUSE
  #define __ARCH_WANT_SYS_GETPGRP
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 9dfdf86..7aa65ea 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -28,7 +28,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
  arm64-obj-$(CONFIG_AARCH32_EL0)   += sys32.o kuser32.o signal32.o 
\
   sys_compat.o entry32.o   
\
   ../../arm/kernel/opcodes.o 
binfmt_elf32.o
-arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o
+arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o sys_ilp32.o
  arm64-obj-$(CONFIG_FUNCTION_TRACER)   += ftrace.o entry-ftrace.o
  arm64-obj-$(CONFIG_MODULES)   += arm64ksyms.o module.o
  arm64-obj-$(CONFIG_ARM64_MODULE_PLTS) += module-plts.o
diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
index cf4d1ae..1f7a145 100644
--- a/arch/arm64/kernel/entry.S
+++ b/arch/arm64/kernel/entry.S
@@ -715,9 +715,13 @@ ENDPROC(ret_from_fork)
   */
.align  6
  el0_svc:
-   adrpstbl, sys_call_table// load syscall table pointer
uxtwscno, w8// syscall number in w8
mov sc_nr, #__NR_syscalls
+#ifdef CONFIG_ARM64_ILP32
+   ldr x16, [tsk, #TI_FLAGS]
+   tbnzx16, #TIF_32BIT_AARCH64, el0_ilp32_svc // We are using ILP32
+#endif
+   adrpstbl, sys_call_table// load syscall table pointer
  el0_svc_naked:// compat entry point
stp x0, scno, [sp, #S_ORIG_X0]  // save the original x0 and 
syscall number
enable_dbg_and_irq
@@ -737,6 +741,12 @@ ni_sys:
b   ret_fast_syscall
  ENDPROC(el0_svc)

+#ifdef CONFIG_ARM64_ILP32
+el0_ilp32_svc:
+   adrpstbl, sys_call_ilp32_table // load syscall table pointer
+   b el0_svc_naked
+#endif
+
/*
 * This is the really slow path.  We're going to be doing context
 * switches, and waiting for our parent to respond.
diff --git a/arch/arm64/kernel/sys_ilp32.c b/arch/arm64/kernel/sys_ilp32.c
new file mode 100644
index 000..0996d8e
--- /dev/null
+++ b/arch/arm64/kernel/sys_ilp32.c
@@ -0,0 +1,65 @@
+/*
+ * AArch64- ILP32 specific system calls implementation
+ *
+ * Copyright (C) 2016 Cavium Inc.
+ * Author: Andrew Pinski <apin...@cavium.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Using non-compat syscalls where necessary */
+#define compat_sys_fadvise64_64sys_fadvise64_64
+#define compat_sys_fallocate   sys_fallocate
+#define compat_sys_ftruncate64 sys_ftruncate
+#define compat_sys_lookup_dcookie  sys_lookup_dcookie
+#define compat_sys_prea

Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-10 Thread Zhangjian (Bamvor)

Hi, Yury

On 2016/5/6 20:37, Yury Norov wrote:

On Fri, May 06, 2016 at 08:16:48PM +0800, Zhangjian (Bamvor) wrote:

Hi,

On 2016/4/6 6:08, Yury Norov wrote:

From: Andrew Pinski 

Add a separate syscall-table for ILP32, which dispatches either to native
LP64 system call implementation or to compat-syscalls, as appropriate.

Signed-off-by: Andrew Pinski 
Signed-off-by: Yury Norov 
---
  arch/arm64/include/asm/unistd.h | 11 ++-
  arch/arm64/kernel/Makefile  |  2 +-
  arch/arm64/kernel/entry.S   | 12 +++-
  arch/arm64/kernel/sys_ilp32.c   | 65 +
  4 files changed, 87 insertions(+), 3 deletions(-)
  create mode 100644 arch/arm64/kernel/sys_ilp32.c

diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h
index 2971dea..5ea18ef 100644
--- a/arch/arm64/include/asm/unistd.h
+++ b/arch/arm64/include/asm/unistd.h
@@ -13,9 +13,18 @@
   * You should have received a copy of the GNU General Public License
   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   */
+
+#ifdef CONFIG_COMPAT
+#define __ARCH_WANT_COMPAT_STAT64
+#endif
+
+#ifdef CONFIG_ARM64_ILP32
+#define __ARCH_WANT_COMPAT_SYS_PREADV64
+#define __ARCH_WANT_COMPAT_SYS_PWRITEV64
+#endif
+
  #ifdef CONFIG_AARCH32_EL0
  #define __ARCH_WANT_COMPAT_SYS_GETDENTS64
-#define __ARCH_WANT_COMPAT_STAT64
  #define __ARCH_WANT_SYS_GETHOSTNAME
  #define __ARCH_WANT_SYS_PAUSE
  #define __ARCH_WANT_SYS_GETPGRP
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 9dfdf86..7aa65ea 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -28,7 +28,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
  arm64-obj-$(CONFIG_AARCH32_EL0)   += sys32.o kuser32.o signal32.o 
\
   sys_compat.o entry32.o   
\
   ../../arm/kernel/opcodes.o 
binfmt_elf32.o
-arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o
+arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o sys_ilp32.o
  arm64-obj-$(CONFIG_FUNCTION_TRACER)   += ftrace.o entry-ftrace.o
  arm64-obj-$(CONFIG_MODULES)   += arm64ksyms.o module.o
  arm64-obj-$(CONFIG_ARM64_MODULE_PLTS) += module-plts.o
diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
index cf4d1ae..1f7a145 100644
--- a/arch/arm64/kernel/entry.S
+++ b/arch/arm64/kernel/entry.S
@@ -715,9 +715,13 @@ ENDPROC(ret_from_fork)
   */
.align  6
  el0_svc:
-   adrpstbl, sys_call_table// load syscall table pointer
uxtwscno, w8// syscall number in w8
mov sc_nr, #__NR_syscalls
+#ifdef CONFIG_ARM64_ILP32
+   ldr x16, [tsk, #TI_FLAGS]
+   tbnzx16, #TIF_32BIT_AARCH64, el0_ilp32_svc // We are using ILP32
+#endif
+   adrpstbl, sys_call_table// load syscall table pointer
  el0_svc_naked:// compat entry point
stp x0, scno, [sp, #S_ORIG_X0]  // save the original x0 and 
syscall number
enable_dbg_and_irq
@@ -737,6 +741,12 @@ ni_sys:
b   ret_fast_syscall
  ENDPROC(el0_svc)

+#ifdef CONFIG_ARM64_ILP32
+el0_ilp32_svc:
+   adrpstbl, sys_call_ilp32_table // load syscall table pointer
+   b el0_svc_naked
+#endif
+
/*
 * This is the really slow path.  We're going to be doing context
 * switches, and waiting for our parent to respond.
diff --git a/arch/arm64/kernel/sys_ilp32.c b/arch/arm64/kernel/sys_ilp32.c
new file mode 100644
index 000..0996d8e
--- /dev/null
+++ b/arch/arm64/kernel/sys_ilp32.c
@@ -0,0 +1,65 @@
+/*
+ * AArch64- ILP32 specific system calls implementation
+ *
+ * Copyright (C) 2016 Cavium Inc.
+ * Author: Andrew Pinski 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Using non-compat syscalls where necessary */
+#define compat_sys_fadvise64_64sys_fadvise64_64
+#define compat_sys_fallocate   sys_fallocate
+#define compat_sys_ftruncate64 sys_ftruncate
+#define compat_sys_lookup_dcookie  sys_lookup_dcookie
+#define compat_sys_pread64 sys_pread64
+#define compat_sys_pwrite64sys_pwrite64
+#define compat_sys_readahead   sys_readah

Re: [PATCH 24/25] arm64:ilp32: add vdso-ilp32 and use for signal return

2016-05-09 Thread Zhangjian (Bamvor)

Hi, yury

I tested successful in both little endian and big endian.
Just two comments below:

On 2016/5/6 22:00, Yury Norov wrote:

Hello colleagues,

After all comments, VDSO fix looks like this for me.

Note I renamed Andrew's ZERO macro to DELOUSE, as
there already is __SC_DELOUSE which does the same,
but in C, not asm.

Like Bamvor, I'm not sure how we'd apply this patch -
standalone or meld to VDSO. I think, VDSO patch is too
big and bad-structurized, and if I find how to refactor
it, I'll incorporate this fix.

Signed-off-by: Yury Norov 
---
  arch/arm64/kernel/asm-offsets.c   |  7 +++
  arch/arm64/kernel/vdso-ilp32/vdso-ilp32.lds.S |  2 +-
  arch/arm64/kernel/vdso/gettimeofday.S | 20 +---
  3 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c
index e229525..fcfd087 100644
--- a/arch/arm64/kernel/asm-offsets.c
+++ b/arch/arm64/kernel/asm-offsets.c
@@ -101,6 +101,13 @@ int main(void)
DEFINE(TSPEC_TV_SEC,offsetof(struct timespec, tv_sec));
DEFINE(TSPEC_TV_NSEC,   offsetof(struct timespec, tv_nsec));
BLANK();
+#ifdef CONFIG_ARM64_ILP32

The following structs exist in both aarch32 el0 and ilp32. How about change it 
to
"#ifdef CONFIG_COMPAT"?

+  DEFINE(COMPAT_TVAL_TV_SEC,   offsetof(struct compat_timeval, tv_sec));
+  DEFINE(COMPAT_TVAL_TV_USEC,  offsetof(struct compat_timeval, tv_usec));
+  DEFINE(COMPAT_TSPEC_TV_SEC,  offsetof(struct compat_timespec, tv_sec));
+  DEFINE(COMPAT_TSPEC_TV_NSEC, offsetof(struct compat_timespec, tv_nsec));
+  BLANK();
+#endif
DEFINE(TZ_MINWEST,  offsetof(struct timezone, tz_minuteswest));
DEFINE(TZ_DSTTIME,  offsetof(struct timezone, tz_dsttime));
BLANK();
diff --git a/arch/arm64/kernel/vdso-ilp32/vdso-ilp32.lds.S 
b/arch/arm64/kernel/vdso-ilp32/vdso-ilp32.lds.S
index ddc63fd..d182a8d 100644
--- a/arch/arm64/kernel/vdso-ilp32/vdso-ilp32.lds.S
+++ b/arch/arm64/kernel/vdso-ilp32/vdso-ilp32.lds.S
@@ -79,7 +79,7 @@ PHDRS
   */
  VERSION
  {
-   LINUX_2.6 {
+   LINUX_2.6.39 {

Do we really want to this version? Maybe 4.x is better?

Regards

Bamvor


global:
__kernel_rt_sigreturn;
__kernel_gettimeofday;
diff --git a/arch/arm64/kernel/vdso/gettimeofday.S 
b/arch/arm64/kernel/vdso/gettimeofday.S
index efa79e8..a2d8a70 100644
--- a/arch/arm64/kernel/vdso/gettimeofday.S
+++ b/arch/arm64/kernel/vdso/gettimeofday.S
@@ -25,6 +25,16 @@
  #define NSEC_PER_SEC_LO16 0xca00
  #define NSEC_PER_SEC_HI16 0x3b9a

+#ifdef __LP64__
+#define PTR_REG(n) x##n
+#define OFFSET(n)  n
+#define DELOUSE(n)
+#else
+#define PTR_REG(n) w##n
+#define OFFSET(n)  COMPAT_##n
+#define DELOUSE(n) mov w##n, w##n
+#endif
+
  vdso_data .reqx6
  use_syscall   .reqw7
  seqcnt.reqw8
@@ -51,6 +61,8 @@ seqcnt.reqw8
  /* int __kernel_gettimeofday(struct timeval *tv, struct timezone *tz); */
  ENTRY(__kernel_gettimeofday)
.cfi_startproc
+   DELOUSE(0)
+   DELOUSE(1)
mov x2, x30
.cfi_register x30, x2

@@ -68,7 +80,7 @@ ENTRY(__kernel_gettimeofday)
mov x13, #1000
lsl x13, x13, x12
udivx11, x11, x13
-   stp x10, x11, [x0, #TVAL_TV_SEC]
+   stp PTR_REG(10), PTR_REG(11), [x0, #OFFSET(TVAL_TV_SEC)]
  2:
/* If tz is NULL, return 0. */
cbz x1, 3f
@@ -88,6 +100,7 @@ ENDPROC(__kernel_gettimeofday)
  /* int __kernel_clock_gettime(clockid_t clock_id, struct timespec *tp); */
  ENTRY(__kernel_clock_gettime)
.cfi_startproc
+   DELOUSE(1)
cmp w0, #CLOCK_REALTIME
ccmpw0, #CLOCK_MONOTONIC, #0x4, ne
b.ne2f
@@ -159,7 +172,7 @@ ENTRY(__kernel_clock_gettime)

  6:/* Store to the user timespec. */
lsr x11, x11, x12
-   stp x10, x11, [x1, #TSPEC_TV_SEC]
+   stp PTR_REG(10), PTR_REG(11), [x1, #OFFSET(TSPEC_TV_SEC)]
mov x0, xzr
ret
  7:
@@ -174,6 +187,7 @@ ENDPROC(__kernel_clock_gettime)
  /* int __kernel_clock_getres(clockid_t clock_id, struct timespec *res); */
  ENTRY(__kernel_clock_getres)
.cfi_startproc
+   DELOUSE(1)
cmp w0, #CLOCK_REALTIME
ccmpw0, #CLOCK_MONOTONIC, #0x4, ne
b.ne1f
@@ -187,7 +201,7 @@ ENTRY(__kernel_clock_getres)
ldr x2, 6f
  2:
cbz w1, 3f
-   stp xzr, x2, [x1]
+   stp PTR_REG(zr), PTR_REG(2), [x1]

  3:/* res == NULL. */
mov w0, wzr





Re: [PATCH 24/25] arm64:ilp32: add vdso-ilp32 and use for signal return

2016-05-09 Thread Zhangjian (Bamvor)

Hi, yury

I tested successful in both little endian and big endian.
Just two comments below:

On 2016/5/6 22:00, Yury Norov wrote:

Hello colleagues,

After all comments, VDSO fix looks like this for me.

Note I renamed Andrew's ZERO macro to DELOUSE, as
there already is __SC_DELOUSE which does the same,
but in C, not asm.

Like Bamvor, I'm not sure how we'd apply this patch -
standalone or meld to VDSO. I think, VDSO patch is too
big and bad-structurized, and if I find how to refactor
it, I'll incorporate this fix.

Signed-off-by: Yury Norov 
---
  arch/arm64/kernel/asm-offsets.c   |  7 +++
  arch/arm64/kernel/vdso-ilp32/vdso-ilp32.lds.S |  2 +-
  arch/arm64/kernel/vdso/gettimeofday.S | 20 +---
  3 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c
index e229525..fcfd087 100644
--- a/arch/arm64/kernel/asm-offsets.c
+++ b/arch/arm64/kernel/asm-offsets.c
@@ -101,6 +101,13 @@ int main(void)
DEFINE(TSPEC_TV_SEC,offsetof(struct timespec, tv_sec));
DEFINE(TSPEC_TV_NSEC,   offsetof(struct timespec, tv_nsec));
BLANK();
+#ifdef CONFIG_ARM64_ILP32

The following structs exist in both aarch32 el0 and ilp32. How about change it 
to
"#ifdef CONFIG_COMPAT"?

+  DEFINE(COMPAT_TVAL_TV_SEC,   offsetof(struct compat_timeval, tv_sec));
+  DEFINE(COMPAT_TVAL_TV_USEC,  offsetof(struct compat_timeval, tv_usec));
+  DEFINE(COMPAT_TSPEC_TV_SEC,  offsetof(struct compat_timespec, tv_sec));
+  DEFINE(COMPAT_TSPEC_TV_NSEC, offsetof(struct compat_timespec, tv_nsec));
+  BLANK();
+#endif
DEFINE(TZ_MINWEST,  offsetof(struct timezone, tz_minuteswest));
DEFINE(TZ_DSTTIME,  offsetof(struct timezone, tz_dsttime));
BLANK();
diff --git a/arch/arm64/kernel/vdso-ilp32/vdso-ilp32.lds.S 
b/arch/arm64/kernel/vdso-ilp32/vdso-ilp32.lds.S
index ddc63fd..d182a8d 100644
--- a/arch/arm64/kernel/vdso-ilp32/vdso-ilp32.lds.S
+++ b/arch/arm64/kernel/vdso-ilp32/vdso-ilp32.lds.S
@@ -79,7 +79,7 @@ PHDRS
   */
  VERSION
  {
-   LINUX_2.6 {
+   LINUX_2.6.39 {

Do we really want to this version? Maybe 4.x is better?

Regards

Bamvor


global:
__kernel_rt_sigreturn;
__kernel_gettimeofday;
diff --git a/arch/arm64/kernel/vdso/gettimeofday.S 
b/arch/arm64/kernel/vdso/gettimeofday.S
index efa79e8..a2d8a70 100644
--- a/arch/arm64/kernel/vdso/gettimeofday.S
+++ b/arch/arm64/kernel/vdso/gettimeofday.S
@@ -25,6 +25,16 @@
  #define NSEC_PER_SEC_LO16 0xca00
  #define NSEC_PER_SEC_HI16 0x3b9a

+#ifdef __LP64__
+#define PTR_REG(n) x##n
+#define OFFSET(n)  n
+#define DELOUSE(n)
+#else
+#define PTR_REG(n) w##n
+#define OFFSET(n)  COMPAT_##n
+#define DELOUSE(n) mov w##n, w##n
+#endif
+
  vdso_data .reqx6
  use_syscall   .reqw7
  seqcnt.reqw8
@@ -51,6 +61,8 @@ seqcnt.reqw8
  /* int __kernel_gettimeofday(struct timeval *tv, struct timezone *tz); */
  ENTRY(__kernel_gettimeofday)
.cfi_startproc
+   DELOUSE(0)
+   DELOUSE(1)
mov x2, x30
.cfi_register x30, x2

@@ -68,7 +80,7 @@ ENTRY(__kernel_gettimeofday)
mov x13, #1000
lsl x13, x13, x12
udivx11, x11, x13
-   stp x10, x11, [x0, #TVAL_TV_SEC]
+   stp PTR_REG(10), PTR_REG(11), [x0, #OFFSET(TVAL_TV_SEC)]
  2:
/* If tz is NULL, return 0. */
cbz x1, 3f
@@ -88,6 +100,7 @@ ENDPROC(__kernel_gettimeofday)
  /* int __kernel_clock_gettime(clockid_t clock_id, struct timespec *tp); */
  ENTRY(__kernel_clock_gettime)
.cfi_startproc
+   DELOUSE(1)
cmp w0, #CLOCK_REALTIME
ccmpw0, #CLOCK_MONOTONIC, #0x4, ne
b.ne2f
@@ -159,7 +172,7 @@ ENTRY(__kernel_clock_gettime)

  6:/* Store to the user timespec. */
lsr x11, x11, x12
-   stp x10, x11, [x1, #TSPEC_TV_SEC]
+   stp PTR_REG(10), PTR_REG(11), [x1, #OFFSET(TSPEC_TV_SEC)]
mov x0, xzr
ret
  7:
@@ -174,6 +187,7 @@ ENDPROC(__kernel_clock_gettime)
  /* int __kernel_clock_getres(clockid_t clock_id, struct timespec *res); */
  ENTRY(__kernel_clock_getres)
.cfi_startproc
+   DELOUSE(1)
cmp w0, #CLOCK_REALTIME
ccmpw0, #CLOCK_MONOTONIC, #0x4, ne
b.ne1f
@@ -187,7 +201,7 @@ ENTRY(__kernel_clock_getres)
ldr x2, 6f
  2:
cbz w1, 3f
-   stp xzr, x2, [x1]
+   stp PTR_REG(zr), PTR_REG(2), [x1]

  3:/* res == NULL. */
mov w0, wzr





Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-06 Thread Zhangjian (Bamvor)

Hi,

On 2016/4/6 6:08, Yury Norov wrote:

From: Andrew Pinski 

Add a separate syscall-table for ILP32, which dispatches either to native
LP64 system call implementation or to compat-syscalls, as appropriate.

Signed-off-by: Andrew Pinski 
Signed-off-by: Yury Norov 
---
  arch/arm64/include/asm/unistd.h | 11 ++-
  arch/arm64/kernel/Makefile  |  2 +-
  arch/arm64/kernel/entry.S   | 12 +++-
  arch/arm64/kernel/sys_ilp32.c   | 65 +
  4 files changed, 87 insertions(+), 3 deletions(-)
  create mode 100644 arch/arm64/kernel/sys_ilp32.c

diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h
index 2971dea..5ea18ef 100644
--- a/arch/arm64/include/asm/unistd.h
+++ b/arch/arm64/include/asm/unistd.h
@@ -13,9 +13,18 @@
   * You should have received a copy of the GNU General Public License
   * along with this program.  If not, see .
   */
+
+#ifdef CONFIG_COMPAT
+#define __ARCH_WANT_COMPAT_STAT64
+#endif
+
+#ifdef CONFIG_ARM64_ILP32
+#define __ARCH_WANT_COMPAT_SYS_PREADV64
+#define __ARCH_WANT_COMPAT_SYS_PWRITEV64
+#endif
+
  #ifdef CONFIG_AARCH32_EL0
  #define __ARCH_WANT_COMPAT_SYS_GETDENTS64
-#define __ARCH_WANT_COMPAT_STAT64
  #define __ARCH_WANT_SYS_GETHOSTNAME
  #define __ARCH_WANT_SYS_PAUSE
  #define __ARCH_WANT_SYS_GETPGRP
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 9dfdf86..7aa65ea 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -28,7 +28,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
  arm64-obj-$(CONFIG_AARCH32_EL0)   += sys32.o kuser32.o signal32.o 
\
   sys_compat.o entry32.o   
\
   ../../arm/kernel/opcodes.o 
binfmt_elf32.o
-arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o
+arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o sys_ilp32.o
  arm64-obj-$(CONFIG_FUNCTION_TRACER)   += ftrace.o entry-ftrace.o
  arm64-obj-$(CONFIG_MODULES)   += arm64ksyms.o module.o
  arm64-obj-$(CONFIG_ARM64_MODULE_PLTS) += module-plts.o
diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
index cf4d1ae..1f7a145 100644
--- a/arch/arm64/kernel/entry.S
+++ b/arch/arm64/kernel/entry.S
@@ -715,9 +715,13 @@ ENDPROC(ret_from_fork)
   */
.align  6
  el0_svc:
-   adrpstbl, sys_call_table// load syscall table pointer
uxtwscno, w8// syscall number in w8
mov sc_nr, #__NR_syscalls
+#ifdef CONFIG_ARM64_ILP32
+   ldr x16, [tsk, #TI_FLAGS]
+   tbnzx16, #TIF_32BIT_AARCH64, el0_ilp32_svc // We are using ILP32
+#endif
+   adrpstbl, sys_call_table// load syscall table pointer
  el0_svc_naked:// compat entry point
stp x0, scno, [sp, #S_ORIG_X0]  // save the original x0 and 
syscall number
enable_dbg_and_irq
@@ -737,6 +741,12 @@ ni_sys:
b   ret_fast_syscall
  ENDPROC(el0_svc)

+#ifdef CONFIG_ARM64_ILP32
+el0_ilp32_svc:
+   adrpstbl, sys_call_ilp32_table // load syscall table pointer
+   b el0_svc_naked
+#endif
+
/*
 * This is the really slow path.  We're going to be doing context
 * switches, and waiting for our parent to respond.
diff --git a/arch/arm64/kernel/sys_ilp32.c b/arch/arm64/kernel/sys_ilp32.c
new file mode 100644
index 000..0996d8e
--- /dev/null
+++ b/arch/arm64/kernel/sys_ilp32.c
@@ -0,0 +1,65 @@
+/*
+ * AArch64- ILP32 specific system calls implementation
+ *
+ * Copyright (C) 2016 Cavium Inc.
+ * Author: Andrew Pinski 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Using non-compat syscalls where necessary */
+#define compat_sys_fadvise64_64sys_fadvise64_64
+#define compat_sys_fallocate   sys_fallocate
+#define compat_sys_ftruncate64 sys_ftruncate
+#define compat_sys_lookup_dcookie  sys_lookup_dcookie
+#define compat_sys_pread64 sys_pread64
+#define compat_sys_pwrite64sys_pwrite64
+#define compat_sys_readahead   sys_readahead
+#define compat_sys_shmat 

Re: [PATCH 20/25] arm64:ilp32: add sys_ilp32.c and a separate table (in entry.S) to use it

2016-05-06 Thread Zhangjian (Bamvor)

Hi,

On 2016/4/6 6:08, Yury Norov wrote:

From: Andrew Pinski 

Add a separate syscall-table for ILP32, which dispatches either to native
LP64 system call implementation or to compat-syscalls, as appropriate.

Signed-off-by: Andrew Pinski 
Signed-off-by: Yury Norov 
---
  arch/arm64/include/asm/unistd.h | 11 ++-
  arch/arm64/kernel/Makefile  |  2 +-
  arch/arm64/kernel/entry.S   | 12 +++-
  arch/arm64/kernel/sys_ilp32.c   | 65 +
  4 files changed, 87 insertions(+), 3 deletions(-)
  create mode 100644 arch/arm64/kernel/sys_ilp32.c

diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h
index 2971dea..5ea18ef 100644
--- a/arch/arm64/include/asm/unistd.h
+++ b/arch/arm64/include/asm/unistd.h
@@ -13,9 +13,18 @@
   * You should have received a copy of the GNU General Public License
   * along with this program.  If not, see .
   */
+
+#ifdef CONFIG_COMPAT
+#define __ARCH_WANT_COMPAT_STAT64
+#endif
+
+#ifdef CONFIG_ARM64_ILP32
+#define __ARCH_WANT_COMPAT_SYS_PREADV64
+#define __ARCH_WANT_COMPAT_SYS_PWRITEV64
+#endif
+
  #ifdef CONFIG_AARCH32_EL0
  #define __ARCH_WANT_COMPAT_SYS_GETDENTS64
-#define __ARCH_WANT_COMPAT_STAT64
  #define __ARCH_WANT_SYS_GETHOSTNAME
  #define __ARCH_WANT_SYS_PAUSE
  #define __ARCH_WANT_SYS_GETPGRP
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 9dfdf86..7aa65ea 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -28,7 +28,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
  arm64-obj-$(CONFIG_AARCH32_EL0)   += sys32.o kuser32.o signal32.o 
\
   sys_compat.o entry32.o   
\
   ../../arm/kernel/opcodes.o 
binfmt_elf32.o
-arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o
+arm64-obj-$(CONFIG_ARM64_ILP32)+= binfmt_ilp32.o sys_ilp32.o
  arm64-obj-$(CONFIG_FUNCTION_TRACER)   += ftrace.o entry-ftrace.o
  arm64-obj-$(CONFIG_MODULES)   += arm64ksyms.o module.o
  arm64-obj-$(CONFIG_ARM64_MODULE_PLTS) += module-plts.o
diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
index cf4d1ae..1f7a145 100644
--- a/arch/arm64/kernel/entry.S
+++ b/arch/arm64/kernel/entry.S
@@ -715,9 +715,13 @@ ENDPROC(ret_from_fork)
   */
.align  6
  el0_svc:
-   adrpstbl, sys_call_table// load syscall table pointer
uxtwscno, w8// syscall number in w8
mov sc_nr, #__NR_syscalls
+#ifdef CONFIG_ARM64_ILP32
+   ldr x16, [tsk, #TI_FLAGS]
+   tbnzx16, #TIF_32BIT_AARCH64, el0_ilp32_svc // We are using ILP32
+#endif
+   adrpstbl, sys_call_table// load syscall table pointer
  el0_svc_naked:// compat entry point
stp x0, scno, [sp, #S_ORIG_X0]  // save the original x0 and 
syscall number
enable_dbg_and_irq
@@ -737,6 +741,12 @@ ni_sys:
b   ret_fast_syscall
  ENDPROC(el0_svc)

+#ifdef CONFIG_ARM64_ILP32
+el0_ilp32_svc:
+   adrpstbl, sys_call_ilp32_table // load syscall table pointer
+   b el0_svc_naked
+#endif
+
/*
 * This is the really slow path.  We're going to be doing context
 * switches, and waiting for our parent to respond.
diff --git a/arch/arm64/kernel/sys_ilp32.c b/arch/arm64/kernel/sys_ilp32.c
new file mode 100644
index 000..0996d8e
--- /dev/null
+++ b/arch/arm64/kernel/sys_ilp32.c
@@ -0,0 +1,65 @@
+/*
+ * AArch64- ILP32 specific system calls implementation
+ *
+ * Copyright (C) 2016 Cavium Inc.
+ * Author: Andrew Pinski 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Using non-compat syscalls where necessary */
+#define compat_sys_fadvise64_64sys_fadvise64_64
+#define compat_sys_fallocate   sys_fallocate
+#define compat_sys_ftruncate64 sys_ftruncate
+#define compat_sys_lookup_dcookie  sys_lookup_dcookie
+#define compat_sys_pread64 sys_pread64
+#define compat_sys_pwrite64sys_pwrite64
+#define compat_sys_readahead   sys_readahead
+#define compat_sys_shmat   sys_shmat
+#define compat_sys_sync_file_range sys_sync_file_range
+#define 

Re: [PATCH 15/25] arm64: introduce is_a32_task and is_a32_thread (for AArch32 compat)

2016-05-06 Thread Zhangjian (Bamvor)

Hi,

On 2016/4/6 6:08, Yury Norov wrote:

Based on patch of Andrew Pinski.

This patch introduces is_a32_compat_task and is_a32_thread so it is
easier to say this is a a32 specific thread or a generic compat thread/task.
Corresponding functions are located in  to avoid mess in
headers.

Some files include both  and ,
and this is wrong because  has  already
included. It was fixed too.


1.  in "kernel/seccomp.c"
There are different list for a32 and LP64. I do not know we
should add a new one or align to one of them. Currently, we
align ilp32 to a32 list.
```
/*
 * Secure computing mode 1 allows only read/write/exit/sigreturn.
 * To be fully secure this must be combined with rlimit
 * to limit the stack allocations too.
 */
static int mode1_syscalls[] = {
__NR_seccomp_read, __NR_seccomp_write, __NR_seccomp_exit, 
__NR_seccomp_sigreturn,
0, /* null terminated */
};

#ifdef CONFIG_COMPAT
static int mode1_syscalls_32[] = {
__NR_seccomp_read_32, __NR_seccomp_write_32, __NR_seccomp_exit_32, 
__NR_seccomp_sigreturn_32,
0, /* null terminated */
};
#endif

static void __secure_computing_strict(int this_syscall)
{
int *syscall_whitelist = mode1_syscalls;
#ifdef CONFIG_COMPAT
if (in_compat_syscall())
syscall_whitelist = mode1_syscalls_32;
#endif
```

2.  in "kernel/auditsc.c"
__audit_seccomp will print if compat or not. But in the same file,
it call syscall_get_arch() to get the architecture in which ILP32
is same as LP64.
And consequenly, do we need to split in_compat_syscall to
in_a32_compat_syscall and in_ilp32 compat_syscall?

```
void __audit_seccomp(unsigned long syscall, long signr, int code)
{
struct audit_buffer *ab;

ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_SECCOMP);
if (unlikely(!ab))
return;
audit_log_task(ab);
audit_log_format(ab, " sig=%ld arch=%x syscall=%ld compat=%d ip=0x%lx 
code=0x%x",
 signr, syscall_get_arch(), syscall,
 in_compat_syscall(), KSTK_EIP(current), code);
audit_log_end(ab);
}
```

Thanks

Bamvor



Re: [PATCH 15/25] arm64: introduce is_a32_task and is_a32_thread (for AArch32 compat)

2016-05-06 Thread Zhangjian (Bamvor)

Hi,

On 2016/4/6 6:08, Yury Norov wrote:

Based on patch of Andrew Pinski.

This patch introduces is_a32_compat_task and is_a32_thread so it is
easier to say this is a a32 specific thread or a generic compat thread/task.
Corresponding functions are located in  to avoid mess in
headers.

Some files include both  and ,
and this is wrong because  has  already
included. It was fixed too.


1.  in "kernel/seccomp.c"
There are different list for a32 and LP64. I do not know we
should add a new one or align to one of them. Currently, we
align ilp32 to a32 list.
```
/*
 * Secure computing mode 1 allows only read/write/exit/sigreturn.
 * To be fully secure this must be combined with rlimit
 * to limit the stack allocations too.
 */
static int mode1_syscalls[] = {
__NR_seccomp_read, __NR_seccomp_write, __NR_seccomp_exit, 
__NR_seccomp_sigreturn,
0, /* null terminated */
};

#ifdef CONFIG_COMPAT
static int mode1_syscalls_32[] = {
__NR_seccomp_read_32, __NR_seccomp_write_32, __NR_seccomp_exit_32, 
__NR_seccomp_sigreturn_32,
0, /* null terminated */
};
#endif

static void __secure_computing_strict(int this_syscall)
{
int *syscall_whitelist = mode1_syscalls;
#ifdef CONFIG_COMPAT
if (in_compat_syscall())
syscall_whitelist = mode1_syscalls_32;
#endif
```

2.  in "kernel/auditsc.c"
__audit_seccomp will print if compat or not. But in the same file,
it call syscall_get_arch() to get the architecture in which ILP32
is same as LP64.
And consequenly, do we need to split in_compat_syscall to
in_a32_compat_syscall and in_ilp32 compat_syscall?

```
void __audit_seccomp(unsigned long syscall, long signr, int code)
{
struct audit_buffer *ab;

ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_SECCOMP);
if (unlikely(!ab))
return;
audit_log_task(ab);
audit_log_format(ab, " sig=%ld arch=%x syscall=%ld compat=%d ip=0x%lx 
code=0x%x",
 signr, syscall_get_arch(), syscall,
 in_compat_syscall(), KSTK_EIP(current), code);
audit_log_end(ab);
}
```

Thanks

Bamvor



Re: [PATCH 24/25] arm64:ilp32: add vdso-ilp32 and use for signal return

2016-05-04 Thread Zhangjian (Bamvor)

Hi,

On 2016/5/5 7:23, Andrew Pinski wrote:

On Wed, May 4, 2016 at 2:49 PM, Yury Norov <yno...@caviumnetworks.com> wrote:

On Tue, May 03, 2016 at 08:41:25PM +0800, Zhangjian (Bamvor) wrote:

Hi, all

After apply this patch with my small testcase, the vsyscall of gettimeofday in
ilp32 works in both big endian and small endian. In this patch, I use the
different register and offset for ilp32 and lp64. Actually, the
COMPAT_TVAL_TV_SEC is same as TVAL_TV_SEC(so as to COMPAT_TSPEC_TV_SEC and
TSPEC_TV_SEC). I add it to keep the logic clear. I also change the version
of vdso to 4.6. It should change to 2.6.39 if glibc is not update.



[...]

Hi Bamvor,

It works for me as well. Thank you.
I'll incorporate it in next submission.


We should add the following so we are complaint to the ILP32 ABI
dealing with pointers don't have to be zero extended for arguments,
Note ZERO should most likely be ZERO_PTR or something to do that
effect, I am not so good with names.
#ifdef __LP64__
#define ZERO(n)
#else
#define ZERO(n) mov w##n, w##n
#endif

...
ENTRY(__kernel_gettimeofday)
 .cfi_startproc
 ZERO(0)
 ZERO(1)
...
ENTRY(__kernel_clock_gettime)
 .cfi_startproc
 ZERO(1)
...
ENTRY(__kernel_clock_getres)
 .cfi_startproc
 ZERO(1)

Thanks. I will test and send a new version.

Thanks.

Bamvor

Thanks,
Andrew Pinski



Yury.




Re: [PATCH 24/25] arm64:ilp32: add vdso-ilp32 and use for signal return

2016-05-04 Thread Zhangjian (Bamvor)

Hi,

On 2016/5/5 7:23, Andrew Pinski wrote:

On Wed, May 4, 2016 at 2:49 PM, Yury Norov  wrote:

On Tue, May 03, 2016 at 08:41:25PM +0800, Zhangjian (Bamvor) wrote:

Hi, all

After apply this patch with my small testcase, the vsyscall of gettimeofday in
ilp32 works in both big endian and small endian. In this patch, I use the
different register and offset for ilp32 and lp64. Actually, the
COMPAT_TVAL_TV_SEC is same as TVAL_TV_SEC(so as to COMPAT_TSPEC_TV_SEC and
TSPEC_TV_SEC). I add it to keep the logic clear. I also change the version
of vdso to 4.6. It should change to 2.6.39 if glibc is not update.



[...]

Hi Bamvor,

It works for me as well. Thank you.
I'll incorporate it in next submission.


We should add the following so we are complaint to the ILP32 ABI
dealing with pointers don't have to be zero extended for arguments,
Note ZERO should most likely be ZERO_PTR or something to do that
effect, I am not so good with names.
#ifdef __LP64__
#define ZERO(n)
#else
#define ZERO(n) mov w##n, w##n
#endif

...
ENTRY(__kernel_gettimeofday)
 .cfi_startproc
 ZERO(0)
 ZERO(1)
...
ENTRY(__kernel_clock_gettime)
 .cfi_startproc
 ZERO(1)
...
ENTRY(__kernel_clock_getres)
 .cfi_startproc
 ZERO(1)

Thanks. I will test and send a new version.

Thanks.

Bamvor

Thanks,
Andrew Pinski



Yury.




  1   2   >