From patchwork Wed Mar 7 14:28:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 882636 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 3zxGGl35kpz9sch; Thu, 8 Mar 2018 01:28:47 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1eta3f-0008DT-NE; Wed, 07 Mar 2018 14:28:43 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1eta3d-0008Bu-Nx for kernel-team@lists.ubuntu.com; Wed, 07 Mar 2018 14:28:41 +0000 Received: from mail-wm0-f69.google.com ([74.125.82.69]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1eta3d-00024u-GD for kernel-team@lists.ubuntu.com; Wed, 07 Mar 2018 14:28:41 +0000 Received: by mail-wm0-f69.google.com with SMTP id a3so1235397wme.1 for ; Wed, 07 Mar 2018 06:28:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=mgG/ruDTwGfq8tLom1xWKBJ/GGdfCgpWIlrhz6MsK+8=; b=ULiIsVnkej+X/eoUx7HTDfsWG4kEVDTTs0uaL2JtTz9fA+KPygE2EmKC3UliMCLfPY v6VgZxId2FcTcwQzURn7v5oaDh23ieOrpqM5hFTu+HB8P6XZOYCOYBwkZza9NamC0qXK SRkN0NY03MjCjaolYExCakNXAJc2fzXpxuc4NoS6+3KMdJukOfVp8ungA6DV1EpDrF8f ij/uchtScmFJqGOvEeb8s9sRWHeDhpr6cser0WUK9rofXVsxmCu84F7slxNQGONgQADN dNmvcbJhUoClCEFBRwFNybZDl9Rsmm+lH162nGFNeS+oM3iTyFmG6vWKIed0MfKU2mEi XFnQ== X-Gm-Message-State: AElRT7FRsFef6ui1iUiCDfLHls7AgsXzmXlYXqc9zsl8Letauq2r9hgg Lk962a8uuU4ycPAPraLdh9+Po0NLm6jEWmxpc6G2p40jzzQZuOl8kqRHocuKeU5CsTVmK/wCJR5 5hFxIK7308q2fbOZPCmPh4hPzdn69O2/lyIEPh0UG X-Received: by 10.28.118.20 with SMTP id r20mr5178024wmc.145.1520432920873; Wed, 07 Mar 2018 06:28:40 -0800 (PST) X-Google-Smtp-Source: AG47ELs2RnssiXSVsJN/RKxC5GH9pP6mrJeLzDzIDeR3Pg2YjQip3uqawm3P8KYbmSZEOdrvUQIJNw== X-Received: by 10.28.118.20 with SMTP id r20mr5178008wmc.145.1520432920588; Wed, 07 Mar 2018 06:28:40 -0800 (PST) Received: from localhost.localdomain ([37.220.133.201]) by smtp.gmail.com with ESMTPSA id 4sm10124603wmz.31.2018.03.07.06.28.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Mar 2018 06:28:39 -0800 (PST) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [azure:x][PATCH v2 4/4] Subject: hv: vmbus: Fix ring buffer signaling Date: Wed, 7 Mar 2018 11:28:31 -0300 Message-Id: <1520432911-4667-5-git-send-email-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520432911-4667-1-git-send-email-marcelo.cerri@canonical.com> References: <1520432911-4667-1-git-send-email-marcelo.cerri@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Michael Kelley BugLink: http://bugs.launchpad.net/bugs/1748662 Fix bugs in signaling the Hyper-V host when freeing space in the host->guest ring buffer: 1. The interrupt_mask must not be used to determine whether to signal on the host->guest ring buffer 2. The ring buffer write_index must be read (via hv_get_bytes_to_write) *after* pending_send_sz is read in order to avoid a race condition 3. Comparisons with pending_send_sz must treat the "equals" case as not-enough-space 4. Don't signal if the pending_send_sz feature is not present. Older versions of Hyper-V that don't implement this feature will poll. Fixes: 03bad714a161 ("vmbus: more host signalling avoidance") Signed-off-by: Michael Kelley Signed-off-by: Marcelo Henrique Cerri --- drivers/hv/ring_buffer.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c index 12eb8caa4263..c28217f4e8f2 100644 --- a/drivers/hv/ring_buffer.c +++ b/drivers/hv/ring_buffer.c @@ -400,7 +400,11 @@ EXPORT_SYMBOL_GPL(__hv_pkt_iter_next); void hv_pkt_iter_close(struct vmbus_channel *channel) { struct hv_ring_buffer_info *rbi = &channel->inbound; - u32 orig_write_sz = hv_get_bytes_to_write(rbi); + u32 curr_write_sz; + u32 delta = rbi->ring_buffer->read_index < rbi->priv_read_index ? + (rbi->priv_read_index - rbi->ring_buffer->read_index) : + (rbi->ring_datasize - rbi->ring_buffer->read_index + + rbi->priv_read_index); /* * Make sure all reads are done before we update the read index since @@ -423,27 +427,31 @@ void hv_pkt_iter_close(struct vmbus_channel *channel) */ virt_mb(); - /* If host has disabled notifications then skip */ - if (rbi->ring_buffer->interrupt_mask) - return; - if (rbi->ring_buffer->feature_bits.feat_pending_send_sz) { u32 pending_sz = READ_ONCE(rbi->ring_buffer->pending_send_sz); /* + * Ensure the read of write_index in hv_get_bytes_to_write() + * happens after the read of pending_send_sz. + */ + virt_rmb(); + curr_write_sz = hv_get_bytes_to_write(rbi); + + /* * If there was space before we began iteration, * then host was not blocked. Also handles case where * pending_sz is zero then host has nothing pending * and does not need to be signaled. */ - if (orig_write_sz > pending_sz) + if (curr_write_sz - delta > pending_sz) return; /* If pending write will not fit, don't give false hope. */ - if (hv_get_bytes_to_write(rbi) < pending_sz) + if (curr_write_sz <= pending_sz) return; + + vmbus_setevent(channel); } - vmbus_setevent(channel); } EXPORT_SYMBOL_GPL(hv_pkt_iter_close);