From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 1C882AC0F1C for ; Wed, 23 Aug 2023 16:10:22 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=pM/8vb6rgpTW1sYw22kSlQVyy3a3ya0hibcdSK4ogIA=; c=relaxed/simple; d=groups.io; h=Subject:To:From:User-Agent:MIME-Version:Date:Message-ID:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type; s=20140610; t=1692807021; v=1; b=RFpTOy+ekh6zgyEtJjuZ/J0CmcVKjQbk3LRVUVafHwALhYae+P7MOzIRyQ97OA7tEXV1SMMT Eg7AoqXdXTgYqdwKTHQYRbrYrUO5s607yS0QHhTwgL9E/eQuuEpdPY1gxJHsNd2ma+4Y0OTwgzD FY+VV1YRIEGXS9sQLnzgEdj8= X-Received: by 127.0.0.2 with SMTP id 48yiYY7687511x3BjnVU7pId; Wed, 23 Aug 2023 09:10:21 -0700 Subject: [edk2-devel] BUG:T imer callback in UEFI application is hanging only in AMI BIOS #bad_mem To: devel@edk2.groups.io From: sasha110397@gmail.com X-Originating-Location: Moscow, RU (91.199.251.7) X-Originating-Platform: Linux Firefox 116 User-Agent: GROUPS.IO Web Poster MIME-Version: 1.0 Date: Wed, 23 Aug 2023 08:29:50 -0700 Message-ID: Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,sasha110397@gmail.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: kWZzzgMHw3yltgDfdmEzezvLx7686176AA= Content-Type: multipart/alternative; boundary="AZ3oEbzdOPFeZq1SUy24" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=RFpTOy+e; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io --AZ3oEbzdOPFeZq1SUy24 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable While porting UEFI application from AARCH64 to X64 i ran into following pro= blem: application was hanging after enabling periodic timer (timer is used = in application for I/O polling). Timer callback finishes and nothing execut= es afterwards. During debugging i tried to find error in code but failed to do so. Now i h= ave very small helloworld example with following properties: * It build in EDK2 according to their instructions (i build on Ubuntu 20 PC= with GCC 9.4.0); * It works perfectly on AARCH64 device; * It works perfectly in X64 QEMU; * It hangs on any actual X64 computer (i tested Gigabyte AM2, MSI LGA1200, = Asus LGA1700 motherboards) Is this example broken or is there a bug in AMI BIOS? Here is the whole source code of crashing application. As you can see, it o= nly tries to overwrite two bytes in static arrays in timer callback, howeve= r application hangs after first execution of callback. Removing any part of= code (using only 1 array, inlining functions) prevents application from ha= nging. What was expected: spam of "Hello World", "timer begin", "timer end"= messages. This is what happens in QEMU and on AARCH64 device. What was rec= eived: few "Hello World" messages, then one iteration of timer callback, af= ter that application hangs. By default EDK2 uses "-Os" optimization which r= equires more complex code to crash, so this functions are explicitly have "= -O0" optimization. Is there a *sever bug in modern AMI BIOS implementations= * or there is something wrong with my code? # include # include # include # include static volatile UINT8 test_buf1[ 200 ]; static volatile UINT8 test_buf2[ 200 ]; void * timer; __attribute((optimize( "O0" ))) void assign ( volatile UINT8* ptr, int ind) { ptr[ind] =3D 10 ; } __attribute((optimize( "O0" ))) void test_func ( void ) { assign(test_buf1, 0 ); assign(test_buf2, 0 ); } __attribute((optimize( "O0" ))) void test_interrupt (EFI_EVENT Event, VOID *Context)=20 { DEBUG ((EFI_D_ERROR, "timer begin\r\n" )); test_func(); DEBUG ((EFI_D_ERROR, "timer end\r\n" )); } EFI_STATUS EFIAPI UefiMain ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; Print( L"Hello World \n" );=20 Status =3D gBS->CreateEvent( EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_CALLBACK, = (EFI_EVENT_NOTIFY)test_interrupt, NULL , &timer); if (EFI_ERROR(Status)) { return -1 ; } Status =3D gBS->SetTimer( timer, TimerPeriodic, EFI_TIMER_PERIOD_MILLISE= CONDS ( 16 )); if (EFI_ERROR(Status)) { return -1 ; } while ( 1 ) Print( L"Hello World \n" );=20 return EFI_SUCCESS; } -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#107983): https://edk2.groups.io/g/devel/message/107983 Mute This Topic: https://groups.io/mt/100917960/7686176 Mute #bad_mem:https://edk2.groups.io/g/devel/mutehashtag/bad_mem Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- --AZ3oEbzdOPFeZq1SUy24 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable

