Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp5906702ybp; Tue, 8 Oct 2019 10:00:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqyVjHgXZQVr4RTzGdEIuU7qkhjyWiaXVURZJ8y3ZZbKaa3KqmARCNZTdHC+JzvPCiqJotq0 X-Received: by 2002:a17:906:1e54:: with SMTP id i20mr18936486ejj.51.1570554003552; Tue, 08 Oct 2019 10:00:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570554003; cv=none; d=google.com; s=arc-20160816; b=SH5trNkiOZ4PLP+f5uEC3dNPDY+pxrLgBR5/m1CCwYRuHrw/8Ky8lBbzVdR0YgjwN/ UbaPaVQzOITUfYWoJCPv70OBPHGFIsaQDH4D+z6kBoTN10y2nzaIN5vJDp+CUTWsVQ4p hnl7FFCqgYSGEya7MfwN8m9S7/M8od1WAAJl+T63IkHwnLbhazMGo4oi+lYOKMjY47lt AUWpnJeSkniEXqIKGVwT1NTC1tN0T6eG9IoBEmUfNhbE0+JH1cXwQitQPq9PIZbbcMzJ FfWJo7DKfRTb+QCp7Ie8n6xF2gZjznpuJjz+IKEMciLQlEB40R+7bsGMHH44Z2gsIDGU KvJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=PergYEriLDUglsTrW6P3NzwIE/Bf7RgswXS4+cJ8FOc=; b=0fqxx427sF3VHdS2lHAPqgFGfrGZo87fK10A2IAQ6W7uVbiQNJf0Hta7xwQ8aB+SLE e7L5WMAaYKUeERW2IIZxMEY3bFjSEr2AMxtsIrq7gxSR1HofVZ4SMuTT4JlsMg7rSYJ/ OZDr7xkYK5CgRKQ9VVNwQEHXelWRPYGz5Gn9TxmSCpy5p1frctbzT5b8DRpqOyXNSCIY W6FzYZhC+iOmU+aoR/Y8DzrUtX+MRc3HvCcycPIqUndMTXA5YR2oitZ8c+8ma9OeUW9U hmcfEYVpENJhJv0wW0pGO3KXrIk5jpyYEl8jbGaJVP4TTfosL6VZTJHFUEjp6mv7gYzO PEVQ== 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=QUARANTINE sp=NONE dis=NONE) header.from=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d24si11133828ede.119.2019.10.08.09.59.39; Tue, 08 Oct 2019 10:00:03 -0700 (PDT) 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=QUARANTINE sp=NONE dis=NONE) header.from=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728104AbfJHQ7M (ORCPT + 99 others); Tue, 8 Oct 2019 12:59:12 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:35745 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727903AbfJHQ7L (ORCPT ); Tue, 8 Oct 2019 12:59:11 -0400 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Tue, 8 Oct 2019 09:44:04 -0700 Received: from akaher-lnx-dev.eng.vmware.com (unknown [10.110.19.203]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 1302A40AF8; Tue, 8 Oct 2019 09:43:58 -0700 (PDT) From: Ajay Kaher To: CC: , , , , , , , , , , , , , , , , , , , Andrea Arcangeli , Hugh Dickins , Dave Hansen , Mel Gorman , Rik van Riel , Naoya Horiguchi , Steve Capper , Johannes Weiner , Michal Hocko , Christoph Lameter , David Rientjes Subject: [PATCH v2 3/8] mm: handle PTE-mapped tail pages in gerneric fast gup implementaiton Date: Wed, 9 Oct 2019 06:14:18 +0530 Message-ID: <1570581863-12090-4-git-send-email-akaher@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1570581863-12090-1-git-send-email-akaher@vmware.com> References: <1570581863-12090-1-git-send-email-akaher@vmware.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: None (EX13-EDG-OU-002.vmware.com: akaher@vmware.com does not designate permitted sender hosts) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Kirill A. Shutemov" commit 7aef4172c7957d7e65fc172be4c99becaef855d4 upstream. With new refcounting we are going to see THP tail pages mapped with PTE. Generic fast GUP rely on page_cache_get_speculative() to obtain reference on page. page_cache_get_speculative() always fails on tail pages, because ->_count on tail pages is always zero. Let's handle tail pages in gup_pte_range(). New split_huge_page() will rely on migration entries to freeze page's counts. Recheck PTE value after page_cache_get_speculative() on head page should be enough to serialize against split. Signed-off-by: Kirill A. Shutemov Tested-by: Sasha Levin Tested-by: Aneesh Kumar K.V Acked-by: Jerome Marchand Acked-by: Vlastimil Babka Cc: Andrea Arcangeli Cc: Hugh Dickins Cc: Dave Hansen Cc: Mel Gorman Cc: Rik van Riel Cc: Naoya Horiguchi Cc: Steve Capper Cc: Johannes Weiner Cc: Michal Hocko Cc: Christoph Lameter Cc: David Rientjes Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Ajay Kaher --- mm/gup.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 2cd3b31..45c544b 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1070,7 +1070,7 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end, * for an example see gup_get_pte in arch/x86/mm/gup.c */ pte_t pte = READ_ONCE(*ptep); - struct page *page; + struct page *head, *page; /* * Similar to the PMD case below, NUMA hinting must take slow @@ -1082,15 +1082,17 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end, VM_BUG_ON(!pfn_valid(pte_pfn(pte))); page = pte_page(pte); + head = compound_head(page); - if (!page_cache_get_speculative(page)) + if (!page_cache_get_speculative(head)) goto pte_unmap; if (unlikely(pte_val(pte) != pte_val(*ptep))) { - put_page(page); + put_page(head); goto pte_unmap; } + VM_BUG_ON_PAGE(compound_head(page) != head, page); pages[*nr] = page; (*nr)++; -- 2.7.4