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,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 C5C18C43457 for ; Sat, 10 Oct 2020 23:01:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8A7E42067C for ; Sat, 10 Oct 2020 23:01:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="i63KoTVh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732666AbgJJW7k (ORCPT ); Sat, 10 Oct 2020 18:59:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730479AbgJJV7Y (ORCPT ); Sat, 10 Oct 2020 17:59:24 -0400 Received: from mail-ot1-x341.google.com (mail-ot1-x341.google.com [IPv6:2607:f8b0:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F241C0613D6 for ; Sat, 10 Oct 2020 14:50:39 -0700 (PDT) Received: by mail-ot1-x341.google.com with SMTP id m13so12305680otl.9 for ; Sat, 10 Oct 2020 14:50:39 -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; bh=zskjUsHTtZxN7/2TQU3peg25br1tT43hRWFs8IXZrR4=; b=i63KoTVhRCCVQE6C47zXN/aote8oxAlq2u8XkZEfRS7C4aCQsGXOTE+Jx6GONLOzLt PE8349J61xYKgijEt/U90UIMaq9DrkU4QY1Tnas9hwBXWmOQCPO26SVsgXlr/ZipK8Ls RMwvBQZd64IkyMtuG55st8dU/i5RoewRXan9Y= 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=zskjUsHTtZxN7/2TQU3peg25br1tT43hRWFs8IXZrR4=; b=VtLKsBAiHfQuu+9HhgaeDh5PBtpuM9X3vpSQ7ycnu9lyGflzCpbRmeUJdQnpylriBQ DRll1c/DhnygW0gSA74Nyz/n8XwGk43XEBU4w3MvwrCjsSI5m8dwogQ5apVh0galYpiw iPg9PBCOOvvAk8eMt/XQy5mLm82WGTesTQlQoMvejGjq4vtXnPk5l9bSkHuf3M1jC32b uhmdEf2bgGk4GAYbgbdlyBrr13ctriTdhYxD9xreozbm+ht98KA3vdokl0vMK7Snbv5y ne4PLHB67Wl5pTkxtf/xQyyV9YC0ln5iQVH1vGLuMuLKi86JG0w2sSQGelMZYSYAIzE8 dboA== X-Gm-Message-State: AOAM530OON5+LAWUI2zjleKLPJ9V6PsLGivQh5k0xxy8vugUdXzjpYrw h2PLaVA7XmqQ6h67qc4NjT9P8M+i/Fy+RtfzWSb95Q== X-Google-Smtp-Source: ABdhPJznztyXj83TXT5Po+mKIPpYBLH3P+nInP8snkNIpnPLWv+XbgGvuCQZzJCVdvnd+c/ezVPBdFh+cvOLaSiqshs= X-Received: by 2002:a05:6830:8b:: with SMTP id a11mr2057108oto.303.1602366638562; Sat, 10 Oct 2020 14:50:38 -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> <20201010213554.GD3939@pendragon.ideasonboard.com> In-Reply-To: <20201010213554.GD3939@pendragon.ideasonboard.com> From: Daniel Vetter Date: Sat, 10 Oct 2020 23:50:27 +0200 Message-ID: Subject: Re: [PATCH v2 09/17] mm: Add unsafe_follow_pfn To: Laurent Pinchart Cc: Tomasz Figa , linux-s390 , linux-samsung-soc , Jan Kara , Kees Cook , KVM list , Linux MM , Mauro Carvalho Chehab , John Hubbard , LKML , DRI Development , Jason Gunthorpe , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Daniel Vetter , Dan Williams , Linus Torvalds , Andrew Morton , Linux ARM , "open list:DMA BUFFER SHARING FRAMEWORK" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Oct 10, 2020 at 11:36 PM Laurent Pinchart wrote: > > Hi Tomasz, > > On Sat, Oct 10, 2020 at 07:22:48PM +0200, Tomasz Figa wrote: > > 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. Yeah. And I missed that v4l2 added dma-buf export too. > > 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. > > There's 8 drivers left, and they support a very large number of devices. > I expect unhappy users distros stop shipping them. On the other hand, > videobuf has been deprecated for a loooooooong time, so there has been > plenty of time to convert the remaining drivers to videobuf2. If nobody > can do it, then we'll have to drop support for these devices given the > security issues. Again, the issue here is _only_ with follow_pfn. For videobuf1 this means videbuf-dma-contig.c userptr support is broken. Unlike videobuf2 it means it's broken for all usage (not just zero-copy userptr), because videbuf-dma-contig.c lacks the pin_user_pages path. But that would be easy to add if this poses a problem I think - we just need to carry over the pin_user_pages_fast logic from videbuf2, no driver changes required. But of course I don't think we should do that before someone reports the regression, since videobuf1 userptr is doubly deprecated :-) Everything else keeps working with videobuf1 with my patch series. So depending upon which videobuf1 implementations these 8 drivers use, you might not even have any real breakage there. > We have moved media drivers to staging in the past when there wasn't > enough maintenance effort, we could do so here too. I'm not breaking the world with this, it's really very minimal use-case. At least as far as I'm understanding the entire media subsystem here. -Daniel > > > - 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. > > -- > Regards, > > Laurent Pinchart -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch 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.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,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 62627C433E7 for ; Sat, 10 Oct 2020 21:52:22 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 012D520679 for ; Sat, 10 Oct 2020 21:52:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="P8Vc2qUn"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="i63KoTVh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 012D520679 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=HZjGngPQxQeVjtWkByM1IOpu4qBmnRZduvtRRGPMKPA=; b=P8Vc2qUnxRuv+2xXvASn2eof+ Tg8s2dsT6tpTsi56eGv3XkqDEIkFFueGe6y634oSXVtguTcpa0wKUy2ZA/dCyp9Divg3NyG2EJl1Y VOh0lfbSQPg3z1ngMa54oB2z1aqMEPRly1AcbTYDmXLtihXLdcsLhPDTqyJkQ/4GxfUSyCidiFLwR 3klgqck4mNfwa6Zy3ilJi2X7mlfbD7d4FFvDMcAzTzzmSyaGiTFrzEFMExrdQxPTfekUtiQyJSUad o/7JFxPucxx5zAPSK7s3y9KUCUa97By/jd++nr4Bn5M35jbwm+F82XjSjwt82f8xGAZBmnvzTVEwa oe0zcaS2g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kRMlI-0005M8-6N; Sat, 10 Oct 2020 21:50:44 +0000 Received: from mail-ot1-x344.google.com ([2607:f8b0:4864:20::344]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kRMlE-0005KH-FS for linux-arm-kernel@lists.infradead.org; Sat, 10 Oct 2020 21:50:42 +0000 Received: by mail-ot1-x344.google.com with SMTP id d28so12363216ote.1 for ; Sat, 10 Oct 2020 14:50:40 -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; bh=zskjUsHTtZxN7/2TQU3peg25br1tT43hRWFs8IXZrR4=; b=i63KoTVhRCCVQE6C47zXN/aote8oxAlq2u8XkZEfRS7C4aCQsGXOTE+Jx6GONLOzLt PE8349J61xYKgijEt/U90UIMaq9DrkU4QY1Tnas9hwBXWmOQCPO26SVsgXlr/ZipK8Ls RMwvBQZd64IkyMtuG55st8dU/i5RoewRXan9Y= 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=zskjUsHTtZxN7/2TQU3peg25br1tT43hRWFs8IXZrR4=; b=f5m/Uz4c00HPFA0pFThRYjuOawzG6GJ6t7ucYZ9xhILrXlFY2rGmZlQC7Iont2YxOe ytVlTtKVgtgs3+J1M56k4rFcJ67ybIp20dk0BSI//KzUiyq0MhUSlY/KGyjiWH9k8B8W PxR4ojPIXDoqQSPUWjKym34+CnlWQBCU/KY2+sx4PkZwmRycRdW+JO0B9ST5yrJ2bqly IpmNSBOHDlS4/5+dPZjky9ZAx7HaUivVrVem50aJlkVsf4uK3VKI07arf6F3KR0P4JJr AX8c8GZfhNB8EMt3LWHGHNUGMFO8zR9Gj1egcwsGnSnIEvXwdoONkQk9SZV1cThC66en I1ZQ== X-Gm-Message-State: AOAM5305gi58S0U3tHbIT5e7EIa8JeflxZgXZz82jxJseZjLcAlYsXE3 GoZrzWNJXThW9ihrJqnt9WQDBmxB4A0yx9RoGwTO9A== X-Google-Smtp-Source: ABdhPJznztyXj83TXT5Po+mKIPpYBLH3P+nInP8snkNIpnPLWv+XbgGvuCQZzJCVdvnd+c/ezVPBdFh+cvOLaSiqshs= X-Received: by 2002:a05:6830:8b:: with SMTP id a11mr2057108oto.303.1602366638562; Sat, 10 Oct 2020 14:50:38 -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> <20201010213554.GD3939@pendragon.ideasonboard.com> In-Reply-To: <20201010213554.GD3939@pendragon.ideasonboard.com> From: Daniel Vetter Date: Sat, 10 Oct 2020 23:50:27 +0200 Message-ID: Subject: Re: [PATCH v2 09/17] mm: Add unsafe_follow_pfn To: Laurent Pinchart X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201010_175040_886416_841948FB X-CRM114-Status: GOOD ( 49.06 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-s390 , linux-samsung-soc , Jan Kara , Kees Cook , KVM list , Jason Gunthorpe , Mauro Carvalho Chehab , John Hubbard , LKML , DRI Development , Tomasz Figa , Linux MM , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Daniel Vetter , Dan Williams , Linus Torvalds , Andrew Morton , Linux ARM , "open list:DMA BUFFER SHARING FRAMEWORK" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Sat, Oct 10, 2020 at 11:36 PM Laurent Pinchart wrote: > > Hi Tomasz, > > On Sat, Oct 10, 2020 at 07:22:48PM +0200, Tomasz Figa wrote: > > 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. Yeah. And I missed that v4l2 added dma-buf export too. > > 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. > > There's 8 drivers left, and they support a very large number of devices. > I expect unhappy users distros stop shipping them. On the other hand, > videobuf has been deprecated for a loooooooong time, so there has been > plenty of time to convert the remaining drivers to videobuf2. If nobody > can do it, then we'll have to drop support for these devices given the > security issues. Again, the issue here is _only_ with follow_pfn. For videobuf1 this means videbuf-dma-contig.c userptr support is broken. Unlike videobuf2 it means it's broken for all usage (not just zero-copy userptr), because videbuf-dma-contig.c lacks the pin_user_pages path. But that would be easy to add if this poses a problem I think - we just need to carry over the pin_user_pages_fast logic from videbuf2, no driver changes required. But of course I don't think we should do that before someone reports the regression, since videobuf1 userptr is doubly deprecated :-) Everything else keeps working with videobuf1 with my patch series. So depending upon which videobuf1 implementations these 8 drivers use, you might not even have any real breakage there. > We have moved media drivers to staging in the past when there wasn't > enough maintenance effort, we could do so here too. I'm not breaking the world with this, it's really very minimal use-case. At least as far as I'm understanding the entire media subsystem here. -Daniel > > > - 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. > > -- > Regards, > > Laurent Pinchart -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel 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.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 03164C433E7 for ; Sat, 10 Oct 2020 21:50:41 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8E4742078A for ; Sat, 10 Oct 2020 21:50:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="i63KoTVh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8E4742078A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 153B46E0C8; Sat, 10 Oct 2020 21:50:40 +0000 (UTC) Received: from mail-ot1-x341.google.com (mail-ot1-x341.google.com [IPv6:2607:f8b0:4864:20::341]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4F5256E0C8 for ; Sat, 10 Oct 2020 21:50:39 +0000 (UTC) Received: by mail-ot1-x341.google.com with SMTP id t15so12380680otk.0 for ; Sat, 10 Oct 2020 14:50:39 -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; bh=zskjUsHTtZxN7/2TQU3peg25br1tT43hRWFs8IXZrR4=; b=i63KoTVhRCCVQE6C47zXN/aote8oxAlq2u8XkZEfRS7C4aCQsGXOTE+Jx6GONLOzLt PE8349J61xYKgijEt/U90UIMaq9DrkU4QY1Tnas9hwBXWmOQCPO26SVsgXlr/ZipK8Ls RMwvBQZd64IkyMtuG55st8dU/i5RoewRXan9Y= 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=zskjUsHTtZxN7/2TQU3peg25br1tT43hRWFs8IXZrR4=; b=sKfJojkVf7faeOuyk8XyoURhDeTrpOYLFhgVajny0wg2lKNzkOXw4tsBx5KmNtI11v 3PQ3Omo6bD0vMSY624fp65AhHiLpcqkQQHg7MGOfwb15f3DZDyUlBs/x7iMakJnbOXx0 OncyfTPQiGUuJQlu9tvF6ojhUFDMef8ObjVVC+5/are3sun/VTTRNymUZLfYICPfuRpX tL6v0IdervnT9sT1ELO3R9ptulYbjFLxiLmvm2IF7rUFvUdW8ehQCKkI0UBRxwNHSWnl JwOoMi0Lye3da8vIEvIAt0GE9j1tqjG5k0vj8E0+9VqhHg1oEtF0qeH3Hv7DlEDy7riQ waRQ== X-Gm-Message-State: AOAM533cEk7h1wNmXUhfhDXN0RqmLWdByhGSV3DqpyUmHpRr3VwRVu1Y wmWEOSQomkv3qX4r8LOeOGZEvskXh5tcf1ntbRftow== X-Google-Smtp-Source: ABdhPJznztyXj83TXT5Po+mKIPpYBLH3P+nInP8snkNIpnPLWv+XbgGvuCQZzJCVdvnd+c/ezVPBdFh+cvOLaSiqshs= X-Received: by 2002:a05:6830:8b:: with SMTP id a11mr2057108oto.303.1602366638562; Sat, 10 Oct 2020 14:50:38 -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> <20201010213554.GD3939@pendragon.ideasonboard.com> In-Reply-To: <20201010213554.GD3939@pendragon.ideasonboard.com> From: Daniel Vetter Date: Sat, 10 Oct 2020 23:50:27 +0200 Message-ID: Subject: Re: [PATCH v2 09/17] mm: Add unsafe_follow_pfn To: Laurent Pinchart X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-s390 , linux-samsung-soc , Jan Kara , Kees Cook , KVM list , Jason Gunthorpe , Mauro Carvalho Chehab , John Hubbard , LKML , DRI Development , Tomasz Figa , Linux MM , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Daniel Vetter , Dan Williams , Linus Torvalds , Andrew Morton , Linux ARM , "open list:DMA BUFFER SHARING FRAMEWORK" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Sat, Oct 10, 2020 at 11:36 PM Laurent Pinchart wrote: > > Hi Tomasz, > > On Sat, Oct 10, 2020 at 07:22:48PM +0200, Tomasz Figa wrote: > > 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. Yeah. And I missed that v4l2 added dma-buf export too. > > 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. > > There's 8 drivers left, and they support a very large number of devices. > I expect unhappy users distros stop shipping them. On the other hand, > videobuf has been deprecated for a loooooooong time, so there has been > plenty of time to convert the remaining drivers to videobuf2. If nobody > can do it, then we'll have to drop support for these devices given the > security issues. Again, the issue here is _only_ with follow_pfn. For videobuf1 this means videbuf-dma-contig.c userptr support is broken. Unlike videobuf2 it means it's broken for all usage (not just zero-copy userptr), because videbuf-dma-contig.c lacks the pin_user_pages path. But that would be easy to add if this poses a problem I think - we just need to carry over the pin_user_pages_fast logic from videbuf2, no driver changes required. But of course I don't think we should do that before someone reports the regression, since videobuf1 userptr is doubly deprecated :-) Everything else keeps working with videobuf1 with my patch series. So depending upon which videobuf1 implementations these 8 drivers use, you might not even have any real breakage there. > We have moved media drivers to staging in the past when there wasn't > enough maintenance effort, we could do so here too. I'm not breaking the world with this, it's really very minimal use-case. At least as far as I'm understanding the entire media subsystem here. -Daniel > > > - 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. > > -- > Regards, > > Laurent Pinchart -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel