From patchwork Tue Jun 26 18:28:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 10490019 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 58368602D8 for ; Tue, 26 Jun 2018 18:34:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4822A28675 for ; Tue, 26 Jun 2018 18:34:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39ED028683; Tue, 26 Jun 2018 18:34:09 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.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 D140628675 for ; Tue, 26 Jun 2018 18:34:08 +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:References: In-Reply-To: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:List-Owner; bh=Oz3D+VqsoOM0ER8ojNswsY1qAmnNPGXGb8ERyJRzB60=; b=MFERu/2sHM+E6sWi4epD+/6ffp Uaxv4bQEYv/y6gxnkIf74TW47h2ArSxCOj/EYuKzSA9xARcjsxQh3xlsfjWuBXVS7m0c43h4VMEHa Qc88/0w9KHc1Gi2VIoiex/e647Eo/RC/gQth/lqC5KLsjHrF68VFICfDrSgBJNirCrLt+w0EnUvuo gSr182kcutyrHgVBtoxZkaMZAs+vdmQipg8zBm7vonZ5JvRgyROw3FqsEz4XdH8uRKqCunsZyB3/y vyZUlNB4wP+ZJvaFQ/KO3G0aKSfzE+ae3GE6G9EgjlEbMpqoIRyUymLakytN4VQeKpSgvFsIuz5PU x1/V3LJA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fXsmt-0002IN-OJ; Tue, 26 Jun 2018 18:33:59 +0000 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fXsi5-00073Y-5q for linux-arm-kernel@lists.infradead.org; Tue, 26 Jun 2018 18:29:09 +0000 Received: by mail-wr0-x242.google.com with SMTP id k6-v6so18211465wrp.4 for ; Tue, 26 Jun 2018 11:28:50 -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:in-reply-to:references; bh=7rtDqZRn08p6IrU2qqSvkpaXuaNX+BLXDAxvrNGfhOo=; b=EjRpK3hSgSPZ2IbhYyfsOubGNygDOsFKwCM0O9hlft6LOomb81jMgHZLG1WCI+dNvN vwGB/iCq21birz/AHBNXyBGsrgQ3lbnnHrZNJiAiEeBSCceRQxS55arQGPVFuWr7/Pbl NbboOjYq/dzf210TIurgGShTofSDL0QKmSEho= 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:in-reply-to :references; bh=7rtDqZRn08p6IrU2qqSvkpaXuaNX+BLXDAxvrNGfhOo=; b=gHw+7yHgChYNvKbTtcgezQ/1znaOUnfPmaqeLpGzSOCWpuEFk4YuPcOITrFwM4vRa5 PO8wshifbi3EHZJE4Tp6fbpXH4E4buKlTpjx0VBhy1uYp+85r/aAnO6QkOO1IrmD6/Hi tTxzh0lxSZgOb+rVtKOl/Z+j602mSchomG5dOjn1H1EYOqGdCtovZZRL5DHIEieBTBsX WN5MCMUUlrAFJP2sfdAcQvbfw8Isq9+tltlx43NaArImfKqZnbAs3Mg+wgT/J+EByoHs lVlDwz/cLs8h2BAkL2yhnWxJvihZo8jAqGIqSkGufzh35QbKNvjfcIBnLgl/5d913jfP x9ag== X-Gm-Message-State: APt69E0KOC6MwZAV30IHAtSNIKnWPh2yaCQOpCdkBwByapB5O33y5qfO KeJRgCgZdrvPcolNjdo/MgGmeA== X-Google-Smtp-Source: AAOMgpeqCv6MP65JB2MZyHSB5NRIj76tnLImVw+2rpBcVe9+O7CH4hwqsUezXu42dAe+1h4BQlRAlw== X-Received: by 2002:adf:8425:: with SMTP id 34-v6mr2402558wrf.72.1530037729483; Tue, 26 Jun 2018 11:28:49 -0700 (PDT) Received: from rev02.home ([2a01:cb1d:112:6f00:d037:e907:f0a2:a5ea]) by smtp.gmail.com with ESMTPSA id s17-v6sm1707664wmc.34.2018.06.26.11.28.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 11:28:48 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Subject: [PATCH v9 5/6] PCI: Add support for relative addressing in quirk tables Date: Tue, 26 Jun 2018 20:28:00 +0200 Message-Id: <20180626182802.19932-6-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180626182802.19932-1-ard.biesheuvel@linaro.org> References: <20180626182802.19932-1-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180626_112901_302098_B21A437C X-CRM114-Status: GOOD ( 16.81 ) 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: Catalin Marinas , Will Deacon , James Morris , Paul Mackerras , Nicolas Pitre , Michael Ellerman , x86@kernel.org, Russell King , Ingo Molnar , Benjamin Herrenschmidt , "Serge E. Hallyn" , Petr Mladek , Kees Cook , Arnd Bergmann , Steven Rostedt , Josh Poimboeuf , Bjorn Helgaas , Thomas Gleixner , linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , linuxppc-dev@lists.ozlabs.org, Sergey Senozhatsky , Jessica Yu , Andrew Morton , Linus Torvalds , Thomas Garnier 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 Allow the PCI quirk tables to be emitted in a way that avoids absolute references to the hook functions. This reduces the size of the entries, and, more importantly, makes them invariant under runtime relocation (e.g., for KASLR) Acked-by: Bjorn Helgaas Signed-off-by: Ard Biesheuvel --- drivers/pci/quirks.c | 12 +++++++++--- include/linux/pci.h | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index f439de848658..0ba4e446e5db 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -64,9 +64,15 @@ static void pci_do_fixups(struct pci_dev *dev, struct pci_fixup *f, f->vendor == (u16) PCI_ANY_ID) && (f->device == dev->device || f->device == (u16) PCI_ANY_ID)) { - calltime = fixup_debug_start(dev, f->hook); - f->hook(dev); - fixup_debug_report(dev, calltime, f->hook); + void (*hook)(struct pci_dev *dev); +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS + hook = offset_to_ptr(&f->hook_offset); +#else + hook = f->hook; +#endif + calltime = fixup_debug_start(dev, hook); + hook(dev); + fixup_debug_report(dev, calltime, hook); } } diff --git a/include/linux/pci.h b/include/linux/pci.h index 340029b2fb38..51baa3ab5195 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1795,7 +1795,11 @@ struct pci_fixup { u16 device; /* Or PCI_ANY_ID */ u32 class; /* Or PCI_ANY_ID */ unsigned int class_shift; /* should be 0, 8, 16 */ +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS + int hook_offset; +#else void (*hook)(struct pci_dev *dev); +#endif }; enum pci_fixup_pass { @@ -1809,12 +1813,28 @@ enum pci_fixup_pass { pci_fixup_suspend_late, /* pci_device_suspend_late() */ }; +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS +#define __DECLARE_PCI_FIXUP_SECTION(sec, name, vendor, device, class, \ + class_shift, hook) \ + __ADDRESSABLE(hook) \ + asm(".section " #sec ", \"a\" \n" \ + ".balign 16 \n" \ + ".short " #vendor ", " #device " \n" \ + ".long " #class ", " #class_shift " \n" \ + ".long " #hook " - . \n" \ + ".previous \n"); +#define DECLARE_PCI_FIXUP_SECTION(sec, name, vendor, device, class, \ + class_shift, hook) \ + __DECLARE_PCI_FIXUP_SECTION(sec, name, vendor, device, class, \ + class_shift, hook) +#else /* Anonymous variables would be nice... */ #define DECLARE_PCI_FIXUP_SECTION(section, name, vendor, device, class, \ class_shift, hook) \ static const struct pci_fixup __PASTE(__pci_fixup_##name,__LINE__) __used \ __attribute__((__section__(#section), aligned((sizeof(void *))))) \ = { vendor, device, class, class_shift, hook }; +#endif #define DECLARE_PCI_FIXUP_CLASS_EARLY(vendor, device, class, \ class_shift, hook) \