Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp1005608rwo; Wed, 2 Aug 2023 07:26:05 -0700 (PDT) X-Google-Smtp-Source: APBJJlHbsy8xR09v1BvOIPprNkoZ9qaGjgRyy5i2UGcYTHXMKoFBEFawVnukUN/TiMkGrFqX1f5R X-Received: by 2002:a17:90b:3712:b0:262:e6d2:2d6 with SMTP id mg18-20020a17090b371200b00262e6d202d6mr16405675pjb.47.1690986364676; Wed, 02 Aug 2023 07:26:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690986364; cv=none; d=google.com; s=arc-20160816; b=iVnznlPHjJvJdb7sLtE54L1GNJKi0PfivFa+ePE9djoYa7kY/L8MomobHUBRFQnU/Z jNf66BZg0T5/Dcrv9oAekdTjnv2UPkfoBCLAT/3kieDUtDm9loNFBMrJPbzlMlI0oGrP c3GtIvJRcUsAA9EIvpQGJxZucXAuVPKMjCEo7YniH7q/eKcH0/k4lrsO1hElWd0FvRDz GQ2TzLoUe0z0T6yXSjTwb3v/D0g2qJTmNmg+ZEVzhUqBZlplLDvHW5oealSbdnKxsvbq 9INkFGKwNZrJbl1zqQ/HdJXJpSqXsWyFAAFFkOXyRX+mdvnFdTsyPgNtMnJO/2PKHKdB mMEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=msXnw5IG4jvKLMzQa2hmaHiEHyhnq8MqCAoMVYtLez8=; fh=CZZKBrk8G7yZJ9svFJoMuwc/zzI+O99nXnjwK1EqPJY=; b=Bt+Bzl5wri+loKWTupKmw7j2wWjnYiZRym71DpqVWgfW9LjVSuY1lsr3khpOwcbsdV zJ3Kx3/akyK4WeWxyse+Qxj4VUHksOf9L+QKQHUMwkfL/NaeIO5nxZMxu93v/5KB44xn L5d/eVEAlrv5FsA576lSOy3W/F0COLDOOE/XkZX1ZpZBcyDQT+Rt54z0kR58/nqwA3gy cKLj9o0u2WAt5b9pf1UB0oAx+52r8sZYvHAbLyqJ5hjSY9T3zFjOlqeUZ+kSj8ZCW2LJ iU4RG2fUXG72CUsxf35gnHKp7q93+LO98B13tnG31tq5C7kyH2beyQjNl++0BeRgyQVW 7jMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mail.ustc.edu.cn header.s=dkim header.b="vD/7w/cw"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mail.ustc.edu.cn Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h14-20020a17090a3d0e00b00252d84b7af0si1264303pjc.181.2023.08.02.07.25.41; Wed, 02 Aug 2023 07:26:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@mail.ustc.edu.cn header.s=dkim header.b="vD/7w/cw"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mail.ustc.edu.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233828AbjHBL4W (ORCPT + 99 others); Wed, 2 Aug 2023 07:56:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232126AbjHBL4V (ORCPT ); Wed, 2 Aug 2023 07:56:21 -0400 Received: from ustc.edu.cn (email.ustc.edu.cn [IPv6:2001:da8:d800::8]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E472E26B0; Wed, 2 Aug 2023 04:56:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mail.ustc.edu.cn; s=dkim; h=Received:Date:From:To:Cc:Subject: Message-ID:Reply-To:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; bh=msXnw5IG4jvKLMzQa2hmaHiEHyhn q8MqCAoMVYtLez8=; b=vD/7w/cwOmZ3edXHeLLoku0r7UxarQs0TgHNr6vfjbOb MavwZ+Xh04TxWTDwF9JLFH50mTDtrRMhgAI+0rf7TNlNIbDXDp2zhA4x2O/J5gEc 1VnpGNphY7VhaKAHy3tYxIzFKvWljEyWpPvjnWhWS9tOQOAYB0FJWxmvXa0Sbvo= Received: from localhost (unknown [139.224.204.105]) by newmailweb.ustc.edu.cn (Coremail) with SMTP id LkAmygBn1BxRRMpkBIUTAA--.3970S2; Wed, 02 Aug 2023 19:56:01 +0800 (CST) Date: Wed, 2 Aug 2023 19:56:01 +0800 From: Wu Zongyo To: Tom Lendacky , Sean Christopherson Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, x86@kernel.org, linux-coco@lists.linux.dev Subject: Re: [Question] int3 instruction generates a #UD in SEV VM Message-ID: Reply-To: Wu Zongyo References: <8eb933fd-2cf3-d7a9-32fe-2a1d82eac42a@mail.ustc.edu.cn> <4ebb3e20-a043-8ad3-ef6c-f64c2443412c@amd.com> <544b7f95-4b34-654d-a57b-3791a6f4fd5f@mail.ustc.edu.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <544b7f95-4b34-654d-a57b-3791a6f4fd5f@mail.ustc.edu.cn> X-CM-TRANSID: LkAmygBn1BxRRMpkBIUTAA--.3970S2 X-Coremail-Antispam: 1UD129KBjvJXoWxXr1xGw1kKFyfXw17Xr4Dtwb_yoW5Xry8pF WxK3ZIkrs7Jrn3Zr4Dta1UAryFya9xGr47Xr18J3s8A3s0v3Za9ryIkrZ0k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IBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 31, 2023 at 11:45:29PM +0800, wuzongyong wrote: > > On 2023/7/31 23:03, Tom Lendacky wrote: > > On 7/31/23 09:30, Sean Christopherson wrote: > >> On Sat, Jul 29, 2023, wuzongyong wrote: > >>> Hi, > >>> I am writing a firmware in Rust to support SEV based on project td-shim[1]. > >>> But when I create a SEV VM (just SEV, no SEV-ES and no SEV-SNP) with the firmware, > >>> the linux kernel crashed because the int3 instruction in int3_selftest() cause a > >>> #UD. > >> > >> ... > >> > >>> BTW, if a create a normal VM without SEV by qemu & OVMF, the int3 instruction always generates a > >>> #BP. > >>> So I am confused now about the behaviour of int3 instruction, could anyone help to explain the behaviour? > >>> Any suggestion is appreciated! > >> > >> Have you tried my suggestions from the other thread[*]? > Firstly, I'm sorry for sending muliple mails with the same content. I thought the mails I sent previously > didn't be sent successfully. > And let's talk the problem here. > >> > >> : > > I'm curious how this happend. I cannot find any condition that would > >> : > > cause the int3 instruction generate a #UD according to the AMD's spec. > >> : > >> : One possibility is that the value from memory that gets executed diverges from the > >> : value that is read out be the #UD handler, e.g. due to patching (doesn't seem to > >> : be the case in this test), stale cache/tlb entries, etc. > >> : > >> : > > BTW, it worked nomarlly with qemu and ovmf. > >> : > > >> : > Does this happen every time you boot the guest with your firmware? What > >> : > processor are you running on? > >> : > Yes, every time. > The processor I used is EPYC 7T83. > >> : And have you ruled out KVM as the culprit? I.e. verified that KVM is NOT injecting > >> : a #UD. That obviously shouldn't happen, but it should be easy to check via KVM > >> : tracepoints. > > > > I have a feeling that KVM is injecting the #UD, but it will take instrumenting KVM to see which path the #UD is being injected from. > > > > Wu Zongyo, can you add some instrumentation to figure that out if the trace points towards KVM injecting the #UD? > Ok, I will try to do that. You're right. The #UD is injected by KVM. The path I found is: svm_vcpu_run svm_complete_interrupts kvm_requeue_exception // vector = 3 kvm_make_request vcpu_enter_guest kvm_check_and_inject_events svm_inject_exception svm_update_soft_interrupt_rip __svm_skip_emulated_instruction x86_emulate_instruction svm_can_emulate_instruction kvm_queue_exception(vcpu, UD_VECTOR) Does this mean a #PF intercept occur when the guest try to deliver a #BP through the IDT? But why? Thanks > > > > Thanks, > > Tom > > > >> > >> [*] https://lore.kernel.org/all/ZMFd5kkehlkIfnBA@google.com