diff options
| author | Greg Steuck <blackgnezdo@gmail.com> | 2018-11-27 04:14:06 -0800 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-11-27 13:14:06 +0100 |
| commit | 6419afbb779b26af853b46d8ad79cfe52b6f7805 (patch) | |
| tree | 7b8ed176a713899de153619f9d41c675c703ed2a /pkg | |
| parent | ac912200b65d80413762b8d61eb6399ef9eccfd9 (diff) | |
openbsd: run on gce
* build/openbsd: minor cleanup (use tuples instead of maps)
* Grammar nits in comments.
* Simplify openbsd.Create, will defer when there's more than one error exit.
* pkg/build: Support copying kernel into GCE image
* Simple test for openbsd image copy build.
* Cleanup in case something failed before.
* Support multi-processor VMs on GCE.
* More debug
* Reformat
* OpenBSD gce image needs to be raw.
* GC
* Force format to GNU directly on Go 1.10 or newer.
* Use vmType passed as a parameter inside openbsd.go
* gofmt
* more fmt
* Can't use GENERIC.mp just yet.
* capitalize
* Copyright
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/build/build.go | 2 | ||||
| -rw-r--r-- | pkg/build/openbsd.go | 64 |
2 files changed, 51 insertions, 15 deletions
diff --git a/pkg/build/build.go b/pkg/build/build.go index 34015f3ab..7ce21e9b0 100644 --- a/pkg/build/build.go +++ b/pkg/build/build.go @@ -71,7 +71,7 @@ func getBuilder(targetOS, targetArch, vmType string) (builder, error) { return fuchsia{}, nil case targetOS == "akaros" && targetArch == "amd64" && vmType == "qemu": return akaros{}, nil - case targetOS == "openbsd" && targetArch == "amd64" && vmType == "vmm": + case targetOS == "openbsd" && targetArch == "amd64" && (vmType == "gce" || vmType == "vmm"): return openbsd{}, nil default: return nil, fmt.Errorf("unsupported image type %v/%v/%v", targetOS, targetArch, vmType) diff --git a/pkg/build/openbsd.go b/pkg/build/openbsd.go index 1ec255ac6..319891cbc 100644 --- a/pkg/build/openbsd.go +++ b/pkg/build/openbsd.go @@ -10,6 +10,7 @@ import ( "strconv" "time" + "github.com/google/syzkaller/pkg/log" "github.com/google/syzkaller/pkg/osutil" ) @@ -21,25 +22,29 @@ func (ctx openbsd) build(targetArch, vmType, kernelDir, outputDir, compiler, use confDir := fmt.Sprintf("%v/sys/arch/%v/conf", kernelDir, targetArch) compileDir := fmt.Sprintf("%v/sys/arch/%v/compile/%v", kernelDir, targetArch, kernelName) - if err := ctx.configure(confDir, compileDir, kernelName); err != nil { + useGCE := vmType == "gce" + if err := ctx.configure(confDir, compileDir, kernelName, useGCE); err != nil { return err } if err := ctx.make(compileDir, "all"); err != nil { return err } - - for src, dst := range map[string]string{ - filepath.Join(compileDir, "obj/bsd"): "kernel", - filepath.Join(compileDir, "obj/bsd.gdb"): "obj/bsd.gdb", - filepath.Join(userspaceDir, "image"): "image", - filepath.Join(userspaceDir, "key"): "key", + for _, s := range []struct{ dir, src, dst string }{ + {compileDir, "obj/bsd", "kernel"}, + {compileDir, "obj/bsd.gdb", "obj/bsd.gdb"}, + {userspaceDir, "image", "image"}, + {userspaceDir, "key", "key"}, } { - fullDst := filepath.Join(outputDir, dst) - if err := osutil.CopyFile(src, fullDst); err != nil { - return fmt.Errorf("failed to copy %v -> %v: %v", src, fullDst, err) + fullSrc := filepath.Join(s.dir, s.src) + fullDst := filepath.Join(outputDir, s.dst) + if err := osutil.CopyFile(fullSrc, fullDst); err != nil { + return fmt.Errorf("failed to copy %v -> %v: %v", fullSrc, fullDst, err) } } + if useGCE { + return CopyKernelToImage(outputDir) + } return nil } @@ -47,11 +52,18 @@ func (ctx openbsd) clean(kernelDir string) error { return ctx.make(kernelDir, "", "clean") } -func (ctx openbsd) configure(confDir, compileDir, kernelName string) error { - conf := []byte(` -include "arch/amd64/conf/GENERIC" +func (ctx openbsd) configure(confDir, compileDir, kernelName string, useGCE bool) error { + baseConfig := "GENERIC" + if useGCE { + // GCE supports multiple CPUs. + // TODO(gnezdo): Switch to GENERIC.MP once kernel crash is solved. + // http://openbsd-archive.7691.n7.nabble.com/option-kcov-GENERIC-MP-gt-silent-crash-tc355807.html + baseConfig = "GENERIC" + } + conf := []byte(fmt.Sprintf(` +include "arch/amd64/conf/%v" pseudo-device kcov 1 -`) +`, baseConfig)) if err := osutil.WriteFile(filepath.Join(confDir, kernelName), conf); err != nil { return err } @@ -78,3 +90,27 @@ func (ctx openbsd) make(kernelDir string, args ...string) error { _, err := osutil.RunCmd(10*time.Minute, kernelDir, "make", args...) return err } + +// The easiest way to make an openbsd image that boots the given +// kernel on GCE is to simply overwrite it inside the disk image. +// Ideally a user space tool capable of understanding FFS should +// implement this directly, but vnd(4) device would do in a pinch. +// Assumes that the outputDir contains the appropriately named files. +func CopyKernelToImage(outputDir string) error { + script := `set -eux +# Cleanup in case something failed before. +doas umount /altroot || true +doas vnconfig -u vnd0 || true + +doas /sbin/vnconfig vnd0 image +doas mount /dev/vnd0a /altroot +doas cp kernel /altroot/bsd +doas umount /altroot +doas vnconfig -u vnd0 +` + debugOut, err := osutil.RunCmd(10*time.Minute, outputDir, "/bin/sh", "-c", script) + if err != nil { + log.Logf(0, "Error copying kernel into image %v\n%v\n", outputDir, debugOut) + } + return err +} |
