virtcontainers: Separate PCI/CCW for net devices

On s390x, virtio-net devices should use CCW, alongside a different
device path. Use accordingly.

Signed-off-by: Jakob Naucke <jakob.naucke@ibm.com>
This commit is contained in:
Jakob Naucke 2025-01-30 16:59:12 +01:00
parent 2aa523f08a
commit a084b99324
No known key found for this signature in database
GPG Key ID: D34F14412FB929FC
4 changed files with 41 additions and 11 deletions

View File

@ -12,6 +12,7 @@ import (
"fmt"
"net"
"os"
"runtime"
"github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"
@ -263,6 +264,15 @@ func generateVCNetworkStructures(ctx context.Context, endpoints []Endpoint) ([]*
ipAddresses = append(ipAddresses, &ipAddress)
}
noarp := endpoint.Properties().Iface.RawFlags & unix.IFF_NOARP
devicePath := endpoint.PciPath().String()
if runtime.GOARCH == "s390x" {
device := endpoint.CcwDevice()
if device == nil {
devicePath = ""
} else {
devicePath = device.String()
}
}
ifc := pbTypes.Interface{
IPAddresses: ipAddresses,
Device: endpoint.Name(),
@ -271,7 +281,7 @@ func generateVCNetworkStructures(ctx context.Context, endpoints []Endpoint) ([]*
Type: string(endpoint.Type()),
RawFlags: noarp,
HwAddr: endpoint.HardwareAddr(),
DevicePath: endpoint.PciPath().String(),
DevicePath: devicePath,
}
ifaces = append(ifaces, &ifc)

View File

@ -1942,16 +1942,7 @@ func (q *qemu) hotplugNetDevice(ctx context.Context, endpoint Endpoint, op Opera
}
}()
bridgeSlot, err := types.PciSlotFromInt(bridge.Addr)
if err != nil {
return err
}
devSlot, err := types.PciSlotFromString(addr)
if err != nil {
return err
}
pciPath, err := types.PciPathFromSlots(bridgeSlot, devSlot)
endpoint.SetPciPath(pciPath)
q.arch.setEndpointDevicePath(endpoint, bridge.Addr, addr)
var machine govmmQemu.Machine
machine, err = q.getQemuMachine()

View File

@ -116,6 +116,9 @@ type qemuArch interface {
// appendRNGDevice appends a RNG device to devices
appendRNGDevice(ctx context.Context, devices []govmmQemu.Device, rngDevice config.RNGDev) ([]govmmQemu.Device, error)
// setEndpointDevicePath sets the appropriate PCI or CCW device path for an endpoint
setEndpointDevicePath(endpoint Endpoint, bridgeAddr int, devAddr string) error
// addDeviceToBridge adds devices to the bus
addDeviceToBridge(ctx context.Context, ID string, t types.Type) (string, types.Bridge, error)
@ -732,6 +735,23 @@ func (q *qemuArchBase) appendRNGDevice(_ context.Context, devices []govmmQemu.De
return devices, nil
}
func (q *qemuArchBase) setEndpointDevicePath(endpoint Endpoint, bridgeAddr int, devAddr string) error {
bridgeSlot, err := types.PciSlotFromInt(bridgeAddr)
if err != nil {
return err
}
devSlot, err := types.PciSlotFromString(devAddr)
if err != nil {
return err
}
pciPath, err := types.PciPathFromSlots(bridgeSlot, devSlot)
if err != nil {
return err
}
endpoint.SetPciPath(pciPath)
return nil
}
func (q *qemuArchBase) handleImagePath(config HypervisorConfig) error {
if config.ImagePath != "" {
kernelRootParams, err := GetKernelRootParams(config.RootfsType, q.disableNvdimm, false)

View File

@ -304,6 +304,15 @@ func (q *qemuS390x) appendIOMMU(devices []govmmQemu.Device) ([]govmmQemu.Device,
return devices, fmt.Errorf("S390x does not support appending a vIOMMU")
}
func (q *qemuS390x) setEndpointDevicePath(endpoint Endpoint, bridgeAddr int, devAddr string) error {
ccwDev, err := types.CcwDeviceFrom(bridgeAddr, devAddr)
if err != nil {
return err
}
endpoint.SetCcwDevice(ccwDev)
return nil
}
func (q *qemuS390x) addDeviceToBridge(ctx context.Context, ID string, t types.Type) (string, types.Bridge, error) {
addr, b, err := genericAddDeviceToBridge(ctx, q.Bridges, ID, types.CCW)
if err != nil {