Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp249088ybh; Tue, 21 Jul 2020 22:50:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzd21pGRgtEEqDVNBxKlPdrZDAhREOhxLPUFvTaa9bXomupkO82KU0YEplccdAZSGf9haOC X-Received: by 2002:a50:c307:: with SMTP id a7mr27999709edb.279.1595397000129; Tue, 21 Jul 2020 22:50:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595397000; cv=none; d=google.com; s=arc-20160816; b=Kvvu5vH4vDZU6nPe9vbL65Q9/ZLjkp+jk5In+icwT4LC2RQKv1M0uJoJRYJX3xailW Z0EYHYyy+yhaiLlWdelnHF2dv5wK7igbRiXyugCKvkiMy7v5ln511oEi90/YwRbC8oh2 zpDHr1MflCTSsg0IipDdTLvjdmzFxCNq4VJhbgLRdfRuWAW9xmOX0iHI8EQoRUqN5jg/ 2XBCt4ZqdzwgfrQigJF0AHEDKLOMGn8HB98qz25XXJbQDiquR2CMzFcQIGc78U0z2sZZ hzfixfYUAsSlgn2hzTboREqL/JHr9HBN3omQYK6lv0vAXgooyn9C+kZbzrX5eEq7X+MT PX3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:to:from:cc:in-reply-to:subject:date:dkim-signature; bh=c3WKCCywdgvLGCz57S7am54sr0h7w7V/JrEMUHUMU/o=; b=DT3wbbyU5xOoMzS5NwxUxhG89f4ybuqXNxLOhoT99eE43+PMwJNeOcn2HY0EOBWVlB 0BydwrpRlYc/PFpzsJIMBsJCNZTIBVPLmPddX/D8eHmH1p9+CyJPTHvafep/lQ/QJPgt RxrO7gf9bkCSEk0r0/mkrOFtOaqTdHuzKQIkvulGUg/unCwe4eKk9y8n7Y0LuaMSxPKM 6ikH6lNPm+fNXjLEM+ALeJ483Fe8YzFFjOTkwrB3tken96eWZubmAlBruWo1BqzY+lNc n2NdP9uy00q/FQmFB/cAu0yHwCoG8y9PkPc2EDZG6md2GZIbYf5lmaRm1koXU+i3BMAo 0GBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dabbelt-com.20150623.gappssmtp.com header.s=20150623 header.b=fCuEEXu+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id yd21si14455496ejb.727.2020.07.21.22.49.37; Tue, 21 Jul 2020 22:50:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@dabbelt-com.20150623.gappssmtp.com header.s=20150623 header.b=fCuEEXu+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727933AbgGVFqk (ORCPT + 99 others); Wed, 22 Jul 2020 01:46:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726696AbgGVFqk (ORCPT ); Wed, 22 Jul 2020 01:46:40 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B162C061794 for ; Tue, 21 Jul 2020 22:46:40 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id s189so592414pgc.13 for ; Tue, 21 Jul 2020 22:46:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20150623.gappssmtp.com; s=20150623; h=date:subject:in-reply-to:cc:from:to:message-id:mime-version :content-transfer-encoding; bh=c3WKCCywdgvLGCz57S7am54sr0h7w7V/JrEMUHUMU/o=; b=fCuEEXu++BATZZEgu63jyhgE+Y1XNFfh/hfRTuYGDp7tRoc6LbkGOtZmRlJEX0Q4mc 58Wx5DrHLgqWGA15ODfmp4BD+A6kqkaXmwBVAcQy7tZT4nC6LrgGJ3lzv06Ej9jur88k XGQBpKOytzyljGp9JTo/2ytrZBP2jJniHbB1MwjDRZhque2NwdZ0aWGsgryRqU+3DE9U m+vgwzNJSvheMii7MxNhJxPUYaZbP4XIj428wVkVonkWkFnWlNi3Hd/UlX/sByadTgHP sXR0VV6uQ74NOk6fTFxzR7f22jvf+xzhKswTeZHjL411qPbZeON+M2WgzsdrCjh868sb i6BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:subject:in-reply-to:cc:from:to:message-id :mime-version:content-transfer-encoding; bh=c3WKCCywdgvLGCz57S7am54sr0h7w7V/JrEMUHUMU/o=; b=jRkuC/v/F5Tj0AZz+3naoWfl++jrWNsGvbu56QzOb+BehDedyFpMkH11GpXA74ko5j 0K5PBnJzjMzf9ANkD0OYcgE82fLHxLlf1yFdfDv2DPcSLvVdCsdfAu8x3MgUGYNdIkjB XtvkTHjSYubMfkFOgTxbqQuWsEfEMDxgDpcn8YQQL0JqQvuTehslgLUl8nwd/F7TWRbY h6eKn/iAmI2pGnBTHrhWrBLSweKdezz2022fy+3g11K68kBMYvgz2AfDhk3yGGk6FmiG /JdYBOkJhV+LtlmMpLNLLmSXBzw737DRZyxyqv6+ZS0YvOBxY0xbVeqyyXG14zaI5zAk idKQ== X-Gm-Message-State: AOAM533k2Qv+yWgayPj2IDJiJam/9ihKSyDcrD2QW2EzJyzeV/43SrgC yA2UzOZPs8UGpjwGM0MfsLNBqg== X-Received: by 2002:a62:7505:: with SMTP id q5mr25490271pfc.262.1595396799507; Tue, 21 Jul 2020 22:46:39 -0700 (PDT) Received: from localhost (76-210-143-223.lightspeed.sntcca.sbcglobal.net. [76.210.143.223]) by smtp.gmail.com with ESMTPSA id r16sm22153983pfh.64.2020.07.21.22.46.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jul 2020 22:46:38 -0700 (PDT) Date: Tue, 21 Jul 2020 22:46:38 -0700 (PDT) X-Google-Original-Date: Tue, 21 Jul 2020 22:46:37 PDT (-0700) Subject: Re: [PATCH v5 1/4] riscv: Move kernel mapping to vmalloc zone In-Reply-To: <87sgdkqhjx.fsf@mpe.ellerman.id.au> CC: benh@kernel.crashing.org, alex@ghiti.fr, paulus@samba.org, Paul Walmsley , aou@eecs.berkeley.edu, Anup Patel , Atish Patra , zong.li@sifive.com, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-mm@kvack.org From: Palmer Dabbelt To: mpe@ellerman.id.au Message-ID: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 21 Jul 2020 21:50:42 PDT (-0700), mpe@ellerman.id.au wrote: > Benjamin Herrenschmidt writes: >> On Tue, 2020-07-21 at 16:48 -0700, Palmer Dabbelt wrote: >>> > Why ? Branch distance limits ? You can't use trampolines ? >>> >>> Nothing fundamental, it's just that we don't have a large code model in the C >>> compiler. As a result all the global symbols are resolved as 32-bit >>> PC-relative accesses. We could fix this with a fast large code model, but then >>> the kernel would need to relax global symbol references in modules and we don't >>> even do that for the simple code models we have now. FWIW, some of the >>> proposed large code models are essentially just split-PLT/GOT and therefor >>> don't require relaxation, but at that point we're essentially PIC until we >>> have more that 2GiB of kernel text -- and even then, we keep all the >>> performance issues. >> >> My memory might be out of date but I *think* we do it on powerpc >> without going to a large code model, but just having the in-kernel >> linker insert trampolines. > > We build modules with the large code model, and always have AFAIK: > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/powerpc/Makefile?commit=4fa640dc52302b5e62b01b05c755b055549633ae#n129 > > # -mcmodel=medium breaks modules because it uses 32bit offsets from > # the TOC pointer to create pointers where possible. Pointers into the > # percpu data area are created by this method. > # > # The kernel module loader relocates the percpu data section from the > # original location (starting with 0xd...) to somewhere in the base > # kernel percpu data space (starting with 0xc...). We need a full > # 64bit relocation for this to work, hence -mcmodel=large. > KBUILD_CFLAGS_MODULE += -mcmodel=large Well, a fast large code model would solve a lot of problems :). Unfortunately we just don't have enough people working on this stuff to do that. It's a somewhat tricky thing to do on RISC-V as there aren't any quick sequences for long addresses, but I don't think we're that much worse off than everyone else. At some point I had a bunch of designs written up, but they probably went along with my SiFive computer. I think we ended up decided that the best bet would be to distribute constant tables throughout the text such that they're accessible via the 32-bit PC-relative loads at any point -- essentially the multi-GOT stuff that MIPS used for big objects. Doing that well is a lot of work and doing it poorly is just as slow as PIC, so we never got around to it. > We also insert trampolines for branches, but IIUC that's a separate > issue. "PowerPC branch trampolines" points me here https://sourceware.org/binutils/docs-2.20/ld/PowerPC-ELF32.html . That sounds like what we're doing already in the medium code models: we have short and medium control transfer sequences, linker relaxation optimizes them when possible. Since we rely on linker relaxation pretty heavily we just don't bother with the smaller code model: it'd be a 12-bit address space for data and a 21-bit address space for text (with 13-bit maximum function size). Instead of building out such a small code model we just spent time improving the linker.