From nobody Sat May 4 23:15:39 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1580493020897447.16993898622184; Fri, 31 Jan 2020 09:50:20 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ixaQH-0005qy-HT; Fri, 31 Jan 2020 17:49: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 1ixaQG-0005qs-J9 for xen-devel@lists.xenproject.org; Fri, 31 Jan 2020 17:49:40 +0000 Received: from mail-wm1-x341.google.com (unknown [2a00:1450:4864:20::341]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 0ca14fc6-4452-11ea-8396-bc764e2007e4; Fri, 31 Jan 2020 17:49:38 +0000 (UTC) Received: by mail-wm1-x341.google.com with SMTP id g1so8887480wmh.4 for ; Fri, 31 Jan 2020 09:49:38 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id 133sm4364352wmd.5.2020.01.31.09.49.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 09:49:34 -0800 (PST) X-Inumbo-ID: 0ca14fc6-4452-11ea-8396-bc764e2007e4 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=Egz3txqQqthBIsSjMFQvj77WUNoiga8Y7f7moMDL01Y=; b=k7BWOimru4Z0jLixjjuChh/KfxXDiHXFwlyGTZCdeeMM/cY7aO3HuZKJDWxehvy/6f mT6JY2/f3/RHYrE26+lssizf58LUauU1CJwXjV7KhCLKsQCCfp62jwgiHAebM5buGeK7 jdLsosIg0fuKO8vJrViGYT+7Y0OK5XnWuNlpSnD4LWZ7C+VNM3/+rpqeAIu/anfdYHwy /jE0tzIeCBzHz1baudJdnyqvaYtOMBjpfo/ijVwYJA6oR1YyLLqh5MzhJj2bcv4s3Vjs O5W5krRLBgue/SwwLAkOe/DVHOPRzXn7XdN6MfoRo1yiSSE2kP4V+r0tS+pr7Aexi4UU A5yg== 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=Egz3txqQqthBIsSjMFQvj77WUNoiga8Y7f7moMDL01Y=; b=YU3Bg/ksqmISiZAm5Z5dC13Xca60lf4vNqoIOmWhSi+7ZBEt6evbrrCbYx0dGdwAdD tysid0eo8+jpGXqv4b6LaiWDvEJcF1RQa5BjNpek/twlla6lPwwK3AdE01tXdWridQNo dMMmuTp8NIUNuXmHVmt+zRDy5/RWhN7KK9kNu5YNImaGbb3qyBq6nxqqcVVFrUFXW3CX AprhKSkDmOG0Ze4TfqYeOe4PyNgnnQ/Yq/DrLl4xQWGcIew8LFjLxWNbb9T/umBrDXcb xSlnmlB8FaZKy1hiESHFpVu7Hdj3DoCPTZ8SY/VAyLYxVhi9PmLp2ovB4UBFUIxaUfu/ R2AQ== X-Gm-Message-State: APjAAAWMAUE1u30edrJ7WEsDyDE33Xx8nant7cSmKfl5+32esNwbYPEw /rmwPj3o/+zAtfG7vKgv98HeRtHyRmE= X-Google-Smtp-Source: APXvYqxRfBxG1yOxDUs3O2IOTU1WaablLfIjYKWavDKt/1y04+C0B3L4gvoN/as1Yh6/4ZwutiJyWg== X-Received: by 2002:a1c:1b42:: with SMTP id b63mr13481018wmb.16.1580492974801; Fri, 31 Jan 2020 09:49:34 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Fri, 31 Jan 2020 17:49:20 +0000 Message-Id: <20200131174930.31045-2-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200131174930.31045-1-liuwe@microsoft.com> References: <20200131174930.31045-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v6 01/11] 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 , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) We want to be able to handle AP setup error in the upper layer. Signed-off-by: Wei Liu --- 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 | 24 +++++++++++++++--------- xen/include/asm-x86/guest/hypervisor.h | 6 +++--- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hyperviso= r.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(); } =20 -void hypervisor_ap_setup(void) +int hypervisor_ap_setup(void) { if ( ops && ops->ap_setup ) - ops->ap_setup(); + return ops->ap_setup(); + + return 0; } =20 void hypervisor_resume(void) diff --git a/xen/arch/x86/guest/xen/xen.c b/xen/arch/x86/guest/xen/xen.c index 6dbc5f953f..d50f86bae7 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 =3D virt_to_mfn(&vcpu_info[vcpu]); info.offset =3D (unsigned long)&vcpu_info[vcpu] & ~PAGE_MASK; rc =3D xen_hypercall_vcpu_op(VCPUOP_register_vcpu_info, vcpu, &info); - if ( rc ) - { - BUG_ON(vcpu >=3D XEN_LEGACY_MAX_VCPUS); - this_cpu(vcpu_info) =3D &XEN_shared_info->vcpu_info[vcpu]; - } - else + if ( !rc ) { this_cpu(vcpu_info) =3D &vcpu_info[vcpu]; set_bit(vcpu, vcpu_info_mapped); } + else if ( vcpu < XEN_LEGACY_MAX_VCPUS ) + { + rc =3D 0; + this_cpu(vcpu_info) =3D &XEN_shared_info->vcpu_info[vcpu]; + } =20 return rc; } @@ -257,11 +257,17 @@ static void __init setup(void) init_evtchn(); } =20 -static void ap_setup(void) +static int ap_setup(void) { + int rc; + set_vcpu_id(); - map_vcpuinfo(); - init_evtchn(); + rc =3D map_vcpuinfo(); + + if ( !rc ) + init_evtchn(); + + return rc; } =20 int xg_alloc_unused_page(mfn_t *mfn) diff --git a/xen/include/asm-x86/guest/hypervisor.h b/xen/include/asm-x86/g= uest/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 { =20 const char *hypervisor_probe(void); void hypervisor_setup(void); -void hypervisor_ap_setup(void); +int hypervisor_ap_setup(void); void hypervisor_resume(void); =20 #else @@ -44,7 +44,7 @@ void hypervisor_resume(void); =20 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(); } =20 #endif /* CONFIG_GUEST */ --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Sat May 4 23:15:39 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1580493018528801.9052197699039; Fri, 31 Jan 2020 09:50:18 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ixaQM-0005s4-Su; Fri, 31 Jan 2020 17:49:46 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ixaQL-0005rn-IG for xen-devel@lists.xenproject.org; Fri, 31 Jan 2020 17:49:45 +0000 Received: from mail-wm1-x343.google.com (unknown [2a00:1450:4864:20::343]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 0d301422-4452-11ea-ad98-bc764e2007e4; Fri, 31 Jan 2020 17:49:39 +0000 (UTC) Received: by mail-wm1-x343.google.com with SMTP id a5so8892727wmb.0 for ; Fri, 31 Jan 2020 09:49:39 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id 133sm4364352wmd.5.2020.01.31.09.49.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 09:49:37 -0800 (PST) X-Inumbo-ID: 0d301422-4452-11ea-ad98-bc764e2007e4 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=ukFC00hv0LSjsqkLHJaQ2pzoEWeQaG6eI/AMe7Aox9U=; b=qY7rrW0y+KtfcnTPkFKPLQUp356gelkjDS2iQfTBVrNBzxXmXJOAsgaZa9ZiBpUfib mqiDb/OLZzLUoblYXbPe8SL8RsiwvSpQdOTiUKeB0Oh+ZlwV7hjuFb/Igmg60cJRvyxr pZv2mYe5VvUs4mytYNVHTSj+X7nwdKw5s1hjR1dWf5s8dpQQ67PJLgkngK/9Cv92Gzro 7wrkWkK+Gdi7FnzyzWYxk0t8/5xLLIceW5uAMQQ9G0CgZfQMI+mFGmRQmkzocHOIOw+p /Qa24Mu88IS1B3ixgdO3saRR1+9tOonPrz7XTJcxl3zaPD1xvlgXW27rI/MfX1Hfenzk P4gQ== 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=ukFC00hv0LSjsqkLHJaQ2pzoEWeQaG6eI/AMe7Aox9U=; b=kBiKH8X2qNJlOs8M2yGfUlPAyyRfdir+ezyQV8+NRf8B1B7J4yYOp8a1GYe9o9mQmG 8VcaTymFdRU46Pn/qAzbzCv/c+OTX4YqtDPOX4WlKfoiBT1M0wsfQg59i8eotnlM3ND2 ijbfBeZNvrHzKHMmrSC5PBh8o4u/gggMPwCri5KeXEQSP38m2cw82Q+4yk5RppvVT+mA QZBxM/uLa/KKLf7sdcKrjP7RuyA1mw3RKG3b2oeEyvxcr6ew0sYYvPhY6NBNsUiQDAD9 P2g02cmATTFhr4W9dkfpgE+8jImwEfAp6ss+KZB5Jfs1tjYsxlpVex3DVrlKd7tcmMEw f3ug== X-Gm-Message-State: APjAAAVB4ADlN3GqAWvckORTFvoP66baqb56pFdFte5QGtTaGiTCkJye ymtJBf+hWijyp82tQ91MJRzGNQ0zhJY= X-Google-Smtp-Source: APXvYqwuyZmsavJInbCXnvE8ycz7lQmctHDLiPtR/S/g4V0xekdfLUqCPu3n8w8cvXI8duzu5MjVOw== X-Received: by 2002:a05:600c:20c6:: with SMTP id y6mr13273447wmm.95.1580492978224; Fri, 31 Jan 2020 09:49:38 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Fri, 31 Jan 2020 17:49:21 +0000 Message-Id: <20200131174930.31045-3-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200131174930.31045-1-liuwe@microsoft.com> References: <20200131174930.31045-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v6 02/11] 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 , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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=C3=A9 Reviewed-by: Jan Beulich --- xen/arch/x86/smpboot.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 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; } =20 + if ( cpu_has_hypervisor && (rc =3D hypervisor_ap_setup()) !=3D 0 ) + { + printk("CPU%d: Failed to initialise hypervisor functions. Not comi= ng online.\n", cpu); + cpu_error =3D rc; + goto halt; + } + if ( (rc =3D hvm_cpu_up()) !=3D 0 ) { printk("CPU%d: Failed to initialise HVM. Not coming online.\n", cp= u); @@ -371,9 +378,6 @@ void start_secondary(void *unused) =20 tsx_init(); /* Needs microcode. May change HLE/RTM feature bits. */ =20 - if ( xen_guest ) - hypervisor_ap_setup(); - smp_callin(); =20 set_cpu_sibling_map(cpu); --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Sat May 4 23:15:39 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1580493022017940.4158507097638; Fri, 31 Jan 2020 09:50:22 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ixaQR-0005t9-9b; Fri, 31 Jan 2020 17:49: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 1ixaQQ-0005t1-Ib for xen-devel@lists.xenproject.org; Fri, 31 Jan 2020 17:49:50 +0000 Received: from mail-wm1-x341.google.com (unknown [2a00:1450:4864:20::341]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 0dd4305c-4452-11ea-a933-bc764e2007e4; Fri, 31 Jan 2020 17:49:40 +0000 (UTC) Received: by mail-wm1-x341.google.com with SMTP id g1so8887571wmh.4 for ; Fri, 31 Jan 2020 09:49:40 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id 133sm4364352wmd.5.2020.01.31.09.49.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 09:49:38 -0800 (PST) X-Inumbo-ID: 0dd4305c-4452-11ea-a933-bc764e2007e4 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=qjVeiSnb0MJod71jgCMzNRSvX/LkPYHFUUnAv8FFvkg=; b=jFUsoUihAsd2Kl/jaoLdHtSVnctmPUOrZ3xJLIAGmcyarZgOVTenFSWiFwK3Btb7/S wpXAWwva2RrgrQtGTTMSrcWwDe09QtPXDahhnWsUQl2ydBD1ubqV7BsWGFWgwuj7iVxP BFc5aZskh8/hL5K//mAoCjCEFPjDNESnyISVh9groAKz2yX1zKkYmUSK/23RsbTYZTGL eFfaezM+uo1eJcYyEOJ+BhI9KwkBu7lm9uJ0CRmonwCrHg+bItLEQGKjK+SfA/vjIrKg dNt2Jp4+GqZMvkRMTl454Xb0iuKC23d0BHdJU3LnCgyjdXl2K1k3fqbowmXOV5xJMF/8 7sOQ== 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=qjVeiSnb0MJod71jgCMzNRSvX/LkPYHFUUnAv8FFvkg=; b=q65C3cvriRQYi9dT982wPabdMFASeLtJqn2tSV7gwUSRxRgvwr3QGQxMM+dM3dVFH5 9imcB+vTstJw6WU6XjdZPp/taQfle/6IzlGxMmYLLjz/jqkBpSjJq8mgpXp/mogOiAoy tJcKJp9tYM2RaOa7zVOKkWo3Ee+vowsDEnbsprfp8ufqscsU9olT90XitE6tJm6QB/T+ 7rrFVrhvmYOHTSsVVIqwFHGhuX4V8QcJ9n0juGWymbb8odiqea/r44GQ8VLaFt5IpFdk uiM1cd1gwW1F4X3/hLzB1NMfl7838atvV4dD8BTnf6ptIzqhzrV8cZDyOofuhu/lngYU jnLw== X-Gm-Message-State: APjAAAVDJRD8kXM68vgclpNFWYkCa1jYxWs8268rhEMiuBtmDvm5FIbQ DgPeC5yiNFDy/XoeJCmseFHGpKl93oE= X-Google-Smtp-Source: APXvYqwh7Nn3SPlNvYxIh6vuxQEsrazPpbo6rbJcbLwnCHfRA22u/ITZouZMXFbtqMFhmALT+y/UyA== X-Received: by 2002:a7b:c8d3:: with SMTP id f19mr12951750wml.26.1580492979229; Fri, 31 Jan 2020 09:49:39 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Fri, 31 Jan 2020 17:49:22 +0000 Message-Id: <20200131174930.31045-4-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200131174930.31045-1-liuwe@microsoft.com> References: <20200131174930.31045-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v6 03/11] 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 , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 --- 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 | 15 ++++++++++++++- xen/arch/x86/smpboot.c | 2 +- xen/arch/x86/xen.lds.S | 3 +++ xen/include/asm-x86/config.h | 2 +- xen/include/asm-x86/fixmap.h | 24 ++++++++++++++++++++++++ 7 files changed, 57 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 =20 /* - * 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 =3D 0 + .rept L2_PAGETABLE_ENTRIES + .if idx =3D=3D l2_table_offset(FIXADDR_X_TOP - 1) + .quad sym_offs(l1_fixmap_x) + __PAGE_HYPERVISOR + .else + .quad 0 + .endif + idx =3D idx + 1 + .endr .size l2_xenmap, . - l2_xenmap =20 /* 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 =20 +#include #include #include =20 @@ -311,7 +312,7 @@ void __init arch_livepatch_init(void) void *start, *end; =20 start =3D (void *)xen_virt_end; - end =3D (void *)(XEN_VIRT_END - NR_CPUS * PAGE_SIZE); + end =3D (void *)(XEN_VIRT_END - FIXADDR_X_SIZE - NR_CPUS * PAGE_SIZE); =20 BUG_ON(end <=3D start); =20 diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index f50c065af3..6b1361845c 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -157,6 +157,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]; =20 paddr_t __read_mostly mem_hotplug; =20 @@ -372,6 +374,10 @@ void __init arch_init_memory(void) } } #endif + + /* Generate a symbol to be used in linker script */ + asm ( ".equ FIXADDR_X_SIZE, %P0; .global FIXADDR_X_SIZE" + :: "i" (FIXADDR_X_SIZE) ); } =20 int page_is_ram_type(unsigned long mfn, unsigned long mem_type) @@ -5718,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 >=3D __end_of_fixed_addresses); + BUG_ON(idx >=3D __end_of_fixed_addresses || idx <=3D FIX_RESERVED); map_pages_to_xen(__fix_to_virt(idx), _mfn(mfn), 1, flags); } =20 +void __set_fixmap_x( + enum fixed_addresses_x idx, unsigned long mfn, unsigned long flags) +{ + BUG_ON(idx >=3D __end_of_fixed_addresses_x || idx <=3D 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, unsigne= d long *mfn) unmap_domain_page(memset(__map_domain_page(pg), 0xcc, PAGE_SIZE)); } =20 - stub_va =3D XEN_VIRT_END - (cpu + 1) * PAGE_SIZE; + stub_va =3D 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..de0856b88e 100644 --- a/xen/arch/x86/xen.lds.S +++ b/xen/arch/x86/xen.lds.S @@ -2,6 +2,8 @@ /* Modified for i386/x86-64 Xen by Keir Fraser */ =20 #include + +#include #include #undef ENTRY #undef ALIGN @@ -352,6 +354,7 @@ SECTIONS } =20 ASSERT(__2M_rwdata_end <=3D XEN_VIRT_END - XEN_VIRT_START + __XEN_VIRT_STA= RT - + FIXADDR_X_SIZE - NR_CPUS * PAGE_SIZE, "Xen image overlaps stubs area") =20 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 fixm= ap (1GB). */ #define XEN_VIRT_START (HIRO_COMPAT_MPT_VIRT_END) #define XEN_VIRT_END (XEN_VIRT_START + GB(1)) =20 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 =20 #define FIXADDR_TOP (VMAP_VIRT_END - PAGE_SIZE) +#define FIXADDR_X_TOP (XEN_VIRT_END - PAGE_SIZE) =20 #ifndef __ASSEMBLY__ =20 @@ -89,6 +90,29 @@ static inline unsigned long virt_to_fix(const unsigned l= ong vaddr) return __virt_to_fix(vaddr); } =20 +enum fixed_addresses_x { + /* Index 0 is reserved since fix_x_to_virt(0) =3D=3D 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__ */ =20 #endif --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Sat May 4 23:15:39 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1580493025657327.9492426141244; Fri, 31 Jan 2020 09:50:25 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ixaQW-0005v2-Kp; Fri, 31 Jan 2020 17:49: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 1ixaQV-0005ua-Is for xen-devel@lists.xenproject.org; Fri, 31 Jan 2020 17:49:55 +0000 Received: from mail-wr1-x443.google.com (unknown [2a00:1450:4864:20::443]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 0e60f60e-4452-11ea-ad98-bc764e2007e4; Fri, 31 Jan 2020 17:49:41 +0000 (UTC) Received: by mail-wr1-x443.google.com with SMTP id z7so9595729wrl.13 for ; Fri, 31 Jan 2020 09:49:41 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id 133sm4364352wmd.5.2020.01.31.09.49.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 09:49:39 -0800 (PST) X-Inumbo-ID: 0e60f60e-4452-11ea-ad98-bc764e2007e4 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=cpuxdCZxCl63G/9gtJCixou5RUbbkJaTIj6MRYrokwk=; b=TxglAh6bFIrgJs/vD17L60YOOcjmIcgkebD8f8vhNKLEcjahLQzUElfVnOhPmLDTXK iTCrdFsu9ojznKuhIcFGb6aQyS+CW0cYDADdgx5oC7XfLfv+CmwPPcBufxWBzx1MmYOQ yAShKBdAMdX3Oag19nhxxtR2F7bJp66DxNa+2TvOxSqZswkpR88iilHyGTiKRWgarqv0 U5iQ3yVsYerMSutKmH81Zz8szBs2bQCRrzLah7ra/RDhrspZ32HfCyAb68aMxLC1CxkA f3Z60V9i6rr5M09lxz20dA8Rx9fpfuVqdu6nhx2QXB6fkOpSYNKj5+4kBsCbixUuhsYw OCpA== 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=cpuxdCZxCl63G/9gtJCixou5RUbbkJaTIj6MRYrokwk=; b=o+SZoMz+dX9f3Jj3EJZz8uu/hHheCBjMKYVFY5yumKMdxslinEXhCqkMMZ5ibULf1g vurr9PhV033WiDQ/+DVh/jU4prrbm9UUnOD2n4+CepAuzXBK20ZLbNvbLTnRA9d4NZw5 KackGM75CnduB1+5+NCsOWgfKVUYmUxNN1OzBo0soZy0H9wHnf4+j7aFt14R4/PDbaGD 71DGABuWUxz3lPnK8F8e8MpSjfcOn0PxPdxyqz4SOeb9FNZHGc/n1vm6NNBTVU5HzwZc /GOz5ZHYObFXG/CeLCg49LbnXkyT487A/am8LPy42TYh25djJ7bTMf8mwetZI3ts6yku m+kA== X-Gm-Message-State: APjAAAWe9Vde4GqDWGtHv9j9NI6hM4VjDIZ1A0juORpoBMiXcNO5XGd+ 7WouVAxLGQfvTgZbQko4tt4uxOOclcQ= X-Google-Smtp-Source: APXvYqzqLv/ITSSG8633ZAzMoen7M10g76yIC+L7oZ/pr4pSsebfKcMw43nrvYP26Vnxk2qVoA7crg== X-Received: by 2002:a5d:61d1:: with SMTP id q17mr7373278wrv.156.1580492980199; Fri, 31 Jan 2020 09:49:40 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Fri, 31 Jan 2020 17:49:23 +0000 Message-Id: <20200131174930.31045-5-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200131174930.31045-1-liuwe@microsoft.com> References: <20200131174930.31045-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v6 04/11] 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 , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) And implement the hook for Xen guest. Signed-off-by: Wei Liu Reviewed-by: Jan Beulich --- 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 3892c9cfb7..2219c63861 100644 --- a/xen/arch/x86/e820.c +++ b/xen/arch/x86/e820.c @@ -690,8 +690,8 @@ unsigned long __init init_e820(const char *str, struct = e820map *raw) =20 machine_specific_memory_setup(raw); =20 - if ( pv_shim ) - pv_shim_fixup_e820(&e820); + if ( cpu_has_hypervisor ) + hypervisor_e820_fixup(&e820); =20 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/hyperviso= r.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(); } =20 +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 d50f86bae7..45e54dfbba 100644 --- a/xen/arch/x86/guest/xen/xen.c +++ b/xen/arch/x86/guest/xen/xen.c @@ -316,11 +316,18 @@ static void resume(void) pv_console_init(); } =20 +static void __init e820_fixup(struct e820map *e820) +{ + if ( pv_shim ) + pv_shim_fixup_e820(e820); +} + static const struct hypervisor_ops ops =3D { .name =3D "Xen", .setup =3D setup, .ap_setup =3D ap_setup, .resume =3D resume, + .e820_fixup =3D e820_fixup, }; =20 const struct hypervisor_ops *__init xg_probe(void) diff --git a/xen/include/asm-x86/guest/hypervisor.h b/xen/include/asm-x86/g= uest/hypervisor.h index b503854c5b..b66cb28333 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__ =20 +#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); }; =20 #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); =20 #else =20 @@ -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) { ASSERT_UNREACHABLE(); return= 0; } static inline void hypervisor_resume(void) { ASSERT_UNREACHABLE(); } +static inline void hypervisor_e820_fixup(struct e820map *e820) { ASSERT_UN= REACHABLE(); } =20 #endif /* CONFIG_GUEST */ =20 --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Sat May 4 23:15:39 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1580493033727202.76071187243735; Fri, 31 Jan 2020 09:50:33 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ixaQc-000640-7e; Fri, 31 Jan 2020 17:50: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 1ixaQa-0005yg-JA for xen-devel@lists.xenproject.org; Fri, 31 Jan 2020 17:50:00 +0000 Received: from mail-wr1-x441.google.com (unknown [2a00:1450:4864:20::441]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 0ef49c10-4452-11ea-ad98-bc764e2007e4; Fri, 31 Jan 2020 17:49:42 +0000 (UTC) Received: by mail-wr1-x441.google.com with SMTP id y11so9664966wrt.6 for ; Fri, 31 Jan 2020 09:49:42 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id 133sm4364352wmd.5.2020.01.31.09.49.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 09:49:40 -0800 (PST) X-Inumbo-ID: 0ef49c10-4452-11ea-ad98-bc764e2007e4 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=rffWGupMx/0ss2WkO2hKOAHYYbHAdj5XTaScjilRkJo=; b=Re3AWwiAYDMHkhWreBGqdd2p8pQI6wvZKfsi/j3j4Dngm/Ld0aPvbr1/XbFEFJdU7H xxrD3ihqxY1PcxavR+lR/IUR9TlNINeAZT60jL/4KmN6QPunSvJjPbd9jkqv50dC8W4m Bn0y5L882CvLI54t/GXmk9YHfqv2f2ejeKsa8rKoNlt2G+MQUzII02hZosX4Yrv8n1eY qokl4f2ANzaVqb05GHj6ilj9h4agPYL/8+fCNDiUUYOe7zWWMc7cJ4q7zsXwBFvaxuTU NgLGXS9+rYqJhESXFeQiuK5zt8GNHGmoiLTIYDvg8nOjoOWIiUwyiRukR3ZsmPl5J2kh 6tFQ== 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=rffWGupMx/0ss2WkO2hKOAHYYbHAdj5XTaScjilRkJo=; b=K0xuDazG++TKaiX4gt7L/MwDDgwSM9Zmq2zaaogF1FqJq3j6ZA401nU1YLfQFRjckN Nvgtr9eifeq4liDfA4pBIzK9dne2ESP+swxYu6ezSGCZrItMtDoS6qxdnDjuGJ6a8QWa P8w7oaNVZIipTvfJ3DYh+QUTJ8cZWP1xuDxtZxpcW2zGdnPMRH/59dCXW1y8P8PnyBnL 3XCexLOQQtE8Q9jZzuKqkx5k93g2VZOs0Ooot1EsnGgDvHsz7FS6j0lQvUYbDh+KIiw4 EiGASMyZSGce1WvAPzvfr560OoMEKmltQSeimsFlA8KGffEVx72lbinTLQSKZe1ZNUTe brjg== X-Gm-Message-State: APjAAAXS1/Dr4qb1DbI6WCnj1+DeFHtE8dA8d20RcY8bXHpMqIE+BWWm Yb8AvcVKa5T7I+HCMD65BF14n48bqfg= X-Google-Smtp-Source: APXvYqxHMUW0mba/78Ye5t1QsiVHR3G4FDLX3+2C1XePNLGkYvqQG04xIx2jcdb5e34NMoCAaYQsMw== X-Received: by 2002:a5d:5283:: with SMTP id c3mr13719944wrv.148.1580492981122; Fri, 31 Jan 2020 09:49:41 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Fri, 31 Jan 2020 17:49:24 +0000 Message-Id: <20200131174930.31045-6-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200131174930.31045-1-liuwe@microsoft.com> References: <20200131174930.31045-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v6 05/11] 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 , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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. 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 --- 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..7c2a96d70e 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 =20 +#include #include #include +#include =20 struct ms_hyperv_info __read_mostly ms_hyperv; =20 -static const struct hypervisor_ops ops =3D { - .name =3D "Hyper-V", -}; +static uint64_t generate_guest_id(void) +{ + union hv_guest_os_id id; + + id.vendor =3D HV_XEN_VENDOR_ID; + id.major =3D xen_major_version(); + id.minor =3D xen_minor_version(); + + return id.raw; +} + +static const struct hypervisor_ops ops; =20 const struct hypervisor_ops *__init hyperv_probe(void) { @@ -72,6 +84,57 @@ const struct hypervisor_ops *__init hyperv_probe(void) return &ops; } =20 +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 !=3D PAGE_SHIFT); + + rdmsrl(HV_X64_MSR_GUEST_OS_ID, guest_id.raw); + if ( !guest_id.raw ) + { + guest_id.raw =3D 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 =3D HV_HCALL_MFN; + hypercall_msr.enable =3D 1; + hypercall_msr.guest_physical_address =3D mfn; + wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); + } else { + mfn =3D 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 =3D 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 =3D { + .name =3D "Hyper-V", + .setup =3D setup, + .e820_fixup =3D 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 05c4044976..07db57b55f 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 * * */ =20 #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 @@ =20 #include =20 +/* 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: --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Sat May 4 23:15:39 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1580493033916190.87758402533314; Fri, 31 Jan 2020 09:50:33 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ixaQg-0006Nx-IZ; Fri, 31 Jan 2020 17:50:06 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ixaQf-0006FO-J7 for xen-devel@lists.xenproject.org; Fri, 31 Jan 2020 17:50:05 +0000 Received: from mail-wr1-x441.google.com (unknown [2a00:1450:4864:20::441]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 0f9cf748-4452-11ea-8396-bc764e2007e4; Fri, 31 Jan 2020 17:49:43 +0000 (UTC) Received: by mail-wr1-x441.google.com with SMTP id z3so9704548wru.3 for ; Fri, 31 Jan 2020 09:49:43 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id 133sm4364352wmd.5.2020.01.31.09.49.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 09:49:41 -0800 (PST) X-Inumbo-ID: 0f9cf748-4452-11ea-8396-bc764e2007e4 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=nzNsiiSOGi+mqFAW4l8/O1Lj/8HbpRuY83zzu3RwubU=; b=DDUv6XpXxu3UfM4Yl/k6vw1eYU6CGHODdrlROZgYKx3r8FPahQTL2cXOPO8jPo4wwX giAgbCz+0ld5CPJx+8J3idMBGi+t+m92geA85GQ0Yu9SQEfHd5m+poQZO3ltriIvH8j7 PzhBBj3/sswQYWqBAtEefCDWmoJKSpbCGAOWoPWIrNJEH3yoX8RgAnf7YCTQX7wKeuMB BMzbeGW/aN07B6Q4VWHxk/ZSrIY5pzIUu5s6zgioc+Yw3UaYfYjXBDIzan97vys71q7f oimSq21yWQ4p2lCy/aznIP0QLOjQo9+fZ8UP10nkOz4dC4J9li+bh9RpK8uSZJ6ASUia Pm+w== 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=nzNsiiSOGi+mqFAW4l8/O1Lj/8HbpRuY83zzu3RwubU=; b=G97+Pws0G1xKEzFOOYDlgcmlWIExFsjCRWvyaFqYBl9fx6LtL4ObM4lZ33jpr/F5i0 nOex17pAarFGcbRVVpuCha2qHZr5sINzVblFXkCxWW2LPcf7m6Z8tg48C0zYvWQm2m9S apq/ndBrY+um6TwL/lKZTTdAEceHURyk5rLyCrms7sXEkQUmgNkD7DBhyOwYib1IQDfn 0VwktisLQte51BXZqXMRPE9Yn/zEialI2ANqudquu6TvBOTZGGJtKs/DiCw1fPAhy1TQ +X2NX0LUkY46ec5xSt2mVT5xibpuZeaZHewnDfLqH3HV0Af7yZ1sgWDOpjaJdLwPeDY7 +uow== X-Gm-Message-State: APjAAAXNfvh79KnG3QHE+fW0GU39ZIB3iLnQaegcTfrlnz3TVO9L3tmy +tmTBVIzTMbqLWRhS0CdpOvrxmVrNcM= X-Google-Smtp-Source: APXvYqz+HcLclbwJ4gmCbsEbXDLBrhg9hJwWpQV3K0BKiR2w/tUBAPQuFxCH0XBoRIW4aO/pyjy8fw== X-Received: by 2002:a5d:6a42:: with SMTP id t2mr9199956wrw.83.1580492982298; Fri, 31 Jan 2020 09:49:42 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Fri, 31 Jan 2020 17:49:25 +0000 Message-Id: <20200131174930.31045-7-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200131174930.31045-1-liuwe@microsoft.com> References: <20200131174930.31045-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v6 06/11] 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 , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) These functions will be used later to make hypercalls to Hyper-V. Signed-off-by: Wei Liu Reviewed-by: Paul Durrant --- 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/mm.c | 4 +- xen/arch/x86/xen.lds.S | 4 + xen/include/asm-x86/guest/hyperv-hcall.h | 97 ++++++++++++++++++++++++ 4 files changed, 105 insertions(+), 1 deletion(-) 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 =20 diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 6b1361845c..e7787c8fde 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -375,9 +375,11 @@ void __init arch_init_memory(void) } #endif =20 - /* Generate a symbol to be used in linker script */ + /* Generate symbols to be used in linker script */ asm ( ".equ FIXADDR_X_SIZE, %P0; .global FIXADDR_X_SIZE" :: "i" (FIXADDR_X_SIZE) ); + asm ( ".equ HV_HCALL_PAGE, %P0; .global HV_HCALL_PAGE" + :: "i" (__fix_x_to_virt(FIX_X_HYPERV_HCALL)) ); } =20 int page_is_ram_type(unsigned long mfn, unsigned long mem_type) diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S index de0856b88e..ec8ab2bec6 100644 --- a/xen/arch/x86/xen.lds.S +++ b/xen/arch/x86/xen.lds.S @@ -328,6 +328,10 @@ SECTIONS efi =3D .; #endif =20 +#ifdef CONFIG_HYPERV_GUEST + hv_hcall_page =3D 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_add= r, + paddr_t output_addr) +{ + uint64_t status; + register unsigned long r8 asm ( "r8" ) =3D output_addr; + + /* See TLFS for volatile registers */ + asm volatile ( "call hv_hcall_page" + : "=3Da" (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 inpu= t2) +{ + uint64_t status; + uint64_t control =3D code | HV_HYPERCALL_FAST_BIT; + register unsigned long r8 asm ( "r8" ) =3D input2; + + /* See TLFS for volatile registers */ + asm volatile ( "call hv_hcall_page" + : "=3Da" (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_cou= nt, + uint16_t varhead_size, + paddr_t input, paddr_t output) +{ + uint64_t control =3D code; + uint64_t status; + uint16_t rep_comp; + + control |=3D (uint64_t)varhead_size << HV_HYPERCALL_VARHEAD_OFFSET; + control |=3D (uint64_t)rep_count << HV_HYPERCALL_REP_COMP_OFFSET; + + do { + status =3D hv_do_hypercall(control, input, output); + if ( (status & HV_HYPERCALL_RESULT_MASK) !=3D HV_STATUS_SUCCESS ) + break; + + rep_comp =3D MASK_EXTR(status, HV_HYPERCALL_REP_COMP_MASK); + + control &=3D ~HV_HYPERCALL_REP_START_MASK; + control |=3D 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: + */ --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Sat May 4 23:15:39 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1580493038948244.33150417049023; Fri, 31 Jan 2020 09:50:38 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ixaQm-0006eQ-0u; Fri, 31 Jan 2020 17:50:12 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ixaQk-0006dl-IU for xen-devel@lists.xenproject.org; Fri, 31 Jan 2020 17:50:10 +0000 Received: from mail-wm1-x343.google.com (unknown [2a00:1450:4864:20::343]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1020cb22-4452-11ea-ad98-bc764e2007e4; Fri, 31 Jan 2020 17:49:44 +0000 (UTC) Received: by mail-wm1-x343.google.com with SMTP id m10so9333793wmc.0 for ; Fri, 31 Jan 2020 09:49:44 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id 133sm4364352wmd.5.2020.01.31.09.49.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 09:49:42 -0800 (PST) X-Inumbo-ID: 1020cb22-4452-11ea-ad98-bc764e2007e4 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=hM+7wdfsP27XGM9zHGwtCWANDp7Dbi20PNshZg97aIU=; b=r2oD2trUuSgbnkg7qk4IJlNrxpS81WnqL0azadH/eEfIsmL+7hkva3aD7uYiLjZs5D ceZr6pv7g07JNibFKF3lSxe3D/6bWdFaKTpQgZ7qqvc5RYk+T6ZhIluBJqRJOatVGLim VKBTeMFor1RWl6S1W0cHnMdqby4xWAU0r2aNRqXxvlQJ8oEFrID61KHiuGiGRxD/bRN6 wFW/7KjtOvJHhgAvrVP8o/UOoRdGhwb7mYjQfw6TMAsugWIF//Gp71HxrH56bfgQi0uM 4MPGBQW5TtMdIdT64zGhJ5kQAJ/wzV0bqg5KdULjvkyTdz5+NOVlg4DX6Sxs7ZqTXbC8 9G5A== 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=hM+7wdfsP27XGM9zHGwtCWANDp7Dbi20PNshZg97aIU=; b=TuieQ3n3Vw9NvZPjOk5MSLYEIb45+J4Snt+Pwx9/2r/PkTkxb35m8rgVs1ojPFqjKK kHcwRmWclp9d8aI4MS66/8yrGu77TFzpSG96r19ceGGgAuCtsFssGvtsZkwJaL5GdtPL F9Y2Gf211yQetClsCnOg4YeynPvbmLdw6AseCaMqliQs2cv+yasnUtVkfg+IR+qnETuT n45+dOBA1nhQ9YF03ljaA6oogj8Xn65Lpd7x1Zyc1kIFIqRMAvDSiprcAFAgN40e3Cl/ joThctL7xxnJsJ6S0k0YJYAnPkTY3wRos5WF5NQ5HpHNtfSUFeEzJ+vw94f1q7TUx7QZ +d5Q== X-Gm-Message-State: APjAAAXiSMXfiVUAy6tv9RpcRbJcCe4tsMtDkE86xVJeVUbB1u0zzeaa Mek8ppOzZLGQuF+mXnfnGHCmfNqQGUA= X-Google-Smtp-Source: APXvYqxeM0hGplB6XELd/R2c0b+0F9jwFuSU2Z3Tp4chVSLJOj461fFocFPKIM98ECOsTS+0+WlaNA== X-Received: by 2002:a1c:7d93:: with SMTP id y141mr13097735wmc.111.1580492983157; Fri, 31 Jan 2020 09:49:43 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Fri, 31 Jan 2020 17:49:26 +0000 Message-Id: <20200131174930.31045-8-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200131174930.31045-1-liuwe@microsoft.com> References: <20200131174930.31045-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v6 07/11] 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 , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 7c2a96d70e..052b053160 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -23,6 +23,7 @@ =20 #include #include +#include #include #include =20 @@ -114,6 +115,19 @@ static void __init setup_hypercall_page(void) BUG_ON(!hypercall_msr.enable); =20 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 =3D hv_do_hypercall(0xffff, 0, 0); + BUG_ON(r !=3D HV_STATUS_INVALID_HYPERCALL_CODE); + r =3D hv_do_fast_hypercall(0xffff, 0, 0); + BUG_ON(r !=3D HV_STATUS_INVALID_HYPERCALL_CODE); + + printk("Successfully issued Hyper-V hypercalls\n"); + } } =20 static void __init setup(void) --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Sat May 4 23:15:39 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1580493046905801.0510082270949; Fri, 31 Jan 2020 09:50:46 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ixaQr-0006lS-ED; Fri, 31 Jan 2020 17:50:17 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ixaQp-0006k2-Im for xen-devel@lists.xenproject.org; Fri, 31 Jan 2020 17:50:15 +0000 Received: from mail-wm1-x344.google.com (unknown [2a00:1450:4864:20::344]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 10c34f6e-4452-11ea-ad98-bc764e2007e4; Fri, 31 Jan 2020 17:49:45 +0000 (UTC) Received: by mail-wm1-x344.google.com with SMTP id q9so8886223wmj.5 for ; Fri, 31 Jan 2020 09:49:45 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id 133sm4364352wmd.5.2020.01.31.09.49.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 09:49:43 -0800 (PST) X-Inumbo-ID: 10c34f6e-4452-11ea-ad98-bc764e2007e4 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=EAsu2Tew/dQ3OuPgDvGiujJ7tHlS5utw9cYPbWTP4Mg=; b=uHkeDxvGsPxI9Is20UMEmPnVDlig1gyoDSeyakFx3FMmsGNTxGxZVo714pegz1Vtp3 rbSxDCfX/qNvpZ/nzQ1sgVv1FiuE9xiB7WoQCFoL60pQM3gDXoxns0qK8VmuuJdqpscC l20mUB52Pjb6ZkbGfANk38PXyU36inQlv+XTS0h7vdVeEh/ii4P4Uv4l3blQvtammSs3 rv09psNHhBCOXZmZq9Xp8vPIJYgdYgIdbFX2KE2qApXRvn90g7v56/npzfVOgBKHPcQ/ TtITu6JwSd8stBUYWaUlkrwEFX88cLHqZUHnNcZ9ld7qXg49GuonkVZUpI7bh0Jz6e9w ajzw== 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=EAsu2Tew/dQ3OuPgDvGiujJ7tHlS5utw9cYPbWTP4Mg=; b=otPTXnIoP0pnw2ejseWqmvwEV8nLXSxEqAEgy6PtFYwArwcecSk6++Gg4Mxw/XysT1 OtF7MyHbplKkBcfRcKueuDiD9L7og3pvuevB/WrUjeqsTSZojELdKjTe/309PSrB56H7 sZOz1FhcuNIAAg+dcCiu/kfZNh0pY3z8BqtXGm8cYEAjnm7DhfCYI8eDX9lNVqn79XPx 0q1d+PTmpkKdm8vpPQql2tNG+wLFYifUXSewIzaBAAivkA+CGRaNkdjRinvf7aEqxfe2 i8kgJnUvSpThoc9EEWLgQRUSs7TmwJQ8whbzyUEtQwcDnPBnvo3tqhrxcXszJCh0CXDn pMbg== X-Gm-Message-State: APjAAAU65dofT+8HdkpYjzT82oollRQjyflaInw5Q7BnURayP3IT9yhK 0Dn7k0FOPfQ2Y/Y3BWfbLAL3Tarm4yA= X-Google-Smtp-Source: APXvYqyfDWXWax1oKHwCbogTBpybCcr6MpSNBDHOEmRXblra4XQ4prcauAnGYguSPSflorjjACh76A== X-Received: by 2002:a1c:1fd0:: with SMTP id f199mr12791824wmf.113.1580492984191; Fri, 31 Jan 2020 09:49:44 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Fri, 31 Jan 2020 17:49:27 +0000 Message-Id: <20200131174930.31045-9-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200131174930.31045-1-liuwe@microsoft.com> References: <20200131174930.31045-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v6 08/11] 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 , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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=C3=A9 --- 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 052b053160..8d44b35aa6 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -27,7 +27,10 @@ #include #include =20 +#include "private.h" + struct ms_hyperv_info __read_mostly ms_hyperv; +DEFINE_PER_CPU_READ_MOSTLY(void *, hv_input_page); =20 static uint64_t generate_guest_id(void) { @@ -130,9 +133,33 @@ static void __init setup_hypercall_page(void) } } =20 +static int setup_hypercall_pcpu_arg(void) +{ + if ( this_cpu(hv_input_page) ) + return 0; + + this_cpu(hv_input_page) =3D 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) { 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(); } =20 static void __init e820_fixup(struct e820map *e820) @@ -146,6 +173,7 @@ static void __init e820_fixup(struct e820map *e820) static const struct hypervisor_ops ops =3D { .name =3D "Hyper-V", .setup =3D setup, + .ap_setup =3D ap_setup, .e820_fixup =3D e820_fixup, }; =20 diff --git a/xen/arch/x86/guest/hyperv/private.h b/xen/arch/x86/guest/hyper= v/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__ */ --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Sat May 4 23:15:39 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 158049305264344.72160557736697; Fri, 31 Jan 2020 09:50:52 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ixaQw-0006pM-0H; Fri, 31 Jan 2020 17:50:22 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ixaQu-0006oO-Je for xen-devel@lists.xenproject.org; Fri, 31 Jan 2020 17:50:20 +0000 Received: from mail-wr1-x443.google.com (unknown [2a00:1450:4864:20::443]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 114f5676-4452-11ea-b211-bc764e2007e4; Fri, 31 Jan 2020 17:49:46 +0000 (UTC) Received: by mail-wr1-x443.google.com with SMTP id a6so9614658wrx.12 for ; Fri, 31 Jan 2020 09:49:46 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id 133sm4364352wmd.5.2020.01.31.09.49.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 09:49:44 -0800 (PST) X-Inumbo-ID: 114f5676-4452-11ea-b211-bc764e2007e4 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=OuvS4yHEnv92OOnV7XktlEYfMKEuteYkS0t0AqPy5go=; b=hwvD5kmfTcaY4SDDf56iLEhTGp+0/f2bFu2wV6wAesdwO/JabEtA5MaYN/5ZtPVntv suaAwo8kO4VM3IPzL6maUg66nkFBijUP8K2viaEK7Aa9T7EFLxIA4Nr0buBNnRyO3G0d Yiubzdy4gjCSHGkiRwXl0DA8+XFl4sEUnLs+6KBk2J4QlO2/VN2D5i6Ee4bjJDNPIPOx zWcpu0JyclCOR//OS9Wq++NKr0qgJPNrku/DwUX87+sJE9yoLMm9ErblRUyd1M9kIy9h naHYR/D8QN2TciW8ttnVdawKwsS7cIq0aAjDbby6EcTF0+AFSlPGXMrGbSY5/FioNA/x zsJQ== 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=OuvS4yHEnv92OOnV7XktlEYfMKEuteYkS0t0AqPy5go=; b=TjnYImh8rT5uf6UJZnvZNU+NPVpJGgzOoQVaQH4d8IZ9OFf2r33pZinTxeaPx68kyO XrCzE4lVYTjMk473TX3ikKC2IqrXhe7udt7NEWuN2o3A51bvzSbBCtQXRnKFjyxnfzrb Qza9Ex3rkNBelkPnJy01OttIOOW2EcLi4UmIuW4Vjn1Vws5Qpfvh/imS5bI4+PXi/iZO jz+VE4s6b1stM0QVDjM2i926Raf0kPlWFYjaV7y4f8+/GMIaWHnycTBWFYNSQcVOfM6F 5mspOsMCT63KphVM8h88Ic5Ubqlgyj0k5GDCTObNGufwNw2io2Yxh5WwapboqI8NdgEl CxMg== X-Gm-Message-State: APjAAAVLNHIp/dkVmnkNmJDoPtD2FCd9bZDNafttVvYHI4/boiwVnW68 y6i0yI2UanhAsqsmhW4kO+Zaq1954pw= X-Google-Smtp-Source: APXvYqyHmpYL9shBrZJ2wnN9iAiM+ykSuxvP+dAaDUSr5n/QJiZkRjMKXJ06LxWT3bKCiy+PtJnsrw== X-Received: by 2002:adf:81c2:: with SMTP id 60mr13002491wra.8.1580492985145; Fri, 31 Jan 2020 09:49:45 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Fri, 31 Jan 2020 17:49:28 +0000 Message-Id: <20200131174930.31045-10-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200131174930.31045-1-liuwe@microsoft.com> References: <20200131174930.31045-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v6 09/11] 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 , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 8d44b35aa6..6dac3bfceb 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -31,6 +31,7 @@ =20 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); =20 static uint64_t generate_guest_id(void) { @@ -135,6 +136,8 @@ static void __init setup_hypercall_page(void) =20 static int setup_hypercall_pcpu_arg(void) { + uint64_t vp_index_msr; + if ( this_cpu(hv_input_page) ) return 0; =20 @@ -146,6 +149,9 @@ static int setup_hypercall_pcpu_arg(void) return -ENOMEM; } =20 + rdmsrl(HV_X64_MSR_VP_INDEX, vp_index_msr); + this_cpu(hv_vp_index) =3D vp_index_msr; + return 0; } =20 diff --git a/xen/arch/x86/guest/hyperv/private.h b/xen/arch/x86/guest/hyper= v/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 =20 DECLARE_PER_CPU(void *, hv_input_page); +DECLARE_PER_CPU(unsigned int, hv_vp_index); =20 #endif /* __XEN_HYPERV_PRIVIATE_H__ */ --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Sat May 4 23:15:39 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1580493056567142.53301374405874; Fri, 31 Jan 2020 09:50:56 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ixaR1-0006tQ-E6; Fri, 31 Jan 2020 17:50:27 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ixaQz-0006sG-Je for xen-devel@lists.xenproject.org; Fri, 31 Jan 2020 17:50:25 +0000 Received: from mail-wr1-x443.google.com (unknown [2a00:1450:4864:20::443]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 11d4d2ba-4452-11ea-a933-bc764e2007e4; Fri, 31 Jan 2020 17:49:47 +0000 (UTC) Received: by mail-wr1-x443.google.com with SMTP id g17so9713435wro.2 for ; Fri, 31 Jan 2020 09:49:46 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id 133sm4364352wmd.5.2020.01.31.09.49.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 09:49:45 -0800 (PST) X-Inumbo-ID: 11d4d2ba-4452-11ea-a933-bc764e2007e4 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=CFk7NSQ22jtMnIw9gaYPgixmKD9SoghgRz4Gqj0PfqY=; b=AioNmFb/mEZABfVfLcSrj2dD4IlWxIoeRsEc5QuK9jtUDTtafpL6ZW67sYSmIvveYF gwFjmkN9A3pHzAIJF7DmfzlwHDC1nNdSSbB++IoUJxgM0ObM0k+NmUmj4dK7h9V/cvoi Ai8tJMnskKmeWlzaHchJDNdF1pfFFGi5YRRIVNzDh00Y6+vfastVjsSJ7Ix7mochAvcK 4bAecsntVsZYsHKghCypujkx6tkZPcqL5mqzptbs19ePipiBV80OuC8q2F4ZixNbA9Ck CEwXUA1KLL5xG1+xMmzMlo+xiqp3m/OmurIh2L7FifAQ+UHetyrvckZ+gmofXC9Dw1XS CImw== 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=CFk7NSQ22jtMnIw9gaYPgixmKD9SoghgRz4Gqj0PfqY=; b=cPvUJpar3nA0Rbu13DXDr4rab9JpUIi599+xd9SXE4CkTBQ9cZexJpR1gDgCJ2n0jS 6EHepe0q0ks6TPR7+Wu0714qkFBxTIZTy95BQakouH1l4gqGAGp207k6+XJ6UrXQkgJz Cnb1X4DlUa3PesVW+CVLWWu47T6F8F1Tr+I/QVTSAKptzSGZhlnpPayBykih/Bmsgr5c X8D4gjRWzmHWbjroRW+swwZOAuuc5LOtw5LPdtKzQ0JTPCFmWnciT39/u/gU+z/ijaXT HM/wSfqTSeHhOkziVYCG8PK9gKyznwEuzzlr9oOHCHg4c0zVjhc8Xwq6G0vLKm0eEfxZ OlWw== X-Gm-Message-State: APjAAAXuWNfAfFgd922izrDpuZ7v2YL6CQYOfZXVVFEw4/1lN+Utm0fb Rwm04ToVvrnkoOeNF0fdhKBJ9HT6k94= X-Google-Smtp-Source: APXvYqwZpue5LqrdUbSfQBsytzq/1Lrz/k+iDVEGACdZOM8Dmc+NexpT60MLOw4Y8v0OREsaxTPDOQ== X-Received: by 2002:adf:b352:: with SMTP id k18mr13025612wrd.242.1580492986036; Fri, 31 Jan 2020 09:49:46 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Fri, 31 Jan 2020 17:49:29 +0000 Message-Id: <20200131174930.31045-11-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200131174930.31045-1-liuwe@microsoft.com> References: <20200131174930.31045-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v6 10/11] x86: move viridian_page_msr to hyperv-tlfs.h 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 , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) And rename it to hv_vp_assist_page_msr. No functional change. Signed-off-by: Wei Liu --- xen/arch/x86/hvm/viridian/viridian.c | 2 +- xen/include/asm-x86/guest/hyperv-tlfs.h | 11 +++++++++++ xen/include/asm-x86/hvm/viridian.h | 15 ++------------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/xen/arch/x86/hvm/viridian/viridian.c b/xen/arch/x86/hvm/viridi= an/viridian.c index 44c8e6cac6..9a6cafcb62 100644 --- a/xen/arch/x86/hvm/viridian/viridian.c +++ b/xen/arch/x86/hvm/viridian/viridian.c @@ -230,7 +230,7 @@ static void dump_guest_os_id(const struct domain *d) =20 static void dump_hypercall(const struct domain *d) { - const union viridian_page_msr *hg; + const union hv_vp_assist_page_msr *hg; =20 hg =3D &d->arch.hvm.viridian->hypercall_gpa; =20 diff --git a/xen/include/asm-x86/guest/hyperv-tlfs.h b/xen/include/asm-x86/= guest/hyperv-tlfs.h index 07db57b55f..0a0f3398c1 100644 --- a/xen/include/asm-x86/guest/hyperv-tlfs.h +++ b/xen/include/asm-x86/guest/hyperv-tlfs.h @@ -558,6 +558,17 @@ struct hv_nested_enlightenments_control { } hypercallControls; }; =20 +union hv_vp_assist_page_msr +{ + uint64_t raw; + struct + { + uint64_t enabled:1; + uint64_t reserved_preserved:11; + uint64_t pfn:48; + }; +}; + /* Define virtual processor assist page structure. */ struct hv_vp_assist_page { __u32 apic_assist; diff --git a/xen/include/asm-x86/hvm/viridian.h b/xen/include/asm-x86/hvm/v= iridian.h index d9138562e6..844e56b38f 100644 --- a/xen/include/asm-x86/hvm/viridian.h +++ b/xen/include/asm-x86/hvm/viridian.h @@ -11,20 +11,9 @@ =20 #include =20 -union viridian_page_msr -{ - uint64_t raw; - struct - { - uint64_t enabled:1; - uint64_t reserved_preserved:11; - uint64_t pfn:48; - }; -}; - struct viridian_page { - union viridian_page_msr msr; + union hv_vp_assist_page_msr msr; void *ptr; }; =20 @@ -70,7 +59,7 @@ struct viridian_time_ref_count struct viridian_domain { union hv_guest_os_id guest_os_id; - union viridian_page_msr hypercall_gpa; + union hv_vp_assist_page_msr hypercall_gpa; struct viridian_time_ref_count time_ref_count; struct viridian_page reference_tsc; }; --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Sat May 4 23:15:39 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1580493057787482.7057214147487; Fri, 31 Jan 2020 09:50:57 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ixaR5-0006x7-So; Fri, 31 Jan 2020 17:50: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 1ixaR4-0006wI-KN for xen-devel@lists.xenproject.org; Fri, 31 Jan 2020 17:50:30 +0000 Received: from mail-wm1-x343.google.com (unknown [2a00:1450:4864:20::343]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 12b1f2da-4452-11ea-8396-bc764e2007e4; Fri, 31 Jan 2020 17:49:48 +0000 (UTC) Received: by mail-wm1-x343.google.com with SMTP id p9so8902714wmc.2 for ; Fri, 31 Jan 2020 09:49:48 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id 133sm4364352wmd.5.2020.01.31.09.49.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 09:49:46 -0800 (PST) X-Inumbo-ID: 12b1f2da-4452-11ea-8396-bc764e2007e4 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=Vy9AWRylVtxfszYTddrOD3+jUXhfGQub8qRdwfYuTdM=; b=rR5jsUWmwjjsnF9BNLaWUKX9rigXWx5G6apWUExUc1FFOEz+NbysHxMHVBvS04pyqj iy1TGgAAOAVoGyPVZytDm8WIYLxeq/tvpP0NwiI7p095uTbJe9MAAmgqpPVhvclNxHAW FOsp4lLK/0UkqxNT9Zq8llT6h8qD946dLN0Vcb24hJufQF/8KGDY/g/0RGk8P1z+XNcK IwSwi4wsX+TFwzOVHMJuM7WhjM9lFMU5R+pRnreAa1nhzOb+j9fh+znZq0Gb6HIH/r3y A/GJJ4wRCFxxK4ALrl7Q2Xl9pEanz9ISC8hCLL1at1mcObtf22Er5ZjgmLKMT1328ezP WNWQ== 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=Vy9AWRylVtxfszYTddrOD3+jUXhfGQub8qRdwfYuTdM=; b=Uw+f9DnsYdet20yrHIV9yY68b98/pdUV7ZiiU1o96+YzJqYkTsa9kUuc5+lXYB47Yq exlmCo7JwOIwif6j2Q8WVP4J2O6bk5DX1w0LXrdCXrppCuOP6JuwyFXNkgT9ui6HSU67 Mc+75AJSWH3Ve1GIOH67POMiwyBK1iRNVLAveetXA12yqatj8Hhj4dlZaaBTdeVuisGz hl/Waxj4dXCcL7L9Zz5KaHHVyFWaSlaBagGBOq9RgNYiO7p1U0tyc81NwN67l2usmYZq Uutho7ZLlSFgI6wxjT+CWf3arIgq78WogNId2f+3/qZaiMSMCdtq9F/ebt3Viy7VxnXj KypA== X-Gm-Message-State: APjAAAUkh3zZ8G1gy7hg7dnebtlCAjq5MPS2mVokBpEBRiE4cHjYFByL 4k6/80hrtvV+GWPCZErGyoV5gzX93W8= X-Google-Smtp-Source: APXvYqxGy1QlNh80bg5rvDBThIbT7nsdaNrtcc1XbDnG/4Eejrnx40obUHcs1xRJKJDbZvNYv/+p2g== X-Received: by 2002:a7b:c753:: with SMTP id w19mr13588770wmk.34.1580492986996; Fri, 31 Jan 2020 09:49:46 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Fri, 31 Jan 2020 17:49:30 +0000 Message-Id: <20200131174930.31045-12-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200131174930.31045-1-liuwe@microsoft.com> References: <20200131174930.31045-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v6 11/11] 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 , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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: Roger Pau Monn=C3=A9 --- 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 6dac3bfceb..75fb329d4d 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -31,6 +31,7 @@ =20 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); =20 static uint64_t generate_guest_id(void) @@ -155,17 +156,51 @@ static int setup_hypercall_pcpu_arg(void) return 0; } =20 +static int setup_vp_assist(void) +{ + union hv_vp_assist_page_msr msr; + + if ( !this_cpu(hv_vp_assist) ) + { + this_cpu(hv_vp_assist) =3D 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 =3D virt_to_mfn(this_cpu(hv_vp_assist)); + msr.enabled =3D 1; + wrmsrl(HV_X64_MSR_VP_ASSIST_PAGE, msr.raw); + + return 0; +} + static void __init setup(void) { setup_hypercall_page(); =20 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"); } =20 static int ap_setup(void) { - return setup_hypercall_pcpu_arg(); + int rc; + + rc =3D setup_hypercall_pcpu_arg(); + if ( rc ) + return rc; + + return setup_vp_assist(); } =20 static void __init e820_fixup(struct e820map *e820) diff --git a/xen/arch/x86/guest/hyperv/private.h b/xen/arch/x86/guest/hyper= v/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 =20 DECLARE_PER_CPU(void *, hv_input_page); +DECLARE_PER_CPU(void *, hv_vp_assist); DECLARE_PER_CPU(unsigned int, hv_vp_index); =20 #endif /* __XEN_HYPERV_PRIVIATE_H__ */ --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel