From patchwork Sat Aug 19 18:10:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 110460 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp2384170qge; Sat, 19 Aug 2017 11:11:46 -0700 (PDT) X-Received: by 10.98.36.93 with SMTP id r90mr6024251pfj.287.1503166306369; Sat, 19 Aug 2017 11:11:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503166306; cv=none; d=google.com; s=arc-20160816; b=p47Z+9815wBPn3X46Eu8EBnPh9Q5YdShs17gGvPQqywllFF2w3bJTKF1T6PhMQZCHE fqdov2zug7o/kkvCwPFM2/yoCR7u6juaqjS+y3WHZpryGOB4pcGJUC73BC2nrxit6ix7 Wrc2JfXZLZyCOJmW+icOcOloxa8gV93PZonSF6kUihe1uzkEjMHAxAALpxYLE7QFoCf+ 9TMcUoVYSncMi6CwsEstJLU5TBZGUnZffMJ+W8mrDo8l+Y2Y5KDhJ70l8M0G1uEBPOk6 jfkDM72acc7m3fgX+oI/hha5+7s4kCEPGyhZ4/9cNAhFYWD3x70NoxdEqdVMBbCAy8Ds 4BdA== 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=rYsb6llfpaqvuAGj2AHZ7qmMX4LU1ZUVfJ8j66knLjQ=; b=P/gy6Rj3Rf7/lxMMjfzCpBSDPUPKPmfRqIycsr8gQqNnVn7+iLc/f5JkEHbxsveA/H panubdvpjii6E7StoWuD7bxwYdTIm5PziMjcl84ai6HzxBJFiuXP+qCNJiXiUdG6sNfW lVcXGcU8eqYIanXOaaERq0gcaqCDBv00ciWns9e85HZfZQEgB3couCfH0miBQpnZOt+4 pSCUPR+KQ9XpSAn7WVTmqxQgIbyv7xjw4GImUKsQdSmsXFcL12+PL8MDs+Z2BQzoGxBz Q2E6bWvq53+umC2LVJJfsxOJXNC9QB+MjD749JzZABFpZh7YQQrCI6RKfb4COEFXbHsl 7X3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CJqicdWj; 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 g15si5626489pln.930.2017.08.19.11.11.46; Sat, 19 Aug 2017 11:11:46 -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=CJqicdWj; 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 S1752491AbdHSSLm (ORCPT + 26 others); Sat, 19 Aug 2017 14:11:42 -0400 Received: from mail-wm0-f44.google.com ([74.125.82.44]:34073 "EHLO mail-wm0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751853AbdHSSLP (ORCPT ); Sat, 19 Aug 2017 14:11:15 -0400 Received: by mail-wm0-f44.google.com with SMTP id c14so6538210wmh.1 for ; Sat, 19 Aug 2017 11:11:14 -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=rYsb6llfpaqvuAGj2AHZ7qmMX4LU1ZUVfJ8j66knLjQ=; b=CJqicdWjWDUAKxgiggFRpms2jK9xy42O7ZMZBszA7ykbw3mGwoPCu89xHmj44INc9G tjqbJkjwu0mrGfEUMlqVkvsEGGST5f+VsKqx8ZEbu+gt1/0mv5gVrimjdUeD6jT5/eGz RstgOCUKkr4f6ysNMFf8yDffYc1gn/NnEVSIE= 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=rYsb6llfpaqvuAGj2AHZ7qmMX4LU1ZUVfJ8j66knLjQ=; b=UroCwXOKYRWExHj4d0oUGUmvfQbsfqmuIzKoCbK8ghApFQf702IKt0p/6HPaS69JU+ eKi07ANofrZIbCDgt/2HAbRE1KS3BzLUiJOKFS2q3EE/PgWo7W6yUOhVHdNDTJJpqA0B zQg9ChrrusHx0IH9Aj3LRVVqGJfXJkvEDNU9hM7bvodEagjjg5Aqt5uq1ZXBpNze4V1V e9tQHjA7FUDJi/7qQP6tdTU0WjRXxQI1hbEZNyenkwNf1ZYPo3uU/sY0c4zVIxiZ8O/G 7VhVblgM8Z+ur4PEzIEXm1zown1HMJGy2WJgbxzO5xYYqtEXlsxC51phR+3sA/wjqSLp dUWQ== X-Gm-Message-State: AHYfb5jTdjm8TS4PUi8VIuai3OmmqLLF+QhyRt8irF+87Wqrs8Wc5ZY0 K/eGRwT2vtz8oLEhXtmGgw== X-Received: by 10.28.146.2 with SMTP id u2mr3255607wmd.76.1503166273754; Sat, 19 Aug 2017 11:11:13 -0700 (PDT) Received: from localhost.localdomain ([154.146.161.128]) by smtp.gmail.com with ESMTPSA id m127sm4056261wmm.46.2017.08.19.11.11.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 19 Aug 2017 11:11:13 -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 , Nicolas Pitre , Steven Rostedt , Martin Schwidefsky , Sergey Senozhatsky , Linus Torvalds , Jessica Yu Subject: [PATCH v3 4/5] drivers: pci: add support for relative addressing in quirk tables Date: Sat, 19 Aug 2017 19:10:34 +0100 Message-Id: <20170819181035.969-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170819181035.969-1-ard.biesheuvel@linaro.org> References: <20170819181035.969-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 | 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 6967c6b4cf6b..10126612e342 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -3547,9 +3547,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 a75c13673852..dd3523c1afbb 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 + signed int hook_offset; +#else void (*hook)(struct pci_dev *dev); +#endif }; enum pci_fixup_pass { @@ -1749,12 +1753,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) \