Skip to contentSkip to conversation

hypercalls with 64-bit results

DISCUSSION Jan Beulich 5 participants 11 messages Jun 16, 2021 – Jun 17, 2021

lore
Share & tools
lore
#0 lore raw

All,

several years back do_memory_op() in libxc was changed to have "long" return type. This is because some of the sub-ops return potentially large values as the hypercall return value (i.e. not in an argument structure field). This change, however, didn't have the intended effect from all I can tell, which apparently manifests in the present two remaining ovmf failures in the staging osstest flights. Anthony tells me that ovmf as of not very long ago puts the shared info page at a really high address, thus making the p2m of the guest very large. Its size gets returned by XENMEM_maximum_gpfn, as function return value.

Since hypercalls from the tool stack are based on ioctl(), and since ioctl() has a return type of "int", I'm afraid there's no way we can deal with this by adjusting function return types in the libraries. Instead we appear to need either a new privcmd ioctl or new XENMEM_* subops (for those cases where potentially large values get returned).

Until we manage to deal with this I wonder whether we should suggest to the ovmf folks to undo that change. I'm anyway not really convinced this aggressive enlarging of the p2m is a good idea. There are a number of cases in the hypervisor where we try to reduce GFN ranges based on this upper bound, and there in particular is a loop in mem-sharing code going all the way up to that limit. EPT P2M dumping also has such a loop.

Jan

#1 lore raw
Quoted 19 lines · Jan Beulich

All,

several years back do_memory_op() in libxc was changed to have "long" return type. This is because some of the sub-ops return potentially large values as the hypercall return value (i.e. not in an argument structure field). This change, however, didn't have the intended effect from all I can tell, which apparently manifests in the present two remaining ovmf failures in the staging osstest flights. Anthony tells me that ovmf as of not very long ago puts the shared info page at a really high address, thus making the p2m of the guest very large. Its size gets returned by XENMEM_maximum_gpfn, as function return value.

Since hypercalls from the tool stack are based on ioctl(), and since ioctl() has a return type of "int", I'm afraid there's no way we can deal with this by adjusting function return types in the libraries. Instead we appear to need either a new privcmd ioctl or new XENMEM_* subops (for those cases where potentially large values get returned).

Quoted 7 lines

Until we manage to deal with this I wonder whether we should suggest to the ovmf folks to undo that change. I'm anyway not really convinced this aggressive enlarging of the p2m is a good idea. There are a number of cases in the hypervisor where we try to reduce GFN ranges based on this upper bound, and there in particular is a loop in mem-sharing code going all the way up to that limit. EPT P2M dumping also has such a loop.

There are multiple things in here which are disappointing, but I think they've mostly been known already.

But I do agree that this is very much another nail in the coffin of the ioctl ABI.

For ABIv2, there are many changes needed, and this ioctl ABI was never going to survive, for other reasons too.  Obviously, we can't wait for ABIv2 to fix this immediate issue.

However, I think it might be reasonable to wait for ABIv2 until we can reasonably support VMs larger than 8T(?).

For now, I'd agree with trying to undo the change in OVMF.

~Andrew

#2 lore raw
Quoted 34 lines · Andrew Cooper
Quoted 19 lines · Jan Beulich

All,

several years back do_memory_op() in libxc was changed to have "long" return type. This is because some of the sub-ops return potentially large values as the hypercall return value (i.e. not in an argument structure field). This change, however, didn't have the intended effect from all I can tell, which apparently manifests in the present two remaining ovmf failures in the staging osstest flights. Anthony tells me that ovmf as of not very long ago puts the shared info page at a really high address, thus making the p2m of the guest very large. Its size gets returned by XENMEM_maximum_gpfn, as function return value.

Since hypercalls from the tool stack are based on ioctl(), and since ioctl() has a return type of "int", I'm afraid there's no way we can deal with this by adjusting function return types in the libraries. Instead we appear to need either a new privcmd ioctl or new XENMEM_* subops (for those cases where potentially large values get returned).

Quoted 7 lines

Until we manage to deal with this I wonder whether we should suggest to the ovmf folks to undo that change. I'm anyway not really convinced this aggressive enlarging of the p2m is a good idea. There are a number of cases in the hypervisor where we try to reduce GFN ranges based on this upper bound, and there in particular is a loop in mem-sharing code going all the way up to that limit. EPT P2M dumping also has such a loop.

