Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp2991716pxb; Mon, 18 Apr 2022 12:54:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8XUoD9g6U7K1L9L6N9wn1UxK79iqhWHRRnekCTEGVmT2LLHRTVGIhFOXi2D744Ic+s2y9 X-Received: by 2002:aa7:c9d2:0:b0:41d:b49:fbc3 with SMTP id i18-20020aa7c9d2000000b0041d0b49fbc3mr13849893edt.245.1650311650682; Mon, 18 Apr 2022 12:54:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650311650; cv=none; d=google.com; s=arc-20160816; b=gjmzQGPXBC19ZDcov+nnntBOCuBj3LZVDF68n8Hy1ohC17+270CKkwyYdEYbtF1Lgh eMuWyiOF0VLxZFxKQyUNwsT1zVPaOIFeUubXO0/VCRIcjv3h8tg+o2NsWd++sIOj2gsb /+z52N/DwQmMkV4FnsnpvsOsJ3qWe5GuCAD+cQlpOH6Qz19+P+bVQz4hfonYZhyCjDM2 ip5/vv8JG3mz1Es83iydb645nexuj7Ay+EGeg7uIprUFHrceuIgj6x6KrFW/FqoIF0Nm VdVj+DZ7DV914mlRi6YhiIBr9z7uirv6W8vFoypeiBS3SHST//JgUyMvihbtXsdBoIq6 jjFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=apqdGBrA7vV6nLOcSwc4j4Duax1hUPkD2hJYjTE39Q8=; b=o/gJfhK/TmPS/yUTJQ/U+8FF+dyfQj4JqfcOt99rUttE1z2qhEZXw1b79XWGuopoQM JaZtcvjh8p8Q5kWwYMqxEvdHyIB3aQz20vCiVshD7ENr474uYcPAUZ/+MFYAPCLzZxn3 89OayAnaNUyQF3OuFhAEn4vGoqY64mQtwHVhniu355QFOWpymegnS2/mmu80qsUhOrHe BZCoDy6/nKtcSwDdw2iV5gyoJhotPz0ONu48MBjuEs5izAbATKjYW7AnUYu+7PiS5Rn2 ukFwwL3QXWEIpqNfRy7PsWJetrJt8gD259izkFd/9apRhr51sTCz9WUIQATWDbXffilH vq9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ASE9RcXQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g26-20020a170906395a00b006df76385cf7si6568915eje.407.2022.04.18.12.53.42; Mon, 18 Apr 2022 12:54:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ASE9RcXQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245053AbiDROE4 (ORCPT + 99 others); Mon, 18 Apr 2022 10:04:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243885AbiDRNqt (ORCPT ); Mon, 18 Apr 2022 09:46:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 198CE29809; Mon, 18 Apr 2022 06:01:05 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6EAD160929; Mon, 18 Apr 2022 13:01:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E3C3C385A1; Mon, 18 Apr 2022 13:01:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650286863; bh=+hLm5oVQl3rCOm+Tv3ZDVA98eqa1DK4EZn9zi/zyyP0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ASE9RcXQMA/7Jw9AFJjfdZpPcp04Ahgk7s2soNEPEsUv9YLrNl2axB39+pLFz33Ut 15xU+kptUK3RiI/pX5mYG4uDEYVUbyYLS9157X0KxIITNa2j+lCv+3zVcA7DH4MUBS EBoLgfpKcgtGi5uclezTXJqnr2Ec8rNbwRPVnPNk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Kelley , "Andrea Parri (Microsoft)" , Wei Liu , Sasha Levin Subject: [PATCH 4.14 270/284] Drivers: hv: vmbus: Prevent load re-ordering when reading ring buffer Date: Mon, 18 Apr 2022 14:14:11 +0200 Message-Id: <20220418121220.532174076@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121210.689577360@linuxfoundation.org> References: <20220418121210.689577360@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michael Kelley [ Upstream commit b6cae15b5710c8097aad26a2e5e752c323ee5348 ] When reading a packet from a host-to-guest ring buffer, there is no memory barrier between reading the write index (to see if there is a packet to read) and reading the contents of the packet. The Hyper-V host uses store-release when updating the write index to ensure that writes of the packet data are completed first. On the guest side, the processor can reorder and read the packet data before the write index, and sometimes get stale packet data. Getting such stale packet data has been observed in a reproducible case in a VM on ARM64. Fix this by using virt_load_acquire() to read the write index, ensuring that reads of the packet data cannot be reordered before it. Preventing such reordering is logically correct, and with this change, getting stale data can no longer be reproduced. Signed-off-by: Michael Kelley Reviewed-by: Andrea Parri (Microsoft) Link: https://lore.kernel.org/r/1648394710-33480-1-git-send-email-mikelley@microsoft.com Signed-off-by: Wei Liu Signed-off-by: Sasha Levin --- drivers/hv/ring_buffer.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c index 74c1dfb8183b..6b08e9d9b382 100644 --- a/drivers/hv/ring_buffer.c +++ b/drivers/hv/ring_buffer.c @@ -340,7 +340,16 @@ int hv_ringbuffer_read(struct vmbus_channel *channel, static u32 hv_pkt_iter_avail(const struct hv_ring_buffer_info *rbi) { u32 priv_read_loc = rbi->priv_read_index; - u32 write_loc = READ_ONCE(rbi->ring_buffer->write_index); + u32 write_loc; + + /* + * The Hyper-V host writes the packet data, then uses + * store_release() to update the write_index. Use load_acquire() + * here to prevent loads of the packet data from being re-ordered + * before the read of the write_index and potentially getting + * stale data. + */ + write_loc = virt_load_acquire(&rbi->ring_buffer->write_index); if (write_loc >= priv_read_loc) return write_loc - priv_read_loc; -- 2.35.1