From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (EUR05-DB8-obe.outbound.protection.outlook.com [40.107.20.51]) by mx.groups.io with SMTP id smtpd.web10.19967.1684422740734513519 for ; Thu, 18 May 2023 08:12:21 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=lLWpx1zm; spf=pass (domain: arm.com, ip: 40.107.20.51, mailfrom: sami.mujawar@arm.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QrIsD5GbRPGjU0m0KE1BpwAmgXFBxrIQsXiDBg+YQfY=; b=lLWpx1zm3afL9xWd+Mp/qlEdhAleFWDsOMxWubnmAtVOgda/Vp8is3vV/bWVCh9Rz/ezLtd2sHxAsYwqbUN8LgkSRJwS31dAKozhijhj3jzkmmtJL/PPsl5dUT9w51DnULp7vyC+7OS9soDD1JizLl2vRRStHdrT7XrPJktp1rY= Received: from AM4PR05CA0031.eurprd05.prod.outlook.com (2603:10a6:205::44) by AS2PR08MB10227.eurprd08.prod.outlook.com (2603:10a6:20b:647::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.17; Thu, 18 May 2023 15:12:17 +0000 Received: from AM7EUR03FT055.eop-EUR03.prod.protection.outlook.com (2603:10a6:205:0:cafe::68) by AM4PR05CA0031.outlook.office365.com (2603:10a6:205::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.19 via Frontend Transport; Thu, 18 May 2023 15:12:17 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM7EUR03FT055.mail.protection.outlook.com (100.127.141.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.19 via Frontend Transport; Thu, 18 May 2023 15:12:17 +0000 Received: ("Tessian outbound 8b05220b4215:v136"); Thu, 18 May 2023 15:12:17 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: c728dd5182c9a530 X-CR-MTA-TID: 64aa7808 Received: from 70ea7a140beb.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 524DD59D-60F4-4DC5-B0C1-E4380C38B197.1; Thu, 18 May 2023 15:12:05 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 70ea7a140beb.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 18 May 2023 15:12:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GpG/OGH3PrCmJjcvdfFs9GIwhtcO/EHJZOeqNnYxxOOo2uWrDa2YLUbZIe3qkn4HauMto7waC0tHPVjDjBx3L8/rAZ/auaW2rC7gCPU7flhDbkbdSY+tW7RZygLcvJ5MadBeMR/Uy1FhKHVWU2DdcE11gqZgLDYE30orJUgMllg30J6gaWHCFZUjOOJcL0Ogs1b17D6jSGyp7lnrDw40n8gBBk7Ut8W3ZRVS/4Z22HaiC8+qQfSX6xzFJyOj9zoHQ5ldJT1U74OGQ7mVFyYUFooxJ/h0m91dxUMAq4fqeln2GQwDVseOAENKaicSqiKrCKoF70pTxCaHzZ5pba2yGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=QrIsD5GbRPGjU0m0KE1BpwAmgXFBxrIQsXiDBg+YQfY=; b=P1WLzK1rWcgFL3I2v2x9h3gHMaA2QOHmf4pIXYEXBHskZnJkW+YMS7k6WgoE1kPop/GTlPCSIKKo7+ATfazxMF/1jdGIMnaGkWUSl3VtNMPxj9RLqKu3eCFWzYL+hlgmFA+C7U+IdQxUyuiLl+bXXfHswZxLW6o/dbVCsmFZy7oB/eKsVsPBltdW4KzWA6Dfuok87J1BcbKadgjnEhS+P9DBXE2Wc1FvoAfa9jB0thRQkBQ12eyxgo7e5LYz+jcKeA83Nua6SSm2Z0ZM2iqMc44PMoH7WpLq/sQrOKMyIVtK2V94CfawR8QB0hzpQqfLORfXOR5+EXaogye47b1gQg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QrIsD5GbRPGjU0m0KE1BpwAmgXFBxrIQsXiDBg+YQfY=; b=lLWpx1zm3afL9xWd+Mp/qlEdhAleFWDsOMxWubnmAtVOgda/Vp8is3vV/bWVCh9Rz/ezLtd2sHxAsYwqbUN8LgkSRJwS31dAKozhijhj3jzkmmtJL/PPsl5dUT9w51DnULp7vyC+7OS9soDD1JizLl2vRRStHdrT7XrPJktp1rY= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from AS8PR08MB6806.eurprd08.prod.outlook.com (2603:10a6:20b:39b::12) by DU0PR08MB9904.eurprd08.prod.outlook.com (2603:10a6:10:474::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.17; Thu, 18 May 2023 15:12:02 +0000 Received: from AS8PR08MB6806.eurprd08.prod.outlook.com ([fe80::7afd:553d:71b8:4c8c]) by AS8PR08MB6806.eurprd08.prod.outlook.com ([fe80::7afd:553d:71b8:4c8c%6]) with mapi id 15.20.6411.017; Thu, 18 May 2023 15:12:02 +0000 Message-ID: <5401cc95-5c66-54b7-38fb-54a6b4c56e5e@arm.com> Date: Thu, 18 May 2023 16:11:58 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [edk2-devel] [PATCH v1 5/6] ArmVirtPkg: Kvmtool: Increase primary core stack size To: devel@edk2.groups.io, ardb@kernel.org CC: ardb+tianocore@kernel.org, quic_llindhol@quicinc.com, kraxel@redhat.com, Pierre.Gondois@arm.com, jean-philippe@linaro.org, Matteo.Carlini@arm.com, Akanksha.Jain2@arm.com, Ben.Adderson@arm.com, Sibel.Allinson@arm.com, nd@arm.com References: <20230518090935.10984-1-sami.mujawar@arm.com> <20230518090935.10984-6-sami.mujawar@arm.com> From: "Sami Mujawar" In-Reply-To: X-ClientProxiedBy: LO4P123CA0621.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:294::21) To AS8PR08MB6806.eurprd08.prod.outlook.com (2603:10a6:20b:39b::12) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: AS8PR08MB6806:EE_|DU0PR08MB9904:EE_|AM7EUR03FT055:EE_|AS2PR08MB10227:EE_ X-MS-Office365-Filtering-Correlation-Id: 190b68f6-fd64-4b5f-c2dc-08db57b244d8 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: fg6wIL5KJLky3N90fVDI30+JzHUNRHN5lLfwJ9kHB7YnrPuJamt0GVjRxphXweD3ZQ8iO5KbAs1ATk4rwLWXXjnvY8IyteUSkZhwlm/qGWGo9jEwhdkKXiVuT+Cbmc7bsesoEOzZBUlsJdk8i4kS+8ijRrIHGQlQTprxxpSbrPYdqwKxA9yYPjpMUN9lv1xwl1MFB0QPBuZrhl/efkgczPdQ9gTrJio9rVpE1dW5CZs6Q4p/VN2Fnea4IieNeBCmn3Pap7mz7HkYQA/8kt4/gADcB4p5xv14wjSsei3X5TvH2UK8A2PhqtZFEPN8WgjbZEkR0hxmM83p8RFke+vTzKxyL+ttQXU0UFPPWJUsjc9zWHhLVVDYSrM43b98wrKOmM4G6umPj4IfSYkjETAfG28gkaM2PO95EvZCMZd1XTcdQ5lsGqVP9yNJIDtHrdaz+z/5QETX1v6R30SbMbEd+GwAEy0lJXHtNyA5iko0rvKZQ+7yHIoaBI3HyUI60W4/NNPj3reUFflH4FbHbxyepiL7MJNNMlANUafT7KXJEMff+MT41lOqU7gX4gj26+Nv5PO6C0ItYpH/sskHjgiRkxZHaE2yyitQguEzD2KofjRxPybvI9zLEj5U0HMVKf8jQH5pZXLnZGt2v56h0AzzqF5SPwoK0OYJHJZ5/fOeqvE= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR08MB6806.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(376002)(136003)(39860400002)(366004)(346002)(451199021)(31686004)(66899021)(66556008)(316002)(66476007)(4326008)(478600001)(966005)(6486002)(31696002)(86362001)(36756003)(6666004)(83380400001)(6512007)(53546011)(6506007)(26005)(66946007)(2616005)(186003)(44832011)(2906002)(5660300002)(8676002)(8936002)(41300700001)(38100700002)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB9904 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Return-Path: Sami.Mujawar@arm.com X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM7EUR03FT055.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: e24467c8-9df2-4e4d-b865-08db57b23b82 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: As6s2OHmtIy+OtBxnlFqlUXZ8pYppIIwXRt12W6JyXXpPBEFbo62XNpKhXxs3vtT4ndB80tVs8BbExXDREfdo+q+FakjaSatxEjaiB+Yxr6xTula36JAuZwyiXL7+EWtntg/O59tT7HhS2aOXudabKCmC+4XCL065PeuWl047qA1GAUVzvMW/j3ao68CyD4O64mWAxi2OsuYWpanydT+arATXIyiDQ1Bf3E2qkth0kzHzs/p/pbG6uVHDglYKQ1csyZPMx4KVHMBsobRQC4Nug9uN426Y3fuT7Ms5x1kRF5ko86LAETLuKd38fHrvBPj7PRVvCRL0I2HA9AxIaABi04EWOUWFX3WCwgCl8GwtGlru3xrW2/cEelVfecDs2YgX020ZFvA/yuX6WgFWw69+wVoAYPkJlTWoS8D//C2jX2cfniDfE8+wBxYE6aVhTM98FdxrI2X/1/hoCHeOQfZ8QQhRcKi6unHRYc02sdol4fP2zBsMRtB2qiLWXIwPbjmwvcsrnfcHEVKiNnkCW1BKSN1VWVSVvgD/IvaemmriVW1be2jQsQY3Ox+t1sr2H5SeyJhhOyKtwdNNM4+3DroG6/dI4VLRX0vEGrpHtWGeHpFKkhuPm/zmyNsFOJmFUDJoJZalV56+AggNaq1pl9P3Z8yq6DSgoehCTxOeV+7Lo4JS1fuvgNed8LVWEHRQNWcineyaS8nbbyHbilMYcet7jz+4xSiPLhF/se2Zo+op0Ybhuenbb9o/d0+uFXZmU1N2XGppNJ7E/F54+eJvhQh5VQ7+K47bLKbxNVNC9K4LY4= X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230028)(4636009)(346002)(136003)(376002)(396003)(39860400002)(451199021)(36840700001)(40470700004)(46966006)(86362001)(31686004)(66899021)(36860700001)(83380400001)(82740400003)(40460700003)(356005)(82310400005)(41300700001)(81166007)(40480700001)(36756003)(5660300002)(8676002)(31696002)(316002)(4326008)(70586007)(70206006)(2906002)(47076005)(336012)(966005)(186003)(44832011)(6506007)(6486002)(6512007)(26005)(8936002)(53546011)(2616005)(478600001)(6666004)(43740500002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 May 2023 15:12:17.3283 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 190b68f6-fd64-4b5f-c2dc-08db57b244d8 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM7EUR03FT055.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR08MB10227 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Hi Ard, Thank you for the feedback and for the pointers. Please see my response inline marked [SAMI]. Regards, Sami Mujawar On 18/05/2023 12:01 pm, Ard Biesheuvel via groups.io wrote: > On Thu, 18 May 2023 at 11:10, Sami Mujawar wrote: >> The patch "f07a9df9af60 ArmVirtPkg: Enable stack guard" >> enabled stack overflow detection for ArmVirtPkg. Following >> this patch, running UEFI shell command 'dmpstore' resulted >> in a crash indicating a stack overflow. Invoking 'dmpstore' >> results in recursive calls to CascadeProcessVariables () >> which apparently consumes the available stack space and >> overflows. >> >> Therefore, increase the primary core stack size. >> > Thanks for the fix. I imagine diagnosing this may not have been trivial. > > However, I don't think this is the right fix tbh. Normally, SEC and > PEI run off this initial stack, and the DxeIpl PEIM is in charging of > launching the DxeCore with a full sized stack, and remapping it > non-executable as well. > > These PrePi platforms take some shortcuts and apparently, one of the > consequences is that DXE and BDS run off the initial stack, which > points into the firmware image IIRC. > > IOW, it would be better to explicitly allocate 128 KiB worth of > bootservices data memory and let the DxeCore run off of that. [SAMI] If the stack size is passed in LoadDxeCoreFromFv() at https://github.com/tianocore/edk2/blob/master/ArmVirtPkg/PrePi/PrePi.c#L104= ,=20 the code at https://github.com/tianocore/edk2/blob/master/EmbeddedPkg/Library/PrePiLib/= PrePiLib.c#L158-L182 allocates the stack and switches it. I have set the stack size to 128KB=20 in the call to LoadDxeCoreFromFv (NULL, SIZE_128KB) and it fixes the issue. However, the PrePiLib implementation lacks the code to remap the stack=20 as NonExecutable as done by=C2=A0 the DxeIplPeim code at https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Core/DxeIplPeim/= Arm/DxeLoadFunc.c#L42-L45). I have added a call to ArmSetMemoryRegionNoExec () in PrePiLib and it=20 works. However, this code would need to go in a separate Arch specific file. I am not sure what would be=20 required for other architectures but I can submit a patch that adds an arch hook function 'ArchSetStackNx=20 (UINTN StackBase, UINTN StackSize)' to set the stack as NonExecutable and provide an implementation for Arm.=20 Other architectures can similarly implement this function. Please let me know if this approach is ok. [/SAMI] > > >> Signed-off-by: Sami Mujawar >> --- >> ArmVirtPkg/ArmVirtKvmTool.dsc | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/ArmVirtPkg/ArmVirtKvmTool.dsc b/ArmVirtPkg/ArmVirtKvmTool.d= sc >> index 4541d03d23e0d98915b3d3ada688c48d979b75d2..664a624fd2a30bb466a3df21= 03482e3e6c1f303a 100644 >> --- a/ArmVirtPkg/ArmVirtKvmTool.dsc >> +++ b/ArmVirtPkg/ArmVirtKvmTool.dsc >> @@ -126,7 +126,7 @@ [PcdsFixedAtBuild.common] >> gArmTokenSpaceGuid.PcdVFPEnabled|1 >> !endif >> >> - gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize|0x4000 >> + gArmPlatformTokenSpaceGuid.PcdCPUCorePrimaryStackSize|0x8000 >> gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000 >> gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x2800 >> >> -- >> 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' >> > >=20 > >