There are multiple things in here which are disappointing, but I think they've mostly been known already.

But I do agree that this is very much another nail in the coffin of the ioctl ABI.

Quoted 6 lines

For ABIv2, there are many changes needed, and this ioctl ABI was never going to survive, for other reasons too.  Obviously, we can't wait for ABIv2 to fix this immediate issue.

However, I think it might be reasonable to wait for ABIv2 until we can reasonably support VMs larger than 8T(?).

But it's not just XENMEM_maximum_gpfn that's affected; that's just the one pointing out the underlying issue. Plus if so, shouldn't we avoid returning values that are going to be truncated (and, as can be seen here, then get perhaps recognized as error codes up the call chain)?

Quoted 1 line

For now, I'd agree with trying to undo the change in OVMF.

Anthony, thoughts?

Jan

#3 lore raw
Quoted 8 lines · Jan Beulich

But it's not just XENMEM_maximum_gpfn that's affected; that's just the one pointing out the underlying issue. Plus if so, shouldn't we avoid returning values that are going to be truncated (and, as can be seen here, then get perhaps recognized as error codes up the call chain)?

Quoted 1 line

For now, I'd agree with trying to undo the change in OVMF.

Anthony, thoughts?

I can map the shared_info page somewhere else, that fine. The hard part is figuring out where. I can probably map it just after the guest RAM (as described by the e820 from hvmloader or Xen).

Signature · 1 line
Anthony PERARD
#4 lore raw
Quoted 6 lines · Anthony PERARD
Quoted 5 lines · Jan Beulich

But it's not just XENMEM_maximum_gpfn that's affected; that's just the one pointing out the underlying issue. Plus if so, shouldn't we avoid returning values that are going to be truncated (and, as can be seen here, then get perhaps recognized as error codes up the call chain)?

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

For now, I'd agree with trying to undo the change in OVMF.

Anthony, thoughts?

I can map the shared_info page somewhere else, that fine. The hard part is figuring out where. I can probably map it just after the guest RAM (as described by the e820 from hvmloader or Xen).

Can't you put it (not necessarily immediately) next to the LAPIC page, for example? Or the IO-APIC one? Or somewhere in that area, which normally OSes won't use for placing BARs?

Jan

#5 lore raw
In reply to Jan Beulich
Quoted 13 lines · Jan Beulich

All,

several years back do_memory_op() in libxc was changed to have "long" return type. This is because some of the sub-ops return potentially large values as the hypercall return value (i.e. not in an argument structure field). This change, however, didn't have the intended effect from all I can tell, which apparently manifests in the present two remaining ovmf failures in the staging osstest flights. Anthony tells me that ovmf as of not very long ago puts the shared info page at a really high address, thus making the p2m of the guest very large. Its size gets returned by XENMEM_maximum_gpfn, as function return value.

Quoted 5 lines

Since hypercalls from the tool stack are based on ioctl(), and since ioctl() has a return type of "int", I'm afraid there's no way we can deal with this by adjusting function return types in the libraries. Instead we appear to need either a new privcmd ioctl or new XENMEM_* subops (for those cases where potentially large values get returned).

I think we can just use a multicall in libxc to wrap the affected operations.

Juergen

#6 lore raw
Quoted 9 lines · Juergen Gross
Quoted 5 lines · Jan Beulich

Since hypercalls from the tool stack are based on ioctl(), and since ioctl() has a return type of "int", I'm afraid there's no way we can deal with this by adjusting function return types in the libraries. Instead we appear to need either a new privcmd ioctl or new XENMEM_* subops (for those cases where potentially large values get returned).

I think we can just use a multicall in libxc to wrap the affected operations.

Hmm, we might, if we're happy for these to then not work in HVM domains (PVH Dom0, which still is experimental only, or PVH/HVM DomU-s using the libraries for some purpose), or if we finally wire up multicalls in the HVM case (there ought to be a reason why they aren't, but I have no idea what that is).

Jan

#7 lore raw
Quoted 8 lines · Jan Beulich
Quoted 7 lines · Juergen Gross
Quoted 5 lines · Jan Beulich

Since hypercalls from the tool stack are based on ioctl(), and since ioctl() has a return type of "int", I'm afraid there's no way we can deal with this by adjusting function return types in the libraries. Instead we appear to need either a new privcmd ioctl or new XENMEM_* subops (for those cases where potentially large values get returned).

