Skip to contentSkip to conversation

cxenstored: wait until after reset to notify dom0less domains

PATCH In review Stefano Stabellini 5 participants 10 messages Oct 13, 2023 – Oct 19, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cxenstored: wait until after reset to notify dom0less domains

From: George Dunlap <[email protected]>

Commit fc2b57c9a ("xenstored: send an evtchn notification on introduce_domain") introduced the sending of an event channel to the guest when first introduced, so that dom0less domains waiting for the connection would know that xenstore was ready to use.

Unfortunately, it was introduced in introduce_domain(), which 1) is called by other functions, where such functionality is unneeded, and
2) after the main XS_INTRODUCE call, calls domain_conn_reset(). This introduces a race condition, whereby if xenstored is delayed, a domain can wake up, send messages to the buffer, only to have them deleted by xenstore before finishing its processing of the XS_INTRODUCE message.

Move the connect-and-notfy call into do_introduce() instead, after the domain_conn_rest(); predicated on the state being in the XENSTORE_RECONNECT state.

(We don't need to check for "restoring", since that value is always passed as "false" from do_domain_introduce()).

Also take the opportunity to add a missing wmb barrier after resetting the indexes of the ring in domain_conn_reset.

This change will also remove an extra event channel notification for dom0 (because the notification is now done by do_introduce which is not called for dom0.) The extra dom0 event channel notification was only introduced by fc2b57c9a and was never present before. It is not needed because dom0 is the one to tell xenstored the connection parameters, so dom0 has to know that the ring page is setup correctly by the time xenstored starts looking at it. It is dom0 that performs the ring page init.

---
 tools/xenstored/domain.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
tools/xenstored/domain.c +8 -6
index a6cd199fdc..f6ef37856c 100644
@@ -923,6 +923,7 @@ static void domain_conn_reset(struct domain *domain)
 
 	domain->interface->req_cons = domain->interface->req_prod = 0;
 	domain->interface->rsp_cons = domain->interface->rsp_prod = 0;
+	xen_wmb();
 }
 
 /*
@@ -988,12 +989,6 @@ static struct domain *introduce_domain(const void *ctx,
 		/* Now domain belongs to its connection. */
 		talloc_steal(domain->conn, domain);
 
-		if (!restore) {
-			/* Notify the domain that xenstore is available */
-			interface->connection = XENSTORE_CONNECTED;
-			xenevtchn_notify(xce_handle, domain->port);
-		}
-
 		if (!is_master_domain && !restore)
 			fire_special_watches("@introduceDomain");
 	} else {
@@ -1033,6 +1028,13 @@ int do_introduce(const void *ctx, struct connection *conn,
 
 	domain_conn_reset(domain);
 
+	if (domain->interface != NULL &&
+		domain->interface->connection == XENSTORE_RECONNECT) {
+		/* Notify the domain that xenstore is available */
+		domain->interface->connection = XENSTORE_CONNECTED;
+		xenevtchn_notify(xce_handle, domain->port);
+	}
+
 	send_ack(conn, XS_INTRODUCE);
 
 	return 0;
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 33 lines · Stefano Stabellini

From: George Dunlap <[email protected]>

Commit fc2b57c9a ("xenstored: send an evtchn notification on introduce_domain") introduced the sending of an event channel to the guest when first introduced, so that dom0less domains waiting for the connection would know that xenstore was ready to use.

Unfortunately, it was introduced in introduce_domain(), which 1) is called by other functions, where such functionality is unneeded, and
2) after the main XS_INTRODUCE call, calls domain_conn_reset(). This introduces a race condition, whereby if xenstored is delayed, a domain can wake up, send messages to the buffer, only to have them deleted by xenstore before finishing its processing of the XS_INTRODUCE message.

Move the connect-and-notfy call into do_introduce() instead, after the domain_conn_rest(); predicated on the state being in the XENSTORE_RECONNECT state.

