Drivers: hv: vmbus: add APIs to register callbacks to process hvsock connection
Subsystems (3)
Dexuan Cui
maintainerPATCH v4 4/7 Drivers: hv: vmbus: add APIs to register callbacks to process hvsock connection
With the 2 APIs supplied by the VMBus driver, the coming net/hvsock driver can register 2 callbacks and can know when a new hvsock connection is offered by the host, and when a hvsock connection is being closed by the host.
--- drivers/hv/Makefile | 4 ++- drivers/hv/channel_mgmt.c | 9 ++++++ drivers/hv/hvsock_callbacks.c | 71 +++++++++++++++++++++++++++++++++++++++++++ include/linux/hyperv.h | 10 ++++++ 4 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 drivers/hv/hvsock_callbacks.c
drivers/hv/Makefile +3 -1
@@ -4,5 +4,7 @@ obj-$(CONFIG_HYPERV_BALLOON) += hv_balloon.o hv_vmbus-y := vmbus_drv.o \ hv.o connection.o channel.o \ - channel_mgmt.o ring_buffer.o + channel_mgmt.o ring_buffer.o \ + hvsock_callbacks.o + hv_utils-y := hv_util.o hv_kvp.o hv_snapshot.o hv_fcopy.o hv_utils_transport.o
drivers/hv/channel_mgmt.c +9 -0
@@ -300,6 +300,12 @@ static void vmbus_process_offer(struct vmbus_channel *newchannel)return ; } +if (is_hvsock_channel (newchannel)) { +if (hvsock_process_offer (newchannel) !=0 ) + goto err_deq_chan; +return ; + } +/* * Start the process of binding this offer to the driver * We need to set the DeviceObject field before calling
@@ -564,7 +570,10 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr)vmbus_device_unregister (channel->device_obj);put_device (dev); } + }else if (is_hvsock_channel (channel)) { +hvsock_process_offer_rescind (channel); }else { +/* it is a sub-channel. */ hv_process_channel_removal (channel, channel->offermsg.child_relid); }
drivers/hv/hvsock_callbacks.c new file +71 -0
71 lines not on this page · raw message
include/linux/hyperv.h +10 -0
@@ -1269,6 +1269,16 @@ extern __u32 vmbus_proto_version;int vmbus_send_tl_connect_request (const uuid_le *shv_guest_servie_id,const uuid_le *shv_host_servie_id); + +extern int hvsock_process_offer (struct vmbus_channel *channel); +extern void hvsock_process_offer_rescind (struct vmbus_channel *channel); + +extern void vmbus_register_hvsock_callbacks ( +int (*process_offer)(struct vmbus_channel *), +void (*process_offer_rescind)(struct vmbus_channel *)); + +void vmbus_unregister_hvsock_callbacks (void ); +struct vmpipe_proto_header {u32 pkt_type;
Signature · 1 line
2.1.0
David Miller
maintainerFrom: Dexuan Cui <[email protected]>
Date: Tue, 28 Jul 2015 05:35:11 -0700
Quoted 6 lines
With the 2 APIs supplied by the VMBus driver, the coming net/hvsock driver can register 2 callbacks and can know when a new hvsock connection is offered by the host, and when a hvsock connection is being closed by the host.
Signed-off-by Dexuan Cui <[email protected]>
This is an extremely terrible interface.
It's an opaque hook that allows on registry, and it's solve purpose is to allow a backdoor call into a foreign driver in another module.
These are exactly the things we try to avoid.
Why not create a real abstraction where clients register an object, that can be contained as a sub-member inside of their own driver private, that provides the callback registry mechanism.
That way you can register multiple clients, do things like allow AF_PACKET capturing of vmbus traffic, etc.
Dexuan Cui
maintainerQuoted 11 lines
From: David Miller
Sent: Thursday, July 30, 2015 6:27From: Dexuan Cui
Date: Tue, 28 Jul 2015 05:35:11 -0700Quoted 5 lines
With the 2 APIs supplied by the VMBus driver, the coming net/hvsock driver can register 2 callbacks and can know when a new hvsock connection is offered by the host, and when a hvsock connection is being closed by the host.
Quoted 6 lines
This is an extremely terrible interface.
It's an opaque hook that allows on registry, and it's solve purpose is to allow a backdoor call into a foreign driver in another module.
These are exactly the things we try to avoid.
Hi David,
Thanks a lot for your reviewing and the suggestion!
Quoted 3 lines
Why not create a real abstraction where clients register an object, that can be contained as a sub-member inside of their own driver private, that provides the callback registry mechanism.
Please pardon me for my inexperience.
Can you please be a bit more specific?
I guess maybe you're referencing a common design pattern in the driver code, so an example in some existing driver would be the best. :-)
"clients register an object " --
does the "clients" mean the hvsock driver?
and the "object" means the 2 callbacks?
IMHO, here the vmbus driver has to synchronously pass the 2 events to the hvsock driver, so a "backdoor call into the hvsock driver" is inevitable anyway?
e.g., in the path vmbus_process_offer() -> hvsock_process_offer(), the return value of the latter is important to the former, because on error the former needs to clean up some internal states of the vmbus driver (that is, the "goto err_deq_chan").
Quoted 2 lines
That way you can register multiple clients, do things like allow
AF_PACKETcapturing of vmbus traffic, etc.
I thought AF_PACKET can only capture IP packets or Ethernet frames.
Can it be used to capture AF_UNIX packet?
If yes, I suppose we can consider making it work for AF_HYPERV too, if people ask for that.
Thanks,
-- Dexuan
Dexuan Cui
maintainerQuoted 24 lines
From: devel [mailto:[email protected]] On Behalf Of Dexuan Cui
Sent: Thursday, July 30, 2015 18:20
To: David Miller <[email protected]>; KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH V4 4/7] Drivers: hv: vmbus: add APIs to register callbacks to process hvsock connectionQuoted 13 lines
From: David Miller
Sent: Thursday, July 30, 2015 6:27From: Dexuan Cui
Date: Tue, 28 Jul 2015 05:35:11 -0700Quoted 5 lines
With the 2 APIs supplied by the VMBus driver, the coming net/hvsock driver can register 2 callbacks and can know when a new hvsock connection is offered by the host, and when a hvsock connection is being closed by the host.
This is an extremely terrible interface.
Quoted 11 lines
Quoted 4 lines
It's an opaque hook that allows on registry, and it's solve purpose is to allow a backdoor call into a foreign driver in another module.
These are exactly the things we try to avoid.
Hi David,
Thanks a lot for your reviewing and the suggestion!Quoted 3 lines
Why not create a real abstraction where clients register an object, that can be contained as a sub-member inside of their own driver private, that provides the callback registry mechanism.
Hi David,
Can you please have a look at my below questions?
I like your idea of a real abstraction. Your answer would definitely help me to implement that correctly.
Quoted 22 lines
Please pardon me for my inexperience.
Can you please be a bit more specific?
I guess maybe you're referencing a common design pattern in the driver code, so an example in some existing driver would be the best. :-)"clients register an object " --
does the "clients" mean the hvsock driver?
and the "object" means the 2 callbacks?IMHO, here the vmbus driver has to synchronously pass the 2 events to the hvsock driver, so a "backdoor call into the hvsock driver" is inevitable anyway?
e.g., in the path
vmbus_process_offer()->hvsock_process_offer(), the return value of the latter is important to the former, because on error the former needs to clean up some internal states of the vmbus driver (that is, the "gotoerr_deq_chan").Quoted 2 lines
That way you can register multiple clients, do things like allow
AF_PACKETcapturing of vmbus traffic, etc.
Quoted 6 lines
I thought
AF_PACKETcan only capture IP packets or Ethernet frames.
Can it be used to captureAF_UNIXpacket?
If yes, I suppose we can consider making it work forAF_HYPERVtoo, if people ask for that.-- Dexuan
Thanks,
-- Dexuan
Quoted 72 lines
-----Original Message-----
From: Dexuan Cui
Sent: Wednesday, August 5, 2015 9:54 PM
To: David Miller <[email protected]>; KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH V4 4/7] Drivers: hv: vmbus: add APIs to register callbacks to process hvsock connectionQuoted 1 line
From: devel [mailto:[email protected]] On
Behalf
Quoted 3 lines
Of Dexuan Cui
Sent: Thursday, July 30, 2015 18:20
To: David Miller <[email protected]>; KY SrinivasanQuoted 3 lines
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected];
Quoted 2 lines
[email protected]; [email protected]; [email protected]
Subject: RE: [PATCH V4 4/7] Drivers: hv: vmbus: add APIs to registercallbacks to
Quoted 9 lines
process hvsock connection
Quoted 7 lines
From: David Miller
Sent: Thursday, July 30, 2015 6:27From: Dexuan Cui
Date: Tue, 28 Jul 2015 05:35:11 -0700Quoted 1 line
With the 2 APIs supplied by the VMBus driver, the coming net/hvsock
driver
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
can register 2 callbacks and can know when a new hvsock connection is offered by the host, and when a hvsock connection is being closed by
the
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
host.
This is an extremely terrible interface.
Quoted 11 lines
Quoted 4 lines
It's an opaque hook that allows on registry, and it's solve purpose is to allow a backdoor call into a foreign driver in another module.
These are exactly the things we try to avoid.
Hi David,
Thanks a lot for your reviewing and the suggestion!Quoted 3 lines
Why not create a real abstraction where clients register an object, that can be contained as a sub-member inside of their own driver private, that provides the callback registry mechanism.
Hi David,
Can you please have a look at my below questions?I like your idea of a real abstraction. Your answer would definitely help me to implement that correctly.
Quoted 9 lines
Please pardon me for my inexperience.
Can you please be a bit more specific?
I guess maybe you're referencing a common design pattern in the driver code, so an example in some existing driver would be the best. :-)"clients register an object " --
does the "clients" mean the hvsock driver?
and the "object" means the 2 callbacks?
Quoted 19 lines
Quoted 7 lines
IMHO, here the vmbus driver has to synchronously pass the 2 events to the hvsock driver, so a "backdoor call into the hvsock driver" is inevitable anyway?
e.g., in the path
vmbus_process_offer()->hvsock_process_offer(), the return value of the latter is important to the former, because on error the former needs to clean up some internal states of the vmbus driver(that
Quoted 11 lines
is, the "goto
err_deq_chan").Quoted 2 lines
That way you can register multiple clients, do things like allow
AF_PACKETcapturing of vmbus traffic, etc.I thought
AF_PACKETcan only capture IP packetsor Ethernet frames. Can it be used to captureAF_UNIXpacket?
If yes, I suppose we can consider making it work forAF_HYPERVtoo, if people ask for that.
Dexuan,
The notion of a channel on Hyper-V has been mapped to a device on Linux and the mechanism we have had of notifying the driver of the creation of the channel was through registering this device with the kernel (vmbus_device_create). The first exception to this was when we introduced multi-channel support that broke the assumption of this one to one mapping between the channel and Linux device. In the case of the sub-channels, we handled the driver notification issue via the sub-channel callback that the driver registers at the point of opening the channel. Perhaps we could make the sub-channel handling mechanism more generic to handle the case of VMSOCK as well?
Regards,
K. Y
Quoted 4 lines
Quoted 1 line
-- Dexuan
Thanks,
-- Dexuan
Dexuan Cui
maintainerQuoted 117 lines
-----Original Message-----
From: KY Srinivasan
Sent: Friday, August 7, 2015 2:28
To: Dexuan Cui <[email protected]>; David Miller <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH V4 4/7] Drivers: hv: vmbus: add APIs to register callbacks to process hvsock connectionQuoted 70 lines
-----Original Message-----
From: Dexuan Cui
Sent: Wednesday, August 5, 2015 9:54 PM
To: David Miller <[email protected]>; KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH V4 4/7] Drivers: hv: vmbus: add APIs to register callbacks to process hvsock connectionQuoted 1 line
From: devel [mailto:[email protected]] On
Behalf
Quoted 3 lines
Of Dexuan Cui
Sent: Thursday, July 30, 2015 18:20
To: David Miller <[email protected]>; KY SrinivasanQuoted 3 lines
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected];
Quoted 2 lines
[email protected]; [email protected]; [email protected]
Subject: RE: [PATCH V4 4/7] Drivers: hv: vmbus: add APIs to registercallbacks to
Quoted 9 lines
process hvsock connection
Quoted 7 lines
From: David Miller
Sent: Thursday, July 30, 2015 6:27From: Dexuan Cui
Date: Tue, 28 Jul 2015 05:35:11 -0700Quoted 1 line
With the 2 APIs supplied by the VMBus driver, the coming net/hvsock
driver
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
can register 2 callbacks and can know when a new hvsock connection is offered by the host, and when a hvsock connection is being closed by
the
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
host.
This is an extremely terrible interface.
Quoted 11 lines
Quoted 4 lines
It's an opaque hook that allows on registry, and it's solve purpose is to allow a backdoor call into a foreign driver in another module.
These are exactly the things we try to avoid.
Hi David,
Thanks a lot for your reviewing and the suggestion!Quoted 3 lines
Why not create a real abstraction where clients register an object, that can be contained as a sub-member inside of their own driver private, that provides the callback registry mechanism.
Hi David,
Can you please have a look at my below questions?I like your idea of a real abstraction. Your answer would definitely help me to implement that correctly.
Quoted 9 lines
Please pardon me for my inexperience.
Can you please be a bit more specific?
I guess maybe you're referencing a common design pattern in the driver code, so an example in some existing driver would be the best. :-)"clients register an object " --
does the "clients" mean the hvsock driver?
and the "object" means the 2 callbacks?Quoted 19 lines
Quoted 7 lines
IMHO, here the vmbus driver has to synchronously pass the 2 events to the hvsock driver, so a "backdoor call into the hvsock driver" is inevitable anyway?
e.g., in the path
vmbus_process_offer()->hvsock_process_offer(), the return value of the latter is important to the former, because on error the former needs to clean up some internal states of the vmbus driver(that
Quoted 11 lines
is, the "goto
err_deq_chan").Quoted 2 lines
That way you can register multiple clients, do things like allow
AF_PACKETcapturing of vmbus traffic, etc.I thought
AF_PACKETcan only capture IP packetsor Ethernet frames. Can it be used to captureAF_UNIXpacket?
If yes, I suppose we can consider making it work forAF_HYPERVtoo, if people ask for that.Dexuan,
The notion of a channel on Hyper-V has been mapped to a device on Linux and the mechanism we have
had of notifying the driver of the creation of the channel was through registering this device with the kernel
(vmbus_device_create). The first exception to this was when we introduced multi-channel support that broke
the assumption of this one to one mapping between the channel and Linux device. In the case of the sub-channels,
we handled the driver notification issue via the sub-channel callback that the driver registers at the point of
opening the channel. Perhaps we could make the sub-channel handling mechanism more generic to handle the case
of VMSOCK as well?
Quoted 1 line
K. Y
Good suggestion!
Let me think this over and make a new patch.
Thanks,
-- Dexuan
Quoted 146 lines
-----Original Message-----
From: Dexuan Cui
Sent: Friday, August 7, 2015 3:27 AM
To: KY Srinivasan <[email protected]>; David Miller <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH V4 4/7] Drivers: hv: vmbus: add APIs to register callbacks to process hvsock connectionQuoted 4 lines
-----Original Message-----
From: KY Srinivasan
Sent: Friday, August 7, 2015 2:28
To: Dexuan Cui <[email protected]>; David MillerQuoted 3 lines
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected];
Quoted 2 lines
[email protected]; [email protected]; [email protected]
Subject: RE: [PATCH V4 4/7] Drivers: hv: vmbus: add APIs to registercallbacks to
Quoted 8 lines
process hvsock connection
Quoted 6 lines
-----Original Message-----
From: Dexuan Cui
Sent: Wednesday, August 5, 2015 9:54 PM
To: David Miller <[email protected]>; KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected];Quoted 5 lines
Quoted 5 lines
[email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH V4 4/7] Drivers: hv: vmbus: add APIs to registercallbacks
Quoted 3 lines
Quoted 3 lines
to process hvsock connection
Quoted 1 line
From: devel [mailto:[email protected]]
On
Quoted 6 lines
Quoted 6 lines
Behalf
Quoted 3 lines
Of Dexuan Cui
Sent: Thursday, July 30, 2015 18:20
To: David Miller <[email protected]>; KY SrinivasanQuoted 1 line
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
[email protected]; [email protected]; [email protected]; [email protected];
Quoted 2 lines
[email protected]; [email protected]; [email protected]
Subject: RE: [PATCH V4 4/7] Drivers: hv: vmbus: add APIs to registercallbacks to
Quoted 2 lines
process hvsock connection
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
From: David Miller
Sent: Thursday, July 30, 2015 6:27From: Dexuan Cui
Date: Tue, 28 Jul 2015 05:35:11 -0700Quoted 1 line
With the 2 APIs supplied by the VMBus driver, the coming
net/hvsock
Quoted 2 lines
Quoted 2 lines
driver
Quoted 1 line
Quoted 1 line
Quoted 1 line
can register 2 callbacks and can know when a new hvsock
connection is
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
offered by the host, and when a hvsock connection is being closed
by
Quoted 20 lines
Quoted 20 lines
the
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
host.
This is an extremely terrible interface.
Quoted 11 lines
Quoted 4 lines
It's an opaque hook that allows on registry, and it's solve purpose is to allow a backdoor call into a foreign driver in another module.
These are exactly the things we try to avoid.
Hi David,
Thanks a lot for your reviewing and the suggestion!Quoted 3 lines
Why not create a real abstraction where clients register an object, that can be contained as a sub-member inside of their own driver private, that provides the callback registry mechanism.
Hi David,
Can you please have a look at my below questions?Quoted 6 lines
Quoted 6 lines
I like your idea of a real abstraction. Your answer would definitely help me to implement that correctly.
Quoted 3 lines
Please pardon me for my inexperience.
Can you please be a bit more specific?
I guess maybe you're referencing a common design pattern in thedriver
Quoted 26 lines
Quoted 6 lines
Quoted 6 lines
code, so an example in some existing driver would be the best. :-)
"clients register an object " --
does the "clients" mean the hvsock driver?
and the "object" means the 2 callbacks?Quoted 19 lines
Quoted 7 lines
IMHO, here the vmbus driver has to synchronously pass the 2 events to the hvsock driver, so a "backdoor call into the hvsock driver" is inevitable anyway?
e.g., in the path
vmbus_process_offer()->hvsock_process_offer(), the return value of the latter is important to the former, because on error the former needs to clean up some internal states of the vmbus driver(that
Quoted 11 lines
is, the "goto
err_deq_chan").Quoted 2 lines
That way you can register multiple clients, do things like allow
AF_PACKETcapturing of vmbus traffic, etc.I thought
AF_PACKETcan only capture IP packetsor Ethernet frames. Can it be used to captureAF_UNIXpacket?
If yes, I suppose we can consider making it work forAF_HYPERVtoo, if people ask for that.Quoted 3 lines
Dexuan,
The notion of a channel on Hyper-V has been mapped to a device on Linux
and
Quoted 4 lines
the mechanism we have
had of notifying the driver of the creation of the channel was through registering this device with the kernel (vmbus_device_create). The first exception to this was when weintroduced
Quoted 4 lines
multi-channel support that broke
the assumption of this one to one mapping between the channel and Linux device. In the case of the sub-channels,
we handled the driver notification issue via the sub-channel callback thatthe
Quoted 5 lines
driver registers at the point of
opening the channel. Perhaps we could make the sub-channel handling mechanism more generic to handle the case
of VMSOCK as well?
Quoted 8 lines
Quoted 1 line
K. Y
Good suggestion!
Let me think this over and make a new patch.Thanks,
-- Dexuan
Looks like VMSOCK handling cannot be accommodated as an extension of sub-channel handling. However, I still think we should use the standard driver core primitives to handle VMSOCK devices. What if we extend the vmbus match function to accommodate vmsock devices. Here is one way we could extend the vmbus match function:
if (the device is not VMSOCK) {
Match the device type ID with the ID table supported by the driver
} else {
Match is based on a special attribute of the driver
}
By doing so, we can use the standard probe call to open the vmsock channel and use the standard mechanism for removing the device.
Regards,
K. Y