From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4001:c0b::22f; helo=mail-it0-x22f.google.com; envelope-from=heyi.guo@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-it0-x22f.google.com (mail-it0-x22f.google.com [IPv6:2607:f8b0:4001:c0b::22f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3679B220F3C29 for ; Thu, 23 Nov 2017 23:00:04 -0800 (PST) Received: by mail-it0-x22f.google.com with SMTP id 72so726429itl.5 for ; Thu, 23 Nov 2017 23:04:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=to:cc:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding:content-language; bh=WfZb5U7P3gmtYqmWyXWHeoMmy9C9qzuBKwEW7CwU7oQ=; b=FWJhoAdKJT0Xp5tPZK/lgbKfLPYQk2E790Upy22wtLtoqFpvcGLQGJax1tyib0dcgr O2XFfUKsH8INB3D0s0yvnP9AG1NulBnUXax8PO31lcCmhd9CTGCrIcvdU0ZhOiebLBov R2+D2LiX3kQPKqpOzn69lXtqCRwY5RFPvG0wY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding:content-language; bh=WfZb5U7P3gmtYqmWyXWHeoMmy9C9qzuBKwEW7CwU7oQ=; b=BCoij9hUPPMJnk+cF3AqI8uEJKVpfocx8ZQpNCsM/Qt35Sx9iPxD7c9vglwuY0Akap zWV9iOC+V+zSKg2icXQxB6rKvop6aDH17uvLTwvhS7Gl7kq9z9BYMgn1N0qiN3X81x0t ipeBKmqm8NCK06S7mfwwNCKfJQx2ILKgb2PhU9eRlBGIko4BuGtRMnhVf57cJkWku+cY JHPDdieq78rXc3OmviTNqWNxGLNUj1BVQSw25uVW+UdURBiIaDYOmcpe1yBmvNw/TBTV 4HV50zOIvlNxiB8sqmydtBK8qgK3/6MVxjPxFKgrWbvlajtQ07MqwFH57/ZeuNHP1YzZ aZcA== X-Gm-Message-State: AJaThX4ogkBMbdg/SHiZEdvN+dcu87StEeexrtae3G11KBK7BIgZSdB8 zXSBe3v77ubNQXpFGrj5a78dQw== X-Google-Smtp-Source: AGs4zMbIrsdcbKQ6+bi//ze/DG+ps5xU7ZKdq2jWkkv1TbOFm18cRQoRlVG3dK8IDIncL6OmNzTQKg== X-Received: by 10.36.158.135 with SMTP id p129mr8497282itd.64.1511507062493; Thu, 23 Nov 2017 23:04:22 -0800 (PST) Received: from [10.68.84.10] ([45.56.152.167]) by smtp.gmail.com with ESMTPSA id w6sm4148670itc.43.2017.11.23.23.04.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Nov 2017 23:04:21 -0800 (PST) To: "edk2-devel@lists.01.org" Cc: Daryl McDaniel , Jaben Carsey From: Heyi Guo Message-ID: <6c7964be-bc2b-3ee4-e09e-c309fec7210f@linaro.org> Date: Fri, 24 Nov 2017 15:04:18 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 Subject: [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 07:00:05 -0000 Content-Type: text/plain; charset=gbk; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Hi folks, We got occasional system exceptions after enabling performance measuring feature in edk2. After debugging, we found there is potential memory overflow in DXE/DXE_CORE PerformanceLib when PERF_START is reentered, and reentrance 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 will be called in CoreConnectSingleController. However I can't reproduce the issue right now; please let me know if PERF reentrance is not theoretically possible in the latest edk2 code. When StartGaugeEx is being reentered, not only the gauge record might be overwritten, more serious situation will be caused if gauge data buffer reallocation procedure is interrupted, between line 180 and 187 in DxeCorePerformanceLib.c specifically. There, mMaxGaugeRecords will be doubled twice (denoted 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 such situation. The test result seemed good on our platforms and the performance measuring data was not impacted much by this patch. Please let me know your comments. Thanks, Gary (Heyi Guo)