From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (EUR04-VI1-obe.outbound.protection.outlook.com [40.107.8.50]) by mx.groups.io with SMTP id smtpd.web11.22920.1669132078208599469 for ; Tue, 22 Nov 2022 07:47:59 -0800 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=38kq8BHK; spf=pass (domain: arm.com, ip: 40.107.8.50, 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=d9VWM/OZ1qyM5FOx1Y9BCB0tz3PcK1SWiGCP6E7TxIw=; b=38kq8BHKoSno/5ecg8qm59jtPoPhwWbY0866hCjdzlsQAyc1ODG4e+mN4yimztH/IOTDen0Gkizw+pBShLJC3ysHbeNGxMz+IppSS3PJ18JysKOdUjMX6cd6uxymN42DgTGLK6eVX8G1lMtrRXU5GPj7P9TRLWs8LiVpuxQz8k8= Received: from FR3P281CA0096.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a1::8) by AS8PR08MB8828.eurprd08.prod.outlook.com (2603:10a6:20b:5b9::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.17; Tue, 22 Nov 2022 15:47:51 +0000 Received: from VI1EUR03FT021.eop-EUR03.prod.protection.outlook.com (2603:10a6:d10:a1:cafe::4f) by FR3P281CA0096.outlook.office365.com (2603:10a6:d10:a1::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.17 via Frontend Transport; Tue, 22 Nov 2022 15:47:50 +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 VI1EUR03FT021.mail.protection.outlook.com (100.127.144.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5834.8 via Frontend Transport; Tue, 22 Nov 2022 15:47:50 +0000 Received: ("Tessian outbound 6c699027a257:v130"); Tue, 22 Nov 2022 15:47:50 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: c9af2d8f4f2a95a6 X-CR-MTA-TID: 64aa7808 Received: from 5e478f46cac6.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id E8AB999E-20EC-4918-BA8D-1E91F7B0A88D.1; Tue, 22 Nov 2022 15:47:43 +0000 Received: from EUR02-DB5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 5e478f46cac6.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 22 Nov 2022 15:47:43 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OQXJjHknse0mUCgbrh0cN92Ske4Svh7GvApn+gOsoodWxWry1RoI/M9UHIFRenS+dIrRGwOZuNWaJ2vHX+ysRGDXAl6T12a2XMZTbWr7wbXWUoxJDq5soGnIer3XuQP83IX6U7vvCUqwb1IJUqeNJNgWqbaxnpLC85R56Zhg5s/iKN7pIGO/cCoFL0q1BwJFjEOFBKtP3nDjziAkz7bi+O2HyGsUASfYX0+Df2piIOPzgjPcFQNag7m9gOjKFiFupCrUG67EV2ehsuqIMbdklr4xbC+YPNhD1LuLYIdI8aDl7TRMFSuvfU7O54LhMsFHvNXrYRLE0cjUXF0d42UB0w== 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=d9VWM/OZ1qyM5FOx1Y9BCB0tz3PcK1SWiGCP6E7TxIw=; b=h48pMyHcXyP9Ff2HLUfHdhBTjYJJOMHRU13hh5OPykQ7gT0j0Q7DCA6zxP9Ofnccceq1wmVXnCwVXHEgKaKIbfSuA+Ar6/WcibxehfWR5mZGSkouQwq7ZqFDmCqpDuEMfyCJsxTyybldYggp0UrxS6p7qTgTZb4voUWoHb21opW8aP32QJ0NTx2bm4/NH4mgx5rx7902+y2BuGkZf2ZnzAYwz/wRbJ7TNybQapc1CLtocgBSvQkhU/KPQWcKhlN+9n9E7ofAFSH0H1im6CyGrrY7Cuzh/QivgjNgxb7jGsR8iCicB+5WM2gUZn0JTYupxjsVZcMvabfD1DI6ScqJIA== 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=d9VWM/OZ1qyM5FOx1Y9BCB0tz3PcK1SWiGCP6E7TxIw=; b=38kq8BHKoSno/5ecg8qm59jtPoPhwWbY0866hCjdzlsQAyc1ODG4e+mN4yimztH/IOTDen0Gkizw+pBShLJC3ysHbeNGxMz+IppSS3PJ18JysKOdUjMX6cd6uxymN42DgTGLK6eVX8G1lMtrRXU5GPj7P9TRLWs8LiVpuxQz8k8= 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 DB9PR08MB8203.eurprd08.prod.outlook.com (2603:10a6:10:39e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.17; Tue, 22 Nov 2022 15:47:40 +0000 Received: from AS8PR08MB6806.eurprd08.prod.outlook.com ([fe80::eca2:349c:4dbf:7f10]) by AS8PR08MB6806.eurprd08.prod.outlook.com ([fe80::eca2:349c:4dbf:7f10%9]) with mapi id 15.20.5857.017; Tue, 22 Nov 2022 15:47:40 +0000 Message-ID: <0149df14-4918-3f7a-7fd1-63c5d4509a9a@arm.com> Date: Tue, 22 Nov 2022 15:47:38 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH 2/3] CloudHv:arm: build hob for kernel image memory as read-only To: Jianyong Wu , devel@edk2.groups.io CC: ardb+tianocore@kernel.org, justin.he@arm.com, "nd@arm.com" References: <20220916024620.114084-1-jianyong.wu@arm.com> <20220916024620.114084-3-jianyong.wu@arm.com> From: "Sami Mujawar" In-Reply-To: <20220916024620.114084-3-jianyong.wu@arm.com> X-ClientProxiedBy: LO6P265CA0022.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2ff::17) To AS8PR08MB6806.eurprd08.prod.outlook.com (2603:10a6:20b:39b::12) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: AS8PR08MB6806:EE_|DB9PR08MB8203:EE_|VI1EUR03FT021:EE_|AS8PR08MB8828:EE_ X-MS-Office365-Filtering-Correlation-Id: 38dff721-aae4-48e5-3a84-08dacca0e942 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: HY2yydomxflXV8QY46ZaCDzQLNyy9+QxCdYFLSJg+AjKcNKkeArIatd0uzOwlQ3tY3UVRgZyjo0hpMNnIL7HxV5TDEObYXCKoc07qHELuK6Q5EJIKpD9+rmWxK/8J3IcXVEyWCX9H/JBLCtrI5+5kfFdrQuRJhP9AMrovdgcsOniiT46uV7aFujuMsTa56CCj3+EzD+4+nMgw/Mc3jANBcNMjMs/ekCxBQC6LqcBavLMu7Q3+R9PI9Czo9ayBKUfzdl/DHLX/MGS5T8T0eZIsJav0ZONqL2lN3UBN+g6vILWHqa7CVsBV46hk3EK3XSeNIjm7TVhgChaolf6upkpTWeKVtoKta7gQT+DlVR+YJpfjC67EATANDdvQcuZg3zM76qv2WXjrjtHoixNQkDIUvK6+AAagbwtKzlfA7chbiDU+ZhpdNvCkOPoBKorJO5PrOFuc7dxwkgd7MC2JdZ8d97Zk4G8+Q6zmnTifw4ZFUkQtf8UKz9a3pWXxkP1LswJiAse7uYKo+2JaVVC8u3S7td84Lo0d2BvOAbpldxaRu50qGOPTQZyqv2CCim6fv+h24NNaMrLMPg7xg8Y8li3QWke3i3XtPJ0mr5sSAEwvKRi3eP4Vxvl5h0TJ1jzmB4X7OQ1/P4Nh2kK9TcsmtDAgKZ11jYgHK9HGZp4DdsjMow8LUqRfqekL6EW9NlvzuNTgUJTu5XGlR1zc6VKE+KNzKUAxm+Epxj1eqI4uFu2zS8= 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:(13230022)(4636009)(136003)(346002)(39860400002)(376002)(396003)(366004)(451199015)(44832011)(5660300002)(66476007)(66946007)(6512007)(66556008)(26005)(8936002)(53546011)(6506007)(316002)(186003)(2616005)(8676002)(41300700001)(83380400001)(4326008)(36756003)(38100700002)(2906002)(31696002)(86362001)(478600001)(6486002)(31686004)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB8203 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: VI1EUR03FT021.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: c16b9c3c-498d-4fcf-a131-08dacca0e350 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HaI4ae4t/DecStZfLR7X5aS8ZHOHp5vc0JjFMpeakv8CSomuwXd87b72PHClAZ2SZihr9ykbVoJjJIqrVyEHJq5MtwaA6eUE4EPclvzjYD+ic/Zb+E+kfmlcaEHi0ZIoAGLIebMgJOR6JwpE9uYCKe7pT/l/GPxe4ovkAV17Trc53HnrfGf/MEKYCjehoPtLoBJiKkonLVEQ+jSOjPub22Esqg654StLKqlwLDrGOhVKHobY0Btw+pPXvGV/+NrD+oGXJ3nOFaPWTY+RCuEb9tjioWEIj1Xx8nNW2ZOp6wdiXaEARTyQO4y4PpqbraIJvi6gNeSl7r7sig2dGHptGD5hpzNeIn+yMI3fvjjXDvJefzYZsWsS3vZ9X267D0SFp2ec3NCorRWYgMCmBJaFvcxrm46I/lDJrKCK1URjg04imac3dVVk88kx669RAcvvgIjVv13kYiaf1Dx7aY2pCglwMaHbo6p+MV4UrMcw1sn+L5BsIbiH0G85dFV7Yg79Tx9q9hv3CsTMmCHYXfkcXEG88zPQL6IKaaspunxfE96TTySEGJ5BLMGexmgICUznHn0W5m6eZgD7dJKloRJpI5sgDJU6lDD4VNwnpoQPkamvdSraHL93B3nN3PMtuSgSk6FZ4QQg2zg7SMJQXV5bhZhVZFWtvfz8p8Ojn8L4HU/e+yEW57Wx+mk1BB0u6VmBVkTsGaDLeACsLq0+Zy7JxsuEZT0EEjOufd3KPvtl7mY= 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:(13230022)(4636009)(396003)(346002)(376002)(136003)(39860400002)(451199015)(46966006)(40470700004)(36840700001)(6486002)(6506007)(6512007)(53546011)(47076005)(26005)(186003)(36756003)(2616005)(2906002)(478600001)(336012)(40460700003)(40480700001)(82740400003)(83380400001)(31696002)(86362001)(356005)(81166007)(36860700001)(82310400005)(8936002)(41300700001)(31686004)(70206006)(44832011)(70586007)(8676002)(4326008)(5660300002)(316002)(43740500002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Nov 2022 15:47:50.5049 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 38dff721-aae4-48e5-3a84-08dacca0e942 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: VI1EUR03FT021.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB8828 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Hi Jianyong, Please see my feedback marked inline as [SAMI]. Regards, Sami Mujawar On 16/09/2022 03:46 am, Jianyong Wu wrote: > As we use memory to pass kernel image, the memory region where kernel > image locates should be added into hob as read-only. > > Signed-off-by: Jianyong Wu > --- > .../CloudHvVirtMemInfoLib.c | 66 +++++++++++++++++-- > 1 file changed, 62 insertions(+), 4 deletions(-) > > diff --git a/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoL= ib.c b/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoLib.c > index 28a0c0b078..d9b7d51a16 100644 > --- a/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoLib.c > +++ b/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoLib.c > @@ -37,13 +37,14 @@ CloudHvVirtMemInfoPeiLibConstructor ( > ) > { > VOID *DeviceTreeBase; > - EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes; > + EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes, ReadOnlyResourceAttri= butes; > INT32 Node, Prev; > UINT64 FirMemNodeBase, FirMemNodeSize; > - UINT64 CurBase, MemBase; > + UINT64 CurBase, MemBase, CurSizeOff; > UINT64 CurSize; > + UINT64 KernelStart, KernelSize; > CONST CHAR8 *Type; > - INT32 Len; > + INT32 Len, ChosenNode; > CONST UINT64 *RegProp; > RETURN_STATUS PcdStatus; > UINT8 Index; > @@ -53,6 +54,8 @@ CloudHvVirtMemInfoPeiLibConstructor ( > FirMemNodeBase =3D 0; > FirMemNodeSize =3D 0; > Index =3D 0; > + CurSizeOff =3D 0; > + KernelSize =3D 0; > MemBase =3D FixedPcdGet64 (PcdSystemMemoryBase); > ResourceAttributes =3D ( > EFI_RESOURCE_ATTRIBUTE_PRESENT | > @@ -60,6 +63,12 @@ CloudHvVirtMemInfoPeiLibConstructor ( > EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE | > EFI_RESOURCE_ATTRIBUTE_TESTED > ); > + ReadOnlyResourceAttributes =3D ( > + EFI_RESOURCE_ATTRIBUTE_PRESENT | > + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | > + EFI_RESOURCE_ATTRIBUTE_TESTED | > + EFI_RESOURCE_ATTRIBUTE_READ_ONLY_PROTECT= ED > + ); > DeviceTreeBase =3D (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseA= ddress); > if (DeviceTreeBase =3D=3D NULL) { > return EFI_NOT_FOUND; > @@ -72,6 +81,21 @@ CloudHvVirtMemInfoPeiLibConstructor ( > return EFI_NOT_FOUND; > } > =20 > + // > + // Try to get kernel image info from DT > + // > + ChosenNode =3D fdt_path_offset (DeviceTreeBase, "/chosen"); > + if (ChosenNode >=3D 0) { > + RegProp =3D fdt_getprop (DeviceTreeBase, ChosenNode, "linux,kernel-s= tart", &Len); > + if ((RegProp !=3D NULL) && (Len > 0)) { > + KernelStart =3D (UINT64)fdt64_to_cpu (ReadUnaligned64 (RegProp)); > + RegProp =3D fdt_getprop (DeviceTreeBase, ChosenNode, "linux,ke= rnel-size", &Len); > + if ((RegProp !=3D NULL) && (Len > 0)) { > + KernelSize =3D (UINT64)fdt64_to_cpu (ReadUnaligned64 (RegProp)); > + } > + } > + } > + > // > // Look for the lowest memory node > // > @@ -105,11 +129,26 @@ CloudHvVirtMemInfoPeiLibConstructor ( > =20 > // We should build Hob seperately for the memory node except th= e first one > if (CurBase !=3D MemBase) { > + // If kernel image resides in current memory node, build hob f= rom CurBase to the beginning of kernel image. > + if ((KernelSize !=3D 0) && (KernelStart >=3D CurBase) && (Kern= elStart + KernelSize <=3D CurBase + CurSize)) { > + CurSizeOff =3D CurBase + CurSize - KernelStart; > + // align up with 0x1000 > + CurSizeOff =3D (CurSizeOff + 0xfff) & ~0xfffUL; > + } > + > BuildResourceDescriptorHob ( > EFI_RESOURCE_SYSTEM_MEMORY, > ResourceAttributes, > CurBase, > - CurSize > + CurSize - CurSizeOff > + ); > + > + // Add kernel image memory region to hob as read only > + BuildResourceDescriptorHob ( > + EFI_RESOURCE_SYSTEM_MEMORY, > + ReadOnlyResourceAttributes, > + CurBase + CurSize - CurSizeOff, > + CurSizeOff > ); [SAMI] Can you explain why this is required and what would happen if=20 this is not done, please?=C2=A0 It would be good to add this description to= =20 the commit message. Also, what about the initrd and the commandline? [/SAMI] > } else { > FirMemNodeBase =3D CurBase; > @@ -146,8 +185,27 @@ CloudHvVirtMemInfoPeiLibConstructor ( > return EFI_NOT_FOUND; > } > =20 > + CurSizeOff =3D 0; > + // Build hob for the lowest memory node from its base to the beginning= of kernel image once the kernel image reside here > + if ((KernelSize !=3D 0) && (KernelStart >=3D FirMemNodeBase) && (Kerne= lStart + KernelSize <=3D FirMemNodeBase + FirMemNodeSize)) { > + CurSizeOff =3D FirMemNodeBase + FirMemNodeSize - KernelStart; > + // Caution the alignment > + CurSizeOff =3D (CurSizeOff + 0xfff) & ~0xfffUL; > + > + // Add kernel image memory region to hob as read only > + BuildResourceDescriptorHob ( > + EFI_RESOURCE_SYSTEM_MEMORY, > + ReadOnlyResourceAttributes, > + FirMemNodeBase + FirMemNodeSize - CurSizeOff, > + CurSizeOff > + ); > + } > + > + FirMemNodeSize -=3D CurSizeOff; > + > PcdStatus =3D PcdSet64S (PcdSystemMemorySize, FirMemNodeSize); > ASSERT_RETURN_ERROR (PcdStatus); > + > ASSERT ( > (((UINT64)PcdGet64 (PcdFdBaseAddress) + > (UINT64)PcdGet32 (PcdFdSize)) <=3D FirMemNodeBase) ||