Received: by 10.213.65.68 with SMTP id h4csp2387964imn; Thu, 5 Apr 2018 14:10:06 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+2Mv02miLSnK1fx4uEW62o1kDzZVFF479OnFkhs9fym14OYXLw+R0Q+xL1J+9xf61WKHOk X-Received: by 10.101.86.141 with SMTP id v13mr15817491pgs.353.1522962606651; Thu, 05 Apr 2018 14:10:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522962606; cv=none; d=google.com; s=arc-20160816; b=wnedbg2pMQNJKCMefdqcOhi50i5KEUscRMTt5WBPItzInPjA+6++zXSa9BT5kdN2al sxY4xPecni9Jw6Esw+Emtb0gquuCFKiKSBMU/dVkc2kTApZh7X2DFezEJ+rb9liAIfP/ bsCVy6KKpxEctGKb8/2kU+rHlbELT+QQNOg3UmafJAS4KuwdAduk71XHd7iH1OX+Em7G H2koP63zKIuL5jI4mzeMGH5W7Hd1utChKYABCggd/oc5Cc2Ta3thRRgjOteUw/fRWmy3 8e+DUl0dGNcEM65wLpxwACjE9eFd9RT6M1DxxXXGKIZdolPAQ/5ao7ZPp5LK8jxxjZ2K MTpA== 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=JMEk+06bvvB5F2pZk6Ru+JYlsZXtzYdnFZz0wNLhOm4=; b=IbLHlzqhgW4tVx9XWQG8jL4118nvQEnkJi7LFvsUvutJGVJX67ir2Gejh2nX8LUZsd chV+xlDv04M3QlusmnNHrX+XXIxWAXd4uMiT+thGlIzL3dNIECZYKvt1Up46AQ1C8yyG 5RUOJBR8JPiuDf9n9EQ5W6EVPcILQKqwBRMBXgzlckE/rj90P6ZdM59dqOfiNS/82whf K9UiEmjZQgvQXPR6ZPO8FN0kWUbufsKBx6HO8dJJYMt04DLvYoQHUDhNAfViTFrOpSci 4Ry5TdSXoybwgxO8IUr71707S5LdNjRUw1UGjoU0ZbG0pVYruyIxXK6GvLhjeOGEU0MI ruXQ== 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 s76si6736735pfi.412.2018.04.05.14.09.51; Thu, 05 Apr 2018 14:10:06 -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 S1751417AbeDEVIM (ORCPT + 99 others); Thu, 5 Apr 2018 17:08:12 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:49514 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750726AbeDEVIK (ORCPT ); Thu, 5 Apr 2018 17:08:10 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 28CCC722C9; Thu, 5 Apr 2018 21:08: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 B86F0AB58A; Thu, 5 Apr 2018 21:08:08 +0000 (UTC) Date: Fri, 6 Apr 2018 00:08: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 Subject: Re: [PATCH] gup: return -EFAULT on access_ok failure Message-ID: <20180406000706-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.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 05 Apr 2018 21:08:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 05 Apr 2018 21:08:10 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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 For now I sent a patchset 1. documenting current behaviour for __get_user_pages_fast. 2. fixing get_user_pages_fast for consistency. -- MST