Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1948039imm; Thu, 11 Oct 2018 02:29:50 -0700 (PDT) X-Google-Smtp-Source: ACcGV63zwhvyOUQ4WmqnONsyO/Q3r1hHqpSqCAHDc8Cv9my3I0zz3dffRXAxZzC/NpgiHvr7AFvh X-Received: by 2002:a63:145f:: with SMTP id 31-v6mr702742pgu.35.1539250190180; Thu, 11 Oct 2018 02:29:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539250190; cv=none; d=google.com; s=arc-20160816; b=mi1Un4ShIgRFrE9iwbpsM4/dp5O9nlGBgkFRLY47Rnb6OcrnCnyFkzhH8O6AY6M45N wGW3uK7aIuRRs9R7HaWKtOwidbfLGGUetjZgI+sWcTN6Mc120nu1mP5JopFyyHzPGOOm BPaWS+MvhJuTN0DqVVTWQamJg1JUP2+M5st7tkHtwdPYz5V0nvfDbDHTnIdVeTX29y5o vYmAAeXyt5Y/TBjbFbNxJdWK07FT441cYv/C1YjnBAT707McKBe8a3ECNDFKY43Dr+lF 0oYLbaKXeOXLqTSEztWSnB+OkqlB1P+xo+cYlgKE7AOcExyf0sQrS67UFs8XFz1WCtgI vi/A== 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=8ChKRcyc7ggiyffUTQrDDQNDYdiS24xv6wZ49e9dfMY=; b=UnGw9wGl4QJ/k34Fdhu2X9EIxlvGEVO5YpiDq7AYOkziVWxqvNil6sd9s2AxSvoDa4 i8ZNGsCXSpY2mZ451twRTGF3UaqPtbPsekmU0XogpL0+5/gqlPWKZKXP2nbpdmCgFgFT KSc36sUoDP+aAJRbwrB8fUuO2JuILTIF49qh8FwkkB2pOA/C2GYHvX/+V5sORFHuyucO iLDLw34PeVzI5zc5sCAkdSYw7ymaaTL+Gj86rivfuV3BPHK+LV3Df/HE8MJIRk/N3XSn 9Qhmo4ReFdJD9YSLqSEhnEWoQtVA9UB+9lOHFTH1cG9LrMzIAqSoo7LH6nkGTIrlDZja xhTw== 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 e3-v6si27026070pga.369.2018.10.11.02.29.35; Thu, 11 Oct 2018 02:29:50 -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 S1727949AbeJKQPu (ORCPT + 99 others); Thu, 11 Oct 2018 12:15:50 -0400 Received: from mx2.suse.de ([195.135.220.15]:35198 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726223AbeJKQPt (ORCPT ); Thu, 11 Oct 2018 12:15:49 -0400 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 0231EB14B; Thu, 11 Oct 2018 08:49:30 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 68E741E3616; Thu, 11 Oct 2018 10:49:29 +0200 (CEST) Date: Thu, 11 Oct 2018 10:49:29 +0200 From: Jan Kara To: Andrew Morton Cc: John Hubbard , john.hubbard@gmail.com, Matthew Wilcox , Michal Hocko , Christopher Lameter , Jason Gunthorpe , Dan Williams , Jan Kara , 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: <20181011084929.GB8418@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181010164541.ec4bf53f5a9e4ba6e5b52a21@linux-foundation.org> 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 Wed 10-10-18 16:45:41, Andrew Morton wrote: > On Tue, 9 Oct 2018 17:42:09 -0700 John Hubbard wrote: > > > > 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? > > > > > > > It might be possible to do a few run-time checks, such as "does page that came > > back to put_user_page() have the correct flags?", but it's harder (without > > having a dedicated page flag) to detect the other direction: "did someone page > > in a get_user_pages page, to put_page?" > > > > As Jan said in his reply, converting get_user_pages (and put_user_page) to > > work with a new data type that wraps struct pages, would solve it, but that's > > an awfully large change. Still...given how much of a mess this can turn into > > if it's wrong, I wonder if it's worth it--maybe? > > 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... Honza -- Jan Kara SUSE Labs, CR