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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C74D8ECAAA1 for ; Fri, 9 Sep 2022 16:29:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 509DA6B0071; Fri, 9 Sep 2022 12:29:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B9D38D0002; Fri, 9 Sep 2022 12:29:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 35A818D0001; Fri, 9 Sep 2022 12:29:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 27C666B0071 for ; Fri, 9 Sep 2022 12:29:55 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 096EF160351 for ; Fri, 9 Sep 2022 16:29:55 +0000 (UTC) X-FDA: 79893083550.15.64CA6CD Received: from mail-yb1-f174.google.com (mail-yb1-f174.google.com [209.85.219.174]) by imf22.hostedemail.com (Postfix) with ESMTP id B37A4C009C for ; Fri, 9 Sep 2022 16:29:54 +0000 (UTC) Received: by mail-yb1-f174.google.com with SMTP id t184so3471652yba.4 for ; Fri, 09 Sep 2022 09:29:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date; bh=/FXE6KT3IEbyxLGcwK+3ue2mjXL44FHoYVt0dMcsy2k=; b=WFC+mmfLyYIjlJGVeXw314g1tcL5tJ4xqzIO2vLl/9rsbaCoGnBIPy0p853g4f7ctg 8sPwQJXyO0UDB/KTe9E1ptVVFk01M9nrUJanKkaeE7/x8YMgQJdHf/BFgfI3HNW8rgRv 6vobpUPxSYdYDFfdxIVAMxCj9HiA28eHAR4hUGCqxOsaz4OkiEsdJPiCQwV6GMlORkUI BXtJonrmNJppW9fC62mn2CBMHbx/j40w37N9WdzohE0jh06zgBKzULolHeam1yoUoSrH Hu4CD+yQ9nXFhR70qoHQP8/d8iHwqo7pk9Xvduf20IcOIKAE33Hdw4PWAhnGhJ63ogWo CIXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date; bh=/FXE6KT3IEbyxLGcwK+3ue2mjXL44FHoYVt0dMcsy2k=; b=dXqZXeT93hftjrF0x9mELhD85pI+I2IKDCbG8AhFtE3fAMVEwVVgBRJxeZ4BI3+UAe Y0B62F2fzEbfdMMlvzlh1zMfoQpH731euTUt4RgVIhbchLGRBkEdKwyMkZmfto/w2GCD CEfEZdsNZoOmNwVVimMPGawJYkb0PIUipmclEWztISPei1TvCU8Dm1dFupihtuWnsa4g ofEjtyURfWwvO/smYoOPXtIV6auzaXR0BIKe1eb7V2FPBQGhPYnElZlxbhPV9wAurusJ o5ojbtXkqwRN7XrW937BhDaeTwcRhNrUcyApGHjBDqCm93HESQM230L7ne40Hen0gXyS q1FQ== X-Gm-Message-State: ACgBeo3k2sioY1s0OQrOLlR3qoAVxK2X90a83+xpXpUTAmafgOVXn5bB Q7GFdIwtRmkZCLTgdubxSYFIyG0OOyC2aD221mXTPg== X-Google-Smtp-Source: AA6agR6gf0Uo8qO+GM5qYvgJUVDtfxBsoCtsc3hcZzYnaKBzzFaVOPRlFWPi3fYi14o77F1R3tazfKeOdbmbw81hzpM= X-Received: by 2002:a25:abea:0:b0:6a8:1bd5:deef with SMTP id v97-20020a25abea000000b006a81bd5deefmr12701640ybi.431.1662740993786; Fri, 09 Sep 2022 09:29:53 -0700 (PDT) MIME-Version: 1.0 References: <20220901173516.702122-1-surenb@google.com> <20220901173516.702122-8-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Fri, 9 Sep 2022 09:29:42 -0700 Message-ID: Subject: Re: [RFC PATCH RESEND 07/28] kernel/fork: mark VMAs as locked before copying pages during fork To: Laurent Dufour Cc: akpm@linux-foundation.org, michel@lespinasse.org, jglisse@google.com, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, mgorman@suse.de, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, peterz@infradead.org, laurent.dufour@fr.ibm.com, paulmck@kernel.org, luto@kernel.org, songliubraving@fb.com, peterx@redhat.com, david@redhat.com, dhowells@redhat.com, hughd@google.com, bigeasy@linutronix.de, kent.overstreet@linux.dev, rientjes@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, kernel-team@android.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=WFC+mmfL; spf=pass (imf22.hostedemail.com: domain of surenb@google.com designates 209.85.219.174 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662740994; a=rsa-sha256; cv=none; b=SfgT0uzblz0DP3oM9l7fGHT/VejKpJ6lr3nphqBBS1xXlUp8UFSTmX31D5YaCtjLPokn3S 7TpIZFc2EKrnUFjIsDzr0QCckdedF54zmWZpOi6dvI3Eon1X9vsny5zlXe1CvyW2PZkzmp CZJ83PDI2F4MCMBDCop1C1ABf8NTJrk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662740994; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/FXE6KT3IEbyxLGcwK+3ue2mjXL44FHoYVt0dMcsy2k=; b=34s0dUEk6+wcSZUyXzyyzEUpxNnyiaPIFRKZyOIq22+qGnwm5x12w2ucdIXUpYmUZlwZq6 mjtSZ/MRd9hzfo5xQnhA3NhaRDrwviqF9mc+HmXkHUByZ3l5DDxSY33HNgcVFS9XG2X3rT kamuPA4HRvP3rsFJTcTw59DyfnxJ7SU= X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: B37A4C009C Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=WFC+mmfL; spf=pass (imf22.hostedemail.com: domain of surenb@google.com designates 209.85.219.174 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: djhp83jnyjzy67mu5mf4fps7w168eojg X-Rspam-User: X-HE-Tag: 1662740994-452987 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, Sep 9, 2022 at 6:27 AM Laurent Dufour wrote= : > > Le 09/09/2022 =C3=A0 01:57, Suren Baghdasaryan a =C3=A9crit : > > On Tue, Sep 6, 2022 at 7:38 AM Laurent Dufour w= rote: > >> > >> Le 01/09/2022 =C3=A0 19:34, Suren Baghdasaryan a =C3=A9crit : > >>> Protect VMAs from concurrent page fault handler while performing > >>> copy_page_range for VMAs having VM_WIPEONFORK flag set. > >> > >> I'm wondering why is that necessary. > >> The copied mm is write locked, and the destination one is not reachabl= e. > >> If any other readers are using the VMA, this is only for page fault ha= ndling. > > > > Correct, this is done to prevent page faulting in the VMA being > > duplicated. I assume we want to prevent the pages in that VMA from > > changing when we are calling copy_page_range(). Am I wrong? > > If a page is faulted while copy_page_range() is in progress, the page may > not be backed on the child side (PTE lock should protect the copy, isn't = it). > Is that a real problem? It will be backed later if accessed on the child = side. > Maybe the per process pages accounting could be incorrect... This feels to me like walking on the edge. Maybe we can discuss this with more people at LPC before trying it? > > > > >> I should have miss something because I can't see any need to mark the = lock > >> VMA here. > >> > >>> Signed-off-by: Suren Baghdasaryan > >>> --- > >>> kernel/fork.c | 4 +++- > >>> 1 file changed, 3 insertions(+), 1 deletion(-) > >>> > >>> diff --git a/kernel/fork.c b/kernel/fork.c > >>> index bfab31ecd11e..1872ad549fed 100644 > >>> --- a/kernel/fork.c > >>> +++ b/kernel/fork.c > >>> @@ -709,8 +709,10 @@ static __latent_entropy int dup_mmap(struct mm_s= truct *mm, > >>> rb_parent =3D &tmp->vm_rb; > >>> > >>> mm->map_count++; > >>> - if (!(tmp->vm_flags & VM_WIPEONFORK)) > >>> + if (!(tmp->vm_flags & VM_WIPEONFORK)) { > >>> + vma_mark_locked(mpnt); > >>> retval =3D copy_page_range(tmp, mpnt); > >>> + } > >>> > >>> if (tmp->vm_ops && tmp->vm_ops->open) > >>> tmp->vm_ops->open(tmp); > >> >