From patchwork Mon Dec 25 20:54:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 122706 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp226369qgn; Mon, 25 Dec 2017 12:56:34 -0800 (PST) X-Google-Smtp-Source: ACJfBovbJxYvNhWWW3+NteffkFv2ofv4HFvsJ6VZXYShYT4KmlQHvWQN6lBn8UD+NRg4sSDAS4/i X-Received: by 10.99.62.133 with SMTP id l127mr20480560pga.41.1514235394811; Mon, 25 Dec 2017 12:56:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514235394; cv=none; d=google.com; s=arc-20160816; b=Gg7gphC9RhoL4zyeo1/73ZdtVQDd3iy6kB5Y4KiHu0/trF8ElbpGPU6m0RFtMbWbC9 HTocXOVX6tPiibAgZ/4/cs7LsuYAURD3pArasPuPCqePqbRev/wAi0jyoHHDUAtqufEa f3xPVzbJFKePZ11xV8lQs2k1lRFCJqjttkBj/T4nriR/04Bbmn4lud6q4j4CoZkMhf2Y NBBpM7IFbHDnskBLP2LLjdn1qq2Ue3dKvUa0trUFClJE80V1oSlt2EFxM8BRMI7Jd92O o05OadXeJR+ukMncdrOQgbrsQMWtSQyMAfcHPk1K6+PLbHnKAU22GdzLuyATHFvEc/hQ X4gQ== 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=MNuvKMvZr3GVfTz4MvnzswRbek+xsbzeG112C9Cor2w=; b=ujNTlGUD9VvKQSTB2Zsgw1PVBGl5QUyzN7jdukhXRSanYH8WIz5jlhUSpE9l6MnHno 4kiVJ5oWBHOElA+mShzP5tXymqWNOnYWdIlkk5G4xmTJj6lkKWy8mW7d1CMxSdbSOqw5 L7WgnEVtrTpt82/BsLnbMI1dBOp+Hwrtg/MT6GUBTFKBvQlg7/5eZQRPYsbfOUgwONs6 knMub298X1AL0+dNnqSDqtlYeo10Bb4XWOOlFoc6QKArraObO4lmlKqnBSMc+pNy52cy HBUOsr2z/paAh9k1f9Uyl4M2GTheDG638y/dq/OXni+GFcvdfVsbu/hsjw3uQIflp4un KguA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BMyTz7wp; 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 t24si19536666pgv.106.2017.12.25.12.56.34; Mon, 25 Dec 2017 12:56:34 -0800 (PST) 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=BMyTz7wp; 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 S1753307AbdLYUzt (ORCPT + 28 others); Mon, 25 Dec 2017 15:55:49 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:46275 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753235AbdLYUzf (ORCPT ); Mon, 25 Dec 2017 15:55:35 -0500 Received: by mail-wm0-f65.google.com with SMTP id r78so33010112wme.5 for ; Mon, 25 Dec 2017 12:55:35 -0800 (PST) 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=MNuvKMvZr3GVfTz4MvnzswRbek+xsbzeG112C9Cor2w=; b=BMyTz7wp+Fxi1An3WUb91pRiOr+As7YcLQ8dArfHH7VtK2l4fc4Q3OOhL1nUxsLzhY KktWHlX+oWyjSJ3k1LQBpLpOIOsvMCPm+09fRDyD0xkV4StB6nNg1EUEWFpX6FmjYupi FamwgJg598YU7xHeL8gkuXiyPYyWKDrKfX6ro= 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=MNuvKMvZr3GVfTz4MvnzswRbek+xsbzeG112C9Cor2w=; b=iMSqFWd8n8kXxM30T9PzL9DODjhA5lVV3C0yQCJ3XdLdxwhxoVHN+LfWry3NKwgkyW mPQMu8fMOpsFxilext3C5+gceVccC91zvj8p/OFH9h6Y1RDh11x84o6Z0SDW2sKBTcbq VK9QaF9lHlBEolXInfjPGKoM5GQewgoGPgJ6463rpX6yNDQgZeJ+219GmzvDpJpOrTq5 C+naQq4vYa6i77brP043lvayEkSD0xEOYwSOxqW0eHtPi/WHktZgO0hHRRR3pIY+pxmG jHOGWjqPnaKJPqLLTLo6K3EmkpzdmgwoQ90QFfHhFnf9vlMrIT6dWiM3ib6mNOYjzITA Z7tA== X-Gm-Message-State: AKGB3mLythDjOwL4ZmhtbDfNhuGtny7Z1PaM8pMgCVaqdVYIgeNrWQWX +K2Bdb3m6cXvFpD1+q6dLYOTqdoJYYY= X-Received: by 10.28.9.146 with SMTP id 140mr22114484wmj.117.1514235334349; Mon, 25 Dec 2017 12:55:34 -0800 (PST) Received: from localhost.localdomain ([160.171.216.245]) by smtp.gmail.com with ESMTPSA id y42sm39552441wrc.96.2017.12.25.12.55.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Dec 2017 12:55:33 -0800 (PST) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , "H. Peter Anvin" , Ralf Baechle , Arnd Bergmann , Heiko Carstens , Kees Cook , Will Deacon , Michael Ellerman , Thomas Garnier , Thomas Gleixner , "Serge E. Hallyn" , Bjorn Helgaas , Benjamin Herrenschmidt , Russell King , Paul Mackerras , Catalin Marinas , "David S. Miller" , Petr Mladek , Ingo Molnar , James Morris , Andrew Morton , Nicolas Pitre , Josh Poimboeuf , Steven Rostedt , Martin Schwidefsky , Sergey Senozhatsky , Linus Torvalds , Jessica Yu , linux-arm-kernel@lists.infradead.org, linux-mips@linux-mips.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, x86@kernel.org Subject: [PATCH v5 4/8] PCI: Add support for relative addressing in quirk tables Date: Mon, 25 Dec 2017 20:54:36 +0000 Message-Id: <20171225205440.14575-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171225205440.14575-1-ard.biesheuvel@linaro.org> References: <20171225205440.14575-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 | 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 10684b17d0bd..b6d51b4d5ce1 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -3556,9 +3556,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 c170c9250c8b..e8c34afb5d4a 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1792,7 +1792,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 { @@ -1806,12 +1810,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) \