Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp6831346ybf; Fri, 6 Mar 2020 05:26:28 -0800 (PST) X-Google-Smtp-Source: ADFU+vvUxLdOSlwVQ5tuvPPB5KgJMphDwoECSUtEiGw/F/AM6Y+JyxHbGY7gjxA7hi4ddIcswyfE X-Received: by 2002:a05:6830:616:: with SMTP id w22mr2423771oti.215.1583501188363; Fri, 06 Mar 2020 05:26:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583501188; cv=none; d=google.com; s=arc-20160816; b=fwrwqCJ3XQVWrAmqYeBHza16LN5LkdlW+JVv7B8xCfufpJDK8eO2ZC4IUDIZrj1GiO gTVh/guf0ns7qphAgxlv4rZkVx6kvWgsK+44+Q3j6o1j7/+OwFQVSw1CTerfgLrAKgxT 0JAjayFI/dTXBQsS5r5aZC0/dkWyJGmg7iLutNf45T5dsbZ48lZO/CLO17xujPV7NQj2 /vMeIzMdAWTDjBQheu+QbM9k6rKoIMpfS3gIdHykL1P6zSXCWvmlToS9Syt9nIQsd16y 9FEQRZoF2NigWbJI/Y5qaFD8zDpzhMQ4HuFgi6coD9kcBBfb5HdLkKqtOn496fmDguEf Uksw== 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=OHZq2wVztye/ZbhaQE2ngK66imeHtner3o3w1rx+zX0=; b=ayyE6yZHEI0rCEu71sVOpIe4QbI+gOOH7RujNmn4Wvlro1PsUZGcOdppDHRsDIp5Qx +mBszAr+UuGn95UiCwFOG8LM88jyWKCddVzzQ7mHUrwGCbMydQd7xKepcLSa+gpZISgg kF16Kh1KmNU0U4gUBn4KE1HvIat62/hK4Br2JjzpMyE5Cr48J5To3fXbq340iq+XuBku FVRPpMCKihjE4x0/kdkR/xYe39PqGug+K/utiP/pa3GOL4wEo9Q7BBQMi1Y6oZ2VmplP CtBDTUY5MeIy41wo7jpPVAoVP//VTjKGAroFdsgHyNX2dYJkB14x3MVQawf3nXiZSt9x ufjw== 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 m25si1413231otn.298.2020.03.06.05.26.14; Fri, 06 Mar 2020 05:26:28 -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 S1727190AbgCFNZr (ORCPT + 99 others); Fri, 6 Mar 2020 08:25:47 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:3698 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726090AbgCFNZr (ORCPT ); Fri, 6 Mar 2020 08:25:47 -0500 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 026DLQn3067151 for ; Fri, 6 Mar 2020 08:25:45 -0500 Received: from e06smtp01.uk.ibm.com (e06smtp01.uk.ibm.com [195.75.94.97]) by mx0b-001b2d01.pphosted.com with ESMTP id 2ykd49vdb2-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 06 Mar 2020 08:25:45 -0500 Received: from localhost by e06smtp01.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 6 Mar 2020 13:25:43 -0000 Received: from b06avi18626390.portsmouth.uk.ibm.com (9.149.26.192) by e06smtp01.uk.ibm.com (192.168.101.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 6 Mar 2020 13:25:40 -0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 026DOebk23920902 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 6 Mar 2020 13:24:40 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 39C4AA4051; Fri, 6 Mar 2020 13:25:39 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9C523A4057; Fri, 6 Mar 2020 13:25:38 +0000 (GMT) Received: from localhost.localdomain (unknown [9.145.0.1]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 6 Mar 2020 13:25:38 +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 v4 1/2] mm/gup: fixup for 9947ea2c1e608e32 "mm/gup: track FOLL_PIN pages" Date: Fri, 6 Mar 2020 14:25:36 +0100 X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200306132537.783769-1-imbrenda@linux.ibm.com> References: <20200306132537.783769-1-imbrenda@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 20030613-4275-0000-0000-000003A8FA56 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20030613-4276-0000-0000-000038BE0CFD Message-Id: <20200306132537.783769-2-imbrenda@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-03-06_04:2020-03-06,2020-03-06 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 phishscore=0 mlxscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 bulkscore=0 priorityscore=1501 mlxlogscore=999 adultscore=0 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2003060096 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 Reviewed-by: John Hubbard --- 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