Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp267011lqr; Wed, 5 Jun 2024 05:43:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUe74uXubbFs9c8HF92oDMWvFdLHYvG6e22s7C6CAJK4eGAogpNcePKUGGxN6AHeXLD/J+hyEnZHJueCVquZdUdNd2d+LK669smsN1UQg== X-Google-Smtp-Source: AGHT+IEACfYnkqti7OKLDCnsEug4cNjpNgptzDOvRrMc/gO1MFnW0eYAdbwOo6e3gbM49BARkYAA X-Received: by 2002:a17:902:eccb:b0:1f6:74e6:1ec1 with SMTP id d9443c01a7336-1f6a5a9d81dmr26917525ad.68.1717591400093; Wed, 05 Jun 2024 05:43:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717591400; cv=pass; d=google.com; s=arc-20160816; b=Oohl5La07nkCpDr5UGqAqka7/K3X1GS8znK1gay2yjAhxBaP7GNrQAkUbiV2D5AUAj goJh3/GT04aqrPvbLEx2jilRRaUNC5nEWD0z7HWhUOoI5PEMJwMpkp5yof9U5lV049SJ CgZjy6E4eeN/jl9Wmj+jQZ0RdzxTytsASLPwO/xZmWNtzvTnjK0i5iqOhU7bWmozYajd 8cMeyQim54Th1DxlGgNSexNza8p/5PRmNZfxNwv49bb7p9hHl7cTZ0T68MMx8xyA0jDG W9SprH1GqhWDfMPMqIYtiX5VVrZ75xGCrRh4QeHm+Ds6yr1tx9Ic9i07kZ95tKglru9t MvkA== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=XD/Zran0wvfvI+B0NQD4TNPuY8OxGe6iS2yDuVoEHvw=; fh=eRn3aFGbY1CisMZyLLyMmxGNJo6kARC+wFQK+XxZu/E=; b=n0tnvogJ8UUCki7Os+PKcXOSQPMxostkBQCwbq0sVE3KvaxDA9Tu8aCUcTlsTJEkOv t5Qqu7nFQAEfh4n5lXWWakCzs1/kYAKdUElpxX4bGPlPtHpYqIvRGCRQdxkGUrGKJQgh mO70VyG4dN9h+YA4xUfqkJS9RrzkPpxo6RI6ex2SppjCcEJ+2Qc2ym47rospypAmSD4a ht8F8aCTrOjh0uOnFcWsvMrp/v8kznJwWZm0X2+YpQwn1coxPj+ywRrP8LAOMUlSdvz7 IMGNsd0BolvcsZlib4iswCpA+91zW2Isojta4rz047gsyG3J0HvPHOcoeTHTCxecv5ZA MVSw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NVM57fu2; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202435-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202435-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d9443c01a7336-1f6323dde78si102025465ad.284.2024.06.05.05.43.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 05:43:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-202435-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NVM57fu2; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202435-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202435-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id A296DB27217 for ; Wed, 5 Jun 2024 12:24:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ED3C61BE22B; Wed, 5 Jun 2024 11:56:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NVM57fu2" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0F12419AD6D; Wed, 5 Jun 2024 11:56:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717588588; cv=none; b=u4FgeLBw9Wtx9j4DAq2WlbQovH+IvdzQIKJhp3CfrAhqSDdyzh8VAkzedANALhRDe3Acb/+LRV1iXHsl15mAZr5ZTHO3xLrzlzzeYdMQ2R3KjcZfkEOUHfzY5mAZvCJw2bxp/nkj+3fGIm9KQ8EGxFGZkANkbFhS4yb/Qn5Y+Zk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717588588; c=relaxed/simple; bh=SjwhFhT8i8cJyN+LotTWnGQb2FKVkJ8FhSqvcrbVnVI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aYiJc1K5cC1X75PjAx54l+rXsdsX80rPmEa+C1UwJYqbsUMiOfkOjSqql9SUnczl2FeQ3GuRXOvEkgiZoaqB2gorRx6iG8i3DzWc5nDEu2x5KcGVj3zzp2t5uV6Xt89Si9jAwU6/NJi4zSFtYMYo6aouSSJI0oeVD8rVFxB597o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NVM57fu2; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE7E6C4AF08; Wed, 5 Jun 2024 11:56:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717588587; bh=SjwhFhT8i8cJyN+LotTWnGQb2FKVkJ8FhSqvcrbVnVI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NVM57fu2/NiNtxLzW9gEfkyruNTGrQd9YE5cWwGLXvBQ6eXiLsMTkXcTSw+gmPBl5 UqkAMIDoLAwu7ceUEbqmH9x/qp8r9dQPiT0xkHgEq4F7I2Hbn1dJ/IvrALBRiGwr6w sC+BhV9gM2ZXArw5PhQ/6EcVq0mrr1FqDQc8k0Kvhr3Uq4LYxxKZeETBr4bQEg7hJ6 1Q9H/sIA/u/sQRQdXx/ygWsr2K+Bxel7ICV6WA23hsSAjWYqFWSWvcOeU6FCnwk8dT LIDsDsgO0exSGQ64L+e6eBc8NG0hXXGyI1PzjBYSbIuF7rCNYTfOTf04gCOk/f59m0 Y5cCoxlLZt2sA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Mike Christie , "Michael S . Tsirkin" , Sasha Levin , jasowang@redhat.com, virtualization@lists.linux.dev, kvm@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 6.6 4/4] vhost-scsi: Handle vhost_vq_work_queue failures for events Date: Wed, 5 Jun 2024 07:56:16 -0400 Message-ID: <20240605115619.2965224-4-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240605115619.2965224-1-sashal@kernel.org> References: <20240605115619.2965224-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.6.32 Content-Transfer-Encoding: 8bit From: Mike Christie [ Upstream commit b1b2ce58ed23c5d56e0ab299a5271ac01f95b75c ] Currently, we can try to queue an event's work before the vhost_task is created. When this happens we just drop it in vhost_scsi_do_plug before even calling vhost_vq_work_queue. During a device shutdown we do the same thing after vhost_scsi_clear_endpoint has cleared the backends. In the next patches we will be able to kill the vhost_task before we have cleared the endpoint. In that case, vhost_vq_work_queue can fail and we will leak the event's memory. This has handle the failure by just freeing the event. This is safe to do, because vhost_vq_work_queue will only return failure for us when the vhost_task is killed and so userspace will not be able to handle events if we sent them. Signed-off-by: Mike Christie Message-Id: <20240316004707.45557-2-michael.christie@oracle.com> Signed-off-by: Michael S. Tsirkin Signed-off-by: Sasha Levin --- drivers/vhost/scsi.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c index abef0619c7901..8f17d29ab7e9c 100644 --- a/drivers/vhost/scsi.c +++ b/drivers/vhost/scsi.c @@ -497,10 +497,8 @@ vhost_scsi_do_evt_work(struct vhost_scsi *vs, struct vhost_scsi_evt *evt) vq_err(vq, "Faulted on vhost_scsi_send_event\n"); } -static void vhost_scsi_evt_work(struct vhost_work *work) +static void vhost_scsi_complete_events(struct vhost_scsi *vs, bool drop) { - struct vhost_scsi *vs = container_of(work, struct vhost_scsi, - vs_event_work); struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; struct vhost_scsi_evt *evt, *t; struct llist_node *llnode; @@ -508,12 +506,20 @@ static void vhost_scsi_evt_work(struct vhost_work *work) mutex_lock(&vq->mutex); llnode = llist_del_all(&vs->vs_event_list); llist_for_each_entry_safe(evt, t, llnode, list) { - vhost_scsi_do_evt_work(vs, evt); + if (!drop) + vhost_scsi_do_evt_work(vs, evt); vhost_scsi_free_evt(vs, evt); } mutex_unlock(&vq->mutex); } +static void vhost_scsi_evt_work(struct vhost_work *work) +{ + struct vhost_scsi *vs = container_of(work, struct vhost_scsi, + vs_event_work); + vhost_scsi_complete_events(vs, false); +} + static int vhost_scsi_copy_sgl_to_iov(struct vhost_scsi_cmd *cmd) { struct iov_iter *iter = &cmd->saved_iter; @@ -1509,7 +1515,8 @@ vhost_scsi_send_evt(struct vhost_scsi *vs, struct vhost_virtqueue *vq, } llist_add(&evt->list, &vs->vs_event_list); - vhost_vq_work_queue(vq, &vs->vs_event_work); + if (!vhost_vq_work_queue(vq, &vs->vs_event_work)) + vhost_scsi_complete_events(vs, true); } static void vhost_scsi_evt_handle_kick(struct vhost_work *work) -- 2.43.0