Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp294664imu; Mon, 5 Nov 2018 00:38:13 -0800 (PST) X-Google-Smtp-Source: AJdET5e+IstdDkhHWTTBs/3lc+3ABYSp5AMohpjVdCNnrw2oyYjUBVD3K19QYE6uq97FuWmIHAJu X-Received: by 2002:a17:902:50ec:: with SMTP id c41-v6mr20758146plj.176.1541407093408; Mon, 05 Nov 2018 00:38:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541407093; cv=none; d=google.com; s=arc-20160816; b=obtccpuF7Zd5h58XI7pdQVRUlPsD2Mf8cVL7kac2kSo9MAiz9yMaM27sePCP6TkfSd VKKWjzX4JBtwBmdcMEwmsBGvOMZi5Qw5esY6q0ovGOEhBn71pwnyudFpfy+YH1uxQceN c+ddYypZgq3O3b3d56mesSjpKtIhF+1cjDKlzJ0jtgk2PRSNzh8C9mFwZGD6IasqREJM qqBRBcfbBNbMysCQdEPRjQx6itXWCeC3w93NOmq8ft+i8osAlNv8f5HhbwJkCzdTYBqK s+NUEbxF/XgFjZKKOYj669ga7XXoIZgcQcP8+zEeFVjiCLzNRRTSWc8IuuYeuoPXVAjy nCjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=G1GqI+rqRLNty9yWcDCOAlys009/ZUSfUnDEt3tDbrs=; b=BB+OtpoYWX7C3rVYKBuMMjQnAz5loiC93GuoQxtgYB6VZHBJ3zw57uDMJ6NOd9xlVD DNwZ/oflftap8c8+iHXrNU5ylSuQ5uqG0P2ez+qTengvag7aHFLxVY/VponidBqBbNIH 3G/SNbnqwbRhl9DmQu0TTLgHSOq+Y1uW2IMZ5y5nzzv0ldD6fKyyi9dj6MSZFDoEUUyI roUIVIqecYVbJjvooSzsXVSEvA54lu9Fq4mmtTboiZyirwLyPejpJhJle82Cgd11bIJS krWj3Cw52tBz69tswPHpVwSn+T9dHu+jaKucgx8TuQ8uHu/cvKz1QeizN7MLhZ7Egb4M ZjEw== 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 w187-v6si13060628pfb.178.2018.11.05.00.37.58; Mon, 05 Nov 2018 00:38:13 -0800 (PST) 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 S1727440AbeKERz5 (ORCPT + 99 others); Mon, 5 Nov 2018 12:55:57 -0500 Received: from mx2.suse.de ([195.135.220.15]:47792 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726086AbeKERz5 (ORCPT ); Mon, 5 Nov 2018 12:55:57 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 8153FACE7; Mon, 5 Nov 2018 08:37:21 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id AF1DE1E07AB; Mon, 5 Nov 2018 09:37:19 +0100 (CET) Date: Mon, 5 Nov 2018 09:37:19 +0100 From: Jan Kara To: John Hubbard Cc: Jason Gunthorpe , Jan Kara , Andrew Morton , john.hubbard@gmail.com, Matthew Wilcox , Michal Hocko , Christopher Lameter , Dan Williams , linux-mm@kvack.org, LKML , linux-rdma , linux-fsdevel@vger.kernel.org, Al Viro , Jerome Glisse , Christoph Hellwig , Ralph Campbell Subject: Re: [PATCH v4 2/3] mm: introduce put_user_page*(), placeholder versions Message-ID: <20181105083719.GA6953@quack2.suse.cz> References: <20181008211623.30796-1-jhubbard@nvidia.com> <20181008211623.30796-3-jhubbard@nvidia.com> <20181008171442.d3b3a1ea07d56c26d813a11e@linux-foundation.org> <5198a797-fa34-c859-ff9d-568834a85a83@nvidia.com> <20181010164541.ec4bf53f5a9e4ba6e5b52a21@linux-foundation.org> <20181011084929.GB8418@quack2.suse.cz> <20181011132013.GA5968@ziepe.ca> <97e89e08-5b94-240a-56e9-ece2b91f6dbc@nvidia.com> <20181022194329.GG30059@ziepe.ca> <532c7ae5-7277-74a7-93f2-afe8b7dc13fc@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <532c7ae5-7277-74a7-93f2-afe8b7dc13fc@nvidia.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun 04-11-18 23:17:58, John Hubbard wrote: > On 10/22/18 12:43 PM, Jason Gunthorpe wrote: > > On Thu, Oct 11, 2018 at 06:23:24PM -0700, John Hubbard wrote: > >> On 10/11/18 6:20 AM, Jason Gunthorpe wrote: > >>> On Thu, Oct 11, 2018 at 10:49:29AM +0200, Jan Kara wrote: > >>> > >>>>> This is a real worry. If someone uses a mistaken put_page() then how > >>>>> will that bug manifest at runtime? Under what set of circumstances > >>>>> will the kernel trigger the bug? > >>>> > >>>> At runtime such bug will manifest as a page that can never be evicted from > >>>> memory. We could warn in put_page() if page reference count drops below > >>>> bare minimum for given user pin count which would be able to catch some > >>>> issues but it won't be 100% reliable. So at this point I'm more leaning > >>>> towards making get_user_pages() return a different type than just > >>>> struct page * to make it much harder for refcount to go wrong... > >>> > >>> At least for the infiniband code being used as an example here we take > >>> the struct page from get_user_pages, then stick it in a sgl, and at > >>> put_page time we get the page back out of the sgl via sg_page() > >>> > >>> So type safety will not help this case... I wonder how many other > >>> users are similar? I think this is a pretty reasonable flow for DMA > >>> with user pages. > >>> > >> > >> That is true. The infiniband code, fortunately, never mixes the two page > >> types into the same pool (or sg list), so it's actually an easier example > >> than some other subsystems. But, yes, type safety doesn't help there. I can > >> take a moment to look around at the other areas, to quantify how much a type > >> safety change might help. > > > > Are most (all?) of the places working with SGLs? > > I finally put together a spreadsheet, in order to answer this sort of thing. > Some notes: > > a) There are around 100 call sites of either get_user_pages*(), or indirect > calls via iov_iter_get_pages*(). Quite a bit... > b) There are only a few SGL users. Most are ad-hoc, instead: some loop that > either can be collapsed nicely into the new put_user_pages*() APIs, or... > cannot. > > c) The real problem is: around 20+ iov_iter_get_pages*() call sites. I need > to change both the iov_iter system a little bit, and also change the callers > so that they don't pile all the gup-pinned pages into the same page** array > that also contains other allocation types. This can be done, it just takes > time, that's the good news. Yes, but looking into iov_iter_get_pages() users, lot of them then end up feeding the result either in SGL, SKB (which is basically the same thing, just for networking), or BVEC (which is again a very similar thing, just for generic block layer). I'm not saying that we must have _sgl() interface as untangling all those users might be just too complex but there is certainly some space for unification and common interfaces ;) Honza -- Jan Kara SUSE Labs, CR