Skip to content

Conversation

rn
Copy link
Member

@rn rn commented Oct 23, 2016

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:

  • whitespace cleanups. Bring hyperkit code more inline with bhyve formatting
  • clean up casts introduced in xhyve. While the casts are necessary to compile with clang, xhyve used a lot of unnecessary parentheses and whitespaces. Cleaning them up increases the chance of upstreaming them to bhyve.

/cc @avsm @luigirizzo

rn and others added 15 commits October 11, 2016 20:48
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>
/* 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);
Copy link
Collaborator

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?

Copy link
Collaborator

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...

Copy link
Member Author

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

else
br->br_resid = 0;
} else
#else
Copy link
Collaborator

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..

Copy link
Member Author

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


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 */
Copy link
Collaborator

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.

Copy link
Member Author

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

#define VTNET_MAXSEGS 32

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-macros"
Copy link
Collaborator

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

@ijc
Copy link
Collaborator

ijc commented Oct 24, 2016

LGTM, I made some comments which were mostly asides rather than issues with the changes. Only one worth thinking about is turning off Wunused-macros globally via CFLAGS rather than file by file.

While the casts are necessary to compile with clang

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 config.mk is turning on lots of extra stuff? Just curious why these casts haven't already been found necessary in bhyve.

rn added 9 commits October 24, 2016 13:51
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>
rn added 4 commits October 24, 2016 17:28
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>
@GordonTheTurtle
Copy link

Please sign your commits following these rules:
https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work
The easiest way to do this is to amend the last commit:

$ 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;
Copy link
Collaborator

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.

Copy link
Collaborator

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.

Copy link
Collaborator

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)
Copy link
Collaborator

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.

Copy link
Member Author

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.

Copy link
Collaborator

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.

Copy link
Member Author

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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, #if __FreeBSD__ sgtm

@grehan-freebsd
Copy link

Just curious why these casts haven't already been found necessary in bhyve

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.

@rn
Copy link
Member Author

rn commented Oct 24, 2016

@grehan-freebsd hyperkit is compiled with -Weverything and then some exceptions added afterwards. Some/most of the casts seem like good practise (like not assuming a void * points to something of size 1 byte, unsigned vs signed arithmetic, assignments to smaller data types etc)

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

@luigirizzo
Copy link

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.

@luigirizzo
Copy link

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.

@ijc
Copy link
Collaborator

ijc commented Oct 25, 2016

@luigirizzo I couldn't agree more regarding -Wpadded!

@thebsdbox
Copy link

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.

  • E1000
  • VNC driver
    • USB device emul (needed by vnc for mouse/kb) <- this being the worst to rely on numerous vm contexts.

(just a thought)

@rn
Copy link
Member Author

rn commented Oct 25, 2016

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

@rn
Copy link
Member Author

rn commented Nov 2, 2016

closing this pull request. GH got confused with rewriting the git authot. Will open an updated one shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants