From patchwork Tue Mar 24 13:10:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 228882 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DFECFC43331 for ; Tue, 24 Mar 2020 13:16:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B5B61208D5 for ; Tue, 24 Mar 2020 13:16:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585055771; bh=tPs/d+Yq2tr/hQqhWozEI/NNN0vW9ApNX+NdvUDSQK0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Yu2uxZ4YIKt9dm3z8kAJpAmbK7ei5r7VFpRir2gG/CE5/u159luWKG52VCePUAWo2 c74zFr6ZX7FmRTp8RgCcPzswAH+FsEVJli59EeegZ41/rSyycSD7GNBpoKJDvVzPoj S4uD+Cwsc8uBs9jRGNM2OEux9Jl8ubJ24SMTQYiI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728376AbgCXNQK (ORCPT ); Tue, 24 Mar 2020 09:16:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:35498 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727455AbgCXNQK (ORCPT ); Tue, 24 Mar 2020 09:16:10 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1FF5E20775; Tue, 24 Mar 2020 13:16:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585055769; bh=tPs/d+Yq2tr/hQqhWozEI/NNN0vW9ApNX+NdvUDSQK0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QGJLmnNkuwiXZ9v0JeHV+PV65bhfdaC+44xxnpXqu24SdAfW8R/C8LqEXV2cEmIyc SPtrmpBRnY7l4DzOjPs3DysEOFPqMXVqRVaH/UE4Mhfr2TEjiwnd2hpBBEJ5/rAzfa Lw26qqNskbdPh71D54V7lmGp6kRPihZp5SD4/IzE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vincent Chen , Alexandre Ghiti , Anup Patel , Carlos de Paula , Palmer Dabbelt , Sasha Levin Subject: [PATCH 5.4 023/102] riscv: avoid the PIC offset of static percpu data in module beyond 2G limits Date: Tue, 24 Mar 2020 14:10:15 +0100 Message-Id: <20200324130808.870718920@linuxfoundation.org> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200324130806.544601211@linuxfoundation.org> References: <20200324130806.544601211@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Vincent Chen [ Upstream commit 0cff8bff7af886af0923d5c91776cd51603e531f ] The compiler uses the PIC-relative method to access static variables instead of GOT when the code model is PIC. Therefore, the limitation of the access range from the instruction to the symbol address is +-2GB. Under this circumstance, the kernel cannot load a kernel module if this module has static per-CPU symbols declared by DEFINE_PER_CPU(). The reason is that kernel relocates the .data..percpu section of the kernel module to the end of kernel's .data..percpu. Hence, the distance between the per-CPU symbols and the instruction will exceed the 2GB limits. To solve this problem, the kernel should place the loaded module in the memory area [&_end-2G, VMALLOC_END]. Signed-off-by: Vincent Chen Suggested-by: Alexandre Ghiti Suggested-by: Anup Patel Tested-by: Alexandre Ghiti Tested-by: Carlos de Paula Signed-off-by: Palmer Dabbelt Signed-off-by: Sasha Levin --- arch/riscv/kernel/module.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c index 70bb94ae61c59..6bf5b16743843 100644 --- a/arch/riscv/kernel/module.c +++ b/arch/riscv/kernel/module.c @@ -8,6 +8,10 @@ #include #include #include +#include +#include +#include +#include static int apply_r_riscv_32_rela(struct module *me, u32 *location, Elf_Addr v) { @@ -386,3 +390,15 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab, return 0; } + +#if defined(CONFIG_MMU) && defined(CONFIG_64BIT) +#define VMALLOC_MODULE_START \ + max(PFN_ALIGN((unsigned long)&_end - SZ_2G), VMALLOC_START) +void *module_alloc(unsigned long size) +{ + return __vmalloc_node_range(size, 1, VMALLOC_MODULE_START, + VMALLOC_END, GFP_KERNEL, + PAGE_KERNEL_EXEC, 0, NUMA_NO_NODE, + __builtin_return_address(0)); +} +#endif