Message ID | 20200121084330.18309-2-jgross@suse.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Add hypervisor sysfs-like support | expand |
On 21.01.2020 09:43, Juergen Gross wrote: > --- /dev/null > +++ b/xen/tools/binfile > @@ -0,0 +1,29 @@ > +#!/bin/sh > +# usage: binfile [-i] <target-src.S> <binary-file> <varname> > +# -i add to .init.rodata (default: .rodata) section > + > +[ "$1" = "-i" ] && { > + shift > + section=".init" > +} > + > +target=$1 > +binsource=$2 > +varname=$3 > + > +cat <<EOF >$target > +#include <asm/asm_defns.h> > + > + .section $section.rodata, "a", %progbits > + > + .global $varname > +$varname: > + .incbin "$binsource" > +.Lend: > + > + .type $varname, %object > + .size $varname, . - $varname I'd prefer if you used .Lend here as well. I wonder whether, right from the beginning, there wouldn't better be a way to also request better than byte alignment for such a blob. > --- a/xen/xsm/flask/Makefile > +++ b/xen/xsm/flask/Makefile > @@ -30,6 +30,9 @@ $(AV_H_FILES): $(AV_H_DEPEND) > obj-bin-$(CONFIG_XSM_FLASK_POLICY) += flask-policy.o > flask-policy.o: policy.bin > > +flask-policy.S: $(XEN_ROOT)/xen/tools/binfile > + $(XEN_ROOT)/xen/tools/binfile -i $@ policy.bin xsm_flask_init_policy Doesn't objcopy provide a means to convert a binary blob into an ELF object containing the binary data from the input file? If so, why involve the assembler and an intermediate file here? Jan
On 03.02.20 14:39, Jan Beulich wrote: > On 21.01.2020 09:43, Juergen Gross wrote: >> --- /dev/null >> +++ b/xen/tools/binfile >> @@ -0,0 +1,29 @@ >> +#!/bin/sh >> +# usage: binfile [-i] <target-src.S> <binary-file> <varname> >> +# -i add to .init.rodata (default: .rodata) section >> + >> +[ "$1" = "-i" ] && { >> + shift >> + section=".init" >> +} >> + >> +target=$1 >> +binsource=$2 >> +varname=$3 >> + >> +cat <<EOF >$target >> +#include <asm/asm_defns.h> >> + >> + .section $section.rodata, "a", %progbits >> + >> + .global $varname >> +$varname: >> + .incbin "$binsource" >> +.Lend: >> + >> + .type $varname, %object >> + .size $varname, . - $varname > > I'd prefer if you used .Lend here as well. Okay. > I wonder whether, right from the beginning, there wouldn't better > be a way to also request better than byte alignment for such a > blob. I can add that. What about "-a <n>" for 2^n alignment? > >> --- a/xen/xsm/flask/Makefile >> +++ b/xen/xsm/flask/Makefile >> @@ -30,6 +30,9 @@ $(AV_H_FILES): $(AV_H_DEPEND) >> obj-bin-$(CONFIG_XSM_FLASK_POLICY) += flask-policy.o >> flask-policy.o: policy.bin >> >> +flask-policy.S: $(XEN_ROOT)/xen/tools/binfile >> + $(XEN_ROOT)/xen/tools/binfile -i $@ policy.bin xsm_flask_init_policy > > Doesn't objcopy provide a means to convert a binary blob into > an ELF object containing the binary data from the input file? > If so, why involve the assembler and an intermediate file here? I can see how to add a symbol for that purpose using a dedicated section for each blob, but how to add the size information of the blob? In the end I just followed commit 8d5671eb31e4bf for the inclusion of the blob. Juergen
On 03.02.2020 15:02, Jürgen Groß wrote: > On 03.02.20 14:39, Jan Beulich wrote: >> On 21.01.2020 09:43, Juergen Gross wrote: >>> --- /dev/null >>> +++ b/xen/tools/binfile >>> @@ -0,0 +1,29 @@ >>> +#!/bin/sh >>> +# usage: binfile [-i] <target-src.S> <binary-file> <varname> >>> +# -i add to .init.rodata (default: .rodata) section >>> + >>> +[ "$1" = "-i" ] && { >>> + shift >>> + section=".init" >>> +} >>> + >>> +target=$1 >>> +binsource=$2 >>> +varname=$3 >>> + >>> +cat <<EOF >$target >>> +#include <asm/asm_defns.h> >>> + >>> + .section $section.rodata, "a", %progbits >>> + >>> + .global $varname >>> +$varname: >>> + .incbin "$binsource" >>> +.Lend: >>> + >>> + .type $varname, %object >>> + .size $varname, . - $varname >> >> I'd prefer if you used .Lend here as well. > > Okay. > >> I wonder whether, right from the beginning, there wouldn't better >> be a way to also request better than byte alignment for such a >> blob. > > I can add that. What about "-a <n>" for 2^n alignment? SGTM. >>> --- a/xen/xsm/flask/Makefile >>> +++ b/xen/xsm/flask/Makefile >>> @@ -30,6 +30,9 @@ $(AV_H_FILES): $(AV_H_DEPEND) >>> obj-bin-$(CONFIG_XSM_FLASK_POLICY) += flask-policy.o >>> flask-policy.o: policy.bin >>> >>> +flask-policy.S: $(XEN_ROOT)/xen/tools/binfile >>> + $(XEN_ROOT)/xen/tools/binfile -i $@ policy.bin xsm_flask_init_policy >> >> Doesn't objcopy provide a means to convert a binary blob into >> an ELF object containing the binary data from the input file? >> If so, why involve the assembler and an intermediate file here? > > I can see how to add a symbol for that purpose using a dedicated section > for each blob, but how to add the size information of the blob? Hmm, right. It would be doable, but perhaps indeed not very nice. Fair enough then. Jan
diff --git a/.gitignore b/.gitignore index 4ca679ddbc..b2624df79a 100644 --- a/.gitignore +++ b/.gitignore @@ -313,6 +313,7 @@ xen/test/livepatch/*.livepatch xen/tools/kconfig/.tmp_gtkcheck xen/tools/kconfig/.tmp_qtcheck xen/tools/symbols +xen/xsm/flask/flask-policy.S xen/xsm/flask/include/av_perm_to_string.h xen/xsm/flask/include/av_permissions.h xen/xsm/flask/include/class_to_string.h diff --git a/xen/tools/binfile b/xen/tools/binfile new file mode 100755 index 0000000000..122111ff6d --- /dev/null +++ b/xen/tools/binfile @@ -0,0 +1,29 @@ +#!/bin/sh +# usage: binfile [-i] <target-src.S> <binary-file> <varname> +# -i add to .init.rodata (default: .rodata) section + +[ "$1" = "-i" ] && { + shift + section=".init" +} + +target=$1 +binsource=$2 +varname=$3 + +cat <<EOF >$target +#include <asm/asm_defns.h> + + .section $section.rodata, "a", %progbits + + .global $varname +$varname: + .incbin "$binsource" +.Lend: + + .type $varname, %object + .size $varname, . - $varname + + .global ${varname}_size + ASM_INT(${varname}_size, .Lend - $varname) +EOF diff --git a/xen/xsm/flask/Makefile b/xen/xsm/flask/Makefile index 7c3f381287..a807521235 100644 --- a/xen/xsm/flask/Makefile +++ b/xen/xsm/flask/Makefile @@ -30,6 +30,9 @@ $(AV_H_FILES): $(AV_H_DEPEND) obj-bin-$(CONFIG_XSM_FLASK_POLICY) += flask-policy.o flask-policy.o: policy.bin +flask-policy.S: $(XEN_ROOT)/xen/tools/binfile + $(XEN_ROOT)/xen/tools/binfile -i $@ policy.bin xsm_flask_init_policy + FLASK_BUILD_DIR := $(CURDIR) POLICY_SRC := $(FLASK_BUILD_DIR)/xenpolicy-$(XEN_FULLVERSION) @@ -39,4 +42,4 @@ policy.bin: FORCE .PHONY: clean clean:: - rm -f $(ALL_H_FILES) *.o $(DEPS_RM) policy.* $(POLICY_SRC) + rm -f $(ALL_H_FILES) *.o $(DEPS_RM) policy.* $(POLICY_SRC) flask-policy.S diff --git a/xen/xsm/flask/flask-policy.S b/xen/xsm/flask/flask-policy.S deleted file mode 100644 index d38aa39964..0000000000 --- a/xen/xsm/flask/flask-policy.S +++ /dev/null @@ -1,16 +0,0 @@ -#include <asm/asm_defns.h> - - .section .init.rodata, "a", %progbits - -/* const unsigned char xsm_flask_init_policy[] __initconst */ - .global xsm_flask_init_policy -xsm_flask_init_policy: - .incbin "policy.bin" -.Lend: - - .type xsm_flask_init_policy, %object - .size xsm_flask_init_policy, . - xsm_flask_init_policy - -/* const unsigned int __initconst xsm_flask_init_policy_size */ - .global xsm_flask_init_policy_size - ASM_INT(xsm_flask_init_policy_size, .Lend - xsm_flask_init_policy)
Add a new script xen/tools/binfile for including a binary file at build time being usable via a pointer and a size variable in the hypervisor. Make use of that generic tool in xsm. Signed-off-by: Juergen Gross <jgross@suse.com> --- V3: - new patch --- .gitignore | 1 + xen/tools/binfile | 29 +++++++++++++++++++++++++++++ xen/xsm/flask/Makefile | 5 ++++- xen/xsm/flask/flask-policy.S | 16 ---------------- 4 files changed, 34 insertions(+), 17 deletions(-) create mode 100755 xen/tools/binfile delete mode 100644 xen/xsm/flask/flask-policy.S