From patchwork Mon Apr 12 08:00:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 12197101 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2C20C433ED for ; Mon, 12 Apr 2021 08:09:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6FCA76120B for ; Mon, 12 Apr 2021 08:09:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6FCA76120B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D5D286B006C; Mon, 12 Apr 2021 04:09:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BBE146B0072; Mon, 12 Apr 2021 04:09:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9C1266B006E; Mon, 12 Apr 2021 04:09:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0203.hostedemail.com [216.40.44.203]) by kanga.kvack.org (Postfix) with ESMTP id 7F4786B006C for ; Mon, 12 Apr 2021 04:09:01 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 3C0DB2461 for ; Mon, 12 Apr 2021 08:09:01 +0000 (UTC) X-FDA: 78022989282.19.6994A75 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf29.hostedemail.com (Postfix) with ESMTP id B93F7EF for ; Mon, 12 Apr 2021 08:08:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=DVIe+4d9I+G/am9Q3PISMJopYc/lkfgh9KdMieTh7Y0=; b=m6p33ZtUeh8y5beGxwx6STY+bL nMh8lFYg+sp9LP+GWzHHPhf+kjX0C9yaDplOYNSWj2fT1R51JhCnkXrA5tuwVtwpHAuUeDGHzkiMY xtg897nAI0LowhlXyL1NUeztXMipuT/XDBLLayK7Y+FiyAGLUQJWaGqP+oAwH34DgAQKva1Wc9aTG 5DLJ70goPvpnRkUYERmAtO8lNrO+umO1D+TlV4mLSC76p8CH/ZSuO+6g7h0yqKACDo17PP0ZDN7CU yx+3YC/1Hmcu5ObrWma/HrptEIu3LQERKl7yQxuJhkVA+NTwfgnHTQnGYpF5cHRHRcVKde0T/X5JU yYwP99kw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lVrck-0063yC-Oe; Mon, 12 Apr 2021 08:08:46 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 7BD63300222; Mon, 12 Apr 2021 10:08:44 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 3262620224231; Mon, 12 Apr 2021 10:08:44 +0200 (CEST) Message-ID: <20210412080611.568192782@infradead.org> User-Agent: quilt/0.66 Date: Mon, 12 Apr 2021 10:00:13 +0200 From: Peter Zijlstra To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, boris.ostrovsky@oracle.com, jgross@suse.com, sstabellini@kernel.org, x86@kernel.org, jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, rodrigo.vivi@intel.com, chris@chris-wilson.co.uk, intel-gfx@lists.freedesktop.org, linux-mm@kvack.org, keescook@chromium.org, hch@lst.de Subject: [PATCH 1/7] mm: Unexport apply_to_existing_page_range() References: <20210412080012.357146277@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: B93F7EF X-Stat-Signature: ncrwz9fmg7cs544uhc5eogw76g1iy3bs Received-SPF: none (infradead.org>: No applicable sender policy available) receiver=imf29; identity=mailfrom; envelope-from=""; helo=desiato.infradead.org; client-ip=90.155.92.199 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618214938-221683 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: There are no modular in-tree users, remove the EXPORT. This is an unsafe function in that it gives direct access to the page-tables. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Christoph Hellwig --- mm/memory.c | 1 - 1 file changed, 1 deletion(-) --- a/mm/memory.c +++ b/mm/memory.c @@ -2558,7 +2558,6 @@ int apply_to_existing_page_range(struct { return __apply_to_page_range(mm, addr, size, fn, data, false); } -EXPORT_SYMBOL_GPL(apply_to_existing_page_range); /* * handle_pte_fault chooses page fault handler according to an entry which was From patchwork Mon Apr 12 08:00:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 12197111 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A786C433B4 for ; Mon, 12 Apr 2021 08:09:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id ADF7E61241 for ; Mon, 12 Apr 2021 08:09:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ADF7E61241 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6DC806B0072; Mon, 12 Apr 2021 04:09:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 63FD16B0075; Mon, 12 Apr 2021 04:09:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 297226B0072; Mon, 12 Apr 2021 04:09:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0184.hostedemail.com [216.40.44.184]) by kanga.kvack.org (Postfix) with ESMTP id D63836B0073 for ; Mon, 12 Apr 2021 04:09:03 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 909958248D7C for ; Mon, 12 Apr 2021 08:09:03 +0000 (UTC) X-FDA: 78022989366.15.8BB6FF0 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf22.hostedemail.com (Postfix) with ESMTP id 1A190C0001FA for ; Mon, 12 Apr 2021 08:08:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=OtIPE7LdX+QBKK2tSqSr9/uYg2L3KF1qrgrA2x1fPJU=; b=Wu1I1vXFc6dGqQYFarxc8bK06Z Km2Pr+jwqQnttpzYUbE7RzxcmP+jqsL1r4g9+WKNlXWUx6AZhWfGvqlybyVpkz/ezIvV9k9lYtf9O W+YPJfUsHf8VfwtRK3kABW9KX2uiytcBvcR/K7XX2/XPWeOUHmJb0tYFs23aUlVZgq8U5UGakAHJt Ys9Ao6rc2EtVEme7dy1Vh2i3iPxrEFdBLEArAgjcH3ulGRsrfEAr43PiPB8w8EBlERdGpKdzxUOWa 6Ssq6pYqqh+++0luSnKiSkLi6GwsqvySfVv0Lza4l5oi59GGVvBxU5OtdzdInLFNlEOvRtA8csp+d CT0XxotA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lVrcl-003yd7-5P; Mon, 12 Apr 2021 08:08:49 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 7DE8230022D; Mon, 12 Apr 2021 10:08:44 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 347FB25F2152E; Mon, 12 Apr 2021 10:08:44 +0200 (CEST) Message-ID: <20210412080611.635125063@infradead.org> User-Agent: quilt/0.66 Date: Mon, 12 Apr 2021 10:00:14 +0200 From: Peter Zijlstra To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, boris.ostrovsky@oracle.com, jgross@suse.com, sstabellini@kernel.org, x86@kernel.org, jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, rodrigo.vivi@intel.com, chris@chris-wilson.co.uk, intel-gfx@lists.freedesktop.org, linux-mm@kvack.org, keescook@chromium.org, hch@lst.de Subject: [PATCH 2/7] xen/gntdev,x86: Remove apply_to_page_range() use from module References: <20210412080012.357146277@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 1A190C0001FA X-Stat-Signature: pxch8brecd4ainxsoxcy553xhrf8koba Received-SPF: none (infradead.org>: No applicable sender policy available) receiver=imf22; identity=mailfrom; envelope-from=""; helo=casper.infradead.org; client-ip=90.155.50.34 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618214939-727058 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Instead of relying on apply_to_page_range() being available to modules, move its use into core kernel code and export it's application. NOTE: ideally we do: use_ptemod = !auto_translate_physmap && gnttab_map_avail_bits and remove this hack. Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/xen/page.h | 2 ++ arch/x86/xen/mmu.c | 26 ++++++++++++++++++++++++++ drivers/xen/gntdev.c | 23 +---------------------- 3 files changed, 29 insertions(+), 22 deletions(-) --- a/arch/x86/include/asm/xen/page.h +++ b/arch/x86/include/asm/xen/page.h @@ -370,4 +370,6 @@ static inline unsigned long xen_get_swio return __get_free_pages(__GFP_NOWARN, order); } +extern void xen_set_grant_as_special(struct vm_area_struct *vma); + #endif /* _ASM_X86_XEN_PAGE_H */ --- a/arch/x86/xen/mmu.c +++ b/arch/x86/xen/mmu.c @@ -51,3 +51,29 @@ int xen_unmap_domain_gfn_range(struct vm return -EINVAL; } EXPORT_SYMBOL_GPL(xen_unmap_domain_gfn_range); + +static int set_grant_ptes_as_special(pte_t *pte, unsigned long addr, void *data) +{ + set_pte_at(current->mm, addr, pte, pte_mkspecial(*pte)); + return 0; +} + +void xen_set_grant_as_special(struct vm_area_struct *vma) +{ + if (xen_feature(XENFEAT_gnttab_map_avail_bits)) + return; + + /* + * If the PTEs were not made special by the grant map + * hypercall, do so here. + * + * This is racy since the mapping is already visible + * to userspace but userspace should be well-behaved + * enough to not touch it until the mmap() call + * returns. + */ + apply_to_page_range(vma->vm_mm, vma->vm_start, + vma->vm_end - vma->vm_start, + set_grant_ptes_as_special, NULL); +} +EXPORT_SYMBOL_GPL(xen_set_grant_as_special); --- a/drivers/xen/gntdev.c +++ b/drivers/xen/gntdev.c @@ -278,14 +278,6 @@ static int find_grant_ptes(pte_t *pte, u return 0; } -#ifdef CONFIG_X86 -static int set_grant_ptes_as_special(pte_t *pte, unsigned long addr, void *data) -{ - set_pte_at(current->mm, addr, pte, pte_mkspecial(*pte)); - return 0; -} -#endif - int gntdev_map_grant_pages(struct gntdev_grant_map *map) { int i, err = 0; @@ -1040,20 +1032,7 @@ static int gntdev_mmap(struct file *flip goto out_put_map; } else { #ifdef CONFIG_X86 - /* - * If the PTEs were not made special by the grant map - * hypercall, do so here. - * - * This is racy since the mapping is already visible - * to userspace but userspace should be well-behaved - * enough to not touch it until the mmap() call - * returns. - */ - if (!xen_feature(XENFEAT_gnttab_map_avail_bits)) { - apply_to_page_range(vma->vm_mm, vma->vm_start, - vma->vm_end - vma->vm_start, - set_grant_ptes_as_special, NULL); - } + xen_set_grant_as_special(vma); #endif } From patchwork Mon Apr 12 08:00:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 12197113 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D300C433ED for ; Mon, 12 Apr 2021 08:09:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C735261243 for ; Mon, 12 Apr 2021 08:09:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C735261243 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 967676B0073; Mon, 12 Apr 2021 04:09:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E0D46B007B; Mon, 12 Apr 2021 04:09:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B9406B0078; Mon, 12 Apr 2021 04:09:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0048.hostedemail.com [216.40.44.48]) by kanga.kvack.org (Postfix) with ESMTP id E1B7D6B0074 for ; Mon, 12 Apr 2021 04:09:03 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 9846C180ACF0D for ; Mon, 12 Apr 2021 08:09:03 +0000 (UTC) X-FDA: 78022989366.13.EC483B7 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf28.hostedemail.com (Postfix) with ESMTP id 4AC0B2000266 for ; Mon, 12 Apr 2021 08:09:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=TguJ2GPrgAOuTqINpCRxcU7hNVbLhj0fwULRtq3UU1o=; b=tXVKWgzFI9zH3GWTObAPMxRBO7 qW1DBUMrGFm+8Qwf/5f5kaJgjQbPbuZpcBeMgGrqDamtRBPvw1pTpVr2UJ4wkG7xmDe6Di8Yizw13 9GTs5P337jFcp1hh0+0w8DIuS2T1XcA/8X/8jZXO7LbqsXqd+cuSpUUH7XqRWZsrciuqpSa3T6ViU VHOH37AwdqrzYt8L/E5mcoFjehXgk/K7L0tv2LZGLuGVe+Usvs4yY8oqKCCGZ2mUiosLBOEzNf0su 6HIQYT4g52hXFae7hh3SOYBAdzsTIEwobt/9jEhPDphWTjWsOUGbej5uU3GqxaW17j9jeBURm2Uxm 3kRDFgFg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lVrcl-003yd8-5W; Mon, 12 Apr 2021 08:08:49 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 7519D3001E1; Mon, 12 Apr 2021 10:08:44 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 3A78625F21530; Mon, 12 Apr 2021 10:08:44 +0200 (CEST) Message-ID: <20210412080611.702979288@infradead.org> User-Agent: quilt/0.66 Date: Mon, 12 Apr 2021 10:00:15 +0200 From: Peter Zijlstra To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, boris.ostrovsky@oracle.com, jgross@suse.com, sstabellini@kernel.org, x86@kernel.org, jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, rodrigo.vivi@intel.com, chris@chris-wilson.co.uk, intel-gfx@lists.freedesktop.org, linux-mm@kvack.org, keescook@chromium.org, hch@lst.de Subject: [PATCH 3/7] xen/gntdev: Remove apply_to_page_range() use from module References: <20210412080012.357146277@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4AC0B2000266 X-Stat-Signature: 4eb4eneb4e16fkeeii4o484mfdnida54 X-Rspamd-Server: rspam02 Received-SPF: none (infradead.org>: No applicable sender policy available) receiver=imf28; identity=mailfrom; envelope-from=""; helo=casper.infradead.org; client-ip=90.155.50.34 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618214944-336898 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Instead of relying on apply_to_page_range() being available to modules, move its use into core kernel code and export it's application. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Christoph Hellwig --- drivers/xen/gntdev-common.h | 2 ++ drivers/xen/gntdev.c | 30 +----------------------------- drivers/xen/grant-table.c | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 29 deletions(-) --- a/drivers/xen/gntdev-common.h +++ b/drivers/xen/gntdev-common.h @@ -86,4 +86,6 @@ bool gntdev_test_page_count(unsigned int int gntdev_map_grant_pages(struct gntdev_grant_map *map); +int gnttab_use_ptemod(struct vm_area_struct *vma, struct gntdev_grant_map *map); + #endif --- a/drivers/xen/gntdev.c +++ b/drivers/xen/gntdev.c @@ -262,32 +262,6 @@ void gntdev_put_map(struct gntdev_priv * /* ------------------------------------------------------------------ */ -static int find_grant_ptes(pte_t *pte, unsigned long addr, void *data) -{ - struct gntdev_grant_map *map = data; - unsigned int pgnr = (addr - map->vma->vm_start) >> PAGE_SHIFT; - int flags = map->flags | GNTMAP_application_map | GNTMAP_contains_pte; - u64 pte_maddr; - - BUG_ON(pgnr >= map->count); - pte_maddr = arbitrary_virt_to_machine(pte).maddr; - - /* - * Set the PTE as special to force get_user_pages_fast() fall - * back to the slow path. If this is not supported as part of - * the grant map, it will be done afterwards. - */ - if (xen_feature(XENFEAT_gnttab_map_avail_bits)) - flags |= (1 << _GNTMAP_guest_avail0); - - gnttab_set_map_op(&map->map_ops[pgnr], pte_maddr, flags, - map->grants[pgnr].ref, - map->grants[pgnr].domid); - gnttab_set_unmap_op(&map->unmap_ops[pgnr], pte_maddr, flags, - INVALID_GRANT_HANDLE); - return 0; -} - int gntdev_map_grant_pages(struct gntdev_grant_map *map) { int i, err = 0; @@ -1028,9 +1002,7 @@ static int gntdev_mmap(struct file *flip mmu_interval_read_begin(&map->notifier); map->pages_vm_start = vma->vm_start; - err = apply_to_page_range(vma->vm_mm, vma->vm_start, - vma->vm_end - vma->vm_start, - find_grant_ptes, map); + err = gnttab_use_ptemod(vma, map); if (err) { pr_warn("find_grant_ptes() failure.\n"); goto out_put_map; --- a/drivers/xen/grant-table.c +++ b/drivers/xen/grant-table.c @@ -1591,6 +1591,43 @@ int gnttab_init(void) } EXPORT_SYMBOL_GPL(gnttab_init); +#include +#include "gntdev-common.h" + +static int find_grant_ptes(pte_t *pte, unsigned long addr, void *data) +{ + struct gntdev_grant_map *map = data; + unsigned int pgnr = (addr - map->vma->vm_start) >> PAGE_SHIFT; + int flags = map->flags | GNTMAP_application_map | GNTMAP_contains_pte; + u64 pte_maddr; + + BUG_ON(pgnr >= map->count); + pte_maddr = arbitrary_virt_to_machine(pte).maddr; + + /* + * Set the PTE as special to force get_user_pages_fast() fall + * back to the slow path. If this is not supported as part of + * the grant map, it will be done afterwards. + */ + if (xen_feature(XENFEAT_gnttab_map_avail_bits)) + flags |= (1 << _GNTMAP_guest_avail0); + + gnttab_set_map_op(&map->map_ops[pgnr], pte_maddr, flags, + map->grants[pgnr].ref, + map->grants[pgnr].domid); + gnttab_set_unmap_op(&map->unmap_ops[pgnr], pte_maddr, flags, + INVALID_GRANT_HANDLE); + return 0; +} + +int gnttab_use_ptemod(struct vm_area_struct *vma, struct gntdev_grant_map *map) +{ + return apply_to_page_range(vma->vm_mm, vma->vm_start, + vma->vm_end - vma->vm_start, + find_grant_ptes, map); +} +EXPORT_SYMBOL_GPL(gnttab_use_ptemod); + static int __gnttab_init(void) { if (!xen_domain()) From patchwork Mon Apr 12 08:00:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 12197107 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4BCEC43470 for ; Mon, 12 Apr 2021 08:09:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7C68B6127A for ; Mon, 12 Apr 2021 08:09:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7C68B6127A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F1CE86B0070; Mon, 12 Apr 2021 04:09:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E7C8A6B0071; Mon, 12 Apr 2021 04:09:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D45CB6B0072; Mon, 12 Apr 2021 04:09:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0229.hostedemail.com [216.40.44.229]) by kanga.kvack.org (Postfix) with ESMTP id B71FC6B0070 for ; Mon, 12 Apr 2021 04:09:02 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 6CC5D1801A0A1 for ; Mon, 12 Apr 2021 08:09:02 +0000 (UTC) X-FDA: 78022989324.08.6554AE1 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf13.hostedemail.com (Postfix) with ESMTP id 4CFE0E000105 for ; Mon, 12 Apr 2021 08:08:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=di4C6bbSl7iLJMkDo7XO8ZICGg5xRWGqLb1m8Rukv20=; b=YbnF5/GCNEslzNuBs5qK0QChkY 4uR2tlI+pJM2mlI4nY0EYfLtOv2DaYf8ETEJq1eLyxCAxq9TGczM8rCp5BGd+Pp07cRAxuXEjm3MH d511RbZdsZe/RF4L6N3ZM5JcGlgKNmsxldb1Ha6aZQlpgGBPRANGEpj5sE2FBpCGyvwTtpMzZqkAu TtunDAx5SH1+UnF7hGsF/IcAodYOGskfZE8U6c2QauhaJGYKoIil9rdGy+alOdxpfNZvDuVLiCUkw kAxBpkAmmy3G1hS15fLPpSpz9pVJj0TFx1VACeorabu44in+T0zAp4K5PJOEAV7dZYkdWPeoJ/9DV FT+b42rw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lVrcl-003yd5-5N; Mon, 12 Apr 2021 08:08:49 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 7766E3001FF; Mon, 12 Apr 2021 10:08:44 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 3F6B025F21531; Mon, 12 Apr 2021 10:08:44 +0200 (CEST) Message-ID: <20210412080611.769864829@infradead.org> User-Agent: quilt/0.66 Date: Mon, 12 Apr 2021 10:00:16 +0200 From: Peter Zijlstra To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, boris.ostrovsky@oracle.com, jgross@suse.com, sstabellini@kernel.org, x86@kernel.org, jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, rodrigo.vivi@intel.com, chris@chris-wilson.co.uk, intel-gfx@lists.freedesktop.org, linux-mm@kvack.org, keescook@chromium.org, hch@lst.de Subject: [PATCH 4/7] mm: Introduce verify_page_range() References: <20210412080012.357146277@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4CFE0E000105 X-Stat-Signature: aiubhp8ya5ffh93rg3s757cnwey6jqxj X-Rspamd-Server: rspam02 Received-SPF: none (infradead.org>: No applicable sender policy available) receiver=imf13; identity=mailfrom; envelope-from=""; helo=casper.infradead.org; client-ip=90.155.50.34 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618214939-73074 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Introduce and EXPORT a read-only counterpart to apply_to_page_range(). It only exposes the PTE value, not a pointer to the pagetables itself and is thus quite a bit safer to export. A number of apply_to_page_range() users can be converted to this primitive. Signed-off-by: Peter Zijlstra (Intel) --- include/linux/mm.h | 4 ++++ mm/memory.c | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2876,6 +2876,10 @@ extern int apply_to_page_range(struct mm extern int apply_to_existing_page_range(struct mm_struct *mm, unsigned long address, unsigned long size, pte_fn_t fn, void *data); +extern int verify_page_range(struct mm_struct *mm, + unsigned long addr, unsigned long size, + int (*fn)(pte_t pte, unsigned long addr, void *data), + void *data); extern void init_mem_debugging_and_hardening(void); #ifdef CONFIG_PAGE_POISONING --- a/mm/memory.c +++ b/mm/memory.c @@ -2559,6 +2559,30 @@ int apply_to_existing_page_range(struct return __apply_to_page_range(mm, addr, size, fn, data, false); } +struct vpr_data { + int (*fn)(pte_t pte, unsigned long addr, void *data); + void *data; +}; + +static int vpr_fn(pte_t *pte, unsigned long addr, void *data) +{ + struct vpr_data *vpr = data; + return vpr->fn(*pte, addr, vpr->data); +} + +int verify_page_range(struct mm_struct *mm, + unsigned long addr, unsigned long size, + int (*fn)(pte_t pte, unsigned long addr, void *data), + void *data) +{ + struct vpr_data vpr = { + .fn = fn, + .data = data, + }; + return apply_to_page_range(mm, addr, size, vpr_fn, &vpr); +} +EXPORT_SYMBOL_GPL(verify_page_range); + /* * handle_pte_fault chooses page fault handler according to an entry which was * read non-atomically. Before making any commitment, on those architectures From patchwork Mon Apr 12 08:00:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 12197099 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87F10C433B4 for ; Mon, 12 Apr 2021 08:09:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2BC436120B for ; Mon, 12 Apr 2021 08:09:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2BC436120B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AFAE46B0036; Mon, 12 Apr 2021 04:09:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AAACD6B0071; Mon, 12 Apr 2021 04:09:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9252C6B0070; Mon, 12 Apr 2021 04:09:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0089.hostedemail.com [216.40.44.89]) by kanga.kvack.org (Postfix) with ESMTP id 6E55C6B0036 for ; Mon, 12 Apr 2021 04:09:01 -0400 (EDT) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 2E29B8248D7C for ; Mon, 12 Apr 2021 08:09:01 +0000 (UTC) X-FDA: 78022989282.31.9E634E9 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf13.hostedemail.com (Postfix) with ESMTP id C1A24E000111 for ; Mon, 12 Apr 2021 08:08:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=qAg7ftC4OvKycFZYdaaiu+3hyvWOHeF5S6ch3cOk3oo=; b=mJW73nMnogALLCn/T+nyvoRxqW YpAoQeHEIvO4hKk/p6e4x3vj5bJ7h8FG3QuAoRXDxwEJDrvWuPVXSHmNBXTJh17grSYZgpiuXFFfP 4NnPM3aFN5h9HNpDVlnB8BbyNlRWQ5w8kfwfFDS3LpeEV70KIjrgxh+sJpWP+oMBXmCZOWQkavDZW scLU/P95X0P1Ax+URV2p26ndNJPDYf1TNcfibumLpgPPOZNwKmM+Id5no3phHBlcZzOzpW2vjaYzM g+qpMTspD2/vHPMqPHIx+Y3LTBb7qugrwl0xGqW5g3E4RsbYPaVhBq7TTbi+8nCiErSW7Wi7No7tN giIPPjBg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lVrcl-0063yK-HH; Mon, 12 Apr 2021 08:08:47 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id E4B133002C1; Mon, 12 Apr 2021 10:08:45 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 4236E25F2152F; Mon, 12 Apr 2021 10:08:44 +0200 (CEST) Message-ID: <20210412080611.835675015@infradead.org> User-Agent: quilt/0.66 Date: Mon, 12 Apr 2021 10:00:17 +0200 From: Peter Zijlstra To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, boris.ostrovsky@oracle.com, jgross@suse.com, sstabellini@kernel.org, x86@kernel.org, jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, rodrigo.vivi@intel.com, chris@chris-wilson.co.uk, intel-gfx@lists.freedesktop.org, linux-mm@kvack.org, keescook@chromium.org, hch@lst.de Subject: [PATCH 5/7] xen/privcmd: Use verify_page_range() References: <20210412080012.357146277@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: C1A24E000111 X-Stat-Signature: zqa41i6ufs4e9b31jhq1qypgjommnz4o Received-SPF: none (infradead.org>: No applicable sender policy available) receiver=imf13; identity=mailfrom; envelope-from=""; helo=desiato.infradead.org; client-ip=90.155.92.199 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618214937-580643 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Avoid using apply_to_page_range() from modules, use the safer verify_page_range() instead. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Christoph Hellwig --- drivers/xen/privcmd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/drivers/xen/privcmd.c +++ b/drivers/xen/privcmd.c @@ -946,9 +946,9 @@ static int privcmd_mmap(struct file *fil * on a per pfn/pte basis. Mapping calls that fail with ENOENT * can be then retried until success. */ -static int is_mapped_fn(pte_t *pte, unsigned long addr, void *data) +static int is_mapped_fn(pte_t pte, unsigned long addr, void *data) { - return pte_none(*pte) ? 0 : -EBUSY; + return pte_none(pte) ? 0 : -EBUSY; } static int privcmd_vma_range_is_mapped( @@ -956,8 +956,8 @@ static int privcmd_vma_range_is_mapped( unsigned long addr, unsigned long nr_pages) { - return apply_to_page_range(vma->vm_mm, addr, nr_pages << PAGE_SHIFT, - is_mapped_fn, NULL) != 0; + return verify_page_range(vma->vm_mm, addr, nr_pages << PAGE_SHIFT, + is_mapped_fn, NULL) != 0; } const struct file_operations xen_privcmd_fops = { From patchwork Mon Apr 12 08:00:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 12197103 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 070A6C433B4 for ; Mon, 12 Apr 2021 08:09:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A061B61220 for ; Mon, 12 Apr 2021 08:09:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A061B61220 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4C0A76B0071; Mon, 12 Apr 2021 04:09:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4466D6B007B; Mon, 12 Apr 2021 04:09:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 074486B0075; Mon, 12 Apr 2021 04:09:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0228.hostedemail.com [216.40.44.228]) by kanga.kvack.org (Postfix) with ESMTP id C96AB6B0072 for ; Mon, 12 Apr 2021 04:09:03 -0400 (EDT) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 9EEB7180ACC34 for ; Mon, 12 Apr 2021 08:09:03 +0000 (UTC) X-FDA: 78022989366.31.9B00C3B Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf15.hostedemail.com (Postfix) with ESMTP id DDCA9A0003A5 for ; Mon, 12 Apr 2021 08:09:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=a6+zHHfrmNSjnuKpDcqXJsViLAaAf+vjd+fWHfxBxIo=; b=iwOjMpKKyzAFrBidkEKF+HSfqn BEsev2o8dOMHA2L1zmtC0v0cDfJ9HOjS5jFS4yuc956dZDcciHG8tfQQIdUNVgs7p31HLXh2UhGNb B3pps3OSkNrQ0HcW5nYzgeNDld2ah1kqbkiuJ1h0vNhDTI5TWwqoLKZ2RqEASFl4cPUljMZmb3GsD g1TBPdomVhvxlaQ6egk0eFTeeLhj14kQf1qdm6o2RwJeQVQIaTYV9PKUEaCadfElKLH2icgOF5WJP z7DRDA90J2bbDAAvPJxdlj96pnVRijnEVnxDLiHHVH9OY+cb7Rv+EUFDV6mS/XDbyT8+lMqgPpz5c HKg0/Oog==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lVrcl-003yd9-Fg; Mon, 12 Apr 2021 08:08:49 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id E3D6830026E; Mon, 12 Apr 2021 10:08:45 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 4B56525F21533; Mon, 12 Apr 2021 10:08:44 +0200 (CEST) Message-ID: <20210412080611.902470568@infradead.org> User-Agent: quilt/0.66 Date: Mon, 12 Apr 2021 10:00:18 +0200 From: Peter Zijlstra To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, boris.ostrovsky@oracle.com, jgross@suse.com, sstabellini@kernel.org, x86@kernel.org, jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, rodrigo.vivi@intel.com, chris@chris-wilson.co.uk, intel-gfx@lists.freedesktop.org, linux-mm@kvack.org, keescook@chromium.org, hch@lst.de Subject: [PATCH 6/7] i915: Convert to verify_page_range() References: <20210412080012.357146277@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: DDCA9A0003A5 X-Stat-Signature: 7hswy66hxdow37i6f1z9utys8pjwpnub Received-SPF: none (infradead.org>: No applicable sender policy available) receiver=imf15; identity=mailfrom; envelope-from=""; helo=casper.infradead.org; client-ip=90.155.50.34 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618214941-930056 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: check_{present,absent}() only need R/O access, use verify_page_range() instead to remove modular use of apply_to_page_range(). Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Christoph Hellwig --- drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) --- a/drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c +++ b/drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c @@ -1225,9 +1225,9 @@ static int igt_mmap_gpu(void *arg) return 0; } -static int check_present_pte(pte_t *pte, unsigned long addr, void *data) +static int check_present_pte(pte_t pte, unsigned long addr, void *data) { - if (!pte_present(*pte) || pte_none(*pte)) { + if (!pte_present(pte) || pte_none(pte)) { pr_err("missing PTE:%lx\n", (addr - (unsigned long)data) >> PAGE_SHIFT); return -EINVAL; @@ -1236,9 +1236,9 @@ static int check_present_pte(pte_t *pte, return 0; } -static int check_absent_pte(pte_t *pte, unsigned long addr, void *data) +static int check_absent_pte(pte_t pte, unsigned long addr, void *data) { - if (pte_present(*pte) && !pte_none(*pte)) { + if (pte_present(pte) && !pte_none(pte)) { pr_err("present PTE:%lx; expected to be revoked\n", (addr - (unsigned long)data) >> PAGE_SHIFT); return -EINVAL; @@ -1249,14 +1249,14 @@ static int check_absent_pte(pte_t *pte, static int check_present(unsigned long addr, unsigned long len) { - return apply_to_page_range(current->mm, addr, len, - check_present_pte, (void *)addr); + return verify_page_range(current->mm, addr, len, + check_present_pte, (void *)addr); } static int check_absent(unsigned long addr, unsigned long len) { - return apply_to_page_range(current->mm, addr, len, - check_absent_pte, (void *)addr); + return verify_page_range(current->mm, addr, len, + check_absent_pte, (void *)addr); } static int prefault_range(u64 start, u64 len) From patchwork Mon Apr 12 08:00:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 12197105 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC6D7C43461 for ; Mon, 12 Apr 2021 08:09:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 75A9A61249 for ; Mon, 12 Apr 2021 08:09:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 75A9A61249 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 01FEB6B006E; Mon, 12 Apr 2021 04:09:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D92F76B0071; Mon, 12 Apr 2021 04:09:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C313D6B0070; Mon, 12 Apr 2021 04:09:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0142.hostedemail.com [216.40.44.142]) by kanga.kvack.org (Postfix) with ESMTP id A72756B006C for ; Mon, 12 Apr 2021 04:09:01 -0400 (EDT) Received: from smtpin35.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 6C670180ACF0D for ; Mon, 12 Apr 2021 08:09:01 +0000 (UTC) X-FDA: 78022989282.35.0C48B6F Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf06.hostedemail.com (Postfix) with ESMTP id 330B2C0007D8 for ; Mon, 12 Apr 2021 08:09:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=hnyJIpIgRwAiJphlWTzrQr9Y8jq97hs5NNvLYyocx0A=; b=WuNlZCexSZVXcdYaTJVvOhXT9y qzdukRmwjcgFaeguHENlqyTcuk2bJ3MUCGWFlCxuf0f52RWB1pCzoojZuCCdb5XjLonouEScQE4Un LAhRDouBPENjjQU5eFcl5UHIAUWJdWmn2jm4OK1sxw8FBoRR65DyvL+vms4hOa8fu2g7oyraEPPTq +7uU/o3K5eLwaaI1bVdOEOOOk7PPzPOkEz6CnrW1234yv56YAMOrYAVDLgQBxOr/xOhjd1AbArjjo UtD1OTVBuGaEQavMSq1vySIpcQS0I1ULwGRMWLotd3SB0wXe/ZjCGlka96oQi1OAt88cYboBfA2Y3 t3Yb19hA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lVrcm-0063yS-8C; Mon, 12 Apr 2021 08:08:49 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id E5B1C3002C4; Mon, 12 Apr 2021 10:08:45 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 5075325F21534; Mon, 12 Apr 2021 10:08:44 +0200 (CEST) Message-ID: <20210412080611.969415860@infradead.org> User-Agent: quilt/0.66 Date: Mon, 12 Apr 2021 10:00:19 +0200 From: Peter Zijlstra To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, boris.ostrovsky@oracle.com, jgross@suse.com, sstabellini@kernel.org, x86@kernel.org, jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, rodrigo.vivi@intel.com, chris@chris-wilson.co.uk, intel-gfx@lists.freedesktop.org, linux-mm@kvack.org, keescook@chromium.org, hch@lst.de Subject: [PATCH 7/7] mm: Unexport apply_to_page_range() References: <20210412080012.357146277@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 330B2C0007D8 X-Stat-Signature: pujs5gxnx9kphc4boijd9qe4ja3bmsyw X-Rspamd-Server: rspam02 Received-SPF: none (infradead.org>: No applicable sender policy available) receiver=imf06; identity=mailfrom; envelope-from=""; helo=desiato.infradead.org; client-ip=90.155.92.199 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618214942-396708 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Now that all module users of apply_to_page_range() have been removed, unexport this function. This is an unsafe function in that it gives direct access to the page-tables. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Christoph Hellwig --- mm/memory.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/mm/memory.c +++ b/mm/memory.c @@ -2544,13 +2544,14 @@ static int __apply_to_page_range(struct /* * Scan a region of virtual memory, filling in page tables as necessary * and calling a provided function on each leaf page table. + * + * DO NOT EXPORT; this hands out our page-tables on a platter. */ int apply_to_page_range(struct mm_struct *mm, unsigned long addr, unsigned long size, pte_fn_t fn, void *data) { return __apply_to_page_range(mm, addr, size, fn, data, true); } -EXPORT_SYMBOL_GPL(apply_to_page_range); /* * Scan a region of virtual memory, calling a provided function on @@ -2558,6 +2559,8 @@ EXPORT_SYMBOL_GPL(apply_to_page_range); * * Unlike apply_to_page_range, this does _not_ fill in page tables * where they are absent. + * + * DO NOT EXPORT; this hands out our page-tables on a platter. */ int apply_to_existing_page_range(struct mm_struct *mm, unsigned long addr, unsigned long size, pte_fn_t fn, void *data)