Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4315923pxu; Tue, 1 Dec 2020 01:45:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJxSovsKMXu49wtnoSf006pkZZgiBKRkI36yNO4XIMQjzcv0quQAXdnJOWzNtz84ZF7RpHg+ X-Received: by 2002:a17:906:9417:: with SMTP id q23mr2179893ejx.438.1606815918903; Tue, 01 Dec 2020 01:45:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606815918; cv=none; d=google.com; s=arc-20160816; b=l8SgUj7ZfXBNIrpwktxEkBNJUtVArTnVHQcJ4bvIV0hFzyQUK9e5A8bHOfE+bpn5it bRffjIVhsYRbALwWQkhm6CGEjzNk+i0Mt+Zhel1421t2CNHhtsm02UZtr9m3iu6KVhWo Vf2zRLAVizIKoqTbNZ7pf/qEEBOryDOK+My2nJ7ynu5muZHhcgpvB2BJUD2xRy1ivfgw GsqLzN8UuH7HYnQ/Wogy9/qw9ggAryPMuiEGdBAy9k+wuiZLbUyyyKg0omUvrScZu/CM Dcd3+5vUFoRD4JdZBSyGVRS7qwVvlyOS2Ic9RnRxHEgpkbcpm5baNG5jH1bPn8g4ygWD YBew== 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 :ironport-sdr:ironport-sdr; bh=mRuaWuQZREMFimlhgd88rdX0dazMTrmM4f638MdS5YE=; b=f6r5dhTm8XNjApjJ8UINeH7LPcoCfPzATLFOTl18KL2yKJp8bra5e3Z3SVExA+dk1n hsYskQOWzO+EvQBuC73Ck48Crjq27boQ8OIaa5dGyfKO5DRxIBVgS8LdrUypKwpXQKm4 2gca3m0Uhklnc/3sDyE3Tl/NiuRd6akOsVUuhYtEyVtpR2qufoIscLdpF+wY91AcrrVp hKt+AaFcKoXd+AX/N1oZ6rg0kLLSpeMd8ZCKkUieXKFDzO4LGe9ycmLlJJIjn+XJFc5a I801pSPh/GrP1QPjlqnH87Oxi08eqcrcyso7DRK1r6Eo72IefN5eYOuKBiZpq4VKw7AR hW1Q== 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 bt1si760380edb.267.2020.12.01.01.44.56; Tue, 01 Dec 2020 01:45:18 -0800 (PST) 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 S2391046AbgLAJmA (ORCPT + 99 others); Tue, 1 Dec 2020 04:42:00 -0500 Received: from mga14.intel.com ([192.55.52.115]:48042 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388433AbgLAJmA (ORCPT ); Tue, 1 Dec 2020 04:42:00 -0500 IronPort-SDR: OuMc5p2xnJ7qc9e7F0toraLaHmJLRjTbks5AeFTtJcsW5PBycYEnADsNY3BSIcSKEyxwOyHHar xNAJWVAY8HMg== X-IronPort-AV: E=McAfee;i="6000,8403,9821"; a="172012471" X-IronPort-AV: E=Sophos;i="5.78,384,1599548400"; d="scan'208";a="172012471" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2020 01:41:18 -0800 IronPort-SDR: H3Ow2RbDBFZ5JiviuPdPBsRa6xGS/Ol6dc0kwJ+97MAHTDDOwRoMA7V4X4jRNxtC6eaziKf7sL NlTkv1he/jqw== X-IronPort-AV: E=Sophos;i="5.78,384,1599548400"; d="scan'208";a="335030427" Received: from shsi6026.sh.intel.com (HELO localhost) ([10.239.147.88]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2020 01:41:15 -0800 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 v6 14/18] virt: acrn: Introduce I/O ranges operation interfaces Date: Tue, 1 Dec 2020 17:38:49 +0800 Message-Id: <20201201093853.12070-15-shuo.a.liu@intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201201093853.12070-1-shuo.a.liu@intel.com> References: <20201201093853.12070-1-shuo.a.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 542448c88026..862d195d4774 100644 --- a/drivers/virt/acrn/acrn_drv.h +++ b/drivers/virt/acrn/acrn_drv.h @@ -197,6 +197,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 b469f273e20c..7d391c026437 100644 --- a/drivers/virt/acrn/ioreq.c +++ b/drivers/virt/acrn/ioreq.c @@ -101,6 +101,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(acrn_dev.this_device, + "Invalid IO range [0x%llx,0x%llx]\n", start, end); + return -EINVAL; + } + + 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