(We don't need to check for "restoring", since that value is always passed as "false" from do_domain_introduce()).

Also take the opportunity to add a missing wmb barrier after resetting the indexes of the ring in domain_conn_reset.

This change will also remove an extra event channel notification for dom0 (because the notification is now done by do_introduce which is not called for dom0.) The extra dom0 event channel notification was only introduced by fc2b57c9a and was never present before. It is not needed because dom0 is the one to tell xenstored the connection parameters, so dom0 has to know that the ring page is setup correctly by the time xenstored starts looking at it. It is dom0 that performs the ring page init.

Quoted 5 lines

Two nits below, with those fixed:

Quoted 30 lines
---
  tools/xenstored/domain.c | 14 ++++++++------
  1 file changed, 8 insertions(+), 6 deletions(-)
tools/xenstored/domain.c +1 -6
index a6cd199fdc..f6ef37856c 100644
@@ -923,6 +923,7 @@ static void domain_conn_reset(struct domain *domain)
 
  	domain->interface->req_cons = domain->interface->req_prod = 0;
  	domain->interface->rsp_cons = domain->interface->rsp_prod = 0;
+	xen_wmb();
  }
 
  /*
@@ -988,12 +989,6 @@ static struct domain *introduce_domain(const void *ctx,
  		/* Now domain belongs to its connection. */
  		talloc_steal(domain->conn, domain);
 
