public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Weidong Wang <wangweidong1@huawei.com>
To: Andy Lutomirski <luto@amacapital.net>
Cc: "Zhangjian (Bamvor)" <bamvor.zhangjian@huawei.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	Al Viro <viro@zeniv.linux.org.uk>, Arnd Bergmann <arnd@arndb.de>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	X86 ML <x86@kernel.org>, Hanjun Guo <guohanjun@huawei.com>,
	Linux-Api <linux-api@vger.kernel.org>
Subject: Re: [RFC PATCH] sys_read: add a compat_sys_read for 64bit system
Date: Tue, 14 Jun 2016 11:05:59 +0800	[thread overview]
Message-ID: <575F7497.9000000@huawei.com> (raw)
In-Reply-To: <CALCETrXCo3doNCoxLPr5p+SPc1CnnFmFcPWKk0m7M1_WOGJWYw@mail.gmail.com>

On 2016/6/10 1:08, Andy Lutomirski wrote:
> On Tue, Jun 7, 2016 at 7:14 PM, Zhangjian (Bamvor)
> <bamvor.zhangjian@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.
> 
> On 64-bit, you get -14 == -EFAULT.  Seems reasonable: you passed a bad pointer.
> 
> On 32-bit, you get -21 == -EISDIR.  Also seems reasonable: fd is a directory.
> 
>>>
>>> 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(0xffffffff), it goes to the sys_read, it would be change to a positive
>>> number.
> 
> That parameter is size_t, which is unsigned.  It's a positive number
> in both cases.
> 
> I don't think there's a bug here.
> 

Yep.
In the progress open the '/tmp' is a directory. If we do open a file '/tmp/files' (exist file),
the result would be different on x86-64bit machine.

On 64-bit, we get -14 == -EFAULT.
On 32-bit, we get the length of the file, the errno is 0.

Regards,
Weidong

> .
> 

      reply	other threads:[~2016-06-14  3:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-08  1:33 [RFC PATCH] sys_read: add a compat_sys_read for 64bit system Weidong Wang
2016-06-08  2:14 ` Zhangjian (Bamvor)
2016-06-08  7:33   ` H. Peter Anvin
2016-06-08 11:44     ` Zhangjian (Bamvor)
2016-06-09 17:08   ` Andy Lutomirski
2016-06-14  3:05     ` Weidong Wang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=575F7497.9000000@huawei.com \
    --to=wangweidong1@huawei.com \
    --cc=arnd@arndb.de \
    --cc=bamvor.zhangjian@huawei.com \
    --cc=guohanjun@huawei.com \
    --cc=hpa@zytor.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=viro@zeniv.linux.org.uk \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox