From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 4C112208D5 for ; Thu, 12 Oct 2023 09:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Ne5qx6cJ" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8488D3 for ; Thu, 12 Oct 2023 02:16:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697102159; 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: in-reply-to:in-reply-to:references:references; bh=4eIreTvOrPbXoRX8kLZoDSLvSMGfzMrvC2GtND0F9cA=; b=Ne5qx6cJsBNHKMzQeTWtxxeXW+EqVWd4EkzUlLaKRorIPK8Feg9examl69LVFVlTw88inC HCwFbSZUtsCJb+5bjrR+v5ABfd/nyeB5kS6z8T3Af78AVQCZJQuLrgflwHekPFOCSpkkle pZ8r7rH9xw7DwEbAlO6Bbddbw/6McEA= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-126-kF-ohkTYMLSEFGOdQLG4XA-1; Thu, 12 Oct 2023 05:15:58 -0400 X-MC-Unique: kF-ohkTYMLSEFGOdQLG4XA-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-32d33e3aea5so561905f8f.0 for ; Thu, 12 Oct 2023 02:15:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697102157; x=1697706957; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=4eIreTvOrPbXoRX8kLZoDSLvSMGfzMrvC2GtND0F9cA=; b=ItZaSOHGgyIkb/XSdFfuJAnxvif4CnPFfheaMdBFQjY7HsoYYhtUDlaMJICXr0YS+U syNVoiQASpwPCW8QaJetOM43GFG/9zjR8qR+RD1m+bAPGBTf+2z1NvN3oXVsKfUHJtri ys2M4un/R4yjOGmK8MiRfbhP0MsAQBXAeS8PjpGZKLg9miNPMNhTMMEuXVWDSjUCsMiu lCKi+2jqbftaz4G6NH9HiahfM51w3kogC+H9vP0WErrGfBq/nzUedhtqZLFRVFJKUDvi fxoNfUGm/djdvwwOMzXUTE56NSpsG5q10kH7EyGnseVh8L5X7VRclK0YQjorGRDKDL8l lmQQ== X-Gm-Message-State: AOJu0YzW9CN9/Z1q9D98nRSQ8DDmKPMR6Jg0hRiMEo8zAWjlZWNoiZQF EqIcvPzwXPfWoOq+2eI7I4Y4U3j1uTS6huO6ioGSXnNp5ZJpkkj5/B1sE0/tOTFfZWgpBfpPF83 KnGt2h8OA+u7RAP1T X-Received: by 2002:a05:6000:790:b0:32c:af13:9084 with SMTP id bu16-20020a056000079000b0032caf139084mr5909607wrb.22.1697102157227; Thu, 12 Oct 2023 02:15:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH7rlxuZwEbkVYUGkhTv9pQBj6vyLGx+IlgJ2DB/HwhEWz42oWGHfUHsA+i3qGbwFoJtnbzXA== X-Received: by 2002:a05:6000:790:b0:32c:af13:9084 with SMTP id bu16-20020a056000079000b0032caf139084mr5909588wrb.22.1697102156824; Thu, 12 Oct 2023 02:15:56 -0700 (PDT) Received: from redhat.com ([2a06:c701:73d2:bf00:e379:826:5137:6b23]) by smtp.gmail.com with ESMTPSA id z19-20020a7bc7d3000000b0040641a9d49bsm18663377wmk.17.2023.10.12.02.15.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 02:15:56 -0700 (PDT) Date: Thu, 12 Oct 2023 05:15:52 -0400 From: "Michael S. Tsirkin" To: Xuan Zhuo Cc: virtualization@lists.linux-foundation.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jason Wang , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , netdev@vger.kernel.org, bpf@vger.kernel.org Subject: Re: [PATCH vhost 01/22] virtio_ring: virtqueue_set_dma_premapped support disable Message-ID: <20231012051416-mutt-send-email-mst@kernel.org> References: <20231011092728.105904-1-xuanzhuo@linux.alibaba.com> <20231011092728.105904-2-xuanzhuo@linux.alibaba.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231011092728.105904-2-xuanzhuo@linux.alibaba.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net On Wed, Oct 11, 2023 at 05:27:07PM +0800, Xuan Zhuo wrote: > virtqueue_set_dma_premapped() adds a new parameter to disable the > virtqueue premapped mode. > > Signed-off-by: Xuan Zhuo > --- > drivers/net/virtio_net.c | 2 +- > drivers/virtio/virtio_ring.c | 11 ++++++++--- > include/linux/virtio.h | 2 +- > 3 files changed, 10 insertions(+), 5 deletions(-) > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > index fe7f314d65c9..6b5f47ebf9b2 100644 > --- a/drivers/net/virtio_net.c > +++ b/drivers/net/virtio_net.c > @@ -737,7 +737,7 @@ static void virtnet_rq_set_premapped(struct virtnet_info *vi) > return; > > for (i = 0; i < vi->max_queue_pairs; i++) { > - if (virtqueue_set_dma_premapped(vi->rq[i].vq)) > + if (virtqueue_set_dma_premapped(vi->rq[i].vq, true)) > continue; > > vi->rq[i].do_dma = true; > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > index 51d8f3299c10..b3ded56722f4 100644 > --- a/drivers/virtio/virtio_ring.c > +++ b/drivers/virtio/virtio_ring.c > @@ -2784,7 +2784,7 @@ EXPORT_SYMBOL_GPL(virtqueue_resize); > * 0: success. > * -EINVAL: vring does not use the dma api, so we can not enable premapped mode. > */ > -int virtqueue_set_dma_premapped(struct virtqueue *_vq) > +int virtqueue_set_dma_premapped(struct virtqueue *_vq, bool mode) > { > struct vring_virtqueue *vq = to_vvq(_vq); > u32 num; > @@ -2803,8 +2803,13 @@ int virtqueue_set_dma_premapped(struct virtqueue *_vq) > return -EINVAL; > } > > - vq->premapped = true; > - vq->do_unmap = false; > + if (mode) { > + vq->premapped = true; > + vq->do_unmap = false; > + } else { > + vq->premapped = false; > + vq->do_unmap = vq->use_dma_api; > + } > > END_USE(vq); > > diff --git a/include/linux/virtio.h b/include/linux/virtio.h > index 4cc614a38376..1cf7b004348b 100644 > --- a/include/linux/virtio.h > +++ b/include/linux/virtio.h > @@ -81,7 +81,7 @@ bool virtqueue_enable_cb(struct virtqueue *vq); > > unsigned virtqueue_enable_cb_prepare(struct virtqueue *vq); > > -int virtqueue_set_dma_premapped(struct virtqueue *_vq); > +int virtqueue_set_dma_premapped(struct virtqueue *_vq, bool mode); > > bool virtqueue_poll(struct virtqueue *vq, unsigned); Wait a sec I thought we never change premapped. If you make this dynamic don't you need a bunch of locking? Or maybe queue is empty when you change this? If yes pls add a bunch of BUG_ON checks to make sure this is not misused. > -- > 2.32.0.3.g01195cf9f