Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp651779pxu; Thu, 3 Dec 2020 09:18:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJxVfP2GAI75UPShdvKtwLfKlGLv6lfe/2AHFsXcWfYnrqLhh2PWVlyhnjy1Uhj5Yt9WR/JV X-Received: by 2002:a17:906:a244:: with SMTP id bi4mr104934ejb.59.1607015905254; Thu, 03 Dec 2020 09:18:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607015905; cv=none; d=google.com; s=arc-20160816; b=rkvMXKKWvH7qIQ4FfrXE5JDYo3mbjBBJKi1rHoCvcz7F4FWhhHS7Ej6wj68XGB4Z00 hnfeyKeiYMdhXu2Z/sVePJubEhAcOwUuCJJZ28U6snEMq7Bx1C0Tx34zdZTmL4IE2cz+ vvdo3rlS/OLPYjLE97IwCiucyyWg+t6WqiW42YCJBTAxs+Lv2YasSGdvLKYvWUJlE3Ll iopg/v0TFVYSoiBwH3JEEjQFbYbGoSDq8yzb+CpyY36fL2Mr2Yai837lcU3w9viiWJZY +/5XvpVS2QFYAnJ0PT04fHCvaOknPvRdeGcYn0FDAdIioQa3pjYPnLKKhMM1BjNd4iLp xzFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=WtIPNoqi/BD0F1oh2hYjLoqJe2WfmOtKOH7qlA9PgjQ=; b=xfEWjhgXghU2btvwSOsHS3mq6pj7LhTgOngNKAJZuTfqKqp0J2bcaAOipN1S5n4PH5 Tfa80A1Y/FYLWZ/2xcnDUyf5JCSO6bs6ZBuoln1EyKIwkq8QRRD8x+3cAPbKUeg76N4B I81I7qofbJ6OvnxJEjXyaTltvzY8RoTSIU3cg35bZfjYKW/h4zoYZSQUM3JvkwrYlNXr cQKyTXw183hPaj9ZnExZgfxyY6o4PKis6wqBZSNYRxq2cDvR57qO5eICU/bcalQXZC1R DAGlCjzPiP8BwykdWpRto2TR8x9FCK8De1RINszv1Sby8tA/7Vd/G/62heT3ySCrb3Vz oNgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=ZntyKQF5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p11si1474564eja.213.2020.12.03.09.18.01; Thu, 03 Dec 2020 09:18:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=ZntyKQF5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727445AbgLCRPf (ORCPT + 99 others); Thu, 3 Dec 2020 12:15:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726299AbgLCRPf (ORCPT ); Thu, 3 Dec 2020 12:15:35 -0500 Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B4CFC061A51 for ; Thu, 3 Dec 2020 09:14:49 -0800 (PST) Received: by mail-ed1-x543.google.com with SMTP id l5so2869338edq.11 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=CBe7bR1YS7WGN04ZUFvqx04MgzX2a7QJImjZgPRoCOon8ev+x6jS6MsVzDcixsVFYV Ruc5ZkCQ4RfLtcHEmilEOGFKzzUOIrph32eYAj8P6USkxzen/eDMCNjINi70oUE60skj bQiCGztHyZoq/uMDTJ41u2mEJZCbcCFQQoDQjSoOqSY1PG18nYI+rEBntSapsL3asJO5 aWHXVzn1X3NatkGbMUKl3XhWMNsPJb2Kn3rq69wmWkMxnHQXkN07sUtDUTToD9dCpiZS TAVro/yjEZlLc3et6Nm++RGkKxFxISOwlQmRmSeWz2WKAsBG3YJvXnjcpoOTXrCB9zJH mSUA== X-Gm-Message-State: AOAM5304qfyF+9VeJOlUFQGNSI4YgtcUoHE8HrDNhwn2Dxh5R/saKfug RRLmx671xSQdHCXsUTazRtXGi6JOvAsbfwqdGMK2Gw== 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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