From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 56BBE220F3C2F for ; Fri, 24 Nov 2017 01:37:44 -0800 (PST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Nov 2017 01:42:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,446,1505804400"; d="scan'208";a="8961509" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by orsmga001.jf.intel.com with ESMTP; 24 Nov 2017 01:42:02 -0800 Received: from fmsmsx113.amr.corp.intel.com (10.18.116.7) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 24 Nov 2017 01:42:02 -0800 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by FMSMSX113.amr.corp.intel.com (10.18.116.7) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 24 Nov 2017 01:42:01 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.175]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.93]) with mapi id 14.03.0319.002; Fri, 24 Nov 2017 17:41:59 +0800 From: "Zeng, Star" To: Heyi Guo , "edk2-devel@lists.01.org" CC: "Carsey, Jaben" , Daryl McDaniel , "Zeng, Star" , "Gao, Liming" Thread-Topic: [edk2] [RFC] Add EFI lock when creating new gauge record Thread-Index: AQHTZPKS3btxLQBCf0CN2pHam8+LLqMjQrQA Date: Fri, 24 Nov 2017 09:41:59 +0000 Message-ID: <0C09AFA07DD0434D9E2A0C6AEB0483103B9BBCD9@shsmsx102.ccr.corp.intel.com> References: <6c7964be-bc2b-3ee4-e09e-c309fec7210f@linaro.org> In-Reply-To: <6c7964be-bc2b-3ee4-e09e-c309fec7210f@linaro.org> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [RFC] Add EFI lock when creating new gauge record X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Nov 2017 09:37:45 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Good problem statement. EndGaugeEx and GetGaugeEx also need to be updated as they are operating sam= e memory buffer, otherwise the performance data may be messed up. Another idea is to just use a global variable, for example mRecording, to p= revent reentrance, but that there may be perf data missing. How to realize " not impacted much " in " the performance measuring data wa= s not impacted much by this patch "? That means there is a little performance impact? Could you re-measure with all StartGaugeEx, EndGaugeEx and GetGaugeEx add l= ock? Cc Liming. Thanks, Star -----Original Message----- From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Heyi= Guo Sent: Friday, November 24, 2017 3:04 PM To: edk2-devel@lists.01.org Cc: Carsey, Jaben ; Daryl McDaniel Subject: [edk2] [RFC] Add EFI lock when creating new gauge record Hi folks, We got occasional system exceptions after enabling performance measuring fe= ature in edk2. After debugging, we found there is potential memory overflow= in DXE/DXE_CORE PerformanceLib when PERF_START is reentered, and reentranc= e is possible since we are supporting something like USB hot-plug, which is= a timer event where gBS->ConnectController might be called and then PERF w= ill be called in CoreConnectSingleController.=20 However I can't reproduce the issue right now; please let me know if PERF r= eentrance is not theoretically possible in the latest edk2 code. When StartGaugeEx is being reentered, not only the gauge record might be ov= erwritten, more serious situation will be caused if gauge data buffer reall= ocation procedure is interrupted, between line 180 and 187 in DxeCorePerfor= manceLib.c specifically. There, mMaxGaugeRecords will be doubled twice (den= oted as 4X), but mGaugeData only points to a buffer of size 2X, which will = probably cause the following 2X memory to be overflowed when gauge records = are increased. My proposal is to add EFI lock with TPL notify in StartGaugeEx to avoid suc= h situation. The test result seemed good on our platforms and the performan= ce measuring data was not impacted much by this patch. Please let me know your comments. Thanks, Gary (Heyi Guo) _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel