2009-06-10 01:32:58

by H. Peter Anvin

[permalink] [raw]
Subject: RFC: x86: cap iomem_resource to addressable physical memory

x86 cannot generate full 64-bit addresses; this patch clamps iomem
addresses to the accessible range.

I wanted to post it for review before committing it, however; comments
would be appreciated, especially of the kind "this is done too early/too
late/in the wrong place/incorrectly".

-hpa


Attachments:
0001-x86-cap-iomem_resource-to-addressable-physical-memo.patch (1.38 kB)

2009-06-11 19:18:31

by Jesse Barnes

[permalink] [raw]
Subject: Re: RFC: x86: cap iomem_resource to addressable physical memory

On Tue, 09 Jun 2009 18:32:53 -0700
"H. Peter Anvin" <[email protected]> wrote:

> x86 cannot generate full 64-bit addresses; this patch clamps iomem
> addresses to the accessible range.
>
> I wanted to post it for review before committing it, however; comments
> would be appreciated, especially of the kind "this is done too
> early/too late/in the wrong place/incorrectly".
>
> -hpa

Seems reasonable, since the iomem_resource describes the CPU's view of
MMIO space it should probably reflect what it can actually access.

Reviewed-by: Jesse Barnes <[email protected]>

--
Jesse Barnes, Intel Open Source Technology Center

2009-06-11 20:43:21

by Yinghai Lu

[permalink] [raw]
Subject: Re: RFC: x86: cap iomem_resource to addressable physical memory

On Tue, Jun 9, 2009 at 6:32 PM, H. Peter Anvin<[email protected]> wrote:
> x86 cannot generate full 64-bit addresses; this patch clamps iomem
> addresses to the accessible range.
>
> I wanted to post it for review before committing it, however; comments
> would be appreciated, especially of the kind "this is done too early/too
> late/in the wrong place/incorrectly".
| --- a/arch/x86/kernel/cpu/common.c
| +++ b/arch/x86/kernel/cpu/common.c
| @@ -839,6 +839,9 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
| #if defined(CONFIG_NUMA) && defined(CONFIG_X86_64)
| numa_add_cpu(smp_processor_id());
| #endif
|+
|+ /* Cap the iomem address space to what is addressable on all CPUs */
|+ iomem_resource.end &= (1ULL << c->x86_phys_bits) - 1;
| }
|


do we need do that on every cpu?

looks like we could do that in identify_boot_cpu.

YH

2009-06-11 20:46:59

by H. Peter Anvin

[permalink] [raw]
Subject: Re: RFC: x86: cap iomem_resource to addressable physical memory

Yinghai Lu wrote:
>
> do we need do that on every cpu?
>
> looks like we could do that in identify_boot_cpu.
>

What if the CPUs are heterogenous? It's obviously a suboptimal
situation, but it doesn't seem like something we can rely on.

-hpa

2009-06-21 06:47:19

by Pavel Machek

[permalink] [raw]
Subject: Re: RFC: x86: cap iomem_resource to addressable physical memory

On Thu 2009-06-11 13:46:52, H. Peter Anvin wrote:
> Yinghai Lu wrote:
> >
> > do we need do that on every cpu?
> >
> > looks like we could do that in identify_boot_cpu.
> >
>
> What if the CPUs are heterogenous? It's obviously a suboptimal
> situation, but it doesn't seem like something we can rely on.

Is it ok if that changes during runtime? What if someone hotplugs
heterogenous cpu? I'd say basing it on boot cpu seems simplest.
Pavel

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

2009-06-21 07:41:04

by H. Peter Anvin

[permalink] [raw]
Subject: Re: RFC: x86: cap iomem_resource to addressable physical memory

Pavel Machek wrote:
> On Thu 2009-06-11 13:46:52, H. Peter Anvin wrote:
>> Yinghai Lu wrote:
>>> do we need do that on every cpu?
>>>
>>> looks like we could do that in identify_boot_cpu.
>>>
>> What if the CPUs are heterogenous? It's obviously a suboptimal
>> situation, but it doesn't seem like something we can rely on.
>
> Is it ok if that changes during runtime? What if someone hotplugs
> heterogenous cpu? I'd say basing it on boot cpu seems simplest.
> Pavel
>

If someone hotplugs heterogenous CPUs it should do the right thing if
the right thing is possible to do. If you already have resource
assignments that are unfulfillable you're screwed anyway.

-hpa

2009-06-21 20:55:43

by Pavel Machek

[permalink] [raw]
Subject: Re: RFC: x86: cap iomem_resource to addressable physical memory

On Sun 2009-06-21 00:40:35, H. Peter Anvin wrote:
> Pavel Machek wrote:
>> On Thu 2009-06-11 13:46:52, H. Peter Anvin wrote:
>>> Yinghai Lu wrote:
>>>> do we need do that on every cpu?
>>>>
>>>> looks like we could do that in identify_boot_cpu.
>>>>
>>> What if the CPUs are heterogenous? It's obviously a suboptimal
>>> situation, but it doesn't seem like something we can rely on.
>>
>> Is it ok if that changes during runtime? What if someone hotplugs
>> heterogenous cpu? I'd say basing it on boot cpu seems simplest.
>
> If someone hotplugs heterogenous CPUs it should do the right thing if
> the right thing is possible to do. If you already have resource
> assignments that are unfulfillable you're screwed anyway.

Ok... and is there enough locking in there so that it is actually ok
to change mask during hotplug? (Is it okay because it is single long
and all the writers are somehow serialized by hotplug mechanism?)
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

2009-06-22 07:54:21

by H. Peter Anvin

[permalink] [raw]
Subject: Re: RFC: x86: cap iomem_resource to addressable physical memory

Pavel Machek wrote:
>
> Ok... and is there enough locking in there so that it is actually ok
> to change mask during hotplug? (Is it okay because it is single long
> and all the writers are somehow serialized by hotplug mechanism?)
> Pavel

Making it a locked reference probably would be a good idea (although I
personally think it will never actually matter in practice). Although
on 32 bits (PAE) it can be more than one long, it doesn't matter because
only the upper long can actually be modified. It does, however,
complicate the actual code somewhat... I'll look at it tomorrow.

-hpa