From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f193.google.com (mail-oi1-f193.google.com [209.85.167.193]) by mx.groups.io with SMTP id smtpd.web10.13254.1583588064606852027 for ; Sat, 07 Mar 2020 05:34:24 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=tJ/mN8Zz; spf=pass (domain: linaro.org, ip: 209.85.167.193, mailfrom: ard.biesheuvel@linaro.org) Received: by mail-oi1-f193.google.com with SMTP id p125so5517732oif.10 for ; Sat, 07 Mar 2020 05:34:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MBytPuxh4Vawi+m2diNKY21qsYtio74DrlHwSTrDdhE=; b=tJ/mN8ZzISj7fejAnd7EtBlshR0Xf/oaM099votdMdQ+8sejC+WhvO0eDQBoGdDpC3 vi4PY2RQUgGh2210E8INgYacnwwOeHsB3J0N730MAg4XGqmt3qUlYsOkLcy1ict6Oi2p 83K0BymkLcE5yXzPX92SEoBSMBGcdBHhHZOo1WxwHgdHFTFKS2sc8B0CkhYcuxfWfRHB 9SXEhlsBGwboe4rjNYx+XhEtTYXD+2Wz8WklS8f6rCvQezdOUXaNCsPz1rJCgpFPvh4a a4kx5tBHl6mG1VHwoaM1OFlVi2vBQH50Y0Jx9IoyDx/txjgonBkTkvAK//xMNs0f5Ybz e1vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MBytPuxh4Vawi+m2diNKY21qsYtio74DrlHwSTrDdhE=; b=EF9aPmY0ZN8fcWzSrp1Hd6pvmilcz/TpeC/3SdxEdcjaxFjTy+CPIMIj/pX7CPzHsY L4fVZ1RhjZ0d0oCB3UVIK4J0ao03dAOOi6ggSBQ9ZAWnK+AMQvF3IxcFYTi29yP7Cy1r nMYf88CISxxfSyWVok6RNokr0JRDt41M/lxud5nyALCFAwXy8fZZCEvp6Hf2hA7UM0mx p/QdEUxLFClmLTbgKwWLgbXsYBxJf6thmWYHkwqKRh76ATdkyPcgZCm3wyUmdynQXSo+ ePpNvbTuthWKc4s8CZmVStlFLOKBJLXu3hEyUIw2fkWHZSI/MaZbcrWkp2AzRvqeLpIN CzMw== X-Gm-Message-State: ANhLgQ2hQO8XXqtqPVfjrkoKCcs/KUF/8T4MOBvVm2HpZJl9SnYkcy00 GP8CnFfESSdfKX5MaZbC82mEiKUMGXCxqA== X-Google-Smtp-Source: ADFU+vvYDDYMJxuc/mfHoPxKBgThdpBbH3Xnv+3Y0pCLLPQFbeb0tnudcJzOClKaShp/twOqFQZHIg== X-Received: by 2002:a54:468a:: with SMTP id k10mr6046894oic.3.1583588063481; Sat, 07 Mar 2020 05:34:23 -0800 (PST) Return-Path: Received: from cam-smtp0.cambridge.arm.com ([2a01:cb1d:112:6f00:816e:ff0d:fb69:f613]) by smtp.gmail.com with ESMTPSA id l15sm7775815otf.12.2020.03.07.05.34.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Mar 2020 05:34:22 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: leif@nuviainc.com, Ard Biesheuvel Subject: [PATCH 1/2] ArmPkg/ArmMmuLib AARCH64: use helpers to determine table entry types Date: Sat, 7 Mar 2020 14:34:14 +0100 Message-Id: <20200307133415.18857-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200307133415.18857-1-ard.biesheuvel@linaro.org> References: <20200307133415.18857-1-ard.biesheuvel@linaro.org> Given how the meaning of the attribute bits for page table entry types is slightly awkward, and changes between levels, add some helpers to abstract from this. Signed-off-by: Ard Biesheuvel --- ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c | 40 +++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c index a43d468b73ca..6f6ef5b05fbc 100644 --- a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c +++ b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c @@ -156,6 +156,36 @@ FreePageTablesRecursive ( FreePages (TranslationTable, 1); } +STATIC +BOOLEAN +IsBlockEntry ( + IN UINT64 Entry, + IN UINTN Level + ) +{ + if (Level == 3) { + return (Entry & TT_TYPE_MASK) == TT_TYPE_BLOCK_ENTRY_LEVEL3; + } + return (Entry & TT_TYPE_MASK) == TT_TYPE_BLOCK_ENTRY; +} + +STATIC +BOOLEAN +IsTableEntry ( + IN UINT64 Entry, + IN UINTN Level + ) +{ + if (Level == 3) { + // + // TT_TYPE_TABLE_ENTRY aliases TT_TYPE_BLOCK_ENTRY_LEVEL3 + // so we need to take the level into account as well. + // + return FALSE; + } + return (Entry & TT_TYPE_MASK) == TT_TYPE_TABLE_ENTRY; +} + STATIC EFI_STATUS UpdateRegionMappingRecursive ( @@ -197,7 +227,7 @@ UpdateRegionMappingRecursive ( if (Level == 0 || ((RegionStart | BlockEnd) & BlockMask) != 0) { ASSERT (Level < 3); - if ((*Entry & TT_TYPE_MASK) != TT_TYPE_TABLE_ENTRY) { + if (!IsTableEntry (*Entry, Level)) { // // No table entry exists yet, so we need to allocate a page table // for the next level. @@ -215,7 +245,7 @@ UpdateRegionMappingRecursive ( InvalidateDataCacheRange (TranslationTable, EFI_PAGE_SIZE); } - if ((*Entry & TT_TYPE_MASK) == TT_TYPE_BLOCK_ENTRY) { + if (IsBlockEntry (*Entry, Level)) { // // We are splitting an existing block entry, so we have to populate // the new table with the attributes of the block entry it replaces. @@ -246,7 +276,7 @@ UpdateRegionMappingRecursive ( AttributeSetMask, AttributeClearMask, TranslationTable, Level + 1); if (EFI_ERROR (Status)) { - if ((*Entry & TT_TYPE_MASK) != TT_TYPE_TABLE_ENTRY) { + if (!IsTableEntry (*Entry, Level)) { // // We are creating a new table entry, so on failure, we can free all // allocations we made recursively, given that the whole subhierarchy @@ -259,10 +289,10 @@ UpdateRegionMappingRecursive ( return Status; } - if ((*Entry & TT_TYPE_MASK) != TT_TYPE_TABLE_ENTRY) { + if (!IsTableEntry (*Entry, Level)) { EntryValue = (UINTN)TranslationTable | TT_TYPE_TABLE_ENTRY; ReplaceTableEntry (Entry, EntryValue, RegionStart, - (*Entry & TT_TYPE_MASK) == TT_TYPE_BLOCK_ENTRY); + IsBlockEntry (*Entry, Level)); } } else { EntryValue = (*Entry & AttributeClearMask) | AttributeSetMask; -- 2.17.1