Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp656449ybe; Wed, 11 Sep 2019 02:39:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqyKq+lHwK2EmHuUZCEvo8UE8OzTITNpDwvwk81ElxyL+LqV0SNwdy5GowSuhST2ZMwlzccw X-Received: by 2002:a50:eb4c:: with SMTP id z12mr35783260edp.155.1568194764639; Wed, 11 Sep 2019 02:39:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568194764; cv=none; d=google.com; s=arc-20160816; b=VHM/KX6dvdR3VhFDfCqyRr26Qf2MvijMxPBhafM5vSZj362GaTSl7sC40kPkmqyl0C SsA6roa9vu7txTOMfgZxgF3ZtBxqOEFu8DGxGWzMGKzyGlAAMoTh1pYy8mplnnAeKwDb k6Hxi0ltgg+jU1+3byjxYb9aPl7nAfvvxP2bYmBX2F+qW28UdtU6rnm4xDNuPQ3eM5zP 6sTVMCx/F95BlZUvQD0+eh3JB39uhSNX7NGnlXnlMoupCipGq1JXSMBiwsTR7XVkax9v cOPXabyEfF3g3GUCwopiEWZvBjgVfjhO/VHr90F+BPPXliQ71LjpOrZzruqOa+A1f+vC nmcg== 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; bh=Pl8aywfJEsNYEX8Cjmv4sK/xJV1YVyk6NPEurxInDFs=; b=LyESjTnpz0j7Evj3f9xlZpD4eKD3ajM5iLyNQdqbSpkE+8hzvYTAomTBuxsn+Q7P3n IN9mDsHd9zdrQKQI8C5C3hkVpM0xXIeSxRxcpAhAPeVT5ZTIbt3Pj3pljZtObgZG6eWo 9c1EeZYv0SjAH0vCmLsc6kT92dQ3PkfDwJANVx5wqUrnbvAvO9QWQIPgQDDhvlJqbNG5 pKl/O4+DUeKGg/lqnQbcmEMRvyeKNF40oBfDNKYkCy/pZV1VSj6DC93uF93kOuOo9KEg L8IT0fHw0Dw6dLShSJwn0Dj6LHRlBAqX7p9zWZj2Kvw8cRz0etVwfTUFKRTsUni2Xj4X AZeA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 u15si10399322ejx.216.2019.09.11.02.39.00; Wed, 11 Sep 2019 02:39:24 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727521AbfIKJg6 (ORCPT + 99 others); Wed, 11 Sep 2019 05:36:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33960 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727329AbfIKJg5 (ORCPT ); Wed, 11 Sep 2019 05:36:57 -0400 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E26D54FCDA for ; Wed, 11 Sep 2019 09:36:56 +0000 (UTC) Received: by mail-qt1-f198.google.com with SMTP id v16so23122206qtp.14 for ; Wed, 11 Sep 2019 02:36:56 -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=Pl8aywfJEsNYEX8Cjmv4sK/xJV1YVyk6NPEurxInDFs=; b=qB88aF6pcW+hBLjIlJGPe+fMybxPhyz/Jnor6tzOpFn4MKUUU8jqbatVsLK1EEmJcv SmTmWkysyfhnxeKiyfE2/m0/Co+2iDxTB6H/O7mq3+Xu7ilomiUBpYmgKGTIZoIQgZLD tK+ZAjU8b/vJnnbNeD/odQvxIc8xUxaQrSP4ZTzXzLedhe/9pgxbhSkO7bGbWwy1HNxS FWmp7WyEN2EkNcBfISJnjOZnXUkAf6xjiCCNTG8oEZwxzvlryJ7zCoHLDZ1epeeWK7AR mBmU5oogKo/rkd6bShL8lohECnkx+/qCAo2YioB++JvJfajcQ31PWcB/ApLhk8JiMAY4 T8GQ== X-Gm-Message-State: APjAAAX24upswhCaBZ2n/T1/YilwXjcElOqImRnAPFyqqZd/vzwVcE6z MMfYJh9meXMdxTvIFCCMAcsj4fkWsvR+lqVLGOMrqN86A+5ig71S2S0ngfKXRwFM0GjA/K6lG9f O81+EXn9F8JjlgxCbHCdBpOn3 X-Received: by 2002:ac8:6b8b:: with SMTP id z11mr25874583qts.294.1568194616187; Wed, 11 Sep 2019 02:36:56 -0700 (PDT) X-Received: by 2002:ac8:6b8b:: with SMTP id z11mr25874563qts.294.1568194616000; Wed, 11 Sep 2019 02:36:56 -0700 (PDT) Received: from redhat.com ([80.74.107.118]) by smtp.gmail.com with ESMTPSA id j7sm13058768qtc.73.2019.09.11.02.36.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2019 02:36:55 -0700 (PDT) Date: Wed, 11 Sep 2019 05:36:47 -0400 From: "Michael S. Tsirkin" To: Jason Wang Cc: kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kwankhede@nvidia.com, alex.williamson@redhat.com, cohuck@redhat.com, tiwei.bie@intel.com, maxime.coquelin@redhat.com, cunming.liang@intel.com, zhihong.wang@intel.com, rob.miller@broadcom.com, idos@mellanox.com, xiao.w.wang@intel.com, haotian.wang@sifive.com Subject: Re: [RFC PATCH 3/4] virtio: introudce a mdev based transport Message-ID: <20190911053502-mutt-send-email-mst@kernel.org> References: <20190910081935.30516-1-jasowang@redhat.com> <20190910081935.30516-4-jasowang@redhat.com> <20190910055744-mutt-send-email-mst@kernel.org> <572ffc34-3081-8503-d3cc-192edc9b5311@redhat.com> <20190910094807-mutt-send-email-mst@kernel.org> <390647ae-0a53-5f2b-ccb0-28ed657636e6@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <390647ae-0a53-5f2b-ccb0-28ed657636e6@redhat.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 11, 2019 at 10:38:39AM +0800, Jason Wang wrote: > > On 2019/9/10 下午9:52, Michael S. Tsirkin wrote: > > On Tue, Sep 10, 2019 at 09:13:02PM +0800, Jason Wang wrote: > > > On 2019/9/10 下午6:01, Michael S. Tsirkin wrote: > > > > > +#ifndef _LINUX_VIRTIO_MDEV_H > > > > > +#define _LINUX_VIRTIO_MDEV_H > > > > > + > > > > > +#include > > > > > +#include > > > > > +#include > > > > > + > > > > > +/* > > > > > + * Ioctls > > > > > + */ > > > > Pls add a bit more content here. It's redundant to state these > > > > are ioctls. Much better to document what does each one do. > > > > > > Ok. > > > > > > > > > > > + > > > > > +struct virtio_mdev_callback { > > > > > + irqreturn_t (*callback)(void *); > > > > > + void *private; > > > > > +}; > > > > > + > > > > > +#define VIRTIO_MDEV 0xAF > > > > > +#define VIRTIO_MDEV_SET_VQ_CALLBACK _IOW(VIRTIO_MDEV, 0x00, \ > > > > > + struct virtio_mdev_callback) > > > > > +#define VIRTIO_MDEV_SET_CONFIG_CALLBACK _IOW(VIRTIO_MDEV, 0x01, \ > > > > > + struct virtio_mdev_callback) > > > > Function pointer in an ioctl parameter? How does this ever make sense? > > > > > > I admit this is hacky (casting). > > > > > > > > > > And can't we use a couple of registers for this, and avoid ioctls? > > > > > > Yes, how about something like interrupt numbers for each virtqueue and > > > config? > > Should we just reuse VIRTIO_PCI_COMMON_Q_XXX then? > > > You mean something like VIRTIO_PCI_COMMON_Q_MSIX? Then it becomes a PCI > transport in fact. And using either MSIX or irq number is actually another > layer of indirection. So I think we can just write callback function and > parameter through registers. I just realized, all these registers are just encoded so you can pass stuff through read/write. But it can instead be just a normal C function call with no messy encoding. So why do we want to do this encoding? > > > > > > > > > > + > > > > > +#define VIRTIO_MDEV_DEVICE_API_STRING "virtio-mdev" > > > > > + > > > > > +/* > > > > > + * Control registers > > > > > + */ > > > > > + > > > > > +/* Magic value ("virt" string) - Read Only */ > > > > > +#define VIRTIO_MDEV_MAGIC_VALUE 0x000 > > > > > + > > > > > +/* Virtio device version - Read Only */ > > > > > +#define VIRTIO_MDEV_VERSION 0x004 > > > > > + > > > > > +/* Virtio device ID - Read Only */ > > > > > +#define VIRTIO_MDEV_DEVICE_ID 0x008 > > > > > + > > > > > +/* Virtio vendor ID - Read Only */ > > > > > +#define VIRTIO_MDEV_VENDOR_ID 0x00c > > > > > + > > > > > +/* Bitmask of the features supported by the device (host) > > > > > + * (32 bits per set) - Read Only */ > > > > > +#define VIRTIO_MDEV_DEVICE_FEATURES 0x010 > > > > > + > > > > > +/* Device (host) features set selector - Write Only */ > > > > > +#define VIRTIO_MDEV_DEVICE_FEATURES_SEL 0x014 > > > > > + > > > > > +/* Bitmask of features activated by the driver (guest) > > > > > + * (32 bits per set) - Write Only */ > > > > > +#define VIRTIO_MDEV_DRIVER_FEATURES 0x020 > > > > > + > > > > > +/* Activated features set selector - Write Only */ > > > > > +#define VIRTIO_MDEV_DRIVER_FEATURES_SEL 0x024 > > > > > + > > > > > +/* Queue selector - Write Only */ > > > > > +#define VIRTIO_MDEV_QUEUE_SEL 0x030 > > > > > + > > > > > +/* Maximum size of the currently selected queue - Read Only */ > > > > > +#define VIRTIO_MDEV_QUEUE_NUM_MAX 0x034 > > > > > + > > > > > +/* Queue size for the currently selected queue - Write Only */ > > > > > +#define VIRTIO_MDEV_QUEUE_NUM 0x038 > > > > > + > > > > > +/* Ready bit for the currently selected queue - Read Write */ > > > > > +#define VIRTIO_MDEV_QUEUE_READY 0x044 > > > > Is this same as started? > > > > > > Do you mean "status"? > > I really meant "enabled", didn't remember the correct name. > > As in: VIRTIO_PCI_COMMON_Q_ENABLE > > > Yes, it's the same. > > Thanks > > > > > > > > > + > > > > > +/* Alignment of virtqueue - Read Only */ > > > > > +#define VIRTIO_MDEV_QUEUE_ALIGN 0x048 > > > > > + > > > > > +/* Queue notifier - Write Only */ > > > > > +#define VIRTIO_MDEV_QUEUE_NOTIFY 0x050 > > > > > + > > > > > +/* Device status register - Read Write */ > > > > > +#define VIRTIO_MDEV_STATUS 0x060 > > > > > + > > > > > +/* Selected queue's Descriptor Table address, 64 bits in two halves */ > > > > > +#define VIRTIO_MDEV_QUEUE_DESC_LOW 0x080 > > > > > +#define VIRTIO_MDEV_QUEUE_DESC_HIGH 0x084 > > > > > + > > > > > +/* Selected queue's Available Ring address, 64 bits in two halves */ > > > > > +#define VIRTIO_MDEV_QUEUE_AVAIL_LOW 0x090 > > > > > +#define VIRTIO_MDEV_QUEUE_AVAIL_HIGH 0x094 > > > > > + > > > > > +/* Selected queue's Used Ring address, 64 bits in two halves */ > > > > > +#define VIRTIO_MDEV_QUEUE_USED_LOW 0x0a0 > > > > > +#define VIRTIO_MDEV_QUEUE_USED_HIGH 0x0a4 > > > > > + > > > > > +/* Configuration atomicity value */ > > > > > +#define VIRTIO_MDEV_CONFIG_GENERATION 0x0fc > > > > > + > > > > > +/* The config space is defined by each driver as > > > > > + * the per-driver configuration space - Read Write */ > > > > > +#define VIRTIO_MDEV_CONFIG 0x100 > > > > Mixing device and generic config space is what virtio pci did, > > > > caused lots of problems with extensions. > > > > It would be better to reserve much more space. > > > > > > I see, will do this. > > > > > > Thanks > > > > > > > > > > > > > > > + > > > > > +#endif > > > > > + > > > > > + > > > > > +/* Ready bit for the currently selected queue - Read Write */ > > > > > -- > > > > > 2.19.1