Quoted 8 lines
Quoted 2 lines

I think we can just use a multicall in libxc to wrap the affected operations.

Hmm, we might, if we're happy for these to then not work in HVM domains (PVH Dom0, which still is experimental only, or PVH/HVM DomU-s using the libraries for some purpose), or if we finally wire up multicalls in the HVM case (there ought to be a reason why they aren't, but I have no idea what that is).

Me neither, especially as on Arm they are supported.

And TBH: PVH Dom0 without multicalls might be hard anyway.

Juergen

#8 lore raw
Quoted 18 lines · Juergen Gross
Quoted 8 lines · Jan Beulich
Quoted 7 lines · Juergen Gross
Quoted 5 lines · Jan Beulich

Since hypercalls from the tool stack are based on ioctl(), and since ioctl() has a return type of "int", I'm afraid there's no way we can deal with this by adjusting function return types in the libraries. Instead we appear to need either a new privcmd ioctl or new XENMEM_* subops (for those cases where potentially large values get returned).

Quoted 8 lines
Quoted 2 lines

I think we can just use a multicall in libxc to wrap the affected operations.

Hmm, we might, if we're happy for these to then not work in HVM domains (PVH Dom0, which still is experimental only, or PVH/HVM DomU-s using the libraries for some purpose), or if we finally wire up multicalls in the HVM case (there ought to be a reason why they aren't, but I have no idea what that is).

Quoted 3 lines

Me neither, especially as on Arm they are supported.

And TBH: PVH Dom0 without multicalls might be hard anyway.

Okay, let me see whether, while trying to wire them up, I run into particular issues.

Jan

#9 lore raw
Quoted 19 lines · Jan Beulich
Quoted 18 lines · Juergen Gross
Quoted 16 lines · Jan Beulich
Quoted 9 lines · Juergen Gross
Quoted 5 lines · Jan Beulich

Since hypercalls from the tool stack are based on ioctl(), and since ioctl() has a return type of "int", I'm afraid there's no way we can deal with this by adjusting function return types in the libraries. Instead we appear to need either a new privcmd ioctl or new XENMEM_* subops (for those cases where potentially large values get returned).

I think we can just use a multicall in libxc to wrap the affected operations.

Hmm, we might, if we're happy for these to then not work in HVM domains (PVH Dom0, which still is experimental only, or PVH/HVM DomU-s using the libraries for some purpose), or if we finally wire up multicalls in the HVM case (there ought to be a reason why they aren't, but I have no idea what that is).

Quoted 6 lines
Quoted 3 lines

Me neither, especially as on Arm they are supported.

And TBH: PVH Dom0 without multicalls might be hard anyway.

Okay, let me see whether, while trying to wire them up, I run into particular issues.

And, at the risk of stating the obvious, this isn't going to help 32-bit Dom0 at all, so (assuming the immediate issue wasn't going to be taken care of at the ovmf side) would help only one of the two tests preventing a push right now. (I have a patch set drafted, but it's yet to be tested. I did find though that the tool stack already uses multicalls in one special case.)

Jan

#10 lore raw
In reply to Jan Beulich
Quoted 13 lines · Jan Beulich

All,

several years back do_memory_op() in libxc was changed to have "long" return type. This is because some of the sub-ops return potentially large values as the hypercall return value (i.e. not in an argument structure field). This change, however, didn't have the intended effect from all I can tell, which apparently manifests in the present two remaining ovmf failures in the staging osstest flights. Anthony tells me that ovmf as of not very long ago puts the shared info page at a really high address, thus making the p2m of the guest very large. Its size gets returned by XENMEM_maximum_gpfn, as function return value.

Quoted 5 lines

Since hypercalls from the tool stack are based on ioctl(), and since ioctl() has a return type of "int", I'm afraid there's no way we can deal with this by adjusting function return types in the libraries. Instead we appear to need either a new privcmd ioctl or new XENMEM_* subops (for those cases where potentially large values get returned).

AFAICT NetBSD and FreeBSD are not affected by this issue as the hypercall return value is propagated to the caller using a long field in the ioctl structure payload for hypercalls.

osdep_hypercall however should be fixed in libs/call in order to return a long instead of an int, and wrappers around it should also be adjusted.

Roger.