Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp172686pxk; Wed, 9 Sep 2020 02:14:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqIfLBYBvHeS/iDv0o61XrSWUAJxN99T2VoY4Kn0g3i4EdWrhahpTPcqihlFsSUTs6te6+ X-Received: by 2002:a17:906:b09a:: with SMTP id x26mr2635038ejy.162.1599642887736; Wed, 09 Sep 2020 02:14:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599642887; cv=none; d=google.com; s=arc-20160816; b=XZ7oMDhOSAgE5R0O6DffFLawJQPfrZpOayNlYRU8pibw1D8f6PDFPdOECqncfJeRk3 aFri8yRZ4zvUfkFCT8FT8hIwXUjrV+zn8hpWK2Ho5XZH5iGN6upqhlGfJSWtuYBU7zAg VKNi7uY8bMA0VxUmF9sZd0h6TIV80qYKZJm6AlsYM5jQcl7ubz9ngYveLWdAEbsAMItf 1qwKcp7RM3m+6FuSPwq2+htI9LhNFLWh73kQjRM/lbzSMW03hq48daAcXFclPVR/RCiZ D+cCC/7zhk7eAg2Rq8BsLnFfGLMf4R5p0Asu6ksz+F4Ec8NtM+e/5MxpFz9aU2MKQPZ+ +3mQ== 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=Or0B1kf5/NbpMj+500IknwuLZx50ViNptZcj0f47f8A=; b=E39VD+XIx+zJtDnkE4jTPFATzES0k681FjhoF6OFDd8s4veXT6MUKsgbIqiane6M6I +ZbrbwGDoqolCaUjUMHmWXpJtj/2W7YFE4lYDt+HCU7HCPeaqohG+OYWGkpo27DjnZOV 6Nw4sqXicDceBLStV95cehW6IZYyH0Kt1V2arNC3HUIBuslVc74lPaYWc8t9OTXUP86s ROVwl5F3VpNWCk/L9JdZiXc9Ab2RYvF5Ya3l23z36E6ucfxfYQk+sZ44RK2Y1SKk+USw XUpLCHRuI7ptTSORULQ5pmIvcl7hmV+cPu0L4+5DqCy2v4APN7ZHpl/NaPJAT7MmqzlK bqMg== 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 md14si1025136ejb.548.2020.09.09.02.14.25; Wed, 09 Sep 2020 02:14:47 -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 S1730206AbgIIJLJ (ORCPT + 99 others); Wed, 9 Sep 2020 05:11:09 -0400 Received: from mga03.intel.com ([134.134.136.65]:25201 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726440AbgIIJLJ (ORCPT ); Wed, 9 Sep 2020 05:11:09 -0400 IronPort-SDR: N1lFwvp43Hj5BP+jV0ccc/99QRu8OOjMRMRkcSAih399v0ubSlkynaCZCVymyTt3f/qXObn6tD tXU5D3uhvkng== X-IronPort-AV: E=McAfee;i="6000,8403,9738"; a="158329219" X-IronPort-AV: E=Sophos;i="5.76,409,1592895600"; d="scan'208";a="158329219" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Sep 2020 02:11:08 -0700 IronPort-SDR: lD1LoAuQEKx2ApgdPjS+K+iP5Y9R+DFoEZniG+gT3uwR4IofpgGB2vHNkfdL3dlqPuPax9VNex RjhtnkLeR78g== X-IronPort-AV: E=Sophos;i="5.76,409,1592895600"; d="scan'208";a="304428438" Received: from shsi6026.sh.intel.com (HELO localhost) ([10.239.147.135]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Sep 2020 02:11:05 -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 v3 14/17] virt: acrn: Introduce I/O ranges operation interfaces Date: Wed, 9 Sep 2020 17:08:33 +0800 Message-Id: <20200909090836.46762-15-shuo.a.liu@intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200909090836.46762-1-shuo.a.liu@intel.com> References: <20200909090836.46762-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 a9953e4322a5..11acfa1be674 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(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