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=-3.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 51A11C433DF for ; Sat, 10 Oct 2020 17:23:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9FBD42245F for ; Sat, 10 Oct 2020 17:23:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Tn1BNmOZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9FBD42245F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D446C900002; Sat, 10 Oct 2020 13:23:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CF5636B0062; Sat, 10 Oct 2020 13:23:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BBDC5900002; Sat, 10 Oct 2020 13:23:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0141.hostedemail.com [216.40.44.141]) by kanga.kvack.org (Postfix) with ESMTP id 8CABB6B005C for ; Sat, 10 Oct 2020 13:23:04 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 2B9868249980 for ; Sat, 10 Oct 2020 17:23:04 +0000 (UTC) X-FDA: 77356686288.17.hook38_0a15497271eb Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id 13D4E180D0180 for ; Sat, 10 Oct 2020 17:23:04 +0000 (UTC) X-HE-Tag: hook38_0a15497271eb X-Filterd-Recvd-Size: 7617 Received: from mail-ed1-f65.google.com (mail-ed1-f65.google.com [209.85.208.65]) by imf13.hostedemail.com (Postfix) with ESMTP for ; Sat, 10 Oct 2020 17:23:03 +0000 (UTC) Received: by mail-ed1-f65.google.com with SMTP id dg9so10300210edb.12 for ; Sat, 10 Oct 2020 10:23:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=AkcMDQ9MzR0MXrPdl4Z5WIlaKuGLuztzGgHABJ/UwRo=; b=Tn1BNmOZPmbfirFetQOYO/ocDzjrlXPQ3LhwSZNpGIDc+8auCeevOxYV9x2mwnL+LJ B1X87tTja6iFvGiJMYchruyGKGyDa2qJyDYXpQ4MO9cDFl66eVBMa7wPbnL2v+lbkE61 A3oosZUv6WC10KVVTloFe7vbgZMt3GHhIV9Zs= 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=AkcMDQ9MzR0MXrPdl4Z5WIlaKuGLuztzGgHABJ/UwRo=; b=Abq3b2ujOCLjHmrZj8iWi3yjfE+rtFvI271W/l1utXGmzosGLu7Cl/qQ3JgdaNd0Su 35QKTKHDn7hJD6KgghDVABrlRV/bNBjkNoj0bFf3pOhK6p0GgTqVLXj4h2+HOxkSqjX4 c3JD5UekwKX5AafFl2dCEqiq/oGFE0OkD2n0zKP1/dx/jr7sbTVbnjZQ4OJBrXC/tQv2 3WZGDRQozO0Qi7dqu7H/sUEuaov8kdOwEeISK7Mo32ehZbNiONx9xReAIHFs/oWilyYd gVZXW8iC38rWMIxqrsm8M5N6O7h51LvMeFDlqNcqhqgH4WZz7gbLI+H3AT1Tzsb0f/TM 2krw== X-Gm-Message-State: AOAM533ES2iAveubHiLcomVy+JgAcICdKsojQNdSI71PMuTnhBE84LcB 20ZjtcQOlkKpdjx3gD8GaVeTk3glVGOipw== X-Google-Smtp-Source: ABdhPJwqQOv+boF+zumzYo40XLQ+e/iVzKZI6URYV+Ztohy7Im56NVlabQrxzBdqYPMoHOb/ZMPbrw== X-Received: by 2002:a50:c05b:: with SMTP id u27mr5337617edd.290.1602350581888; Sat, 10 Oct 2020 10:23:01 -0700 (PDT) Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com. [209.85.128.45]) by smtp.gmail.com with ESMTPSA id cx12sm8679599edb.48.2020.10.10.10.22.59 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 10 Oct 2020 10:23:00 -0700 (PDT) Received: by mail-wm1-f45.google.com with SMTP id d81so12880436wmc.1 for ; Sat, 10 Oct 2020 10:22:59 -0700 (PDT) X-Received: by 2002:a1c:2d85:: with SMTP id t127mr3480262wmt.22.1602350579384; Sat, 10 Oct 2020 10:22:59 -0700 (PDT) MIME-Version: 1.0 References: <20201009075934.3509076-1-daniel.vetter@ffwll.ch> <20201009075934.3509076-10-daniel.vetter@ffwll.ch> <20201009123421.67a80d72@coco.lan> <20201009122111.GN5177@ziepe.ca> <20201009143723.45609bfb@coco.lan> <20201009124850.GP5177@ziepe.ca> In-Reply-To: From: Tomasz Figa Date: Sat, 10 Oct 2020 19:22:48 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 09/17] mm: Add unsafe_follow_pfn To: Daniel Vetter Cc: Jason Gunthorpe , Mauro Carvalho Chehab , DRI Development , LKML , KVM list , Linux MM , Linux ARM , linux-samsung-soc , "open list:DMA BUFFER SHARING FRAMEWORK" , linux-s390 , Daniel Vetter , Kees Cook , Dan Williams , Andrew Morton , John Hubbard , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Jan Kara , Linus Torvalds 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: Hi Daniel, On Fri, Oct 9, 2020 at 7:52 PM Daniel Vetter wrote: > > On Fri, Oct 9, 2020 at 2:48 PM Jason Gunthorpe wrote: > > > > On Fri, Oct 09, 2020 at 02:37:23PM +0200, Mauro Carvalho Chehab wrote: > > > > > I'm not a mm/ expert, but, from what I understood from Daniel's patch > > > description is that this is unsafe *only if* __GFP_MOVABLE is used. > > > > No, it is unconditionally unsafe. The CMA movable mappings are > > specific VMAs that will have bad issues here, but there are other > > types too. > > > > The only way to do something at a VMA level is to have a list of OK > > VMAs, eg because they were creatd via a special mmap helper from the > > media subsystem. > > > > > Well, no drivers inside the media subsystem uses such flag, although > > > they may rely on some infrastructure that could be using it behind > > > the bars. > > > > It doesn't matter, nothing prevents the user from calling media APIs > > on mmaps it gets from other subsystems. > > I think a good first step would be to disable userptr of non struct > page backed storage going forward for any new hw support. Even on > existing drivers. dma-buf sharing has been around for long enough now > that this shouldn't be a problem. Unfortunately right now this doesn't > seem to exist, so the entire problem keeps getting perpetuated. > > > > If this is the case, the proper fix seems to have a GFP_NOT_MOVABLE > > > flag that it would be denying the core mm code to set __GFP_MOVABLE. > > > > We can't tell from the VMA these kinds of details.. > > > > It has to go the other direction, evey mmap that might be used as a > > userptr here has to be found and the VMA specially created to allow > > its use. At least that is a kernel only change, but will need people > > with the HW to do this work. > > I think the only reasonable way to keep this working is: > - add a struct dma_buf *vma_tryget_dma_buf(struct vm_area_struct *vma); > - add dma-buf export support to fbdev and v4l I assume you mean V4L2 and not the obsolete V4L that is emulated in the userspace by libv4l. If so, every video device that uses videobuf2 gets DMA-buf export for free and there is nothing needed to enable it. We probably still have a few legacy drivers using videobuf (non-2), but IMHO those should be safe to put behind some disabled-by-default Kconfig symbol or even completely drop, as the legacy framework has been deprecated for many years already. > - roll this out everywhere we still need it. > > Realistically this just isn't going to happen. And anything else just > reimplements half of dma-buf, which is kinda pointless (you need > minimally refcounting and some way to get at a promise of a permanent > sg list for dma. Plus probably the vmap for kernel cpu access. > > > > Please let address the issue on this way, instead of broken an > > > userspace API that it is there since 1991. > > > > It has happened before :( It took 4 years for RDMA to undo the uAPI > > breakage caused by a security fix for something that was a 15 years > > old bug. > > Yeah we have a bunch of these on the drm side too. Some of them are > really just "you have to upgrade userspace", and there's no real fix > for the security nightmare without that. I think we need to phase out such userspace indeed. The Kconfig symbol allows enabling the unsafe functionality for anyone who still needs it, so I think it's not entirely a breakage. Best regards, Tomasz