Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp4494025ybf; Wed, 4 Mar 2020 05:09:27 -0800 (PST) X-Google-Smtp-Source: ADFU+vu+rADAjwXjumzTFkzivDeKw3a6TbCEAWTNv26rW2fAvA0EE30MFL2KqnEw3xkSrvhJ4CU+ X-Received: by 2002:aca:c78e:: with SMTP id x136mr1657862oif.116.1583327367719; Wed, 04 Mar 2020 05:09:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583327367; cv=none; d=google.com; s=arc-20160816; b=RyGUu/0BrMmtIc9TAFbqEN+TROThgyHjmz53bdvEtrbuGfxkJEXnu4rCpLB43gOwkX BpzhzM1E9da50EMXLVD4npxoenW56Vb3qrB9N6goxEwGkh5yVAzt4Z/evhqHzejGjeWm MLXg5dyJn1M23WvirnZuFgwnp+joFzljwTszB7eBlQQgy5dY+aJ1KWa63ZOoYwg0G6ng IOYaX/+zMTAzCO2+syb04Sd4CBX/UCt1q4X8LSnu6u4+ARi/p7bOb3JrMTiA04KpGcp6 F0uBD+wiyA0raJEE5E8DVCTZBB1e0RjSBNmmdj1jZ5dCreGlos5PXbgP+6YQoQPRd8hf uXHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :mime-version:references:in-reply-to:date:subject:cc:to:from; bh=rTJBoXzcRp136JbJ+mWfuUIzGHfbQgwSw9fR3l0UPNI=; b=EPN1AvVMPI6R1gMdlfGc1uO8RPwYfMdHy+dyfnwY1aNE/pV5pVitd+JvmEA7lualc6 K2szjZxbeGsRi5zRZaGmlAH5JoZalQSxsOGnYbRxlB7XrEO0YIcUoGK5YYHmv1x0Mgb+ U3qkq91VN+EEOeNOWWg5kTrMdnFtfstwafuG51Hbs2JnmY1ervSqeSw2tz/4Yw9fNDST 4fPDh280vYZoynWYFdlDgJu5v8mt9UzRoJML2WRd4BpCdVSc6Qj42t1CQ1+OvpVM4HiZ /UwaOywdhpVUWyKso+3scC5di2GtC2fn1kqLUBKNxCw7NF4bQRlNroCG8Vqh8w/vmXrO d+kw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 5si1033684otr.108.2020.03.04.05.09.13; Wed, 04 Mar 2020 05:09:27 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388136AbgCDNHQ (ORCPT + 99 others); Wed, 4 Mar 2020 08:07:16 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:11550 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387776AbgCDNHQ (ORCPT ); Wed, 4 Mar 2020 08:07:16 -0500 Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 024D6TjR177025 for ; Wed, 4 Mar 2020 08:07:14 -0500 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0a-001b2d01.pphosted.com with ESMTP id 2yfmg2gjgh-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 04 Mar 2020 08:07:13 -0500 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 4 Mar 2020 13:07:04 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp04.uk.ibm.com (192.168.101.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 4 Mar 2020 13:07:00 -0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 024D6x1V52756676 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 4 Mar 2020 13:06:59 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4EFC042041; Wed, 4 Mar 2020 13:06:59 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id ACE304203F; Wed, 4 Mar 2020 13:06:58 +0000 (GMT) Received: from localhost.localdomain (unknown [9.145.0.1]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 4 Mar 2020 13:06:58 +0000 (GMT) From: Claudio Imbrenda To: linux-next@vger.kernel.org, akpm@linux-foundation.org, jack@suse.cz, kirill@shutemov.name Cc: borntraeger@de.ibm.com, david@redhat.com, aarcange@redhat.com, linux-mm@kvack.org, frankja@linux.ibm.com, sfr@canb.auug.org.au, jhubbard@nvidia.com, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org Subject: [PATCH v3 1/2] mm/gup: fixup for 9947ea2c1e608e32 "mm/gup: track FOLL_PIN pages" Date: Wed, 4 Mar 2020 14:06:54 +0100 X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200304130655.462517-1-imbrenda@linux.ibm.com> References: <20200304130655.462517-1-imbrenda@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 20030413-0016-0000-0000-000002ED1A6F X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20030413-0017-0000-0000-000033506807 Message-Id: <20200304130655.462517-2-imbrenda@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-03-04_05:2020-03-04,2020-03-04 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 clxscore=1015 lowpriorityscore=0 malwarescore=0 adultscore=0 suspectscore=0 priorityscore=1501 spamscore=0 mlxscore=0 bulkscore=0 phishscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2003040099 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In case pin fails, we need to unpin, a simple put_page will not be enough fixup for commit 9947ea2c1e608e32 ("mm/gup: track FOLL_PIN pages") it can be simply squashed in Signed-off-by: Claudio Imbrenda --- mm/gup.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index f589299b0d4a..81a95fbe9901 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -116,6 +116,28 @@ static __maybe_unused struct page *try_grab_compound_head(struct page *page, return NULL; } +static void put_compound_head(struct page *page, int refs, unsigned int flags) +{ + if (flags & FOLL_PIN) { + mod_node_page_state(page_pgdat(page), NR_FOLL_PIN_RELEASED, + refs); + + if (hpage_pincount_available(page)) + hpage_pincount_sub(page, refs); + else + refs *= GUP_PIN_COUNTING_BIAS; + } + + VM_BUG_ON_PAGE(page_ref_count(page) < refs, page); + /* + * Calling put_page() for each ref is unnecessarily slow. Only the last + * ref needs a put_page(). + */ + if (refs > 1) + page_ref_sub(page, refs - 1); + put_page(page); +} + /** * try_grab_page() - elevate a page's refcount by a flag-dependent amount * @@ -2134,7 +2156,7 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end, goto pte_unmap; if (unlikely(pte_val(pte) != pte_val(*ptep))) { - put_page(head); + put_compound_head(head, 1, flags); goto pte_unmap; } @@ -2267,28 +2289,6 @@ static int record_subpages(struct page *page, unsigned long addr, return nr; } -static void put_compound_head(struct page *page, int refs, unsigned int flags) -{ - if (flags & FOLL_PIN) { - mod_node_page_state(page_pgdat(page), NR_FOLL_PIN_RELEASED, - refs); - - if (hpage_pincount_available(page)) - hpage_pincount_sub(page, refs); - else - refs *= GUP_PIN_COUNTING_BIAS; - } - - VM_BUG_ON_PAGE(page_ref_count(page) < refs, page); - /* - * Calling put_page() for each ref is unnecessarily slow. Only the last - * ref needs a put_page(). - */ - if (refs > 1) - page_ref_sub(page, refs - 1); - put_page(page); -} - #ifdef CONFIG_ARCH_HAS_HUGEPD static unsigned long hugepte_addr_end(unsigned long addr, unsigned long end, unsigned long sz) -- 2.24.1