From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by mx.groups.io with SMTP id smtpd.web11.22271.1670523047654933557 for ; Thu, 08 Dec 2022 10:10:48 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=J1rIWv/e; spf=pass (domain: kernel.org, ip: 145.40.68.75, mailfrom: ardb@kernel.org) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 43F3DB825D7 for ; Thu, 8 Dec 2022 18:10:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E5F8C433F0 for ; Thu, 8 Dec 2022 18:10:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670523044; bh=xzhfZd+19j3UBGkxTbmgeWckkqMGRW8rBrKJGeWCYOg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=J1rIWv/emkrqzENAri9ILQBDEnZvXkeMT9uov85yfPobU4JM9RFGkVcoG4tM9Svem UkhfbLVZ99cBHuejS9U34N2o9Bvpx/T7kuKdkDRpOmeLevslxEMdA7IRMrtWMs8lCL uBOPxhqGnnpUkDUqSd0MSgM0dIyak8husYf71et9uSt6kr+kHJ/a1Ip4bvJn3Cv3bR UStJKoM+jJLdZTUVAJ0oLJFPGdKbTycNN7qSt/lZQwE+yuKoGlyhltp2l6e7KfekWp 3DHSjrHOZHPwXuBJ/zKutQg4tckrvhfWPFfLAj0+3fR6H14ckmGaU2VI7wdse7113l cT2nG6wYa+Zww== Received: by mail-lf1-f51.google.com with SMTP id y25so3245774lfa.9 for ; Thu, 08 Dec 2022 10:10:43 -0800 (PST) X-Gm-Message-State: ANoB5pk6XJzUQclHjbjVJojjRGatxNNzkZVbpz2Fz+1ZUn6/mzYSX7OF 1z4xpivZGqasbZtE4+iemdbJFYQfB59NI/QKlbs= X-Google-Smtp-Source: AA0mqf7dlPZ/SnIMWsK7JOVFO7ycygW/lr1SBk0DTTBORuRJ3lPy8pXjPHnNhEJGHKu5TEjmFjDMoQC1/qc9iVkQ7l8= X-Received: by 2002:a19:6b19:0:b0:4a2:740b:5b02 with SMTP id d25-20020a196b19000000b004a2740b5b02mr29808488lfa.122.1670523042091; Thu, 08 Dec 2022 10:10:42 -0800 (PST) MIME-Version: 1.0 References: <20221207180044.2863126-1-ardb@kernel.org> In-Reply-To: From: "Ard Biesheuvel" Date: Thu, 8 Dec 2022 19:10:30 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [edk2-devel] [PATCH] MdeModulePkg/DxeCore: Use correct type for alignment mask To: "Kinney, Michael D" Cc: "devel@edk2.groups.io" , "Bi, Dandan" , "Gao, Liming" , "Wang, Jian J" Content-Type: text/plain; charset="UTF-8" On Thu, 8 Dec 2022 at 00:13, Kinney, Michael D wrote: > > Reviewed-by: Michael D Kinney > Thanks Merged as #3738 > > > -----Original Message----- > > From: devel@edk2.groups.io On Behalf Of Ard Biesheuvel > > Sent: Wednesday, December 7, 2022 10:01 AM > > To: devel@edk2.groups.io > > Cc: Bi, Dandan ; Gao, Liming ; Wang, Jian J ; Ard > > Biesheuvel > > Subject: [edk2-devel] [PATCH] MdeModulePkg/DxeCore: Use correct type for alignment mask > > > > The page allocator code in CoreFindFreePagesI() uses a mask derived from > > its UINTN Alignment argument to align the descriptor end address of a > > MEMORY_MAP entry to the requested alignment, in order to check whether > > the descriptor covers enough sufficiently aligned area to satisfy the > > request. > > > > However, on 32-bit architectures, 'Alignment' is a 32-bit type, whereas > > DescEnd is a 64-bit type, and so the resulting operation performed on > > the end address comes down to masking with 0xfffff000 instead of the > > intended 0xffffffff_fffff000. Given the -1 at the end of the expression, > > the resulting address is 0xffffffff_fffffffff for any descriptor that > > ends on a 4G aligned boundary, and this is certainly not what was > > intended. > > > > So cast Alignment to UINT64 to ensure that the mask has the right size. > > > > Signed-off-by: Ard Biesheuvel > > --- > > MdeModulePkg/Core/Dxe/Mem/Page.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c > > index 160289c1f9ec..5903ce7ab525 100644 > > --- a/MdeModulePkg/Core/Dxe/Mem/Page.c > > +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c > > @@ -1097,7 +1097,7 @@ CoreFindFreePagesI ( > > DescEnd = MaxAddress; > > > > } > > > > > > > > - DescEnd = ((DescEnd + 1) & (~(Alignment - 1))) - 1; > > > > + DescEnd = ((DescEnd + 1) & (~((UINT64)Alignment - 1))) - 1; > > > > > > > > // Skip if DescEnd is less than DescStart after alignment clipping > > > > if (DescEnd < DescStart) { > > > > -- > > 2.35.1 > > > > > > > > -=-=-=-=-=-= > > Groups.io Links: You receive all messages sent to this group. > > View/Reply Online (#97101): https://edk2.groups.io/g/devel/message/97101 > > Mute This Topic: https://groups.io/mt/95520976/1643496 > > Group Owner: devel+owner@edk2.groups.io > > Unsubscribe: https://edk2.groups.io/g/devel/unsub [michael.d.kinney@intel.com] > > -=-=-=-=-=-= > > >