From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7110EC64E7C for ; Wed, 2 Dec 2020 19:01:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C7D7F20DD4 for ; Wed, 2 Dec 2020 19:01:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C7D7F20DD4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D623F6B0036; Wed, 2 Dec 2020 14:01:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CED6B6B005C; Wed, 2 Dec 2020 14:01:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B8DF56B005D; Wed, 2 Dec 2020 14:01:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0240.hostedemail.com [216.40.44.240]) by kanga.kvack.org (Postfix) with ESMTP id A0AEA6B0036 for ; Wed, 2 Dec 2020 14:01:07 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 5E0B61EFD for ; Wed, 2 Dec 2020 19:01:07 +0000 (UTC) X-FDA: 77549259774.18.blood35_0c05bdf273b5 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id A68FD100ED0F8 for ; Wed, 2 Dec 2020 19:01:06 +0000 (UTC) X-HE-Tag: blood35_0c05bdf273b5 X-Filterd-Recvd-Size: 6761 Received: from mail-qt1-f196.google.com (mail-qt1-f196.google.com [209.85.160.196]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Wed, 2 Dec 2020 19:01:06 +0000 (UTC) Received: by mail-qt1-f196.google.com with SMTP id 7so1864077qtp.1 for ; Wed, 02 Dec 2020 11:01:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Ex6whwlqrxCFKKDxiBHCz0Iun6q+iHD48FG8thAt3fM=; b=tZMMtKfJdT15exuAK2gRKZczPljRL5vGy+JomKrE9H42xmQTdFNQFuShKRGDn/YksS LC1ZNOCv75/pxA90sPrT4F1AefQOXFNQAE9mixAmkr4jpYQFWC/TiOnPfKVbZYjvY0Gv h/lC/UrIJcWcFKb3pr6YdFT6TYPVos7Exrxfi8cBbK4TdwEF/hMvrLZ1jKPkwm3mQlkz y6GzvAmwoiF39s0B1Or8v7ZbC3ZXoKPN77URTZZGsOoUCLxjGR7q0QwtUFcTAEXO1CLw RiVmHrWQWld0eoAyfZ2dKPzW4yEEXc8Bn01MNnR6g+BBBBR2zN4BJOuLKXCGv/47xT8t gXBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=Ex6whwlqrxCFKKDxiBHCz0Iun6q+iHD48FG8thAt3fM=; b=rJHtqHffY7GVJ3fDVDK4qqv1elH7ChYzKsStzKfnRy5syqVLY2OI2szBV4KWueUUvq +zHpvPaV2XsfcqHpjP520ipGur931fI+tYQZlx6p4Or/ERDlmFF/C0LdcjKiaA2CxjDS kMHISk1R8D0oz5Np7oAHSQG31tRLdNb7xFx9COij11T9TsgWS1RlN/oauVfqMbIL+6fN FlBJ/uWXq3NqYE6pDBlQeePm/ONmSEv1e86BKn+U8eZKpeRe+JFYXjv2ct57KbmTxsFl jKhhJgW9irzU6G8Ng4u1Ma2eT8pJ5Ry6t8iImb6eLziZ+liOADRRpBJ9LKojMJY4yvLj mcGA== X-Gm-Message-State: AOAM5331AN+hvlbO14kWA0gCxPQ7ljy23U5+QDJm1WGvlS/OFDShh3QU w1Q+LKb8bDlApszqwPopW90= X-Google-Smtp-Source: ABdhPJxhHqhvqzx/xH94AgsGYWvBMWrtyiVjgIAbw0jjz8xci7x6+BUJMpxAWYS8J9g6a99eF7qm/A== X-Received: by 2002:ac8:7b85:: with SMTP id p5mr1791191qtu.264.1606935665249; Wed, 02 Dec 2020 11:01:05 -0800 (PST) Received: from localhost ([2620:10d:c091:480::1:8dbd]) by smtp.gmail.com with ESMTPSA id v13sm1546960qkb.130.2020.12.02.11.01.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 11:01:04 -0800 (PST) Date: Wed, 2 Dec 2020 14:00:37 -0500 From: Tejun Heo To: Shakeel Butt Cc: Axel Rasmussen , Greg Thelen , Andrew Morton , Chinwen Chang , Daniel Jordan , David Rientjes , Davidlohr Bueso , Ingo Molnar , Jann Horn , Laurent Dufour , Michel Lespinasse , Stephen Rothwell , Steven Rostedt , Vlastimil Babka , Yafang Shao , "David S . Miller" , dsahern@kernel.org, Greg Kroah-Hartman , Jakub Kicinski , liuhangbin@gmail.com, LKML , Linux MM Subject: Re: [PATCH] mm: mmap_lock: fix use-after-free race and css ref leak in tracepoints Message-ID: References: <20201130233504.3725241-1-axelrasmussen@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hello, On Tue, Dec 01, 2020 at 12:53:46PM -0800, Shakeel Butt wrote: > The writeback tracepoint in include/trace/events/writeback.h is > already using the cgroup IDs. Actually it used to use cgroup_path but > converted to cgroup_ino. > > Tejun, how do you use these tracepoints? There've been some changes to cgroup ids recently and now cgroup id, ino and its file_handle are all compatible. On 64bit ino machines, they're all the same and won't be reused. On 32bit ino machines, the lower 32bit of full id is used as ino. ino may be reused but not the full 64bit id. You can map back cgroup id to path from userspace using open_by_handle_at(). The following is an example program which does path -> cgrp id -> path mappings. #define _GNU_SOURCE #include #include #include #include #include #include #include #include #ifndef FILEID_KERNFS #define FILEID_KERNFS 0xfe #endif struct fh_store { struct file_handle fh; char stor[MAX_HANDLE_SZ]; }; uint64_t path_to_cgrp_id(const char *path) { struct fh_store fh_store; struct file_handle *fh = &fh_store.fh; int mnt_id; fh->handle_bytes = MAX_HANDLE_SZ; if (name_to_handle_at(AT_FDCWD, path, fh, &mnt_id, 0)) { perror("name_to_handle_at"); abort(); } if (fh->handle_type != FILEID_KERNFS) { fprintf(stderr, "invalid handle_type 0x%x\n", fh->handle_type); abort(); } return *(uint64_t *)fh->f_handle; } void cgrp_id_to_path(uint64_t cgrp_id, char *path_buf) { struct fh_store fh_store; struct file_handle *fh = &fh_store.fh; char proc_path[PATH_MAX]; int mnt_fd, fd; fh->handle_type = FILEID_KERNFS; fh->handle_bytes = sizeof(uint64_t); *(uint64_t *)fh->f_handle = cgrp_id; mnt_fd = open("/sys/fs/cgroup", O_RDONLY); if (mnt_fd < 0) { perror("open(\"/sys/fs/cgroup\")"); abort(); } fd = open_by_handle_at(mnt_fd, fh, O_RDONLY); if (fd < 0) { perror("open_by_handle_at"); abort(); } snprintf(proc_path, PATH_MAX, "/proc/self/fd/%d", fd); printf("proc_path=%s\n", proc_path); if (readlink(proc_path, path_buf, PATH_MAX) < 0) { perror("readlink"); abort(); } } int main(int argc, char **argv) { char path_buf[PATH_MAX + 1] = ""; uint64_t cgrp_id; if (argc != 2) { fprintf(stderr, "Usage: test-cgrp-id CGROUP_PATH\n"); return 1; } cgrp_id = path_to_cgrp_id(argv[1]); printf("cgrp_id=%llu\n", (unsigned long long)cgrp_id); cgrp_id_to_path(cgrp_id, path_buf); printf("cgrp_path=%s\n", path_buf); return 0; }