2007-08-09 05:36:54

by Jidong Xiao

[permalink] [raw]
Subject: Question on IS_ERR

I saw we call IS_ERR(ptr) after executing kthread_run() each time.
But we don't need to call IS_ERR(ptr) after kmalloc().

My understanding is,
the kernel pointer ptr for IS_ERR to check should be page aligned, so
its kernel address should be less than 0xfffff000(or 0xffff ffff ffff
f000, 64bits),

kthread_run returns a struct task_struct pointer,which is always page aligned,
however the pointer returned by kmalloc() might not be page aligned,
so we cannot use IS_ERR to check.

Is my understanding correct?

Thanks
Jason


2007-08-09 06:13:23

by H. Peter Anvin

[permalink] [raw]
Subject: Re: Question on IS_ERR

jidong xiao wrote:
> I saw we call IS_ERR(ptr) after executing kthread_run() each time.
> But we don't need to call IS_ERR(ptr) after kmalloc().
>
> My understanding is,
> the kernel pointer ptr for IS_ERR to check should be page aligned, so
> its kernel address should be less than 0xfffff000(or 0xffff ffff ffff
> f000, 64bits),
>
> kthread_run returns a struct task_struct pointer,which is always page aligned,
> however the pointer returned by kmalloc() might not be page aligned,
> so we cannot use IS_ERR to check.
>
> Is my understanding correct?
>

No. There is no requirement that the pointer is page-aligned. The last
page of the address space is (in the Linux kernel) invalid by
definition, so there are in effect three kinds of pointers in the Linux
kernel: valid pointers, NULL, and ERR_PTR()s.

-hpa

2007-08-09 06:31:53

by Jidong Xiao

[permalink] [raw]
Subject: Re: Question on IS_ERR

On 8/9/07, H. Peter Anvin <[email protected]> wrote:
>
> No. There is no requirement that the pointer is page-aligned. The last
> page of the address space is (in the Linux kernel) invalid by
> definition, so there are in effect three kinds of pointers in the Linux
> kernel: valid pointers, NULL, and ERR_PTR()s.
>
> -hpa
>

Regarding "The last page of the address space is invalid by definition",
I am wondering why do we define the last page as invalid.
The reason for defining this is just because we want to take use of
the error number handling?

Regards
Jason

2007-08-09 07:22:16

by H. Peter Anvin

[permalink] [raw]
Subject: Re: Question on IS_ERR

jidong xiao wrote:
> On 8/9/07, H. Peter Anvin <[email protected]> wrote:
>> No. There is no requirement that the pointer is page-aligned. The last
>> page of the address space is (in the Linux kernel) invalid by
>> definition, so there are in effect three kinds of pointers in the Linux
>> kernel: valid pointers, NULL, and ERR_PTR()s.
>>
>> -hpa
>>
>
> Regarding "The last page of the address space is invalid by definition",
> I am wondering why do we define the last page as invalid.
> The reason for defining this is just because we want to take use of
> the error number handling?
>

Pretty much.

-hpa