[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] x86/ucode: Fix error paths control_thread_fn()


  • To: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Fri, 24 Mar 2023 21:44:30 +0000
  • Authentication-results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Jan Beulich <JBeulich@xxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Sergey Dyasli <sergey.dyasli@xxxxxxxxxx>
  • Delivery-date: Fri, 24 Mar 2023 21:45:02 +0000
  • Ironport-data: A9a23:7ZVrhq/KfH1qMY4GJjuTDrUD/H6TJUtcMsCJ2f8bNWPcYEJGY0x3m mtLC2nQaKqDZTT8eY0nOdm19k5U7MDcmtVqT1E6pHg8E34SpcT7XtnIdU2Y0wF+jCHgZBk+s 5hBMImowOQcFCK0SsKFa+C5xZVE/fjUAOG6UKicYXoZqTZMEE8JkQhkl/MynrlmiN24BxLlk d7pqojUNUTNNwRcawr40Ire7kI/1BjOkGlA5AdmPqoX5AW2e0Q9V/rzG4ngdxMUfaEMdgKKb 76r5K20+Grf4yAsBruN+losWhRXKlJ6FVHmZkt+A8BOsDAbzsAB+v9T2M4nQVVWk120c+VZk 72hg3ASpTABZcUgkMxFO/VR/roX0aduoNcrKlDn2SCfItGvn9IBDJyCAWlvVbD09NqbDklL2 a1BCAopZSy8gvm44qiKeMV0huAKeZyD0IM34hmMzBncBPciB5vCX7/L9ZlT2zJYasJmRKiEI ZBDMHw2MUqGOkcUUrsUIMtWcOOAr3/zaTBH7nmSorI6+TP7xw1tyrn9dtHSf7RmQO0MxhzB9 jOXrz2R7hcyDv2DyT+50i2QherrvHriQtMVRZLn6as/6LGU7jNKU0BHPbehmtGph0j7V99BJ kg8/is1sbN05EGtVsP6XRCzvDiDpBF0c/h6HvA+6QqN4rHJ+AvfDW8BJhZebPQ2uclwQiYlv mJlhPuwW2Yp6ufMDyvAqPHN92ja1TUpwXEqYANVFCs/x9Lfn4QogDDVf+RPCK6Rp4igcd3v+ AxmvBTSlp1K05Faifvmpwuf696/jsOXF1Bov207Skrgt1okP9D9OuRE/HCBtZ59wJClok5tV ZTus+yX96gwAJ6Ej0Rhq81dTejyt55p3NAx6GOD/qXNFBz3oRZPhagKvFlDyL5Ba67ogwPBb k7Joh9275ROJnasZqIfS9vvVJV0nfO4TIW+D628gj9yjn9ZKme6ENxGPxbMjwgBbmB1+U3AB XtrWZn1VitLYUiW5DG3W/0cwdcW+8zK/kuKHcqT503+gdKjiIu9Fe9t3K2mMrpos8tpYWz9r 75iCid940oBC7KkMnGOq+b+7zkidBAGOHw/kOQPHsbrH+asMD1xYxMN6dvNo7BYopk=
  • Ironport-hdrordr: A9a23:j5ehD64e89Enr83QPwPXwA/XdLJyesId70hD6qhwISYlFPBw9v rPoB1/73TJYVkqOU3I9erwXZVoIkmsjKKdg7NhRYtKNTOO0ATHEGgL1/qY/9SKIVybygcy79 YGT4FOTPDLIBxdq+2S2mWF+tAbquWvweSTqd2b5VFLYiFFV5pJ0ideLUKgPnAefngkObMJUJ Wd48ZcpymtYx0sA/iTDGUeQu7Gq8bqufvdEHw7OyI=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

These two early exits skipped re-enabling the watchdog, and restoring the NMI
callback.  Always execute the tail of the function on the way out.

Fixes: 8dd4dfa92d62 ("x86/microcode: Synchronize late microcode loading")
Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: Jan Beulich <JBeulich@xxxxxxxx>
CC: Roger Pau Monné <roger.pau@xxxxxxxxxx>
CC: Wei Liu <wl@xxxxxxx>
CC: Sergey Dyasli <sergey.dyasli@xxxxxxxxxx>

Also, added in the same patch is:

   * Note that RDTSC (in wait_for_condition()) is safe for threads to
   * execute while waiting for completion of loading an update.

which is absolutely not true in the slightest.  RDTSC is all microcode, and
Intel's guidance on the matter right now is that LFENCE is about the only safe
instruction to execute in a wait loop.  Even PAUSE is explcitily prohibited...
---
 xen/arch/x86/cpu/microcode/core.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/xen/arch/x86/cpu/microcode/core.c 
b/xen/arch/x86/cpu/microcode/core.c
index cfa2d5053a52..61cd36d601d6 100644
--- a/xen/arch/x86/cpu/microcode/core.c
+++ b/xen/arch/x86/cpu/microcode/core.c
@@ -492,10 +492,7 @@ static int control_thread_fn(const struct microcode_patch 
*patch)
     ret = wait_for_condition(wait_cpu_callin, num_online_cpus(),
                              MICROCODE_CALLIN_TIMEOUT_US);
     if ( ret )
-    {
-        set_state(LOADING_EXIT);
-        return ret;
-    }
+        goto out;
 
     /* Control thread loads ucode first while others are in NMI handler. */
     ret = alternative_call(ucode_ops.apply_microcode, patch);
@@ -507,8 +504,7 @@ static int control_thread_fn(const struct microcode_patch 
*patch)
     {
         printk(XENLOG_ERR
                "Late loading aborted: CPU%u failed to update ucode\n", cpu);
-        set_state(LOADING_EXIT);
-        return ret;
+        goto out;
     }
 
     /* Let primary threads load the given ucode update */
@@ -539,6 +535,7 @@ static int control_thread_fn(const struct microcode_patch 
*patch)
         }
     }
 
+ out:
     /* Mark loading is done to unblock other threads */
     set_state(LOADING_EXIT);
 
-- 
2.30.2




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.