mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: Brendan Jackman <jackmanb@google.com>,
	Kieran Bingham <kbingham@kernel.org>
Cc: Florian Rommel <mail@florommel.de>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] scripts/gdb: Add $lx_per_cpu_ptr()
Date: Thu, 20 Feb 2025 08:06:18 +0100	[thread overview]
Message-ID: <8ae2c5bc-7751-4635-8b4b-07f7366ffed0@siemens.com> (raw)
In-Reply-To: <20250219-lx-per-cpu-ptr-v1-1-b4492fc471e7@google.com>

On 19.02.25 16:40, Brendan Jackman wrote:
> We currently have $lx_per_cpu() which works fine for stuff that kernel
> code would access via per_cpu(). But this doesn't work for stuff that
> kernel code accesses via per_cpu_ptr():
> 
> (gdb) p $lx_per_cpu(node_data[1].node_zones[2]->per_cpu_pageset)
> Cannot access memory at address 0xffff11105fbd6c28
> 
> This is because we take the address of the pointer and use that as the
> offset, instead of using the stored value.
> 
> Add a GDB version that mirrors the kernel API, which uses the pointer
> value.
> 
> To be consistent with per_cpu_ptr(), we need to return the pointer value
> instead of dereferencing it for the user. Therefore, move the existing
> dereference out of the per_cpu() Python helper and do that only in the
> $lx_per_cpu() implementation.
> 
> Signed-off-by: Brendan Jackman <jackmanb@google.com>
> ---
>  scripts/gdb/linux/cpus.py | 21 +++++++++++++++++++--
>  1 file changed, 19 insertions(+), 2 deletions(-)
> 
> diff --git a/scripts/gdb/linux/cpus.py b/scripts/gdb/linux/cpus.py
> index 13eb8b3901b8fc5e2500138c7d204ac5f7c9858c..1f7e62efb38bf4ddee0058fea8634fd377317669 100644
> --- a/scripts/gdb/linux/cpus.py
> +++ b/scripts/gdb/linux/cpus.py
> @@ -46,7 +46,7 @@ def per_cpu(var_ptr, cpu):
>              # !CONFIG_SMP case
>              offset = 0
>      pointer = var_ptr.cast(utils.get_long_type()) + offset
> -    return pointer.cast(var_ptr.type).dereference()
> +    return pointer.cast(var_ptr.type)
>  
>  
>  cpu_mask = {}
> @@ -149,11 +149,28 @@ Note that VAR has to be quoted as string."""
>          super(PerCpu, self).__init__("lx_per_cpu")
>  
>      def invoke(self, var, cpu=-1):
> -        return per_cpu(var.address, cpu)
> +        return per_cpu(var.address, cpu).dereference()
>  
>  
>  PerCpu()
>  

Style nit: additional blank line here

> +class PerCpuPtr(gdb.Function):
> +    """Return per-cpu pointer.
> +
> +$lx_per_cpu_ptr("VAR"[, CPU]): Return the per-cpu pointer called VAR for the
> +given CPU number. If CPU is omitted, the CPU of the current context is used.
> +Note that VAR has to be quoted as string."""
> +
> +    def __init__(self):
> +        super(PerCpuPtr, self).__init__("lx_per_cpu_ptr")
> +
> +    def invoke(self, var, cpu=-1):
> +        return per_cpu(var, cpu)
> +
> +
> +PerCpuPtr()
> +
> +
>  def get_current_task(cpu):
>      task_ptr_type = task_type.get_type().pointer()
>  
> 
> ---
> base-commit: f527c5c2abb60ddfd6b929d479b985071500419d
> change-id: 20250219-lx-per-cpu-ptr-c9dfd3098721
> 
> Best regards,

Makes sense!

Reviewed-by: Jan Kiszka <jan.kiszka@siemens.com>

Jan

-- 
Siemens AG, Foundational Technologies
Linux Expert Center

      reply	other threads:[~2025-02-20  7:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-19 15:40 Brendan Jackman
2025-02-20  7:06 ` Jan Kiszka [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8ae2c5bc-7751-4635-8b4b-07f7366ffed0@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=jackmanb@google.com \
    --cc=kbingham@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mail@florommel.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®