Received: by 10.213.65.68 with SMTP id h4csp2311516imn; Thu, 5 Apr 2018 12:41:47 -0700 (PDT) X-Google-Smtp-Source: AIpwx493kt80N2q/GRxAk1M6lGeyOWSic3O9C0ZogrSzQ2fs5g+jfoVDuMCtnDhV0Xh43H8s6wcc X-Received: by 10.99.107.196 with SMTP id g187mr7035253pgc.384.1522957307388; Thu, 05 Apr 2018 12:41:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522957307; cv=none; d=google.com; s=arc-20160816; b=j6VMbocynEjVwxnmmzxx/a7Wb8kLKg2QHyg1Nqwb+/GON44dGYlckzjvYWbx05ZlY5 K3PpOkNqc2x8dcGvqk7Qeh5beBiSjEVIDqO7V0WvHYCKSkIbZnXp6LiY/an13i6d2jX1 5cLBoO4Cr6fF5swTh/9Yrp5JrQmEDdEkacuYRt2wVMD+UItrTvZjj9ah4yfLiLDcI96i 0qa+gAecgC75l/Ms87MnUsuQZHOaXkPgq7MfwDTvVO6UMJD0qiGJFLM+ITq+772Gqd2g czVYcCKVB12pDkCaGCb5zabMo1eTSvxCqY0JWCzV9WV+uOxStfcn9oy7JDEG8lRRSQww UxPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:subject:user-agent:message-id :references:cc:in-reply-to:from:to:content-transfer-encoding :mime-version:arc-authentication-results; bh=aF0SXRaPnYrChkz1v4SE8NrOmk7Qy6Z41bkVGYL9edU=; b=iBxU/pR5/Z8flfvP7Kk+FrSRpfA15hCzs5lWHn1WNkwnXuidLOzhtrZqcCgrT7jgyj V0YZgPTyWNX/X6zWsDQpDpfj5BpEnxy/DqtoSN7KL+rv6qlF+nNGxavsneP+3ymt/h/L VLRxUg67MVxXGy9ssBJHbFEJeSXeeSvFk5xKJXCbk8f9Rsx0XVgHV8VBw3PY0uhJhHFj odQ3MC+67c973TxdvCG/UXfIAovEZ4GYob7C8gXLlaCrBmdV+0fYwAf382ybuEMwUBbW kEHoz3eUAHA0XyI88NvTIH0vPChHhpG1F7q7ZxOuiS2kj2ur0nq8iHdC23DFlJeBSoSP mWug== 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 x6si5981954pgc.57.2018.04.05.12.41.32; Thu, 05 Apr 2018 12:41:47 -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 S1752615AbeDETkZ convert rfc822-to-8bit (ORCPT + 99 others); Thu, 5 Apr 2018 15:40:25 -0400 Received: from mail.fireflyinternet.com ([109.228.58.192]:55484 "EHLO fireflyinternet.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751952AbeDETkX (ORCPT ); Thu, 5 Apr 2018 15:40:23 -0400 X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from localhost (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP (TLS) id 11276298-1500050 for multiple; Thu, 05 Apr 2018 20:39:34 +0100 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT To: "Michael S. Tsirkin" , "Linus Torvalds" From: Chris Wilson In-Reply-To: <20180405215744-mutt-send-email-mst@kernel.org> Cc: "Al Viro" , "Linux Kernel Mailing List" , "stable" , syzbot+6304bf97ef436580fede@syzkaller.appspotmail.com, "linux-mm" , "Kirill A. Shutemov" , "Andrew Morton" , "Huang Ying" , "Jonathan Corbet" , "Peter Zijlstra" , "Thomas Gleixner" , "Thorsten Leemhuis" , "Tvrtko Ursulin" , "Gong, Zhipeng" , "Akash Goel" , "Volkin, Bradley D" , "Daniel Vetter" References: <1522431382-4232-1-git-send-email-mst@redhat.com> <20180405045231-mutt-send-email-mst@kernel.org> <20180405171009-mutt-send-email-mst@kernel.org> <20180405211945-mutt-send-email-mst@kernel.org> <20180405215744-mutt-send-email-mst@kernel.org> Message-ID: <152295717252.23264.15314297102427001125@mail.alporthouse.com> User-Agent: alot/0.3.6 Subject: Re: [PATCH] gup: return -EFAULT on access_ok failure Date: Thu, 05 Apr 2018 20:39:32 +0100 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Michael S. Tsirkin (2018-04-05 20:34:08) > On Thu, Apr 05, 2018 at 11:43:27AM -0700, Linus Torvalds wrote: > > On Thu, Apr 5, 2018 at 11:28 AM, Michael S. Tsirkin wrote: > > > > > > to repeat what you are saying IIUC __get_user_pages_fast returns 0 if it can't > > > pin any pages and that is by design. Returning 0 on error isn't usual I think > > > so I guess this behaviour should we well documented. > > > > Arguably it happens elsewhere too, and not just in the kernel. > > "read()" at past the end of a file is not an error, you'll just get 0 > > for EOF. > > > > So it's not really "returning 0 on error". > > > > It really is simply returning the number of pages it got. End of > > story. That number of pages can be smaller than the requested number > > of pages, and _that_ is due to some error, but note how it can return > > "5" on error too - you asked for 10 pages, but the error happened in > > the middle! > > > > So the right way to check for error is to bverify that you get the > > number of pages that you asked for. If you don't, something bad > > happened. > > > > Of course, many users don't actually care about "I didn't get > > everything". They only care about "did I get _something_". Then that 0 > > ends up being the error case, but note how it depends on the caller. > > > > > What about get_user_pages_fast though? > > > > We do seem to special-case the first page there. I'm not sure it's a > > good idea. But like the __get_user_pages_fast(), we seem to have users > > that know about the particular semantics and depend on it. > > > > It's all ugly, I agree. > > > > End result: we can't just change semantics of either of them. > > > > At least not without going through every single user and checking that > > they are ok with it. > > > > Which I guess I could be ok with. Maybe changing the semantics of > > __get_user_pages_fast() is acceptable, if you just change it > > *everywhere* (which includes not just he users, but also the couple of > > architecture-specific versions of that same function that we have. > > > > Linus > > OK I hope I understood what you are saying here. > > At least drivers/gpu/drm/i915/i915_gem_userptr.c seems to > get it wrong: > > pinned = __get_user_pages_fast(obj->userptr.ptr, > > if (pinned < 0) { > pages = ERR_PTR(pinned); > pinned = 0; > } else if (pinned < num_pages) { > pages = __i915_gem_userptr_get_pages_schedule(obj); > active = pages == ERR_PTR(-EAGAIN); > } else { > pages = __i915_gem_userptr_alloc_pages(obj, pvec, num_pages); > active = !IS_ERR(pages); > } > > The <0 path is never taken. Please note that it only recently lost other paths that set an error beforehand. Not exactly wrong since the short return is expected and handled. > Cc maintainers - should that driver be changed to use > get_user_pages_fast? It's not allowed to fault. __gup_fast has that comment, gup_fast does not. -Chris