Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2846481pxa; Mon, 17 Aug 2020 22:32:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxuHbue9Li8LcFzUtpBfqNOHThRyF4zhphR/9mYnx269WyIHzipB+fBZPS2aurW+G3WI5m1 X-Received: by 2002:a17:907:1191:: with SMTP id uz17mr19306649ejb.184.1597728723165; Mon, 17 Aug 2020 22:32:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597728723; cv=none; d=google.com; s=arc-20160816; b=XqjlKbxr+c/M6MAMgacmxeoKbn4NZkLG7pMPK9zjapAAfjuPn/N/PhNTUcW6DDFaOj VbOiCpKs7LvN7jRnI7xGqpD8dmYRRuniMpsQ/vUX8mi4oLbAt6/6VkLk/JnWuedEQAVV Ni8KHzmzuAEyUfxRmjgSvWnqR3nrv9M/BdWSOWy1pNlBzrVy/93neBiANuwWE7wPmO+g QQFZGDrvXqgojtr4sKTD9OoQJXTl/0gHqHAqf4rz5gTapr6sSzbMT/g0PCmHRphACPoY u0hy86nHJO7jSrZ591rnp/EDi6/uAZs+6o7M8if9QYxj4NwmVEZ3XdL5yryn7Qh/fWs3 oaxA== 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=M61IL04q3vhSzPu7X0Awpojp80VBHrSDiI6eQnV7c+Y=; b=XAUpljxAp4IFCqCskZ7X0BdfisZGAyAcYIU60vT2+nFBwpiu28ar+4PM2HyPUPUTbi n/tiZ1qfMoHle9Xc5bZNfX7eLtzNzLb5NoRui40qlOYdkZ7o9658igSYHAnAqTXd80j1 riwqUY/JNKM6yVYtORmXvoJJjtGZbdY90TVq7IjF6FbfLI71A0/pTFz0Sd2aRWuREUab zxt2wvF3U6hX3IJUnf1L9cbvTRLThDIqn/FYiCb8vP9Rf+Fhh9ZEz322AlAekD1xRuhR ols2b8tZG3jPRMqfgTfqVE9/1Qs1NKTKNMlsat7QlhOO1PqmDeT2lKYLlq2dRm4GBP9k uD7Q== 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 w2si9704280ejz.34.2020.08.17.22.31.39; Mon, 17 Aug 2020 22:32:03 -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 S1726583AbgHRFaf (ORCPT + 99 others); Tue, 18 Aug 2020 01:30:35 -0400 Received: from mga02.intel.com ([134.134.136.20]:23245 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726480AbgHRFae (ORCPT ); Tue, 18 Aug 2020 01:30:34 -0400 IronPort-SDR: HYJEAGVrbfq6DqtPpiji/3BNcVCu6/m+vVSpmKiRagfoak6KzXeU4f+kSw0Iad53hbAiVtGiFu IyA/6tk/hFmg== X-IronPort-AV: E=McAfee;i="6000,8403,9716"; a="142671900" X-IronPort-AV: E=Sophos;i="5.76,326,1592895600"; d="scan'208";a="142671900" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Aug 2020 22:30:33 -0700 IronPort-SDR: JCeOFRprVuwng85bEu6hJrSPQv4h6XQZrKdSlv/9/73LvIJ3QNcbWjyrYwtbXogMDgree0RS59 Q1pGXk7ylpaw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,326,1592895600"; d="scan'208";a="326628848" Received: from lcrossx-mobl1.ger.corp.intel.com (HELO localhost) ([10.249.46.217]) by orsmga008.jf.intel.com with ESMTP; 17 Aug 2020 22:30:30 -0700 Date: Tue, 18 Aug 2020 08:30:29 +0300 From: Jarkko Sakkinen To: Mike Rapoport Cc: Ingo Molnar , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andi Kleen , Masami Hiramatsu , Peter Zijlstra , "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , Jessica Yu , Ard Biesheuvel Subject: Re: [PATCH v5 5/6] kprobes: Use text_alloc() and text_free() Message-ID: <20200818053029.GE44714@linux.intel.com> References: <20200724050553.1724168-1-jarkko.sakkinen@linux.intel.com> <20200724050553.1724168-6-jarkko.sakkinen@linux.intel.com> <20200724092746.GD517988@gmail.com> <20200725031648.GG17052@linux.intel.com> <20200726081408.GB2927915@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200726081408.GB2927915@kernel.org> 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 Sun, Jul 26, 2020 at 11:14:08AM +0300, Mike Rapoport wrote: > On Sat, Jul 25, 2020 at 06:16:48AM +0300, Jarkko Sakkinen wrote: > > > I've read the observations in the other threads, but this #ifdef > > > jungle is silly, it's a de-facto open coded text_alloc() with a > > > module_alloc() fallback... > > > > In the previous version I had: > > > > https://lore.kernel.org/lkml/20200717030422.679972-4-jarkko.sakkinen@linux.intel.com/ > > > > and I had just calls to text_alloc() and text_free() in corresponding > > snippet to the above. > > > > I got this feedback from Mike: > > > > https://lore.kernel.org/lkml/20200718162359.GA2919062@kernel.org/ > > > > I'm not still sure that I fully understand this feedback as I don't see > > any inherent and obvious difference to the v4. In that version fallbacks > > are to module_alloc() and module_memfree() and text_alloc() and > > text_memfree() can be overridden by arch. > > Let me try to elaborate. > > There are several subsystems that need to allocate memory for executable > text. As it happens, they use module_alloc() with some abilities for > architectures to override this behaviour. > > For many architectures, it would be enough to rename modules_alloc() to > text_alloc(), make it built-in and this way allow removing dependency on > MODULES. > > Yet, some architectures have different restrictions for code allocation > for different subsystems so it would make sense to have more than one > variant of text_alloc() and a single config option ARCH_HAS_TEXT_ALLOC > won't be sufficient. > > I liked Mark's suggestion to have text_alloc_() and proposed > a way to introduce text_alloc_kprobes() along with > HAVE_KPROBES_TEXT_ALLOC to enable arch overrides of this function. > > The major difference between your v4 and my suggestion is that I'm not > trying to impose a single ARCH_HAS_TEXT_ALLOC as an alternative to > MODULES but rather to use per subsystem config option, e.g. > HAVE_KPROBES_TEXT_ALLOC. > > Another thing, which might be worth doing regardless of the outcome of > this discussion is to rename alloc_insn_pages() to text_alloc_kprobes() > because the former is way too generic and does not emphasize that the > instruction page is actually used by kprobes only. What if we in kernel/kprobes.c just: #ifndef CONFIG_ARCH_HAS_TEXT_ALLOC void __weak *alloc_insn_page(void) { return module_alloc(PAGE_SIZE); } void __weak free_insn_page(void *page) { module_memfree(page); } #endif In Kconfig (as in v5): config KPROBES bool "Kprobes" depends on MODULES || ARCH_HAS_TEXT_ALLOC I checked architectures that override alloc_insn_page(). With the exception of x86, they do not call module_alloc(). If no rename was done, then with this approach a more consistent. config flag name would be CONFIG_ARCH_HAS_ALLOC_INSN_PAGE. I'd call the function just as kprobes_alloc_page(). Then the config flag would become CONFIG_HAS_KPROBES_ALLOC_PAGE. > -- > Sincerely yours, > Mike. Thanks for the feedback! /Jarkko