diff mbox

[v3,09/16] hvmloader: Check modules whereabouts

Message ID 1456412174-20162-10-git-send-email-anthony.perard@citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Anthony PERARD Feb. 25, 2016, 2:56 p.m. UTC
As perform_tests() is going to clear memory past 4MB, we check that the
memory can be use.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
New in V3
---
 tools/firmware/hvmloader/hvmloader.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Jan Beulich Feb. 29, 2016, 4:58 p.m. UTC | #1
>>> On 25.02.16 at 15:56, <anthony.perard@citrix.com> wrote:
> --- a/tools/firmware/hvmloader/hvmloader.c
> +++ b/tools/firmware/hvmloader/hvmloader.c
> @@ -303,6 +303,15 @@ int main(void)
>  
>      smp_initialise();
>  
> +    /* Check that tests does not use memory where modules are stored */
> +    BUG_ON( ((uint32_t)hvm_start_info + sizeof(struct hvm_start_info)) >= 4 << 20 );
> +    for ( unsigned i = 0; i < hvm_start_info->nr_modules; i++ )
> +    {
> +        const struct hvm_modlist_entry *modlist =
> +            (struct hvm_modlist_entry *)hvm_start_info->modlist_paddr;
> +        if ( modlist[i].size )
> +            BUG_ON( modlist[i].paddr + modlist[i].size >= 4ul << 20 );
> +    }

First of all both checks should use > instead of >=. And then
expecting all modules to live below 4Mb doesn't seem very
reasonable.

Jan
Anthony PERARD March 3, 2016, 4 p.m. UTC | #2
On Mon, Feb 29, 2016 at 09:58:29AM -0700, Jan Beulich wrote:
> >>> On 25.02.16 at 15:56, <anthony.perard@citrix.com> wrote:
> > --- a/tools/firmware/hvmloader/hvmloader.c
> > +++ b/tools/firmware/hvmloader/hvmloader.c
> > @@ -303,6 +303,15 @@ int main(void)
> >  
> >      smp_initialise();
> >  
> > +    /* Check that tests does not use memory where modules are stored */
> > +    BUG_ON( ((uint32_t)hvm_start_info + sizeof(struct hvm_start_info)) >= 4 << 20 );
> > +    for ( unsigned i = 0; i < hvm_start_info->nr_modules; i++ )
> > +    {
> > +        const struct hvm_modlist_entry *modlist =
> > +            (struct hvm_modlist_entry *)hvm_start_info->modlist_paddr;
> > +        if ( modlist[i].size )
> > +            BUG_ON( modlist[i].paddr + modlist[i].size >= 4ul << 20 );
> > +    }
> 
> First of all both checks should use > instead of >=. And then
> expecting all modules to live below 4Mb doesn't seem very
> reasonable.

Yes, and this can be an issue with OVMF, it's a 2MB binary. I'm not sure
what to do about this, should I ignore perform_tests() if it going to
clear the memory used by the modules?

I should probably check that the modules are outside the memory region that
is going to be used by perform_tests(), instead of just checking that they
are bellow 4MB.
Jan Beulich March 3, 2016, 4:18 p.m. UTC | #3
>>> On 03.03.16 at 17:00, <anthony.perard@citrix.com> wrote:
> On Mon, Feb 29, 2016 at 09:58:29AM -0700, Jan Beulich wrote:
>> >>> On 25.02.16 at 15:56, <anthony.perard@citrix.com> wrote:
>> > --- a/tools/firmware/hvmloader/hvmloader.c
>> > +++ b/tools/firmware/hvmloader/hvmloader.c
>> > @@ -303,6 +303,15 @@ int main(void)
>> >  
>> >      smp_initialise();
>> >  
>> > +    /* Check that tests does not use memory where modules are stored */
>> > +    BUG_ON( ((uint32_t)hvm_start_info + sizeof(struct hvm_start_info)) >= 4 
> << 20 );
>> > +    for ( unsigned i = 0; i < hvm_start_info->nr_modules; i++ )
>> > +    {
>> > +        const struct hvm_modlist_entry *modlist =
>> > +            (struct hvm_modlist_entry *)hvm_start_info->modlist_paddr;
>> > +        if ( modlist[i].size )
>> > +            BUG_ON( modlist[i].paddr + modlist[i].size >= 4ul << 20 );
>> > +    }
>> 
>> First of all both checks should use > instead of >=. And then
>> expecting all modules to live below 4Mb doesn't seem very
>> reasonable.
> 
> Yes, and this can be an issue with OVMF, it's a 2MB binary. I'm not sure
> what to do about this, should I ignore perform_tests() if it going to
> clear the memory used by the modules?

