From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9909126A08F for ; Tue, 24 Mar 2026 16:00:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774368024; cv=none; b=nJSH5P2bRqjqspyFjt9EWT3EK6jtWDgbN36tmMovYcN53KkMTsSaD6LVWDybathyYqFvVZUVVvmahsudI4SQfRvial9X/tu20YHhOQeMUcd4z/30s6X6bwIj91/Evbw1MpurN635aaHc91quQMZ6Z8qlbyIJSeT2P2ODh4OTPSA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774368024; c=relaxed/simple; bh=o+cMkXZ4AL0yvc8YxODTxfgOpONgzCRH94hoPaiSk6g=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=oQeXOJs4vDISNP0ac+cI7N/qFkNEHCc3CPIMBW7Dwc/tE072SfequGC7KKqcSyMsF6OdpJJFEcWpODGdyWPNja2X4EI1oXHG11CIfzMYXcwqnUD0h+iUlqjouojZKVVprdQaQdgyJcrlkSz4Kw/06LpMn9vnI166z2S9KvpmAwA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=KkAkN/7n; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="KkAkN/7n" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-486fd27754bso12025075e9.3 for ; Tue, 24 Mar 2026 09:00:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1774368021; x=1774972821; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=JZud2txb2+gokYF6qCswpOqRe8hThYc5D0An7F/T1G0=; b=KkAkN/7nZwFHSlOrMHhFIszI7EZfNiGhn2NZaPp3knF8FbvT7qhEsjnixr18ZsPQ8F Np694D1YOe7BoBzB06L6vrk44wLjWMWnkgXEjYUCNuk/nUAcrOazMZ/scQP6rctvOpQ8 LlUa3xx/PjV6E1b47uLOkTh4GrxZBh25woSoYps5wJzpOkbCjEWWEtHoIFpGIpZoSFIj FX+VQxihc19Umdtg1EwdS+Qt0Q/v4QCIIVnV5969BwS118bpndgeKe1mzo4Y6KDlWneV JFTCVf11QpRpe1vcHy7jPH+oE6oAejDbwwylsLzsf9nhEs0vc51h886yPsVqpln9Xq5q 3JFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774368021; x=1774972821; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JZud2txb2+gokYF6qCswpOqRe8hThYc5D0An7F/T1G0=; b=Sce9Sa4D9bt6ZirGACi4W2RV6J3GNQmBqr0Uiy+mF10q2qTYiygsagq0SQwdc0ATtl roeZfX8VrgMXRDeBCQK2GkOZxwzmYP/ln9lk+azksy2B7nLqmWVMShtiwCFEUstlZMfs jQ36A7nDx5qanopeGa2uNyQuavBUJr6TGcGuKLBcSpJ450Au5w1XYQAU85BWKYnhl/NO uJtyfvZzR8LZsDtLOYbw5iLyKrnea0o+uFK90KolZC4SOZJboktJxWurLwwTYMOGDv34 BF/cFuiBBWdo9IWQpvPz2JqhCf7BBcK67MtgyjB9szkbTaQUk7xSsrlOKKgBwuymvKqx eOkg== X-Forwarded-Encrypted: i=1; AJvYcCVOIBmYDFrvmeFP33sQtBFrhaZwzjYd6U7W8cB4Llw1GF+KqGZ28nzKIcOzOFbFFK4niOnyhrJUBRWMjXU=@vger.kernel.org X-Gm-Message-State: AOJu0YxZhGSmTWx9+AQTzn22mnoh4XVQq+LzuLZBPrJMVsXlDl+ug5xM DEjKxKg7YYWilek5iHluntoBtRvT/Z5HHXdFeN6GrCm2HpT7k07pkpW6+GmbBxGLmc0= X-Gm-Gg: ATEYQzzhJ0zi6/OlFNnmt9kAOg7LkZMKQ+Gi+3Z4pq4+k9s3jKwvHXsduomR8VWnYTy E/tdTVLSks7HYqERS87+pooIxJXaJjgr05koCu9axG9kFi8QJNRpWBPsH4wd9lvBeJA/87l8jCR aYEPMnCnVMt6QW+ks4Ov0gcr3ZfscvSoVrllJCDJ7ioQj09n0CmFNYW9Iy53v1Z3+5yRH3UoYdu 8rVmZdGCIxp4Cd/wG2pXAlheEBD5Jq+dAacuCt95CvtX6j0t/vCVb8EFlLHQTbiRHfGtgP52PFz dQNE5Kcs+uOt6M5hfJKjPXnhWiPSvimTqRB2yrM64oBYt07NmmXqZ4XNeSmQgOrwl1Vq8BUPBso edk8M4Wd+m/37TF2epU2v9zBmSaeGO8mIOS2hYIgsnWoV0dP+ytORLTnLhxhHCBKfnHjWzUDhO1 JWh3XrAaM8oEMMbZQNG7hM4l+UbXNOl7bAGJYiI9eUdxok X-Received: by 2002:a05:600c:8b31:b0:485:30f7:6e88 with SMTP id 5b1f17b1804b1-487160881a5mr4153985e9.31.1774368020765; Tue, 24 Mar 2026 09:00:20 -0700 (PDT) Received: from [10.100.51.209] (nat2.prg.suse.com. [195.250.132.146]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-487113c4eb3sm68147455e9.0.2026.03.24.09.00.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 24 Mar 2026 09:00:20 -0700 (PDT) Message-ID: <282574df-7689-4677-929b-b844e7201bd5@suse.com> Date: Tue, 24 Mar 2026 17:00:19 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] module/kallsyms: sort function symbols and use binary search To: Stanislaw Gruszka Cc: linux-modules@vger.kernel.org, Sami Tolvanen , Luis Chamberlain , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, live-patching@vger.kernel.org, Daniel Gomez , Aaron Tomlin , Steven Rostedt , Masami Hiramatsu , Jordan Rome , Viktor Malik References: <20260317110423.45481-1-stf_xl@wp.pl> <20260324125304.GA15972@wp.pl> Content-Language: en-US From: Petr Pavlu In-Reply-To: <20260324125304.GA15972@wp.pl> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 3/24/26 1:53 PM, Stanislaw Gruszka wrote: > Hi, > > On Mon, Mar 23, 2026 at 02:06:43PM +0100, Petr Pavlu wrote: >> On 3/17/26 12:04 PM, Stanislaw Gruszka wrote: >>> Module symbol lookup via find_kallsyms_symbol() performs a linear scan >>> over the entire symtab when resolving an address. The number of symbols >>> in module symtabs has grown over the years, largely due to additional >>> metadata in non-standard sections, making this lookup very slow. >>> >>> Improve this by separating function symbols during module load, placing >>> them at the beginning of the symtab, sorting them by address, and using >>> binary search when resolving addresses in module text. >> >> Doesn't considering only function symbols break the expected behavior >> with CONFIG_KALLSYMS_ALL=y. For instance, when using kdb, is it still >> able to see all symbols in a module? The module loader should be remain >> consistent with the main kallsyms code regarding which symbols can be >> looked up. > > We already have a CONFIG_KALLSYMS_ALL=y inconsistency between kernel and > module symbol lookup, independent of this patch. find_kallsyms_symbol() > restricts the search to MOD_TEXT (or MOD_INIT_TEXT) address ranges, so > it cannot resolve data or rodata symbols. My understanding is that find_kallsyms_symbol() can identify all symbols in a module by their addresses. However, the issue I see with MOD_TEXT/MOD_INIT_TEXT is that the function may incorrectly calculate the size of symbols that are not within these ranges, which is a bug that should be fixed. A test using kdb confirms that non-text symbols can be found by their addresses. The following shows the current behavior with 7.0-rc5 when printing a module parameter in mlx4_en: [1]kdb> mds __param_arr_num_vfs 0xffffffffc1209f20 0000000100000003 ........ 0xffffffffc1209f28 ffffffffc0fbf07c [mlx4_core]num_vfs_argc 0xffffffffc1209f30 ffffffff8844bba0 param_ops_byte 0xffffffffc1209f38 ffffffffc0fbf080 [mlx4_core]num_vfs 0xffffffffc1209f40 000000785f69736d msi_x... 0xffffffffc1209f48 656c5f6775626564 debug_le 0xffffffffc1209f50 00000000006c6576 vel..... 0xffffffffc1209f58 0000000000000000 ........ .. and the behavior with the proposed patch: [1]kdb> mds __param_arr_num_vfs 0xffffffffc1077f20 0000000100000003 ........ 0xffffffffc1077f28 ffffffffc104707c |p...... 0xffffffffc1077f30 ffffffffb4a4bba0 param_ops_byte 0xffffffffc1077f38 ffffffffc1047080 .p...... 0xffffffffc1077f40 000000785f69736d msi_x... 0xffffffffc1077f48 656c5f6775626564 debug_le 0xffffffffc1077f50 00000000006c6576 vel..... 0xffffffffc1077f58 0000000000000000 ........ -- Thanks, Petr