Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp1467709pxt; Sat, 7 Aug 2021 11:47:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyoR0/gRNwIKDS05Ogl+ChnqVG2s9+9FnudkY6DsJcDuy5qNMewo38L6Bg7E5L9K+yDOOBj X-Received: by 2002:a92:dac6:: with SMTP id o6mr220810ilq.31.1628362063877; Sat, 07 Aug 2021 11:47:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628362063; cv=none; d=google.com; s=arc-20160816; b=NqQKkeowPn0fUYF9ae+gIkLAK6+vRA4vbflz1dYV6BpkBaoznTUgs7PzHF5iXhlDHU 7izcPmC8HT/twXUP+9b7yNeyonkbBNvU+4HSJln+UwA7W77929nsdtlx2CdPZjnD15La B5tj3T+rsYGOuFEqAXHyBV+525BdlvlJXIkUfL168+1Ua2OywytXmfpCs4jcMCv1CSU1 9VsDQ7dGdUq5VPD4LKQkCDSvzgdcAfwYOYgKUY13zc9y7eHV31RGmjS87N3H8V8ciTMP MpDl+WPXeKxSZHsUmWw3jWd/krl+tNwChRosau2RoNH+mhqm1wiufQSLx3u1SnNC6g5s dMHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:to:from:date :dkim-signature; bh=9PilfQSMPa/UbjjmwB+4dtsFS/CjHXTpnwaq5J01e1Y=; b=RZvoMf8EiqxQ7jopfeEKhJsgdhI+xmVdpoGV5WAtRsViui3i6XkCuIkGoggOX1YtTU h0D753kTd9ypO8dx42ov6PPAnxY6lj1ixXw53NsShw6AC+reCSFIQ9q3pNnX480/X/Sw k0IQ1Txmme0JoQv6QSdfBeODdfCek4l/i1wBee+7tzSKySp4DkBMuwGTuPO/muzZa/7B pH2otvMIfzQPmyQPDA1++uOY7wyOE1BLB4/Vp/piUt0si1xaILYENZOwuMmaPkF+stjk 4xxq72E2h+avFOyWPBoI9NataLrOwJGrGhmoocivPoRhin6oTom4ZCP/IILTig7VXdcN nfBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=ZWbhHPbY; 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 x26si1890223jai.112.2021.08.07.11.47.32; Sat, 07 Aug 2021 11:47:43 -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=@linux-foundation.org header.s=korg header.b=ZWbhHPbY; 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 S229562AbhHGSqF (ORCPT + 99 others); Sat, 7 Aug 2021 14:46:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:44552 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229464AbhHGSqF (ORCPT ); Sat, 7 Aug 2021 14:46:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 82D0E6105A; Sat, 7 Aug 2021 18:45:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1628361946; bh=63Jc6H88mizk3nUpvFQNU59wRQKIju43S/xVoUsb28w=; h=Date:From:To:Subject:In-Reply-To:References:From; b=ZWbhHPbYrBKKHHFzhGRwXYCeGqFdPaIIKIrm9PmOPVIqDUA/RVrG8O/yz83O6F3KD QRrxUlQBmg/CXG6xr3202Tv/cNOVgHOIIfdCOCvD+4dXrEXHGhp+8Pk1jO0kra1SVh I2gTaRiKRkukwEy0BUnEDBYVxjkmEj8f3oplpCvU= Date: Sat, 7 Aug 2021 11:45:45 -0700 From: Andrew Morton To: Miaohe Lin , , , , , , Subject: Re: [PATCH 4/5] mm: gup: fix potential pgmap refcnt leak in __gup_device_huge() Message-Id: <20210807114545.eaee318909a9215c4e056aa3@linux-foundation.org> In-Reply-To: <20210807114112.6e45b31c65dd62169fee8718@linux-foundation.org> References: <20210807093620.21347-1-linmiaohe@huawei.com> <20210807093620.21347-5-linmiaohe@huawei.com> <20210807114112.6e45b31c65dd62169fee8718@linux-foundation.org> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 7 Aug 2021 11:41:12 -0700 Andrew Morton wrote: > We can simplify further, and remove the troublesome multiple return points? > oops. --- a/mm/gup.c~mm-gup-fix-potential-pgmap-refcnt-leak-in-__gup_device_huge-fix-fix +++ a/mm/gup.c @@ -2240,6 +2240,7 @@ static int __gup_device_huge(unsigned lo { int nr_start = *nr; struct dev_pagemap *pgmap = NULL; + int ret = 1; do { struct page *page = pfn_to_page(pfn); @@ -2247,12 +2248,14 @@ static int __gup_device_huge(unsigned lo pgmap = get_dev_pagemap(pfn, pgmap); if (unlikely(!pgmap)) { undo_dev_pagemap(nr, nr_start, flags, pages); + ret = 0; break; } SetPageReferenced(page); pages[*nr] = page; if (unlikely(!try_grab_page(page, flags))) { undo_dev_pagemap(nr, nr_start, flags, pages); + ret = 0; break; } (*nr)++; @@ -2260,7 +2263,7 @@ static int __gup_device_huge(unsigned lo } while (addr += PAGE_SIZE, addr != end); put_dev_pagemap(pgmap); - return 1; + return ret; } static int __gup_device_huge_pmd(pmd_t orig, pmd_t *pmdp, unsigned long addr, Not sure if it's worth bothering, really...