xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Bastian Blank <waldi@debian.org>
To: xen-devel@lists.xen.org, Ian Campbell <Ian.Campbell@citrix.com>
Subject: [RFC] libxc: Add trusted decompressors
Date: Tue, 26 Feb 2013 23:32:49 +0100	[thread overview]
Message-ID: <20130226223249.GD27098@waldi.eu.org> (raw)
In-Reply-To: <20130226222502.GB27098@waldi.eu.org>

Add trusted decompressors based on hypervisor code.
This are used in mini-os by pv-grub.

Signed-off-by: Bastian Blank <waldi@debian.org>

diff -r efdc4bbfdd20 stubdom/Makefile
--- a/stubdom/Makefile	Tue Feb 26 19:42:36 2013 +0100
+++ b/stubdom/Makefile	Tue Feb 26 23:20:22 2013 +0100
@@ -328,7 +328,7 @@
 .PHONY: libxc
 libxc: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a
 libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: cross-zlib
-	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libxc-$(XEN_TARGET_ARCH)
+	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= CONFIG_LIBXC_MINIOS=y -C libxc-$(XEN_TARGET_ARCH)
 
  libxc-$(XEN_TARGET_ARCH)/libxenguest.a: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a
 
diff -r efdc4bbfdd20 tools/libxc/Makefile
--- a/tools/libxc/Makefile	Tue Feb 26 19:42:36 2013 +0100
+++ b/tools/libxc/Makefile	Tue Feb 26 23:20:22 2013 +0100
@@ -58,7 +58,6 @@
 GUEST_SRCS-y                 += xc_dom_core.c xc_dom_boot.c
 GUEST_SRCS-y                 += xc_dom_elfloader.c
 GUEST_SRCS-$(CONFIG_X86)     += xc_dom_bzimageloader.c
-GUEST_SRCS-$(CONFIG_X86)     += xc_dom_decompress.c
 GUEST_SRCS-$(CONFIG_ARM)     += xc_dom_armzimageloader.c
 GUEST_SRCS-y                 += xc_dom_binloader.c
 GUEST_SRCS-y                 += xc_dom_compat_linux.c
@@ -69,6 +68,16 @@
 GUEST_SRCS-$(CONFIG_ARM)     += xc_dom_arm.c
 GUEST_SRCS-$(CONFIG_ARM)     += xc_hvm_build_arm.c
 
+ifeq ($(CONFIG_LIBXC_MINIOS),y)
+GUEST_SRCS-y                 += xc_dom_decompress_trusted.c
+GUEST_SRCS-y                 += xc_dom_decompress_trusted_bzip2.c
+GUEST_SRCS-y                 += xc_dom_decompress_trusted_lzma.c
+GUEST_SRCS-y                 += xc_dom_decompress_trusted_lzo1x.c
+GUEST_SRCS-y                 += xc_dom_decompress_trusted_xz.c
+else
+GUEST_SRCS-y                 += xc_dom_decompress.c
+endif
+
 OSDEP_SRCS-y                 += xenctrl_osdep_ENOSYS.c
 
 -include $(XEN_TARGET_ARCH)/Makefile
