From patchwork Wed Nov 15 17:16:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 13457138 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 464BDC2BB3F for ; Wed, 15 Nov 2023 17:17:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=xxTPTK1P88NqHnRgV+Vox3vdDznghjtqNbUFHIY0Mas=; b=PjIO0HxTnAq2o43FxZnwO+lXdk v08tLxt0swhR/DC9YUyXD1lSiYK/ySe62YC5eVeG0LCjLEJWU8D8da8ieiqBYC4pEc97Bs39ZagZl 1yEle1NyEK3K/MkJjhivWHw2JjdxYeINAJpsA0FyVGuKNjZltsJWiyNcf4qwBeauzTj7QjFfZ99kP o4coHKT4GPleY6sw34Et6E/JJWZ2OCqip9g6Psr895qynZSAmSb97WtOm++yhrNuqCT28VLcDO0Nb 4rQtmzdYIpuq+PqQarszZmG68eT3XIauHPHwTBjfyO7XnX/5qPJf1+HJP1yTzlHoqNN6KSI8CdF92 3FGHJQ0g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r3JVp-001PXh-16; Wed, 15 Nov 2023 17:17:13 +0000 Received: from mail-ed1-x54a.google.com ([2a00:1450:4864:20::54a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r3JVk-001PTj-1u for linux-arm-kernel@lists.infradead.org; Wed, 15 Nov 2023 17:17:09 +0000 Received: by mail-ed1-x54a.google.com with SMTP id 4fb4d7f45d1cf-54366567af4so1439872a12.1 for ; Wed, 15 Nov 2023 09:17:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700068625; x=1700673425; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=jRY8TG/l5J/FMDXcrN4aaEldbJZIXmAxT86BWF/4hG4=; b=FGx+ThrrRZ61SfirpHCCOBxlAjJYK6NU1OCUnzP6NZMDMriKpMjEEJshIlN0hoMCsR /Z59vWAQ1qC62N+EEPb9+OTG7EfZ5xcw9CknFpXbi/1ytqnY3phyXrN2eNZhhlpPpzu3 bHUrvU14w6CJJRAsAmTD00JnILoQkrbgBJGm/FjhAxBR3hg8l9GLxW4NFIm7YOc+f1Hf eKo8gtFnHkPukJGvsic7ZYdMVo0rHRILDtBi8FsKLl8DrW1FXToEUc17hhuH7xVQWuVF g22pUNIz5aRJJGySbuoASodyITAiUAzzx6WLeUSzcB6dC05OFK373PfK8WNIcsgH+tY9 SPTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700068625; x=1700673425; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jRY8TG/l5J/FMDXcrN4aaEldbJZIXmAxT86BWF/4hG4=; b=XU6eONvO0PMnKZ6jwKmJ2JrHVAX7tBnXpB1NZHGdArUD3ZTSfUyir6fsO9RpAmm4tC CuS+09xGd7KVv/eJbZnekNiP6BFdxkO9L2aqG1RF1/ohRLf9/HER8KDXjKzWOZFJTVYB 4DntKIWhT3yR54FPGMxUEJ9jmZxUjVmeY7dKAwIV9JbLoLWw9FeNUQfZ969ZdvwOn4jm RIWr4Dytf6PUXtK6Lrq7BtLYhbsFmoBonboy8eXH5dUDMrBVFZBCL8eB8XDkFbCQCOrj gwxdKxqXY1dX2wT+1oWZ62M5pMU1qOqgziDn3SLqzvj9liCa69nt3dfmS1L/KcakIAw/ 6BUA== X-Gm-Message-State: AOJu0YyUZw0Jv9HougjCCGBw7fnfiw/b/vIb1RRoC+hDdrHb9/gPqwWb TWZLu/9TVOmGIU+6eUq48DUmz3yFV/EG703rTr0= X-Google-Smtp-Source: AGHT+IEOG5AerWV4vOx8AuRc42o64gL06+fbFGWcKCfeIT2GBbZFlEcOhn/Yr4W2MhCZYOUvUqW8pWEYcTbHukKLs3o= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:a05:6402:156:b0:53d:ad8a:b0bd with SMTP id s22-20020a056402015600b0053dad8ab0bdmr104536edu.3.1700068625280; Wed, 15 Nov 2023 09:17:05 -0800 (PST) Date: Wed, 15 Nov 2023 17:16:35 +0000 In-Reply-To: <20231115171639.2852644-2-sebastianene@google.com> Mime-Version: 1.0 References: <20231115171639.2852644-2-sebastianene@google.com> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog Message-ID: <20231115171639.2852644-7-sebastianene@google.com> Subject: [PATCH v3 05/10] arm64: ptdump: Add hooks on debugfs file operations From: Sebastian Ene To: will@kernel.org, Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, vdonnefort@google.com, qperret@google.com, smostafa@google.com, Sebastian Ene X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231115_091708_628901_C9FCF07D X-CRM114-Status: GOOD ( 16.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Introduce callbacks invoked when the debugfs entry is accessed from userspace. This hooks will allow us to allocate and prepare the memory resources used by ptdump when the debugfs file is opened/closed. Signed-off-by: Sebastian Ene --- arch/arm64/include/asm/ptdump.h | 7 +++++ arch/arm64/mm/ptdump_debugfs.c | 53 +++++++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h index 1f6e0aabf16a..9b2bebfcefbe 100644 --- a/arch/arm64/include/asm/ptdump.h +++ b/arch/arm64/include/asm/ptdump.h @@ -20,9 +20,16 @@ struct ptdump_info { const struct addr_marker *markers; unsigned long base_addr; void (*ptdump_walk)(struct seq_file *s, struct ptdump_info *info); + int (*ptdump_prepare_walk)(void *file_priv); + void (*ptdump_end_walk)(void *file_priv); }; void ptdump_walk(struct seq_file *s, struct ptdump_info *info); + +struct ptdump_info_file_priv { + struct ptdump_info info; + void *file_priv; +}; #ifdef CONFIG_PTDUMP_DEBUGFS #define EFI_RUNTIME_MAP_END DEFAULT_MAP_WINDOW_64 void __init ptdump_debugfs_register(struct ptdump_info *info, const char *name); diff --git a/arch/arm64/mm/ptdump_debugfs.c b/arch/arm64/mm/ptdump_debugfs.c index 7564519db1e6..3bf5de51e8c3 100644 --- a/arch/arm64/mm/ptdump_debugfs.c +++ b/arch/arm64/mm/ptdump_debugfs.c @@ -7,7 +7,8 @@ static int ptdump_show(struct seq_file *m, void *v) { - struct ptdump_info *info = m->private; + struct ptdump_info_file_priv *f_priv = m->private; + struct ptdump_info *info = &f_priv->info; get_online_mems(); if (info->ptdump_walk) @@ -15,7 +16,55 @@ static int ptdump_show(struct seq_file *m, void *v) put_online_mems(); return 0; } -DEFINE_SHOW_ATTRIBUTE(ptdump); + +static int ptdump_open(struct inode *inode, struct file *file) +{ + int ret; + struct ptdump_info *info = inode->i_private; + struct ptdump_info_file_priv *f_priv; + + f_priv = kzalloc(sizeof(struct ptdump_info_file_priv), GFP_KERNEL); + if (!f_priv) + return -ENOMEM; + + memcpy(&f_priv->info, info, sizeof(*info)); + + ret = single_open(file, ptdump_show, f_priv); + if (ret) { + kfree(f_priv); + return ret; + } + + if (info->ptdump_prepare_walk) { + ret = info->ptdump_prepare_walk(f_priv); + if (ret) + kfree(f_priv); + } + + return ret; +} + +static int ptdump_release(struct inode *inode, struct file *file) +{ + struct seq_file *f = file->private_data; + struct ptdump_info_file_priv *f_priv = f->private; + struct ptdump_info *info = &f_priv->info; + + if (info->ptdump_end_walk) + info->ptdump_end_walk(f_priv); + + kfree(f_priv); + + return single_release(inode, file); +} + +static const struct file_operations ptdump_fops = { + .owner = THIS_MODULE, + .open = ptdump_open, + .read = seq_read, + .llseek = seq_lseek, + .release = ptdump_release, +}; void __init ptdump_debugfs_register(struct ptdump_info *info, const char *name) {