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,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 05BEDC04EBE for ; Thu, 8 Oct 2020 08:13:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 90DF52177B for ; Thu, 8 Oct 2020 08:13:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="hMW7zxgB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 90DF52177B 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 CBA096B005C; Thu, 8 Oct 2020 04:13:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C68A46B005D; Thu, 8 Oct 2020 04:13:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B095D6B0068; Thu, 8 Oct 2020 04:13:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0112.hostedemail.com [216.40.44.112]) by kanga.kvack.org (Postfix) with ESMTP id 859C96B005C for ; Thu, 8 Oct 2020 04:13:19 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 2816F8249980 for ; Thu, 8 Oct 2020 08:13:19 +0000 (UTC) X-FDA: 77348043318.24.lunch49_400d4ce271d6 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin24.hostedemail.com (Postfix) with ESMTP id 06B671A4A5 for ; Thu, 8 Oct 2020 08:13:19 +0000 (UTC) X-HE-Tag: lunch49_400d4ce271d6 X-Filterd-Recvd-Size: 6050 Received: from mail-ot1-f67.google.com (mail-ot1-f67.google.com [209.85.210.67]) by imf18.hostedemail.com (Postfix) with ESMTP for ; Thu, 8 Oct 2020 08:13:18 +0000 (UTC) Received: by mail-ot1-f67.google.com with SMTP id s66so4773208otb.2 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=XgbMLIxnzifKDbr8qxPKXWVcBc9dbJZnlDNAMlxuCq7UrnWdK+nuha2dMuZqTIttjX +siqXaVOnjfAWH0t6dhvoTv3yiVfVqkBx7/+qB/K0WKjjneU49W8jXWCvycKIwBG4DXX bU0uhNFUpCcGauwi6Aqs+cOejTA0ELkobzEwHC63dimusGKaF6hR4sZBV22EY+nfyPmA K1rlNyeSXuza+HfsYMmm5S9dVEuNtxEuTPjGPHXkCzHX6F03x4O2WbKAiGjhKAwyHWY4 ScUyH64vVjt4E6GgDT2JbbCI2SWYpJ6HF1N9131uN2bOIRcSJC3AZIaeBl4x11Mn5/J/ uRwg== X-Gm-Message-State: AOAM533GQRvlDtiKd8PBTdSAuqTVU2p3wokiAmcBOmb4bdVr/BYJbtME 22IFKyRSaYWEaDL4cMLo+UEG/DOanL4b0UiFw1NCow== X-Google-Smtp-Source: ABdhPJzi+1LyDtM+RDWyhibTLQ/9o198dN3ibfXFnaztfI6BQhE6ckMA8Uych0T6Rb8ANf5SnQ1gmeZGjO89xISEbKU= 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" 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 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