)]}'
{
  "commit": "fe1f8d5f3dd80b723bb4bf7f9a8ccdedb16d6fec",
  "tree": "6624e75e299affd864040523c3f06c2c8500485f",
  "parents": [
    "f24ac8b3944b8d4405736267fe7d8c883f18f67d"
  ],
  "author": {
    "name": "Mark Brown",
    "email": "broonie@kernel.org",
    "time": "Tue Oct 22 22:32:52 2024 +0100"
  },
  "committer": {
    "name": "Mark Brown",
    "email": "broonie@kernel.org",
    "time": "Tue Nov 05 19:47:17 2024 +0000"
  },
  "message": "arm64/signal: Avoid corruption of SME state when entering signal handler\n\nWe intend that signal handlers are entered with PSTATE.{SM,ZA}\u003d{0,0}.\nThe logic for this in setup_return() manipulates the saved state and\nlive CPU state in an unsafe manner, and consequently, when a task enters\na signal handler:\n\n * The task entering the signal handler might not have its PSTATE.{SM,ZA}\n   bits cleared, and other register state that is affected by changes to\n   PSTATE.{SM,ZA} might not be zeroed as expected.\n\n * An unrelated task might have its PSTATE.{SM,ZA} bits cleared\n   unexpectedly, potentially zeroing other register state that is\n   affected by changes to PSTATE.{SM,ZA}.\n\n   Tasks which do not set PSTATE.{SM,ZA} (i.e. those only using plain\n   FPSIMD or non-streaming SVE) are not affected, as there is no\n   resulting change to PSTATE.{SM,ZA}.\n\nConsider for example two tasks on one CPU:\n\n A: Begins signal entry in kernel mode, is preempted prior to SMSTOP.\n B: Using SM and/or ZA in userspace with register state current on the\n    CPU, is preempted.\n A: Scheduled in, no register state changes made as in kernel mode.\n A: Executes SMSTOP, modifying live register state.\n A: Scheduled out.\n B: Scheduled in, fpsimd_thread_switch() sees the register state on the\n    CPU is tracked as being that for task B so the state is not reloaded\n    prior to returning to userspace.\n\nTask B is now running with SM and ZA incorrectly cleared.\n\nFix this by:\n\n * Checking TIF_FOREIGN_FPSTATE, and only updating the saved or live\n   state as appropriate.\n\n * Using {get,put}_cpu_fpsimd_context() to ensure mutual exclusion\n   against other code which manipulates this state. To allow their use,\n   the logic is moved into a new fpsimd_enter_sighandler() helper in\n   fpsimd.c.\n\nThis race has been observed intermittently with fp-stress, especially\nwith preempt disabled, commonly but not exclusively reporting \"Bad SVCR: 0\".\n\nWhile we\u0027re at it also fix a discrepancy between in register and in memory\nentries. When operating on the register state we issue a SMSTOP, exiting\nstreaming mode if we were in it. This clears the V/Z and P register and\nFPMR but nothing else. The in memory version clears all the user FPSIMD\nstate including FPCR and FPSR but does not clear FPMR. Add the clear of\nFPMR and limit the existing memset() to only cover the vregs, preserving\nthe state of FPCR and FPSR like SMSTOP does.\n\nFixes: 40a8e87bb3285 (\"arm64/sme: Disable ZA and streaming mode when handling signals\")\nSigned-off-by: Mark Brown \u003cbroonie@kernel.org\u003e\nCc: stable@vger.kernel.org\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "f2a84efc361858d4deda99faf1967cc7cac386c1",
      "old_mode": 33188,
      "old_path": "arch/arm64/include/asm/fpsimd.h",
      "new_id": "09af7cfd9f6c2cec26332caa4c254976e117b1bf",
      "new_mode": 33188,
      "new_path": "arch/arm64/include/asm/fpsimd.h"
    },
    {
      "type": "modify",
      "old_id": "77006df20a75aee7c991cf116b6d06bfe953d1a4",
      "old_mode": 33188,
      "old_path": "arch/arm64/kernel/fpsimd.c",
      "new_id": "10c8efd1c5ce83f4ea4025b213111ab9519263b1",
      "new_mode": 33188,
      "new_path": "arch/arm64/kernel/fpsimd.c"
    },
    {
      "type": "modify",
      "old_id": "5619869475304776fc005fe24a385bf86bfdd253",
      "old_mode": 33188,
      "old_path": "arch/arm64/kernel/signal.c",
      "new_id": "fe07d0bd9f7978d73973f07ce38b7bdd7914abb2",
      "new_mode": 33188,
      "new_path": "arch/arm64/kernel/signal.c"
    }
  ]
}
