From patchwork Fri Sep 22 18:38:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Das Neves X-Patchwork-Id: 13396340 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1057ECD4852 for ; Fri, 22 Sep 2023 18:39:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=InKEEH4F0AeEz/EU4SHtJXf6Kt33Gh65BI0dTZUF+V4=; b=oPEXU5PneG9kVI u/FrF0vI8S4sOHk/P8nXBviH2Q2Fyeno0a4JFbolnf4wALwfbW12BDtgEk7g0v0WE5pJ+UnT25m8a rxYS/I4wxGDfXqmME5GkxcOLwmsSIzq4cPzmLrGLlopE+Qlc1Vr1p1GfreqKXkyCHx2XnN7yvLmP8 s4QSbqV9HpB9sarwT4cqzIwE+bEoOA7CL8G97tFedawzzn3RGmQSOXSVn8U98/R3suw9jUg52Siy7 EHfdWIDKO43bkZ0AeixVwuSSXJqbuvqqz3LLKwRuoMpoqYEsyPGkovNMGzW52GflP9w05fMq7kgF6 g/MvgIVrSIXc979gBCHw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qjl3N-009dh9-2H; Fri, 22 Sep 2023 18:39:01 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qjl37-009dSo-30 for linux-arm-kernel@lists.infradead.org; Fri, 22 Sep 2023 18:38:49 +0000 Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id B66B0212C5DC; Fri, 22 Sep 2023 11:38:41 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com B66B0212C5DC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1695407921; bh=pW3Yrix8vKqYOaoZlcQrpVvf9L1HIpWKGzxBC51MI24=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pr5uPVrNpqX5lEgV8BxPtT1rJA14gCmrRE3y67wUi0LKFNb9h85ZKA1z993lQ9tqx pNQCi1J0Vz5jHZnWTisXm7LTK8g4cgb6KS3vvIKE53vKUHmtIciH8kyGrP+9R/S5pC onzc/P3nRGXzhj5mrMrYI3ImPngZyOMkwnbeU5XE= From: Nuno Das Neves To: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org Cc: patches@lists.linux.dev, mikelley@microsoft.com, kys@microsoft.com, wei.liu@kernel.org, gregkh@linuxfoundation.org, haiyangz@microsoft.com, decui@microsoft.com, apais@linux.microsoft.com, Tianyu.Lan@microsoft.com, ssengar@linux.microsoft.com, mukeshrathor@microsoft.com, stanislav.kinsburskiy@gmail.com, jinankjain@linux.microsoft.com, vkuznets@redhat.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, will@kernel.org, catalin.marinas@arm.com Subject: [PATCH v3 08/15] Drivers: hv: Introduce per-cpu event ring tail Date: Fri, 22 Sep 2023 11:38:28 -0700 Message-Id: <1695407915-12216-9-git-send-email-nunodasneves@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1695407915-12216-1-git-send-email-nunodasneves@linux.microsoft.com> References: <1695407915-12216-1-git-send-email-nunodasneves@linux.microsoft.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230922_113846_021911_9F00000B X-CRM114-Status: GOOD ( 17.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add a pointer hv_synic_eventring_tail to track the tail pointer for the SynIC event ring buffer for each SINT. This will be used by the mshv driver, but must be tracked independently since the driver module could be removed and re-inserted. Signed-off-by: Nuno Das Neves Reviewed-by: Wei Liu --- drivers/hv/hv_common.c | 28 ++++++++++++++++++++++++++-- include/asm-generic/mshyperv.h | 2 ++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c index 8c6ab60d5387..d346ce6adf00 100644 --- a/drivers/hv/hv_common.c +++ b/drivers/hv/hv_common.c @@ -62,6 +62,16 @@ static void hv_kmsg_dump_unregister(void); static struct ctl_table_header *hv_ctl_table_hdr; +/* + * Per-cpu array holding the tail pointer for the SynIC event ring buffer + * for each SINT. + * + * We cannot maintain this in mshv driver because the tail pointer should + * persist even if the mshv driver is unloaded. + */ +u8 __percpu **hv_synic_eventring_tail; +EXPORT_SYMBOL_GPL(hv_synic_eventring_tail); + /* * Hyper-V specific initialization and shutdown code that is * common across all architectures. Called from architecture @@ -84,6 +94,9 @@ void __init hv_common_free(void) free_percpu(hyperv_pcpu_input_arg); hyperv_pcpu_input_arg = NULL; + + free_percpu(hv_synic_eventring_tail); + hv_synic_eventring_tail = NULL; } /* @@ -333,6 +346,8 @@ int __init hv_common_init(void) if (hv_root_partition) { hyperv_pcpu_output_arg = alloc_percpu(void *); BUG_ON(!hyperv_pcpu_output_arg); + hv_synic_eventring_tail = alloc_percpu(u8 *); + BUG_ON(hv_synic_eventring_tail == NULL); } hv_vp_index = kmalloc_array(num_possible_cpus(), sizeof(*hv_vp_index), @@ -357,6 +372,7 @@ int __init hv_common_init(void) int hv_common_cpu_init(unsigned int cpu) { void **inputarg, **outputarg; + u8 **synic_eventring_tail; u64 msr_vp_index; gfp_t flags; int pgcount = hv_root_partition ? 2 : 1; @@ -369,8 +385,8 @@ int hv_common_cpu_init(unsigned int cpu) inputarg = (void **)this_cpu_ptr(hyperv_pcpu_input_arg); /* - * hyperv_pcpu_input_arg and hyperv_pcpu_output_arg memory is already - * allocated if this CPU was previously online and then taken offline + * The per-cpu memory is already allocated if this CPU was previously + * online and then taken offline */ if (!*inputarg) { mem = kmalloc(pgcount * HV_HYP_PAGE_SIZE, flags); @@ -380,6 +396,14 @@ int hv_common_cpu_init(unsigned int cpu) if (hv_root_partition) { outputarg = (void **)this_cpu_ptr(hyperv_pcpu_output_arg); *outputarg = (char *)mem + HV_HYP_PAGE_SIZE; + synic_eventring_tail = (u8 **)this_cpu_ptr(hv_synic_eventring_tail); + *synic_eventring_tail = kcalloc(HV_SYNIC_SINT_COUNT, sizeof(u8), + flags); + + if (unlikely(!*synic_eventring_tail)) { + kfree(mem); + return -ENOMEM; + } } if (!ms_hyperv.paravisor_present && diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h index 5be3e3402e37..5a12e5754e97 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -77,6 +77,8 @@ extern bool hv_nested; extern void * __percpu *hyperv_pcpu_input_arg; extern void * __percpu *hyperv_pcpu_output_arg; +extern u8 __percpu **hv_synic_eventring_tail; + extern u64 hv_do_hypercall(u64 control, void *inputaddr, void *outputaddr); extern u64 hv_do_fast_hypercall8(u16 control, u64 input8); bool hv_isolation_type_snp(void);