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: 143641 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5844285vqi; Fri, 22 Sep 2023 13:20:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGuUCX5uMlwCc4q6ypHQ5MO3sw9H43avnIeAYotkEuRNLlRIzHDOKgEEnC67XfLHyuxmKik X-Received: by 2002:a05:6a00:1817:b0:68f:b8ca:b11 with SMTP id y23-20020a056a00181700b0068fb8ca0b11mr529086pfa.11.1695414000015; Fri, 22 Sep 2023 13:20:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695414000; cv=none; d=google.com; s=arc-20160816; b=un0MTx68AIOOY8/lLlvh1Vicn4zhSV27gmnb4VmF2cFoQcjZG9zA1zcc4XfMH6tKlp jGqQFhSiTPwV6L4uC3M9LFuBtyGk9/ygVCC6JSgGg3QopFRm7d5zGFjJoANBYJAAfW8C GQt8fNBMcATJtAKBR+fTFm3js40TBha0tD3cHk2upKchMbp8JKAt2egfAZIU0qAWn44E NbZENiMdLOFyP5GH7rWr8aCjEmdVoXoxRj4aEHUQOVrGcHN4A+6OU4FOi0zHqZvRirD7 m9DpG5Yyhzl/ty1zTLW9M/53DxgzrWIB4I1lZ503NDTdENDaxJQbnhnQ2TKf4Gwk4GbK x5aA== 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=pW3Yrix8vKqYOaoZlcQrpVvf9L1HIpWKGzxBC51MI24=; fh=rrENblR9DW+P8f8MSnFC4QkpxyTeAbSNxgPLVTXlWGs=; b=pNEfdZWuqVD1HTGrJA6Z6961t5VzfdEcXmMaJPMw7DXZvMp5uFbwDgSDd9vyWBbT2m l6V2tEiXdTZQzGBYxDay7B5Ostdytb1l8hwz66zA9OnLGXUYBVbuf7OgCktqFDw1eIr2 G80bow7ayvZaXWWRHXMvNZHi2sCSdhKCvOuxQZrGGjCfK96S0ih53wZeO7Y0A3byjBS8 EywnzIZjPY/lw0M90kZE4OmZ6izO/NWgHeVLbgpU8NjFwQfa+Rbr9TJGsjOSpzH8VN8s AHFTUTLtidpT8wch2FIQgNOZT7kwAPoC4umHBFqqMVz91C1KQTsWXu0LLF5mivUJWjvp +94A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=pr5uPVrN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id g22-20020a056a001a1600b00690c94b4cd1si4688350pfv.291.2023.09.22.13.19.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 13:19:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=pr5uPVrN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id C6AF384CE668; Fri, 22 Sep 2023 11:39:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233828AbjIVSjS (ORCPT + 28 others); Fri, 22 Sep 2023 14:39:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233431AbjIVSit (ORCPT ); Fri, 22 Sep 2023 14:38:49 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8E174E8; Fri, 22 Sep 2023 11:38:43 -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 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-Spam-Status: No, score=-17.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Fri, 22 Sep 2023 11:39:20 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777770430305354511 X-GMAIL-MSGID: 1777770430305354511 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);