Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp1035129pxu; Thu, 8 Oct 2020 01:14:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/9m3iOBnOdwTKgzAiF//H7Y4ZAqR+nldrDkpknud1y6D9+bm3JjpvhS7fHflnS8ryvRms X-Received: by 2002:a05:6402:754:: with SMTP id p20mr1203521edy.109.1602144898712; Thu, 08 Oct 2020 01:14:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602144898; cv=none; d=google.com; s=arc-20160816; b=c/6lAPdLwGGc7ZmR/Y8a1IBn0V8G5rUsCsRz6goLEhf4YIe82lA/McUZAj4JQeauTH eCsnsInvvV//2cGZvQOAb3ar9wfuBaTII0EuCVr8/0XDah75HgtWRpDAF8OxBIrw3FjU YpDb3BdiSRsg8mu5/RW3tedsxce3idI8NkjYUNcOiZp1c7/DGZKLOl3QVSIhHEVQhg7V ytwTKYMcnvVCZC00KcsAFT6oMxQjw6AWKGTXWf7D+Ur8BFbZtDghVt/rVMWdhL2cyfAI 7MUk+NCxK2tW+13Zr/rLssCDXpVZjbBoSgBNiRCyeipPazXm9ZNfE8gOmjD5iDIAzUfy CAnQ== 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=6GE5pSnNRg0KlyvewB9QKOrrd6/Nut8BwJvyodyZJd4=; b=UlO30Fz0WImcT38jnxDeDnAxp+DFJNlB/tx8dq3y27Sn42BDh5djqcUEC+GriBMCJ7 hAQC61d/30kpUOmdMmdgiznnNlXK511FB0Ny2HNB5t6AtGLJcxrFlpZtsShdloLmo/1b YTSJEiJDmrX9gejdeH2U3jyU3Txjn63mhyavCo1seTzPwW1IEMtO+O5i3bHbBDECrEy3 OXO96ZizCmwF7gLiG+fs7tSTElITDoGDcUiM5zuASx0lOand4SggaS9fytCO0hwPrJDa NBhIlvQ32c/pE9Ln6NCBt1C+o2XYn5ZJLDzy8oJSOmTSSV8oELfYJREyb1+s4Jc+HG/a CF/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=hMW7zxgB; 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 r2si3405260ejr.265.2020.10.08.01.14.35; Thu, 08 Oct 2020 01:14:58 -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=hMW7zxgB; 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 S1728386AbgJHINV (ORCPT + 99 others); Thu, 8 Oct 2020 04:13:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728004AbgJHINU (ORCPT ); Thu, 8 Oct 2020 04:13:20 -0400 Received: from mail-ot1-x342.google.com (mail-ot1-x342.google.com [IPv6:2607:f8b0:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CF50C0613D3 for ; Thu, 8 Oct 2020 01:13:18 -0700 (PDT) Received: by mail-ot1-x342.google.com with SMTP id n61so4721401ota.10 for ; Thu, 08 Oct 2020 01:13:18 -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=6GE5pSnNRg0KlyvewB9QKOrrd6/Nut8BwJvyodyZJd4=; b=hMW7zxgBaxDt7Z8CMDWn3cCXSOY5QqOrFQ/uoN1baUlAIhOFYy+4SzujzZvv4Ur9FN onPuYsY03fgo4HL/In06Uiy/3ynGYwzwiQV3wfZ6whnso50XlzhHTRy/QZJCTuip3uEr ueKV+xdznXeh2dJB78HPK0Klt6lkMJnLUSyGA= 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=6GE5pSnNRg0KlyvewB9QKOrrd6/Nut8BwJvyodyZJd4=; b=kmOVP53g4C1HxobKIetHbPsCb/878CtYp4BMtCBNHCWtJjU/M5dq6ziKiHx9x1vAA1 BBVl0cbznyjrGYMNDdnKZ+fVtw+eZi/sTc0Pd4xXIcRVGTKibh8OJkH/0muMSPEkwlAu 8zdmUct41ke9I0MY7eq3k3Edj2TJ4t68gG4hkvlX7JYddr5FYgFazPDE5Xabwkc8B4Nx Ykt4SbWZco4jLUJdDjqSFkgTsRfI3Zjwe7kSD2bsLQYs0BXUmLmw86H7pyCAw8LBoXB2 N6T+y3t+bdeheEjGloHaKyt/WZRrfztavjUXdQaA3j4I6BLsE5IMmWHZXJMK9iTm6bcF 1ETA== X-Gm-Message-State: AOAM533FWHsSQv2UNAgM3uYH6zWYrIAzMgHgMQUQfwjlSV32ZYUKdhs0 dUb4otM5/ZMhksMTH8kTWkgH+/7vG9Ji7z/laYUJmw== X-Received: by 2002:a05:6830:1647:: with SMTP id h7mr4572127otr.281.1602144797647; Thu, 08 Oct 2020 01:13:17 -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: Daniel Vetter Date: Thu, 8 Oct 2020 10:13:06 +0200 Message-ID: Subject: Re: [PATCH 10/13] PCI: revoke mappings like devmem To: Dan Williams Cc: Jason Gunthorpe , 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?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 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. -Daniel -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch