From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web11.600.1577086711145639272 for ; Sun, 22 Dec 2019 23:38:31 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.31, mailfrom: ray.ni@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Dec 2019 23:38:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,346,1571727600"; d="scan'208";a="207184488" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by orsmga007.jf.intel.com with ESMTP; 22 Dec 2019 23:38:30 -0800 Received: from FMSMSX109.amr.corp.intel.com (10.18.116.9) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.439.0; Sun, 22 Dec 2019 23:38:30 -0800 Received: from shsmsx106.ccr.corp.intel.com (10.239.4.159) by fmsmsx109.amr.corp.intel.com (10.18.116.9) with Microsoft SMTP Server (TLS) id 14.3.439.0; Sun, 22 Dec 2019 23:38:30 -0800 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.90]) by SHSMSX106.ccr.corp.intel.com ([169.254.10.236]) with mapi id 14.03.0439.000; Mon, 23 Dec 2019 15:38:28 +0800 From: "Ni, Ray" To: "devel@edk2.groups.io" , "Dong, Eric" CC: Laszlo Ersek Subject: Re: [edk2-devel] [PATCH v2 1/2] UefiCpuPkg/PiSmmCpuDxeSmm: Remove dependence between APs Thread-Topic: [edk2-devel] [PATCH v2 1/2] UefiCpuPkg/PiSmmCpuDxeSmm: Remove dependence between APs Thread-Index: AQHVuVz0JLgSVfRhGkKbSI5iGEufJ6fHUE1g Date: Mon, 23 Dec 2019 07:38:28 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5C3A8DBD@SHSMSX104.ccr.corp.intel.com> References: <20191223064806.682-1-eric.dong@intel.com> <20191223064806.682-2-eric.dong@intel.com> In-Reply-To: <20191223064806.682-2-eric.dong@intel.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Return-Path: ray.ni@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable >=20 > + WaitForSemaphore (&Token->RunningApCount);=20 > +=20 > + if (Token->RunningApCount =3D=3D 0) { > + ReleaseSpinLock (Token->SpinLock);=20 > } 1. if (InterlockedDecrement (&Token->RunningApCount) =3D=3D 0) { ReleaseSpinLock (Token->SpinLock); } We should avoid checking RunningApCount directly because it's possible that AP#1 decrease the Count to 1 and before AP#1 checks the value against = 0 the Count is decreased by AP#2 to 0. So that causes AP#1 and AP#2 call ReleaseSpinLock() on the same SpinLock. >=20 > + // Decrease the count to mark this AP as finished. 2. BSP is also handled here. So this comment is mis-leading. >=20 > + // >=20 > + if (Token !=3D NULL) {=20 > + WaitForSemaphore (&ProcToken->RunningApCount); 3. The code is written correctly but improperly IMO. Token is checked but ProcToken is deferenced. I suggest you check ProcToken directly.