diff -r efdc4bbfdd20 tools/libxc/xc_dom_decompress_trusted.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/libxc/xc_dom_decompress_trusted.c	Tue Feb 26 23:20:22 2013 +0100
@@ -0,0 +1,49 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <inttypes.h>
+
+#include "xg_private.h"
+#include "xc_dom_decompress_trusted.h"
+
+struct xc_dom_image *trusted_dom;
+static unsigned char *output_blob;
+static unsigned int output_size;
+
+static void trusted_error(const char *msg)
+{
+    xc_dom_panic(trusted_dom->xch, XC_INVALID_KERNEL, "%s", msg);
+}
+
+static int trusted_flush(void *src, unsigned int size)
+{
+    void *n = realloc(output_blob, output_size + size);
+    if (!n)
+        return -1;
+    output_blob = n;
+
+    memcpy(&output_blob[output_size], src, size);
+    output_size += size;
+    return size;
+}
+
+int xc_dom_decompress_trusted_decompress(
+    decompress_fn fn, struct xc_dom_image *dom, void **blob, size_t *size)
+{
+    int ret;
+
+    trusted_dom = dom;
+    output_blob = NULL;
+    output_size = 0;
+
+    ret = fn(dom->kernel_blob, dom->kernel_size, NULL, trusted_flush, NULL, NULL, trusted_error);
+
+    if (ret)
+        free(output_blob);
+    else {
+        *blob = output_blob;
+        *size = output_size;
+    }
+
+    return ret;
+}
+
diff -r efdc4bbfdd20 tools/libxc/xc_dom_decompress_trusted.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/libxc/xc_dom_decompress_trusted.h	Tue Feb 26 23:20:22 2013 +0100
@@ -0,0 +1,12 @@
+#include "xc_dom.h"
+
+typedef int decompress_fn(unsigned char *inbuf, unsigned int len,
+                          int (*fill)(void*, unsigned int),
+                          int (*flush)(void*, unsigned int),
+                          unsigned char *outbuf, unsigned int *posp,
+                          void (*error)(const char *x));
+
+int xc_dom_decompress_trusted_decompress(
+    decompress_fn fn, struct xc_dom_image *dom, void **blob, size_t *size)
+    __attribute__((visibility("hidden")));
+
diff -r efdc4bbfdd20 tools/libxc/xc_dom_decompress_trusted_bzip2.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/libxc/xc_dom_decompress_trusted_bzip2.c	Tue Feb 26 23:20:22 2013 +0100
@@ -0,0 +1,14 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <inttypes.h>
+
+#include "xg_private.h"
+#include "xc_dom_decompress_trusted.h"
+
+#include "../../xen/common/bunzip2.c"
+
+int xc_try_bzip2_decode(
+    struct xc_dom_image *dom, void **blob, size_t *size)
+{
+    return xc_dom_decompress_trusted_decompress(bunzip2, dom, blob, size);
+}
diff -r efdc4bbfdd20 tools/libxc/xc_dom_decompress_trusted_lzma.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/libxc/xc_dom_decompress_trusted_lzma.c	Tue Feb 26 23:20:22 2013 +0100
@@ -0,0 +1,14 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <inttypes.h>
+
+#include "xg_private.h"
+#include "xc_dom_decompress_trusted.h"
+
+#include "../../xen/common/unlzma.c"
+
+int xc_try_lzma_decode(
+    struct xc_dom_image *dom, void **blob, size_t *size)
+{
+    return xc_dom_decompress_trusted_decompress(unlzma, dom, blob, size);
+}
diff -r efdc4bbfdd20 tools/libxc/xc_dom_decompress_trusted_lzo1x.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/libxc/xc_dom_decompress_trusted_lzo1x.c	Tue Feb 26 23:20:22 2013 +0100
@@ -0,0 +1,15 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <inttypes.h>
+
+#include "xg_private.h"
+#include "xc_dom_decompress_trusted.h"
+
+#include "../../xen/common/lzo.c"
+#include "../../xen/common/unlzo.c"
+
+int xc_try_lzo1x_decode(
+    struct xc_dom_image *dom, void **blob, size_t *size)
+{
+    return xc_dom_decompress_trusted_decompress(unlzo, dom, blob, size);
+}
diff -r efdc4bbfdd20 tools/libxc/xc_dom_decompress_trusted_xz.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/libxc/xc_dom_decompress_trusted_xz.c	Tue Feb 26 23:20:22 2013 +0100
@@ -0,0 +1,17 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <inttypes.h>
+
+#include "xg_private.h"
+#include "xc_dom_decompress_trusted.h"
+
+// TODO
+#define XZ_DEC_X86
+
+#include "../../xen/common/unxz.c"
+
+int xc_try_xz_decode(
+    struct xc_dom_image *dom, void **blob, size_t *size)
+{
+    return xc_dom_decompress_trusted_decompress(unxz, dom, blob, size);
+}
diff -r efdc4bbfdd20 xen/common/decompress.h
--- a/xen/common/decompress.h	Tue Feb 26 19:42:36 2013 +0100
+++ b/xen/common/decompress.h	Tue Feb 26 23:20:22 2013 +0100
@@ -1,3 +1,5 @@
+#ifdef __XEN__
+
 #include <xen/config.h>
 #include <xen/cache.h>
 #include <xen/decompress.h>
@@ -15,3 +17,14 @@
 
 #define large_malloc xmalloc_bytes
 #define large_free xfree
+
+#else
+
+#define STATIC static
+#define INIT
+#define INITDATA
+
+#define large_malloc malloc
+#define large_free free
+
+#endif
diff -r efdc4bbfdd20 xen/common/lzo.c
--- a/xen/common/lzo.c	Tue Feb 26 19:42:36 2013 +0100
+++ b/xen/common/lzo.c	Tue Feb 26 23:20:22 2013 +0100
@@ -68,7 +68,19 @@
  *  Richard Purdie <rpurdie@openedhand.com>
  */
 
+#ifndef __MINIOS__
 #include <xen/types.h>
+#else
+#include <stdint.h>
+
+typedef uint32_t u32;
+typedef uint16_t u16;
+
+#define likely(a) a
+#define noinline
+#define unlikely(a) a
+#endif
+
 #include <xen/lzo.h>
 #define get_unaligned(_p) (*(_p))
 #define put_unaligned(_val,_p) (*(_p)=_val)
diff -r efdc4bbfdd20 xen/common/unlzma.c
--- a/xen/common/unlzma.c	Tue Feb 26 19:42:36 2013 +0100
+++ b/xen/common/unlzma.c	Tue Feb 26 23:20:22 2013 +0100
@@ -54,7 +54,9 @@
  * Copyright (c) 1999-2005  Igor Pavlov
  */
 
+#ifndef __MINIOS__
 #include <xen/compiler.h>
+#endif
 
 #define LZMA_IOBUF_SIZE	0x10000
 
diff -r efdc4bbfdd20 xen/common/unlzo.c
--- a/xen/common/unlzo.c	Tue Feb 26 19:42:36 2013 +0100
+++ b/xen/common/unlzo.c	Tue Feb 26 23:20:22 2013 +0100
@@ -32,7 +32,43 @@
 
 #include "decompress.h"
 #include <xen/lzo.h>
+
+#ifndef __MINIOS__
 #include <asm/byteorder.h>
+#else
+#include <endian.h>
+#include <stdint.h>
+
+typedef uint8_t u8;
+typedef uint16_t u16;
+typedef uint32_t u32;
+
+static inline u16 be16_to_cpup(const u16 *p)
+{
+	u16 v = *p;
+#if BYTE_ORDER == LITTLE_ENDIAN
+	return (((v & 0x00ffU) << 8) |
+                ((v & 0xff00U) >> 8));
+#else
+	return v;
+#endif
+}
+
+static inline u32 be32_to_cpup(const u32 *p)
+{
+	u32 v = *p;
+#if BYTE_ORDER == LITTLE_ENDIAN
+	return (((v & 0x000000ffUL) << 24) |
+                ((v & 0x0000ff00UL) <<  8) |
+                ((v & 0x00ff0000UL) >>  8) |
+                ((v & 0xff000000UL) >> 24));
+#else
+	return v;
+#endif
+}
+
+#define unlikely(a) a
+#endif
 
 #if 1 /* ndef CONFIG_??? */
 static inline u16 INIT get_unaligned_be16(void *p)
diff -r efdc4bbfdd20 xen/common/xz/private.h
--- a/xen/common/xz/private.h	Tue Feb 26 19:42:36 2013 +0100
+++ b/xen/common/xz/private.h	Tue Feb 26 23:20:22 2013 +0100
@@ -10,8 +10,53 @@
 #ifndef XZ_PRIVATE_H
 #define XZ_PRIVATE_H
 
+#ifndef __MINIOS__
 #include <xen/kernel.h>
 #include <asm/byteorder.h>
+#else
+#include <endian.h>
+#include <stddef.h>
+#include <stdint.h>
+
+typedef char bool_t;
+typedef uint8_t u8;
+typedef uint16_t u16;
+typedef uint32_t u32;
+typedef uint32_t __le32;
+
+static inline u32 cpu_to_le32(const u32 v)
+{
+#if BYTE_ORDER == BIG_ENDIAN
+	return (((v & 0x000000ffUL) << 24) |
+	        ((v & 0x0000ff00UL) <<  8) |
+	        ((v & 0x00ff0000UL) >>  8) |
+	        ((v & 0xff000000UL) >> 24));
+#else  
+	return v;
+#endif
+}
+
+static inline u32 le32_to_cpup(const u32 *p)
+{
+	return cpu_to_le32(*p);
+}
+
+#define min(x,y) ({ \
+        const typeof(x) _x = (x);       \
+        const typeof(y) _y = (y);       \
+        (void) (&_x == &_y);            \
+        _x < _y ? _x : _y; })
+
+#define min_t(type,x,y) \
+        ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
+#define max_t(type,x,y) \
+        ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
+
+#define __force
+#define always_inline
+
+#endif
+
 #define get_le32(p) le32_to_cpup((const uint32_t *)(p))
 
 #if 1 /* ndef CONFIG_??? */

  parent reply	other threads:[~2013-02-26 22:32 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-04 11:56 [PATCH] pv-grub: Support bzip2, xz and lzo compressed kernels Ian Campbell
2013-01-04 12:15 ` Samuel Thibault
2013-01-04 12:43   ` Ian Campbell
2013-01-04 23:42     ` Samuel Thibault
2013-09-10 18:51     ` Matt Wilson
2013-09-10 19:05       ` Bastian Blank
2013-09-10 19:14         ` Matt Wilson
2013-01-04 12:33 ` Bastian Blank
2013-01-04 12:40   ` Ian Campbell
2013-02-26 22:25     ` Bastian Blank
2013-02-26 22:30       ` [RFC] libxc: Move compression support into own file Bastian Blank
2013-02-26 22:32       ` Bastian Blank [this message]
2013-02-27 12:17         ` [RFC] libxc: Add trusted decompressors Ian Campbell
2013-02-27 12:44           ` Bastian Blank
2013-02-27 14:28             ` Ian Campbell
2013-03-04 10:33             ` George Dunlap
2013-03-04 11:02               ` Tim Deegan
2013-03-12 15:21                 ` Ian Campbell
2013-03-02 20:16         ` [PATCH] " Bastian Blank

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130226223249.GD27098@waldi.eu.org \
    --to=waldi@debian.org \
    --cc=Ian.Campbell@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).