From patchwork Tue Apr 11 08:43:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 9674729 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6130860234 for ; Tue, 11 Apr 2017 08:44:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D52E2845F for ; Tue, 11 Apr 2017 08:44:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4237E2850E; Tue, 11 Apr 2017 08:44:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BE8CA2845F for ; Tue, 11 Apr 2017 08:44:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=4jQ5gcy40PXVSuwEKqNQWfAdHtuw3lz3SsW9HtXm6TI=; b=Qbh ju7ZJkhs2vpOLVMMXkay/v7sSJBEaM++FqJDdCj8J5oP6vIKC8D59V5iE7nHexkl6YdfuJFs7LZZH Z+ZcDxRhEF/ujwVIkpzAtKrEYIxFAJ2rRLLruJ+yVqqxcIo4RBQr/cG24tKUiixqqB3nIGA+3IbBo T/+frQpYvurnBfb6T3nL2tnOdW5ZC508qH77iUts/AGcCvYwJR/GHQUtBnORIiq9KAsFxo5VLpD0X BOIuLclDNJHHTOV6VJRjVGhuGtbJTK8L+paBSHRhxTpdG8p3v7JKdEO20kkA4s4woZrDtrNbg5xgQ j0ATTzS36heTYgQvNj7gMOgc2AWYNDw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cxrPP-0008Uy-J6; Tue, 11 Apr 2017 08:44:19 +0000 Received: from merlin.infradead.org ([205.233.59.134]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cxrOz-000827-Aq for linux-arm-kernel@bombadil.infradead.org; Tue, 11 Apr 2017 08:43:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=f9A28CiDNro7VUQyOYTO25PAauuqBVevjzPwIozjECA=; b=oFJJRntjTL0rkMBTvBy50SQL+ dTByWWsgRrp4ovSkhLwtqLUHxJaC5Wgxz9Brx5A8k7Cshy2QURWUmuFJ+80DTXvped/mTWka9mOKj dQL3SjwoYUwdGKJ9c93tm4F74xsFirpIIlMU4DruYjO7gjn6IiEAL5azRY3iXv7O+UciheI7XOht4 PgK7bRmcLzDhTLhRpFsfaKVhG9Zu7RmWL00gKsNPtGNlaT0AJTioFx5jqWQen7COASGNu+OuluwED kxoDjjpQhN78D01lyXypa7CmBiyNlqn8kaZtZvVgx6bpML11xjGp6yLKyfzOvNzsBTO5YLDQJexjT k2y9v8nyg==; Received: from mail-wm0-x230.google.com ([2a00:1450:400c:c09::230]) by merlin.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cxrOu-0005WP-Dy for linux-arm-kernel@lists.infradead.org; Tue, 11 Apr 2017 08:43:52 +0000 Received: by mail-wm0-x230.google.com with SMTP id t189so55465449wmt.1 for ; Tue, 11 Apr 2017 01:43:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=f9A28CiDNro7VUQyOYTO25PAauuqBVevjzPwIozjECA=; b=KB4QCgCSGzzCbZh43VdyBk1ddsizqbgSDmxgzs5x0p9kwDnw4HyEHrRr876ICe2yjk J4EjMoKR9uWqTTq/QStVepjouE0l4dtjqrOFCUw+hPtqe/p76dXEWGwdpLEfHy3GeTkl 08vsMW84iSot1VMsgbbQDBcM2OTgJZMwMN9/k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=f9A28CiDNro7VUQyOYTO25PAauuqBVevjzPwIozjECA=; b=m+y6Nuj8Lz3JqvkOwlLqSceqX0Rj0cKPqenjOeA5mqr8IkWnSp3MRuyQOnhzpT3MnR GWLhN7Q1bA09IEFi+wk41GMNBjYz8YYTvnEpetqtaq88of6w8r7EzP71vpdDZWd/46ng k8efOzvUW/17PeYUKZRkTMVm3E/ec6Q/n1tBCJ/DA0d91RWnzdV+ZoAdR8+aRRW2OtVZ MTKdJiD8IqGLNNJkNQau3SrRDUH9kh/LLJ5MSsDLIEOtXLHvCIy/RuRtEnTghAwieTTF awLxIS8khMr7oHnT4HrVjw6Cuu6wiuOeVvRLrDPHfJEak3liK+axQ/SdHxyF1FkQK0Nd oznQ== X-Gm-Message-State: AN3rC/4xXVfwX/kjWkqfNSbMYOjTqr/1z/VnojX9lA5sw7tdCvBapvsW D297qvlQDXm+Itwg X-Received: by 10.28.195.7 with SMTP id t7mr12616977wmf.62.1491900205878; Tue, 11 Apr 2017 01:43:25 -0700 (PDT) Received: from localhost.localdomain ([196.85.182.219]) by smtp.gmail.com with ESMTPSA id e21sm1557466wma.5.2017.04.11.01.43.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Apr 2017 01:43:25 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org Subject: [PATCH] efifb: arm/arm64: validate fb BAR instead of claiming it Date: Tue, 11 Apr 2017 09:43:18 +0100 Message-Id: <1491900198-26187-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170411_044348_657666_FD5A2AB9 X-CRM114-Status: GOOD ( 15.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-fbdev@vger.kernel.org, lorenzo.pieralisi@arm.com, b.zolnierkie@samsung.com, matt@codeblueprint.co.uk, Ard Biesheuvel , okaya@codeaurora.org, pjones@redhat.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Claiming the BAR that matches the framebuffer base address in a PCI header fixup quirk only works as expected when the PCI device is on bus 0. If not, it will produce the following error: pci 0000:01:01.0: can't claim BAR 0 [mem 0x10000000-0x10ffffff pref]: no compatible bridge window pci 0000:01:01.0: BAR 0: failed to claim resource for efifb! Since claiming the entire path up to the root is non-trivial at this point, and also undesirable given that we have no way of making sure that the existing configuration is sound, let's not claim anything at all, and simply record the resource so we can check that it did not move when the EFI fb driver is probed. Signed-off-by: Ard Biesheuvel --- drivers/video/fbdev/efifb.c | 23 +++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/drivers/video/fbdev/efifb.c b/drivers/video/fbdev/efifb.c index b827a8113e26..21d635ef5be2 100644 --- a/drivers/video/fbdev/efifb.c +++ b/drivers/video/fbdev/efifb.c @@ -146,6 +146,8 @@ ATTRIBUTE_GROUPS(efifb); static bool pci_dev_disabled; /* FB base matches BAR of a disabled device */ +static struct resource *pci_dev_bar_resource; + static int efifb_probe(struct platform_device *dev) { struct fb_info *info; @@ -179,6 +181,20 @@ static int efifb_probe(struct platform_device *dev) } printk(KERN_INFO "efifb: probing for efifb\n"); + if (pci_dev_bar_resource) { + u64 base = screen_info.lfb_base; + u64 size = screen_info.lfb_size; + + if (screen_info.capabilities & VIDEO_CAPABILITY_64BIT_BASE) + base |= (u64)screen_info.ext_lfb_base << 32; + + if (pci_dev_bar_resource->start > base || + pci_dev_bar_resource->end < base + size - 1) { + pr_err("efifb: PCI BAR has moved, disabling ...\n"); + return -ENODEV; + } + } + /* just assume they're all unset if any are */ if (!screen_info.blue_size) { screen_info.blue_size = 8; @@ -383,12 +399,7 @@ static void claim_efifb_bar(struct pci_dev *dev, int idx) return; } - if (pci_claim_resource(dev, idx)) { - pci_dev_disabled = true; - dev_err(&dev->dev, - "BAR %d: failed to claim resource for efifb!\n", idx); - return; - } + pci_dev_bar_resource = dev->resource + idx; dev_info(&dev->dev, "BAR %d: assigned to efifb\n", idx); }