-		if (!restore) {
-			/* Notify the domain that xenstore is available */
-			interface->connection = XENSTORE_CONNECTED;
-			xenevtchn_notify(xce_handle, domain->port);
-		}
-
  		if (!is_master_domain && !restore)
  			fire_special_watches("@introduceDomain");
  	} else {

tools/xenstored/domain.c int do_introduce(const void *ctx, struct connection *conn, · line 1032

Quoted 5 lines
tools/xenstored/domain.c +2 -0
@@ -1033,6 +1028,13 @@ int do_introduce(const void *ctx, struct connection *conn,
 
  	domain_conn_reset(domain);
 
+	if (domain->interface != NULL &&
+		domain->interface->connection == XENSTORE_RECONNECT) {

Identation should be fixed (both tested conditions at the same position).

tools/xenstored/domain.c int do_introduce(const void *ctx, struct connection *conn, · line 1033

Quoted 1 line
tools/xenstored/domain.c +1 -0
+		/* Notify the domain that xenstore is available */

Please add a "." at the end of the sentence while you are moving this line.

tools/xenstored/domain.c int do_introduce(const void *ctx, struct connection *conn, · line 1040

Quoted 7 lines
tools/xenstored/domain.c +4 -0
+		domain->interface->connection = XENSTORE_CONNECTED;
+		xenevtchn_notify(xce_handle, domain->port);
+	}
+
  	send_ack(conn, XS_INTRODUCE);
 
  	return 0;

Juergen

#2 lore raw
Quoted 4 lines · Juergen Gross
Quoted 1 line · Stefano Stabellini

+ /* Notify the domain that xenstore is available */

Please add a "." at the end of the sentence while you are moving this line.

CODING_STYLE explicitly allows the omission of a '.' when a comment is only a single sentence.

More generally, in this context in English at least, a comment seems to me more like a sign (which should not have punctuation) than a normal English sentence (which does). As such, to me the period actually seems wrong.

In any case, CODING_STYLE was modified to avoid having to spend time arguing about this sort of thing. :-)

-George

#3 lore raw
Quoted 9 lines · George Dunlap
Quoted 4 lines · Juergen Gross
Quoted 1 line · Stefano Stabellini

+ /* Notify the domain that xenstore is available */

Please add a "." at the end of the sentence while you are moving this line.

CODING_STYLE explicitly allows the omission of a '.' when a comment is only a single sentence.

Quoted 7 lines

More generally, in this context in English at least, a comment seems to me more like a sign (which should not have punctuation) than a normal English sentence (which does). As such, to me the period actually seems wrong.

In any case, CODING_STYLE was modified to avoid having to spend time arguing about this sort of thing. :-)

I won't fight for the period. :-)

Maybe I've just read too many kernel reviews asking for it.

Juergen

#4 lore raw
In reply to Stefano Stabellini

+Henry for release ack

Quoted 84 lines · Stefano Stabellini

From: George Dunlap <[email protected]>

Commit fc2b57c9a ("xenstored: send an evtchn notification on introduce_domain") introduced the sending of an event channel to the guest when first introduced, so that dom0less domains waiting for the connection would know that xenstore was ready to use.

Unfortunately, it was introduced in introduce_domain(), which 1) is called by other functions, where such functionality is unneeded, and
2) after the main XS_INTRODUCE call, calls domain_conn_reset(). This introduces a race condition, whereby if xenstored is delayed, a domain can wake up, send messages to the buffer, only to have them deleted by xenstore before finishing its processing of the XS_INTRODUCE message.

Move the connect-and-notfy call into do_introduce() instead, after the domain_conn_rest(); predicated on the state being in the XENSTORE_RECONNECT state.

(We don't need to check for "restoring", since that value is always passed as "false" from do_domain_introduce()).

Also take the opportunity to add a missing wmb barrier after resetting the indexes of the ring in domain_conn_reset.

This change will also remove an extra event channel notification for dom0 (because the notification is now done by do_introduce which is not called for dom0.) The extra dom0 event channel notification was only introduced by fc2b57c9a and was never present before. It is not needed because dom0 is the one to tell xenstored the connection parameters, so dom0 has to know that the ring page is setup correctly by the time xenstored starts looking at it. It is dom0 that performs the ring page init.

---
 tools/xenstored/domain.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
tools/xenstored/domain.c +8 -6
index a6cd199fdc..f6ef37856c 100644
@@ -923,6 +923,7 @@ static void domain_conn_reset(struct domain *domain)
 
 	domain->interface->req_cons = domain->interface->req_prod = 0;
 	domain->interface->rsp_cons = domain->interface->rsp_prod = 0;
+	xen_wmb();
 }
 
 /*
@@ -988,12 +989,6 @@ static struct domain *introduce_domain(const void *ctx,
 		/* Now domain belongs to its connection. */
 		talloc_steal(domain->conn, domain);
 
-		if (!restore) {
-			/* Notify the domain that xenstore is available */
-			interface->connection = XENSTORE_CONNECTED;
-			xenevtchn_notify(xce_handle, domain->port);
-		}
-
 		if (!is_master_domain && !restore)
 			fire_special_watches("@introduceDomain");
 	} else {
@@ -1033,6 +1028,13 @@ int do_introduce(const void *ctx, struct connection *conn,
 
 	domain_conn_reset(domain);
 
+	if (domain->interface != NULL &&
+		domain->interface->connection == XENSTORE_RECONNECT) {
+		/* Notify the domain that xenstore is available */
+		domain->interface->connection = XENSTORE_CONNECTED;
+		xenevtchn_notify(xce_handle, domain->port);
+	}
+
 	send_ack(conn, XS_INTRODUCE);
 
 	return 0;
Signature · 1 line
2.25.1
#5 lore raw

Hi Stefano,

Quoted 3 lines · Stefano Stabellini

+Henry for release ack

Thanks, I think we did have Juergen for reviewing this patch so:

Kind regards,
Henry

Quoted 87 lines · Stefano Stabellini
Quoted 84 lines

From: George Dunlap <[email protected]>

Commit fc2b57c9a ("xenstored: send an evtchn notification on introduce_domain") introduced the sending of an event channel to the guest when first introduced, so that dom0less domains waiting for the connection would know that xenstore was ready to use.

Unfortunately, it was introduced in introduce_domain(), which 1) is called by other functions, where such functionality is unneeded, and
2) after the main XS_INTRODUCE call, calls domain_conn_reset(). This introduces a race condition, whereby if xenstored is delayed, a domain can wake up, send messages to the buffer, only to have them deleted by xenstore before finishing its processing of the XS_INTRODUCE message.

Move the connect-and-notfy call into do_introduce() instead, after the domain_conn_rest(); predicated on the state being in the XENSTORE_RECONNECT state.

