Hi,

On Monday, July 29, 2024 1:51:27 PM GMT+5:30 Eugenio Perez Martin wrote:
> On Sun, Jul 28, 2024 at 7:37 PM Sahil <icegambi...@gmail.com> wrote:
> > [...]
> > > > +static bool vhost_svq_add_packed(VhostShadowVirtqueue *svq,
> > > > +                                const struct iovec *out_sg, size_t 
> > > > out_num,
> > > > +                                const struct iovec *in_sg, size_t 
> > > > in_num,
> > > > +                                unsigned *head)
> > > > +{
> > > > +    bool ok;
> > > > +    uint16_t head_flags = 0;
> > > > +    g_autofree hwaddr *sgs = g_new(hwaddr, out_num + in_num);
> > > > +
> > > > +    *head = svq->vring_packed.next_avail_idx;
> > > > +
> > > > +    /* We need some descriptors here */
> > > > +    if (unlikely(!out_num && !in_num)) {
> > > > +        qemu_log_mask(LOG_GUEST_ERROR,
> > > > +                      "Guest provided element with no descriptors");
> > > > +        return false;
> > > > +    }
> > > > +
> > > > +    uint16_t id, curr, i;
> > > > +    unsigned n;
> > > > +    struct vring_packed_desc *descs = svq->vring_packed.vring.desc;
> > > > +
> > > > +    i = *head;
> > > > +    id = svq->free_head;
> > > > +    curr = id;
> > > > +
> > > > +    size_t num = out_num + in_num;
> > > > +
> > > > +    ok = vhost_svq_translate_addr(svq, sgs, out_sg, out_num);
> > > > +    if (unlikely(!ok)) {
> > > > +        return false;
> > > > +    }
> > > > +
> > > > +    ok = vhost_svq_translate_addr(svq, sgs + out_num, in_sg, in_num);
> > > > +    if (unlikely(!ok)) {
> > > > +        return false;
> > > > +    }
> > > > +
> > > 
> > > (sorry I missed this from the RFC v1) I think all of the above should
> > > be in the caller, isn't it? It is duplicated with split.
> > 
> > I don't think this will be straightforward. While they perform the same
> > logical step in both cases, their implementation is a little different.
> > For example, the "sgs" pointer is created a little differently in both
> > cases.
> 
> Do you mean because MAX() vs in_num+out_num? It is ok to convert both
> to the latter.
> 
> > The parameters to
> > "vhost_svq_translate_addr" is also a little different. I think if they are
> > moved to the caller, they will be in both "svq->is_packed" branches (in
> > "vhost_svq_add").
> I don't see any difference apart from calling it with in and out sgs
> separately or calling it for all of the array, am I missing something?
> 

I tried refactoring this and have sent a new patch series. Please let me
know if I have missed something.

Thanks,
Sahil



Reply via email to