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=-10.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 9BA4AC433E3 for ; Fri, 24 Jul 2020 23:31:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 620272070B for ; Fri, 24 Jul 2020 23:31:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 620272070B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CEC816B000C; Fri, 24 Jul 2020 19:31:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C9C8B8D0003; Fri, 24 Jul 2020 19:31:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B8C626B0023; Fri, 24 Jul 2020 19:31:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0192.hostedemail.com [216.40.44.192]) by kanga.kvack.org (Postfix) with ESMTP id A3AB46B000C for ; Fri, 24 Jul 2020 19:31:19 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 4B7071839764F for ; Fri, 24 Jul 2020 23:31:19 +0000 (UTC) X-FDA: 77074567878.12.meal72_1115fbe26f4b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 1C33E180CE88C for ; Fri, 24 Jul 2020 23:31:19 +0000 (UTC) X-HE-Tag: meal72_1115fbe26f4b X-Filterd-Recvd-Size: 5581 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Fri, 24 Jul 2020 23:31:18 +0000 (UTC) IronPort-SDR: +c5TYtItPUEO7UNRJsna8uBW8+Rkq71aZhlwe8MfmfYoZaG1nPT60+vlVEpqP1tWZXLOF5/vc2 wYtFI/mpTarA== X-IronPort-AV: E=McAfee;i="6000,8403,9692"; a="148283738" X-IronPort-AV: E=Sophos;i="5.75,392,1589266800"; d="scan'208";a="148283738" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jul 2020 16:31:16 -0700 IronPort-SDR: vM3hI6y3HwRn5mpCP4pGqF4nVH6OqOUYGJY1CTQX0RM/7wvssCZ6X2+GqfOyotb4deRWrvhyqZ sz6OQUzxz+AA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,392,1589266800"; d="scan'208";a="329064042" Received: from assenmac-mobl1.ger.corp.intel.com (HELO localhost) ([10.249.38.15]) by orsmga007.jf.intel.com with ESMTP; 24 Jul 2020 16:31:13 -0700 Date: Sat, 25 Jul 2020 02:31:12 +0300 From: Jarkko Sakkinen To: Mike Rapoport Cc: linux-kernel@vger.kernel.org, Andi Kleen , Masami Hiramatsu , Peter Zijlstra , Andrew Morton , "open list:MEMORY MANAGEMENT" Subject: Re: [PATCH v4 3/7] vmalloc: Add text_alloc() and text_free() Message-ID: <20200724233112.GA1903189@linux.intel.com> References: <20200717030422.679972-1-jarkko.sakkinen@linux.intel.com> <20200717030422.679972-4-jarkko.sakkinen@linux.intel.com> <20200718162359.GA2919062@kernel.org> <20200723222835.GC12405@linux.intel.com> <20200724101302.GF927924@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200724101302.GF927924@kernel.org> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Rspamd-Queue-Id: 1C33E180CE88C X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Jul 24, 2020 at 01:13:02PM +0300, Mike Rapoport wrote: > On Fri, Jul 24, 2020 at 01:28:35AM +0300, Jarkko Sakkinen wrote: > > On Sat, Jul 18, 2020 at 07:23:59PM +0300, Mike Rapoport wrote: > > > On Fri, Jul 17, 2020 at 06:04:17AM +0300, Jarkko Sakkinen wrote: > > > > Introduce functions for allocating memory for dynamic trampolines, such > > > > as kprobes. An arch can promote the availability of these functions with > > > > CONFIG_ARCH_HAS_TEXT_ALLOC. Provide default/fallback implementation > > > > wrapping module_alloc() and module_memfree(). > > > > > > > > Cc: Andi Kleen > > > > Cc: Masami Hiramatsu > > > > Suggested-by: Peter Zijlstra > > > > Signed-off-by: Jarkko Sakkinen > > > > --- > > > > include/linux/vmalloc.h | 23 +++++++++++++++++++++++ > > > > 1 file changed, 23 insertions(+) > > > > > > > > diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h > > > > index 0221f852a7e1..e981436e30b6 100644 > > > > --- a/include/linux/vmalloc.h > > > > +++ b/include/linux/vmalloc.h > > > > @@ -9,6 +9,7 @@ > > > > #include /* pgprot_t */ > > > > #include > > > > #include > > > > +#include > > > > > > > > #include > > > > > > > > @@ -249,4 +250,26 @@ pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms) > > > > int register_vmap_purge_notifier(struct notifier_block *nb); > > > > int unregister_vmap_purge_notifier(struct notifier_block *nb); > > > > > > > > +#ifdef CONFIG_ARCH_HAS_TEXT_ALLOC > > > > +/* > > > > + * Allocate memory to be used for dynamic trampoline code. > > > > + */ > > > > +void *text_alloc(unsigned long size); > > > > + > > > > +/* > > > > + * Free memory returned from text_alloc(). > > > > + */ > > > > +void text_free(void *region); > > > > +#else > > > > +static inline void *text_alloc(unsigned long size) > > > > +{ > > > > + return module_alloc(size); > > > > +} > > > > + > > > > +static inline void text_free(void *region) > > > > +{ > > > > + module_memfree(region); > > > > +} > > > > > > Using module_alloc() as the default implementation of generic > > > text_alloc() does not sound right to me. > > > > > > I would suggest rename module_alloc() to text_alloc() on x86, as Peter > > > proposed and then add text_alloc_kprobes() that can be overridden by the > > > architectures. x86 could use text_alloc(), arm64 vmalloc() with options > > > of their choice and the fallback would remain module_alloc(). Something > > > like (untested) patch below: > > > > I'm not exactly sure which of the below is relevant as the patch set > > includes the exact same changes with maybe different phrasing: > > The difference in parsing is what differentiates semantically clean code > from duct tape. > > As several people pointed out, a single text_alloc(), and apprently a > single ARCH_HAS_TEXT_ALLOC, would not fit all architectures and some > ground work required to implement a generic text allocation. > > Your patch works aroung this for x86 with broken semantics of > text_alloc() when ARCH_HAS_TEXT_ALLOC is not defined. > > My suggestion does not make text_alloc() a special case of > module_alloc() but rather makes text_alloc_kprobes() to fallback to > module_alloc() when architecture does not provide its implementation. OK, I see your point now. I'll response in detail to v5 comments. Thank you. /Jarkko