Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp749103pxj; Wed, 2 Jun 2021 10:24:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxylkVeNVVI4iWRco+daw8tGfQkv/PcAhySTV4sIDtSu9Vkh0eYs5kfdRLSI6F/43laz7DO X-Received: by 2002:aa7:cfd4:: with SMTP id r20mr16524305edy.237.1622654680009; Wed, 02 Jun 2021 10:24:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622654680; cv=none; d=google.com; s=arc-20160816; b=DL3YcWE29axddDmRp4X2EDU5CeL81O6clbh2T02YZ93kjaVPQ0P/OymZBdQ7u1NYMr oM1y/W0oN8sNG/gfJGmDGjhVCwKN8zvGVZu5R2ms8SisIrCQpPtsKHwrYSeahZBUY1qL SNWCsu8/ZCa7Gv88QNfO0GQT/ugg7iWEibCRs3598XoUcePJfKsEeOMq9uapY/fZ9Ct3 MOZC7/xEtLVxjW3hITdOWVklNOUedJ/NVNmbVRDCkEy1qpMqb+UNNo3y4yFLEBJMTH5u hc0Xa1QevHNMPcYujikCMaAHbhwbUSeGLAW1pPJ0vbLOnx+GSzIeOyzhVEDYh5yzf10G +iFg== 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=OJ9pPwP8H50eEvzj/RL3PydJAKG9PhqRRXT3CuRFK7g=; b=032xlESuYXPiR+HWEyDvb6US/LhXjlJf4IIKiVhe45YvUJQP13koHpQYgthi4dla1r gJ+xn6oY/jW9ppO6Q2ZbDV7dHtDAXlJgBpdYRCK8yRGDBeL3QMGrEfb9GjdyeevxHoA2 N6IXm+di7qeB+WBAgcjBX9ek4hW/aehVKVT+1bfDczike5NKM52hjEdrO1UbC3HoOjq1 +BTMR0VmYh9/T9OKZ6t/0NobiomJledR5GdtKqDbme0mPRqgRUXWCCBsKbZefzhLSyat /ToRpQAIVBSN+ED+wwfCo9dcahzR+rkF84BHtdNe6HAUdHwXQYDI05TBtAHmQk0oiAya N2tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=k3VdqdvK; 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 z26si353176eje.396.2021.06.02.10.24.16; Wed, 02 Jun 2021 10:24:39 -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=k3VdqdvK; 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 S231434AbhFBRXU (ORCPT + 99 others); Wed, 2 Jun 2021 13:23:20 -0400 Received: from linux.microsoft.com ([13.77.154.182]:51186 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230394AbhFBRWz (ORCPT ); Wed, 2 Jun 2021 13:22:55 -0400 Received: from viremana-dev.fwjladdvyuiujdukmejncen4mf.xx.internal.cloudapp.net (unknown [13.66.132.26]) by linux.microsoft.com (Postfix) with ESMTPSA id B1E8020B801C; Wed, 2 Jun 2021 10:21:11 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com B1E8020B801C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1622654471; bh=OJ9pPwP8H50eEvzj/RL3PydJAKG9PhqRRXT3CuRFK7g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k3VdqdvKeuGxGAPK9mpFPWh4ZCffwf8JRQX7RdFN3ZZfjZguCYOJAiyJf1HAkHWtL wqqUAYr/cuhnXAi4oH2U/KilP6AdHZH5ldGnRIIf1XnA1WuSV1+X8PN68+aVy+cL+0 PdJai2C3KB+Enjd3G/daA3y4GLgfSvOTpdgeo+eo= 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 10/17] mshv: Doorbell register/unregister API Date: Wed, 2 Jun 2021 17:20:55 +0000 Message-Id: <1a1e91505da1548664060f9e8a73f81423dff100.1622654100.git.viremana@linux.microsoft.com> 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 Doorbell is a mechanism by which a parent partition can register for notification if a specified mmio address is touched by a child partition. Parent partition can setup the notification by specifying mmio address, size of the data written(1/2/4/8 bytes) and optionally the data as well. APIs for registering and unregistering doorbell notification. Signed-off-by: Vineeth Pillai --- drivers/hv/hv_synic.c | 81 +++++++++++++++++++++++++++++++++++++++++++ drivers/hv/mshv.h | 4 +++ 2 files changed, 85 insertions(+) diff --git a/drivers/hv/hv_synic.c b/drivers/hv/hv_synic.c index e3262f6d3daa..af6653967209 100644 --- a/drivers/hv/hv_synic.c +++ b/drivers/hv/hv_synic.c @@ -9,6 +9,7 @@ */ #include +#include #include #include #include @@ -389,3 +390,83 @@ int mshv_synic_cleanup(unsigned int cpu) return 0; } + +int +hv_register_doorbell(u64 partition_id, doorbell_cb_t doorbell_cb, void *data, + u64 gpa, u64 val, u64 flags) +{ + struct hv_connection_info connection_info = { 0 }; + union hv_connection_id connection_id = { 0 }; + struct port_table_info *port_table_info; + struct hv_port_info port_info = { 0 }; + union hv_port_id port_id = { 0 }; + int ret; + + port_table_info = kmalloc(sizeof(struct port_table_info), + GFP_KERNEL); + if (!port_table_info) + return -ENOMEM; + + port_table_info->port_type = HV_PORT_TYPE_DOORBELL; + port_table_info->port_doorbell.doorbell_cb = doorbell_cb; + port_table_info->port_doorbell.data = data; + ret = hv_portid_alloc(port_table_info); + if (ret < 0) { + pr_err("Failed to create the doorbell port!\n"); + kfree(port_table_info); + return ret; + } + + port_id.u.id = ret; + port_info.port_type = HV_PORT_TYPE_DOORBELL; + port_info.doorbell_port_info.target_sint = HV_SYNIC_DOORBELL_SINT_INDEX; + port_info.doorbell_port_info.target_vp = HV_ANY_VP; + ret = hv_call_create_port(hv_current_partition_id, port_id, partition_id, + &port_info, + 0, 0, NUMA_NO_NODE); + + if (ret < 0) { + pr_err("Failed to create the port!\n"); + hv_portid_free(port_id.u.id); + return ret; + } + + connection_id.u.id = port_id.u.id; + connection_info.port_type = HV_PORT_TYPE_DOORBELL; + connection_info.doorbell_connection_info.gpa = gpa; + connection_info.doorbell_connection_info.trigger_value = val; + connection_info.doorbell_connection_info.flags = flags; + + ret = hv_call_connect_port(hv_current_partition_id, port_id, partition_id, + connection_id, &connection_info, 0, NUMA_NO_NODE); + if (ret < 0) { + hv_call_delete_port(hv_current_partition_id, port_id); + hv_portid_free(port_id.u.id); + return ret; + } + + // lets use the port_id as the doorbell_id + return port_id.u.id; +} + +int +hv_unregister_doorbell(u64 partition_id, int doorbell_portid) +{ + int ret = 0; + union hv_port_id port_id = { 0 }; + union hv_connection_id connection_id = { 0 }; + + connection_id.u.id = doorbell_portid; + ret = hv_call_disconnect_port(partition_id, connection_id); + if (ret < 0) + pr_err("Failed to disconnect the doorbell connection!\n"); + + port_id.u.id = doorbell_portid; + ret = hv_call_delete_port(hv_current_partition_id, port_id); + if (ret < 0) + pr_err("Failed to disconnect the doorbell connection!\n"); + + hv_portid_free(doorbell_portid); + + return ret; +} diff --git a/drivers/hv/mshv.h b/drivers/hv/mshv.h index 07b0e7865a4c..76cd00fd4b3f 100644 --- a/drivers/hv/mshv.h +++ b/drivers/hv/mshv.h @@ -74,6 +74,10 @@ 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); +int hv_register_doorbell(u64 partition_id, doorbell_cb_t doorbell_cb, + void *data, u64 gpa, u64 val, u64 flags); +int hv_unregister_doorbell(u64 partition_id, int doorbell_portid); + /* * Hyper-V hypercalls */ -- 2.25.1