From patchwork Fri Feb 21 02:47:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Chen X-Patchwork-Id: 11395273 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4830F1395 for ; Fri, 21 Feb 2020 02:48:50 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 266BB24673 for ; Fri, 21 Feb 2020 02:48:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="tH4tcyb2"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="WqfOzVTg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 266BB24673 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:MIME-Version: Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=UCnRku7aM70HyAAc+r9OSumncSqlXmUg2yjLr43iIfs=; b=tH4tcyb2FFONaZ o0bsFAD1qP6Py+l7JAiGT581gtqvO1DNW9nHd7H8vohcHVVl4M3WyaG6Gor9f9P+O2f8LYiI2Ud0S OGCFOakbupn9xIc9SOaCyEN8gVV4j7AdARscQJBc6Si3ZGmi8wVriMPfFaHPOp/FV0oAZM3fEQN0y VJ8Ck77N6gg+ToCqSO6veI1cFWsPtxo5OHxkSw9OaWKq2YaFawQkfWbCi5k3pYipeKtWeRfbxZdFk gAleHDYLZXn5d4eNWXi1jzl7cZMhIHxH2m6kxAKCbr8JmBysumNjDrEWKB7e2A27YfeV2otqRQvJU 6o4XbQ69YUyLe36KbuDw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j4yMw-0006Ej-8v; Fri, 21 Feb 2020 02:48:46 +0000 Received: from mail-pj1-x1044.google.com ([2607:f8b0:4864:20::1044]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1j4yMt-0006EN-Jg for linux-riscv@lists.infradead.org; Fri, 21 Feb 2020 02:48:44 +0000 Received: by mail-pj1-x1044.google.com with SMTP id r67so88657pjb.0 for ; Thu, 20 Feb 2020 18:48:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UCnRku7aM70HyAAc+r9OSumncSqlXmUg2yjLr43iIfs=; b=WqfOzVTg9Hr8U2AMQVIYpiWGpvl0NuZJtcdMnVVdZukwHisxFfgl/QcidiFPpKSi8a ctr8INPH8KoRUl1c6FwxBJ025SvkX2OXQgckD1SrOQKGK1eeJmPH7kvckJlGUFgPG82/ X4aJzpf3HNSPQcZH84DzP82TDli2xFOp0etJMhIRIjwuG3Znee81OGzVdrc7dHuEBDmU bxs3y+IDmu150YVaSdDhoQ2Ry9Y8zzeyiPbionBTuzSb6HHVIZ4qgtClRxnXSgHeJ23j njadmrcP338wRJuurRluOdviLs8dykKrMKaz6tFcdRrTMdFir0PIbERNllaPJ4uvTEhR 9mWw== 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=UCnRku7aM70HyAAc+r9OSumncSqlXmUg2yjLr43iIfs=; b=UTsJrEWTn9rum6rqgX84Ih6OGN08IEkrozoyqHPVrx5DVx+sMbhz6PooglEnk2Ksdi RT7funi38AldhnKfC3123AysNeyt1mNaXveLldnZOINlSw6Pgj0g+UFS8mI+hYlsO4AX PxbpV8seRHm9I6YcL7l6OqcHnvLAINV2qZalzBVS1k18q0246d1LiGmjRguWlLEYjk7n J6fpCuA8lsnOxGMxduv+C3hx/1cUDtNmObEVufiAD+7gpzI1D8Q290isZKifcMH2P8yD fFnHCDm704usMUA7pFRwPMD5WZYj3g+a22qyWeCmTi3HK+PPK4Dy3dpAyPD0be+o4qCj s0TA== X-Gm-Message-State: APjAAAUcCdb8Aqdogv+KEbZUjzYDJtJ2wcP5O3nYn1Hn02q1+SGHF10k kk/pT9UvT+5pmQw5yL7dcxzVo9egVU2xbw== X-Google-Smtp-Source: APXvYqyOwtTFcyvCxpdLFTVvhSdfGFsynFwOuv3p310ZEa+KxrK0PB6ikVebOeeUNiwm+EHj8l8GWg== X-Received: by 2002:a17:902:61:: with SMTP id 88mr33906874pla.17.1582253322350; Thu, 20 Feb 2020 18:48:42 -0800 (PST) Received: from VincentChen-ThinkPad-T480s.internal.sifive.com (220-132-236-182.HINET-IP.hinet.net. [220.132.236.182]) by smtp.gmail.com with ESMTPSA id 28sm618810pgl.42.2020.02.20.18.48.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Feb 2020 18:48:41 -0800 (PST) From: Vincent Chen To: paul.walmsley@sifive.com, palmer@dabbelt.com Subject: [PATCH V2 1/2] riscv: avoid the PIC offset of static percpu data in module beyond 2G limits Date: Fri, 21 Feb 2020 10:47:54 +0800 Message-Id: <1582253275-28181-2-git-send-email-vincent.chen@sifive.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1582253275-28181-1-git-send-email-vincent.chen@sifive.com> References: <1582253275-28181-1-git-send-email-vincent.chen@sifive.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200220_184843_650419_CF8DB79C X-CRM114-Status: GOOD ( 12.23 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vincent Chen , linux-riscv@lists.infradead.org, deanbo422@gmail.com Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org 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 --- 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 b7401858d872..ef81a75b1302 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 From patchwork Fri Feb 21 02:47:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vincent Chen X-Patchwork-Id: 11395275 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9132A1395 for ; Fri, 21 Feb 2020 02:48:52 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6FF2824676 for ; Fri, 21 Feb 2020 02:48:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="mT5PpnJ4"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="foBMxyFq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6FF2824676 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7RE8yadqunBbRH3qS8QB++tHjtjwApk9t/HNNGZGt0k=; b=mT5PpnJ4nOFI5O fwlpVn9TsanLhYsZSsa+wc7eFBcii62JdAQ6sv4rCLhQjIdbAGMt0VkeTw8L5zMUzeB+Xu7oOCG90 58uJq3xyqfTaJE+iUkfCD6WkSfzPNf6QgvF6P+QyTKO7gWLRzT/CdJPuMhLSmBJV7o9mNwTi720P1 2jrvkXvkgw2r91OUfSoZoqD0khZB0XFJkgysAm4MDuKJDY+ydTw0/2lAxToNt1pZfXmHefunXjtVD m7qCiluiDXXpo0jY8Iv1pUdI/22i04Wp48vwk5b46vQN97uhw8CbgIfuNVL0KGpBcMFgeg96w5h7X h0sdhDSEsA++3dR+E9gA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j4yMz-0006Hb-FY; Fri, 21 Feb 2020 02:48:49 +0000 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1j4yMw-0006Ek-Ek for linux-riscv@lists.infradead.org; Fri, 21 Feb 2020 02:48:47 +0000 Received: by mail-pj1-x1042.google.com with SMTP id ep11so85302pjb.2 for ; Thu, 20 Feb 2020 18:48:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7RE8yadqunBbRH3qS8QB++tHjtjwApk9t/HNNGZGt0k=; b=foBMxyFqL1HySLXOnP3m4B+MiwL1nxlFgeYNRauFdEl0F0zmvYob0JOb+opoi1gSLs Z32gBcoGDrUVBWMvUnNjUkb6Bl/CakeWFI1Dw1FwlklPqEQxb9R0gLxcxkHBssHLVuMj uqbvjaEENysX/AP5QPjmVK10a4Gl9tfgtNiTq8ApZuyN3GSWw6WH0VMbl+2BcHWpobhn ykdS+pw4t8UBPFOb6/7ZB0dj+81dk7OxIbCZ4Bu6UtvNURFq4w612kt3zK/hHmmZ2SIu wCmCxh0+J4BgHb6RjSUPrcj7MugIy+Gulp6MtrCv5+BEMT01HGaEM+VBFulVELD2WO0l CKgg== 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:mime-version:content-transfer-encoding; bh=7RE8yadqunBbRH3qS8QB++tHjtjwApk9t/HNNGZGt0k=; b=sntybhghLeGZvSILCqQV4Ck5OfLztddgtRmVlsqO2la2vNz1m6RxUZ7GPvt2TpbHKK iOr2FKCzU09RxSFQ8TwkLDLWzntnxMAdO/8Bp7IAf8qkdUUIF6tRt8PhpUg/zti7gCpM mE3eZmJ6vfHn1U3t3N7S9KneyI6sHEBWZDNZE1An1/BmZzFTr1/O77bcKMzaSOtRL0ZY oi7o0bFeL0uJnreITmoc/hBTlGEjS5Cv76fSfbewWAeCwBnoDBox8Sw37WxqnskhywOt 9qXMAWCJ9hewIF4RHiUqHIr5iB/5qP6l39D5sAtlM9uRSBmwqB99YSkVKpzOCNpyW8vX KFzw== X-Gm-Message-State: APjAAAVvC4u9qNIxyG4OcMqY5eP9nC7TAdn3Mc31810cGQ165qcCZwux 0qPwNS1m7iWw6rLOhBzRGCsSrw== X-Google-Smtp-Source: APXvYqzMKIf5wkNGM3pzO9lo8wI2MZTmVLQGT0rG5tN/RteRBvqkWtb9ujdKOdoOkoK1dfe/AodaKQ== X-Received: by 2002:a17:90a:2351:: with SMTP id f75mr294048pje.133.1582253325879; Thu, 20 Feb 2020 18:48:45 -0800 (PST) Received: from VincentChen-ThinkPad-T480s.internal.sifive.com (220-132-236-182.HINET-IP.hinet.net. [220.132.236.182]) by smtp.gmail.com with ESMTPSA id 28sm618810pgl.42.2020.02.20.18.48.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Feb 2020 18:48:45 -0800 (PST) From: Vincent Chen To: paul.walmsley@sifive.com, palmer@dabbelt.com Subject: [PATCH V2 2/2] riscv: Change code model of module to medany to improve data accessing Date: Fri, 21 Feb 2020 10:47:55 +0800 Message-Id: <1582253275-28181-3-git-send-email-vincent.chen@sifive.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1582253275-28181-1-git-send-email-vincent.chen@sifive.com> References: <1582253275-28181-1-git-send-email-vincent.chen@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200220_184846_511817_31604970 X-CRM114-Status: GOOD ( 10.81 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vincent Chen , linux-riscv@lists.infradead.org, deanbo422@gmail.com Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org All the loaded module locates in the region [&_end-2G,VMALLOC_END] at runtime, so the distance from the module start to the end of the kernel image does not exceed 2GB. Hence, the code model of the kernel module can be changed to medany to improve the performance data access. Signed-off-by: Vincent Chen --- arch/riscv/Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index 33a1d7cbf775..a6abe5847e42 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -13,8 +13,10 @@ LDFLAGS_vmlinux := ifeq ($(CONFIG_DYNAMIC_FTRACE),y) LDFLAGS_vmlinux := --no-relax endif -KBUILD_AFLAGS_MODULE += -fPIC -KBUILD_CFLAGS_MODULE += -fPIC + +ifeq ($(CONFIG_64BIT)$(CONFIG_CMODEL_MEDLOW),yy) +KBUILD_CFLAGS_MODULE += -mcmodel=medany +endif export BITS ifeq ($(CONFIG_ARCH_RV64I),y)