Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2565277ybh; Fri, 24 Jul 2020 16:43:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz31UJ0ur9pJpHR6gtFAX5VXliPdNgG20COx5Jht3YW+Kyf5FaBVHeGp0/osPpR/9NODwRb X-Received: by 2002:a17:906:3c10:: with SMTP id h16mr11232004ejg.87.1595634225282; Fri, 24 Jul 2020 16:43:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595634225; cv=none; d=google.com; s=arc-20160816; b=ORv3brImmfrH3HrEE/FIqxfXQCZT87YTvM84S8jvfJBhwUmgZhRmjVj9/5PCFT5I3p HDSJEFoZ3p4snFz2kxfIe9LT5ijiQd3Pw/dbpuLmXqKQC2lD4tTZ0p4v9IX2meUB1pqS voxv6FjpRW3xhCl8xf2KnRhSC6neD9KsvTMM9YaB94EF08vjWJB8U53+rvN2B/Jq+7Mn W4J6IjmKYX83jPvQ0p6BBwV+BSsVQ2EsdFzwLuxKejdwzs1L+7LYJh70i7ixD1+98O8g x7Exrr6Rwny9jY9Hljd9jLuZ05PbVI3YNiSFRZp609R8aNcNjgC25QqJhY4PakT6eRIH QQ/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=rHlfzQteayi824bbFPmE8jD3tkhakNp0JAeFEhmCNDw=; b=ZNGCiTY0785UxMNEYb8NUOLbshZSu8g524gaH7vzDpzJIm7pPGFIJZYW1YBpEgNK5K vMVWqNbx/2YuQLvGNjXeAJRAkU1OmDhz6ydhdUU3tbB4hRynfFibYpNQU+jujPr3KX9V 6UrdLM5okkDUa5QsN9SZVufEC+Ybn0hN5qeoh3hDMz/N+Gad8ktWFn6kiYcMbQsii0h2 mI17MO7C7H+V/tyhIMy9W0Y4i0OOTFhbdRdRNET1bcUhAwJ4bZ41kjJ3MaCDGfS1mVlA uDB+4jI65pSenxj0C7md6hAayQ0GW90GeddpZCOFczqe+NY7oe7miNp+LSTQhdLwxeWB IJlA== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qk16si1436512ejb.532.2020.07.24.16.43.21; Fri, 24 Jul 2020 16:43:45 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726882AbgGXXk4 (ORCPT + 99 others); Fri, 24 Jul 2020 19:40:56 -0400 Received: from mga09.intel.com ([134.134.136.24]:33322 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726592AbgGXXk4 (ORCPT ); Fri, 24 Jul 2020 19:40:56 -0400 IronPort-SDR: 6/k+66Q2GyQk5r5jjrOdGheaLrEW3Bt0WXPF35sknkTnSjyfeDxLW6XlAX+pDZmGFtXUJVjj6t tocOB3dbelDg== X-IronPort-AV: E=McAfee;i="6000,8403,9692"; a="152072502" X-IronPort-AV: E=Sophos;i="5.75,392,1589266800"; d="scan'208";a="152072502" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jul 2020 16:40:53 -0700 IronPort-SDR: BqdVcPt3MfBCQAQuAdkO5t3owXWmJyO0xcDvlLil8k+ZYMM/xNXpFu+hDa3Ow/TodiDaDesdcY AlPT90GnMZLA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,392,1589266800"; d="scan'208";a="272711681" Received: from assenmac-mobl1.ger.corp.intel.com (HELO localhost) ([10.249.38.15]) by fmsmga008.fm.intel.com with ESMTP; 24 Jul 2020 16:40:50 -0700 Date: Sat, 25 Jul 2020 02:40:48 +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: <20200724234048.GC1903189@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> <20200724233112.GA1903189@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200724233112.GA1903189@linux.intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jul 25, 2020 at 02:31:16AM +0300, Jarkko Sakkinen wrote: > 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. I also extended the explicit CC list heavily for follow up version. Apologies if this have been somewhat confusing so far (e.g. getting only a subportion of patches). /Jarkko