Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2404270lqp; Sun, 24 Mar 2024 18:06:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXmpP8K0TKGquPKXCaEsN9PiHeXn1jay2mu3IcmIfsIH6uKQThd8R31AGwB4rs3BJ7yrJrYdvk6p/3kncqNox87MRGHhEB+QNrD2Gq8Lg== X-Google-Smtp-Source: AGHT+IF/0og725hp28VaNiu4RFuRU/emYTaiH4w4I7bX+uvkrsXViLV5si1rGGOOImMEXeMD/Vqo X-Received: by 2002:a05:6a20:9f88:b0:1a3:c63a:c6f8 with SMTP id mm8-20020a056a209f8800b001a3c63ac6f8mr2840865pzb.56.1711328799162; Sun, 24 Mar 2024 18:06:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711328799; cv=pass; d=google.com; s=arc-20160816; b=d1THySewKgS/4+I0FdBSmDLfURxeS7gVU9DVs5BQHVWbF5/Vi2QYpwjU8CljZLOvF5 UHtgve3+XQWY9OWBnt4GcpxZIaPHVaNRWlyOl9U7Vw8e8eajC04ZKQn25+Zk3ViXw7LA CIsgHvXYmHVtwE8n3/iYffHG8KNCUHl+809Mz8AWEnzD2xECnd5qq1vNzEgDuWiajBK2 EScyfxxScWpyYrl9LjWBkfvtSymDH3eVhKTu9bdlp7wt7r/CrHfNUFs/vtAi4NRYmBcY L/pAqKegrhajmv74hmkdwLQgkmA056s54POj0L9YL6S7XVAx+zSz6OLx0OAZZC3z5bM5 iQwQ== 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=cnXzIYlJtljwT2z1IihFKhzChfTbIcYZfAtF4MZu8kM=; fh=3aQkzVPwo3SrqBHuirQ7QXvw1qvLy3O2d+/je03cHDA=; b=LUtvEVcQ804RbEiBB/w5ym38P/YBFzmtVcci2xvHJHS4cRuQPMty/S+kQLj1QS/MCl YT2bkLeH+DRJD3TbYdpeU+wmkiSwzVPcKi9jLUuvcmpeXWUZFrgu2eT/72i35bmg1HYZ o7ya7x92tpQg3hDpXJKC4pTSl78OdxhkiZsm6GlWHqW2VZrCgFy2sI82TNSwemc+l161 N6ZyQ+Co0PDG0/7TR3fg/FP2hObO0PcUX3OAFUVVsd13uVA3ceD3RL416/g+9EfGqLHm 6fM1sB8mSSJYWbzuNnBVsxFJIaGujd2MhhKZRMZghz3fLAiiNorwbu1GbLb1+PWfBjmf vHOg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="jbN22/n6"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113571-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113571-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id f2-20020a17090ab94200b0029c66c7602csi6554502pjw.124.2024.03.24.18.06.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 18:06:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113571-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="jbN22/n6"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113571-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113571-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 410FC284025 for ; Mon, 25 Mar 2024 01:06:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2D6C713E8B2; Sun, 24 Mar 2024 22:46:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jbN22/n6" 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 35AB013E898; Sun, 24 Mar 2024 22:46:14 +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=1711320374; cv=none; b=Oxtry3PltObY1wVRXuXbrKrra+0jTyQyAOprllLS00TjzuW9QRAJVXpJUVVeh6c7GNgszkB+0Lnci3tIsqE6PG7w2M0+1nk0PsZXAP8byHprNi0kAaTNkUIkoYzP+PgSJlRj95yK4ANNrz3UUUIYUUBhkuKEngoLxo6HT1FWFu4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320374; c=relaxed/simple; bh=rbPa+Ctn/YI4xgNS41/BQYk1owmjhkNPLW58UozUyrQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JCcWbYpfeLpfnGFpaNoFK7YEhWLCcN5LFjpY1NWa931JPizkFphei4qdMdy503vY7uBZTQFG7QPupwQkTMCDKVYzH6o6khiHGNfGl/c5Y+q54Qe0eahNDKgFZsv80xZm6dz6aTedCF4NVkwcMzkrYqa5CS0omiDH5jDXfCGdrws= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jbN22/n6; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BE73C43399; Sun, 24 Mar 2024 22:46:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320374; bh=rbPa+Ctn/YI4xgNS41/BQYk1owmjhkNPLW58UozUyrQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jbN22/n6QRsJziKMJLm2r9cVKgBconOE3XzT5gxC7RZJGm3QXJqwoiDvxCCuxv42U 534Fy3umm6EtHh/+ahGoGdLpAHwF4fYOumm9hswRPEESn/XA1emiaQFJ60LSVbDd1l ehECuiep8SCjP0iAvT2Bf37JjOAKv91sqUZ8OfWdo7cju+kZY8LbRrbJpEdMpS5Wtp F7vTCIYnGWSLoHqj5N+31uaLJgKvOUFlI9ivgNxnD4DQ3uPD+QyMqhHsM1P/nZwl1v ek3vO9tOMawfFRGrWBdD2Q1wTiUxlsH9k48XXNi38ZdIzoYaoqZeOmaR/URFFPW86V P+H51IL+mUZ1w== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Xuan Zhuo , "Michael S . Tsirkin" , Sasha Levin Subject: [PATCH 6.8 680/715] virtio: packed: fix unmap leak for indirect desc table Date: Sun, 24 Mar 2024 18:34:19 -0400 Message-ID: <20240324223455.1342824-681-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-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 Content-Transfer-Encoding: 8bit From: Xuan Zhuo [ Upstream commit d5c0ed17fea60cca9bc3bf1278b49ba79242bbcd ] When use_dma_api and premapped are true, then the do_unmap is false. Because the do_unmap is false, vring_unmap_extra_packed is not called by detach_buf_packed. if (unlikely(vq->do_unmap)) { curr = id; for (i = 0; i < state->num; i++) { vring_unmap_extra_packed(vq, &vq->packed.desc_extra[curr]); curr = vq->packed.desc_extra[curr].next; } } So the indirect desc table is not unmapped. This causes the unmap leak. So here, we check vq->use_dma_api instead. Synchronously, dma info is updated based on use_dma_api judgment This bug does not occur, because no driver use the premapped with indirect. Fixes: b319940f83c2 ("virtio_ring: skip unmap for premapped") Signed-off-by: Xuan Zhuo Message-Id: <20240223071833.26095-1-xuanzhuo@linux.alibaba.com> Signed-off-by: Michael S. Tsirkin Signed-off-by: Sasha Levin --- drivers/virtio/virtio_ring.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 49299b1f9ec74..6f7e5010a6735 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -1340,7 +1340,7 @@ static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq, sizeof(struct vring_packed_desc)); vq->packed.vring.desc[head].id = cpu_to_le16(id); - if (vq->do_unmap) { + if (vq->use_dma_api) { vq->packed.desc_extra[id].addr = addr; vq->packed.desc_extra[id].len = total_sg * sizeof(struct vring_packed_desc); @@ -1481,7 +1481,7 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq, desc[i].len = cpu_to_le32(sg->length); desc[i].id = cpu_to_le16(id); - if (unlikely(vq->do_unmap)) { + if (unlikely(vq->use_dma_api)) { vq->packed.desc_extra[curr].addr = addr; vq->packed.desc_extra[curr].len = sg->length; vq->packed.desc_extra[curr].flags = @@ -1615,7 +1615,7 @@ static void detach_buf_packed(struct vring_virtqueue *vq, vq->free_head = id; vq->vq.num_free += state->num; - if (unlikely(vq->do_unmap)) { + if (unlikely(vq->use_dma_api)) { curr = id; for (i = 0; i < state->num; i++) { vring_unmap_extra_packed(vq, -- 2.43.0