Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2131050ybh; Fri, 24 Jul 2020 05:17:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCLdM2ahEcTT3Gybw+pfkXvmzq+LMZuHrS3J6MDFCFtySXOBDH3CHK/OPCEsEDCP1MoVaF X-Received: by 2002:a17:907:2108:: with SMTP id qn8mr8765523ejb.16.1595593074310; Fri, 24 Jul 2020 05:17:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595593074; cv=none; d=google.com; s=arc-20160816; b=u+0SR+Fj997oyoz3sfkO296HbAKg2+BXzPh/sb13v4iu3q6wInWh3wjyNL5Bjgbn6J w7GMoEQDtg90Y8yM8sfRP6cSF5zq9l9R9eRsdsHY7BO9BbMTZgCu0SoC68komE44/3Zj j4vWFXbTfeKqIzcrzzUrc/7kaWCIXTQGR4T/q5WitcUO5P/dZ+Y8NrkJUNq9t+q8BRU0 NscqUAA0yksTqf3gYh/Dc/d1dVz2kbD7Vl871qbSpphwaa/vRqSDeMmOvqi9maejgHgE ciGlLYqPE1VjTRwSVbYwoO0lFvnX5GlxT67qeIflC8hYeb3WtBaDkNppW7KLHwazpHtK HMow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=ZDjWSdDQySTSo6zrgj5ZiQmcwGnXM4kzlUoGH1QjHC0=; b=Np2G8egDpSP6zpNCENyRHJbiZgThfU3yV2A5ItK1s0FaA04du5sipuYng+HtSi9oSs rrDTb0FB38mGQyIqeznbY1yWHLlWmEzEa3w15+9UbguMqPSwstLnZydY558BTku/On7C JSn7KegUsK7wvwRmHAxgNHijd8uElrLQwLn8s1C1pIGYrL/KsY2APdw1/WToePLF6m+j /iZspwkgZ9PvmIH8fim/nzaNiA3nTVJNm1wLSYI995ZV/tPdfYbdbzkC9tqp9NMCbW0u kApu9UarVb31nzNb32FzLJNmzTk3Nt+tmm67MpHRwI/VsSPMMOlY524GUN9cizAxC5OQ nYhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VFB+q4nt; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o21si356103ejc.533.2020.07.24.05.17.31; Fri, 24 Jul 2020 05:17:54 -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=@kernel.org header.s=default header.b=VFB+q4nt; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726931AbgGXMQW (ORCPT + 99 others); Fri, 24 Jul 2020 08:16:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:58818 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726488AbgGXMQV (ORCPT ); Fri, 24 Jul 2020 08:16:21 -0400 Received: from mail-oi1-f182.google.com (mail-oi1-f182.google.com [209.85.167.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7EF162073E for ; Fri, 24 Jul 2020 12:16:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595592980; bh=WdKBttJSrUprqS6V7PDxTgYqLUaZfmvXP2DkIOtu0so=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=VFB+q4ntLqL2Ctbo5MgHkPItgam47VQK06Pl1wqcpJGLX3T+w3386RUBz+2EpNySK 6e+zBJSOnsYMp+UAN8UaF6g9qY7oaCIMxUPAPcg3G3O6RdbTlfmDVvbbL0CzNrghCh kl33diwLiJ14k+lGLNFeolqDXVRL54593INbIlKQ= Received: by mail-oi1-f182.google.com with SMTP id e4so7851082oib.1 for ; Fri, 24 Jul 2020 05:16:20 -0700 (PDT) X-Gm-Message-State: AOAM532s6+DSrNQ2ye3hOjowe3nnzQ/Es564+Xf5aebmyi3DY+bER7qz COQJjm/1KK2+UH98m8ng7xpQWGV+eX9xYW9vZ/4= X-Received: by 2002:aca:5516:: with SMTP id j22mr7411445oib.47.1595592979858; Fri, 24 Jul 2020 05:16:19 -0700 (PDT) MIME-Version: 1.0 References: <20200724050553.1724168-1-jarkko.sakkinen@linux.intel.com> <20200724050553.1724168-6-jarkko.sakkinen@linux.intel.com> <20200724092746.GD517988@gmail.com> In-Reply-To: <20200724092746.GD517988@gmail.com> From: Ard Biesheuvel Date: Fri, 24 Jul 2020 15:16:08 +0300 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v5 5/6] kprobes: Use text_alloc() and text_free() To: Ingo Molnar Cc: Jarkko Sakkinen , Linux Kernel Mailing List , linux-mm@kvack.org, Andi Kleen , Masami Hiramatsu , Peter Zijlstra , "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , Jessica Yu Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 24 Jul 2020 at 12:27, Ingo Molnar wrote: > > > * Jarkko Sakkinen wrote: > > > Use text_alloc() and text_free() instead of module_alloc() and > > module_memfree() when an arch provides them. > > > > Cc: linux-mm@kvack.org > > Cc: Andi Kleen > > Cc: Masami Hiramatsu > > Cc: Peter Zijlstra > > Signed-off-by: Jarkko Sakkinen > > --- > > kernel/kprobes.c | 9 +++++++++ > > 1 file changed, 9 insertions(+) > > > > diff --git a/kernel/kprobes.c b/kernel/kprobes.c > > index 4e46d96d4e16..611fcda9f6bf 100644 > > --- a/kernel/kprobes.c > > +++ b/kernel/kprobes.c > > @@ -40,6 +40,7 @@ > > #include > > #include > > #include > > +#include > > > > #define KPROBE_HASH_BITS 6 > > #define KPROBE_TABLE_SIZE (1 << KPROBE_HASH_BITS) > > @@ -111,12 +112,20 @@ enum kprobe_slot_state { > > > > void __weak *alloc_insn_page(void) > > { > > +#ifdef CONFIG_ARCH_HAS_TEXT_ALLOC > > + return text_alloc(PAGE_SIZE); > > +#else > > return module_alloc(PAGE_SIZE); > > +#endif > > } > > > > void __weak free_insn_page(void *page) > > { > > +#ifdef CONFIG_ARCH_HAS_TEXT_ALLOC > > + text_free(page); > > +#else > > module_memfree(page); > > +#endif > > } > > 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... > Also, as I attempted to explain before, there is no reason to allocate kasan shadow for any of these use cases, so cloning module_alloc() to implement text_alloc() is not the correct approach even on x86. I suppose module_alloc() could be reimplemented in terms of text_alloc() in this case, but simply relabelling it like this seems inappropriate on all architectures.