LKML Archive on lore.kernel.org help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk> To: "Michael S. Tsirkin" <mst@redhat.com>, "Linus Torvalds" <torvalds@linux-foundation.org> Cc: "Al Viro" <viro@zeniv.linux.org.uk>, "Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>, "stable" <stable@vger.kernel.org>, syzbot+6304bf97ef436580fede@syzkaller.appspotmail.com, "linux-mm" <linux-mm@kvack.org>, "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>, "Andrew Morton" <akpm@linux-foundation.org>, "Huang Ying" <ying.huang@intel.com>, "Jonathan Corbet" <corbet@lwn.net>, "Peter Zijlstra" <peterz@infradead.org>, "Thomas Gleixner" <tglx@linutronix.de>, "Thorsten Leemhuis" <regressions@leemhuis.info>, "Tvrtko Ursulin" <tvrtko.ursulin@linux.intel.com>, "Gong, Zhipeng" <zhipeng.gong@intel.com>, "Akash Goel" <akash.goel@intel.com>, "Volkin, Bradley D" <bradley.d.volkin@intel.com>, "Daniel Vetter" <daniel.vetter@ffwll.ch> Subject: Re: [PATCH] gup: return -EFAULT on access_ok failure Date: Thu, 05 Apr 2018 20:39:32 +0100 [thread overview] Message-ID: <152295717252.23264.15314297102427001125@mail.alporthouse.com> (raw) In-Reply-To: <20180405215744-mutt-send-email-mst@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 <mst@redhat.com> 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
next prev parent reply other threads:[~2018-04-05 19:40 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top [not found] <1522431382-4232-1-git-send-email-mst@redhat.com> 2018-04-05 1:53 ` [PATCH] gup: return -EFAULT on access_ok failure Michael S. Tsirkin 2018-04-05 2:40 ` Linus Torvalds 2018-04-05 14:17 ` Michael S. Tsirkin 2018-04-05 15:40 ` Linus Torvalds 2018-04-05 18:28 ` Michael S. Tsirkin 2018-04-05 18:43 ` Linus Torvalds 2018-04-05 19:34 ` Michael S. Tsirkin 2018-04-05 19:39 ` Chris Wilson [this message] 2018-04-05 21:08 ` Michael S. Tsirkin 2018-04-06 11:35 ` Alan Cox
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=152295717252.23264.15314297102427001125@mail.alporthouse.com \ --to=chris@chris-wilson.co.uk \ --cc=akash.goel@intel.com \ --cc=akpm@linux-foundation.org \ --cc=bradley.d.volkin@intel.com \ --cc=corbet@lwn.net \ --cc=daniel.vetter@ffwll.ch \ --cc=kirill.shutemov@linux.intel.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=mst@redhat.com \ --cc=peterz@infradead.org \ --cc=regressions@leemhuis.info \ --cc=stable@vger.kernel.org \ --cc=syzbot+6304bf97ef436580fede@syzkaller.appspotmail.com \ --cc=tglx@linutronix.de \ --cc=torvalds@linux-foundation.org \ --cc=tvrtko.ursulin@linux.intel.com \ --cc=viro@zeniv.linux.org.uk \ --cc=ying.huang@intel.com \ --cc=zhipeng.gong@intel.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).