Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp2640248ima; Mon, 22 Oct 2018 13:15:31 -0700 (PDT) X-Google-Smtp-Source: ACcGV60nIFaz99oQwxlim9ZIJRrb3RjsJEAIy8Q7fLsOBWa1HhjbA3SLn8teL48Y+RQHU3qdXmOA X-Received: by 2002:a17:902:758f:: with SMTP id j15-v6mr47040253pll.160.1540239331832; Mon, 22 Oct 2018 13:15:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540239331; cv=none; d=google.com; s=arc-20160816; b=p2Gu+dDuGJDYwqrBtir1h/S+yqu0m2qgiZzKAfH/z4oQkuuUOAe2Km2ihDVWCkuPkm nq3kryTa35zYNrMR5UbmhgJY/V9OtNmm0tgntqEVnjAY3baFJqVge+ycbblCCNm6JPFq cRUxrMOKEHghoR1KlrC2pfEtOI0LucV0thDZ1Z27cIozwP3V6KTVxGRp/jv8c5sqG04u rTgw50IsPwPjW86X4wiH3mlFJHBnKlhIAVgGDbwSpFp+PSCfto7MONejL4QwHTJyNs12 7PPlbqN94mlzHUhwCUFvbuIl9SaLbwfmT2nNp57IFpuHTpY7s0bgq+BDjh9aEpH8Do4o khCA== 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:dkim-signature; bh=Ng8XJRjDLo4T9LQsxwyGWYLTrEX5ScPLIw/PST11mFo=; b=0g9r5lhuOjl7uvkELCxS07tWD7+BZ5kDIYbVu74tMrbiV5aaTyIGV43bp5P1xixzwP Pr7Tky6WC+cyCmggtt3PmySjSHd6yA9/WTiWjA1tuVA9uDQ4BDrmsnFMm70u/11fVMok z0viWWcz3mcZ4UNZAX948KR7vdv6davV+8hJNAxzzF0JPBUZyT9bbNk2l7DuHug2YiER vpyYAk73al2nSn2NIpZqOLZ/lBZIdgfpNvfvrxbQC4P/UXC6U6ycVXsxOLO9FPhvjMr8 d7W8wnJPvDybQwwLPQyF7sCHdGKbpz0ZYkcDs7EVf0TZNK4Nxo9DeX7f04iWf4xi036r 0KCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=BPCn1eup; 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 k6-v6si872812pgl.454.2018.10.22.13.15.16; Mon, 22 Oct 2018 13:15:31 -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; dkim=pass header.i=@ziepe.ca header.s=google header.b=BPCn1eup; 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 S1726082AbeJWEDY (ORCPT + 99 others); Tue, 23 Oct 2018 00:03:24 -0400 Received: from mail-it1-f193.google.com ([209.85.166.193]:38040 "EHLO mail-it1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725768AbeJWEDY (ORCPT ); Tue, 23 Oct 2018 00:03:24 -0400 Received: by mail-it1-f193.google.com with SMTP id i76-v6so14107174ita.3 for ; Mon, 22 Oct 2018 12:43:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Ng8XJRjDLo4T9LQsxwyGWYLTrEX5ScPLIw/PST11mFo=; b=BPCn1eupFN9NutuXdmEI1Td77GX1f/wLwQ3a8A2M2Zh4/pNW7X6tjh5xSX7/QiOAMO GWHNWSLMNjHO9RsQ02YFThuwhFJy9k5fel5JdeHx7ut+bjWfkpKKHrxlK+IjyGwsvXvX HUIgxx3LOvs+HwB8dbJgluRJPgdOYPrTqLstOy/MWodciWAoPQU1kEdYruFoHyFBNoEF olGZkib2KSN8p7MV4oCv5NjRw7Izx1bGA9/j8Q56zTYlS5EVP3PUCJt+dOm7JbeYyEIs BFIrsl4Z9uhzda8lhxYVQXfdXPtoTS8+CtDqFqPwawVjcG49m7JOH0v87Y3XL+lY3S+W 1VgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Ng8XJRjDLo4T9LQsxwyGWYLTrEX5ScPLIw/PST11mFo=; b=BEuRrf61wSFWs6YrA8AxiRS6vQOP3dzsV13t2/AHcwOUcmkm5dRDUP1RhC2KRvC5Vr 7azhkNak7K10wcww1JXiDsT6gxNQvpsB96zQM3BILKID6qzWBEtbu5kG7modrx/M8VgG pCwW4tm62j/tirJmO54TUp/PvhFIcfmQZV5uda51FrSNCJwnEc9zWnpy2hwcAsIdHO+Y p452qfseOAjyoAVfc5EukAdGOFK9FM08N0TR0s6/qXSd16edcqkZ8veb/lrEu2KsODWD bXcAGvh97FWO4n6CHblpYQLR/ymu8Bq6W9nFUs86D0b9PFnpBpTl1rDGguhmV7/N5ycZ uleA== X-Gm-Message-State: ABuFfojuJphj+bv32opyDTQxxxsvygQ6B3hCjeir4VgK0TQBJxh3cYG2 MJuHRLASvzqVW+1lHyKIVeDPYQ== X-Received: by 2002:a24:8e41:: with SMTP id h62-v6mr1015709ite.126.1540237412079; Mon, 22 Oct 2018 12:43:32 -0700 (PDT) Received: from ziepe.ca (S010614cc2056d97f.ed.shawcable.net. [174.3.196.123]) by smtp.gmail.com with ESMTPSA id d124-v6sm11084751iof.57.2018.10.22.12.43.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 Oct 2018 12:43:30 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1gEg6r-0002Uo-OO; Mon, 22 Oct 2018 13:43:29 -0600 Date: Mon, 22 Oct 2018 13:43:29 -0600 From: Jason Gunthorpe To: John Hubbard Cc: 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: <20181022194329.GG30059@ziepe.ca> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <97e89e08-5b94-240a-56e9-ece2b91f6dbc@nvidia.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? Maybe we could just have a 'get_user_pages_to_sgl' and 'put_pages_sgl' sort of interface that handled all this instead of trying to make something that is struct page based? It seems easier to get an extra bit for user/!user in the SGL datastructure? Jason