Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3197919pxb; Mon, 9 Nov 2020 05:23:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJxM8JUH5cZVrqxS+/g/IpCJ8G2aSsvWqrFo0uRLWutwMFZNeMmgN5adhJc9tQBYFfNYMCZK X-Received: by 2002:a50:d5dd:: with SMTP id g29mr15230232edj.344.1604928210939; Mon, 09 Nov 2020 05:23:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604928210; cv=none; d=google.com; s=arc-20160816; b=AAVr01gKQ8pZi6FIa5Rsw5Kvr9Ue3jyOst1XESyG4o179Hd4K1tqXYtPoeZf8n1DMP UUATp5e2N/W63ndibmuU+32TYrkFwPuxO+xXvDBHrc7nETzlB0qHvCYEaTg4oRhTZ+pq 5P9zaRboy+5YTNLfNzqWnDU3b6wBaJcgVcr3MEnkvSEiisNN4vyiGgr4XT+vVTn4lqUu Hm7B5M7RVHbav5eqbigYGWD5nz8YKocqF0fhX75A09ue4bsBiPww597S1mEg6YH6aNFM Fcn5TqRDK1EjGP43fErkWHrhkODwDXgBK1c2qz92hNk3LioPhf9n8EjzvcK5rpKD8YKc SI/Q== 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=FCyMpXhNTdvrLIVI9UuyJlcs1rgAdTXWuYTGOkPJcn4=; b=O+sRxZtWwQb3fehn+MoScOVfcLcNXRy+tMSga9GPO6wP02ipmLvNzgVZhBFjgt9wGc Kgmecb63KV/LPgoPLEYPAMUvSEY8hnqQb4KnjgZFGrmTW/PoUxEDajrulq4etCc5pWs+ Uo7DzN78tDenG8K/071WAqj5N9T67K+pLrHp78py9HJLzznLnex3S4UjbqguxMXnHQ1c UMEYCSLtfLL3YtBF3gSjEwxA3thtiZBf5MVv/M+6KdX7YAjygoYNwgX7rkcwn0mChd/z c+eQAO1nZ+XIgRODFkWKIXZDgf73q6oqo+evf7aOgl8C5FPMzOxNmhEXnaI+bQfrT9Hz oEcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rVtjKaUU; 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=fail (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 cq14si3322390edb.207.2020.11.09.05.23.07; Mon, 09 Nov 2020 05:23:30 -0800 (PST) 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=@kernel.org header.s=default header.b=rVtjKaUU; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732681AbgKINUx (ORCPT + 99 others); Mon, 9 Nov 2020 08:20:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:48526 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387988AbgKINUw (ORCPT ); Mon, 9 Nov 2020 08:20:52 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 6C0EA2076E; Mon, 9 Nov 2020 13:20:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604928051; bh=GSlhinP0ajG89SWkjKT8XVTuEdeiZOeCztjRjQ9zIfg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rVtjKaUUO329E/LiHarrXjUJUSzGWUrJpUlMoa4KxRYTLdQ8q2QvLnm481F1j9pX9 Td+cfj9NbjLxz22+9evtGX3RqE4V2m7anRIFKUr1u/1qkXfMqNKw0DjKGs/eZaZWQc YguYSPVhDm0v2jS4YFBCBqhk+G9SM1U4VvaGKT4k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gerald Schaefer , Alexander Gordeev , Heiko Carstens Subject: [PATCH 5.9 111/133] s390/mm: make pmd/pud_deref() large page aware Date: Mon, 9 Nov 2020 13:56:13 +0100 Message-Id: <20201109125036.029459109@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125030.706496283@linuxfoundation.org> References: <20201109125030.706496283@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: Gerald Schaefer commit b0e98aa9c411585eb586b2fa98873c936735008e upstream. pmd/pud_deref() assume that they will never operate on large pmd/pud entries, and therefore only use the non-large _xxx_ENTRY_ORIGIN mask. With commit 9ec8fa8dc331b ("s390/vmemmap: extend modify_pagetable() to handle vmemmap"), that assumption is no longer true, at least for pmd_deref(). In theory, we could end up with wrong addresses because some of the non-address bits of a large entry would not be masked out. In practice, this does not (yet) show any impact, because vmemmap_free() is currently never used for s390. Fix pmd/pud_deref() to check for the entry type and use the _xxx_ENTRY_ORIGIN_LARGE mask for large entries. While at it, also move pmd/pud_pfn() around, in order to avoid code duplication, because they do the same thing. Fixes: 9ec8fa8dc331b ("s390/vmemmap: extend modify_pagetable() to handle vmemmap") Cc: # 5.9 Signed-off-by: Gerald Schaefer Reviewed-by: Alexander Gordeev Signed-off-by: Heiko Carstens Signed-off-by: Greg Kroah-Hartman --- arch/s390/include/asm/pgtable.h | 52 +++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 22 deletions(-) --- a/arch/s390/include/asm/pgtable.h +++ b/arch/s390/include/asm/pgtable.h @@ -691,16 +691,6 @@ static inline int pud_large(pud_t pud) return !!(pud_val(pud) & _REGION3_ENTRY_LARGE); } -static inline unsigned long pud_pfn(pud_t pud) -{ - unsigned long origin_mask; - - origin_mask = _REGION_ENTRY_ORIGIN; - if (pud_large(pud)) - origin_mask = _REGION3_ENTRY_ORIGIN_LARGE; - return (pud_val(pud) & origin_mask) >> PAGE_SHIFT; -} - #define pmd_leaf pmd_large static inline int pmd_large(pmd_t pmd) { @@ -746,16 +736,6 @@ static inline int pmd_none(pmd_t pmd) return pmd_val(pmd) == _SEGMENT_ENTRY_EMPTY; } -static inline unsigned long pmd_pfn(pmd_t pmd) -{ - unsigned long origin_mask; - - origin_mask = _SEGMENT_ENTRY_ORIGIN; - if (pmd_large(pmd)) - origin_mask = _SEGMENT_ENTRY_ORIGIN_LARGE; - return (pmd_val(pmd) & origin_mask) >> PAGE_SHIFT; -} - #define pmd_write pmd_write static inline int pmd_write(pmd_t pmd) { @@ -1230,11 +1210,39 @@ static inline pte_t mk_pte(struct page * #define pud_index(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD-1)) #define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1)) -#define pmd_deref(pmd) (pmd_val(pmd) & _SEGMENT_ENTRY_ORIGIN) -#define pud_deref(pud) (pud_val(pud) & _REGION_ENTRY_ORIGIN) #define p4d_deref(pud) (p4d_val(pud) & _REGION_ENTRY_ORIGIN) #define pgd_deref(pgd) (pgd_val(pgd) & _REGION_ENTRY_ORIGIN) +static inline unsigned long pmd_deref(pmd_t pmd) +{ + unsigned long origin_mask; + + origin_mask = _SEGMENT_ENTRY_ORIGIN; + if (pmd_large(pmd)) + origin_mask = _SEGMENT_ENTRY_ORIGIN_LARGE; + return pmd_val(pmd) & origin_mask; +} + +static inline unsigned long pmd_pfn(pmd_t pmd) +{ + return pmd_deref(pmd) >> PAGE_SHIFT; +} + +static inline unsigned long pud_deref(pud_t pud) +{ + unsigned long origin_mask; + + origin_mask = _REGION_ENTRY_ORIGIN; + if (pud_large(pud)) + origin_mask = _REGION3_ENTRY_ORIGIN_LARGE; + return pud_val(pud) & origin_mask; +} + +static inline unsigned long pud_pfn(pud_t pud) +{ + return pud_deref(pud) >> PAGE_SHIFT; +} + /* * The pgd_offset function *always* adds the index for the top-level * region/segment table. This is done to get a sequence like the