Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1365607pxb; Fri, 21 Jan 2022 16:38:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJzxn4M13z2paFzAdP44xKplCW3b+K992xKCmqxevh7LoW4fsKv94aTLqUnEyBE0g/sVBmYW X-Received: by 2002:a17:90b:1b45:: with SMTP id nv5mr3083188pjb.142.1642811887255; Fri, 21 Jan 2022 16:38:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1642811887; cv=pass; d=google.com; s=arc-20160816; b=YDhvWqsxze3axI72+Zq54lXkCfILOATgVoKoCoFl+L343ZqV89Cp2+3c0TAQggPfYh 9EyoTC+vUR1I5qcBE7LjrQIeZ/Mq8YscEdH7dMlTKGjmuQyu5ku6Z75gSoLV0WB/jc8F VbHbBV/MMSr/rusn/4S5nq9nurAi5VPj6BK2B/j+0bSpcWsCyiRvRUvM5VqHvl6/29li qhDqjLVDt8gvXWnl/nvMNpMQtCFDopuIF0I9oVKbazYwXFf/MimDFuPJ1YiKe2Rh7Ze9 6QCBF0KlU3Z3bOWP5t0hhmBOCYQconudGcGvB3TRU6iUSl9NNVgxassFfNlTs9S45+2u yJ5w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-language :content-transfer-encoding:in-reply-to:user-agent:date:message-id :from:references:cc:to:subject:dkim-signature; bh=iUBtkZ2BcghzFyZ2PjNQeXYgfAPdDWVDgSO3Kyl2Scg=; b=vhLXXgVhtNl3Hh5LX/Q06RYPSwQc4Yl2AlD+d/2+FS+Sh41Jp7BtkrfGSmRk2+l0uK /pp1zmxSVIOGdCFrNgamiSkQw/9UYnH759JbZIKX5eRpcRIVN0A5stGW71muHDfOZAEZ a2fNKUcllJlV6qSEwe95aJpiC8zAgNyGWClUt1OV0LRRW8FlLx80k0vT2H1M2foY4LNP ha0OSzflcC8yGVt/UdyCF9sO6aScmekv4Y4/uvrPC/T77UD4BaQktaZ3YDgn66+VwKYb nVyhHjiYRlaVcEjzACFd9REwTZWfxfEo/4kyTrCkcCt/fKHrwwf34pENaTiJLLcaQ06t JWRg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=gUOLOrnu; arc=pass (i=1); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b8si736295plg.363.2022.01.21.16.37.55; Fri, 21 Jan 2022 16:38:07 -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=@amd.com header.s=selector1 header.b=gUOLOrnu; arc=pass (i=1); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379110AbiAUHpT (ORCPT + 99 others); Fri, 21 Jan 2022 02:45:19 -0500 Received: from mail-bn7nam10on2069.outbound.protection.outlook.com ([40.107.92.69]:55550 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234487AbiAUHpO (ORCPT ); Fri, 21 Jan 2022 02:45:14 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PHBeOo6p7m0C+4JMGG/XcV1ijWehs3hLBCwPTSuwkHFSVP/ZGsRjrzSLmUxH6tFylxZrcXDxbJ5nTECYzy68HhLyTenWpHl9BUwghRo2G2GcrTvp8PkXAKTxA1lGOEKa17oseu+FICb5Jy7yMdU8+7VnmRnFxRJcQpzmXZgGz4JkcnxxivJC5L/Yb4iJ6kmyKxKavrXuTfgHJjpOPkr4DflNQxthOizl4wVuivwr/2U10vdMhJbgx6lZKhYJZQAqJLdBP5ts3Ovgddp6R9XZODiEWh2WIYkDz6jj1aW+EYckmd4xMLfokViZUyei5G7xQSeZAmz0x1GBbhP1oN12pg== 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=iUBtkZ2BcghzFyZ2PjNQeXYgfAPdDWVDgSO3Kyl2Scg=; b=eU9tx2gZkMBtN+n1c8Gm2CmMnHF8tH9VqB50o6mFk5XAY2UMsQMKUxZAIUpo/2WMGR7OFA5cH4g6jw8a/WWr8vLcQm+VUlfjFN6sCIpN9NoQgJXGkJsx7DOZAGu1+WOlcasqMD1A3JJ3oRqBp9z/fdEm9+8k6jYhe6+9QbTvxJfaTFxgcgsNEXi2yp3XM73cVyILbZlt267QQuBcWepl2PyVe9CEgTXMCqy2Eh46Mbgo/pQ26zlgjhU/J392/vBA7W9eAtCp4zSbJD+EyjetZUOjIZMNeaZ9PZi4Ndybm9RnYRfDCzxdkbkTCAksrcv5wfJwc/5Fkf+3VSFNwMGZlA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; 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=iUBtkZ2BcghzFyZ2PjNQeXYgfAPdDWVDgSO3Kyl2Scg=; b=gUOLOrnurNOg/MXy+5h+OumMecrzGrFfhZg3JS2FxrFzd0jU67rAxzJJFfUNn1S7niqXyJNJ1E+/Gn7CP3hZTi7CEwOCb6bAk8nIo0RAJV3WZyjFTsU/etwxJKFj36OSQxEn5qxZ+w+ub5EsSwowpcHvCV0VzwsJd+ZJZZdLYTs= 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 BN6PR12MB1201.namprd12.prod.outlook.com (2603:10b6:404:20::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.7; Fri, 21 Jan 2022 07:45:12 +0000 Received: from BN8PR12MB3587.namprd12.prod.outlook.com ([fe80::d8e7:e6b0:d63c:4a21]) by BN8PR12MB3587.namprd12.prod.outlook.com ([fe80::d8e7:e6b0:d63c:4a21%5]) with mapi id 15.20.4909.012; Fri, 21 Jan 2022 07:45:12 +0000 Subject: Re: [PATCH] drm/amd/amdgpu/amdgpu_cs: fix refcount leak of a dma_fence obj To: Xin Xiong , Alex Deucher , "Pan, Xinhui" , David Airlie , Daniel Vetter , Sumit Semwal , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org Cc: yuanxzhang@fudan.edu.cn, Xin Tan References: <20220121052827.4384-1-xiongx18@fudan.edu.cn> From: =?UTF-8?Q?Christian_K=c3=b6nig?= Message-ID: <23d5251f-c910-aed3-5d9e-07d6e5e5add2@amd.com> Date: Fri, 21 Jan 2022 08:45:06 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 In-Reply-To: <20220121052827.4384-1-xiongx18@fudan.edu.cn> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-ClientProxiedBy: AS8PR05CA0019.eurprd05.prod.outlook.com (2603:10a6:20b:311::24) To BN8PR12MB3587.namprd12.prod.outlook.com (2603:10b6:408:43::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0dd3f7ab-8835-461b-7aa6-08d9dcb1f4ef X-MS-TrafficTypeDiagnostic: BN6PR12MB1201:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8YhGhWqwPmejYbYSrWO7Q8yI+MRGRId79SEj+PXCGsqJoyjeBQ+GFbo8DlCu6C9DZD28NQXWjQfnax1uRx9f6QM8MqnYDGuoGhdQmP3plUDqALVk0hxMDS2ksAqG0OEaist4DGRvUI+jDassTXw7+c5xlvDFMpVlbSmktwOX4dp7iJQ7H6kZJPyFjkxA13Ebw3M87aNSbEIBo5gjWOo+qF+p7lPC+rjiu+zRbEKojEwMPwsxtVgugTdDdisO47a3WMEPXd611NWrJsaoJUW22CeI26ob2EyhZWZxMJtTkdQIextXXX5jg95xA9sb5lR2M8WbfldFORqsGe1b9i01kAbGlLo6/sG0ij3HmsKudngvC1pWk+KQNnBSN9DKytHq5bzqmjWTN4qrCdK2rqOQY8HXBm7285cyjB/RqwhU+uISKLzrFzHApxiRGDavumEhayG0YiT+Iqir3spzqVepNLTzwh9QMhn/8TLzZ9oy7zZuLLunDfPqXVmNH9L1ceB63EiS6/sWY7oZO5vQ0qt6m8QPbVnyLTX7p9Nfa9Kxo+RSDFswRAoBwH5ELcVb1Im0Vi2GMet3Sm8EtMx7A07Lryq1A9TLOj6v14Hd2JOrqHXTkQgKAoP/ypDXxVLJIX40jHchG0O66mGpB+McUYTxlgKnghqzZpnCb9DBxs9/IRyTv1XHHxmnjNA1mj4zJofjKy2DJZ0NjGfiRnTQSNmrv+aV61CdHeuKOZbDRDc7nHbkdCuw7Vpoj0eCkxlJyBC0 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:(4636009)(366004)(316002)(8936002)(110136005)(7416002)(6512007)(186003)(6666004)(4326008)(8676002)(6486002)(5660300002)(2906002)(921005)(66556008)(66476007)(36756003)(31696002)(2616005)(38100700002)(31686004)(6506007)(86362001)(508600001)(66946007)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?M2FEZnFPUDVybTNZRDVIMTU3NTgxc2UzbWFrSjJqR2N4K3h2c0FyS1FseU1w?= =?utf-8?B?WS9teEhISyt3c09DUDFyL0ZSWjdiYXZuc1VHYmNUYjl5cWVPL1JsTi9leFlJ?= =?utf-8?B?TXU0Mk4xMTBhUmIvZ0lJUmJkYXVBZFc0ZVlndDhlKzQ3eHFOL1poQm05eUdW?= =?utf-8?B?dFdjWXlFV21LK3B5Y0NybkhNK0YyaGZseTVIanhQRmY0N3I5bkRXVEtIMUQr?= =?utf-8?B?Znl1bDZBVHhidGxNMC81RGo0M3pzd3B5V0w0MldlZE4yMStpUGErY0crbXUz?= =?utf-8?B?dG91UHExUDY2cFIyV1JGME5KQmVHSU5obXR2V3YyWDFkejBrNlNuNk1iUHFx?= =?utf-8?B?SjRGRExUWlVUMDIySUNmdENrYzRIY2taZDcyYWh4aXA0Q1BPREhnRGowaGF0?= =?utf-8?B?QnQ0Y1oybng5WHJ0MXo3WE4yRTlKQitOYlJ5azYvQ1J0dzNBL3VURy9IVzdJ?= =?utf-8?B?UmR2RnYxQ3MrRitNSFdEdVd5K28yWXUwVnVBOVM4Uis0SlVpUVFUcmlTZFVU?= =?utf-8?B?T1RVUzQ3T3d6djVqUWU4QXlGK0ZuWGNmOVIyT3RVMmlQemxJT0dHZGZjOEc4?= =?utf-8?B?bGpyM1M5ZzNrNjh1MHBucWM0YXhhbUp3Wko3dkNMQy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VZkpnRlFOdzBxSE0zWFpaSk8x?= =?utf-8?B?S3RqODNQcGQ4THdDbzhxY2JuODRabzJzQ3lTai9oZVBDVmlkbGV3UGVnUzR2?= =?utf-8?B?WHhrNDFzUTFxU2lrckI4WUZYdWZjcmszcExiTkhLLzV4aTZtbVVNYldxRjk2?= =?utf-8?B?ZEVqNDVpNHMvTW9WNnh6ZmF6clZjRzdkRTVYTjhlYlU1YlN4dGxHYjZVQ3dn?= =?utf-8?B?WWl6MEpDK3NmY0pRNkM2N2hCZ3hINE9ua1YybHEvdHpnU1k1N05hNXR2TnVS?= =?utf-8?B?ekdoNjN4WHFCcXhWZnNXSFZKTm1pUldKWllFZXJ2WGVsNUk1T2lSTVYrRHJn?= =?utf-8?B?anpZMFBKanljdGxQK3kzZTljT0NmWTFxU0dnNWh2Vi9NVmtOVFd0VXIyYjBY?= =?utf-8?B?NlE5SExYR1ZyT3k5aXI2QS9Fd1BzSlN1dldNQlpXaUR6Y0p4VE8yODRtTVpD?= =?utf-8?B?bkUvNEluOVNvTTVEV2ErVVBDd2h4d0N5ampVbnpPNnc2ZlltTXFzQ2pOVkEy?= =?utf-8?B?dHNoT2w0QitodkpUa0luNmVTZWswNmRSSXhXc2pZNDNONDg4R2UxWXZnWXF6?= =?utf-8?B?NS9WdEZiTTJqY0o3TUp0cVI3NmNwYS8wWkxMTnV4TzI4UWxjcmVWVTR1c0Ni?= =?utf-8?Q?+O5kZsvxWVbIxh+6gqRTwRs=3D?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0dd3f7ab-8835-461b-7aa6-08d9dcb1f4ef X-MS-Exchange-CrossTenant-AuthSource: BN8PR12MB3587.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jan 2022 07:45:12.7230 (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: 4u5/H12HeZEwGqRLdbVBruYKfinZXtGyrEpRcMiybUXET7aSRVRoykhV5ZAwGYAY X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1201 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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önig > --- > 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/amd/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_device *dev, void *data, > return 0; > > default: > + dma_fence_put(fence); > return -EINVAL; > } > }