From patchwork Thu Jul 27 19:54:43 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: 127148 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:d09a:b0:134:c3fc:3153 with SMTP id jc26csp181281rwb; Thu, 27 Jul 2023 13:31:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlGgcCjVC+CFcJ6aW9EcUExCLKwbx7L0wey+FJChZIET/DltCObR3DpQmGq2rMD+bO6MfriV X-Received: by 2002:a19:8c10:0:b0:4fe:ecd:494f with SMTP id o16-20020a198c10000000b004fe0ecd494fmr193716lfd.33.1690489860581; Thu, 27 Jul 2023 13:31:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690489860; cv=none; d=google.com; s=arc-20160816; b=aYLE/YZdv9GrRfxDgM3Te3umDbANfQB1751dfCmTvrhS1tLV1m1jKdzPYo6FfvXc5B 89D1Psk4dWqcE+PpOvbxgpUpGpHekzBaFulLEQPAkXg1+BYGqywFWPAhmvKktAqrdH6E WgcXS6iGwqoKY9dw9aIWPCdIhSS24e3TTp4kRx6W0gue509ytU7SMmj7a/iuTEIJ6tl5 Tl5cptVpCHIhxRInbHHS7VtsLmWO7pT01HPMo2feBUEU8WXUxwQzyHqvr8BYUffZ6+Z4 Ur0XAlnBrY4lBNPuxErYvRymdru2Powc8H6FwRItJPS//Am79beOf4QUXMt4TYXJjgDa DRMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature:dkim-filter; bh=HPETpWBPXcktJiZxDGWrM7Bd3Q7E+nExHqjfNeCbApo=; fh=y8tS7hHyMnVm4J/EG8JBk7xmqgMCnIiFB1dTM3zggRY=; b=JK5YRfFj2SHMZNkB/urzQWg9RTaBCisppHrTQ+aJSEwds5WWQRwD/Ed4ukiUfaD7IG 3Z4DCxkh6P/wnc7ckQkSAhL5Lk4DWKgu1kYZz8+AWvHjK6MfEfavlVvlx2hDSQe59Tsb 6g03gMpnYW/nMfOphtqnG0lt2+6OxdFg1R0MgbsXSyFLPzVVfJU39LpxeULWMwVnIogP 4Y5qowmMoBShHRz5iDOOZEKrHhOldz6rlXbaZFond91IfojuB2AVoX02AY8+rAK98OSR QEDuKDwtcvXGk94Qwtt9inHpgh5J2TcjQBJ3LjsUeby1vGP89oWH8hChBl4pcMlBnbAj E/nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=fTWMskoQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j26-20020aa7ca5a000000b005221da47f59si1344261edt.172.2023.07.27.13.30.35; Thu, 27 Jul 2023 13:31:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=fTWMskoQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232532AbjG0Tzb (ORCPT + 99 others); Thu, 27 Jul 2023 15:55:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229995AbjG0TzA (ORCPT ); Thu, 27 Jul 2023 15:55:00 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4C6A030D4; Thu, 27 Jul 2023 12:54:59 -0700 (PDT) Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id 3D8EF2383EF5; Thu, 27 Jul 2023 12:54:57 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 3D8EF2383EF5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1690487697; bh=HPETpWBPXcktJiZxDGWrM7Bd3Q7E+nExHqjfNeCbApo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fTWMskoQmaiRKYdKSqF8KN7KIhXNYhlpbivfWu4+Oy1P7HYd9Z+BoDF38kI6TH7b6 KqqJ1TpASd3aeiNA2Mak+9sdTcFrsiLjjsPwTmYiP1WS/42I6mYZDf5lr7zmQYZZV9 S7qwQ8Z/HVglVTZKCWImoAOU4lsYLcQXP3OnRoiE= 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: mikelley@microsoft.com, kys@microsoft.com, wei.liu@kernel.org, haiyangz@microsoft.com, decui@microsoft.com, ssengar@linux.microsoft.com, mukeshrathor@microsoft.com, stanislav.kinsburskiy@gmail.com, jinankjain@linux.microsoft.com, apais@linux.microsoft.com, Tianyu.Lan@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 08/15] Drivers: hv: Introduce per-cpu event ring tail Date: Thu, 27 Jul 2023 12:54:43 -0700 Message-Id: <1690487690-2428-9-git-send-email-nunodasneves@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1690487690-2428-1-git-send-email-nunodasneves@linux.microsoft.com> References: <1690487690-2428-1-git-send-email-nunodasneves@linux.microsoft.com> X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772607095876769092 X-GMAIL-MSGID: 1772607095876769092 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 --- drivers/hv/hv_common.c | 25 +++++++++++++++++++++++++ include/asm-generic/mshyperv.h | 2 ++ 2 files changed, 27 insertions(+) diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c index 9f9c3dc89bb2..99d9b262b8a7 100644 --- a/drivers/hv/hv_common.c +++ b/drivers/hv/hv_common.c @@ -61,6 +61,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 @@ -332,6 +342,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), @@ -356,6 +368,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; @@ -371,6 +384,14 @@ int hv_common_cpu_init(unsigned int cpu) if (hv_root_partition) { outputarg = (void **)this_cpu_ptr(hyperv_pcpu_output_arg); *outputarg = (char *)(*inputarg) + 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(*inputarg); + return -ENOMEM; + } } msr_vp_index = hv_get_register(HV_MSR_VP_INDEX); @@ -387,6 +408,7 @@ int hv_common_cpu_die(unsigned int cpu) { unsigned long flags; void **inputarg, **outputarg; + u8 **synic_eventring_tail; void *mem; local_irq_save(flags); @@ -398,6 +420,9 @@ int hv_common_cpu_die(unsigned int cpu) if (hv_root_partition) { outputarg = (void **)this_cpu_ptr(hyperv_pcpu_output_arg); *outputarg = NULL; + synic_eventring_tail = (u8 **)this_cpu_ptr(hv_synic_eventring_tail); + kfree(*synic_eventring_tail); + *synic_eventring_tail = NULL; } local_irq_restore(flags); diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h index 0c94d20b4d44..9118d678b27a 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -73,6 +73,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); extern bool hv_isolation_type_snp(void);