From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 7DC7693CA for ; Thu, 22 Oct 2015 09:26:53 +0200 (CEST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP; 22 Oct 2015 00:26:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,181,1444719600"; d="scan'208";a="585845349" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by FMSMGA003.fm.intel.com with ESMTP; 22 Oct 2015 00:26:52 -0700 Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.248.2; Thu, 22 Oct 2015 00:26:52 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.96]) by shsmsx102.ccr.corp.intel.com ([169.254.2.253]) with mapi id 14.03.0248.002; Thu, 22 Oct 2015 15:26:49 +0800 From: "Xie, Huawei" To: Yuanhan Liu , "dev@dpdk.org" Thread-Topic: [PATCH v7 4/8] vhost: rxtx: use queue id instead of constant ring index Thread-Index: AdEMmwOTSkREsQdGQpeUH6AYGFOV/w== Date: Thu, 22 Oct 2015 07:26:49 +0000 Message-ID: References: <1445399294-18826-1-git-send-email-yuanhan.liu@linux.intel.com> <1445399294-18826-5-git-send-email-yuanhan.liu@linux.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Cc: "Adams, Steve" , "Michael S. Tsirkin" , "marcel@redhat.com" Subject: Re: [dpdk-dev] [PATCH v7 4/8] vhost: rxtx: use queue id instead of constant ring index X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Oct 2015 07:26:54 -0000 On 10/21/2015 11:48 AM, Yuanhan Liu wrote:=0A= =0A= [...]=0A= > =0A= > #define MAX_PKT_BURST 32=0A= > =0A= > +static inline int __attribute__((always_inline))=0A= > +is_valid_virt_queue_idx(uint32_t virtq_idx, int is_tx, uint32_t max_qp_i= dx)=0A= > +{=0A= > + if ((is_tx ^ (virtq_idx & 0x1)) ||=0A= > + (virtq_idx >=3D max_qp_idx * VIRTIO_QNUM))=0A= > + return 0;=0A= > +=0A= > + return 1;=0A= > +}=0A= > +=0A= > /**=0A= > * This function adds buffers to the virtio devices RX virtqueue. Buffer= s can=0A= > * be received from the physical port or from another virtio device. A p= acket=0A= > @@ -68,12 +78,14 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_= id,=0A= > uint8_t success =3D 0;=0A= > =0A= > LOG_DEBUG(VHOST_DATA, "(%"PRIu64") virtio_dev_rx()\n", dev->device_fh);= =0A= > - if (unlikely(queue_id !=3D VIRTIO_RXQ)) {=0A= > - LOG_DEBUG(VHOST_DATA, "mq isn't supported in this version.\n");=0A= > + if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->virt_qp_nb))) {= =0A= > + RTE_LOG(ERR, VHOST_DATA,=0A= > + "%s (%"PRIu64"): virtqueue idx:%d invalid.\n",=0A= > + __func__, dev->device_fh, queue_id);=0A= > return 0;=0A= > }=0A= > =0A= > - vq =3D dev->virtqueue[VIRTIO_RXQ];=0A= > + vq =3D dev->virtqueue[queue_id];=0A= > count =3D (count > MAX_PKT_BURST) ? MAX_PKT_BURST : count;=0A= > =0A= > /*=0A= >=0A= Besides the always_inline issue, i think we should remove the queue_id=0A= check here in the "data" path. Caller should guarantee that they pass us=0A= the correct queue idx.=0A= We could add VHOST_DEBUG macro for the sanity check for debug purpose only.= =0A= =0A= On the other hand, currently we lack of enough check for the guest=0A= because there could be malicious guests. Plan to fix this in next release.= =0A= =0A= [...]=0A= =0A=