Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp1965559lqz; Tue, 2 Apr 2024 03:16:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUPGUlE51sVAFtFIVnTPJYlXXgu1XOVDigxKj+cKPNtshb7aOTe8MCDddbJckDkJtlT/RrYpIK/hYUlVFDhXpny8/iFjTgWn0JPXwalcA== X-Google-Smtp-Source: AGHT+IFpAAhvo+RhIMdJmA+pp4nVsKGMVUx1eRGmaQPhfzyu05kkQO1oIt8MMz0vqmhxWj+COmCK X-Received: by 2002:a17:906:e24c:b0:a46:f99d:1af9 with SMTP id gq12-20020a170906e24c00b00a46f99d1af9mr10863827ejb.1.1712052986231; Tue, 02 Apr 2024 03:16:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712052986; cv=pass; d=google.com; s=arc-20160816; b=v9hPpR+r6Ykyy1W/UuXBtgt0V0ucwNMZJQD2CeG0WbtTb3d14ATB74lVMBkj9LX2IH KlwrYkVg1Y+kVOb8yl4j1gowYcsXjbil4w0zaxBFAnnbcCyI71xr2rtaiVks+0ClF/Mk IRk2/0GXRv8NtZEfenmjohulmdtDsUp3ZLM7Mjg5SaadWj7r9qJAkgYH9QdibnvsPTfH TO0IrTh5cewNrljvnlMpKdaJD2azctEa+e429OGePoQhA2sna4Ch+tvz5GoYNjakWzrM /3DXR7oMqUsjDIbX7R7Y9qcb+NEr0/2TwTX1GfKu4Sm8vScAxqsJLjHAlB4Oc5flT3Gu NrRA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=OlRSV1PuXUdbroCy1WdaqtPCyvUiMBYKbOn985ph798=; fh=zDbdc48tP89DNo5wgmPwOB+1Dsiv/pWtGPeK0oE7+Dw=; b=y/ePxm5/+Z0ndoT8iwBFBLXF9zjqVTz66WuVB3djJIucSpfCOkqFc7uMM6Jm2zfaHo yUfkDz3SHjJBJdFSm1XRxQoyW3ymNKisBU9QYSTGhSJg3Dk8tY25dEGm/CWdbKEoEqAt qZKPdlKDu3mg1KtGRnu5K+GLV0wj/G2kWD/b0ZAp7vOSHQoL1MXhE2DNNH1sgsy3e0V5 22PzExbUM1FbYZpo7XAjWi3mdz1xOvspfUmJ9A2plnnLfy19fautnYmuzqy4KXl6O0P2 eXBA9qUJt7/rtlSuxDbp/MxJ0k/POrVRmDSygF/xt4S8Qkn1mQM6cgfSA3OsgacZ5cxS IbpA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=kylinos.cn); spf=pass (google.com: domain of linux-kernel+bounces-127707-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127707-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id f4-20020a17090660c400b00a4df40d1ab4si5471148ejk.690.2024.04.02.03.16.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 03:16:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-127707-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=kylinos.cn); spf=pass (google.com: domain of linux-kernel+bounces-127707-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127707-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id EB3341F2213B for ; Tue, 2 Apr 2024 10:16:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7E0965B699; Tue, 2 Apr 2024 10:15:37 +0000 (UTC) Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4423A59B4B for ; Tue, 2 Apr 2024 10:15:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712052936; cv=none; b=RemSn9pNRH9M3y+pW1DQwvRCaSgXonu7l03ClWfEJA7Zg9iSgopGSjEqOEVU+hvIVsXzWX61ZbbSvgL3P0YQCoOUiZ4ofYoUQKIobhC2NHvUXWUs2nDTq2ARMt+TEOv9H9y68ILwgjOVw8a2udgQIJ77YOxb2NMcv+55oI1CyiI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712052936; c=relaxed/simple; bh=0xWnBySin3hvFWM+Gg+lPth7dwJaIqmVEkA7v93kco4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=hI+rbgPV1IDnojobyW9Ok/3P/Gn63FUb5pcidZLTc/KmDlAsv/c5vUHfipADv7Xumhm9KcuTgCY7RwHixTAuk07cXhVOak3NsFpTD1p0DtIczZiUvyX/J5o10dErUaNNuQ/RknCD0Jx80MzEXuR8GDRKxpXyLAo9EiRnWXSpnDc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: d83da598f0d411eeaf09c5092e5928d1-20240402 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.37,REQID:4be312ba-0d57-473e-9cf3-0be3798783b4,IP:25, URL:0,TC:0,Content:0,EDM:0,RT:0,SF:-1,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:24 X-CID-INFO: VERSION:1.1.37,REQID:4be312ba-0d57-473e-9cf3-0be3798783b4,IP:25,UR L:0,TC:0,Content:0,EDM:0,RT:0,SF:-1,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:24 X-CID-META: VersionHash:6f543d0,CLOUDID:c582b24fc3314ef5df3245e2b4f54bab,BulkI D:24040217390781IC21SF,BulkQuantity:0,Recheck:0,SF:38|25|72|19|44|66|102,T C:nil,Content:0,EDM:-3,IP:-2,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil ,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FSD,TF_CID_SPAM_FSI X-CTIC-Tags: HR_CC_COUNT, HR_CC_DOMAIN_COUNT, HR_CC_NO_NAME, HR_CTE_8B, HR_CTT_TXT HR_DATE_H, HR_DATE_WKD, HR_DATE_ZONE, HR_FROM_NAME, HR_SJ_LANG HR_SJ_LEN, HR_SJ_LETTER, HR_SJ_NOR_SYM, HR_SJ_PHRASE, HR_SJ_PHRASE_LEN HR_SJ_WS, HR_TO_COUNT, HR_TO_DOMAIN_COUNT, HR_TO_NO_NAME, IP_TRUSTED SRC_TRUSTED, DN_TRUSTED, SA_UNTRUSTED, SA_UNFAMILIAR, SN_UNTRUSTED SN_UNFAMILIAR, SPF_NOPASS, DKIM_NOPASS, DMARC_NOPASS, CIE_BAD CIE_GOOD_SPF, GTI_FG_BS, GTI_RG_INFO, GTI_C_BU, AMN_T1 AMN_GOOD, AMN_C_TI, AMN_C_BU, ABX_MISS_RDNS, ZHF_RECV_LOCALHOST X-UUID: d83da598f0d411eeaf09c5092e5928d1-20240402 X-User: liweishi@kylinos.cn Received: from localhost.localdomain [(116.128.244.171)] by mailgw (envelope-from ) (Generic MTA) with ESMTP id 1972772985; Tue, 02 Apr 2024 17:39:04 +0800 From: Weishi Li To: airlied@redhat.com, kraxel@redhat.com, gurchetansingh@chromium.org, olvaffe@gmail.com, maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, daniel@ffwll.ch Cc: dri-devel@lists.freedesktop.org, virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, liweishi@kylinos.cn Subject: [PATCH] drm/virtio: fix memory leak of vbuf Date: Tue, 2 Apr 2024 17:39:22 +0800 Message-Id: <20240402093922.268368-1-liweishi@kylinos.cn> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both virtio_gpu_queue_ctrl_buffer and virtio_gpu_queue_cursor use virtqueue_add_sgs to upload the structure virtio_gpu_vbuffer * vbuf to virtqueue. However, when virtqueue_add_sgs returns -EIO or -ENOMEM, it means vbuf upload failed, and vbuf will not be able to be free by virtio_gpu_dequeue_*_func, resulting in a continuous increase in memory allocated to vgdev ->vbufs. Therefore, when upload fails,vbuf needs to be free directly. Signed-off-by: Weishi Li --- drivers/gpu/drm/virtio/virtgpu_vq.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c index b1a00c0c25a7..26f2e45635c1 100644 --- a/drivers/gpu/drm/virtio/virtgpu_vq.c +++ b/drivers/gpu/drm/virtio/virtgpu_vq.c @@ -356,12 +356,14 @@ static int virtio_gpu_queue_ctrl_sgs(struct virtio_gpu_device *vgdev, ret = virtqueue_add_sgs(vq, sgs, outcnt, incnt, vbuf, GFP_ATOMIC); WARN_ON(ret); + if (ret < 0 && ret != -ENOSPC) { + free_vbuf(vgdev, vbuf); + } else { + vbuf->seqno = ++vgdev->ctrlq.seqno; + trace_virtio_gpu_cmd_queue(vq, virtio_gpu_vbuf_ctrl_hdr(vbuf), vbuf->seqno); - vbuf->seqno = ++vgdev->ctrlq.seqno; - trace_virtio_gpu_cmd_queue(vq, virtio_gpu_vbuf_ctrl_hdr(vbuf), vbuf->seqno); - - atomic_inc(&vgdev->pending_commands); - + atomic_inc(&vgdev->pending_commands); + } spin_unlock(&vgdev->ctrlq.qlock); drm_dev_exit(idx); @@ -469,6 +471,8 @@ static void virtio_gpu_queue_cursor(struct virtio_gpu_device *vgdev, wait_event(vgdev->cursorq.ack_queue, vq->num_free >= outcnt); spin_lock(&vgdev->cursorq.qlock); goto retry; + else if (ret < 0) { + free_vbuf(vgdev, vbuf); } else { vbuf->seqno = ++vgdev->cursorq.seqno; trace_virtio_gpu_cmd_queue(vq, -- 2.25.1