Skip to contentSkip to conversation

xen: rework `checkpolicy` detection when using "randconfig"

PATCH Superseded Anthony PERARD 2 participants 4 messages Sep 8, 2021 – Sep 27, 2021

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 xen: rework `checkpolicy` detection when using "randconfig"

This will help prevent the CI loop from having build failures when checkpolicy isn't available when doing "randconfig" jobs.

To prevent "randconfig" from selecting XSM_FLASK_POLICY when checkpolicy isn't available, we will actually override the config output with the use of KCONFIG_ALLCONFIG.

Doing this way still allow a user/developer to set XSM_FLASK_POLICY even when "checkpolicy" isn't available. It also prevent the build system from reset the config when "checkpolicy" isn't available anymore. And XSM_FLASK_POLICY is still selected automatically when checkpolicy is available.
But this also work well for "randconfig", as it will not select XSM_FLASK_POLICY when "checkpolicy" is missing.

This patch allows to easily add more override which depends on the environment.

Also, move the check out of Config.mk and into xen/ build system. Nothing in tools/ is using that information as it's done by ./configure.

---
v3:
- use KCONFIG_ALLCONFIG
- don't override XSM_FLASK_POLICY value unless we do randconfig.
- no more changes to the current behavior of kconfig, only to randconfig.

v2 was "[XEN PATCH v2] xen: allow XSM_FLASK_POLICY only if checkpolicy binary is available"

---
 Config.mk          |  6 ------
 xen/Makefile       | 18 ++++++++++++++++--
 xen/common/Kconfig |  2 +-
 3 files changed, 17 insertions(+), 9 deletions(-)
Config.mk +0 -6
index d0712724f8e4..144411133f38 100644
@@ -137,12 +137,6 @@ export XEN_HAS_BUILD_ID=y
 build_id_linker := --build-id=sha1
 endif
 
-ifndef XEN_HAS_CHECKPOLICY
-    CHECKPOLICY ?= checkpolicy
-    XEN_HAS_CHECKPOLICY := $(shell $(CHECKPOLICY) -h 2>&1 | grep -q xen && echo y || echo n)
-    export XEN_HAS_CHECKPOLICY
-endif
-
 define buildmakevars2shellvars
     export PREFIX="$(prefix)";                                            \
     export XEN_SCRIPT_DIR="$(XEN_SCRIPT_DIR)";                            \
xen/Makefile +16 -2
index f47423dacd9a..89804aefe385 100644
@@ -17,6 +17,8 @@ export XEN_BUILD_HOST	?= $(shell hostname)
 PYTHON_INTERPRETER	:= $(word 1,$(shell which python3 python python2 2>/dev/null) python)
 export PYTHON		?= $(PYTHON_INTERPRETER)
 
+export CHECKPOLICY	?= checkpolicy
+
 export BASEDIR := $(CURDIR)
 export XEN_ROOT := $(BASEDIR)/..
 
@@ -178,6 +180,8 @@ CFLAGS += $(CLANG_FLAGS)
 export CLANG_FLAGS
 endif
 
+export HAS_CHECKPOLICY := $(call success,$(CHECKPOLICY) -h 2>&1 | grep -q xen)
+
 export root-make-done := y
 endif # root-make-done
 
@@ -189,14 +193,24 @@ ifeq ($(config-build),y)
 # *config targets only - make sure prerequisites are updated, and descend
 # in tools/kconfig to make the *config target
 
+# Create a file for KCONFIG_ALLCONFIG which depends on the environment.
+# This will be use by kconfig targets allyesconfig/allmodconfig/allnoconfig/randconfig
+filechk_kconfig_allconfig = \
+    $(if $(findstring n,$(HAS_CHECKPOLICY)),echo 'CONFIG_XSM_FLASK_POLICY=n';) \
+    $(if $(KCONFIG_ALLCONFIG), cat $(KCONFIG_ALLCONFIG), :)
+
+
+.allconfig.tmp: FORCE
+	set -e; { $(call filechk_kconfig_allconfig); } > $@
+
 config: FORCE
 	$(MAKE) $(kconfig) $@
 
 # Config.mk tries to include .config file, don't try to remake it
 %/.config: ;
 
-%config: FORCE
-	$(MAKE) $(kconfig) $@
+%config: .allconfig.tmp FORCE
+	$(MAKE) $(kconfig) KCONFIG_ALLCONFIG=$< $@
 
 else # !config-build
 
xen/common/Kconfig +1 -1
index 0ddd18e11af3..73d8afb7bcbd 100644
@@ -235,7 +235,7 @@ config XSM_FLASK_AVC_STATS
 
 config XSM_FLASK_POLICY
 	bool "Compile Xen with a built-in FLASK security policy"
