Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4137807pxv; Mon, 26 Jul 2021 22:56:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfdCLEVzoM0Bkqmxt/Gu0xD+dHtfFTdMPDTeAW1tYMUbkP8zT/HajewLxYZVG/uPtbwy4r X-Received: by 2002:a02:380c:: with SMTP id b12mr19890894jaa.68.1627365418486; Mon, 26 Jul 2021 22:56:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1627365418; cv=pass; d=google.com; s=arc-20160816; b=ObhDAXDLyQDKdOQXwNfA+Gk2TJnifRionQhMqxa+17ACdAEc6Zcwh1EoCSUIjyGqCc w7IY6UzOJkf2evouosmDySk5OiRFj2KASQ75OMrMaknQPwS3HRD8rSnYK87kDCSvC9It /UirJLmb9FS/oEkX2E6utABK2WdBdnIMRCAyNDWcOTz4zU9OY4lAYX061355dCrNqRn6 ckuPs7v2FwyTMoYuvW9PKt6xUeZ/uneai1+YnQ04xs8QoImVdmPPHnqd5GC0fG0FJsfM ZYsFCfAQFB4h+AHe0184N3mvVcE6xlrUxHHxqwMiVrEZ9iCq4C/gyAX3LqOmZ701OFTy GCVQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:wdcipoutbound:mime-version :content-transfer-encoding:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-signature; bh=2QB9qLbdPYwWtHU4whXnsAgVXdk/CityJKrJVZG8nBs=; b=duKDeeW3b/2gwqo9+J2u+52Ol/2rC6ykMWOogzOha0RgvCcwdb7jKIHAHFBO03gC0f LONEZt/VGEXjU4VLgG5fGb2Mwew7KOy0VWikVK0m96uvMHgQiGJ5Is4yUPvewwxk8Fm9 69l0KmiFjGN6RWWOtoLC5ev2eiFzl/tyI8HlxFr6yubiUvmJvjxHfA0bCQ5tATWy710U 1fhLhbNk0tiJBxCVediL6gQMWdY7uazr0NuRmyIUYBsDryOHVsV8mE/c+NgOkFw3LvCl r+esJY27NbxLdPRhjFWyBBuwkIYoMYxSAIHsdlXxYfJkQqOVzbolPoZZ+E8pG/0o282v dvJA== ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=J2sPF57n; dkim=pass header.i=@sharedspace.onmicrosoft.com header.s=selector2-sharedspace-onmicrosoft-com header.b=K1sIc4cC; arc=pass (i=1 spf=pass spfdomain=wdc.com dkim=pass dkdomain=wdc.com dmarc=pass fromdomain=wdc.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b8si2322649jav.94.2021.07.26.22.56.46; Mon, 26 Jul 2021 22:56:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=J2sPF57n; dkim=pass header.i=@sharedspace.onmicrosoft.com header.s=selector2-sharedspace-onmicrosoft-com header.b=K1sIc4cC; arc=pass (i=1 spf=pass spfdomain=wdc.com dkim=pass dkdomain=wdc.com dmarc=pass fromdomain=wdc.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235537AbhG0Fzm (ORCPT + 99 others); Tue, 27 Jul 2021 01:55:42 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:33012 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235440AbhG0Fza (ORCPT ); Tue, 27 Jul 2021 01:55:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1627365330; x=1658901330; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=4op3gDfyuIjX7mZXswjaAB1urPk+E5h0NC5D/eVt23Y=; b=J2sPF57nX9zV9f216vP7YRKpr3RoFCh8K4usCfyDZWl501avfN9omkxE Wrn12ZUn466b9ozP34pLQF/kXc8rPoePm7gRF5D7dn3cCjqaHmyayWlEz 5eCVUW+pb7nSBU1ATmVo+eSQq7UU+jor84nJMMJe8ucoJ/EXq6np7I88z ZhQXDk7Z7AiAiwSWHah9OQZmFgwGkdmzdf1gRC47N5fyTl8SPVq/Jf0nG LwHkG+HfCq13H6zkBU3EnNH9ZuTZphZYN9O8RY6ieQzmgHdgXt4+IVy0t oXKamqdfhijvgfQThNY8U2IYPLS2UH9wxhxmsfiZmsTdN/TweuPTxY7R3 w==; X-IronPort-AV: E=Sophos;i="5.84,272,1620662400"; d="scan'208";a="180385866" Received: from mail-mw2nam12lp2043.outbound.protection.outlook.com (HELO NAM12-MW2-obe.outbound.protection.outlook.com) ([104.47.66.43]) by ob1.hgst.iphmx.com with ESMTP; 27 Jul 2021 13:55:30 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LxZ0Jp18MFTrXSRPeH9lgwXb/eSJDC3Zq0gbq0pg7Hib4qltTjlt3NAzkR7iUZU5nByYqWTHzZykPHipuujBUz4u48mNHnvmafXX/E1d9oD07T1zIcop49bCPZuWmiauK+h0wtl+7aNZ83F3m8hdH2AJVVhj9OomH4Dl8UxMIOxZKWuaxSkumse1cXFgS8x+limblA7eSUAOhnGfsjT/W2XJB341DSRPaLB599/xIkSJn5lZePEnPUl6Y54NbwgmGA2BXhkU2vmv8wANxHtJ5sMEWTB9V737GnBgOhXwHR2TV/bwjUM95HpUd/KWCJzZJB1+Yh2+HhZxZNB5ximPXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2QB9qLbdPYwWtHU4whXnsAgVXdk/CityJKrJVZG8nBs=; b=gbeVAFW6pc9VlxeVPLGSYkcrDs+Pk62uw+JCV+NknoMNONtBdeKm05mpHSgj0HfUTQM2g5TE4S2xeSirdLuLney+rDyUYxinAV7972nRP7dl6n7AipoG9/oGEMKLvwuK39mwZX7MZBkYzsGhbTn0BRF0TXL0EgAMAUm7QqQ47embmFG8gvbUFKKxjGpiPkGC45FmgCT4NogP3oZi74DdgwnWIjfT9yH8KGAfRUSpp1vJo6R1qvW00SofNdDki98i2hvU+47W2wMJeK+sGajshnUw2aQQIdqgdcQ1sPWfjTA6xQSGksuRtViPiC816a0OExp2vlcb2K2DIin7Ip7Vhw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wdc.com; dmarc=pass action=none header.from=wdc.com; dkim=pass header.d=wdc.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector2-sharedspace-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2QB9qLbdPYwWtHU4whXnsAgVXdk/CityJKrJVZG8nBs=; b=K1sIc4cCMYtIn2i8uqTMjpQiR9kDwmCcPt5SIPyIzr5Axzp6q5QVNnD1GrFvQIGnxmdJYTWLRdqK8tjqZp7jjKtGsNNLANm4enrb5GhvN41Aviw+G8ikkFOpeuN/E2cI/6VDGO9hIzn71fVjAyCQHsZpDVMDhn5oCJCbU6C5qcQ= Authentication-Results: dabbelt.com; dkim=none (message not signed) header.d=none;dabbelt.com; dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO6PR04MB8377.namprd04.prod.outlook.com (2603:10b6:303:140::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.29; Tue, 27 Jul 2021 05:55:30 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::a153:b7f8:c87f:89f8]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::a153:b7f8:c87f:89f8%8]) with mapi id 15.20.4352.031; Tue, 27 Jul 2021 05:55:30 +0000 From: Anup Patel To: Palmer Dabbelt , Palmer Dabbelt , Paul Walmsley , Albert Ou , Paolo Bonzini Cc: Alexander Graf , Atish Patra , Alistair Francis , Damien Le Moal , Anup Patel , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel Subject: [PATCH v19 03/17] RISC-V: KVM: Implement VCPU create, init and destroy functions Date: Tue, 27 Jul 2021 11:24:36 +0530 Message-Id: <20210727055450.2742868-4-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210727055450.2742868-1-anup.patel@wdc.com> References: <20210727055450.2742868-1-anup.patel@wdc.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: MA1PR0101CA0030.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::16) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from wdc.com (122.171.179.229) by MA1PR0101CA0030.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.26 via Frontend Transport; Tue, 27 Jul 2021 05:55:26 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 62c785d1-9545-4556-31a5-08d950c323e2 X-MS-TrafficTypeDiagnostic: CO6PR04MB8377: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:1284; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WWRajYwdRrJDWDtWzHWV31wT6nz0/fsr7JxsQnlD+osLLYShzFlxm/b5VSXDyPhon0z1YwcJLywJzaDn2X7DsV4Y+pYTt5XP0AfhvaPwJ0UZ4r69g8Pg/wFHShz2Tx/5l9UVVihK0J00Ss5THTLGGQ4iI6Jmv48P6gP7ioQS0TzuL3pEaHsLLsUiCqtfqBLzRsS7c935Vrwqx8ueqYcq2LgYQc3A99hCqmPK8S1Ft9FtJrOqDAH8n0GCZC6WeepJNe1OAyDriqhREgtFpX3Y0gym9aa80JmKbReceF9Eja7xR3Le7cmRYfJdPwAZ/7Ey4UZrEA51EhaMjBxdlrKGUyRE8N++ARC7O/gNUTSYPcFpnpii8xf08bH73SqIOX+1k4oHkQOgy+rD6hqXj4NIh5kgbP6Bt2LTWX3b2Gdd8paHrVePFaOAO79aJ4cNouSe9oPb/bl85ek1300K1Xsu+7m2sL/X43glUse1dhd3N39VNM+vPHtkcy5iu/GY+NvPtR4kRGLLqYkZLzKePyU8ppH7KZMs9/B86vced3f9oDuKlTPgeks407ALJ4X5tjvjPwBDcqgc/s68tpfFv7VI9t18yDYB8UtY2dB5b5o0eOPKgh6nMPNjkDlklUBoQ3paQ0GJOfRzTloF/CbJC7Yin5QJA+0jB0FPH+HpIEuPRIQEfUtGXfiGPIzescosT16o X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CO6PR04MB7812.namprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(7696005)(52116002)(26005)(66946007)(54906003)(5660300002)(6666004)(956004)(2616005)(8936002)(186003)(38100700002)(316002)(36756003)(508600001)(8886007)(7416002)(66476007)(2906002)(1076003)(110136005)(86362001)(44832011)(83380400001)(8676002)(4326008)(66556008)(55016002)(38350700002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?/O+FQvqU2IGww6Q1E6t0wkfdv/qQfswc7HmpAS9i2bGFnm7tJ+bQgUTWpass?= =?us-ascii?Q?ZIuptbMIzNi3cBVRVwBxbyByOXfM/UGmQPuzHa7O/Mhc9eo6Z5sZ57ubjoXc?= =?us-ascii?Q?XIAAln1NXFJOhsnrsf46/ZLDwY4Akj1o7PuCzwnqmXHzVONJ+AN1yAe3bDSa?= =?us-ascii?Q?wHhCFFfAP5LytB8UwttPI9gc57RRt85M/iAwXPcI6SX/+u7mOIre+4GvNqgT?= =?us-ascii?Q?IM4z292IrumpRJdwZit3+m7vZGIib+pFo0XYlozG56jfHV1ZMH1LzFdBLQOG?= =?us-ascii?Q?AbgJCEYemsArQ0l2TPyt/IGgygwr7wpdqoCacvbCL5WUM5aD+m7oDPM9vihz?= =?us-ascii?Q?tgMXPw5wNuYsaASCVCkfaLYoL01VSrKgt4FM/4k6fCLl71DM1Zi67BDjSygf?= =?us-ascii?Q?mHqwBpAoJCSSB712izcAYlC1nyahl6j7w2M5eR0Ntjwgn2nguc3a2WIhy7Z7?= =?us-ascii?Q?LWA41SDOaAaVIkAE64Yij0Wsyqqh+XZ+JGrSnt8u9uJ+hF6VIZhYPn26wkMn?= =?us-ascii?Q?7W5Dd091474nPvUJIkOGvaI70bAbCu73EQddl1cUmSOsIFNu1pIbK1Kwa9XX?= =?us-ascii?Q?svCxUzkICICstWy/dzQ9sdT83bBlY0d3YbpKDfCy+hdz6T+EJXaTf6lcUtKV?= =?us-ascii?Q?DHWtakFrXpC0yHdYeI0xUfxX5po6mD6q10hSBq7VlLg16w9iMFCqEJiBGD9s?= =?us-ascii?Q?JhD1VEB4uRpu/t0FSR1oLkgn1UZNPjKvS2PXoJTRaNGPZAg+aPYLX0T3nqYv?= =?us-ascii?Q?2mGjz+vFPdHUh9Mt8/huGLUrfdV2lohxhR/owtanbhU2s+WIZJ4hX0qEqCFe?= =?us-ascii?Q?61Tl/o3xr6tb/PDFE80f0FVeOQ3n5SLpx79Dm1MQojPjx9uyOisqCEFfyAHX?= =?us-ascii?Q?4UhgP6VeW0TqQtt58DAJHLDgKmdQ4i9I7iKju8wODY2+9TWlfhrGhgSXah9c?= =?us-ascii?Q?11eD6G0UkGjxhH0fTImcaPwIj9klyrKIiDiRZJMX1RyAurwSn5KBQlZoiRoU?= =?us-ascii?Q?X5blgooDz0ICu1ROHYSUOEKVyFZ05Mjn/PeS3TaXtP2o8p5epvEcIB5o9Yt1?= =?us-ascii?Q?hlSKlr5+rbDS0Q57WLxZm7xnbE46/exUQcK5SWchn58ontQGxqfgGnkyi4ui?= =?us-ascii?Q?+rMDyPdUUfxVl/s2M0Mu1rNdmMS2AiROlQ4b70isXwpSB1Z9OWHmoMn5w0XQ?= =?us-ascii?Q?UN5tQIWQTUrlusAxPX1DMj6zE3g4HmifJ4VlcCqMPdetGtADGXeAQ4HokKBv?= =?us-ascii?Q?Vn9gOV1gtOdyddJTlycamS33wzY6bPeioguJvJlORAElg4P12qzKqeCRTr4m?= =?us-ascii?Q?fzxOY8f4euWkR8XRKePkUNdW?= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 62c785d1-9545-4556-31a5-08d950c323e2 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2021 05:55:30.1950 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: DjfBBBOHBmmO68wTeF6Re7goOeVvRLW/XYziL2R2/TiPNt/+FzvsBuik4Q484xMTMrEaL2686m+AWiU9zlVsdw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8377 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch implements VCPU create, init and destroy functions required by generic KVM module. We don't have much dynamic resources in struct kvm_vcpu_arch so these functions are quite simple for KVM RISC-V. Signed-off-by: Anup Patel Acked-by: Paolo Bonzini Reviewed-by: Paolo Bonzini Reviewed-by: Alexander Graf --- arch/riscv/include/asm/kvm_host.h | 69 +++++++++++++++++++++++++++++++ arch/riscv/kvm/vcpu.c | 55 ++++++++++++++++++++---- 2 files changed, 115 insertions(+), 9 deletions(-) diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h index 08a8f53bf814..5fd969bd3bfd 100644 --- a/arch/riscv/include/asm/kvm_host.h +++ b/arch/riscv/include/asm/kvm_host.h @@ -57,7 +57,76 @@ struct kvm_cpu_trap { unsigned long htinst; }; +struct kvm_cpu_context { + unsigned long zero; + unsigned long ra; + unsigned long sp; + unsigned long gp; + unsigned long tp; + unsigned long t0; + unsigned long t1; + unsigned long t2; + unsigned long s0; + unsigned long s1; + unsigned long a0; + unsigned long a1; + unsigned long a2; + unsigned long a3; + unsigned long a4; + unsigned long a5; + unsigned long a6; + unsigned long a7; + unsigned long s2; + unsigned long s3; + unsigned long s4; + unsigned long s5; + unsigned long s6; + unsigned long s7; + unsigned long s8; + unsigned long s9; + unsigned long s10; + unsigned long s11; + unsigned long t3; + unsigned long t4; + unsigned long t5; + unsigned long t6; + unsigned long sepc; + unsigned long sstatus; + unsigned long hstatus; +}; + +struct kvm_vcpu_csr { + unsigned long vsstatus; + unsigned long hie; + unsigned long vstvec; + unsigned long vsscratch; + unsigned long vsepc; + unsigned long vscause; + unsigned long vstval; + unsigned long hvip; + unsigned long vsatp; + unsigned long scounteren; +}; + struct kvm_vcpu_arch { + /* VCPU ran at least once */ + bool ran_atleast_once; + + /* ISA feature bits (similar to MISA) */ + unsigned long isa; + + /* CPU context of Guest VCPU */ + struct kvm_cpu_context guest_context; + + /* CPU CSR context of Guest VCPU */ + struct kvm_vcpu_csr guest_csr; + + /* CPU context upon Guest VCPU reset */ + struct kvm_cpu_context guest_reset_context; + + /* CPU CSR context upon Guest VCPU reset */ + struct kvm_vcpu_csr guest_reset_csr; + /* Don't run the VCPU (blocked) */ bool pause; diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index 299442c4a988..eef6b772c6e2 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -40,6 +40,27 @@ const struct kvm_stats_header kvm_vcpu_stats_header = { sizeof(kvm_vcpu_stats_desc), }; +#define KVM_RISCV_ISA_ALLOWED (riscv_isa_extension_mask(a) | \ + riscv_isa_extension_mask(c) | \ + riscv_isa_extension_mask(d) | \ + riscv_isa_extension_mask(f) | \ + riscv_isa_extension_mask(i) | \ + riscv_isa_extension_mask(m) | \ + riscv_isa_extension_mask(s) | \ + riscv_isa_extension_mask(u)) + +static void kvm_riscv_reset_vcpu(struct kvm_vcpu *vcpu) +{ + struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr; + struct kvm_vcpu_csr *reset_csr = &vcpu->arch.guest_reset_csr; + struct kvm_cpu_context *cntx = &vcpu->arch.guest_context; + struct kvm_cpu_context *reset_cntx = &vcpu->arch.guest_reset_context; + + memcpy(csr, reset_csr, sizeof(*csr)); + + memcpy(cntx, reset_cntx, sizeof(*cntx)); +} + int kvm_arch_vcpu_precreate(struct kvm *kvm, unsigned int id) { return 0; @@ -47,7 +68,25 @@ int kvm_arch_vcpu_precreate(struct kvm *kvm, unsigned int id) int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu) { - /* TODO: */ + struct kvm_cpu_context *cntx; + + /* Mark this VCPU never ran */ + vcpu->arch.ran_atleast_once = false; + + /* Setup ISA features available to VCPU */ + vcpu->arch.isa = riscv_isa_extension_base(NULL) & KVM_RISCV_ISA_ALLOWED; + + /* Setup reset state of shadow SSTATUS and HSTATUS CSRs */ + cntx = &vcpu->arch.guest_reset_context; + cntx->sstatus = SR_SPP | SR_SPIE; + cntx->hstatus = 0; + cntx->hstatus |= HSTATUS_VTW; + cntx->hstatus |= HSTATUS_SPVP; + cntx->hstatus |= HSTATUS_SPV; + + /* Reset VCPU */ + kvm_riscv_reset_vcpu(vcpu); + return 0; } @@ -55,15 +94,10 @@ void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu) { } -int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu) -{ - /* TODO: */ - return 0; -} - void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu) { - /* TODO: */ + /* Flush the pages pre-allocated for Stage2 page table mappings */ + kvm_riscv_stage2_flush_cache(vcpu); } int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu) @@ -199,6 +233,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) struct kvm_cpu_trap trap; struct kvm_run *run = vcpu->run; + /* Mark this VCPU ran at least once */ + vcpu->arch.ran_atleast_once = true; + vcpu->arch.srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); /* Process MMIO value returned from user-space */ @@ -272,7 +309,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) * get an interrupt between __kvm_riscv_switch_to() and * local_irq_enable() which can potentially change CSRs. */ - trap.sepc = 0; + trap.sepc = vcpu->arch.guest_context.sepc; trap.scause = csr_read(CSR_SCAUSE); trap.stval = csr_read(CSR_STVAL); trap.htval = csr_read(CSR_HTVAL); -- 2.25.1