-
Notifications
You must be signed in to change notification settings - Fork 333
First pass at reducing the diff between bhyve and hyperkit #73
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
Conversation
Remove mirage-block-unix pin
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
Use the initrd_addr_max value from the kernel header if the kernel version is 2.03 or newer. Use hardcoded(0x37ffffff) value if older. Compare the initrd_max and memory.size, and re-assign if initrd_max is larger. Add ALIGNDOWN for ramdisk_start, uses prevent to go past the address limit. Based on qemu/hw/i386/pc.c, Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
kexec: fix wrong calculation method of ramdisk_start
Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
Also adjust the make variables and their names Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
[RFC] restructure the layout of the source code
Various bits of code (e.g. kernel and initrd loading) rely on memory.base and memory.size referring to lowmem only, with highmem being handled separately, in order to avoid locating things into the MMIO region between the two. Rename the variable to make this more obvious and to forestall any ideas about "fixing" memory.size. Signed-off-by: Ian Campbell <ian.campbell@docker.com>
kexec: Rename "memory" to "lowmem".
… tracker We get a small but steady stream of Docker for Mac bug reports filled against Hyperkit, many of which are not actually Hyperkit issues. Try and direct users to file the bugs downstream by default so that they can be more effectively triaged. Signed-off-by: Ian Campbell <ian.campbell@docker.com>
src/lib/acpitbl.c
Outdated
/* fixup table */ | ||
acpitbl_write32(rdsp, 0x10, ((uint32_t) (XHYVE_ACPI_BASE + RSDT_OFFSET))); | ||
acpitbl_write64(rdsp, 0x18, ((uint64_t) (XHYVE_ACPI_BASE + XSDT_OFFSET))); | ||
acpitbl_write32(rdsp, 0x10, (uint32_t)XHYVE_ACPI_BASE + RSDT_OFFSET); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ones a bit subtle, depending on how the constants are defined. If RSDT_OFFSET
were 0xXXXXUL
(which wouldn't be unreasonable) then I think the uint32_t + unsigned long
would potentially be promoted to an unsigned long
, despite the first operand having been cast to uint32_t
, which wasn't quite as intended.
We could write it as (unt32_t)(FOO + BAR)
(i.e. just fix the whitespace not the braces) but perhaps we would be better off letting the implicit conversion (due to the argument to acpitbl_write32
taking a uint32_t
) DTRT? That might mean changing the constants to be unsigned, but arguably that would be correct in its own right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, I would be fine with a "lets apply as is now and reconsider later" answer here...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll fix it. was a bit too eager removing parentheses
src/lib/block_if.c
Outdated
else | ||
br->br_resid = 0; | ||
} else | ||
#else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we just delete this? We can always get it back from git if we need it..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was contemplating this as well. Yeah, I'll remove it
src/lib/pci_emul.c
Outdated
|
||
if ((size & (size - 1)) != 0) | ||
size = 1UL << flsl((long) size); /* round up to a power of 2 */ | ||
size = 1UL << flsl((long)size); /* round up to a power of 2 */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an existing problem, but isn't this chopping the top bit off (size
is a uint64_t
, long
is a signed
probably 64-bit value). Maybe we want the long long
version? Obviously size
> 2^63
is not something we should worry about in practice, except I'm not 100% convinced there isn't some UD here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the signed-ness of the variable should not matter for flsl
as it would just look at the bits. long
is indeed 64bit so this should work...though i'm going to change this to long long
which is a bit more correct, I think, at least on 32bit systems
src/lib/pci_virtio_net_tap.c
Outdated
#define VTNET_MAXSEGS 32 | ||
|
||
#pragma clang diagnostic push | ||
#pragma clang diagnostic ignored "-Wunused-macros" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should just add this to CFLAGS
LGTM, I made some comments which were mostly asides rather than issues with the changes. Only one worth thinking about is turning off
I didn't spot any casts which didn't look like good practice (as opposed to just placating the compiler), but isn't FreeBSD (and hence bhyve) compiling with clang by default these days too? Is it just that Apple's version of clang is defaulting to more warnings, or is it that Hyperkit's |
Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
Also re-arrange CFLAGS_WARN so that disabling warnings is at the end and in alphabetical order. Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
Remove excessive parentheses. Perform pointer arithmetic on (char *) instead of casting to a uintptr_t and back to pointer. While at it, also do some minor coding style clean up. Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
- removed disabled code (and added a comment) - remove excessive parenthesis in conditionals and casts - fix indentation Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
While at it also fix up some whitespaces to redice diff with bhyve. Note: bhyve's version of inout.c is very untidy wrt to whitespaces. this patch does not copy this untidiness. Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
While at it, do some minor whitespace cleanup to reduce the diff with bhyve and replace a flsl() with a slightly more correct flsll (this shouldn't matter on 64bit systems). Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
While at it, adjust some whitespaces to reduce the diff to bhyve Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
While the network backends are quite different, they still share a lot of common code. Unify it as much as possible. While at it, remove some superfluous parentheses from casts and asserts. Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
While at it, also tidy up a few casts. Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
Please sign your commits following these rules: $ git clone -b "cleanup" git@github.com:rneugeba/hyperkit.git somewhere
$ cd somewhere
$ git rebase -i HEAD~28
editor opens
change each 'pick' to 'edit'
save the file and quit
$ git commit --amend -s --no-edit
$ git rebase --continue # and repeat the amend for each commit
$ git push -f Amending updates the existing PR. You DO NOT need to open a new one. |
}; | ||
|
||
struct blockif_ctxt { | ||
int bc_magic; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we know why an assert is appropriate here instead of a dynamic check? All the lseeks appear to assume success.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did GH misplace your comment? there seems to be no assert in the context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like everything got very confused after a force push...
@@ -372,7 +389,7 @@ blockif_proc(struct blockif_ctxt *bc, struct blockif_elem *be, uint8_t *buf) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would just prefer to keep this codebase clean without the "bhyve removal" comments -- its pretty obvious from the perror that alternative implementations could exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the comment, because in a previous version i had #if 0
and the original version had the bhyve code commented out. Both of which make it blindingly obvious that something from the original source was hacked to make it work on OSX. I'm for removing dead code, but do prefer to leave a breadcrumb indicating that something may have changed due to a hack, just in case someone is debugging this code in a few months time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just brainstorming some alternatives...
An #ifdef BHYVE
or #ifdef __FreeBSD__
might be nicer than the big block of commented code (which == a big hunk of diff vs upstream) and not as objectionable as the breadcrumb comment?
In some cases perhaps a #define FEATURE_BLAH 0
would allow some of the if (bh->something)
blocks to turn into if(FEATURE_BLAH && bh->something)
and clang could still do dead code elimination.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I like that, ie either __FreeBSD__
or feature (if appropriate). Will update again...though it looks like GH was royally confused with my force push which also updated the author and committer. Might have to open a new PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, #if __FreeBSD__
sgtm
usr.sbin/bhyve is built with WARNS=2 in the Makefile - this may not be as strict as the default with clang on OSX. More than happy to take changes which would allow a stricter WARNS value to be used on FreeBSD. |
@grehan-freebsd hyperkit is compiled with I currently don't have a FreeBSD dev environment set up, but we are definitely interested in reducing the diff, especially for the device emulation portions. It might take a few more passes before we get there, re @luigirizzo email to emulation@freebsd.org |
Peter, Rolf: I am in favour of strict compiler warnings, the only one I would remove in CFLAGS is -Wpadded because it seems to make life miserable: it complains both when a struct is declared __packed but no padding would be inserted anyways, and when it is not __packed but padding is inserted. The whole point of using __packed is tell the compiler which structs should be packed and which should not, then leave us alone. |
Regarding diff reduction with bhyve, given that the task is much larger than I expected, I would approach it in an opportunistic way, i.e. as we go through a subsystem (e.g. for merging a new device emulation or fixing a feature) also take the chance to revert the gratuitous changes applied in the port (whitespace, file renaming, changes in function prototypes). Likewise for importing changes into FreeBSD. |
@luigirizzo I couldn't agree more regarding |
Given most of the bhyve code is focussed on contexts of a number of VMs, would you look at reinstating the code to act in the following manner (although always referencing the same context as hyperkit doesn't run multiple VMs the same way bhyve does). This would make it much simpler to import the additional pci devices that have been added into bhyve e.g.
(just a thought) |
I haven't looked at the context structure in FreeBSD in too much detail yet, but re-instating it would maybe make sense. However, there are q fair few number of lower hanging fruits, which I would pick first |
closing this pull request. GH got confused with rewriting the git authot. Will open an updated one shortly. |
xhyve/hyperkit was derived from bhyve and shares more common code with it than there are differences. This is a first pass at trying to reduce the difference and mostly does two things:
/cc @avsm @luigirizzo