From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [216.205.24.74]) by mx.groups.io with SMTP id smtpd.web12.21459.1585165746970807918 for ; Wed, 25 Mar 2020 12:49:07 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OFzMejex; spf=pass (domain: redhat.com, ip: 216.205.24.74, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585165746; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5M1LPBA68FWM+1W0Z4hpTbcd8zIAWPfAWxulx5RttXE=; b=OFzMejexjs8o3aD7mJZik8VTa9NqyUP2yzw0MEthpZhNlt1WPp23e1WC1hnFoTvXwyUuuv M8P1VRUh1fAGgaKoii0mifwb9iu36jUIk83vBcQ56upKqeiGHfIZk7LAROCV9XtsKYDdKw znMqJqQqP9TF/UaeABxjVBk0saGEbpE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-461-RYEWdu6SP92HIMaQAMmz6Q-1; Wed, 25 Mar 2020 15:49:04 -0400 X-MC-Unique: RYEWdu6SP92HIMaQAMmz6Q-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EB9B01B18BC3; Wed, 25 Mar 2020 19:49:02 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-113-153.ams2.redhat.com [10.36.113.153]) by smtp.corp.redhat.com (Postfix) with ESMTP id DE768BBBDD; Wed, 25 Mar 2020 19:49:01 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH v3 0/3] ArmPkg/ArmMmuLib AARCH64: correctness fix To: devel@edk2.groups.io, ard.biesheuvel@linaro.org Cc: Leif Lindholm , Ashish Singhal References: <20200325152940.1492-1-ard.biesheuvel@linaro.org> From: "Laszlo Ersek" Message-ID: <4e92b528-921a-6159-55b8-bb0d6d7dea7d@redhat.com> Date: Wed, 25 Mar 2020 20:49:01 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20200325152940.1492-1-ard.biesheuvel@linaro.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit On 03/25/20 16:29, Ard Biesheuvel wrote: > The new ArmMmuLib code is easier to reason about, so that is what I did: > currently, when we create mappings that cover existing table entries, we > may end up overwriting those with block entries without taking the mapping > attributes of the original table entries into account. So let's fix this. > > I honestly don't know whether the original code was better at dealing with > this: I do remember some changes from Heyi that may have been related, but > the old code is not easy to follow. In any case, I didn't manage to hit this > case in practice, given that we typically start out with large mappings, and > break them down later (to set permissions), rather than the other way around. > > Patch #1 adds some helpers to hide the insane way the type bits change > meaning when you change to level 3. > > Patch #2 ensures that we only replace (and free) table entries with block > entries if it is guaranteed that doing so will not lose any attribute > information. > > Changes since v2: > - add patch to limit recursion to levels < 3 in FreePageTablesRecursive() > > Changes since v1: > - zero newly allocated pages before splitting a block entry into a table > entry, to avoid garbage in that page being misidentified as entry type > attributes - this should fix the crash observed by Laszlo > > Cc: Laszlo Ersek > Cc: Leif Lindholm > Cc: Ashish Singhal > > Ard Biesheuvel (3): > ArmPkg/ArmMmuLib AARCH64: limit recursion when freeing page tables > ArmPkg/ArmMmuLib AARCH64: use helpers to determine table entry types > ArmPkg/ArmMmuLib AARCH64: preserve attributes when replacing a table > entry > > .../Library/ArmMmuLib/AArch64/ArmMmuLibCore.c | 83 +++++++++++++++---- > 1 file changed, 68 insertions(+), 15 deletions(-) > Tested-by: Laszlo Ersek Thanks! Laszlo