Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1036352pxk; Fri, 25 Sep 2020 04:43:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5h5GIKqtWjRMTO5JokDRNVorxRSbcodYKJDfOe584EMwZInnThicIcCgwRpCJNR75aaJp X-Received: by 2002:a17:906:b7d1:: with SMTP id fy17mr2344645ejb.391.1601034201477; Fri, 25 Sep 2020 04:43:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601034201; cv=none; d=google.com; s=arc-20160816; b=mk3b4CBMtJpdWGX7KuwzV9ru0TEvEGFnhxROVUhE3c/b86fIiIF/6ImRw2bky1PnE7 anzAcCSs659E2K4UsJ2Py1dBPKlyljNM4V9TlIpnxlhGTID7pPYsF0JoxjVe+bt95iYE rSWlfJ6OuFJ9ww+5yY6YC9UrZv6OEVPWgzoDI2hP58m1wbrfBQEYRnRjk1wmP+yFxTJ6 hWTLXnTdX6T/LOHbx8flzvvU4f1spMsUEFPpdBdBBC/8f/0ug5dLPPO1N24uKA3aN/9g 6Mbsqk1Px7aTpfdjJGkayoyr5p5N55lNpMjiY7eS8iOpOGJuVEZp8JiI/qiDv15Lf8Jf 778A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=4y1m9JMkkDOJsL4k1JE6OPASJ9H32SGI/WQkPFQ5hvU=; b=LT0vWBRCN2zANiU43sIWeIZGqWkVP9gY9OS7XtsFZk0zUXkuFesGoJFD09cKP/7EIA As4I4fygFJL7cWtaJdd5YxkmBCxFgexC8Rk8uN+h0mg7K8vmr1ekoLyZnXBwf+MR/xZt T6IZNpOSFUQH7nfU2JwyHjJCyoCXgF5+sBPAsdT2y366v3Y5vaTR7qwGUaS2Uz52YJMa xGk8odH4fDB2SdFEtHqy8lF+xumDs9K7Wu+ppHTkoSKHhQ8i5JZLYvplmonHTg7uN9B8 wwH22Q7Z2fpBtc2xNv/JLbxU+ewOYjtwF6FzhdMjMMyIVTKBnKhOGcOj0J1TdqqLfwnf TvTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BehAv66n; 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=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t17si1667167eje.331.2020.09.25.04.42.58; Fri, 25 Sep 2020 04:43:21 -0700 (PDT) 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=@redhat.com header.s=mimecast20190719 header.b=BehAv66n; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728165AbgIYLl7 (ORCPT + 99 others); Fri, 25 Sep 2020 07:41:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58547 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728038AbgIYLl7 (ORCPT ); Fri, 25 Sep 2020 07:41:59 -0400 Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601034117; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4y1m9JMkkDOJsL4k1JE6OPASJ9H32SGI/WQkPFQ5hvU=; b=BehAv66nOqG6+fVz9X/JJ18JBB8nqRlvBbI1jkIqwwuAo6o5JUespK6ltjCjkPoDHY1Ofh R4ujNICOJ5TgB3rt0ECTv6P2UJa7uzixSTYIyfRA+pDWfUqjwewI1PxxExwsH3p+DmpZ0t NVXeMwkqHDSzPB28yrn1nx0PeYyFvdI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-291-oSmASuxLNzWLqtK_WBmrYA-1; Fri, 25 Sep 2020 07:41:55 -0400 X-MC-Unique: oSmASuxLNzWLqtK_WBmrYA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C6C8B1007382; Fri, 25 Sep 2020 11:41:53 +0000 (UTC) Received: from [10.72.12.44] (ovpn-12-44.pek2.redhat.com [10.72.12.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5FB527BB7; Fri, 25 Sep 2020 11:41:38 +0000 (UTC) Subject: Re: [RFC PATCH 02/24] vhost-vdpa: fix vqs leak in vhost_vdpa_open() To: Eli Cohen Cc: mst@redhat.com, lulu@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, rob.miller@broadcom.com, lingshan.zhu@intel.com, eperezma@redhat.com, hanand@xilinx.com, mhabets@solarflare.com, eli@mellanox.com, amorenoz@redhat.com, maxime.coquelin@redhat.com, stefanha@redhat.com, sgarzare@redhat.com References: <20200924032125.18619-1-jasowang@redhat.com> <20200924032125.18619-3-jasowang@redhat.com> <20200924074816.GC170403@mtl-vdi-166.wap.labs.mlnx> From: Jason Wang Message-ID: <7237334f-10df-6d5b-dce9-c16b38166ae0@redhat.com> Date: Fri, 25 Sep 2020 19:41:37 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200924074816.GC170403@mtl-vdi-166.wap.labs.mlnx> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/9/24 下午3:48, Eli Cohen wrote: > On Thu, Sep 24, 2020 at 11:21:03AM +0800, Jason Wang wrote: >> We need to free vqs during the err path after it has been allocated >> since vhost won't do that for us. >> >> Signed-off-by: Jason Wang >> --- >> drivers/vhost/vdpa.c | 11 ++++++++--- >> 1 file changed, 8 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c >> index 796fe979f997..9c641274b9f3 100644 >> --- a/drivers/vhost/vdpa.c >> +++ b/drivers/vhost/vdpa.c >> @@ -764,6 +764,12 @@ static void vhost_vdpa_free_domain(struct vhost_vdpa *v) >> v->domain = NULL; >> } >> >> +static void vhost_vdpa_cleanup(struct vhost_vdpa *v) >> +{ >> + vhost_dev_cleanup(&v->vdev); >> + kfree(v->vdev.vqs); >> +} >> + > Wouldn't it be cleaner to call kfree(vqs) explicilty inside > vhost_vdpa_open() in case of failure and keep the symetry of > vhost_dev_init()/vhost_dev_cleanup()? That's also fine. See https://www.mail-archive.com/virtualization@lists.linux-foundation.org/msg42558.html I will use that for the next version. Thanks. > >> static int vhost_vdpa_open(struct inode *inode, struct file *filep) >> { >> struct vhost_vdpa *v; >> @@ -809,7 +815,7 @@ static int vhost_vdpa_open(struct inode *inode, struct file *filep) >> return 0; >> >> err_init_iotlb: >> - vhost_dev_cleanup(&v->vdev); >> + vhost_vdpa_cleanup(v); >> err: >> atomic_dec(&v->opened); >> return r; >> @@ -840,8 +846,7 @@ static int vhost_vdpa_release(struct inode *inode, struct file *filep) >> vhost_vdpa_free_domain(v); >> vhost_vdpa_config_put(v); >> vhost_vdpa_clean_irq(v); >> - vhost_dev_cleanup(&v->vdev); >> - kfree(v->vdev.vqs); >> + vhost_vdpa_cleanup(v); >> mutex_unlock(&d->mutex); >> >> atomic_dec(&v->opened); >> -- >> 2.20.1 >>