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 09EB0C4727E for ; Wed, 7 Oct 2020 19:25:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2BA6121D24 for ; Wed, 7 Oct 2020 19:25:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="IfegH4nw" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2BA6121D24 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2E7356B005C; Wed, 7 Oct 2020 15:25:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 297CC8E0001; Wed, 7 Oct 2020 15:25:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 186656B0068; Wed, 7 Oct 2020 15:25:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0161.hostedemail.com [216.40.44.161]) by kanga.kvack.org (Postfix) with ESMTP id E0B076B005C for ; Wed, 7 Oct 2020 15:25:03 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 835CC180AD804 for ; Wed, 7 Oct 2020 19:25:03 +0000 (UTC) X-FDA: 77346107286.30.way30_4805cfc271d1 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id 622EC180B3C85 for ; Wed, 7 Oct 2020 19:25:03 +0000 (UTC) X-HE-Tag: way30_4805cfc271d1 X-Filterd-Recvd-Size: 6458 Received: from mail-oi1-f196.google.com (mail-oi1-f196.google.com [209.85.167.196]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Wed, 7 Oct 2020 19:25:02 +0000 (UTC) Received: by mail-oi1-f196.google.com with SMTP id w141so3711766oia.2 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=GcJXVjm2+jikildcUY7jRw+MCZSepdArmDn5fCAahkS3nhpuIrSZXNRxpengZneheJ uBE2hWeNqMNBbwE1Mx4WTAcgZ85R+R98OuDlfFgpu0BGNmfBgls1CpKN2u4/2pyplqjA UkSAKnGFwdxW30Y9JaqgKs/Zgkx1QUjaE9Kl+w1FFOtnPY99WGGIPLsSIan9vlAXsMTb 8EHR92o56eMIBzeexc/uEh8QK6YWmZPzcrCCzMb62Ba7MxWNc1iYRCyGhaoyJ5MW1sm2 E9WHIPPC1IIlZcLXqzVkZaUJXkTgg1PMLafQKQMqXDZwnW0ynGNX1JMxAiZ96pP5sLKe 8TfA== X-Gm-Message-State: AOAM5332sNpor+MW6YXcNqz2CFhPeKcKhTGS/vsWY7hPcpPqZtrpM5Ye rTq1cgJwLzqO2s8PQaU9UiNG85mfzHvXvsXNAXt1ZA== X-Google-Smtp-Source: ABdhPJzhvBCanKpF9yHYf4rPvV3OgJoXcQ8bSZqPwzVGdWv0uBGdiJso5tL8awsEi+dW1GpdYavbUXQPpc/1p2uOTug= 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" X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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