Received: by 10.192.165.156 with SMTP id m28csp277628imm; Tue, 17 Apr 2018 10:00:05 -0700 (PDT) X-Google-Smtp-Source: AIpwx49/FFaZK+N51OcMeIh7IuGuqTaliamMYQLgbkxTjncVWOlhynsVEbs8fA0NHabMCQ57iZBd X-Received: by 10.98.59.24 with SMTP id i24mr2191226pfa.246.1523984405818; Tue, 17 Apr 2018 10:00:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523984405; cv=none; d=google.com; s=arc-20160816; b=bkIIXhjOyjrVAwjJGgSkqFgBhZc0hwYVY1u0ZeiZjTXlMlbhrGjJsJz2XREb6ayE18 bhT6/HMeldCb9AT0S3ypiTdFcHRS855Pq3UcHHKpvh4u2x77e2zhsUN0hwNMR3gN7wd4 XqMu9Qgnej2D6k6/ChX3mRO+7ySnlO0wDOlKVjMZdjRjmHTKpenruBkdpiCS2mZ4n0Rk NhhIg/pBBPvRP+aDDMRyxFnekqGsx9Un5F+z/wdkks9hakaY2nJ/AKhBLhwn656Cf4n6 w6NKB4QzhJZLTvXW6bml/2RrPyYgtIK9SAx4HJ0wXOjxpExdvSCuWX+wXWzB9BUbzi1+ 66zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=qxznT3jt8kVxh2Fp+zdVJ3m3TFLhMnw/58hCfiQET0g=; b=F65fsRBfrwC/9GQappaFVBws2HYMC0qs1SWOe8vi2Rf5s+75AuaGFLC9mK829xOlmX +VhyxTDVY7hsI9FLxr2i0+UggUA/E3JnaPbK9cweZGnwh1Cfolq8TjfbLVjAxO5d0aPP OtvJJviaucnafW5IKRDou13r3WZz/AXXJTFcSIsJMYTQJDCjrzJ65UWwEL/AkFbwZJ21 o1g97SwAQk7wU2Qee9SkcnPYOIvqduX/3EJe88n0YV9SpNyArOrA0NryudvgZlwdDtUY yCsbmBucJlOqom45D17P/Xusg0Rbq4hKZHcC30iTSSlSFOB6smtjru0+8NAtAtxs8SGA lZfw== 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 1si13429801pfq.172.2018.04.17.09.59.51; Tue, 17 Apr 2018 10:00:05 -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 S1754240AbeDQQ6L (ORCPT + 99 others); Tue, 17 Apr 2018 12:58:11 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:60966 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753526AbeDQQCz (ORCPT ); Tue, 17 Apr 2018 12:02:55 -0400 Received: from localhost (unknown [46.44.180.42]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 1842BE98; Tue, 17 Apr 2018 16:02:54 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Michael S. Tsirkin" , Andrew Morton , "Kirill A. Shutemov" , Huang Ying , Jonathan Corbet , Peter Zijlstra , Thomas Gleixner , Thorsten Leemhuis , Linus Torvalds Subject: [PATCH 4.16 64/68] mm/gup_benchmark: handle gup failures Date: Tue, 17 Apr 2018 17:58:17 +0200 Message-Id: <20180417155751.942473855@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180417155749.341779147@linuxfoundation.org> References: <20180417155749.341779147@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michael S. Tsirkin commit 09e35a4a1ca8b9988ca9b8557d17948cd6c0808b upstream. Patch series "mm/get_user_pages_fast fixes, cleanups", v2. Turns out get_user_pages_fast and __get_user_pages_fast return different values on error when given a single page: __get_user_pages_fast returns 0. get_user_pages_fast returns either 0 or an error. Callers of get_user_pages_fast expect an error so fix it up to return an error consistently. Stress the difference between get_user_pages_fast and __get_user_pages_fast to make sure callers aren't confused. This patch (of 3): __gup_benchmark_ioctl does not handle the case where get_user_pages_fast fails: - a negative return code will cause a buffer overrun - returning with partial success will cause use of uninitialized memory. [akpm@linux-foundation.org: simplification] Link: http://lkml.kernel.org/r/1522962072-182137-3-git-send-email-mst@redhat.com Signed-off-by: Michael S. Tsirkin Reviewed-by: Andrew Morton Cc: Kirill A. Shutemov Cc: Huang Ying Cc: Jonathan Corbet Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Thorsten Leemhuis Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/gup_benchmark.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/mm/gup_benchmark.c +++ b/mm/gup_benchmark.c @@ -23,7 +23,7 @@ static int __gup_benchmark_ioctl(unsigne struct page **pages; nr_pages = gup->size / PAGE_SIZE; - pages = kvmalloc(sizeof(void *) * nr_pages, GFP_KERNEL); + pages = kvzalloc(sizeof(void *) * nr_pages, GFP_KERNEL); if (!pages) return -ENOMEM; @@ -41,6 +41,8 @@ static int __gup_benchmark_ioctl(unsigne } nr = get_user_pages_fast(addr, nr, gup->flags & 1, pages + i); + if (nr <= 0) + break; i += nr; } end_time = ktime_get();