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: 131345 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp3055630lja; Sun, 11 Mar 2018 05:39:23 -0700 (PDT) X-Google-Smtp-Source: AG47ELv08+5ObQsSsBkYOoSUDMDgETwb4XBrfcRAuGaxV3XWkscj4DjIODEiWdZc17bBUA0zO9V7 X-Received: by 2002:a17:902:7088:: with SMTP id z8-v6mr4835200plk.174.1520771963742; Sun, 11 Mar 2018 05:39:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520771963; cv=none; d=google.com; s=arc-20160816; b=t2OyWDnneZc51bfh4w/ABQ8D0e0316xgSe4a/LP6u1Bm5X2riNxwTOC6dCoGx/30j6 ZeM+J/ZA85k0wSuCOxxVGI+fg68I2mD41Gt5fL5kvWgPSrADfasAEZ6m9n1cyQZP7Jj1 SAizMiRNQWXAvOLfZ58F7jZMV0DkLmHLvvrURJ3JXrisr1ejp2Pm1dspfukfVrZ2DWYA UjZPgpUixc6FJBf0llqQe2ywMIQbxUx/zgWpZC2OP0Rggh2uOBb0h08BswCcF7RLfyhz eZZhHaDNDyFNmCjLb2QMuBT7vqdbvbtXUQDgeu4yfbm6y0gMxtgeIsOpAiirZfCMF16a LDZw== 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=72OAPI9Kvt1iwKA3RSKe8xgQu1XKCUkEMrG/Hji532U=; b=xi4n4YLsp2SxG9HBtEI92Sxzzr63AloMpj234MzmHX27qPZP/3MjQXjvJusl24LS6O RWFj0sqXPWcD/5Qous6MjrZix9ZePO6teZp7zbelv0sxqbQ5xtHy5ndxOO073ypqgI/Q XS70y/8YT6UhObvrMVZB5CuHAJ2B4G8l6RPBw+QTLavtkJbFXbEP3HvwWssx5l/fZolq 6PBzNPNYSWaSmhgFumS6vQB5v59CWOYXQQGacNHx9KAdlUgTKnrafyiLRZkjxTWX301D ycrHffjj8TMfMsZhwcDWHKBQBDV5l0z8lPheAidOASWt65iQAhXEJY2/hkeYuKIgkPov kZLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DXVoHVls; 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 x3-v6si1385175plw.269.2018.03.11.05.39.23; Sun, 11 Mar 2018 05:39:23 -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=DXVoHVls; 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 S932295AbeCKMjS (ORCPT + 28 others); Sun, 11 Mar 2018 08:39:18 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:33120 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932126AbeCKMjP (ORCPT ); Sun, 11 Mar 2018 08:39:15 -0400 Received: by mail-wm0-f65.google.com with SMTP id s206so9520413wme.0 for ; Sun, 11 Mar 2018 05:39: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=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=maaJoAK+nEoHAZh7XnCkt/rSgyLFCvC8/a4vOn1Wqomb3Fx8jh+YRKc8h0efVQJtOw fjOySfovZdLVd7UOYcNNRDoCfvYefoVkZEjJrrjgfnhCZ5RFjDocMZmAar2sFYo/lnZF n3pZlewPc79XQMQIsZSybRgD6Zw97Ixvw+fHL83B5OJQ4Zj2YGe9dz8iUcaa9UgOaI5O PMfnsWIw9X2pV21pykfFlajvCm1wU7XqrRZrJ0/6jAIvRSpHqLJrCAfJpKmL6eh7+NYw Ctxv+T2lIl3nRiHJ3sZHM23T/el0jeqoWzvfFc4IbE65vs/zByIb/JxSTZnb+ZMvM4bH IwHA== X-Gm-Message-State: AElRT7Hm7CMwutzBh0EzdmUy0rcgfT+a9dtfTKyLSTM2bR8+MIvKuBs/ rGMFUi+naWQWMju/HlkWDkvEdQ== 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 Cc: Ard Biesheuvel , Arnd Bergmann , Kees Cook , Will Deacon , Michael Ellerman , Thomas Garnier , Thomas Gleixner , "Serge E. Hallyn" , Bjorn Helgaas , Benjamin Herrenschmidt , Russell King , Paul Mackerras , Catalin Marinas , Petr Mladek , Ingo Molnar , James Morris , Andrew Morton , Nicolas Pitre , Josh Poimboeuf , Steven Rostedt , Sergey Senozhatsky , Linus Torvalds , Jessica Yu , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.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> 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 | 12 +++++++++--- include/linux/pci.h | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) -- 2.15.1 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) \