Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1438352pxb; Wed, 4 Nov 2020 08:56:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJychwNWH4BoBLGQDKxPTd603VcOzWlV+5nmZqAnL9nakoXhJiG9o0RhxiPvWV6oz5+iqrXc X-Received: by 2002:a05:6402:290:: with SMTP id l16mr26652539edv.104.1604508962685; Wed, 04 Nov 2020 08:56:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604508962; cv=none; d=google.com; s=arc-20160816; b=GcOybqKtrerBSqlg20+N7X7h8u5i7ROeznUaN8y4JDUWBRJ/TSPhKXwPXkaTm+HmbJ xD+hCO8UbSiSXH/+A/6go8L1Wz4qz51KZ/y4SjRNANWEfxSWN5x7YbPEh91ySaZR3nnX nTwgN/npDZhmZBUyhBIQjDRoI4PpeYkdIzkanXImPKJaAKL43Gw+65AJMT+ErlJP6Xhj I6Zl8MiqWZ5Xmm3lHTumUncKmdKkV6BUG9lPWKPe9DKsPPVJi0Kebbrgcjrthr0NLPt1 OVKlGqPidc1hpaSaDb4CQmeCxEikl1cd2UEyyM8sXzWPNbYM9RGNqEE3fH6wGfzBJ298 eZiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=giL5BXKljscVBLRq6n+zYIQKOepMMfQYEwjEt+vkZ/E=; b=IM0SKgxfRnaRM+oCo4okWDe2ViR2ra8VVNvz2rZAcwszbZbXi5wssvPudfW2OJmIlJ 9JuqO8gkauh9SPAtEVp6ACdkFxTgCsl8dgZEL48WQzAemSgEHP7e6yfBok85uoiJxWyY QLeVUuCNJlUe+byohLJUR9XjxfH8fS96g6tBobb35QkF/56GzlAEBmMdl8J3FZqHeEnX 2cfwfYgzg/vb9lq4debbFMZhIlpsDTeoV3VTnMK5Pd6L3MOXsLk60RU3H0mW3pU06puP MzwHJ1Ks3xAgNnhXPNBtQ2RI3zJElzAZvgM2nw4e8kG7FtmkSiRXZ43usS6IeuAK6KpU CYnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=C3pX6cmo; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i7si1631435edj.303.2020.11.04.08.55.40; Wed, 04 Nov 2020 08:56:02 -0800 (PST) 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=@kernel.org header.s=default header.b=C3pX6cmo; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731687AbgKDQvg (ORCPT + 99 others); Wed, 4 Nov 2020 11:51:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:47120 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731683AbgKDQuU (ORCPT ); Wed, 4 Nov 2020 11:50:20 -0500 Received: from localhost (230.sub-72-107-127.myvzw.com [72.107.127.230]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 01712206CA; Wed, 4 Nov 2020 16:50:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604508619; bh=KzXcQsv6oXQiPT6pQbTFR35Ks2A09AmGg4NdOMxDZU4=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=C3pX6cmo6q8mwyEj5GO30o1K3DmrMhjsd197OHFiySwAIRZVIm3gcmWDrE+eCPQYz sPh4rcY/+zTADvqe8t10fQKgN6B/uva7r/Rm33jjbBhTlqD9gCI3SGCFFhZSFec0de QvdkQtLCYpZ8r9E77lkRpGYf+6s0+xBDMYsFK0NQ= Date: Wed, 4 Nov 2020 10:50:17 -0600 From: Bjorn Helgaas To: Daniel Vetter Cc: Dan Williams , 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: <20201104165017.GA352206@bjorn-Precision-5520> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.