Skip to content

Commit 29fee6e

Browse files
jpemartinsjgross1
authored andcommitted
xenbus: track caller request id
Commit fd8aa90 ("xen: optimize xenbus driver for multiple concurrent xenstore accesses") optimized xenbus concurrent accesses but in doing so broke UABI of /dev/xen/xenbus. Through /dev/xen/xenbus applications are in charge of xenbus message exchange with the correct header and body. Now, after the mentioned commit the replies received by application will no longer have the header req_id echoed back as it was on request (see specification below for reference), because that particular field is being overwritten by kernel. struct xsd_sockmsg { uint32_t type; /* XS_??? */ uint32_t req_id;/* Request identifier, echoed in daemon's response. */ uint32_t tx_id; /* Transaction id (0 if not related to a transaction). */ uint32_t len; /* Length of data following this. */ /* Generally followed by nul-terminated string(s). */ }; Before there was only one request at a time so req_id could simply be forwarded back and forth. To allow simultaneous requests we need a different req_id for each message thus kernel keeps a monotonic increasing counter for this field and is written on every request irrespective of userspace value. Forwarding again the req_id on userspace requests is not a solution because we would open the possibility of userspace-generated req_id colliding with kernel ones. So this patch instead takes another route which is to artificially keep user req_id while keeping the xenbus logic as is. We do that by saving the original req_id before xs_send(), use the private kernel counter as req_id and then once reply comes and was validated, we restore back the original req_id. Cc: <[email protected]> # 4.11 Fixes: fd8aa90 ("xen: optimize xenbus driver for multiple concurrent xenstore accesses") Reported-by: Bhavesh Davda <[email protected]> Signed-off-by: Joao Martins <[email protected]> Reviewed-by: Juergen Gross <[email protected]> Signed-off-by: Juergen Gross <[email protected]>
1 parent 1e3510b commit 29fee6e

File tree

3 files changed

+5
-0
lines changed

3 files changed

+5
-0
lines changed

drivers/xen/xenbus/xenbus.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ struct xb_req_data {
7676
struct list_head list;
7777
wait_queue_head_t wq;
7878
struct xsd_sockmsg msg;
79+
uint32_t caller_req_id;
7980
enum xsd_sockmsg_type type;
8081
char *body;
8182
const struct kvec *vec;

drivers/xen/xenbus/xenbus_comms.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ static int process_msg(void)
309309
goto out;
310310

311311
if (req->state == xb_req_state_wait_reply) {
312+
req->msg.req_id = req->caller_req_id;
312313
req->msg.type = state.msg.type;
313314
req->msg.len = state.msg.len;
314315
req->body = state.body;

drivers/xen/xenbus/xenbus_xs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ static void xs_send(struct xb_req_data *req, struct xsd_sockmsg *msg)
227227
req->state = xb_req_state_queued;
228228
init_waitqueue_head(&req->wq);
229229

230+
/* Save the caller req_id and restore it later in the reply */
231+
req->caller_req_id = req->msg.req_id;
230232
req->msg.req_id = xs_request_enter(req);
231233

232234
mutex_lock(&xb_write_mutex);
@@ -310,6 +312,7 @@ static void *xs_talkv(struct xenbus_transaction t,
310312
req->num_vecs = num_vecs;
311313
req->cb = xs_wake_up;
312314

315+
msg.req_id = 0;
313316
msg.tx_id = t.id;
314317
msg.type = type;
315318
msg.len = 0;

0 commit comments

Comments
 (0)