Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp377481ybl; Thu, 15 Aug 2019 19:35:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqz9cwKsZD2DWYjlhKBJHTvqGkDljwYk/TTQldcK2FdIY1BQbt4rTwd+j3MeF2LMZkllrWDb X-Received: by 2002:aa7:8b11:: with SMTP id f17mr8523762pfd.19.1565922959203; Thu, 15 Aug 2019 19:35:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565922959; cv=none; d=google.com; s=arc-20160816; b=UYsCeyzPlqhf6MMB/q5NOpeDQtVW6ZoYXhzj3gJfReFBXBIAXyzdgCAHuBJP0GtDe3 OsWmf8UvtpCSY4zQZyNr/8h3KiSEy7Y52thKUigi4wb8y2rgRIUFUOme/aiFp5MQwyQR fUc5mgYqR6Vkr2iWYjrBiuV69+OCsKM1AEo4nD5Mbq7bgZVioUCFp+7mYRz/Jj58lBDz fZ/IOdNhOAVh76rXJ1IPvhHLaT3q/StXOASP9AFKH++ZLKtndgzzZ6UQ+/3OR48EnPoE JQ2i1kL6NYtGrvKz1Dgf7Hue+0dcMZa9vAR/h/ct9R692Y8aEeJcK0DZ2OeIpTsJACdl CaQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=7IeWB/w+MFqs7NluQsXYxK0ZaSsP7HPcYoVnkmtDiHg=; b=DL0fNwq7HMPPrU0U8WsPbjH85YN0+AUgTi3DT8cKAeZC7Eh4Z6EqTsR+pZtl/177HC 6WxlPNtK70SSzK4bcN7YumiUNCDnlqg9cZ35DvRoqMy+SCXDvpKT96so6ykeCHstXXoI H+Kc5+DnpdJ5FP8fYsbAgqYuQij4eIYgdn7jIrN1RUv7LKdX4bg8U0o/Qg8/XRBNyHEY 7ClkLKCIG9h6Yl+I4vxgfCr7xtUWp4SREkMccbv3qdc6PrpR9xSrI0sI5i4T+di8yG10 QefeTdI+sIRKMy5Di5lo4y6VhOIqOAkciW3dUY244FXLucc0Cqlcb/et8Bfjk6SGJmeF Bw9w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id g34si1471104pld.86.2019.08.15.19.35.43; Thu, 15 Aug 2019 19:35:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1726730AbfHPCdV (ORCPT + 99 others); Thu, 15 Aug 2019 22:33:21 -0400 Received: from mga09.intel.com ([134.134.136.24]:24701 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726694AbfHPCdT (ORCPT ); Thu, 15 Aug 2019 22:33:19 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Aug 2019 19:33:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,391,1559545200"; d="scan'208";a="194894538" Received: from genxtest-ykzhao.sh.intel.com ([10.239.143.71]) by fmsmga001.fm.intel.com with ESMTP; 15 Aug 2019 19:33:17 -0700 From: Zhao Yakui To: x86@kernel.org, linux-kernel@vger.kernel.org, devel@driverdev.osuosl.org Cc: Zhao Yakui , Jason Chen CJ , Mingqiang Chi , Liu Shuo Subject: [RFC PATCH 12/15] drivers/acrn: add driver-specific IRQ handle to dispatch IO_REQ request Date: Fri, 16 Aug 2019 10:25:53 +0800 Message-Id: <1565922356-4488-13-git-send-email-yakui.zhao@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1565922356-4488-1-git-send-email-yakui.zhao@intel.com> References: <1565922356-4488-1-git-send-email-yakui.zhao@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org After ACRN hypervisor captures the io_request(mmio, IO, PCI access) from guest OS, it will send the IRQ interrupt to SOS system. The HYPERVISOR_CALLBACK_VECTOR ISR handler will be executed and it needs to call the driver-specific ISR handler to dispatch emulated io_request. After the emulation of ioreq request is finished, the ACRN hypervisor is notified and then can resume the execution of guest OS. Co-developed-by: Jason Chen CJ Signed-off-by: Jason Chen CJ Co-developed-by: Mingqiang Chi Signed-off-by: Mingqiang Chi Co-developed-by: Liu Shuo Signed-off-by: Liu Shuo Signed-off-by: Zhao Yakui --- drivers/staging/acrn/acrn_dev.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/staging/acrn/acrn_dev.c b/drivers/staging/acrn/acrn_dev.c index 28258fb..93f45e3 100644 --- a/drivers/staging/acrn/acrn_dev.c +++ b/drivers/staging/acrn/acrn_dev.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -41,6 +42,7 @@ static int acrn_hsm_inited; static int major; static struct class *acrn_class; static struct device *acrn_device; +static struct tasklet_struct acrn_io_req_tasklet; static int acrn_dev_open(struct inode *inodep, struct file *filep) @@ -416,6 +418,16 @@ long acrn_dev_ioctl(struct file *filep, break; } case IC_CLEAR_VM_IOREQ: { + /* + * we need to flush the current pending ioreq dispatch + * tasklet and finish it before clearing all ioreq of this VM. + * With tasklet_kill, there still be a very rare race which + * might lost one ioreq tasklet for other VMs. So arm one after + * the clearing. It's harmless. + */ + tasklet_schedule(&acrn_io_req_tasklet); + tasklet_kill(&acrn_io_req_tasklet); + tasklet_schedule(&acrn_io_req_tasklet); acrn_ioreq_clear_request(vm); break; } @@ -449,6 +461,28 @@ static int acrn_dev_release(struct inode *inodep, struct file *filep) return 0; } +static void io_req_tasklet(unsigned long data) +{ + struct acrn_vm *vm; + /* This is already in tasklet. Use read_lock for list_lock */ + + read_lock(&acrn_vm_list_lock); + list_for_each_entry(vm, &acrn_vm_list, list) { + if (!vm || !vm->req_buf) + break; + + get_vm(vm); + acrn_ioreq_distribute_request(vm); + put_vm(vm); + } + read_unlock(&acrn_vm_list_lock); +} + +static void acrn_intr_handler(void) +{ + tasklet_schedule(&acrn_io_req_tasklet); +} + static const struct file_operations fops = { .open = acrn_dev_open, .release = acrn_dev_release, @@ -462,6 +496,7 @@ static const struct file_operations fops = { static int __init acrn_init(void) { + unsigned long flag; struct api_version *api_version; acrn_hsm_inited = 0; if (x86_hyper_type != X86_HYPER_ACRN) @@ -518,6 +553,10 @@ static int __init acrn_init(void) return PTR_ERR(acrn_device); } + tasklet_init(&acrn_io_req_tasklet, io_req_tasklet, 0); + local_irq_save(flag); + acrn_setup_intr_irq(acrn_intr_handler); + local_irq_restore(flag); acrn_ioreq_driver_init(); pr_info("acrn: ACRN Hypervisor service module initialized\n"); acrn_hsm_inited = 1; @@ -529,6 +568,8 @@ static void __exit acrn_exit(void) if (!acrn_hsm_inited) return; + tasklet_kill(&acrn_io_req_tasklet); + acrn_remove_intr_irq(); device_destroy(acrn_class, MKDEV(major, 0)); class_unregister(acrn_class); class_destroy(acrn_class); -- 2.7.4