diff --git a/docs/development/steam-launch-hardware.md b/docs/development/steam-launch-hardware.md index d696a2316e..a345980339 100644 --- a/docs/development/steam-launch-hardware.md +++ b/docs/development/steam-launch-hardware.md @@ -48,7 +48,8 @@ crash in `FEX::FetchHostFeatures()` on a 4.9 L4T kernel Linux 5.15. When any core's `Features` line lacks `cpuid`, `droiddeck-steam-x64 --prepare` -now stops before downloading FEX, its rootfs and the client. The session end +now stops before downloading FEX, its rootfs and the client, and +`droiddeck-fex prepare` stops before installing FEX for x86 Linux programs. The session end screen says FEX can't run on this kernel and stops suggesting x86-64 after an arm64 client SIGILL. Absent or unreadable feature data keeps the previous behavior. diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex b/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex index af04761346..8e8b5c50d4 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-fex @@ -71,6 +71,7 @@ STEAM_VERBS = ("run", "waitforexitandrun") ESCAPE = re.compile(rb"\\([0-7]{3})") DEVICE_FONTS = "/usr/local/share/fonts/android" FONT_RULES = "/etc/fonts/conf.d/66-droiddeck-device-fonts.conf" +CPUINFO = "/proc/cpuinfo" def say(message): @@ -519,7 +520,17 @@ def describe(fex, platform, graphics=None): } +def kernel_hides_cpu_features(): + cores = [line.partition(":")[2].split() for line in (read_text(CPUINFO) or "").splitlines() + if line.partition(":")[0].strip() == "Features"] + return any("cpuid" not in features for features in cores) + + def prepare(app=SNIPER_APPID): + if kernel_hides_cpu_features(): + say("x86 Linux programs need Linux 4.11 or newer to run FEX: Linux %s does not let programs read the CPU's " + "features (no cpuid in %s)" % (os.uname().release, CPUINFO)) + return None with locked(): update_own_fex() fex = fex_install() diff --git a/tools/tests/test_droiddeck_fex.py b/tools/tests/test_droiddeck_fex.py index 35c8201d58..e926fcf517 100644 --- a/tools/tests/test_droiddeck_fex.py +++ b/tools/tests/test_droiddeck_fex.py @@ -51,6 +51,7 @@ class FexTestCase(unittest.TestCase): "FONT_RULES": str(self.tmp / "66-droiddeck-device-fonts.conf"), "OWN_FEX": str(self.tmp / "own"), "OWN_FEX_TAG": str(self.tmp / "own/share/fex-emu/.droiddeck-tag"), + "CPUINFO": str(self.tmp / "cpuinfo"), } patcher = mock.patch.dict(G, patches) patcher.start() @@ -375,6 +376,34 @@ class PrepareTest(FexTestCase): status = json.loads((self.home / ".local/share/droiddeck-fex/status.json").read_text()) self.assertFalse(status["ready"]) + def test_a_kernel_without_cpuid_stops_before_fex_is_installed(self): + self.write(self.tmp / "cpuinfo", "processor : 0\nFeatures : fp asimd evtstrm aes pmull sha1 sha2 crc32\n") + installs = [] + with mock.patch.dict(G, {"fex_install": lambda: installs.append(1), "update_own_fex": lambda: installs.append(1)}): + fex, said = self.quiet(FEX["prepare"]) + self.assertIsNone(fex) + self.assertEqual(installs, []) + self.assertTrue(said.startswith("droiddeck-fex: x86 Linux programs need Linux 4.11 or newer to run FEX")) + self.assertIn("no cpuid", said) + + def test_every_core_must_report_the_exact_cpuid_flag(self): + for features in ("Features : fp asimd cpuid\nFeatures : fp asimd\n", "Features : fp nocpuid cpuid_x\n", + "Features :\n"): + self.write(self.tmp / "cpuinfo", features) + self.assertTrue(FEX["kernel_hides_cpu_features"](), features) + + def test_cpuid_or_no_feature_data_prepares_as_before(self): + tool = self.fex_tool() + self.runtime() + for cpuinfo in ("Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid\n", "processor : 0\n", None): + with contextlib.suppress(FileNotFoundError): + (self.tmp / "cpuinfo").unlink() + if cpuinfo is not None: + self.write(self.tmp / "cpuinfo", cpuinfo) + fex, said = self.quiet(FEX["prepare"]) + self.assertEqual(fex["bin"], str(tool / "usr/bin/FEX"), cpuinfo) + self.assertNotIn("4.11", said) + def test_a_missing_steam_runtime_4_is_named(self): self.fex_tool() self.runtime()