From patchwork Tue Sep 19 22:24:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Murphy X-Patchwork-Id: 28971 X-Patchwork-Delegate: yuanhan.liu@linux.intel.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id F2C80F94; Wed, 20 Sep 2017 00:24:16 +0200 (CEST) Received: from mail-qk0-f177.google.com (mail-qk0-f177.google.com [209.85.220.177]) by dpdk.org (Postfix) with ESMTP id A7458DE0 for ; Wed, 20 Sep 2017 00:24:14 +0200 (CEST) Received: by mail-qk0-f177.google.com with SMTP id t67so180496qkl.12 for ; Tue, 19 Sep 2017 15:24:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; h=mime-version:from:date:message-id:subject:to; bh=LFvzA7xR0y8/yEVM9rBA6Z2PXf525r0oRHmbJUCZhlM=; b=hoaAcQSHQX9xU31bjGvIKkZdsHBdLTWbazcQRsOguQxNvAjUAjiq6JI40+0dvA9ul4 y1c5othSVy0kfnlSugdsBNWpnVRJXfietC0RK9aj3cPDSpqqjxLOuI6yp9MWfJbJrEij +GmbwSiCuHNAt89Rtn3U6tocfioUkyjuSKi9w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=LFvzA7xR0y8/yEVM9rBA6Z2PXf525r0oRHmbJUCZhlM=; b=Z5LHdEMUb4ka8nWh/UJ1wdACYIkdfVaeiPyABx7EMcxP2irJTSomnTm31jcW7EeT/U 4gZNxMrZi+1SZa524i7flWQXCajvlylmHSmlMtEsIOW9zLGasy8AjNrb+NVfEZ+KT0JL OuH01IOghud8to9mx0mIru3dirTx5vGNyVrN1v9fgmyllZohTqE4H0gbf7cwsmp3wsrH jqYAUBseKOyNdg6NxVWqjD0E0w7f6AYahuvxJnak+slVTZsfDEe8ryOSa9BnNNe1CB9t n9HA/VdijR0HCcw3PraWMGWL8bK/1UxMRb4jJOZJaNIj+nrY5PEFRxG+XY4QN2gf+eGa OOtA== X-Gm-Message-State: AHPjjUh0Rltp9EVaDbHF8mNy8ZbgRXxspUK4Z/R3kv+GBnjYqPdoVf8E ACE27u23khIQ13P46m4P0+9Vehh0dgoJfK5ZKVssakbxMH4= X-Google-Smtp-Source: AOwi7QBsM8rtYuR1iC9otjHu6otuHU4FLsaB0/hW1RRcdnvZ7SlgRk3IkBVAvk604IGZ9w2BKuaTchWDucphLB4QHQY= X-Received: by 10.55.158.6 with SMTP id h6mr4271379qke.32.1505859853637; Tue, 19 Sep 2017 15:24:13 -0700 (PDT) MIME-Version: 1.0 Received: by 10.140.101.16 with HTTP; Tue, 19 Sep 2017 15:24:13 -0700 (PDT) From: Jim Murphy Date: Tue, 19 Sep 2017 15:24:13 -0700 Message-ID: To: dev@dpdk.org X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Subject: [dpdk-dev] [PATCH v2] net/virtio-user: fix not working on 32-bit system X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Hi, The fix contained in this patch breaks under the following scenario: 1. A 64 bit host and virtual machine. Therefore all physical addresses are 64 bits. 2. A 32 bit user mode DPDK process running on a 64 bit virtual machine (64 bit kernel). In this case, the physical address is 64bits but the virtual address of the user process is 32 bits so uintptr_t is only 32 bits. As a result when: (uintptr_t)(mb) + (vq)->offset) is referenced, only 32 bits are copied into the descriptor but 64 bits are required because in this scenario that is the size of a physical address. So it seems like we need a way to determine the size of the physical address and then VIRTIO_MBUF_ADDR should be written to copy that many bytes into the uint64_t. Does anyone know how to determine the size of the physical address? Thanks, Jim Original Post: virtio-user cannot work on 32-bit system as higher 32-bit of the addr field (64-bit) in the desc is filled with non-zero value which should not happen for a 32-bit system. In case of virtio-user, we use buf_addr of mbuf to fill the virtqueue desc addr. This is a regression bug. For 32-bit system, the first 4 bytes of mbuf is buf_addr, with following 8 bytes for buf_phyaddr. With below wrong definition, both buf_addr and lower 4 bytes buf_phyaddr are obtained to fill the virtqueue desc. #define VIRTIO_MBUF_ADDR(mb, vq) \ (*(uint64_t *)((uintptr_t)(mb) + (vq)->offset)) Fixes: 25f80d108780 ("net/virtio: fix packet corruption") Cc: stable at dpdk.org Signed-off-by: Jianfeng Tan > --- drivers/net/virtio/virtqueue.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) #endif diff --git a/drivers/net/virtio/virtqueue.h b/drivers/net/virtio/virtqueue.h index f9e3736..2e67460 100644 --- a/drivers/net/virtio/virtqueue.h +++ b/drivers/net/virtio/virtqueue.h @@ -69,10 +69,16 @@ struct rte_mbuf; #ifdef RTE_VIRTIO_USER /** - * Return the physical address (or virtual address in case of - * virtio-user) of mbuf data buffer. + * + * Return the physical address of mbuf data buffer for virtio pci: + * on 32-bit system, offset equals 4, return the second four bytes of mbuf; + * on 64-bit system, offset equals 8, return the second eight bytes of mbuf. + * Return the virtual address of mbuf data buffer for virtio-user. + * on 32-bit system, offset equals 0, return the first four bytes of mbuf; + * on 64-bit system, offset equals 0, return the first eight bytes of mbuf; */ -#define VIRTIO_MBUF_ADDR(mb, vq) (*(uint64_t *)((uintptr_t)(mb) + (vq)->offset)) +#define VIRTIO_MBUF_ADDR(mb, vq) \ + ((uint64_t)(*(uintptr_t *)((uintptr_t)(mb) + (vq)->offset))) #else #define VIRTIO_MBUF_ADDR(mb, vq) ((mb)->buf_physaddr)