Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp761598pxu; Wed, 7 Oct 2020 15:31:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7mPkLKOFQV+56aoDUNuIosIePq1tw9TcN8cstFQBMvJauj25HYgSg14kwdwCpy/IfuTaY X-Received: by 2002:a17:906:3789:: with SMTP id n9mr5685777ejc.273.1602109905903; Wed, 07 Oct 2020 15:31:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602109905; cv=none; d=google.com; s=arc-20160816; b=i6hvLHtWHCTPul64b3G7CVd/31GhHU1DoOZtv6FqWAgXFUll9gSYGuPHC0kgba8Xcv SD+nL6aEt6W/pknQL1NZ52jUhw/LC1mwDSVkmlxEyOrS8qfhWZzyKJQUsHNmo3i9zzpN 06eRrXGNwdWuDfhVfmEtr3+tEjwnpYXWG5VJ4SFzAHIcjSSSkHzvvRyhKAnwXDjlyPwu 2w3f+yuLcPTk4I+2x5C/98WhFqrjDJj+ULap5yB7j+MmEU+IB8XGkPutOLtuN4qNJOgX iEWNNVX1iZhWiRFQThoP+vFJH7PxXKEoJP59pM5xsg7SCEnahPpHT+mGN34AuFBCSlFa eCgw== 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=CTESbqWcckMo/4i92TzIl4y3TmAuiek3Eq/3qJ27aVE=; b=imnI/SAC4B8dvIKOsTWgnn7ugQ+/kGuRAku5V6ZJ8VDggllEbq8B86xY1hT60kPmWF ydb6HFnRHLKtbq0FDKU85AnraXD/RP7OcphPB8SfOIqIteLzR3DsazZ/rropIQSJyrKY 7yrHetycki1OSnQ66KxHJPnE8n8jyncMr9aowpB4B7Tr13DLEBY0JCyLnKxzieIgko1Y DJA8ECNptH0pIKthCJH8xTNY+Gr/pGJuiIyFyb2PpYadjJjeq6pxpRCHcy6yEqaPxRjG 33jepqIG25f+IkBO8sqEDnJYjV2zYBgmmvSW3MPZbtgBx3mUtTy9ojJNvoYzU1E9lmuK vHQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=C9Ia3VCK; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i19si2342316ejc.229.2020.10.07.15.31.09; Wed, 07 Oct 2020 15:31:45 -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=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=C9Ia3VCK; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728868AbgJGW3e (ORCPT + 99 others); Wed, 7 Oct 2020 18:29:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728849AbgJGW3e (ORCPT ); Wed, 7 Oct 2020 18:29:34 -0400 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF9BEC0613D5 for ; Wed, 7 Oct 2020 15:29:33 -0700 (PDT) Received: by mail-ed1-x544.google.com with SMTP id i5so3850851edr.5 for ; Wed, 07 Oct 2020 15:29:33 -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=CTESbqWcckMo/4i92TzIl4y3TmAuiek3Eq/3qJ27aVE=; b=C9Ia3VCKylLvch2Mm4CFE1Tgnfv5R+vpt+Gkie2pCUYaMg+MkmANBvB5fv/6gLxHxE bqKJ+r7mFS4NA8UmxE4KYJZ33h0CYTX0aZwWDh5/vd1BekkHTnqpnKypSF28zWn4K8H0 LKnkgKM1Z6rkuZBOAzYfh5nH/xOSDZ3VaVqsFGiTKhdbNpRTH5LDgJn++bCaD2RQJ9I2 b/yb82cHyyvSeJ6CHCNH7JIYmVCxoXypsBHBMmGij+CrG19A8lbexSM+QLvs1Sqc47pm mzhEavRU8o1d5Wa2DTKdErhBCi8bj8r7+t/oYkUYIZbU0ZApbdX2cmoy5guFURB/fOut NK3w== 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=CTESbqWcckMo/4i92TzIl4y3TmAuiek3Eq/3qJ27aVE=; b=VTBZu8nVWfuDd4JSjTm0p/z6NIxQkO81QxDt5NLd/7z4pkd3XOilV8D0e7g6EPxDKc L8TyLmgB0952HCTgEiOeWpewKu1DEJCxXYY0+qEhIASmFAq4S0nhvLF/kX2cDcGJpduH hIfpJgnuPNXqebHFI7oVyNR9D1W92AbgP+3LxOeRRdUVtUcZ2N1b9pD3dNPjZlGLeJ+2 ZwNRwyYte2vOyB+7QmFVQCEl+G3KDbF0etMYE5NBgdbXjh/aAtksAEWPZpemliKnX/nG mg2SF8ARdbLsyX8rCW9zY5OIWnahi58Vq5urzaACMmbgdtSTRTQZF5Fvk48gWezu05Va 1WZQ== X-Gm-Message-State: AOAM533cz/1NDSLqXhkigGjoQqdn1BPtdQOlEvC5AUZLoXjuoL3VsqOv ld+Wd3yjk7XqmZ219kVkHvdPJxc8H7eYoB/dGLo8nsfqCb+YCg== X-Received: by 2002:a50:9ea6:: with SMTP id a35mr6269472edf.52.1602109772370; Wed, 07 Oct 2020 15:29:32 -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:29:21 -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 3:23 PM Dan Williams wrote: > > 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. To me this seems like a new sysfs_create_bin_file() flavor that registers the file with the common devmem address_space.