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.133.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 3367B2040AB for ; Mon, 2 Jun 2025 10:50:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748861461; cv=none; b=PTulIjxx8yOX0v9ZHr6+gxYMIH+x6SE26mp0voRNZZ2k3WLxpiH8fbm9cle40D4X8Ak2gz73Vk1SglSLzgNLt0TCnDuw07tWTnd1Tjik6cSGOxAY9bEoNp9nmBGV/Zs/uWtffOxHfRsZjsqgdY0pF8jEWMDFWwKPbbVOUhkooPU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748861461; c=relaxed/simple; bh=ILQSEnW/GjqVd/gxsMnNJ1HRnoEwz/XJrNQGydauf94=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Xh8uigwuBgqkjpvaMf80XYusVmN5U2QiRCeC9FaFejzd1cuu8nVVjYfxUECxvydL/s5nshbMcDNCKHeBmgTgJzobZ1LjfCkdM4KXbA7Wea59qiDZmYU6MPYdGxv0XdZF5hiPmk5oyxndsNYk2NiaPLW0tk9/0vbEas7bj6QNy9s= 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=Ut/IbH1s; arc=none smtp.client-ip=170.10.133.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="Ut/IbH1s" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748861459; 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=qm8T0wNFp6RwcZhPAwYUxESZ7xXlskOh08SMV4HZcMY=; b=Ut/IbH1sop7a/KcpWdvBM+YLC9unia2+NaebZWCrn0DZ8/MzKdrnxsUdyABSQgc9Of1T+q MzjyIpLx44JS01dtJC2m6GWasge4X8QlGFKlCprIfPKyjf1tUr21qrvasC9SZeost7mLIv w+Ol50YsvBnuqJvQU6m0n8xXf/g5sog= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-46-5d1eN0hJNhq2vJxsci_bOA-1; Mon, 02 Jun 2025 06:50:56 -0400 X-MC-Unique: 5d1eN0hJNhq2vJxsci_bOA-1 X-Mimecast-MFC-AGG-ID: 5d1eN0hJNhq2vJxsci_bOA_1748861454 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1BA92195609F; Mon, 2 Jun 2025 10:50:54 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.45.224.29]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2E62619560AB; Mon, 2 Jun 2025 10:50:52 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id C59841800634; Mon, 02 Jun 2025 12:50:50 +0200 (CEST) From: Gerd Hoffmann To: linux-coco@lists.linux.dev Cc: kvm@vger.kernel.org, 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 v2 1/2] x86/sev/vc: fix efi runtime instruction emulation Date: Mon, 2 Jun 2025 12:50:48 +0200 Message-ID: <20250602105050.1535272-2-kraxel@redhat.com> In-Reply-To: <20250602105050.1535272-1-kraxel@redhat.com> References: <20250602105050.1535272-1-kraxel@redhat.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 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"). Signed-off-by: Gerd Hoffmann --- arch/x86/coco/sev/vc-handle.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/coco/sev/vc-handle.c b/arch/x86/coco/sev/vc-handle.c index 0989d98da130..01c78182da88 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 @@ -180,7 +181,7 @@ static enum es_result __vc_decode_kern_insn(struct es_em_ctxt *ctxt) static enum es_result vc_decode_insn(struct es_em_ctxt *ctxt) { - if (user_mode(ctxt->regs)) + if (user_mode(ctxt->regs) || current->active_mm == &efi_mm) return __vc_decode_user_insn(ctxt); else return __vc_decode_kern_insn(ctxt); -- 2.49.0