Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3379892ybp; Sun, 6 Oct 2019 10:39:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpNVE33zbQcLsQOWW1QJQ6Ahm4Yi6CZVWNipG7aljUMoFJofR5c6IN3IheFtE3MOnflxwC X-Received: by 2002:a17:906:fd4:: with SMTP id c20mr20764803ejk.41.1570383548410; Sun, 06 Oct 2019 10:39:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570383548; cv=none; d=google.com; s=arc-20160816; b=MvO1gOgLt41cQ6MLRjixOIK5vhwgCDS7xGGqvSWbCoYq1iLejH+r+RaKgs5huvBJkd aC+oTe/RDl+28q35mKEufSpRYjmKfoo8m+sQ0k8+DsAC6lk4gfjvFEOOdJkEttrYto8z 8R5dKljExPeMLYcqEiNOIletvT/5QcoDEiTwQg3XNVYtJfFihaqJs+bbkewEQ/ChxrIx zOqhroKZz/tk3G7lj6pX8qpAk01QpTrpqyrp6TgE0BuAgvDJz24HuLBktBpI2Bels63H +m5bh5cu2cbU4BCHPOdVnyrIOAoMMZFQbOY87Jdzp88fsDexTDkoPUeW/YUN1//Xym1P uKcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PQfmEheMul+FQaQzxUoakqzQk4NnMFnQinn1sONxG4k=; b=S+AhFGhLkpMU+iXk0T4+D35jlTpjQNvzdH+GFVbzGLQEztkgvX7xovCX6Hp+BB3wH4 j4Y7fVHpOIsyv3Kcep0HdZKbyWbtpdKcfa+o9OOGB/PMPdDc7eQvdYVNSQ4MqFQkvc1Y U/OJmCD0xcTa3HtumqMy2dOsWABfx0ZL7XYLKh5pxzYzLGoYMHSH9woW5gexhEoyp4D5 6JuQQ3AeSySOIUtEtKjFisLEBDERqBFukGBPhEP4epo379DY5NoV6f7gbS6TNfvlPV88 5MpGoUxukDPi8eXXCkIq5AgP2mg+G4Ar0HC59lJpVMFb79DU34vZih8SDdPEz5RS+rR8 HCKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Wm/rXwIm"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y23si7619014edb.208.2019.10.06.10.38.44; Sun, 06 Oct 2019 10:39:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Wm/rXwIm"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730399AbfJFRhN (ORCPT + 99 others); Sun, 6 Oct 2019 13:37:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:36080 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730396AbfJFRhL (ORCPT ); Sun, 6 Oct 2019 13:37:11 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A4BD92080F; Sun, 6 Oct 2019 17:37:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570383430; bh=BPODHx9SJViM3rcdfGPO6Ypkbm/NKj/WB+7yagIecvc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wm/rXwImI5SfsJj0nJJdFep6lepcDz8QYHM1BFKxhYfh2hrngHcFAksSTswWrYZGK EUELCAsAZIJ08sMGfgZGHuN82sfwqiIJHNK2+1b76EOZdcQ9R2OhaqWg0utziV/rZ+ 4UpqF8c3gE49eVVt5bIwNOO9Id4PX15ezqEa6BKg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Orion Hodson , Will Deacon , Russell King , Sasha Levin Subject: [PATCH 5.2 102/137] ARM: 8898/1: mm: Dont treat faults reported from cache maintenance as writes Date: Sun, 6 Oct 2019 19:21:26 +0200 Message-Id: <20191006171217.419771424@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191006171209.403038733@linuxfoundation.org> References: <20191006171209.403038733@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Will Deacon [ Upstream commit 834020366da9ab3fb87d1eb9a3160eb22dbed63a ] Translation faults arising from cache maintenance instructions are rather unhelpfully reported with an FSR value where the WnR field is set to 1, indicating that the faulting access was a write. Since cache maintenance instructions on 32-bit ARM do not require any particular permissions, this can cause our private 'cacheflush' system call to fail spuriously if a translation fault is generated due to page aging when targetting a read-only VMA. In this situation, we will return -EFAULT to userspace, although this is unfortunately suppressed by the popular '__builtin___clear_cache()' intrinsic provided by GCC, which returns void. Although it's tempting to write this off as a userspace issue, we can actually do a little bit better on CPUs that support LPAE, even if the short-descriptor format is in use. On these CPUs, cache maintenance faults additionally set the CM field in the FSR, which we can use to suppress the write permission checks in the page fault handler and succeed in performing cache maintenance to read-only areas even in the presence of a translation fault. Reported-by: Orion Hodson Signed-off-by: Will Deacon Signed-off-by: Russell King Signed-off-by: Sasha Levin --- arch/arm/mm/fault.c | 4 ++-- arch/arm/mm/fault.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c index 0048eadd0681a..e76155d5840bd 100644 --- a/arch/arm/mm/fault.c +++ b/arch/arm/mm/fault.c @@ -211,7 +211,7 @@ static inline bool access_error(unsigned int fsr, struct vm_area_struct *vma) { unsigned int mask = VM_READ | VM_WRITE | VM_EXEC; - if (fsr & FSR_WRITE) + if ((fsr & FSR_WRITE) && !(fsr & FSR_CM)) mask = VM_WRITE; if (fsr & FSR_LNX_PF) mask = VM_EXEC; @@ -282,7 +282,7 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) if (user_mode(regs)) flags |= FAULT_FLAG_USER; - if (fsr & FSR_WRITE) + if ((fsr & FSR_WRITE) && !(fsr & FSR_CM)) flags |= FAULT_FLAG_WRITE; /* diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h index c063708fa5032..9ecc2097a87a0 100644 --- a/arch/arm/mm/fault.h +++ b/arch/arm/mm/fault.h @@ -6,6 +6,7 @@ * Fault status register encodings. We steal bit 31 for our own purposes. */ #define FSR_LNX_PF (1 << 31) +#define FSR_CM (1 << 13) #define FSR_WRITE (1 << 11) #define FSR_FS4 (1 << 10) #define FSR_FS3_0 (15) -- 2.20.1