Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1467129ybb; Sun, 29 Mar 2020 05:33:00 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuvEFVKKVrNqo2RYYBOWIJxl/Cz09zZHIJHkoqd7xSLc0NycZ/rPXIqClrxn0dMCKC4s0Xu X-Received: by 2002:a9d:264a:: with SMTP id a68mr5488685otb.176.1585485180167; Sun, 29 Mar 2020 05:33:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585485180; cv=none; d=google.com; s=arc-20160816; b=aSdcl0SAwRKZ7mI8GB4ASz/F2JFXfonHQGpA8Ch8yRwAtWaX0Ym3Z/e5cn6oN4Wb9I yCSI40urmJdfQFJ8OQF4sFFD5nc9g4b+IsVYK7RfoIsXSWDx3DeZdLY5wwE8nIu2zzOD aHj48PuKTiVF6DUoIyoQ+0oXqL/ZMXmjRK1t7F1hsxFr5htI7KksRgL0xeDY6LZ3JsUd CFAxCmWPzTZjqsNfQMgM0r7i1PYx7k1brKVIbcPlYlzleyFNtdfhGJJ1k966A+bYESqw aVQRluTW+0jWba+a0RRHcibRfriQ6CYYFM9Xa6JLFrjUyYHR9kqKqTlo2kYLdKkC5yli THIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=7vKFOd347o9WoHxHI6B5j1Zjim146jeGZmfmqH7fBaE=; b=bgAbc7aAH5AAk+voFN7h08pbRfNYXKuXaV69k7TdJx1jX8B0+ZRDAcCsT5ANBXq8wB Ccie/1ff7QFxJ+Vp0zlPbCqhb+CNURzhFI3K0wJISE8/fcq5RFHuyzh1UYi/i9yvykP3 lB/pCz/jQf4Dcsff2K9uSvlT5eD2veYxS1AGDnhGSMTYQQqQyDfTcHaDy8vW8Zq2nyFk IC60vvBdLWgtO79JBNEDCHwneM4sPGdTAgwYsjUazj9K2nIPJ9bZOWcWaMhGP2JfyJh3 VuhKD6WPj+EJaO6Jdtv21OvRu0fBF+j4GV2SGSqQPa6rZlZY/FHh9nWA9+HEI8JgqaH4 H/hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VHUz0MaS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x13si4831519oto.105.2020.03.29.05.32.47; Sun, 29 Mar 2020 05:33:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VHUz0MaS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728112AbgC2MZP (ORCPT + 99 others); Sun, 29 Mar 2020 08:25:15 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:52126 "EHLO us-smtp-delivery-74.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728035AbgC2MZO (ORCPT ); Sun, 29 Mar 2020 08:25:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585484712; 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=7vKFOd347o9WoHxHI6B5j1Zjim146jeGZmfmqH7fBaE=; b=VHUz0MaS4vNfPH/0cf3Zf+xwu5h5sHffUwCSz0zS8j0A333VSbvBkh+hV+phUmhOyoRAxJ pNoJ+h/8MkpqRgeZfUFfJCLw0I4zWZi2ikLj+inNBjpba1JmErmu7Up7Ojaf1fo03fa8LU neMk6zH/1A0wjNvjjeARfeaFcCYywO0= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-381-rzRsFZ8PPjGXGwyfzw4NMw-1; Sun, 29 Mar 2020 08:25:10 -0400 X-MC-Unique: rzRsFZ8PPjGXGwyfzw4NMw-1 Received: by mail-wr1-f72.google.com with SMTP id t25so6047565wrb.16 for ; Sun, 29 Mar 2020 05:25:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=7vKFOd347o9WoHxHI6B5j1Zjim146jeGZmfmqH7fBaE=; b=HzqLDPLfNQaqsPuKMrPTT3gEblmJiVAUhhkO5QMGY0fDHelvE79lZJkjR3y7uHTZaX 2Ephn8Vp+uOjiXwBdUynXTk5P3LW8aM/k9sg4nEYBMGwuKL4URfSBuNZ6mOc47TvvtqF LqKZbfdc40E0nqc4Ym/bq8yQTQ6rk4OfVhYGX7MwHv0mOCzlBTTMF3nTzJfx/B/u22Yo nGwQU8Y1hLikb1/5M9qq46iU2N39s8x+80QohtRWlhNTEdpEe2A425mKQjVrNwF8AVJe D3uINKKI06E7zksFT2Xrcx1OB0Taqu3YbEwLU2MnQ0aqhJXCOBK90QbO6/sqA+NQrUlJ dXxg== X-Gm-Message-State: ANhLgQ3pWEKhw3bh2yqcbFNsnaf0HDGND0f4BRzw0lXI8H2R1Bc5V2oC dYK0tZ0k59I9uHc7qQkT9uVcU/Y8VmHWpPz2L9zfxiEAAO7qMwcwlAQTELX9+PGPF35nPZQsXHs Kf2tFKKvn8GhZ6YjQGGQhVHYw X-Received: by 2002:adf:e942:: with SMTP id m2mr9560604wrn.364.1585484709219; Sun, 29 Mar 2020 05:25:09 -0700 (PDT) X-Received: by 2002:adf:e942:: with SMTP id m2mr9560582wrn.364.1585484708917; Sun, 29 Mar 2020 05:25:08 -0700 (PDT) Received: from redhat.com (bzq-79-183-139-129.red.bezeqint.net. [79.183.139.129]) by smtp.gmail.com with ESMTPSA id z129sm16715180wmb.7.2020.03.29.05.25.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Mar 2020 05:25:08 -0700 (PDT) Date: Sun, 29 Mar 2020 08:25:05 -0400 From: "Michael S. Tsirkin" To: Eugenio Perez Martin Cc: "virtualization@lists.linux-foundation.org" , Halil Pasic , Stephen Rothwell , Linux Next Mailing List , kvm list , Cornelia Huck , Christian Borntraeger , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH 0/6] vhost: Reset batched descriptors on SET_VRING_BASE call Message-ID: <20200329082055-mutt-send-email-mst@kernel.org> References: <20200329113359.30960-1-eperezma@redhat.com> <20200329074023-mutt-send-email-mst@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Mar 29, 2020 at 02:19:55PM +0200, Eugenio Perez Martin wrote: > On Sun, Mar 29, 2020 at 1:49 PM Michael S. Tsirkin wrote: > > > > On Sun, Mar 29, 2020 at 01:33:53PM +0200, Eugenio P?rez wrote: > > > Vhost did not reset properly the batched descriptors on SET_VRING_BASE event. Because of that, is possible to return an invalid descriptor to the guest. > > > This series ammend this, and creates a test to assert correct behavior. To do that, they need to expose a new function in virtio_ring, virtqueue_reset_free_head. Not sure if this can be avoided. > > > > Question: why not reset the batch when private_data changes? > > At the moment both net and scsi poke at private data directly, > > if they do this through a wrapper we can use that to > > 1. check that vq mutex is taken properly > > 2. reset batching > > > > This seems like a slightly better API > > > > I didn't do that way because qemu could just SET_BACKEND to -1 and > SET_BACKEND to the same one, with no call to SET_VRING. In this case, > I think that qemu should not change the descriptors already pushed. Well dropping the batch is always safe, batch is an optimization. > I > do agree with the interface to modify private_data properly (regarding > the mutex). > > However, I can see how your proposal is safer, so we don't even need > to check if private_data is != NULL when we have descriptors in the > batch_descs array. Also, this ioctls should not be in the hot path, so > we can change to that mode anyway. > > > > > > > Also, change from https://lkml.org/lkml/2020/3/27/108 is not included, that avoids to update a variable in a loop where it can be updated once. > > > > > > This is meant to be applied on top of eccb852f1fe6bede630e2e4f1a121a81e34354ab in git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git, and some commits should be squashed with that series. > > > > Thanks a lot! I'll apply this for now so Christian can start testing, > > but I'd like the comment above addressed before I push this to Linus. > > > > > Eugenio P?rez (6): > > > tools/virtio: Add --batch option > > > tools/virtio: Add --batch=random option > > > tools/virtio: Add --reset=random > > > tools/virtio: Make --reset reset ring idx > > > vhost: Delete virtqueue batch_descs member > > > fixup! vhost: batching fetches > > > > > > drivers/vhost/test.c | 57 ++++++++++++++++ > > > drivers/vhost/test.h | 1 + > > > drivers/vhost/vhost.c | 12 +++- > > > drivers/vhost/vhost.h | 1 - > > > drivers/virtio/virtio_ring.c | 18 +++++ > > > include/linux/virtio.h | 2 + > > > tools/virtio/linux/virtio.h | 2 + > > > tools/virtio/virtio_test.c | 123 +++++++++++++++++++++++++++++++---- > > > 8 files changed, 201 insertions(+), 15 deletions(-) > > > > > > -- > > > 2.18.1 > >