From patchwork Fri Nov 30 11:28:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 152519 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3539484ljp; Fri, 30 Nov 2018 03:28:38 -0800 (PST) X-Google-Smtp-Source: AFSGD/Wq6UVVD9+ntcgDpyyqMaVKffJrNISG6ZtYACb1Kg4UoFm1MRXdh1mT+fAwhnnHjPeuXTcl X-Received: by 2002:a17:902:7c0a:: with SMTP id x10mr5400483pll.65.1543577318516; Fri, 30 Nov 2018 03:28:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543577318; cv=none; d=google.com; s=arc-20160816; b=JeOynRTWetk08pZcXz6Y15yDtiZmH6D+X73ADjpwZJW2/2I1Utli2iQJV0u1e8XuAl kGyJEcZ/OLm7XGVbBWPdiH6gQns7VHQ13fLm1Y0MMBRdemYSuDZTGGmMj4iqsuy9+peA gVK6OCfFrqnWLr4yIENWH5O584djjQM6xRHBCZsQhbXaYSaIJlM6Qizb+2jfqsrSm4ol 6ZcKmPe4mvQWD55WcGfADvqJvVR5tpMRtBkERNd1eGlDphfk6CxnlKKjbzCV5JeyLRwm NsG/KAZIDOWGVEh2DOKlsKHAuLEFBhV7FpR54nkP3USRvuvAZEp+1q5l8IVKOi/ekosc OWTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=gJOZZMkYIVqe/pbSRSw5GgXxc9S9rVw3e+ODAsvWydY=; b=s+sT0W2PBKyqtha4ju/whddWooTFSdyaqMBJweMl36E2tMdmGTf0Df+cf1wEY1v47S rDXWXgKd3tBaF7KQ8LAwUIfoMkK+xmcUvkfvt0GZmbZdOxbAvFitXm6Q3bcOgA05iuEA tBr6J7WzjWgLWuT8siP2pwqnASksTzTWQ704Ii5WZ5YAl+543ioTbJVRYtilajHL4j5W v03DOKqeKzlcAMlgJqdDM6BI8Vbg1gPKM3rSSvVRHBWviIH8i+7x6Vpn/08jytplYwU9 vQiOTtIAQdtvpwF3TouaZ1MpdQYRx/3AIlb7dQGF3qwD+rLIiONXCrrGugKh5jYAMC3q q2uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=CFZuGmam; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id 41si5029010plf.347.2018.11.30.03.28.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Nov 2018 03:28:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=CFZuGmam; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id BD40C2119739E; Fri, 30 Nov 2018 03:28:36 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::341; helo=mail-wm1-x341.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) (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 00EBD2117D76B for ; Fri, 30 Nov 2018 03:28:35 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id k198so5366373wmd.3 for ; Fri, 30 Nov 2018 03:28:35 -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 :mime-version:content-transfer-encoding; bh=SoPA/xPSkYtoqdMYE6fW82fWunjWMgKB9dw55lI2VBs=; b=CFZuGmamOsQuAWK8u1kBwUANiHNXcOtJGOUDyeV73aKg0Ylo8hX0p+vgL3rGw3bkI7 Fy6pdkBJ+/4HklRfSrqHaZcjrGP23v/MU2Qp1LASTffLD5QBKjXl0OCZQzMACOhIJ5Fh /XEks3Z/UYqb9+Lqf3GGzWb8oGL0RIqPhuEcY= 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:mime-version:content-transfer-encoding; bh=SoPA/xPSkYtoqdMYE6fW82fWunjWMgKB9dw55lI2VBs=; b=JcHsm67fxKjDu4yX3AJvVkFa8WfKU/W80CuEM3oZgRCX3e0Rg3GrUx+7vYo1UQeYr+ 6ieRz6tSeW/MlXmgzS6rC6qg3efZjbiM9mqf/eAepqnTsxP+Aj/dvxRkK3pTuF3Niaq+ AsQVxo0aJ8SEnvfh0/a27l6qY8FkBI6ptHILUcQDGxiqkCYHK0tS8rJtgxTjAukuEDYF EFXHnWwhzpenk2OWTetbNDVz7mzxANEwU9pUnGfYj7FWK8z23GIMIvs9k5dq7xSnlC+W o0+hVlS1vNSdvxBU7Sh507ZaR29t1iWEIM5B73xC7U0KRbgtWlFr0GGMeBBEbF4OWjr/ chyg== X-Gm-Message-State: AA+aEWbW77eWWCtw9llhLamEJTYB/MTU1nkOWhaKBlRfyo6otShpZt+v uToAN0XcHxUu1acbHSZbMrv0SBPuGOk= X-Received: by 2002:a1c:7d54:: with SMTP id y81mr5397298wmc.78.1543577314164; Fri, 30 Nov 2018 03:28:34 -0800 (PST) Received: from harold.home ([2a01:cb1d:112:6f00:f070:d240:312e:9f99]) by smtp.gmail.com with ESMTPSA id h16sm4340570wrs.60.2018.11.30.03.28.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Nov 2018 03:28:33 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Fri, 30 Nov 2018 12:28:26 +0100 Message-Id: <20181130112829.12173-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181130112829.12173-1-ard.biesheuvel@linaro.org> References: <20181130112829.12173-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Subject: [edk2] [PATCH v2 1/4] ArmPkg/ArmMmuLib ARM: handle unmapped section in GetMemoryRegion() X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jones , Laszlo Ersek Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" GetMemoryRegion() is used to obtain the attributes of an existing mapping, to permit permission attribute changes to be optimized away if the attributes don't actually change. The current ARM code assumes that a section mapping or a page mapping exists for any region passed into GetMemoryRegion(), but the region may be unmapped entirely, in which case the code will crash. So check if a section mapping exists before dereferencing it. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- ArmPkg/Drivers/CpuDxe/Arm/Mmu.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.19.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Leif Lindholm Reviewed-by: Philippe Mathieu-Daudé diff --git a/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c b/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c index 12ca5b26673e..3b29d33d0a9c 100644 --- a/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c +++ b/ArmPkg/Drivers/CpuDxe/Arm/Mmu.c @@ -457,6 +457,9 @@ GetMemoryRegion ( // Get the section at the given index SectionDescriptor = FirstLevelTable[TableIndex]; + if (!SectionDescriptor) { + return EFI_NOT_FOUND; + } // If 'BaseAddress' belongs to the section then round it to the section boundary if (((SectionDescriptor & TT_DESCRIPTOR_SECTION_TYPE_MASK) == TT_DESCRIPTOR_SECTION_TYPE_SECTION) || From patchwork Fri Nov 30 11:28:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 152520 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3539526ljp; Fri, 30 Nov 2018 03:28:41 -0800 (PST) X-Google-Smtp-Source: AFSGD/UhfIYqv1LnVIZbdhiUsFfNMEn6zq7rokjbRWONYLEf3T44l3EE5ANFes8GhwAFIY/DCWng X-Received: by 2002:a63:1766:: with SMTP id 38mr4392819pgx.299.1543577321597; Fri, 30 Nov 2018 03:28:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543577321; cv=none; d=google.com; s=arc-20160816; b=nxR8E03klhIPZFwHuJ3fc4xWs7Uoitaus7bcrsGuNjZziIFMuF/X00i3EIyP5oklNW iWG0AcLaV3Fw4PrsFEc3BMLe6TwBX3t4Kgf6yP0YwbFpgQ8n4JX4losw0MBeSgWpEACZ 68kpl8OFYv7HJWrXwe7y+PH9EHN7C75ls/NugHTnqPMwG2Srm+001fh+xEiqfuBfFdql UFUA7kcSHuzAFRmrS8MD2IrpGWfWbQPnetVvOi5jfQR+vWxIHsX5r9Z9QAFGhwVspSfQ qIGqSQZdEExzFVaQmTHMntYv8dIkQne7+MkX5BSgLd/NNrhB/ALuZRqg312xohd/eJie OtLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=XdNWZVBpLgPEQhLyKJ+tvZ/AwW+r0xKITNwt6/xP0G8=; b=wmQP5GF+c916g0EgJhu1umpTq9KtdSCWIIbWbfHO0g3otcwK7vA/Qi5+e7LmL/e+e/ K47U9qyai9Ao11Za0J1mpeVQhwZJuSNKD/fj0wDM/VVqUVvZeYCcWS5dlHcBXoRLf+SN O+jv1ZArsyfznf7H9JHPM7Mx1B6r/yV8Q/uW4LU5EMcwPgyhZHTrDekU5Hh0ip/n0cP8 5UPgAFHytqeJiWQxndLEJwgrJFqFSQ4DT5nZd3jDq4e7pXsqykqRowdYQ/sU4lqOmvfM 0gAaG15K4LjCtFtb4OgOU2fumzvzo+93/DTb2rcOPA3wPvB/lhnskzlFBTkNwHqqJFhC nZaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=DrvwL9yY; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id q18si4833781pls.30.2018.11.30.03.28.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Nov 2018 03:28:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=DrvwL9yY; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id EFCF021197B01; Fri, 30 Nov 2018 03:28:38 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::343; helo=mail-wm1-x343.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) (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 24C7721CAD998 for ; Fri, 30 Nov 2018 03:28:37 -0800 (PST) Received: by mail-wm1-x343.google.com with SMTP id k198so5366434wmd.3 for ; Fri, 30 Nov 2018 03:28:37 -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 :mime-version:content-transfer-encoding; bh=i7vr5ZjMFgX+1eTECSn7kjNQU6jaQGfmNlsOKqY/sVQ=; b=DrvwL9yY/x6GcoOszy6zZsPEzP4t3i8Y46m5P1gsa8tgUHkDR6kEIry2IINfZUg5Cq 7kHCLchg6h9Z8iGxsD3l5v6tL23I9wPv1fVjqYNz48wxHUX4d8yhFPEqJcXDoz3lAKa4 ih2dS0itx8WybnMkoWNE53JYJ0VRPOjiqxaOE= 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:mime-version:content-transfer-encoding; bh=i7vr5ZjMFgX+1eTECSn7kjNQU6jaQGfmNlsOKqY/sVQ=; b=fB99qcP7qU/EDDDnsU4CpI6+8+jyf1LwHD5eaDIFv5T/07B1qxOgzHeSzAjg5BP9jx p1YIFgpmO+tDsxfQTcSSWAKifXUUsRVPEhWsa4cnMyUCDbBS8fhuAzQ18m7lSQxqV9ym SU3npxPlHp0edqG0Y1pA3SjvgmK1JhB3aFaTB9K/+MTdFimSs6uODRpsx9cpUkx1Yp/h hNXJqD5ilwgCc82palfSkqR9RizKaEf3ZcS70Pyh8aSr8heiuQW/icjn6DVjho00bslz 9vy2xcsn45Mf2PLfsd7hcDmR+hFzVM7BUZrAlGi8TYOoBEvKF/lBsdSiC9ic9WUeMgaq TCkA== X-Gm-Message-State: AA+aEWY4Lme526XcG6oU+f3NFdXUggUh+hSJV4up8Zob54IX9d5qbIGw qs8skvXGWyycV2HHalPgeqEnHk6U6Nc= X-Received: by 2002:a1c:93ca:: with SMTP id v193mr5434899wmd.82.1543577315387; Fri, 30 Nov 2018 03:28:35 -0800 (PST) Received: from harold.home ([2a01:cb1d:112:6f00:f070:d240:312e:9f99]) by smtp.gmail.com with ESMTPSA id h16sm4340570wrs.60.2018.11.30.03.28.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Nov 2018 03:28:34 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Fri, 30 Nov 2018 12:28:27 +0100 Message-Id: <20181130112829.12173-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181130112829.12173-1-ard.biesheuvel@linaro.org> References: <20181130112829.12173-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Subject: [edk2] [PATCH v2 2/4] ArmPkg/ArmMmuLib ARM: handle unmapped sections when updating permissions X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jones , Laszlo Ersek Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" The ARM ArmMmuLib code currently does not take into account that setting permissions on a region should take into account that a region may not be mapped yet to begin with. So when updating a section descriptor whose old value is zero, pass in the address explicitly. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) -- 2.19.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Leif Lindholm diff --git a/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c b/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c index ec51e072ab43..889b22867dc7 100644 --- a/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c +++ b/ArmPkg/Library/ArmMmuLib/Arm/ArmMmuLibCore.c @@ -695,8 +695,12 @@ UpdateSectionEntries ( } else { // still a section entry - // mask off appropriate fields - Descriptor = CurrentDescriptor & ~EntryMask; + if (CurrentDescriptor != 0) { + // mask off appropriate fields + Descriptor = CurrentDescriptor & ~EntryMask; + } else { + Descriptor = ((UINTN)FirstLevelIdx + i) << TT_DESCRIPTOR_SECTION_BASE_SHIFT; + } // mask in new attributes and/or permissions Descriptor |= EntryValue; From patchwork Fri Nov 30 11:28:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 152521 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3539568ljp; Fri, 30 Nov 2018 03:28:44 -0800 (PST) X-Google-Smtp-Source: AFSGD/UOWI6wBRhGuexmpEILgtutOfyCEQma/hm1DXgXudd62L+vyYDI03nt/CdhoG80qSxD7QWM X-Received: by 2002:a63:91c1:: with SMTP id l184mr4560724pge.29.1543577324638; Fri, 30 Nov 2018 03:28:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543577324; cv=none; d=google.com; s=arc-20160816; b=rX1t+s9WEhzXCsDrz/kn9EUwKuLsiwgvCCMB8R/Lyz05i7UL5+u/1D5OhbLA13Wlhs A4tKhzk8Hh+FgdWHsDmzvtu4WK7yV1fmKsyt36vrlHq5vWY2bRWfoYk2Fj3veP3PC1J0 VU0uILl9D4WUqfXWPOWJWftQuV8nzGsmt9qLXafClKU1tAuJZn3IvItMm2p8dTb2czjn nAFAi1KFwzS/rDcAYaRUo3UyR4kUXQ6hBLNwhk781uPGLHqeG4iwdQ0N9tDtyQfApB1A 1Ql/ZuihpiPd9C+jX572L4j3Thq8gDWr8Ry+D/wEuVIuEuzlShXurZ6NNoqqrLlt9rAf cx3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=0vh6VldzeYUTYBpQHIUq+JlZQ5NCpyie1UVq5lDAp7I=; b=uVknewzDXhz/Wo8PxsbP+4jeLXWOALJNvv/QXmEUFZPAgUFHnWNuT96vlrs6SlE96c VH/ouQjLvymrAbKdSEzOHge2XkX3bj2KRwtyEJZEgQK8MlYN9QX+eeDn+88oVv1vnzfd 0Bq0eJlb5BrQnvEM98BJRm4jL3Brev5Z5Nav9CfonvsaVRyeauZw+KeayXMwibh+uIu6 F2u4hHcznNkUjZm8N7+PWMRpF0nvqMck2jLXUJSqu7LZDnYeaDErwAPKr9lBBVWx6D61 FN0v1aID3hQfHw8jYEhg13HjSOQlXFer0AHzIpjyOiNVGLOfy7eabChv7YRTB/K/j7cf Nr5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=aON6NwC8; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id w185si4563823pgd.518.2018.11.30.03.28.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Nov 2018 03:28:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=aON6NwC8; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 30A5B21197B05; Fri, 30 Nov 2018 03:28:40 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::342; helo=mail-wm1-x342.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) (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 38C1021CAD998 for ; Fri, 30 Nov 2018 03:28:38 -0800 (PST) Received: by mail-wm1-x342.google.com with SMTP id a18so5369732wmj.1 for ; Fri, 30 Nov 2018 03:28:38 -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 :mime-version:content-transfer-encoding; bh=MJ/ZzR1ylqeOzeN1tiHAk13ATMWys8ZBmKY7NZRfF/I=; b=aON6NwC8afurOD/n52RUoDwjsRql6jcLP6eXWAEYT3g2W45X4dk+KnP0n26BgLNkkj bRtUEzIrLHxYmLL38NrK4Iivvaa/vsVXclv/xCw7oAP870yrQ/oLzKrcb3Wc4w2RXVP8 G80yLokMT0qZwmQN/+Y5h9fyRw7g3HYic7kVU= 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:mime-version:content-transfer-encoding; bh=MJ/ZzR1ylqeOzeN1tiHAk13ATMWys8ZBmKY7NZRfF/I=; b=TMbLmS+vqQ2hSk9ug3V8N3c0N4OoXU8sEVgxH2lmZ6vIjogn2F2rXm43rp6pJRrnRR a3se9T4qBeqmODZp63U4GP9LJJbKaZBlPFxNvpJB8B1x/NKIo/q/rmkwg2rhg+rOhjBE daNBQMQ3EpDA2qlL5UhtU0q36Wf1FHdhiw9ge2dSSAfgEjqy5Ayq5Hm7s01aMY4rXESW xIQacCzq65ojeM1p2BTYzjM7OPJ3yP+GhBUl/RqlwFm3qyiMozyoIeR1kXZvj5sCFX2d oN7+Qe38NOZGQs9OPPv0//xBkfJqdRyRum7cuDe/TTsFLleCAz9R1Hgt8VoWCWhnHO7K 0SjA== X-Gm-Message-State: AA+aEWYZdVa1Twfg5Mz1Y+C0BjrFybs6BKY5+ziK5IV/lYGnAeGpWOV/ gIyNS8ZwKc95gOxg0xFGlPo7Jzqe2Dc= X-Received: by 2002:a7b:c218:: with SMTP id x24mr1576929wmi.58.1543577316476; Fri, 30 Nov 2018 03:28:36 -0800 (PST) Received: from harold.home ([2a01:cb1d:112:6f00:f070:d240:312e:9f99]) by smtp.gmail.com with ESMTPSA id h16sm4340570wrs.60.2018.11.30.03.28.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Nov 2018 03:28:35 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Fri, 30 Nov 2018 12:28:28 +0100 Message-Id: <20181130112829.12173-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181130112829.12173-1-ard.biesheuvel@linaro.org> References: <20181130112829.12173-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Subject: [edk2] [PATCH v2 3/4] ArmVirtPkg/NorFlashQemuLib: disregard our primary FV X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jones , Laszlo Ersek Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" The primary FV contains the firmware boot image, which is not runtime updatable in our case. So exposing it to the NOR flash driver is undesirable, since it may attempt to modify the NOR flash contents. It is also rather pointless, since we don't keep anything there that we care to expose. (the SEC and PEI phase modules are not executable from DXE context, and the contents of the embedded DXE phase FV are exposed by the DXE core directly via the FVB2 protocol) So let's disregard the NOR flash block that covers the primary FV. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf | 5 +++++ ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c | 13 +++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) -- 2.19.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Laszlo Ersek diff --git a/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf b/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf index d86ff36dbd58..c5752a243e6b 100644 --- a/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf +++ b/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf @@ -28,6 +28,7 @@ [Sources.common] [Packages] MdePkg/MdePkg.dec ArmPlatformPkg/ArmPlatformPkg.dec + ArmPkg/ArmPkg.dec ArmVirtPkg/ArmVirtPkg.dec [LibraryClasses] @@ -40,3 +41,7 @@ [Protocols] [Depex] gFdtClientProtocolGuid + +[Pcd] + gArmTokenSpaceGuid.PcdFvBaseAddress + gArmTokenSpaceGuid.PcdFvSize diff --git a/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c b/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c index 2678f57eaaad..d238e39a59f1 100644 --- a/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c +++ b/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c @@ -75,13 +75,22 @@ NorFlashPlatformGetDevices ( Size = SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[2])); Reg += 4; + PropSize -= 4 * sizeof (UINT32); + + // + // Disregard any flash devices that overlap with the primary FV. + // The firmware is not updatable from inside the guest anyway. + // + if ((PcdGet64 (PcdFvBaseAddress) + PcdGet32 (PcdFvSize) > Base) && + (Base + Size) > PcdGet64 (PcdFvBaseAddress)) { + continue; + } + mNorFlashDevices[Num].DeviceBaseAddress = (UINTN)Base; mNorFlashDevices[Num].RegionBaseAddress = (UINTN)Base; mNorFlashDevices[Num].Size = (UINTN)Size; mNorFlashDevices[Num].BlockSize = QEMU_NOR_BLOCK_SIZE; Num++; - - PropSize -= 4 * sizeof (UINT32); } } From patchwork Fri Nov 30 11:28:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 152522 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3539631ljp; Fri, 30 Nov 2018 03:28:48 -0800 (PST) X-Google-Smtp-Source: AFSGD/UtCLwANhjXiOLCr7HdJW8Wo+MhNeJ+lzsPx5Dz6Y3JaQCRKZ0nGg7FCBBMBjMMpU+kpdCE X-Received: by 2002:a62:31c1:: with SMTP id x184mr5400349pfx.204.1543577328783; Fri, 30 Nov 2018 03:28:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543577328; cv=none; d=google.com; s=arc-20160816; b=Hb4T5VMDuIguECF1mNJJZ+qdVn4vw2dS5vBQ52pTK4mJ77A7rzug06YqFFqgwo4L2a rn4sTXSZ5w3LxXI/oe2pNMKY+hEJSwVsymM3kyfIX2xC2gtEW/LjYniWJI84e8CCV8ld P6Z57bn106sBg7s7kVB9+OFJXPHXp2igB8duejtPWC4O+aZRkkYrLVfo0ybNz1XN5JEq hwSahW54JNVHvG3OdmIakqfbDs2h4z+G11vcpivcW1zegD4MZmcon63pacFmuDd5v0k3 MjjaK5A+sKf5bPPDs0jrwsbzr+d5cCtMvVpynDGGgMXcCY4OtQIYMECxYvXgtzk7PcaL Dm1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=98h+ZGD9KLiP13EuTZvnGLgRapMQhOB8mKxyIFyd4pM=; b=pjfSsaNYAdSXO1xHdmddlJfNVfJ8Dd5Dqd3PtIc5vVzRquMDswPD01Vps/w2cX/Ej1 n4pTlLTk5SWMSkQENKZOEcdqG0Vz9zXqjSCHomgUNW+VH8RvPKQ5zAMg4Ty5jmliZiOZ GQA6Lb1FHhpkEUURF/rHQDgQB4QT1WDifz1Pv0V7xTiFrWBTHatlPZWPouMyvVVbJmvd L57H8Pk4yLCv0NvcgOlOsqyqtpl58TpBf6H4GS1cMcNdQTilJqIg65a5/h1OC+sljboT O1wX5rAKDnANMl2z0RQy/vhz9Nj4JnMAt8Pqtrk4h0xqXlESzCgxgisFm6MV2VLk7hcS SqjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=DYWliSqt; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id t75si5137568pfa.170.2018.11.30.03.28.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Nov 2018 03:28:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=DYWliSqt; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 5F89C21197B07; Fri, 30 Nov 2018 03:28:42 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::344; helo=mail-wm1-x344.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) (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 4C7B12119621B for ; Fri, 30 Nov 2018 03:28:39 -0800 (PST) Received: by mail-wm1-x344.google.com with SMTP id 125so5453044wmh.0 for ; Fri, 30 Nov 2018 03:28:39 -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 :mime-version:content-transfer-encoding; bh=4J4s4Z+Da5KYfTmxw0rgK6u8yguHuT/uO6R+YAazook=; b=DYWliSqtfPBwafO6DBedagJmrdECsXA64fudiUK2fEX0Zzf2OSoPWre3OgWELz9ERF w9XycaSTqeu1fFRNazpFLfUNrLsxfgUsnKTg9XcnscZ2PN63IKst/WCTOHmhBrB2CJkE RqnQrzu1LFb9UfMC/cvCBqg1wLRYo2Jo5qWgY= 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:mime-version:content-transfer-encoding; bh=4J4s4Z+Da5KYfTmxw0rgK6u8yguHuT/uO6R+YAazook=; b=PW6qlIVN8eCJGOYQA8tJqdBYx1rk3aiRDF3tsx8ppxip24Eria7Z/Q5IlWRnsQJ7hb GKQnZWBs44NhS3qCMtuaLNDSoKsNWDD5dq/pifcTElqgWATIECb/Mv6TtI9Bkg8fVMxg zBGp5sAHsrhLQ1kmFKUjn9ynxJdFQOxfqpiptCIIjA2nm4VFP+0Tbo3hg34triUkRo8Q M7Dzw3o/YUcDH62Ez/dlH2v9uOoFJqAXMb7UOlEjvgfQBHULE+mPhEdalAXOfU7PvbMg xuxGLas1zfZ9TEmqVtN1SwbaklZ+cFJbe4OGmnOIdlGF+5RAPmV+nkeQ6js/Fd/6exZm lx4w== X-Gm-Message-State: AA+aEWZ81HuZsMYwOsZYvGZebtBziGWE7B6yCAAys1zChnEFNT1ZiIp6 c9GZuDZGJs80Eaik6PZ3jjdGi5wVBLQ= X-Received: by 2002:a1c:5506:: with SMTP id j6mr5593817wmb.44.1543577317586; Fri, 30 Nov 2018 03:28:37 -0800 (PST) Received: from harold.home ([2a01:cb1d:112:6f00:f070:d240:312e:9f99]) by smtp.gmail.com with ESMTPSA id h16sm4340570wrs.60.2018.11.30.03.28.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Nov 2018 03:28:36 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Fri, 30 Nov 2018 12:28:29 +0100 Message-Id: <20181130112829.12173-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181130112829.12173-1-ard.biesheuvel@linaro.org> References: <20181130112829.12173-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Subject: [edk2] [PATCH v2 4/4] ArmVirtPkg/QemuVirtMemInfoLib: trim the MMIO region mapping X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jones , Laszlo Ersek Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" QEMU/mach-virt is rather unhelpful when it comes to tracking down NULL pointer dereferences that occur while running in UEFI: since we have NOR flash mapped at address 0x0, inadvertent reads go unnoticed, and even most writes are silently dropped, unless you're unlucky and the instruction in question is one that KVM cannot emulate, in which case you end up with a QEMU crash like this: error: kvm run failed Function not implemented PC=000000013f7ff804 X00=000000013f7ab108 X01=0000000000000064 X02=000000013f801988 X03=00000000800003c4 X04=0000000000000000 X05=0000000096000044 X06=fffffffffffd8270 X07=000000013f7ab4a0 X08=0000000000000001 X09=000000013f803b88 X10=000000013f7e88d0 X11=0000000000000009 X12=000000013f7ab554 X13=0000000000000008 X14=0000000000000002 X15=0000000000000000 X16=0000000000000000 X17=0000000000000000 X18=0000000000000000 X19=0000000000000000 X20=000000013f81c000 X21=000000013f7ab170 X22=000000013f81c000 X23=0000000009000018 X24=000000013f407020 X25=000000013f81c000 X26=000000013f803530 X27=000000013f802000 X28=000000013f7ab270 X29=000000013f7ab0d0 X30=000000013f7fee10 SP=000000013f7a6f30 PSTATE=800003c5 N--- EL1h and a warning in the host kernel log that load/store instruction decoding is not supported by KVM. Given that the first page of the flash device is not actually used anyway, let's reduce the mappings of the peripheral space and the flash device (both of which cover page #0) to only cover what is actually required: ArmVirtQemu.fdf: > 0x00001000|0x001ff000 > gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize ArmVirtQemuKernel.fdf: > 0x00008000|0x001f8000 > gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize For ArmVirtQemu, the resulting virtual mapping looks roughly like: - [0, 4K) : flash, unmapped - [4K, 2M) : flash, mapped as WB+X RAM - [2M, 64M) : flash, unmapped - [64M, 128M) : varstore flash, will be mapped by the NOR flash driver - [128M, 256M) : peripherals, mapped as device - [256M, 1GB) : 32-bit MMIO aperture, translated IO aperture, ECAM, will be mapped by the PCI host bridge driver - [1GB, ...) : RAM, mapped. After this change, any inadvertent read or write from/to the first physical page will trigger a translation fault inside the guest, regardless of the nature of the instruction, without crashing QEMU. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf | 4 ++-- ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf | 2 ++ ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c | 23 ++++++++++++++------ 3 files changed, 20 insertions(+), 9 deletions(-) -- 2.19.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Laszlo Ersek diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf index 5c5b841051ad..b6abc52531a8 100644 --- a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf +++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.inf @@ -39,9 +39,9 @@ [LibraryClasses] PcdLib [Pcd] - gArmTokenSpaceGuid.PcdFdBaseAddress + gArmTokenSpaceGuid.PcdFvBaseAddress gArmTokenSpaceGuid.PcdSystemMemoryBase gArmTokenSpaceGuid.PcdSystemMemorySize [FixedPcd] - gArmTokenSpaceGuid.PcdFdSize + gArmTokenSpaceGuid.PcdFvSize diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf index d12089760b22..16802c5c414b 100644 --- a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf +++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoPeiLib.inf @@ -43,9 +43,11 @@ [LibraryClasses] [Pcd] gArmTokenSpaceGuid.PcdFdBaseAddress + gArmTokenSpaceGuid.PcdFvBaseAddress gArmTokenSpaceGuid.PcdSystemMemoryBase gArmTokenSpaceGuid.PcdSystemMemorySize [FixedPcd] gArmTokenSpaceGuid.PcdFdSize + gArmTokenSpaceGuid.PcdFvSize gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c index 0285a11b1d77..a26b2fbad9be 100644 --- a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c +++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c @@ -21,6 +21,15 @@ // Number of Virtual Memory Map Descriptors #define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 5 +// +// mach-virt's core peripherals such as the UART, the GIC and the RTC are +// all mapped in the 'miscellaneous device I/O' region, which we just map +// in its entirety rather than device by device. Note that it does not +// cover any of the NOR flash banks or PCI resource windows. +// +#define MACH_VIRT_PERIPH_BASE 0x08000000 +#define MACH_VIRT_PERIPH_SIZE SIZE_128MB + /** Return the Virtual Memory Map of your platform @@ -66,16 +75,16 @@ ArmVirtGetMemoryMap ( VirtualMemoryTable[0].VirtualBase, VirtualMemoryTable[0].Length)); - // Peripheral space before DRAM - VirtualMemoryTable[1].PhysicalBase = 0x0; - VirtualMemoryTable[1].VirtualBase = 0x0; - VirtualMemoryTable[1].Length = VirtualMemoryTable[0].PhysicalBase; + // Memory mapped peripherals (UART, RTC, GIC, virtio-mmio, etc) + VirtualMemoryTable[1].PhysicalBase = MACH_VIRT_PERIPH_BASE; + VirtualMemoryTable[1].VirtualBase = MACH_VIRT_PERIPH_BASE; + VirtualMemoryTable[1].Length = MACH_VIRT_PERIPH_SIZE; VirtualMemoryTable[1].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE; - // Remap the FD region as normal executable memory - VirtualMemoryTable[2].PhysicalBase = PcdGet64 (PcdFdBaseAddress); + // Map the FV region as normal executable memory + VirtualMemoryTable[2].PhysicalBase = PcdGet64 (PcdFvBaseAddress); VirtualMemoryTable[2].VirtualBase = VirtualMemoryTable[2].PhysicalBase; - VirtualMemoryTable[2].Length = FixedPcdGet32 (PcdFdSize); + VirtualMemoryTable[2].Length = FixedPcdGet32 (PcdFvSize); VirtualMemoryTable[2].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK; // End of Table