Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2537242ybp; Thu, 10 Oct 2019 08:47:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqzsqU88rY2DwLlL/cdX8poufit33+2hTy7iZk6YAJPIm5SCuMV5WRnHJ7N3EubmgN9FJeQp X-Received: by 2002:a17:906:e108:: with SMTP id gj8mr9104309ejb.1.1570722454987; Thu, 10 Oct 2019 08:47:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570722454; cv=none; d=google.com; s=arc-20160816; b=Cuqg/cubWo/NxvxnLtbMN1atoOIAxOPAu2FiVzfAmX8pAzmnP1qQcJH9BKZkhaTrZm 3fAc56QYzwCKKTiefqsQULaG/ZuMO5/mqTTLJcmyymAP+Qkx4TN1OUdVmo/rXHugS8W7 IrAR9j11p+yrT/t02wC62kTMUIt7h4LcG4Hkt9l3cRAsoF8zabYsI6zWMfXO1FtTgO81 IR0f4KFo70Mx3XzD6Of6ffWlyCX2lnQg3WZebjDl+1hnzEB0f6ODioflm50zvB0lIMvw 2BFvKGBKCugAFrGTreqRyu6BQbi5XFjzgxaRxUp+BxFK7f3shDqONjDJMaQWYYCx32+T JKpA== 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:date:subject:cc:to:from :dkim-signature; bh=xZh1qCpJn2QAbOo99c0vzLdcWFHT9UIhmOuoKjFsElM=; b=w1CduWA5dnMtgFWhgTe6vRbZ93vJC10vtEjvZgdc2BFvARIuwxzZ29CBjmCrBFf4F9 pN3k9nCpFK+OzlJauWzxv/h5HpL8A9zOjzhy1cqbFHvFenKIvO2RhAwtXEXHax5FIaZs ZIK0cJ1wbAeb0RUfXOKUMZ+H6FyIT7vGYBEvsL7yhJJKfwl3o47UlaOtjCEbC6HmkOs8 ehsigVC2x7294N/QYrSuHjwvxsBBHBATUIbXQXCgT+zb+hf0KVNJXd2qBp/u8s6NislS x+0Owj72bN/EMzEB6GKiAf0lYLgHMb/hhG47hvd4A42DB4XvlVSnr3ZXyXZbdEkwJCGo SdpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=YtPiXxpN; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g10si2950147ejc.424.2019.10.10.08.47.11; Thu, 10 Oct 2019 08:47:34 -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=@gmail.com header.s=20161025 header.b=YtPiXxpN; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726546AbfJJPqZ (ORCPT + 99 others); Thu, 10 Oct 2019 11:46:25 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:34267 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726148AbfJJPqY (ORCPT ); Thu, 10 Oct 2019 11:46:24 -0400 Received: by mail-wr1-f67.google.com with SMTP id j11so8533182wrp.1; Thu, 10 Oct 2019 08:46:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xZh1qCpJn2QAbOo99c0vzLdcWFHT9UIhmOuoKjFsElM=; b=YtPiXxpNXtM6Q/G5oAVZD14ilY+pO468GIuMqcUJGDkZUXbN4qczNJoSzBPjCTeCaq W3cPYbIYyohMC+tDEnU1QgfurNWVczGcPdYz6aPMvdENV/Wb4rh/wAC77SkEICzPTIMs 3vpsYK0u828hPPJ6bvc0Q7/uIHLXhWX4w+4dk6utUqH4vimJbbjvp9C96TNwcqRktN38 GeZyoCWkInlhIy1eU8icW0THvOsMv4bb5zLBzD8QRliOKPz+s6nTZDda4e4BpE6QAdN5 ZfE+q4/LRUK7svPiBy7+8kNkz+kFtOCSazTj/tkIL4ZqF1z49zqrFGfH8DgKH9KUjwNi gv+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xZh1qCpJn2QAbOo99c0vzLdcWFHT9UIhmOuoKjFsElM=; b=G97mRvg98w5OvIQuia2RsPMlprRqAe5TczGioUHP5BEuvyBZuCWwfv8YhjBjZtClP0 uo8GHo39yWcW2OfyJLE/ToAgKpiv20flsfqnVfG/VWKzJHfryTLi2ZKV6Jk0cHI7V+zI UVjnDJQ+86ry2FP1WuJrUHcndu2W9u1CwJ35CZ/W35MfMKaWsi+roMPmcMDbb1DaEjPX FB1dVyTSRGRJnQ/5gfP7JVmxtBhfUIQm7NFQ1x29yToE7Lt1fxozTB25ZlQkbU9TR1Xz XQqOCOzKd+9te9FLsZmXGIgETqCqgPk467A/CtBnbU/sUKN3o0Xbs9i/wWSY2kxVUnxn PmMg== X-Gm-Message-State: APjAAAW087QvlajvoAnxWkMxYnpWIsNLADCQnWosNAWYLJ0VPv0Tcff9 QFhXCV7g5bPiPOIGVweeH2583PjmU47omA== X-Received: by 2002:a5d:6949:: with SMTP id r9mr5928459wrw.106.1570722382383; Thu, 10 Oct 2019 08:46:22 -0700 (PDT) Received: from andrea.corp.microsoft.com ([2a01:110:8012:1010:e9a3:da77:7120:dee0]) by smtp.gmail.com with ESMTPSA id u25sm6719807wml.4.2019.10.10.08.46.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 08:46:21 -0700 (PDT) From: Andrea Parri To: linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, netdev@vger.kernel.org Cc: "K . Y . Srinivasan" , Haiyang Zhang , Stephen Hemminger , Sasha Levin , "David S . Miller" , Michael Kelley , Vitaly Kuznetsov , Dexuan Cui , Andrea Parri Subject: [PATCH v2 1/3] Drivers: hv: vmbus: Introduce table of VMBus protocol versions Date: Thu, 10 Oct 2019 17:45:58 +0200 Message-Id: <20191010154600.23875-2-parri.andrea@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191010154600.23875-1-parri.andrea@gmail.com> References: <20191010154600.23875-1-parri.andrea@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The technique used to get the next VMBus version seems increasisly clumsy as the number of VMBus versions increases. Performance is not a concern since this is only done once during system boot; it's just that we'll end up with more lines of code than is really needed. As an alternative, introduce a table with the version numbers listed in order (from the most recent to the oldest). vmbus_connect() loops through the versions listed in the table until it gets an accepted connection or gets to the end of the table (invalid version). Suggested-by: Michael Kelley Signed-off-by: Andrea Parri --- drivers/hv/connection.c | 46 ++++++++++++++--------------------------- drivers/hv/vmbus_drv.c | 3 +-- include/linux/hyperv.h | 4 ---- 3 files changed, 17 insertions(+), 36 deletions(-) diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c index 6e4c015783ffc..b1f805426e6b4 100644 --- a/drivers/hv/connection.c +++ b/drivers/hv/connection.c @@ -40,29 +40,17 @@ EXPORT_SYMBOL_GPL(vmbus_connection); __u32 vmbus_proto_version; EXPORT_SYMBOL_GPL(vmbus_proto_version); -static __u32 vmbus_get_next_version(__u32 current_version) -{ - switch (current_version) { - case (VERSION_WIN7): - return VERSION_WS2008; - - case (VERSION_WIN8): - return VERSION_WIN7; - - case (VERSION_WIN8_1): - return VERSION_WIN8; - - case (VERSION_WIN10): - return VERSION_WIN8_1; - - case (VERSION_WIN10_V5): - return VERSION_WIN10; - - case (VERSION_WS2008): - default: - return VERSION_INVAL; - } -} +/* + * Table of VMBus versions listed from newest to oldest. + */ +static __u32 vmbus_versions[] = { + VERSION_WIN10_V5, + VERSION_WIN10, + VERSION_WIN8_1, + VERSION_WIN8, + VERSION_WIN7, + VERSION_WS2008 +}; int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo, u32 version) { @@ -169,8 +157,8 @@ int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo, u32 version) */ int vmbus_connect(void) { - int ret = 0; struct vmbus_channel_msginfo *msginfo = NULL; + int i, ret = 0; __u32 version; /* Initialize the vmbus connection */ @@ -244,20 +232,18 @@ int vmbus_connect(void) * version. */ - version = VERSION_CURRENT; + for (i = 0; i < ARRAY_SIZE(vmbus_versions); i++) { + version = vmbus_versions[i]; - do { ret = vmbus_negotiate_version(msginfo, version); if (ret == -ETIMEDOUT) goto cleanup; if (vmbus_connection.conn_state == CONNECTED) break; + } - version = vmbus_get_next_version(version); - } while (version != VERSION_INVAL); - - if (version == VERSION_INVAL) + if (vmbus_connection.conn_state != CONNECTED) goto cleanup; vmbus_proto_version = version; diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 391f0b225c9ae..a0cd65ab9a950 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -2215,8 +2215,7 @@ static int vmbus_bus_resume(struct device *dev) * We only use the 'vmbus_proto_version', which was in use before * hibernation, to re-negotiate with the host. */ - if (vmbus_proto_version == VERSION_INVAL || - vmbus_proto_version == 0) { + if (!vmbus_proto_version) { pr_err("Invalid proto version = 0x%x\n", vmbus_proto_version); return -EINVAL; } diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index b4a017093b697..c08b62dbd151f 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -192,10 +192,6 @@ static inline u32 hv_get_avail_to_write_percent( #define VERSION_WIN10 ((4 << 16) | (0)) #define VERSION_WIN10_V5 ((5 << 16) | (0)) -#define VERSION_INVAL -1 - -#define VERSION_CURRENT VERSION_WIN10_V5 - /* Make maximum size of pipe payload of 16K */ #define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384) -- 2.23.0