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=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 8437CC433E0 for ; Mon, 18 Jan 2021 08:00:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0C9FD2255F for ; Mon, 18 Jan 2021 08:00:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0C9FD2255F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4F17F6B0284; Mon, 18 Jan 2021 03:00:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 47A576B02DC; Mon, 18 Jan 2021 03:00:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 342516B02FA; Mon, 18 Jan 2021 03:00:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 17C346B0284 for ; Mon, 18 Jan 2021 03:00:27 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id BE73A181AF5C7 for ; Mon, 18 Jan 2021 08:00:26 +0000 (UTC) X-FDA: 77718148452.10.tiger78_2e096f027547 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin10.hostedemail.com (Postfix) with ESMTP id 9261116A4B8 for ; Mon, 18 Jan 2021 08:00:26 +0000 (UTC) X-HE-Tag: tiger78_2e096f027547 X-Filterd-Recvd-Size: 4469 Received: from mail-io1-f47.google.com (mail-io1-f47.google.com [209.85.166.47]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Mon, 18 Jan 2021 08:00:26 +0000 (UTC) Received: by mail-io1-f47.google.com with SMTP id u17so31165357iow.1 for ; Mon, 18 Jan 2021 00:00:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=8OfZKb4cqcXMoBH9fvApxmM17l0hGSZVwx3GOAoWeqU=; b=GTI+2rwfbYgzvXpaL2iOMBdCRom0RLZnhBN0yF0GB6DMwUY1qD/yxrZQe4SVb0AYjj xdne9urxn6WWzK+kiDNoeJ6WFa/tJ1nDITyWzSc3zNDa7rjTkDv2sJvLdmfbrxFRTUXc GIoJFFq7Sdv0H7QNlXL8kgFoJhQJBXyTKCTV6KrXH9/6r5d8uYCfTMe3DSo2zHvYft+l kRr8RZ1AlKhmeUn3v3iVQ86Z27rkcDOepViecLl7fBH8hxhAXmvwNI9/r+1LZ9FRNA1t BJ4rHC+Jy4JT/S6HcsZYt8ThR01wt877DSTK3KW98zMSqWROydqgTy57OIrFKyJGjtnd Cguw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=8OfZKb4cqcXMoBH9fvApxmM17l0hGSZVwx3GOAoWeqU=; b=RKehVCAk/LXgFQBKMREcOIqMMAFplc1YCOYc71OJ3A4KrIpo/dFGA6Au7B+v8JsCCO qGejMurKE3qhswFD3C91lcEIJMaxRqIqT5HJ0btmhCsVrcdrT2WRIJV+Vz8GKRUFwLN/ u2g/FuPqSTjwbhytXO74L2r0M9SyTxGiPVxzjc19IkisjiPCvmapdXoOj443gn+1B3HJ KITTBTguMubYBwV0Exj7veBmrmxKUxf8lHX+6sIRZeQm4NI84GJgwwFyiM5TQY8cTf8J utt6MjDYlhhV6aiO4WRyOTYD1CAaBSWM25qBHjwonoypYQlMM0W0A7bvFk2ZnOvGA0vA Jb7g== X-Gm-Message-State: AOAM5302uAKVrc9iP3JZZVg5ydGGynbvvIJ3FKiYK1cHFwJx31ipjByu stkhERwzCQ2a3irVflzQXqtdl2zOAy/0Rg3a2QvBPdXfO3Q= X-Google-Smtp-Source: ABdhPJxzPecy7qQPpLGcoebsgs9HIYdJPJHkOIppOn5WtuIVKJfLmi4iSgUfcQHPEKX1w++PTlfjKnhuBAgF/Egn7ms= X-Received: by 2002:a92:c692:: with SMTP id o18mr20192560ilg.215.1610956825641; Mon, 18 Jan 2021 00:00:25 -0800 (PST) MIME-Version: 1.0 References: <20210116090910.5671-1-linmiaohe@huawei.com> In-Reply-To: <20210116090910.5671-1-linmiaohe@huawei.com> From: Muchun Song Date: Mon, 18 Jan 2021 15:59:48 +0800 Message-ID: Subject: Re: [PATCH] hugetlbfs: make BUG_ON(!inode) takes effect in hugetlbfs_setattr To: Miaohe Lin Cc: mike.kravetz@oracle.com, linux-mm@kvack.org, linux-kernel Content-Type: text/plain; charset="UTF-8" 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: On Sat, Jan 16, 2021 at 5:11 PM Miaohe Lin wrote: > > When we reach here with inode = NULL, we should have crashed as inode has > already been dereferenced via hstate_inode. In order to make BUG_ON(!inode) > takes effect, we should defer initializing hstate until we really need it. > Also do this for hugetlbfs_inode_info as it's only used when ia_valid is > verified with ATTR_SIZE. > > Signed-off-by: Miaohe Lin > --- > fs/hugetlbfs/inode.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c > index 740693d7f255..9b221b87fbea 100644 > --- a/fs/hugetlbfs/inode.c > +++ b/fs/hugetlbfs/inode.c > @@ -755,10 +755,8 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset, > static int hugetlbfs_setattr(struct dentry *dentry, struct iattr *attr) > { > struct inode *inode = d_inode(dentry); > - struct hstate *h = hstate_inode(inode); If inode == NULL, it will panic here when we access inode->i_sb. I have seen many other file system implementations about setattr, they all think that d_inode() will return a non-NULL pointer. So I prefer to just remove the BUG_ON(). Thanks. > int error; > unsigned int ia_valid = attr->ia_valid; > - struct hugetlbfs_inode_info *info = HUGETLBFS_I(inode); > > BUG_ON(!inode); > > @@ -767,6 +765,8 @@ static int hugetlbfs_setattr(struct dentry *dentry, struct iattr *attr) > return error; > > if (ia_valid & ATTR_SIZE) { > + struct hstate *h = hstate_inode(inode); > + struct hugetlbfs_inode_info *info = HUGETLBFS_I(inode); > loff_t oldsize = inode->i_size; > loff_t newsize = attr->ia_size; > > -- > 2.19.1 >