1. 16 Nov, 2019 28 commits
  2. 12 Nov, 2019 12 commits
    • Greg Kroah-Hartman's avatar
      Linux 4.9.201 · 9829ecfd
      Greg Kroah-Hartman authored
      9829ecfd
    • Ben Hutchings's avatar
      drm/i915/cmdparser: Fix jump whitelist clearing · 139bb57b
      Ben Hutchings authored
      commit ea0b163b upstream.
      
      When a jump_whitelist bitmap is reused, it needs to be cleared.
      Currently this is done with memset() and the size calculation assumes
      bitmaps are made of 32-bit words, not longs.  So on 64-bit
      architectures, only the first half of the bitmap is cleared.
      
      If some whitelist bits are carried over between successive batches
      submitted on the same context, this will presumably allow embedding
      the rogue instructions that we're trying to reject.
      
      Use bitmap_zero() instead, which gets the calculation right.
      
      Fixes: f8c08d8f ("drm/i915/cmdparser: Add support for backward jumps")
      Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
      Signed-off-by: default avatarJon Bloomfield <jon.bloomfield@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      139bb57b
    • Imre Deak's avatar
      drm/i915/gen8+: Add RC6 CTX corruption WA · 00194ecf
      Imre Deak authored
      commit 7e34f4e4 upstream.
      
      In some circumstances the RC6 context can get corrupted. We can detect
      this and take the required action, that is disable RC6 and runtime PM.
      The HW recovers from the corrupted state after a system suspend/resume
      cycle, so detect the recovery and re-enable RC6 and runtime PM.
      
      v2: rebase (Mika)
      v3:
      - Move intel_suspend_gt_powersave() to the end of the GEM suspend
        sequence.
      - Add commit message.
      v4:
      - Rebased on intel_uncore_forcewake_put(i915->uncore, ...) API
        change.
      v5:
      - Rebased on latest upstream gt_pm refactoring.
      Signed-off-by: default avatarImre Deak <imre.deak@intel.com>
      Signed-off-by: default avatarMika Kuoppala <mika.kuoppala@linux.intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      00194ecf
    • Uma Shankar's avatar
      drm/i915: Lower RM timeout to avoid DSI hard hangs · ebd6ded1
      Uma Shankar authored
      commit 1d85a299 upstream.
      
      In BXT/APL, device 2 MMIO reads from MIPI controller requires its PLL
      to be turned ON. When MIPI PLL is turned off (MIPI Display is not
      active or connected), and someone (host or GT engine) tries to read
      MIPI registers, it causes hard hang. This is a hardware restriction
      or limitation.
      
      Driver by itself doesn't read MIPI registers when MIPI display is off.
      But any userspace application can submit unprivileged batch buffer for
      execution. In that batch buffer there can be mmio reads. And these
      reads are allowed even for unprivileged applications. If these
      register reads are for MIPI DSI controller and MIPI display is not
      active during that time, then the MMIO read operation causes system
      hard hang and only way to recover is hard reboot. A genuine
      process/application won't submit batch buffer like this and doesn't
      cause any issue. But on a compromised system, a malign userspace
      process/app can generate such batch buffer and can trigger system
      hard hang (denial of service attack).
      
      The fix is to lower the internal MMIO timeout value to an optimum
      value of 950us as recommended by hardware team. If the timeout is
      beyond 1ms (which will hit for any value we choose if MMIO READ on a
      DSI specific register is performed without PLL ON), it causes the
      system hang. But if the timeout value is lower than it will be below
      the threshold (even if timeout happens) and system will not get into
      a hung state. This will avoid a system hang without losing any
      programming or GT interrupts, taking the worst case of lowest CDCLK
      frequency and early DC5 abort into account.
      Signed-off-by: default avatarUma Shankar <uma.shankar@intel.com>
      Reviewed-by: default avatarJon Bloomfield <jon.bloomfield@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ebd6ded1
    • Jon Bloomfield's avatar
      drm/i915/cmdparser: Ignore Length operands during command matching · bd671d06
      Jon Bloomfield authored
      commit 926abff2 upstream.
      
      Some of the gen instruction macros (e.g. MI_DISPLAY_FLIP) have the
      length directly encoded in them. Since these are used directly in
      the tables, the Length becomes part of the comparison used for
      matching during parsing. Thus, if the cmd being parsed has a
      different length to that in the table, it is not matched and the
      cmd is accepted via the default variable length path.
      
      Fix by masking out everything except the Opcode in the cmd tables
      
      Cc: Tony Luck <tony.luck@intel.com>
      Cc: Dave Airlie <airlied@redhat.com>
      Cc: Takashi Iwai <tiwai@suse.de>
      Cc: Tyler Hicks <tyhicks@canonical.com>
      Signed-off-by: default avatarJon Bloomfield <jon.bloomfield@intel.com>
      Reviewed-by: default avatarChris Wilson <chris.p.wilson@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bd671d06
    • Jon Bloomfield's avatar
      drm/i915/cmdparser: Add support for backward jumps · a7a1a3e3
      Jon Bloomfield authored
      commit f8c08d8f upstream.
      
      To keep things manageable, the pre-gen9 cmdparser does not
      attempt to track any form of nested BB_START's. This did not
      prevent usermode from using nested starts, or even chained
      batches because the cmdparser is not strictly enforced pre gen9.
      
      Instead, the existence of a nested BB_START would cause the batch
      to be emitted in insecure mode, and any privileged capabilities
      would not be available.
      
      For Gen9, the cmdparser becomes mandatory (for BCS at least), and
      so not providing any form of nested BB_START support becomes
      overly restrictive. Any such batch will simply not run.
      
      We make heavy use of backward jumps in igt, and it is much easier
      to add support for this restricted subset of nested jumps, than to
      rewrite the whole of our test suite to avoid them.
      
      Add the required logic to support limited backward jumps, to
      instructions that have already been validated by the parser.
      
      Note that it's not sufficient to simply approve any BB_START
      that jumps backwards in the buffer because this would allow an
      attacker to embed a rogue instruction sequence within the
      operand words of a harmless instruction (say LRI) and jump to
      that.
      
      We introduce a bit array to track every instr offset successfully
      validated, and test the target of BB_START against this. If the
      target offset hits, it is re-written to the same offset in the
      shadow buffer and the BB_START cmd is allowed.
      
      Note: This patch deliberately ignores checkpatch issues in the
      cmdtables, in order to match the style of the surrounding code.
      We'll correct the entire file in one go in a later patch.
      
      v2: set dispatch secure late (Mika)
      v3: rebase (Mika)
      v4: Clear whitelist on each parse
      Minor review updates (Chris)
      v5: Correct backward jump batching
      v6: fix compilation error due to struct eb shuffle (Mika)
      
      Cc: Tony Luck <tony.luck@intel.com>
      Cc: Dave Airlie <airlied@redhat.com>
      Cc: Takashi Iwai <tiwai@suse.de>
      Cc: Tyler Hicks <tyhicks@canonical.com>
      Signed-off-by: default avatarJon Bloomfield <jon.bloomfield@intel.com>
      Signed-off-by: default avatarMika Kuoppala <mika.kuoppala@linux.intel.com>
      Reviewed-by: default avatarChris Wilson <chris.p.wilson@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a7a1a3e3
    • Jon Bloomfield's avatar
      drm/i915/cmdparser: Use explicit goto for error paths · 81848cc9
      Jon Bloomfield authored
      commit 0546a29c upstream.
      
      In the next patch we will be adding a second valid
      termination condition which will require a small
      amount of refactoring to share logic with the BB_END
      case.
      
      Refactor all error conditions to jump to a dedicated
      exit path, with 'break' reserved only for a successful
      parse.
      Signed-off-by: default avatarJon Bloomfield <jon.bloomfield@intel.com>
      Cc: Tony Luck <tony.luck@intel.com>
      Cc: Dave Airlie <airlied@redhat.com>
      Cc: Takashi Iwai <tiwai@suse.de>
      Cc: Tyler Hicks <tyhicks@canonical.com>
      Signed-off-by: default avatarMika Kuoppala <mika.kuoppala@linux.intel.com>
      Reviewed-by: default avatarChris Wilson <chris.p.wilson@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      81848cc9
    • Jon Bloomfield's avatar
      drm/i915: Add gen9 BCS cmdparsing · a6ba2df1
      Jon Bloomfield authored
      commit 0f2f3975 upstream.
      
      For gen9 we enable cmdparsing on the BCS ring, specifically
      to catch inadvertent accesses to sensitive registers
      
      Unlike gen7/hsw, we use the parser only to block certain
      registers. We can rely on h/w to block restricted commands,
      so the command tables only provide enough info to allow the
      parser to delineate each command, and identify commands that
      access registers.
      
      Note: This patch deliberately ignores checkpatch issues in
      favour of matching the style of the surrounding code. We'll
      correct the entire file in one go in a later patch.
      
      v3: rebase (Mika)
      v4: Add RING_TIMESTAMP registers to whitelist (Jon)
      Signed-off-by: default avatarJon Bloomfield <jon.bloomfield@intel.com>
      Cc: Tony Luck <tony.luck@intel.com>
      Cc: Dave Airlie <airlied@redhat.com>
      Cc: Takashi Iwai <tiwai@suse.de>
      Cc: Tyler Hicks <tyhicks@canonical.com>
      Signed-off-by: default avatarMika Kuoppala <mika.kuoppala@linux.intel.com>
      Reviewed-by: default avatarChris Wilson <chris.p.wilson@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a6ba2df1
    • Jon Bloomfield's avatar
      drm/i915: Allow parsing of unsized batches · 05e5cf18
      Jon Bloomfield authored
      commit 435e8fc0 upstream.
      
      In "drm/i915: Add support for mandatory cmdparsing" we introduced the
      concept of mandatory parsing. This allows the cmdparser to be invoked
      even when user passes batch_len=0 to the execbuf ioctl's.
      
      However, the cmdparser needs to know the extents of the buffer being
      scanned. Refactor the code to ensure the cmdparser uses the actual
      object size, instead of the incoming length, if user passes 0.
      Signed-off-by: default avatarJon Bloomfield <jon.bloomfield@intel.com>
      Cc: Tony Luck <tony.luck@intel.com>
      Cc: Dave Airlie <airlied@redhat.com>
      Cc: Takashi Iwai <tiwai@suse.de>
      Cc: Tyler Hicks <tyhicks@canonical.com>
      Reviewed-by: default avatarChris Wilson <chris.p.wilson@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      05e5cf18
    • Jon Bloomfield's avatar
      drm/i915: Support ro ppgtt mapped cmdparser shadow buffers · 9f5fb6f2
      Jon Bloomfield authored
      commit 4f7af194 upstream.
      
      For Gen7, the original cmdparser motive was to permit limited
      use of register read/write instructions in unprivileged BB's.
      This worked by copying the user supplied bb to a kmd owned
      bb, and running it in secure mode, from the ggtt, only if
      the scanner finds no unsafe commands or registers.
      
      For Gen8+ we can't use this same technique because running bb's
      from the ggtt also disables access to ppgtt space. But we also
      do not actually require 'secure' execution since we are only
      trying to reduce the available command/register set. Instead we
      will copy the user buffer to a kmd owned read-only bb in ppgtt,
      and run in the usual non-secure mode.
      
      Note that ro pages are only supported by ppgtt (not ggtt), but
      luckily that's exactly what we need.
      
      Add the required paths to map the shadow buffer to ppgtt ro for Gen8+
      
      v2: IS_GEN7/IS_GEN (Mika)
      v3: rebase
      v4: rebase
      v5: rebase
      Signed-off-by: default avatarJon Bloomfield <jon.bloomfield@intel.com>
      Cc: Tony Luck <tony.luck@intel.com>
      Cc: Dave Airlie <airlied@redhat.com>
      Cc: Takashi Iwai <tiwai@suse.de>
      Cc: Tyler Hicks <tyhicks@canonical.com>
      Signed-off-by: default avatarMika Kuoppala <mika.kuoppala@linux.intel.com>
      Reviewed-by: default avatarChris Wilson <chris.p.wilson@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9f5fb6f2
    • Jon Bloomfield's avatar
      drm/i915: Add support for mandatory cmdparsing · 943ccd0c
      Jon Bloomfield authored
      commit 311a50e7 upstream.
      
      The existing cmdparser for gen7 can be bypassed by specifying
      batch_len=0 in the execbuf call. This is safe because bypassing
      simply reduces the cmd-set available.
      
      In a later patch we will introduce cmdparsing for gen9, as a
      security measure, which must be strictly enforced since without
      it we are vulnerable to DoS attacks.
      
      Introduce the concept of 'required' cmd parsing that cannot be
      bypassed by submitting zero-length bb's.
      
      v2: rebase (Mika)
      v2: rebase (Mika)
      v3: fix conflict on engine flags (Mika)
      Signed-off-by: default avatarJon Bloomfield <jon.bloomfield@intel.com>
      Cc: Tony Luck <tony.luck@intel.com>
      Cc: Dave Airlie <airlied@redhat.com>
      Cc: Takashi Iwai <tiwai@suse.de>
      Cc: Tyler Hicks <tyhicks@canonical.com>
      Signed-off-by: default avatarMika Kuoppala <mika.kuoppala@linux.intel.com>
      Reviewed-by: default avatarChris Wilson <chris.p.wilson@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      943ccd0c
    • Jon Bloomfield's avatar
      drm/i915: Remove Master tables from cmdparser · 44f0f8d4
      Jon Bloomfield authored
      commit 66d8aba1 upstream.
      
      The previous patch has killed support for secure batches
      on gen6+, and hence the cmdparsers master tables are
      now dead code. Remove them.
      Signed-off-by: default avatarJon Bloomfield <jon.bloomfield@intel.com>
      Cc: Tony Luck <tony.luck@intel.com>
      Cc: Dave Airlie <airlied@redhat.com>
      Cc: Takashi Iwai <tiwai@suse.de>
      Cc: Tyler Hicks <tyhicks@canonical.com>
      Signed-off-by: default avatarMika Kuoppala <mika.kuoppala@linux.intel.com>
      Reviewed-by: default avatarChris Wilson <chris.p.wilson@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      44f0f8d4