From patchwork Thu Jul 27 19:54:44 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: 127139 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b8e4:0:b0:3e9:de7a:15be with SMTP id v4csp1373239vqw; Thu, 27 Jul 2023 13:22:55 -0700 (PDT) X-Google-Smtp-Source: APBJJlGw6h9KA5QMjQ5ih4CVvGK/WeZtGPu8ytFsjRIf26EElTSTZtdBgSMU9BTCkHGRsR2Zcwwd X-Received: by 2002:a05:6a20:42a4:b0:136:faec:a7dc with SMTP id o36-20020a056a2042a400b00136faeca7dcmr188650pzj.11.1690489375306; Thu, 27 Jul 2023 13:22:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690489375; cv=none; d=google.com; s=arc-20160816; b=DZdLQ9mfe1W26QcaVDWZHArkEGd1y+24Rkz0kK6Xx7q/lVR+81O5um7T60KGVs4GLT +QbB1K3nxEktwNZGVsAE0rQt/GU9jloVMT1bDQXhDZvKXxd4+BIN9PaXoT1X5T0dVu4r +0Kik/wqUbaJX0EGJ9kkQMh2KkcvCfnvDaTVqIhw/HnT+PnscFavwptYuJ6/yaDBYq65 qmuzU/KDTZthp9yA9dR4zXOkIWle0buitR5HThWi9u7y8k7CvXDm2goyQ3U/WCq4LTRi E6YD+icbCr2aRWtYRCka2JFCaPTqCwWndik7m13GY1RQJK2oaw4GshyOnersGScN7W/V yhdA== 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=NiawUFGJjTGeRxVPGVpR8qcuG+E+da5tkmNfJ3Hns0s=; fh=y8tS7hHyMnVm4J/EG8JBk7xmqgMCnIiFB1dTM3zggRY=; b=Tbvb9G8dF9HtRIKICepdblKfnDQ/UFVwP4QXMW2s74aXPedaVZH7SFnuXzyJVPtG5K BvRIr43d0TTWafbsvzpQA6PGnL8utdIr+4JUYlIEKTHUhYDsdrCeWbxb9TFBdE0sqsPx ku1ITb26X40iGoM/cyVZYru3CaktSqc6BAao1npNxBrWKVbiNxzIyM+2t1Gzb63c+xMr OBytKqe37zl/WX6VoRbaocYoCdrNBssQ/3kcU9CERLooVKqJsIAR1lHq23pl6qyg7ew/ rbqtGVaYWGiTHqCRW1j5U5ymF2RcKMR8aje8cVGsspLk0xxvf1qg/96u6bDKdB019C7l vyew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=BSVqcTGs; 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 i14-20020a636d0e000000b00563fc0d174csi1678046pgc.791.2023.07.27.13.22.40; Thu, 27 Jul 2023 13:22:55 -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=BSVqcTGs; 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 S232604AbjG0Tzg (ORCPT + 99 others); Thu, 27 Jul 2023 15:55:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232174AbjG0TzC (ORCPT ); Thu, 27 Jul 2023 15:55:02 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4ED6330DA; 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 587962383EEE; Thu, 27 Jul 2023 12:54:57 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 587962383EEE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1690487697; bh=NiawUFGJjTGeRxVPGVpR8qcuG+E+da5tkmNfJ3Hns0s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BSVqcTGs0sca4q1vp+eV4WQSiNAs5TTc52KIq6JJVagBdaj1RPI+DkDfSC/Fm/F8O wpb46/1BPJOv/z8+K67zWwmF47R9fGkNNI4W0IDqtNkii80KxCPzpaJEsEafEocxV6 BGY+ThBmWfoHnQ9n3Fj1bZFPvCYWrTJAN8gZhcQk= 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 09/15] Drivers: hv: Introduce hv_output_arg_exists in hv_common Date: Thu, 27 Jul 2023 12:54:44 -0700 Message-Id: <1690487690-2428-10-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: 1772606587640332289 X-GMAIL-MSGID: 1772606587640332289 This is a more flexible approach for determining whether to allocate the output page. This will be used in both mshv_vtl and root partition. Signed-off-by: Nuno Das Neves --- drivers/hv/hv_common.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c index 99d9b262b8a7..16f069beda78 100644 --- a/drivers/hv/hv_common.c +++ b/drivers/hv/hv_common.c @@ -57,6 +57,18 @@ EXPORT_SYMBOL_GPL(hyperv_pcpu_input_arg); void * __percpu *hyperv_pcpu_output_arg; EXPORT_SYMBOL_GPL(hyperv_pcpu_output_arg); +/* + * Determine whether output arg is in use, for allocation/deallocation + */ +static bool hv_output_arg_exists(void) +{ + bool ret = hv_root_partition ? true : false; +#ifdef CONFIG_MSHV_VTL + ret = true; +#endif + return ret; +} + static void hv_kmsg_dump_unregister(void); static struct ctl_table_header *hv_ctl_table_hdr; @@ -338,10 +350,12 @@ int __init hv_common_init(void) hyperv_pcpu_input_arg = alloc_percpu(void *); BUG_ON(!hyperv_pcpu_input_arg); - /* Allocate the per-CPU state for output arg for root */ - if (hv_root_partition) { + if (hv_output_arg_exists()) { hyperv_pcpu_output_arg = alloc_percpu(void *); BUG_ON(!hyperv_pcpu_output_arg); + } + + if (hv_root_partition) { hv_synic_eventring_tail = alloc_percpu(u8 *); BUG_ON(hv_synic_eventring_tail == NULL); } @@ -371,7 +385,7 @@ int hv_common_cpu_init(unsigned int cpu) u8 **synic_eventring_tail; u64 msr_vp_index; gfp_t flags; - int pgcount = hv_root_partition ? 2 : 1; + int pgcount = hv_output_arg_exists() ? 2 : 1; /* hv_cpu_init() can be called with IRQs disabled from hv_resume() */ flags = irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL; @@ -381,9 +395,12 @@ int hv_common_cpu_init(unsigned int cpu) if (!(*inputarg)) return -ENOMEM; - if (hv_root_partition) { + if (hv_output_arg_exists()) { outputarg = (void **)this_cpu_ptr(hyperv_pcpu_output_arg); *outputarg = (char *)(*inputarg) + HV_HYP_PAGE_SIZE; + } + + if (hv_root_partition) { synic_eventring_tail = (u8 **)this_cpu_ptr(hv_synic_eventring_tail); *synic_eventring_tail = kcalloc(HV_SYNIC_SINT_COUNT, sizeof(u8), flags); @@ -417,9 +434,12 @@ int hv_common_cpu_die(unsigned int cpu) mem = *inputarg; *inputarg = NULL; - if (hv_root_partition) { + if (hv_output_arg_exists()) { outputarg = (void **)this_cpu_ptr(hyperv_pcpu_output_arg); *outputarg = NULL; + } + + if (hv_root_partition) { synic_eventring_tail = (u8 **)this_cpu_ptr(hv_synic_eventring_tail); kfree(*synic_eventring_tail); *synic_eventring_tail = NULL;