All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/3] SMBIOS table passthrough support
@ 2012-02-21  2:56 Ross Philipson
  2012-02-21  8:48 ` Ian Campbell
  0 siblings, 1 reply; 3+ messages in thread
From: Ross Philipson @ 2012-02-21  2:56 UTC (permalink / raw)
  To: xen-devel

[-- Attachment #1: Type: text/plain, Size: 123 bytes --]

Utility routines in hvmloader for SMBIOS table validation.

Signed-off-by: Ross Philipson <ross.philipson@citrix.com>


[-- Attachment #2: smbios-passthrough-02.patch --]
[-- Type: application/octet-stream, Size: 3362 bytes --]

diff -r 0900b1c905f1 tools/firmware/hvmloader/util.c
--- a/tools/firmware/hvmloader/util.c	Mon Feb 20 18:58:07 2012 +0000
+++ b/tools/firmware/hvmloader/util.c	Mon Feb 20 20:37:12 2012 -0500
@@ -709,37 +709,38 @@
     crash();
 }
 
-static void validate_hvm_info(struct hvm_info_table *t)
+static int validate_hvm_info_table(uint8_t *table, uint32_t table_length,
+    const char *table_sig, const char *sig)
 {
-    uint8_t *ptr = (uint8_t *)t;
     uint8_t sum = 0;
     int i;
 
-    if ( strncmp(t->signature, "HVM INFO", 8) )
+    if (table_length == 0)
+        printf("Empty HVM info table: %.*s\n", 8, sig);
+
+    /* NOTE made this a common routine to validate all HVM tables. Removed 
+       BUG() on failure in here - let the caller decide if a checksum failure
+       warrants that */
+
+    /* strncmp(t->signature, signature, 8) */
+    for ( i = 0; i < 8; i++ )
     {
-        printf("Bad hvm info signature\n");
-        BUG();
+        if ( table_sig[i] != sig[i] )
+        {
+            printf("Bad HVM info signature for: %.*s\n", 8, sig);
+            return 0;
+        }
     }
 
-    if ( t->length < sizeof(struct hvm_info_table) )
-    {
-        printf("Bad hvm info length\n");
-        BUG();
-    }
+    for ( i = 0; i < table_length; i++ )
+        sum += table[i];
 
-    for ( i = 0; i < t->length; i++ )
-        sum += ptr[i];
-
-    if ( sum != 0 )
-    {
-        printf("Bad hvm info checksum\n");
-        BUG();
-    }
+    return (sum == 0);
 }
 
 struct hvm_info_table *get_hvm_info_table(void)
 {
-    static struct hvm_info_table *table;
+    static struct hvm_info_table *table = NULL;
     struct hvm_info_table *t;
 
     if ( table != NULL )
@@ -747,13 +748,44 @@
 
     t = (struct hvm_info_table *)HVM_INFO_PADDR;
 
-    validate_hvm_info(t);
+    if ( !validate_hvm_info_table((uint8_t*)t, t->length, t->signature, "HVM INFO") )
+    {
+        printf("Bad HVM info table\n");
+        BUG();
+    }
 
     table = t;
 
     return table;
 }
 
+struct hvm_smbios_info_table *get_hvm_smbios_info_table(void)
+{
+    static struct hvm_smbios_info_table *table = NULL;
+    static int validated = 0;
+    struct hvm_smbios_info_table *t;
+
+    if ( validated )
+        return table;
+
+    t = (struct hvm_smbios_info_table *)HVM_SMBIOS_INFO_PADDR;
+
+    if ( (t->length == 0) && (t->count == 0) )
+    {
+        printf("Empty HVM SMBIOS info table\n");
+        validated = 1;
+        return table;
+    }
+
+    if ( validate_hvm_info_table((uint8_t*)t, t->length, t->signature, "SMBIOSPT") )
+        table = t;
+    else
+        printf("Bad or missing HVM SMBIOS info table\n");
+    validated = 1;
+
+    return table;
+}
+
 struct shared_info *get_shared_info(void) 
 {
     static struct shared_info *shared_info = NULL;
diff -r 0900b1c905f1 tools/firmware/hvmloader/util.h
--- a/tools/firmware/hvmloader/util.h	Mon Feb 20 18:58:07 2012 +0000
+++ b/tools/firmware/hvmloader/util.h	Mon Feb 20 20:37:12 2012 -0500
@@ -145,6 +145,8 @@
 /* HVM-builder info. */
 struct hvm_info_table *get_hvm_info_table(void) __attribute__ ((const));
 #define hvm_info (get_hvm_info_table())
+struct hvm_smbios_info_table *get_hvm_smbios_info_table(void) __attribute__ ((const));
+#define hvm_smbios_info (get_hvm_smbios_info_table())
 
 /* String and memory functions */
 int strcmp(const char *cs, const char *ct);

[-- Attachment #3: Type: text/plain, Size: 132 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/3] SMBIOS table passthrough support
  2012-02-21  2:56 [PATCH 2/3] SMBIOS table passthrough support Ross Philipson
@ 2012-02-21  8:48 ` Ian Campbell
  2012-02-21 13:42   ` Ross Philipson
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Campbell @ 2012-02-21  8:48 UTC (permalink / raw)
  To: Ross Philipson; +Cc: xen-devel


> -static void validate_hvm_info(struct hvm_info_table *t)
> +static int validate_hvm_info_table(uint8_t *table, uint32_t
> table_length,
> +    const char *table_sig, const char *sig)
>  {
> -    uint8_t *ptr = (uint8_t *)t;
>      uint8_t sum = 0;
>      int i;
>  
> -    if ( strncmp(t->signature, "HVM INFO", 8) )
> +    if (table_length == 0)
> +        printf("Empty HVM info table: %.*s\n", 8, sig);
> +
> +    /* NOTE made this a common routine to validate all HVM tables.
> Removed 
> +       BUG() on failure in here - let the caller decide if a checksum
> failure
> +       warrants that */

I think comments about what code looked like historically, what changed
and why belong in the commit message, not inline in the code.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/3] SMBIOS table passthrough support
  2012-02-21  8:48 ` Ian Campbell
