Author: mmel
Date: Mon Dec 14 11:57:43 2020
New Revision: 368633
URL: https://svnweb.freebsd.org/changeset/base/368633

Log:
  Verify (and fix) the context_id argument passed to the mpentry () by PSCI.
  
  Some older PSCI implementations corrupt (or do not pass) the context_id
  argument to newly started secondary cores. Although the ideal solution to this
  problem is u-boot update, we can find the correct value for the argument 
(cpuid)
  by comparing of real core mpidr register with the value stored in pcu->mpidr.
  
  MFC after:    2 weeks

Modified:
  head/sys/arm64/arm64/mp_machdep.c

Modified: head/sys/arm64/arm64/mp_machdep.c
==============================================================================
--- head/sys/arm64/arm64/mp_machdep.c   Mon Dec 14 11:56:16 2020        
(r368632)
+++ head/sys/arm64/arm64/mp_machdep.c   Mon Dec 14 11:57:43 2020        
(r368633)
@@ -206,6 +206,21 @@ init_secondary(uint64_t cpu)
 {
        struct pcpu *pcpup;
        pmap_t pmap0;
+       u_int mpidr;
+
+       /*
+        * Verify that the value passed in 'cpu' argument (aka context_id) is
+        * valid. Some older U-Boot based PSCI implementations are buggy,
+        * they can pass random value in it.
+        */
+       mpidr = READ_SPECIALREG(mpidr_el1) & CPU_AFF_MASK;
+       if  (cpu >= MAXCPU || __pcpu[cpu].pc_mpidr != mpidr) {
+               for (cpu = 0; cpu < mp_maxid; cpu++)
+                       if (__pcpu[cpu].pc_mpidr == mpidr)
+                               break;
+               if ( cpu >= MAXCPU)
+                       panic("MPIDR for this CPU is not in pcpu table");
+       }
 
        pcpup = &__pcpu[cpu];
        /*
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to