Re: [PATCH v10] i2c: virtio: add a virtio i2c frontend driver

2 messages, 2 authors, 2021-06-29 · open the first message on its own page

Re: [PATCH v10] i2c: virtio: add a virtio i2c frontend driver

From: Arnd Bergmann <arnd@arndb.de>
Date: 2021-06-28 09:04:20

On Mon, Jun 28, 2021 at 10:39 AM Wolfram Sang [off-list ref] wrote:
sorry for the long delay. I am not familiar with VFIO, so I had to dive
into the topic a little first. I am still not seeing through it
completely, so I have very high-level questions first.
You probably know this already, but just in case for clarification
these are two different things:

VFIO: kernel feature to make raw (usually PCI) devices available
           to user space drivers and virtual machines from a kernel
           running on bare metal.

virtio: transport protocol for implementing arbitrary paravirtualized
          drivers in (usually) a virtual machine guest without giving the
          guest access to hardware registers.

Both can be used for letting a KVM guest talk to the outside world,
but usually you have one or the other, not both.
quoted
The device specification can be found on
https://lists.oasis-open.org/archives/virtio-comment/202101/msg00008.html.
I think we need to start here:

===

If ``length of \field{read_buf}''=0 and ``length of \field{write_buf}''>0,
the request is called write request.

If ``length of \field{read_buf}''>0 and ``length of \field{write_buf}''=0,
the request is called read request.

If ``length of \field{read_buf}''>0 and ``length of \field{write_buf}''>0,
the request is called write-read request. It means an I2C write segment followed
by a read segment. Usually, the write segment provides the number of an I2C
controlled device register to be read.

===

I2C transactions can have an arbitrary number of messages which can
arbitrarily be read or write. As I understand the above, only one read,
write or read-write transaction is supported. If that is the case, it
would be not very much I2C but more SMBus. If my assumptions are true,
we first need to decide if you want to go the I2C way or SMBus subset.
This has come up in previous reviews already. I think it comes down
to the requirement that the virtio i2c protocol should allow passthrough
access to any client devices connected to a physical i2c bus on the host,
and this should ideally be independent of whether the host driver
exposes I2C_RDWR or I2C_SMBUS ioctl interface, or both.

This can be done either by having both interface types in the transport,
or picking one of the two, and translating to the host interface type
in software.

As far as I understand me (please clarify), implementing only the smbus
subset would mean that we cannot communicate with all client devices,
while implementing both would add more complexity than the lower-level
protocol.
===

The case when ``length of \field{write_buf}''=0, and at the same time,
``length of \field{read_buf}''=0 doesn't make any sense.

===

Oh, it does. That's a legal transfer, both in SMBus and I2C. It is used
to e.g. discover devices. I think it should be supported, even though
not all bus master drivers on the host can support it. Is it possible?

Also, as I read it, a whole bus is para-virtualized to the guest, or?
Wouldn't it be better to allow just specific devices on a bus? Again, I
am kinda new to this, so I may have overlooked things.
Do you mean just allowing a single device per bus (as opposed to
having multiple devices as on a real bus), or just allowing
a particular set of client devices that can be identified using
virtio specific configuration (as opposed to relying on device
tree or similar for probing). Both of these are valid questions that
have been discussed before, but that could be revisited.

          Arnd
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Re: [PATCH v10] i2c: virtio: add a virtio i2c frontend driver

From: Jie Deng <hidden>
Date: 2021-06-29 03:03:52

On 2021/6/28 17:01, Arnd Bergmann wrote:
On Mon, Jun 28, 2021 at 10:39 AM Wolfram Sang [off-list ref] wrote:
quoted
sorry for the long delay. I am not familiar with VFIO, so I had to dive
into the topic a little first. I am still not seeing through it
completely, so I have very high-level questions first.
You probably know this already, but just in case for clarification
these are two different things:

VFIO: kernel feature to make raw (usually PCI) devices available
            to user space drivers and virtual machines from a kernel
            running on bare metal.

virtio: transport protocol for implementing arbitrary paravirtualized
           drivers in (usually) a virtual machine guest without giving the
           guest access to hardware registers.
Thanks Arnd for clarification.

Let me add some more:


The native model is as follows: a specific native I2C driver operates a 
specific hardware.

A specific native I2C driver  <--> A specific hardware


The virtio paravirtualized model is something like:

virtio-i2c <--> virtio I2C interfaces <--> virtio-backend <--> Real hardware

virtio-i2c: is this driver, the frontend driver.

virtio I2C interfaces: which are described in the specification.

https://raw.githubusercontent.com/oasis-tcs/virtio-spec/master/virtio-i2c.tex.

     I had tried to mirror Linux I2C interfaces (like "i2c_msg") into 
virtio I2C interface directly. But

     when I was doing upstream for this specification, I understood the 
virtio TC had the design philosophy

     "VIRTIO devices are not specific to Linux so the specs design 
should avoid the limitations of the

     current Linux driver behavior." So we redefined a minimum virtio 
I2C interfaces to make a working POC.

     and we may extend it in the future according to the need.

virtio-backend: the backend driver communicate with virtio-i2c by 
following virtio I2C interfaces specs.

      The are already two backend drivers developed by Viresh, one in 
QEMU, another in rust-vmm.

      1. vhost-user: 
https://lore.kernel.org/qemu-devel/cover.1617278395.git.viresh.kumar@linaro.org/t/#m3b5044bad9769b170f505e63bd081eb27cef8db2

      2. rust-vmm I2C backend: 
https://github.com/rust-vmm/vhost-device/pull/1


Regards,

Jie







_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help