Received: by 10.213.65.68 with SMTP id h4csp2306516imn; Thu, 5 Apr 2018 12:35:42 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+5JrD2qlor534b1udqw/RpBzqRH2QBxdqgZhQAvA5SVYW4UwdXgluJtuV4JuHs+gTuRCuw X-Received: by 2002:a17:902:9001:: with SMTP id a1-v6mr23532202plp.211.1522956942185; Thu, 05 Apr 2018 12:35:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522956942; cv=none; d=google.com; s=arc-20160816; b=nT84jhK+n4N2jmi3YF/uHIvwmrAZRYrr2hLJk+s6s6rGVNMcZzx0i28NzAzYbU1Qls GdlSbCe5GRtZCE4zRUwckJK/nh5JJMST5JJDkPxwEMtse2rV5yRf5cdTYz84zaL+h6n4 LdNYTVvbvqrKrx0qqVXtnVCkYtp+ZvHvA8LqCxiKbnkuGPZomZVriyYcC3RXfJlXgWNZ rsu9CXlIHd4lkQiqeRlS6GRDZby8dvZwPH9YaWsYpxTV/2UxRet7J4P+13GJ+5UrRUm7 w0Sf1+6zQNj3EuxX8R0wCGL39zgf71wE9iQmow/KZYFEoZ58DvCP0jHFwKC6lWypS8VD crkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=eynfkmC9OUyXRHyCdcvpEvTsm8/LN+BjjTPSe7yhnng=; b=HCZZXgbZA6fscuMhYXXfLu3o5mmX5Z11Pzk0dmzmVUpxoPTGjpH9SvgZuc9jwOggCq lCEetlflK1tSny4lWLTqmHkWUkzHaXJ6NnKUBfY4LlKOpmb7bFxHieodL2RJOHXf7KIf F4iYmEqYcO8hw5I7OTDJQVww3aRVcxm6hABNZeV1T0QWr9kfP1kiC8dbRXf4A1GqzWe2 41og6MfxQ+s8hr5V1FeQJtGEN0ppysA0PjrBaMM/Kei+6Zo/iIX4EbKLZHqD2Ctnpc7v TK1ZfNbDpMWucjw4dX0NAsvNuRtiBdbZk8L/mtyIQDWiPSTekTNLn2hH5E9B8nBuURxQ Di3w== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r138si5925802pgr.84.2018.04.05.12.35.27; Thu, 05 Apr 2018 12:35:42 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752506AbeDETeM (ORCPT + 99 others); Thu, 5 Apr 2018 15:34:12 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45574 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751932AbeDETeK (ORCPT ); Thu, 5 Apr 2018 15:34:10 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0668F722F2; Thu, 5 Apr 2018 19:34:10 +0000 (UTC) Received: from redhat.com (ovpn-122-62.rdu2.redhat.com [10.10.122.62]) by smtp.corp.redhat.com (Postfix) with SMTP id 3829A2026980; Thu, 5 Apr 2018 19:34:08 +0000 (UTC) Date: Thu, 5 Apr 2018 22:34:08 +0300 From: "Michael S. Tsirkin" To: Linus Torvalds 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 , Chris Wilson , Tvrtko Ursulin , "Gong, Zhipeng" , Akash Goel , "Volkin, Bradley D" , Daniel Vetter Subject: Re: [PATCH] gup: return -EFAULT on access_ok failure Message-ID: <20180405215744-mutt-send-email-mst@kernel.org> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 05 Apr 2018 19:34:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 05 Apr 2018 19:34:10 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mst@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Cc maintainers - should that driver be changed to use get_user_pages_fast?