Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2831152pxv; Mon, 12 Jul 2021 03:02:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwic04vLtUCbEeYaka38TYKkTXRoqgnFgOUFp/1oC1d8/dmto8HyISHOJv3Q6PA5/6M7N9+ X-Received: by 2002:a05:6402:1488:: with SMTP id e8mr40405288edv.341.1626084128175; Mon, 12 Jul 2021 03:02:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626084128; cv=none; d=google.com; s=arc-20160816; b=Tb9/vreIVC2bTd4FDlN1yaP1TVbigerMrF6/lmLC2mC/YXziEcZRp5lz1QjTx4+BOC i/kSuRx/s+807p1BS1n16vPT65S+1SPaEOsu8i9BZ9l2HGX50oiat52D6rN0KD56s2eZ JV8NotUs5fvskYNhzKDnjaBXiL+ZoGhPzJFqSaOQm4rvtnlpHyqTFEf76WQx+MRYyzDT x0hSsfTsp2bzF8P16Zk6B7v6B8RIknzCtEIrvK/mwBqMIwknZ53Lx/2JH+Hspo80VKrf DNH0vuXUInOPcNRoHsyjPF8zfxixmiwqafS86XgsmZjzeCTj7LrZe3XXj1Iiffi9h9yr WdLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=O02EQdyM3gmqSDWV+jTm5igJI4HBlPnt3tWPRn4MAHM=; b=to/W+CQXgBbImJUbW1lF2B6jYOt/TM2s6ZIBBSZMWODevPcS0iWuzBF2FhCzxrG/25 bX9NmJe/DaJ7niZelVGp9YSkbK82ODjOqS2alNaKXh4CmVUPI83fCqqUh2HFZr3FpduD tf0Hr1olBDPvCrUCQAFKNhMmqEq81f1B5YRBttcTFujmZYtNPMVy508cUOMqCuqe+ps8 sdWWqZoIFs7JvOqUjq0JLVAdYv8Y8/wuUXa2WU+CVpRxtB8wh8C05RT6VyUYS92NSxAg zyOg0EVyMUTvKLnS+HQBQpW93z/OIA7QZdizjHy/PFQ6sN15AHnBU6SM7IyuC5oTOYmY 0WuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hUkKoZON; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id by14si15347619ejc.595.2021.07.12.03.01.27; Mon, 12 Jul 2021 03:02:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hUkKoZON; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241579AbhGLHOs (ORCPT + 99 others); Mon, 12 Jul 2021 03:14:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:49874 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239930AbhGLGuG (ORCPT ); Mon, 12 Jul 2021 02:50:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 403AE61004; Mon, 12 Jul 2021 06:47:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626072438; bh=M+7KL+MhXotuYuHWFd6yo8cNqW5Y9Up0QO3Dbt70Kr0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hUkKoZONLiR6cyZYPjqGkWsLzbv6sH4uimAD7inVPHqRZ9j+Xfik5ALsqUpMYbD3x 3yMHGOjJgXQpHTSKKIot7+3aDxOiNCiZ7xCi1B3hjBUSpWKvCR9VpVRNAFpunOZnpi 68eoSE90s4w7dOm8VHnwdp6xUtbcdBEwZ1XPLGAY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gerald Schaefer , Niklas Schnelle , Vasily Gorbik , Sasha Levin Subject: [PATCH 5.10 497/593] s390: enable HAVE_IOREMAP_PROT Date: Mon, 12 Jul 2021 08:10:57 +0200 Message-Id: <20210712060946.126430986@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060843.180606720@linuxfoundation.org> References: <20210712060843.180606720@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Niklas Schnelle [ Upstream commit d460bb6c6417588dd8b0907d34f69b237918812a ] In commit b02002cc4c0f ("s390/pci: Implement ioremap_wc/prot() with MIO") we implemented both ioremap_wc() and ioremap_prot() however until now we had not set HAVE_IOREMAP_PROT in Kconfig, do so now. This also requires implementing pte_pgprot() as this is used in the generic_access_phys() code enabled by CONFIG_HAVE_IOREMAP_PROT. As with ioremap_wc() we need to take the MMIO Write Back bit index into account. Moreover since the pgprot value returned from pte_pgprot() is to be used for mappings into kernel address space we must make sure that it uses appropriate kernel page table protection bits. In particular a pgprot value originally coming from userspace could have the _PAGE_PROTECT bit set to enable fault based dirty bit accounting which would then make the mapping inaccessible when used in kernel address space. Fixes: b02002cc4c0f ("s390/pci: Implement ioremap_wc/prot() with MIO") Reviewed-by: Gerald Schaefer Signed-off-by: Niklas Schnelle Signed-off-by: Vasily Gorbik Signed-off-by: Sasha Levin --- arch/s390/Kconfig | 1 + arch/s390/include/asm/pgtable.h | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig index dc5c3e6fd200..7105d44a335b 100644 --- a/arch/s390/Kconfig +++ b/arch/s390/Kconfig @@ -154,6 +154,7 @@ config S390 select HAVE_FUTEX_CMPXCHG if FUTEX select HAVE_GCC_PLUGINS select HAVE_GENERIC_VDSO + select HAVE_IOREMAP_PROT if PCI select HAVE_IRQ_EXIT_ON_IRQ_STACK select HAVE_KERNEL_BZIP2 select HAVE_KERNEL_GZIP diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h index b5dbae78969b..2338345912a3 100644 --- a/arch/s390/include/asm/pgtable.h +++ b/arch/s390/include/asm/pgtable.h @@ -864,6 +864,25 @@ static inline int pte_unused(pte_t pte) return pte_val(pte) & _PAGE_UNUSED; } +/* + * Extract the pgprot value from the given pte while at the same time making it + * usable for kernel address space mappings where fault driven dirty and + * young/old accounting is not supported, i.e _PAGE_PROTECT and _PAGE_INVALID + * must not be set. + */ +static inline pgprot_t pte_pgprot(pte_t pte) +{ + unsigned long pte_flags = pte_val(pte) & _PAGE_CHG_MASK; + + if (pte_write(pte)) + pte_flags |= pgprot_val(PAGE_KERNEL); + else + pte_flags |= pgprot_val(PAGE_KERNEL_RO); + pte_flags |= pte_val(pte) & mio_wb_bit_mask; + + return __pgprot(pte_flags); +} + /* * pgd/pmd/pte modification functions */ -- 2.30.2