Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp548578pxk; Thu, 3 Sep 2020 06:48:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyspBE6bxo4Ygk2D5h6sIfnl7Eb3EJgqKqQM9vZu/LLLP/5e5LUU2BG+fzpDen+H2oshUUH X-Received: by 2002:a50:ec89:: with SMTP id e9mr3380320edr.32.1599140884534; Thu, 03 Sep 2020 06:48:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599140884; cv=none; d=google.com; s=arc-20160816; b=rfU3vzcSdehstm8THpEzG9p08t2oegZ/uLtHgMgW22pkfi0AyNdLUChAjLT3x2sJWl 27HmmJe2MWJvqlwgqUSZbUhp0qGPnsVY71Dhw5O3yinGIDf0+JV2ogAnKFijkC05Rsl2 j0sLY9Hg97qKqo+hMRn/IMaBvn5MkDZ+chEFgbySJ03CUqaSQSlsxL5I8TiCdP+OHbQ0 oZ46QO9xpoLvDrzAvnLE0Y8hqPPzOguL/2/PFb0d8qtajs6r6TesFkv/FYc6n1pdZ901 eEQFu+kBa91cDQpkVLBSo199JYhMeufB308FhUSmCYEPg4MdqGya4StVr2hP7lp4jWzv NM5w== 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 :ironport-sdr:ironport-sdr; bh=XkLTK0W7Y15zpMZWDjvsa8JBkEZzYF2RvlGuaTN4T+I=; b=mmoBiskXe0VHZ0o5bkH7PN/eFqQcpO7nNl2bNL/sccGQqntFJh4B04S6C9yibAalyD cvDFczkoyRU1X442ZpX4Vs5wixPHgD+yHzWo5o6Yhb3zB6E7MLbL4ugP/iyJ9XSddcaK SNqIvh4KTrob+k5+vymSBNm/3r9kxlkqibJbHp5kUVF4LwRiclUbpvWZ+3yF4ueBppp8 d+QjHGz+Q5lCaJVQW2YUL4MFej3n6RWGDYtaaz5WojSFSxdg2lFWJjWkA08mRebkg8Mp sUE4pyAUAv5cPQkEtQqkgbUfCp2v934gPsGp+jezLADqnjgHO8/F7rUKM1dbrYxxqtBv 3kyQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a20si2157307edj.133.2020.09.03.06.47.42; Thu, 03 Sep 2020 06:48:04 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728871AbgICNpn (ORCPT + 99 others); Thu, 3 Sep 2020 09:45:43 -0400 Received: from mga11.intel.com ([192.55.52.93]:9530 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728962AbgICMpv (ORCPT ); Thu, 3 Sep 2020 08:45:51 -0400 IronPort-SDR: EfEbsoBe8jOKzrZAj2+fduQx+oaeF3cy0abA6l+wPXmWH+UPMk7nEsoaMaDOl25hOt3ljutDPQ Ce4kSNR6Vaow== X-IronPort-AV: E=McAfee;i="6000,8403,9732"; a="155069760" X-IronPort-AV: E=Sophos;i="5.76,386,1592895600"; d="scan'208";a="155069760" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Sep 2020 05:43:42 -0700 IronPort-SDR: 5iVsMplXIfUSZJ9rVZxnnxar8iO+OT6l4a/6v0+UHywlcKoGKIE26dvgnEDiFPN6piT+tghm6W G/Hr6wut/gvw== X-IronPort-AV: E=Sophos;i="5.76,386,1592895600"; d="scan'208";a="405467695" Received: from shsi6026.sh.intel.com (HELO localhost) ([10.239.147.135]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Sep 2020 05:43:38 -0700 From: shuo.a.liu@intel.com To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Greg Kroah-Hartman , "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Sean Christopherson , Yu Wang , Reinette Chatre , Shuo Liu , Zhi Wang , Zhenyu Wang Subject: [PATCH v2 14/17] virt: acrn: Introduce I/O ranges operation interfaces Date: Thu, 3 Sep 2020 20:41:58 +0800 Message-Id: <20200903124201.17275-15-shuo.a.liu@intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200903124201.17275-1-shuo.a.liu@intel.com> References: <20200903124201.17275-1-shuo.a.liu@intel.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 From: Shuo Liu An I/O request of a User VM, which is constructed by hypervisor, is distributed by the ACRN Hypervisor Service Module to an I/O client corresponding to the address range of the I/O request. I/O client maintains a list of address ranges. Introduce acrn_ioreq_range_{add,del}() to manage these address ranges. Signed-off-by: Shuo Liu Reviewed-by: Reinette Chatre Cc: Zhi Wang Cc: Zhenyu Wang Cc: Yu Wang Cc: Reinette Chatre Cc: Greg Kroah-Hartman --- drivers/virt/acrn/acrn_drv.h | 4 +++ drivers/virt/acrn/ioreq.c | 60 ++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/drivers/virt/acrn/acrn_drv.h b/drivers/virt/acrn/acrn_drv.h index 84d9a8f80101..cde12eaa492e 100644 --- a/drivers/virt/acrn/acrn_drv.h +++ b/drivers/virt/acrn/acrn_drv.h @@ -198,6 +198,10 @@ struct acrn_ioreq_client *acrn_ioreq_client_create(struct acrn_vm *vm, void *data, bool is_default, const char *name); void acrn_ioreq_client_destroy(struct acrn_ioreq_client *client); +int acrn_ioreq_range_add(struct acrn_ioreq_client *client, + u32 type, u64 start, u64 end); +void acrn_ioreq_range_del(struct acrn_ioreq_client *client, + u32 type, u64 start, u64 end); int acrn_msi_inject(struct acrn_vm *vm, u64 msi_addr, u64 msi_data); diff --git a/drivers/virt/acrn/ioreq.c b/drivers/virt/acrn/ioreq.c index d1e1062e9d75..cf0e05864b99 100644 --- a/drivers/virt/acrn/ioreq.c +++ b/drivers/virt/acrn/ioreq.c @@ -104,6 +104,66 @@ int acrn_ioreq_request_default_complete(struct acrn_vm *vm, u16 vcpu) return ret; } +/** + * acrn_ioreq_range_add() - Add an iorange monitored by an ioreq client + * @client: The ioreq client + * @type: Type (ACRN_IOREQ_TYPE_MMIO or ACRN_IOREQ_TYPE_PORTIO) + * @start: Start address of iorange + * @end: End address of iorange + * + * Return: 0 on success, <0 on error + */ +int acrn_ioreq_range_add(struct acrn_ioreq_client *client, + u32 type, u64 start, u64 end) +{ + struct acrn_ioreq_range *range; + + if (end < start) { + dev_err(client->vm->dev, + "Invalid IO range [0x%llx,0x%llx]\n", start, end); + return -EFAULT; + } + + range = kzalloc(sizeof(*range), GFP_KERNEL); + if (!range) + return -ENOMEM; + + range->type = type; + range->start = start; + range->end = end; + + write_lock_bh(&client->range_lock); + list_add(&range->list, &client->range_list); + write_unlock_bh(&client->range_lock); + + return 0; +} + +/** + * acrn_ioreq_range_del() - Del an iorange monitored by an ioreq client + * @client: The ioreq client + * @type: Type (ACRN_IOREQ_TYPE_MMIO or ACRN_IOREQ_TYPE_PORTIO) + * @start: Start address of iorange + * @end: End address of iorange + */ +void acrn_ioreq_range_del(struct acrn_ioreq_client *client, + u32 type, u64 start, u64 end) +{ + struct acrn_ioreq_range *range; + + write_lock_bh(&client->range_lock); + list_for_each_entry(range, &client->range_list, list) { + if (type == range->type && + start == range->start && + end == range->end) { + list_del(&range->list); + kfree(range); + break; + } + } + write_unlock_bh(&client->range_lock); +} + /* * ioreq_task() is the execution entity of handler thread of an I/O client. * The handler callback of the I/O client is called within the handler thread. -- 2.28.0