Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4201278rdb; Mon, 11 Dec 2023 11:43:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IF5MtOVGH6Gc228H1KLPceqx2oC7dEOqLwuwUeAIvnHBkHVF7p8pycUOF9Va/x138JfIjvP X-Received: by 2002:a05:6a00:b87:b0:6ce:6f21:566c with SMTP id g7-20020a056a000b8700b006ce6f21566cmr6571600pfj.7.1702323799323; Mon, 11 Dec 2023 11:43:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702323799; cv=none; d=google.com; s=arc-20160816; b=CPpPdFqcv7QnXyuXpAcati2ADpFiTTHA9P8IW29s0D8zduMTL4JQX7T3ADTFwmVqoU 0iVD0jH4lURwtVolRvGmNXQbh2TW85aF9bAD3y440XzXuenCGQdhB55IyV4ZpCkxR9cb kW9ro/FvYPg1f6odrgEX7qYigUyJ5+Gpe2xxxS4VR59VfrFd2n8QxkIBb0DW5qAZkDvg eSuJPBe3hZ2NFsdgM8ESN5gylCsilzoDwQ04eK9B9Xx0EUDq9cE/eVLhhYjScYYG1yb7 qST06/FfihIDdCfUM21iZSym8SX84c5yw0Qp2U1F6z1YC3vDQu7TMn8gILgA0rfKRRRt qwEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=SHbD62vnUieHB3LgBj5kNhSvpPwhiruzSC2e8Ua11Yw=; fh=ZEYcDl4GLK87zDYniPABKQGmy9TYUqthtzIL1+w10so=; b=f5JhSPcsg050qNpmKiyablIucoV0L2XaXe7RtK4KR+CmY8Fext2JY4VtPl+iMJxXVO XO0hqtw61Qtq9fr33iwe1b2+7X5zMIaN9MonBTnPVau0BBxQQOCD3PjXxNhyuw4IaGbP AdEej9735b0jlVMle1dBRJD2XMu0tz5QC9K8KCrSCAmWC1paZxo4Z9kfygmRSHhObxHl Yyiz8klyY3ZeHLGdnI2TlXkHroc1StkNLzSmkybNqvjYXaprMfu38/C0TGowVLf77yXU AKkL/Fe9YrAweJQt+V4gHut4Gr4s0/ix5xs42OFgkKV2U1XTHeckCbvI+yUl8cu+R20x 47Aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=ejO1qmcD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id by26-20020a056a02059a00b005c6832282f7si6809023pgb.304.2023.12.11.11.43.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 11:43:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=ejO1qmcD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id D707B8093789; Mon, 11 Dec 2023 11:43:16 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344844AbjLKTnC (ORCPT + 99 others); Mon, 11 Dec 2023 14:43:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344839AbjLKTnB (ORCPT ); Mon, 11 Dec 2023 14:43:01 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC54AD0 for ; Mon, 11 Dec 2023 11:43:07 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 689E6C433C8; Mon, 11 Dec 2023 19:43:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1702323787; bh=P9nO0lI0Oyoyv1jHeWoc7C5Rh/xtPh/b1M+xSJ63B6s=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ejO1qmcDqnwmNWyow7QSq3OnuYlDX6RYwsIUXBjw9XzxO8ETyk48R5Y83g2rWMLoE FsIA7khIRJmQoP2anZeYhhwWuZUomjkJcJ+MB9SLY1JbRpEpgqGkf109l46uWe4RGI i0HLGHAq8tIg2u0giF87VpwMLS0rtNWw5Z1D3m9s= Date: Mon, 11 Dec 2023 11:43:06 -0800 From: Andrew Morton To: Andrei Vagin Cc: linux-kernel@vger.kernel.org, Amir Goldstein , Alexander Mikhalitsyn , Alexey Dobriyan , Al Viro Subject: Re: [PATCH 1/2] fs/proc: show correct device and inode numbers in /proc/pid/maps Message-Id: <20231211114306.08211860253a77c69bab2a87@linux-foundation.org> In-Reply-To: <20231211193048.580691-1-avagin@google.com> References: <20231211193048.580691-1-avagin@google.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 11 Dec 2023 11:43:17 -0800 (PST) On Mon, 11 Dec 2023 11:30:47 -0800 Andrei Vagin wrote: > Device and inode numbers in /proc/pid/maps have to match numbers returned by > statx for the same files. > > /proc/pid/maps shows device and inode numbers of vma->vm_file-s. Here is > an issue. If a mapped file is on a stackable file system (e.g., > overlayfs), vma->vm_file is a backing file whose f_inode is on the > underlying filesystem. To show correct numbers, we need to get a user > file and shows its numbers. The same trick is used to show file paths in > /proc/pid/maps. > > But it isn't the end of this story. A file system can manipulate inode numbers > within the getattr callback (e.g., ovl_getattr), so vfs_getattr must be used to > get correct numbers. Al, could you please comment on this? Thanks. > --- a/fs/proc/task_mmu.c > +++ b/fs/proc/task_mmu.c > @@ -273,9 +273,23 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma) > const char *name = NULL; > > if (file) { > - struct inode *inode = file_inode(vma->vm_file); > - dev = inode->i_sb->s_dev; > - ino = inode->i_ino; > + const struct path *path; > + struct kstat stat; > + > + path = file_user_path(file); > + /* > + * A file system can manipulate inode numbers within the > + * getattr callback (e.g. ovl_getattr). > + */ > + if (!vfs_getattr_nosec(path, &stat, STATX_INO, AT_STATX_DONT_SYNC)) { > + dev = stat.dev; > + ino = stat.ino; > + } else { > + struct inode *inode = d_backing_inode(path->dentry); > + > + dev = inode->i_sb->s_dev; > + ino = inode->i_ino; > + } > pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT; > } > > -- > 2.43.0.472.g3155946c3a-goog