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 BEFB4C41604 for ; Wed, 7 Oct 2020 23:24:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 675EF20789 for ; Wed, 7 Oct 2020 23:24:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="Bk3vyARb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728008AbgJGXYv (ORCPT ); Wed, 7 Oct 2020 19:24:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727033AbgJGXYv (ORCPT ); Wed, 7 Oct 2020 19:24:51 -0400 Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA350C0613D5 for ; Wed, 7 Oct 2020 16:24:50 -0700 (PDT) Received: by mail-qt1-x843.google.com with SMTP id q26so3575135qtb.5 for ; Wed, 07 Oct 2020 16:24:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=grnZFDXCMGq7gJnj3rv4Eh6ohpICuLZnEtrVn22rZIo=; b=Bk3vyARb7iuiAU0SAUq2s6xtQRFkx0zrhk9G+DPyvRRbTItWJ6gpJPPsdXndWqM30C q+51nknw/1tIIM/cbEQqZbvmH3mHkhAx0ZhbONTIkwW+SkBnLf5drgGQk3B1JkUtZLQv md+QvQFk56zu60Z3GjZl1EqhU0rhhNSdsHAK30qke9EYBs5AaSpcAL2z/rCUCwa8FQqH 2eNBU8guUIVdzfovxzjr065TJHAf7Ql5Nk2Q1fuOqG9vuautugZBwiS50HM9Bf6R7BJy wX6YvRVCp5ueNYkN+1r4/AuMm2/5dBOzuXJknmpl6H2z8DDtJhmovZxfsbStATmFT07H 6VSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=grnZFDXCMGq7gJnj3rv4Eh6ohpICuLZnEtrVn22rZIo=; b=foFKOP9MPpnTkABfmnbqr/qbQMmBNMqTwpN7whOhYOFfCbWDdEPKNHWHFVcepwGW7G iIJmNaRZeBbhsyQYO5FgIMPFZk7UMt4TMIpyGn1Lfqpo+JimAGhF3Ia6tHPCfSgJlxdl HSGR1yeuJoEHlo5+KJyAKiLfqzFk0TyACSuoy/2YJRq5+09/N472i3FVjo6rIs8F8gEC FZy6KBjZ0sufAM4rRYTZA0WwNKqypO7tmOtzgaWTr+OvKyTJIy1jmYuS2j8rDgReaURk WbWi4VVp+w8DBL5VU22zhJiKWMrZYewM6MI7mOS3ZSd1ObmRcbXODwm/zFWZnsiDclGJ pfFw== X-Gm-Message-State: AOAM5325OCnP9I8iiY+Bs+t4KD99FezCe3OTLvnxdzoEO0RJ10WXOmhu 1A4PYSsBr6geKSTwqdZwNKom4g== X-Google-Smtp-Source: ABdhPJwQSs4RGdtelbtYNd2YLomE1YhjE8V063EOvVpVE89mpXbPIH2mKCjwjLbwP7cugbXVynYwbw== X-Received: by 2002:aed:3282:: with SMTP id z2mr6021380qtd.375.1602113090013; Wed, 07 Oct 2020 16:24:50 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-156-34-48-30.dhcp-dynamic.fibreop.ns.bellaliant.net. [156.34.48.30]) by smtp.gmail.com with ESMTPSA id r17sm2946100qtc.22.2020.10.07.16.24.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Oct 2020 16:24:49 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kQIng-001Ing-AW; Wed, 07 Oct 2020 20:24:48 -0300 Date: Wed, 7 Oct 2020 20:24:48 -0300 From: Jason Gunthorpe To: Dan Williams Cc: Daniel Vetter , DRI Development , LKML , KVM list , Linux MM , Linux ARM , linux-samsung-soc , "Linux-media@vger.kernel.org" , linux-s390 , Daniel Vetter , Kees Cook , Andrew Morton , John Hubbard , =?utf-8?B?SsOpcsO0bWU=?= Glisse , Jan Kara , Bjorn Helgaas , linux-pci@vger.kernel.org Subject: Re: [PATCH 10/13] PCI: revoke mappings like devmem Message-ID: <20201007232448.GC5177@ziepe.ca> References: <20201007164426.1812530-1-daniel.vetter@ffwll.ch> <20201007164426.1812530-11-daniel.vetter@ffwll.ch> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 07, 2020 at 12:33:06PM -0700, Dan Williams wrote: > On Wed, Oct 7, 2020 at 11:11 AM Daniel Vetter wrote: > > > > Since 3234ac664a87 ("/dev/mem: Revoke mappings when a driver claims > > the region") /dev/kmem zaps ptes when the kernel requests exclusive > > acccess to an iomem region. And with CONFIG_IO_STRICT_DEVMEM, this is > > the default for all driver uses. > > > > Except there's two more ways to access pci bars: sysfs and proc mmap > > support. Let's plug that hole. > > Ooh, yes, lets. > > > > > For revoke_devmem() to work we need to link our vma into the same > > address_space, with consistent vma->vm_pgoff. ->pgoff is already > > adjusted, because that's how (io_)remap_pfn_range works, but for the > > mapping we need to adjust vma->vm_file->f_mapping. Usually that's done > > at ->open time, but that's a bit tricky here with all the entry points > > and arch code. So instead create a fake file and adjust vma->vm_file. > > I don't think you want to share the devmem inode for this, this should > be based off the sysfs inode which I believe there is already only one > instance per resource. In contrast /dev/mem can have multiple inodes > because anyone can just mknod a new character device file, the same > problem does not exist for sysfs. The inode does not come from the filesystem char/mem.c creates a singular anon inode in devmem_init_inode() Seems OK to use this more widely, but it feels a bit weird to live in char/memory.c. This is what got me thinking maybe this needs to be a bit bigger generic infrastructure - eg enter this scheme from fops mmap and everything else is in mm/user_iomem.c Jason 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=-4.5 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 CFD5AC4363D for ; Wed, 7 Oct 2020 23:26:05 +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 69C102053B for ; Wed, 7 Oct 2020 23:26:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="3MeTbIjh"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="Bk3vyARb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 69C102053B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca 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:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=rcclAHk8JNGKNfHdNP78+Xg/uxlwev20Jsk4AiR8pZ0=; b=3MeTbIjhp6GSvfLsuhPpYqdba t6+OBbRqybO4AK0CmowmZmgdFmTraOE4bCzafmUAhgWhnvviHkA34PfFHiMgOz54ra6J26/lfIHr9 ldlTokiILYJl4LFLDgpRngTkYBkNEcUz+PQFdx3Ag9yL2V6dAivpfj7ej9Gk1wXJB7c1dht1xePH+ SqRngUpEHAA3HhOD0wYhQWkKoYg1tVstb1pgy8XsUcp4FJzVYy+VUT9CKsApCNEmWP+dzafWBfvfP 2drlQ8AXDnL+OUfrmnz426KCtK64TTrQMWKb8ST/U+sT4EkqxKaHIPoSi5U0VsRUQ57lH3P1CoYC2 +oax58z7g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQInl-0007qb-Q0; Wed, 07 Oct 2020 23:24:53 +0000 Received: from mail-qt1-x843.google.com ([2607:f8b0:4864:20::843]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQInj-0007po-LL for linux-arm-kernel@lists.infradead.org; Wed, 07 Oct 2020 23:24:52 +0000 Received: by mail-qt1-x843.google.com with SMTP id c5so3577720qtw.3 for ; Wed, 07 Oct 2020 16:24:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=grnZFDXCMGq7gJnj3rv4Eh6ohpICuLZnEtrVn22rZIo=; b=Bk3vyARb7iuiAU0SAUq2s6xtQRFkx0zrhk9G+DPyvRRbTItWJ6gpJPPsdXndWqM30C q+51nknw/1tIIM/cbEQqZbvmH3mHkhAx0ZhbONTIkwW+SkBnLf5drgGQk3B1JkUtZLQv md+QvQFk56zu60Z3GjZl1EqhU0rhhNSdsHAK30qke9EYBs5AaSpcAL2z/rCUCwa8FQqH 2eNBU8guUIVdzfovxzjr065TJHAf7Ql5Nk2Q1fuOqG9vuautugZBwiS50HM9Bf6R7BJy wX6YvRVCp5ueNYkN+1r4/AuMm2/5dBOzuXJknmpl6H2z8DDtJhmovZxfsbStATmFT07H 6VSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=grnZFDXCMGq7gJnj3rv4Eh6ohpICuLZnEtrVn22rZIo=; b=eX0vdbsmLdXponp9sRibvzm9dlJy/fNub/V4xHSS+GJ+IFQEAyvDGDxbzvrOiYtMxR PIDGxdD7D+p6aPRVXCZxUikHfYJxIZJ0ii7qpREqEWmwrf/sSviBZ5IKKupR2w0ytfPA QEa+dpHMpvG/7vM/L27V+4af1UVp7iiuaRebycFywR0ZU02jTqRyYci75CLpvCJdtgT/ B63j1zwx9/E4gIjDKJ6biPdYn1Zau2u9KddVVFaX2u4QqOsoAjEueGd55NgBBjzCeR1a rYfHSmvzPr36t1RYZ06oM3Z+uCyrsK4HbbxH3Zzia7xlkbMz6cT1+4p/D4OuUIdTepaG 9Jtw== X-Gm-Message-State: AOAM531HJCUmStwte7hBsuMwtmDwGXeCHipC8vfTmCBGmNBTrQghU25O HELJXF7MRaC+1IF76mvqu3XWMg== X-Google-Smtp-Source: ABdhPJwQSs4RGdtelbtYNd2YLomE1YhjE8V063EOvVpVE89mpXbPIH2mKCjwjLbwP7cugbXVynYwbw== X-Received: by 2002:aed:3282:: with SMTP id z2mr6021380qtd.375.1602113090013; Wed, 07 Oct 2020 16:24:50 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-156-34-48-30.dhcp-dynamic.fibreop.ns.bellaliant.net. [156.34.48.30]) by smtp.gmail.com with ESMTPSA id r17sm2946100qtc.22.2020.10.07.16.24.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Oct 2020 16:24:49 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kQIng-001Ing-AW; Wed, 07 Oct 2020 20:24:48 -0300 Date: Wed, 7 Oct 2020 20:24:48 -0300 From: Jason Gunthorpe To: Dan Williams Subject: Re: [PATCH 10/13] PCI: revoke mappings like devmem Message-ID: <20201007232448.GC5177@ziepe.ca> References: <20201007164426.1812530-1-daniel.vetter@ffwll.ch> <20201007164426.1812530-11-daniel.vetter@ffwll.ch> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201007_192451_728604_55ABA0DC X-CRM114-Status: GOOD ( 21.32 ) 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 , Daniel Vetter , linux-pci@vger.kernel.org, LKML , DRI Development , Linux MM , =?utf-8?B?SsOpcsO0bWU=?= Glisse , John Hubbard , Bjorn Helgaas , Daniel Vetter , Andrew Morton , Linux ARM , "Linux-media@vger.kernel.org" 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 Wed, Oct 07, 2020 at 12:33:06PM -0700, Dan Williams wrote: > On Wed, Oct 7, 2020 at 11:11 AM Daniel Vetter wrote: > > > > Since 3234ac664a87 ("/dev/mem: Revoke mappings when a driver claims > > the region") /dev/kmem zaps ptes when the kernel requests exclusive > > acccess to an iomem region. And with CONFIG_IO_STRICT_DEVMEM, this is > > the default for all driver uses. > > > > Except there's two more ways to access pci bars: sysfs and proc mmap > > support. Let's plug that hole. > > Ooh, yes, lets. > > > > > For revoke_devmem() to work we need to link our vma into the same > > address_space, with consistent vma->vm_pgoff. ->pgoff is already > > adjusted, because that's how (io_)remap_pfn_range works, but for the > > mapping we need to adjust vma->vm_file->f_mapping. Usually that's done > > at ->open time, but that's a bit tricky here with all the entry points > > and arch code. So instead create a fake file and adjust vma->vm_file. > > I don't think you want to share the devmem inode for this, this should > be based off the sysfs inode which I believe there is already only one > instance per resource. In contrast /dev/mem can have multiple inodes > because anyone can just mknod a new character device file, the same > problem does not exist for sysfs. The inode does not come from the filesystem char/mem.c creates a singular anon inode in devmem_init_inode() Seems OK to use this more widely, but it feels a bit weird to live in char/memory.c. This is what got me thinking maybe this needs to be a bit bigger generic infrastructure - eg enter this scheme from fops mmap and everything else is in mm/user_iomem.c Jason _______________________________________________ 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 108BCC04EBE for ; Thu, 8 Oct 2020 07:21:17 +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 9DD2221D41 for ; Thu, 8 Oct 2020 07:21:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="Bk3vyARb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9DD2221D41 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca 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 D39E66EA3D; Thu, 8 Oct 2020 07:20:59 +0000 (UTC) Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by gabe.freedesktop.org (Postfix) with ESMTPS id D57146E9CC for ; Wed, 7 Oct 2020 23:24:50 +0000 (UTC) Received: by mail-qt1-x843.google.com with SMTP id s47so3585427qth.4 for ; Wed, 07 Oct 2020 16:24:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=grnZFDXCMGq7gJnj3rv4Eh6ohpICuLZnEtrVn22rZIo=; b=Bk3vyARb7iuiAU0SAUq2s6xtQRFkx0zrhk9G+DPyvRRbTItWJ6gpJPPsdXndWqM30C q+51nknw/1tIIM/cbEQqZbvmH3mHkhAx0ZhbONTIkwW+SkBnLf5drgGQk3B1JkUtZLQv md+QvQFk56zu60Z3GjZl1EqhU0rhhNSdsHAK30qke9EYBs5AaSpcAL2z/rCUCwa8FQqH 2eNBU8guUIVdzfovxzjr065TJHAf7Ql5Nk2Q1fuOqG9vuautugZBwiS50HM9Bf6R7BJy wX6YvRVCp5ueNYkN+1r4/AuMm2/5dBOzuXJknmpl6H2z8DDtJhmovZxfsbStATmFT07H 6VSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=grnZFDXCMGq7gJnj3rv4Eh6ohpICuLZnEtrVn22rZIo=; b=I8iZB8YWFI/QywCkq6+RqS5K9ivbOEFaKOHVmvc8Oc5GvlU0KKdpdiSytXqkbRnOvl 8qp5WBxll61BmFQtJtwOBJzFLv0XIgQKm/LWAeOjqR+qwIcCj5nKXa3s2ock2VWO4FFL z5RyRQKcPqH5g8St/KI+Cx6xAFXpeqMchsKiDPV3K3bGnJqHFb8Ckw0Sy5fA2UO9ROGh yH+6WY0WZoXoc6JE761dznemW557AdCfdinj1gaYIFsKIjU4vGosxCplrYSygYQt2EIc Ps67BrFeCZs/BiRJ4WvdfaUBr0r5sTeCFRaBwfEEyj2qRs6XsEC06JV7eqlmI+oaYnLR aatQ== X-Gm-Message-State: AOAM530YLdoo6TeefTqhk2FFmI5YubGGCP4hkSQsRZ6nSuchS+MZ0wA3 OhNogZmGd3Jlo3rO0kWmK2K6AA== X-Google-Smtp-Source: ABdhPJwQSs4RGdtelbtYNd2YLomE1YhjE8V063EOvVpVE89mpXbPIH2mKCjwjLbwP7cugbXVynYwbw== X-Received: by 2002:aed:3282:: with SMTP id z2mr6021380qtd.375.1602113090013; Wed, 07 Oct 2020 16:24:50 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-156-34-48-30.dhcp-dynamic.fibreop.ns.bellaliant.net. [156.34.48.30]) by smtp.gmail.com with ESMTPSA id r17sm2946100qtc.22.2020.10.07.16.24.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Oct 2020 16:24:49 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kQIng-001Ing-AW; Wed, 07 Oct 2020 20:24:48 -0300 Date: Wed, 7 Oct 2020 20:24:48 -0300 From: Jason Gunthorpe To: Dan Williams Subject: Re: [PATCH 10/13] PCI: revoke mappings like devmem Message-ID: <20201007232448.GC5177@ziepe.ca> References: <20201007164426.1812530-1-daniel.vetter@ffwll.ch> <20201007164426.1812530-11-daniel.vetter@ffwll.ch> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailman-Approved-At: Thu, 08 Oct 2020 07:20:54 +0000 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 , Daniel Vetter , linux-pci@vger.kernel.org, LKML , DRI Development , Linux MM , =?utf-8?B?SsOpcsO0bWU=?= Glisse , John Hubbard , Bjorn Helgaas , Daniel Vetter , Andrew Morton , Linux ARM , "Linux-media@vger.kernel.org" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Wed, Oct 07, 2020 at 12:33:06PM -0700, Dan Williams wrote: > On Wed, Oct 7, 2020 at 11:11 AM Daniel Vetter wrote: > > > > Since 3234ac664a87 ("/dev/mem: Revoke mappings when a driver claims > > the region") /dev/kmem zaps ptes when the kernel requests exclusive > > acccess to an iomem region. And with CONFIG_IO_STRICT_DEVMEM, this is > > the default for all driver uses. > > > > Except there's two more ways to access pci bars: sysfs and proc mmap > > support. Let's plug that hole. > > Ooh, yes, lets. > > > > > For revoke_devmem() to work we need to link our vma into the same > > address_space, with consistent vma->vm_pgoff. ->pgoff is already > > adjusted, because that's how (io_)remap_pfn_range works, but for the > > mapping we need to adjust vma->vm_file->f_mapping. Usually that's done > > at ->open time, but that's a bit tricky here with all the entry points > > and arch code. So instead create a fake file and adjust vma->vm_file. > > I don't think you want to share the devmem inode for this, this should > be based off the sysfs inode which I believe there is already only one > instance per resource. In contrast /dev/mem can have multiple inodes > because anyone can just mknod a new character device file, the same > problem does not exist for sysfs. The inode does not come from the filesystem char/mem.c creates a singular anon inode in devmem_init_inode() Seems OK to use this more widely, but it feels a bit weird to live in char/memory.c. This is what got me thinking maybe this needs to be a bit bigger generic infrastructure - eg enter this scheme from fops mmap and everything else is in mm/user_iomem.c Jason _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel