From patchwork Wed Jul 4 08:36:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 10506197 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 0407E60532 for ; Wed, 4 Jul 2018 08:53:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD72428D40 for ; Wed, 4 Jul 2018 08:53:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CEBE828D43; Wed, 4 Jul 2018 08:53:30 +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 8F89228D40 for ; Wed, 4 Jul 2018 08:53:29 +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=E6mSGXvZvwE/h7t75G9UeaCOVxyBOUtnbHKQRhnVCb0=; b=DDO1SchLS0BgArH3YRyMii6GFn UnrXL8De1LoAyPo1daemPJP33flOyioJ3YN0Uz/Eu/cKM799NS++b3kjqAOAvfudQSAILovBNmzrn yfw7wIrvNzeq27s7a8+qX9WKnyX8wXfbrqWKI72JmON5K09fBtQdf0PEy2xL2hmSN8hJzGw2Hmbx0 Ie0y+F1VbEGSth+nNNLEXsyOwCNPP/OCUN9s6uCjcARBXwEUIt53gQbqBxGmhdngbvtndvSVS7fp5 E2EXjMxT2Er20xSxcC8C0BziormPrFucYrp2I8fIzfBIe6bDqsrBveV0eRStC3x8HhhM6ZnNEsWja mcUn+PNg==; 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 1fadXP-0008QW-GK; Wed, 04 Jul 2018 08:53:23 +0000 Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fadJX-00078Q-32 for linux-arm-kernel@lists.infradead.org; Wed, 04 Jul 2018 08:39:08 +0000 Received: by mail-ed1-x541.google.com with SMTP id g15-v6so3454895edr.12 for ; Wed, 04 Jul 2018 01:38:55 -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=sqbAdR8mVhPUbhBZJ1W38BSLp0pkEn3sNHW4MKbPLbQ=; b=IDNcrj1NlIQfgGHybPnbkoQiCFRN8HfZ/uGEfeoFAbZcFwUmSNtrr3SBeVTsgY/2q4 vA7HY38Uc/kmvDOwTlKRcAQl1tuXDYF+ZNH/IytTXD6s//FRTSj5JSW+gdEHE0xX9kNT xE3EfGwkeGYMaMfn4Qg1RFs0TgS9XKCnTI4Cg= 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=sqbAdR8mVhPUbhBZJ1W38BSLp0pkEn3sNHW4MKbPLbQ=; b=WX16+1epvpZ5304DN135Npbbx39JLIGadsEcoADDk5S2DF/EdNX5fmWpiXZJOa6j9m hFz4B6GzGJkrT01J71i4NH7fR/5DP4UghePK5twyk4ycsjsuPfuxqU2jbGJHuoAkWgN/ 7yOPO3IEm0WlYs+U+SnqRblj1JXjimhk0RdyKG+tFXub/6wVSSWKSriAkuFCPu3uaxz6 l2+VImMj12hsqjJiKsypqfuQCk2g47KxlSploMLf5oez31JIzpR1+H8d0GIwtID4FARy 9oy3ri15hsrUjdmsA6g5yIVbz/CgUqEtWiKuleP6IT+BU9P5dM6k+uZWMOvTF6WTBnKx /pCQ== X-Gm-Message-State: APt69E0x5j345Elz1Vh7R9EJGCSoi7PHQ+znDXlhFVta/vKxHWDMm9S1 Ub0AUC26f9Vb4wlaHSJT2XRYYw== X-Google-Smtp-Source: AAOMgpf0CYYAUABUsKAF5bXTnzl0YtYjlCK+DcHRC/0559Jq0/xOgGvZ7OQdcNTkb/DLPnd7q5NT5g== X-Received: by 2002:a50:ad0f:: with SMTP id y15-v6mr1715278edc.78.1530693534421; Wed, 04 Jul 2018 01:38:54 -0700 (PDT) Received: from ards-mac-mini.arnhem.chello.nl (dhcp-077-251-017-237.chello.nl. [77.251.17.237]) by smtp.gmail.com with ESMTPSA id k13-v6sm1821740edj.55.2018.07.04.01.38.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Jul 2018 01:38:53 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Subject: [PATCH v10 5/6] PCI: Add support for relative addressing in quirk tables Date: Wed, 4 Jul 2018 10:36:50 +0200 Message-Id: <20180704083651.24360-6-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180704083651.24360-1-ard.biesheuvel@linaro.org> References: <20180704083651.24360-1-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180704_013903_459788_91D710B7 X-CRM114-Status: GOOD ( 15.96 ) 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 Acked-by: Michael Ellerman Acked-by: Ingo Molnar 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) \