Received: by 10.192.165.156 with SMTP id m28csp266510imm; Tue, 17 Apr 2018 09:48:19 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+RMKJ1TSFfnFt6/JKJ4I6Y6hV/xpVsNe9PZ0VUQSNTWBMvMjQPH1SZJxK4h71HmwDp1YXk X-Received: by 10.98.83.199 with SMTP id h190mr2639892pfb.146.1523983699138; Tue, 17 Apr 2018 09:48:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523983699; cv=none; d=google.com; s=arc-20160816; b=NkLrGHdGMwqf9rXNYMiyJtjOmP4XWiz7ZDprGpJOQcwHCmUVcrkKp7zTSj6YdX097X dZgYY7iapdQV1kL4h5IehWN6zxspUwn2sY7/iXMBR0fjvS18d/9hQT109G4BaYIH+GfV k8Mt2IA8xYp1fr8rf7XtdocKLlUR84KxEjfKLAXn6m0oL0jazKzOSWe2zwevYJ8TnpuH tF++uw8+kjsNJMxWR+5/tLvFw3TpUHFqTGejAJMa37tv0l2Nr1bEtfasiJtpIqeWa+3C SVSrBJMo0oAd9YqNW44O7tc0mMUToyveWcS8p7fTL8kHUaN9GeOSYo9qgWeVVKggmyEH hvcg== 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=9Hqi5ssF5i9sN2syXwMJaQAWbkX711AB0NYywtZUUyg=; b=kkh549IgvbE4k6wmxPhYTAg6usLerV/s4uLMTYpCWT9lY4xHpUCvwdq/s0bNHWOcRU SOA6fkXJzyEBqa7iS8wbuyX1OI9sBNOI0O3Is1K7kDCaWw6mkGJh9iPfEiHgqP5Krq2G Qm65o7lG8zIy9p/3LgprBOfFwESgci5ucOFpul71YvApR8CmaFvJYZ91LTqUi9PjeC2k /AmgMSLB7+ViFDYHKt3q7ACFVG7qWUnvGbPiY0n/0ucpmdHCHO0ARLOrl9MqHfrIw0za bClPesVMSWVr/EwuHqw0Vyglx9gJrBxH5wIOtzd3eXf0Ue+98v2vrUIQSnDt/KdNreBY yG3w== 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 e12si11704541pgn.339.2018.04.17.09.48.04; Tue, 17 Apr 2018 09:48:19 -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 S1754494AbeDQQpc (ORCPT + 99 others); Tue, 17 Apr 2018 12:45:32 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34608 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754473AbeDQQFf (ORCPT ); Tue, 17 Apr 2018 12:05:35 -0400 Received: from localhost (unknown [46.44.180.42]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 01681E38; Tue, 17 Apr 2018 16:05:35 +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.15 48/53] mm/gup_benchmark: handle gup failures Date: Tue, 17 Apr 2018 17:59:13 +0200 Message-Id: <20180417155725.410047334@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180417155723.091120060@linuxfoundation.org> References: <20180417155723.091120060@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.15-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();