Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp5795736ybp; Tue, 15 Oct 2019 05:17:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqzSVQVfeAyyirlZFMFFkpSNNmfQFIiaR1ouBGVKdc+HvWtptRNBSkpB30GoOv+VVtyvq3eY X-Received: by 2002:a05:6402:1686:: with SMTP id a6mr6077675edv.174.1571141824760; Tue, 15 Oct 2019 05:17:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571141824; cv=none; d=google.com; s=arc-20160816; b=Dbobolm2QAPpwoNuSdxQbgAKKe2hQNCrpnD6x6W3hRccWPdLBjnAha4gKYEqVPnBFi c0Ai2Dc4H7hSAdPCf9YXtipYVQOLEiJfFKGVne0FmcxHb9UDk+Tbz8B7wWy8/Yil2dgK qC3ibkZEg/Hhyo7BHWsQe6VD2Okl1dfQFvEvx1oO6VJnHJ3oEy0op+QFmajH8FefDLSe o8Fh/VohSpRxJi4NERvoOLIi9/IDkGnYjI4HqK7Mwc/kgKwB2LxCpCprsMfCMR5UFpAi rBJPnUFcFfWHLb9f/GINqG3q5nPavc97lVbVc323cCWh8JnETVdJ6xkAqyfldIB6DxZc A9Uw== 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=dBUvui5EkolStKapN5CJl6A6wSxDxOynlr2athqyN+Y=; b=XN9hdTO30jlULdDF6NH5yyVEfhLUbG4KtwSI1JV9l9uXWCTqjeTbaNwqmGpjv9+LKU rtXhS7PL0QCvGPPw+avmTVimbS0WjRoyeIdwClk55vxFLeSPcYXPhlh1AJpMojNqgEf8 b+a2K9D12+SkEq2Aa/HJpCP0LvK9AaEfYU7gEXfrkvM+w8mwsy55IRIdB7uzFiPWxKR7 TptFMjaXS6m8MCN0CHlzXif2HT0WBTPsZdXcsbho1KYtD+kQ3aCPjE33TYOvAqwTX7B8 UteT68d5RDIG+BflKKtXLDVbdqfI2P8U8j4E0VFxCN11swyHJf5lvQwLk23MWCN0615E LoWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dwcWLgm6; 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 t4si12517027ejd.328.2019.10.15.05.16.41; Tue, 15 Oct 2019 05:17:04 -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=dwcWLgm6; 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 S1729419AbfJOLrT (ORCPT + 99 others); Tue, 15 Oct 2019 07:47:19 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:36857 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726208AbfJOLrT (ORCPT ); Tue, 15 Oct 2019 07:47:19 -0400 Received: by mail-wm1-f66.google.com with SMTP id m18so19954909wmc.1; Tue, 15 Oct 2019 04:47:16 -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=dBUvui5EkolStKapN5CJl6A6wSxDxOynlr2athqyN+Y=; b=dwcWLgm6xM5Y9bUW1KqdxYjwLgQneImF/FCTkhE3N6yTvho5/Llli7UUK57VPZx70D cTOLiwKTh9zMopsEHbJc1tdPpSSTIZibEdE/DcIaKXhHJ405FxKSwmalp9WnsdqlD5QE UkXYbAo+ytjCX6WIWjHMtQXoBkBBWLLlUQf0+zS1w0lLbLAimW1drwMF+a9P0llutlu0 qYCcttOSpycSgUckWUB4OAshntPG2pAQuvhzt3ZPrcEJCF/MothHITHQ3T4EO5I/wIjQ 0DTF0HQdUtzQAaqwWbepjJ4cOYn1H5mwDHGPOvyHgklVmgcdIBlq6ob4U4ZXx497/ROQ Vp3w== 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=dBUvui5EkolStKapN5CJl6A6wSxDxOynlr2athqyN+Y=; b=tXLwwAoxe5gu/GnBbDZM5Q+rnTA6cGu4GR2VmtNfbDESa/26liEVw9NcE81XtHOf2E S07cnBRF37wtPwbeW42o87UL4cqBDXB/4uhDIP4Zo+E6Bwivf4ImjlnL6uQkpx0VIdVl 2qG0q7Ic4doGetxUeIRveYMHdMZYLXNybAPWBpjYjrftr7aw71HlwurLGY+65c27dbax jHAAeMUv71kYLtlEf9wUm8z32UH5hdQ9aE29InUsBtqxERW9gnaYtGYxJDjfUQcA5WvD U/IScs/uqeyQOsh0q2vCij9IQUMk4npz5jFOLo4kYdwHR2d7aVrdNZ/MpDnsQ+z3riNc Y6yQ== X-Gm-Message-State: APjAAAVIS0MVvwGrqJ7Dd5SW4Cq2M3AxmCJ83Yn+DySSmdjGtpK6rVqC LoWXUNigTMRKpDodb8Nkh4n8s9UhuxegMA== X-Received: by 2002:a1c:a9c5:: with SMTP id s188mr17356846wme.61.1571140035286; Tue, 15 Oct 2019 04:47:15 -0700 (PDT) Received: from andrea.corp.microsoft.com ([2a01:110:8012:1010:8d42:cc61:bfff:65c2]) by smtp.gmail.com with ESMTPSA id u11sm20237307wmd.32.2019.10.15.04.47.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 04:47:14 -0700 (PDT) From: Andrea Parri To: linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org Cc: "K . Y . Srinivasan" , Haiyang Zhang , Stephen Hemminger , Sasha Levin , Michael Kelley , Vitaly Kuznetsov , Dexuan Cui , Wei Liu , Andrea Parri Subject: [PATCH v3 1/3] Drivers: hv: vmbus: Introduce table of VMBus protocol versions Date: Tue, 15 Oct 2019 13:46:44 +0200 Message-Id: <20191015114646.15354-2-parri.andrea@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191015114646.15354-1-parri.andrea@gmail.com> References: <20191015114646.15354-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 | 50 +++++++++++++++-------------------------- drivers/hv/vmbus_drv.c | 3 +-- include/linux/hyperv.h | 4 ---- 3 files changed, 19 insertions(+), 38 deletions(-) diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c index 6e4c015783ffc..8dc48f53c1ac4 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,21 +232,19 @@ int vmbus_connect(void) * version. */ - version = VERSION_CURRENT; + for (i = 0; ; i++) { + if (i == ARRAY_SIZE(vmbus_versions)) + goto cleanup; + + 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) - goto cleanup; + } vmbus_proto_version = version; pr_info("Vmbus version:%d.%d\n", diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 53a60c81e220d..0ac874faf7209 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -2220,8 +2220,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