-	default y if "$(XEN_HAS_CHECKPOLICY)" = "y"
+	default y if "$(HAS_CHECKPOLICY)"
 	depends on XSM_FLASK
 	---help---
 	  This includes a default XSM policy in the hypervisor so that the
Signature · 1 line
Anthony PERARD
#1 lore raw

Config.mk export XEN_HAS_BUILD_ID=y · line 144

Quoted 11 lines · Anthony PERARD
Config.mk +0 -5
@@ -137,12 +137,6 @@ export XEN_HAS_BUILD_ID=y
 build_id_linker := --build-id=sha1
 endif
 
-ifndef XEN_HAS_CHECKPOLICY
-    CHECKPOLICY ?= checkpolicy
-    XEN_HAS_CHECKPOLICY := $(shell $(CHECKPOLICY) -h 2>&1 | grep -q xen && echo y || echo n)
-    export XEN_HAS_CHECKPOLICY
-endif

Is there a particular reason to go from XEN_HAS_CHECKPOLICY to ...

Quoted 12 lines
xen/Makefile +2 -0
@@ -17,6 +17,8 @@ export XEN_BUILD_HOST	?= $(shell hostname)
 PYTHON_INTERPRETER	:= $(word 1,$(shell which python3 python python2 2>/dev/null) python)
 export PYTHON		?= $(PYTHON_INTERPRETER)
 
+export CHECKPOLICY	?= checkpolicy
+
 export BASEDIR := $(CURDIR)
 export XEN_ROOT := $(BASEDIR)/..
 

xen/Makefile CFLAGS += $(CLANG_FLAGS) · line 183

Quoted 4 lines
xen/Makefile +1 -0
@@ -178,6 +180,8 @@ CFLAGS += $(CLANG_FLAGS)
 export CLANG_FLAGS
 endif
 
+export HAS_CHECKPOLICY := $(call success,$(CHECKPOLICY) -h 2>&1 | grep -q xen)

... HAS_CHECKPOLICY? As soon as things get put in the environment, I'm always suspecting possible name collisions ...

xen/Makefile ifeq ($(config-build),y) · line 200

Quoted 9 lines
xen/Makefile +5 -0
@@ -189,14 +193,24 @@ ifeq ($(config-build),y)
 # *config targets only - make sure prerequisites are updated, and descend
 # in tools/kconfig to make the *config target
 
+# Create a file for KCONFIG_ALLCONFIG which depends on the environment.
+# This will be use by kconfig targets allyesconfig/allmodconfig/allnoconfig/randconfig
+filechk_kconfig_allconfig = \
+    $(if $(findstring n,$(HAS_CHECKPOLICY)),echo 'CONFIG_XSM_FLASK_POLICY=n';) \
+    $(if $(KCONFIG_ALLCONFIG), cat $(KCONFIG_ALLCONFIG), :)

Nit: It would be nice if you were consistent with the blanks after commas in $(if ...). Personally I'm also considering $(if ...)s the more difficult to follow the longer they are. Hence for the 2nd one I wonder whether

    $(if $(KCONFIG_ALLCONFIG),cat,:) $(KCONFIG_ALLCONFIG)

wouldn't be easier to read.

xen/Makefile ifeq ($(config-build),y) · line 202

Quoted 2 lines
xen/Makefile +2 -0
+
+

Nit: Please avoid double blank lines.

xen/Makefile ifeq ($(config-build),y) · line 204

Quoted 2 lines
xen/Makefile +2 -0
+.allconfig.tmp: FORCE
+	set -e; { $(call filechk_kconfig_allconfig); } > $@

Is there a particular reason for the .tmp suffix?

Jan

#2 lore raw
Quoted 26 lines · Jan Beulich

Config.mk export XEN_HAS_BUILD_ID=y · line 144

Quoted 11 lines · Anthony PERARD
Config.mk +0 -5
@@ -137,12 +137,6 @@ export XEN_HAS_BUILD_ID=y
 build_id_linker := --build-id=sha1
 endif
 
-ifndef XEN_HAS_CHECKPOLICY
-    CHECKPOLICY ?= checkpolicy
-    XEN_HAS_CHECKPOLICY := $(shell $(CHECKPOLICY) -h 2>&1 | grep -q xen && echo y || echo n)
-    export XEN_HAS_CHECKPOLICY
-endif

Is there a particular reason to go from XEN_HAS_CHECKPOLICY to ...

Quoted 11 lines
xen/Makefile +2 -0
@@ -17,6 +17,8 @@ export XEN_BUILD_HOST	?= $(shell hostname)
 PYTHON_INTERPRETER	:= $(word 1,$(shell which python3 python python2 2>/dev/null) python)
 export PYTHON		?= $(PYTHON_INTERPRETER)
 
