Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp4623244rwb; Mon, 31 Jul 2023 09:33:17 -0700 (PDT) X-Google-Smtp-Source: APBJJlF8MiOBE556OgcTemF+oQsvv/TW/ssNEWwW6BkqMMe0Im006ep6/t4ZypOzLyex4j/QCSyu X-Received: by 2002:a05:6a00:228f:b0:687:4de3:d6f7 with SMTP id f15-20020a056a00228f00b006874de3d6f7mr780346pfe.20.1690821197307; Mon, 31 Jul 2023 09:33:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690821197; cv=none; d=google.com; s=arc-20160816; b=Bd6l3+S5XAs7Y5hjyHvVk9dclAgh0VVhOpo2lUEOwjeflAK1V6TDBls6kacQr9cryr +ZwfwzFRYTr9wtLR5nCjepwLXf8VDiHzT5ZH8NVcKtQuGjOkKsQC2cBbVink1xv9w0tN PHLh9nvPabnTaLek1/XwiLqDajnYN6upcIxGrCEO11OuzYiPH7m6zhbHn54EW1KZLTc5 8iHJb1w9BErRR2aPs21/0FVBWZ5uB8tqk9UYI4WRBUJXO4EyRDqfUcKNqjkk+oYDNXJk zEmf2GWiJeNjtieMEZqfK+RX2t/p5CTVdu9ROOjCWx1DrIiQRW80e/w9EZwMnDiKn+hl 3OdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id :dkim-signature; bh=vFtCHrIgigSbtoNV1mnQVn3W557qU3XL1eHMMQCtsxQ=; fh=fjKDo8egD8mhAo6o9u3RgWMgjG4TM/7OwX+fd9bWAKs=; b=YIETHkbY6aQIw92M0sE1YV4Lg4MVnD1FRdGRSFn63CMqEAqNaeICl/mmDC5y87Q0dr dvOxekfZ2u9TcW4rfw/WpSncubTtQarZ2NytQkz2eGUmML2yy59rvxiTX8vYx/nsiyXC DwUVgIm2/ne85BAQOISxaae2FSEtLC/ed2Dt+lFj63keCPp9+deYjT8jJSznOhW1QWG+ G6xtRXS0nj3l1qMs5h8Scm9xEF4trLzD8DIiRjeyAn/3QkqcdWQNltb0Wa0vC2tLgShi ZE99MJ4EQpQqc3wDwgIsuHkTKPYfi5G0bGld6aE2QxnYlCjZfQh1BVr+V7HKR7aJ/NOx FyZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mail.ustc.edu.cn header.s=dkim header.b=PnDU1Xgf; 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 n25-20020aa79059000000b0067dd7254cb0si7308539pfo.39.2023.07.31.09.33.02; Mon, 31 Jul 2023 09:33:17 -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=PnDU1Xgf; 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 S232365AbjGaPpv (ORCPT + 99 others); Mon, 31 Jul 2023 11:45:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229570AbjGaPpt (ORCPT ); Mon, 31 Jul 2023 11:45:49 -0400 Received: from ustc.edu.cn (email.ustc.edu.cn [IPv6:2001:da8:d800::8]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 988BE170A; Mon, 31 Jul 2023 08:45:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mail.ustc.edu.cn; s=dkim; h=Received:Message-ID:Date: MIME-Version:User-Agent:Subject:To:Cc:References:From: In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=vFtCHrIgi gSbtoNV1mnQVn3W557qU3XL1eHMMQCtsxQ=; b=PnDU1XgfaWjFE0R/iRY8ZcwRU PjF2z+Wk29ng5gv49OSFr41GNTf65fqJWqn7Huyen1+xoHtIeLwBZAF6xoTxNxRZ 0jGAyVnVPUc2GFTo2bDCnab2avuPJu9z69eqpWqf3CDIcZHRF4uR9A4XexwkYqIW h5ePxnbDqU1FyLL47w= Received: from [192.168.199.152] (unknown [180.158.176.68]) by newmailweb.ustc.edu.cn (Coremail) with SMTP id LkAmygDHNJAZ18dkdd_iAA--.31594S2; Mon, 31 Jul 2023 23:45:29 +0800 (CST) Message-ID: <544b7f95-4b34-654d-a57b-3791a6f4fd5f@mail.ustc.edu.cn> Date: Mon, 31 Jul 2023 23:45:29 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [Question] int3 instruction generates a #UD in SEV VM To: Tom Lendacky , Sean Christopherson Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, x86@kernel.org, linux-coco@lists.linux.dev References: <8eb933fd-2cf3-d7a9-32fe-2a1d82eac42a@mail.ustc.edu.cn> <4ebb3e20-a043-8ad3-ef6c-f64c2443412c@amd.com> From: wuzongyong In-Reply-To: <4ebb3e20-a043-8ad3-ef6c-f64c2443412c@amd.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-CM-TRANSID: LkAmygDHNJAZ18dkdd_iAA--.31594S2 X-Coremail-Antispam: 1UD129KBjvJXoW7ZF1fJrWxWw1kAF1kCryxuFg_yoW8uFy7pF Z7ta4YyFsrGr1kAr12yr48Za4Fv39xJFsrXrn8J3s8AayUZas2gFW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T_LINE 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 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. > > Thanks, > Tom > >> >> [*] https://lore.kernel.org/all/ZMFd5kkehlkIfnBA@google.com