* [PATCH] x86/setup: correct off-by-1 in module mapping
@ 2025-03-19 11:21 Jan Beulich
2025-03-19 12:15 ` Roger Pau Monné
2025-03-19 13:58 ` Roger Pau Monné
0 siblings, 2 replies; 5+ messages in thread
From: Jan Beulich @ 2025-03-19 11:21 UTC (permalink / raw)
To: xen-devel@lists.xenproject.org
Cc: Andrew Cooper, Roger Pau Monné, Daniel Smith
If a module's length is an exact multiple of PAGE_SIZE, the 2nd argument
passed to set_pdx_range() would be one larger than intended. Use
PFN_{UP,DOWN}() there instead.
Fixes: cd7cc5320bb2 ("x86/boot: add start and size fields to struct boot_module")
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -1730,7 +1730,7 @@ void asmlinkage __init noreturn __start_
{
unsigned long s = bi->mods[i].start, l = bi->mods[i].size;
- set_pdx_range(paddr_to_pfn(s), paddr_to_pfn(s + l) + 1);
+ set_pdx_range(PFN_DOWN(s), PFN_UP(s + l));
map_pages_to_xen((unsigned long)maddr_to_virt(s), maddr_to_mfn(s),
PFN_UP(l), PAGE_HYPERVISOR);
}
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] x86/setup: correct off-by-1 in module mapping
2025-03-19 11:21 [PATCH] x86/setup: correct off-by-1 in module mapping Jan Beulich
@ 2025-03-19 12:15 ` Roger Pau Monné
2025-03-19 12:21 ` Andrew Cooper
2025-03-19 12:40 ` Jan Beulich
2025-03-19 13:58 ` Roger Pau Monné
1 sibling, 2 replies; 5+ messages in thread
From: Roger Pau Monné @ 2025-03-19 12:15 UTC (permalink / raw)
To: Jan Beulich; +Cc: xen-devel@lists.xenproject.org, Andrew Cooper, Daniel Smith
On Wed, Mar 19, 2025 at 12:21:53PM +0100, Jan Beulich wrote:
> If a module's length is an exact multiple of PAGE_SIZE, the 2nd argument
> passed to set_pdx_range() would be one larger than intended. Use
> PFN_{UP,DOWN}() there instead.
>
> Fixes: cd7cc5320bb2 ("x86/boot: add start and size fields to struct boot_module")
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>
> --- a/xen/arch/x86/setup.c
> +++ b/xen/arch/x86/setup.c
> @@ -1730,7 +1730,7 @@ void asmlinkage __init noreturn __start_
> {
> unsigned long s = bi->mods[i].start, l = bi->mods[i].size;
>
> - set_pdx_range(paddr_to_pfn(s), paddr_to_pfn(s + l) + 1);
> + set_pdx_range(PFN_DOWN(s), PFN_UP(s + l));
Is the set_pdx_range() provided smfn, emfn range inclusive?
> map_pages_to_xen((unsigned long)maddr_to_virt(s), maddr_to_mfn(s),
> PFN_UP(l), PAGE_HYPERVISOR);
Isn't this line also bogus, as there's no guarantee that the start
address is aligned to PAGE_SIZE? And hence the length should take
into account a possible page offset of s?
Thanks, Roger.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] x86/setup: correct off-by-1 in module mapping
2025-03-19 12:15 ` Roger Pau Monné
@ 2025-03-19 12:21 ` Andrew Cooper
2025-03-19 12:40 ` Jan Beulich
1 sibling, 0 replies; 5+ messages in thread
From: Andrew Cooper @ 2025-03-19 12:21 UTC (permalink / raw)
To: Roger Pau Monné, Jan Beulich
Cc: xen-devel@lists.xenproject.org, Daniel Smith
On 19/03/2025 12:15 pm, Roger Pau Monné wrote:
> On Wed, Mar 19, 2025 at 12:21:53PM +0100, Jan Beulich wrote:
>> If a module's length is an exact multiple of PAGE_SIZE, the 2nd argument
>> passed to set_pdx_range() would be one larger than intended. Use
>> PFN_{UP,DOWN}() there instead.
>>
>> Fixes: cd7cc5320bb2 ("x86/boot: add start and size fields to struct boot_module")
>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>>
>> --- a/xen/arch/x86/setup.c
>> +++ b/xen/arch/x86/setup.c
>> @@ -1730,7 +1730,7 @@ void asmlinkage __init noreturn __start_
>> {
>> unsigned long s = bi->mods[i].start, l = bi->mods[i].size;
>>
>> - set_pdx_range(paddr_to_pfn(s), paddr_to_pfn(s + l) + 1);
>> + set_pdx_range(PFN_DOWN(s), PFN_UP(s + l));
> Is the set_pdx_range() provided smfn, emfn range inclusive?
>
>> map_pages_to_xen((unsigned long)maddr_to_virt(s), maddr_to_mfn(s),
>> PFN_UP(l), PAGE_HYPERVISOR);
> Isn't this line also bogus, as there's no guarantee that the start
> address is aligned to PAGE_SIZE? And hence the length should take
> into account a possible page offset of s?
All modules are page aligned, because we require this of the bootloader.
Prior to cd7cc5320bb2, Xen strictly depended on it, because we shifted
mod_start by 12 to operate on it.
cd7cc5320bb2 retained the alignment check, panic("Bootloader didn't
honor module alignment request\n");, but operates in terms of paddr, not
frames.
~Andrew
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] x86/setup: correct off-by-1 in module mapping
2025-03-19 12:15 ` Roger Pau Monné
2025-03-19 12:21 ` Andrew Cooper
@ 2025-03-19 12:40 ` Jan Beulich
1 sibling, 0 replies; 5+ messages in thread
From: Jan Beulich @ 2025-03-19 12:40 UTC (permalink / raw)
To: Roger Pau Monné
Cc: xen-devel@lists.xenproject.org, Andrew Cooper, Daniel Smith
On 19.03.2025 13:15, Roger Pau Monné wrote:
> On Wed, Mar 19, 2025 at 12:21:53PM +0100, Jan Beulich wrote:
>> If a module's length is an exact multiple of PAGE_SIZE, the 2nd argument
>> passed to set_pdx_range() would be one larger than intended. Use
>> PFN_{UP,DOWN}() there instead.
>>
>> Fixes: cd7cc5320bb2 ("x86/boot: add start and size fields to struct boot_module")
>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>>
>> --- a/xen/arch/x86/setup.c
>> +++ b/xen/arch/x86/setup.c
>> @@ -1730,7 +1730,7 @@ void asmlinkage __init noreturn __start_
>> {
>> unsigned long s = bi->mods[i].start, l = bi->mods[i].size;
>>
>> - set_pdx_range(paddr_to_pfn(s), paddr_to_pfn(s + l) + 1);
>> + set_pdx_range(PFN_DOWN(s), PFN_UP(s + l));
>
> Is the set_pdx_range() provided smfn, emfn range inclusive?
No, it's exclusive at the end. See all other uses in this file.
>> map_pages_to_xen((unsigned long)maddr_to_virt(s), maddr_to_mfn(s),
>> PFN_UP(l), PAGE_HYPERVISOR);
>
> Isn't this line also bogus, as there's no guarantee that the start
> address is aligned to PAGE_SIZE? And hence the length should take
> into account a possible page offset of s?
See Andrew's reply.
Jan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] x86/setup: correct off-by-1 in module mapping
2025-03-19 11:21 [PATCH] x86/setup: correct off-by-1 in module mapping Jan Beulich
2025-03-19 12:15 ` Roger Pau Monné
@ 2025-03-19 13:58 ` Roger Pau Monné
1 sibling, 0 replies; 5+ messages in thread
From: Roger Pau Monné @ 2025-03-19 13:58 UTC (permalink / raw)
To: Jan Beulich; +Cc: xen-devel@lists.xenproject.org, Andrew Cooper, Daniel Smith
On Wed, Mar 19, 2025 at 12:21:53PM +0100, Jan Beulich wrote:
> If a module's length is an exact multiple of PAGE_SIZE, the 2nd argument
> passed to set_pdx_range() would be one larger than intended. Use
> PFN_{UP,DOWN}() there instead.
>
> Fixes: cd7cc5320bb2 ("x86/boot: add start and size fields to struct boot_module")
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Thanks, Roger.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-03-19 13:58 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-19 11:21 [PATCH] x86/setup: correct off-by-1 in module mapping Jan Beulich
2025-03-19 12:15 ` Roger Pau Monné
2025-03-19 12:21 ` Andrew Cooper
2025-03-19 12:40 ` Jan Beulich
2025-03-19 13:58 ` Roger Pau Monné
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.