Skip to contentSkip to conversation

Domain IDs and Capabilities

DISCUSSION Jason Andryuk 3 participants 5 messages Mar 31, 2025 – Apr 2, 2025

lore
Share & tools
lore
#0 lore raw

Hi,

I'm finding it necessary to expose a domain's domid and capabilities to the domain itself.

On x86, SIF_privileged and SIF_hardware allow a domain to know its privileges through start_info. ARM does not have start_info, and xenstore domain status is not exposed.

Xen sets XENFEAT_dom0 for is_hardware_domain(), and then ARM Linux creates local xen_start_flags with both SIF_PRIVILEGED (control) and SIF_INITDOMAIN (hardware) set. This is inaccurate with a split hardware and control domains.

(This looks like a mis-use of XENFEAT_dom0. It's present in ELF Notes seems more like a flag for a binary to indicate to Xen's ELF loader that it is capable of running as dom0.)

xen_start_flags influences Linux kernel behavior and userspace. /proc/xen/capabilities control_d is only set for SIF_INITDOMAIN. Similarly, the /proc/xen/xsd_{kva,port} keys needed to run xenstored locally depend on xen_initial_domain(), which can be incorrect.

It is useful for a domain to know its own domid. Xenstored has command line flags to set --master-domid (the local domid) and --priv-domid, but it would be better to autodetect those. Also, domids are necessary to set xenstore permissions - DOMID_SELF is not supported today.

Juergen already implemented a get_domid() function for Mini-OS for a xenstore stubdom to query its own domid indirectly through event channel games. That can be re-imlemented in Linux userspace, but it needs the unstable xenctrl library to query event channel status.

x86 HVM exposes the domid through a CPUID leaf, so it isn't actually hidden.

Should I add a hypercall to query a domid? An alternative, for ARM at least, is to expose the domid and capabilities in the domain's DT in /hypervisor/domid and /hypervisor/caps. I've tried this out as just dumping the domid and caps as uint32_ts.

Reviewing https://lore.kernel.org/xen-devel/[email protected]/ it seems like both a hypercall and an arch specific means might be possible.

XENFEAT could be extended to exposed finer grain capabilities: XENFEAT_{control,hwdom,xenstore}. This is easy. Seems a little bit like a mis-use of XENFEAT to me, but it works.

If generally exposing domids is not desirable, they could be exposed only to domains with capabilities since those are not migratable, AFAICT.

I'm open to suggestions.

Regards,
Jason

#1 lore raw
Quoted 4 lines · Jason Andryuk

It is useful for a domain to know its own domid. Xenstored has command line flags to set --master-domid (the local domid) and --priv-domid, but it would be better to autodetect those. Also, domids are necessary to set xenstore permissions - DOMID_SELF is not supported today.

Setting permissions for oneself?

Quoted 16 lines

Juergen already implemented a get_domid() function for Mini-OS for a xenstore stubdom to query its own domid indirectly through event channel games. That can be re-imlemented in Linux userspace, but it needs the unstable xenctrl library to query event channel status.

x86 HVM exposes the domid through a CPUID leaf, so it isn't actually hidden.

Should I add a hypercall to query a domid? An alternative, for ARM at least, is to expose the domid and capabilities in the domain's DT in /hypervisor/domid and /hypervisor/caps. I've tried this out as just dumping the domid and caps as uint32_ts.

Reviewing
https://lore.kernel.org/xen-devel/[email protected]/
it seems like both a hypercall and an arch specific means might be possible.

Quoted 6 lines

XENFEAT could be extended to exposed finer grain capabilities:
XENFEAT_{control,hwdom,xenstore}. This is easy. Seems a little bit like a mis-use of XENFEAT to me, but it works.

If generally exposing domids is not desirable, they could be exposed only to domains with capabilities since those are not migratable, AFAICT.

Since guests have ways to figure out their IDs, there's probably nothing wrong with having a dedicated means for them to obtain them. It just needs to be made very clear that the ID can (and, at least for now, typically will) change across migration. As to the mechanism thereof, I stand by my views voiced in that earlier thread you point at.

Jan

#2 lore raw
Quoted 7 lines · Jan Beulich
Quoted 4 lines · Jason Andryuk

It is useful for a domain to know its own domid. Xenstored has command line flags to set --master-domid (the local domid) and --priv-domid, but it would be better to autodetect those. Also, domids are necessary to set xenstore permissions - DOMID_SELF is not supported today.

Setting permissions for oneself?

Any call to xs_set_permissions(), AIUI. Say you have two domUs, dom1 & dom2. dom1 wants to create a shared xenstore node with full permissions for itself, but read-only permission for dom2. dom1 needs to know its own domid to set the permissions:

* struct xs_permissions perms[2];
*

 *  perms[0].id = domid1;
 *  perms[0].perms = XS_PERM_NONE;
 *  perms[1].id = domid2;
 *  perms[1].perms = XS_PERM_READ;

perms[].id doesn't handle DOMID_SELF

Quoted 5 lines

Since guests have ways to figure out their IDs, there's probably nothing wrong with having a dedicated means for them to obtain them. It just needs to be made very clear that the ID can (and, at least for now, typically will) change across migration. As to the mechanism thereof, I stand by my views voiced in that earlier thread you point at.

Thanks,
Jason

#3 lore raw
Quoted 14 lines · Jason Andryuk
Quoted 7 lines · Jan Beulich
Quoted 4 lines · Jason Andryuk

It is useful for a domain to know its own domid. Xenstored has command line flags to set --master-domid (the local domid) and --priv-domid, but it would be better to autodetect those. Also, domids are necessary to set xenstore permissions - DOMID_SELF is not supported today.

Setting permissions for oneself?

Any call to xs_set_permissions(), AIUI. Say you have two domUs, dom1 & dom2. dom1 wants to create a shared xenstore node with full permissions for itself, but read-only permission for dom2. dom1 needs to know its own domid to set the permissions:

Quoted 8 lines

* struct xs_permissions perms[2];
*

  *  perms[0].id = domid1;
  *  perms[0].perms = XS_PERM_NONE;
  *  perms[1].id = domid2;
  *  perms[1].perms = XS_PERM_READ;

perms[].id doesn't handle DOMID_SELF

That is, XS_SET_PERMS only ever fully replaces existing permissions, rather than allowing incremental permit/revoke?

Jan

#4 lore raw
Quoted 22 lines · Jan Beulich
Quoted 21 lines · Jason Andryuk
Quoted 7 lines · Jan Beulich
Quoted 4 lines · Jason Andryuk

It is useful for a domain to know its own domid. Xenstored has command line flags to set --master-domid (the local domid) and --priv-domid, but it would be better to autodetect those. Also, domids are necessary to set xenstore permissions - DOMID_SELF is not supported today.

Setting permissions for oneself?

Any call to xs_set_permissions(), AIUI. Say you have two domUs, dom1 & dom2. dom1 wants to create a shared xenstore node with full permissions for itself, but read-only permission for dom2. dom1 needs to know its own domid to set the permissions:

* struct xs_permissions perms[2];
*

   *  perms[0].id = domid1;
   *  perms[0].perms = XS_PERM_NONE;
   *  perms[1].id = domid2;
   *  perms[1].perms = XS_PERM_READ;
Quoted 4 lines
Quoted 1 line

perms[].id doesn't handle DOMID_SELF

That is, XS_SET_PERMS only ever fully replaces existing permissions, rather than allowing incremental permit/revoke?

Correct.

BTW, it is quite easy to get the data needed for setting the permissions:

1. create the new node
2. read the current permissions (will have the owner in perms[0])
3. extend the permissions as needed

Juergen