-
Notifications
You must be signed in to change notification settings - Fork 884
Updating IOCTL interface #121
base: master
Are you sure you want to change the base?
Conversation
4fd6614
to
761d8f2
Compare
Alternatively, as yet another option: We would be could allow both numberings to coexist: (1) Mac/Linux, and (2) Windows. This would be backwards-compatible, and just require a slight modification of the macro: -#define HAX_IOCTL(access, code, type) // ...
+#define HAX_IOCTL(access, code_posix, code_windows, type) // ... This would be strict refactoring, i.e. changing code, without effect on functionality or compatibility. |
Ah, yes, thanks for considering the issue of backward compatibility! That's my biggest concern, and I was trying to break this to you in the post I've been writing. I'm glad that we can now solve this problem together :-) First of all, I really appreciate this carefully thought and well written proposal, as always! Indeed this is a big change, one that we should handle with care. But if we do this right, we'll have a cleaner and more coherent HAXM interface that can pave the way for more extensions and innovations. Please allow me more time to review the details of the proposal. Before that, let's talk about the issue of backward compatibility. As you know, there are the tens of thousands of users who install HAXM as an accelerator for Android Emulator (especially on Windows), and we don't want a new HAXM release to suddenly break their user experience. Android Emulator already has a "minimum HAXM version" requirement, which is currently set to 6.x. So one option is to raise it to 8.x in a future Android Emulator release, but we don't have control over when the new Android Emulator version is released (which may be a lot later than HAXM 8.0.0), and users who try to run the current Android Emulator with HAXM 8.x will get a mysterious failure and have no idea what's going on. Therefore, I think it would be better to have a grace period for Android Emulator (and QEMU as well) to adopt the new IOCTL encoding scheme, so when a user tries to run:
This means we have to keep the old IOCTL definitions somewhere before eventually getting rid of them. They have to be renamed, e.g. to You said your alternative macro also maintains backward compatibility, so basically we'll just pass the old IOCTL codes to |
Regarding the pending changes, I agree with the removal of unused IOCTLs like As to the radical approach of adopting the KVM API, I think we have to agree on what we want to gain from doing that, since it'll incur a lot of work:
|
761d8f2
to
b144c47
Compare
Really good idea. I've done that and force-pushed the last commit. Just a small note, rather than modifying the prefix to:
as opposed to:
Anyway, just a minor thought: it doesn't matter much, since it will get removed in the future anyway. If you want me to use the Regarding the new grace period, I have added reminder comments in the appropriate places to remind ourselves to remove old interfaces. I've specified 2020-01-01. No need to consider it a "strict deadline", but just a future date where we can re-surface this issue and possibly remove legacy interfaces.
Done!
True, that makes quite a lot of sense. After re-reading the KVM API docs, it seems rather hard to make the same API compatible with Windows-hosts, e.g. due to POSIX-specific concepts like fd's.
Fully agreed. Let's do it that way! :-) |
Another thing that needs to be changed is the read/write flags used in Linux/Mac (IO, IOR, IOW, IOWR). They were chosen quite arbitrarily, e.g.:
Regarding the issue with IOCTL renaming, I've replied to your inlined comment. Let me know your thoughts! |
b144c47
to
eb55883
Compare
Yes, thanks! Since we're starting afresh, let's get it right this time. Just curious: do you know if these different access flags are merely for readability, or are actually enforced? E.g. does On Windows, it seems we can label the IOCTLs with appropriate access flags as well via the last parameter for
And I'd suggest the following mapping:
I've also noticed that QEMU always opens every HAXM device in RW mode, and reuse the fd/handle for all subsequent IOCTLs on that device. Therefore, the proposed change shouldn't break anything on Windows. |
Regarding the IOCTL interface revamp, I have a few more ideas. Not all of them need to be done in this PR.
|
I don't think the kernel bothers enforcing anything, since the driver itself runs at kernel-level too and could bypass any measures, if it wanted. However, these macros are useful beyond mere readability: I remember seeing some ARM GPU drivers using them to automatically dispatch the |
Regarding the versions, we could simply call it About that: what versioning system does HAXM use? Note that a system like Semantic Versioning would simplify the required information, since the release version already describes API compatibility via it's
That way, this PR would bump the HAXM version to v7.4.0 (new functionality/API, but compatible with userland applications written for v7.x.x). After the grace period, we would remove legacy interfaces and bump it to v8.0.0 (which implies incompatibility with v7.x.x). PS: It's just a thought on the matter. If Intel uses a different internal versioning system, that's alright too. |
c594386
to
18887e9
Compare
Regarding "capabilities" (i.e. extensions in KVM terms) vs "extensions". We could offer these two ioctl's:
Absolutely. The main purpose of "extensions" is creating very-concrete applications with HAXM, e.g. creating specific tunnels with specific guest systems or instrumenting specific instructions, which might not be suitable to be upstreamed. With this |
18887e9
to
6d36461
Compare
Good idea!
Thanks for explaining the semver system! Having a separate API version is indeed not the best design. For the release version, I wouldn't say we have been following any well-established versioning convention for HAXM... For "MINOR" and "PATCH" numbers, I think we do try to follow semver, but we've been incrementing "MAJOR" for non-technical reasons (e.g. 7.0 doesn't break backward compatibility with 6.x, but it's the first HAXM release based on the open source codebase, so we wanted a change). I don't know if deviations like this from the semver rules will happen again in the future, so I'd just keep the API version for now. After all, there may be a point in the future when we declare the HAXM API to be stable and do not allow backward-incompatible changes (KVM does that), yet we somehow have another incentive to bump the major version. |
Sounds good! The only advantage of using bit fields is to allow specifying a combination of capabilities, but I don't think we ever need that. As for making provision for 3rd-party extensions, I agree with your reasoning. Please feel free to implement your proposal with this PR or leave it for later. I can review the code, but since this IOCTL is currently unused, it would be best if you could test it on your side. |
There is also interest in NetBSD and HAXM (I have got a scratch locally, need to rebase and fix bugs).. so getting another Linux-only API will be rejecting the non-Linux world. |
There is also one person trying to port HAXM to DragonFlyBSD. |
It's rather POSIX-only, but yeah that statement makes sense regardless. I didn't think about this issue when I mentioned "adopting the KVM API". So instead the optimal approach (what this PR does) is just keeping the current API, but just renumbering/renaming IOCTL's to have their definitions shared across all platforms: Windows, Linux, Mac (and hopefully *BSD!). |
Crazy idea... how about merging HAXM with nvmm from NetBSD? NVMM ships with AMD CPUs support and it has API inspired by the Windows one. Today HAXM is open-source and radical changes in interface are probably fine as everybody is able to rebuild it from sources. |
http://m00nbsd.net/4e0798b7f2620c965d0dd9d6a7a2f296.html it got merged with the NetBSD source-code |
@AlexAltea I will drop you a line in a mail. |
Since the main advantage here is AMD CPU support, probably the discussion is better suited for #5. Regarding license, since NVMM is BSD-licensed, this is definitely possible. Quoting Intel's position on AMD support:
So I don't think there's going to be any opposition if we cherry-pick the necessary parts of NVMM and integrate them into HAXM. Of course, it will require some refactoring, specially since vcpu.c is polluted with VMX-specific code that should go into vmx.c, but it's definitely doable.
Unfortunately, this is not the case. It seems a majority of the HAXM usage share comes from Android Studio developers who rely on pre-built QEMU (provided by Google) + HAXM (provided by Intel). Any change to the interface needs to be coordinated with Intel, Google and QEMU developers. And to prevent issues caused mismatching on QEMU-HAXM versions, legacy interfaces will require support during a grace period. Summarizing:
That said, I'm just another contributor here: @raphaelning will probably be the one deciding. |
@AlexAltea in #qemu I was pointed to: https://lists.gnu.org/archive/html/qemu-devel/2018-11/msg01482.html Do you have a qemu fork with your changes? What do you use to test your linux port? |
@tuxillo The QEMU patch for haxm-linux support can be found at: https://github.com/kryptoslogic/qemu/tree/haxm-linux (specifically: kryptoslogic/qemu@860b93f) Please, let's keep this thread on-topic ("Updating IOCTL interface"). Any HAXM-on-Linux questions can be discussed on #108 instead. :-) |
@AlexAltea Thanks for the summary! Indeed, proposals for radical API changes must come with a plan to maintain backward compatibility. But I see that @krytarowski has dropped his idea about adopting the NVMM IOCTL interface, so you can continue with what you planned to do with this PR. |
- The *DEBUG ioctl of VCPU devices was accidentally declared with a `HAX_IOCTL_VCPU_` prefix, not with the de-facto standard `HAX_VCPU_IOCTL_` prefix. This has been corrected. - The *GET_REGS, *SET_REGS ioctls of VCPU devices were declared with the `HAX_VCPU_`, not `HAX_VCPU_IOCTL_`. This has been corrected. Signed-off-by: Alexandro Sanchez Bach <[email protected]>
- Centralizing ioctl definitions in hax_interface.h, and adding __LEGACY suffix to previous platform-specific definitions. - Removed previously deprecated ioctls: HAX_VM_IOCTL_VCPU_CREATE_ORIG and HAX_VCPU_IOCTL_KICKOFF. Removed underlying functions, if any. - Deprecated HAX_VM_IOCTL_NOTIFY_QEMU_VERSION, and turned into a no-op ioctl. Signed-off-by: Alexandro Sanchez Bach <[email protected]>
Signed-off-by: Alexandro Sanchez Bach <[email protected]>
Signed-off-by: Alexandro Sanchez Bach <[email protected]>
23219d2
to
49eb94f
Compare
Build finished. |
sorry,please disregard my previous comment. |
Can one of the admins verify this patch? |
sorry,please disregard my previous comment. |
563eb1b
to
6b942e3
Compare
b73a231
to
da1b8ec
Compare
Disclaimer: This changes the API. Consider it just a proposal, rather than a ready-to-merge patch.
Following the IOCTL-refactoring discussion at #108 (comment), I prepared this "proposal" PR, just for the sake of open discussion: this way seems more appropriate than the issue tracker.
Although centralizing IOCTL's seemed trivial at first, it seems the Darwin and Windows backends evolved separately (not sure though, due to #23). Consequently, they have different numbering, and some comments hint that at some point even the API differed more than it does today. Thus, unifying definitions require backwards-incompatible changes.
Assuming HAXM is using semver this should bump it to v8.x.x.
Changes
The code is self-explanatory. This patch (specifically, 761d8f2) centralizes all IOCTL definitions in the hax_interface.h file by renumbering the function codes as follows:
Windows will mask this code with 0x800, to enable the "Custom bit" (see reference).
Additionally, since the API is changing, I took the opportunity to corrected naming inconsistencies:
*DEBUG
ioctl of VCPU devices was accidentally declared with a HAX_IOCTL_VCPU_ prefix, not with the de-facto standard HAX_VCPU_IOCTL_ prefix. This has been corrected.*GET_REGS
,*SET_REGS
ioctls of VCPU devices were declared with a HAX_VCPU_ prefix, not HAX_VCPU_IOCTL_. This has been corrected.Pending
There's other proposals that I haven't implemented yet, but might be worth discussing (if we are going to change the interface that radically, it's better to get it done right in one attempt):
All platforms treat it exactly the same as HAX_VM_IOCTL_VCPU_CREATE.
Seems to be Windows XP specific, which is no longer supported (?).
An hypervisor should have no dependency on a specific host userland application.
Alternatively, and this is a radically different approach, there's the option of adopting the KVM API, as suggested in #106 (comment), but I'm not sure how large the internal differences between both hypervisors are. Regarding license implications, as long as we provide custom headers with identical constants, we should be GPL-free, so it's doable.
The question is whether we want to do it now (v8.x.x), in the future (v9.x.x?), or never.