Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp3408402pxu; Sun, 11 Oct 2020 08:37:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw61wpTmf2bFZ0ZOW7htgSpart96dd6mccL0uVQq/dlLuMsUbi6OuzoYJY9IrKMEmHhGMi5 X-Received: by 2002:a05:6402:945:: with SMTP id h5mr9833998edz.6.1602430649019; Sun, 11 Oct 2020 08:37:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602430648; cv=none; d=google.com; s=arc-20160816; b=dd2rY0g6KKDWVfahvUpbMmhjdzbg9BTopNmhwEv9+vtoKYxESz050qAjO61xMPK9Gp 1BMtOJ+Kse25n60UUKLTQ4eqbSFiYaSVEJknRpnc2SXb+TXWQXHAmePdYQE14QIS6z0r 7M8ZS1DlsSpNa9ctcYnzI4sWroycEphYv9rpnULGYSdOGe8YSGbH4PaC/PbWpYBHIqW2 YmmUPoRRaTvXtARmDl6HLfXAedkBZ7zxrda1NywkHimLxM9N6t1zOu/buci/uPR3P3R5 ox5addvd5J65fS/QbF3gMUvn0sqUBTJ5Q15ZzdCSXWcN+af+8XUHj1uEu7iHiV/23++B GgLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=AkcMDQ9MzR0MXrPdl4Z5WIlaKuGLuztzGgHABJ/UwRo=; b=xRFKIQA7Q+/LsHt/Wq0yQWfHlKmy7WHIfm6KSORSm+h1h48yMipVleCL+MUazjtBHb Rnqtizt+ExKoG8yCmIh4rtrZN5leYg84SAocfXWHnjGNmkiaLC2pTfmnAyjbAWKZzK4i mj/sN0HHcylImx5w09hHaksvQc/96FbUPftFaGl9KjnlX20W8mSbix6D02ZuIJwCKNE5 pbCgzA03SrOsRiLqxZVfddFt4sVBgFMh2uzGuPdG071WqR6W1Hjzx1q/imWcRoekMF++ gwu/SbZL7KtUk6r+YpapireFYI411lim7Xru0GtIX9nePd/YkkpScm1QSEJaxRthK+CG kLdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Tn1BNmOZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g23si1544558edh.377.2020.10.11.08.37.05; Sun, 11 Oct 2020 08:37:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Tn1BNmOZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730293AbgJJW6f (ORCPT + 99 others); Sat, 10 Oct 2020 18:58:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731170AbgJJTxO (ORCPT ); Sat, 10 Oct 2020 15:53:14 -0400 Received: from mail-ed1-x541.google.com (mail-ed1-x541.google.com [IPv6:2a00:1450:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B853C08EA77 for ; Sat, 10 Oct 2020 10:23:03 -0700 (PDT) Received: by mail-ed1-x541.google.com with SMTP id dg9so10300205edb.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=fngoOloc0Tl/UeHxePi5izrdMpKTcVLhD3zQP6qR7nlXANW1JKLN3wG099ieZUehTW Nx8z+UBxg81zZ2TB+b7AhpW1FHgwzJI7CGHtmIC2VrRtn0Ef5BLSaI5Si2DGuEUXV04f 4r8N0K0deiUXnIFCU/h3AflsHUG9gCCvj8Ivt7N4lUxTCfigjyz23O9wNkRpiTx4SBJY BeKKoDhSh0w73fmktd57BUJTLq2rLoAqip4I325HfLdnA3e1vC0wwbTNBlDTKVbGPES2 2nhdHi8e1JO4cxCtKV86oDx2imGyj0fbHcQii5yzBHZEYW9EPFARovTOUDNE0XSKhqJw N3FA== X-Gm-Message-State: AOAM5320oUH7dy/8dUEkvfiB26ovXG+ag1HZXWMGPZI8IskteoeY9QWJ tfhcUG0vA3Gu1eNFiKYOzZq3kI02Ikxs8Q== X-Received: by 2002:aa7:d781:: with SMTP id s1mr5594197edq.102.1602350581743; Sat, 10 Oct 2020 10:23:01 -0700 (PDT) Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com. [209.85.128.42]) by smtp.gmail.com with ESMTPSA id m16sm7722480edj.37.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-f42.google.com with SMTP id e23so5856603wme.2 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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