From nobody Sat Nov 2 14:30:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1488379356186871.1819406452656; Wed, 1 Mar 2017 06:42:36 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 0354B821D4; Wed, 1 Mar 2017 06:42:35 -0800 (PST) Received: from mail-wm0-x232.google.com (mail-wm0-x232.google.com [IPv6:2a00:1450:400c:c09::232]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id F3AFC821D4 for ; Wed, 1 Mar 2017 06:42:32 -0800 (PST) Received: by mail-wm0-x232.google.com with SMTP id u199so38102266wmd.1 for ; Wed, 01 Mar 2017 06:42:32 -0800 (PST) Received: from localhost.localdomain ([105.147.1.203]) by smtp.gmail.com with ESMTPSA id h75sm6867958wrh.37.2017.03.01.06.42.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 01 Mar 2017 06:42:30 -0800 (PST) X-Original-To: edk2-devel@lists.01.org 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=+mzqQMaJ/AUAudad2arLI0sy0YzsWhrOE8F4eXEsFGo=; b=LwL6QDQIsqJq5Y7z3cYb8hfGG4ms8+hxY9np1MpMynHtDcbYbv0JNE6UalqDDGX6Lm 6WQaoKbKPY2f00UlImC6Jj7lBiRwfQATDX4Pw8RyI8FUDAOZ9iWtGE0qkWAe+hzfL5KV 9SwLEAGJ9wuosRU5h7ZDQzAIJwrrN7OEb94FU= 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=+mzqQMaJ/AUAudad2arLI0sy0YzsWhrOE8F4eXEsFGo=; b=Js7uDsiRlga4xpMUqOa8Bcn3cMLFpPi8JuHex1lGaCV2HmzY6nQ++vz/oLrSpWs3LC bydQdYGu9gPFHoCq9Gv+IjHAwG27kNLb3PsOLmvUMMkjNIFcuW/Cx/kod4sXO2zhVaPe P7AhQbdqRo5mDG8IEqKfJnjOEYw5eAN+DR2e0ye8r8nnoWNnc+jJ8XNzAWOWXVYuiBw8 hUijW5u7tHXuHRaRtq0e7GS1WcZ+gJ9in5qbnGK73aUGDDhVKJePd9jS4NhyTERpUp4i u09+Yrmfyhuuj+edQlObEWUhHNbCZYxYwcAVTk9xTxvZZHpsL6JBA60id+A/iqOLb/L0 sIWQ== X-Gm-Message-State: AMke39mz3EYn2ru/U5ia9SYGdEG9e33BCpi5g5SYDG1Kx6unYdZgQHve37SreMvDJyRtbyla X-Received: by 10.28.111.136 with SMTP id c8mr3644809wmi.128.1488379350764; Wed, 01 Mar 2017 06:42:30 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org, leif.lindholm@linaro.org, lersek@redhat.com Date: Wed, 1 Mar 2017 14:42:21 +0000 Message-Id: <1488379344-16273-2-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488379344-16273-1-git-send-email-ard.biesheuvel@linaro.org> References: <1488379344-16273-1-git-send-email-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH 1/4] ArmPkg/CpuDxe ARM: avoid splitting page table sections unnecessarily X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Currently, any range passed to CpuArchProtocol::SetMemoryAttributes is fully broken down into page mappings if the start or the size of the region happens to be misaliged relative to the section size of 1 MB. This is going to hurt when we enable strict memory permissions, given that we remap the entire RAM space non-executable (modulo the code bits) when the CpuArchProtocol is installed. So refactor the code to iterate over the range in a way that ensures that all naturally aligned section sized subregions are not broken up. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- ArmPkg/Drivers/CpuDxe/Arm/Mmu.c | 47 ++++++++++++++++---- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c b/ArmPkg/Drivers/CpuDxe/Arm/Mm= u.c index 89e429925ba9..046620f79185 100644 --- a/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c +++ b/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c @@ -679,6 +679,7 @@ SetMemoryAttributes ( ) { EFI_STATUS Status; + UINT64 ChunkLength; =20 // // Ignore invocations that only modify permission bits @@ -687,14 +688,44 @@ SetMemoryAttributes ( return EFI_SUCCESS; } =20 - if(((BaseAddress & 0xFFFFF) =3D=3D 0) && ((Length & 0xFFFFF) =3D=3D 0)) { - // Is the base and length a multiple of 1 MB? - DEBUG ((EFI_D_PAGE, "SetMemoryAttributes(): MMU section 0x%x length 0x= %x to %lx\n", (UINTN)BaseAddress, (UINTN)Length, Attributes)); - Status =3D UpdateSectionEntries (BaseAddress, Length, Attributes, Virt= ualMask); - } else { - // Base and/or length is not a multiple of 1 MB - DEBUG ((EFI_D_PAGE, "SetMemoryAttributes(): MMU page 0x%x length 0x%x = to %lx\n", (UINTN)BaseAddress, (UINTN)Length, Attributes)); - Status =3D UpdatePageEntries (BaseAddress, Length, Attributes, Virtual= Mask); + while (Length > 0) { + if ((BaseAddress % TT_DESCRIPTOR_SECTION_SIZE =3D=3D 0) && + Length >=3D TT_DESCRIPTOR_SECTION_SIZE) { + + ChunkLength =3D Length - Length % TT_DESCRIPTOR_SECTION_SIZE; + + DEBUG ((DEBUG_PAGE | DEBUG_INFO, + "SetMemoryAttributes(): MMU section 0x%lx length 0x%lx to %lx\n", + BaseAddress, ChunkLength, Attributes)); + + Status =3D UpdateSectionEntries (BaseAddress, ChunkLength, Attribute= s, + VirtualMask); + } else { + + // + // Process page by page until the next section boundary, but only if + // we have more than a section's worth of area to deal with after th= at. + // + ChunkLength =3D TT_DESCRIPTOR_SECTION_SIZE - + (BaseAddress % TT_DESCRIPTOR_SECTION_SIZE); + if (ChunkLength + TT_DESCRIPTOR_SECTION_SIZE > Length) { + ChunkLength =3D Length; + } + + DEBUG ((DEBUG_PAGE | DEBUG_INFO, + "SetMemoryAttributes(): MMU page 0x%lx length 0x%lx to %lx\n", + BaseAddress, ChunkLength, Attributes)); + + Status =3D UpdatePageEntries (BaseAddress, ChunkLength, Attributes, + VirtualMask); + } + + if (EFI_ERROR (Status)) { + break; + } + + BaseAddress +=3D ChunkLength; + Length -=3D ChunkLength; } =20 // Flush d-cache so descriptors make it back to uncached memory for subs= equent table walks --=20 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel