mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-28 11:18:45 +07:00
e0fa3e5e7d
Background: userspace daemons registration protocol for Hyper-V utilities drivers has two steps: 1) daemon writes its own version to kernel 2) kernel reads it and replies with module version at this point we consider the handshake procedure being completed and we do hv_poll_channel() transitioning the utility device to HVUTIL_READY state. At this point we're ready to handle messages from kernel. When hvutil_transport is in HVUTIL_TRANSPORT_CHARDEV mode we have a single buffer for outgoing message. hvutil_transport_send() puts to this buffer and till the buffer is cleared with hvt_op_read() returns -EFAULT to all consequent calls. Host<->guest protocol guarantees there is no more than one request at a time and we will not get new requests till we reply to the previous one so this single message buffer is enough. Now to the race. When we finish negotiation procedure and send kernel module version to userspace with hvutil_transport_send() it goes into the above mentioned buffer and if the daemon is slow enough to read it from there we can get a collision when a request from the host comes, we won't be able to put anything to the buffer so the request will be lost. To solve the issue we need to know when the negotiation is really done (when the version message is read by the daemon) and transition to HVUTIL_READY state after this happens. Implement a callback on read to support this. Old style netlink communication is not affected by the change, we don't really know when these messages are delivered but we don't have a single message buffer there. Reported-by: Barry Davis <barry_davis@stormagic.com> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com> Signed-off-by: K. Y. Srinivasan <kys@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
55 lines
2.0 KiB
C
55 lines
2.0 KiB
C
/*
|
|
* Kernel/userspace transport abstraction for Hyper-V util driver.
|
|
*
|
|
* Copyright (C) 2015, Vitaly Kuznetsov <vkuznets@redhat.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License version 2 as published
|
|
* by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
|
|
* NON INFRINGEMENT. See the GNU General Public License for more
|
|
* details.
|
|
*
|
|
*/
|
|
|
|
#ifndef _HV_UTILS_TRANSPORT_H
|
|
#define _HV_UTILS_TRANSPORT_H
|
|
|
|
#include <linux/connector.h>
|
|
#include <linux/miscdevice.h>
|
|
|
|
enum hvutil_transport_mode {
|
|
HVUTIL_TRANSPORT_INIT = 0,
|
|
HVUTIL_TRANSPORT_NETLINK,
|
|
HVUTIL_TRANSPORT_CHARDEV,
|
|
HVUTIL_TRANSPORT_DESTROY,
|
|
};
|
|
|
|
struct hvutil_transport {
|
|
int mode; /* hvutil_transport_mode */
|
|
struct file_operations fops; /* file operations */
|
|
struct miscdevice mdev; /* misc device */
|
|
struct cb_id cn_id; /* CN_*_IDX/CN_*_VAL */
|
|
struct list_head list; /* hvt_list */
|
|
int (*on_msg)(void *, int); /* callback on new user message */
|
|
void (*on_reset)(void); /* callback when userspace drops */
|
|
void (*on_read)(void); /* callback on message read */
|
|
u8 *outmsg; /* message to the userspace */
|
|
int outmsg_len; /* its length */
|
|
wait_queue_head_t outmsg_q; /* poll/read wait queue */
|
|
struct mutex lock; /* protects struct members */
|
|
};
|
|
|
|
struct hvutil_transport *hvutil_transport_init(const char *name,
|
|
u32 cn_idx, u32 cn_val,
|
|
int (*on_msg)(void *, int),
|
|
void (*on_reset)(void));
|
|
int hvutil_transport_send(struct hvutil_transport *hvt, void *msg, int len,
|
|
void (*on_read_cb)(void));
|
|
void hvutil_transport_destroy(struct hvutil_transport *hvt);
|
|
|
|
#endif /* _HV_UTILS_TRANSPORT_H */
|