From patchwork Tue Jun 26 18:28:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 140075 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp5573165lji; Tue, 26 Jun 2018 11:29:16 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIcy4KjQcLh2A/ie+kDiMt+MKAp45L7iHXbDW9Owt48oGJCxAXqaaCPu91opEDvdVbYLX9p X-Received: by 2002:a17:902:650c:: with SMTP id b12-v6mr2747900plk.31.1530037756535; Tue, 26 Jun 2018 11:29:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530037756; cv=none; d=google.com; s=arc-20160816; b=ZgP0CX/lCqx2fzJmWNQK5guAPOmeHD3naywRrvqhI+eUwWSmg1sQA/9QMF3tPOisq5 b1uBWv1sGCjXJLaUXRq6l0Y24YmyRhzVB1Z7x5tBzbH1gYmjZJAH4MYN5pU8w/6/C9ms tAEvSNF71UrP1ysAUU+/Y/pJVIf/kiaT2M4j10k87dKhC39QSGelBa6PotGaud40eLAt 6mUHj5DxfH1bwtS1TgHFeigem+YDkPb6wqcXmPZ8LEpI962D+Nr+CAMSnsn152RpL3Vj mUPnnj3rBLvcg8p/IKWkXLjXrlllRwHYi6MKEpxXkOgh2UB4hLpe1AP70gq9AM1a5jtk FyFQ== 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=7rtDqZRn08p6IrU2qqSvkpaXuaNX+BLXDAxvrNGfhOo=; b=K71aV8KRYW4O+5IxBIGfRitdRDIh/4Q4hbyMg2FwLnYlHU5Q2ulsF1jNVdU96WyG2I PP1BV5Y32UMkwk5JOMLX0leAKyAYFAWX+GfZe+Lobkc1zZQYf5ZADVGx47w7nFD7vEtb BWrhbTW1jjSwkUSklcf06ypI89CBNFtWZTLR1KFuJdrnHAIBvwJ98GM2vrIjgOGqJ5g/ tpAFWlK8Rb3kh1OLfONQhDOmUziEVtssKdK1mdhf67FKeLbavVAyKnrOf4Ohz5NCoOSM qxcQo5I+BHVOd+CkdUEVcS8bYccY96f1I6o4boEVwk16S1QfUswHtZLU4Z5SPn5bOpni /ipg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EjRpK3hS; 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 d11-v6si1833023pgn.563.2018.06.26.11.29.16; Tue, 26 Jun 2018 11:29: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=EjRpK3hS; 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 S934063AbeFZS3O (ORCPT + 31 others); Tue, 26 Jun 2018 14:29:14 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:43619 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752786AbeFZS2v (ORCPT ); Tue, 26 Jun 2018 14:28:51 -0400 Received: by mail-wr0-f193.google.com with SMTP id c5-v6so7056980wrs.10 for ; Tue, 26 Jun 2018 11:28:50 -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=7rtDqZRn08p6IrU2qqSvkpaXuaNX+BLXDAxvrNGfhOo=; b=EjRpK3hSgSPZ2IbhYyfsOubGNygDOsFKwCM0O9hlft6LOomb81jMgHZLG1WCI+dNvN vwGB/iCq21birz/AHBNXyBGsrgQ3lbnnHrZNJiAiEeBSCceRQxS55arQGPVFuWr7/Pbl NbboOjYq/dzf210TIurgGShTofSDL0QKmSEho= 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=7rtDqZRn08p6IrU2qqSvkpaXuaNX+BLXDAxvrNGfhOo=; b=am1TWE3DgI1tiLy7Bh18CSDaN8IIFJU9lBdnSks4lh2R9B1TnMkDn7nv9DX4gOxN4T Kni/Y52Jki6uZCF1hKmYwpfMTWSHVzRJL42JQBBxAHWDz5bXQiWSaTpCeZJKuy7HZAme V2XoyT9+Ruuf3gTPCeJO8Kv5Nl9E5s7/+TV0Dzrx35NpYxD8r5zQXLkZEfCFhECWVD29 Ddb7bf0PKUoJY+vRee3Fw8KF6ictIJCwbqHfKARt0Sip/HWuFvwke4/t5wAS5IUOKu2H iokZ45klytsFDKH4JLSBLYNJh47ceysHLNWqSzlWnGzroYW6VzgeHf5/0qvwYXGmRIcZ EyjA== X-Gm-Message-State: APt69E0gFlVc8yqpWGuQZDJtsWViSgyp2pBBIh7S6cM/ceCIG9mVAqY7 WOznHZIYUl/WHhuaq+RdmL72iEUCe/k= X-Received: by 2002:adf:8425:: with SMTP id 34-v6mr2402558wrf.72.1530037729483; Tue, 26 Jun 2018 11:28:49 -0700 (PDT) Received: from rev02.home ([2a01:cb1d:112:6f00:d037:e907:f0a2:a5ea]) by smtp.gmail.com with ESMTPSA id s17-v6sm1707664wmc.34.2018.06.26.11.28.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 11:28:48 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.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-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org Subject: [PATCH v9 5/6] PCI: Add support for relative addressing in quirk tables Date: Tue, 26 Jun 2018 20:28:00 +0200 Message-Id: <20180626182802.19932-6-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180626182802.19932-1-ard.biesheuvel@linaro.org> References: <20180626182802.19932-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.11.0 diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index f439de848658..0ba4e446e5db 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -64,9 +64,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 340029b2fb38..51baa3ab5195 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1795,7 +1795,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 { @@ -1809,12 +1813,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 " #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) \