Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3376049ybp; Sun, 6 Oct 2019 10:34:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqzX5Xy3yrj5vO69vsohb+dxpommKhltRe6bn7k1JFlAFxN36tn2jokzsmuQA8c/34hCQyPL X-Received: by 2002:a50:f703:: with SMTP id g3mr25334969edn.43.1570383243040; Sun, 06 Oct 2019 10:34:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570383243; cv=none; d=google.com; s=arc-20160816; b=dCjlxsxUCoGZcRcHVJ0XXn4TaIEoXGVWqZTDd3ASF9Ckz8AaZn118bE5m28gok5n9S 34uI1hj/DH05/pdQNRvhyRXuY5WBzIRVYFZBvzBcf1KInIW/c9gsT2J1MvBZXC21yDTl UW1LibD9qYzehdd8xjtBuj7VQpDLDsmtXlmmQ94NPAFGnH5LHA8Klmvmx8BTOM2FIuBn yuPyqSVmsrBvmlxwk5iVV7xYDxzm9RkgLyx2CAzSeNzgaj1MJh7PGVOgr7BTHskZm6Cx J+iALhffeVQHPYulnN8JOHUsOGFmi4CgfKcYCcrzMfTFG2yf3EaWRTAueioPQuw/R6PC QVXg== 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=6MbqUXi+Zu0l0OWXlG1rx3C/9uL25WkBaOpzBXUoe/Y=; b=HyNmUzlO5jtqhQJx9zLhPlGNkYBu9NLRip3CeWCei4bn12vtv5PcZ48imBL1CcI5Fk p4lwXgSmcMKKaM9FlQpLpC8LMgP+I7IyLmEFeqKb52IZHpREQ9IG/i6yjfxFRwRXU5kK 5Y7ONIpq4m8g6nvVoCYHuw+9NezfgCIhAWEoUMnS+BkzU+4/VCjYz9Mxkrabgsw6qGD7 V9tXvHTd9JCVSxJPMeDzv41/QeJwDR4n9hfdiTc1rYK+JtIJ8nIvg7X/AHvGpaSBW9DK qZ0XORmbHkAstvPhzGFw87lDpFMnzIcmPGEYoFkLbPXayJkdMqiEsMEStHyGDY36OCDD w3IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bMySIFxL; 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 b35si7505640edb.204.2019.10.06.10.33.39; Sun, 06 Oct 2019 10:34:03 -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=bMySIFxL; 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 S1729213AbfJFRaT (ORCPT + 99 others); Sun, 6 Oct 2019 13:30:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:56122 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729196AbfJFRaO (ORCPT ); Sun, 6 Oct 2019 13:30:14 -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 3BD4021479; Sun, 6 Oct 2019 17:30:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570383013; bh=3IstOCt8DF1LlC7NwUbUAu1NTRKIhaLMQQKjqiQFfpo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bMySIFxLDNAfTpLk9XX1fNei4g6tF8+0Wft1YKZlgRkWf0fXutNhqLBBmgpkfrtGs mh0DhzZOKR3r7qn9XDFvfcnd+mkq/KYY4wVlptkys/h7fvLNM6o8M8+AUNwLRFSc4S BCBKlxclzxugTxTpw4QTjLfxgthjawAqtVX03Vfw= 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 4.19 055/106] ARM: 8898/1: mm: Dont treat faults reported from cache maintenance as writes Date: Sun, 6 Oct 2019 19:21:01 +0200 Message-Id: <20191006171147.589399213@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191006171124.641144086@linuxfoundation.org> References: <20191006171124.641144086@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 3232afb6fdc00..a9ee0d9dc740a 100644 --- a/arch/arm/mm/fault.c +++ b/arch/arm/mm/fault.c @@ -216,7 +216,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; @@ -287,7 +287,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