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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64E3DC7618D for ; Mon, 13 Mar 2023 07:14:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229906AbjCMHOL (ORCPT ); Mon, 13 Mar 2023 03:14:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229698AbjCMHOJ (ORCPT ); Mon, 13 Mar 2023 03:14:09 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2045.outbound.protection.outlook.com [40.107.94.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E415434C0F; Mon, 13 Mar 2023 00:14:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DoF5mncloM8XdZfpFTapDwL6Z4Btpe+VZ9XQNOKK2Ug/NbR9ZyliJRBPvXSYLkebBXteWj41RRryaxSu3S/DyLTg9VMsPY+A6dEM/CvrT4s5KbqdSE8oPsyi38SC8byBmRinpzCVg8amH2Zq6YbhnAoYNxyHLmbeqj+FJ+cPfTTYfkKJNJ3sY5++n2bvB3rmRr4lDGBqjsCeBVJ9MI1Xgtne8Ul0TbtOZhr2g0+KpJnRYoG/9SzPw3ysR1OnM/i3Fg87HmvoCSzlEObQvHlfTrj+oASTNZFAfIoWvkMHYfTeQjp1X2rqGue0R1dG67WqdYEkTEorWkFmjvcNUN+ngg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LNKASwhWnj0+V8fAuOu0kSapKGVv2O/0u4q4MzcrOMY=; b=V2Rk2Ls7TkIAF4StnhiKfMZhdzKNfNRwdY0iJlO43LpoCTA3+uWtTfSWNRQk7VrZePT70EZkwTGOv5sOso5CaOyphniW09ezoKHQrOIGCKGh2iaXE53tGxT21xc/dY42bva1bClIsBmnVDk3oqlbThGMNXuQXCpcAmqNiDhUYjio0zkBo0JQg2DkWoqnnnRr9lRgprLR2Cy61zbjyGgagJuBPjdEKWCu7eXTGvQ4zH8rYyzPiL3+ND+jXoYGCsDwD30Kd6ZtLBz0ZELbNLtBr531pe9eVQAX4nJPMvjk0Kc3knhgE2MB3b9fS3HMXdjowApceh53xubjOl7t3Xywog== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LNKASwhWnj0+V8fAuOu0kSapKGVv2O/0u4q4MzcrOMY=; b=U7vuKhIdedcCc8SGhCQApDkLHxYQNZ+FCA0QCEFcKOkbqWAzi1r50/5NvqcstIqbDfflDFl4CHGipNTAZDPGUPMGEje7eAnoaGdhwWy9wOpXTuJaKJ7zJDgG/wA8IRxB/uJh4JesCYiKARLx0zs4HHcOtr6/xwo5ai4IbcR32Ks= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from BN8PR12MB3587.namprd12.prod.outlook.com (2603:10b6:408:43::13) by SJ2PR12MB8845.namprd12.prod.outlook.com (2603:10b6:a03:538::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.24; Mon, 13 Mar 2023 07:14:05 +0000 Received: from BN8PR12MB3587.namprd12.prod.outlook.com ([fe80::d23f:bb1:df95:3918]) by BN8PR12MB3587.namprd12.prod.outlook.com ([fe80::d23f:bb1:df95:3918%4]) with mapi id 15.20.6178.024; Mon, 13 Mar 2023 07:14:05 +0000 Message-ID: <1e3d4830-4797-8cc2-5882-02de44424ec7@amd.com> Date: Mon, 13 Mar 2023 08:13:58 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: [PATCH 1/2] dma-buf/dma-fence: Add dma_fence_init_noref() Content-Language: en-US To: Rob Clark , dri-devel@lists.freedesktop.org Cc: linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org, Rob Clark , Sumit Semwal , Gustavo Padovan , "open list:SYNC FILE FRAMEWORK" , "moderated list:DMA BUFFER SHARING FRAMEWORK" , open list References: <20230311173513.1080397-1-robdclark@gmail.com> <20230311173513.1080397-2-robdclark@gmail.com> From: =?UTF-8?Q?Christian_K=c3=b6nig?= In-Reply-To: <20230311173513.1080397-2-robdclark@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: FR0P281CA0143.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:96::17) To BN8PR12MB3587.namprd12.prod.outlook.com (2603:10b6:408:43::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8PR12MB3587:EE_|SJ2PR12MB8845:EE_ X-MS-Office365-Filtering-Correlation-Id: 2115dad2-0ed9-4f4b-9a88-08db23928799 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CbGWYZTPPuU39sndv4/Vo79q4DBKCyHbxlHSD38zF7hHliqSHIH0gTdSH4njegJbVRA4J19jEj8XCHKlTvViFhWp/YUF7b2BVfJd+MGRhUUcUx/SIfkAVB9GK+CxEwQiO+KxdJjY24r2zcJiTkse+jGrqzjzSwyRYNfOVeA/UuTyHLtgNNhd36X0mXs3pNFNFS4MGkmCaTN1uat+7O1uG6c0E7xN9zDTYayEjIGp4F31m++EJ9IGeuTcy5f5gSHsJpp+eQzX7A8grzuG1ynCFMVxHkdI1CsYGt8A23H9Jr0dMNEtazoqrxM1fQeXhtHAC8bV2H0mPS9QSCrcCU2aWEbTOxR6AYPmlsPL3Xey/VlSuFfVgogzGv1buCE+B4u1oobN1pbUf2wCtN5r1lJqAlVRUFtXUPtWzO2hUl6yuMOwGgTL5rSDGhoALoNWy+e1E3htZFuMrMToKNarCQv/FztdK0um99LmLcOifmEdFOhBKdsijavOnSGvMiCsDrMCT+jvYrrm2vR+aSiY6VwoRgnXTS0eLIsm3waBReiBr/7B+JNrX8MQ3mTmavkFBH3sEUiRqU1V4nm8HRyumiUHZrsqmjQM8eTUodwAex78JifUTsojnJTCqmcM6kLp63Jc6kXyv8NuMrP3poIuEE5YemN12VLfnzCkOtM6KS5tGYSS/21mfPf0FCzflU9VLMVQFYbcL7MgXpE5aF9qPIwrrApQhcicZwQ5/ihgm1xB8Zw= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR12MB3587.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(366004)(376002)(346002)(136003)(396003)(39860400002)(451199018)(31686004)(54906003)(41300700001)(8936002)(478600001)(66476007)(4326008)(66946007)(66556008)(8676002)(36756003)(86362001)(31696002)(38100700002)(26005)(6506007)(6486002)(6666004)(186003)(7416002)(5660300002)(2906002)(316002)(6512007)(83380400001)(2616005)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?cDBoVkhUZGk4U09zdkw0M0d1a1dVTXE5T0IxQzF4ZU5tOG9YbTE4UG9kZjJy?= =?utf-8?B?MnprZThzc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orQk5iU3FpMEVSUGw0WXVT?= =?utf-8?B?UkVzMU9zMUNEa29QaSt3WGhsOVFsQTV6V0d5RWJvNXk2NXRmSUhNd0E1VlhT?= =?utf-8?B?UzArSGtwYkFXVW1wbGxyR0hXTUR2a1ZRMEZ6cVpYdmxzczJYNjhKcE12TGYx?= =?utf-8?B?YzJsV3ZJVGZrL1dZdzJLcG9WN1JJQmRGQ3lUVHFWNXZGa3JoKzNNWFZCdDA2?= =?utf-8?B?Zm9Ca0kzSlNhYWJJbkwrV05raDZ0dmRZUW1rKzZkdm80Qm15d0NKRVFsaWJz?= =?utf-8?Q?5g2XCfUo0DOBV+D63/wOp1nO8?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2115dad2-0ed9-4f4b-9a88-08db23928799 X-MS-Exchange-CrossTenant-AuthSource: BN8PR12MB3587.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Mar 2023 07:14:05.3057 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: qFXrh7LglSsqodMWtvS0Kuz+Vxr6LRaMDYzNqDg+2yfI0U5A2tLS2B10gLUKqf9A X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8845 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am 11.03.23 um 18:35 schrieb Rob Clark: > From: Rob Clark > > Add a way to initialize a fence without touching the refcount. This is > useful, for example, if the fence is embedded in a drm_sched_job. In > this case the refcount will be initialized before the job is queued. > But the seqno of the hw_fence is not known until job_run(). > > Signed-off-by: Rob Clark Well that approach won't work. The fence can only be initialized in the job_run() callback because only then the sequence number can be determined. Regards, Christian. > --- > drivers/dma-buf/dma-fence.c | 43 ++++++++++++++++++++++++++++--------- > include/linux/dma-fence.h | 2 ++ > 2 files changed, 35 insertions(+), 10 deletions(-) > > diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c > index 74e36f6d05b0..97c05a465cb4 100644 > --- a/drivers/dma-buf/dma-fence.c > +++ b/drivers/dma-buf/dma-fence.c > @@ -989,28 +989,27 @@ void dma_fence_describe(struct dma_fence *fence, struct seq_file *seq) > EXPORT_SYMBOL(dma_fence_describe); > > /** > - * dma_fence_init - Initialize a custom fence. > + * dma_fence_init_noref - Initialize a custom fence without initializing refcount. > * @fence: the fence to initialize > * @ops: the dma_fence_ops for operations on this fence > * @lock: the irqsafe spinlock to use for locking this fence > * @context: the execution context this fence is run on > * @seqno: a linear increasing sequence number for this context > * > - * Initializes an allocated fence, the caller doesn't have to keep its > - * refcount after committing with this fence, but it will need to hold a > - * refcount again if &dma_fence_ops.enable_signaling gets called. > - * > - * context and seqno are used for easy comparison between fences, allowing > - * to check which fence is later by simply using dma_fence_later(). > + * Like &dma_fence_init but does not initialize the refcount. Suitable > + * for cases where the fence is embedded in another struct which has it's > + * refcount initialized before the fence is initialized. Such as embedding > + * in a &drm_sched_job, where the job is created before knowing the seqno > + * of the hw_fence. > */ > void > -dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops, > - spinlock_t *lock, u64 context, u64 seqno) > +dma_fence_init_noref(struct dma_fence *fence, const struct dma_fence_ops *ops, > + spinlock_t *lock, u64 context, u64 seqno) > { > BUG_ON(!lock); > BUG_ON(!ops || !ops->get_driver_name || !ops->get_timeline_name); > + BUG_ON(!kref_read(&fence->refcount)); > > - kref_init(&fence->refcount); > fence->ops = ops; > INIT_LIST_HEAD(&fence->cb_list); > fence->lock = lock; > @@ -1021,4 +1020,28 @@ dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops, > > trace_dma_fence_init(fence); > } > +EXPORT_SYMBOL(dma_fence_init_noref); > + > +/** > + * dma_fence_init - Initialize a custom fence. > + * @fence: the fence to initialize > + * @ops: the dma_fence_ops for operations on this fence > + * @lock: the irqsafe spinlock to use for locking this fence > + * @context: the execution context this fence is run on > + * @seqno: a linear increasing sequence number for this context > + * > + * Initializes an allocated fence, the caller doesn't have to keep its > + * refcount after committing with this fence, but it will need to hold a > + * refcount again if &dma_fence_ops.enable_signaling gets called. > + * > + * context and seqno are used for easy comparison between fences, allowing > + * to check which fence is later by simply using dma_fence_later(). > + */ > +void > +dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops, > + spinlock_t *lock, u64 context, u64 seqno) > +{ > + kref_init(&fence->refcount); > + dma_fence_init_noref(fence, ops, lock, context, seqno); > +} > EXPORT_SYMBOL(dma_fence_init); > diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h > index d54b595a0fe0..f617c78a2e0a 100644 > --- a/include/linux/dma-fence.h > +++ b/include/linux/dma-fence.h > @@ -279,6 +279,8 @@ struct dma_fence_ops { > void (*set_deadline)(struct dma_fence *fence, ktime_t deadline); > }; > > +void dma_fence_init_noref(struct dma_fence *fence, const struct dma_fence_ops *ops, > + spinlock_t *lock, u64 context, u64 seqno); > void dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops, > spinlock_t *lock, u64 context, u64 seqno); >