Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp21262img; Wed, 20 Mar 2019 13:07:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqw4ix7xFyajgCXxeZTfmqXblVjMOj9mXe2ko9xBhB8Rw2Y1gj5VAYqeGXNCqqdoAm4ksYDF X-Received: by 2002:aa7:811a:: with SMTP id b26mr9342100pfi.250.1553112471539; Wed, 20 Mar 2019 13:07:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553112471; cv=none; d=google.com; s=arc-20160816; b=jcuLbGikYvuflp1+KsnnLm7oB/YDwSab1a5j4fq87x0DCn8Y2BkaVQ+idzRjuat9d9 ZfuL1nBxUTTwHIat84fKQjBwunrh6SgV+JsoUyqcYpkxDp5pZ4mEKd5LtoC15+YSUUyk /FltVHHM+7GDTwI7HWP6ghTy6c5nlO/NAGUbUCNiF8KgW4lWQZbfzP2q1vk16Qz0sYqN dM1UoQWC57vbFf0o1IjPBpPZV4phRst1FbISfTAYUeFMQoWYm+Rw3WOCCIjots0+V85l o3wEEJSHRfxotwvtI6owWvkfGmseAPHCjYStdl6HANZ08OJAOl5qD+LuUBYg0rl2RpSA ka8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=xdDPEIia79uGc35RkRI3ur8MSsWm0kMcfVaI5TTx+RA=; b=rNqExaT/8RUMziQxwqnFqLD/kWYgLzvKlA4HJDH4vPqXrfAOguwnGqggNnwuYVu2Uv CDRFgUTZONFDL/TDj9mXlLhEL3YQa1v85bEC5TUUsJdAwfyHSrI4miJpA5vsz9E/Tvdx SAhhZFfL34jbF7n1PKajOrFZSEy/nzkT5Ma6M6tUzsPb6niskvqeB4v3Fs2BeW/zJfA8 SNLqbKqIOnlRFd8zaECP6dXFIKP9Y0vqZXOjkJSCl5JTT3Gut2U2kqmEKf/RZuLnYXbP H+2mw69tdj9HS9Afp0l8Amb8M+Mm8JXXbJKJRuqfwIWHtW11BFWmxAou75a3vLSnzYTI UubQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@networkplumber-org.20150623.gappssmtp.com header.s=20150623 header.b=JfVC2UZ3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j5si2572919pgc.239.2019.03.20.13.07.36; Wed, 20 Mar 2019 13:07:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@networkplumber-org.20150623.gappssmtp.com header.s=20150623 header.b=JfVC2UZ3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727241AbfCTUGX (ORCPT + 99 others); Wed, 20 Mar 2019 16:06:23 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:35998 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727137AbfCTUGX (ORCPT ); Wed, 20 Mar 2019 16:06:23 -0400 Received: by mail-pf1-f193.google.com with SMTP id p10so2706876pff.3 for ; Wed, 20 Mar 2019 13:06:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xdDPEIia79uGc35RkRI3ur8MSsWm0kMcfVaI5TTx+RA=; b=JfVC2UZ3idGczEJfuKhFb6uueH8DsRD90IWXap15PjjPUEQ/wGnAhKyQm4trxg6KZ/ 6Zgwl+ch6gTyuGc9qGkFeFl93J1D+d+wAmZW+Ho4YNhe2b5T0y7tHQH3DBkWQ6fJbA2C 0n4dFne4HxAKBDrv5Cufv5ZAKWx0ELuAIhkWZFcAstSPUoi2yWMwhax1MIS77KfgkLej UW/pWfnIfUGQ5YxSUBjtrkng1yrESMvw4Z1B0IdgLC43X/mACMGliwnJdRJcIRttlF1o cfwYF5Fg4oq9FojaMoOARf7XoHxM+qkS3fe4rATMrX3dIZUTsPM/muRnrSaxajvEUISJ 8g8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xdDPEIia79uGc35RkRI3ur8MSsWm0kMcfVaI5TTx+RA=; b=BBuYBOAi8HR7MAzQDIfkn9IR9SEJr252t/uqxbig2nCuS2l889jGD+SU/OebXg2ID2 ypNcQrH2CeEzS3XO2MNHgU9nD+6XFg9p4/Rbcsgy/w0wUOZHU56RqOjYdrdlzyqWYssf iDXBAhCRB3FbCE4MLt/8NDD+13lANH9V8nEjps/nKVoeImohZCBzF9oUIYkTGLmQGAct J0+HlBaGG3orurMmAvm61+SUs9tYrxI+9zhJPNBUikB/d7m0WIQtjqd9JSfreII+/EHN jhLI67RyvXILypxTpUvvL3//aHnbvToEH3fM/TnQsC4332jJQabPIxdD9Nq6gKE+3q1r 9c8w== X-Gm-Message-State: APjAAAUQDNgyHeyd5GzvO25m7umjNYnm8ifvJXCNnD9CQv8sdd10Thti R/9jisVL/HX/LPm3Ja+Wr5PY2Q== X-Received: by 2002:a65:6483:: with SMTP id e3mr9477237pgv.273.1553112382216; Wed, 20 Mar 2019 13:06:22 -0700 (PDT) Received: from shemminger-XPS-13-9360 (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id g67sm7237602pfg.13.2019.03.20.13.06.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 13:06:22 -0700 (PDT) Date: Wed, 20 Mar 2019 13:06:19 -0700 From: Stephen Hemminger To: Kimberly Brown Cc: Michael Kelley , Long Li , Sasha Levin , Stephen Hemminger , Dexuan Cui , KY Srinivasan , Haiyang Zhang , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 3/3] Drivers: hv: vmbus: Fix race condition with new ring_buffer_info mutex Message-ID: <20190320130619.07e49c97@shemminger-XPS-13-9360> In-Reply-To: <20190317014927.GA60356@ubu-Virtual-Machine> References: <262046fa9e89d5f483ecd5972d86f4f9608dbcc3.1552592620.git.kimbrownkd@gmail.com> <20190314154533.17c8a362@shemminger-XPS-13-9360> <20190317014927.GA60356@ubu-Virtual-Machine> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 16 Mar 2019 21:49:28 -0400 Kimberly Brown wrote: > On Thu, Mar 14, 2019 at 03:45:33PM -0700, Stephen Hemminger wrote: > > On Thu, 14 Mar 2019 13:05:15 -0700 > > "Kimberly Brown" wrote: > > > > > Fix a race condition that can result in a ring buffer pointer being set > > > to null while a "_show" function is reading the ring buffer's data. This > > > problem was discussed here: > > > https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Flkml.org > > > %2Flkml%2F2018%2F10%2F18%2F779&data=02%7C01%7Csthemmin%40microsoft.com > > > %7C1d7557d667b741bdbb6008d6a8b8620f%7C72f988bf86f141af91ab2d7cd011db47%7C1 > > > %7C0%7C636881907217609564&sdata=1bUbLaxsODANM7lCBR8lxyYajNpufuwUW%2FOl > > > vtGu2hU%3D&reserved=0 > > > > > > To fix the race condition, add a new mutex lock to the > > > "hv_ring_buffer_info" struct. Add a new function, > > > "hv_ringbuffer_pre_init()", where a channel's inbound and outbound > > > ring_buffer_info mutex locks are initialized. > > > > > > ... snip ... > > > > Adding more locks will solve the problem but it seems like overkill. > > Why not either use a reference count or an RCU style access for the > > ring buffer? > > I agree that a reference count or RCU could also solve this problem. > Using mutex locks seemed like the most straightforward solution, but > I'll certainly switch to a different approach if it's better! > > Are you concerned about the extra memory required for the mutex locks, > read performance, or something else? Locks in control path are ok, but my concern is performance of the data path which puts packets in/out of rings. To keep reasonable performance, no additional locking should be added in those paths. So if data path is using RCU, can/should the control operations also use it?