Re: [vfio-users] Accessing the PCI config space from both the VM and the host

2022-08-02 Thread Alex Williamson
On Fri, 29 Jul 2022 21:43:44 +0300
Cosmin Chenaru  wrote:

> Hi,
> 
> I have an Intel network card inside a VM using PCI-Passthrough and I would
> like to write one register (the Physical Hardware Clock) but from inside
> the host, as writing it from inside the VM is complicated with all the
> unstable vTSC or other time sensitive tools which don't work best from
> inside a VM.
> 
> I know that I cannot write it from the host's network driver, as the driver
> will unbind the card when starting the VM, so let's say I write the
> register from another place (either hacking the network driver or from the
> VFIO driver). Do you think this would be possible?
> 
> Also, should I worry about locking the access so that the host and VM don't
> write to the PCI config space at the same time? I watched Alex's VFIO
> presentations and I understand that through Memory Mapped IO the VM can
> directly write the PCI config space, so the host will not be able to
> intercept and, in my case, to do the locking.
> 
> And my apologies if these questions were asked before. I did do a quick
> search but could not find anything relevant.

If you want special handling of the device in the host then you could
write a vfio-pci variant driver, see for instance the mlx5 one recently
added, and do the register write at an opportune time.  I'm a bit
dubious why this can't be written in the guest though.

If you want the simplest means to poke the register from the host, see
setpci(8).  I don't think you need any special locking, all config space
accesses come in through read/write operations to the config space
region and go through the same accessor functions that setpci would
use.  Thanks,

Alex

___
vfio-users mailing list
vfio-users@redhat.com
https://listman.redhat.com/mailman/listinfo/vfio-users



[vfio-users] Accessing the PCI config space from both the VM and the host

2022-08-01 Thread Cosmin Chenaru
Hi,

I have an Intel network card inside a VM using PCI-Passthrough and I would
like to write one register (the Physical Hardware Clock) but from inside
the host, as writing it from inside the VM is complicated with all the
unstable vTSC or other time sensitive tools which don't work best from
inside a VM.

I know that I cannot write it from the host's network driver, as the driver
will unbind the card when starting the VM, so let's say I write the
register from another place (either hacking the network driver or from the
VFIO driver). Do you think this would be possible?

Also, should I worry about locking the access so that the host and VM don't
write to the PCI config space at the same time? I watched Alex's VFIO
presentations and I understand that through Memory Mapped IO the VM can
directly write the PCI config space, so the host will not be able to
intercept and, in my case, to do the locking.

And my apologies if these questions were asked before. I did do a quick
search but could not find anything relevant.

Thank you.

Cosmin.
___
vfio-users mailing list
vfio-users@redhat.com
https://listman.redhat.com/mailman/listinfo/vfio-users