Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3687994lfo; Mon, 23 May 2022 11:28:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzPZbdHKcnu2gWiWduJ8tm1Pmftv7hy9/uVEZsNcSmt8P6J26oRGnaVZB2pCZKb7IAaqyq X-Received: by 2002:a63:521e:0:b0:3db:7de7:322a with SMTP id g30-20020a63521e000000b003db7de7322amr20813556pgb.43.1653330529670; Mon, 23 May 2022 11:28:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653330529; cv=none; d=google.com; s=arc-20160816; b=ByGG6rZwT/7WihIzwx0Xdfp0cgzqlUBE3q3ImT15X4VCld5pvezV9dha97jKsBm6ta Kejqtg3yMbpSGrPEHpn6bj/TJ6fUdH0ppFQ1nFb00ZG9HK42vU4kn0xZdyS5YSXHeSO/ diHfxOdfPlzl6rnZNSoRS/oBH5FO1oEgvyATAARgJHFLo6hJbBRKyOZPpPaUTtX8CwNq QsaV4X5gqTAEJXA2qaSQxepsOcnwGMT6ZMqJSwTLR0LWsFGmgN6c7V09J++uTnEgQDLO 9vTqjxS/dj+xf9w5lcod23bciu/E1RWaL8LU1yLAP6nIik0VD1az3q/JN9NjyX1bsTUW +P9Q== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lkY8QWrMoSpSH5vBNxrUcID14Bi4ePe02dp6JSRV3xU=; b=luZ7FRz3BDu86bLTo2uPtfd0wSM+mXKk3QWdq2w4uC5DAKfSaeCBkrNhtKXw23eYSb VOPJO0Kwhi1qxx+OTv7bH9eH3hTYHcCeVsUgoAyKF1nxzKU21Majvn5cjIBFlj9ojy5s H8JQMVXkmZDTIowIEUczKEUcFb8qmgY4u4i4n3CjUNWdn6Jx1hTbv6ovsuccEy6p+wEg 9BVKt5iz8z2H73LdP29aFiHkVIeXtQATBjV2IBBiSWqdeEbIfJrNFbV0HFCE8hvxgTuP R+5DMpq2tEXjB5r9bPZmvId7zB4jXrPMB5KLE5VPMwNGlxpwmLzk8QDoRMl/ANRXhKzM 3PHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wYgwDuKl; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id il18-20020a17090b165200b001c6f8b9aea5si87932pjb.42.2022.05.23.11.28.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 11:28:49 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wYgwDuKl; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F0FBF119922; Mon, 23 May 2022 11:28:21 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243074AbiEWSE5 (ORCPT + 99 others); Mon, 23 May 2022 14:04:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241782AbiEWRgD (ORCPT ); Mon, 23 May 2022 13:36:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BCFF90CE8; Mon, 23 May 2022 10:29:59 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C0A6960B2C; Mon, 23 May 2022 17:28:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9900C385A9; Mon, 23 May 2022 17:28:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653326919; bh=2K0Ed2rmG9vLt8EFWi7OhhXbZZ/LsAZmEhrjRjuARM4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wYgwDuKlA+TNyRx4dXAXed3Ee8FKQOEEC3saczeCmQ9h0WjpbT9somWEqXucYsi7H P+CDDCYUaCC0ccxyTR83NgE/fRcWHF1EW3p7YEzeHW3sbe683QDxCcjHXpL4Lq7IyE 6Lef+SdjJHItiySKX57HYvX1O2I3tdbq/ubyMcfs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Charan Teja Kalla , =?UTF-8?q?Christian=20K=C3=B6nig?= Subject: [PATCH 5.17 067/158] dma-buf: ensure unique directory name for dmabuf stats Date: Mon, 23 May 2022 19:03:44 +0200 Message-Id: <20220523165841.999829287@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220523165830.581652127@linuxfoundation.org> References: <20220523165830.581652127@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Charan Teja Kalla commit 370704e707a5f2d3c9a1d4ed8bd8cd67507d7bb5 upstream. The dmabuf file uses get_next_ino()(through dma_buf_getfile() -> alloc_anon_inode()) to get an inode number and uses the same as a directory name under /sys/kernel/dmabuf/buffers/. This directory is used to collect the dmabuf stats and it is created through dma_buf_stats_setup(). At current, failure to create this directory entry can make the dma_buf_export() to fail. Now, as the get_next_ino() can definitely give a repetitive inode no causing the directory entry creation to fail with -EEXIST. This is a problem on the systems where dmabuf stats functionality is enabled on the production builds can make the dma_buf_export(), though the dmabuf memory is allocated successfully, to fail just because it couldn't create stats entry. This issue we are able to see on the snapdragon system within 13 days where there already exists a directory with inode no "122602" so dma_buf_stats_setup() failed with -EEXIST as it is trying to create the same directory entry. To make the dentry name as unique, use the dmabuf fs specific inode which is based on the simple atomic variable increment. There is tmpfs subsystem too which relies on its own inode generation rather than relying on the get_next_ino() for the same reason of avoiding the duplicate inodes[1]. [1] https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/patch/?id=e809d5f0b5c912fe981dce738f3283b2010665f0 Signed-off-by: Charan Teja Kalla Cc: # 5.15.x+ Reviewed-by: Greg Kroah-Hartman Reviewed-by: Christian König Link: https://patchwork.freedesktop.org/patch/msgid/1652441296-1986-1-git-send-email-quic_charante@quicinc.com Signed-off-by: Christian König Signed-off-by: Greg Kroah-Hartman --- drivers/dma-buf/dma-buf.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -407,6 +407,7 @@ static inline int is_dma_buf_file(struct static struct file *dma_buf_getfile(struct dma_buf *dmabuf, int flags) { + static atomic64_t dmabuf_inode = ATOMIC64_INIT(0); struct file *file; struct inode *inode = alloc_anon_inode(dma_buf_mnt->mnt_sb); @@ -416,6 +417,13 @@ static struct file *dma_buf_getfile(stru inode->i_size = dmabuf->size; inode_set_bytes(inode, dmabuf->size); + /* + * The ->i_ino acquired from get_next_ino() is not unique thus + * not suitable for using it as dentry name by dmabuf stats. + * Override ->i_ino with the unique and dmabuffs specific + * value. + */ + inode->i_ino = atomic64_add_return(1, &dmabuf_inode); file = alloc_file_pseudo(inode, dma_buf_mnt, "dmabuf", flags, &dma_buf_fops); if (IS_ERR(file))