Skip to content

Commit 86c0195

Browse files
committed
Merge tag 'for-linus-6.15a-rc6-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip
Pull xen fixes from Juergen Gross: - A fix for the xenbus driver allowing to use a PVH Dom0 with Xenstore running in another domain - A fix for the xenbus driver addressing a rare race condition resulting in NULL dereferences and other problems - A fix for the xen-swiotlb driver fixing a problem seen on Arm platforms * tag 'for-linus-6.15a-rc6-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip: xenbus: Use kref to track req lifetime xenbus: Allow PVH dom0 a non-local xenstore xen: swiotlb: Use swiotlb bouncing if kmalloc allocation demands it
2 parents acbf235 + 1f0304d commit 86c0195

File tree

6 files changed

+32
-14
lines changed

6 files changed

+32
-14
lines changed

drivers/xen/swiotlb-xen.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
217217
* buffering it.
218218
*/
219219
if (dma_capable(dev, dev_addr, size, true) &&
220+
!dma_kmalloc_needs_bounce(dev, size, dir) &&
220221
!range_straddles_page_boundary(phys, size) &&
221222
!xen_arch_need_swiotlb(dev, phys, dev_addr) &&
222223
!is_swiotlb_force_bounce(dev))

drivers/xen/xenbus/xenbus.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ enum xb_req_state {
7777
struct xb_req_data {
7878
struct list_head list;
7979
wait_queue_head_t wq;
80+
struct kref kref;
8081
struct xsd_sockmsg msg;
8182
uint32_t caller_req_id;
8283
enum xsd_sockmsg_type type;
@@ -103,6 +104,7 @@ int xb_init_comms(void);
103104
void xb_deinit_comms(void);
104105
int xs_watch_msg(struct xs_watch_event *event);
105106
void xs_request_exit(struct xb_req_data *req);
107+
void xs_free_req(struct kref *kref);
106108

107109
int xenbus_match(struct device *_dev, const struct device_driver *_drv);
108110
int xenbus_dev_probe(struct device *_dev);

drivers/xen/xenbus/xenbus_comms.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ static int process_msg(void)
309309
virt_wmb();
310310
req->state = xb_req_state_got_reply;
311311
req->cb(req);
312-
} else
313-
kfree(req);
312+
}
313+
kref_put(&req->kref, xs_free_req);
314314
}
315315

316316
mutex_unlock(&xs_response_mutex);
@@ -386,14 +386,13 @@ static int process_writes(void)
386386
state.req->msg.type = XS_ERROR;
387387
state.req->err = err;
388388
list_del(&state.req->list);
389-
if (state.req->state == xb_req_state_aborted)
390-
kfree(state.req);
391-
else {
389+
if (state.req->state != xb_req_state_aborted) {
392390
/* write err, then update state */
393391
virt_wmb();
394392
state.req->state = xb_req_state_got_reply;
395393
wake_up(&state.req->wq);
396394
}
395+
kref_put(&state.req->kref, xs_free_req);
397396

398397
mutex_unlock(&xb_write_mutex);
399398

drivers/xen/xenbus/xenbus_dev_frontend.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ void xenbus_dev_queue_reply(struct xb_req_data *req)
406406
mutex_unlock(&u->reply_mutex);
407407

408408
kfree(req->body);
409-
kfree(req);
409+
kref_put(&req->kref, xs_free_req);
410410

411411
kref_put(&u->kref, xenbus_file_free);
412412

drivers/xen/xenbus/xenbus_probe.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -966,9 +966,15 @@ static int __init xenbus_init(void)
966966
if (xen_pv_domain())
967967
xen_store_domain_type = XS_PV;
968968
if (xen_hvm_domain())
969+
{
969970
xen_store_domain_type = XS_HVM;
970-
if (xen_hvm_domain() && xen_initial_domain())
971-
xen_store_domain_type = XS_LOCAL;
971+
err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v);
972+
if (err)
973+
goto out_error;
974+
xen_store_evtchn = (int)v;
975+
if (!v && xen_initial_domain())
976+
xen_store_domain_type = XS_LOCAL;
977+
}
972978
if (xen_pv_domain() && !xen_start_info->store_evtchn)
973979
xen_store_domain_type = XS_LOCAL;
974980
if (xen_pv_domain() && xen_start_info->store_evtchn)
@@ -987,10 +993,6 @@ static int __init xenbus_init(void)
987993
xen_store_interface = gfn_to_virt(xen_store_gfn);
988994
break;
989995
case XS_HVM:
990-
err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v);
991-
if (err)
992-
goto out_error;
993-
xen_store_evtchn = (int)v;
994996
err = hvm_get_parameter(HVM_PARAM_STORE_PFN, &v);
995997
if (err)
996998
goto out_error;

drivers/xen/xenbus/xenbus_xs.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ static void xs_suspend_exit(void)
112112
wake_up_all(&xs_state_enter_wq);
113113
}
114114

115+
void xs_free_req(struct kref *kref)
116+
{
117+
struct xb_req_data *req = container_of(kref, struct xb_req_data, kref);
118+
kfree(req);
119+
}
120+
115121
static uint32_t xs_request_enter(struct xb_req_data *req)
116122
{
117123
uint32_t rq_id;
@@ -237,6 +243,12 @@ static void xs_send(struct xb_req_data *req, struct xsd_sockmsg *msg)
237243
req->caller_req_id = req->msg.req_id;
238244
req->msg.req_id = xs_request_enter(req);
239245

246+
/*
247+
* Take 2nd ref. One for this thread, and the second for the
248+
* xenbus_thread.
249+
*/
250+
kref_get(&req->kref);
251+
240252
mutex_lock(&xb_write_mutex);
241253
list_add_tail(&req->list, &xb_write_list);
242254
notify = list_is_singular(&xb_write_list);
@@ -261,8 +273,8 @@ static void *xs_wait_for_reply(struct xb_req_data *req, struct xsd_sockmsg *msg)
261273
if (req->state == xb_req_state_queued ||
262274
req->state == xb_req_state_wait_reply)
263275
req->state = xb_req_state_aborted;
264-
else
265-
kfree(req);
276+
277+
kref_put(&req->kref, xs_free_req);
266278
mutex_unlock(&xb_write_mutex);
267279

268280
return ret;
@@ -291,6 +303,7 @@ int xenbus_dev_request_and_reply(struct xsd_sockmsg *msg, void *par)
291303
req->cb = xenbus_dev_queue_reply;
292304
req->par = par;
293305
req->user_req = true;
306+
kref_init(&req->kref);
294307

295308
xs_send(req, msg);
296309

@@ -319,6 +332,7 @@ static void *xs_talkv(struct xenbus_transaction t,
319332
req->num_vecs = num_vecs;
320333
req->cb = xs_wake_up;
321334
req->user_req = false;
335+
kref_init(&req->kref);
322336

323337
msg.req_id = 0;
324338
msg.tx_id = t.id;

0 commit comments

Comments
 (0)