From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24E99C43331 for ; Sun, 29 Mar 2020 12:25:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D69E82073B for ; Sun, 29 Mar 2020 12:25:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="VHUz0MaS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727998AbgC2MZN (ORCPT ); Sun, 29 Mar 2020 08:25:13 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:50840 "EHLO us-smtp-delivery-74.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727916AbgC2MZN (ORCPT ); Sun, 29 Mar 2020 08:25:13 -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-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-363-8HZDNI0jM6iLHM1IYcqd7A-1; Sun, 29 Mar 2020 08:25:10 -0400 X-MC-Unique: 8HZDNI0jM6iLHM1IYcqd7A-1 Received: by mail-wr1-f71.google.com with SMTP id o18so8411177wrx.9 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=bCQ0FVDiQf2dP7Pu7fxLT8nklAaW2bNjjI14sUGPMn+EOG8D8GzoGFoDHc0QHuK2h7 ChCS08INYAVrDVYj3lnX7M3GwxLk6P8RTSuFYv4kIYjZOFcHSr/M8UuDmi1V37LcVjOW Htu6+Taukn6twhRhjBM4cOpqnIuTOc8uAKcSEq1H1OzpnmulzFuAOgbpsxPWTjHj9ZGK uqERhZijZfA/CqwU5KxBSj6iWRGwIdsHHp5rS20Ehrp+dLuSr+iXNQiutZ3iSh9+vxqH HwwNRX3dayxHBacuZDUKlc2VGLu9aiN7B7pqbnNI1df6G6G5XimAIMXtMO6ZJk/3B0Bj ZJUQ== X-Gm-Message-State: ANhLgQ2wGF9JZi+EnBbxK8d2XCDiorwk0YGzimqZEu//chcj6sPcEMKb InaBN6djjZibxVt7kK77ptOjWaryk0/Ebq76CsKfxyne9WIZ18W9+0d7yBl0DIJGcFGB1OVhA6Y v4Nxm/z+BS4CDbfudrxuL0A== X-Received: by 2002:adf:e942:: with SMTP id m2mr9560605wrn.364.1585484709222; Sun, 29 Mar 2020 05:25:09 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuHbrAQAMGspN3vkSyUCV4rlxQ2qSDmnNPRnKfein9CsAMF+8qjUPe34LCmI1NXow9ZnUY3qA== 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-next-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-next@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 > >