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 ACEB6C74A5B for ; Fri, 17 Mar 2023 19:08:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0B1646B0075; Fri, 17 Mar 2023 15:08:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0612B6B0078; Fri, 17 Mar 2023 15:08:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E43786B007B; Fri, 17 Mar 2023 15:08:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D3A5C6B0075 for ; Fri, 17 Mar 2023 15:08:46 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A9F711C53B1 for ; Fri, 17 Mar 2023 19:08:46 +0000 (UTC) X-FDA: 80579327052.26.A4148B4 Received: from mail-yw1-f172.google.com (mail-yw1-f172.google.com [209.85.128.172]) by imf08.hostedemail.com (Postfix) with ESMTP id E6E8D160026 for ; Fri, 17 Mar 2023 19:08:44 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=A9Xx39Vs; spf=pass (imf08.hostedemail.com: domain of surenb@google.com designates 209.85.128.172 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679080124; 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=TtkQvqCybTAazWJPrit1AMvXQMfmRWKtxssDGkkt4aI=; b=K3u26xnl7o6MTt9Xyt/2u5sr1OZDObyz9mx8tbFUTA18TiObsAEfeUpldF51hwpTwp4opC z6vktsgla/0iSECoMGQw9pyTaMz6vk91mYSLR715kSWwaNKWbXhKCORrXVhttIqsHPDFZm kftomV9wqe/hqQzKRkeVUDVv0eaGt5g= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=A9Xx39Vs; spf=pass (imf08.hostedemail.com: domain of surenb@google.com designates 209.85.128.172 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=1679080125; a=rsa-sha256; cv=none; b=IXLYUQuS73tH4wayExGqu3puzhMosa/UuQXvrSRK/eFr1HzeAxEziUWJgIIAQVJRy2WoqH lI7E1fjiv1I8DTwUWrxDXyjwZSwkhvV/ZlwRbtkFMTvWpHAwupkmtI+HRjMGeV+gV22apF XJf9wLi0Ct8PbQon5/dbybJbSif3jpg= Received: by mail-yw1-f172.google.com with SMTP id 00721157ae682-5418c2b8ef2so111528127b3.5 for ; Fri, 17 Mar 2023 12:08:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679080124; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=TtkQvqCybTAazWJPrit1AMvXQMfmRWKtxssDGkkt4aI=; b=A9Xx39VsDfAww1P3KBrqNePQW4nRTeWl/oDLqWC2n9XHSShzJU08lYLiMMTwNuGaEL KdK8emE8pLHmmgtPc3KiKRt8iMMNn6bunG0BxWE+/Y0kXLIqyLLMQ/d6v9MSPL73Gv8G 55ALxvCKGbWb3efEI06Hlt57hqgzCVfid+MBX1/Uz7NSfxcBnnWoXIlEDRiTefNn2JGN Hpx42UiDje0uBZczcnQwT5097VwnM434IYLfWDKadih442QI8+PFv9m6tYDQUEFxb4rW vwF/X+YfmBG3+KdUHmX/M29EsSkeE9vOoDQ2BJ8aA2WNpChMeA9ztvHHxtdzHaiBKQyl Ar2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679080124; 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:message-id:reply-to; bh=TtkQvqCybTAazWJPrit1AMvXQMfmRWKtxssDGkkt4aI=; b=mISkPxvUa+brTv2DvvcKFDURakigc9URUcoy2n10vzkSJMDuNcIJtTMWCHu8fnF2x1 c9VTs57zVWhcZoG30D8Pv3uUK1EsZLWcisdzeix79c/QHi95Eoie0TQpErf1GGjopvp+ SFU9k50N1DMlv3+dsqcoRrir8p+iX2rXglJ+IdIyh+sEpq3HG6sVsAN4eKcBqA5mSg4c e6SvjyV7nr4ucif2C5D77tp5LdDXn/TLZ7mS+BKdNf1J4Sh/GAgEXVwh7C6gFISKeWvk eutJJoLrvGA6X4PhGsKKwG6HhDil7EyfGiSSHadllC1jWraq23qJshX+mtKqCKOcHIJ4 YHOg== X-Gm-Message-State: AO0yUKU3nR9Uy0bWwKyk8iyFqzgsxI6wilG1QSTDThESnj0omOhS+QXA wcIe2MtT/dkfFiiMArr2NqTuzRXH7VTtb++DsgFKug== X-Google-Smtp-Source: AK7set9XdXibjKhLKLOpCgfHP3zHh4i0ReloLFIdYIvJHM4aukAMgg/kqZsVAHifAGiXEo7BWTSJHGdDz1qRr77kcJo= X-Received: by 2002:a81:4517:0:b0:536:38b4:f50 with SMTP id s23-20020a814517000000b0053638b40f50mr5188310ywa.1.1679080123783; Fri, 17 Mar 2023 12:08:43 -0700 (PDT) MIME-Version: 1.0 References: <20230126193752.297968-1-surenb@google.com> <20230314141144.6a0892e6.alex.williamson@redhat.com> In-Reply-To: <20230314141144.6a0892e6.alex.williamson@redhat.com> From: Suren Baghdasaryan Date: Fri, 17 Mar 2023 12:08:32 -0700 Message-ID: Subject: Re: [PATCH v4 0/7] introduce vm_flags modifier functions To: Alex Williamson Cc: akpm@linux-foundation.org, michel@lespinasse.org, jglisse@google.com, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, mgorman@techsingularity.net, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, peterz@infradead.org, ldufour@linux.ibm.com, paulmck@kernel.org, mingo@redhat.com, will@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, punit.agrawal@bytedance.com, lstoakes@gmail.com, peterjung1337@gmail.com, rientjes@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, rppt@kernel.org, jannh@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@google.com, leewalsh@google.com, posk@google.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com, "Michael S. Tsirkin" , Jason Wang , Jason Gunthorpe , =?UTF-8?Q?C=C3=A9dric_Le_Goater?= , dimitri.sivanich@hpe.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: E6E8D160026 X-Stat-Signature: ametzpk13uhb4z51yucfxzmbfn6osxi5 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1679080124-45703 X-HE-Meta: U2FsdGVkX189bv96giCRituMzoeQ47bX2Q466or839rOZz6Ln/6X8lkvHkbjAoqm3R/h2wAQl67q7jT7sdbEwg0l0DC3VFMrKmjeMST6+SD0ADMHNnlhsyMqtDDsk/CzrJIDm+7x65W4mOH2HkWC7CmannRm1Yy2o7aj6eTSHsW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5aMBDFVVueyJAUPGuSGC+6udntRQIywtortL9ibHe0khMyE0ObT3/49F/a2FKbe9LTCddeSBOwIGjPqsocEhKgiinhzkcWtKJf/VTr62tGF1pYIprcS3/3WkirL7M2e09jBWa87Q= 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 Tue, Mar 14, 2023 at 1:11=E2=80=AFPM Alex Williamson wrote: > > On Thu, 26 Jan 2023 11:37:45 -0800 > Suren Baghdasaryan wrote: > > > This patchset was originally published as a part of per-VMA locking [1]= and > > was split after suggestion that it's viable on its own and to facilitat= e > > the review process. It is now a preprequisite for the next version of p= er-VMA > > lock patchset, which reuses vm_flags modifier functions to lock the VMA= when > > vm_flags are being updated. > > > > VMA vm_flags modifications are usually done under exclusive mmap_lock > > protection because this attrubute affects other decisions like VMA merg= ing > > or splitting and races should be prevented. Introduce vm_flags modifier > > functions to enforce correct locking. > > > > The patchset applies cleanly over mm-unstable branch of mm tree. > > With this series, vfio-pci developed a bunch of warnings around not > holding the mmap_lock write semaphore while calling > io_remap_pfn_range() from our fault handler, vfio_pci_mmap_fault(). > > I suspect vdpa has the same issue for their use of remap_pfn_range() > from their fault handler, JasonW, MST, FYI. > > It also looks like gru_fault() would have the same issue, Dimitri. > > In all cases, we're preemptively setting vm_flags to what > remap_pfn_range_notrack() uses, so I thought we were safe here as I > specifically remember trying to avoid changing vm_flags from the > fault handler. But apparently that doesn't take into account > track_pfn_remap() where VM_PAT comes into play. > > The reason for using remap_pfn_range() on fault in vfio-pci is that > we're mapping device MMIO to userspace, where that MMIO can be disabled > and we'd rather zap the mapping when that occurs so that we can sigbus > the user rather than allow the user to trigger potentially fatal bus > errors on the host. > > Peter Xu has suggested offline that a non-lazy approach to reinsert the > mappings might be more inline with mm expectations relative to touching > vm_flags during fault. What's the right solution here? Can the fault > handling be salvaged, is proactive remapping the right approach, or is > there something better? Thanks, Hi Alex, If in your case it's safe to change vm_flags without holding exclusive mmap_lock, maybe you can use __vm_flags_mod() the way I used it in https://lore.kernel.org/all/20230126193752.297968-7-surenb@google.com, while explaining why this should be safe? > > Alex >