Message ID | 1680564178-31023-1-git-send-email-nunodasneves@linux.microsoft.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2652579vqo; Mon, 3 Apr 2023 16:42:17 -0700 (PDT) X-Google-Smtp-Source: AKy350aW+OO/2FprsSZ5+a0U127RA1XMKSJatuc0om7+i+z+rRS2QSPigpxTdi8bMYvKpa7HIgwK X-Received: by 2002:a17:907:98a4:b0:932:ac6c:7ef9 with SMTP id ju4-20020a17090798a400b00932ac6c7ef9mr315891ejc.22.1680565336822; Mon, 03 Apr 2023 16:42:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680565336; cv=none; d=google.com; s=arc-20160816; b=XptvmyKCC7DCDHIOC9uU/Kz/WNLuW5NpR7asGy6GZ4zQwc7U8rjSOKrBgGB6tDiy91 tfVl3Dwe6E9/DSQmoPdUkFviweJ7jRurUd1UqhepDHY+ePgUtZPkzCaD6MiY1OYe68an O0zy/+9swpsK4IJGotR5aU3HnIoQ6tlEnrRXqEq/Siv8uNlta1kAOoYyqlEWE8/87lgi gbPdnIRlUggiA5vfBJFONvU2dBO0nQ/MHFa2rCMgxsSw0cRkcy8AG2AV0YPkuh6E+gNu BFreDNLUNZeI5/nXhkTLDUBWc9fxrKMnuqW/UQB+EYJwDgE9h9T122Q6VpJfXA37ZNq0 7tzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=y3i3ILhMmxV1ebXDwdyEOEKLgDclYCNwTf+8O1DdSIY=; b=NPTkH4IebWGVVv6yQQqzT+0vBYxEk/HSn5DgvZeRVTJh3Yenj1aUItmx9aW+LzHOx+ 91jRGS6j5Qyskq6ReKcDpBfl9Nm7ZXJolg+zrbED5glbnaM94ANSsRiuhnzKFj33gdPP 3Gy8vQd6YEE5oSX5GmBO181FORInF4PLDc/6/HypYA2Y0/MMw4tiChFb2THL3k5VBhr+ PCtk8Q61/+pSk7ESeFCd9J8lPngCYw2d11FIyBvTQJ2jh30fG9uNvkVaG9NhbSUWSTU3 qXsACnNbOxwWskbnGEAk3CaYoJLqfpIM1evJvOPTBSoNSbbQ/IjwVLOZNRmyLEO0VsTW xoog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=JZ59pRik; 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 q5-20020a1709064c8500b0093d9b73f078si8337468eju.223.2023.04.03.16.41.53; Mon, 03 Apr 2023 16:42:16 -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=JZ59pRik; 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 S233174AbjDCXXN (ORCPT <rfc822;zwp10758@gmail.com> + 99 others); Mon, 3 Apr 2023 19:23:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232745AbjDCXXJ (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 3 Apr 2023 19:23:09 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AB6FA10C; Mon, 3 Apr 2023 16:23:08 -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 3C148210CBF2; Mon, 3 Apr 2023 16:23:08 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 3C148210CBF2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1680564188; bh=y3i3ILhMmxV1ebXDwdyEOEKLgDclYCNwTf+8O1DdSIY=; h=From:To:Cc:Subject:Date:From; b=JZ59pRikh4gCot8Snc/748VAOZv2Rto3GGHicLk4hnI+99Km6WH75zI2DsTvgj+am IAbKMcgpIERqL8K45BbrcHwxJEya++Ol1B7eW2WaNIC3KeRUodmXwhnMnfY7zmJjhf l17luQKroD6tGj4Phh6ruCOa1jaer2dQTBbWsYaI= From: Nuno Das Neves <nunodasneves@linux.microsoft.com> To: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Cc: mikelley@microsoft.com, kys@microsoft.com, wei.liu@kernel.org, haiyangz@microsoft.com, decui@microsoft.com Subject: [PATCH] Drivers: hv: Use nested hypercall for post message and signal event Date: Mon, 3 Apr 2023 16:22:58 -0700 Message-Id: <1680564178-31023-1-git-send-email-nunodasneves@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 X-Spam-Status: No, score=-17.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762200478548604444?= X-GMAIL-MSGID: =?utf-8?q?1762200478548604444?= |
Series |
Drivers: hv: Use nested hypercall for post message and signal event
|
|
Commit Message
Nuno Das Neves
April 3, 2023, 11:22 p.m. UTC
When running nested, these hypercalls must be sent to the L0 hypervisor
or vmbus will fail.
Only relevant for x86; nested functionality is not available in ARM64.
Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
---
drivers/hv/connection.c | 4 ++++
drivers/hv/hv.c | 5 +++++
2 files changed, 9 insertions(+)
Comments
Mon, 3 Apr 2023 16:22:58 -0700 Nuno Das Neves <nunodasneves@linux.microsoft.com>: > Only relevant for x86; nested functionality is not available in ARM64. > +#if defined(CONFIG_X86_64) > + else if (hv_nested) Should there be a hv_nested in the ARM64 code path? Looks like c4bdf94f97c86 provided such thing, so the Kconfig conditional could be removed. Olaf
On 4/3/2023 11:45 PM, Olaf Hering wrote: > Mon, 3 Apr 2023 16:22:58 -0700 Nuno Das Neves <nunodasneves@linux.microsoft.com>: > >> Only relevant for x86; nested functionality is not available in ARM64. > >> +#if defined(CONFIG_X86_64) >> + else if (hv_nested) > > Should there be a hv_nested in the ARM64 code path? > Looks like c4bdf94f97c86 provided such thing, so the Kconfig conditional could be removed. > > Olaf This will not compile on ARM64 without the guard, because hv_do_nested_hypercall and hv_do_fast_nested_hypercall8 are not defined. These are inline functions only defined in the x86 mshyperv.h header. The alternative to these guards would be defining dummy inline functions for the nested versions of hv_do_hypercall in the ARM64 mshyperv.h. I could take that approach if it is preferable.
From: Nuno Das Neves <nunodasneves@linux.microsoft.com> Sent: Tuesday, April 4, 2023 9:57 AM > > On 4/3/2023 11:45 PM, Olaf Hering wrote: > > Mon, 3 Apr 2023 16:22:58 -0700 Nuno Das Neves > <nunodasneves@linux.microsoft.com>: > > > >> Only relevant for x86; nested functionality is not available in ARM64. > > > >> +#if defined(CONFIG_X86_64) > >> + else if (hv_nested) > > > > Should there be a hv_nested in the ARM64 code path? > > Looks like c4bdf94f97c86 provided such thing, so the Kconfig conditional could be > removed. > > > > Olaf > > This will not compile on ARM64 without the guard, because hv_do_nested_hypercall > and hv_do_fast_nested_hypercall8 are not defined. > These are inline functions only defined in the x86 mshyperv.h header. > > The alternative to these guards would be defining dummy inline functions for the > nested versions of hv_do_hypercall in the ARM64 mshyperv.h. > I could take that approach if it is preferable. Having to do "if (hv_nested)" and "#ifdef CONFIG_X86_64" at multiple call sites is indeed rather messy. I wonder if it is feasible to fold all this logic into the x86 version of hv_do_hypercall() and friends, so that the call sites are not affected? That's what was done with hv_get/set_register(). And it would allow the ARM64 side to be unchanged. Here's an approach: 1) Create a global bitmap with one bit for each hypercall code that Hyper-V accepts. The max is something less than 512, so this bitmap is less than 64 bytes. Initialize the bitmap to all zeros. 2) During early initialization, if hv_nested is set to "true", set the bit in the bitmap corresponding to hypercalls that need the HV_HYPERCALL_NESTED flag added. 3) In hv_do_hypercall(), use the hypercall code to index into the bitmap and retrieve the bit. Use that bit to decide whether to set HV_HYPERCALL_NESTED. Note that hv_nested doesn't even need to be tested because the bitmap will be all zeros when hv_nested is "false". The one snag is extended hypercalls, for which the hypercall code is a much bigger value, and we might not want to make the bitmap that big. Maybe they have to be special-cased to be non-nested. This approach assumes that a hypercall is always either nested or non-nested from all call sites. If the bitmap approach is too obscure, testing hv_nested and doing a switch statement to handle the cases that need HV_HYPERCALL_NESTED would also work. The performance probably wouldn't be as good, but it probably doesn't matter. Again, this would be like hv_get/set_register(). With this approach, hv_do_nested_hypercall() and friends are not needed, but I don't know what other usage patterns for hv_do_nested_hypercall() might be planned. These other usage patterns might make this idea not so workable. Michael
diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c index 9dc27e5d367a..04bf7f168976 100644 --- a/drivers/hv/connection.c +++ b/drivers/hv/connection.c @@ -539,6 +539,10 @@ void vmbus_set_event(struct vmbus_channel *channel) if (hv_isolation_type_snp()) hv_ghcb_hypercall(HVCALL_SIGNAL_EVENT, &channel->sig_event, NULL, sizeof(channel->sig_event)); +#if defined(CONFIG_X86_64) + else if (hv_nested) + hv_do_fast_nested_hypercall8(HVCALL_SIGNAL_EVENT, channel->sig_event); +#endif else hv_do_fast_hypercall8(HVCALL_SIGNAL_EVENT, channel->sig_event); } diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index 8b0dd8e5244d..c7f7652932ca 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -102,6 +102,11 @@ int hv_post_message(union hv_connection_id connection_id, status = hv_ghcb_hypercall(HVCALL_POST_MESSAGE, (void *)aligned_msg, NULL, sizeof(*aligned_msg)); +#if defined(CONFIG_X86_64) + else if (hv_nested) + status = hv_do_nested_hypercall(HVCALL_POST_MESSAGE, + aligned_msg, NULL); +#endif else status = hv_do_hypercall(HVCALL_POST_MESSAGE, aligned_msg, NULL);