Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4205792imm; Mon, 8 Oct 2018 17:16:48 -0700 (PDT) X-Google-Smtp-Source: ACcGV62Bn74qjo/zUuYa6cbAWyDpzkgwVlT6Kg1hPFPh9AWh1eAcKvSFZojZyEgeoxoxVPMEf1xj X-Received: by 2002:a63:d444:: with SMTP id i4-v6mr23035743pgj.194.1539044208182; Mon, 08 Oct 2018 17:16:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539044208; cv=none; d=google.com; s=arc-20160816; b=JT11/DN6yAbEa9m99nLGfLMjcDsHVNWiR90EWHCW9fSNg1fm8KXubBal1a5hJvvmrR COF/SIxjRh8xreCDLyUD78sGDC0IeG+PgLuVIFQoo00jkTd3ZhfORJRdkbFLxwRD9oCk LZGuQfIoLQE7rRMJikQtqoK094LoCO/JQSTH1PAlTf+4/yoUY14aPYfwRO1PSeBi4Kz2 JUQ24ZlYYYgDp1lSAAkbsk/jbIWBCaus9vpt8UOAB6pdDlcVlz/Na5MQoRfn7VDAphdv EsKiSEU4cbfdCf/roPQY7bgAm1+GNLaYiNCRIrO5xrEyDrY17SX3DMnQSnKIm/z6nYJz Jy+g== 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 :references:in-reply-to:message-id:subject:cc:to:from:date; bh=jG2iL6q5aGCZMdGbHFi4cGu3a1VvjCCgnnzxq3lM91E=; b=xIOJHe96T1i4c4da2bpf07YyyaciFtfbn1pXfJLCGEtzW3BtglXIdDa527DCLHo0qt UbemBwUmjeDfz9bROo9t5uxBKkn02G7ptM0e1xw72mYaPiwq4gP6PD+YW/4i6nVLnMY5 jaqfyBv0JRuEwSts8yOIHaMNEpZ76paj2WrCKocPdcbbJH50ORzVTfuS/yyobsc/ab6J DoiDuxqkjgNxLEUm1fBXuGUyKmEd+imyxIOXnT9KyNCfthtLk9MTRlWPb2iNBWp2Wdmh F/VGinylLgS+9O9h1ZSUjGXspLKG0X9XmFc31Nhb54wkj8jirN81F2IYEs81s+uYQuei xLmw== ARC-Authentication-Results: i=1; mx.google.com; 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 j10-v6si19218810pgi.223.2018.10.08.17.16.32; Mon, 08 Oct 2018 17:16:48 -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; 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 S1726496AbeJIH3A (ORCPT + 99 others); Tue, 9 Oct 2018 03:29:00 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:54074 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725927AbeJIH3A (ORCPT ); Tue, 9 Oct 2018 03:29:00 -0400 Received: from akpm3.svl.corp.google.com (unknown [104.133.8.65]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id AEBEF7152; Tue, 9 Oct 2018 00:14:43 +0000 (UTC) Date: Mon, 8 Oct 2018 17:14:42 -0700 From: Andrew Morton To: john.hubbard@gmail.com Cc: Matthew Wilcox , Michal Hocko , Christopher Lameter , Jason Gunthorpe , Dan Williams , Jan Kara , linux-mm@kvack.org, LKML , linux-rdma , linux-fsdevel@vger.kernel.org, John Hubbard , Al Viro , Jerome Glisse , Christoph Hellwig , Ralph Campbell Subject: Re: [PATCH v4 2/3] mm: introduce put_user_page*(), placeholder versions Message-Id: <20181008171442.d3b3a1ea07d56c26d813a11e@linux-foundation.org> In-Reply-To: <20181008211623.30796-3-jhubbard@nvidia.com> References: <20181008211623.30796-1-jhubbard@nvidia.com> <20181008211623.30796-3-jhubbard@nvidia.com> X-Mailer: Sylpheed 3.6.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 8 Oct 2018 14:16:22 -0700 john.hubbard@gmail.com wrote: > From: John Hubbard > > Introduces put_user_page(), which simply calls put_page(). > This provides a way to update all get_user_pages*() callers, > so that they call put_user_page(), instead of put_page(). > > Also introduces put_user_pages(), and a few dirty/locked variations, > as a replacement for release_pages(), and also as a replacement > for open-coded loops that release multiple pages. > These may be used for subsequent performance improvements, > via batching of pages to be released. > > This prepares for eventually fixing the problem described > in [1], and is following a plan listed in [2], [3], [4]. > > [1] https://lwn.net/Articles/753027/ : "The Trouble with get_user_pages()" > > [2] https://lkml.kernel.org/r/20180709080554.21931-1-jhubbard@nvidia.com > Proposed steps for fixing get_user_pages() + DMA problems. > > [3]https://lkml.kernel.org/r/20180710082100.mkdwngdv5kkrcz6n@quack2.suse.cz > Bounce buffers (otherwise [2] is not really viable). > > [4] https://lkml.kernel.org/r/20181003162115.GG24030@quack2.suse.cz > Follow-up discussions. > > ... > > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -137,6 +137,8 @@ extern int overcommit_ratio_handler(struct ctl_table *, int, void __user *, > size_t *, loff_t *); > extern int overcommit_kbytes_handler(struct ctl_table *, int, void __user *, > size_t *, loff_t *); > +int set_page_dirty(struct page *page); > +int set_page_dirty_lock(struct page *page); > > #define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n)) > > @@ -943,6 +945,51 @@ static inline void put_page(struct page *page) > __put_page(page); > } > > +/* > + * Pages that were pinned via get_user_pages*() should be released via > + * either put_user_page(), or one of the put_user_pages*() routines > + * below. > + */ > +static inline void put_user_page(struct page *page) > +{ > + put_page(page); > +} > + > +static inline void put_user_pages_dirty(struct page **pages, > + unsigned long npages) > +{ > + unsigned long index; > + > + for (index = 0; index < npages; index++) { > + if (!PageDirty(pages[index])) Both put_page() and set_page_dirty() handle compound pages. But because of the above statement, put_user_pages_dirty() might misbehave? Or maybe it won't - perhaps the intent here is to skip dirtying the head page if the sub page is clean? Please clarify, explain and add comment if so. > + set_page_dirty(pages[index]); > + > + put_user_page(pages[index]); > + } > +} > + > +static inline void put_user_pages_dirty_lock(struct page **pages, > + unsigned long npages) > +{ > + unsigned long index; > + > + for (index = 0; index < npages; index++) { > + if (!PageDirty(pages[index])) > + set_page_dirty_lock(pages[index]); Ditto. > + put_user_page(pages[index]); > + } > +} > + > +static inline void put_user_pages(struct page **pages, > + unsigned long npages) > +{ > + unsigned long index; > + > + for (index = 0; index < npages; index++) > + put_user_page(pages[index]); > +} > + Otherwise looks OK. Ish. But it would be nice if that comment were to explain *why* get_user_pages() pages must be released with put_user_page(). Also, maintainability. What happens if someone now uses put_page() by mistake? Kernel fails in some mysterious fashion? How can we prevent this from occurring as code evolves? Is there a cheap way of detecting this bug at runtime?