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,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 082F7C4363D for ; Wed, 7 Oct 2020 22:24:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B085B2083B for ; Wed, 7 Oct 2020 22:24: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="QQSRcBFI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728846AbgJGWYL (ORCPT ); Wed, 7 Oct 2020 18:24:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728654AbgJGWYK (ORCPT ); Wed, 7 Oct 2020 18:24:10 -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 D1F31C0613D2 for ; Wed, 7 Oct 2020 15:24:09 -0700 (PDT) Received: by mail-ed1-x543.google.com with SMTP id cq12so3854700edb.2 for ; Wed, 07 Oct 2020 15:24:09 -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=Zic23vwE4RxhL64QubFNAgrR6bPLwF/Sw808vPXOvcE=; b=QQSRcBFI6KAV++JS9/GFj7Fmw4j7a/iMiUg1ZTuLmVxWhkZMKv0QD8k1ukWq7eq/is aqhku7tesefyyeplMfP+uZ40G5Eu5h32eX3quWRsYX4t93t8hfPAksy+eKFnntLzh659 XKe6EgVkLvN8qFLGttYIbd5R75etFF329oIsGVg7tFamYwMf914oOqvj5Aj57gMZmmXn BdX+R3HH+c0ZbeHsryryJmXxzi8LbxHVyDfXa28xyWATs9steaqxyt3ORz7tJ5iS3p0B /C9lomlbRYU4nllCvXcMpiVBxaPdCxNSDAwt+Wnv7NkDlHC0AVoEJJmmbnIbcEEDMbkk VNvg== 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=Zic23vwE4RxhL64QubFNAgrR6bPLwF/Sw808vPXOvcE=; b=HFcoiRUtYZmksIvpN5vNHxr6mVoOVqOy7/4DAnVSd19TnDdDRWg+mHIBXvh2jR/VFs PocUq5NNgr9hEgaP74rVPsxxXdjzyhvHoPKBZuuvCvCJ3gHwbyJY6xn2+UZfqz7n03OJ Yeciu00vju+aLVmZ0kkoUlEgWdhMJjrdYDiq6RkDX3e/aapboS+QdloU8CP89pq/oDZG vASZvj8LSeH9sXQBNgalHTAz61a0mAJlGDi6oRsIbYtBPUjwZQb74D1cMUPf6D9fNwg4 3Lvi0LVBH36RMoa9UrScG97NDrezyrnDO5v9PF6EOxcqt5P8kxtcs5iz6YCykww1b9f8 gAAQ== X-Gm-Message-State: AOAM530zrGW+/zIrpoInQIFbM5+NOZtjSxz8p0vsKastyRz1wL3X7D20 mty7Y31K+sitDmevO1P+HXVafX96bhYelit/8AizfQ== X-Google-Smtp-Source: ABdhPJyEbSoLmGrub89sZew46mtuYR5cC3wqZnDpHg2eEdBRv6ndP1ZtRmu/HFaFG/gOZx15NdgN0Q/4bhJSTz4VXAk= X-Received: by 2002:a50:d0d0:: with SMTP id g16mr5862132edf.18.1602109448239; Wed, 07 Oct 2020 15:24:08 -0700 (PDT) MIME-Version: 1.0 References: <20201007164426.1812530-1-daniel.vetter@ffwll.ch> <20201007164426.1812530-11-daniel.vetter@ffwll.ch> In-Reply-To: From: Dan Williams Date: Wed, 7 Oct 2020 15:23:57 -0700 Message-ID: Subject: Re: [PATCH 10/13] PCI: revoke mappings like devmem To: Daniel Vetter Cc: DRI Development , LKML , KVM list , Linux MM , Linux ARM , linux-samsung-soc , "Linux-media@vger.kernel.org" , linux-s390 , Daniel Vetter , Jason Gunthorpe , 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 12:49 PM Daniel Vetter wrote: > > On Wed, Oct 7, 2020 at 9:33 PM 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. > > But then I need to find the right one, plus I also need to find the > right one for the procfs side. That gets messy, and I already have no > idea how to really test this. Shared address_space is the same trick > we're using in drm (where we have multiple things all pointing to the > same underlying resources, through different files), and it gets the > job done. So that's why I figured the shared address_space is the > cleaner solution since then unmap_mapping_range takes care of > iterating over all vma for us. I guess I could reimplement that logic > with our own locking and everything in revoke_devmem, but feels a bit > silly. But it would also solve the problem of having mutliple > different mknod of /dev/kmem with different address_space behind them. > Also because of how remap_pfn_range works, all these vma do use the > same pgoff already anyway. True, remap_pfn_range() makes sure that ->pgoff is an absolute physical address offset for all use cases. So you might be able to just point proc_bus_pci_open() at the shared devmem address space. For sysfs it's messier. I think you would need to somehow get the inode from kernfs_fop_open() to adjust its address space, but only if the bin_file will ultimately be used for PCI memory. 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=-4.5 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 583F2C4363D for ; Wed, 7 Oct 2020 22:25:44 +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 B74E82083B for ; Wed, 7 Oct 2020 22:25:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="bdVQTVQs"; 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="QQSRcBFI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B74E82083B 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=fTnDOC1RLc21SA+z8GMCWD9z5Usz7hqK/Uw/eJLb+y8=; b=bdVQTVQsnPCuK39NbNHlQSVz4 NjNk5VozTcI7t2CDDwmkNmFvBK3NWhUJm08EfP7PJFvyd0qcgX1Ccd/+r6NN2dvIjkiHQUvPmu8Wc Cg7aOSejiP72/SSgxtaBG+l70zhfO/fLp1X3XbTHocfGU/MhWwU9Z4g2pznq4ItK2wsrUj770Xccv hkd+xm0Usn5SF5ZTcHiy7zEBYbF20p4qzc1dKjgyV45z1pTVjab4UJs4OGa5MQBeBMKpZucXwr+VK MT5PoR1vjfwE7oo0sDCV5WTgIqOu0BeISjWB8YfpWHgst0ccb1Ju8Brm0SUwJE4CTJguLwU2vL7ZM ZBVVOoXkw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQHr5-00047P-Nh; Wed, 07 Oct 2020 22:24:15 +0000 Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQHr1-00045M-9m for linux-arm-kernel@lists.infradead.org; Wed, 07 Oct 2020 22:24:12 +0000 Received: by mail-ed1-x541.google.com with SMTP id dn5so3825852edb.10 for ; Wed, 07 Oct 2020 15:24:09 -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=Zic23vwE4RxhL64QubFNAgrR6bPLwF/Sw808vPXOvcE=; b=QQSRcBFI6KAV++JS9/GFj7Fmw4j7a/iMiUg1ZTuLmVxWhkZMKv0QD8k1ukWq7eq/is aqhku7tesefyyeplMfP+uZ40G5Eu5h32eX3quWRsYX4t93t8hfPAksy+eKFnntLzh659 XKe6EgVkLvN8qFLGttYIbd5R75etFF329oIsGVg7tFamYwMf914oOqvj5Aj57gMZmmXn BdX+R3HH+c0ZbeHsryryJmXxzi8LbxHVyDfXa28xyWATs9steaqxyt3ORz7tJ5iS3p0B /C9lomlbRYU4nllCvXcMpiVBxaPdCxNSDAwt+Wnv7NkDlHC0AVoEJJmmbnIbcEEDMbkk VNvg== 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=Zic23vwE4RxhL64QubFNAgrR6bPLwF/Sw808vPXOvcE=; b=uKfV1nLaV7ejMyaf9pbqOYHwY0FCxo6h3GBCPddccxCEf0USo86dFIx+4hYCi4qjyc 0cIMOEHFeQS7TcX+WHOWe+pujbBKu/J9eKBHcjGl9peXF/itT9zlY0w+NP33/dAseVSD YyYRwwFjvRrMqUPB4JznIiO/xAFpQF5IiIHfA5BVWGuQ7Ri2Gk4wdGhDTdMuceaC1KqG GDUsAm+7ae9xjvlcztDSjGXS2abXta3TXd1HzReL+3kwUXb+Ds16YgjZoO4pbV6OEWhU aaPIWlmdxb4AUOYrmF/J2yJA3cgc6xb79HE0mcsvxmhgzFEkhEDIVkXvgRQ0ve+Yw+8J cf0w== X-Gm-Message-State: AOAM53177H7qUQJXc1D2n0NNSOkv2f563ZmNfmGvoiwIBxKv7KhUnYDl qms8GKPwGSiGt2BosjUgaWFIj/Tmlfg6heiORJxh+w== X-Google-Smtp-Source: ABdhPJyEbSoLmGrub89sZew46mtuYR5cC3wqZnDpHg2eEdBRv6ndP1ZtRmu/HFaFG/gOZx15NdgN0Q/4bhJSTz4VXAk= X-Received: by 2002:a50:d0d0:: with SMTP id g16mr5862132edf.18.1602109448239; Wed, 07 Oct 2020 15:24:08 -0700 (PDT) MIME-Version: 1.0 References: <20201007164426.1812530-1-daniel.vetter@ffwll.ch> <20201007164426.1812530-11-daniel.vetter@ffwll.ch> In-Reply-To: From: Dan Williams Date: Wed, 7 Oct 2020 15:23:57 -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-20201007_182411_348979_C33BDD79 X-CRM114-Status: GOOD ( 27.32 ) 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 Wed, Oct 7, 2020 at 12:49 PM Daniel Vetter wrote: > > On Wed, Oct 7, 2020 at 9:33 PM 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. > > But then I need to find the right one, plus I also need to find the > right one for the procfs side. That gets messy, and I already have no > idea how to really test this. Shared address_space is the same trick > we're using in drm (where we have multiple things all pointing to the > same underlying resources, through different files), and it gets the > job done. So that's why I figured the shared address_space is the > cleaner solution since then unmap_mapping_range takes care of > iterating over all vma for us. I guess I could reimplement that logic > with our own locking and everything in revoke_devmem, but feels a bit > silly. But it would also solve the problem of having mutliple > different mknod of /dev/kmem with different address_space behind them. > Also because of how remap_pfn_range works, all these vma do use the > same pgoff already anyway. True, remap_pfn_range() makes sure that ->pgoff is an absolute physical address offset for all use cases. So you might be able to just point proc_bus_pci_open() at the shared devmem address space. For sysfs it's messier. I think you would need to somehow get the inode from kernfs_fop_open() to adjust its address space, but only if the bin_file will ultimately be used for PCI memory. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel 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.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 8550FC4727E for ; Wed, 7 Oct 2020 22:24:12 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 2A5152083B for ; Wed, 7 Oct 2020 22:24:11 +0000 (UTC) Authentication-Results: mail.kernel.org; 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="QQSRcBFI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2A5152083B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 450A96E9C7; Wed, 7 Oct 2020 22:24:11 +0000 (UTC) Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by gabe.freedesktop.org (Postfix) with ESMTPS id A5C4C6E9C7 for ; Wed, 7 Oct 2020 22:24:09 +0000 (UTC) Received: by mail-ed1-x543.google.com with SMTP id v19so3828820edx.9 for ; Wed, 07 Oct 2020 15:24:09 -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=Zic23vwE4RxhL64QubFNAgrR6bPLwF/Sw808vPXOvcE=; b=QQSRcBFI6KAV++JS9/GFj7Fmw4j7a/iMiUg1ZTuLmVxWhkZMKv0QD8k1ukWq7eq/is aqhku7tesefyyeplMfP+uZ40G5Eu5h32eX3quWRsYX4t93t8hfPAksy+eKFnntLzh659 XKe6EgVkLvN8qFLGttYIbd5R75etFF329oIsGVg7tFamYwMf914oOqvj5Aj57gMZmmXn BdX+R3HH+c0ZbeHsryryJmXxzi8LbxHVyDfXa28xyWATs9steaqxyt3ORz7tJ5iS3p0B /C9lomlbRYU4nllCvXcMpiVBxaPdCxNSDAwt+Wnv7NkDlHC0AVoEJJmmbnIbcEEDMbkk VNvg== 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=Zic23vwE4RxhL64QubFNAgrR6bPLwF/Sw808vPXOvcE=; b=SjMuR+eBrS6yzCud/PFyjI1el5v2O2K4bdlSMPNvaNuDGx7ysR+Xgp1QI7ENI3qJrO Y8eHSW4w9lQH4DywYMBiiLAQwU89uJWajeF20JdzqI68etNQSyNQXsukQMKIBGE/cPLw G4YmEpnoyEH4Xj1WfxtmBMCnFxWAHBK24kxGuENnkga3zFG/MFLtgys1S6Teq4/8NkDD RMz7Znm3XfQ2EBZNHs4CcQ+4mOEYYO7tzOiADEZAHTYPsq/YiVA6ceQ0ojjELKubjxIW LD+Wk+lgypM1CvK58TMAvQjpC0d/i11UiR07EL1mEOkuZq3lsPPNCslm4CQ3BOxNYb5k fWFg== X-Gm-Message-State: AOAM530ppFul6Zaz9ZKp0G6E1HAiZZ10BOrZ9v99yGsS2J0XaLjFaz+i sEHXAuXiwkyEt48tpz+SrlmMi2ncssbK3+b4ACIknw== X-Google-Smtp-Source: ABdhPJyEbSoLmGrub89sZew46mtuYR5cC3wqZnDpHg2eEdBRv6ndP1ZtRmu/HFaFG/gOZx15NdgN0Q/4bhJSTz4VXAk= X-Received: by 2002:a50:d0d0:: with SMTP id g16mr5862132edf.18.1602109448239; Wed, 07 Oct 2020 15:24:08 -0700 (PDT) MIME-Version: 1.0 References: <20201007164426.1812530-1-daniel.vetter@ffwll.ch> <20201007164426.1812530-11-daniel.vetter@ffwll.ch> In-Reply-To: From: Dan Williams Date: Wed, 7 Oct 2020 15:23:57 -0700 Message-ID: Subject: Re: [PATCH 10/13] PCI: revoke mappings like devmem To: Daniel Vetter X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development 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 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Wed, Oct 7, 2020 at 12:49 PM Daniel Vetter wrote: > > On Wed, Oct 7, 2020 at 9:33 PM 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. > > But then I need to find the right one, plus I also need to find the > right one for the procfs side. That gets messy, and I already have no > idea how to really test this. Shared address_space is the same trick > we're using in drm (where we have multiple things all pointing to the > same underlying resources, through different files), and it gets the > job done. So that's why I figured the shared address_space is the > cleaner solution since then unmap_mapping_range takes care of > iterating over all vma for us. I guess I could reimplement that logic > with our own locking and everything in revoke_devmem, but feels a bit > silly. But it would also solve the problem of having mutliple > different mknod of /dev/kmem with different address_space behind them. > Also because of how remap_pfn_range works, all these vma do use the > same pgoff already anyway. True, remap_pfn_range() makes sure that ->pgoff is an absolute physical address offset for all use cases. So you might be able to just point proc_bus_pci_open() at the shared devmem address space. For sysfs it's messier. I think you would need to somehow get the inode from kernfs_fop_open() to adjust its address space, but only if the bin_file will ultimately be used for PCI memory. _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel