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 2F539C43467 for ; Thu, 8 Oct 2020 08:37:32 +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 8FBCE215A4 for ; Thu, 8 Oct 2020 08:37:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Llup/evv"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=intel-com.20150623.gappssmtp.com header.i=@intel-com.20150623.gappssmtp.com header.b="YbQ4JKBc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8FBCE215A4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com 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=JoPYnKo8eVGItv6nVXKJ5HDyfSUZZRpJctdxGuhzwso=; b=Llup/evvm318XqC6u7JSPlGot rYV3KS+gAp42A2u2f6k/4jcheTJ0VoHGhFSN/CO4sRtukav1+loisl5I+ajnUvl9QpmadxJIvuxXl 2a55kDuulPP/8w2tIsSEXSF4qV1CqTNYLjrmpoFTrZsoDe35qfSjUveDk3/vvm7DeYikAqOHxB+DI QJ9Q3g35qzGrQW8IQ9gbed+0VxnmrzyVUFXJ3ahKDN1gAEuwauj+OCC11iG2qeil8VCma4r7INIEr JyIf3Le7eg9p25qqyFdoBH4eRyTT4Jz24ourpQnGuQZm8fjrhhJZqKbntbdXW56oXYkbexA/OWUxb jRlofgVlQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQRP2-0004QE-Rx; Thu, 08 Oct 2020 08:35:56 +0000 Received: from mail-ed1-x544.google.com ([2a00:1450:4864:20::544]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQROz-0004Pl-RJ for linux-arm-kernel@lists.infradead.org; Thu, 08 Oct 2020 08:35:54 +0000 Received: by mail-ed1-x544.google.com with SMTP id p13so4966067edi.7 for ; Thu, 08 Oct 2020 01:35:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=jJ+2+sl7v16ZFQwrrbmFXcTV3fSlDqvjbzZU8FH7J0k=; b=YbQ4JKBcC915g3FwIkD4kMLjfA+HVo2VeyW7+RDRzBMyT6+pZrez6yFdxS1JVF+MCw I9fi5xpJkCMQ1MZFTgUNhIEalXi4O0KwTMs6M55IBSfgwcTCW7bCzjzwadX5IHs01Ys+ QUkVJA+YFpvasOLS9njwPhCahsqEDmCIU3hjqiJOLg6eOuSAtlQRKOhBK1ipMWiljZWh bYsA4n/IJXJ6UoXazYhMMo1uHPy0DHAjqas/E118aED/AKQSL4ZqYOLHJELydII57n0C lMedTQeMsrYtUwkqt58wwsiqUj0n2XZJEoEzBMy4uQlfr4hZt8lgFUBScrlQH+fPt2h/ k/2A== 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=jJ+2+sl7v16ZFQwrrbmFXcTV3fSlDqvjbzZU8FH7J0k=; b=nCbG5p/kxbImM6BFs+Geh3KcB6ep7/m0w2v6uyyrEs03oIJX3iZUJk4OqIAxFKDVD8 LGF/mZwk7BuddHLdj2md8qK3UOyZ1HomNfWsjzTuc/5bJtzz4MPcWkjfDMppsiSiLKk0 TVquRfFhcVx5VwQRr6UOq3bsqd3LEdC8FrjWHlrdh76J2vq8LSuigmN+1K7cVj8UHNoL 84uHCZ7zJyIL0zRj1c0/qn8Sbe75hHsv3agbqQdJc8H58k/A+ewYlKJXIwZrjGSKMS5z K3/Y2R7qKotOmWiB+V3XawBazgoj+Jx+ywt7wdw6lfkHs2gl1nJPSrW0zAKR/ROawgsl +ewg== X-Gm-Message-State: AOAM5338fZDFYItMroBxpemRCgyLlLPYI3L4pqrW2fLopCZDpkQpYpak uDW74HbrU5/KFkCtelQDtG+y4Pxclr+pIH62JOpLlQ== X-Google-Smtp-Source: ABdhPJzrgg4QxWXsEzPYzTcGzHWRGJzutSHzxf7MyS7jl8fXaPnvZsxbr7tbXLGs65s2GKo7inPQ7k7YwejU0k9swws= X-Received: by 2002:a50:9ea6:: with SMTP id a35mr8193746edf.52.1602146152651; Thu, 08 Oct 2020 01:35:52 -0700 (PDT) MIME-Version: 1.0 References: <20201007164426.1812530-1-daniel.vetter@ffwll.ch> <20201007164426.1812530-11-daniel.vetter@ffwll.ch> <20201007232448.GC5177@ziepe.ca> In-Reply-To: From: Dan Williams Date: Thu, 8 Oct 2020 01:35:41 -0700 Message-ID: Subject: Re: [PATCH 10/13] PCI: revoke mappings like devmem To: Daniel Vetter X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201008_043553_909074_B420D064 X-CRM114-Status: GOOD ( 35.01 ) 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 , John Hubbard , LKML , DRI Development , Linux MM , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Linux PCI , 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 Thu, Oct 8, 2020 at 1:13 AM Daniel Vetter wrote: > > On Thu, Oct 8, 2020 at 9:50 AM Dan Williams wrote: > > > > On Wed, Oct 7, 2020 at 4:25 PM Jason Gunthorpe wrote: > > > > > > 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() > > > > That's not quite right, An inode does come from the filesystem I just > > arranged for that inode's i_mapping to be set to a common instance. > > > > > Seems OK to use this more widely, but it feels a bit weird to live in > > > char/memory.c. > > > > Sure, now that more users have arrived it should move somewhere common. > > > > > 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 > > > > It still requires every file that can map physical memory to have its > > ->open fop do > > > > inode->i_mapping = devmem_inode->i_mapping; > > filp->f_mapping = inode->i_mapping; > > > > I don't see how you can centralize that part. > > btw, why are you setting inode->i_mapping? The inode is already > published, changing that looks risky. And I don't think it's needed, > vma_link() only looks at filp->f_mapping, and in our drm_open() we > only set that one. I think you're right it is unnecessary for devmem, but I don't think it's dangerous to do it from the very first open before anything is using the address space. It's copy-paste from what all the other "shared address space" implementers do. For example, block-devices in bd_acquire(). However, the rationale for block_devices to do it is so that page cache pages can be associated with the address space in the absence of an f_mapping. Without filesystem page writeback to coordinate I don't see any devmem code paths that would operate on the inode->i_mapping. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel