Skip to content

Commit ff4b3da

Browse files
Stefano Stabellinimichalsimek
Stefano Stabellini
authored andcommitted
xen/pvcalls: frontend enable
The Xen pvcalls frontend driver needs to be explicitly enabled, and there isn't a way to do it upstream yet. This patch adds a simple boolean command line option (gated on CONFIG_XEN_PVCALLS_FRONTEND) to enable pvcalls. It is a temporary solution but it is the best we can do until a proper upstream mechanism to enable pvcalls is introduced. The patch has no effect if CONFIG_XEN_PVCALLS_FRONTEND is not enabled, or if pvcalls=true is not passed as a command line argument. Signed-off-by: Stefano Stabellini <[email protected]> State: not-upstreamable [michals: Squashed with xen/pvcalls: change CONFIG_XEN_PVCALLS_FRONTEND to bool ]
1 parent 210891a commit ff4b3da

File tree

5 files changed

+155
-1
lines changed

5 files changed

+155
-1
lines changed

drivers/xen/Kconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ config XEN_PCIDEV_BACKEND
229229
If in doubt, say m.
230230

231231
config XEN_PVCALLS_FRONTEND
232-
tristate "XEN PV Calls frontend driver"
232+
bool "XEN PV Calls frontend driver"
233233
depends on INET && XEN
234234
select XEN_XENBUS_FRONTEND
235235
help

drivers/xen/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ obj-$(CONFIG_XEN_SCSI_BACKEND) += xen-scsiback.o
3232
obj-$(CONFIG_XEN_AUTO_XLATE) += xlate_mmu.o
3333
obj-$(CONFIG_XEN_PVCALLS_BACKEND) += pvcalls-back.o
3434
obj-$(CONFIG_XEN_PVCALLS_FRONTEND) += pvcalls-front.o
35+
obj-$(CONFIG_XEN_PVCALLS_FRONTEND) += pvcalls.o
3536
xen-evtchn-y := evtchn.o
3637
xen-gntdev-y := gntdev.o
3738
xen-gntdev-$(CONFIG_XEN_GNTDEV_DMABUF) += gntdev-dmabuf.o

drivers/xen/pvcalls.c

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#include <linux/types.h>
2+
#include <linux/bitops.h>
3+
#include <linux/cred.h>
4+
#include <linux/init.h>
5+
#include <linux/io.h>
6+
#include <linux/kernel.h>
7+
#include <linux/kmod.h>
8+
#include <linux/list.h>
9+
#include <linux/miscdevice.h>
10+
#include <linux/module.h>
11+
#include <linux/mutex.h>
12+
#include <linux/net.h>
13+
#include <linux/poll.h>
14+
#include <linux/skbuff.h>
15+
#include <linux/smp.h>
16+
#include <linux/socket.h>
17+
#include <linux/stddef.h>
18+
#include <linux/unistd.h>
19+
#include <linux/wait.h>
20+
#include <linux/workqueue.h>
21+
#include <net/sock.h>
22+
#include <net/inet_common.h>
23+
24+
#include "pvcalls-front.h"
25+
26+
static int
27+
pvcalls_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
28+
{
29+
int ret;
30+
ret = pvcalls_front_socket(sock);
31+
if (ret < 0)
32+
return ret;
33+
return pvcalls_front_bind(sock, addr, addr_len);
34+
}
35+
36+
static int pvcalls_stream_connect(struct socket *sock, struct sockaddr *addr,
37+
int addr_len, int flags)
38+
{
39+
int ret;
40+
ret = pvcalls_front_socket(sock);
41+
if (ret < 0)
42+
return ret;
43+
return pvcalls_front_connect(sock, addr, addr_len, flags);
44+
}
45+
46+
static int pvcalls_accept(struct socket *sock, struct socket *newsock, int flags, bool kern)
47+
{
48+
return pvcalls_front_accept(sock, newsock, flags);
49+
}
50+
51+
static int pvcalls_getname(struct socket *sock,
52+
struct sockaddr *uaddr, int peer)
53+
{
54+
DECLARE_SOCKADDR(struct sockaddr_in *, sin, uaddr);
55+
56+
sin->sin_family = AF_INET;
57+
memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
58+
return 0;
59+
}
60+
61+
static unsigned int pvcalls_poll(struct file *file, struct socket *sock,
62+
poll_table *wait)
63+
{
64+
return pvcalls_front_poll(file, sock, wait);
65+
}
66+
67+
static int pvcalls_listen(struct socket *sock, int backlog)
68+
{
69+
return pvcalls_front_listen(sock, backlog);
70+
}
71+
72+
static int pvcalls_stream_sendmsg(struct socket *sock, struct msghdr *msg,
73+
size_t len)
74+
{
75+
return pvcalls_front_sendmsg(sock, msg, len);
76+
}
77+
78+
static int
79+
pvcalls_stream_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
80+
int flags)
81+
{
82+
return pvcalls_front_recvmsg(sock, msg, len, flags);
83+
}
84+
85+
static int pvcalls_release(struct socket *s)
86+
{
87+
return pvcalls_front_release(s);
88+
}
89+
90+
static int pvcalls_shutdown(struct socket *s, int h)
91+
{
92+
return -ENOTSUPP;
93+
}
94+
95+
static int sock_no_setsockopt(struct socket *sock, int level, int optname,
96+
sockptr_t optval, unsigned int optlen)
97+
{
98+
return -ENOTSUPP;
99+
}
100+
101+
static int sock_no_getsockopt(struct socket *sock, int level, int optname,
102+
char __user *optval, int __user *optlen)
103+
{
104+
return -ENOTSUPP;
105+
}
106+
107+
const struct proto_ops pvcalls_stream_ops = {
108+
.family = PF_INET,
109+
.owner = THIS_MODULE,
110+
.release = pvcalls_release,
111+
.bind = pvcalls_bind,
112+
.connect = pvcalls_stream_connect,
113+
.socketpair = sock_no_socketpair,
114+
.accept = pvcalls_accept,
115+
.getname = pvcalls_getname,
116+
.poll = pvcalls_poll,
117+
.ioctl = sock_no_ioctl,
118+
.listen = pvcalls_listen,
119+
.shutdown = pvcalls_shutdown,
120+
.setsockopt = sock_no_setsockopt,
121+
.getsockopt = sock_no_getsockopt,
122+
.sendmsg = pvcalls_stream_sendmsg,
123+
.recvmsg = pvcalls_stream_recvmsg,
124+
.mmap = sock_no_mmap,
125+
.sendpage = sock_no_sendpage,
126+
};
127+
128+
bool pvcalls = false;
129+
static __init int xen_parse_pvcalls(char *arg)
130+
{
131+
pvcalls = true;
132+
return 0;
133+
}
134+
early_param("pvcalls", xen_parse_pvcalls);

include/xen/pvcalls.h

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef __LINUX_NET_PVCALLS_H
2+
#define __LINUX_NET_PVCALLS_H
3+
4+
#include <linux/net.h>
5+
6+
#ifdef CONFIG_XEN_PVCALLS_FRONTEND
7+
extern bool pvcalls;
8+
#else
9+
#define pvcalls (0)
10+
#endif
11+
extern const struct proto_ops pvcalls_stream_ops;
12+
13+
#endif

net/ipv4/af_inet.c

+6
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
#include <net/compat.h>
121121

122122
#include <trace/events/sock.h>
123+
#include <xen/pvcalls.h>
123124

124125
/* The inetsw table contains everything that inet_create needs to
125126
* build a new socket.
@@ -1982,6 +1983,11 @@ static int __init inet_init(void)
19821983
for (r = &inetsw[0]; r < &inetsw[SOCK_MAX]; ++r)
19831984
INIT_LIST_HEAD(r);
19841985

1986+
if (pvcalls) {
1987+
pr_info("Enabling pvcalls for AF_INET SOCK_STREAM\n");
1988+
inetsw_array[0].ops = &pvcalls_stream_ops;
1989+
}
1990+
19851991
for (q = inetsw_array; q < &inetsw_array[INETSW_ARRAY_LEN]; ++q)
19861992
inet_register_protosw(q);
19871993

0 commit comments

Comments
 (0)