From patchwork Wed Dec 27 08:50:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 122761 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1919948qgn; Wed, 27 Dec 2017 00:51:20 -0800 (PST) X-Google-Smtp-Source: ACJfBouhLzJJfjD6+5HE+D5y/frAIybrj2f+C0tCfaAMipcDOvEydf5XqWnie/EXlOLsS1Sq6oQv X-Received: by 10.98.252.7 with SMTP id e7mr27659988pfh.12.1514364680150; Wed, 27 Dec 2017 00:51:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514364680; cv=none; d=google.com; s=arc-20160816; b=Kxfms+0LTScBZDkUK1mjb1u8Kq9RHFWkJhn+41jHR9aAiOyhfjUqLgyf1hNZKcNqzn xpqoVapCftK80Zr5OK9LGXWE/IOcIgknPTalY9b7AKuR29i2m7hcoBzsHjCYcZ9+nJ9Y huwHpNlJLM2eyT6KQcXvBKbsYtSFgFB75SoJOdfq26NMZWvyVtOEkJ3ahg18WpMGN15T MtHXfxZRgZEIqsgT/NwCGzhKUAxgNfXue3p4PcezQfjnZyCibTnaa13ARUMsyALdgORy f+3SYHGc0Yg/sy0egP1Ldit6DEaQek1u4cZBd8Wt6E09ypXE6igUfMLUImd5jav9FVjq JA8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=MNuvKMvZr3GVfTz4MvnzswRbek+xsbzeG112C9Cor2w=; b=ciRVMrkBIFMGpxRXg0iMwc8ROuFGYxPhY60TaVTOmidkKeYegyStAAfo91ePqsKm15 zHYA9NZpGjrsXT2S/4L0/PuW8IuMCEgxdnMAKhM40g1AMzecY9DccUGoFGY/im8JiKo7 g8iqtkYCQnCIIeW7eH30ce3gsSBwLceEAD4edK9XVhqSfNGLhAc9gnXrfw0q3PuFhWOr AAAwPiZQ36q0GaJD1F1QS/Ez4zM0RCMDDBKXzDg7c0VHbnwu/ZYd6PLbXLkMcGuCiU2Y FmEs9OqFmsC9ydo8J3kv1FGyXtbLLYg4l1izCXi96xEK+bBwTfaKyJ4oGj5B5KTd5YSN byYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AJ/zr34a; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f1si24887036pln.118.2017.12.27.00.51.19; Wed, 27 Dec 2017 00:51:20 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AJ/zr34a; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751887AbdL0IvQ (ORCPT + 28 others); Wed, 27 Dec 2017 03:51:16 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:45768 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751867AbdL0IvM (ORCPT ); Wed, 27 Dec 2017 03:51:12 -0500 Received: by mail-wr0-f193.google.com with SMTP id o15so4022592wrf.12 for ; Wed, 27 Dec 2017 00:51:11 -0800 (PST) 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=MNuvKMvZr3GVfTz4MvnzswRbek+xsbzeG112C9Cor2w=; b=AJ/zr34aK0sT46fTFsfCFR1G30dXqEZ4pyPPilfvxKN86s3tJsT9l08DRTgEjFquhT JRk6X/cAvjr272ahonxRSd8HJ3zdzM93Lqw+0YW3ftpE5HIFcpceZ42qkfgsPKlN5E1z Khsmi+imR9JlPH8hPy3YgBFyJyeMNX7h8Otkk= 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=MNuvKMvZr3GVfTz4MvnzswRbek+xsbzeG112C9Cor2w=; b=GlHr7T3jpLX1gSGL8p7g+6ZPqAWNoxmAsNRgFzGKq5GKiA1Xt/kFBnI7sLxQMs7AjE 8fxqyY6hSoSs8KEiDRXoDLLMiXv3JAeTmibatm/PRt7ZD4eITY259VQeDDNqteWR+3jI KGYkn2ptJfLYjQuDUGkk02AKye/A8v2C5vtc5yakTMsbOm8LOiAq4DWqGyjJ1MCD4bJe aPR046oN6ChZCPJ2LuUD063+ImwApcFShEgLU3gv9NR37BuIDb7FiLcPbscmLvPbAv+t Vk1OVrXyZjMbp9x9ysJI+P1YTw1Wn3QZBcO5UAEb3fUTf9/oDVdidLAdSYGnrNoVlcZl EwpA== X-Gm-Message-State: AKGB3mKXjOOCgH3LFpN94iXmf1+Wf6txm87wNjLYN8hw2wndK0h5dEr8 f1em3hDhUhU4qBrlfV5XfxrUVJW7+oU= X-Received: by 10.223.128.9 with SMTP id 9mr19838598wrk.70.1514364670694; Wed, 27 Dec 2017 00:51:10 -0800 (PST) Received: from localhost.localdomain ([105.137.110.132]) by smtp.gmail.com with ESMTPSA id q74sm32677226wmg.22.2017.12.27.00.51.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Dec 2017 00:51:09 -0800 (PST) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , "H. Peter Anvin" , Ralf Baechle , Arnd Bergmann , Heiko Carstens , Kees Cook , Will Deacon , Michael Ellerman , Thomas Garnier , Thomas Gleixner , "Serge E. Hallyn" , Bjorn Helgaas , Benjamin Herrenschmidt , Russell King , Paul Mackerras , Catalin Marinas , "David S. Miller" , Petr Mladek , Ingo Molnar , James Morris , Andrew Morton , Nicolas Pitre , Josh Poimboeuf , Steven Rostedt , Martin Schwidefsky , Sergey Senozhatsky , Linus Torvalds , Jessica Yu , linux-arm-kernel@lists.infradead.org, linux-mips@linux-mips.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, x86@kernel.org Subject: [PATCH v6 4/8] PCI: Add support for relative addressing in quirk tables Date: Wed, 27 Dec 2017 08:50:29 +0000 Message-Id: <20171227085033.22389-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171227085033.22389-1-ard.biesheuvel@linaro.org> References: <20171227085033.22389-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 13 ++++++++++--- include/linux/pci.h | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) -- 2.11.0 diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index 10684b17d0bd..b6d51b4d5ce1 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -3556,9 +3556,16 @@ 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 = (void *)((unsigned long)&f->hook_offset + + 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 c170c9250c8b..e8c34afb5d4a 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1792,7 +1792,11 @@ struct pci_fixup { u16 device; /* You can use PCI_ANY_ID here of course */ u32 class; /* You can use PCI_ANY_ID here too */ unsigned int class_shift; /* should be 0, 8, 16 */ +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS + signed int hook_offset; +#else void (*hook)(struct pci_dev *dev); +#endif }; enum pci_fixup_pass { @@ -1806,12 +1810,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) \