Makefile: Enable kselftest modules in .config

Add LINUX_MODULES variable that contains a list of Kconfig options that
are to be enabled on top of defconfig.

This is needed to enable kernel modules used by kselftest. Normally this
would be done by running `make kselftest-merge` but that enables too
many options that we don't need, including many debugging features of
the kernel which make the tests timeout. Instead we will only enable the
modules/features that our selected tests need.

Bug: 193407077
Test: make linux_modules
Change-Id: Ia1a43ebb35e0710ee83e9605a2c8d324f0eb77d1
diff --git a/Makefile b/Makefile
index 6a65868..dbab5af 100644
--- a/Makefile
+++ b/Makefile
@@ -201,6 +201,7 @@
 LINUX_VMLINUX = $(LINUX_OUT)/vmlinux
 LINUX_CONFIG := $(LINUX_OUT)/.config
 LINUX_DIST_FILES = $(LINUX_CONFIG) $(LINUX_VMLINUX) $(KERNEL_IMAGE)
+LINUX_LSMOD_TXT := $(LINUX_OUT)/lsmod.txt
 
 LINUX_TOOLCHAIN ?= $(TOOLCHAIN)
 $(eval $(call define_toolchain,$(LINUX_TOOLCHAIN),LINUX_))
@@ -223,9 +224,16 @@
 	V=$(LINUX_VERBOSE) \
 	O=$(LINUX_OUT)
 
+LINUX_MODULES := \
+	TEST_PRINTF
+
 .PHONY: linux_defconfig
 linux_defconfig $(LINUX_CONFIG):
 	+ $(LINUX_MAKE) $(LINUX_DEFCONFIG)
+	# Disable all modules, then selectively enable those in LINUX_MODULES.
+	@ echo > $(LINUX_LSMOD_TXT)
+	+ $(LINUX_MAKE) LSMOD=$(LINUX_LSMOD_TXT) localmodconfig
+	$(LINUX_SRC)/scripts/config --file $(LINUX_CONFIG) $(addprefix -m CONFIG_,$(LINUX_MODULES))
 
 .PHONY: linux_menuconfig
 linux_menuconfig: $(LINUX_CONFIG)