(We don't need to check for "restoring", since that value is always passed as "false" from do_domain_introduce()).

Also take the opportunity to add a missing wmb barrier after resetting the indexes of the ring in domain_conn_reset.

This change will also remove an extra event channel notification for dom0 (because the notification is now done by do_introduce which is not called for dom0.) The extra dom0 event channel notification was only introduced by fc2b57c9a and was never present before. It is not needed because dom0 is the one to tell xenstored the connection parameters, so dom0 has to know that the ring page is setup correctly by the time xenstored starts looking at it. It is dom0 that performs the ring page init.

---
tools/xenstored/domain.c | 14 ++++++++------

1 file changed, 8 insertions(+), 6 deletions(-)
tools/xenstored/domain.c +8 -6
index a6cd199fdc..f6ef37856c 100644
@@ -923,6 +923,7 @@ static void domain_conn_reset(struct domain *domain)
 
 domain->interface->req_cons = domain->interface->req_prod = 0;
 domain->interface->rsp_cons = domain->interface->rsp_prod = 0;
+ xen_wmb();
 }
 
 /*
@@ -988,12 +989,6 @@ static struct domain *introduce_domain(const void *ctx,
 /* Now domain belongs to its connection. */
 talloc_steal(domain->conn, domain);
 
- if (!restore) {
- /* Notify the domain that xenstore is available */
- interface->connection = XENSTORE_CONNECTED;
- xenevtchn_notify(xce_handle, domain->port);
- }
-
 if (!is_master_domain && !restore)
 fire_special_watches("@introduceDomain");
 } else {
@@ -1033,6 +1028,13 @@ int do_introduce(const void *ctx, struct connection *conn,
 
 domain_conn_reset(domain);
 
+ if (domain->interface != NULL &&
+ domain->interface->connection == XENSTORE_RECONNECT) {
+ /* Notify the domain that xenstore is available */
+ domain->interface->connection = XENSTORE_CONNECTED;
+ xenevtchn_notify(xce_handle, domain->port);
+ }
+
 send_ack(conn, XS_INTRODUCE);
 
 return 0;
Signature · 1 line
2.25.1
#6 lore raw
In reply to Stefano Stabellini
Quoted 33 lines · Stefano Stabellini

From: George Dunlap <[email protected]>

Commit fc2b57c9a ("xenstored: send an evtchn notification on introduce_domain") introduced the sending of an event channel to the guest when first introduced, so that dom0less domains waiting for the connection would know that xenstore was ready to use.

Unfortunately, it was introduced in introduce_domain(), which 1) is called by other functions, where such functionality is unneeded, and
2) after the main XS_INTRODUCE call, calls domain_conn_reset(). This introduces a race condition, whereby if xenstored is delayed, a domain can wake up, send messages to the buffer, only to have them deleted by xenstore before finishing its processing of the XS_INTRODUCE message.

Move the connect-and-notfy call into do_introduce() instead, after the domain_conn_rest(); predicated on the state being in the XENSTORE_RECONNECT state.

(We don't need to check for "restoring", since that value is always passed as "false" from do_domain_introduce()).

Also take the opportunity to add a missing wmb barrier after resetting the indexes of the ring in domain_conn_reset.

This change will also remove an extra event channel notification for dom0 (because the notification is now done by do_introduce which is not called for dom0.) The extra dom0 event channel notification was only introduced by fc2b57c9a and was never present before. It is not needed because dom0 is the one to tell xenstored the connection parameters, so dom0 has to know that the ring page is setup correctly by the time xenstored starts looking at it. It is dom0 that performs the ring page init.

Quoted 2 lines

Should this have had a Fixes: tag thus marking it to pick up for backport?

Jan

#7 lore raw
Quoted 35 lines · Jan Beulich
Quoted 33 lines · Stefano Stabellini

From: George Dunlap <[email protected]>

Commit fc2b57c9a ("xenstored: send an evtchn notification on introduce_domain") introduced the sending of an event channel to the guest when first introduced, so that dom0less domains waiting for the connection would know that xenstore was ready to use.

Unfortunately, it was introduced in introduce_domain(), which 1) is called by other functions, where such functionality is unneeded, and
2) after the main XS_INTRODUCE call, calls domain_conn_reset(). This introduces a race condition, whereby if xenstored is delayed, a domain can wake up, send messages to the buffer, only to have them deleted by xenstore before finishing its processing of the XS_INTRODUCE message.

Move the connect-and-notfy call into do_introduce() instead, after the domain_conn_rest(); predicated on the state being in the XENSTORE_RECONNECT state.

