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.7 required=3.0 tests=BAYES_00,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 0DEF5C4727E for ; Thu, 8 Oct 2020 07:50:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AC4A721897 for ; Thu, 8 Oct 2020 07:50:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=intel-com.20150623.gappssmtp.com header.i=@intel-com.20150623.gappssmtp.com header.b="OpyjCwq7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728319AbgJHHuK (ORCPT ); Thu, 8 Oct 2020 03:50:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727694AbgJHHuH (ORCPT ); Thu, 8 Oct 2020 03:50:07 -0400 Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5118CC061755 for ; Thu, 8 Oct 2020 00:50:07 -0700 (PDT) Received: by mail-ed1-x543.google.com with SMTP id v19so4826453edx.9 for ; Thu, 08 Oct 2020 00:50:07 -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=grdLjPbma4xWpmrd4kIhxHd3k84viXKhZjuHjyaNtUE=; b=OpyjCwq7o157Xb/2yloDuUEV/w+tdNn7bUkqj6LGjYZdXbdkHQlqz4Xs0Zg4Edt33w 0nqk5otSDvrBFIDqX3NWTcYGdyooPoOy++oKoeLN7+9FcA3Y2j9gM2FY12udB5BbTLzF o4Fgw3h+eUO3zgDHQ6b7I7KPL5f+fMHf9I0lTVCozAWjOJH1Lu9JW2FcOGR5M99QQ9cG 2z2FugDTtkLvyx7A5kfM8jqHqXj/RdTCprPD7XpZha+SBgeMVVhbtPHFs1tz0HiaUe6C BI4I++Hc0Q/c9P8rPs6vNR5tBGxtF7FZ8cn1qblN1zBUwaF08Qp+hX6dqbT1VyZULWij t42Q== 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=grdLjPbma4xWpmrd4kIhxHd3k84viXKhZjuHjyaNtUE=; b=gwm2whLL1c3ooNkupxqPjFHp92ttDmDr1YqNlHzSjpYzq6ABJ5rfdr5pP8oh+2FHiW CWDsrEnuE3oyTHFcs52Ma559hafHWCQKb8AofYf/IUlh+Ke6BO9W9tPE33ExZhZiprm6 eDqj1sDBMX4kOZeGoePolSmOgmUZztRYOeUr2ZB6RHDlT+oi+2P6Xdr2qtTAfkYkvFhc hjj8FX/GCyTlHHvO7Lw87uwNFeSGxjuarR2dC/sW2jE/GD8/zTa5XJZ2ows919+RdDI5 QgJKLB0sw6f2o8OBkusI8xBTl06KQ3lr/RHPcGC6MuuJWcpyzV9QwQnG1iy+QezhKEWL DG/Q== X-Gm-Message-State: AOAM5328Pw+pPdR+fBfUzR4Wtyy0IzfSnRH881gmYmmGeDfMDsP5Y2j8 IwmVdGvfe9gNcDSVP6h1tik69RKd5B/ID8xPieWwSQ== X-Google-Smtp-Source: ABdhPJysuJa5L2PxuxTzTLWSnwn1TbnDhi3QjUi/pDReBeAUTyUIbYuBaOL8Vyczi/qAthRLw4c82m5S1UkBlboYvQw= X-Received: by 2002:aa7:cd1a:: with SMTP id b26mr960294edw.97.1602143405978; Thu, 08 Oct 2020 00:50:05 -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: <20201007232448.GC5177@ziepe.ca> From: Dan Williams Date: Thu, 8 Oct 2020 00:49:54 -0700 Message-ID: Subject: Re: [PATCH 10/13] PCI: revoke mappings like devmem To: Jason Gunthorpe 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?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 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.