From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87E2AC433DF for ; Mon, 18 May 2020 21:37:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E805205CB for ; Mon, 18 May 2020 21:37:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589837847; bh=EUyWXexSsbz75cYmX07WWKXWXKLhqB/4DeEQtFnWqlw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:List-ID:From; b=C+NOtnWYzz6/eD1pqW34DPmfNc0e0X8uNJEXc5i4U0+cjyXC8hGKA3yUr6Ul8s8uU 2vEZmYzU1k9nb2oSF5W83CICrJbK99/LX13d80BP3AOlczfohJ6zPV2NdBevhJEbIf HM/d17e+/Zf9O2479VG8rxpacLpJ45vInOCBK8MU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726831AbgERVhY (ORCPT ); Mon, 18 May 2020 17:37:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:46884 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726443AbgERVhY (ORCPT ); Mon, 18 May 2020 17:37:24 -0400 Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A40E0205CB; Mon, 18 May 2020 21:37:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589837844; bh=EUyWXexSsbz75cYmX07WWKXWXKLhqB/4DeEQtFnWqlw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=qclqy01Zzf4awU5/li0KjuAMvhHjWCiNdgctP3bwqEBf4vQJFfodBIGCpmPtFzRls Rvpj8Pp410HK9Dr1ImCBroRyEMQB6QHNwINSZ+RfX6901h45KISoZbKZC2f78tJ4Ww l3VS3req8WcMjQPEhnHcvBAcxvSoxI6iGRfJDQeQ= Date: Mon, 18 May 2020 14:37:23 -0700 From: Andrew Morton To: John Hubbard Cc: LKML , Matt Porter , Alexandre Bounine , Sumit Semwal , Dan Carpenter , , Subject: Re: [PATCH 1/2] rapidio: fix an error in get_user_pages_fast() error handling Message-Id: <20200518143723.2c3159ddd53345b9cde5d869@linux-foundation.org> In-Reply-To: <20200517235620.205225-2-jhubbard@nvidia.com> References: <20200517235620.205225-1-jhubbard@nvidia.com> <20200517235620.205225-2-jhubbard@nvidia.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org On Sun, 17 May 2020 16:56:19 -0700 John Hubbard wrote: > In the case of get_user_pages_fast() returning fewer pages than > requested, rio_dma_transfer() does not quite do the right thing. > It attempts to release all the pages that were requested, rather > than just the pages that were pinned. > > Fix the error handling so that only the pages that were successfully > pinned are released. > > ... > > --- a/drivers/rapidio/devices/rio_mport_cdev.c > +++ b/drivers/rapidio/devices/rio_mport_cdev.c > @@ -877,6 +877,11 @@ rio_dma_transfer(struct file *filp, u32 transfer_mode, > rmcd_error("pinned %ld out of %ld pages", > pinned, nr_pages); > ret = -EFAULT; > + /* > + * Set nr_pages up to mean "how many pages to unpin, in > + * the error handler: > + */ > + nr_pages = pinned; > goto err_pg; > } The code is a bit odd. If (xfer->loc_addr == 0) then we do the `else' stuff then fall through to err_pg: if (!req->page_list) { for (i = 0; i < nr_pages; i++) put_page(page_list[i]); kfree(page_list); } all of which is a big no-op because nr_pages==0 and page_list==NULL, but it could all be easily avoided. Oh well. Reviewed-by:me.