From patchwork Fri Aug 18 11:26:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 110375 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp780696qge; Fri, 18 Aug 2017 04:27:16 -0700 (PDT) X-Received: by 10.84.217.206 with SMTP id d14mr2884730plj.319.1503055636551; Fri, 18 Aug 2017 04:27:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503055636; cv=none; d=google.com; s=arc-20160816; b=YN8oa04HFddYrXXWFFLRD/uTi7HuDWnAl5smb7D4Vlq5tLVC8bSJY2QQHNAYovqcwT uxnNB1ZvmfaFPZzdwuVFDKwv+ra/kzaScYhVYw9gl55iem8e9bD9P6iIBCBut87j80Qw ZNevYXkIrk3WBY17f6+Rb3UGpBRmSTeKgbzxMjEIuLIwbu3w4Iwds3MUSJ9u+94VQMEh 3XxKUk8ARkDa+poNVJ8vhKEZOJAYT2Te1LQQFvR9VJ7Rehii3uSrkoKGBjIWZJaywLk3 jqheUwaXnrggt1jnvDok579drZAVgvt9gQDNDWgjh9U/tuQFEP91es9vWFOYU4OGCXn8 0GHQ== 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=sFVtzTun5xTiJYGGxiun2ScLBv7r6A52dK4isjQD32I=; b=C+nRSJOIqFRatKx19OKyUzIs/laktZSJqC6D1nVSA7rksXq+BaNvIO9iuUQ3DqDBAG 1mP1aMZATJKSbWxcGC700o0lAfJ1U6MTCGwxnhxm0w7Z+xHCq87jqONL7cI4daFyeqfE 6wsqMwnGTZ2vxR3MP1N3govX8Y5anW2vGWfhWpZJaZYNoctqdGoGgkqh3MIsy10sdubY X3uSrzk5dGovQLWQgcey1wITSH5sfmZVZVmOMylvGeZRV8mOcp5CaZLitdZZ0flFqRoR WiLxww/Q8BxKPUyRyKnnTcyXonKmfQxI2g1L3Pa1f0nc80CMJuYX8rMx5LD06S0wmnMP nGAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fyAAAwes; 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 o1si3767189pld.315.2017.08.18.04.27.16; Fri, 18 Aug 2017 04:27:16 -0700 (PDT) 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=fyAAAwes; 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 S1752029AbdHRL1O (ORCPT + 26 others); Fri, 18 Aug 2017 07:27:14 -0400 Received: from mail-wr0-f174.google.com ([209.85.128.174]:35799 "EHLO mail-wr0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751892AbdHRL1J (ORCPT ); Fri, 18 Aug 2017 07:27:09 -0400 Received: by mail-wr0-f174.google.com with SMTP id 49so58879998wrw.2 for ; Fri, 18 Aug 2017 04:27:09 -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=sFVtzTun5xTiJYGGxiun2ScLBv7r6A52dK4isjQD32I=; b=fyAAAwes2jRWmKqtL36vTtlqafyjIhd2PVauB/+8w6rImAM1MwUR40xWLU94dL5qDp q5vF5C/vhfjS1/jKE/YlMqLtM2s7WRd1coIIp7UPphPqKYvBKa2kiqPn/Ecw7GdUz/cf BDEB8llk2XiaSP9Ij6gzLYk1N6vfDxM+lX27U= 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=sFVtzTun5xTiJYGGxiun2ScLBv7r6A52dK4isjQD32I=; b=PUDwaJudJf3ISazs9V73LuyQOIcWAyrmezfc6hhP9+OqIJH5mQxWuyc8AZnqDSrqcV dJ6jsLP/JLw/qvsNegn5X9AngmiG0+V/UkQMYhNF+97z2cKcytvNeB3uVwOLhB6mk8RV pSnznNWo+PGnxaeJC/TU8/8tzPGaSKO3ZOSg+57nafUMLq2g0cFH2IBPXMboXv0xsD1E CZnQvwRsJ3fTgWVXAKEgfD12O51PFh9001sQSXzXi72QE080zT+W3W9l0CduiRXnKasY mCNEfm922VPgRYB4PC+zh2DaSL9u8wJhY/Vrdc2vSv6qMTZ+ZZ2KUJR+d9iL85Nn5ND2 Q6Eg== X-Gm-Message-State: AHYfb5hbZj3RzRWeMspn1bhfT966vXAql/rJ4js4Xwhj4PnUG4rK/o1X uMDUrlG0jhEfnoZ+qbXkeg== X-Received: by 10.28.236.67 with SMTP id k64mr1179002wmh.128.1503055628183; Fri, 18 Aug 2017 04:27:08 -0700 (PDT) Received: from localhost.localdomain ([154.146.161.128]) by smtp.gmail.com with ESMTPSA id f4sm1047111wmh.28.2017.08.18.04.27.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Aug 2017 04:27:07 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org Cc: Ard Biesheuvel , "H. Peter Anvin" , Arnd Bergmann , Heiko Carstens , Kees Cook , Will Deacon , Michael Ellerman , Thomas Garnier , Thomas Gleixner , "Serge E. Hallyn" , Bjorn Helgaas , Benjamin Herrenschmidt , Paul Mackerras , Catalin Marinas , Petr Mladek , Ingo Molnar , James Morris , Andrew Morton , Joe Perches , Nicolas Pitre , Steven Rostedt , Martin Schwidefsky , Sergey Senozhatsky , Linus Torvalds , Andy Whitcroft , Jessica Yu Subject: [PATCH v2 5/6] drivers: pci: add support for relative addressing in quirk tables Date: Fri, 18 Aug 2017 12:26:23 +0100 Message-Id: <20170818112624.24991-6-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170818112624.24991-1-ard.biesheuvel@linaro.org> References: <20170818112624.24991-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) Cc: Bjorn Helgaas Signed-off-by: Ard Biesheuvel --- drivers/pci/quirks.c | 6 ++-- include/linux/pci.h | 32 ++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) -- 2.11.0 diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index 6967c6b4cf6b..0a7ba8c7f1f6 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -3547,9 +3547,9 @@ 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); + calltime = fixup_debug_start(dev, pci_fixup_hook(f)); + pci_fixup_hook(f)(dev); + fixup_debug_report(dev, calltime, pci_fixup_hook(f)); } } diff --git a/include/linux/pci.h b/include/linux/pci.h index a75c13673852..58eb4e7a15c3 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1735,7 +1735,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 + int hook_offset; +#else void (*hook)(struct pci_dev *dev); +#endif }; enum pci_fixup_pass { @@ -1749,6 +1753,27 @@ 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) + +static inline +void (*pci_fixup_hook(const struct pci_fixup *f))(struct pci_dev *) +{ + return (void *)((unsigned long)&f->hook_offset + f->hook_offset); +} +#else /* Anonymous variables would be nice... */ #define DECLARE_PCI_FIXUP_SECTION(section, name, vendor, device, class, \ class_shift, hook) \ @@ -1756,6 +1781,13 @@ enum pci_fixup_pass { __attribute__((__section__(#section), aligned((sizeof(void *))))) \ = { vendor, device, class, class_shift, hook }; +static inline +void (*pci_fixup_hook(const struct pci_fixup *f))(struct pci_dev *) +{ + return f->hook; +} +#endif + #define DECLARE_PCI_FIXUP_CLASS_EARLY(vendor, device, class, \ class_shift, hook) \ DECLARE_PCI_FIXUP_SECTION(.pci_fixup_early, \