@ 2012-02-21 13:42   ` Ross Philipson
  0 siblings, 0 replies; 3+ messages in thread
From: Ross Philipson @ 2012-02-21 13:42 UTC (permalink / raw)
  To: Ian Campbell; +Cc: xen-devel

> -----Original Message-----
> From: Ian Campbell [mailto:Ian.Campbell@citrix.com]
> Sent: Tuesday, February 21, 2012 3:48 AM
> To: Ross Philipson
> Cc: xen-devel@lists.xensource.com
> Subject: Re: [Xen-devel] [PATCH 2/3] SMBIOS table passthrough support
> 
> 
> > -static void validate_hvm_info(struct hvm_info_table *t)
> > +static int validate_hvm_info_table(uint8_t *table, uint32_t
> > table_length,
> > +    const char *table_sig, const char *sig)
> >  {
> > -    uint8_t *ptr = (uint8_t *)t;
> >      uint8_t sum = 0;
> >      int i;
> >
> > -    if ( strncmp(t->signature, "HVM INFO", 8) )
> > +    if (table_length == 0)
> > +        printf("Empty HVM info table: %.*s\n", 8, sig);
> > +
> > +    /* NOTE made this a common routine to validate all HVM tables.
> > Removed
> > +       BUG() on failure in here - let the caller decide if a checksum
> > failure
> > +       warrants that */
> 
> I think comments about what code looked like historically, what changed
> and why belong in the commit message, not inline in the code.
> 

Wilco

Ross

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-02-21 13:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-21  2:56 [PATCH 2/3] SMBIOS table passthrough support Ross Philipson
2012-02-21  8:48 ` Ian Campbell
2012-02-21 13:42   ` Ross Philipson

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.