Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1143133pxb; Wed, 4 Nov 2020 00:48:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJyxNlCmQYeGeb9j93m9jACmdv+3oUkQ2Fx5cCBzblDEUMwCo9ngpw47eCbd07JXMnmbeHCc X-Received: by 2002:aa7:da0a:: with SMTP id r10mr11117310eds.102.1604479695819; Wed, 04 Nov 2020 00:48:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604479695; cv=none; d=google.com; s=arc-20160816; b=KwPfDTP0Bl81WXG8YQbch0C+PJ+aEXUHjIQFQS4d+PRXmtAsVXd1Z0ZeaZivlIsz+E PvHV8+iZGlSles2K2sNGSOrgyQejoIozJZ631BN91NDAaQrpvsUZfW3dODEGI6pAiUyj Eex6PzNahCG16pdXHBnICn7q8fbMKKkxdUqtwntZjvAaR0Q50SFQTWzV4New3fGvEuMi ExhDlliuHLnK10lf+EgShr/qG3c1/pXUe0iqbDlJc3a3eb2vfKAq9E11auFZ0tlOVC4e 3WKWjwAJeXAd0dRRvjGT13i8GKU2pojk1+OdTqsO/4geyLLy/7lRziLawXbcK2FWcesM MJWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ycqoIkcF9lPtiJBVMgjq7zwCX8Gyu6JCtVXT12jKTV8=; b=DWO4PqtNEh8A7wCN72XpQQiFoUiC3iKx/PuCYirBYmjaFvLwwERQ0Hm7zqUp0SfWQN LDmTqyvjo0iW/+KX7s/Jc8gpsamvy+6x92ACdlphnQtlJHLMtWt+f2fPM2+vg3o4KpEz XiC03gtb06+ZjCNDzCcVMIyuchM0sXDBMQ9lHqexauObOe50HqyEpnzUWxBhYpD0GJ6C 4inWFtbIaEKU3MEu+bp3XCtsVyK2tsvxwALVlY/+PaNO/dRx2J26ZqpwwkcfzIbGYMh6 iluHzlIWhKBaWW+h2Dlp0UqJ3KDBYf1sffDxvFUFyh6XZKB7/bEf4ssU8nU4yTQ23krU obBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=SO6a9eIH; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cd24si968254ejb.213.2020.11.04.00.47.51; Wed, 04 Nov 2020 00:48:15 -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=@ffwll.ch header.s=google header.b=SO6a9eIH; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728207AbgKDIoU (ORCPT + 99 others); Wed, 4 Nov 2020 03:44:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727812AbgKDIoT (ORCPT ); Wed, 4 Nov 2020 03:44:19 -0500 Received: from mail-oi1-x244.google.com (mail-oi1-x244.google.com [IPv6:2607:f8b0:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9A89C061A4D for ; Wed, 4 Nov 2020 00:44:15 -0800 (PST) Received: by mail-oi1-x244.google.com with SMTP id m13so12330220oih.8 for ; Wed, 04 Nov 2020 00:44:15 -0800 (PST) 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=ycqoIkcF9lPtiJBVMgjq7zwCX8Gyu6JCtVXT12jKTV8=; b=SO6a9eIH6r+EzFThZ6MTARjwHEtx6LFHOpOvFgwKmnw7LjZXHcgycyhZfUmdSwXoni 9VPCbgc6ODqmZSPJVN4eXwn3IqpRr3uXKNjrMKGfBOBHLutZLHhso+mS3OiPqxM7Q6/l K5a5NNqZWoxju2yJSN+OURI61y0XID3dk0Roo= 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=ycqoIkcF9lPtiJBVMgjq7zwCX8Gyu6JCtVXT12jKTV8=; b=S8bCfPK0wQxdm37ulmQZGO0dGuJAcNZmiUcdEJTKLXw+NpY8QlJ0MlVAyLWghs1Tes rf3OjsMA/IS5cY9hp0QBm2kdGISo8+Qbj/AAlR6koOZSh/PesDnuZkkZ34rG2i3IaAEY qGlb98TpVcv5hny0B43TRg4WyOCpZzZlfe0/oWUHWqkIhZ7T6AAwIUj/BLsYMyh3Z+Cy HfrERmEgoj+5uZd6ds4NdoT/yYDLIwdgkaBgRsk6xTJelclePT575xq27RjmFdyYJB7M oK8aTYIdf5Obe7ntQdnhxpzexJQxHeEY3jshsBN96mIteWkqpC0PxQUaTsrw7iUZqzzw N3kA== X-Gm-Message-State: AOAM532RRWUDL6nt5A4psTeK9mDzrntrToob8qFzhTBpkBfaOTHUqQ5I sOgAgqsvRfEfsKNegap7tKpjMRhAQRQXM7C9MJ5Z+A== X-Received: by 2002:aca:b141:: with SMTP id a62mr1813813oif.101.1604479455139; Wed, 04 Nov 2020 00:44:15 -0800 (PST) MIME-Version: 1.0 References: <20201030100815.2269-12-daniel.vetter@ffwll.ch> <20201103212840.GA266427@bjorn-Precision-5520> In-Reply-To: From: Daniel Vetter Date: Wed, 4 Nov 2020 09:44:04 +0100 Message-ID: Subject: Re: [PATCH v5 11/15] PCI: Obey iomem restrictions for procfs mmap To: Dan Williams Cc: 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 , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Jan Kara , Bjorn Helgaas , Linux PCI Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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. -Daniel -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch