Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp749586pxj; Wed, 2 Jun 2021 10:25:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJweeehINXBH7AyMwgBD2fKgZDPAhHu0znBT/0P+uhEpIi5HhXCWfjgOAxieW1XCEdUHxTWj X-Received: by 2002:a50:ff0a:: with SMTP id a10mr40005420edu.273.1622654725578; Wed, 02 Jun 2021 10:25:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622654725; cv=none; d=google.com; s=arc-20160816; b=C5ik88u6UGtCnrc2Mv08zQ+5UMfDcRFTP/bYXjnxHxaT2ypu0s7+Tf/SphdOG5NxQK o9XkLTVnVtF9xrKRe/1bO11YTL+qW+6nIKWxxeWBvxILiydmfqeNbmToXwnB2TVpD4fl bDy4/1Ps1A4DsTcMKZHZuujxgqFoTVVKrX73Btyeun8VOb3BUgJOg3sXO73LiUWQt4oJ 6PR2ehyD02C5KXalPmpCq/2pO0q5R01YFXNGmSjQ21UkWMk0in5fnn7HcnZsnIMyErfO 36p697Q1iKSNmJJher5BsLVBs+khTUDs5lQZL/dsJIjefROS950CGpEImWFTdqPz/zvk uh7w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=LqIAPp9b4xr0FaDrJqaVWN3iMnfFRXlJZFkyUUKF0Rc=; b=QKBwGAz74zbkkkXFimQDEdlcWI7zQos164tCGawikLZX5i4FI4e/vNxBQoPgYgZ5L8 sJd1JJhVD8UmidlTRF8UiwfWLr0Kz4qYyPSzSk+1m4kEFas6ma4xWsjomru/hF775Vfi V9qiuCdetYevLF2LJ7xGEp3dO6W/ryEE2pV+3B6jodSwUZRrbOHm9RLM9BCHgtBnASZ0 ZCXo/30y2qSH9DUch5sNtiALHQg/7VspESivLy7o2SkTiRPz8VEAyYRw89FMrW/99iE+ EIih8B8DKV6JHYjXZnuDYWhewhKjJY/do8Bldp/OFH7/NJJRYFprZ5mV9w/3e5orMzvz mqeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=KD89Y0w1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c11si436984edw.282.2021.06.02.10.25.01; Wed, 02 Jun 2021 10:25:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=KD89Y0w1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231329AbhFBRXM (ORCPT + 99 others); Wed, 2 Jun 2021 13:23:12 -0400 Received: from linux.microsoft.com ([13.77.154.182]:51164 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230378AbhFBRWy (ORCPT ); Wed, 2 Jun 2021 13:22:54 -0400 Received: from viremana-dev.fwjladdvyuiujdukmejncen4mf.xx.internal.cloudapp.net (unknown [13.66.132.26]) by linux.microsoft.com (Postfix) with ESMTPSA id 831D120B8016; Wed, 2 Jun 2021 10:21:11 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 831D120B8016 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1622654471; bh=LqIAPp9b4xr0FaDrJqaVWN3iMnfFRXlJZFkyUUKF0Rc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KD89Y0w11I4iJpq6aXWTI6oDHT/ce5KxcTlggBvbLRf9TFe9WNwY8/vonxvJZcIyH Ovl26R8Zs6LI2IhX/hCJtJnbY8WIk54VUDbjiFqy6mmHSdiUPBY8VNC5tEsWFayszD XUeGE2IL29wdb9UmGCDAeW1yZtF4jGyHLBv62/yA= From: Vineeth Pillai To: Nuno Das Neves , Wei Liu , Sunil Muthuswamy , Michael Kelley , Vitaly Kuznetsov Cc: Vineeth Pillai , "K. Y. Srinivasan" , virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org Subject: [PATCH 08/17] mshv: Port id management Date: Wed, 2 Jun 2021 17:20:53 +0000 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Each port in the partition should be uniquely identified by an id. Partition is responsible for managing the port id. Signed-off-by: Vineeth Pillai --- drivers/hv/Makefile | 2 +- drivers/hv/hv_portid_table.c | 83 ++++++++++++++++++++++++++++++++++++ drivers/hv/mshv.h | 35 +++++++++++++++ drivers/hv/mshv_main.c | 2 + 4 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 drivers/hv/hv_portid_table.c diff --git a/drivers/hv/Makefile b/drivers/hv/Makefile index a2b698661b5e..455a2c01f52c 100644 --- a/drivers/hv/Makefile +++ b/drivers/hv/Makefile @@ -13,4 +13,4 @@ hv_vmbus-y := vmbus_drv.o \ hv_vmbus-$(CONFIG_HYPERV_TESTING) += hv_debugfs.o hv_utils-y := hv_util.o hv_kvp.o hv_snapshot.o hv_fcopy.o hv_utils_transport.o -mshv-y += mshv_main.o hv_call.o hv_synic.o +mshv-y += mshv_main.o hv_call.o hv_synic.o hv_portid_table.o diff --git a/drivers/hv/hv_portid_table.c b/drivers/hv/hv_portid_table.c new file mode 100644 index 000000000000..3e8feefc3fc9 --- /dev/null +++ b/drivers/hv/hv_portid_table.c @@ -0,0 +1,83 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include + +#include "mshv.h" + +/* + * Ports and connections are hypervisor struct used for inter-partition + * communication. Port represents the source and connection represents + * the destination. Partitions are responsible for managing the port and + * connection ids. + * + */ + +#define PORTID_MIN 1 +#define PORTID_MAX INT_MAX + +static DEFINE_IDR(port_table_idr); + +void +hv_port_table_fini(void) +{ + struct port_table_info *port_info; + unsigned long i, tmp; + + idr_lock(&port_table_idr); + if (!idr_is_empty(&port_table_idr)) { + idr_for_each_entry_ul(&port_table_idr, port_info, tmp, i) { + port_info = idr_remove(&port_table_idr, i); + kfree_rcu(port_info, rcu); + } + } + idr_unlock(&port_table_idr); +} + +int +hv_portid_alloc(struct port_table_info *info) +{ + int ret = 0; + + idr_lock(&port_table_idr); + ret = idr_alloc(&port_table_idr, info, PORTID_MIN, + PORTID_MAX, GFP_KERNEL); + idr_unlock(&port_table_idr); + + return ret; +} + +void +hv_portid_free(int port_id) +{ + struct port_table_info *info; + + idr_lock(&port_table_idr); + info = idr_remove(&port_table_idr, port_id); + WARN_ON(!info); + idr_unlock(&port_table_idr); + + synchronize_rcu(); + kfree(info); +} + +int +hv_portid_lookup(int port_id, struct port_table_info *info) +{ + struct port_table_info *_info; + int ret = -ENOENT; + + rcu_read_lock(); + _info = idr_find(&port_table_idr, port_id); + rcu_read_unlock(); + + if (_info) { + *info = *_info; + ret = 0; + } + + return ret; +} diff --git a/drivers/hv/mshv.h b/drivers/hv/mshv.h index e16818e977b9..ff5dc02cd8b6 100644 --- a/drivers/hv/mshv.h +++ b/drivers/hv/mshv.h @@ -39,6 +39,41 @@ void mshv_isr(void); int mshv_synic_init(unsigned int cpu); int mshv_synic_cleanup(unsigned int cpu); +/* + * Callback for doorbell events. + * NOTE: This is called in interrupt context. Callback + * should defer slow and sleeping logic to later. + */ +typedef void (*doorbell_cb_t) (void *); + +/* + * port table information + */ +struct port_table_info { + struct rcu_head rcu; + enum hv_port_type port_type; + union { + struct { + u64 reserved[2]; + } port_message; + struct { + u64 reserved[2]; + } port_event; + struct { + u64 reserved[2]; + } port_monitor; + struct { + doorbell_cb_t doorbell_cb; + void *data; + } port_doorbell; + }; +}; + +void hv_port_table_fini(void); +int hv_portid_alloc(struct port_table_info *info); +int hv_portid_lookup(int port_id, struct port_table_info *info); +void hv_portid_free(int port_id); + /* * Hyper-V hypercalls */ diff --git a/drivers/hv/mshv_main.c b/drivers/hv/mshv_main.c index 2adae676dba5..ccf0971d0d39 100644 --- a/drivers/hv/mshv_main.c +++ b/drivers/hv/mshv_main.c @@ -1146,6 +1146,8 @@ __exit mshv_exit(void) cpuhp_remove_state(mshv_cpuhp_online); free_percpu(mshv.synic_pages); + hv_port_table_fini(); + misc_deregister(&mshv_dev); } -- 2.25.1