Temporarily this might be an option, but ultimately the tests
shouldn't assume a fixed memory location to be available.

> I should probably check that the modules are outside the memory region that
> is going to be used by perform_tests(), instead of just checking that they
> are bellow 4MB.

Yes.

Jan
Andrew Cooper March 3, 2016, 4:34 p.m. UTC | #4
On 03/03/16 16:00, Anthony PERARD wrote:
> On Mon, Feb 29, 2016 at 09:58:29AM -0700, Jan Beulich wrote:
>>>>> On 25.02.16 at 15:56, <anthony.perard@citrix.com> wrote:
>>> --- a/tools/firmware/hvmloader/hvmloader.c
>>> +++ b/tools/firmware/hvmloader/hvmloader.c
>>> @@ -303,6 +303,15 @@ int main(void)
>>>  
>>>      smp_initialise();
>>>  
>>> +    /* Check that tests does not use memory where modules are stored */
>>> +    BUG_ON( ((uint32_t)hvm_start_info + sizeof(struct hvm_start_info)) >= 4 << 20 );
>>> +    for ( unsigned i = 0; i < hvm_start_info->nr_modules; i++ )
>>> +    {
>>> +        const struct hvm_modlist_entry *modlist =
>>> +            (struct hvm_modlist_entry *)hvm_start_info->modlist_paddr;
>>> +        if ( modlist[i].size )
>>> +            BUG_ON( modlist[i].paddr + modlist[i].size >= 4ul << 20 );
>>> +    }
>> First of all both checks should use > instead of >=. And then
>> expecting all modules to live below 4Mb doesn't seem very
>> reasonable.
> Yes, and this can be an issue with OVMF, it's a 2MB binary. I'm not sure
> what to do about this, should I ignore perform_tests() if it going to
> clear the memory used by the modules?
>
> I should probably check that the modules are outside the memory region that
> is going to be used by perform_tests(), instead of just checking that they
> are bellow 4MB.

Now that I have published my Xen Test Framework, these hvmloader tests
should be moved across and removed entirely from hvmloader.  This was
one of the original intentions.

~Andrew
diff mbox

Patch

diff --git a/tools/firmware/hvmloader/hvmloader.c b/tools/firmware/hvmloader/hvmloader.c
index d319de0..a40503d 100644
--- a/tools/firmware/hvmloader/hvmloader.c
+++ b/tools/firmware/hvmloader/hvmloader.c
@@ -303,6 +303,15 @@  int main(void)
 
     smp_initialise();
 
+    /* Check that tests does not use memory where modules are stored */
+    BUG_ON( ((uint32_t)hvm_start_info + sizeof(struct hvm_start_info)) >= 4 << 20 );
+    for ( unsigned i = 0; i < hvm_start_info->nr_modules; i++ )
+    {
+        const struct hvm_modlist_entry *modlist =
+            (struct hvm_modlist_entry *)hvm_start_info->modlist_paddr;
+        if ( modlist[i].size )
+            BUG_ON( modlist[i].paddr + modlist[i].size >= 4ul << 20 );
+    }
     perform_tests();
 
     if ( bios->bios_info_setup )