xl/libxl: Add ability to specify SMBIOS strings

hvm_xs_strings.h specifies xenstore entries which can be used to set or
override smbios strings.  hvmloader has support for reading them, but
xl/libxl support is not wired up.

Allow specifying the strings with the new xl.cfg option:
smbios=["bios_vendor=Xen Project","system_version=1.0"]

In terms of strings, the SMBIOS specification 3.5 says:
https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.5.0.pdf
"""
Strings must be encoded as UTF-8 with no byte order mark (BOM). For
compatibility with older SMBIOS parsers, US-ASCII characters should be
used.  NOTE There is no limit on the length of each individual text
string. However, the length of the entire structure table (including all
strings) must be reported in the Structure Table Length field of the
32-bit Structure Table Entry Point (see 5.2.1) and/or the Structure
Table Maximum Size field of the 64-bit Structure Table Entry Point (see
5.2.2).
"""

The strings aren't checked for utf-8 or length.  hvmloader has a sanity
check on the overall length.

The libxl_smbios_type enum starts at 1 since otherwise the 0th key is
not printed in the json output.

Signed-off-by: Jason Andryuk <jandryuk@gmail.com>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
This commit is contained in:
Jason Andryuk authored and Andrew Cooper committed 2023-03-15 18:41:46 +00:00
1 parent d03246206c
commit 9aeb3a20c4
7 files changed
+232 -1

No files matched your search

+51
View File
@@ -589,6 +589,38 @@ xc.build_id = C.CString(x.BuildId)}
return nil
}
// NewSmbios returns an instance of Smbios initialized with defaults.
func NewSmbios() (*Smbios, error) {
var (
x Smbios
xc C.libxl_smbios)
C.libxl_smbios_init(&xc)
defer C.libxl_smbios_dispose(&xc)
if err := x.fromC(&xc); err != nil {
return nil, err }
return &x, nil}
func (x *Smbios) fromC(xc *C.libxl_smbios) error {
x.Key = SmbiosType(xc.key)
x.Value = C.GoString(xc.value)
return nil}
func (x *Smbios) toC(xc *C.libxl_smbios) (err error){defer func(){
if err != nil{
C.libxl_smbios_dispose(xc)}
}()
xc.key = C.libxl_smbios_type(x.Key)
if x.Value != "" {
xc.value = C.CString(x.Value)}
return nil
}
// NewDomainCreateInfo returns an instance of DomainCreateInfo initialized with defaults.
func NewDomainCreateInfo() (*DomainCreateInfo, error) {
var (
@@ -1183,6 +1215,15 @@ return fmt.Errorf("converting field Altp2M: %v", err)
}
x.SystemFirmware = C.GoString(tmp.system_firmware)
x.SmbiosFirmware = C.GoString(tmp.smbios_firmware)
x.Smbios = nil
if n := int(tmp.num_smbios); n > 0 {
cSmbios := (*[1<<28]C.libxl_smbios)(unsafe.Pointer(tmp.smbios))[:n:n]
x.Smbios = make([]Smbios, n)
for i, v := range cSmbios {
if err := x.Smbios[i].fromC(&v); err != nil {
return fmt.Errorf("converting field Smbios: %v", err) }
}
}
x.AcpiFirmware = C.GoString(tmp.acpi_firmware)
x.Hdtype = Hdtype(tmp.hdtype)
if err := x.Nographic.fromC(&tmp.nographic);err != nil {
@@ -1495,6 +1536,16 @@ if tmp.SystemFirmware != "" {
hvm.system_firmware = C.CString(tmp.SystemFirmware)}
if tmp.SmbiosFirmware != "" {
hvm.smbios_firmware = C.CString(tmp.SmbiosFirmware)}
if numSmbios := len(tmp.Smbios); numSmbios > 0 {
hvm.smbios = (*C.libxl_smbios)(C.malloc(C.ulong(numSmbios)*C.sizeof_libxl_smbios))
hvm.num_smbios = C.int(numSmbios)
cSmbios := (*[1<<28]C.libxl_smbios)(unsafe.Pointer(hvm.smbios))[:numSmbios:numSmbios]
for i,v := range tmp.Smbios {
if err := v.toC(&cSmbios[i]); err != nil {
return fmt.Errorf("converting field Smbios: %v", err)
}
}
}
if tmp.AcpiFirmware != "" {
hvm.acpi_firmware = C.CString(tmp.AcpiFirmware)}
hvm.hdtype = C.libxl_hdtype(tmp.Hdtype)
+27
View File
@@ -392,6 +392,32 @@ Commandline string
BuildId string
}
type SmbiosType int
const(
SmbiosTypeBiosVendor SmbiosType = 1
SmbiosTypeBiosVersion SmbiosType = 2
SmbiosTypeSystemManufacturer SmbiosType = 3
SmbiosTypeSystemProductName SmbiosType = 4
SmbiosTypeSystemVersion SmbiosType = 5
SmbiosTypeSystemSerialNumber SmbiosType = 6
SmbiosTypeBaseboardManufacturer SmbiosType = 7
SmbiosTypeBaseboardProductName SmbiosType = 8
SmbiosTypeBaseboardVersion SmbiosType = 9
SmbiosTypeBaseboardSerialNumber SmbiosType = 10
SmbiosTypeBaseboardAssetTag SmbiosType = 11
SmbiosTypeBaseboardLocationInChassis SmbiosType = 12
SmbiosTypeEnclosureManufacturer SmbiosType = 13
SmbiosTypeEnclosureSerialNumber SmbiosType = 14
SmbiosTypeEnclosureAssetTag SmbiosType = 15
SmbiosTypeBatteryManufacturer SmbiosType = 16
SmbiosTypeBatteryDeviceName SmbiosType = 17
)
type Smbios struct {
Key SmbiosType
Value string
}
type DomainCreateInfo struct {
Type DomainType
Hap Defbool
@@ -572,6 +598,7 @@ NestedHvm Defbool
Altp2M Defbool
SystemFirmware string
SmbiosFirmware string
Smbios []Smbios
AcpiFirmware string
Hdtype Hdtype
Nographic Defbool
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.