Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp8073814ybi; Tue, 23 Jul 2019 02:23:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqx7RZjDPl8Ld34VL8OHMJfGaPhLA+1x+d1C4VqD3CiTJCcEM79malYmgkYWdmAniAdszAyP X-Received: by 2002:a17:902:9b94:: with SMTP id y20mr79462392plp.260.1563873814620; Tue, 23 Jul 2019 02:23:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563873814; cv=none; d=google.com; s=arc-20160816; b=vVK/D4eIucT+jThh39A9uMO8mhle10bnZerNa4pvb5d93yb1skWoJ4BgEFusk2aX/A fyehJlcnidfaUaJABKpCs32hYdgQ2wdiOXYBVCNDgIvAqYi3hJa9gdnJjBzQ5XqD8k7x g26Iu9okenzShbz9S/tLidZNqrgVhJqu9jMHcnW/AlTXUeqiu7o9/Tgebnbnn8tr7etT crKGB5Ot0Z8TKCvbN3BCH1TuMfyUoyk3QBO+USubFpqs46DklzwJzw2N0gplXnDQIT42 L542qIpZ01J5BqBJD1DP7Y8fvmbqPGEX9L63pFKX17X2QeaSA8P/iQ7NnQK0IrnzsF0Q MAFA== 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=bt5JBqGs6dLN7U8E7NPIVh9me0xealYJhuCPY+J4ic13zotbPxNshEo3S9Di673ptE sJqXtzdRtM6LFDCj34IWxAkjbB2X+m15W61pB5tVs+UA5avMbLILvYUBXTl4yyZ5b+I2 iQ89doY1jLBwuePt4JF+4Pi7h/XHm1DKz1uHEU7vN6QhWGTFnvCmyx62vkUFtBsPqjX2 3zfoEXkBY1q2wOZ3nc0pkFi6XUqYi/Q1xIt+s9dakS6WpQUZto/HmB1xN+0bQSrgfg8C vWP1gIEmuoHkPO+Q1AGZwiXBRPfkwxCxIhkMQrgDziPA3DqGi3f94OowmikTD9NGnQA8 b/Vg== 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 141si11107684pgh.166.2019.07.23.02.23.18; Tue, 23 Jul 2019 02:23:34 -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 S2387894AbfGWDIo (ORCPT + 99 others); Mon, 22 Jul 2019 23:08:44 -0400 Received: from ex13-edg-ou-001.vmware.com ([208.91.0.189]:12328 "EHLO EX13-EDG-OU-001.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387875AbfGWDIl (ORCPT ); Mon, 22 Jul 2019 23:08:41 -0400 Received: from sc9-mailhost2.vmware.com (10.113.161.72) by EX13-EDG-OU-001.vmware.com (10.113.208.155) with Microsoft SMTP Server id 15.0.1156.6; Mon, 22 Jul 2019 20:08:22 -0700 Received: from akaher-lnx-dev.eng.vmware.com (unknown [10.110.19.203]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 10E83B24DB; Mon, 22 Jul 2019 23:08:34 -0400 (EDT) From: Ajay Kaher To: CC: , , , , , , , , , , , , , , , , , , "Kirill A. Shutemov" , Naoya Horiguchi , Steve Capper , Johannes Weiner , Christoph Lameter , David Rientjes , Andrew Morton Subject: [PATCH 3/8] mm: handle PTE-mapped tail pages in gerneric fast gup implementaiton Date: Tue, 23 Jul 2019 16:38:26 +0530 Message-ID: <1563880111-19058-4-git-send-email-akaher@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1563880111-19058-1-git-send-email-akaher@vmware.com> References: <1563880111-19058-1-git-send-email-akaher@vmware.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: None (EX13-EDG-OU-001.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