From patchwork Sun Mar 11 12:38:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 10274727 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 B6DEF601A0 for ; Sun, 11 Mar 2018 12:42:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A694328DEE for ; Sun, 11 Mar 2018 12:42:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B5AD28DF4; Sun, 11 Mar 2018 12:42:02 +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=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 4D68E28DEE for ; Sun, 11 Mar 2018 12:42:01 +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=3gUFqrXzvJ0/nQZ/1tlyVioggvUIlDHodGZv+g4lS6U=; b=f1vcXynRq/HkOvOePa4kCfSDbJ aItaJYuOKtsii6XmvuN0MtoCnq8x1rqRGVJSHJvcF388uHB6ot0N97jI94UbZ2jkLSWGEcbrGfOEF m2HhtOuSWS36C+H6KSp3rkRPdvU20HOuAPqx7lJzNGzxKgOnn+TQdseE/X+myyOC5boTs4hskh3I0 0oQ8XAmVlr5kHIY5lp/KbUmh6zuMRkE5zxKH/X+RIDBqtpHjIAVSTdpsk+ornpFOPSe5QfMVKvMW+ sTJCrUBz327OdHU9cR8FMyWo8yJ1uRX93ZCDrYv0FzEqyUbmIliqzGcm+gPhwcmM8arJSXW4unH3t /dy+oU8g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1ev0IR-0005Vx-HI; Sun, 11 Mar 2018 12:41:51 +0000 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1ev0G6-0002gG-4c for linux-arm-kernel@lists.infradead.org; Sun, 11 Mar 2018 12:39:38 +0000 Received: by mail-wm0-x242.google.com with SMTP id a20so9511204wmd.1 for ; Sun, 11 Mar 2018 05:39:15 -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=72OAPI9Kvt1iwKA3RSKe8xgQu1XKCUkEMrG/Hji532U=; b=DXVoHVlsex+jQ6eacasWEx6IPON3vb7ibDZgPBkHSmmblHnmS/kylgN5Qm7zERsRDc o2iVDcwix2ZWvHSj7RAZyl/ctiT0Vztuoc2bCNh5oAkTOqrmLNoGeM5uZMTvwJwPbjmy cid+ShSZ3Zmx0mFW+HI6jgPNNdB4WD1A6+/o8= 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=72OAPI9Kvt1iwKA3RSKe8xgQu1XKCUkEMrG/Hji532U=; b=GsaWKdoSjfYsW8Zh/5uhqnjbXMmfiskYgFPsAPLugd5qwPZlMR4AISGEt+YZ7Rvibi esV1XSVppd5WwLn2k/Ifs+Yc9qjPJCxZB1Dev75AjeCKZDnmneyHKJ6kJKZJlleC6Upi aIfR9Sgrj1czfQ/enyiDtP8sOlkOd1tBpFlAaSol9nDEtsLJR1pQOOiPKJqG5WJrEdlT OOZJr0J3YVcMGMrBf/EqLnPZDou5rvnaqxcUqN0BP70mkkKm+oCXJabChEYiBzTwXT+t Z/M95459MVxQZiEwZP7OG4uoJBRvbX/R0+KvmHXqKnE4gY/niMXVtfjvvL+2/Q6XQCgs UEEQ== X-Gm-Message-State: AElRT7Hz+a8gpyXxW1xyLn0kFQ4hDoRnHMsU56eQCcV3z7JnzkK2ZsYa XjBW/6mUROIfvW4qifc5IaHxFJClWhM= X-Google-Smtp-Source: AG47ELvfRVCqaEDMDHQDVqiqNfu2ZFIO+q7L6Y9Hk/fGDjbQzyRKrqZMNjVWyHiLtRwJS42di6IEpQ== X-Received: by 10.28.161.4 with SMTP id k4mr2856331wme.103.1520771953915; Sun, 11 Mar 2018 05:39:13 -0700 (PDT) Received: from localhost.localdomain ([105.148.128.186]) by smtp.gmail.com with ESMTPSA id h188sm2569103wmf.37.2018.03.11.05.39.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Mar 2018 05:39:13 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v8 5/6] PCI: Add support for relative addressing in quirk tables Date: Sun, 11 Mar 2018 12:38:14 +0000 Message-Id: <20180311123815.17916-6-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180311123815.17916-1-ard.biesheuvel@linaro.org> References: <20180311123815.17916-1-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180311_053927_090584_35502AEA X-CRM114-Status: GOOD ( 15.97 ) 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 , 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 , James Morris , Josh Poimboeuf , Bjorn Helgaas , Thomas Gleixner , Ard Biesheuvel , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.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 8b14bd326d4a..24abfaccd2a0 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -3563,9 +3563,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 024a1beda008..765044bb9e8e 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1790,7 +1790,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 { @@ -1804,12 +1808,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 " VMLINUX_SYMBOL_STR(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) \