Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PCI passthrough support for cloud-hypervisor platform #3331

Closed
wants to merge 2 commits into from

Conversation

smit-gardhariya
Copy link
Collaborator

Add PCI passthrough support for cloud-hypervisor platform
Add parameter to pass options while loading module using modprobe

Add options parameter for modprobe load function. This is
usefull when we need to pass options while loading the module

Signed-off-by: Smit Gardhariya <sgardhariya@microsoft.com>
@smit-gardhariya smit-gardhariya changed the title Sgardhariya/libvirt hostdev Add PCI passthrough support for cloud-hypervisor platform Jul 2, 2024
@smit-gardhariya smit-gardhariya force-pushed the sgardhariya/libvirt_hostdev branch 2 times, most recently from 1b8f941 to 930f9ae Compare July 2, 2024 12:59
squirrelsc
squirrelsc previously approved these changes Jul 2, 2024
@@ -396,7 +398,7 @@ def _configure_nodes(self, environment: Environment, log: Logger) -> None:
vm_name_prefix,
)

def _configure_node(
def _configure_node( # noqa: C901
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What warning does this suppress and why?

Copy link
Collaborator Author

@smit-gardhariya smit-gardhariya Jul 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of lot of if/else in this function, it will throw too complex function error which is C901 for flak8. There is no better way to handle this as those if/else are needed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, we can refactor the new code to a new function for example _configure_node_passthrough_devices and call this fn from _config_node

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still one if condition we have to add like below snippet, and this would cause the same error of C901

# Set device passthrough params for node context
        if node_runbook.device_passthrough:
            self._configure_device_passthrough(self, node_runbook, node_context)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it still throw the same error if we move the condition to _configure_device_passthrough itself ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we should skip the redundant call to function. Anyway, i made the change please check

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no better way to handle this as those if/else are needed

If we make the function smaller by extracting bits out into functions, this error will go away, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no better way to handle this as those if/else are needed

If we make the function smaller by extracting bits out into functions, this error will go away, right?

Even if i would put one if condition, it was coming. I wanted to call fn only when needed and avoid redundant call even when device pass through is not required.

I removed that condition also now. Please check the latest push

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this change. Looks like we got rid of the flake8 error now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that was because of IF we added. Now we removed it and calling fn every time

lisa/sut_orchestrator/libvirt/platform.py Outdated Show resolved Hide resolved
lisa/sut_orchestrator/libvirt/platform.py Outdated Show resolved Hide resolved
squirrelsc
squirrelsc previously approved these changes Jul 2, 2024
@squirrelsc squirrelsc self-requested a review July 2, 2024 16:06
@squirrelsc squirrelsc dismissed their stale review July 2, 2024 16:07

It's in reviewing by others.

lisa/sut_orchestrator/libvirt/schema.py Outdated Show resolved Hide resolved
lisa/sut_orchestrator/libvirt/schema.py Outdated Show resolved Hide resolved
lisa/sut_orchestrator/libvirt/platform.py Outdated Show resolved Hide resolved
lisa/sut_orchestrator/libvirt/context.py Outdated Show resolved Hide resolved
lisa/sut_orchestrator/libvirt/platform.py Outdated Show resolved Hide resolved
@@ -396,7 +398,7 @@ def _configure_nodes(self, environment: Environment, log: Logger) -> None:
vm_name_prefix,
)

def _configure_node(
def _configure_node( # noqa: C901
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, we can refactor the new code to a new function for example _configure_node_passthrough_devices and call this fn from _config_node

@smit-gardhariya smit-gardhariya force-pushed the sgardhariya/libvirt_hostdev branch 12 times, most recently from 952c7b7 to e727dcb Compare July 3, 2024 10:29
Add hostdev support for libvirt passthrough. This is
only for PCI device passthrough libvirt.

Signed-off-by: Smit Gardhariya <sgardhariya@microsoft.com>
@anirudhrb
Copy link
Contributor

Could you please post a sample of how a runbook with passthrough configuration would look?

@smit-gardhariya
Copy link
Collaborator Author

smit-gardhariya commented Jul 3, 2024

Could you please post a sample of how a runbook with passthrough configuration would look?

requirement: core_count: $(guest_vcpu) memory_mb: $(guest_memory) cloud-hypervisor: disk_img: $(qcow2) disk_img_format: "qcow2" firmware: $(firmware_path) cloud_init: extra_user_data: $(extra_user_data) device_passthrough: - managed: "yes" device_type: "pci" host_domain: "0000" host_bus: "19" host_slot: "00" host_function: "0" - managed: "yes" device_type: "pci" host_domain: "0000" host_bus: "19" host_slot: "00" host_function: "1"

This would remain same for QEMU/CLH. As of now we are focusing on CLH only. QEMU might require some additional change.

# Configuration options for device-passthrough for the VM.
@dataclass_json()
@dataclass
class LibvirtHostPciDeviceSchema:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing all the comments, Smit.

I have another comment in general about the approach.

As I understand it, device_passthrough is under node requirements. While this approach works with deploying of a single node, this fails with cases where multiple nodes with passthrough is needed. For example, all network tests will create multiple nodes. And by the current code logic, the deployment of second will fail since all pci devices provided in runbook would be assigned to first node itself.

PCI devices are associated with the host node. And in our context, host node is synonymous to platform. So, we should associate the host pci devices to platform than to node requirement.

Here is what I'm thinking in the form of a sample schema. Introduce 'device_pools' at platform level and define all the host devices there. Pools can be of different types like 'pci_net', 'pci_gpu' etc. All the devices that we want to be used in provisioning guests need to be defined here. And for a node/VM to use a passthrough device, the pool type and devices count has to be mentioned in the node requirement. Platform needs to handle assigning the devices accordingly from the available devices of the pool. Platform needs to maintain the state of the devices (which vm a device is assigned to or not, etc).

platform:
  - type: cloud-hypervisor
    cloud-hypervisor:
      network_boot_timeout: $(boot_timeout)
      hosts:
        - address: $(host_address)
          username: $(host_username)
          private_key_file: $(admin_private_key_file)
      capture_libvirt_debug_logs: true
      device_pools:
        - type: "pci_net"
           devices:
             - domain: "1"
                bus: "1"
                slot: "1"
                function: "1"
             - domain: "2"
                bus: "2"
                slot: "2"
                function: "2"
        - type: "pci_gpu"
           devices:
             - domain: "3"
                bus: "3"
                slot: "3"
                function: "3"
             - domain: "4"
                bus: "4"
                slot: "4"
                function: "4"
    requirement:
      core_count: $(guest_vcpu)
      memory_mb: $(guest_memory)
      cloud-hypervisor:
        disk_img: $(qcow2)
        disk_img_format: "qcow2"
        cloud_init:
          extra_user_data: $(extra_user_data)
        device_passthrough:
          - host_device_pool: "pci_net" 
            managed: "yes"
            count: 2

I haven't put too much thought into schema. What I listed above is the rough idea. I've also discussed this with @anirudhrb . We can brainstorm more on this offline and finalize the schema.

@smit-gardhariya smit-gardhariya deleted the sgardhariya/libvirt_hostdev branch July 24, 2024 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants