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,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,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 24620C55179 for ; Thu, 5 Nov 2020 09:35:19 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9A3822083B for ; Thu, 5 Nov 2020 09:35:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="d7PUFeO+"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="ST87g3bo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9A3822083B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=XQPBZdH9sn3yc9KJA3x2Pu4qZcIjM6KaRHKL/qkUqN8=; b=d7PUFeO+g/GQ4gxeBIzhrLnm3 qq2yfhFmpZdM9QKnX/bTaXhK3dwj9WyvYaIT90RvMfQZCpI0M8xqME3IT5kzM8Wva8BLnFyHveanS zhgVTGH6T4SuxVMDMWChx1Ws8ItmFBvF90iP9DlcbFyUA5PKqlB+o/XsJjRp0lg2WIzK6jWaSm8Li hIUC4ZdR22R/fTZFqvTakdlfnO9b3Xowj1NH9iEjykHOe38tmoz5WxrD2GQr2/Cm+XyDBcFigj9bd wuotAPfpxgIz3d2DmmF7lGyIqFOE7Y0Dbcb05/DTuqKz31LnSgnEBc04zaJizItVHpTSbN8ceKzlI MTVt+oxJA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kabeq-0003wW-9Q; Thu, 05 Nov 2020 09:34:16 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaben-0003vP-P0 for linux-arm-kernel@lists.infradead.org; Thu, 05 Nov 2020 09:34:14 +0000 Received: by mail-wm1-x343.google.com with SMTP id h22so885312wmb.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=iPNg7okk+7mc29numWEaCCND12JVEvU0uaUsXYRIJDLO1E7FESDiXM6i3cLVaMZx8Y np0cApmtQekiHAknTYZMD1nL2GJorS5tfsbxbyxTjoKsGbWeioGvP5aR6L6yj6vuerV1 B6xY/QaZwzzY/KZ6J4+wNBWpZoMra7N7aEV89O/o6w/sHaIPW/E64J9Ar7YfvbFJtNRJ kAV5Z77w/gy8Jz+KqsO9fCX1U7zqdXpejqE/eA4e82r9GAtZHzflLhb+UllV83n+sgsv 2OHqfKzMofK3jkzGhH7B8P42ta/SZTG4d/UlcQG8oYy94QvQJPl1GMVNRzi7eslL4Id7 tpMA== X-Gm-Message-State: AOAM533QW5pFZcm6rWD/1Ygc8v7HWEYS9ibsXROEleBDJAoNH9Z5g21W LIY/5bj9lb9walLBv8QdmnW1mg== 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 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-Disposition: inline In-Reply-To: X-Operating-System: Linux phenom 5.7.0-1-amd64 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201105_043413_850667_B3061A14 X-CRM114-Status: GOOD ( 41.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-samsung-soc , Jan Kara , Kees Cook , KVM list , Jason Gunthorpe , Daniel Vetter , Linux PCI , LKML , DRI Development , Linux MM , =?iso-8859-1?B?Suly9G1l?= Glisse , Bjorn Helgaas , John Hubbard , Bjorn Helgaas , Daniel Vetter , Andrew Morton , Linux ARM , "Linux-media@vger.kernel.org" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel