From owner-svn-src-all@freebsd.org Mon Dec 14 11:57:44 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 373B44B763E; Mon, 14 Dec 2020 11:57:44 +0000 (UTC) (envelope-from mmel@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Cvfyw15DXz4msH; Mon, 14 Dec 2020 11:57:44 +0000 (UTC) (envelope-from mmel@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 182A421537; Mon, 14 Dec 2020 11:57:44 +0000 (UTC) (envelope-from mmel@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0BEBvhHg069472; Mon, 14 Dec 2020 11:57:43 GMT (envelope-from mmel@FreeBSD.org) Received: (from mmel@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0BEBvhI9069471; Mon, 14 Dec 2020 11:57:43 GMT (envelope-from mmel@FreeBSD.org) Message-Id: <202012141157.0BEBvhI9069471@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mmel set sender to mmel@FreeBSD.org using -f From: Michal Meloun Date: Mon, 14 Dec 2020 11:57:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r368633 - head/sys/arm64/arm64 X-SVN-Group: head X-SVN-Commit-Author: mmel X-SVN-Commit-Paths: head/sys/arm64/arm64 X-SVN-Commit-Revision: 368633 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Dec 2020 11:57:44 -0000 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]; /*