[{"id":1773106,"web_url":"http://patchwork.ozlabs.org/comment/1773106/","msgid":"<20170921210312.GK22312@bhelgaas-glaptop.roam.corp.google.com>","list_archive_url":null,"date":"2017-09-21T21:03:13","subject":"Re: [PATCH v4 4/5] drivers: pci: add support for relative addressing\n\tin quirk tables","submitter":{"id":67298,"url":"http://patchwork.ozlabs.org/api/people/67298/","name":"Bjorn Helgaas","email":"helgaas@kernel.org"},"content":"[+cc linux-pci]\n\nYou copied LKML on some previous versions, but not this one.  Seems\nlike that would be useful.\n\nPlease adjust the subject line of this one so it matches the typical\nones for this file, e.g.,\n\n  PCI: Add support for relative addressing in quirk tables\n\nOn Wed, Sep 20, 2017 at 12:57:20PM -0700, Ard Biesheuvel wrote:\n> Allow the PCI quirk tables to be emitted in a way that avoids absolute\n> references to the hook functions. This reduces the size of the entries,\n> and, more importantly, makes them invariant under runtime relocation\n> (e.g., for KASLR)\n> \n> Cc: Bjorn Helgaas <bhelgaas@google.com>\n> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>\n\nAcked-by: Bjorn Helgaas <bhelgaas@google.com>\n\nThis really uglifies the code (and initcall_from_entry() in the other\npatch makes my head hurt), but I don't have any cleaner implementation\nideas, and it does seem like a worthwhile space optimization.\n\n> ---\n>  drivers/pci/quirks.c | 13 ++++++++++---\n>  include/linux/pci.h  | 20 ++++++++++++++++++++\n>  2 files changed, 30 insertions(+), 3 deletions(-)\n> \n> diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c\n> index a4d33619a7bb..82a66235d60c 100644\n> --- a/drivers/pci/quirks.c\n> +++ b/drivers/pci/quirks.c\n> @@ -3548,9 +3548,16 @@ static void pci_do_fixups(struct pci_dev *dev, struct pci_fixup *f,\n>  \t\t     f->vendor == (u16) PCI_ANY_ID) &&\n>  \t\t    (f->device == dev->device ||\n>  \t\t     f->device == (u16) PCI_ANY_ID)) {\n> -\t\t\tcalltime = fixup_debug_start(dev, f->hook);\n> -\t\t\tf->hook(dev);\n> -\t\t\tfixup_debug_report(dev, calltime, f->hook);\n> +\t\t\tvoid (*hook)(struct pci_dev *dev);\n> +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS\n> +\t\t\thook = (void *)((unsigned long)&f->hook_offset +\n> +\t\t\t\t\tf->hook_offset);\n> +#else\n> +\t\t\thook = f->hook;\n> +#endif\n> +\t\t\tcalltime = fixup_debug_start(dev, hook);\n> +\t\t\thook(dev);\n> +\t\t\tfixup_debug_report(dev, calltime, hook);\n>  \t\t}\n>  }\n>  \n> diff --git a/include/linux/pci.h b/include/linux/pci.h\n> index f68c58a93dd0..d7a01d7fc3a7 100644\n> --- a/include/linux/pci.h\n> +++ b/include/linux/pci.h\n> @@ -1791,7 +1791,11 @@ struct pci_fixup {\n>  \tu16 device;\t\t/* You can use PCI_ANY_ID here of course */\n>  \tu32 class;\t\t/* You can use PCI_ANY_ID here too */\n>  \tunsigned int class_shift;\t/* should be 0, 8, 16 */\n> +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS\n> +\tsigned int hook_offset;\n> +#else\n>  \tvoid (*hook)(struct pci_dev *dev);\n> +#endif\n>  };\n>  \n>  enum pci_fixup_pass {\n> @@ -1805,12 +1809,28 @@ enum pci_fixup_pass {\n>  \tpci_fixup_suspend_late,\t/* pci_device_suspend_late() */\n>  };\n>  \n> +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS\n> +#define __DECLARE_PCI_FIXUP_SECTION(sec, name, vendor, device, class,\t\\\n> +\t\t\t\t    class_shift, hook)\t\t\t\\\n> +\t__ADDRESSABLE(hook)\t\t\t\t\t\t\\\n> +\tasm(\".section \"\t#sec \", \\\"a\\\"\t\t\t\t\\n\"\t\\\n> +\t    \".balign\t16\t\t\t\t\t\\n\"\t\\\n> +\t    \".short \"\t#vendor \", \" #device \"\t\t\t\\n\"\t\\\n> +\t    \".long \"\t#class \", \" #class_shift \"\t\t\\n\"\t\\\n> +\t    \".long \"\tVMLINUX_SYMBOL_STR(hook) \" - .\t\t\\n\"\t\\\n> +\t    \".previous\t\t\t\t\t\t\\n\");\n> +#define DECLARE_PCI_FIXUP_SECTION(sec, name, vendor, device, class,\t\\\n> +\t\t\t\t  class_shift, hook)\t\t\t\\\n> +\t__DECLARE_PCI_FIXUP_SECTION(sec, name, vendor, device, class,\t\\\n> +\t\t\t\t  class_shift, hook)\n> +#else\n>  /* Anonymous variables would be nice... */\n>  #define DECLARE_PCI_FIXUP_SECTION(section, name, vendor, device, class,\t\\\n>  \t\t\t\t  class_shift, hook)\t\t\t\\\n>  \tstatic const struct pci_fixup __PASTE(__pci_fixup_##name,__LINE__) __used\t\\\n>  \t__attribute__((__section__(#section), aligned((sizeof(void *)))))    \\\n>  \t\t= { vendor, device, class, class_shift, hook };\n> +#endif\n>  \n>  #define DECLARE_PCI_FIXUP_CLASS_EARLY(vendor, device, class,\t\t\\\n>  \t\t\t\t\t class_shift, hook)\t\t\\\n> -- \n> 2.11.0\n> \n> \n> _______________________________________________\n> linux-arm-kernel mailing list\n> linux-arm-kernel@lists.infradead.org\n> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel","headers":{"Return-Path":"<linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org>","X-Original-To":"incoming-imx@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming-imx@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=lists.infradead.org\n\t(client-ip=65.50.211.133; helo=bombadil.infradead.org;\n\tenvelope-from=linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (2048-bit key;\n\tunprotected) header.d=lists.infradead.org\n\theader.i=@lists.infradead.org\n\theader.b=\"KRCXvtUK\"; dkim-atps=neutral","mail.kernel.org;\n\tdmarc=none (p=none dis=none) header.from=kernel.org","mail.kernel.org;\n\tspf=none smtp.mailfrom=helgaas@kernel.org"],"Received":["from bombadil.infradead.org (bombadil.infradead.org\n\t[65.50.211.133])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xypxY166Gz9s7B\n\tfor <incoming-imx@patchwork.ozlabs.org>;\n\tFri, 22 Sep 2017 07:03:45 +1000 (AEST)","from localhost ([127.0.0.1] helo=bombadil.infradead.org)\n\tby bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux))\n\tid 1dv8dH-0001Nz-VS; Thu, 21 Sep 2017 21:03:39 +0000","from mail.kernel.org ([198.145.29.99])\n\tby bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux))\n\tid 1dv8dE-0001L1-9j for linux-arm-kernel@lists.infradead.org;\n\tThu, 21 Sep 2017 21:03:38 +0000","from localhost (unknown [64.22.249.253])\n\t(using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits))\n\t(No client certificate requested)\n\tby mail.kernel.org (Postfix) with ESMTPSA id 58FE721EA8;\n\tThu, 21 Sep 2017 21:03:14 +0000 (UTC)"],"DKIM-Signature":"v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=lists.infradead.org; s=bombadil.20170209; h=Sender:\n\tContent-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post:\n\tList-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:\n\tMessage-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description:\n\tResent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:\n\tList-Owner; bh=iOY++0LeZ7XU1AcFejXGEwXhEtHo7fkclGRsDfYGojY=;\n\tb=KRCXvtUK4bb4ci\n\tmDTK4Ht6KuKNBHsVBukJREqn67AisyE7W32xWOk2WFeByb2J7pNb7BXhioxLvabaCbXInO4pHsNU1\n\tgfI5qkFbqkGS53k5Mf2Z0wIxkyvzBhB2MfMU0TsNhtTlf2LZ0ApA4hL3uVXTKhUNlw0ZQ0c0PeuYW\n\tWgFQnacxvHNTW1YQNgjxlUi0El28QOa102/VMLIdu8F7fN4MMxWziEkg8P2fYXiuzK4tL5SOOIlym\n\tm6mCnb1m1kicjqQL3XjN9VDGpVfn5kkuas2APfjLqAqxkLiUpEDp6dOMEtUzJZur5HxYkGuxOtRVz\n\tJbOM2Cn4NkRAUQxTMCDA==;","DMARC-Filter":"OpenDMARC Filter v1.3.2 mail.kernel.org 58FE721EA8","Date":"Thu, 21 Sep 2017 16:03:13 -0500","From":"Bjorn Helgaas <helgaas@kernel.org>","To":"Ard Biesheuvel <ard.biesheuvel@linaro.org>","Subject":"Re: [PATCH v4 4/5] drivers: pci: add support for relative addressing\n\tin quirk tables","Message-ID":"<20170921210312.GK22312@bhelgaas-glaptop.roam.corp.google.com>","References":"<20170920195721.7939-1-ard.biesheuvel@linaro.org>\n\t<20170920195721.7939-5-ard.biesheuvel@linaro.org>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20170920195721.7939-5-ard.biesheuvel@linaro.org>","User-Agent":"Mutt/1.5.21 (2010-09-15)","X-CRM114-Version":"20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 ","X-CRM114-CacheID":"sfid-20170921_140336_401433_12DCF54C ","X-CRM114-Status":"GOOD (  20.20  )","X-Spam-Score":"-6.9 (------)","X-Spam-Report":"SpamAssassin version 3.4.1 on bombadil.infradead.org summary:\n\tContent analysis details:   (-6.9 points)\n\tpts rule name              description\n\t---- ----------------------\n\t--------------------------------------------------\n\t-5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/,\n\thigh trust [198.145.29.99 listed in list.dnswl.org]\n\t-0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay\n\tdomain\n\t-1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%\n\t[score: 0.0000]","X-BeenThere":"linux-arm-kernel@lists.infradead.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Unsubscribe":"<http://lists.infradead.org/mailman/options/linux-arm-kernel>,\n\t<mailto:linux-arm-kernel-request@lists.infradead.org?subject=unsubscribe>","List-Archive":"<http://lists.infradead.org/pipermail/linux-arm-kernel/>","List-Post":"<mailto:linux-arm-kernel@lists.infradead.org>","List-Help":"<mailto:linux-arm-kernel-request@lists.infradead.org?subject=help>","List-Subscribe":"<http://lists.infradead.org/mailman/listinfo/linux-arm-kernel>,\n\t<mailto:linux-arm-kernel-request@lists.infradead.org?subject=subscribe>","Cc":"Catalin Marinas <catalin.marinas@arm.com>,\n\tHeiko Carstens <heiko.carstens@de.ibm.com>,\n\tPaul Mackerras <paulus@samba.org>, \n\t\"H. Peter Anvin\" <hpa@zytor.com>, Nicolas Pitre <nico@linaro.org>,\n\tMichael Ellerman <mpe@ellerman.id.au>, Ingo Molnar <mingo@redhat.com>,\n\tBenjamin Herrenschmidt <benh@kernel.crashing.org>,\n\t\"Serge E. Hallyn\" <serge@hallyn.com>, Petr Mladek <pmladek@suse.com>, \n\tKees Cook <keescook@chromium.org>, Arnd Bergmann <arnd@arndb.de>,\n\tWill Deacon <will.deacon@arm.com>, Steven Rostedt <rostedt@goodmis.org>, \n\tJames Morris <james.l.morris@oracle.com>,\n\tBjorn Helgaas <bhelgaas@google.com>, \n\tThomas Gleixner <tglx@linutronix.de>,\n\tlinux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org,\n\tSergey Senozhatsky <sergey.senozhatsky@gmail.com>, \n\tJessica Yu <jeyu@kernel.org>,\n\tMartin Schwidefsky <schwidefsky@de.ibm.com>, \n\tAndrew Morton <akpm@linux-foundation.org>,\n\tLinus Torvalds <torvalds@linux-foundation.org>,\n\tThomas Garnier <thgarnie@google.com>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Sender":"\"linux-arm-kernel\" <linux-arm-kernel-bounces@lists.infradead.org>","Errors-To":"linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org","List-Id":"linux-imx-kernel.lists.patchwork.ozlabs.org"}}]