Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1548190pxx; Fri, 30 Oct 2020 12:37:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy25mMHpM54hZDj4SN1IAhGn9O44GDKAZa2vFQ562rM+lqe3JFLq3QJd1UG5ABY1wEQHsV4 X-Received: by 2002:aa7:c9c3:: with SMTP id i3mr4270673edt.236.1604086631928; Fri, 30 Oct 2020 12:37:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604086631; cv=none; d=google.com; s=arc-20160816; b=w/zxu8eQsxb64+kljdv3gFflq4TSC9HF2zCF5J+HAvVgPMLK16aTgpdeAcE9LVlj/6 QeBqWy8kG3wbDXEUTzSLQwjsWoh6vaEUXKa9xmU4bEaMFyOrnIASuvQSkyuykWHyBw+M auWOejkdX08ICYMWERT7Oammq0hdT2XHu41qH77ogBklByOy0h0kt88dZ5Z3EU3cTdMh KmjMyg10bsRaRSr6mlX9CrGEopvaer8Lw9xu1Z2Z9LKMZ8+9/LBuv7EB2stB9kR1mVmX bz/9AOMlycTrsg9txgQlQf7uE8JAQbrYLiBXi3ipUVUco0yVhlV9DXkgjoSXcO3SZV1r cwjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=cL9WOPO2zHT1vQiE1Idu/YzBY6AJ1/e6GyUyFPMSPBE=; b=D8tidgn1/P37E50pzOvts5Q0A2WKH/nIXLLibyHZt6cAwsEn8bvJaA+Wnd1iDnYJDv jFATVsAjxsohq+puHdnZwqM6Rg7JKar1qDHBdP/SNw21w/FmtH+PaZ/NPBguo6oJAvTU Ax82C1JD6Rhir5lNi3DzmiZEkWR+yaP1u2ZaadNbsx8vk7gI25LWb6E3FXlKSSP9meo4 ZUSIog2xVMjqe9sWxdNIqii+LuCXZfKvjdH5cCL2QJkigp3f7mLlQSYBfS3E0ZKMI8MP yOJInzJkaYVYfl0chYXW68h0DMC5EgjD6PFwuDTCJCOOHIdL0ExnUH+yC1H0NcHjPGQg sPGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b="lEC/i/Ha"; 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 by20si6572114ejc.528.2020.10.30.12.36.48; Fri, 30 Oct 2020 12:37:11 -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="lEC/i/Ha"; 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 S1727713AbgJ3TYq (ORCPT + 99 others); Fri, 30 Oct 2020 15:24:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727704AbgJ3TXK (ORCPT ); Fri, 30 Oct 2020 15:23:10 -0400 Received: from mail-ej1-x641.google.com (mail-ej1-x641.google.com [IPv6:2a00:1450:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CB31C0613D5 for ; Fri, 30 Oct 2020 12:23:10 -0700 (PDT) Received: by mail-ej1-x641.google.com with SMTP id p9so10124332eji.4 for ; Fri, 30 Oct 2020 12:23:10 -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:content-transfer-encoding; bh=cL9WOPO2zHT1vQiE1Idu/YzBY6AJ1/e6GyUyFPMSPBE=; b=lEC/i/HaCAbfQosRN4vmMobfCxVR+WZvnS6eUCNPlKWH+DM9vHMj7SqJcRXOIjY3gR X7fqNKkZHnLb3MSxwodUICF97jfOsHKnuDyEcvSjhdLdPJDHWyuIEcOT1bdngZUgm+fB LnvKGjcJua2dQA5V5B17tvYJrJ6z/kJG7BObCa8rMFSzoI2LQncz5V1J1hPiz0LBLrhB ehP68u5wwlkkRu5765qgLOCoQ/hOKUaoLOB0RlxdEAi5wNF8262oDo5KcRXIkHzdad7I P2+qsjLodK5zSNdL+ykfiARoWE6cSX7jXnihb6GRYo+FQOn/ZAgy9c4PIkYJzVJruoKu pI/A== 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:content-transfer-encoding; bh=cL9WOPO2zHT1vQiE1Idu/YzBY6AJ1/e6GyUyFPMSPBE=; b=QXwq4doPkdUL7RLO6szd3EtoOjN2oD9q30bmrP+zOxuRK6QMmNSLE3Sa5QwuTDJOTF ia7owDMZjSk3Q/PIXZD5UeSDRsvhxHwl2RmRDebIU6FO/3X06L1DWcBCuVgMohknideK hq7l4ThwHnar6Hjt5YnhWL+foP7txi2cv5iIU/wUW1VK8tL06xtjKqurJWrOrPjd2tR1 qQ4B5ZWx+YhfeAM5qEfeVTd1lS/aFZ4nvygTjhFgDBuSekheEvB+pOF/1Nti8O0N6e5N 2h8n8rBM/GesDMIXq3uX+3hqLbKgwExLRD+rYmQBp4T+YOhDaTXx8dBDMNqqQtr8CyGc zX2g== X-Gm-Message-State: AOAM531QSTND+v5S3gMZirOYE7SOQeWG0BhexfYN5ylZmkjnKo8sVnHA gwaXGoQvdP9/1Z8aTNONQnu08MXDnsSzTgMK+NJssw== X-Received: by 2002:a17:906:70cf:: with SMTP id g15mr3935941ejk.323.1604085788862; Fri, 30 Oct 2020 12:23:08 -0700 (PDT) MIME-Version: 1.0 References: <20201030100815.2269-1-daniel.vetter@ffwll.ch> <20201030100815.2269-16-daniel.vetter@ffwll.ch> In-Reply-To: <20201030100815.2269-16-daniel.vetter@ffwll.ch> From: Dan Williams Date: Fri, 30 Oct 2020 12:22:54 -0700 Message-ID: Subject: Re: [PATCH v5 15/15] 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" , Daniel Vetter , Jason Gunthorpe , Kees Cook , Andrew Morton , John Hubbard , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Jan Kara , Greg Kroah-Hartman , Bjorn Helgaas , Linux PCI Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 30, 2020 at 3:09 AM Daniel Vetter wrot= e: > > 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. > > 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. The cleanest way is > to adjust this at at ->open time: > > - for sysfs this is easy, now that binary attributes support this. We > just set bin_attr->mapping when mmap is supported > - for procfs it's a bit more tricky, since procfs pci access has only > one file per device, and access to a specific resources first needs > to be set up with some ioctl calls. But mmap is only supported for > the same resources as sysfs exposes with mmap support, and otherwise > rejected, so we can set the mapping unconditionally at open time > without harm. > > A special consideration is for arch_can_pci_mmap_io() - we need to > make sure that the ->f_mapping doesn't alias between ioport and iomem > space. There's only 2 ways in-tree to support mmap of ioports: generic > pci mmap (ARCH_GENERIC_PCI_MMAP_RESOURCE), and sparc as the single > architecture hand-rolling. Both approach support ioport mmap through a > special pfn range and not through magic pte attributes. Aliasing is > therefore not a problem. > > The only difference in access checks left is that sysfs PCI mmap does > not check for CAP_RAWIO. I'm not really sure whether that should be > added or not. > > Signed-off-by: Daniel Vetter > Cc: Jason Gunthorpe > Cc: Kees Cook > Cc: Dan Williams > Cc: Andrew Morton > Cc: John Hubbard > Cc: J=C3=A9r=C3=B4me Glisse > Cc: Jan Kara > Cc: Dan Williams Looks good to me: Reviewed-by: Dan Williams