From patchwork Thu Oct 19 14:40:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 13429343 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 64D72CDB465 for ; Thu, 19 Oct 2023 14:41:45 +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=vUX3tpzkMjshSJy6eNLIpb1frNrCEA+Tp/N84ZH7Rx0=; b=IaQOYp1oB9SSoAC0rs7hTFujIj AowNMORNSiOrHMNhmO0C+nQcsub2PnzmcHmjEPi07sCCdQccQlo2GqjbCAkhQwouLWZG9t17lNKaH adqRrS6/x+SkX3m+pNM19s7RRoRzgqn9laOLrI+r0gdGGIH1nJhVPluJdV1r2sEpuNIk5eohQbyWt vKfjbNCXqC491iZ5gjnMufe0RChF+XBXT/nA0xhMqsGD4YZja6NVsZaIBUFDZdafl6SGmF/+6vrDA CSJTsRbbte8HAZZqxNvi8Bi0cghTGTya0072z3qeiBzekM/xfQm+3S6vp3mZW3QRdiz79aszGV/1L 1Fd77dMg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qtUD7-0006SE-33; Thu, 19 Oct 2023 14:41:18 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qtUCq-0006He-0E for linux-arm-kernel@lists.infradead.org; Thu, 19 Oct 2023 14:41:01 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a7cfdacf8fso7106217b3.0 for ; Thu, 19 Oct 2023 07:40:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697726458; x=1698331258; 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=xM59NTfupiUDLHnq4Q6FLBD9y4loLd8ebx5nbjkuBV4=; b=x2anHkeRsbUpHh3EwiJkbOGS9UMUwiRkJVGGsKydcGkKH1XYvWmKJ4BspWNNYT5ZAS itS3gJPCbcKaBibnnboiMi31iDu9q8LJBOPFH0PqpPr+3dIY84vLouIAxdWHtlirtWyi YzC1ORNv53zL0CxyabN1z15kvLfCBz/hdcbIentkzp7KWa+UPypIikKl6nIpePpwtUNP HG6PvzPc47/0UKNg+FXqv85bIPmv3kochfT36vDupCwp41O3TsX/J7cAoBhAF570zaQk X68tNQ3oSjV+jFwFGCWgnvSLr1XAA9kAh3njXxYURT2SABEe5mUUMB79gDzsgDLNNHzU 41lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697726458; x=1698331258; 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=xM59NTfupiUDLHnq4Q6FLBD9y4loLd8ebx5nbjkuBV4=; b=IVMX3LwXqXQvyvZRnZyYpYkJSes+QwvWewYqznVgUrq5a/JGUVg6uFxKTuZaCbp+sR KcaI9GxQcRKwZ2x42srD3F7LDx4rAPcVCIhcZOHfJIAtlKH52eUDKDRlUfPacifhaJBf /QojfWCrLuYJh9H/fr/xbaPMEHqldiA4ZWnH+WoANAwEptpu0i/lFCkcZ1qBBs/m+qMJ 0WiaD9yJW5VA+WuCm/guk5k/BIxTC77KLgsb3ClhsIY4cNU9o2ZkTuLNofww9naIoueh 9K+iob0hD+CQA+58BeEEI0oSFPp7kiF6BebaiibvWzfMBJjnDm5qxSgN7NTGe5Q1woCz Icpw== X-Gm-Message-State: AOJu0YyoEtj+54DTKWlyHkcBlR1EL4ixz5hxUud2+ybsGplRMFyNiS9o ZKYa0/oWYS9PQIE8xflugUbaMgr72NlLSZnVyaQ= X-Google-Smtp-Source: AGHT+IG8PnUAgdVOzgFJnXSouFnnC8HLG+an2r3K1uH0YuVQiR/aIH437YP18wYS6/QUlklnP1Kr3S2Yt4L3/KAbUeU= X-Received: from seb.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:31bd]) (user=sebastianene job=sendgmr) by 2002:a05:6902:691:b0:d9a:fd4d:d536 with SMTP id i17-20020a056902069100b00d9afd4dd536mr51027ybt.3.1697726458604; Thu, 19 Oct 2023 07:40:58 -0700 (PDT) Date: Thu, 19 Oct 2023 14:40:28 +0000 In-Reply-To: <20231019144032.2943044-1-sebastianene@google.com> Mime-Version: 1.0 References: <20231019144032.2943044-1-sebastianene@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231019144032.2943044-8-sebastianene@google.com> Subject: [PATCH v2 06/11] arm64: ptdump: Add hooks on debugfs file operations From: Sebastian Ene To: will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: 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-20231019_074100_119065_EE906906 X-CRM114-Status: GOOD ( 16.81 ) 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 | 3 +++ arch/arm64/mm/ptdump.c | 1 + arch/arm64/mm/ptdump_debugfs.c | 34 ++++++++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h index 1f6e0aabf16a..88dcab1dab97 100644 --- a/arch/arm64/include/asm/ptdump.h +++ b/arch/arm64/include/asm/ptdump.h @@ -19,7 +19,10 @@ struct ptdump_info { struct mm_struct *mm; const struct addr_marker *markers; unsigned long base_addr; + void (*ptdump_prepare_walk)(struct ptdump_info *info); void (*ptdump_walk)(struct seq_file *s, struct ptdump_info *info); + void (*ptdump_end_walk)(struct ptdump_info *info); + struct mutex file_lock; }; void ptdump_walk(struct seq_file *s, struct ptdump_info *info); diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 58a4ea975497..fe239b9af50c 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -24,6 +24,7 @@ #include #include #include +#include #include diff --git a/arch/arm64/mm/ptdump_debugfs.c b/arch/arm64/mm/ptdump_debugfs.c index 7564519db1e6..14619452dd8d 100644 --- a/arch/arm64/mm/ptdump_debugfs.c +++ b/arch/arm64/mm/ptdump_debugfs.c @@ -15,7 +15,39 @@ 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; + + ret = single_open(file, ptdump_show, inode->i_private); + if (!ret && info->ptdump_prepare_walk) { + mutex_lock(&info->file_lock); + info->ptdump_prepare_walk(info); + } + return ret; +} + +static int ptdump_release(struct inode *inode, struct file *file) +{ + struct ptdump_info *info = inode->i_private; + + if (info->ptdump_end_walk) { + info->ptdump_end_walk(info); + mutex_unlock(&info->file_lock); + } + + 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) {