From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BCE2FC433E0 for ; Tue, 12 Jan 2021 17:43:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6424323120 for ; Tue, 12 Jan 2021 17:43:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391316AbhALRmz (ORCPT ); Tue, 12 Jan 2021 12:42:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390845AbhALRmy (ORCPT ); Tue, 12 Jan 2021 12:42:54 -0500 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CF6CC061795 for ; Tue, 12 Jan 2021 09:42:14 -0800 (PST) Received: by mail-pf1-x42c.google.com with SMTP id h10so1801856pfo.9 for ; Tue, 12 Jan 2021 09:42:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=s31IkhAz2nWDObQ5y1qk010QUglbb2JaCz6paHFbgKE=; b=ua53268TZsH8TsHxFaEpE3Lg38Obz2bJP4oWXSdDQ3eDw2YOCRWhARGn0Rb1Rf0Auw TtLaGqIvDQcsU6PinS85yVOCI23qw0qdoAeiNyFCeUupmIvS/D0EwslofU1OfJp+5Nr9 RdOfGVyn1o9B3rsJcU1JwJgn895dz+lxPubshGzX0GziRzBrnxat/6eNuHXzhumCQxfQ MNEgc4DQT0+5MeEzMPrYC7Dd4HPwoDJi9tgkfW5RAE0qNXK106rmLg9fsOT+om26SptI 9wA1Gor3x2F4n27lSQ51xEL0motMhUf0C2EZi/42mJqUdH5myNu29lByLdWu6nZzqhKk b7XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=s31IkhAz2nWDObQ5y1qk010QUglbb2JaCz6paHFbgKE=; b=Sb/4h1IOjM1rA4h4nZq+aPNY8V32wuzoLVmlkLGYZIKMyNStda19QUGIEqB8MdVzNg gwRFVclFrQhJWrsTYewNGedgJw92/dg9NhJnT/E9PStir705DcEhGIIwVvv1q/mGDhHp Rvmns/FFuSD8vVtBiAuFNqRLaYkjpEn4TRGau0oT5R4OGJw9MXtIuyfKh8wbRYJzpi6U yrdsCSHpoeBeWVJFbQ6U6t0xN2+AWMbG8s1SuVqIP4+UsN63I0ps62DkaNq3zg2xbOs9 3euXKJ+zQ3Kj5Zr5VGpIgZZMStWwM5cuTdYd2QbGQ56d8lAYvgBAOQgPeuUWGU0SpoJU UTWg== X-Gm-Message-State: AOAM533o42zno4Rgns0lUg5swa/wPnnvr3XHJwYuu6cHbryPNQzYCjOG /gxjG+kJhu1kbJePbwKHiJXL5A== X-Google-Smtp-Source: ABdhPJzVO5KIL0Bbdp4cP/dveCjEiVGXuDYxY1LjLiCENCJSSZtyZGJ5CtUindfKmib6RkB3GMEZ8g== X-Received: by 2002:a62:1896:0:b029:197:491c:be38 with SMTP id 144-20020a6218960000b0290197491cbe38mr246893pfy.15.1610473333520; Tue, 12 Jan 2021 09:42:13 -0800 (PST) Received: from google.com ([2620:15c:f:10:1ea0:b8ff:fe73:50f5]) by smtp.gmail.com with ESMTPSA id a23sm4163925pju.31.2021.01.12.09.42.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jan 2021 09:42:12 -0800 (PST) Date: Tue, 12 Jan 2021 09:42:05 -0800 From: Sean Christopherson To: Paolo Bonzini Cc: Wei Huang , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, vkuznets@redhat.com, joro@8bytes.org, bp@alien8.de, tglx@linutronix.de, mingo@redhat.com, x86@kernel.org, jmattson@google.com, wanpengli@tencent.com, bsd@redhat.com, dgilbert@redhat.com, mlevitsk@redhat.com Subject: Re: [PATCH 1/2] KVM: x86: Add emulation support for #GP triggered by VM instructions Message-ID: References: <20210112063703.539893-1-wei.huang2@amd.com> <090232a9-7a87-beb9-1402-726bb7cab7e6@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <090232a9-7a87-beb9-1402-726bb7cab7e6@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 12, 2021, Paolo Bonzini wrote: > On 12/01/21 07:37, Wei Huang wrote: > > static int gp_interception(struct vcpu_svm *svm) > > { > > struct kvm_vcpu *vcpu = &svm->vcpu; > > u32 error_code = svm->vmcb->control.exit_info_1; > > - > > - WARN_ON_ONCE(!enable_vmware_backdoor); > > + int rc; > > /* > > - * VMware backdoor emulation on #GP interception only handles IN{S}, > > - * OUT{S}, and RDPMC, none of which generate a non-zero error code. > > + * Only VMware backdoor and SVM VME errata are handled. Neither of > > + * them has non-zero error codes. > > */ > > if (error_code) { > > kvm_queue_exception_e(vcpu, GP_VECTOR, error_code); > > return 1; > > } > > - return kvm_emulate_instruction(vcpu, EMULTYPE_VMWARE_GP); > > + > > + rc = kvm_emulate_instruction(vcpu, EMULTYPE_PARAVIRT_GP); > > + if (rc > 1) > > + rc = svm_emulate_vm_instr(vcpu, rc); > > + return rc; > > } > > Passing back the third byte is quick hacky. Instead of this change to > kvm_emulate_instruction, I'd rather check the instruction bytes in > gp_interception before calling kvm_emulate_instruction. Agreed. And I'd also prefer that any pure refactoring is done in separate patch(es) so that the actual functional change is better isolated. On a related topic, it feels like nested should be disabled by default on SVM until it's truly ready for primetime, with the patch tagged for stable. That way we don't have to worry about crafting non-trivial fixes (like this one) to make them backport-friendly.