From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=EM6w+Gf9; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id A12DB5A004E for ; Thu, 12 Sep 2024 16:08:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726150127; 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=UP1iLXMA3MeNGuPUwQOS7eKBTjqdoqkANKLyaxatDZ8=; b=EM6w+Gf9xUaOaDdVKGhb4uciuaJs+MBnELzD6z+8ijJ5NKAJZpcC6t1KMEqhcvxjrCLyWi P7QTUOM+RzLQmYaBHKbQ43gndLD3VnJQbDpFJEAFcULK0xDrKi02HIADCaou8sQe5hm4cf UoCuH8OZv1IJAvYGU8kpWgp60fBhxcw= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-63-c8DGUpNfMDWREepBS9wxyQ-1; Thu, 12 Sep 2024 10:08:45 -0400 X-MC-Unique: c8DGUpNfMDWREepBS9wxyQ-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-374bb2f100fso473002f8f.0 for ; Thu, 12 Sep 2024 07:08:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726150123; x=1726754923; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=UP1iLXMA3MeNGuPUwQOS7eKBTjqdoqkANKLyaxatDZ8=; b=B4LCWHV5Dj8u55HtN1AUrRxPzLd6XHHgjLukDX05Ll3+3QWyx7RLwaod91WWcdsmPZ vMf/ftL/idzUKiD14FEAJNBZiS1d06/yb4dYl9sP0sTVFW9qN+eBQao6w/7MXXvCk8Dq 0wQY29PM1OA1Z6Lek4HiWmlIC3SolQfUCIPUu4MSVwUAru0UaYXJ6MkteseVdqRcWKqz jGl4OTKzWLAehfIYk6eWnZ6AhxqLDY0LSZZhTIcs/U7fVLz+c8qsKEnDbY0vm+UvvqAh UZ6pTc5vKEp4mPMMKA1H+ap6xLE4A5xYtx/9u2PlCntWQ3BsrW54Xpi1JxViY/RVIA79 gTyQ== X-Gm-Message-State: AOJu0YwkaYws00xsz9/BjOM3Qf+EJ/A/UBwzT4tNkfQIENfVKy0pHNkz VDw+wZgaDAmDaTDxCYB7djLZ8fIzg7Fvzm6CDPov5aw9RDgbiqdsCw6Fxyf05Q9dPa3dVN6Ps7z UxOZ5N+weexpuue0ZYlQCKiFK+mmKzg/BWuUBy5YaX+2IJlQOZHMQ6x25DYMGfRZYGId6/IHNPx zlgCbGsExrj30B7GhY2jHHM4RA74iKXiM1 X-Received: by 2002:a05:6000:1042:b0:374:b71f:72c9 with SMTP id ffacd0b85a97d-378c2cfc476mr1830588f8f.16.1726150121444; Thu, 12 Sep 2024 07:08:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFZnIYhBWXRnZjsgN7/tj4Ko1YYoDMqhsAo+GV4IyAQHrrLFnPQwMT6qy09qCGIMBE/xn90wQ== X-Received: by 2002:a05:6000:1042:b0:374:b71f:72c9 with SMTP id ffacd0b85a97d-378c2cfc476mr1830559f8f.16.1726150120747; Thu, 12 Sep 2024 07:08:40 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378956650fdsm14578309f8f.25.2024.09.12.07.08.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 07:08:40 -0700 (PDT) Date: Thu, 12 Sep 2024 16:08:17 +0200 From: Stefano Brivio To: Laurent Vivier Subject: Re: [PATCH v4 2/4] vhost-user: introduce virtio API Message-ID: <20240912160817.098f1cba@elisabeth> In-Reply-To: <6b67bacf-06ae-45fe-9e5e-9f51794bdc79@redhat.com> References: <20240906160455.2088854-1-lvivier@redhat.com> <20240906160455.2088854-3-lvivier@redhat.com> <20240910174731.3c4db56f@elisabeth> <20240912153632.66e880b1@elisabeth> <6b67bacf-06ae-45fe-9e5e-9f51794bdc79@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: WXG34SRHPN7FTXUBZL3FDRFAEQGIK4U3 X-Message-ID-Hash: WXG34SRHPN7FTXUBZL3FDRFAEQGIK4U3 X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Thu, 12 Sep 2024 16:03:46 +0200 Laurent Vivier wrote: > On 12/09/2024 15:36, Stefano Brivio wrote: > > On Thu, 12 Sep 2024 13:23:58 +0200 > > Laurent Vivier wrote: > > > >> On 10/09/2024 17:47, Stefano Brivio wrote: > >>>> + > >>>> +/** > >>>> + * virtqueue_read_indirect_desc() - Copy virtio ring descriptors from guest > >>>> + * memory > >>>> + * @dev: Vhost-user device > >>>> + * @desc: Destination address to copy the descriptors to > >>>> + * @addr: Guest memory address to copy from > >>>> + * @len: Length of memory to copy > >>>> + * > >>>> + * Return: -1 if there is an error, 0 otherwise > >>>> + */ > >>>> +static int virtqueue_read_indirect_desc(struct vu_dev *dev, struct vring_desc *desc, > >>>> + uint64_t addr, size_t len) > >>>> +{ > >>>> + uint64_t read_len; > >>>> + > >>>> + if (len > (VIRTQUEUE_MAX_SIZE * sizeof(struct vring_desc))) > >>>> + return -1; > >>>> + > >>>> + if (len == 0) > >>>> + return -1; > >>>> + > >>>> + while (len) { > >>>> + const struct vring_desc *orig_desc; > >>>> + > >>>> + read_len = len; > >>>> + orig_desc = vu_gpa_to_va(dev, &read_len, addr); > >>> In case you missed this in my review of v3 (I'm not sure if it's a > >>> valid concern): > >>> > >>> -- > >>> Should we also return if read_len < sizeof(struct vring_desc) after > >>> this call? Can that ever happen, if we pick a particular value of addr > >>> so that it's almost at the end of a region? > >>> -- > >> > >> In fact, read_len can be < sizeof(struct vring_desc) after this call but if orig_desc != > >> NULL it means we can continue in another region to continue to fill the structure. > > > > Right, I see that. > > > >> If there is not enough memory to fill "len" bytes it exits with -1. > > > > ...and this as well. But let's say that read_len is 1 (and struct > > vring_desc is 16 bytes). Then: > > > > memcpy(desc, orig_desc, read_len); > > > > copies one byte > > > > [...] > > > > desc += read_len / sizeof(struct vring_desc); > > > > doesn't increase desc. > > > > At the next iteration with len > 0 and read_len > 0, the memcpy() will > > overwrite that one byte, as we didn't increase desc. Or it's not > > possible for some other reason? > > > > We can add a check for that case, but my guess is memory region size is a multiple of page > size (4k or 64k or ...) so I think we will always be able to read 16 bytes (if we loop on > 16 bytes reads). Ah, okay, it makes sense. I would still suggest to have an explicit check, so that we don't crash if there's an issue in the hypervisor, but it's not a strong preference. -- Stefano