Skip to content

Commit b220001

Browse files
committed
CA-375277: xenctrlext_stubs.c: add missing enter/leave blocking section
Most of these calls pass only integers or pointers allocated in C, so it is safe to release the OCaml runtime lock. Replace direct passing of Xfm_val/Caml_ba_data_val with storing in a temporary local variable (the result of Xfm_val or Caml_ba_data_val won't move since they are C pointers, but the OCaml value passed in as params to these macros might!) Signed-off-by: Edwin Török <[email protected]>
1 parent a836eb3 commit b220001

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

ocaml/xenopsd/c_stubs/xenctrlext_stubs.c

+40-5
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ CAMLprim value stub_xenctrlext_get_runstate_info(value xch_val, value domid)
117117
int retval;
118118
xc_interface *xch = xch_of_val(xch_val);
119119

120+
caml_enter_blocking_section();
120121
retval = xc_get_runstate_info(xch, Int_val(domid), &info);
122+
caml_leave_blocking_section();
121123
if (retval < 0)
122124
failwith_xc(xch);
123125

@@ -153,7 +155,9 @@ CAMLprim value stub_xenctrlext_get_boot_cpufeatures(value xch_val)
153155
int ret;
154156
xc_interface *xch = xch_of_val(xch_val);
155157

158+
caml_enter_blocking_section();
156159
ret = xc_get_boot_cpufeatures(xch, &a, &b, &c, &d, &e, &f, &g, &h);
160+
caml_leave_blocking_section();
157161
if (ret < 0)
158162
failwith_xc(xch);
159163

@@ -191,7 +195,9 @@ CAMLprim value stub_xenctrlext_domain_get_acpi_s_state(value xch_val, value domi
191195
int ret;
192196
xc_interface* xch = xch_of_val(xch_val);
193197

198+
caml_enter_blocking_section();
194199
ret = xc_get_hvm_param(xch, Int_val(domid), HVM_PARAM_ACPI_S_STATE, &v);
200+
caml_leave_blocking_section();
195201
if (ret != 0)
196202
failwith_xc(xch);
197203

@@ -203,7 +209,9 @@ CAMLprim value stub_xenctrlext_domain_send_s3resume(value xch_val, value domid)
203209
CAMLparam2(xch_val, domid);
204210
xc_interface *xch = xch_of_val(xch_val);
205211

212+
caml_enter_blocking_section();
206213
xcext_domain_send_s3resume(xch, Int_val(domid));
214+
caml_leave_blocking_section();
207215
CAMLreturn(Val_unit);
208216
}
209217

@@ -213,7 +221,9 @@ CAMLprim value stub_xenctrlext_domain_set_timer_mode(value xch_val, value id, va
213221
int ret;
214222
xc_interface* xch = xch_of_val(xch_val);
215223

224+
caml_enter_blocking_section();
216225
ret = xcext_domain_set_timer_mode(xch, Int_val(id), Int_val(mode));
226+
caml_leave_blocking_section();
217227
if (ret < 0)
218228
failwith_xc(xch);
219229
CAMLreturn(Val_unit);
@@ -243,7 +253,9 @@ CAMLprim value stub_xenctrlext_domain_set_target(value xch_val,
243253
CAMLparam3(xch_val, domid, target);
244254
xc_interface* xch = xch_of_val(xch_val);
245255

256+
caml_enter_blocking_section();
246257
int retval = xc_domain_set_target(xch, Int_val(domid), Int_val(target));
258+
caml_leave_blocking_section();
247259
if (retval)
248260
failwith_xc(xch);
249261
CAMLreturn(Val_unit);
@@ -327,7 +339,9 @@ static int get_cpumap_len(value xch_val, value cpumap)
327339
{
328340
xc_interface* xch = xch_of_val(xch_val);
329341
int ml_len = Wosize_val(cpumap);
342+
caml_enter_blocking_section();
330343
int xc_len = xc_get_max_cpus(xch);
344+
caml_leave_blocking_section();
331345

332346
return (ml_len < xc_len ? ml_len : xc_len);
333347
}
@@ -341,19 +355,23 @@ CAMLprim value stub_xenctrlext_vcpu_setaffinity_soft(value xch_val, value domid,
341355
int retval;
342356
xc_interface* xch = xch_of_val(xch_val);
343357

358+
caml_enter_blocking_section();
344359
c_cpumap = xc_cpumap_alloc(xch);
360+
caml_leave_blocking_section();
345361
if (c_cpumap == NULL)
346362
failwith_xc(xch);
347363

348364
for (i=0; i<len; i++) {
349365
if (Bool_val(Field(cpumap, i)))
350366
c_cpumap[i/8] |= 1 << (i&7);
351367
}
368+
caml_enter_blocking_section();
352369
retval = xc_vcpu_setaffinity(xch, Int_val(domid),
353370
Int_val(vcpu),
354371
NULL, c_cpumap,
355372
XEN_VCPUAFFINITY_SOFT);
356373
free(c_cpumap);
374+
caml_leave_blocking_section();
357375

358376
if (retval < 0)
359377
failwith_xc(xch);
@@ -371,7 +389,9 @@ CAMLprim value stub_xenctrlext_numainfo(value xch_val)
371389
int retval;
372390
xc_interface* xch = xch_of_val(xch_val);
373391

392+
caml_enter_blocking_section();
374393
retval = xc_numainfo(xch, &max_nodes, NULL, NULL);
394+
caml_leave_blocking_section();
375395
if (retval < 0)
376396
failwith_xc(xch);
377397

@@ -383,7 +403,9 @@ CAMLprim value stub_xenctrlext_numainfo(value xch_val)
383403
caml_raise_out_of_memory();
384404
}
385405

406+
caml_enter_blocking_section();
386407
retval = xc_numainfo(xch, &max_nodes, meminfo, distance);
408+
caml_leave_blocking_section();
387409
if (retval < 0) {
388410
free(meminfo);
389411
free(distance);
@@ -425,15 +447,19 @@ CAMLprim value stub_xenctrlext_cputopoinfo(value xch_val)
425447
int retval;
426448
xc_interface* xch = xch_of_val(xch_val);
427449

450+
caml_enter_blocking_section();
428451
retval = xc_cputopoinfo(xch, &max_cpus, NULL);
452+
caml_leave_blocking_section();
429453
if (retval < 0)
430454
failwith_xc(xch);
431455

432456
cputopo = calloc(max_cpus, sizeof(*cputopo));
433457
if (!cputopo)
434458
caml_raise_out_of_memory();
435459

460+
caml_enter_blocking_section();
436461
retval = xc_cputopoinfo(xch, &max_cpus, cputopo);
462+
caml_leave_blocking_section();
437463
if (retval < 0) {
438464
free(cputopo);
439465
failwith_xc(xch);
@@ -553,7 +579,9 @@ CAMLprim value stub_xenforeignmemory_open(value unit)
553579
result = caml_alloc(1, Abstract_tag);
554580

555581
// use NULL instead of a xentoollog handle as those bindings are flawed
582+
caml_enter_blocking_section();
556583
fmem = xenforeignmemory_open(NULL, 0);
584+
caml_leave_blocking_section();
557585

558586
if(fmem == NULL) {
559587
caml_failwith("Error when opening foreign memory handle");
@@ -568,13 +596,16 @@ CAMLprim value stub_xenforeignmemory_close(value fmem)
568596
{
569597
CAMLparam1(fmem);
570598
int retval;
599+
struct xenforeignmemory_handle *handle = Xfm_val(fmem);
571600

572-
if(Xfm_val(fmem) == NULL) {
601+
if(handle == NULL) {
573602
caml_invalid_argument(
574603
"Error: cannot close NULL foreign memory handle");
575604
}
576605

577-
retval = xenforeignmemory_close(Xfm_val(fmem));
606+
caml_enter_blocking_section();
607+
retval = xenforeignmemory_close(handle);
608+
caml_leave_blocking_section();
578609

579610
if(retval < 0) {
580611
caml_failwith("Error when closing foreign memory handle");
@@ -632,11 +663,12 @@ CAMLprim value stub_xenforeignmemory_map(value fmem, value dom,
632663
cell = Field(cell, 1);
633664
}
634665

666+
caml_enter_blocking_section();
635667
retval = xenforeignmemory_map
636668
(handle, Int_val(dom), prot, pages_length, arr, NULL);
637669
the_errno = errno;
638-
639670
free(arr);
671+
caml_leave_blocking_section();
640672

641673
if(retval == NULL) {
642674
raise_unix_errno_msg(the_errno,
@@ -655,12 +687,15 @@ CAMLprim value stub_xenforeignmemory_unmap(value fmem, value mapping)
655687
CAMLparam2(fmem, mapping);
656688
size_t pages;
657689
int retval, the_errno;
690+
struct xenforeignmemory_handle *handle = Xfm_val(fmem);
691+
void *data = Caml_ba_data_val(mapping);
658692

659693
// convert mapping to pages and addr
660694
pages = Caml_ba_array_val(mapping)->dim[0] / 4096;
661695

662-
retval = xenforeignmemory_unmap(Xfm_val(fmem),
663-
Caml_ba_data_val(mapping), pages);
696+
caml_enter_blocking_section();
697+
retval = xenforeignmemory_unmap(handle, data, pages);
698+
caml_leave_blocking_section();
664699
the_errno = errno;
665700

666701
if(retval < 0) {

0 commit comments

Comments
 (0)