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=-9.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 816DEC4727F for ; Wed, 7 Oct 2020 21:30:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0903A2083B for ; Wed, 7 Oct 2020 21:30:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="BaAFboFh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0903A2083B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 264676B0068; Wed, 7 Oct 2020 17:30:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1EB326B006C; Wed, 7 Oct 2020 17:30:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0B29D6B0070; Wed, 7 Oct 2020 17:30:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0216.hostedemail.com [216.40.44.216]) by kanga.kvack.org (Postfix) with ESMTP id CFC516B0068 for ; Wed, 7 Oct 2020 17:30:14 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 6358E181AE86A for ; Wed, 7 Oct 2020 21:30:14 +0000 (UTC) X-FDA: 77346422748.11.bulb28_5b12b5d271d2 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin11.hostedemail.com (Postfix) with ESMTP id 3DD5D180F8B81 for ; Wed, 7 Oct 2020 21:30:14 +0000 (UTC) X-HE-Tag: bulb28_5b12b5d271d2 X-Filterd-Recvd-Size: 8271 Received: from mail-ot1-f66.google.com (mail-ot1-f66.google.com [209.85.210.66]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Wed, 7 Oct 2020 21:30:13 +0000 (UTC) Received: by mail-ot1-f66.google.com with SMTP id q21so3633615ota.8 for ; Wed, 07 Oct 2020 14:30:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=nNtozmj/MGUZLHZxI3A6qXOhVAeMPho+2jjUlqwzPiY=; b=BaAFboFhzjSDkIsRiKkVY5HnY80F0qFikzkwGLzbiZiDPe/NeBFe6zpt+tRZBXwSlf cldboSnNlcSz1Qnd+/D1yNqcLjwz5qLQP01nnTJ9te1SLWuuX0nGjEu12aT61tF+abrF VMjcmWsESAMRsIG40QQOk22zLTky3pJD0lB9E= 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:content-transfer-encoding; bh=nNtozmj/MGUZLHZxI3A6qXOhVAeMPho+2jjUlqwzPiY=; b=artQXcA6WIl7sTKOW5h+b4tpgmmdVYaq+tmoH4HPdASBM6fKUFlrEMz6pgJ23afo1s VLGb1UgYKhZHKzl96BV/0liDE9qomu9N8yhaX5jERukUa/sxwXJPH+CYA9oyzaFM6zSr KvweuhXve/YBw7RjF/b+cFdcktBONRAKtvoghhGFJAXB3Ft95qp/yO7RkgC/SnmKo090 VVzPoSRtajPcM+4qaWDAt8qAmwyFa5nxz5sauxZqJEbHkEx5QQ9Td7c5PWrKTydcm6sH cd3cRdMA4CQh8+dNyApFCqhBkd7t9zydF8gJrj5xT1vT99fNMgGw42JcFzxwtH/P1ohV akNg== X-Gm-Message-State: AOAM531eM5JF59RZmRXtOCBfOqVurSg4Cm3Qa1SWZ07iTs4j4Khcf17B Z5npZcEIPaVSvYLZ4GhTzUb4myNuFBFmzp06Cdr76g== X-Google-Smtp-Source: ABdhPJzDIRAj53qXn+wCstFj7fFAXvpqHS6peJb8d7VCpx3oiEDiFkz29m0ZVMR9QW+s4BR0BiMsr7SeQunifX3iVl4= X-Received: by 2002:a05:6830:1e56:: with SMTP id e22mr2939594otj.303.1602106212518; Wed, 07 Oct 2020 14:30:12 -0700 (PDT) MIME-Version: 1.0 References: <20201007164426.1812530-1-daniel.vetter@ffwll.ch> <20201007164426.1812530-6-daniel.vetter@ffwll.ch> In-Reply-To: From: Daniel Vetter Date: Wed, 7 Oct 2020 23:30:01 +0200 Message-ID: Subject: Re: [PATCH 05/13] mm/frame-vector: Use FOLL_LONGTERM To: John Hubbard , Dan Williams Cc: DRI Development , LKML , kvm@vger.kernel.org, Linux MM , Linux ARM , linux-samsung-soc , "open list:DMA BUFFER SHARING FRAMEWORK" , linux-s390@vger.kernel.org, Daniel Vetter , Jason Gunthorpe , Pawel Osciak , Marek Szyprowski , Kyungmin Park , Tomasz Figa , Mauro Carvalho Chehab , Andrew Morton , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Jan Kara Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 Wed, Oct 7, 2020 at 11:13 PM John Hubbard wrote: > > On 10/7/20 9:44 AM, Daniel Vetter wrote: > > This is used by media/videbuf2 for persistent dma mappings, not just > > for a single dma operation and then freed again, so needs > > FOLL_LONGTERM. > > > > Unfortunately current pup_locked doesn't support FOLL_LONGTERM due to > > locking issues. Rework the code to pull the pup path out from the > > mmap_sem critical section as suggested by Jason. > > > > Signed-off-by: Daniel Vetter > > Cc: Jason Gunthorpe > > Cc: Pawel Osciak > > Cc: Marek Szyprowski > > Cc: Kyungmin Park > > Cc: Tomasz Figa > > Cc: Mauro Carvalho Chehab > > Cc: Andrew Morton > > Cc: John Hubbard > > Cc: J=C3=A9r=C3=B4me Glisse > > Cc: Jan Kara > > Cc: Dan Williams > > Cc: linux-mm@kvack.org > > Cc: linux-arm-kernel@lists.infradead.org > > Cc: linux-samsung-soc@vger.kernel.org > > Cc: linux-media@vger.kernel.org > > --- > > mm/frame_vector.c | 36 +++++++++++------------------------- > > 1 file changed, 11 insertions(+), 25 deletions(-) > > > > diff --git a/mm/frame_vector.c b/mm/frame_vector.c > > index 10f82d5643b6..39db520a51dc 100644 > > --- a/mm/frame_vector.c > > +++ b/mm/frame_vector.c > > @@ -38,7 +38,6 @@ int get_vaddr_frames(unsigned long start, unsigned in= t nr_frames, > > struct vm_area_struct *vma; > > int ret =3D 0; > > int err; > > - int locked; > > > > if (nr_frames =3D=3D 0) > > return 0; > > @@ -48,35 +47,22 @@ int get_vaddr_frames(unsigned long start, unsigned = int nr_frames, > > > > start =3D untagged_addr(start); > > > > + ret =3D pin_user_pages_fast(start, nr_frames, > > + FOLL_FORCE | FOLL_WRITE | FOLL_LONGTERM= , > > + (struct page **)(vec->ptrs)); > > + if (ret > 0) { > > + vec->got_ref =3D true; > > + vec->is_pfns =3D false; > > + goto out_unlocked; > > + } > > This part looks good, and changing to _fast is a potential performance im= provement, > too. > > > + > > mmap_read_lock(mm); > > - locked =3D 1; > > vma =3D find_vma_intersection(mm, start, start + 1); > > if (!vma) { > > ret =3D -EFAULT; > > goto out; > > } > > > > - /* > > - * While get_vaddr_frames() could be used for transient (kernel > > - * controlled lifetime) pinning of memory pages all current > > - * users establish long term (userspace controlled lifetime) > > - * page pinning. Treat get_vaddr_frames() like > > - * get_user_pages_longterm() and disallow it for filesystem-dax > > - * mappings. > > - */ > > - if (vma_is_fsdax(vma)) { > > - ret =3D -EOPNOTSUPP; > > - goto out; > > - } > > Are you sure we don't need to check vma_is_fsdax() anymore? Since FOLL_LONGTERM checks for this and can only return struct page backed memory, and explicitly excludes VM_IO | VM_PFNMAP, was assuming this is not needed for follow_pfn. And the get_user_pages_locked this used back then didn't have the same check, hence why it was added (and FOLL_LONGTERM still doesn't work for the _locked versions, as you pointed out on the last round of this discussion). But now that you're asking, I have no idea whether fsdax vma can also be of VM_IO | VM_PFNMAP type. I'm not seeing that set anywhere in fs/dax.c, but that says nothing :-) Dan, you added this check originally, do we need it for VM_SPECIAL vmas too= ? Thanks, Daniel > > > - > > - if (!(vma->vm_flags & (VM_IO | VM_PFNMAP))) { > > - vec->got_ref =3D true; > > - vec->is_pfns =3D false; > > - ret =3D pin_user_pages_locked(start, nr_frames, > > - gup_flags, (struct page **)(vec->ptrs), &locked); > > - goto out; > > - } > > - > > vec->got_ref =3D false; > > vec->is_pfns =3D true; > > do { > > @@ -101,8 +87,8 @@ int get_vaddr_frames(unsigned long start, unsigned i= nt nr_frames, > > vma =3D find_vma_intersection(mm, start, start + 1); > > } while (vma && vma->vm_flags & (VM_IO | VM_PFNMAP)); > > out: > > - if (locked) > > - mmap_read_unlock(mm); > > + mmap_read_unlock(mm); > > +out_unlocked: > > if (!ret) > > ret =3D -EFAULT; > > if (ret > 0) > > > > All of the error handling still looks accurate there. > > thanks, > -- > John Hubbard > NVIDIA --=20 Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch