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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F989C433FE for ; Thu, 23 Dec 2021 05:12:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D9126B0072; Thu, 23 Dec 2021 00:12:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 888D26B0073; Thu, 23 Dec 2021 00:12:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 74FDB6B0074; Thu, 23 Dec 2021 00:12:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0083.hostedemail.com [216.40.44.83]) by kanga.kvack.org (Postfix) with ESMTP id 650F26B0072 for ; Thu, 23 Dec 2021 00:12:13 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 1144D181AC9C6 for ; Thu, 23 Dec 2021 05:12:13 +0000 (UTC) X-FDA: 78947887746.07.ECAEEF1 Received: from mail-io1-f53.google.com (mail-io1-f53.google.com [209.85.166.53]) by imf08.hostedemail.com (Postfix) with ESMTP id 84BAA160013 for ; Thu, 23 Dec 2021 05:12:05 +0000 (UTC) Received: by mail-io1-f53.google.com with SMTP id e128so5637626iof.1 for ; Wed, 22 Dec 2021 21:12:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=UuLwAbQ1jnMAbt5WK9pjv43q57hnU7ZpBUC8SgtaEwY=; b=JWxLbg9g+XejRLq6wFQZpd5b0q8gKjHY9sZebAr8x3oA25Db6O6zBt+GFcAjAvPT3H BahMkHRUOAEN7R1iUuzMEy0mfXFv40fkjxw3ivHYwmdssofubyraMQ5fq6XVoFo0EIcb nxrJuKTASdTWnHPwcAjTKPvCEB4fEutD3Q8tj6hjfBzYBVEcw+ec5mCSIyJRHfkwOYoB c/hqjuX9DQql7KXadsl0y8DOA1BDqaxiQGcuvd5REVk6/tcZWyyBcxSs5q7UnUx3wvZx aIDa0hOJLkULAyCMDQ+4KE1yP31Jvg6pnnz3jasOpPWN5g1tK4fLwfAhWBaY8YOpiNpP WCng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=UuLwAbQ1jnMAbt5WK9pjv43q57hnU7ZpBUC8SgtaEwY=; b=zrWsLKDEkUYRBrWUtVqZpK8QJlHV1j0KMg5qXSfhJ0SK+dSwZQAmbe5+w6N7igYkDr haA2ioj+qUxZEs4m8rmuUcIkv8TyMnhyps/w60UiDVt3729STujJMmhNYIUEFPoYBuU8 suFBw14pXjWTs1P5HpZRNRTO6V5TwZ8Jd4H8QFCqHNuxNO3FNpVKZXLsOdRQ1Iw7qe/R uxH5Wv3B3QlmlNbj+dgE8w+eLP3sVQywxAMVqCouSa/3Rxka4AZh0HKl7TCb2TmJBHko Nc+kGQ45amW5pTOMeGmfZ6KpF1YQex0cvSIJ/haXDqxw/X5fMQ98hIkUw9fvScCxh/bC 5/mA== X-Gm-Message-State: AOAM531C3ppl0vXDOnouv9Uv+rizMbB3K6g6aHfJD0qG7Fq/eXOUX1TQ kHnn8TKlnp9JPyBxwpYRvAI= X-Google-Smtp-Source: ABdhPJyFfKXX+2kAlC6TqGgP8VNft2z3Dloqkcrd5Ea90+WU9dHoDi+7biR8HedP8N/IurSGrGM8Mg== X-Received: by 2002:a05:6638:2402:: with SMTP id z2mr365165jat.200.1640236331920; Wed, 22 Dec 2021 21:12:11 -0800 (PST) Received: from smtpclient.apple ([2601:285:8200:efd:acef:6a41:306c:188b]) by smtp.gmail.com with ESMTPSA id k7sm2648838iov.40.2021.12.22.21.12.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Dec 2021 21:12:11 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 15.0 \(3693.40.0.1.81\)) Subject: Re: [PATCH] mm,fs: Split dump_mapping() out from dump_page() From: William Kucharski In-Reply-To: <20211121121056.2870061-1-willy@infradead.org> Date: Wed, 22 Dec 2021 22:12:09 -0700 Cc: Andrew Morton , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Vlastimil Babka , Michal Hocko Content-Transfer-Encoding: quoted-printable Message-Id: <0DC4DA13-319E-4EA3-B154-761D1D20FFD5@gmail.com> References: <20211121121056.2870061-1-willy@infradead.org> To: "Matthew Wilcox (Oracle)" X-Mailer: Apple Mail (2.3693.40.0.1.81) X-Rspamd-Queue-Id: 84BAA160013 X-Stat-Signature: 3t4zb9mdr8okdcb9ihfe4qo5zkp567ti Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=JWxLbg9g; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf08.hostedemail.com: domain of kucharsk@gmail.com designates 209.85.166.53 as permitted sender) smtp.mailfrom=kucharsk@gmail.com X-Rspamd-Server: rspam02 X-HE-Tag: 1640236325-938463 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: Looks good to me. Reviewed-by: William Kucharski > On Nov 21, 2021, at 5:10 AM, Matthew Wilcox (Oracle) = wrote: >=20 > dump_mapping() is a big chunk of dump_page(), and it'd be handy to be > able to call it when we don't have a struct page. Split it out and = move > it to fs/inode.c. Take the opportunity to simplify some of the debug > messages a little. >=20 > Signed-off-by: Matthew Wilcox (Oracle) > --- > fs/inode.c | 49 +++++++++++++++++++++++++++++++++++++++++++ > include/linux/fs.h | 1 + > mm/debug.c | 52 ++-------------------------------------------- > 3 files changed, 52 insertions(+), 50 deletions(-) >=20 > diff --git a/fs/inode.c b/fs/inode.c > index bdfbd5962f2b..67758b2b702f 100644 > --- a/fs/inode.c > +++ b/fs/inode.c > @@ -522,6 +522,55 @@ void __remove_inode_hash(struct inode *inode) > } > EXPORT_SYMBOL(__remove_inode_hash); >=20 > +void dump_mapping(const struct address_space *mapping) > +{ > + struct inode *host; > + const struct address_space_operations *a_ops; > + struct hlist_node *dentry_first; > + struct dentry *dentry_ptr; > + struct dentry dentry; > + unsigned long ino; > + > + /* > + * If mapping is an invalid pointer, we don't want to crash > + * accessing it, so probe everything depending on it carefully. > + */ > + if (get_kernel_nofault(host, &mapping->host) || > + get_kernel_nofault(a_ops, &mapping->a_ops)) { > + pr_warn("invalid mapping:%px\n", mapping); > + return; > + } > + > + if (!host) { > + pr_warn("aops:%ps\n", a_ops); > + return; > + } > + > + if (get_kernel_nofault(dentry_first, &host->i_dentry.first) || > + get_kernel_nofault(ino, &host->i_ino)) { > + pr_warn("aops:%ps invalid inode:%px\n", a_ops, host); > + return; > + } > + > + if (!dentry_first) { > + pr_warn("aops:%ps ino:%lx\n", a_ops, ino); > + return; > + } > + > + dentry_ptr =3D container_of(dentry_first, struct dentry, = d_u.d_alias); > + if (get_kernel_nofault(dentry, dentry_ptr)) { > + pr_warn("aops:%ps ino:%lx invalid dentry:%px\n", > + a_ops, ino, dentry_ptr); > + return; > + } > + > + /* > + * if dentry is corrupted, the %pd handler may still crash, > + * but it's unlikely that we reach here with a corrupt mapping > + */ > + pr_warn("aops:%ps ino:%lx dentry name:\"%pd\"\n", a_ops, ino, = &dentry); > +} > + > void clear_inode(struct inode *inode) > { > /* > diff --git a/include/linux/fs.h b/include/linux/fs.h > index d6a4eb6cf825..acaad2b0d5b9 100644 > --- a/include/linux/fs.h > +++ b/include/linux/fs.h > @@ -3149,6 +3149,7 @@ extern void unlock_new_inode(struct inode *); > extern void discard_new_inode(struct inode *); > extern unsigned int get_next_ino(void); > extern void evict_inodes(struct super_block *sb); > +void dump_mapping(const struct address_space *); >=20 > /* > * Userspace may rely on the the inode number being non-zero. For = example, glibc > diff --git a/mm/debug.c b/mm/debug.c > index fae0f81ad831..b3ebfab21cb3 100644 > --- a/mm/debug.c > +++ b/mm/debug.c > @@ -110,56 +110,8 @@ static void __dump_page(struct page *page) > type =3D "ksm "; > else if (PageAnon(page)) > type =3D "anon "; > - else if (mapping) { > - struct inode *host; > - const struct address_space_operations *a_ops; > - struct hlist_node *dentry_first; > - struct dentry *dentry_ptr; > - struct dentry dentry; > - unsigned long ino; > - > - /* > - * mapping can be invalid pointer and we don't want to = crash > - * accessing it, so probe everything depending on it = carefully > - */ > - if (get_kernel_nofault(host, &mapping->host) || > - get_kernel_nofault(a_ops, &mapping->a_ops)) { > - pr_warn("failed to read mapping contents, not a = valid kernel address?\n"); > - goto out_mapping; > - } > - > - if (!host) { > - pr_warn("aops:%ps\n", a_ops); > - goto out_mapping; > - } > - > - if (get_kernel_nofault(dentry_first, = &host->i_dentry.first) || > - get_kernel_nofault(ino, &host->i_ino)) { > - pr_warn("aops:%ps with invalid host inode = %px\n", > - a_ops, host); > - goto out_mapping; > - } > - > - if (!dentry_first) { > - pr_warn("aops:%ps ino:%lx\n", a_ops, ino); > - goto out_mapping; > - } > - > - dentry_ptr =3D container_of(dentry_first, struct dentry, = d_u.d_alias); > - if (get_kernel_nofault(dentry, dentry_ptr)) { > - pr_warn("aops:%ps ino:%lx with invalid dentry = %px\n", > - a_ops, ino, dentry_ptr); > - } else { > - /* > - * if dentry is corrupted, the %pd handler may = still > - * crash, but it's unlikely that we reach here = with a > - * corrupted struct page > - */ > - pr_warn("aops:%ps ino:%lx dentry = name:\"%pd\"\n", > - a_ops, ino, &dentry); > - } > - } > -out_mapping: > + else if (mapping) > + dump_mapping(mapping); > BUILD_BUG_ON(ARRAY_SIZE(pageflag_names) !=3D __NR_PAGEFLAGS + = 1); >=20 > pr_warn("%sflags: %#lx(%pGp)%s\n", type, head->flags, = &head->flags, > --=20 > 2.33.0 >=20 >=20