While porting UEFI application from AARCH64 to X64 i ran into following = problem: application was hanging after enabling periodic timer (timer is us= ed in application for I/O polling). Timer callback finishes and nothing exe= cutes afterwards.

During debugging i tried to find error in code but failed to do so. Now = i have very small helloworld example with following properties:

  • It build in EDK2 according to their instructions (i build on Ubuntu 20 = PC with GCC 9.4.0);
  • It works perfectly on AARCH64 device;
  • It works perfectly in X64 QEMU;
  • It hangs on any actual X64 computer (i tested Gigabyte AM2, MSI LGA1200= , Asus LGA1700 motherboards)

Is this example broken or is there a bug in AMI BIOS?

Here is the whole source code of crashing application. As you can see, i= t only tries to overwrite two bytes in static arrays in timer callback, how= ever application hangs after first execution of callback. Removing any part= of code (using only 1 array, inlining functions) prevents application from= hanging. What was expected: spam of "Hello World", "timer begin", "timer e= nd" messages. This is what happens in QEMU and on AARCH64 device. What was = received: few "Hello World" messages, then one iteration of timer callback,= after that application hangs. By default EDK2 uses "-Os" optimization whic= h requires more complex code to crash, so this functions are explicitly hav= e "-O0" optimization. Is there a sever bug in modern AMI BIOS imple= mentations or there is something wrong with my code?


#include <Library/UefiApplicationEntryPoint.h><=
/span>
#include <Library/UefiLib.h>
#include <Library/DebugLib.h>
#include <Library/UefiBootServicesTableLib.h>

static volati=
le UINT8 test_buf1[200];
static volati=
le UINT8 test_buf2[200];
void* timer;

__attribute((optimize("O0")))
void =
assign(vola=
tile UINT8* ptr, int ind)
{
    ptr[ind] =3D 10;
}

__attribute((optimize("O0")))
void =
test_func(void=
)
{
    assign(test_buf1, 0);
    assign(test_buf2, 0);
}

__attribute((optimize("O0")))
void =
test_interrupt(EFI_EVENT Event, VOID *Co=
ntext)=20
{
    DEBUG ((EFI_D_ERROR, "timer begin\r\n"));
  test_func();
    DEBUG ((EFI_D_ERROR, "timer end\r\n"=
));
}

EFI_STATUS
EFIAPI
UefiMain (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  EFI_STATUS  Status;

  Print(L"Hello World \n");=20

  Status =3D gBS->CreateEvent( EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_CALLBA=
CK, (EFI_EVENT_NOTIFY)test_interrupt, NULL, &timer);
    if (EFI_ERROR(Status)) {
        return -1;
    }

    Status =3D gBS->SetTimer( timer, TimerPeriodic, EFI_TIMER_PERIOD_MIL=
LISECONDS (16));
    if (EFI_ERROR(Status)) {
        return -1;
    }

  while(1)
    Print(L"Hello World \n");=20

  return EFI_SUCCESS;
}

_._,_._,_

Groups.io Links:

=20 You receive all messages sent to this group. =20 =20

View/Reply Online (#107983) | =20 | Mute= This Topic | New Topic
=20 =20 =20 Mute #= bad_mem =20 =20
Your Subscriptio= n | Contact Group Owner | Unsubscribe [rebecca@openfw.io]

_._,_._,_
--AZ3oEbzdOPFeZq1SUy24--