[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [RFC] libxc: Add trusted decompressors



On Tue, 2013-02-26 at 22:32 +0000, Bastian Blank wrote:
> Add trusted decompressors based on hypervisor code.
> This are used in mini-os by pv-grub.

I think this is a reasonably pragmatic way to arrange the build.

I'm not sure "trusted" is quite the right term though, these aren't
really any more trustworthy than the library supplied ones -- they are
just more suitable for a mini-os environment.

I can't think of a better term though...

> 
> Signed-off-by: Bastian Blank <waldi@xxxxxxxxxx>
> 
> 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@xxxxxxxxxxxxxx>
>   */
>  
> +#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_??? */



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.