Skip to contentSkip to conversation

tools/oxenstored: port XS_INTRODUCE evtchn rebind function from cxenstored

PATCH In review Igor Druzhinin 2 participants 6 messages Aug 19, 2019 – Aug 20, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/oxenstored: port XS_INTRODUCE evtchn rebind function from cxenstored

C version of xenstored had this ability since 61aaed0d5 ("Allow XS_INTRODUCE to be used for rebinding the xenstore evtchn.") from 2007. Copy it as is to Ocaml version.

---
 tools/ocaml/xenstored/domain.ml  | 6 +++++-
 tools/ocaml/xenstored/process.ml | 8 +++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)
tools/ocaml/xenstored/domain.ml +5 -1
index b0a01b0..aeb185f 100644
@@ -23,9 +23,9 @@ type t =
 {
 	id: Xenctrl.domid;
 	mfn: nativeint;
-	remote_port: int;
 	interface: Xenmmap.mmap_interface;
 	eventchn: Event.t;
+	mutable remote_port: int;
 	mutable port: Xeneventchn.t option;
 	mutable bad_client: bool;
 	mutable io_credit: int; (* the rounds of ring process left to do, default is 0,
@@ -71,6 +71,10 @@ let notify dom = match dom.port with
 	Event.notify dom.eventchn port
 
 let bind_interdomain dom =
+	begin match dom.port with
+	| None -> ()
+	| Some port -> Event.unbind dom.eventchn port
+	end;
 	dom.port <- Some (Event.bind_interdomain dom.eventchn dom.id dom.remote_port);
 	debug "bound domain %d remote port %d to local port %s" dom.id dom.remote_port (string_of_port dom.port)
 
tools/ocaml/xenstored/process.ml +7 -1
index 8a7e538..ff5c948 100644
@@ -408,7 +408,13 @@ let do_introduce con _t domains cons data =
 		in
 	let dom =
 		if Domains.exist domains domid then
-			Domains.find domains domid
+			let edom = Domains.find domains domid in
+			if (Domain.get_mfn edom) = mfn && (Connections.find_domain cons domid) != con then begin
+				(* Use XS_INTRODUCE for recreating the xenbus event-channel. *)
+				edom.remote_port <- port;
+				Domain.bind_interdomain edom;
+			end;
+			edom
 		else try
 			let ndom = Domains.create domains domid mfn port in
 			Connections.add_domain cons ndom;
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

tools/ocaml/xenstored/process.ml let do_introduce con _t domains cons data = · line 412

Quoted 1 line
tools/ocaml/xenstored/process.ml +1 -0
+			if (Domain.get_mfn edom) = mfn && (Connections.find_domain cons domid) != con then begin

This should use <> instead of != because != is pointer inequality in OCaml. The parentheses are not strictly necessary because function application has precedence. So:

	if Domain.get_mfn edom = mfn && Connections.find_domain cons domid <> con then begin

— Christian

Quoted 60 lines · Igor Druzhinin

C version of xenstored had this ability since 61aaed0d5 ("Allow XS_INTRODUCE to be used for rebinding the xenstore evtchn.") from 2007. Copy it as is to Ocaml version.

---
tools/ocaml/xenstored/domain.ml | 6 +++++-
tools/ocaml/xenstored/process.ml | 8 +++++++-

2 files changed, 12 insertions(+), 2 deletions(-)
tools/ocaml/xenstored/domain.ml +1 -1
index b0a01b0..aeb185f 100644
@@ -23,9 +23,9 @@ type t =
 {
 	id: Xenctrl.domid;
 	mfn: nativeint;
-	remote_port: int;
 	interface: Xenmmap.mmap_interface;
 	eventchn: Event.t;
+	mutable remote_port: int;
 	mutable port: Xeneventchn.t option;
 	mutable bad_client: bool;
 	mutable io_credit: int; (* the rounds of ring process left to do, default is 0,
@@ -71,6 +71,10 @@ let notify dom = match dom.port with
 	Event.notify dom.eventchn port
 

let bind_interdomain dom =

tools/ocaml/xenstored/domain.ml +4 -0
+	begin match dom.port with
+	| None -> ()
+	| Some port -> Event.unbind dom.eventchn port
+	end;
	dom.port <- Some (Event.bind_interdomain dom.eventchn dom.id dom.remote_port);
	debug "bound domain %d remote port %d to local port %s" dom.id dom.remote_port (string_of_port dom.port)
tools/ocaml/xenstored/process.ml +7 -1
index 8a7e538..ff5c948 100644
@@ -408,7 +408,13 @@ let do_introduce con _t domains cons data =
 		in
 	let dom =
 		if Domains.exist domains domid then
-			Domains.find domains domid
+			let edom = Domains.find domains domid in
+			if (Domain.get_mfn edom) = mfn && (Connections.find_domain cons domid) != con then begin
+				(* Use XS_INTRODUCE for recreating the xenbus event-channel. *)
+				edom.remote_port <- port;
+				Domain.bind_interdomain edom;
+			end;
+			edom
 		else try
 			let ndom = Domains.create domains domid mfn port in
 			Connections.add_domain cons ndom;
Signature · 1 line
2.7.4

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
Quoted 6 lines · Christian Lindig

tools/ocaml/xenstored/process.ml let do_introduce con _t domains cons data = · line 412

Quoted 1 line
tools/ocaml/xenstored/process.ml +1 -0
+			if (Domain.get_mfn edom) = mfn && (Connections.find_domain cons domid) != con then begin

This should use <> instead of != because != is pointer inequality in OCaml. The parentheses are not strictly necessary because function application has precedence. So:

	if Domain.get_mfn edom = mfn && Connections.find_domain cons domid <> con then begin

But I actually want to compare pointers here - the idea is that the connection object in the hashtable indexed by domid is not the same as connection that we got XS_INTRODUCE message from. (see tools/xenstore/xenstrored_domain.c)

Igor

Quoted 52 lines
Quoted 52 lines · Igor Druzhinin

C version of xenstored had this ability since 61aaed0d5 ("Allow XS_INTRODUCE to be used for rebinding the xenstore evtchn.") from 2007. Copy it as is to Ocaml version.

---
tools/ocaml/xenstored/domain.ml | 6 +++++-
tools/ocaml/xenstored/process.ml | 8 +++++++-

2 files changed, 12 insertions(+), 2 deletions(-)
tools/ocaml/xenstored/domain.ml +1 -1
index b0a01b0..aeb185f 100644
@@ -23,9 +23,9 @@ type t =
 {
 	id: Xenctrl.domid;
 	mfn: nativeint;
-	remote_port: int;
 	interface: Xenmmap.mmap_interface;
 	eventchn: Event.t;
+	mutable remote_port: int;
 	mutable port: Xeneventchn.t option;
 	mutable bad_client: bool;
 	mutable io_credit: int; (* the rounds of ring process left to do, default is 0,
@@ -71,6 +71,10 @@ let notify dom = match dom.port with
 	Event.notify dom.eventchn port
 

let bind_interdomain dom =

tools/ocaml/xenstored/domain.ml +4 -0
+	begin match dom.port with
+	| None -> ()
+	| Some port -> Event.unbind dom.eventchn port
+	end;
	dom.port <- Some (Event.bind_interdomain dom.eventchn dom.id dom.remote_port);
	debug "bound domain %d remote port %d to local port %s" dom.id dom.remote_port (string_of_port dom.port)
tools/ocaml/xenstored/process.ml +5 -1
index 8a7e538..ff5c948 100644
@@ -408,7 +408,13 @@ let do_introduce con _t domains cons data =
 		in
 	let dom =
 		if Domains.exist domains domid then
-			Domains.find domains domid
+			let edom = Domains.find domains domid in
+			if (Domain.get_mfn edom) = mfn && (Connections.find_domain cons domid) != con then begin
+				(* Use XS_INTRODUCE for recreating the xenbus event-channel. *)
+				edom.remote_port <- port;
+				Domain.bind_interdomain edom;
Quoted 9 lines
Quoted 8 lines
tools/ocaml/xenstored/process.ml +2 -0
+			end;
+			edom
 		else try
 			let ndom = Domains.create domains domid mfn port in
 			Connections.add_domain cons ndom;
Signature · 1 line
2.7.4

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
Quoted 9 lines · Igor Druzhinin
Quoted 4 lines · Christian Lindig

tools/ocaml/xenstored/process.ml let do_introduce con _t domains cons data = · line 412

Quoted 1 line
tools/ocaml/xenstored/process.ml +1 -0
+			if (Domain.get_mfn edom) = mfn && (Connections.find_domain cons domid) != con then begin

This should use <> instead of != because != is pointer inequality in OCaml. The parentheses are not strictly necessary because function application has precedence. So:

Quoted 7 lines
Quoted 2 lines
	if Domain.get_mfn edom = mfn && Connections.find_domain cons domid <> con then begin

But I actually want to compare pointers here - the idea is that the connection object in the hashtable indexed by domid is not the same as connection that we got XS_INTRODUCE message from. (see tools/xenstore/xenstrored_domain.c)

In your code, a != b is true, if a and b have identical structure but different addresses. I strongly suspect that two connection values should have different structure to be considered different, not just different addresses. When a <> b is true, it implies a != b. So using a <> b is safe(r). By using != you would rely on an invariant that every connection (con) exists only once and is never copied.

— Christian

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw
Quoted 12 lines · Christian Lindig
Quoted 12 lines · Igor Druzhinin
Quoted 6 lines · Christian Lindig

tools/ocaml/xenstored/process.ml let do_introduce con _t domains cons data = · line 412

Quoted 1 line
tools/ocaml/xenstored/process.ml +1 -0
+			if (Domain.get_mfn edom) = mfn && (Connections.find_domain cons domid) != con then begin

This should use <> instead of != because != is pointer inequality in OCaml. The parentheses are not strictly necessary because function application has precedence. So:

	if Domain.get_mfn edom = mfn && Connections.find_domain cons domid <> con then begin
Quoted 7 lines
Quoted 4 lines

But I actually want to compare pointers here - the idea is that the connection object in the hashtable indexed by domid is not the same as connection that we got XS_INTRODUCE message from. (see tools/xenstore/xenstrored_domain.c)

In your code, a != b is true, if a and b have identical structure but different addresses. I strongly suspect that two connection values should have different structure to be considered different, not just different addresses. When a <> b is true, it implies a != b. So using a <> b is safe(r). By using != you would rely on an invariant that every connection (con) exists only once and is never copied.

Connection is a complex object (has various counters and internal structures) and I don't think simple field by field comparison (is <> just that in Ocaml?) is appropriate here.

con is passed into that function from xenstored.ml where it's extracted from the same hashtable (Connections) so it's actually the exactly same object. There are other examples in connections.ml where pointer comparison is used to compare connections.

Igor

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw
Quoted 7 lines · Igor Druzhinin

con is passed into that function from xenstored.ml where it's extracted from the same hashtable (Connections) so it's actually the exactly same object.

This comes down to what semantics you want. It is unfortunate that Connection.t is not abstract and its equality not well defined. Using != now relies on the fact that you only compare values stored in the same hash table.

— C

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel