Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5619395img; Wed, 27 Mar 2019 11:51:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqyotsVIeBPEVWCrPYCwww7jE1REaF8Q/2akqpfT3HWLpSgYbXBVF7/weqjom7M+KFC1Z72W X-Received: by 2002:aa7:8c13:: with SMTP id c19mr14362738pfd.225.1553712681227; Wed, 27 Mar 2019 11:51:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553712681; cv=none; d=google.com; s=arc-20160816; b=C7dbFAWfRDaCbfy9FqAm2eWxOucoX6D/Q+Hiw6qZbNRB/kyUi8aI4ypOhLw62uvcFs 4L5z7ozzRg2GCj1fdI//h6NezII9+shZV/dLdhy0sBHsYmpEJ6vF3oRBvfqLxAeycxCm 0urWia5D5A606bMz3tXNMnXJ9NI3GKKRe78lmWdPQOt8F7fKubhsYVeopsX58XkcBJf7 EMi/jc62QzqPg9GAz2vqJdJukDIF44tiY5xDIqLvBj4ktCkuY8tb6hYug6qs8VYVPZpA KDV1/fOwYZKqyjHZBcIV3s3qD72rhsPrM3wlV96WBn9EEhY/TNO3f6ZEqmik50Rlj3r4 E7+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=TAUq2ExNl6bOTjgAZ9UkIrdZWwV5meLmJgAKu/DHkTA=; b=ywUivy24ltbyONO+lLOEQpr3lAzTu35ONbIsKpJYNR9Gu8OxZSyLO60nVjwc2Xg5GF Pw2HnKDLQuS8nr8MGRC6OGm6DNS0jw1bHi1K8y/MhYJfnVlNJtVJMpo7fZUvrMLsCia3 u5kF1391p20or0O2CjIFxoJHnAz0aeigBRUvo85C3DY2EV8qPpvJ+nOmIukg1cPWocPo /p8Az3a/IthnimK7NZP6zkW5nYDt6VQwCF74/YPtzE8jBVNfB+k5i3htuUnrFcSh0vYo bjqi5UIK4sZ0eHTCeMP3BqThAa7c4ZrGXnYKFIgrnkpMdv+yn5WEDBuZBVtoS5FMdMhO U2KA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o12si20681465plg.221.2019.03.27.11.51.06; Wed, 27 Mar 2019 11:51:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390562AbfC0SSj (ORCPT + 99 others); Wed, 27 Mar 2019 14:18:39 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:49760 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2390539AbfC0SSe (ORCPT ); Wed, 27 Mar 2019 14:18:34 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4B2AECB9F3; Wed, 27 Mar 2019 18:18:33 +0000 (UTC) Received: from slave.localdomain.com (unknown [10.64.242.113]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7DC59111DCFB; Wed, 27 Mar 2019 18:18:31 +0000 (UTC) From: Masatake YAMATO To: linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk, akpm@linux-foundation.org Cc: linux-fsdevel@vger.kernel.org, yamato@redhat.com Subject: [PATCH v2] eventfd: prepare id to userspace via fdinfo Date: Thu, 28 Mar 2019 03:18:23 +0900 Message-Id: <20190327181823.20222-1-yamato@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 27 Mar 2019 18:18:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 27 Mar 2019 18:18:33 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'yamato@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Finding endpoints of an IPC channel is one of essential task to understand how a user program works. Procfs and netlink socket provide enough hints to find endpoints for IPC channels like pipes, unix sockets, and pseudo terminals. However, there is no simple way to find endpoints for an eventfd file from userland. An inode number doesn't hint. Unlike pipe, all eventfd files share the same inode object. To provide the way to find endpoints of an eventfd file, this patch adds "eventfd-id" field to /proc/PID/fdinfo of eventfd as identifier. Integers managed by an IDA are used as ids. A tool like lsof can utilize the information to print endpoints. Change in v2: Use integers as ids instead of memory addresses of eventfd contexts. Signed-off-by: Masatake YAMATO --- fs/eventfd.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/eventfd.c b/fs/eventfd.c index 08d3bd602f73..ce8fa15cebe5 100644 --- a/fs/eventfd.c +++ b/fs/eventfd.c @@ -21,6 +21,9 @@ #include #include #include +#include + +DEFINE_IDA(eventfd_ida); struct eventfd_ctx { struct kref kref; @@ -35,6 +38,7 @@ struct eventfd_ctx { */ __u64 count; unsigned int flags; + int id; }; /** @@ -69,6 +73,8 @@ EXPORT_SYMBOL_GPL(eventfd_signal); static void eventfd_free_ctx(struct eventfd_ctx *ctx) { + if (ctx->id >= 0) + ida_simple_remove(&eventfd_ida, ctx->id); kfree(ctx); } @@ -297,6 +303,7 @@ static void eventfd_show_fdinfo(struct seq_file *m, struct file *f) seq_printf(m, "eventfd-count: %16llx\n", (unsigned long long)ctx->count); spin_unlock_irq(&ctx->wqh.lock); + seq_printf(m, "eventfd-id: %d\n", ctx->id); } #endif @@ -400,6 +407,7 @@ static int do_eventfd(unsigned int count, int flags) init_waitqueue_head(&ctx->wqh); ctx->count = count; ctx->flags = flags; + ctx->id = ida_simple_get(&eventfd_ida, 0, 0, GFP_KERNEL); fd = anon_inode_getfd("[eventfd]", &eventfd_fops, ctx, O_RDWR | (flags & EFD_SHARED_FCNTL_FLAGS)); -- 2.17.2