Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allowing context state to quickly change status from xxx -> initial #26

Open
ubc-guy opened this issue Feb 19, 2024 · 1 comment
Open

Comments

@ubc-guy
Copy link
Collaborator

ubc-guy commented Feb 19, 2024

When an application opens/closes the same context several times, it may be advantagious to reuse the same state context. In this case, the cx_open() places the context into the initial state, which may incur some time delays.

instead, it might be desirable to allocate a new state context that is uninitialized. this would be a security hazard if the OS was allocating a context that had been previously used by a different process. however, if it is the same process, there is no such concern.

this would mimic the way malloc() recycles memory to the same process; when the OS provides the virtual pages initially, they are always cleaned, but when recycled they can be dirty.

@grayresearch
Copy link
Owner

grayresearch commented Feb 19, 2024

I infer this Issue proposes the CX API cx_open() sometimes (following happenings on this thread) provides a selector for a CX state context that is NOT in the initial state. This must not ever happen because it violates the CX contract.

A CX is an immutable interface behavior contract for the CX's set of custom instructions (and soon, some custom CSRs too). This contract says, starting from an initial state and applying this set of custom instructions in this order, you get to this state and will observe such and such behavior and (sometimes even) values.

When a thread in a process opens a CX it must be in the initial state so that software that is written to this contract sees this contract.

Under composition there is no guarantee that when the OS sees cx_open() ... cx_close() ... cx_open() on a thread, the second open is another from the first library. It may be a different library that will exhibit undefined behavior if the CX contract is not honored.

There will be diverse use cases for CX API but in general CX libraries composed in a process or on a thread are separately authored and have a very weak notion of mutual trust.

One way to make work what you are trying to do here, within one CX library, is to cx_open() a CX state context once, and when it is idle, keep it in a data structure, don't cx_close() it, and next time this CX library needs a CX state context (and since it knows it may get a non-initial one) it can recycle the one it the library's own private data structure. Here the first CX library is not surprised it is starting with a recycled state context, and it doesn't break the second CX library that happens to also use this CX.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants