From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA151351C07 for ; Fri, 3 Apr 2026 18:18:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775240340; cv=none; b=nrOx2wCiU74reMWz9SKDDPYVLkYpfLvRftph+5wYH6HCzgvv3CQBD/QAOe7Rj7d3RltsdfptK7ir1cQ4NyVe3DoC4HbEcRWRDdMEPaZp9rawkcyBpbGsBz+KajDDspqsO3rpxL3XfsZvL78z/3h2txAXTbY0vAnmxTbeefo/nxU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775240340; c=relaxed/simple; bh=d9fKYrqvm9ZHBMycKk5RMsjxR4vI8S4HZQmJk/NMbws=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fwO2MMINDF+yRE3S2PSwcMgSZxQr+sQkcdPjgK3OvSP7uhG7l9tRio9ewCJ6MM9X1pq0e5DthrL7gDx+5XIvmDwIuCrQDAFlRAdZUvH/7w+OjmpHVSx2PakULyxNNwJArob/hUWViBUiVlEBFwRaq6UrgFQ80TSqskzMKlyDDbg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=l37S/32R; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="l37S/32R" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-82c613194caso1290410b3a.1 for ; Fri, 03 Apr 2026 11:18:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775240337; x=1775845137; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=p/7vx0Uuo6no7a/ymxenB3UXpA7SrTt89T79ZimZz8o=; b=l37S/32R0BcQEQ3XjsM813qBV586jphPrh9S5BqW9APxLF6qnlnjWLlWsuDiHhyTp2 nr9hJc9NNwnTgbUFkAoAnvFyA3K+MnR4mvx598vL2eapDOnIXJQZubFI3ZcSVbCp1Nry elCqMiZcOFvvLJYg3gnad0bnMBaUHc1qM/EaQpPBFXSk9zjkv5K2VcOMG0PwGea1BAMK FrPFFZEBSFQpnp9RjgEfHSMLb9WFLzsBngwhDZElHrKOH/Tyu6b/RVcPYX4YzFwQ5u+5 pEgSjKEi5hkmjJPJRP3I94Lqr5uRWHf0oEEstTG+SezCWAgg6I2jByPTvz97qh8dOVAN PjkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775240337; x=1775845137; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=p/7vx0Uuo6no7a/ymxenB3UXpA7SrTt89T79ZimZz8o=; b=fFG/iKDr0aRLYmHvD/YeP50lQXQ2JDdU+NUggfO4Sdv92aOmhzL7UX6uTNFAElwTV7 itAvCs29/H+/w0QDScOSZOxiHbSoHBrMX5nQoJ2t7TCMI9KdSgvkcW2ymyKV2rX0HyXW K4OH1mQ3zqwhzUffkxUKQlFujRc1MWaLfo2zEjVVkU77Cpokr0fEF2H7xbEm5CucdTgg ciIcQASww0OavA5vUOraKIeuX425GQI+ncer5sX0e03hmy649lDG8CDuwuDgkru1ctud O0AhIvyoNeImtLKZ8E073UiB3rUo52LjsuKus7rdVRf+zfVckdzZaob/h72j/ZyWei8H i+oQ== X-Forwarded-Encrypted: i=1; AJvYcCXYeHJZDWZGjGUHaPvayolXJ1k9bUNfizWQVYRoD4xWJPZrFhsEfix/oojHtWL9AEEtafmp7ETFP3oScTU=@vger.kernel.org X-Gm-Message-State: AOJu0YxJDCWrzs5tjr9tHt5Y5CEe7gCTVRQmblbaYJ4lwSXIMTX+Cx2h +VvnT7S6tb5BOsnRmSS0lqydjMEjrs9jvFRQ34tXjo1xnU4TOMYw81rtgmoyZRnW8BSB0WDGeU7 lbe2q2A== X-Received: from pfwz16.prod.google.com ([2002:a05:6a00:1d90:b0:827:45df:8f74]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:a0b:b0:81f:852b:a925 with SMTP id d2e1a72fcca58-82d0da4594cmr3624925b3a.1.1775240336723; Fri, 03 Apr 2026 11:18:56 -0700 (PDT) Date: Fri, 3 Apr 2026 11:18:55 -0700 In-Reply-To: <20260316202732.3164936-3-yosry@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260316202732.3164936-1-yosry@kernel.org> <20260316202732.3164936-3-yosry@kernel.org> Message-ID: Subject: Re: [PATCH v4 2/9] KVM: SVM: Refactor SVM instruction handling on #GP intercept From: Sean Christopherson To: Yosry Ahmed Cc: Paolo Bonzini , Jim Mattson , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="us-ascii" On Mon, Mar 16, 2026, Yosry Ahmed wrote: > +/* Return 0 if not SVM instr, otherwise return associated exit_code */ > +static u64 svm_instr_exit_code(struct kvm_vcpu *vcpu) To make it very clear what this is doing how about: static u64 svm_get_decoded_instr_exit_code(struct kvm_vcpu *vcpu) > { > struct x86_emulate_ctxt *ctxt = vcpu->arch.emulate_ctxt; > > if (ctxt->b != 0x1 || ctxt->opcode_len != 2) > - return NONE_SVM_INSTR; > + return 0; This should assert to ensure there's no collision with '0', i.e. BUILD_BUG_ON(!SVM_EXIT_VMRUN || !SVM_EXIT_VMLOAD || !SVM_EXIT_VMSAVE); > + if (!is_guest_mode(vcpu)) > + return kvm_emulate_instruction(vcpu, > + EMULTYPE_VMWARE_GP | EMULTYPE_NO_DECODE); Since you're moving this anyways: if (!is_guest_mode(vcpu)) return kvm_emulate_instruction(vcpu, EMULTYPE_VMWARE_GP | EMULTYPE_NO_DECODE); Actually! Better idea, for this code and for the page_address_valid() checks: invert the checks to reduce indentation, i.e. end up with: /* FIXME: Handle SVM instructions through the emulator */ svm_exit_code = svm_get_decoded_instr_exit_code(vcpu); if (svm_exit_code) { if (!is_guest_mode(vcpu)) return svm_invoke_exit_handler(vcpu, svm_exit_code); if (nested_svm_check_permissions(vcpu)) return 1; if (!page_address_valid(vcpu, kvm_register_read(vcpu, VCPU_REGS_RAX))) goto reinject; /* * FIXME: Only synthesize a #VMEXIT if L1 sets the intercept, * but only after the VMLOAD/VMSAVE exit handlers can properly * handle VMLOAD/VMSAVE from L2 with VLS enabled in L1 (i.e. * RAX is an L2 GPA that needs translation through L1's NPT). */ nested_svm_simple_vmexit(svm, svm_exit_code); return 1; } /* * VMware backdoor emulation on #GP interception only handles * IN{S}, OUT{S}, and RDPMC, and only for L1. */ if (!enable_vmware_backdoor || is_guest_mode(vcpu)) goto reinject; return kvm_emulate_instruction(vcpu, EMULTYPE_VMWARE_GP | EMULTYPE_NO_DECODE); > + > reinject: > kvm_queue_exception_e(vcpu, GP_VECTOR, error_code); > return 1; > -- > 2.53.0.851.ga537e3e6e9-goog >