All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: Juergen Gross <jgross@suse.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Daniel De Graaf <dgdegra@tycho.nsa.gov>
Subject: [Xen-devel] [PATCH v2 1/3] xen/flask: Drop the gen-policy.py script
Date: Sat, 7 Dec 2019 18:18:11 +0000	[thread overview]
Message-ID: <20191207181813.30176-2-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <20191207181813.30176-1-andrew.cooper3@citrix.com>

The script is Python 2 specific, and fails with string/binary issues with
Python 3:

  Traceback (most recent call last):
    File "gen-policy.py", line 14, in <module>
      for char in sys.stdin.read():
    File "/usr/lib/python3.5/codecs.py", line 321, in decode
      (result, consumed) = self._buffer_decode(data, self.errors, final)
  UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8c in position 0: invalid start byte

Fixing the script to be compatible isn't hard, but using python here is
wasteful.  Drop the script entirely, and write a short flask-policy.S instead.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Daniel De Graaf <dgdegra@tycho.nsa.gov>
CC: Juergen Gross <jgross@suse.com>

v2:
 * Fix tabs vs spaces issues

For 4.13.  This is a blocker to our intent to by Py3-clean in this release.

Discovered entirely accidently when testing the final patch.
---
 xen/xsm/flask/Makefile       |  6 ++----
 xen/xsm/flask/flask-policy.S | 20 ++++++++++++++++++++
 xen/xsm/flask/gen-policy.py  | 23 -----------------------
 3 files changed, 22 insertions(+), 27 deletions(-)
 create mode 100644 xen/xsm/flask/flask-policy.S
 delete mode 100644 xen/xsm/flask/gen-policy.py

diff --git a/xen/xsm/flask/Makefile b/xen/xsm/flask/Makefile
index f5ffab1226..7c3f381287 100644
--- a/xen/xsm/flask/Makefile
+++ b/xen/xsm/flask/Makefile
@@ -27,7 +27,8 @@ $(FLASK_H_FILES): $(FLASK_H_DEPEND)
 $(AV_H_FILES): $(AV_H_DEPEND)
 	$(CONFIG_SHELL) policy/mkaccess_vector.sh $(AWK) $(AV_H_DEPEND)
 
-obj-$(CONFIG_XSM_FLASK_POLICY) += policy.o
+obj-bin-$(CONFIG_XSM_FLASK_POLICY) += flask-policy.o
+flask-policy.o: policy.bin
 
 FLASK_BUILD_DIR := $(CURDIR)
 POLICY_SRC := $(FLASK_BUILD_DIR)/xenpolicy-$(XEN_FULLVERSION)
@@ -36,9 +37,6 @@ policy.bin: FORCE
 	$(MAKE) -f $(XEN_ROOT)/tools/flask/policy/Makefile.common -C $(XEN_ROOT)/tools/flask/policy FLASK_BUILD_DIR=$(FLASK_BUILD_DIR)
 	cmp -s $(POLICY_SRC) $@ || cp $(POLICY_SRC) $@
 
-policy.c: policy.bin gen-policy.py
-	$(PYTHON) gen-policy.py < $< > $@
-
 .PHONY: clean
 clean::
 	rm -f $(ALL_H_FILES) *.o $(DEPS_RM) policy.* $(POLICY_SRC)
diff --git a/xen/xsm/flask/flask-policy.S b/xen/xsm/flask/flask-policy.S
new file mode 100644
index 0000000000..b63a14851d
--- /dev/null
+++ b/xen/xsm/flask/flask-policy.S
@@ -0,0 +1,20 @@
+        .section .init.rodata, "a", @progbits
+
+/* const unsigned char xsm_flask_init_policy[] __initconst */
+        .align 4
+        .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 */
+        .align 4
+        .global xsm_flask_init_policy_size
+xsm_flask_init_policy_size:
+        .long .Lend - xsm_flask_init_policy
+
+        .type xsm_flask_init_policy_size, @object
+        .size xsm_flask_init_policy_size, . - xsm_flask_init_policy_size
diff --git a/xen/xsm/flask/gen-policy.py b/xen/xsm/flask/gen-policy.py
deleted file mode 100644
index c7501e4614..0000000000
--- a/xen/xsm/flask/gen-policy.py
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/usr/bin/env python
-import sys
-
-policy_size = 0
-
-sys.stdout.write("""
-/* This file is autogenerated by gen_policy.py */
-#include <xen/init.h>
-#include <xsm/xsm.h>
-
-const unsigned char xsm_flask_init_policy[] __initconst = {
-""")
-
-for char in sys.stdin.read():
-    sys.stdout.write(" 0x%02x," % ord(char))
-    policy_size = policy_size + 1
-    if policy_size % 13 == 0:
-        sys.stdout.write("\n")
-
-sys.stdout.write("""
-};
-const unsigned int __initconst xsm_flask_init_policy_size = %d;
-""" % policy_size)
-- 
2.11.0


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2019-12-07 18:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-07 18:18 [Xen-devel] [PATCH for-4.13 v2 0/3] xen: Build fixes related to Python3 Andrew Cooper
2019-12-07 18:18 ` Andrew Cooper [this message]
2019-12-07 18:18 ` [Xen-devel] [PATCH v2 2/3] xen/banner: Drop the fig-to-oct.py script Andrew Cooper
2019-12-07 18:18 ` [Xen-devel] [PATCH v2 3/3] xen/build: Automatically locate a suitable python interpreter Andrew Cooper

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=20191207181813.30176-2-andrew.cooper3@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=dgdegra@tycho.nsa.gov \
    --cc=jgross@suse.com \
    --cc=xen-devel@lists.xenproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.