From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 497F9C4361A for ; Thu, 3 Dec 2020 17:14:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 92F08207A4 for ; Thu, 3 Dec 2020 17:14:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 92F08207A4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E93B56B0068; Thu, 3 Dec 2020 12:14:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E43CC6B006C; Thu, 3 Dec 2020 12:14:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D5A7F8D0001; Thu, 3 Dec 2020 12:14:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0051.hostedemail.com [216.40.44.51]) by kanga.kvack.org (Postfix) with ESMTP id BBC1D6B0068 for ; Thu, 3 Dec 2020 12:14:49 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 89250180AD807 for ; Thu, 3 Dec 2020 17:14:49 +0000 (UTC) X-FDA: 77552620698.01.yard39_2d07ea5273bd Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin01.hostedemail.com (Postfix) with ESMTP id 6376D1004EF48 for ; Thu, 3 Dec 2020 17:14:49 +0000 (UTC) X-HE-Tag: yard39_2d07ea5273bd X-Filterd-Recvd-Size: 5453 Received: from mail-ed1-f66.google.com (mail-ed1-f66.google.com [209.85.208.66]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Thu, 3 Dec 2020 17:14:48 +0000 (UTC) Received: by mail-ed1-f66.google.com with SMTP id c7so2899283edv.6 for ; Thu, 03 Dec 2020 09:14:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=WtIPNoqi/BD0F1oh2hYjLoqJe2WfmOtKOH7qlA9PgjQ=; b=ZntyKQF5o81ERLDj2oodoU3jNqDI+rBFys/NaNCuT3D7hPteHUxxnK26Wa0owvhz2Y Sfwi4ngOMxDByY2nbO/Mu0k3F5KtA5evQqJ8JJJdSYI1i7Nu+Ux1jt3bpBDlStFR0cQ5 Cxe8XlOivVMOgWAWYfS/bHKX7WvFk5gpFNLgNyyWf87Cd0w+Yi7mVueSlPMXQr/Oa4C3 qVe2xnUbwj/ofJkQDpiy0ClmAMjLFrCqWJrtBpCG+yXix2x6JQQpHGwpyojM1I9MDONl yS9EbP9ZG/uEiFTh76hrB6vdiPGc2dMB5QvgsQXjGzPw8Js4nhZaoxkutj4I8v4l1lqr MpHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=WtIPNoqi/BD0F1oh2hYjLoqJe2WfmOtKOH7qlA9PgjQ=; b=BZpBOh0s6FEZqdNDhbCb6MwhG1j4G2DywtvhBfPJSZAbMeMkfD1a/0+CqWnOfX44t9 KxKgrKcDHFHZ85EmK4Bz/2yzsWvxVtOBCoP/pq3HgM2iR5s7NdAS8dpVNVcu4HIn+U18 uzWBh5IWwHd4XxBBbHI51nhPQgutg/hn/J7i81xYKiRv7F9ufeDTbBnUWQUBhg+Z4VkF DkDT4eSMaE53/fbXAt54tSU7F5dhPyJQtXCpVhRS0TCEeX7gi85gu0DOa/RTu4tubCnx wWomXVMKiCR15HqP+mI9l66hYZnzsx12ighg3RH8F7yTpwjiCz2jldnBnGCCSgwmSo0H GyMw== X-Gm-Message-State: AOAM533K8UN38uRyyTw17J6ZpfbNx1vykMmC9cnzgaNMqKOcsWJCqBtq PH0A/fNdD4n/Xlqkb1YmAI4WBY1NxhZsnrI8guGAag== X-Google-Smtp-Source: ABdhPJxU9HZX2AEQweVrxtSIoipOVk3c6tRBdh1cl9UbCMNohli/o5y4McNfSlfnA6FPg74lIFITu6lqfdvdRjJi+rc= X-Received: by 2002:aa7:c652:: with SMTP id z18mr3664034edr.60.1607015687752; Thu, 03 Dec 2020 09:14:47 -0800 (PST) MIME-Version: 1.0 References: <20201202052330.474592-1-pasha.tatashin@soleen.com> <20201202052330.474592-7-pasha.tatashin@soleen.com> <20201202163507.GL5487@ziepe.ca> <20201203010809.GQ5487@ziepe.ca> <20201203141729.GS5487@ziepe.ca> <20201203165937.GU5487@ziepe.ca> In-Reply-To: <20201203165937.GU5487@ziepe.ca> From: Pavel Tatashin Date: Thu, 3 Dec 2020 12:14:11 -0500 Message-ID: Subject: Re: [PATCH 6/6] mm/gup: migrate pinned pages out of movable zone To: Jason Gunthorpe Cc: LKML , linux-mm , Andrew Morton , Vlastimil Babka , Michal Hocko , David Hildenbrand , Oscar Salvador , Dan Williams , Sasha Levin , Tyler Hicks , Joonsoo Kim , mike.kravetz@oracle.com, Steven Rostedt , Ingo Molnar , Peter Zijlstra , Mel Gorman , Matthew Wilcox , David Rientjes , John Hubbard Content-Type: text/plain; charset="UTF-8" X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Dec 3, 2020 at 11:59 AM Jason Gunthorpe wrote: > > On Thu, Dec 03, 2020 at 11:40:15AM -0500, Pavel Tatashin wrote: > > > Looking at this code some more.. How is it even correct? > > > > > > 1633 if (!isolate_lru_page(head)) { > > > 1634 list_add_tail(&head->lru, &cma_page_list); > > > > > > Here we are only running under the read side of the mmap sem so multiple > > > GUPs can be calling that sequence in parallel. I don't see any > > > obvious exclusion that will prevent corruption of head->lru. The first > > > GUP thread to do isolate_lru_page() will ClearPageLRU() and the second > > > GUP thread will be a NOP for isolate_lru_page(). > > > > > > They will both race list_add_tail and other list ops. That is not OK. > > > > Good question. I studied it, and I do not see how this is OK. Worse, > > this race is also exposable as a syscall instead of via driver: two > > move_pages() run simultaneously. Perhaps in other places? > > > > move_pages() > > kernel_move_pages() > > mmget() > > do_pages_move() > > add_page_for_migratio() > > mmap_read_lock(mm); > > list_add_tail(&head->lru, pagelist); <- Not protected > > When this was CMA only it might have been rarer to trigger, but this > move stuff sounds like it makes it much more broadly, eg on typical > servers with RDMA exposed/etc > > Seems like it needs fixing as part of this too :\ Just to clarify the stack that I showed above is outside of gup, it is the same issue that you pointed out that happens elsewhere. I suspect there might be more. All of them should be addressed together. Pasha > > Page at a time inside the gup loop could address both concerns, unsure > about batching performance here though.. > > Jason