From patchwork Wed Jul 4 08:36:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 141023 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp543265ljj; Wed, 4 Jul 2018 01:41:16 -0700 (PDT) X-Google-Smtp-Source: AAOMgpefJv0BOy3Ytah5rTi5U3ved2NneLk76v66YZarHHZs4n2hLR93SF2JNgcV13l4zE+0Q9ef X-Received: by 2002:a63:1e08:: with SMTP id e8-v6mr1042242pge.281.1530693676452; Wed, 04 Jul 2018 01:41:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530693676; cv=none; d=google.com; s=arc-20160816; b=j4YRnmhSgXBRiPf4RU/2zqSU0mVHMzWLYnNySPyQQULMXPWVg9SKnLFx6fEl3VqSqb v1rTw+XJpntGHGx6OgsdCVTt2n8rXdKYd1V6ydpzaOiIZgBWQ7W2rSeiIo90H50mpnnK xkT7D+xXN/4MEqvx3hdcwdDhmmORroEpxgB6UH8XwBmgMurOIceu37VWfK0H6XblYoqX zdjEhdDwGk4Zmgl4BS3sSTb/s0+TOAFnEfoZ5BxqKUUg0igOo1gauFW/aKBLGsINQ7XS pqeslExUhP6HdSL4BNAdrTRLSr1TgvSk66OjmSExjTRkIVlwRAzRVgcNTNMSwv0TuzGY EPPg== 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=sqbAdR8mVhPUbhBZJ1W38BSLp0pkEn3sNHW4MKbPLbQ=; b=jwfGmONHX5hG7TL1AVKXhEd3xD3b/6GgmYkiziwOouHmsPrXup/plWPMuruIdDtMRQ O3gaXbHOy6TBboIrlACjcqj/EJtsQqYPUTuEEa5TH8dhlw/N56JMG0oSutlQJf52E7ki BNBBDO3EhRNlOz0fsK1xw9sdboAXz9slIjN/1xNPoi0RIJoJ5AF/4y03Bj/TeCd67zKi LqrG3GzV+A1Epaq225lNBZAES2mROynoGsB0ZsViZZJZSKCObGyb41OCEsasUTy1HD++ Hnmif+3IBnbRDqXLPWB1Q+8GOIT+YQJzIJN3BzsJQvM1ztz70mALUQkq+U3WORK0Qx3v 7z/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IDNcrj1N; 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 g92-v6si3135469plg.0.2018.07.04.01.41.16; Wed, 04 Jul 2018 01:41: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=IDNcrj1N; 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 S934129AbeGDIlM (ORCPT + 31 others); Wed, 4 Jul 2018 04:41:12 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:42218 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933653AbeGDIiz (ORCPT ); Wed, 4 Jul 2018 04:38:55 -0400 Received: by mail-ed1-f68.google.com with SMTP id g12-v6so3453102edi.9 for ; Wed, 04 Jul 2018 01:38:55 -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=sqbAdR8mVhPUbhBZJ1W38BSLp0pkEn3sNHW4MKbPLbQ=; b=IDNcrj1NlIQfgGHybPnbkoQiCFRN8HfZ/uGEfeoFAbZcFwUmSNtrr3SBeVTsgY/2q4 vA7HY38Uc/kmvDOwTlKRcAQl1tuXDYF+ZNH/IytTXD6s//FRTSj5JSW+gdEHE0xX9kNT xE3EfGwkeGYMaMfn4Qg1RFs0TgS9XKCnTI4Cg= 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=sqbAdR8mVhPUbhBZJ1W38BSLp0pkEn3sNHW4MKbPLbQ=; b=q4c2X8+OKjHZrE0uG5JrqPIaYP1qvTQ3OAi0ucK8+9LXJPGhZknHuRaSnKHfPYIO7Y LPCtNrhF4JSFmxTroeBZniZk0ELlYq6tj2+pOSSQcj5L/4e+Ly8bkdO64zj7eu5c6lIT rDW84csYcAjzit9kKn7M5ZDNss2MzMwjo5/mAsYK3LSC42rZf3GnQHRxtttKXG9LDphS 6UltMG5DSfaibA9ni5TS3tZF1LginglgQngZrWQlI6KHY3bDp8aLA81MQQlsFPEF75Ux awHGl+mP919vD70JqcGnXTo4+S9nPK7VOpYdS/XvqubqSzm1FWmC8Lm0DPKKX3Ibohpt f2pA== X-Gm-Message-State: APt69E2c4iA+np95IPkNLQGZ5/lxVQpgX1/2znwObv+RUrE8c94j8nDo H9ThVxMoWtG+RCU50V4K0NmfHfx4yb0= X-Received: by 2002:a50:ad0f:: with SMTP id y15-v6mr1715278edc.78.1530693534421; Wed, 04 Jul 2018 01:38:54 -0700 (PDT) Received: from ards-mac-mini.arnhem.chello.nl (dhcp-077-251-017-237.chello.nl. [77.251.17.237]) by smtp.gmail.com with ESMTPSA id k13-v6sm1821740edj.55.2018.07.04.01.38.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Jul 2018 01:38:53 -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 v10 5/6] PCI: Add support for relative addressing in quirk tables Date: Wed, 4 Jul 2018 10:36:50 +0200 Message-Id: <20180704083651.24360-6-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180704083651.24360-1-ard.biesheuvel@linaro.org> References: <20180704083651.24360-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 Acked-by: Michael Ellerman Acked-by: Ingo Molnar Signed-off-by: Ard Biesheuvel --- drivers/pci/quirks.c | 12 +++++++++--- include/linux/pci.h | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) -- 2.17.1 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) \