From patchwork Mon Aug 14 10:52:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 109980 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp4170655qge; Mon, 14 Aug 2017 03:53:30 -0700 (PDT) X-Received: by 10.99.3.197 with SMTP id 188mr24556772pgd.288.1502708010541; Mon, 14 Aug 2017 03:53:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502708010; cv=none; d=google.com; s=arc-20160816; b=ezOm98M+AyC4VFVpgX0zNURQmxXkueJ30BmueI0kUUwYzzQKsnahH9d3I29JBTIcJi dC6RcCLOGGODvp3OOnI1p7aDDg9HLniXGKMwY7tkiZ/li5qkXEFSIx6OS8DWjui/z3hF 82gPlI2TvsbQgwrOIOaCxAWAensY8+9fh3I+/J7jMjusz92uzqEbdbVSyjvuFWkULerz ZIBsw2sSY4wEFPcfkrxMcUdJniJHYO48V16wMG3qfh2vgCnkj0CTRP+UtUHbZBXYErzA cQ840AlvWK3Jwen23mKBKVhzHm4N4gMm23ZZDYMMsH7Pc79h32eV9MMGzarNMCADWoD9 5YOw== 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=T1/I/dl/glTN9Fw6FNXgw+ZEb6RKfMBrOWi+jqpuGSk=; b=jFMOSrhGTb2mdPW6Nzzb7zxBkIFFYUHaZU49H9m5KiJw1vsMZ7KE0LTM7dDNf7bGz7 eTuhG6yPivO2h97Sr2qOY5EnrLIMSOJ+83byd+aAcPQHP5isddEO7Qwr594lUkDtTtlY TqL9Q0F8UGJU09GRFU+I9YrovtvUqfayQbtWiAntSQ1ps8RFEGR5tpy/SZK/hcqiJ6lI 5q+Me7yGp0M15R+kQ2vspUgmFAJMIIFxaQ4SRHJCceVF5ykCW80Byjr6z5AYK9UGtS/K Zn2MfLiLGthpxQoXX+EE16bx+CQyPdLGf9z85TnQtVD0XePej10bRdJXjGhFLhM6r3l8 ynCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UQiV3kye; 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 z19si3910380pgn.611.2017.08.14.03.53.30; Mon, 14 Aug 2017 03:53:30 -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=UQiV3kye; 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 S1753040AbdHNKx0 (ORCPT + 25 others); Mon, 14 Aug 2017 06:53:26 -0400 Received: from mail-wm0-f49.google.com ([74.125.82.49]:37705 "EHLO mail-wm0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752986AbdHNKxW (ORCPT ); Mon, 14 Aug 2017 06:53:22 -0400 Received: by mail-wm0-f49.google.com with SMTP id i66so40651378wmg.0 for ; Mon, 14 Aug 2017 03:53:21 -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=T1/I/dl/glTN9Fw6FNXgw+ZEb6RKfMBrOWi+jqpuGSk=; b=UQiV3kye6z5oVA5oXcF9E+jxs/FpJERXRBEwO75LSG2KjNyCe8IYxKGaSTqTtlbm8Z Chv+7wrWPAhRcQQGS/b4oL9InG4duhYLG+FW1Ez+HROKvxTPJhT+hfbwBiRV4Q7b6Bn/ 0Qs40c304jQSiXZUBo4MXz3hej96feeC0dQ3E= 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=T1/I/dl/glTN9Fw6FNXgw+ZEb6RKfMBrOWi+jqpuGSk=; b=ulVY8DeK9e35QDyoywAtxagM7PQgtCyCIL0jXe50VsR5+Z+bPEuRJKSKaYeqD47iav SqrHflFHT2jTWpdjHI922If0/KZ9PzFMJq+TpQmcD357CQCy53U1JSLf/5CUwH5utIB0 rwfiqymQn+CunjtAKN6VPXVrdBjWuiDhh5XDDUk7XX0jkw7LiaSvH9oRCstozuTuDBwE PqP6H1ZmBOIERbywNePFnbsA0u+u2b0hMY/a8C5ZDnpoEe6Q/av7YAsaIir8jPJRz6+K usNxTDDrWhpfAlN7yFaG8Ofk/bc6Vjue8Ab6asWQ3NdjodRM4UywyxjhjvW66RJB2dvE YMLA== X-Gm-Message-State: AHYfb5hbsB3HLChLo/IUvhBIJy7rTczvf/v1jl+4Zi6JT9o+/pe7Q3x4 Y1/q4jfQq2lzRP3rFtjW4Q== X-Received: by 10.28.13.78 with SMTP id 75mr3584753wmn.11.1502708000547; Mon, 14 Aug 2017 03:53:20 -0700 (PDT) Received: from localhost.localdomain ([154.146.161.128]) by smtp.gmail.com with ESMTPSA id b15sm1490732wra.68.2017.08.14.03.53.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Aug 2017 03:53:19 -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 , Jessica Yu Subject: [PATCH 4/5] drivers: pci: add support for relative addressing in quirk tables Date: Mon, 14 Aug 2017 11:52:30 +0100 Message-Id: <20170814105231.14608-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170814105231.14608-1-ard.biesheuvel@linaro.org> References: <20170814105231.14608-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 4869e66dd659..203544f33345 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1734,7 +1734,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 { @@ -1748,12 +1752,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) \