Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1579069pxb; Sat, 22 Jan 2022 00:08:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJzLgWtQYU0NgxfXUMuQJQJ328CbYSy2xAUF/+aVItaUbV6tJIrNAF3kfCUIASINwL14EZyU X-Received: by 2002:a05:6a00:174c:b0:4bf:31d7:8d0e with SMTP id j12-20020a056a00174c00b004bf31d78d0emr6769386pfc.49.1642838899062; Sat, 22 Jan 2022 00:08:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642838899; cv=none; d=google.com; s=arc-20160816; b=d6i7U+lIZstqySeu9HQvAjRa0GbW4+4XFG/fqZJf3oXE6nl+j6rzNOb9lZPvRU72Gw vMBw9oQdVs/gJJskqzT/Y/YO0F3n7jH3QRasf1Lw6SaGwQsx612VlFhrAgqH0gAWq0go LGv00Simypx75R4WJpAAAk6A9GqODnEZUW2EHvYmMLzemRRPuBYOfrJNRyjM8fRpNkQf ztyMmMAfAHmipuXRZ/MSJUlkbVOxDHMhe682xxMRaM1y+Yt5zkd4VuXaRYEy2dbp8ShQ QV9ZuhoOVS1wm6LVWGmHI54Deszw9Mg8rTfSJelEDxGan1WA9/CrmibWE6qB85lYYpER Z+wA== 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=WGjUTrV5mgHMzDhyvLsZZ8pd7X6AuuH7QuhfJeG9EgY=; b=gkZkQjxFOdXAlSUuB1GLZa7JpgvYcO8Tz2wK9WQe45GtA1e49OdtcsiqWJVBLH+8Du pc0MYk+cM7B7xw8gw6VxuTooB3mPwz/AlXnxGc3O0MYMlYw3Vx5s05YtfNty/zrHd843 5k11RoLxT6zREWRP6FWxFRiHSjxXp46JD2PljlOVqR2nMXgvW/tonWFOTsXS6asYjqgZ CRD8+Vo+jqCPCJ2GEhcqFqINIfMRCA+FDZ7vaDxK/KKavdu3gGYVRGprP8ukz7P54sqs 3XdsLa6S+rxEbCjo6fgM3t0/W4+3ZWkAhaBsGWgna2Xjwc1wPC95CMfpg1so7moXhYZu t30Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=kvmf2OSx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id pi7si18339522pjb.154.2022.01.22.00.08.07; Sat, 22 Jan 2022 00:08:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=kvmf2OSx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231270AbiAUUsa (ORCPT + 99 others); Fri, 21 Jan 2022 15:48:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229583AbiAUUs3 (ORCPT ); Fri, 21 Jan 2022 15:48:29 -0500 Received: from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com [IPv6:2607:f8b0:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DBC6C06173B; Fri, 21 Jan 2022 12:48:26 -0800 (PST) Received: by mail-oi1-x22b.google.com with SMTP id r138so15316454oie.3; Fri, 21 Jan 2022 12:48:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=WGjUTrV5mgHMzDhyvLsZZ8pd7X6AuuH7QuhfJeG9EgY=; b=kvmf2OSxp7vQKMwYR1dLgO6WSiX2+4nzHhjmW/Oz5Vx0F/DK5D1vuYufA1qJh9Hx8a LfHmpvcS+ayKbXU3K1KqQvhGyBD1/9voVd8xBJhLWdUkaeOtZNW8nOlj2NT51r791/iw C1yXy+49U6UWHQxbmVxO2gR3A0Ot1byMBQMNkzoEOFKlPDfLSYdkPZ3ueek84qDVORVm ItiKUCPqLuAw3+Ac8+8viaNyNaokKwZyq7tsXOPOs0ZJV8ts+QZSdT+X526m/fv2gVZA dvucmMp0dZvzSnL7KV3yLFjafRYSt+ieGp4YyxXF6N3JQnT2EjKZqCvaQdHGuocKInoQ /1JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=WGjUTrV5mgHMzDhyvLsZZ8pd7X6AuuH7QuhfJeG9EgY=; b=lYvtHHbULd7RD6RvRqfCpysWW1AeiRxGscxOcDRbrYP3+iv/UH9Rd6sggBq5/psrYf nueK09T+he6JiYKP2Wff1jxuurLfBClIfmwTnAir5ZFmg4kn2LhJJlmRBIGAymG3jT/r EEalMbPUQxPBjcIg+5py+SCfjjIvdB0a8CsF+WSmgUvDJHVR27biEN/E+yQeCJ7zUcv9 oaS6xeD/fQqbSJKfk7WL8zKLRplaP8vVI6jlaXmJljkUXDuptIbIBhl4yosOvU46+pBq EQn1q2meXnnS9Hef9dRzoRYKc+iAj8g3bYy6eO6095QeFeQzMgLzsDL+xcRuyy4ZjQnp 0Z1w== X-Gm-Message-State: AOAM5333zuXXUt4vV/90K6K7xnEoDXdHczlwWic001E85NfdZMx3gCza 6wx3Gt9HS21EJsq4rlEcs6afT/qCW//Wlt3W/Zs= X-Received: by 2002:a05:6808:300b:: with SMTP id ay11mr2012664oib.120.1642798104543; Fri, 21 Jan 2022 12:48:24 -0800 (PST) MIME-Version: 1.0 References: <20220121052827.4384-1-xiongx18@fudan.edu.cn> <23d5251f-c910-aed3-5d9e-07d6e5e5add2@amd.com> In-Reply-To: <23d5251f-c910-aed3-5d9e-07d6e5e5add2@amd.com> From: Alex Deucher Date: Fri, 21 Jan 2022 15:48:13 -0500 Message-ID: Subject: Re: [PATCH] drm/amd/amdgpu/amdgpu_cs: fix refcount leak of a dma_fence obj To: =?UTF-8?Q?Christian_K=C3=B6nig?= Cc: Xin Xiong , Alex Deucher , "Pan, Xinhui" , David Airlie , Daniel Vetter , Sumit Semwal , amd-gfx list , Maling list - DRI developers , LKML , linux-media , "moderated list:DMA BUFFER SHARING FRAMEWORK" , Xin Tan , yuanxzhang@fudan.edu.cn Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 21, 2022 at 2:45 AM Christian K=C3=B6nig wrote: > > Am 21.01.22 um 06:28 schrieb Xin Xiong: > > This issue takes place in an error path in > > amdgpu_cs_fence_to_handle_ioctl(). When `info->in.what` falls into > > default case, the function simply returns -EINVAL, forgetting to > > decrement the reference count of a dma_fence obj, which is bumped > > earlier by amdgpu_cs_get_fence(). This may result in reference count > > leaks. > > > > Fix it by decreasing the refcount of specific object before returning > > the error code. > > > > Signed-off-by: Xin Xiong > > Signed-off-by: Xin Tan > > Good catch. Reviewed-by: Christian K=C3=B6nig Applied manually. Strangely I never got this on any of my emails, and I don't see it in the archives. Alex > > > --- > > drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 1 + > > 1 file changed, 1 insertion(+) > > > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/a= md/amdgpu/amdgpu_cs.c > > index 0311d799a..894869789 100644 > > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c > > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c > > @@ -1510,6 +1510,7 @@ int amdgpu_cs_fence_to_handle_ioctl(struct drm_de= vice *dev, void *data, > > return 0; > > > > default: > > + dma_fence_put(fence); > > return -EINVAL; > > } > > } >