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=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 25978C4361B for ; Fri, 11 Dec 2020 21:58:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E31E123B85 for ; Fri, 11 Dec 2020 21:58:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2395192AbgLKVLD (ORCPT ); Fri, 11 Dec 2020 16:11:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391366AbgLKVKT (ORCPT ); Fri, 11 Dec 2020 16:10:19 -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 78149C0613CF for ; Fri, 11 Dec 2020 13:09:39 -0800 (PST) Received: by mail-ed1-x543.google.com with SMTP id v22so10793090edt.9 for ; Fri, 11 Dec 2020 13:09:39 -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=Ao7xOAmYaX/ywGJg0iG/Mh6Kx1f1ZcL87diFd+Y1lgA=; b=aAfGSlEUgcDLpXRNkXIwp3DHZUaleYjADDcGxmniPbgCxhcNtqJwGP/McXAsdM/BAJ m9xejVVYuVGT+X0oCTQc5OkBSfq4uYXO1r0vnIGX6iznyDLybhsStAqQ8nE+VTYvT41/ Q4AzJl/Rj5EBBtSby6Bvg346cED2t0FBYmJ1URTPm8E51HEVUW0ZlkLZ5mCMQ2HSZucZ nEm1DGQ0qOiATOM2Oc5DpmESg938oYmpTdtoJ8KTNWhi2qVmXaFEWcaFR8F4hLAn+D81 B7LILJrvJvcZF/0nUbkByJepMPWl2TJXBXZ0L76aSvoQ0s31nM2o5dO4av6j9PkDHbjK YybQ== 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=Ao7xOAmYaX/ywGJg0iG/Mh6Kx1f1ZcL87diFd+Y1lgA=; b=Je8kcDBQeEZC1869h2SMMbCeh3t1OXEgtPIzgruTgVe+JAxNCcYIrTH89zeRGqZ9SL 5bX2kr/bI7arnDnIuD8F4gV4PzNDvABh3XJLWAcT8/f3fx1yjyl3XfHanxG6q0qT7zjk EVcFxYRphDHu3UBamEb8poR/WPEl39YjYUeP3YoJ/VIibQ+L2x3CYmekSf2qbIB+wZyg vQHCk0Xg1VP2Non/oX9FKXIu+XbENcU4JfDwBnmaKH30vMlGvo1snZfU59rb0DzeU47f m8YWt3myif1/W+wVK57c47R38iVkZxq/2EjU5Bz0AZ0zc1dQzLZevHZNcG4jGYKXdjFe RjvA== X-Gm-Message-State: AOAM5330cjikJJbVBw9SyOCFyKrs4qniM3m3gLwZsbqL9NmYz1En7GOB WJbd+bR7jlTvp7v9YmsUO1kXR+I0UpXMgFjg4Yeo3w== X-Google-Smtp-Source: ABdhPJwlIqvueU3MoneKnbIXloAwNr6Ag2h5LtdJXzZ0BBDjWxTCUfq7+QMT89nt5UYSontzpxc+l3g5STb19Q+QkAU= X-Received: by 2002:a50:f404:: with SMTP id r4mr975568edm.62.1607720978232; Fri, 11 Dec 2020 13:09:38 -0800 (PST) MIME-Version: 1.0 References: <20201211202140.396852-1-pasha.tatashin@soleen.com> <20201211202140.396852-6-pasha.tatashin@soleen.com> <20201211202354.GA2225686@ziepe.ca> <20201211204600.GD5487@ziepe.ca> In-Reply-To: <20201211204600.GD5487@ziepe.ca> From: Pavel Tatashin Date: Fri, 11 Dec 2020 16:09:02 -0500 Message-ID: Subject: Re: [PATCH v3 5/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 , Linux Doc Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 11, 2020 at 3:46 PM Jason Gunthorpe wrote: > > On Fri, Dec 11, 2020 at 03:40:57PM -0500, Pavel Tatashin wrote: > > On Fri, Dec 11, 2020 at 3:23 PM Jason Gunthorpe wrote: > > > > > > On Fri, Dec 11, 2020 at 03:21:39PM -0500, Pavel Tatashin wrote: > > > > @@ -1593,7 +1592,7 @@ static long check_and_migrate_cma_pages(struct mm_struct *mm, > > > > } > > > > > > > > if (!isolate_lru_page(head)) { > > > > - list_add_tail(&head->lru, &cma_page_list); > > > > + list_add_tail(&head->lru, &movable_page_list); > > > > mod_node_page_state(page_pgdat(head), > > > > NR_ISOLATED_ANON + > > > > page_is_file_lru(head), > > > > @@ -1605,7 +1604,7 @@ static long check_and_migrate_cma_pages(struct mm_struct *mm, > > > > i += step; > > > > } > > > > > > > > - if (!list_empty(&cma_page_list)) { > > > > + if (!list_empty(&movable_page_list)) { > > > > > > You didn't answer my earlier question, is it OK that ZONE_MOVABLE > > > pages leak out here if ioslate_lru_page() fails but the > > > moval_page_list is empty? > > > > > > I think the answer is no, right? > > In my opinion it is OK. We are doing our best to not pin movable > > pages, but if isolate_lru_page() fails because pages are currently > > locked by someone else, we will end up long-term pinning them. > > See comment in this patch: > > + * 1. Pinned pages: (long-term) pinning of movable pages is avoided > > + * when pages are pinned and faulted, but it is still possible that > > + * address space already has pages in ZONE_MOVABLE at the time when > > + * pages are pinned (i.e. user has touches that memory before > > + * pinning). In such case we try to migrate them to a different zone, > > + * but if migration fails the pages can still end-up pinned in > > + * ZONE_MOVABLE. In such case, memory offlining might retry a long > > + * time and will only succeed once user application unpins pages. > > It is not "retry a long time" it is "might never complete" because > userspace will hold the DMA pin indefinitely. > > Confused what the point of all this is then ?? > > I thought to goal here is to make memory unplug reliable, if you leave > a hole like this then any hostile userspace can block it forever. You are right, I used a wording from the previous comment, and it should be made clear that pin may be forever. Without these patches it is guaranteed that hot-remove will fail if there are pinned pages as ZONE_MOVABLE is actually the first to be searched. Now, it will fail only due to exceptions listed in ZONE_MOVABLE comment: 1. pin + migration/isolation failure 2. memblock allocation due to limited amount of space for kernelcore 3. memory holes 4. hwpoison 5. Unmovable PG_offline pages (? need to study why this is a scenario). Do you think we should unconditionally unpin pages, and return error when isolation/migration fails? Pasha > > Jason 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=-10.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 3C946C433FE for ; Fri, 11 Dec 2020 21:09:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AE79A24078 for ; Fri, 11 Dec 2020 21:09:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AE79A24078 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 C61C16B0036; Fri, 11 Dec 2020 16:09:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BEC9C6B005C; Fri, 11 Dec 2020 16:09:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD9186B005D; Fri, 11 Dec 2020 16:09:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0075.hostedemail.com [216.40.44.75]) by kanga.kvack.org (Postfix) with ESMTP id 909716B0036 for ; Fri, 11 Dec 2020 16:09:40 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 4F62C1DFE for ; Fri, 11 Dec 2020 21:09:40 +0000 (UTC) X-FDA: 77582242920.03.time49_270c6b027404 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin03.hostedemail.com (Postfix) with ESMTP id 17CFF28A4EC for ; Fri, 11 Dec 2020 21:09:40 +0000 (UTC) X-HE-Tag: time49_270c6b027404 X-Filterd-Recvd-Size: 6777 Received: from mail-ed1-f65.google.com (mail-ed1-f65.google.com [209.85.208.65]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Fri, 11 Dec 2020 21:09:39 +0000 (UTC) Received: by mail-ed1-f65.google.com with SMTP id b73so10780430edf.13 for ; Fri, 11 Dec 2020 13:09:39 -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=Ao7xOAmYaX/ywGJg0iG/Mh6Kx1f1ZcL87diFd+Y1lgA=; b=aAfGSlEUgcDLpXRNkXIwp3DHZUaleYjADDcGxmniPbgCxhcNtqJwGP/McXAsdM/BAJ m9xejVVYuVGT+X0oCTQc5OkBSfq4uYXO1r0vnIGX6iznyDLybhsStAqQ8nE+VTYvT41/ Q4AzJl/Rj5EBBtSby6Bvg346cED2t0FBYmJ1URTPm8E51HEVUW0ZlkLZ5mCMQ2HSZucZ nEm1DGQ0qOiATOM2Oc5DpmESg938oYmpTdtoJ8KTNWhi2qVmXaFEWcaFR8F4hLAn+D81 B7LILJrvJvcZF/0nUbkByJepMPWl2TJXBXZ0L76aSvoQ0s31nM2o5dO4av6j9PkDHbjK YybQ== 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=Ao7xOAmYaX/ywGJg0iG/Mh6Kx1f1ZcL87diFd+Y1lgA=; b=f4KdbiXCE/Qq/kAjE+q9rSMxgClonpjqEtp43UoobidiYuD7i7vbnI51HcLpOHpWNb dIVSmqAkTmBgAILKwH0Nss87qMHAhuL4VYWtyKOpIJvTz1PHB5pKa5aDLvi8M+2CEDXo +LuxB36E3Y4MAc+dlMASMfSgQkABIUFm8dRAJ8qnThiwfFrTUg9OXyREH8ilcTplgbN2 f7N3JamED9rE+JYtrOvAyBCMcA9eeK1kJHLkY/hxLcH+Pc6KOTK8qIqxjKu9g2yJQ8tE lGiNQe5N6BBHwGJgW6UNRw1ctQusGyOyCWbWCbvNm1qOIZ+x6KPxOGDtLQsH+4s8JTrQ VZ7A== X-Gm-Message-State: AOAM532nxfPTZIpz6C1vjwQaMiPyCIyz40FcPFB5oejTtXcBa6yXbR+G A0lnpoVdOSGwv8dQajEdwTlfEUGUQ9jiHb3ckP4fZw== X-Google-Smtp-Source: ABdhPJwlIqvueU3MoneKnbIXloAwNr6Ag2h5LtdJXzZ0BBDjWxTCUfq7+QMT89nt5UYSontzpxc+l3g5STb19Q+QkAU= X-Received: by 2002:a50:f404:: with SMTP id r4mr975568edm.62.1607720978232; Fri, 11 Dec 2020 13:09:38 -0800 (PST) MIME-Version: 1.0 References: <20201211202140.396852-1-pasha.tatashin@soleen.com> <20201211202140.396852-6-pasha.tatashin@soleen.com> <20201211202354.GA2225686@ziepe.ca> <20201211204600.GD5487@ziepe.ca> In-Reply-To: <20201211204600.GD5487@ziepe.ca> From: Pavel Tatashin Date: Fri, 11 Dec 2020 16:09:02 -0500 Message-ID: Subject: Re: [PATCH v3 5/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 , Linux Doc Mailing List 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 Fri, Dec 11, 2020 at 3:46 PM Jason Gunthorpe wrote: > > On Fri, Dec 11, 2020 at 03:40:57PM -0500, Pavel Tatashin wrote: > > On Fri, Dec 11, 2020 at 3:23 PM Jason Gunthorpe wrote: > > > > > > On Fri, Dec 11, 2020 at 03:21:39PM -0500, Pavel Tatashin wrote: > > > > @@ -1593,7 +1592,7 @@ static long check_and_migrate_cma_pages(struct mm_struct *mm, > > > > } > > > > > > > > if (!isolate_lru_page(head)) { > > > > - list_add_tail(&head->lru, &cma_page_list); > > > > + list_add_tail(&head->lru, &movable_page_list); > > > > mod_node_page_state(page_pgdat(head), > > > > NR_ISOLATED_ANON + > > > > page_is_file_lru(head), > > > > @@ -1605,7 +1604,7 @@ static long check_and_migrate_cma_pages(struct mm_struct *mm, > > > > i += step; > > > > } > > > > > > > > - if (!list_empty(&cma_page_list)) { > > > > + if (!list_empty(&movable_page_list)) { > > > > > > You didn't answer my earlier question, is it OK that ZONE_MOVABLE > > > pages leak out here if ioslate_lru_page() fails but the > > > moval_page_list is empty? > > > > > > I think the answer is no, right? > > In my opinion it is OK. We are doing our best to not pin movable > > pages, but if isolate_lru_page() fails because pages are currently > > locked by someone else, we will end up long-term pinning them. > > See comment in this patch: > > + * 1. Pinned pages: (long-term) pinning of movable pages is avoided > > + * when pages are pinned and faulted, but it is still possible that > > + * address space already has pages in ZONE_MOVABLE at the time when > > + * pages are pinned (i.e. user has touches that memory before > > + * pinning). In such case we try to migrate them to a different zone, > > + * but if migration fails the pages can still end-up pinned in > > + * ZONE_MOVABLE. In such case, memory offlining might retry a long > > + * time and will only succeed once user application unpins pages. > > It is not "retry a long time" it is "might never complete" because > userspace will hold the DMA pin indefinitely. > > Confused what the point of all this is then ?? > > I thought to goal here is to make memory unplug reliable, if you leave > a hole like this then any hostile userspace can block it forever. You are right, I used a wording from the previous comment, and it should be made clear that pin may be forever. Without these patches it is guaranteed that hot-remove will fail if there are pinned pages as ZONE_MOVABLE is actually the first to be searched. Now, it will fail only due to exceptions listed in ZONE_MOVABLE comment: 1. pin + migration/isolation failure 2. memblock allocation due to limited amount of space for kernelcore 3. memory holes 4. hwpoison 5. Unmovable PG_offline pages (? need to study why this is a scenario). Do you think we should unconditionally unpin pages, and return error when isolation/migration fails? Pasha > > Jason