From mboxrd@z Thu Jan 1 00:00:00 1970 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=-4.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 9F449C433E1 for ; Tue, 14 Jul 2020 13:01:33 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 6CEFE22473 for ; Tue, 14 Jul 2020 13:01:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="NVQKVm/a"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Jtl1Wg+/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6CEFE22473 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=o7Ih0kl6C3t4HKppBzNCCZtxW+SJrSlW0pdFsmuktvQ=; b=NVQKVm/aDMlE4Fg/uhJGNx97L UIZyfDKeQDjsZgY8aY2P6cTy3IkQ++9Lonk0cp5bHYAgWCtj+/7jrKzkuLiHAujIE5Oe2N6jEWSFH MzCm6860EENE3eAKdgKlGl32jVwzOldi+8GZ0kGulSu0vNln3/dGMRe6LhzKz92ykVLSUwbqyNaLj Ksii/HLyfxUesmY7rj0BS4Tt55dirYgstZAELzwTGUe9l16g9lIr1jUX32iYw6x3W7rxQxxs4w0uX 1457eT2VfCB7tsCx/dM9t+BvXT3+AnwkKFDWK7MjgPBrsYBHQ7WgLmRgGiZ6Ww8PyCZIdSo7viUha wYQsj3Wqw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jvKYl-0008HO-H9; Tue, 14 Jul 2020 13:01:23 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jvKYj-0008Gx-Jh; Tue, 14 Jul 2020 13:01:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=J/gJvCUhZaH49je89LCcpmy+HAxWN3dlCfIW7kcsmZs=; b=Jtl1Wg+/IxJqXObLY4gMXGB04G rv3ag64EJ2iC/BjPNU4r2hN8OvMmXH351iMvO+JpgUH/mNB68Wna7pfwMiJN4NDbMihaumJqfgOgB 2a/8fJ6v0OeRswNbUD9NWStEzOcMj5PLIFApH01iTjh9OdFjHo2emsusFazRi5faO+Q6fSFt0Iacv ZfWAOaGfdDqy9fOUmZN9dJcH9hPxaaHVNZRYEwuSWZdiJct2B0mjw51bXqS9vsqbYNylSs7EM/bAk HsfFkjVnW8/3iH/0MiCbiOzCbnnOAVGFQxF0Bt6z7Dsu3XZev3Dqqy1x32CkwRcHkeQ5LO9f7NOAW msrUfdWg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jvKYa-0003Vq-Ii; Tue, 14 Jul 2020 13:01:13 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id A29CE302753; Tue, 14 Jul 2020 15:01:09 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 854E92B0C0D90; Tue, 14 Jul 2020 15:01:09 +0200 (CEST) Date: Tue, 14 Jul 2020 15:01:09 +0200 From: Peter Zijlstra To: Ard Biesheuvel Subject: Re: [PATCH v2 1/3] module: Rename module_alloc() to text_alloc() and move to kernel proper Message-ID: <20200714130109.GX10769@hirez.programming.kicks-ass.net> References: <20200714094625.1443261-1-jarkko.sakkinen@linux.intel.com> <20200714094625.1443261-2-jarkko.sakkinen@linux.intel.com> <20200714102826.GB4756@willie-the-truck> <20200714112927.GV10769@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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: Catalin Marinas , Kefeng Wang , Paul Mackerras , Zong Li , Andi Kleen , Paul Burton , Michael Ellerman , Vincent Whitchurch , Benjamin Herrenschmidt , Petr Mladek , Brian Gerst , Andy Lutomirski , Thomas Gleixner , Jiri Kosina , Anup Patel , Linux Kernel Mailing List , Philipp Rudo , Torsten Duwe , Masami Hiramatsu , Andrew Morton , Mark Rutland , "James E.J. Bottomley" , Vincent Chen , Omar Sandoval , "open list:S390" , Joe Lawrence , Helge Deller , John Fastabend , Anil S Keshavamurthy , Yonghong Song , Iurii Zaikin , Andrii Nakryiko , Thomas Huth , Vasily Gorbik , "moderated list:ARM PORT" , Daniel Axtens , Damien Le Moal , Martin KaFai Lau , Song Liu , Paul Walmsley , Heiko Carstens , Alexei Starovoitov , Jarkko Sakkinen , Atish Patra , Will Deacon , Daniel Borkmann , Masahiro Yamada , Nayna Jain , Ley Foon Tan , Christian Borntraeger , Sami Tolvanen , "Naveen N. Rao" , Mao Han , Marco Elver , Steven Rostedt , Babu Moger , Borislav Petkov , Greentime Hu , Ben Dooks , Guan Xuetao , Thomas Bogendoerfer , "open list:PARISC ARCHITECTURE" , Jessica Yu , "open list:BPF JIT for MIPS \(32-BIT AND 64-BIT\)" , "David S. Miller" , Thiago Jung Bauermann , David Howells , "open list:SPARC + UltraSPARC \(sparc/sparc64\)" , Sandipan Das , "H. Peter Anvin" , Amit Daniel Kachhap , Tiezhu Yang , Miroslav Benes , Jiri Olsa , "open list:RISC-V ARCHITECTURE" , Vincenzo Frascino , Anders Roxell , Sven Schnelle , "maintainer:X86 ARCHITECTURE \(32-BIT AND 64-BIT\)" , Russell King , Mike Rapoport , Ingo Molnar , Albert Ou , "Paul E. McKenney" , Josh Poimboeuf , KP Singh , Dmitry Vyukov , Nick Hu , "open list:BPF JIT for MIPS \(32-BIT AND 64-BIT\)" , "open list:MIPS" , Palmer Dabbelt , "open list:LINUX FOR POWERPC \(32-BIT AND 64-BIT\)" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Tue, Jul 14, 2020 at 03:19:24PM +0300, Ard Biesheuvel wrote: > So perhaps the answer is to have text_alloc() not with a 'where' > argument but with a 'why' argument. Or more simply, just have separate > alloc/free APIs for each case, with generic versions that can be > overridden by the architecture. Well, there only seem to be 2 cases here, either the pointer needs to fit in some immediate displacement, or not. On x86 we seem have the advantage of a fairly large immediate displacement as compared to many other architectures (due to our variable sized instructions). And thus have been fairly liberal with our usage of it (also our indirect jmps/calls suck, double so with RETCH-POLINE). Still, the indirect jump, as mentioned by Russel should work for arbitrarily placed code for us too. So I'm thinking that something like: enum ptr_type { immediate_displacement, absolute, }; void *text_alloc(unsigned long size, enum ptr_type type) { unsigned long vstart = VMALLOC_START; unsigned long vend = VMALLOC_END; if (type == immediate_displacement) { vstart = MODULES_VADDR; vend = MODULES_END; } return __vmalloc_node_range(size, TEXT_ALIGN, vstart, vend, GFP_KERNEL, PAGE_KERNEL_EXEC, 0, NUMA_NO_NODE, _RET_IP_); } void text_free(void *ptr) { vfree(ptr); } Should work for all cases. Yes, we might then want something like a per arch: {BPF,FTRACE,KPROBE}_TEXT_TYPE to help with text_alloc() usage in generic code, but I think fundamentally, there's only these two options. _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv From mboxrd@z Thu Jan 1 00:00:00 1970 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=-3.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no 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 0FCF0C433E1 for ; Tue, 14 Jul 2020 19:17:54 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (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 761FD2242C for ; Tue, 14 Jul 2020 19:17:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Jtl1Wg+/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 761FD2242C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4B5qzL3ZDDzDqhT for ; Wed, 15 Jul 2020 05:17:50 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1236::1; helo=casper.infradead.org; envelope-from=peterz@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=casper.20170209 header.b=Jtl1Wg+/; dkim-atps=neutral Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4B5gd638JpzDqMt for ; Tue, 14 Jul 2020 23:01:28 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=J/gJvCUhZaH49je89LCcpmy+HAxWN3dlCfIW7kcsmZs=; b=Jtl1Wg+/IxJqXObLY4gMXGB04G rv3ag64EJ2iC/BjPNU4r2hN8OvMmXH351iMvO+JpgUH/mNB68Wna7pfwMiJN4NDbMihaumJqfgOgB 2a/8fJ6v0OeRswNbUD9NWStEzOcMj5PLIFApH01iTjh9OdFjHo2emsusFazRi5faO+Q6fSFt0Iacv ZfWAOaGfdDqy9fOUmZN9dJcH9hPxaaHVNZRYEwuSWZdiJct2B0mjw51bXqS9vsqbYNylSs7EM/bAk HsfFkjVnW8/3iH/0MiCbiOzCbnnOAVGFQxF0Bt6z7Dsu3XZev3Dqqy1x32CkwRcHkeQ5LO9f7NOAW msrUfdWg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jvKYa-0003Vq-Ii; Tue, 14 Jul 2020 13:01:13 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id A29CE302753; Tue, 14 Jul 2020 15:01:09 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 854E92B0C0D90; Tue, 14 Jul 2020 15:01:09 +0200 (CEST) Date: Tue, 14 Jul 2020 15:01:09 +0200 From: Peter Zijlstra To: Ard Biesheuvel Subject: Re: [PATCH v2 1/3] module: Rename module_alloc() to text_alloc() and move to kernel proper Message-ID: <20200714130109.GX10769@hirez.programming.kicks-ass.net> References: <20200714094625.1443261-1-jarkko.sakkinen@linux.intel.com> <20200714094625.1443261-2-jarkko.sakkinen@linux.intel.com> <20200714102826.GB4756@willie-the-truck> <20200714112927.GV10769@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Mailman-Approved-At: Wed, 15 Jul 2020 05:16:18 +1000 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Catalin Marinas , Kefeng Wang , Paul Mackerras , Zong Li , Andi Kleen , Paul Burton , Vincent Whitchurch , Petr Mladek , Brian Gerst , Andy Lutomirski , Thomas Gleixner , Jiri Kosina , Anup Patel , Linux Kernel Mailing List , Philipp Rudo , Torsten Duwe , Masami Hiramatsu , Andrew Morton , Mark Rutland , "James E.J. Bottomley" , Vincent Chen , Omar Sandoval , "open list:S390" , Joe Lawrence , Helge Deller , John Fastabend , Anil S Keshavamurthy , Yonghong Song , Iurii Zaikin , Andrii Nakryiko , Thomas Huth , Vasily Gorbik , "moderated list:ARM PORT" , Daniel Axtens , Damien Le Moal , Martin KaFai Lau , Song Liu , Paul Walmsley , Heiko Carstens , Alexei Starovoitov , Jarkko Sakkinen , Atish Patra , Will Deacon , Daniel Borkmann , Masahiro Yamada , Nayna Jain , Ley Foon Tan , Christian Borntraeger , Sami Tolvanen , "Naveen N. Rao" , Mao Han , Marco Elver , Steven Rostedt , Babu Moger , Borislav Petkov , Greentime Hu , Ben Dooks , Guan Xuetao , Thomas Bogendoerfer , "open list:PARISC ARCHITECTURE" , Jessica Yu , "open list:BPF JIT for MIPS \(32-BIT AND 64-BIT\)" , "David S. Miller" , Thiago Jung Bauermann , David Howells , "open list:SPARC + UltraSPARC \(sparc/sparc64\)" , Sandipan Das , "H. Peter Anvin" , Amit Daniel Kachhap , Tiezhu Yang , Miroslav Benes , Jiri Olsa , "open list:RISC-V ARCHITECTURE" , Vincenzo Frascino , Anders Roxell , Sven Schnelle , "maintainer:X86 ARCHITECTURE \(32-BIT AND 64-BIT\)" , Russell King , Mike Rapoport , Ingo Molnar , Albert Ou , "Paul E. McKenney" , Josh Poimboeuf , KP Singh , Dmitry Vyukov , Nick Hu , "open list:BPF JIT for MIPS \(32-BIT AND 64-BIT\)" , "open list:MIPS" , Palmer Dabbelt , "open list:LINUX FOR POWERPC \(32-BIT AND 64-BIT\)" Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Tue, Jul 14, 2020 at 03:19:24PM +0300, Ard Biesheuvel wrote: > So perhaps the answer is to have text_alloc() not with a 'where' > argument but with a 'why' argument. Or more simply, just have separate > alloc/free APIs for each case, with generic versions that can be > overridden by the architecture. Well, there only seem to be 2 cases here, either the pointer needs to fit in some immediate displacement, or not. On x86 we seem have the advantage of a fairly large immediate displacement as compared to many other architectures (due to our variable sized instructions). And thus have been fairly liberal with our usage of it (also our indirect jmps/calls suck, double so with RETCH-POLINE). Still, the indirect jump, as mentioned by Russel should work for arbitrarily placed code for us too. So I'm thinking that something like: enum ptr_type { immediate_displacement, absolute, }; void *text_alloc(unsigned long size, enum ptr_type type) { unsigned long vstart = VMALLOC_START; unsigned long vend = VMALLOC_END; if (type == immediate_displacement) { vstart = MODULES_VADDR; vend = MODULES_END; } return __vmalloc_node_range(size, TEXT_ALIGN, vstart, vend, GFP_KERNEL, PAGE_KERNEL_EXEC, 0, NUMA_NO_NODE, _RET_IP_); } void text_free(void *ptr) { vfree(ptr); } Should work for all cases. Yes, we might then want something like a per arch: {BPF,FTRACE,KPROBE}_TEXT_TYPE to help with text_alloc() usage in generic code, but I think fundamentally, there's only these two options.