Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp3022281rwo; Thu, 3 Aug 2023 20:28:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHT1c8q1iB/kUNBxzZ36KALG77oZ5O6myk4mEa4EcxC34PVoP+zGH4e+QGQvy9dR3kHE2gM X-Received: by 2002:a17:906:cc4a:b0:99b:6687:6107 with SMTP id mm10-20020a170906cc4a00b0099b66876107mr367467ejb.5.1691119721327; Thu, 03 Aug 2023 20:28:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691119721; cv=none; d=google.com; s=arc-20160816; b=shHYAYdMH9LGXURcIrnxfaZPNPyL0+Fa2x+5ZLqb0Pxsfx7UuITnpOIhIUI2CSbfXS mp/zjgf+AtYSw/At34Usm1CayKXI3O6P4MSDcfQz+yA5LpWB10MzHy7c4QuimGc2QL/F WPwGDkziD2uGSm0EQ1qggri1DVDixDRmImgsF48VCdH9cabrj6UnsykyG4eygyS08nn0 3NqMHhvVgHOatqV/wfsIG1Wwo3XUGZPCGj/J2K+4oCmc0sgeteG7v7aG+YMtwyt3VuD0 fspwhn5P/k+p2JeN2J2/h5e2/mlVaTHJnph/5PxxwisXw3zBB2gjjMBF3U/5cdUNqr3U SaUA== 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=EBhrcRFMBzAWOm64LZMJWLBVhYxmtGhdBvKAQ5lgBYE=; fh=005p6MixfUuBbt/4RSzBVGvIq9jNM3JZWnQ+Ve5nKOI=; b=CqwqYicKS0NvNLxsbRrgLq0os32LNM2i9irS986qZ0NFQVJoeUvnmFhaBGW3/S9aPz C6WkNbdvwt+x7UugN/YlH4zx7Bo1SGz4QkZltytn+m9hQdvS+v44W88UlhZ6XNeGEb2r eR8rKUoYrWBkj0LV/caSGavut02IRuxnHAQxqKuQLIOAzpuwW1m8fXx6MdxXYqBkudbo qMNA1ahlsDR/XrPMBCFEsz1dBXtwIl8ZHE3qqltNDPaC7Ug23935EyKJ64YftelUAgNH JoGB2zTdIP0CVSFKpJzkLDFPZTbQSae67HHJs57RGDd4cpi9lLv6jcL43QrT5+OqcgDE kAnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mail.ustc.edu.cn header.s=dkim header.b=Wh5dde25; 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 lc17-20020a170906dff100b0098dfec24292si916195ejc.829.2023.08.03.20.28.16; Thu, 03 Aug 2023 20:28:40 -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=Wh5dde25; 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 S230500AbjHDCdu (ORCPT + 99 others); Thu, 3 Aug 2023 22:33:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230048AbjHDCds (ORCPT ); Thu, 3 Aug 2023 22:33:48 -0400 Received: from ustc.edu.cn (email.ustc.edu.cn [IPv6:2001:da8:d800::8]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6B9FB4224; Thu, 3 Aug 2023 19:33:45 -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=EBhrcRFMBzAWOm64LZMJWLBVhYxm tGhdBvKAQ5lgBYE=; b=Wh5dde25GmuwklwJ81uWjJBzppn4Oc8m+1vYEcTO+SgQ 4rr/6IpZEIbvxyxfHxkOw+dMjy7CO/q6wMjZxA424FQ8cwKz3OcxJgTwwtqfl7r1 8DdxdxWq8qBTty24cgcf/ayVHVep+CuMqZKCwySAWOb4Yyf758xwid0xr2gVb0g= Received: from localhost (unknown [139.224.204.105]) by newmailweb.ustc.edu.cn (Coremail) with SMTP id LkAmygBn1Bx4Y8xkRIguAA--.7404S2; Fri, 04 Aug 2023 10:33:28 +0800 (CST) Date: Fri, 4 Aug 2023 10:33:28 +0800 From: Wu Zongyo To: Sean Christopherson Cc: Tom Lendacky , 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: <4ebb3e20-a043-8ad3-ef6c-f64c2443412c@amd.com> <544b7f95-4b34-654d-a57b-3791a6f4fd5f@mail.ustc.edu.cn> <7a4f3f59-1482-49c4-92b2-aa621e9b06b3@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-CM-TRANSID: LkAmygBn1Bx4Y8xkRIguAA--.7404S2 X-Coremail-Antispam: 1UD129KBjvJXoW7WFyrJF4fuF4xZry7Cw48WFg_yoW8Aw48pF yrJa10yF4ktrW7Grsayrn0yFW2y392krW5uryxGrn5Awn0v3s7XF4xWryjkr9xur1rK3WF qF4Yvw43uwn7Z3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUyFb7Iv0xC_Zr1lb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJr0_GcWl84ACjcxK6I 8E87Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI 64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8Jw Am72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E 4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGV WUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_ Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rV WrZr1j6s0DMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Jr0_ GrUvcSsGvfC2KfnxnUUI43ZEXa7IU8pnQUUUUUU== X-CM-SenderInfo: pzx200xj1rqzxdloh3xvwfhvlgxou0/ X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_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 Thu, Aug 03, 2023 at 02:34:50PM +0000, Sean Christopherson wrote: > On Thu, Aug 03, 2023, Wu Zongyo wrote: > > On Thu, Aug 03, 2023 at 11:27:12AM +0800, Wu Zongyo wrote: > > > > > > > > > > > > I'm guessing it was a #NPF, too. Could it be related to the changes that > > > > > > went in around svm_update_soft_interrupt_rip()? > > > Yes, it's a #NPF with exit code 0x400. > > > > > > There must be something I didn't handle corretly since it behave normally with > > > qemu & ovmf If I don't add int3 before mcheck_cpu_init(). > > > > > > So it'a about memory, is there something I need to pay special attention > > > to? > > > > > > Thanks > > I check the fault address of #NPF, and it is the IDT entry address of > > the guest kernel. The NPT page table is not constructed for the IDT > > entry and the #NPF is generated when guest try to access IDT. > > > > With qemu & ovmf, I didn't see the #NPF when guest invoke the int3 > > handler. That means the NPT page table has already been constructed, but > > when? > > More than likely, the page was used by the guest at some point earlier in boot. > Why the page is faulted in for certain setups but not others isn't really all > that interesting in terms of fixing the KVM bug, both guest behaviors are completely > normal and should work. > > Can you try this patch I suggested earlier? If this fixes the problem, I'll post > a formal patch. > > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > index d381ad424554..2eace114a934 100644 > --- a/arch/x86/kvm/svm/svm.c > +++ b/arch/x86/kvm/svm/svm.c > @@ -385,6 +385,9 @@ static int __svm_skip_emulated_instruction(struct kvm_vcpu *vcpu, > } > > if (!svm->next_rip) { > + if (sev_guest(vcpu->kvm)) > + return 0; > + > if (unlikely(!commit_side_effects)) > old_rflags = svm->vmcb->save.rflags; > Yes, the patch solves the problem.