[PATCH v2 10/17] tools/xenstored: Read event channel from xenstored page

Jason Andryuk posted 17 patches 3 months, 2 weeks ago
[PATCH v2 10/17] tools/xenstored: Read event channel from xenstored page
Posted by Jason Andryuk 3 months, 2 weeks ago
Make introduce_domain() use an event channel from the the xenstore page.
It is only used if non-zero.  Otherwise the passed in event channel port
is used.

The is useful for a xenstored stubdom to configure domains autonomously.

Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
---
 tools/xenstored/domain.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c
index e1d5e8d614..94b2a1eaa7 100644
--- a/tools/xenstored/domain.c
+++ b/tools/xenstored/domain.c
@@ -1021,9 +1021,15 @@ static struct domain *introduce_domain(const void *ctx,
 		return NULL;
 
 	if (!domain->introduced) {
+		evtchn_port_t iface_port;
 		interface = map_interface(domid);
 		if (!interface && !restore)
 			return NULL;
+
+		iface_port = interface->evtchn_port;
+		if (iface_port)
+			port = iface_port;
+
 		if (new_domain(domain, port, restore)) {
 			rc = errno;
 			if (interface)
-- 
2.50.0
Re: [PATCH v2 10/17] tools/xenstored: Read event channel from xenstored page
Posted by Juergen Gross 3 months, 2 weeks ago
On 16.07.25 23:14, Jason Andryuk wrote:
> Make introduce_domain() use an event channel from the the xenstore page.
> It is only used if non-zero.  Otherwise the passed in event channel port
> is used.
> 
> The is useful for a xenstored stubdom to configure domains autonomously.
> 
> Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
> ---
>   tools/xenstored/domain.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c
> index e1d5e8d614..94b2a1eaa7 100644
> --- a/tools/xenstored/domain.c
> +++ b/tools/xenstored/domain.c
> @@ -1021,9 +1021,15 @@ static struct domain *introduce_domain(const void *ctx,
>   		return NULL;
>   
>   	if (!domain->introduced) {
> +		evtchn_port_t iface_port;
>   		interface = map_interface(domid);
>   		if (!interface && !restore)
>   			return NULL;
> +
> +		iface_port = interface->evtchn_port;
> +		if (iface_port)
> +			port = iface_port;
> +

Any reason you introduced iface_port?

I think you could just use:

+		if (interface->evtchn_port)
+			port = interface->evtchn_port;

In case the guest is modifying the field in parallel, it would only shoot
itself in the foot. So there is no real risk in a possible double read.


Juergen
Re: [PATCH v2 10/17] tools/xenstored: Read event channel from xenstored page
Posted by Jason Andryuk 3 months, 2 weeks ago
On 2025-07-17 02:22, Juergen Gross wrote:
> On 16.07.25 23:14, Jason Andryuk wrote:
>> Make introduce_domain() use an event channel from the the xenstore page.
>> It is only used if non-zero.  Otherwise the passed in event channel port
>> is used.
>>
>> The is useful for a xenstored stubdom to configure domains autonomously.
>>
>> Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
>> ---
>>   tools/xenstored/domain.c | 6 ++++++
>>   1 file changed, 6 insertions(+)
>>
>> diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c
>> index e1d5e8d614..94b2a1eaa7 100644
>> --- a/tools/xenstored/domain.c
>> +++ b/tools/xenstored/domain.c
>> @@ -1021,9 +1021,15 @@ static struct domain *introduce_domain(const 
>> void *ctx,
>>           return NULL;
>>       if (!domain->introduced) {
>> +        evtchn_port_t iface_port;
>>           interface = map_interface(domid);
>>           if (!interface && !restore)
>>               return NULL;
>> +
>> +        iface_port = interface->evtchn_port;
>> +        if (iface_port)
>> +            port = iface_port;
>> +
> 
> Any reason you introduced iface_port?
> 
> I think you could just use:
> 
> +        if (interface->evtchn_port)
> +            port = interface->evtchn_port;

Yes, I think this would be fine.

Thanks,
Jason