From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 75BE6275858 for ; Thu, 26 Jun 2025 11:40:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750938028; cv=none; b=neNwZnhZnR+ZqxhSse2c6BK7z/iVutn74AvLy+ifhLTC6LeiFvlYi0xwuUdK00bwlJleUDkPi4ufsdOPjEYfx+Uy+w0NAu4BnpTWVD45GmcPYnk7K+WOl8N+ZHNtckso1RM1wa3SxpA3o8RuhF7+mRLS2552RcGHNtHtTTlxqrk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750938028; c=relaxed/simple; bh=oNvwLB2lfGqrrR8EvkRE6amHYGzvK/WygnHnRd4gKNY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U+PSzHZ8NATdGnZmLNvNF4eFGyyYdKNQqjrjoMfmUuBGVm8I6asVRrxkYC/bv3G9KkGn/LztDY7vXwl8v3Cr0mkKqoJWk+Idd7eP6I22YMPaXTGWDgtjYyEny1/SP8W1lw9ROtquBi+a/YF2dayil2AVFM/onmDrmTghTeYQNwU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=QF+ducAg; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="QF+ducAg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1750938024; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=88TPU2dHD1DbKiB3ujBOs3Z/qPWIjWIwUGPUy1mGrV0=; b=QF+ducAgh4rDwCxvkv3d6yd/NV2zmn8m7WII7DaDFmng4PDfDP0lEMf5M6msNuJfqUK4aN FiStRU8+xxsHIvE6HYPHQQ0yzLgyfepq59AgWtljxAQ3MWjw1Zmybf6VDN4UpAzYiEnDHF AVNPkk4uFr9iyhtC7wAKvJK7zkyUoSA= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-557-cVHGdSxTPOSzEAxGMapT0Q-1; Thu, 26 Jun 2025 07:40:20 -0400 X-MC-Unique: cVHGdSxTPOSzEAxGMapT0Q-1 X-Mimecast-MFC-AGG-ID: cVHGdSxTPOSzEAxGMapT0Q_1750938019 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D89741800343; Thu, 26 Jun 2025 11:40:18 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.44.32.244]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 94B6D180045B; Thu, 26 Jun 2025 11:40:17 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 1E9F91800394; Thu, 26 Jun 2025 13:40:15 +0200 (CEST) From: Gerd Hoffmann To: linux-coco@lists.linux.dev, kvm@vger.kernel.org Cc: Gerd Hoffmann , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "H. Peter Anvin" , linux-kernel@vger.kernel.org (open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)) Subject: [PATCH v4 1/3] x86/sev/vc: fix efi runtime instruction emulation Date: Thu, 26 Jun 2025 13:40:11 +0200 Message-ID: <20250626114014.373748-2-kraxel@redhat.com> In-Reply-To: <20250626114014.373748-1-kraxel@redhat.com> References: <20250626114014.373748-1-kraxel@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 In case efi_mm is active go use the userspace instruction decoder which supports fetching instructions from active_mm. This is needed to make instruction emulation work for EFI runtime code, so it can use cpuid and rdmsr. EFI runtime code uses the cpuid instruction to gather information about the environment it is running in, such as SEV being enabled or not, and choose (if needed) the SEV code path for ioport access. EFI runtime code uses the rdmsr instruction to get the location of the CAA page (see SVSM spec, section 4.2 - "Post Boot"). The big picture behind this is that the kernel needs to be able to properly handle #VC exceptions that come from EFI runtime services. Since EFI runtime services have a special page table mapping for the EFI virtual address space, the efi_mm context must be used when decoding instructions during #VC handling. Signed-off-by: Gerd Hoffmann --- arch/x86/coco/sev/vc-handle.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/x86/coco/sev/vc-handle.c b/arch/x86/coco/sev/vc-handle.c index 0989d98da130..faf1fce89ed4 100644 --- a/arch/x86/coco/sev/vc-handle.c +++ b/arch/x86/coco/sev/vc-handle.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -178,9 +179,15 @@ static enum es_result __vc_decode_kern_insn(struct es_em_ctxt *ctxt) return ES_OK; } +/* + * User instruction decoding is also required for the EFI runtime. Even though + * the EFI runtime is running in kernel mode, it uses special EFI virtual + * address mappings that require the use of efi_mm to properly address and + * decode. + */ static enum es_result vc_decode_insn(struct es_em_ctxt *ctxt) { - if (user_mode(ctxt->regs)) + if (user_mode(ctxt->regs) || mm_is_efi(current->active_mm)) return __vc_decode_user_insn(ctxt); else return __vc_decode_kern_insn(ctxt); -- 2.50.0