Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp771088pxu; Wed, 7 Oct 2020 15:51:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLUzbM9HCu5lg1AxiuldvyhtdxLqFSXSRL/SMCtG4pu6/A0eM+aAqp5BpIAufTCyifqsML X-Received: by 2002:a17:906:86ce:: with SMTP id j14mr5820990ejy.158.1602111094088; Wed, 07 Oct 2020 15:51:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602111094; cv=none; d=google.com; s=arc-20160816; b=w5Wyps7wVdAH/rp95H4DxI7Z2NL7ZcEAHiNzotjw0ukiaJV8ncprsU6hlhB+4iWqyw 6t8IAfvR7Hy/oM0Iz+CqfJ7wkwf+YPQOGjKHjeYgCbG/1Vs9KmNtnEWMKHp1VSOSEI91 fqx4VfMf3PfVOib7iDljjm220uFF9H3mFFhbdtkYFPQ+PiBECY6KFqK157h8cdwI1Drc M+uvI0Lm9PtOCJbPpHUQ/tDZTW7hfMmmkSmzFpntO8iSGWAjMLieCTiOidPCvjajq9t7 52x0uCi5MGjOcfMZjDcc4gIP6dNRg9pbDtT73naMJIPutilMOlMbRY4mhIlcx07tFQnj Jcdg== 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=BZRP/YEUZ8RoSb8Ypgb3DGxVhdoAtHRN1N0p0L0pWpA=; b=nVn8dRPckQj69vigzEzkWb0i9qpTLol3OplVBPrQ6szFhVt2KV2xBGxzbp0n5V1DX1 ZbfBjCzrAY3FZKvLyJ7VaVyMNrnuH9jz+FQP4TJHw07f5192TXokt+zVn/EsPFpOLv6/ n14cvGjZMo31HBAFko8WMjQ5PYVhAqf6VKlidawn9ri9CrR3Uw3Px2LTMPy6WqcHcrK1 LoU6gvOOiIZDiVThK3AZLhwUl4s61bliJhIWhiwbFvlsRPZOrnwpESMYVvKBJCmdt60p AvUXjuDD0NISXiqZ9JkcsvY7K9PhkKC8icmGtiwJe1z6Qu2jXwvLsOGpF3ojJMy7cQAK J4aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=IfegH4nw; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qo22si2417567ejb.178.2020.10.07.15.51.10; Wed, 07 Oct 2020 15:51:34 -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=@ffwll.ch header.s=google header.b=IfegH4nw; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727766AbgJGTZD (ORCPT + 99 others); Wed, 7 Oct 2020 15:25:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727430AbgJGTZC (ORCPT ); Wed, 7 Oct 2020 15:25:02 -0400 Received: from mail-oi1-x243.google.com (mail-oi1-x243.google.com [IPv6:2607:f8b0:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B27A0C0613D4 for ; Wed, 7 Oct 2020 12:25:02 -0700 (PDT) Received: by mail-oi1-x243.google.com with SMTP id t77so3697386oie.4 for ; Wed, 07 Oct 2020 12:25:02 -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=BZRP/YEUZ8RoSb8Ypgb3DGxVhdoAtHRN1N0p0L0pWpA=; b=IfegH4nwN/o6kcQDvfu01nenDUeNQgBkda4/dhczUdP0kMFXcvE572DUDzf1wvqGpa nyp1a/D73Mflnvnu40XfTC32OrNKnzCHp2mvGEYcnzK1KJ6+dezHuXb9vC5VNmLGIhTb kwAV9e9OpEVj4sQ6ggzRYYm32tqaPtdzoptpI= 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=BZRP/YEUZ8RoSb8Ypgb3DGxVhdoAtHRN1N0p0L0pWpA=; b=WCSQNNfD/9MAsVw1VmeVjMdL67GKHC/X1Y9jfF8ojlRruPXgdqlD8zJYOb5NUjTf6O a4KT5RDf2FWUnE5/N5NhSCLB17m6wR6xSG7Xz6j1nR/7XgJeLLx5hsSSaDDyP41A5b9q z7Mpoe7MliHOi8Ow+4rJ3vlExX5fT+xP6DYxnP6KiI+4F1jZ9Xnl6k3gNnKlhhi9s+j4 Lcfyx9xEjCPjZqjbtqzv9V9Tua2VpG/eU7j+p+aAHJ4WOP7oeJNDEOc6upsILGVRrWZJ UVEOG/u2N5GkSo6B7BBbm/Hi+5LJ1dj+IaF6GwrGwVNDPgw/+gHrTO/LO0ncC3bsqTVW tsSg== X-Gm-Message-State: AOAM532xaU0t58uNDS3gWCr5+ASscpF7zv+flLIeoJ+a9Pi/a+RC7ddh 8+SdeB2H6oKFD/krf3GfiSRzGSaY4cSxd4YnhE1nOw== X-Received: by 2002:aca:6083:: with SMTP id u125mr2929990oib.14.1602098701967; Wed, 07 Oct 2020 12:25:01 -0700 (PDT) MIME-Version: 1.0 References: <20201007164426.1812530-11-daniel.vetter@ffwll.ch> <20201007184131.GA3259154@bjorn-Precision-5520> In-Reply-To: <20201007184131.GA3259154@bjorn-Precision-5520> From: Daniel Vetter Date: Wed, 7 Oct 2020 21:24:49 +0200 Message-ID: Subject: Re: [PATCH 10/13] PCI: revoke mappings like devmem To: Bjorn Helgaas Cc: DRI Development , LKML , kvm@vger.kernel.org, Linux MM , Linux ARM , linux-samsung-soc , "open list:DMA BUFFER SHARING FRAMEWORK" , linux-s390@vger.kernel.org, Daniel Vetter , Jason Gunthorpe , Kees Cook , Dan Williams , Andrew Morton , John Hubbard , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Jan Kara , Bjorn Helgaas , Linux PCI Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 7, 2020 at 8:41 PM Bjorn Helgaas wrote: > > Capitalize subject, like other patches in this series and previous > drivers/pci history. > > On Wed, Oct 07, 2020 at 06:44:23PM +0200, 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. > > s/pci/PCI/ in commit logs and comments. > > > 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. > > > > Note this only works for ARCH_GENERIC_PCI_MMAP_RESOURCE. But that > > seems to be a subset of architectures support STRICT_DEVMEM, so we > > should be good. > > > > The only difference in access checks left is that sysfs pci mmap does > > not check for CAP_RAWIO. But I think that makes some sense compared to > > /dev/mem and proc, where one file gives you access to everything and > > no ownership applies. > > > --- a/drivers/char/mem.c > > +++ b/drivers/char/mem.c > > @@ -810,6 +810,7 @@ static loff_t memory_lseek(struct file *file, loff_t offset, int orig) > > } > > > > static struct inode *devmem_inode; > > +static struct vfsmount *devmem_vfs_mount; > > > > #ifdef CONFIG_IO_STRICT_DEVMEM > > void revoke_devmem(struct resource *res) > > @@ -843,6 +844,20 @@ void revoke_devmem(struct resource *res) > > > > unmap_mapping_range(inode->i_mapping, res->start, resource_size(res), 1); > > } > > + > > +struct file *devmem_getfile(void) > > +{ > > + struct file *file; > > + > > + file = alloc_file_pseudo(devmem_inode, devmem_vfs_mount, "devmem", > > + O_RDWR, &kmem_fops); > > + if (IS_ERR(file)) > > + return NULL; > > + > > + file->f_mapping = devmem_indoe->i_mapping; > > "devmem_indoe"? Obviously not compiled, I guess? Yeah apologies, I forgot to compile this with CONFIG_IO_STRICT_DEVMEM set. The entire series is more rfc about the overall problem really, I need to also figure out how to even this this somehow. I guess there's nothing really ready made here? -Daniel > > --- a/include/linux/ioport.h > > +++ b/include/linux/ioport.h > > @@ -304,8 +304,10 @@ struct resource *request_free_mem_region(struct resource *base, > > > > #ifdef CONFIG_IO_STRICT_DEVMEM > > void revoke_devmem(struct resource *res); > > +struct file *devm_getfile(void); > > #else > > static inline void revoke_devmem(struct resource *res) { }; > > +static inline struct file *devmem_getfile(void) { return NULL; }; > > I guess these names are supposed to match? > > > #endif > > > > #endif /* __ASSEMBLY__ */ > > -- > > 2.28.0 > > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch