Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3394428lqp; Tue, 26 Mar 2024 08:05:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVbyHWyRtaIRx10JLcIDaWsJhXnyJIUCaCk3UIZj8vs6omPyU57O4Rc6ebpEkRxESZTvNq0g9asQvIiZ3z9mmzwntkWbALJOmubR35sig== X-Google-Smtp-Source: AGHT+IEnbVzBhFu4WadX9hckc9y8xz1Stf0YU9T+7QUMeQiavdEatCbpmhlna3OgU+JXX1XFy9Le X-Received: by 2002:a17:906:4102:b0:a4a:347f:a835 with SMTP id j2-20020a170906410200b00a4a347fa835mr1507548ejk.19.1711465534287; Tue, 26 Mar 2024 08:05:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711465534; cv=pass; d=google.com; s=arc-20160816; b=BQH377pxvIVvlzBmxknOLmp5lgFRHzwJf47QWwXCvFV5L90n1PWqxtsd76MjXTBl6H qx0Mx1Is3HeX3M7oryYEeBX0wAwpMQ2XVXtTsYZKQkOCE+MTS/ETamZmQXwjOTs9W3/X qJ3mgO8LyU4nA+IoFt0KweVnSuAtfyHdDP0A5aQnwq4vKzD/BB4AZ6NI/SzbNYJ3+kyL jw/ZHDllHTswDj1omXtZ5gDslmfY2+xnNKaC7M884RDLnD4UCtq+8bxd3zZyOLv136hy MzTAcCYHcLDramqNWW1VNgeGwppoZPN0owxrgyDdpzwOFEx8gFNnpK5wTtsIXj/pejUI vTmg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=J1z+SR5tp5fcczqcGYnPaOHtot+8C4g/2xvySa+4dXM=; fh=leopQn5WpbrgAzCEiIqtyvip9oyymH01OxUsrrpJ3yU=; b=dLz+jFnRVHcWspdu4YOr8DNzp9eMi80ZxG0+QjWa0nuMakFj04Et/YxQJ7QJGz5DlR bh383e+aU0LOg0BUbf6HBUK1YGmc790LAg4EYUhWXBH4wN5hlRHZ80Jxux2fj2vRy07+ AHX6F0jEdI7iJWXzfgI2CeS5rga84Bg116ukUZRZXYMXld766MGH0vzvi6jfsKODIw// 28/RUFokHHdJfbukzRJwwsRH76hnbWkkJGP9lkqYqrf4YFqy0lc2YO0EdcVQGxfrJYkQ Y9vqqxC98xD68ySokhEQ+nrD5BzRflETcWY2eXNks+Im/aav7dc/f9Qje/K3BwUNbkOi kwZg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=c9yMVpI+; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-119259-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119259-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id q23-20020a1709060f9700b00a46fbbc2f56si91928ejj.460.2024.03.26.08.05.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 08:05:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-119259-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=c9yMVpI+; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-119259-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119259-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D8EB71F65FCD for ; Tue, 26 Mar 2024 15:05:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 254D613C69D; Tue, 26 Mar 2024 15:05:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="c9yMVpI+" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4871E12D76F; Tue, 26 Mar 2024 15:05:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711465526; cv=none; b=OTqYbL11O7KZqkIb6BT3EM5zvqN4L4Co6PSuClIgxljQQwFOn4PUs4G5Z8imNE+dFi93Rgh9xnaxOH82aUQ2gogiejGAzopYRXmHQH1XNoPDrLY275Gi5LbRuD+uhvirFmMHg8+SyVnCzhBhDBc6JM2HNX6xd/igWd/WEx+6DJI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711465526; c=relaxed/simple; bh=/qmndJDlWupnnpJi65R442kaOqvhHDX628LndcyMGs8=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=SjOYj3ENWOo/WBb3Q+bMl41WOTGPB7AToKfhrJEVSrbzZNnRCJghrsTIC4outKzP6be03WRFZP8QanVAOr0IZkiWUa7huzzTkOYNFwc2pS+9zdro6t2ywvjLZCHj491n1MtfoJyMCmW+itDtEwzoj8cgVNELjQYGh3DvvNeUQi4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=c9yMVpI+; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0E1CC433F1; Tue, 26 Mar 2024 15:05:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711465525; bh=/qmndJDlWupnnpJi65R442kaOqvhHDX628LndcyMGs8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=c9yMVpI+L1invWuAwwgd4+iMcVeBkKccwiZLj5q45v6lHB4Yo+LFvKNJfp6wGJqGS T5NU0KIKcXNJTidqaVE1V4KsGz+s8Vk9t4M5UPrDzgFqe2DHM1I2MyiTV4ZTcV4jQ1 qwh8O/bchWcGVDQgex+cdEi25PRJ9YqfgTNoA1EXYqVcilAUKBYxsEmpO2qll0uLhs au9zOblYVYw0CZAPdfj7/5hR6WyRKTdvUYZgsTWgCQRDTzNt9BeNb6W3tRbiJ8G17M MaEfUW86u/t1oTYAva+0z3ktZeVheXh5CO68B+Z5/KHwFyH9L1YSB8mrhLMNaE7zl2 UPm9/VvaazOtA== Date: Wed, 27 Mar 2024 00:05:20 +0900 From: Masami Hiramatsu (Google) To: "Jarkko Sakkinen" Cc: , "Paul Walmsley" , "Palmer Dabbelt" , "Albert Ou" , , "Luis Chamberlain" , , "Naveen N . Rao" , "Anil S Keshavamurthy" , "David S . Miller" Subject: Re: [PATCH v5 1/2] kprobes: textmem API Message-Id: <20240327000520.ec13b2646ed1cd621e5b1d9d@kernel.org> In-Reply-To: References: <20240325215502.660-1-jarkko@kernel.org> <20240326095836.f43d259b7747269a7c0b9d23@kernel.org> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Tue, 26 Mar 2024 15:18:21 +0200 "Jarkko Sakkinen" wrote: > On Tue Mar 26, 2024 at 4:01 AM EET, Jarkko Sakkinen wrote: > > On Tue Mar 26, 2024 at 3:31 AM EET, Jarkko Sakkinen wrote: > > > > > +#endif /* _LINUX_EXECMEM_H */ > > > > > diff --git a/kernel/kprobes.c b/kernel/kprobes.c > > > > > index 9d9095e81792..87fd8c14a938 100644 > > > > > --- a/kernel/kprobes.c > > > > > +++ b/kernel/kprobes.c > > > > > @@ -44,6 +44,7 @@ > > > > > #include > > > > > #include > > > > > #include > > > > > +#include > > > > > > > > > > #define KPROBE_HASH_BITS 6 > > > > > #define KPROBE_TABLE_SIZE (1 << KPROBE_HASH_BITS) > > > > > @@ -113,17 +114,17 @@ enum kprobe_slot_state { > > > > > void __weak *alloc_insn_page(void) > > > > > { > > > > > /* > > > > > - * Use module_alloc() so this page is within +/- 2GB of where the > > > > > + * Use alloc_execmem() so this page is within +/- 2GB of where the > > > > > * kernel image and loaded module images reside. This is required > > > > > * for most of the architectures. > > > > > * (e.g. x86-64 needs this to handle the %rip-relative fixups.) > > > > > */ > > > > > - return module_alloc(PAGE_SIZE); > > > > > + return alloc_execmem(PAGE_SIZE, GFP_KERNEL); > > > > > } > > > > > > > > > > static void free_insn_page(void *page) > > > > > { > > > > > - module_memfree(page); > > > > > + free_execmem(page); > > > > > } > > > > > > > > > > struct kprobe_insn_cache kprobe_insn_slots = { > > > > > @@ -1580,6 +1581,7 @@ static int check_kprobe_address_safe(struct kprobe *p, > > > > > goto out; > > > > > } > > > > > > > > > > +#ifdef CONFIG_MODULES > > > > > > > > You don't need this block, because these APIs have dummy functions. > > > > > > Hmm... I'll verify this tomorrow. > > > > It depends on having struct module available given "(*probed_mod)->state". Ah, indeed. We need module_state() function to avoid it. > > > > It is non-existent unless CONFIG_MODULES is set given how things are > > flagged in include/linux/module.h. > > Hey, noticed kconfig issue. > > According to kconfig-language.txt: > > "select should be used with care. select will force a symbol to a value > without visiting the dependencies." > > So the problem here lies in KPROBES config entry using select statement > to pick ALLOC_EXECMEM. It will not take the depends on statement into > account and thus will allow to select kprobes without any allocator in > place. OK, in that case "depend on" is good. > > So to address this I'd suggest to use depends on statement also for > describing relation between KPROBES and ALLOC_EXECMEM. It does not make > life worse than before for anyone because even with the current kernel > you have to select MODULES before you can move forward with kprobes. Yeah, since ALLOC_EXECMEM is enabled by default. Thank you! > > BR, Jarkko -- Masami Hiramatsu (Google)