From patchwork Tue Feb 4 15:36:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11364871 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1B48C92A for ; Tue, 4 Feb 2020 15:38:10 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EC7AD20674 for ; Tue, 4 Feb 2020 15:38:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="M/0GpiCD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EC7AD20674 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iz0GK-0001Hh-8h; Tue, 04 Feb 2020 15:37:16 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iz0GJ-0001HS-9t for xen-devel@lists.xenproject.org; Tue, 04 Feb 2020 15:37:15 +0000 X-Inumbo-ID: 353637f2-4764-11ea-8396-bc764e2007e4 Received: from mail-wm1-x342.google.com (unknown [2a00:1450:4864:20::342]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 353637f2-4764-11ea-8396-bc764e2007e4; Tue, 04 Feb 2020 15:37:10 +0000 (UTC) Received: by mail-wm1-x342.google.com with SMTP id p9so3805562wmc.2 for ; Tue, 04 Feb 2020 07:37:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aG90iG13/0eYUDF/3LrYyCyn+fxbAfySSbQ2wlI3Qww=; b=M/0GpiCDJiLyUaV+iYwQOHlrlkeNvWy3oUJKwGRM3/z7rToX/WpYji61av7hAebDFw i+rQIaCk6ly8GXpov0PbJUeclfq9gyCQeEwMJJhsbh/rNsIQx/l9FFvEQzZFMb6+iCrS jtjqvgx6TJsvE8Sycu62SjuhzS+JrF+pGrPhN0FcJsoEgIYcP+P7yVS3u1VnuUbGgvEp PWR3DiGc5BA+1CfLVsUX51i0whuj37FuOeQqzVr7Z47Lho27z7VsB4u1U6+LuR7nT2rr AxSYj0yH1c/5Lo6T/I8mUeyDZsa0MpCdEFv90DanaswN9jZ8dm4i/9C/MNDeNAFZWTDo LWHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=aG90iG13/0eYUDF/3LrYyCyn+fxbAfySSbQ2wlI3Qww=; b=rjhUbY9hDxDFaBOhL6dEJnZ803hBjr/Hi+Jab+swqroVwYezeaU06kKJjYUqs+3S8L +NDwO1Z2vjLmHZ34lCRNSooLUDCnY2SYEKchZleclS6mRy1add7Yt2/aRVk8RIoDxcL1 8vhTcSJxym0mDjSzrTRWja8DM6IyBrwJXHxaGpqJpiv1ByqBJMshlVrystTCKtSMHuO0 p3aLj5xOj0jgcw/bBnpp8Y1l6sH4QKx/ETG0cJH9qNQGCMtUGFCLhqpULgGVCRfwfV+h gw6aTZ+2Mj6T20AlI6OUSattT/QBAuuc0nW80GjoCR2vGnDOFvplmxCbyXADDBDWEBac c2LQ== X-Gm-Message-State: APjAAAXUN0dafB6hFU8i4kmybIzAdLv/F8Mb94GSYOvz+s7ZumKxf081 ulWZBLi1u5KhY394G46vB6H6IG4woxw= X-Google-Smtp-Source: APXvYqxdp+yJBoBr7Qph0C3n4m9hTqut/78cGrZ/3UpN169IwftMv0hTjrOTj1I5CMCWwKhrbUCInA== X-Received: by 2002:a7b:c1da:: with SMTP id a26mr6831535wmj.155.1580830629750; Tue, 04 Feb 2020 07:37:09 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id p26sm4067143wmc.24.2020.02.04.07.37.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 07:37:09 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Tue, 4 Feb 2020 15:36:55 +0000 Message-Id: <20200204153704.15934-2-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200204153704.15934-1-liuwe@microsoft.com> References: <20200204153704.15934-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v7 01/10] x86/hypervisor: make hypervisor_ap_setup return an error code X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Andrew Cooper , Paul Durrant , Michael Kelley , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" We want to be able to handle AP setup error in the upper layer. For Xen, remove all panic() and BUG_ON() in init_evtchn and map_vcpuinfo. Only panic/BUG_ON when Xen can't fail gracefully. Signed-off-by: Wei Liu Reviewed-by: Jan Beulich --- v7: 1. Change init_evtchn v6: 1. Change map_vcpuinfo as well 2. Make code shorter --- xen/arch/x86/guest/hypervisor.c | 6 ++- xen/arch/x86/guest/xen/xen.c | 58 ++++++++++++++++---------- xen/include/asm-x86/guest/hypervisor.h | 6 +-- 3 files changed, 42 insertions(+), 28 deletions(-) diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c index 4f27b98740..e72c92ffdf 100644 --- a/xen/arch/x86/guest/hypervisor.c +++ b/xen/arch/x86/guest/hypervisor.c @@ -52,10 +52,12 @@ void __init hypervisor_setup(void) ops->setup(); } -void hypervisor_ap_setup(void) +int hypervisor_ap_setup(void) { if ( ops && ops->ap_setup ) - ops->ap_setup(); + return ops->ap_setup(); + + return 0; } void hypervisor_resume(void) diff --git a/xen/arch/x86/guest/xen/xen.c b/xen/arch/x86/guest/xen/xen.c index 6dbc5f953f..1cf09886da 100644 --- a/xen/arch/x86/guest/xen/xen.c +++ b/xen/arch/x86/guest/xen/xen.c @@ -113,16 +113,16 @@ static int map_vcpuinfo(void) info.mfn = virt_to_mfn(&vcpu_info[vcpu]); info.offset = (unsigned long)&vcpu_info[vcpu] & ~PAGE_MASK; rc = xen_hypercall_vcpu_op(VCPUOP_register_vcpu_info, vcpu, &info); - if ( rc ) - { - BUG_ON(vcpu >= XEN_LEGACY_MAX_VCPUS); - this_cpu(vcpu_info) = &XEN_shared_info->vcpu_info[vcpu]; - } - else + if ( !rc ) { this_cpu(vcpu_info) = &vcpu_info[vcpu]; set_bit(vcpu, vcpu_info_mapped); } + else if ( vcpu < XEN_LEGACY_MAX_VCPUS ) + { + rc = 0; + this_cpu(vcpu_info) = &XEN_shared_info->vcpu_info[vcpu]; + } return rc; } @@ -202,10 +202,15 @@ static void xen_evtchn_upcall(struct cpu_user_regs *regs) ack_APIC_irq(); } -static void init_evtchn(void) +static int init_evtchn(void) { static uint8_t evtchn_upcall_vector; int rc; + struct xen_hvm_param a = { + .domid = DOMID_SELF, + .index = HVM_PARAM_CALLBACK_IRQ, + .value = 1, + }; if ( !evtchn_upcall_vector ) alloc_direct_apic_vector(&evtchn_upcall_vector, xen_evtchn_upcall); @@ -215,18 +220,19 @@ static void init_evtchn(void) rc = xen_hypercall_set_evtchn_upcall_vector(this_cpu(vcpu_id), evtchn_upcall_vector); if ( rc ) - panic("Unable to set evtchn upcall vector: %d\n", rc); + { + printk("Unable to set evtchn upcall vector: %d\n", rc); + goto out; + } /* Trick toolstack to think we are enlightened */ - { - struct xen_hvm_param a = { - .domid = DOMID_SELF, - .index = HVM_PARAM_CALLBACK_IRQ, - .value = 1, - }; + rc = xen_hypercall_hvm_op(HVMOP_set_param, &a); - BUG_ON(xen_hypercall_hvm_op(HVMOP_set_param, &a)); - } + if ( rc ) + printk("Unable to set HVM_PARAM_CALLBACK_IRQ\n"); + + out: + return rc; } static void __init setup(void) @@ -254,14 +260,20 @@ static void __init setup(void) XEN_LEGACY_MAX_VCPUS); } - init_evtchn(); + BUG_ON(init_evtchn()); } -static void ap_setup(void) +static int ap_setup(void) { + int rc; + set_vcpu_id(); - map_vcpuinfo(); - init_evtchn(); + + rc = map_vcpuinfo(); + if ( rc ) + return rc; + + return init_evtchn(); } int xg_alloc_unused_page(mfn_t *mfn) @@ -283,8 +295,8 @@ int xg_free_unused_page(mfn_t mfn) static void ap_resume(void *unused) { - map_vcpuinfo(); - init_evtchn(); + BUG_ON(map_vcpuinfo()); + BUG_ON(init_evtchn()); } static void resume(void) @@ -303,7 +315,7 @@ static void resume(void) panic("unable to remap vCPU info and vCPUs > legacy limit\n"); /* Setup event channel upcall vector. */ - init_evtchn(); + BUG_ON(init_evtchn()); smp_call_function(ap_resume, NULL, 1); if ( pv_console ) diff --git a/xen/include/asm-x86/guest/hypervisor.h b/xen/include/asm-x86/guest/hypervisor.h index 392f4b90ae..b503854c5b 100644 --- a/xen/include/asm-x86/guest/hypervisor.h +++ b/xen/include/asm-x86/guest/hypervisor.h @@ -25,7 +25,7 @@ struct hypervisor_ops { /* Main setup routine */ void (*setup)(void); /* AP setup */ - void (*ap_setup)(void); + int (*ap_setup)(void); /* Resume from suspension */ void (*resume)(void); }; @@ -34,7 +34,7 @@ struct hypervisor_ops { const char *hypervisor_probe(void); void hypervisor_setup(void); -void hypervisor_ap_setup(void); +int hypervisor_ap_setup(void); void hypervisor_resume(void); #else @@ -44,7 +44,7 @@ void hypervisor_resume(void); static inline const char *hypervisor_probe(void) { return NULL; } static inline void hypervisor_setup(void) { ASSERT_UNREACHABLE(); } -static inline void hypervisor_ap_setup(void) { ASSERT_UNREACHABLE(); } +static inline int hypervisor_ap_setup(void) { ASSERT_UNREACHABLE(); return 0; } static inline void hypervisor_resume(void) { ASSERT_UNREACHABLE(); } #endif /* CONFIG_GUEST */ From patchwork Tue Feb 4 15:36:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11364875 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 200E6138D for ; Tue, 4 Feb 2020 15:38:12 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EFE8620674 for ; Tue, 4 Feb 2020 15:38:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UPTvmR3v" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EFE8620674 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iz0GP-0001KO-S7; Tue, 04 Feb 2020 15:37:21 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iz0GO-0001Jt-9r for xen-devel@lists.xenproject.org; Tue, 04 Feb 2020 15:37:20 +0000 X-Inumbo-ID: 35ccc6e0-4764-11ea-a933-bc764e2007e4 Received: from mail-wm1-x343.google.com (unknown [2a00:1450:4864:20::343]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 35ccc6e0-4764-11ea-a933-bc764e2007e4; Tue, 04 Feb 2020 15:37:11 +0000 (UTC) Received: by mail-wm1-x343.google.com with SMTP id p9so3805615wmc.2 for ; Tue, 04 Feb 2020 07:37:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fEg9XwS3HG4yiw/+hl5IAq+iztDUQZOPprrs17H6Elw=; b=UPTvmR3vxuIFBpQs2c6MWJIAT0+TAxB1oAyULf/8+udbXKufr2C23LV7+f/MlHIYGa PBPjQTR2vtK+sV4UkP8A/fpQf7VM79QNI410G3ILCuY7mrtLey0K53BUrRwaKYTTX/Xo p0qNBRSIc6iJOEu2BWXachY3fDKM2ZZpFE5ovH2sirw5buE6grqLDmxnQJOQzojQauJN JCjan7z5bS6TryW58CqoP0m7CdQgaehsI1psYQ7v81VrI48LwQ8/HyK1G1FNp8t2T+YW JIpXNOa1njuobg9t4PM2I5nQyV3KUzWYEPTR8eNLnMmr1oufktqN2cztVY/+Im+mUjDm ybcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=fEg9XwS3HG4yiw/+hl5IAq+iztDUQZOPprrs17H6Elw=; b=VjDrh7YCaUHI0s6lGVkBE87AqE9js7B8yI6qA50WcVqX+gL7cZ+wY8S6QW0NQ8W6QF ALixm5/K1yRMotvSBQzPNLRQJGz4jS/tura66fYLfdv/gIU8ev9v7kM7uB9WqZxCKSNQ scF/6FqOQ8thx2U38oIcPdTLXPXiv9o8FYOJVRciBXKTMKMEmJRDZcwlZqlJVsMtQTuu X1N/sx7Eo45RLWCevUqV6qF0o45trjXPqSa2O8GGcnVLQzfS8y8x8uZzuap8vtHGBsNV EfV4zBW6Gr0o+fVd1+BqDKX7HqMtXO1J94xsU4wPQK8OjNLRyljC6nDHFX2eJfg7am6X NGyw== X-Gm-Message-State: APjAAAUVKZfBJHCPAyjxaVLqyKezwBsPbLJf81gDZXxnhnSG8GI5U2HC J04AsROknYNbr5rI4TK+MNABSsA4Ksc= X-Google-Smtp-Source: APXvYqw/h2j5v7RW3J0sxA6E1zesuRlFk1KvgnGKjX6iEQNzdQ+jTz96tWnZUpV8486CGqRgrscF1A== X-Received: by 2002:a7b:c8d7:: with SMTP id f23mr6243018wml.173.1580830630796; Tue, 04 Feb 2020 07:37:10 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id p26sm4067143wmc.24.2020.02.04.07.37.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 07:37:10 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Tue, 4 Feb 2020 15:36:56 +0000 Message-Id: <20200204153704.15934-3-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200204153704.15934-1-liuwe@microsoft.com> References: <20200204153704.15934-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v7 02/10] x86/smp: don't online cpu if hypervisor_ap_setup fails X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Andrew Cooper , Paul Durrant , Michael Kelley , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Push hypervisor_ap_setup down to smp_callin. Take the chance to replace xen_guest with cpu_has_hypervisor. Signed-off-by: Wei Liu Reviewed-by: Roger Pau Monné Reviewed-by: Jan Beulich --- xen/arch/x86/smpboot.c | 10 +++++++--- xen/include/asm-x86/guest/hypervisor.h | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c index c9d1ab4423..93b86a09e9 100644 --- a/xen/arch/x86/smpboot.c +++ b/xen/arch/x86/smpboot.c @@ -199,6 +199,13 @@ static void smp_callin(void) goto halt; } + if ( cpu_has_hypervisor && (rc = hypervisor_ap_setup()) != 0 ) + { + printk("CPU%d: Failed to initialise hypervisor functions. Not coming online.\n", cpu); + cpu_error = rc; + goto halt; + } + if ( (rc = hvm_cpu_up()) != 0 ) { printk("CPU%d: Failed to initialise HVM. Not coming online.\n", cpu); @@ -371,9 +378,6 @@ void start_secondary(void *unused) tsx_init(); /* Needs microcode. May change HLE/RTM feature bits. */ - if ( xen_guest ) - hypervisor_ap_setup(); - smp_callin(); set_cpu_sibling_map(cpu); diff --git a/xen/include/asm-x86/guest/hypervisor.h b/xen/include/asm-x86/guest/hypervisor.h index b503854c5b..64383f0c3d 100644 --- a/xen/include/asm-x86/guest/hypervisor.h +++ b/xen/include/asm-x86/guest/hypervisor.h @@ -44,7 +44,7 @@ void hypervisor_resume(void); static inline const char *hypervisor_probe(void) { return NULL; } static inline void hypervisor_setup(void) { ASSERT_UNREACHABLE(); } -static inline int hypervisor_ap_setup(void) { ASSERT_UNREACHABLE(); return 0; } +static inline int hypervisor_ap_setup(void) { return 0; } static inline void hypervisor_resume(void) { ASSERT_UNREACHABLE(); } #endif /* CONFIG_GUEST */ From patchwork Tue Feb 4 15:36:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11364877 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7D3F5138D for ; Tue, 4 Feb 2020 15:38:19 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4F0D620674 for ; Tue, 4 Feb 2020 15:38:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="oIqv+n8p" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4F0D620674 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iz0GU-0001Mz-7z; Tue, 04 Feb 2020 15:37:26 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iz0GT-0001MU-9E for xen-devel@lists.xenproject.org; Tue, 04 Feb 2020 15:37:25 +0000 X-Inumbo-ID: 36748b00-4764-11ea-8396-bc764e2007e4 Received: from mail-wm1-x341.google.com (unknown [2a00:1450:4864:20::341]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 36748b00-4764-11ea-8396-bc764e2007e4; Tue, 04 Feb 2020 15:37:12 +0000 (UTC) Received: by mail-wm1-x341.google.com with SMTP id t14so4201149wmi.5 for ; Tue, 04 Feb 2020 07:37:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EI+IPWPMCwYrt4h7PFw+ok+7p6QoR9pnusk/lv/AnJU=; b=oIqv+n8pO8IRxFHpLpSDqHb/dZ+FdWHLH/TgdzWpgO3XXDk8svio1SGlYIXioE3b60 uwV6p0104oueFK7o3xhC3w/fmzSDKYRdPk57Zl+KZ15FvJ+ky3ADFhnISPsNjKbRZiHI fjdoIA/FFgggo9AP1rLftAgbLzprcT1r4uWJhzhkf8bUmYCz3ME53JrsXY26YSCdyr+4 9kmu4WjKqrfNCLPYOPXNmMGI/BGavv46KdgCkhe/xAHekgBS6ExihMGAEbF6EBRtSUdI 7OFDu/Iev54alWnPkBmQAH+EAAw/p3xRkxhR7m356jmiTcJOul70pzIDbsXGMFbOX56d oUrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=EI+IPWPMCwYrt4h7PFw+ok+7p6QoR9pnusk/lv/AnJU=; b=NfHX3v7Vdf5+Q8EpcGQnWZ07/1b9F8wl3ymEu926noEKOQ6w+qSjOg+OMukxZtsZdW eIIXGRmGEOBN+s+yIjatza8rVWjFIfHSHoi1OgiJatxoG1u27yM5DalkxGeR7mg6wiz8 tSp+JxJkuOVGCurbuH8n9p/71TLR3xRbX9WNr1t4Mmjbo34zsd/soty2DwckhKOy/HBb fost4cRlRzJrMgWYjsGSkD+PFZSDy02FnKA6Wz0g9a7tkx2axn6cbpGctY05Hx38Dns7 O7qheyy6ie8ZQMZm1wAofjp4RSTRESeER0J8DVFKadJ/Um1b7GZtgL5b7np1mNL8Cnp9 vXGw== X-Gm-Message-State: APjAAAV19ghkDL+CWwnPjGte6zXGm4it4Yk5aFR9tTd/ocbn5C8G6upy n98gco+b+N0cL8MCKa6GKs7Wj1QNHN8= X-Google-Smtp-Source: APXvYqzBQ5zO1Z4xbrl7e6DwNuL5OIYxTMWmBJva2R9wQZFR8SBQ56BCAGhX3/JLndXn9yF5URnULg== X-Received: by 2002:a05:600c:294:: with SMTP id 20mr6677887wmk.135.1580830631761; Tue, 04 Feb 2020 07:37:11 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id p26sm4067143wmc.24.2020.02.04.07.37.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 07:37:11 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Tue, 4 Feb 2020 15:36:57 +0000 Message-Id: <20200204153704.15934-4-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200204153704.15934-1-liuwe@microsoft.com> References: <20200204153704.15934-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v7 03/10] x86: provide executable fixmap facility X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Konrad Rzeszutek Wilk , Andrew Cooper , Paul Durrant , Michael Kelley , Ross Lagerwall , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This allows us to set aside some address space for executable mapping. This fixed map range starts from XEN_VIRT_END so that it is within reach of the .text section. Shift the percpu stub range and shrink livepatch range accordingly. Signed-off-by: Wei Liu Reviewed-by: Jan Beulich --- v7: 1. Introduce ASM_CONSTANT v6: 1. Move symbol generation snippet to arch_init_memory and use %P0 v5: 1. drop __virt_to_fix_x 2. also check FIX*_RESERVED in __set_fixmap* 3. generate global symbol to be used in linker script 4. address other misc comments --- xen/arch/x86/boot/x86_64.S | 15 ++++++++++++--- xen/arch/x86/livepatch.c | 3 ++- xen/arch/x86/mm.c | 14 +++++++++++++- xen/arch/x86/smpboot.c | 2 +- xen/arch/x86/xen.lds.S | 1 + xen/include/asm-x86/asm_defns.h | 5 +++++ xen/include/asm-x86/config.h | 2 +- xen/include/asm-x86/fixmap.h | 24 ++++++++++++++++++++++++ 8 files changed, 59 insertions(+), 7 deletions(-) diff --git a/xen/arch/x86/boot/x86_64.S b/xen/arch/x86/boot/x86_64.S index 1cbf5acdfb..314a32a19f 100644 --- a/xen/arch/x86/boot/x86_64.S +++ b/xen/arch/x86/boot/x86_64.S @@ -81,11 +81,20 @@ GLOBAL(l2_directmap) .size l2_directmap, . - l2_directmap /* - * L2 mapping the Xen text/data/bss region, constructed dynamically. Uses 1x - * 4k page. + * L2 mapping the Xen text/data/bss region, constructed dynamically. + * Executable fixmap is hooked up statically. + * Uses 1x 4k page. */ GLOBAL(l2_xenmap) - .fill L2_PAGETABLE_ENTRIES, 8, 0 + idx = 0 + .rept L2_PAGETABLE_ENTRIES + .if idx == l2_table_offset(FIXADDR_X_TOP - 1) + .quad sym_offs(l1_fixmap_x) + __PAGE_HYPERVISOR + .else + .quad 0 + .endif + idx = idx + 1 + .endr .size l2_xenmap, . - l2_xenmap /* L2 mapping the fixmap. Uses 1x 4k page. */ diff --git a/xen/arch/x86/livepatch.c b/xen/arch/x86/livepatch.c index 2749cbc5cf..513b0f3841 100644 --- a/xen/arch/x86/livepatch.c +++ b/xen/arch/x86/livepatch.c @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -311,7 +312,7 @@ void __init arch_livepatch_init(void) void *start, *end; start = (void *)xen_virt_end; - end = (void *)(XEN_VIRT_END - NR_CPUS * PAGE_SIZE); + end = (void *)(XEN_VIRT_END - FIXADDR_X_SIZE - NR_CPUS * PAGE_SIZE); BUG_ON(end <= start); diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index a05a713276..9b33829084 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -158,6 +158,8 @@ /* Mapping of the fixmap space needed early. */ l1_pgentry_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) l1_fixmap[L1_PAGETABLE_ENTRIES]; +l1_pgentry_t __section(".bss.page_aligned") __aligned(PAGE_SIZE) + l1_fixmap_x[L1_PAGETABLE_ENTRIES]; paddr_t __read_mostly mem_hotplug; @@ -373,6 +375,9 @@ void __init arch_init_memory(void) } } #endif + + /* Generate a symbol to be used in linker script */ + ASM_CONSTANT(FIXADDR_X_SIZE, FIXADDR_X_SIZE); } int page_is_ram_type(unsigned long mfn, unsigned long mem_type) @@ -5719,10 +5724,17 @@ int destroy_xen_mappings(unsigned long s, unsigned long e) void __set_fixmap( enum fixed_addresses idx, unsigned long mfn, unsigned long flags) { - BUG_ON(idx >= __end_of_fixed_addresses); + BUG_ON(idx >= __end_of_fixed_addresses || idx <= FIX_RESERVED); map_pages_to_xen(__fix_to_virt(idx), _mfn(mfn), 1, flags); } +void __set_fixmap_x( + enum fixed_addresses_x idx, unsigned long mfn, unsigned long flags) +{ + BUG_ON(idx >= __end_of_fixed_addresses_x || idx <= FIX_X_RESERVED); + map_pages_to_xen(__fix_x_to_virt(idx), _mfn(mfn), 1, flags); +} + void *__init arch_vmap_virt_end(void) { return fix_to_virt(__end_of_fixed_addresses); diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c index 93b86a09e9..e83e4564a4 100644 --- a/xen/arch/x86/smpboot.c +++ b/xen/arch/x86/smpboot.c @@ -644,7 +644,7 @@ unsigned long alloc_stub_page(unsigned int cpu, unsigned long *mfn) unmap_domain_page(memset(__map_domain_page(pg), 0xcc, PAGE_SIZE)); } - stub_va = XEN_VIRT_END - (cpu + 1) * PAGE_SIZE; + stub_va = XEN_VIRT_END - FIXADDR_X_SIZE - (cpu + 1) * PAGE_SIZE; if ( map_pages_to_xen(stub_va, page_to_mfn(pg), 1, PAGE_HYPERVISOR_RX | MAP_SMALL_PAGES) ) { diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S index f5730ffe93..44fda616d5 100644 --- a/xen/arch/x86/xen.lds.S +++ b/xen/arch/x86/xen.lds.S @@ -352,6 +352,7 @@ SECTIONS } ASSERT(__2M_rwdata_end <= XEN_VIRT_END - XEN_VIRT_START + __XEN_VIRT_START - + FIXADDR_X_SIZE - NR_CPUS * PAGE_SIZE, "Xen image overlaps stubs area") diff --git a/xen/include/asm-x86/asm_defns.h b/xen/include/asm-x86/asm_defns.h index 370f239c50..98cd49a89b 100644 --- a/xen/include/asm-x86/asm_defns.h +++ b/xen/include/asm-x86/asm_defns.h @@ -392,4 +392,9 @@ label: .long (val); \ .size label, . - label; \ .type label, @object + +#define ASM_CONSTANT(name, value) \ + asm ( ".equ " #name ", %P0; .global " #name \ + :: "i" ((value)) ); + #endif /* __X86_ASM_DEFNS_H__ */ diff --git a/xen/include/asm-x86/config.h b/xen/include/asm-x86/config.h index d0cfbb70a8..a34053c4c0 100644 --- a/xen/include/asm-x86/config.h +++ b/xen/include/asm-x86/config.h @@ -218,7 +218,7 @@ extern unsigned char boot_edid_info[128]; /* Slot 261: high read-only compat machine-to-phys conversion table (1GB). */ #define HIRO_COMPAT_MPT_VIRT_START RDWR_COMPAT_MPT_VIRT_END #define HIRO_COMPAT_MPT_VIRT_END (HIRO_COMPAT_MPT_VIRT_START + GB(1)) -/* Slot 261: xen text, static data and bss (1GB). */ +/* Slot 261: xen text, static data, bss, per-cpu stubs and executable fixmap (1GB). */ #define XEN_VIRT_START (HIRO_COMPAT_MPT_VIRT_END) #define XEN_VIRT_END (XEN_VIRT_START + GB(1)) diff --git a/xen/include/asm-x86/fixmap.h b/xen/include/asm-x86/fixmap.h index 9fb2f47946..8330097a74 100644 --- a/xen/include/asm-x86/fixmap.h +++ b/xen/include/asm-x86/fixmap.h @@ -15,6 +15,7 @@ #include #define FIXADDR_TOP (VMAP_VIRT_END - PAGE_SIZE) +#define FIXADDR_X_TOP (XEN_VIRT_END - PAGE_SIZE) #ifndef __ASSEMBLY__ @@ -89,6 +90,29 @@ static inline unsigned long virt_to_fix(const unsigned long vaddr) return __virt_to_fix(vaddr); } +enum fixed_addresses_x { + /* Index 0 is reserved since fix_x_to_virt(0) == FIXADDR_X_TOP. */ + FIX_X_RESERVED, +#ifdef CONFIG_HYPERV_GUEST + FIX_X_HYPERV_HCALL, +#endif + __end_of_fixed_addresses_x +}; + +#define FIXADDR_X_SIZE (__end_of_fixed_addresses_x << PAGE_SHIFT) +#define FIXADDR_X_START (FIXADDR_X_TOP - FIXADDR_X_SIZE) + +extern void __set_fixmap_x( + enum fixed_addresses_x idx, unsigned long mfn, unsigned long flags); + +#define set_fixmap_x(idx, phys) \ + __set_fixmap_x(idx, (phys)>>PAGE_SHIFT, PAGE_HYPERVISOR_RX | MAP_SMALL_PAGES) + +#define clear_fixmap_x(idx) __set_fixmap_x(idx, 0, 0) + +#define __fix_x_to_virt(x) (FIXADDR_X_TOP - ((x) << PAGE_SHIFT)) +#define fix_x_to_virt(x) ((void *)__fix_x_to_virt(x)) + #endif /* __ASSEMBLY__ */ #endif From patchwork Tue Feb 4 15:36:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11364879 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 58D4F92A for ; Tue, 4 Feb 2020 15:38:25 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 35C5720674 for ; Tue, 4 Feb 2020 15:38:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FxUCKDN1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 35C5720674 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iz0GZ-0001QH-Ki; Tue, 04 Feb 2020 15:37:31 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iz0GY-0001PP-9y for xen-devel@lists.xenproject.org; Tue, 04 Feb 2020 15:37:30 +0000 X-Inumbo-ID: 370f315a-4764-11ea-8396-bc764e2007e4 Received: from mail-wr1-x444.google.com (unknown [2a00:1450:4864:20::444]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 370f315a-4764-11ea-8396-bc764e2007e4; Tue, 04 Feb 2020 15:37:13 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id z9so11401217wrs.10 for ; Tue, 04 Feb 2020 07:37:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RamMyxA7eCEhhsUkaM1ZIdMTbkYKaRV5qn3nRLFrXI8=; b=FxUCKDN1EFpDKVMer6ECw/dYqN3wYNYg9Jr9xTXc0mSUuBYp4h8XsTC8sZHF7XYRlI YuFmakjbWU/E8qpYtBDlIOrw0Ms91yGFvFaRIgVt5nV/8lSiKKGP8KNqlAN/lmbmw2h4 fyN+LOIzaVbjb4r9EsSbisl9d0CGkwFtZ21aHdY9YKcwiVqFSRZ6j+qUDgtkULWxc//K WsKXt5eDRZaWbsJZadHYJOt44FJj79KYVSaugWQA+aOAeGPT3WrufCnyhtmRY49uGvIT UNnOCvE+Z3AfRMPxjs78dvIyIOBsUH9hside4tXwoA6bXozlrdpxZqyYIB7Q1X9nvf2W i8Wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=RamMyxA7eCEhhsUkaM1ZIdMTbkYKaRV5qn3nRLFrXI8=; b=I8zVNCZtof5n51dWuy+rWOqe2xnjKzoy22JohfBMXqy/X86S8TKOQXHwWL3DSYZYiu DZuLcMvJHTsXuc1Wfa/CRUupuZz0dY97NGhVKlRO69a0RLdkXZffDjfrQDRTUqbP65Nt pnoTw6hldyDO2+5+Jpejcmu8ZTh01uP9zmFd0KOllVc5YS8YaWflUEHR4LmqqRFmsExv iZ4dfBJ3is8yu+bicDghFpXVZwY/+9TjcbjKOOSxX7BVAoAozsHVZgg1xiQvreCZdQ/T MhCW6HjHPfKtgmj7k1oLdlA48hiGVC59aE0mNx18yK6s7323zQGn8N89WmlsE7rqpD42 p7zg== X-Gm-Message-State: APjAAAUiVDiOFTAGFLKk2L6o+xod8q9wub9HdWtpcDvQkZ8nrro/SPVW tdE4J6HWLxAH1wXp4YZT0jTZkIzHe8o= X-Google-Smtp-Source: APXvYqyXIv8AhYrQsvNztjZlBUrSpG0bafdrwper0ZIxiI8BNjj6TmSQJXehGFA9nc+/XbLpWRo98A== X-Received: by 2002:adf:ea88:: with SMTP id s8mr22563522wrm.293.1580830632917; Tue, 04 Feb 2020 07:37:12 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id p26sm4067143wmc.24.2020.02.04.07.37.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 07:37:12 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Tue, 4 Feb 2020 15:36:58 +0000 Message-Id: <20200204153704.15934-5-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200204153704.15934-1-liuwe@microsoft.com> References: <20200204153704.15934-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v7 04/10] x86/hypervisor: provide hypervisor_fixup_e820 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Andrew Cooper , Paul Durrant , Michael Kelley , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" And implement the hook for Xen guest. Signed-off-by: Wei Liu Reviewed-by: Jan Beulich --- v7: 1. Drop bogus ASSERT_UNREACHABLE from stub 2. Add Jan's Rb, considering #1 doesn't change the meat of the patch --- xen/arch/x86/e820.c | 4 ++-- xen/arch/x86/guest/hypervisor.c | 6 ++++++ xen/arch/x86/guest/xen/xen.c | 7 +++++++ xen/include/asm-x86/guest/hypervisor.h | 6 ++++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/e820.c b/xen/arch/x86/e820.c index b9f589cac3..160f029edd 100644 --- a/xen/arch/x86/e820.c +++ b/xen/arch/x86/e820.c @@ -691,8 +691,8 @@ unsigned long __init init_e820(const char *str, struct e820map *raw) machine_specific_memory_setup(raw); - if ( pv_shim ) - pv_shim_fixup_e820(&e820); + if ( cpu_has_hypervisor ) + hypervisor_e820_fixup(&e820); printk("%s RAM map:\n", str); print_e820_memory_map(e820.map, e820.nr_map); diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c index e72c92ffdf..5fd433c8d4 100644 --- a/xen/arch/x86/guest/hypervisor.c +++ b/xen/arch/x86/guest/hypervisor.c @@ -66,6 +66,12 @@ void hypervisor_resume(void) ops->resume(); } +void __init hypervisor_e820_fixup(struct e820map *e820) +{ + if ( ops && ops->e820_fixup ) + ops->e820_fixup(e820); +} + /* * Local variables: * mode: C diff --git a/xen/arch/x86/guest/xen/xen.c b/xen/arch/x86/guest/xen/xen.c index 1cf09886da..5a7f3cce42 100644 --- a/xen/arch/x86/guest/xen/xen.c +++ b/xen/arch/x86/guest/xen/xen.c @@ -322,11 +322,18 @@ static void resume(void) pv_console_init(); } +static void __init e820_fixup(struct e820map *e820) +{ + if ( pv_shim ) + pv_shim_fixup_e820(e820); +} + static const struct hypervisor_ops ops = { .name = "Xen", .setup = setup, .ap_setup = ap_setup, .resume = resume, + .e820_fixup = e820_fixup, }; const struct hypervisor_ops *__init xg_probe(void) diff --git a/xen/include/asm-x86/guest/hypervisor.h b/xen/include/asm-x86/guest/hypervisor.h index 64383f0c3d..ade10e74ea 100644 --- a/xen/include/asm-x86/guest/hypervisor.h +++ b/xen/include/asm-x86/guest/hypervisor.h @@ -19,6 +19,8 @@ #ifndef __X86_HYPERVISOR_H__ #define __X86_HYPERVISOR_H__ +#include + struct hypervisor_ops { /* Name of the hypervisor */ const char *name; @@ -28,6 +30,8 @@ struct hypervisor_ops { int (*ap_setup)(void); /* Resume from suspension */ void (*resume)(void); + /* Fix up e820 map */ + void (*e820_fixup)(struct e820map *e820); }; #ifdef CONFIG_GUEST @@ -36,6 +40,7 @@ const char *hypervisor_probe(void); void hypervisor_setup(void); int hypervisor_ap_setup(void); void hypervisor_resume(void); +void hypervisor_e820_fixup(struct e820map *e820); #else @@ -46,6 +51,7 @@ static inline const char *hypervisor_probe(void) { return NULL; } static inline void hypervisor_setup(void) { ASSERT_UNREACHABLE(); } static inline int hypervisor_ap_setup(void) { return 0; } static inline void hypervisor_resume(void) { ASSERT_UNREACHABLE(); } +static inline void hypervisor_e820_fixup(struct e820map *e820) {} #endif /* CONFIG_GUEST */ From patchwork Tue Feb 4 15:36:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11364883 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D2A7F92A for ; Tue, 4 Feb 2020 15:38:32 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AF58320674 for ; Tue, 4 Feb 2020 15:38:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="oWFuSr55" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AF58320674 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iz0Gf-0001TL-1N; Tue, 04 Feb 2020 15:37:37 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iz0Gd-0001Sd-AF for xen-devel@lists.xenproject.org; Tue, 04 Feb 2020 15:37:35 +0000 X-Inumbo-ID: 379c1b88-4764-11ea-b211-bc764e2007e4 Received: from mail-wr1-x443.google.com (unknown [2a00:1450:4864:20::443]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 379c1b88-4764-11ea-b211-bc764e2007e4; Tue, 04 Feb 2020 15:37:14 +0000 (UTC) Received: by mail-wr1-x443.google.com with SMTP id z3so23679672wru.3 for ; Tue, 04 Feb 2020 07:37:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2o+ZbfiA0a6Wu3YZ4de0M249TmV6XmlurF8HVqhhL2Q=; b=oWFuSr55Wpmndzs8SN9c2Lm8sz56GbSC8F/2KL3FZRjz8eEfcSd5uhjMc65fB5slqy SXgmCXzheWUP4Rwm4Vd6z/Z0P7L++XeY7X0NFg7e09LkpDSN2ac6DWTP2/rJju+YQEDk btML7Rs+qc+07Gu5fwV5iTlINZNTOz1yPcFAxL/ExNUWbMza8ZEV36MwENVZqHWGFeQN GOiLG6anKwQZd+DgI8PsScz5svgaEm8t0PqIRv+wXRF7yIGSzrYaUmtKlt9wLK5ZFJti r820oVZz5jEE06eQ/Hwmv7b+jHCYRN13oW8IehDHIGVYSmLkZfRj5m/mAg3o3cE123mg k7ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=2o+ZbfiA0a6Wu3YZ4de0M249TmV6XmlurF8HVqhhL2Q=; b=bGpNQ/DVt8+m64F2tm5uLlfskhcanslspMyBQs0R48+RKBDkc2CbiFzwnK/3ETA6mK SdVFua9glMfZenbPAGWvLrXLwURaE+lv77YEUTogCs5FCW1AQWAWlS3A0MAUngYd7yQY TIRLVVeQhvUEiRJi9L2dh4IV0g0/DVIQNxsWa1BFmbemsPRI0FuK4AFKjZ2Nat6Mv9H9 Iy88+VTRObnUu3eCRP/VvDrVrFN+H3AJMPHxkMGQbsNS+dcArbHxRIywZpo7TyF//QS3 1jVK3bXhp3u/uTcRFWTmyBkz6mqscJMDMBWy3VvDO5KasIZQxCi5e+auuRB6SOmt+1vo kPwg== X-Gm-Message-State: APjAAAVSM7MaB61npQte4e68KhH2R9hmz80x9njy0kwAugkOuYrkUhUX Tjk2Bpqbyekuwf7oU/SKkeRrcQkxGTM= X-Google-Smtp-Source: APXvYqzufoR5C7xLbPZeGeTwiN703d6qgtrbLKyDC4fFTo3mtRKYZor7Q+HtnQQG/l8VfX+zhoY2XQ== X-Received: by 2002:adf:cd92:: with SMTP id q18mr22223567wrj.261.1580830633811; Tue, 04 Feb 2020 07:37:13 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id p26sm4067143wmc.24.2020.02.04.07.37.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 07:37:13 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Tue, 4 Feb 2020 15:36:59 +0000 Message-Id: <20200204153704.15934-6-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200204153704.15934-1-liuwe@microsoft.com> References: <20200204153704.15934-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v7 05/10] x86/hyperv: setup hypercall page X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Andrew Cooper , Paul Durrant , Michael Kelley , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Hyper-V uses a technique called overlay page for its hypercall page. It will insert a backing page to the guest when the hypercall functionality is enabled. That means we can use a page that is not backed by real memory for hypercall page. To avoid shattering L0 superpages and treading on any MMIO areas residing in low addresses, use the top-most addressable page for that purpose. Adjust e820 map accordingly. We also need to register Xen's guest OS ID to Hyper-V. Use 0x3 as the vendor ID. Fix the comment in hyperv-tlfs.h while at it. Signed-off-by: Wei Liu Reviewed-by: Roger Pau Monné Acked-by: Paul Durrant --- v7: 1. Fix a style issue 2. Initialise ID to 0 3. Update commit message v6: 1. Use hv_guest_os_id 2. Use new e820_fixup hook 3. Add a BUILD_BUG_ON v5: 1. use hypervisor_reserve_top_pages 2. add a macro for hypercall page mfn 3. address other misc comments v4: 1. Use fixmap 2. Follow routines listed in TLFS --- xen/arch/x86/guest/hyperv/hyperv.c | 69 +++++++++++++++++++++++-- xen/include/asm-x86/guest/hyperv-tlfs.h | 5 +- xen/include/asm-x86/guest/hyperv.h | 3 ++ 3 files changed, 72 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index 8d38313d7a..2e20a96f30 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -19,15 +19,27 @@ * Copyright (c) 2019 Microsoft. */ #include +#include +#include #include #include +#include struct ms_hyperv_info __read_mostly ms_hyperv; -static const struct hypervisor_ops ops = { - .name = "Hyper-V", -}; +static uint64_t generate_guest_id(void) +{ + union hv_guest_os_id id = {}; + + id.vendor = HV_XEN_VENDOR_ID; + id.major = xen_major_version(); + id.minor = xen_minor_version(); + + return id.raw; +} + +static const struct hypervisor_ops ops; const struct hypervisor_ops *__init hyperv_probe(void) { @@ -72,6 +84,57 @@ const struct hypervisor_ops *__init hyperv_probe(void) return &ops; } +static void __init setup_hypercall_page(void) +{ + union hv_x64_msr_hypercall_contents hypercall_msr; + union hv_guest_os_id guest_id; + unsigned long mfn; + + BUILD_BUG_ON(HV_HYP_PAGE_SHIFT != PAGE_SHIFT); + + rdmsrl(HV_X64_MSR_GUEST_OS_ID, guest_id.raw); + if ( !guest_id.raw ) + { + guest_id.raw = generate_guest_id(); + wrmsrl(HV_X64_MSR_GUEST_OS_ID, guest_id.raw); + } + + rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); + if ( !hypercall_msr.enable ) + { + mfn = HV_HCALL_MFN; + hypercall_msr.enable = 1; + hypercall_msr.guest_physical_address = mfn; + wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); + } + else + mfn = hypercall_msr.guest_physical_address; + + rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); + BUG_ON(!hypercall_msr.enable); + + set_fixmap_x(FIX_X_HYPERV_HCALL, mfn << PAGE_SHIFT); +} + +static void __init setup(void) +{ + setup_hypercall_page(); +} + +static void __init e820_fixup(struct e820map *e820) +{ + uint64_t s = HV_HCALL_MFN << PAGE_SHIFT; + + if ( !e820_add_range(e820, s, s + PAGE_SIZE, E820_RESERVED) ) + panic("Unable to reserve Hyper-V hypercall range\n"); +} + +static const struct hypervisor_ops ops = { + .name = "Hyper-V", + .setup = setup, + .e820_fixup = e820_fixup, +}; + /* * Local variables: * mode: C diff --git a/xen/include/asm-x86/guest/hyperv-tlfs.h b/xen/include/asm-x86/guest/hyperv-tlfs.h index 091e25cdd1..0a0f3398c1 100644 --- a/xen/include/asm-x86/guest/hyperv-tlfs.h +++ b/xen/include/asm-x86/guest/hyperv-tlfs.h @@ -318,15 +318,16 @@ struct ms_hyperv_tsc_page { * * Bit(s) * 63 - Indicates if the OS is Open Source or not; 1 is Open Source - * 62:56 - Os Type; Linux is 0x100 + * 62:56 - Os Type; Linux 0x1, FreeBSD 0x2, Xen 0x3 * 55:48 - Distro specific identification - * 47:16 - Linux kernel version number + * 47:16 - Guest OS version number * 15:0 - Distro specific identification * * */ #define HV_LINUX_VENDOR_ID 0x8100 +#define HV_XEN_VENDOR_ID 0x8300 union hv_guest_os_id { uint64_t raw; diff --git a/xen/include/asm-x86/guest/hyperv.h b/xen/include/asm-x86/guest/hyperv.h index c7a7f32bd5..1a1b47831c 100644 --- a/xen/include/asm-x86/guest/hyperv.h +++ b/xen/include/asm-x86/guest/hyperv.h @@ -21,6 +21,9 @@ #include +/* Use top-most MFN for hypercall page */ +#define HV_HCALL_MFN (((1ull << paddr_bits) - 1) >> HV_HYP_PAGE_SHIFT) + /* * The specification says: "The partition reference time is computed * by the following formula: From patchwork Tue Feb 4 15:37:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11364881 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1A114138D for ; Tue, 4 Feb 2020 15:38:28 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EB26520674 for ; Tue, 4 Feb 2020 15:38:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dGZTjetT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EB26520674 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iz0Gj-0001Wm-M6; Tue, 04 Feb 2020 15:37:41 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iz0Gi-0001W0-Ae for xen-devel@lists.xenproject.org; Tue, 04 Feb 2020 15:37:40 +0000 X-Inumbo-ID: 387649c0-4764-11ea-8396-bc764e2007e4 Received: from mail-wr1-x443.google.com (unknown [2a00:1450:4864:20::443]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 387649c0-4764-11ea-8396-bc764e2007e4; Tue, 04 Feb 2020 15:37:16 +0000 (UTC) Received: by mail-wr1-x443.google.com with SMTP id a6so23597001wrx.12 for ; Tue, 04 Feb 2020 07:37:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EKuTjmynFU1SnW3qUHLFCseCIXL0qzB/eqlqEgR7D1c=; b=dGZTjetTeT6Zhp4Ghw7q4zZ+vSiQkpfjOpqlok7wc0dkXCMHSrtzqoEx+KnN/yyduj qhOhq1YU+AVc/ifOGl+HbcKLxurZ/kesfKx2XZ9rU/DjAHDLumwgF0+WrzVLYpE9Y1r9 MPRkZwkG/H8wmxbMXxRZna43eTPD9FE44H2262lFuwiFEgsx8KSWSaNX7pOdnyuxj8EG CZZnyfVXlvHFqP8PV2dzqqHz4H77IFRf0SW5UEOU+hOs/QXg9Dxpc9ZRFfGq2rWPu1+U quNAuIEhUWhJpXaoWXlMZwSjunW23IsP9zwcsNd8Tx9Lp0rLun1g0npYfBsezjDAT+Ab 5WGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=EKuTjmynFU1SnW3qUHLFCseCIXL0qzB/eqlqEgR7D1c=; b=NfXiYS5gv/H55Bm1/tiG0XsaPruMVU27jPKAUMuuuXaxVIC4vYH47R2FeYY2DDelJ2 SVIPddVVM1NnJvcw8TZizoLQhULnB27pnISVbPkGxkGuz54FGDMCur9EUFSy3r4Z3TQc R9XVpTU+jhyCrd0Iw3SDAjMHUq7O+husWva1IIRVR8iMereI0ZyiMOvBugwSK/SW9lKy h02q+tWaGd0X9iBAk5Mf8IkTtvlBUhqOPQ3dQ6rdaGpwl9a9hZoSHbzXjZN6Xln/yxyI ASFizlfk4ShmHr0qzbuFVmvSkItWT8ryYeV+CtPTlaeLvvyMsMhPhcRtfmTss3oSXITI PUQQ== X-Gm-Message-State: APjAAAXtks8UAXgaq2AIBzvldFIqJmfrfpwKEvCpuxmOiH5Vn9GecTPm tkHagQgaPPnkmoDl0aTPytKC7m5eOpQ= X-Google-Smtp-Source: APXvYqyjV5G5GpE/32n97a1haVR2UnKK+TZ5VAHD0k29XwwhL3qNVKwyeBnytzuxLSxlo/yKkxvfQw== X-Received: by 2002:a5d:4481:: with SMTP id j1mr22350879wrq.348.1580830635260; Tue, 04 Feb 2020 07:37:15 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id p26sm4067143wmc.24.2020.02.04.07.37.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 07:37:14 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Tue, 4 Feb 2020 15:37:00 +0000 Message-Id: <20200204153704.15934-7-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200204153704.15934-1-liuwe@microsoft.com> References: <20200204153704.15934-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v7 06/10] x86/hyperv: provide Hyper-V hypercall functions X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Wei Liu , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Paul Durrant , Ian Jackson , Michael Kelley , Jan Beulich , Julien Grall , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" These functions will be used later to make hypercalls to Hyper-V. Signed-off-by: Wei Liu Reviewed-by: Paul Durrant Acked-by: Jan Beulich --- v7: 1. Use ASM_CONSTANT and put it in hyperv.c v6: 1. Use asm(...) to generate symbol 2. Add a comment regarding volatile registers v5: 1. Switch back to direct call 2. Fix some issues pointed out by Jan --- MAINTAINERS | 1 + xen/arch/x86/guest/hyperv/hyperv.c | 2 + xen/arch/x86/xen.lds.S | 4 + xen/include/asm-x86/guest/hyperv-hcall.h | 97 ++++++++++++++++++++++++ 4 files changed, 104 insertions(+) create mode 100644 xen/include/asm-x86/guest/hyperv-hcall.h diff --git a/MAINTAINERS b/MAINTAINERS index 04d91482cd..d0a5ed635b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -519,6 +519,7 @@ S: Supported F: xen/arch/x86/guest/hyperv/ F: xen/arch/x86/hvm/viridian/ F: xen/include/asm-x86/guest/hyperv.h +F: xen/include/asm-x86/guest/hyperv-hcall.h F: xen/include/asm-x86/guest/hyperv-tlfs.h F: xen/include/asm-x86/hvm/viridian.h diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index 2e20a96f30..888bda25b0 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -118,6 +118,8 @@ static void __init setup_hypercall_page(void) static void __init setup(void) { + ASM_CONSTANT(HV_HCALL_PAGE, __fix_x_to_virt(FIX_X_HYPERV_HCALL)); + setup_hypercall_page(); } diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S index 44fda616d5..7f9459d683 100644 --- a/xen/arch/x86/xen.lds.S +++ b/xen/arch/x86/xen.lds.S @@ -326,6 +326,10 @@ SECTIONS efi = .; #endif +#ifdef CONFIG_HYPERV_GUEST + hv_hcall_page = ABSOLUTE(HV_HCALL_PAGE); +#endif + /* Sections to be discarded */ /DISCARD/ : { *(.exit.text) diff --git a/xen/include/asm-x86/guest/hyperv-hcall.h b/xen/include/asm-x86/guest/hyperv-hcall.h new file mode 100644 index 0000000000..4d3b131b3a --- /dev/null +++ b/xen/include/asm-x86/guest/hyperv-hcall.h @@ -0,0 +1,97 @@ +/****************************************************************************** + * asm-x86/guest/hyperv-hcall.h + * + * This program is free software; you can redistribute it and/or + * modify it under the terms and conditions of the GNU General Public + * License, version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; If not, see . + * + * Copyright (c) 2019 Microsoft. + */ + +#ifndef __X86_HYPERV_HCALL_H__ +#define __X86_HYPERV_HCALL_H__ + +#include +#include + +#include +#include +#include +#include + +static inline uint64_t hv_do_hypercall(uint64_t control, paddr_t input_addr, + paddr_t output_addr) +{ + uint64_t status; + register unsigned long r8 asm ( "r8" ) = output_addr; + + /* See TLFS for volatile registers */ + asm volatile ( "call hv_hcall_page" + : "=a" (status), "+c" (control), + "+d" (input_addr) ASM_CALL_CONSTRAINT + : "r" (r8) + : "memory" ); + + return status; +} + +static inline uint64_t hv_do_fast_hypercall(uint16_t code, + uint64_t input1, uint64_t input2) +{ + uint64_t status; + uint64_t control = code | HV_HYPERCALL_FAST_BIT; + register unsigned long r8 asm ( "r8" ) = input2; + + /* See TLFS for volatile registers */ + asm volatile ( "call hv_hcall_page" + : "=a" (status), "+c" (control), + "+d" (input1) ASM_CALL_CONSTRAINT + : "r" (r8) ); + + return status; +} + +static inline uint64_t hv_do_rep_hypercall(uint16_t code, uint16_t rep_count, + uint16_t varhead_size, + paddr_t input, paddr_t output) +{ + uint64_t control = code; + uint64_t status; + uint16_t rep_comp; + + control |= (uint64_t)varhead_size << HV_HYPERCALL_VARHEAD_OFFSET; + control |= (uint64_t)rep_count << HV_HYPERCALL_REP_COMP_OFFSET; + + do { + status = hv_do_hypercall(control, input, output); + if ( (status & HV_HYPERCALL_RESULT_MASK) != HV_STATUS_SUCCESS ) + break; + + rep_comp = MASK_EXTR(status, HV_HYPERCALL_REP_COMP_MASK); + + control &= ~HV_HYPERCALL_REP_START_MASK; + control |= MASK_INSR(rep_comp, HV_HYPERCALL_REP_START_MASK); + } while ( rep_comp < rep_count ); + + return status; +} + +#endif /* __X86_HYPERV_HCALL_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ From patchwork Tue Feb 4 15:37:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11364885 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 63EF392A for ; Tue, 4 Feb 2020 15:38:44 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4075F20674 for ; Tue, 4 Feb 2020 15:38:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bmMq8d43" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4075F20674 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iz0Gp-0001an-2D; Tue, 04 Feb 2020 15:37:47 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iz0Gn-0001ZS-Ag for xen-devel@lists.xenproject.org; Tue, 04 Feb 2020 15:37:45 +0000 X-Inumbo-ID: 3927529c-4764-11ea-a933-bc764e2007e4 Received: from mail-wm1-x341.google.com (unknown [2a00:1450:4864:20::341]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 3927529c-4764-11ea-a933-bc764e2007e4; Tue, 04 Feb 2020 15:37:17 +0000 (UTC) Received: by mail-wm1-x341.google.com with SMTP id q9so3777314wmj.5 for ; Tue, 04 Feb 2020 07:37:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lx6aI7LGswDmSt31XBjw6y0ZT47SzYKNZSKQP2MOBpk=; b=bmMq8d43p8nkqHb75gLI5GH2BjLUPh8jv8scZjvRSt8vqcgX1myWTJ7fZLoRqo2HI5 A3g1zBJhkPsIkOV22xBRoXRojXZ8f0IHTEvihoLPCWbRjbE8A63lNd6G3fh12pnLZD3A LSFO1rKz1Sjz3hnqoEGvE3lgJU6MZCQBVDlh7tSai6rPNK/DTvOXgpJ3qEQIP7Bl+tOj 3cArvOeuBnbkGVkWDfSIRMfWVly8uHPEEYhoAq75pFO47UHwS5qev2YvZDtsO+xDgu3H X+3taVF6Z86PntbZAeDKP1ynX85ov6EJVqmks3DwjTI2QQ/arB69b8DO0y+wsXmkBn5L IKDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=lx6aI7LGswDmSt31XBjw6y0ZT47SzYKNZSKQP2MOBpk=; b=XVFEAh5kA+ZlnmQt8U1y3gU9cGe4Ia7RKgxZXOoapqdwPZY8QGCZICBEWC+97gHIRv FFQQRPnAb6HI6yKWameEJRFRlDQL7rC6QpOQzk2/MH1rWvJNO6v1Dh3uPtcro7JmCJ4J t0JLa+7tp0SP8nKW5u41miPTihXuydv3Ta1bW9Uh10mGRrjh8uWTaLpLZnC+TDlsClDo 6kwzPVi9v6pPNtYRiJwzVPbVnfN4redYGm4QChfPunNKPWEkqKjRdduw91JmqwTBIDDC fqsjRAZmGtsKAupabbiv8Q32hEhKJLDiCdOZPSaPq4U+6Ul2CgHBmadfcMkTsVGRZAH8 h7BQ== X-Gm-Message-State: APjAAAVk5yPRFhoK4hheq7tZlbU0i3gyccChPRXpSRxOA9SlFieNRUA9 rDwABz6H2lWka998Y1TD+YMXUYd/Hq4= X-Google-Smtp-Source: APXvYqy7P9iOFGDC0ujXcqu3X880lt6G3RIgwcwBd7XtZW81RuvWrvtMm3boEfX+Rkd/hGx1QfiNRA== X-Received: by 2002:a05:600c:2551:: with SMTP id e17mr6571784wma.187.1580830636248; Tue, 04 Feb 2020 07:37:16 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id p26sm4067143wmc.24.2020.02.04.07.37.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 07:37:15 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Tue, 4 Feb 2020 15:37:01 +0000 Message-Id: <20200204153704.15934-8-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200204153704.15934-1-liuwe@microsoft.com> References: <20200204153704.15934-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v7 07/10] DO NOT APPLY: x86/hyperv: issue an hypercall X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Andrew Cooper , Paul Durrant , Michael Kelley , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Test if the infrastructure works. Signed-off-by: Wei Liu --- xen/arch/x86/guest/hyperv/hyperv.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index 888bda25b0..2a2afcb363 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -114,6 +115,19 @@ static void __init setup_hypercall_page(void) BUG_ON(!hypercall_msr.enable); set_fixmap_x(FIX_X_HYPERV_HCALL, mfn << PAGE_SHIFT); + + /* XXX Wei: Issue an hypercall here to make sure things are set up + * correctly. When there is actual use of the hypercall facility, + * this can be removed. + */ + { + uint16_t r = hv_do_hypercall(0xffff, 0, 0); + BUG_ON(r != HV_STATUS_INVALID_HYPERCALL_CODE); + r = hv_do_fast_hypercall(0xffff, 0, 0); + BUG_ON(r != HV_STATUS_INVALID_HYPERCALL_CODE); + + printk("Successfully issued Hyper-V hypercalls\n"); + } } static void __init setup(void) From patchwork Tue Feb 4 15:37:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11364887 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C683F92A for ; Tue, 4 Feb 2020 15:38:49 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A2ECC20674 for ; Tue, 4 Feb 2020 15:38:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mVqLMm9V" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A2ECC20674 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iz0Gt-0001eB-EM; Tue, 04 Feb 2020 15:37:51 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iz0Gs-0001dO-AH for xen-devel@lists.xenproject.org; Tue, 04 Feb 2020 15:37:50 +0000 X-Inumbo-ID: 3a4cb3c4-4764-11ea-8396-bc764e2007e4 Received: from mail-wr1-x442.google.com (unknown [2a00:1450:4864:20::442]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 3a4cb3c4-4764-11ea-8396-bc764e2007e4; Tue, 04 Feb 2020 15:37:19 +0000 (UTC) Received: by mail-wr1-x442.google.com with SMTP id z7so23550777wrl.13 for ; Tue, 04 Feb 2020 07:37:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rHW797PnSnAKQGPtPpxfNCtXqooWzhK9wvrkDonruZY=; b=mVqLMm9VDCdYFpGHPyTKdGykWzEkUQqpZa9ht5jTLuo+aalA3pZhVUyE7M2FQSlF8g d3+2BlOGdEpikghRAX6uDphm0Pcui2Q4cDuZ+U5Arfsxo0TknMF8+tRYMdjCjr51uOyx KkLE64WXwpnBsNljG1HFjZPc0rbPbo0ptz1hXuhyw96K2/H2z7us5QBerlNxUN9NY9vd xdqFCAjDLEwfsnq8oQms/bYHslFGVO3NAJKs4ltqQJeBBXM9d/P0PwmxVto+KumwEm34 rFnZ8B+IFbjUdvxnCwaKGEiCWLYyS03dX8/JVzTBYWBk8M8LogvST46WX+m+XTfVPGcp F5VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=rHW797PnSnAKQGPtPpxfNCtXqooWzhK9wvrkDonruZY=; b=FB4qJr9dkCDWGrlctIPtuMO9vCbiFMnKIY0MR1pvJfiPmzf9Y6oFSdlLxymoT5UtYY 8qGE0p6q4EJUeIj3ptTPTjKerew4sPQNke16yMjakt+rLXMHPar1mq/xnJx3MqEHGmYE fPOyJsx/Vy+XakeWItLC6y3PvXANeOk74cvVZojKFTTmUBd08Y1I5zv1bsvPRGSMZ3OS QXA/uUxWK97ulcKJ3Rak4k5dwk43+DdItVVNUL+1YjdehrjnqfkfkbQ7rHqsbspRYI61 eTasIfXZANb5DjxfENGdjwgRJaUrD3MAp/wGi52w03EkfB5owADx3zrqHwg5kIr0w88U zKcw== X-Gm-Message-State: APjAAAV8Q+n8Qgsc2LRDL17wBBuZjStuDiJq6nVqXB0tvdyv45/WDudx BULdy3PykmyjbXl/bOvXyAvhMQo3cnY= X-Google-Smtp-Source: APXvYqw74B6LPmIVyxElrEIagcvKTsXOsSenaCZop0exi2LVFFcDApz813LIvle+0RtlozLYgqzx9w== X-Received: by 2002:adf:b64b:: with SMTP id i11mr24453079wre.58.1580830638351; Tue, 04 Feb 2020 07:37:18 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id p26sm4067143wmc.24.2020.02.04.07.37.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 07:37:17 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Tue, 4 Feb 2020 15:37:02 +0000 Message-Id: <20200204153704.15934-9-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200204153704.15934-1-liuwe@microsoft.com> References: <20200204153704.15934-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v7 08/10] x86/hyperv: provide percpu hypercall input page X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Andrew Cooper , Paul Durrant , Michael Kelley , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Hyper-V's input / output argument must be 8 bytes aligned an not cross page boundary. One way to satisfy those requirements is to use percpu page. For the foreseeable future we only need to provide input for TLB and APIC hypercalls, so skip setting up an output page. We will also need to provide an ap_setup hook for secondary cpus to setup its own input page. Signed-off-by: Wei Liu Reviewed-by: Paul Durrant Reviewed-by: Roger Pau Monné --- v6: 1. Make code shorter 2. Change variable name v5: 1. Adjust to new ap_setup 2. Change variable name to hv_pcpu_input_page v4: 1. Change wording in commit message 2. Prevent leak 3. Introduce a private header v3: 1. Use xenheap page instead 2. Drop page tracking structure 3. Drop Paul's review tag address comments --- xen/arch/x86/guest/hyperv/hyperv.c | 28 ++++++++++++++++++++++++++++ xen/arch/x86/guest/hyperv/private.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 xen/arch/x86/guest/hyperv/private.h diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index 2a2afcb363..6b58065c78 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -27,7 +27,10 @@ #include #include +#include "private.h" + struct ms_hyperv_info __read_mostly ms_hyperv; +DEFINE_PER_CPU_READ_MOSTLY(void *, hv_input_page); static uint64_t generate_guest_id(void) { @@ -130,11 +133,35 @@ static void __init setup_hypercall_page(void) } } +static int setup_hypercall_pcpu_arg(void) +{ + if ( this_cpu(hv_input_page) ) + return 0; + + this_cpu(hv_input_page) = alloc_xenheap_page(); + if ( !this_cpu(hv_input_page) ) + { + printk("CPU%u: Failed to allocate hypercall input page\n", + smp_processor_id()); + return -ENOMEM; + } + + return 0; +} + static void __init setup(void) { ASM_CONSTANT(HV_HCALL_PAGE, __fix_x_to_virt(FIX_X_HYPERV_HCALL)); setup_hypercall_page(); + + if ( setup_hypercall_pcpu_arg() ) + panic("Hyper-V hypercall percpu arg setup failed\n"); +} + +static int ap_setup(void) +{ + return setup_hypercall_pcpu_arg(); } static void __init e820_fixup(struct e820map *e820) @@ -148,6 +175,7 @@ static void __init e820_fixup(struct e820map *e820) static const struct hypervisor_ops ops = { .name = "Hyper-V", .setup = setup, + .ap_setup = ap_setup, .e820_fixup = e820_fixup, }; diff --git a/xen/arch/x86/guest/hyperv/private.h b/xen/arch/x86/guest/hyperv/private.h new file mode 100644 index 0000000000..093985a94b --- /dev/null +++ b/xen/arch/x86/guest/hyperv/private.h @@ -0,0 +1,29 @@ +/****************************************************************************** + * arch/x86/guest/hyperv/private.h + * + * Definitions / declarations only useful to Hyper-V code. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; If not, see . + * + * Copyright (c) 2020 Microsoft. + */ + +#ifndef __XEN_HYPERV_PRIVIATE_H__ +#define __XEN_HYPERV_PRIVIATE_H__ + +#include + +DECLARE_PER_CPU(void *, hv_input_page); + +#endif /* __XEN_HYPERV_PRIVIATE_H__ */ From patchwork Tue Feb 4 15:37:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11364889 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 30BD2139A for ; Tue, 4 Feb 2020 15:38:50 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0DDD820674 for ; Tue, 4 Feb 2020 15:38:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RZ3zEa41" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0DDD820674 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iz0Gy-0001if-TC; Tue, 04 Feb 2020 15:37:56 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iz0Gx-0001he-Aw for xen-devel@lists.xenproject.org; Tue, 04 Feb 2020 15:37:55 +0000 X-Inumbo-ID: 3ae0e224-4764-11ea-b211-bc764e2007e4 Received: from mail-wr1-x444.google.com (unknown [2a00:1450:4864:20::444]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 3ae0e224-4764-11ea-b211-bc764e2007e4; Tue, 04 Feb 2020 15:37:20 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id w15so23670428wru.4 for ; Tue, 04 Feb 2020 07:37:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=W+fIUGL54VDjFvlN5NvdUJjiDGrz9F9XnuiMBBpSm/k=; b=RZ3zEa41XOa7IKXYLw5JVHKyBQZfnhdWOu8y/1x9l1Ho0Uxw0AjkTIJqlvDyVcAUXX efkmhKzI3+nSyn6rHv4oRFQgzbKLrO2ATvi4TPHdCpLKakXq6+0dXV2JW7ZCpIA+91/3 9Z/aAUlCUeJqC2C+OCBDSO4CdxwH4wb/b5wYlURFOKOQsw3sO3hj/mx55CPLPIqGaXlr Q3ZFCBdj8PTDu1Ih0MC8+Y2NHEz8KBGc1nt/Ddl23IPkJDBtSVyGwVG6dsEQurCGc46h VjRUBQLri0UF+FumrRzA6PF/5AMqkDhjq3+QmlPTUwYZzpdo2AyP/9SjksKLE7OfDers dUiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=W+fIUGL54VDjFvlN5NvdUJjiDGrz9F9XnuiMBBpSm/k=; b=J8lZTq7KJ/E/04F8Xs+Mv8cxzdjR93YqbDnfJOnluV7k8r0yxVUAcREkJeQkjI9Ppl iH0E+xgdj12tvWj1PwDH8rZ/rm3FuBDFqjF7umxyvHeLTMGOgeoKztmBG5TTPSksBKgX nG+NYcHmb8eo/joe0KPB0cR9Ldi7yF7m9H0XPTxDzo/uCu5bucQSnfyX1fNd+quyzFMT jj/R2+BS6PUJw4F0a2GldUbnneywczneJegQePwjW8OHwkiZyw+GoYJOcsNaoyh4zXWO 4ltokDlDijMJSYHQKa0HCLDLtbAPmBWuAuPDP3UTotVGzBs3bsEchR2RC2yG6StMdEZY J50A== X-Gm-Message-State: APjAAAWFnq1A+feVtuhJkB80zriWH/GKKdbwDvFUzoj1WoVEsykHS4ef 6zlZ1LSlna3J6OLRZRKsDEorb+x2wXM= X-Google-Smtp-Source: APXvYqzuj6E+k6UwyKZ7Qo/sUUTOB+Zv00lWZCDCoZsPpt527rOtRj1rcPFhRCGqy7RIrfRxiYONvA== X-Received: by 2002:adf:e8c9:: with SMTP id k9mr23014221wrn.168.1580830639405; Tue, 04 Feb 2020 07:37:19 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id p26sm4067143wmc.24.2020.02.04.07.37.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 07:37:18 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Tue, 4 Feb 2020 15:37:03 +0000 Message-Id: <20200204153704.15934-10-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200204153704.15934-1-liuwe@microsoft.com> References: <20200204153704.15934-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v7 09/10] x86/hyperv: retrieve vp_index from Hyper-V X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Paul Durrant , Andrew Cooper , Paul Durrant , Michael Kelley , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This will be useful when invoking hypercall that targets specific vcpu(s). Signed-off-by: Wei Liu Reviewed-by: Paul Durrant Acked-by: Jan Beulich --- v5: 1. Add Jan's Ack. v4: 1. Use private.h 2. Add Paul's review tag v2: 1. Fold into setup_pcpu_arg function --- xen/arch/x86/guest/hyperv/hyperv.c | 6 ++++++ xen/arch/x86/guest/hyperv/private.h | 1 + 2 files changed, 7 insertions(+) diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index 6b58065c78..e31c4b30b8 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -31,6 +31,7 @@ struct ms_hyperv_info __read_mostly ms_hyperv; DEFINE_PER_CPU_READ_MOSTLY(void *, hv_input_page); +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, hv_vp_index); static uint64_t generate_guest_id(void) { @@ -135,6 +136,8 @@ static void __init setup_hypercall_page(void) static int setup_hypercall_pcpu_arg(void) { + uint64_t vp_index_msr; + if ( this_cpu(hv_input_page) ) return 0; @@ -146,6 +149,9 @@ static int setup_hypercall_pcpu_arg(void) return -ENOMEM; } + rdmsrl(HV_X64_MSR_VP_INDEX, vp_index_msr); + this_cpu(hv_vp_index) = vp_index_msr; + return 0; } diff --git a/xen/arch/x86/guest/hyperv/private.h b/xen/arch/x86/guest/hyperv/private.h index 093985a94b..d1765d4f23 100644 --- a/xen/arch/x86/guest/hyperv/private.h +++ b/xen/arch/x86/guest/hyperv/private.h @@ -25,5 +25,6 @@ #include DECLARE_PER_CPU(void *, hv_input_page); +DECLARE_PER_CPU(unsigned int, hv_vp_index); #endif /* __XEN_HYPERV_PRIVIATE_H__ */ From patchwork Tue Feb 4 15:37:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11364891 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0506A138D for ; Tue, 4 Feb 2020 15:38:55 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D5E4D2082E for ; Tue, 4 Feb 2020 15:38:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="W9n4dXVH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D5E4D2082E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iz0H4-0001mN-BB; Tue, 04 Feb 2020 15:38:02 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iz0H2-0001l1-B3 for xen-devel@lists.xenproject.org; Tue, 04 Feb 2020 15:38:00 +0000 X-Inumbo-ID: 3b6f9898-4764-11ea-b211-bc764e2007e4 Received: from mail-wr1-x444.google.com (unknown [2a00:1450:4864:20::444]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 3b6f9898-4764-11ea-b211-bc764e2007e4; Tue, 04 Feb 2020 15:37:21 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id y17so23643826wrh.5 for ; Tue, 04 Feb 2020 07:37:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ixwCG7/dZigNeiQzjDCIJqTFxi0+dHXprIOccPvDWlE=; b=W9n4dXVH3YhHhSFNQL7ay9oK4yb/l8DW3qCFgZWh8/LZ4SI1Em49MYLmkAXflaXf6p eLlYcGKHMElmRemTL2RGXusI7flXFfrp5VnE4xnoBdIpVybjR3WqfIzuDtviB+5DQXNz f4mkUdPIvwFmRF9LT3LLMolrIDKnuRZ+j13v4el9wiiabiV74XCT3hHFAilD6GqhAjPK PSVtB85f+9FQqflfbwTFEAJxKv0tZddxzr/SNMQD/9jQpTY5XeZ6JSk1umCeOXk7VT8n U4mr//9c6/trOH6trb+tqqAIfcK2fMh6gpaaorNejoYR9peen5GZPjX9/vgkfFSq9ScO W/6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=ixwCG7/dZigNeiQzjDCIJqTFxi0+dHXprIOccPvDWlE=; b=JtTkc7ehz3K1pkLiQodeFFSX+LFQn1rDUpr2St+Fo5DgmyCEAkRMN11gFpynb/Kc54 SK/RODFhPHYCl+M9+ih1LXIWTi7VSZf17fh4zCixhSmBV4DQBcKNzFFgGOpOPqFQaXlz 29ejBjYerg+CGLMzENkXh8VS6vXPWqng6iEEL7yQR+Az54BMol1ErzP14LGSXFOJE+6D KO2CwK65EU/rCD6pAUtJhNrn3kF0pLijM40Acn4e0aKFKmBKz6AyrjWIqR5dCVcsGMJE RAZKsCk1EMZpJItN4NEIlWEEFWEv44o8uwWfLSuEVkf0TcufxZxbMoRmK1fkIgFRi8Bb zklQ== X-Gm-Message-State: APjAAAWTd54nFj21NQXtbtgBEY/ajXWnROYW3fz+cVKcHFbFSFh8tYQz 3yD8fCl46rm8BW/kvJAVb1wcEQ8D14g= X-Google-Smtp-Source: APXvYqyiU6qRLPBWmWeyDX9Fop1YYuoqvKApCuYZBDwUm8hYOrjIIB9n2ASEN5V7azHy7AQqGI39zw== X-Received: by 2002:a05:6000:118e:: with SMTP id g14mr24264342wrx.39.1580830640287; Tue, 04 Feb 2020 07:37:20 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id p26sm4067143wmc.24.2020.02.04.07.37.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 07:37:19 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Tue, 4 Feb 2020 15:37:04 +0000 Message-Id: <20200204153704.15934-11-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200204153704.15934-1-liuwe@microsoft.com> References: <20200204153704.15934-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v7 10/10] x86/hyperv: setup VP assist page X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Andrew Cooper , Paul Durrant , Michael Kelley , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" VP assist page is rather important as we need to toggle some bits in it for efficient nested virtualisation. Signed-off-by: Wei Liu Reviewed-by: Paul Durrant Reviewed-by: Roger Pau Monné --- v6: 1. Use hv_vp_assist_page_msr 2. Make code shorter 3. Preserve rsvdP fields v5: 1. Deal with error properly instead of always panicking 2. Swap percpu variables declarations' location v4: 1. Use private.h 2. Prevent leak v3: 1. Use xenheap page 2. Drop set_vp_assist v2: 1. Use HV_HYP_PAGE_SHIFT instead --- xen/arch/x86/guest/hyperv/hyperv.c | 37 ++++++++++++++++++++++++++++- xen/arch/x86/guest/hyperv/private.h | 1 + 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index e31c4b30b8..248f854d6e 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -31,6 +31,7 @@ struct ms_hyperv_info __read_mostly ms_hyperv; DEFINE_PER_CPU_READ_MOSTLY(void *, hv_input_page); +DEFINE_PER_CPU_READ_MOSTLY(void *, hv_vp_assist); DEFINE_PER_CPU_READ_MOSTLY(unsigned int, hv_vp_index); static uint64_t generate_guest_id(void) @@ -155,6 +156,31 @@ static int setup_hypercall_pcpu_arg(void) return 0; } +static int setup_vp_assist(void) +{ + union hv_vp_assist_page_msr msr; + + if ( !this_cpu(hv_vp_assist) ) + { + this_cpu(hv_vp_assist) = alloc_xenheap_page(); + if ( !this_cpu(hv_vp_assist) ) + { + printk("CPU%u: Failed to allocate vp_assist page\n", + smp_processor_id()); + return -ENOMEM; + } + + clear_page(this_cpu(hv_vp_assist)); + } + + rdmsrl(HV_X64_MSR_VP_ASSIST_PAGE, msr.raw); + msr.pfn = virt_to_mfn(this_cpu(hv_vp_assist)); + msr.enabled = 1; + wrmsrl(HV_X64_MSR_VP_ASSIST_PAGE, msr.raw); + + return 0; +} + static void __init setup(void) { ASM_CONSTANT(HV_HCALL_PAGE, __fix_x_to_virt(FIX_X_HYPERV_HCALL)); @@ -163,11 +189,20 @@ static void __init setup(void) if ( setup_hypercall_pcpu_arg() ) panic("Hyper-V hypercall percpu arg setup failed\n"); + + if ( setup_vp_assist() ) + panic("VP assist page setup failed\n"); } static int ap_setup(void) { - return setup_hypercall_pcpu_arg(); + int rc; + + rc = setup_hypercall_pcpu_arg(); + if ( rc ) + return rc; + + return setup_vp_assist(); } static void __init e820_fixup(struct e820map *e820) diff --git a/xen/arch/x86/guest/hyperv/private.h b/xen/arch/x86/guest/hyperv/private.h index d1765d4f23..956eff831f 100644 --- a/xen/arch/x86/guest/hyperv/private.h +++ b/xen/arch/x86/guest/hyperv/private.h @@ -25,6 +25,7 @@ #include DECLARE_PER_CPU(void *, hv_input_page); +DECLARE_PER_CPU(void *, hv_vp_assist); DECLARE_PER_CPU(unsigned int, hv_vp_index); #endif /* __XEN_HYPERV_PRIVIATE_H__ */