(We don't need to check for "restoring", since that value is always passed as "false" from do_domain_introduce()).

Also take the opportunity to add a missing wmb barrier after resetting the indexes of the ring in domain_conn_reset.

This change will also remove an extra event channel notification for dom0 (because the notification is now done by do_introduce which is not called for dom0.) The extra dom0 event channel notification was only introduced by fc2b57c9a and was never present before. It is not needed because dom0 is the one to tell xenstored the connection parameters, so dom0 has to know that the ring page is setup correctly by the time xenstored starts looking at it. It is dom0 that performs the ring page init.

Quoted 5 lines
Quoted 2 lines

Should this have had a Fixes: tag thus marking it to pick up for backport?

Sorry this was committed already

#8 lore raw
Quoted 36 lines · Stefano Stabellini
Quoted 35 lines · Jan Beulich
Quoted 33 lines · Stefano Stabellini

From: George Dunlap <[email protected]>

Commit fc2b57c9a ("xenstored: send an evtchn notification on introduce_domain") introduced the sending of an event channel to the guest when first introduced, so that dom0less domains waiting for the connection would know that xenstore was ready to use.

Unfortunately, it was introduced in introduce_domain(), which 1) is called by other functions, where such functionality is unneeded, and
2) after the main XS_INTRODUCE call, calls domain_conn_reset(). This introduces a race condition, whereby if xenstored is delayed, a domain can wake up, send messages to the buffer, only to have them deleted by xenstore before finishing its processing of the XS_INTRODUCE message.

Move the connect-and-notfy call into do_introduce() instead, after the domain_conn_rest(); predicated on the state being in the XENSTORE_RECONNECT state.

(We don't need to check for "restoring", since that value is always passed as "false" from do_domain_introduce()).

Also take the opportunity to add a missing wmb barrier after resetting the indexes of the ring in domain_conn_reset.

This change will also remove an extra event channel notification for dom0 (because the notification is now done by do_introduce which is not called for dom0.) The extra dom0 event channel notification was only introduced by fc2b57c9a and was never present before. It is not needed because dom0 is the one to tell xenstored the connection parameters, so dom0 has to know that the ring page is setup correctly by the time xenstored starts looking at it. It is dom0 that performs the ring page init.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Should this have had a Fixes: tag thus marking it to pick up for backport?

Sorry this was committed already

That's why I used "have had". I still need an answer to the question though; your reply only hints towards "yes".

Jan

#9 lore raw
Quoted 40 lines · Jan Beulich
Quoted 39 lines · Stefano Stabellini
Quoted 38 lines · Jan Beulich
Quoted 35 lines · Stefano Stabellini

From: George Dunlap <[email protected]>

Commit fc2b57c9a ("xenstored: send an evtchn notification on introduce_domain") introduced the sending of an event channel to the guest when first introduced, so that dom0less domains waiting for the connection would know that xenstore was ready to use.

Unfortunately, it was introduced in introduce_domain(), which 1) is called by other functions, where such functionality is unneeded, and
2) after the main XS_INTRODUCE call, calls domain_conn_reset(). This introduces a race condition, whereby if xenstored is delayed, a domain can wake up, send messages to the buffer, only to have them deleted by xenstore before finishing its processing of the XS_INTRODUCE message.

Move the connect-and-notfy call into do_introduce() instead, after the domain_conn_rest(); predicated on the state being in the XENSTORE_RECONNECT state.

(We don't need to check for "restoring", since that value is always passed as "false" from do_domain_introduce()).

Also take the opportunity to add a missing wmb barrier after resetting the indexes of the ring in domain_conn_reset.

This change will also remove an extra event channel notification for dom0 (because the notification is now done by do_introduce which is not called for dom0.) The extra dom0 event channel notification was only introduced by fc2b57c9a and was never present before. It is not needed because dom0 is the one to tell xenstored the connection parameters, so dom0 has to know that the ring page is setup correctly by the time xenstored starts looking at it. It is dom0 that performs the ring page init.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Should this have had a Fixes: tag thus marking it to pick up for backport?

Sorry this was committed already

That's why I used "have had". I still need an answer to the question though; your reply only hints towards "yes".

Yes, I would add the Fixes tag