usb-ccid device (v2)
Quoted 93 lines · ----- "Anthony Liguori
Quoted 6 lines · Alon Levy
Quoted 3 lines · ----- "Anthony Liguori
Quoted 1 line · Alon Levy
This patch adds a new device, it is described in full in the
second
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
patch
Quoted 1 line
intro and also in the documentation in docs. In brief it provides
a
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
standard
Quoted 4 lines
smart card reader device.
The first patch is the configure change and docs.
The second patch contains the actual device, I couldn't figure outa
Quoted 11 lines
Quoted 11 lines
Quoted 1 line
good
Quoted 8 lines
way to split it to ease review.
v2 changed:
* all QSIMPLEQ turned into fixed sized rings
* all allocated buffers turned into fixed size buffers
* added migration support
* added a message to tell client qemu has migrated to ip:port
* for lack of monitor commands ip:port are 0:0, which causesthe
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
updated
Quoted 1 line
vscclient to connect to one port higher on the same host.
will
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
add monitor
Quoted 3 lines
commands in a separate patch. tested with current setup.
This is way too much magic to live within a device. Devices
manage
Quoted 8 lines
Quoted 8 lines
reconnecting themselves during migration. When you create the destination qemu instance, you specify what to connect to.
IOW,
On the source:
qemu -chardev tcp:localhost:1025,id=foo -usbdevice
ccid,chardev=foo
Quoted 5 lines
Quoted 5 lines
...
On the destination:
qemu -chardev tcp:localhost:1026,id=foo -usbdevice
ccid,chardev=foo
Quoted 5 lines
Quoted 5 lines
-incoming tcp:0.0.0.0:1024 ...
A connection happens when the device is created.
But now I'm even further confused then when I first reviewed it..
If
Quoted 2 lines
Quoted 2 lines
you're now supporting migration, does that mean that you're relying
on
Quoted 5 lines
Quoted 4 lines
the daemon to emulate the device?
Let me try to clarify this. Nothing has changed since the last patch
except
Quoted 1 line
for what's in the notes, i.e. migration support. The device I'm
adding is a
Quoted 1 line
reader. The reader is just a pipe between smart cards and the guest
operating
Quoted 1 line
system. The smart card logic does live outside of this device, and
is available
Quoted 1 line
in the
cac_cardsources athttp://cgit.freedesktop.org/~alon/cac_card/ (all of
Quoted 3 lines
this is in
docs/usb_ccid.txt).So when I speak of vscclient, I'm talking of an application that
emulates a smart
Quoted 1 line
card and initiates a tcp connection to qemu that connects to the
usb-ccid device.
Quoted 2 lines
vscclient is also in the
cac_cardsources.
Quoted 6 lines
Okay, let me be clear. We shouldn't be doing device emulation outside
of QEMU's source tree--at least, not in this type of context. External
devices present a great deal of challenges and we shouldn't just approach it in an ad-hoc fashion.
There are two devices:
smart card reader, aka CCID device - emulated inside qemu. Submitted. smart card - emulated outside of qemu. Fully available, open source separate project.
The idea here is to allow a remote device to be accessed from the guest. The remote device is not running necessarily on the qemu host, so there has to be a network connection, which implies some remote client. The only thing that is changeable is where the card is emulated - at the client side or at qemu side. I understand you favor qemu. But really this is not that much of a change as you imply, and there is a good reason for having it on the client side, namely latency of talking to the real card reader. Even if it was local to qemu, it would still have to wait for responses from the network, so I don't see how it would be less fragile.
I don't think the device right now is done ad-hoc, but you are welcome to comment on anything specific (it is up for review).
(sorry for repeating myself, I guess what follows is the main point): The CCID device is a standard USB class device, some of the USB events are handled without access to the network, and some result in a write to the chardev (==network), which is recorded, and when a read from the chardev happens some resulting USB activity happens. It is not yet without errors, but it is stable, passes migration, and works most of the time. The only exception are occasional short packets that I am still investigating, and hope won't prevent a review of the current status.
Quoted 3 lines
I'm not opposed to passthrough although I'd prefer QEMU to talk to the
passthrough I'm familiar with are all on the same host QEMU is running on, that goes for pci and usb passthrough (afaik those are the only ones).
Quoted 14 lines
device directly instead of going through a daemon.
There's a lot of delicate integration between QEMU and a device and if a
device lives outside of QEMU, it makes it extremely difficult for us to
influence changes to that device to support QEMU new features.Quoted 1 line
Regarding the method of reconnection: You are absolutely right that
if I have qemu
Quoted 1 line
connect to the remote instead of the other way around then I remove
the need to inform
Quoted 1 line
vscclient of the new address. But the way it stands requires the
client to know the
Quoted 9 lines
Quoted 1 line
address of the destination qemu. I have to inform it somehow. You
are saying that
Quoted 1 line
devices shouldn't know this information? ok, that's why I talked
about monitor commands.
Quoted 1 line
I come from the world of spice - in spice we use monitor commands
for this.
And none of that is upstream.
You only replied to the last part. What is your suggested fix for this case:
1. qemu -chardev socket,server,host=0.0.0.0,port=2001,id=foo,nowait -device virtioserial-port,chardev=foo
2. app X connects to 2001 from clienthost
3. migrate to otherhost running on otherport
otherhost$ qemu.. <same commandline, 2001 replaced with otherport>
4. X is left hanging
I realize it seems a contrived example, but I imagine the socket,server option is actually used like this, otherwise what is it there for?
Quoted 38 lines
Regards,
Anthony Liguori
Quoted 2 lines
I could
change this to have qemu connect to vscclient, but I don't see thelogic in general -
Quoted 1 line
sometimes you do want to have a chardev that is listening (the fact
that it is implemented
Quoted 1 line
suggests someone found it useful), if you then migrate you have the
same problem I'm
Quoted 27 lines
solving.
Quoted 24 lines
Regards,
Anthony Liguori
Quoted 9 lines
Alon Levy (2):
usb-ccid: add CCID device. add configure option.
usb-ccid: add CCID device (device itself)Makefile.objs | 1 + configure | 12 + docs/usb-ccid.txt | 115 +++++ hw/usb-ccid.c | 1376++++++++++++++++++++++++++++++++++++++++++++++++++++
Quoted 8 lines
hw/vscard_common.h | 131 +++++ 5 files changed, 1635 insertions(+), 0 deletions(-)create mode 100644
docs/usb-ccid.txt
create mode 100644hw/usb-ccid.c
create mode 100644hw/vscard_common.h
Quoted 145 lines · Alon Levy
Quoted 142 lines · ----- "Anthony Liguori
Quoted 9 lines · Alon Levy
Quoted 5 lines · ----- "Anthony Liguori
Quoted 2 lines · Alon Levy
This patch adds a new device, it is described in full in the
second
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
patch
Quoted 2 lines
intro and also in the documentation in docs. In brief it provides
a
Quoted 10 lines
Quoted 10 lines
Quoted 2 lines
standard
Quoted 5 lines
smart card reader device.
The first patch is the configure change and docs.
The second patch contains the actual device, I couldn't figure outa
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
good
Quoted 2 lines
way to split it to ease review.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
v2 changed:
* all QSIMPLEQ turned into fixed sized rings
* all allocated buffers turned into fixed size buffers
* added migration support
* added a message to tell client qemu has migrated to ip:port
* for lack of monitor commands ip:port are 0:0, which causesthe
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
updated
Quoted 2 lines
vscclient to connect to one port higher on the same host.
will
Quoted 11 lines
Quoted 11 lines
Quoted 2 lines
add monitor
Quoted 4 lines
commands in a separate patch. tested with current setup.
This is way too much magic to live within a device. Devices
manage
Quoted 9 lines
Quoted 9 lines
reconnecting themselves during migration. When you create the destination qemu instance, you specify what to connect to.
IOW,
On the source:
qemu -chardev tcp:localhost:1025,id=foo -usbdevice
ccid,chardev=foo
Quoted 6 lines
Quoted 6 lines
...
On the destination:
qemu -chardev tcp:localhost:1026,id=foo -usbdevice
ccid,chardev=foo
Quoted 6 lines
Quoted 6 lines
-incoming tcp:0.0.0.0:1024 ...
A connection happens when the device is created.
But now I'm even further confused then when I first reviewed it..
If
Quoted 2 lines
Quoted 2 lines
you're now supporting migration, does that mean that you're relying
on
Quoted 6 lines
Quoted 4 lines
the daemon to emulate the device?
Let me try to clarify this. Nothing has changed since the last patch
except
Quoted 2 lines
for what's in the notes, i.e. migration support. The device I'm
adding is a
Quoted 2 lines
reader. The reader is just a pipe between smart cards and the guest
operating
Quoted 2 lines
system. The smart card logic does live outside of this device, and
is available
Quoted 2 lines
in the
cac_cardsources athttp://cgit.freedesktop.org/~alon/cac_card/ (all of
Quoted 4 lines
this is in
docs/usb_ccid.txt).So when I speak of vscclient, I'm talking of an application that
emulates a smart
Quoted 2 lines
card and initiates a tcp connection to qemu that connects to the
usb-ccid device.
Quoted 3 lines
vscclient is also in the
cac_cardsources.Okay, let me be clear. We shouldn't be doing device emulation outside
Quoted 9 lines
Quoted 5 lines
of QEMU's source tree--at least, not in this type of context. External
devices present a great deal of challenges and we shouldn't just approach it in an ad-hoc fashion.There are two devices:
smart card reader, aka CCID device - emulated inside qemu. Submitted. smart card - emulated outside of qemu. Fully available, open source separate project.
And how does the smart card state get migrated during migration? How do you keep it synced with QEMU?
I don't understand the use-case behind this. Is this so that a local physical smart card can be passed through to a guest from a Spice client and when migration happens, the QEMU instance connects back to the Spice client? So the device is never actually migrated?
Regards,
Anthony Liguori
Quoted 163 lines · ----- "Anthony Liguori
Quoted 14 lines · Alon Levy
Quoted 11 lines · ----- "Anthony Liguori
Quoted 9 lines · Alon Levy
Quoted 5 lines · ----- "Anthony Liguori
Quoted 2 lines · Alon Levy
This patch adds a new device, it is described in full in the
Quoted 8 lines
Quoted 8 lines
second
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
patch
Quoted 1 line
intro and also in the documentation in docs. In brief it
provides
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
a
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
standard
Quoted 4 lines
smart card reader device.
The first patch is the configure change and docs. The second patch contains the actual device, I couldn't figure
out
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
a
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
good
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
way to split it to ease review.
v2 changed:
* all QSIMPLEQ turned into fixed sized rings
* all allocated buffers turned into fixed size buffers
* added migration support
* added a message to tell client qemu has migrated toip:port
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
* for lack of monitor commands ip:port are 0:0, which
causes
Quoted 42 lines
Quoted 42 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
the
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
updated
Quoted 2 lines
vscclient to connect to one port higher on the same host.
will
Quoted 11 lines
Quoted 11 lines
Quoted 2 lines
add monitor
Quoted 4 lines
commands in a separate patch. tested with current setup.
This is way too much magic to live within a device. Devices
manage
Quoted 9 lines
Quoted 9 lines
reconnecting themselves during migration. When you create the destination qemu instance, you specify what to connect to.
IOW,
On the source:
qemu -chardev tcp:localhost:1025,id=foo -usbdevice
ccid,chardev=foo
Quoted 6 lines
Quoted 6 lines
...
On the destination:
qemu -chardev tcp:localhost:1026,id=foo -usbdevice
Quoted 7 lines
Quoted 7 lines
ccid,chardev=foo
Quoted 5 lines
Quoted 5 lines
-incoming tcp:0.0.0.0:1024 ...
A connection happens when the device is created.
But now I'm even further confused then when I first reviewed
it..
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
If
Quoted 1 line
Quoted 1 line
you're now supporting migration, does that mean that you're
relying
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
on
Quoted 5 lines
Quoted 4 lines
the daemon to emulate the device?
Let me try to clarify this. Nothing has changed since the last
patch
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
except
Quoted 2 lines
for what's in the notes, i.e. migration support. The device I'm
adding is a
Quoted 1 line
reader. The reader is just a pipe between smart cards and the
guest
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
operating
Quoted 1 line
system. The smart card logic does live outside of this device,
and
Quoted 13 lines
Quoted 13 lines
Quoted 1 line
is available
Quoted 2 lines
in the
cac_cardsources athttp://cgit.freedesktop.org/~alon/cac_card/ (all of
Quoted 4 lines
this is in
docs/usb_ccid.txt).So when I speak of vscclient, I'm talking of an application that
emulates a smart
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
card and initiates a tcp connection to qemu that connects to the
usb-ccid device.
Quoted 3 lines
vscclient is also in the
cac_cardsources.Okay, let me be clear. We shouldn't be doing device emulation
outside
Quoted 8 lines
Quoted 6 lines
of QEMU's source tree--at least, not in this type of context. External
devices present a great deal of challenges and we shouldn't just approach it in an ad-hoc fashion.There are two devices:
smart card reader, aka CCID device - emulated inside qemu.
Quoted 8 lines
Submitted.
Quoted 1 line
smart card - emulated outside of qemu. Fully available, open
source separate project.
Quoted 1 line
And how does the smart card state get migrated during migration? How do
you keep it synced with QEMU?
The smart card is not being migrated. It is running on the client machine, which is not being migrated/shutdown (same as vncviewer isn't migrated).
Quoted 9 lines
I don't understand the use-case behind this. Is this so that a local
physical smart card can be passed through to a guest from a Spice client
and when migration happens, the QEMU instance connects back to the Spice
client? So the device is never actually migrated?
The *smart card* is never migrated. The ccid device is. Here is the scenario:
Host A: qemu_aqemu_a: guest
Host B: vscclient
- physical reader
Host C: qemu_b -incoming ..
yes, we will use this for SPICE, but this is submitted
to qemu on the hopes and with testing ensuring it is perfectly usable as is without using SPICE, otherwise I wouldn't have sent it upstream.
non-SPICE usage:
1. user on B runs vscclient (and presumably the user has some connection to the guest to use the smartcard device, i.e. vnc/ssh/spice, but that's not relevant).
2. vscclient connects via tcp to qemu_a.
3. qemu_a starts migrating to qemu_b.
(qemu_b is alive at this point, can receive incoming tcp connections on chardev - otherwise a migration fails immediately anyway)
4. pre_load for usb-ccid sends a Reconnect message
5. vscclient gets the Reconnect message, closes socket to qemu_a, opens socket to qemu_b
6. from guest pov nothing happened (no device detach/attach).
I have to stress that the main problem the migration intends to solve is to avoid a detach/attach in the guest. Actual operations on the smartcard could possibly fail as a result of the migration, and it would not be a real problem (i.e. we could live without, but we can't leave with a lock of the guest screen as a result of a migration). Which is why I consider the current code good enough. It is certainly not perfect (short packet issue), or tested enough.
The SPICE usage scenario is basically the same, just replace vscclient with spicec, and
we don't need the Reconnect message since SPICE takes care of this for us (we just get
a channel detach/attach event if we care).
1. user on B runs spicec
2. spicec connects to qemu via spice channel, smart card channel connects to usb-ccid device via spicevmc chardev (so it doesn't care it's spice or not).
3. qemu_a migrates
4. spicec disconnects from qemu_a and connects to qemu_b
5. from guest os pov nothing happens on the ccid usb device.
Quoted 3 lines
Regards,
Anthony Liguori
Quoted 4 lines · Alon Levy
The smart card is not being migrated. It is running on the client machine, which is not being migrated/shutdown (same as vncviewer isn't migrated).
Ok, let's look at this compared to another similar use-case: USB passthrough of a webcam device that's remoted using USB over IP.
In this model, you have a USB bus that's modelled as a bus and a device. Within the USB bus, you have additional devices. These are all qdev devices and they may be emulated or they may be implemented using passthrough. While we don't do it today, USB over IP would be just another form of passthrough.
Migration is a rather interesting challenge in this model. You've got a mix of client state and server state on the USB over IP connection. You could marshal up the client state and as long as you reconnected to the same server on the destination, I guess it would be okay.
I think the problem with your current implementation is that you've completed skipped the bus modelling and you're also using the Device over IP connection to implement device emulation.
What I would suggest is that you model the bus/device relationship via qdev and move the Smart Card emulation into QEMU. I would also suggest adding proper passthrough support in QEMU. CCID over IP is a reasonable thing to have but I think you've got way too much outside of QEMU right now such that long term maintenance is going to be exceedingly difficult.
Regards,
Anthony Liguori
Quoted 52 lines
Quoted 9 lines
I don't understand the use-case behind this. Is this so that a local
physical smart card can be passed through to a guest from a Spice client
and when migration happens, the QEMU instance connects back to the Spice
client? So the device is never actually migrated?The *smart card* is never migrated. The ccid device is. Here is the scenario:
Host A:
qemu_aqemu_a: guestHost B: vscclient
- physical readerHost C:
qemu_b-incoming ..yes, we will use this for SPICE, but this is submitted
to qemu on the hopes and with testing ensuring it is perfectly usable as is without using SPICE, otherwise I wouldn't have sent it upstream.non-SPICE usage:
1. user on B runs vscclient (and presumably the user has some connection to the guest to use the smartcard device, i.e. vnc/ssh/spice, but that's not relevant).
2. vscclient connects via tcp toqemu_a.
3.qemu_astarts migrating toqemu_b.
(qemu_bis alive at this point, can receive incoming tcp connections on chardev - otherwise a migration fails immediately anyway)
4.pre_loadfor usb-ccid sends a Reconnect message
5. vscclient gets the Reconnect message, closes socket toqemu_a, opens socket toqemu_b
6. from guest pov nothing happened (no device detach/attach).I have to stress that the main problem the migration intends to solve is to avoid a detach/attach in the guest. Actual operations on the smartcard could possibly fail as a result of the migration, and it would not be a real problem (i.e. we could live without, but we can't leave with a lock of the guest screen as a result of a migration). Which is why I consider the current code good enough. It is certainly not perfect (short packet issue), or tested enough.
The SPICE usage scenario is basically the same, just replace vscclient with spicec, and
we don't need the Reconnect message since SPICE takes care of this for us (we just get
a channel detach/attach event if we care).
1. user on B runs spicec
2. spicec connects to qemu via spice channel, smart card channel connects to usb-ccid device via spicevmc chardev (so it doesn't care it's spice or not).
3.qemu_amigrates
4. spicec disconnects fromqemu_aand connects toqemu_b
5. from guest os pov nothing happens on the ccid usb device.Quoted 4 lines
Regards,
Anthony Liguori
Quoted 33 lines · ----- "Anthony Liguori
Quoted 1 line · Alon Levy
The smart card is not being migrated. It is running on the client
machine,
Quoted 1 line
which is not being migrated/shutdown (same as vncviewer isn't
migrated).
Quoted 2 lines
Ok, let's look at this compared to another similar use-case: USB passthrough of a webcam device that's remoted using USB over IP.
In this model, you have a USB bus that's modelled as a bus and a device. Within the USB bus, you have additional devices. These are all
qdev devices and they may be emulated or they may be implemented usingpassthrough. While we don't do it today, USB over IP would be just another form of passthrough.
Migration is a rather interesting challenge in this model. You've got a
mix of client state and server state on the USB over IP connection. You
could marshal up the client state and as long as you reconnected to the
same server on the destination, I guess it would be okay.I think the problem with your current implementation is that you've completed skipped the bus modelling and you're also using the Device over IP connection to implement device emulation.
What I would suggest is that you model the bus/device relationship via
Quoted 9 lines
qdev and move the Smart Card emulation into QEMU. I would also suggest
adding proper passthrough support in QEMU. CCID over IP is a reasonable
thing to have but I think you've got way too much outside of QEMU right
now such that long term maintenance is going to be exceedingly difficult.
CCID over IP doesn't make any sense (It's just a specific sort of reader), but I assume you meant APDU (the smart card protocol) over IP, which is exactly what vscard_common.h protocol has (so that's already ready). I'll address the modeling of the reader device as a bus and add optional card emulation. You can regard the current implementation as exactly passthrough of APDU, that's what it does - pushes the APDU's to a remote client, and gets APDUs in return. Since I'm using an existing library for the card emulation I will make qemu link with it.
Alon
Quoted 72 lines
Regards,
Anthony Liguori
Quoted 1 line
Quoted 1 line
I don't understand the use-case behind this. Is this so that a
local
Quoted 9 lines
Quoted 8 lines
physical smart card can be passed through to a guest from a Spice client
and when migration happens, the QEMU instance connects back to the Spice
client? So the device is never actually migrated?The *smart card* is never migrated. The ccid device is. Here is the
scenario:
Quoted 11 lines
Host A:
qemu_aqemu_a: guestHost B: vscclient
- physical readerHost C:
qemu_b-incoming ..yes, we will use this for SPICE, but this is submitted to qemu on the hopes and with testing ensuring it is perfectly
usable as is
Quoted 5 lines
without using SPICE, otherwise I wouldn't have sent it upstream.
non-SPICE usage:
1. user on B runs vscclient (and presumably the user has some
connection to the guest to use the smartcard device, i.e. vnc/ssh/spice, but that's not relevant).
Quoted 3 lines
2. vscclient connects via tcp to
qemu_a.
3.qemu_astarts migrating toqemu_b.
(qemu_bis alive at this point, can receive incoming tcpconnections on chardev - otherwise a migration fails immediately anyway)
Quoted 2 lines
4.
pre_loadfor usb-ccid sends a Reconnect message
5. vscclient gets the Reconnect message, closes socket toqemu_a,opens socket to
qemu_bQuoted 3 lines
6. from guest pov nothing happened (no device detach/attach).
I have to stress that the main problem the migration intends to
solve is to avoid a detach/attach in the guest. Actual
Quoted 1 line
operations on the smartcard could possibly fail as a result of the
migration, and it would not be a real problem (i.e.
Quoted 1 line
we could live without, but we can't leave with a lock of the guest
screen as a result of a migration). Which is why I
Quoted 1 line
consider the current code good enough. It is certainly not perfect
(short packet issue), or tested enough.
Quoted 2 lines
The SPICE usage scenario is basically the same, just replace
vscclient with spicec, and
Quoted 1 line
we don't need the Reconnect message since SPICE takes care of this
for us (we just get
Quoted 3 lines
a channel detach/attach event if we care).
1. user on B runs spicec
2. spicec connects to qemu via spice channel, smart card channelconnects to usb-ccid device via spicevmc chardev (so it doesn't care it's spice or not).
Quoted 9 lines
3.
qemu_amigrates
4. spicec disconnects fromqemu_aand connects toqemu_b
5. from guest os pov nothing happens on the ccid usb device.Quoted 4 lines
Regards,
Anthony Liguori