From patchwork Fri Feb 23 18:04:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 10238473 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A216E602DC for ; Fri, 23 Feb 2018 18:06:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8EAB9295DA for ; Fri, 23 Feb 2018 18:06:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 83045297DF; Fri, 23 Feb 2018 18:06:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F0C30295DA for ; Fri, 23 Feb 2018 18:06:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=vfD+htYPOzzXuMACYnc0pH+JZyiRZ/da9nuNwCxub8U=; b=GS+ zW5+sVMugMDfXHuv81//tt17uYLFgpg3J70sI+67XNBmGXtU9MPcJWVx6eyIGUQ3ZXX9uMVQNkurB V40jk/ysfBL/4d2v1cA6pgND7Buvvojp0jCiCyZrTAqIV5aPMGNn6e1PWYrY86Co8b90PRHsRH3ek deoZvKYlBT264J89qIQ2jP1m4ZNeXqVp/e485Bhb7JIbShS6UAVQG78sbMFghd9t9ysiujCbQSs5N +OHppSh9Z0wb5SV2JVVlGQ6RaYrQ1Z6FslF7xv19qFhcqqgYnCdYaxzAhEMkOa32wNPHiHw6vCBS5 MB3wbfY2SGpixkbhoUX83cr4Kql2xdw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1epHjm-000310-9p; Fri, 23 Feb 2018 18:06:26 +0000 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1epHiy-0002Tw-W0 for linux-arm-kernel@lists.infradead.org; Fri, 23 Feb 2018 18:05:45 +0000 Received: by mail-wr0-x242.google.com with SMTP id m5so14984717wrg.1 for ; Fri, 23 Feb 2018 10:05:26 -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; bh=OazrKwwhpDL7D7X+HMuhHLOAkEDcxjYshmnw41ZM2Mo=; b=NjgairJ1FWXY5P75OYwbn2vyHFoL7lAAIAqpIAVYEQyBgkjzUNspZzGK9ZxW3sDBNw YiPKtuw2MaasAR5uw536YsyyS/FkzTqCYRDjM9CnvBtro9QTaQi0IQYD4RzQC+Gv3eG9 OEcGIantJAu4M9NEZLiMYiNLCqb1eZ3V87TNg= 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; bh=OazrKwwhpDL7D7X+HMuhHLOAkEDcxjYshmnw41ZM2Mo=; b=gzNjpepW7vz18ES59ZGk0aRpScjZQE+4pq1bPYiwr3Xh+OcNaeIEaVJOUzKcyiOyb/ msxLERqgqss+AzLx3q9Tqkbl1rH8oTRraGzYoD/dlpKA/7UiMw1oq1rIwSMY/At0LW4N XSCHgYOqO9G47RIwDlJo6BHGqmkXRxCV54sLvNI0Tf1F+UjvDr+2secB2ysYd832fbIC OwE6TJdG1x8tem6+HdpU2ozrFh+n9vKcfJxCu58CX/0PxncQDRTstDy6eLEjtte3ATOb lnQaog86nN/PleoYW8lKPUIB3O4vOo9q4Gq8q6LOnNGzLWEvG4w3F8zDM6ij5g2NBIan 9PYw== X-Gm-Message-State: APf1xPDRE9Bc7WmB/PkkgSJSckU3TfnfDGCtXGwZHDbR8bviYKlgIrLF FkqFUy96DTfaYJ7s9/MaXXDnXiGUBTM= X-Google-Smtp-Source: AH8x226vOGOI1yi2y+IfIP1uZPmppvTwnVq/ZBlg6T4lTaSu3fIBTxGgJCEmsUXD/1ba/EfU+II9dw== X-Received: by 10.223.199.6 with SMTP id k6mr2435539wrg.197.1519409124409; Fri, 23 Feb 2018 10:05:24 -0800 (PST) Received: from localhost.localdomain ([196.90.4.100]) by smtp.gmail.com with ESMTPSA id h50sm5269879wrf.65.2018.02.23.10.05.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Feb 2018 10:05:23 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [PATCH] arm64: mm: fix thinko in non-global page table attribute check Date: Fri, 23 Feb 2018 18:04:48 +0000 Message-Id: <20180223180448.6006-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180223_100537_451803_CAE2352B X-CRM114-Status: GOOD ( 14.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, Ard Biesheuvel , marc.zyngier@arm.com, catalin.marinas@arm.com, will.deacon@arm.com, nicholas.dechesne@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The routine pgattr_change_is_safe() was extended in commit 4e6020565596 ("arm64: mm: Permit transitioning from Global to Non-Global without BBM") to permit changing the nG attribute from not set to set, but did so in a way that inadvertently disallows such changes if other permitted attribute changes take place at the same time. So update the code to take this into account. Fixes: 4e6020565596 ("arm64: mm: Permit transitioning from Global to ...") Signed-off-by: Ard Biesheuvel Acked-by: Mark Rutland Reviewed-by: Marc Zyngier Acked-by: Will Deacon --- arch/arm64/mm/mmu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 451f96f3377c..5bdc2c4db9ad 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -107,7 +107,7 @@ static bool pgattr_change_is_safe(u64 old, u64 new) * The following mapping attributes may be updated in live * kernel mappings without the need for break-before-make. */ - static const pteval_t mask = PTE_PXN | PTE_RDONLY | PTE_WRITE; + static const pteval_t mask = PTE_PXN | PTE_RDONLY | PTE_WRITE | PTE_NG; /* creating or taking down mappings is always safe */ if (old == 0 || new == 0) @@ -117,9 +117,9 @@ static bool pgattr_change_is_safe(u64 old, u64 new) if ((old | new) & PTE_CONT) return false; - /* Transitioning from Global to Non-Global is safe */ - if (((old ^ new) == PTE_NG) && (new & PTE_NG)) - return true; + /* Transitioning from Non-Global to Global is unsafe */ + if (old & ~new & PTE_NG) + return false; return ((old ^ new) & ~mask) == 0; }