Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp420541rdb; Tue, 5 Dec 2023 08:57:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IHor1l+TaApkYPuVM1fiXdFHTrdflaoZskRmPVlAfiwm083anKrQuQ9aS0Ntnx63XXoPvZt X-Received: by 2002:a17:90b:1652:b0:286:bfed:6f55 with SMTP id il18-20020a17090b165200b00286bfed6f55mr1297856pjb.38.1701795451681; Tue, 05 Dec 2023 08:57:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701795451; cv=none; d=google.com; s=arc-20160816; b=lB1+dGsqucNvXcfDZ1Np/5T69NYMLy/Z0QjNbnFi1fApGD5EFLba/A1PSFiVgsb7Zu p6LWyauhqSG7KwBLejfKK2SIIYD00vNExzAN9YW372aXpHo+J/pnvcD8w3Ln4q+57FKg hKxVNyBlv8XSVgrUdxEb9iF25WD3lcamixbD1FwbUN99mtpYUA6wWk5OMR9xf4WqgRiM He6juwTk7nbyUIyrx3/ePVDKHf0CojwpklDPRVztMQr8Je1Pb6SK3jdxscQROajdM83Q 1H1P9af1Fp+yRUnV0JDXs4+PmYDQWnOnniZrcTaJ00c7/pqOMXqiC/V33QQEN8xcgwBC p+Vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=+tSnatXurhj334T7o40bU3YRBBZ1jj+JdLiwdM1Rc8A=; fh=e5rKN6v2uIX7OpjYyZBKs4yx9LJafobFJ6E6MFsmETo=; b=Wu+6sm4DJVKTN8Ru94m5MH6NWN45binjCOSd/cpl6a8cGCz0+qz++QTBf423DCi+Qo 0R2Ki+8Dshf2EQ9Tq3NiPfJila/U4GnQMeRxJtuBQ3V6Zcd3ZuASmuguxJa1cGsn9CFL /MRv/z+2KKIjCPZuvN484rsn/GOv/EjHronf5ppjbRBtVMbFz6pP2N3AQXEr5s8qA7Vp /oRoVKXtkdRdphu45DFeK91DQTUPs5MI6aR0De0wKxnE2m3f3yWWszBOxWV5Ofeiup1H 3tgcrni8wyyJCZgYj2KrOHz6nh3Sg6MU5BZgsgEzxY+/8c1Y6s9iaJvtEBkUPzo7QOSw SMcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=XW5IykQg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id pv9-20020a17090b3c8900b00286742c07e9si5804308pjb.43.2023.12.05.08.57.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 08:57:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=XW5IykQg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id CB99C82492AB; Tue, 5 Dec 2023 08:57:26 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345137AbjLEQ5A (ORCPT + 99 others); Tue, 5 Dec 2023 11:57:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232145AbjLEQ4s (ORCPT ); Tue, 5 Dec 2023 11:56:48 -0500 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 628DC9B; Tue, 5 Dec 2023 08:56:54 -0800 (PST) Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-54c5d041c23so5615212a12.2; Tue, 05 Dec 2023 08:56:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701795413; x=1702400213; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=+tSnatXurhj334T7o40bU3YRBBZ1jj+JdLiwdM1Rc8A=; b=XW5IykQgWV1ZdM2a/pHdtOGbRDJNc8gEdBZtRCiGzAno3BybcfRYEX9h1Yjkd6OVj+ /lXsJ0eojtGVSOetgJVYVcWvqDmEG8rg0xFtZtnREvRpX3QN9XJuhf5qZp8Dw+jTmkz5 79OyzZKG9915c5aNhdkefi0pTY1zYYDyyQkGBHBavMQ9y+t9wOnPEMVav+YT098ROFbN o7OC9dTsIj6tZumREaU8unZmYJADWlWeJx/kil/jQBlkYGwRqNufLfXsa9nq0F/CMKOQ EF9U3+w21YhurhULyprH8Or1IoD8QQWFkWcpyLNwKWbOkqUHRfvbrPj9v9MO8aOdXVJW 34bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701795413; x=1702400213; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+tSnatXurhj334T7o40bU3YRBBZ1jj+JdLiwdM1Rc8A=; b=IAKxgreOscPAXPfP30OlOek3iHe2aKdqMlTnLu0oyD0Hht4jxn+xXnJlWsNFlvqOge RoOlh/f/oF9t4/WCU22SoxCHgGCSJRy/9k4Aytad8MDiB73U4l881E5/V2m/G0s6PVmY 3YsW77O9zEhZ9iJzhUEIBNo5yoPHLGc59y2/F1U8kh9PGQCctYhT0qu9ITsefZZDemyF yxKvOxjuBOxK/bTIrLdoQi6uN9rgL5rcY+gWtwCSpP41cUEfaVsSYnx2x+U37XEuet8t k/vivZkG6fefL5Dc8rSMMf4V1ukIzLnHsxRZmT6l+Jklml1UCKf6z47cdYnDPJjiW76l 6PhQ== X-Gm-Message-State: AOJu0YwGvXnWNCpGs5r15lmz6OTlDnl59ZGXVQhV9wh1i3lRfcZ5rBgp PJudIQLqyeW9p2kECwqnXo88Jfq7O+sXjyxKvhI= X-Received: by 2002:a50:b412:0:b0:54b:67a7:efe5 with SMTP id b18-20020a50b412000000b0054b67a7efe5mr2421516edh.1.1701795412571; Tue, 05 Dec 2023 08:56:52 -0800 (PST) MIME-Version: 1.0 References: <20230322224403.35742-1-robdclark@gmail.com> <69d66b9e-5810-4844-a53f-08b7fd8eeccf@amd.com> <96665cc5-01ab-4446-af37-e0f456bfe093@amd.com> In-Reply-To: <96665cc5-01ab-4446-af37-e0f456bfe093@amd.com> From: Rob Clark Date: Tue, 5 Dec 2023 08:56:40 -0800 Message-ID: Subject: Re: [RFC] drm/scheduler: Unwrap job dependencies To: =?UTF-8?Q?Christian_K=C3=B6nig?= Cc: dri-devel@lists.freedesktop.org, Rob Clark , Luben Tuikov , David Airlie , Daniel Vetter , Sumit Semwal , open list , "open list:DMA BUFFER SHARING FRAMEWORK" , "moderated list:DMA BUFFER SHARING FRAMEWORK" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,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 howler.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 (howler.vger.email [0.0.0.0]); Tue, 05 Dec 2023 08:57:27 -0800 (PST) On Tue, Dec 5, 2023 at 7:58=E2=80=AFAM Christian K=C3=B6nig wrote: > > Am 05.12.23 um 16:41 schrieb Rob Clark: > > On Mon, Dec 4, 2023 at 10:46=E2=80=AFPM Christian K=C3=B6nig > > wrote: > >> Am 04.12.23 um 22:54 schrieb Rob Clark: > >>> On Thu, Mar 23, 2023 at 2:30=E2=80=AFPM Rob Clark wrote: > >>>> [SNIP] > >>> So, this patch turns out to blow up spectacularly with dma_fence > >>> refcnt underflows when I enable DRIVER_SYNCOBJ_TIMELINE .. I think, > >>> because it starts unwrapping fence chains, possibly in parallel with > >>> fence signaling on the retire path. Is it supposed to be permissible > >>> to unwrap a fence chain concurrently? > >> The DMA-fence chain object and helper functions were designed so that > >> concurrent accesses to all elements are always possible. > >> > >> See dma_fence_chain_walk() and dma_fence_chain_get_prev() for example. > >> dma_fence_chain_walk() starts with a reference to the current fence (t= he > >> anchor of the walk) and tries to grab an up to date reference on the > >> previous fence in the chain. Only after that reference is successfully > >> acquired we drop the reference to the anchor where we started. > >> > >> Same for dma_fence_array_first(), dma_fence_array_next(). Here we hold= a > >> reference to the array which in turn holds references to each fence > >> inside the array until it is destroyed itself. > >> > >> When this blows up we have somehow mixed up the references somewhere. > > That's what it looked like to me, but wanted to make sure I wasn't > > overlooking something subtle. And in this case, the fence actually > > should be the syncobj timeline point fence, not the fence chain. > > Virtgpu has essentially the same logic (there we really do want to > > unwrap fences so we can pass host fences back to host rather than > > waiting in guest), I'm not sure if it would blow up in the same way. > > Well do you have a backtrace of what exactly happens? > > Maybe we have some _put() before _get() or something like this. I hacked up something to store the backtrace in dma_fence_release() (and leak the block so the backtrace would still be around later when dma_fence_get/put was later called) and ended up with: [ 152.811360] freed at: [ 152.813718] dma_fence_release+0x30/0x134 [ 152.817865] dma_fence_put+0x38/0x98 [gpu_sched] [ 152.822657] drm_sched_job_add_dependency+0x160/0x18c [gpu_sched] [ 152.828948] drm_sched_job_add_syncobj_dependency+0x58/0x88 [gpu_sched] [ 152.835770] msm_ioctl_gem_submit+0x580/0x1160 [msm] [ 152.841070] drm_ioctl_kernel+0xec/0x16c [ 152.845132] drm_ioctl+0x2e8/0x3f4 [ 152.848646] vfs_ioctl+0x30/0x50 [ 152.851982] __arm64_sys_ioctl+0x80/0xb4 [ 152.856039] invoke_syscall+0x8c/0x120 [ 152.859919] el0_svc_common.constprop.0+0xc0/0xdc [ 152.864777] do_el0_svc+0x24/0x30 [ 152.868207] el0_svc+0x8c/0xd8 [ 152.871365] el0t_64_sync_handler+0x84/0x12c [ 152.875771] el0t_64_sync+0x190/0x194 I suppose that doesn't guarantee that this was the problematic put. But dropping this patch to unwrap the fence makes the problem go away.. BR, -R > Thanks, > Christian. > > > > > BR, > > -R > > > >> Regards, > >> Christian. > >> > >>> BR, > >>> -R >