Received: by 2002:a17:90a:bc8d:0:0:0:0 with SMTP id x13csp1496270pjr; Mon, 18 May 2020 14:41:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhuRGTvWD0B4l/lT+xzOWMeEKJ0D6V5vD5JCtzgcqZM/7r/MiioUEym6xTP+kEPPZra/3E X-Received: by 2002:aa7:c887:: with SMTP id p7mr15259901eds.269.1589838076115; Mon, 18 May 2020 14:41:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589838076; cv=none; d=google.com; s=arc-20160816; b=DQxmFNA8ROTCz0iZYea4v7puT0cca7YCoLSlmrzVymRnGfyJzFet/zIEE0+N9b9wrX 16SA9ZwYdM30KtVQwOKyGCCMCMT+ahhRb1TtIqoJkEG5+xnxJqJf97xC8QdttxIiPzeG 8hFQVGep5QHy60X9owqRxKSMOjHyQaiV1UDEvQlz1r81gmjNcuZFN7Mb1CkpUjSYHdPX tHWdBv+Clion5WxV5WRtqWbBcUhRQzvFqL0LoTQXLc76hDlx6+1/1ZecuKApjrFasLRS oahFso7W1dST9QB/stBwcVTIOQlGf6d/v7n9Yuthy32luu8JlFgGCYeh24Q4olueqxPg 3QfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=Ocd+L7IcS3nUM4lx9O9rmXfepbAqCtgO/fLMpuj6Aas=; b=tmBqHbU3ccCHX+UqLoW3tivCIVHrnDg3K1/FcyCZfrj1syCtbbw1hdhIq7f6/QPxYp MVkHBtQUZcl2vFFq9d0Z8F23u+XGZx0Uv7Ttzr7qw6OKYh6BvhHzigMJLo8WbACmZNet fShTmyoPtQRnJbBtUALb1IFadnks0GdZ0Horq+YUKg93SRTifqiFMgU8ZjRQ1t+6VOgb fAkIznHU0+J3/dGtsAWcbyNYAgAPUlN4e3DRObZRzzEcvvU70HOAtOV2s6HpCEQowYrt XaGSZ8kX+Ff5oV/j7e0/wNsPHYCycnaaKxthbRXjqoq8YTXxln4Cts0lzxsrMQYq//3F 33YA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qclqy01Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h12si7130057ejq.371.2020.05.18.14.40.52; Mon, 18 May 2020 14:41:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qclqy01Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727827AbgERVhY (ORCPT + 99 others); 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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.