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=-6.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,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 0DD17C4742C for ; Thu, 5 Nov 2020 09:34:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 319B521556 for ; Thu, 5 Nov 2020 09:34:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="ST87g3bo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 319B521556 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 20F9A6B00CF; Thu, 5 Nov 2020 04:34:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 19A416B00D0; Thu, 5 Nov 2020 04:34:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0393B6B00D1; Thu, 5 Nov 2020 04:34:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C09CD6B00CF for ; Thu, 5 Nov 2020 04:34:15 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 674FED200 for ; Thu, 5 Nov 2020 09:34:15 +0000 (UTC) X-FDA: 77449853670.11.arch45_570ba39272c8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin11.hostedemail.com (Postfix) with ESMTP id 31097180F8B80 for ; Thu, 5 Nov 2020 09:34:15 +0000 (UTC) X-HE-Tag: arch45_570ba39272c8 X-Filterd-Recvd-Size: 8996 Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Thu, 5 Nov 2020 09:34:14 +0000 (UTC) Received: by mail-wm1-f65.google.com with SMTP id h22so885310wmb.0 for ; Thu, 05 Nov 2020 01:34:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=dhezt058VYAXUzsmT6wFAloMyt6Frs+cE6TCkSAcHPs=; b=ST87g3boTQObR5JxsvDJGIfMAlcgsXvr+F3JKuft7VsNKm+GuZmFkRWYBz/N9m+nP5 gUOFOdjErnnQz3ZNReWuFokDdnl7uPc7ZMOj6kqNide21CEbt+Pus48kXLDRURvnNC2N 3RAKhoWa6Hje1zG3vURpcraCOdJW7Q+XZ+t28= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=dhezt058VYAXUzsmT6wFAloMyt6Frs+cE6TCkSAcHPs=; b=l/AIu4hWGPP+Wxk8kWnDrATkpQwfKAjawDi/rWiQRZuvYWIS+bMVWW60+cRjQDU1BI GvxGr9RMfS3b7xnPnOkfM4GtFwwPxU6ZTwqXgayH/DRQgHi+mdMg33exD2OTOhEpXD/y DD1yX2//uAsy/2YNbOeZ26cBmL8Vq/0//2te3A4fav1UXZBrJvqcFtY8izuZftnJYi2M t/zbQKSfUVJ61y246PR46n/yVZTw5FUxWoW8GPjbVmXapYKwY0kyaLGGpr5G5M5l1XEW OcgrRX6oPRXhPZVnhNRpHokJc3Pmc6aEb+aZBGxtCv++V4rY2CMVkIAGHEzCLPmseSVw oWAw== X-Gm-Message-State: AOAM5336aPnEw1HlTs4K3T3F45Ra/qz1FW2AKQHrYaJztMH1LNSoAG/m fZCcWkktyESDCicJcGp6LVzmrw== X-Google-Smtp-Source: ABdhPJwBx2+thaZ4Z7KLrdw1GbhrDGTHyh3vgC78jGbXnmbFtcgLmot8B2SlqilS+tbAOr47w4H/Mg== X-Received: by 2002:a1c:21c1:: with SMTP id h184mr1802586wmh.106.1604568852772; Thu, 05 Nov 2020 01:34:12 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id s202sm1648809wme.39.2020.11.05.01.34.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2020 01:34:11 -0800 (PST) Date: Thu, 5 Nov 2020 10:34:09 +0100 From: Daniel Vetter To: Dan Williams Cc: Bjorn Helgaas , Daniel Vetter , 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 , =?iso-8859-1?B?Suly9G1l?= Glisse , Jan Kara , Bjorn Helgaas , Linux PCI Subject: Re: [PATCH v5 11/15] PCI: Obey iomem restrictions for procfs mmap Message-ID: <20201105093409.GR401619@phenom.ffwll.local> Mail-Followup-To: Dan Williams , Bjorn Helgaas , 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 , =?iso-8859-1?B?Suly9G1l?= Glisse , Jan Kara , Bjorn Helgaas , Linux PCI References: <20201104165017.GA352206@bjorn-Precision-5520> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: Linux phenom 5.7.0-1-amd64 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 Wed, Nov 04, 2020 at 12:12:15PM -0800, Dan Williams wrote: > On Wed, Nov 4, 2020 at 8:50 AM Bjorn Helgaas wrote: > > > > On Wed, Nov 04, 2020 at 09:44:04AM +0100, Daniel Vetter wrote: > > > On Tue, Nov 3, 2020 at 11:09 PM Dan Williams wrote: > > > > On Tue, Nov 3, 2020 at 1:28 PM Bjorn Helgaas wrote: > > > > > On Fri, Oct 30, 2020 at 11:08:11AM +0100, Daniel Vetter wrote: > > > > > > There's three ways to access PCI BARs from userspace: /dev/mem, sysfs > > > > > > files, and the old proc interface. Two check against > > > > > > iomem_is_exclusive, proc never did. And with CONFIG_IO_STRICT_DEVMEM, > > > > > > this starts to matter, since we don't want random userspace having > > > > > > access to PCI BARs while a driver is loaded and using it. > > > > > > > > > > > > Fix this by adding the same iomem_is_exclusive() check we already have > > > > > > on the sysfs side in pci_mmap_resource(). > > > > > > > > > > > > References: 90a545e98126 ("restrict /dev/mem to idle io memory ranges") > > > > > > Signed-off-by: Daniel Vetter > > > > > > > > > > This is OK with me but it looks like IORESOURCE_EXCLUSIVE is currently > > > > > only used in a few places: > > > > > > > > > > e1000_probe() calls pci_request_selected_regions_exclusive(), > > > > > ne_pci_probe() calls pci_request_regions_exclusive(), > > > > > vmbus_allocate_mmio() calls request_mem_region_exclusive() > > > > > > > > > > which raises the question of whether it's worth keeping > > > > > IORESOURCE_EXCLUSIVE at all. I'm totally fine with removing it > > > > > completely. > > > > > > > > Now that CONFIG_IO_STRICT_DEVMEM upgrades IORESOURCE_BUSY to > > > > IORESOURCE_EXCLUSIVE semantics the latter has lost its meaning so I'd > > > > be in favor of removing it as well. > > > > > > Still has some value since it enforces exclusive access even if the > > > config isn't enabled, and iirc e1000 had some fun with userspace tools > > > clobbering the firmware and bricking the chip. > > > > There's *some* value; I'm just skeptical since only three drivers use > > it. > > > > IORESOURCE_EXCLUSIVE is from e8de1481fd71 ("resource: allow MMIO > > exclusivity for device drivers"), and the commit message says this is > > only active when CONFIG_STRICT_DEVMEM is set. I didn't check to see > > whether that's still true. > > > > That commit adds a bunch of wrappers and "__"-prefixed functions to > > pass the IORESOURCE_EXCLUSIVE flag around. That's a fair bit of > > uglification for three drivers. > > > > > Another thing I kinda wondered, since pci maintainer is here: At least > > > in drivers/gpu I see very few drivers explicitly requestion regions > > > (this might be a historical artifact due to the shadow attach stuff > > > before we had real modesetting drivers). And pci core doesn't do that > > > either, even when a driver is bound. Is this intentional, or > > > should/could we do better? Since drivers work happily without > > > reserving regions I don't think "the drivers need to remember to do > > > this" will ever really work out well. > > > > You're right, many drivers don't call pci_request_regions(). Maybe we > > could do better, but I haven't looked into that recently. There is a > > related note in Documentation/PCI/pci.rst that's been there for a long > > time (it refers to "pci_request_resources()", which has never existed > > AFAICT). I'm certainly open to proposals. > > It seems a bug that the kernel permits MMIO regions with side effects > to be ioremap()'ed without request_mem_region() on the resource. I > wonder how much log spam would happen if ioremap() reported whenever a > non-IORESOURE_BUSY range was passed to it? The current state of > affairs to trust *remap users to have claimed their remap target seems > too ingrained to unwind now. Yeah I think that's hopeless. I think the only feasible approach is if bus drivers claim resources by default when a driver is bound (it should nest, so if the driver claims again, I think that should all keep working), just using the driver name. Probably with some special casing for legacy io (vgaarb.c should claim these I guess). Still probably tons of fallout. Once that's rolled out to all bus drivers we could perhaps add the ioremap check without drowning in log spam. Still a multi-year project I think :-/ -Daniel -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch