From patchwork Tue Aug 1 09:01:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tiwei Bie X-Patchwork-Id: 27305 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 [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id EAA249A01; Tue, 1 Aug 2017 11:15:47 +0200 (CEST) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 57FC699FA; Tue, 1 Aug 2017 11:15:46 +0200 (CEST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Aug 2017 02:15:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.41,305,1498546800"; d="scan'208"; a="1157638112" Received: from dpdk19.sh.intel.com ([10.67.111.74]) by orsmga001.jf.intel.com with ESMTP; 01 Aug 2017 02:15:43 -0700 From: Tiwei Bie To: dev@dpdk.org Cc: yliu@fridaylinux.org, maxime.coquelin@redhat.com, stable@dpdk.org Date: Tue, 1 Aug 2017 17:01:21 +0800 Message-Id: <1501578081-191381-1-git-send-email-tiwei.bie@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [dpdk-dev] [PATCH] vhost: make the page logging atomic 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" Each dirty page logging operation should be atomic. But it's not atomic in current implementation. So it's possible that some dirty pages can't be logged successfully when different threads try to log different pages into the same byte of the log buffer concurrently. This patch fixes this issue. Fixes: b171fad1ffa5 ("vhost: log used vring changes") Cc: stable@dpdk.org Reported-by: Xiao Wang Signed-off-by: Tiwei Bie Reviewed-by: Maxime Coquelin --- lib/librte_vhost/vhost.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index 0f294f3..6fe72ae 100644 --- a/lib/librte_vhost/vhost.h +++ b/lib/librte_vhost/vhost.h @@ -201,10 +201,19 @@ struct virtio_net { #define VHOST_LOG_PAGE 4096 +/* + * Atomically set a bit in memory. + */ +static __rte_always_inline void +vhost_set_bit(unsigned int nr, volatile uint8_t *addr) +{ + __sync_fetch_and_or_8(addr, (1U << nr)); +} + static __rte_always_inline void vhost_log_page(uint8_t *log_base, uint64_t page) { - log_base[page / 8] |= 1 << (page % 8); + vhost_set_bit(page % 8, &log_base[page / 8]); } static __rte_always_inline void