1. 13 Feb, 2023 4 commits
    • Nathan Lynch's avatar
      powerpc/rtas: handle extended delays safely in early boot · 09d1ea72
      Nathan Lynch authored
      Some code that runs early in boot calls RTAS functions that can return
      -2 or 990x statuses, which mean the caller should retry. An example is
      pSeries_cmo_feature_init(), which invokes ibm,get-system-parameter but
      treats these benign statuses as errors instead of retrying.
      
      pSeries_cmo_feature_init() and similar code should be made to retry
      until they succeed or receive a real error, using the usual pattern:
      
      	do {
      		rc = rtas_call(token, etc...);
      	} while (rtas_busy_delay(rc));
      
      But rtas_busy_delay() will perform a timed sleep on any 990x
      status. This isn't safe so early in boot, before the CPU scheduler and
      timer subsystem have initialized.
      
      The -2 RTAS status is much more likely to occur during single-threaded
      boot than 990x in practice, at least on PowerVM. This is because -2
      usually means that RTAS made progress but exhausted its self-imposed
      timeslice, while 990x is associated with concurrent requests from the
      OS causing internal contention. Regardless, according to the language
      in PAPR, the OS should be prepared to handle either type of status at
      any time.
      
      Add a fallback path to rtas_busy_delay() to handle this as safely as
      possible, performing a small delay on 990x. Include a counter to
      detect retry loops that aren't making progress and bail out. Add __ref
      to rtas_busy_delay() since it now conditionally calls an __init
      function.
      
      This was found by inspection and I'm not aware of any real
      failures. However, the implementation of rtas_busy_delay() before
      commit 38f7b706 ("powerpc/rtas: rtas_busy_delay() improvements")
      was not susceptible to this problem, so let's treat this as a
      regression.
      Signed-off-by: default avatarNathan Lynch <nathanl@linux.ibm.com>
      Fixes: 38f7b706 ("powerpc/rtas: rtas_busy_delay() improvements")
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/20230125-b4-powerpc-rtas-queue-v3-1-26929c8cce78@linux.ibm.com
      09d1ea72
    • Russell Currey's avatar
      integrity/powerpc: Support loading keys from PLPKS · 4b3e71e9
      Russell Currey authored
      Add support for loading keys from the PLPKS on pseries machines, with the
      "ibm,plpks-sb-v1" format.
      
      The object format is expected to be the same, so there shouldn't be any
      functional differences between objects retrieved on powernv or pseries.
      
      Unlike on powernv, on pseries the format string isn't contained in the
      device tree. Use secvar_ops->format() to fetch the format string in a
      generic manner, rather than searching the device tree ourselves.
      
      (The current code searches the device tree for a node compatible with
      "ibm,edk2-compat-v1". This patch switches to calling secvar_ops->format(),
      which in the case of OPAL/powernv means opal_secvar_format(), which
      searches the device tree for a node compatible with "ibm,secvar-backend"
      and checks its "format" property. These are equivalent, as skiboot creates
      a node with both "ibm,edk2-compat-v1" and "ibm,secvar-backend" as
      compatible strings.)
      Signed-off-by: default avatarRussell Currey <ruscur@russell.cc>
      Signed-off-by: default avatarAndrew Donnellan <ajd@linux.ibm.com>
      Reviewed-by: default avatarStefan Berger <stefanb@linux.ibm.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/20230210080401.345462-27-ajd@linux.ibm.com
      4b3e71e9
    • Russell Currey's avatar
      integrity/powerpc: Improve error handling & reporting when loading certs · 3c8069b0
      Russell Currey authored
      A few improvements to load_powerpc.c:
      
       - include integrity.h for the pr_fmt()
       - move all error reporting out of get_cert_list()
       - use ERR_PTR() to better preserve error detail
       - don't use pr_err() for missing keys
      Reviewed-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      Signed-off-by: default avatarRussell Currey <ruscur@russell.cc>
      Signed-off-by: default avatarAndrew Donnellan <ajd@linux.ibm.com>
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/20230210080401.345462-26-ajd@linux.ibm.com
      3c8069b0
    • Russell Currey's avatar
      powerpc/pseries: Implement secvars for dynamic secure boot · ccadf154
      Russell Currey authored
      The pseries platform can support dynamic secure boot (i.e. secure boot
      using user-defined keys) using variables contained with the PowerVM LPAR
      Platform KeyStore (PLPKS).  Using the powerpc secvar API, expose the
      relevant variables for pseries dynamic secure boot through the existing
      secvar filesystem layout.
      
      The relevant variables for dynamic secure boot are signed in the
      keystore, and can only be modified using the H_PKS_SIGNED_UPDATE hcall.
      Object labels in the keystore are encoded using ucs2 format.  With our
      fixed variable names we don't have to care about encoding outside of the
      necessary byte padding.
      
      When a user writes to a variable, the first 8 bytes of data must contain
      the signed update flags as defined by the hypervisor.
      
      When a user reads a variable, the first 4 bytes of data contain the
      policies defined for the object.
      
      Limitations exist due to the underlying implementation of sysfs binary
      attributes, as is the case for the OPAL secvar implementation -
      partial writes are unsupported and writes cannot be larger than PAGE_SIZE.
      (Even when using bin_attributes, which can be larger than a single page,
      sysfs only gives us one page's worth of write buffer at a time, and the
      hypervisor does not expose an interface for partial writes.)
      Co-developed-by: default avatarNayna Jain <nayna@linux.ibm.com>
      Signed-off-by: default avatarNayna Jain <nayna@linux.ibm.com>
      Co-developed-by: default avatarAndrew Donnellan <ajd@linux.ibm.com>
      Signed-off-by: default avatarAndrew Donnellan <ajd@linux.ibm.com>
      Signed-off-by: default avatarRussell Currey <ruscur@russell.cc>
      [mpe: Add NLS dependency to fix build errors, squash fix from ajd]
      Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/20230210080401.345462-25-ajd@linux.ibm.com
      ccadf154
  2. 12 Feb, 2023 27 commits
  3. 10 Feb, 2023 9 commits