From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 67F4B230D08 for ; Tue, 14 Jan 2025 11:26:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736853975; cv=none; b=SX4DYU2CV7cZtERsejqwKosdV5vedvrKLhPUylc86iOuVJ/YkeuS63SvQMT/eZEFsN7uIlpD+uQC5V4c14+OC9Cg8LFJtlHHLluDan2eV8iXykC4FXk71BXJjTbQb5KkZDjVcYNPx8N1FAjYTNkiV5TOQUddTEGQdTaPzQam84s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736853975; c=relaxed/simple; bh=P5WOc1gqUz8scmwf5xVMe2cVdYOYl+zpgG91/lMjQ8E=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Es/KWAP5wBtnq9ZF02ph4sOxm6mzzrUAftqAYS4evoTqvl4mAODAPuSiLgPS0H1H+0DtPL4Ccn07vBmQoVKIFczo6VH2IijkDvDkPtKk+eRZYgL19USUBKG1YE3qcTfZq2Es0HPjzSTD0JD453JirMB9J9fy6fVsA6xL8VV/ErE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=cxWKJ36C; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cxWKJ36C" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736853972; 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: in-reply-to:in-reply-to:references:references; bh=MsY6pEzLRQ774Ovx8M1YoG6AKNuIHynFJ8DXSapB998=; b=cxWKJ36C2xicuoB0Fo4zeOdovQsNbbeM845YaG4djHem/yNtQhyO2n3FRL3BL3jOD4x/do a9od8XLYWrAbN4eOlcVp18CzBoxJ8nmH8cQg3E7OmLREci5A8IFhiCu1yH3ShcAMcUgBNa L9oSBqnObdeWRXuo8SULx/RdHlYJPQQ= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-137-45GPQshXN2i0sU97i0a-eA-1; Tue, 14 Jan 2025 06:26:11 -0500 X-MC-Unique: 45GPQshXN2i0sU97i0a-eA-1 X-Mimecast-MFC-AGG-ID: 45GPQshXN2i0sU97i0a-eA Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4361efc9d1fso42855695e9.2 for ; Tue, 14 Jan 2025 03:26:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736853970; x=1737458770; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=MsY6pEzLRQ774Ovx8M1YoG6AKNuIHynFJ8DXSapB998=; b=mO2Tp9FlFoibSejyvZXeIpsGAEyxMZ7kYm7paHYvh9GNKPiXzSmStRG3ybyaeQx0Jv nzxCU3zBPtRsmQyTTIHcg1pesjg43JnQDs769VXdnfjXFoYEVf643Fsazz27T3zDdsr+ bz+DnnDI9PHDLDSX6ZOlGgdB8Ad5Q+3dl59m4HpRIoHgo75GAOjxHj3EfkPSZmyvOCaX faNd5DFyIErqoEyVbdj34wIITiY+QeuOpobx4ydIYIzVsIeSjYItG6+A4FDlknEiWyJx QV0X0HyvYTk9j9Fjb1FXF6fqcIpULeHykrLbh8i+JIOHBPrJdB8O6T3PU7XZe0crhlgI 60ZQ== X-Forwarded-Encrypted: i=1; AJvYcCXnNEHxF33x8nbB2iWpBe5qhw72eHPYcEoK9QTOvdLTstE8GQF6U9FnI0/W+4xOIdhP5c7GqTa/HVCszLE=@vger.kernel.org X-Gm-Message-State: AOJu0YwgnJ+zYcSoYGoDWqVQ7F8zLWimxnetyFMpr3LHHMJO1o7KPVsp KpJ3um2NM4nmZc033TvjK/LEAyZmbaVTWPtycukwzJI/XIDy1m9VZH23QLyj8bttUzKcB0HhgiR yin+od6AfUmPTUgYuxGTXrjp0mAvUQ5SbDgrfV3m43kfl2GAK7/J7zJNVqpPG9g== X-Gm-Gg: ASbGncvTYI6ubRqCX4hsbl8GFMM1pm+FvzTABHkMuJm5fKZgThIhvDO+6a0kB4npvSh tzHscCowhvcaaXL9Uy+YN0Zyay0kUFY4byHTerFA4KuX3YnGR9K1s2ycpM/E42QPsHWm4Qz5yMP 6IHTCGlLnhavTUq+WaKoKywt/RQvIJfocGlhPjX3abm+ZMm87GD3smWlM28EJAMSE8DKMFLuPpk rbhqJgc+vO+YxlS7LSC1YW5OM8V4sU/JfKKS/WmLnfPwwnK8Q== X-Received: by 2002:a7b:c4c9:0:b0:436:f960:3428 with SMTP id 5b1f17b1804b1-436f96034b3mr87034385e9.29.1736853970036; Tue, 14 Jan 2025 03:26:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IGArTmmJVNPIIZQEpvn3/I+W40gy72w27dB0r1QO7CEIvxpSiVE4IdF93HeHvTkZVp04ua2Ng== X-Received: by 2002:a7b:c4c9:0:b0:436:f960:3428 with SMTP id 5b1f17b1804b1-436f96034b3mr87034075e9.29.1736853969706; Tue, 14 Jan 2025 03:26:09 -0800 (PST) Received: from redhat.com ([2a02:14f:175:f243:3731:6014:d7c:f11f]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38a8e383882sm14683861f8f.34.2025.01.14.03.26.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 03:26:08 -0800 (PST) Date: Tue, 14 Jan 2025 06:26:04 -0500 From: "Michael S. Tsirkin" To: Mike Christie Cc: Haoran Zhang , jasowang@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, eperezma@redhat.com, virtualization@lists.linux.dev, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] vhost/scsi: Fix improper cleanup in vhost_scsi_set_endpoint() Message-ID: <20250114062550-mutt-send-email-mst@kernel.org> References: <20250111033454.26596-1-wh1sper@zju.edu.cn> <481cd60a-d633-4251-bb53-d3026e005930@oracle.com> 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=us-ascii Content-Disposition: inline In-Reply-To: <481cd60a-d633-4251-bb53-d3026e005930@oracle.com> On Sun, Jan 12, 2025 at 03:19:44PM -0600, Mike Christie wrote: > On 1/12/25 11:35 AM, michael.christie@oracle.com wrote: > > So I think to fix the issue, we would want to: > > > > 1. move the > > > > memcpy(vs_tpg, vs->vs_tpg, len); > > > > to the end of the function after we do the vhost_scsi_flush. This will > > be more complicated than the current memcpy though. We will want to > > merge the local vs_tpg and the vs->vs_tpg like: > > > > for (i = 0; i < VHOST_SCSI_MAX_TARGET; i++) { > > if (vs_tpg[i]) > > vs->vs_tpg[i] = vs_tpg[i]) > > } > > I think I wrote that in reverse. We would want: > > vhost_scsi_flush(vs); > > if (vs->vs_tpg) { > for (i = 0; i < VHOST_SCSI_MAX_TARGET; i++) { > if (vs->vs_tpg[i]) > vs_tpg[i] = vs->vs_tpg[i]) > } > } > > kfree(vs->vs_tpg); > vs->vs_tpg = vs_tpg; > > or we could just allocate the vs_tpg with the vhost_scsi like: > > struct vhost_scsi { > .... > > struct vhost_scsi_tpg *vs_tpg[VHOST_SCSI_MAX_TARGET]; > > then when we loop in vhost_scsi_set/clear_endpoint set/clear the > every vs_tpg entry. Wanna post the patch, Mike? -- MST