+export CHECKPOLICY	?= checkpolicy
+
 export BASEDIR := $(CURDIR)
 export XEN_ROOT := $(BASEDIR)/..
 
Quoted 7 lines

xen/Makefile CFLAGS += $(CLANG_FLAGS) · line 183

Quoted 5 lines
xen/Makefile +1 -0
@@ -178,6 +180,8 @@ CFLAGS += $(CLANG_FLAGS)
 export CLANG_FLAGS
 endif
 
+export HAS_CHECKPOLICY := $(call success,$(CHECKPOLICY) -h 2>&1 | grep -q xen)

... HAS_CHECKPOLICY? As soon as things get put in the environment,

Not really anymore, it's just left over from having put this in Kconfig in previous version of the patch.

Quoted 1 line

I'm always suspecting possible name collisions ...

Yes, it's probably better to keep the XEN_ prefix.

Quoted 15 lines

xen/Makefile ifeq ($(config-build),y) · line 200

Quoted 9 lines
xen/Makefile +5 -0
@@ -189,14 +193,24 @@ ifeq ($(config-build),y)
 # *config targets only - make sure prerequisites are updated, and descend
 # in tools/kconfig to make the *config target
 
+# Create a file for KCONFIG_ALLCONFIG which depends on the environment.
+# This will be use by kconfig targets allyesconfig/allmodconfig/allnoconfig/randconfig
+filechk_kconfig_allconfig = \
+    $(if $(findstring n,$(HAS_CHECKPOLICY)),echo 'CONFIG_XSM_FLASK_POLICY=n';) \
+    $(if $(KCONFIG_ALLCONFIG), cat $(KCONFIG_ALLCONFIG), :)

Nit: It would be nice if you were consistent with the blanks after commas in $(if ...). Personally I'm also considering $(if ...)s the more difficult to follow the longer they are. Hence for the 2nd one I wonder whether

Quoted 3 lines
    $(if $(KCONFIG_ALLCONFIG),cat,:) $(KCONFIG_ALLCONFIG)

wouldn't be easier to read.

How about:

    $(if $(KCONFIG_ALLCONFIG), cat $(KCONFIG_ALLCONFIG);) \
    :

.. instead, as that would be more consistent with the previous line, that is there would be only one branch to the $(if ) and no else, and thus probably easier to read.

Quoted 4 lines

xen/Makefile ifeq ($(config-build),y) · line 204

Quoted 2 lines
xen/Makefile +2 -0
+.allconfig.tmp: FORCE
+	set -e; { $(call filechk_kconfig_allconfig); } > $@

Is there a particular reason for the .tmp suffix?

Yes, .*.tmp are already ignored via .gitignore.

Thanks,

Signature · 1 line
Anthony PERARD
#3 lore raw
Quoted 21 lines · Anthony PERARD
Quoted 16 lines · Jan Beulich

xen/Makefile ifeq ($(config-build),y) · line 200

Quoted 9 lines · Anthony PERARD
xen/Makefile +5 -0
@@ -189,14 +193,24 @@ ifeq ($(config-build),y)
 # *config targets only - make sure prerequisites are updated, and descend
 # in tools/kconfig to make the *config target
 
+# Create a file for KCONFIG_ALLCONFIG which depends on the environment.
+# This will be use by kconfig targets allyesconfig/allmodconfig/allnoconfig/randconfig
+filechk_kconfig_allconfig = \
+    $(if $(findstring n,$(HAS_CHECKPOLICY)),echo 'CONFIG_XSM_FLASK_POLICY=n';) \
+    $(if $(KCONFIG_ALLCONFIG), cat $(KCONFIG_ALLCONFIG), :)

Nit: It would be nice if you were consistent with the blanks after commas in $(if ...). Personally I'm also considering $(if ...)s the more difficult to follow the longer they are. Hence for the 2nd one I wonder whether

Quoted 3 lines
    $(if $(KCONFIG_ALLCONFIG),cat,:) $(KCONFIG_ALLCONFIG)

wouldn't be easier to read.

Quoted 8 lines

How about:

    $(if $(KCONFIG_ALLCONFIG), cat $(KCONFIG_ALLCONFIG);) \
    :

.. instead, as that would be more consistent with the previous line, that is there would be only one branch to the $(if ) and no else, and thus probably easier to read.

Oh, sure, even better if that works.

Quoted 6 lines
Quoted 4 lines

xen/Makefile ifeq ($(config-build),y) · line 204

Quoted 2 lines
xen/Makefile +2 -0
+.allconfig.tmp: FORCE
+	set -e; { $(call filechk_kconfig_allconfig); } > $@

Is there a particular reason for the .tmp suffix?

Yes, .*.tmp are already ignored via .gitignore.

I see. Could you add two words to the description saying so? Or maybe even just a post-commit-message remark would do.

Jan