From patchwork Wed Jan 29 20:20:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11356775 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 C89E414E3 for ; Wed, 29 Jan 2020 20:21:57 +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 A59FA20702 for ; Wed, 29 Jan 2020 20:21:57 +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="UZSq7Iga" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A59FA20702 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 1iwtpN-0006UG-Bm; Wed, 29 Jan 2020 20:20:45 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iwtpL-0006U8-VA for xen-devel@lists.xenproject.org; Wed, 29 Jan 2020 20:20:43 +0000 X-Inumbo-ID: d0c7aa5a-42d4-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 d0c7aa5a-42d4-11ea-b211-bc764e2007e4; Wed, 29 Jan 2020 20:20:39 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id g17so1091942wro.2 for ; Wed, 29 Jan 2020 12:20:39 -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=LQqzUPBymPorZGjCWxaYwWR7iFi3Kgmiz5j6a+T8YdM=; b=UZSq7IgaKYltE9vVjojgpW7GA13ZN2VQAat27xCcG0QBbryzFKZDuWctHzjbeR86bo QDJKJJaWXfDdDgnjFmFpAsbcxORNpb9LcayDBnnPomIbT3u4ds9QTZ5fb00RI6TwkMQB 4x+h4YNPOgZfDOzN+mG8EQKthnKHfz5G+2/my54EB4L7s5KuXCS1Ve/le6dGuRfAb5cK 4Qs0+riIJ74kueUHMzgc/3HZFHK18nYrhNPo9InLldamkXDJFVJHR3w0EQtSBA7aWnc8 JFd/llQC5s4nTTo+wkocKOtANzyqjzK06jn+B8uMt04frFCx/JA91P0DdE53TJcu81h0 fm1w== 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=LQqzUPBymPorZGjCWxaYwWR7iFi3Kgmiz5j6a+T8YdM=; b=kWTDfno9iTS2jxcRKmEvmujRrJ6Xa61FQkEnVn6pksTnIjiigRUxLtBAJBXmDnlX7z JVHMtPeMZ1KbN0bZsIdSn3gB9qDqZKCSVmStQowrxGhqr65RzDEzwWm/vLL8Pq0YJa3U aZp+4PRPWLhWOknnKymrtAi4nkC5ZQ1qHrHdlzGxkvJx+B54i7wvn+clDrBCVg0PTRUD ZqzN6v3B45GtQaITog3A1cZPdz0/corrU0dsNEVW1PJrCUeGzO36e2yTyVrSjpVe/Do2 7s+fHoedRNzPc73A+IT+ZcJt2MLsKMqaMucDon0lnDqLjRM/4kIEswC8n0zNHErmpAU3 8OWg== X-Gm-Message-State: APjAAAXubKXX0BkGp5E8a7Nd8fFQ2E6SXbIikZu/cXy99cnol6w6DnYb EJrya11k+qESptjOlCKScINrcpKeSW4= X-Google-Smtp-Source: APXvYqxnPnxwc/4ocQUAKsqSIim0R/fgW7k64kymFIDEYUSkbjNvZMPrsKfkikXlCvfutejrK4xSXA== X-Received: by 2002:adf:eb8e:: with SMTP id t14mr605541wrn.384.1580329238558; Wed, 29 Jan 2020 12:20: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 a22sm3564115wmd.20.2020.01.29.12.20.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2020 12:20:38 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Wed, 29 Jan 2020 20:20:23 +0000 Message-Id: <20200129202034.15052-2-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200129202034.15052-1-liuwe@microsoft.com> References: <20200129202034.15052-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 01/12] MAINTAINERS: put Hyper-V code under Viridian maintainership 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 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" And add myself as a maintainer. Sort the list alphabetically while at it. Signed-off-by: Wei Liu Signed-off-by: Wei Liu Reviewed-by: Paul Durrant --- MAINTAINERS | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/MAINTAINERS b/MAINTAINERS index 1915e09f8b..04d91482cd 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -514,10 +514,13 @@ F: xen/arch/x86/mm/shadow/ X86 VIRIDIAN ENLIGHTENMENTS M: Paul Durrant +M: Wei Liu S: Supported +F: xen/arch/x86/guest/hyperv/ F: xen/arch/x86/hvm/viridian/ -F: xen/include/asm-x86/hvm/viridian.h +F: xen/include/asm-x86/guest/hyperv.h F: xen/include/asm-x86/guest/hyperv-tlfs.h +F: xen/include/asm-x86/hvm/viridian.h XENTRACE M: George Dunlap From patchwork Wed Jan 29 20:20:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11356773 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 1C60014E3 for ; Wed, 29 Jan 2020 20:21:57 +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 ED44520702 for ; Wed, 29 Jan 2020 20:21:56 +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="Be2+uZN/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ED44520702 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 1iwtpS-0006VC-Ll; Wed, 29 Jan 2020 20:20:50 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iwtpQ-0006Ue-Vv for xen-devel@lists.xenproject.org; Wed, 29 Jan 2020 20:20:49 +0000 X-Inumbo-ID: d1575e5c-42d4-11ea-b211-bc764e2007e4 Received: from mail-wr1-x441.google.com (unknown [2a00:1450:4864:20::441]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d1575e5c-42d4-11ea-b211-bc764e2007e4; Wed, 29 Jan 2020 20:20:40 +0000 (UTC) Received: by mail-wr1-x441.google.com with SMTP id y11so1042967wrt.6 for ; Wed, 29 Jan 2020 12:20:40 -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=9adkovXBXcrsU2wrP2JH6R+/kChgLQsRH9C97w7ZMwg=; b=Be2+uZN/IU3vEeyirsev19HR7abf6wkSb8D0/01Cx5Zw6CEZ5K/p+6P4NNk4vYq1Po 4GFkfFS8U7ZVJVDvVO+7Uiu0Bdipm7sSlPz2vQYSkyxCPCB2aagp0jZyd0e43Td9kkvM R1ly2U2e7BD/mtUxax0XY8zB8c0kNIgK45foJfaRcuOEyZuMvcjUPsVtQgN0xYrqTy8g 5K3FYhNYZYk3NOcYDk/rd/xkjVI14lsUZAS2/tQ4ZcJrCTfRNKVMf5r6GvPwEG6tQVhJ ooou8jBv7RG5xgFkbAVLd/mepxE3w43RjqmjelX9dE1WcnrldrIPSYk2Oi60YEq2OPoh 3kJA== 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=9adkovXBXcrsU2wrP2JH6R+/kChgLQsRH9C97w7ZMwg=; b=NEbG1rSNlhoKePzYLMBWpB8MpBf0/YO6JOXK8co3o8M/MvYuw8UKY12AQTTDWPh7yW ve3CcjoY9o2OjVUt7EOFPFOSi+eZZZiJswT23fPnx8SmjaCH9wunxynMJaJYW80zDOwr P+0V92ctf8SEKSm6imepRn1L/91Grobp97LZGCqosx3ShhsBXku7SlAsw1I/XJqpmmWA cEy0G+sdM9imCmaCsDGl9B1a7UObnyy6Xk4lms/a49oSXsc2VFu28tZadvCIPYQsvAvz SQvL0bBASRMIWrGqKqz2MzcmNqr85T/o7207cmKEo8FybXwLbNY6/++8nLCQUovubQMm +RpA== X-Gm-Message-State: APjAAAWFZur+ZgfCxjTHFGb/y3XyZ1gYfzGs7dqWu0iR0OzT9jR3gafl tVtK0GH0aZEW/CFE7PstHePJkJplxII= X-Google-Smtp-Source: APXvYqxcplD/sL4f1zqvSxzOgdqa8zb6xw3FwUzA0TaA288GWgQuGTGSBlHh5lMXyHkrAYCROMutAw== X-Received: by 2002:adf:bc87:: with SMTP id g7mr605314wrh.121.1580329239560; Wed, 29 Jan 2020 12:20: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 a22sm3564115wmd.20.2020.01.29.12.20.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2020 12:20:39 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Wed, 29 Jan 2020 20:20:24 +0000 Message-Id: <20200129202034.15052-3-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200129202034.15052-1-liuwe@microsoft.com> References: <20200129202034.15052-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 02/12] 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_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. Signed-off-by: Wei Liu --- xen/arch/x86/guest/hypervisor.c | 6 ++++-- xen/arch/x86/guest/xen/xen.c | 11 +++++++++-- xen/include/asm-x86/guest/hypervisor.h | 6 +++--- 3 files changed, 16 insertions(+), 7 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..eed8a6edae 100644 --- a/xen/arch/x86/guest/xen/xen.c +++ b/xen/arch/x86/guest/xen/xen.c @@ -257,11 +257,18 @@ static void __init setup(void) init_evtchn(); } -static void ap_setup(void) +static int ap_setup(void) { + int rc; + set_vcpu_id(); - map_vcpuinfo(); + rc = map_vcpuinfo(); + if ( rc ) + return rc; + init_evtchn(); + + return 0; } int xg_alloc_unused_page(mfn_t *mfn) 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 Wed Jan 29 20:20:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11356783 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 0AB2E159A for ; Wed, 29 Jan 2020 20:22:00 +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 DAA0220716 for ; Wed, 29 Jan 2020 20:21:59 +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="BLGE7OHa" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DAA0220716 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 1iwtpX-0006Wt-6O; Wed, 29 Jan 2020 20:20:55 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iwtpV-0006Wd-Ue for xen-devel@lists.xenproject.org; Wed, 29 Jan 2020 20:20:53 +0000 X-Inumbo-ID: d1eddfe4-42d4-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 d1eddfe4-42d4-11ea-b211-bc764e2007e4; Wed, 29 Jan 2020 20:20:41 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id t2so1090251wrr.1 for ; Wed, 29 Jan 2020 12:20:41 -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=/FbJPxpmB5OoBHeLoD4a2Tb0dzwLPZohxRxFGDvz/aM=; b=BLGE7OHaGGUF5ilIbVyBjY9XiiaCmjK4Mfe60MEmj8qbr5cB9EpoYL61G16cSaTvJ5 oIepJoEa3iXy+ti7A3ap+Pnyss7gXd8Z0FOk/F1FQEUX1KIRe2Sf+MnZg6oepsNEneUP +mh3rEUvel9pPv+qgEPl8hvFVmGDfHDKzkdaVays1soHKiL2VwzHHNAh1sjYezYLMzQn CHV+GTZhqbrvFqSAei2qQ60ApcZaIIYALZM3Oyx1UT0CSmM4fpaPyYgM/IE7tZ2dyXsX 50MC+euCeN7fZYXg6BsfXwLJH+aszcBDPeIvtCoV47VTbBDZIRyVz+XSl/pfzVBtSamZ 58Lg== 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=/FbJPxpmB5OoBHeLoD4a2Tb0dzwLPZohxRxFGDvz/aM=; b=P0UWrWOTNEB5VTXTgQfvHLCqtE56AazotW9o9EgbaIwqGu85TQWhGpGVskCtiPjzfc E9KZ1/SdqLnWaMm7TLiUxPtFmwnTni8d4v84OHGzYu8BbRqocrHPo3+iaOGd1YPPFNiw vO0kM9j4x5prC2oUmOdTB4I7CqzIBzY93DZL8so/FC30NZz3OouTpSLwuXa3pRp+jpuY eT7XkHEwn1eCK7EDkBrS9tZ4rqdNzaqwRX5ql61KCWT2jcPGlrnnSO99ag8c+MM4MZTv GrLUlkGLtQAvr4HEbcC6DTvXVuNyAQMigHuxO/hm73PPj6warqbXiy+b7IQh690UBcf/ yctw== X-Gm-Message-State: APjAAAWxscpBrQyKAQ3LQiDptPj2C0Y4ukRZudJBDSKekieL/zSgVBn8 Xl1Ro6j9m86Rhu9CbBE9cDB9rSibbuw= X-Google-Smtp-Source: APXvYqw7egBWkgvJxpUfm4AAiudYV7Ho+QXD1BugIAlILurcy88HxFWc1wrKRwjq7XeXsnzXIDy0Gw== X-Received: by 2002:adf:f58a:: with SMTP id f10mr633206wro.105.1580329240578; Wed, 29 Jan 2020 12:20: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 a22sm3564115wmd.20.2020.01.29.12.20.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2020 12:20:40 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Wed, 29 Jan 2020 20:20:25 +0000 Message-Id: <20200129202034.15052-4-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200129202034.15052-1-liuwe@microsoft.com> References: <20200129202034.15052-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 03/12] 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_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 +++++++--- 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; } + 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); From patchwork Wed Jan 29 20:20:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11356781 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 EE45714E3 for ; Wed, 29 Jan 2020 20:21:59 +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 CAC4720702 for ; Wed, 29 Jan 2020 20:21:59 +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="UGdQvDH0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CAC4720702 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 1iwtpc-0006Yk-HM; Wed, 29 Jan 2020 20:21:00 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iwtpa-0006YD-VO for xen-devel@lists.xenproject.org; Wed, 29 Jan 2020 20:20:58 +0000 X-Inumbo-ID: d290ead6-42d4-11ea-8396-bc764e2007e4 Received: from mail-wr1-x441.google.com (unknown [2a00:1450:4864:20::441]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d290ead6-42d4-11ea-8396-bc764e2007e4; Wed, 29 Jan 2020 20:20:42 +0000 (UTC) Received: by mail-wr1-x441.google.com with SMTP id z7so979852wrl.13 for ; Wed, 29 Jan 2020 12:20:42 -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=gCFi7p2cW832Oj/4SVP/DOq5zNQ19Ssf0CeEfHPDZW8=; b=UGdQvDH0kvj8CPfpAVPM2GPWDjpOeQV+LlipPwIQQajytXitYVU8e6auoEOexZ51Co aHmLhglQy5QVyCWl3gat1MnhrmwvsMCmRwcO7jBKjHSAheIsJBmJ9/5zVm0JlqhJc0z5 vpSyvSxrZuVPWRgMK+Z2gj1KvOBQKr1LxVtV5G9bOrU4U0otxJ3hgayBaGwMjSoF2KWs SsyBWWoPbzMmHkGZ6o3VMEZD8Wq0JMjE5Sgf/z6+E4p6eL7frHtH3C0rBs5T2TJEoCLp zfjM2/o4D1rP3tSFDvHoilybJwCdv5SHxK07xbM2WNtkKkfE0VxBaJlK4kS66auL2K2s BrfA== 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=gCFi7p2cW832Oj/4SVP/DOq5zNQ19Ssf0CeEfHPDZW8=; b=nDENmJdvw+LLqx/pHB40SCWfmLzs15p05uaTKmFMPkLsEDgGfL0H9KiScXDDGgr5/7 zlI+OC3Ugdl1GwT18ZPIPqjlepfKfjlosbkJ/2mn0qkcG/givdCu5Y7KvlzY8jyqwIJO Bb51LNRGCVU5sOVnESz76Lxnw+QhEfx4xiFfwSLVxq3V6l8TMngFCDQf7xLqElphLHOW 43WREbyZjwc3kPUnRhbm1sWMiCiC0P5OzwN1nTyEedPk9yM/ZehYOp4HNjPOIdSGH50H XF7forzZNwhDa1OzGt3xCyKC9s7IHyh+e5rkwAzTlFv+NtLbID0wvBl/Jn42DhfdiIdG jXug== X-Gm-Message-State: APjAAAWNzSCFl/lDEKxM8TFIv8v+YEzspzVJ706nsfqYxNUdxroxoK1z sDUZYb4rtlEh+3GthfrEKg8hjPD0+BY= X-Google-Smtp-Source: APXvYqzt8Mlxu7sk+n0p3Z+yz/gJsQAhDgj0fvBlFArkkEcdGPWBrI5u9ORxFQ9ccso3qsYIEDpQhQ== X-Received: by 2002:adf:f64b:: with SMTP id x11mr560145wrp.355.1580329241596; Wed, 29 Jan 2020 12:20: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 a22sm3564115wmd.20.2020.01.29.12.20.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2020 12:20:41 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Wed, 29 Jan 2020 20:20:26 +0000 Message-Id: <20200129202034.15052-5-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200129202034.15052-1-liuwe@microsoft.com> References: <20200129202034.15052-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 04/12] x86: make paddr_bits available earlier 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_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Move early_cpu_init before init_e820, such that paddr_bits can be used by e820 code. This will reduce code repetition and prepare for further adjustment when L0 hypervisor comes into play. Signed-off-by: Wei Liu Reviewed-by: Roger Pau Monné Acked-by: Jan Beulich --- xen/arch/x86/e820.c | 14 ++++---------- xen/arch/x86/setup.c | 5 +++-- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/xen/arch/x86/e820.c b/xen/arch/x86/e820.c index 082f9928a1..3892c9cfb7 100644 --- a/xen/arch/x86/e820.c +++ b/xen/arch/x86/e820.c @@ -420,7 +420,7 @@ static uint64_t __init mtrr_top_of_ram(void) { uint32_t eax, ebx, ecx, edx; uint64_t mtrr_cap, mtrr_def, addr_mask, base, mask, top; - unsigned int i, phys_bits = 36; + unsigned int i; /* By default we check only Intel systems. */ if ( e820_mtrr_clip == -1 ) @@ -445,15 +445,9 @@ static uint64_t __init mtrr_top_of_ram(void) if ( !test_bit(X86_FEATURE_MTRR & 31, &edx) ) return 0; - /* Find the physical address size for this CPU. */ - eax = cpuid_eax(0x80000000); - if ( (eax >> 16) == 0x8000 && eax >= 0x80000008 ) - { - phys_bits = (uint8_t)cpuid_eax(0x80000008); - if ( phys_bits > PADDR_BITS ) - phys_bits = PADDR_BITS; - } - addr_mask = ((1ull << phys_bits) - 1) & ~((1ull << 12) - 1); + /* paddr_bits must have been set at this point */ + ASSERT(paddr_bits); + addr_mask = ((1ull << paddr_bits) - 1) & PAGE_MASK; rdmsrl(MSR_MTRRcap, mtrr_cap); rdmsrl(MSR_MTRRdefType, mtrr_def); diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index d858883404..89fe49149f 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -954,6 +954,9 @@ void __init noreturn __start_xen(unsigned long mbi_p) else panic("Bootloader provided no memory information\n"); + /* This must come before e820 code becuause it sets paddr_bits. */ + early_cpu_init(); + /* Sanitise the raw E820 map to produce a final clean version. */ max_page = raw_max_page = init_e820(memmap_type, &e820_raw); @@ -1532,8 +1535,6 @@ void __init noreturn __start_xen(unsigned long mbi_p) softirq_init(); tasklet_subsys_init(); - early_cpu_init(); - paging_init(); tboot_probe(); From patchwork Wed Jan 29 20:20:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11356779 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 1882792A for ; Wed, 29 Jan 2020 20:21:59 +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 E968D20702 for ; Wed, 29 Jan 2020 20:21:58 +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="e0RLakOE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E968D20702 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 1iwtph-0006b6-Si; Wed, 29 Jan 2020 20:21:05 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iwtpf-0006aO-Vq for xen-devel@lists.xenproject.org; Wed, 29 Jan 2020 20:21:04 +0000 X-Inumbo-ID: d32f214c-42d4-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 d32f214c-42d4-11ea-b211-bc764e2007e4; Wed, 29 Jan 2020 20:20:43 +0000 (UTC) Received: by mail-wr1-x443.google.com with SMTP id w15so1065997wru.4 for ; Wed, 29 Jan 2020 12:20:43 -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=cLJgFPr57iEIt0cWTwdp4rQGYu8h82jvo9pSTpYW02s=; b=e0RLakOEr6u+WdJ+xPbJGytMfwZaK5EX6iACn5XOShZ67X/KMgy6DWLkPeQj8bONdD +yN73gNSPX/5KtpQ4lP1ET3LxDSFgN2m1TY/eUDGtbYILBdgd6bThN9cM2Tjd7bSKw/D 4UzI4/tfAbWil+w2NuSd/+QWFuudwufKSGEpI0A1xX2LAtMGYnMuOvhiBEmb6MRQCgWB bxr3wtBhDSDvOyI82iO7Hd5E6weRdDUod4Cpnz3bEmOt5hfeYZJh2pyUPfqwO0d2VLe6 uhM+79n1E4ftRY5Bif38yiMHkn4OUExLMyLYTShejyC8e9fodRCjdoRV4pGXRDHXTMze O1+A== 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=cLJgFPr57iEIt0cWTwdp4rQGYu8h82jvo9pSTpYW02s=; b=Q3wvXvBrQDdU5tPlV6sajEaVFiHKHIqiI0o5jP9w5fUEIc3w81y5MZK0gAWQv4Xby9 7juCZ7lLGFTXvk8h9KwB5nquCOGfCrZHtOMWpN7VqLOv9xQf3KeqvjX9x8f+uowRkiMW C5Qn+YcQiJn0j3lLtu88XIde5V/f/32ALfYLJCpukkigwBfvAIC0+GB3oB2KvaTnuWke fauKqJCNfR+erV0iJJvq+nhoywj/QspaDgOJ+5fpbBySRxWXqY+vrjq3U70U3RGl9SCo qeNURdVwXYREtOSzGyvxvvreCGNu9xEzCCV92R4OQKOxslcQcpxJD0xRT21t4+NndQC5 rTZA== X-Gm-Message-State: APjAAAWdYM2Y3N50cEjQIzwZTNCKvDtB4NI1FH4ngUoh8zhQnhrcRvOc daXCKXtzLR2oQODse1yRqDK5QA5yfzU= X-Google-Smtp-Source: APXvYqwc3+mcOV4ai1N9vaXa03fziJTBIHcCF8iOSF40iYcCHpvJ09bvqX2WV3BKUOR1KP9HJPWvzA== X-Received: by 2002:a5d:45c4:: with SMTP id b4mr561131wrs.303.1580329242595; Wed, 29 Jan 2020 12:20: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 a22sm3564115wmd.20.2020.01.29.12.20.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2020 12:20:42 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Wed, 29 Jan 2020 20:20:27 +0000 Message-Id: <20200129202034.15052-6-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200129202034.15052-1-liuwe@microsoft.com> References: <20200129202034.15052-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 05/12] 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_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 --- 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 | 25 +++++++++++++++++++++++++ 7 files changed, 58 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 f50c065af3..44abde24b2 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]; paddr_t __read_mostly mem_hotplug; @@ -5718,10 +5720,21 @@ 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); + + /* Generate a symbol to be used in linker script */ + asm ( ".equ FIXADDR_X_SIZE, %c0; .global FIXADDR_X_SIZE" + :: "i" (__end_of_fixed_addresses_x << PAGE_SHIFT) ); +} + 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 07c6448dbb..97f9c07891 100644 --- a/xen/arch/x86/xen.lds.S +++ b/xen/arch/x86/xen.lds.S @@ -3,6 +3,8 @@ #include #include + +#include #include #undef ENTRY #undef ALIGN @@ -353,6 +355,7 @@ SECTIONS } ASSERT(__2M_rwdata_end <= XEN_VIRT_END - XEN_VIRT_START + __XEN_VIRT_START - + FIXADDR_X_SIZE - DIV_ROUND_UP(NR_CPUS, STUBS_PER_PAGE) * PAGE_SIZE, "Xen image overlaps stubs area") 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..8094546b75 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,30 @@ 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 Wed Jan 29 20:20:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11356777 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 4D07392A for ; Wed, 29 Jan 2020 20:21:58 +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 29B0D20702 for ; Wed, 29 Jan 2020 20:21:58 +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="gvI2Of03" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 29B0D20702 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 1iwtpm-0006dR-7O; Wed, 29 Jan 2020 20:21:10 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iwtpk-0006cr-WB for xen-devel@lists.xenproject.org; Wed, 29 Jan 2020 20:21:09 +0000 X-Inumbo-ID: d3bb65da-42d4-11ea-b211-bc764e2007e4 Received: from mail-wr1-x441.google.com (unknown [2a00:1450:4864:20::441]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d3bb65da-42d4-11ea-b211-bc764e2007e4; Wed, 29 Jan 2020 20:20:44 +0000 (UTC) Received: by mail-wr1-x441.google.com with SMTP id z7so979970wrl.13 for ; Wed, 29 Jan 2020 12:20:44 -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=ITFZiTyiTf8vIPKBbhv8PPdQmh+pCqfsfzWwanxg5Zc=; b=gvI2Of03ObHu/iEQibeI0lBSv6UU9zrXLeW71/w+iXSh//RCMfYN0c9QHkD3g3qM09 GzDbe11VNWTNav219i5NI+FsXnS225uIgk91Oyg5BA+Cvm64hK6fwte+EZKdIDJbRQtG 3lkrThmf0ISCfo+YhvDuHNI13nr6Ae0OU0UbHy6VMnT6LzmVfL4xLt8NuJcr0Je2LhkC R6t/Y49lIM3rMgM+bLVJusxjz0+iDdTSZMX/+rYyNFDzm3D2lxravWz1cchDga7l+vuV fnbWmjAIHU1VR9ASHtVrH3A4kdNfD+sZWHnctTWpwEBkYuomXRgrn/pAJ1p9Ud0Z+vxt oNJw== 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=ITFZiTyiTf8vIPKBbhv8PPdQmh+pCqfsfzWwanxg5Zc=; b=hLIPJYe5OEXUeQgEGCCnB+KlodbiRpt4V33LXTkoyhgHqSUUEyYGqAQn1530Zt9Gqs zuXBZIVWCzYx/vpICfGET8Kbn8hYNL8XwydVfEVgqVuhi9xXKeUnt29+y71DB8oucI+3 4FS6PmEk2lEtO9aHb4h1j+7XZgVIyKvXEbTM+8HuYVcBTQBeG6RecHsAxB1aCXo3uP89 M3zbZBJqJAIalP1Ino2STUX+imNXjsDutRbBlI20Z8BzMMGZtD+KHJbgcr6efy+WXC5B ew/+9uiFujqQxK1nQ4W+AuMI49oirkvUXf9SJrLRVW/O7RWdeMxTeOBo2yAnwwKtOQF5 uMfg== X-Gm-Message-State: APjAAAUeLR5fEzwQjkPwbwtZ34zBMsbO0sku2p5/PLwxWvClSrIugZu0 kaJbcvgMiXDqZH/hfSidGnsroAvLlT8= X-Google-Smtp-Source: APXvYqwU7K3c6tO3fT6jxXBkrE8TA2G8+vyjQ942jcAaTi+RClCSCHwZuD6A6JnLtf0tnHqannAHmA== X-Received: by 2002:adf:f3d0:: with SMTP id g16mr663979wrp.2.1580329243528; Wed, 29 Jan 2020 12:20: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 a22sm3564115wmd.20.2020.01.29.12.20.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2020 12:20:43 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Wed, 29 Jan 2020 20:20:28 +0000 Message-Id: <20200129202034.15052-7-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200129202034.15052-1-liuwe@microsoft.com> References: <20200129202034.15052-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 06/12] x86/hypervisor: provide hypervisor_reserve_top_pages 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_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This function will return the number of pages that need to be reserved in the machine address space. E820 code will use that number to adjust the maximum PFN available to Xen. Signed-off-by: Wei Liu --- xen/arch/x86/guest/hypervisor.c | 8 ++++++++ xen/include/asm-x86/guest/hypervisor.h | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c index e72c92ffdf..8b9cf1ce4c 100644 --- a/xen/arch/x86/guest/hypervisor.c +++ b/xen/arch/x86/guest/hypervisor.c @@ -66,6 +66,14 @@ void hypervisor_resume(void) ops->resume(); } +unsigned int hypervisor_reserve_top_pages(void) +{ + if ( ops && ops->reserve_top_pages ) + return ops->reserve_top_pages(); + + return 0; +} + /* * Local variables: * mode: C diff --git a/xen/include/asm-x86/guest/hypervisor.h b/xen/include/asm-x86/guest/hypervisor.h index b503854c5b..37eb9d531e 100644 --- a/xen/include/asm-x86/guest/hypervisor.h +++ b/xen/include/asm-x86/guest/hypervisor.h @@ -28,6 +28,8 @@ struct hypervisor_ops { int (*ap_setup)(void); /* Resume from suspension */ void (*resume)(void); + /* How many top pages to be reserved in machine address space? */ + unsigned int (*reserve_top_pages)(void); }; #ifdef CONFIG_GUEST @@ -36,6 +38,7 @@ const char *hypervisor_probe(void); void hypervisor_setup(void); int hypervisor_ap_setup(void); void hypervisor_resume(void); +unsigned int hypervisor_reserve_top_pages(void); #else @@ -46,6 +49,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 unsigned int hypervisor_reserve_top_pages(void) { return 0; } #endif /* CONFIG_GUEST */ From patchwork Wed Jan 29 20:20:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11356787 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 D7ABD14E3 for ; Wed, 29 Jan 2020 20:22:13 +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 B3DD320702 for ; Wed, 29 Jan 2020 20:22:13 +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="Dur2/pYX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B3DD320702 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 1iwtpr-0006h1-M3; Wed, 29 Jan 2020 20:21:15 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iwtpp-0006g5-VZ for xen-devel@lists.xenproject.org; Wed, 29 Jan 2020 20:21:13 +0000 X-Inumbo-ID: d45fc6ac-42d4-11ea-a933-bc764e2007e4 Received: from mail-wr1-x443.google.com (unknown [2a00:1450:4864:20::443]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d45fc6ac-42d4-11ea-a933-bc764e2007e4; Wed, 29 Jan 2020 20:20:45 +0000 (UTC) Received: by mail-wr1-x443.google.com with SMTP id a6so993363wrx.12 for ; Wed, 29 Jan 2020 12:20:45 -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=iwQJpxgP/vljEjr3HG+eqYIFxXkmHKLinOPCzBMa6MA=; b=Dur2/pYXn3Mzrt/pCnA28zzcQ6/sAcaK2QGp/0yQ17theK1tBJcrMHT13bC/byuFuP 1wEu4iVC0R43Q4ad8Yrgnjv0PfntLi1VacGpmXz/vCGVrzZ4gY8DVDXFkBfg7XVgM6/n LNKUQUx/0TmwLoRwLvmApDXS3d3RfxHiIM1a9rQUvdVKM87F4W6JECmmFdOD85A96Ff8 QWPhU7bGdhaM6RZI6qFmahKi6UU1rs00UljJ1/4+sxa9dRTOvwZoC4njKYMuAcdOSObo aL5K0AzfUH1F02ZT5rH7n5gSmb5N1jB9EKTDxBCvVZM7I7HkRCkaNlHRTTbkBvpFofoN RSNw== 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=iwQJpxgP/vljEjr3HG+eqYIFxXkmHKLinOPCzBMa6MA=; b=WTJ7W8TIa7Iu0yVIguHlNh5eQcFkr1/szBY8Gbyq0CkN9PQ/cJkxuSavHgSqbqAhVQ XL+O3YtMN44ufpY8x9gIEimypHjXz2yml2R6N/cpsLuaZWV++eiaDryJ1e6bop48I41y ixw9PpGfALgUCvJvT4gjyC3khyF5Ew0fLRe0AAbWnmy0HmibdrCJA/TyAHWvjdKoYgy3 AyPdFU6sKK2y4/+vkgZdvf90uCHY3YFojsKqJe6oi39Pc9OI7bL2Qfx2i7NpCK6fjZBv rLkg8MzZMcDu8UmL0Gb2hIY+idKdDj24B6Y+DRQkhLProoRU+/TH8vCph8yhA43EVZHJ 1rDw== X-Gm-Message-State: APjAAAUnYwOKuEVeupIIc2/zKRR4IQ6mEUk6ZTkBmv+Ij82fJg2DrQZH /q+rWoc79MgnGsh1v5OSRl63nRO+ZzQ= X-Google-Smtp-Source: APXvYqxFSKauMHACpbNv6FR8ensHdGTuJtxxpWiEcRHnesJolhPX4KCJ6SLzwnafG6i8av+YVTjotw== X-Received: by 2002:adf:f0cb:: with SMTP id x11mr568510wro.421.1580329244539; Wed, 29 Jan 2020 12:20: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 a22sm3564115wmd.20.2020.01.29.12.20.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2020 12:20:44 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Wed, 29 Jan 2020 20:20:29 +0000 Message-Id: <20200129202034.15052-8-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200129202034.15052-1-liuwe@microsoft.com> References: <20200129202034.15052-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 07/12] 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_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. Use the top-most addressable page for that purpose. Adjust e820 code 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 --- 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/e820.c | 5 +++ xen/arch/x86/guest/hyperv/hyperv.c | 57 +++++++++++++++++++++++-- xen/include/asm-x86/guest/hyperv-tlfs.h | 5 ++- xen/include/asm-x86/guest/hyperv.h | 3 ++ 4 files changed, 65 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/e820.c b/xen/arch/x86/e820.c index 3892c9cfb7..99643f3ea0 100644 --- a/xen/arch/x86/e820.c +++ b/xen/arch/x86/e820.c @@ -343,6 +343,7 @@ static unsigned long __init find_max_pfn(void) { unsigned int i; unsigned long max_pfn = 0; + unsigned long top_pfn = ((1ull << paddr_bits) - 1) >> PAGE_SHIFT; for (i = 0; i < e820.nr_map; i++) { unsigned long start, end; @@ -357,6 +358,10 @@ static unsigned long __init find_max_pfn(void) max_pfn = end; } + top_pfn -= hypervisor_reserve_top_pages(); + if ( max_pfn >= top_pfn ) + max_pfn = top_pfn; + return max_pfn; } diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index 8d38313d7a..2bedcc438c 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -19,15 +19,26 @@ * 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) +{ + uint64_t id; + + id = (uint64_t)HV_XEN_VENDOR_ID << 48; + id |= (xen_major_version() << 16) | xen_minor_version(); + + return id; +} + +static const struct hypervisor_ops ops; const struct hypervisor_ops *__init hyperv_probe(void) { @@ -72,6 +83,46 @@ 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; + + 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 const struct hypervisor_ops ops = { + .name = "Hyper-V", + .setup = setup, +}; + /* * 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 * * */ #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..0dcd8082ad 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 Wed Jan 29 20:20:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11356785 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 1208192A for ; Wed, 29 Jan 2020 20:22:13 +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 E2BCC20702 for ; Wed, 29 Jan 2020 20:22:12 +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="gAXEf7Se" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E2BCC20702 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 1iwtpw-0006lK-BC; Wed, 29 Jan 2020 20:21:20 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iwtpu-0006k9-VW for xen-devel@lists.xenproject.org; Wed, 29 Jan 2020 20:21:18 +0000 X-Inumbo-ID: d4f048e4-42d4-11ea-a933-bc764e2007e4 Received: from mail-wr1-x444.google.com (unknown [2a00:1450:4864:20::444]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d4f048e4-42d4-11ea-a933-bc764e2007e4; Wed, 29 Jan 2020 20:20:46 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id z3so1076025wru.3 for ; Wed, 29 Jan 2020 12:20:46 -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=GVwT/fRB4x8eA70WV+TcjUCD3Ezn+Rwuk+S0GkkMty8=; b=gAXEf7Se8v8p9nT0qBBqFghoKfIJKvPBa3M4QWikvczdKUiWZcGDYpMkqTKPYu8PP8 h57uT8eWlXFlKLkOwFlyoQxR7clrTg5dpL4Ej1n8amYKtFbRihbW8/Qgs43McI6HeGaa ZiLMEs36c5Rb6ZHPPJvxzyy/xjf/XQZD1GXs14p0c4hhxZm0UoFiS2WyUBSQl93Uvvm+ kK3lA/YXEKWR+OgBZXkDW1TefIRL4cklDitVGG98m6xBQSQoQTGWcA3WbnUXuxXjLbRT vQ48pDIeJ/HRFOKPycLbbKLB0BLcZPrnwq7ftfFlcQA4AsMgdxKN4vOUFyH3Bd6H+T5S OhxA== 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=GVwT/fRB4x8eA70WV+TcjUCD3Ezn+Rwuk+S0GkkMty8=; b=Q9ZLabAbyYPJBLFLgV9uSgHHztl8cVMXmOXleoe6usGhVkcSzl6txp8MycjnogN4fX UbHcUQwaURTmAd1fF2Nlmsbmb/8WHwq4Jw9tLfrc9y3J9K5+c000u3bfWAxPxq3AYTCT FJdnsJwhEXjAQpGg0goLgeei6FHmG+ZIl9z2ubZ33htWi9ZuM9O9uDZh+h+acfbJxdqM VXifQdjzUazpb6aIaXG3QWNorGt6JRUDx0mlf2DiVzDrbaiELbJPI1nC8iZmTP+bCDdF 4xl2zOM0wjDgZ5RcZu9daaiteE5W8CLjDalQBxuw6Qwe9hLabWrrJFU7P1U3On9gGZPJ tPFg== X-Gm-Message-State: APjAAAW/sKDYHase3AOLsJDjxLjBMWN4wTMK7EAAq3RyG91r3sHPhgHS 2MTqgAgvnq/axJWJuj+KFxTwmEb1sFQ= X-Google-Smtp-Source: APXvYqwAbYO5qpKgjBv6vkVVZMyWpCUtW9Q2/wRvX2tv0EcaSAVI+10pmrYFri7BkOMy1Ly35gXQtA== X-Received: by 2002:a5d:488c:: with SMTP id g12mr619047wrq.67.1580329245583; Wed, 29 Jan 2020 12:20: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 a22sm3564115wmd.20.2020.01.29.12.20.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2020 12:20:45 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Wed, 29 Jan 2020 20:20:30 +0000 Message-Id: <20200129202034.15052-9-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200129202034.15052-1-liuwe@microsoft.com> References: <20200129202034.15052-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 08/12] 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_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 --- v5: 1. Switch back to direct call 2. Fix some issues pointed out by Jan I tried using the asm(".equ ..") trick but hit a problem with %c again. mm.c:5736:5: error: invalid 'asm': operand is not a condition code, invalid operand code 'c' asm ( ".equ HV_HCALL_PAGE, %c0; .global HV_HCALL_PAGE" --- MAINTAINERS | 1 + xen/arch/x86/guest/hyperv/hyperv.c | 6 ++ xen/arch/x86/xen.lds.S | 4 + xen/include/asm-x86/fixmap.h | 3 +- xen/include/asm-x86/guest/hyperv-hcall.h | 96 ++++++++++++++++++++++++ 5 files changed, 108 insertions(+), 2 deletions(-) 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 2bedcc438c..932a648ff7 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -123,6 +123,12 @@ static const struct hypervisor_ops ops = { .setup = setup, }; +static void __maybe_unused build_assertions(void) +{ + /* We use 1 in linker script */ + BUILD_BUG_ON(FIX_X_HYPERV_HCALL != 1); +} + /* * Local variables: * mode: C diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S index 97f9c07891..8e02b4c648 100644 --- a/xen/arch/x86/xen.lds.S +++ b/xen/arch/x86/xen.lds.S @@ -329,6 +329,10 @@ SECTIONS efi = .; #endif +#ifdef CONFIG_HYPERV_GUEST + hv_hcall_page = ABSOLUTE(__fix_x_to_virt(1)); +#endif + /* Sections to be discarded */ /DISCARD/ : { *(.exit.text) diff --git a/xen/include/asm-x86/fixmap.h b/xen/include/asm-x86/fixmap.h index 8094546b75..a9bcb068cb 100644 --- a/xen/include/asm-x86/fixmap.h +++ b/xen/include/asm-x86/fixmap.h @@ -16,6 +16,7 @@ #define FIXADDR_TOP (VMAP_VIRT_END - PAGE_SIZE) #define FIXADDR_X_TOP (XEN_VIRT_END - PAGE_SIZE) +#define __fix_x_to_virt(x) (FIXADDR_X_TOP - ((x) << PAGE_SHIFT)) #ifndef __ASSEMBLY__ @@ -110,8 +111,6 @@ extern void __set_fixmap_x( #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__ */ 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..5b7509b3b5 --- /dev/null +++ b/xen/include/asm-x86/guest/hyperv-hcall.h @@ -0,0 +1,96 @@ +/****************************************************************************** + * 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; + + 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; + + 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 Wed Jan 29 20:20:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11356789 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 4DF74159A for ; Wed, 29 Jan 2020 20:22:14 +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 2AE9C20702 for ; Wed, 29 Jan 2020 20:22:14 +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="A8Tfm+9S" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2AE9C20702 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 1iwtq1-0006pS-NK; Wed, 29 Jan 2020 20:21:25 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iwtq0-0006oA-0m for xen-devel@lists.xenproject.org; Wed, 29 Jan 2020 20:21:24 +0000 X-Inumbo-ID: d5796732-42d4-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 d5796732-42d4-11ea-b211-bc764e2007e4; Wed, 29 Jan 2020 20:20:47 +0000 (UTC) Received: by mail-wr1-x443.google.com with SMTP id w15so1066204wru.4 for ; Wed, 29 Jan 2020 12:20:47 -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=gVgi6YBrthYt44Wqrj9O7ZKyhRLbqO7Cs1SR/Wr9UuA=; b=A8Tfm+9SGhaeBy2/SnmLj6UDr3Y91pGgh7YUe3IMyvLJYnHRpFpTJMmhHrgkwL3/D2 rOh9XImEmIG8hcuymgaaIqVW5Ahwpzt9bUc3pnNee0XmYJ42niCp1Xoe8XDXJAZNjFZJ Hj8Yl1zTdVzfwo6KetJ0lS/PyGkgpNI9+iUGfk7o4jQ2W38VcpYy1f97COhK1iFIe2WS +bB6renOG4UskqdPt8hFPse5K3BroBWUhOAv1V4WfisdWLMRPLR3AEpRqpbpp/195BVp AdsCjNWJppoCmU5H5SHU8bzA3/lG4FRJpXOU6Pa2L5ewvY/TfdOi89OCxZY7UWMYuqUk tFbg== 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=gVgi6YBrthYt44Wqrj9O7ZKyhRLbqO7Cs1SR/Wr9UuA=; b=goNOJDUZzqpik+LVOzLMlNZ/HxZ2akJR32S204bisdumLfR3ojEqDISWWrOpYIiKJT F3PX1ZiUiWpayMpO/F/cPx36ei7f/jW7KcIbaZQMMQJTLL/02DAePRd3rPPJtwaY0TJB xuiygvvOsXxUFlHJ/eKro6LlqBIciDfwWqzc91yI2b7jdxUs7SvrZ06rpM2tBTVfDZxM od9nS/lOSqdnf0Ys0qLPUroYgQi56wUAfs9Wa9NXEfGffDSqywwv2nCtKr6cOcZVPWs6 1o7eTB46MwINR17fQbHAbw2AS5/C9HtS/h89g5xxTB/wS+ulDYJyQnKE/ZNjVGC5JJfD MtbQ== X-Gm-Message-State: APjAAAUo46M23jcCt0skH16FVh7sfvf7oDm3bON7WXobKlJ83aGINeAq lheH19AyNoI4PezlBJnrW8I8ITabiJ4= X-Google-Smtp-Source: APXvYqwPinvoLOIfW/IKtHyR6DxnZ7vKLwYyuQVmGE7asoN63UT7xuLBWNx/d5x66D6VXBU3smP/fQ== X-Received: by 2002:a5d:5706:: with SMTP id a6mr635351wrv.108.1580329246460; Wed, 29 Jan 2020 12:20: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 a22sm3564115wmd.20.2020.01.29.12.20.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2020 12:20:46 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Wed, 29 Jan 2020 20:20:31 +0000 Message-Id: <20200129202034.15052-10-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200129202034.15052-1-liuwe@microsoft.com> References: <20200129202034.15052-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 09/12] 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_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 932a648ff7..4387b6541e 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 @@ -111,6 +112,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 Wed Jan 29 20:20:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11356791 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 626AB92A for ; Wed, 29 Jan 2020 20:22: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 3F1CA20702 for ; Wed, 29 Jan 2020 20:22: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="tVwiF6rL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3F1CA20702 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 1iwtq7-0006tl-3v; Wed, 29 Jan 2020 20:21: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 1iwtq5-0006sR-0K for xen-devel@lists.xenproject.org; Wed, 29 Jan 2020 20:21:29 +0000 X-Inumbo-ID: d61964f8-42d4-11ea-b211-bc764e2007e4 Received: from mail-wr1-x441.google.com (unknown [2a00:1450:4864:20::441]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d61964f8-42d4-11ea-b211-bc764e2007e4; Wed, 29 Jan 2020 20:20:48 +0000 (UTC) Received: by mail-wr1-x441.google.com with SMTP id y11so1043480wrt.6 for ; Wed, 29 Jan 2020 12:20:48 -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=RzyOqBOVVAhQpV3lENjn6NyUC6dkaBmuVSXJthxFeDo=; b=tVwiF6rLrO3eOWMXW337suntCd+02cBaulZA8iz82SvDHIxXPKlDhU1WZ693ML3BP3 NjXO1XHGo6EysyZ7CLntBoluIMWcFu3zjM8M3rfs5ybgF8J1eMQ9mgUMMfZta2eSy30X +qXiwES7EhGudr8CxQWMrCMb7bdrKhaC7tl+0o3Pm+x6lrU+3hwQvvWRleEjuj9PBtg0 ANx80USJP9IpNK3dInzDkZaWTMSNftycTRToW6J97TlmbeQukfKVyk41jlzaW/ZUNpqE Hen0LoURoeFWY+CeDOT5I/EM7s12rNrHhOAJFyYIFpn+NdWo89VmD0XA220eQT3RRGkY 1wJA== 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=RzyOqBOVVAhQpV3lENjn6NyUC6dkaBmuVSXJthxFeDo=; b=tWSjO5VNplATU1mAzBkZe6v3dGVn2pOz0DLncmhwDzKPYrEEPp6zteKalqLmtbPo/3 h94PB0uO5rKmmN+A+gcL8xFfte29w60YMJw7k9BSGsmE4ZnbfLUOmQdtsBc2GxKn7Ckh txJZiSPGVxAkJWqmy7azYxHU/1rC10RWNdKDQ12U/0CElJEhjMbNKVkJ9vV4X/dJPafw +wRtUzBa3vvlUE+aX8F5tAAxZOF3KV2aZxu/y06DnD8Drt7Te1z+pxlBP9GqYA7ePOob 9r2KLcCJbCNTclHE3hqLblxNCoK1yyin4nRuwNHgJAylqCvEWP6MoSjsPZL+y/WQ4enF f72g== X-Gm-Message-State: APjAAAXRBbVKPNt1WWNSBcEcMgGUVpSuCHo3S4iX+OWIT4h9s8v8XEeD ih+SVTRKcwR6zeb5s36Thl4Mi0WkMjs= X-Google-Smtp-Source: APXvYqzwjLjlOp06e+zlACqgmsdgD2iIe6NpsKXB8oa29a81W/0W/Qetj2PJHKKKNz4LwsuofXKrcA== X-Received: by 2002:adf:e74a:: with SMTP id c10mr624231wrn.386.1580329247544; Wed, 29 Jan 2020 12:20:47 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id a22sm3564115wmd.20.2020.01.29.12.20.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2020 12:20:47 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Wed, 29 Jan 2020 20:20:32 +0000 Message-Id: <20200129202034.15052-11-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200129202034.15052-1-liuwe@microsoft.com> References: <20200129202034.15052-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 10/12] 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_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é --- 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 --- xen/arch/x86/guest/hyperv/hyperv.c | 31 +++++++++++++++++++++++++++++ xen/arch/x86/guest/hyperv/private.h | 29 +++++++++++++++++++++++++++ 2 files changed, 60 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 4387b6541e..f0facccbad 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_pcpu_input_page); static uint64_t generate_guest_id(void) { @@ -127,14 +130,42 @@ static void __init setup_hypercall_page(void) } } +static int setup_hypercall_pcpu_arg(void) +{ + void *mapping; + + if ( this_cpu(hv_pcpu_input_page) ) + return 0; + + mapping = alloc_xenheap_page(); + if ( !mapping ) + { + printk("Failed to allocate hypercall input page for CPU%u\n", + smp_processor_id()); + return -ENOMEM; + } + + this_cpu(hv_pcpu_input_page) = mapping; + + return 0; +} + static void __init setup(void) { setup_hypercall_page(); + if ( setup_hypercall_pcpu_arg() ) + panic("Hypercall percpu arg setup failed\n"); +} + +static int ap_setup(void) +{ + return setup_hypercall_pcpu_arg(); } static const struct hypervisor_ops ops = { .name = "Hyper-V", .setup = setup, + .ap_setup = ap_setup, }; static void __maybe_unused build_assertions(void) diff --git a/xen/arch/x86/guest/hyperv/private.h b/xen/arch/x86/guest/hyperv/private.h new file mode 100644 index 0000000000..a339274985 --- /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_pcpu_input_page); + +#endif /* __XEN_HYPERV_PRIVIATE_H__ */ From patchwork Wed Jan 29 20:20:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11356795 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 41788159A for ; Wed, 29 Jan 2020 20:22: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 1E68020716 for ; Wed, 29 Jan 2020 20:22: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="f0PScuK5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1E68020716 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 1iwtqA-0006wV-Gl; Wed, 29 Jan 2020 20:21:34 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iwtqA-0006w6-0Z for xen-devel@lists.xenproject.org; Wed, 29 Jan 2020 20:21:34 +0000 X-Inumbo-ID: d6ac66fe-42d4-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 d6ac66fe-42d4-11ea-8396-bc764e2007e4; Wed, 29 Jan 2020 20:20:49 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id k11so1024681wrd.9 for ; Wed, 29 Jan 2020 12:20:49 -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=9g3iTQhv4DyHzwGgjHdIef6GauOsAtk67e0Cyiz0EQw=; b=f0PScuK5w4yGOs6U+IObwEnYCSaWM9BSUS5EJ/TVYFueKkgOcLlZTnUhZqozYejssr i3EQ/NX0qI2zc27HvqhQXJ4XgzU6uEFGF+gLBbveCMSMmoJoA5rZ80ksZsMujPM2MCtR A9WQkmSfpS+FfljjBMPfY3krGc+yd8jtPAVVGEefmCtGjaNO07kZoAl5JABb1BbIj80d /C8Ee9iZ1eyDEZKS2WyfxMMJa9XPbUmTFVqKjapQ4/tih4VPorHZdffcJtVe8KF5GNhY oLiJoALiBJI7xWN3fYtkObxBzRDIT88dbVBoTCpRa9nxiLg0aLb5Vq+PoTAerJUVC7RK FkRw== 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=9g3iTQhv4DyHzwGgjHdIef6GauOsAtk67e0Cyiz0EQw=; b=cPwAMgYFJac0AGnKrs50aGyw1royZSezbS6b+MCewi2lTAqU1cdCVkXK2EPFq7nmrl Bkbyqzmb5GmCE1laI8Qx/qlzdr91PJJb9uh2ejlUVI1/rPi8hO0SxRgLFRfrUKfyJYLK KIcNwnc+/IKQ6qwX9d0R1zDU3sJjzdcyA/48Kx5RFQ/7ZTt4QnwTB2nOwQGnQZelK2HE ytKS5xObcrZ/PsUV8hCo4HC3g2P2Cef2kXstWxvKMhAu2zYgN+paSyJ7Up9OS6vBWqhN JAgDcgUkzOEEAFjR2yRsyFe2F4QY0DmHqJ/H2Nb7e7uMY3vgJQPVqSt5YfL7cARJDqf2 0CBQ== X-Gm-Message-State: APjAAAWZ/36xy48U3hVSJIpo3EBEPouf5bLM5J4y0bfF2XrtzJ1cYE4a 1zRhTijEaMPJGM2NMsgYN9E5Kxi68wc= X-Google-Smtp-Source: APXvYqwp6kymbHNPC8nm/01CpwpfI7w1ecgBosM7fI+t2uwImDdGy8S/3Qs1fx9uYKW9TY2NiY/FGw== X-Received: by 2002:a5d:6406:: with SMTP id z6mr618262wru.294.1580329248522; Wed, 29 Jan 2020 12:20: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 a22sm3564115wmd.20.2020.01.29.12.20.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2020 12:20:48 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Wed, 29 Jan 2020 20:20:33 +0000 Message-Id: <20200129202034.15052-12-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200129202034.15052-1-liuwe@microsoft.com> References: <20200129202034.15052-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 11/12] 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_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 | 5 +++++ xen/arch/x86/guest/hyperv/private.h | 1 + 2 files changed, 6 insertions(+) diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index f0facccbad..af0d6ed692 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_pcpu_input_page); +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, hv_vp_index); static uint64_t generate_guest_id(void) { @@ -133,6 +134,7 @@ static void __init setup_hypercall_page(void) static int setup_hypercall_pcpu_arg(void) { void *mapping; + uint64_t vp_index_msr; if ( this_cpu(hv_pcpu_input_page) ) return 0; @@ -147,6 +149,9 @@ static int setup_hypercall_pcpu_arg(void) this_cpu(hv_pcpu_input_page) = mapping; + 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 a339274985..c1c2431eff 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_pcpu_input_page); +DECLARE_PER_CPU(unsigned int, hv_vp_index); #endif /* __XEN_HYPERV_PRIVIATE_H__ */ From patchwork Wed Jan 29 20:20:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11356793 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 1FB4214E3 for ; Wed, 29 Jan 2020 20:22: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 F09ED20702 for ; Wed, 29 Jan 2020 20:22:24 +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="cqrZ/HK5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F09ED20702 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 1iwtqF-00071c-Sn; Wed, 29 Jan 2020 20:21:39 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iwtqF-00070e-13 for xen-devel@lists.xenproject.org; Wed, 29 Jan 2020 20:21:39 +0000 X-Inumbo-ID: d73435f2-42d4-11ea-a933-bc764e2007e4 Received: from mail-wr1-x444.google.com (unknown [2a00:1450:4864:20::444]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d73435f2-42d4-11ea-a933-bc764e2007e4; Wed, 29 Jan 2020 20:20:50 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id z7so980299wrl.13 for ; Wed, 29 Jan 2020 12:20:50 -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=Rh3eILGi6Pt9jrhFdjXvi2DHTn3SFwkuAe2IR7Kx73I=; b=cqrZ/HK5s+9C95BpQsykUZBvq8Jcim3QbrSzcndE9FH3xdhaBPs4L6BJmoYJC3d7/Z Dbt4ztw6r5vPp4gvUbTqUBGIJoXQe46JUs5QtwE57SNpd0vjaPG3ezrmD6N+1KFqGkFE QiAjcCnseqzi4eWf4VXCaJPTfBXBnAtdox4S534yJOPCp7f/fKZcIzqgV3jbbw8Xap4L 6Cz7OFPifeLBMuDlG9q7jhMyLnD3pphXpONedrCx+/7vzXg0LAjJd2xIuwxF6eEVMEAc MjZto6Qrr6FCq7cFGPproX+qabF/vC8gpbal49qxWjSTIkGJWidrqFBq92dPNjQHzQg4 F45w== 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=Rh3eILGi6Pt9jrhFdjXvi2DHTn3SFwkuAe2IR7Kx73I=; b=EGhzElnZaiV2zHBpbPz+7YMISLfR/KNTr7N5nQtVt3+rPUhS4l3ntCy+h1kKdKYSfZ gh6Gpx0jkfV2inkQlZEpZ58LhikjYALsRfLhy4eHPGPe6Iaf9Pv6kSkRpbIvbyw7N7OT TN0QDnE6Ydkk8XtiGSaRrwIcc3DEi2gfZyJ7hYGpTaH/i7QqOrsP3mU32yKyraPXhjgv tuzF9ZeUUHi8fXmRCZ68+PyffoF3AR92hgO0rrSPX7unR/8SJRH2+SWDOTnc7/ibz7w7 hI6AXVsC1UVPJ+Fh5/eX2oYSHd63/wtprxztMD4rla3ibeiVLUUwiFpA84TJHPOzoDzZ WFCg== X-Gm-Message-State: APjAAAWe34p14xD+fTju20EaTM2IKN7jV+NyI38zQQE6dx1qW1AUOxfb vst+NkCbrTUNnFjDdywIBSMDpnUvnBk= X-Google-Smtp-Source: APXvYqwijMIDoAbcJTodCytjbe3qLDZnoi+0PHbIxiYk2xgC9j6ATtj966TGNyNQzCsXnfAc91IACg== X-Received: by 2002:a5d:6144:: with SMTP id y4mr552432wrt.367.1580329249422; Wed, 29 Jan 2020 12:20:49 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id a22sm3564115wmd.20.2020.01.29.12.20.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2020 12:20:49 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Wed, 29 Jan 2020 20:20:34 +0000 Message-Id: <20200129202034.15052-13-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200129202034.15052-1-liuwe@microsoft.com> References: <20200129202034.15052-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 12/12] 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_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 --- 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 | 44 ++++++++++++++++++++++++++++- xen/arch/x86/guest/hyperv/private.h | 1 + 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index af0d6ed692..bc40a3d338 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_pcpu_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,16 +156,57 @@ static int setup_hypercall_pcpu_arg(void) return 0; } +static int setup_vp_assist(void) +{ + void *mapping; + uint64_t val; + + mapping = this_cpu(hv_vp_assist); + + if ( !mapping ) + { + mapping = alloc_xenheap_page(); + if ( !mapping ) + { + printk("Failed to allocate vp_assist page for CPU%u\n", + smp_processor_id()); + return -ENOMEM; + } + + clear_page(mapping); + this_cpu(hv_vp_assist) = mapping; + } + + val = (virt_to_mfn(mapping) << HV_HYP_PAGE_SHIFT) + | HV_X64_MSR_VP_ASSIST_PAGE_ENABLE; + wrmsrl(HV_X64_MSR_VP_ASSIST_PAGE, val); + + return 0; +} + static void __init setup(void) { setup_hypercall_page(); + if ( setup_hypercall_pcpu_arg() ) panic("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 ) + goto out; + + rc = setup_vp_assist(); + + out: + return rc; } static const struct hypervisor_ops ops = { diff --git a/xen/arch/x86/guest/hyperv/private.h b/xen/arch/x86/guest/hyperv/private.h index c1c2431eff..fcddc47544 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_pcpu_input_page); +DECLARE_PER_CPU(void *, hv_vp_assist); DECLARE_PER_CPU(unsigned int, hv_vp_index); #endif /* __XEN_HYPERV_PRIVIATE_H__ */