From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0613A1A072C for ; Thu, 19 Dec 2024 17:49:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734630592; cv=none; b=uESRxgB6Y4QpAs2BwyZEmKxPIOCo3NPnaAfakswsT2u2TkuQnaCZ9s0dN/i94DbSReyEJZmoSVdn1YkKX7OBAErY2yQy9zE/hw7J3Cxl7Fr1/QsnxtwdVZWES1SvzBt4gzeAiut3XCAeb2TFvr9+ri9WUEgKB9FYVE2Tgkq3KF4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734630592; c=relaxed/simple; bh=W2AE3efuXPQM2Td61Im0ibq+bjHsOT+eUUp2GvmHqlI=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=XMoh84kN4VMJ8lGwGLb0DLPoVmFnraa6WA7oMlec2BVK0Pf4RhXTqj0DwFnqYV6gwHLMQ+b5DCkZIfIePHr3Fzxp+KqWP12vjanYqsegCZjnzUYUisAjx30Fa6ZdOQ2rFofjNDl1Sqk0qMxymcX0Qx7EmqhojyDZHgLvSovodfo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=BSgWDdDU; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BSgWDdDU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734630590; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SFYxzBnH9Nmr3/1+Gv4ueOJjpF8J01T/gwryfiZdCzY=; b=BSgWDdDUW5DXmOWufMVnA1O6LIgKXVoq8OOEGrhVyEXhFNqqwiKanptLhg5Pf/d4GolCsu 47SYByvzvT6FNFdgghDY4W291fnRHmTRE5WQAr9QBKpVaqDq0cc1mgN5PE4GjeUi+t9Yrt 2UcANTB3ukKwbOHc0YsxI4BoVJRPErY= Received: from mail-il1-f198.google.com (mail-il1-f198.google.com [209.85.166.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-342-1GocjDlSMD-LLtDfjysPgg-1; Thu, 19 Dec 2024 12:49:48 -0500 X-MC-Unique: 1GocjDlSMD-LLtDfjysPgg-1 X-Mimecast-MFC-AGG-ID: 1GocjDlSMD-LLtDfjysPgg Received: by mail-il1-f198.google.com with SMTP id e9e14a558f8ab-3a7de3ab182so18521375ab.1 for ; Thu, 19 Dec 2024 09:49:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734630588; x=1735235388; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=SFYxzBnH9Nmr3/1+Gv4ueOJjpF8J01T/gwryfiZdCzY=; b=MYdp6LW23TO+nALhgWEHzELvEB3RVAX+UhWdW77EOtB9o87G7tsjawLGdAamNkWe53 289dOeUO/mp1rge2w3gw2kT8oitn5ygQi/X9JJKetXCghiAiS9oqBI1Rw2P6D/gno2EF vdNldMERbzBPVGioFoEaZbQWtCIdPmIxKWwuY2W/qy0moxiBWy1z2xmZEkBltTBRmiXT JOJcM3VnQfEN/fEtJZ71yYt3CvJaPBKl/+3zrVKp8GO22awK7rPNpfMI7P/dMHCkXUxc F6UrVb+A0k5pmxbW/y3gVBaKuTUcg0zjLBFNyJarA9R/xXH/03pf7qvRrQTHnxOZdv7h PzXg== X-Forwarded-Encrypted: i=1; AJvYcCU2Gikbmrhupj1kwWQ97ya8DVI55MCzAXQ5G0h1/pUrSFTMhJu179lI5RFABJtc5SZtm6svMiqfjO/NMKM=@vger.kernel.org X-Gm-Message-State: AOJu0YwFWHeyz2h6J7ZuyKS9EFezkuVE577ik5OdqC1oi28DgcJIBmSg crdJCYmWhNGK+sFiPmqZhkhzIhz0CmSPswVwClOd83xziDBs0oCWzHogq0udULRNMo3Izeh5qd0 uyI1gxrKgdY0aF0hqAUoAVS3oq7LFvfWNMj1jW+/grvntaVU6DCFp7Xhui4tyaA== X-Gm-Gg: ASbGnctom2PIbKXMY5iox+wNbazVV5nTEnlDr5lmzktsyoEGx2bTw9byeTVjuYNBvtc RqqA96P7qrndsMo6KBmEdNswrCNkIr4Gx+tkPT06g7Ucs/PBfc75FUWIRX3JUNZ/DJB8MtThTjY Bhw94pYseIRpWFZhRbQ/U+0mCYpLNUJ6VxP0d4raKs9xTWulrJTnQVBYq7Y7S2th4z+ehfSsAb4 lumFMcQdZgNgSS2pglPlsHVRTcXbV4dWHf2WUg5yITGaJyLbZFgFjUv X-Received: by 2002:a05:6e02:742:b0:3a7:fe8c:b012 with SMTP id e9e14a558f8ab-3bdc4659beemr74802545ab.18.1734630587964; Thu, 19 Dec 2024 09:49:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IEFQ5a9tvcbkcwAiXwoc4j7pG79MjTcFmv/Tx/EmA6juS7AFcCVHd4xkdAN74hjjKq0QhgCiA== X-Received: by 2002:a05:6e02:742:b0:3a7:fe8c:b012 with SMTP id e9e14a558f8ab-3bdc4659beemr74802255ab.18.1734630587644; Thu, 19 Dec 2024 09:49:47 -0800 (PST) Received: from starship ([2607:fea8:fc01:8d8d:6adb:55ff:feaa:b156]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4e68bf7ecb9sm370539173.73.2024.12.19.09.49.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2024 09:49:47 -0800 (PST) Message-ID: <4c1c999c29809c683cc79bc8c77cbe5d7eca37b7.camel@redhat.com> Subject: Re: [PATCH v5 3/3] KVM: x86: add new nested vmexit tracepoints From: Maxim Levitsky To: Paolo Bonzini , kvm@vger.kernel.org Cc: x86@kernel.org, Dave Hansen , Thomas Gleixner , Borislav Petkov , Ingo Molnar , Sean Christopherson , "H. Peter Anvin" , linux-kernel@vger.kernel.org Date: Thu, 19 Dec 2024 12:49:46 -0500 In-Reply-To: <9ff2be87-117a-4f96-af3b-dacb55467449@redhat.com> References: <20240910200350.264245-1-mlevitsk@redhat.com> <20240910200350.264245-4-mlevitsk@redhat.com> <9ff2be87-117a-4f96-af3b-dacb55467449@redhat.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7bit On Thu, 2024-12-19 at 18:33 +0100, Paolo Bonzini wrote: > On 9/10/24 22:03, Maxim Levitsky wrote: > > Add 3 new tracepoints for nested VM exits which are intended > > to capture extra information to gain insights about the nested guest > > behavior. > > > > The new tracepoints are: > > > > - kvm_nested_msr > > - kvm_nested_hypercall > > > > These tracepoints capture extra register state to be able to know > > which MSR or which hypercall was done. > > > > - kvm_nested_page_fault > > > > This tracepoint allows to capture extra info about which host pagefault > > error code caused the nested page fault. > > > > Signed-off-by: Maxim Levitsky > > --- > > arch/x86/kvm/svm/nested.c | 22 +++++++++++ > > arch/x86/kvm/trace.h | 82 +++++++++++++++++++++++++++++++++++++-- > > arch/x86/kvm/vmx/nested.c | 27 +++++++++++++ > > arch/x86/kvm/x86.c | 3 ++ > > 4 files changed, 131 insertions(+), 3 deletions(-) > > > > diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c > > index 6f704c1037e51..2020307481553 100644 > > --- a/arch/x86/kvm/svm/nested.c > > +++ b/arch/x86/kvm/svm/nested.c > > @@ -38,6 +38,8 @@ static void nested_svm_inject_npf_exit(struct kvm_vcpu *vcpu, > > { > > struct vcpu_svm *svm = to_svm(vcpu); > > struct vmcb *vmcb = svm->vmcb; > > + u64 host_error_code = vmcb->control.exit_info_1; > > + > > > > if (vmcb->control.exit_code != SVM_EXIT_NPF) { > > /* > > @@ -48,11 +50,15 @@ static void nested_svm_inject_npf_exit(struct kvm_vcpu *vcpu, > > vmcb->control.exit_code_hi = 0; > > vmcb->control.exit_info_1 = (1ULL << 32); > > vmcb->control.exit_info_2 = fault->address; > > + host_error_code = 0; > > } > > > > vmcb->control.exit_info_1 &= ~0xffffffffULL; > > vmcb->control.exit_info_1 |= fault->error_code; > > > > + trace_kvm_nested_page_fault(fault->address, host_error_code, > > + fault->error_code); > > + > > I disagree with Sean about trace_kvm_nested_page_fault. It's a useful > addition and it is easier to understand what's happening with a > dedicated tracepoint (especially on VMX). > > Tracepoint are not an exact science and they aren't entirely kernel API. > At least they can just go away at any time (changing them is a lot > more tricky, but their presence is not guaranteed). The one below has > the slight ugliness of having to do some computation in > nested_svm_vmexit(), this one should go in. > > > nested_svm_vmexit(svm); > > } > > > > @@ -1126,6 +1132,22 @@ int nested_svm_vmexit(struct vcpu_svm *svm) > > vmcb12->control.exit_int_info_err, > > KVM_ISA_SVM); > > > > + /* Collect some info about nested VM exits */ > > + switch (vmcb12->control.exit_code) { > > + case SVM_EXIT_MSR: > > + trace_kvm_nested_msr(vmcb12->control.exit_info_1 == 1, > > + kvm_rcx_read(vcpu), > > + (vmcb12->save.rax & 0xFFFFFFFFull) | > > + (((u64)kvm_rdx_read(vcpu) << 32))); > > + break; > > + case SVM_EXIT_VMMCALL: > > + trace_kvm_nested_hypercall(vmcb12->save.rax, > > + kvm_rbx_read(vcpu), > > + kvm_rcx_read(vcpu), > > + kvm_rdx_read(vcpu)); > > + break; > > Here I probably would have preferred an unconditional tracepoint giving > RAX/RBX/RCX/RDX after a nested vmexit. This is not exactly what Sean > wanted but perhaps it strikes a middle ground? I know you wrote this > for a debugging tool, do you really need to have everything in a single > tracepoint, or can you correlate the existing exit tracepoint with this > hypothetical trace_kvm_nested_exit_regs, to pick RDMSR vs. WRMSR? Hi! If the new trace_kvm_nested_exit_regs tracepoint has a VM exit number argument, then I can enable this new tracepoint twice with a different filter (vm_exit_num number == msr and vm_exit_num == vmcall), and each instance will count the events that I need. So this can work. Thanks! Best regards, Maxim Levitsky > > Paolo >