From patchwork Fri Aug 18 15:46:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinoh Kang X-Patchwork-Id: 13357953 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6C792C77B7C for ; Fri, 18 Aug 2023 15:46:49 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.586409.917642 (Exim 4.92) (envelope-from ) id 1qX1gP-00054i-NO; Fri, 18 Aug 2023 15:46:41 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 586409.917642; Fri, 18 Aug 2023 15:46:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qX1gP-00054b-Km; Fri, 18 Aug 2023 15:46:41 +0000 Received: by outflank-mailman (input) for mailman id 586409; Fri, 18 Aug 2023 15:46:41 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qX1gP-00054Q-45 for xen-devel@lists.xenproject.org; Fri, 18 Aug 2023 15:46:41 +0000 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [2607:f8b0:4864:20::1036]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 6a88522d-3dde-11ee-9b0c-b553b5be7939; Fri, 18 Aug 2023 17:46:38 +0200 (CEST) Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-268bc714ce0so1578154a91.0 for ; Fri, 18 Aug 2023 08:46:38 -0700 (PDT) Received: from [10.137.0.57] ([14.33.99.107]) by smtp.gmail.com with ESMTPSA id o4-20020a17090a5b0400b00263b4b1255esm3403185pji.51.2023.08.18.08.46.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 18 Aug 2023 08:46:35 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 6a88522d-3dde-11ee-9b0c-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692373597; x=1692978397; h=content-transfer-encoding:in-reply-to:content-language:references :cc:subject:from:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=+jx5RSLTw30Nq5GpRjwoFyWLugIiYJY9y8Xx3gRG6sI=; b=dCCwD3hqVs7Yr2LWpptrZcV6PcAZ6BDxhAhTcBtu8PJarJv3MYUgOR/N0K/T4vjvNl k37JFTrgIXU59YjTnEUbCqDhDJHGDpd8+u5eMGknQZWC44BqeFPKzBg3vj9g8Bajw/GB gnQRQ9M2DkbXmDUwDS5jH296X2j5WeNaC23GH36Fwi/1AYwwM4OWtXN2S7gWCnc2iAGM aQQIabgHDo376lGK/006z/RQs3nWgJ5eRWtVYXDj7S3R+1vOS0yWUeEghVnmJHShO8bW iv81PvYVhlpyKaRsU/k0pZ+nR6EoI8znqGqgIVVgtTLiTTgMyhaCGjXhWY30Phpjiecg sc7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692373597; x=1692978397; h=content-transfer-encoding:in-reply-to:content-language:references :cc:subject:from:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+jx5RSLTw30Nq5GpRjwoFyWLugIiYJY9y8Xx3gRG6sI=; b=EZELB0xXh9CqfxUPIQO1v61nOIbvFhSh00nzbDZQ6vsV3oS9uVbdia+7fwz2qESwCN J3k1jmu+zyBQo539Po/ZvjRGSxW2ApgwkxKM5OkgFvTZaxJz5uJr92wBrO1OnzXGywgY je4aAq3roV8TlQQIflfWSIS6k24NEg/9Gwtxl/XvAwcz4cK5bauChnqDEqSC8lv0zPcr t0sa2+lX6DIpnRahkShR+w1SX/5HDveEqpmImkmSrTWSiB3doHlcv0DNqUIObazsyKfl FyPT5uxLC5pDSJ/+zeBHGaSkk5pN35fmbyO+24zXL82au/rzNS3kmuDVIWyNIevuinv6 oBXA== X-Gm-Message-State: AOJu0YwZmDorGcSeoC3OhD/uHSUVu9SGKD/BAxy5Fl50iflQjuEuuTUy oWyuupn/MD4UuF2n41LlbCM= X-Google-Smtp-Source: AGHT+IFItXjWmD7PhztM9Z2UGCNDAzLriU9yJ3S5cvEVu8a73PjHzSAClc7U+oxddT87zvdBX+jUwA== X-Received: by 2002:a17:90b:3908:b0:268:2f6:61c4 with SMTP id ob8-20020a17090b390800b0026802f661c4mr3888963pjb.12.1692373596701; Fri, 18 Aug 2023 08:46:36 -0700 (PDT) Message-ID: <46162899-50bb-30ac-133f-90355706347b@gmail.com> Date: Sat, 19 Aug 2023 00:46:05 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 From: Jinoh Kang Subject: [PATCH 1/6] x86/hvm: only populate info->cr2 for #PF in hvm_get_pending_event() Cc: Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Paul Durrant , Jun Nakajima , Kevin Tian , Tim Deegan , George Dunlap , xen-devel@lists.xenproject.org References: Content-Language: en-US In-Reply-To: Prepare for an upcoming patch that overloads the 'cr2' field for #DB. Signed-off-by: Jinoh Kang --- xen/arch/x86/hvm/hvm.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 3a99c0ff20be..48a77524f198 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -502,9 +502,14 @@ void hvm_migrate_pirqs(struct vcpu *v) static bool hvm_get_pending_event(struct vcpu *v, struct x86_event *info) { - info->cr2 = v->arch.hvm.guest_cr[2]; + if ( !alternative_call(hvm_funcs.get_pending_event, v, info) ) + return false; + + if ( info->type == X86_EVENTTYPE_HW_EXCEPTION && + info->vector == X86_EXC_PF ) + info->cr2 = v->arch.hvm.guest_cr[2]; - return alternative_call(hvm_funcs.get_pending_event, v, info); + return true; } void hvm_do_resume(struct vcpu *v) From patchwork Fri Aug 18 15:46:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinoh Kang X-Patchwork-Id: 13357957 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E98F4C77B7C for ; Fri, 18 Aug 2023 15:47:22 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.586414.917652 (Exim 4.92) (envelope-from ) id 1qX1gr-0005Wq-W7; Fri, 18 Aug 2023 15:47:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 586414.917652; Fri, 18 Aug 2023 15:47:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qX1gr-0005Wj-S9; Fri, 18 Aug 2023 15:47:09 +0000 Received: by outflank-mailman (input) for mailman id 586414; Fri, 18 Aug 2023 15:47:09 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qX1gr-00054Q-29 for xen-devel@lists.xenproject.org; Fri, 18 Aug 2023 15:47:09 +0000 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [2607:f8b0:4864:20::630]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7bb83a46-3dde-11ee-9b0c-b553b5be7939; Fri, 18 Aug 2023 17:47:07 +0200 (CEST) Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1bc8a2f71eeso8232065ad.0 for ; Fri, 18 Aug 2023 08:47:07 -0700 (PDT) Received: from [10.137.0.57] ([14.33.99.107]) by smtp.gmail.com with ESMTPSA id n9-20020a170902e54900b001bde65894d5sm1927812plf.109.2023.08.18.08.47.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 18 Aug 2023 08:47:04 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 7bb83a46-3dde-11ee-9b0c-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692373626; x=1692978426; h=content-transfer-encoding:in-reply-to:content-language:references :cc:subject:from:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=YufZI707Ujs7/EHXRSsM3OL/ONxDf9+knc8Qd0VFQb0=; b=ANvSuiNqMBOnMC7iWNij8pcQeyH6Aq0GtjMwfSJfuoHrl20GNw17WE+HCJXD53wHQO nDEg73h7OH5WYWVlubU28uDNluBJMc5FXzMZQGiufj0+kXHUvtFGlb3U4m5DsuRA8gvV Ax5YN4FUXAIM+o4p8fgIbOzEegzgjWwlfLLuhp5l4Dcx6k0c3awjpNpPqAjcdmXM4diX 7+uYd+zy23CnK/oy88yVy+cymM/7hY95K6YsZXeFxbnLFw5oHtyPKkaRffonZbvZNBji IE84Nphrrk7Nn3zzGEyHK8ummAECI4iP2FjhkB0nb/51u2oje0beB4zebwKgFseLwFu5 tXsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692373626; x=1692978426; h=content-transfer-encoding:in-reply-to:content-language:references :cc:subject:from:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YufZI707Ujs7/EHXRSsM3OL/ONxDf9+knc8Qd0VFQb0=; b=PPk8OA5+H+cMM1f1RlrjIQEINl//WURnR1+ah/+0iiZrGfbNTwmSHKRdS3p2rO1pyA YIKgfbaEdV0VSTZBnFMbZaVdAUX5A2GJkm8xXRFB78abe2vjfZjOhEQ9cIy36XPfXk6v 5QBmuKrSoNCeXwyp1iBn7I24Gaz28mV8eV7EDGDz3iysBi5NBqRnAzZQyTROm8etwOL1 BfdZLu8Zt1Wd/3fUK52dXJQe3CEa6G1C11d4xjA3NSbXc8kYQud7kFyclRUsGtBiYNR1 IucA29QAlBZdYmRJVC66I/myi9PHNpwEKMTejVyz9dNRsTPnzR3ymgcbogYjK13eSXJw Dlxw== X-Gm-Message-State: AOJu0YxMrScyqKFM8l9zAV16Gv8Zv7NhAPO2fe/RqDUAAQGbf0bNLn0g ZNV8KidZNXUgCy/Hhc7D8VI= X-Google-Smtp-Source: AGHT+IHzLF0b96EvpA38KVA9ROOq938j//LDF2HFOhNJI+AGqrjTGq9l4olg7IfGeLyyFwf8BwheMg== X-Received: by 2002:a17:902:b7c4:b0:1bf:c59:c944 with SMTP id v4-20020a170902b7c400b001bf0c59c944mr2775991plz.22.1692373625690; Fri, 18 Aug 2023 08:47:05 -0700 (PDT) Message-ID: <0a5b5331-a77a-6dc7-a822-638be6ce598d@gmail.com> Date: Sat, 19 Aug 2023 00:46:59 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 From: Jinoh Kang Subject: [PATCH 2/6] x86emul: rename field 'cr2' of struct x86_event to 'extra' Cc: Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Paul Durrant , Jun Nakajima , Kevin Tian , Tim Deegan , George Dunlap , xen-devel@lists.xenproject.org References: Content-Language: en-US In-Reply-To: XEN_DMOP_inject_event() copies the 'cr2' argument to struct x86_event. 'cr2' is overladed to mean pending_dbg for a debug trap, but consumers of struct x86_event always interpret it as CR2. Clarify the role of the 'cr2' field by renaming it to 'extra', in preparation for an upcoming patch that uses it to actually populate dr6. Signed-off-by: Jinoh Kang --- xen/arch/x86/hvm/dm.c | 2 +- xen/arch/x86/hvm/hvm.c | 4 ++-- xen/arch/x86/hvm/svm/nestedsvm.c | 2 +- xen/arch/x86/hvm/svm/svm.c | 8 ++++---- xen/arch/x86/hvm/vmx/vmx.c | 2 +- xen/arch/x86/include/asm/domain.h | 2 +- xen/arch/x86/include/asm/hvm/hvm.h | 2 +- xen/arch/x86/pv/traps.c | 8 ++++---- xen/arch/x86/x86_emulate/x86_emulate.h | 4 ++-- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/xen/arch/x86/hvm/dm.c b/xen/arch/x86/hvm/dm.c index 462691f91d3c..48a0c09f7af3 100644 --- a/xen/arch/x86/hvm/dm.c +++ b/xen/arch/x86/hvm/dm.c @@ -314,7 +314,7 @@ static int inject_event(struct domain *d, v->arch.hvm.inject_event.type = data->type; v->arch.hvm.inject_event.insn_len = data->insn_len; v->arch.hvm.inject_event.error_code = data->error_code; - v->arch.hvm.inject_event.cr2 = data->cr2; + v->arch.hvm.inject_event.extra = data->cr2; smp_wmb(); v->arch.hvm.inject_event.vector = data->vector; diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 48a77524f198..1abdec35257b 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -507,7 +507,7 @@ static bool hvm_get_pending_event(struct vcpu *v, struct x86_event *info) if ( info->type == X86_EVENTTYPE_HW_EXCEPTION && info->vector == X86_EXC_PF ) - info->cr2 = v->arch.hvm.guest_cr[2]; + info->extra = v->arch.hvm.guest_cr[2]; return true; } @@ -548,7 +548,7 @@ void hvm_do_resume(struct vcpu *v) if ( hvm_get_pending_event(v, &info) ) { hvm_monitor_interrupt(info.vector, info.type, info.error_code, - info.cr2); + info.extra); v->arch.monitor.next_interrupt_enabled = false; } } diff --git a/xen/arch/x86/hvm/svm/nestedsvm.c b/xen/arch/x86/hvm/svm/nestedsvm.c index a09b6abaaeaf..9bd2a304ac01 100644 --- a/xen/arch/x86/hvm/svm/nestedsvm.c +++ b/xen/arch/x86/hvm/svm/nestedsvm.c @@ -842,7 +842,7 @@ int cf_check nsvm_vcpu_vmexit_event( ASSERT(vcpu_nestedhvm(v).nv_vvmcx != NULL); nestedsvm_vmexit_defer(v, VMEXIT_EXCEPTION_DE + event->vector, - event->error_code, event->cr2); + event->error_code, event->extra); return NESTEDHVM_VMEXIT_DONE; } diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index 01dd592d9b83..d5e8cb0722ca 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -1252,7 +1252,7 @@ static void svm_emul_swint_injection(struct x86_event *event) { fault = X86_EXC_PF; ec = pfinfo.ec; - event->cr2 = pfinfo.linear; + event->extra = pfinfo.linear; } goto raise_exception; @@ -1345,8 +1345,8 @@ static void cf_check svm_inject_event(const struct x86_event *event) case X86_EXC_PF: ASSERT(_event.type == X86_EVENTTYPE_HW_EXCEPTION); - curr->arch.hvm.guest_cr[2] = _event.cr2; - vmcb_set_cr2(vmcb, _event.cr2); + curr->arch.hvm.guest_cr[2] = _event.extra; + vmcb_set_cr2(vmcb, _event.extra); break; } @@ -1430,7 +1430,7 @@ static void cf_check svm_inject_event(const struct x86_event *event) if ( _event.vector == X86_EXC_PF && _event.type == X86_EVENTTYPE_HW_EXCEPTION ) HVMTRACE_LONG_2D(PF_INJECT, _event.error_code, - TRC_PAR_LONG(_event.cr2)); + TRC_PAR_LONG(_event.extra)); else HVMTRACE_2D(INJ_EXC, _event.vector, _event.error_code); } diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 7ec44018d4ed..8823ca13e55d 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -2051,7 +2051,7 @@ static void cf_check vmx_inject_event(const struct x86_event *event) case X86_EXC_PF: ASSERT(_event.type == X86_EVENTTYPE_HW_EXCEPTION); - curr->arch.hvm.guest_cr[2] = _event.cr2; + curr->arch.hvm.guest_cr[2] = _event.extra; break; } diff --git a/xen/arch/x86/include/asm/domain.h b/xen/arch/x86/include/asm/domain.h index c2d9fc333be5..0e445cff5c08 100644 --- a/xen/arch/x86/include/asm/domain.h +++ b/xen/arch/x86/include/asm/domain.h @@ -735,7 +735,7 @@ static inline void pv_inject_page_fault(int errcode, unsigned long cr2) .vector = X86_EXC_PF, .type = X86_EVENTTYPE_HW_EXCEPTION, .error_code = errcode, - .cr2 = cr2, + .extra = cr2, }; pv_inject_event(&event); diff --git a/xen/arch/x86/include/asm/hvm/hvm.h b/xen/arch/x86/include/asm/hvm/hvm.h index 6d53713fc3a9..f3f6310ab684 100644 --- a/xen/arch/x86/include/asm/hvm/hvm.h +++ b/xen/arch/x86/include/asm/hvm/hvm.h @@ -532,7 +532,7 @@ static inline void hvm_inject_page_fault(int errcode, unsigned long cr2) .vector = X86_EXC_PF, .type = X86_EVENTTYPE_HW_EXCEPTION, .error_code = errcode, - .cr2 = cr2, + .extra = cr2, }; hvm_inject_event(&event); diff --git a/xen/arch/x86/pv/traps.c b/xen/arch/x86/pv/traps.c index 74f333da7e1c..e5c9734b8204 100644 --- a/xen/arch/x86/pv/traps.c +++ b/xen/arch/x86/pv/traps.c @@ -53,15 +53,15 @@ void pv_inject_event(const struct x86_event *event) if ( event->type == X86_EVENTTYPE_HW_EXCEPTION && vector == X86_EXC_PF ) { - curr->arch.pv.ctrlreg[2] = event->cr2; - arch_set_cr2(curr, event->cr2); + curr->arch.pv.ctrlreg[2] = event->extra; + arch_set_cr2(curr, event->extra); /* Re-set error_code.user flag appropriately for the guest. */ error_code &= ~PFEC_user_mode; if ( !guest_kernel_mode(curr, regs) ) error_code |= PFEC_user_mode; - trace_pv_page_fault(event->cr2, error_code); + trace_pv_page_fault(event->extra, error_code); } else trace_pv_trap(vector, regs->rip, use_error_code, error_code); @@ -82,7 +82,7 @@ void pv_inject_event(const struct x86_event *event) vector, vector_name(vector), error_code); if ( vector == X86_EXC_PF ) - show_page_walk(event->cr2); + show_page_walk(event->extra); } } diff --git a/xen/arch/x86/x86_emulate/x86_emulate.h b/xen/arch/x86/x86_emulate/x86_emulate.h index 698750267a90..bad957f9bcb2 100644 --- a/xen/arch/x86/x86_emulate/x86_emulate.h +++ b/xen/arch/x86/x86_emulate/x86_emulate.h @@ -78,7 +78,7 @@ struct x86_event { uint8_t type; /* X86_EVENTTYPE_* */ uint8_t insn_len; /* Instruction length */ int32_t error_code; /* X86_EVENT_NO_EC if n/a */ - unsigned long cr2; /* Only for X86_EXC_PF h/w exception */ + unsigned long extra; /* CR2 if X86_EXC_PF h/w exception */ }; /* @@ -831,7 +831,7 @@ static inline void x86_emul_pagefault( ctxt->event.vector = X86_EXC_PF; ctxt->event.type = X86_EVENTTYPE_HW_EXCEPTION; ctxt->event.error_code = error_code; - ctxt->event.cr2 = cr2; + ctxt->event.extra = cr2; ctxt->event_pending = true; } From patchwork Fri Aug 18 15:47:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinoh Kang X-Patchwork-Id: 13357958 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 63CF4C71159 for ; Fri, 18 Aug 2023 15:47:25 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.586416.917662 (Exim 4.92) (envelope-from ) id 1qX1gy-0005sh-Aa; Fri, 18 Aug 2023 15:47:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 586416.917662; Fri, 18 Aug 2023 15:47:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qX1gy-0005sU-71; Fri, 18 Aug 2023 15:47:16 +0000 Received: by outflank-mailman (input) for mailman id 586416; Fri, 18 Aug 2023 15:47:14 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qX1gw-0005WD-Tc for xen-devel@lists.xenproject.org; Fri, 18 Aug 2023 15:47:14 +0000 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [2607:f8b0:4864:20::636]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7fed8f25-3dde-11ee-877e-cb3800f73035; Fri, 18 Aug 2023 17:47:14 +0200 (CEST) Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1bd9b4f8e0eso8036285ad.1 for ; Fri, 18 Aug 2023 08:47:14 -0700 (PDT) Received: from [10.137.0.57] ([14.33.99.107]) by smtp.gmail.com with ESMTPSA id x19-20020a170902ea9300b001b8b0ac2258sm1936083plb.174.2023.08.18.08.47.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 18 Aug 2023 08:47:11 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 7fed8f25-3dde-11ee-877e-cb3800f73035 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692373633; x=1692978433; h=content-transfer-encoding:in-reply-to:content-language:references :cc:subject:from:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=djtTkadKsD4CONvDQuXhksDL4gNlsVo29HPt0IPnNF4=; b=OJ0/M2acxRmMUy0VRoHu5fSKWHh+FyuWJh10aZeHCfjueL9yxNygxC/kcOOfVehYji rDZtOXy0oLCv51mOwtGLsTwt3ribruEKr7jphDTXRaecRbU29AddnDq8jwkEoCy4C75G UNd9BxUAxts+MaQKDcZ5kFT9gqORNoPSzQUkrUTXIsIzyzKsO5DUtyJ6JnQS6Tw8/wI6 YsIZLtNYLu9+F6uk9fO12XQWmMiqqeXriaA9ZY2eio0fI0PboRW+hlKC8ZR6m+hh5Uhi /3yeqsG/8rt0RJLIk1RjPa1Z87y00doL1BnYB7aSSWH77Njsm+iNDqwO7bvfxnAFm/4x hJAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692373633; x=1692978433; h=content-transfer-encoding:in-reply-to:content-language:references :cc:subject:from:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=djtTkadKsD4CONvDQuXhksDL4gNlsVo29HPt0IPnNF4=; b=FzEPOR8RQ+3N1J4ELzVwQe8UQuHA4om/uRnCUTKuPjtBjp5TCrJEwo65/Iu29zz6N1 QGWsj0jW1rx64Ja7Gh0HdEGaLsZW5gwbYNlLbnsxYfx4krnMkFYWWtf7dv+b3Q/sP/Q9 xuQELvkAz4x8rMWz+S74QNm4RqPo4rozjaGtnPAIt9syu7i1U2ObPv4zZOrg1PlAhWgC vIMLK0tKo6qeHwUtXgRcS2Pe+Y+uv1L41KEgCwH4M+3F8NPw892clsQfsqT8ISzqChvr Qty00AK5Ti2NIi75lFEBxA/djPJ08JoQJgUMliQsX++2TqkZZdTrqptB3jAQD6j3Wt4h vU1w== X-Gm-Message-State: AOJu0Yy3ZMnzfiFg9ixIyW98eTaTOWG+XuV4KtdlZ3snJwVm61cikC6q VaDmBhHHY14SU5XjG3axhMY= X-Google-Smtp-Source: AGHT+IHqy1TH7bzZekJKUHcP0iJmdUhe/OYKWuwUM06BtmA9yw8Kgbc5hJMHzUiMUdqGAITyzFbYlg== X-Received: by 2002:a17:903:234f:b0:1bf:1:a4a8 with SMTP id c15-20020a170903234f00b001bf0001a4a8mr3653078plh.25.1692373632717; Fri, 18 Aug 2023 08:47:12 -0700 (PDT) Message-ID: Date: Sat, 19 Aug 2023 00:47:06 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 From: Jinoh Kang Subject: [PATCH 3/6] x86: don't assume #DB is always caused by singlestep if EFLAGS.TF is set Cc: Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Paul Durrant , Jun Nakajima , Kevin Tian , Tim Deegan , George Dunlap , xen-devel@lists.xenproject.org References: Content-Language: en-US In-Reply-To: Today, when a HVM (or PVH) guest triggers a hardware breakpoint while EFLAGS.TF is set, Xen incorrectly assumes that this is a single stepping exception and sets DR_STEP in dr6 in addition to DR_TRAP. This causes problems with Linux HW breakpoint handler, which ignores DR_TRAP bits when DR_STEP is set. This prevents user-mode debuggers from recognizing hardware breakpoints if EFLAGS.TF is set. Fix this by not setting DR_STEP in {vmx,svm}_inject_event, unless the emulator explicitly signals the single-stepping mode via the newly added "singlestep" boolean field of struct x86_event. Fixes: 8b831f4189 ("x86: single step after instruction emulation") Signed-off-by: Jinoh Kang --- xen/arch/x86/hvm/emulate.c | 3 ++- xen/arch/x86/hvm/svm/svm.c | 6 +++--- xen/arch/x86/hvm/vmx/vmx.c | 6 +++--- xen/arch/x86/include/asm/hvm/hvm.h | 12 ++++++++++++ xen/arch/x86/mm/shadow/multi.c | 5 +++-- xen/arch/x86/x86_emulate/x86_emulate.h | 4 +++- 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/xen/arch/x86/hvm/emulate.c b/xen/arch/x86/hvm/emulate.c index 9b6e4c8bc61b..5ad372466e1d 100644 --- a/xen/arch/x86/hvm/emulate.c +++ b/xen/arch/x86/hvm/emulate.c @@ -26,6 +26,7 @@ #include #include #include +#include struct hvmemul_cache { @@ -2673,7 +2674,7 @@ static int _hvm_emulate_one(struct hvm_emulate_ctxt *hvmemul_ctxt, } if ( hvmemul_ctxt->ctxt.retire.singlestep ) - hvm_inject_hw_exception(X86_EXC_DB, X86_EVENT_NO_EC); + hvm_inject_debug_exception(DR_STEP); new_intr_shadow = hvmemul_ctxt->intr_shadow; diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index d5e8cb0722ca..f25d6a53f092 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -96,7 +96,7 @@ void __update_guest_eip(struct cpu_user_regs *regs, unsigned int inst_len) curr->arch.hvm.svm.vmcb->int_stat.intr_shadow = 0; if ( regs->eflags & X86_EFLAGS_TF ) - hvm_inject_hw_exception(X86_EXC_DB, X86_EVENT_NO_EC); + hvm_inject_debug_exception(DR_STEP); } static void cf_check svm_cpu_down(void) @@ -1328,10 +1328,10 @@ static void cf_check svm_inject_event(const struct x86_event *event) switch ( _event.vector | -(_event.type == X86_EVENTTYPE_SW_INTERRUPT) ) { case X86_EXC_DB: - if ( regs->eflags & X86_EFLAGS_TF ) + if ( event->extra ) { __restore_debug_registers(vmcb, curr); - vmcb_set_dr6(vmcb, vmcb_get_dr6(vmcb) | DR_STEP); + vmcb_set_dr6(vmcb, vmcb_get_dr6(vmcb) | event->extra); } /* fall through */ case X86_EXC_BP: diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 8823ca13e55d..1795b9479cf9 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -2022,10 +2022,10 @@ static void cf_check vmx_inject_event(const struct x86_event *event) switch ( _event.vector | -(_event.type == X86_EVENTTYPE_SW_INTERRUPT) ) { case X86_EXC_DB: - if ( guest_cpu_user_regs()->eflags & X86_EFLAGS_TF ) + if ( event->extra ) { __restore_debug_registers(curr); - write_debugreg(6, read_debugreg(6) | DR_STEP); + write_debugreg(6, read_debugreg(6) | event->extra); } if ( !nestedhvm_vcpu_in_guestmode(curr) || !nvmx_intercepts_exception(curr, X86_EXC_DB, _event.error_code) ) @@ -3068,7 +3068,7 @@ void update_guest_eip(void) } if ( regs->eflags & X86_EFLAGS_TF ) - hvm_inject_hw_exception(X86_EXC_DB, X86_EVENT_NO_EC); + hvm_inject_debug_exception(DR_STEP); } static void cf_check vmx_fpu_dirty_intercept(void) diff --git a/xen/arch/x86/include/asm/hvm/hvm.h b/xen/arch/x86/include/asm/hvm/hvm.h index f3f6310ab684..6a0b9e3ff01e 100644 --- a/xen/arch/x86/include/asm/hvm/hvm.h +++ b/xen/arch/x86/include/asm/hvm/hvm.h @@ -538,6 +538,18 @@ static inline void hvm_inject_page_fault(int errcode, unsigned long cr2) hvm_inject_event(&event); } +static inline void hvm_inject_debug_exception(unsigned long pending_dbg) +{ + struct x86_event event = { + .vector = X86_EXC_DB, + .type = X86_EVENTTYPE_HW_EXCEPTION, + .error_code = X86_EVENT_NO_EC, + .extra = pending_dbg, + }; + + hvm_inject_event(&event); +} + static inline bool hvm_event_pending(const struct vcpu *v) { return alternative_call(hvm_funcs.event_pending, v); diff --git a/xen/arch/x86/mm/shadow/multi.c b/xen/arch/x86/mm/shadow/multi.c index cf74fdf5dda6..365af5169750 100644 --- a/xen/arch/x86/mm/shadow/multi.c +++ b/xen/arch/x86/mm/shadow/multi.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "private.h" #include "types.h" @@ -2788,7 +2789,7 @@ static int cf_check sh_page_fault( #endif if ( emul_ctxt.ctxt.retire.singlestep ) - hvm_inject_hw_exception(X86_EXC_DB, X86_EVENT_NO_EC); + hvm_inject_debug_exception(DR_STEP); #if GUEST_PAGING_LEVELS == 3 /* PAE guest */ /* @@ -2829,7 +2830,7 @@ static int cf_check sh_page_fault( TRACE_SHADOW_PATH_FLAG(TRCE_SFLAG_EMULATION_LAST_FAILED); if ( emul_ctxt.ctxt.retire.singlestep ) - hvm_inject_hw_exception(X86_EXC_DB, X86_EVENT_NO_EC); + hvm_inject_debug_exception(DR_STEP); break; /* Don't emulate again if we failed! */ } diff --git a/xen/arch/x86/x86_emulate/x86_emulate.h b/xen/arch/x86/x86_emulate/x86_emulate.h index bad957f9bcb2..868a64ab20e6 100644 --- a/xen/arch/x86/x86_emulate/x86_emulate.h +++ b/xen/arch/x86/x86_emulate/x86_emulate.h @@ -78,7 +78,9 @@ struct x86_event { uint8_t type; /* X86_EVENTTYPE_* */ uint8_t insn_len; /* Instruction length */ int32_t error_code; /* X86_EVENT_NO_EC if n/a */ - unsigned long extra; /* CR2 if X86_EXC_PF h/w exception */ + + /* Type-specific extra data (%cr2 for #PF, pending_dbg for #DB) */ + unsigned long extra; }; /* From patchwork Fri Aug 18 15:47:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinoh Kang X-Patchwork-Id: 13357959 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4C792C77B7C for ; Fri, 18 Aug 2023 15:47:36 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.586417.917672 (Exim 4.92) (envelope-from ) id 1qX1h3-0006CD-HK; Fri, 18 Aug 2023 15:47:21 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 586417.917672; Fri, 18 Aug 2023 15:47:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qX1h3-0006C4-E2; Fri, 18 Aug 2023 15:47:21 +0000 Received: by outflank-mailman (input) for mailman id 586417; Fri, 18 Aug 2023 15:47:20 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qX1h2-0005WD-9t for xen-devel@lists.xenproject.org; Fri, 18 Aug 2023 15:47:20 +0000 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [2607:f8b0:4864:20::102f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 833a6e06-3dde-11ee-877e-cb3800f73035; Fri, 18 Aug 2023 17:47:19 +0200 (CEST) Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-26d54d3d984so329510a91.1 for ; Fri, 18 Aug 2023 08:47:19 -0700 (PDT) Received: from [10.137.0.57] ([14.33.99.107]) by smtp.gmail.com with ESMTPSA id rm4-20020a17090b3ec400b0026094c23d0asm1717425pjb.17.2023.08.18.08.47.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 18 Aug 2023 08:47:17 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 833a6e06-3dde-11ee-877e-cb3800f73035 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692373638; x=1692978438; h=content-transfer-encoding:in-reply-to:content-language:references :cc:subject:from:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=Vxu4BWosO06wdQVnGmCCgPXnQgECbdfZfm/WjoZh/WM=; b=X9F25AXnH9TmwZRfJJw7gbAbh5UWbe3it0a6R/9Bsl+60AGYSaXTaLV/I5l73MS2A+ EqnW7YTe846s4OaRx1zI5G3QNIB75NL4fduaz2ElhIN4YVutFavh9Xd5qNC/9nEyNfju Zk0nvJiyAlLPJrrZZSjnfbpKB3RkB31vuEh3+wXiuj9aSBXKh550oEzYNl+7sGAsw1/O svNljWF58V67CanyRqg2wtzbvespKQSphq+HCudiLKKau3usCUS5OSxSAOR+Ye4Kwg0O vqk7hgWkpRpTJoilFLEPq8m63hqAPkp2TxusD8LwHP1ntPjahBmoSALc50Qt8QhGXV2S mLAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692373638; x=1692978438; h=content-transfer-encoding:in-reply-to:content-language:references :cc:subject:from:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Vxu4BWosO06wdQVnGmCCgPXnQgECbdfZfm/WjoZh/WM=; b=dr2PAwcmfJ7X5aOwH4Jwz0iQ4JzbOsMWJHVVugPThXwO/eQndpogkhihmEk++dmKNy eF8dtjZhGW+pPrYJmbnKbNIloUXtdnokyf7T+a7Z3MBcNcXY5UaNJnA5BfUx0GNGM+A0 s9LLp9qnHvZWWfZKVnnsU5IwCwb6sQZgf1GMKeYKwIDwz3PWdk4tIWq9jWe0nfZrMDZT c8OkRdpU8/JuzN5dntg2y/s7hHeCD8/zDNQwvztOHzDU/v3Dxl+j9eqATE7DLHkjb7ib ECBaHH0XQ3m9RFK+y18vZGwIwl7GWEXzSkyI5q13hrQf06cb4N6ip+3oa7zVYrYI6bgx KB9A== X-Gm-Message-State: AOJu0YxuttP2ITAXJBGWsKbJCVvey8Nr3uHusDOREw2pQ0VcNGXw353v 7KmDHBuXwXm9KNSsEvXCTGE= X-Google-Smtp-Source: AGHT+IFMeKKMDRP91za9mlECpdKbVEJw9ePs0osxm4JWhWj8/CiqALhLvv85YSHlIE+jCZ13VrPP9w== X-Received: by 2002:a17:90a:d78a:b0:26b:1081:a432 with SMTP id z10-20020a17090ad78a00b0026b1081a432mr2707022pju.30.1692373638303; Fri, 18 Aug 2023 08:47:18 -0700 (PDT) Message-ID: <2c68b5aa-843c-7d59-7137-5ea72363ea0d@gmail.com> Date: Sat, 19 Aug 2023 00:47:12 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 From: Jinoh Kang Subject: [PATCH 4/6] x86/pv: set DR_STEP if single-stepping after ro page fault emulation Cc: Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Paul Durrant , Jun Nakajima , Kevin Tian , Tim Deegan , George Dunlap , xen-devel@lists.xenproject.org References: Content-Language: en-US In-Reply-To: Signed-off-by: Jinoh Kang --- xen/arch/x86/pv/ro-page-fault.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xen/arch/x86/pv/ro-page-fault.c b/xen/arch/x86/pv/ro-page-fault.c index cad28ef928ad..238bfbeb4ac4 100644 --- a/xen/arch/x86/pv/ro-page-fault.c +++ b/xen/arch/x86/pv/ro-page-fault.c @@ -10,6 +10,7 @@ #include #include +#include #include "emulate.h" #include "mm.h" @@ -390,7 +391,10 @@ int pv_ro_page_fault(unsigned long addr, struct cpu_user_regs *regs) /* Fallthrough */ case X86EMUL_OKAY: if ( ctxt.retire.singlestep ) + { + current->arch.dr6 |= DR_STEP | DR_STATUS_RESERVED_ONE; pv_inject_hw_exception(X86_EXC_DB, X86_EVENT_NO_EC); + } /* Fallthrough */ case X86EMUL_RETRY: From patchwork Fri Aug 18 15:47:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinoh Kang X-Patchwork-Id: 13357960 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A1F87C77B7F for ; Fri, 18 Aug 2023 15:47:37 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.586420.917682 (Exim 4.92) (envelope-from ) id 1qX1h9-0006Zp-Q1; Fri, 18 Aug 2023 15:47:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 586420.917682; Fri, 18 Aug 2023 15:47:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qX1h9-0006Zi-Lm; Fri, 18 Aug 2023 15:47:27 +0000 Received: by outflank-mailman (input) for mailman id 586420; Fri, 18 Aug 2023 15:47:26 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qX1h8-0005WD-FL for xen-devel@lists.xenproject.org; Fri, 18 Aug 2023 15:47:26 +0000 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [2607:f8b0:4864:20::632]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 86cf8867-3dde-11ee-877e-cb3800f73035; Fri, 18 Aug 2023 17:47:25 +0200 (CEST) Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1bdb7b0c8afso7835985ad.3 for ; Fri, 18 Aug 2023 08:47:25 -0700 (PDT) Received: from [10.137.0.57] ([14.33.99.107]) by smtp.gmail.com with ESMTPSA id s15-20020a170902ea0f00b001bbc8d65de0sm1943507plg.67.2023.08.18.08.47.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 18 Aug 2023 08:47:23 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 86cf8867-3dde-11ee-877e-cb3800f73035 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692373644; x=1692978444; h=content-transfer-encoding:in-reply-to:content-language:references :cc:subject:from:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=+UQOAr2es15lGNIQkp28TBH1fdCufuHHrfjqiigg570=; b=nJKjzEqTQmvgKRLNwxm5vRYBizrbO2NCA6BcKPVlXia+kIz0VShaLrmTiIe0rpFU3g 3UeiBahNIgZ15SWSYY1ll2IUZTokVKAK5NTH4pY1V3xeO45QWIKZKz6k0zHRb58jMFO8 BWyoiM3IzY9ziljVDVP8feuJ4q8+xXNeAPXNTwO27hyZwfDu7RgyJjcJ4E3fjgNU/Chc by10w7y4mKNlkeyZkUitaRPmk3mgQ92NpK310yQ7Iv5bLLJEJdExI97Yeu1d+TG/iW/C yrvoTZL4uulQrB2KCZI32fuKRwQ3Iqb3dVEncbmOXmYOVeyHH7apKMQIQ1Ew9HV60oIf +LFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692373644; x=1692978444; h=content-transfer-encoding:in-reply-to:content-language:references :cc:subject:from:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+UQOAr2es15lGNIQkp28TBH1fdCufuHHrfjqiigg570=; b=jaEO4fjCoSnpEsxTvwf+qAH3SwG5RPfimiaa7KuAWI0UVou+r/zcrd73BstXALx5E9 01zg5YMZzFZV6rufC4MATNzhOH/r71U9D80xKl33oN+Tj/LzKwM9djLIr3LZNJhZnbMG MTvBkylfExquqpg403uXS3D3XAfMt9+sZSro5pKOt10g3keABiwMrYmuDh1/iJwNBl0p VyWh0Sa9PlJ8DnaQMj2sf3fYNd79siThk+/Kk0HwkmYdKmIX320k5k3EjMtd7Nx8xBit QRtKsUvF6YieyXifrGXhYcWqqljMlAC3d5snR4kZcxMxU++JOOei/AjD4qAIcIRzZX9v b+cQ== X-Gm-Message-State: AOJu0YwHNrK0R0uqGqVf19L0lVmVCSt41o7d6pWAoXlWYeTntG004ITz H7x//nT2PlN0Qp53Q6tBf38= X-Google-Smtp-Source: AGHT+IHfVY3KfelMtXzv0+WXeFdg+/KO8mkApg3yj5eWvyPb8Q6pcMAOuzfzXqLpugaz/ClRAD8UJw== X-Received: by 2002:a17:903:486:b0:1bd:a22a:d40a with SMTP id jj6-20020a170903048600b001bda22ad40amr2493815plb.2.1692373644336; Fri, 18 Aug 2023 08:47:24 -0700 (PDT) Message-ID: <5c1cd2ca-880a-72d4-e586-3d0838adf8eb@gmail.com> Date: Sat, 19 Aug 2023 00:47:18 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 From: Jinoh Kang Subject: [PATCH 5/6] x86/pv: factor out single-step debug trap injection Cc: Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Paul Durrant , Jun Nakajima , Kevin Tian , Tim Deegan , George Dunlap , xen-devel@lists.xenproject.org References: Content-Language: en-US In-Reply-To: Add pv_inject_debug_exception() helper and use it wherever applicable. This helper corresponds to hvm_inject_debug_exception() in HVM. Signed-off-by: Jinoh Kang --- xen/arch/x86/include/asm/domain.h | 12 ++++++++++++ xen/arch/x86/pv/emulate.c | 5 +---- xen/arch/x86/pv/ro-page-fault.c | 5 +---- xen/arch/x86/pv/traps.c | 10 ++++++++++ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/xen/arch/x86/include/asm/domain.h b/xen/arch/x86/include/asm/domain.h index 0e445cff5c08..cfeb63da6cd6 100644 --- a/xen/arch/x86/include/asm/domain.h +++ b/xen/arch/x86/include/asm/domain.h @@ -741,6 +741,18 @@ static inline void pv_inject_page_fault(int errcode, unsigned long cr2) pv_inject_event(&event); } +static inline void pv_inject_debug_exception(unsigned long pending_dbg) +{ + const struct x86_event event = { + .vector = X86_EXC_DB, + .type = X86_EVENTTYPE_HW_EXCEPTION, + .error_code = X86_EVENT_NO_EC, + .extra = pending_dbg, + }; + + pv_inject_event(&event); +} + static inline void pv_inject_sw_interrupt(unsigned int vector) { const struct x86_event event = { diff --git a/xen/arch/x86/pv/emulate.c b/xen/arch/x86/pv/emulate.c index e7a1c0a2cc4f..865b05337192 100644 --- a/xen/arch/x86/pv/emulate.c +++ b/xen/arch/x86/pv/emulate.c @@ -72,10 +72,7 @@ void pv_emul_instruction_done(struct cpu_user_regs *regs, unsigned long rip) regs->rip = rip; regs->eflags &= ~X86_EFLAGS_RF; if ( regs->eflags & X86_EFLAGS_TF ) - { - current->arch.dr6 |= DR_STEP | DR_STATUS_RESERVED_ONE; - pv_inject_hw_exception(X86_EXC_DB, X86_EVENT_NO_EC); - } + pv_inject_debug_exception(DR_STEP); } uint64_t pv_get_reg(struct vcpu *v, unsigned int reg) diff --git a/xen/arch/x86/pv/ro-page-fault.c b/xen/arch/x86/pv/ro-page-fault.c index 238bfbeb4ac4..9c6042cab3b2 100644 --- a/xen/arch/x86/pv/ro-page-fault.c +++ b/xen/arch/x86/pv/ro-page-fault.c @@ -391,10 +391,7 @@ int pv_ro_page_fault(unsigned long addr, struct cpu_user_regs *regs) /* Fallthrough */ case X86EMUL_OKAY: if ( ctxt.retire.singlestep ) - { - current->arch.dr6 |= DR_STEP | DR_STATUS_RESERVED_ONE; - pv_inject_hw_exception(X86_EXC_DB, X86_EVENT_NO_EC); - } + pv_inject_debug_exception(DR_STEP); /* Fallthrough */ case X86EMUL_RETRY: diff --git a/xen/arch/x86/pv/traps.c b/xen/arch/x86/pv/traps.c index e5c9734b8204..4cf31558ac2f 100644 --- a/xen/arch/x86/pv/traps.c +++ b/xen/arch/x86/pv/traps.c @@ -15,6 +15,7 @@ #include #include #include +#include #include void pv_inject_event(const struct x86_event *event) @@ -64,7 +65,16 @@ void pv_inject_event(const struct x86_event *event) trace_pv_page_fault(event->extra, error_code); } else + { + if ( event->type == X86_EVENTTYPE_HW_EXCEPTION && + vector == X86_EXC_DB ) + { + if ( event->extra ) + curr->arch.dr6 |= event->extra | DR_STATUS_RESERVED_ONE; + } + trace_pv_trap(vector, regs->rip, use_error_code, error_code); + } if ( use_error_code ) { From patchwork Fri Aug 18 15:47:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinoh Kang X-Patchwork-Id: 13357961 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 70F49C71159 for ; Fri, 18 Aug 2023 15:47:49 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.586426.917693 (Exim 4.92) (envelope-from ) id 1qX1hK-0007H5-6F; Fri, 18 Aug 2023 15:47:38 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 586426.917693; Fri, 18 Aug 2023 15:47:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qX1hK-0007G5-08; Fri, 18 Aug 2023 15:47:38 +0000 Received: by outflank-mailman (input) for mailman id 586426; Fri, 18 Aug 2023 15:47:37 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qX1hJ-0005WD-Ae for xen-devel@lists.xenproject.org; Fri, 18 Aug 2023 15:47:37 +0000 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [2607:f8b0:4864:20::432]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8d49504b-3dde-11ee-877e-cb3800f73035; Fri, 18 Aug 2023 17:47:36 +0200 (CEST) Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-6887ccba675so895641b3a.3 for ; Fri, 18 Aug 2023 08:47:36 -0700 (PDT) Received: from [10.137.0.57] ([14.33.99.107]) by smtp.gmail.com with ESMTPSA id i23-20020aa787d7000000b0064d47cd116esm1696837pfo.161.2023.08.18.08.47.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 18 Aug 2023 08:47:34 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 8d49504b-3dde-11ee-877e-cb3800f73035 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692373655; x=1692978455; h=content-transfer-encoding:in-reply-to:content-language:references :cc:subject:from:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=muARqwg7J0jXaBR6Kw/+0enh70UHMI8H+VpfrjX65HY=; b=GI4X1ZXl15ePzbLTKA3KP6YAaayNEue6osptafFWdlUkZcD0++bgp22YZZRYsR1EV4 EX5UHl0dqumQ2fgQeX5j38N9KYJzS3l/8OiqopCoZtCJfuTm3gccPSt4N2LyfYnumEM/ yt0OpGEQHkW2FfRTgyMMfafYaFHsPYy/FFptlbb/nLqYYAREqHE28Qxi7qDS4KH/EG3L 2CO4durEoJicjPsce8weecxG4pRDYpiKkNCk6OOoN3B8pg5XsOdSymcduzvzAe+Ekxl9 QNP6cySDtGu86iTvlkrAQY9Hf1DR3LsqvjXkoQHlOhc2OOe3F9HgcVWRsL2SRHDXMGHk WsSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692373655; x=1692978455; h=content-transfer-encoding:in-reply-to:content-language:references :cc:subject:from:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=muARqwg7J0jXaBR6Kw/+0enh70UHMI8H+VpfrjX65HY=; b=EmOUzVb7Kd1o5JiOFh8Q9yV0gBYjev2zuUDNqSD5nUa5F9SSNbDAvyZi5UXEQmshGR NQ0fsx/CZ6DdVkXL4vRnS0ExJ1Pt6QEdn8lYvhZy681LCD7GffqUu4FrsAH1VUVOAHmp M9yFylH82KidIyO1UdUz5bbifowz+cEEMK4la8ALxFZpLGXowj9RugfHlqnDFawFHtsv pBCUeCV/D60xcBK/ElpomoMLTwtLMo/pd4V81I3lQUP3lNJOM9Op8rVhfIfo32eb+Ucp dYr8JdLALgy3tWZpXxQnaogPLACOLC3o+NwJKHnwaPGJlZSgYe0/NsPk4ZqzRyhmi1ui 35aA== X-Gm-Message-State: AOJu0YxxGjnFYlpjHYjDb21f+0/gOm8/0LN5YqTZIpt8Wt5/rPc5prm8 KXyApP7kw7cuqA6SIAb1dls= X-Google-Smtp-Source: AGHT+IFrEcSVZ5bF+25U50HXbWsCwjKMl5JjVl/wXApRgYbnKFmtiSaPsksLQzNm96WXHXvxM0L9RA== X-Received: by 2002:a05:6a00:1acc:b0:687:5763:ef27 with SMTP id f12-20020a056a001acc00b006875763ef27mr3062865pfv.33.1692373655118; Fri, 18 Aug 2023 08:47:35 -0700 (PDT) Message-ID: <231aa9dc-ca45-491f-26d2-72b4365219a6@gmail.com> Date: Sat, 19 Aug 2023 00:47:28 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 From: Jinoh Kang Subject: [PATCH 6/6] x86/debug: actually plumb pending_dbg through the monitor and devicemodel interfaces Cc: Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Paul Durrant , Jun Nakajima , Kevin Tian , Tim Deegan , George Dunlap , xen-devel@lists.xenproject.org References: Content-Language: en-US In-Reply-To: Commit 21867648033d ("x86/debug: Plumb pending_dbg through the monitor and devicemodel interfaces") introduced pending_dbg, but did not actually populate or use the field. Signed-off-by: Jinoh Kang --- xen/arch/x86/hvm/svm/svm.c | 34 +++++++++++++++++++++++++++++++--- xen/arch/x86/hvm/vmx/vmx.c | 32 ++++++++++++++++++++++++-------- 2 files changed, 55 insertions(+), 11 deletions(-) diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index f25d6a53f092..139be9902dae 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -2422,6 +2422,14 @@ static bool cf_check svm_get_pending_event( info->type = vmcb->event_inj.type; info->error_code = vmcb->event_inj.ec; + if ( info->type == X86_EVENTTYPE_HW_EXCEPTION && + info->vector == X86_EXC_DB ) + { + unsigned long dr6 = v->arch.hvm.flag_dr_dirty ? + vmcb_get_dr6(vmcb) : v->arch.dr6; + info->extra = dr6 & ~DR_STATUS_RESERVED_ONE; + } + return true; } @@ -2733,16 +2741,28 @@ void svm_vmexit_handler(void) if ( !v->domain->debugger_attached ) { unsigned int trap_type; + unsigned long exit_pending_dbg; if ( likely(exit_reason != VMEXIT_ICEBP) ) { trap_type = X86_EVENTTYPE_HW_EXCEPTION; insn_len = 0; + + __restore_debug_registers(vmcb, v); + + /* + * NOTE: This is slightly wrong; old bits in dr6 are not + * automatically cleared by CPU on #DB, so it's not exactly + * equivalent to PENDING_DBG_EXCEPTIONS in semantics. + */ + exit_pending_dbg = vmcb_get_dr6(vmcb) & ~DR_STATUS_RESERVED_ONE; + vmcb_set_dr6(vmcb, DR_STATUS_RESERVED_ONE); } else { trap_type = X86_EVENTTYPE_PRI_SW_EXCEPTION; insn_len = svm_get_insn_len(v, INSTR_ICEBP); + exit_pending_dbg = 0; if ( !insn_len ) break; @@ -2750,12 +2770,20 @@ void svm_vmexit_handler(void) rc = hvm_monitor_debug(regs->rip, HVM_MONITOR_DEBUG_EXCEPTION, - trap_type, insn_len, 0); + trap_type, insn_len, exit_pending_dbg); if ( rc < 0 ) goto unexpected_exit_type; if ( !rc ) - hvm_inject_exception(X86_EXC_DB, - trap_type, insn_len, X86_EVENT_NO_EC); + { + if (trap_type == X86_EVENTTYPE_HW_EXCEPTION) + { + /* Updates DR6 where debugger can peek. */ + hvm_inject_debug_exception(exit_pending_dbg); + } + else + hvm_inject_exception(X86_EXC_DB, + trap_type, insn_len, X86_EVENT_NO_EC); + } } else domain_pause_for_debugger(); diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 1795b9479cf9..63411b62cb94 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -2469,6 +2469,14 @@ static bool cf_check vmx_get_pending_event( info->type = MASK_EXTR(intr_info, INTR_INFO_INTR_TYPE_MASK); info->error_code = error_code; + if ( info->type == X86_EVENTTYPE_HW_EXCEPTION && + info->vector == X86_EXC_DB ) + { + unsigned long dr6 = v->arch.hvm.flag_dr_dirty ? + read_debugreg(6) : v->arch.dr6; + info->extra = dr6 & ~DR_STATUS_RESERVED_ONE; + } + return true; } @@ -4240,13 +4248,11 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs) { case X86_EXC_DB: /* - * Updates DR6 where debugger can peek (See 3B 23.2.1, - * Table 23-1, "Exit Qualification for Debug Exceptions"). + * See 3B 23.2.1, Table 23-1, "Exit Qualification for Debug + * Exceptions". */ __vmread(EXIT_QUALIFICATION, &exit_qualification); HVMTRACE_1D(TRAP_DEBUG, exit_qualification); - __restore_debug_registers(v); - write_debugreg(6, exit_qualification | DR_STATUS_RESERVED_ONE); /* * Work around SingleStep + STI/MovSS VMEntry failures. @@ -4285,22 +4291,32 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs) if ( !v->domain->debugger_attached ) { - unsigned long insn_len = 0; + unsigned long exit_pending_dbg = 0, insn_len = 0; int rc; unsigned long trap_type = MASK_EXTR(intr_info, INTR_INFO_INTR_TYPE_MASK); - if ( trap_type >= X86_EVENTTYPE_SW_INTERRUPT ) + if ( trap_type == X86_EVENTTYPE_HW_EXCEPTION ) + exit_pending_dbg = exit_qualification; + else if ( trap_type >= X86_EVENTTYPE_SW_INTERRUPT ) __vmread(VM_EXIT_INSTRUCTION_LEN, &insn_len); rc = hvm_monitor_debug(regs->rip, HVM_MONITOR_DEBUG_EXCEPTION, - trap_type, insn_len, 0); + trap_type, insn_len, exit_pending_dbg); if ( rc < 0 ) goto exit_and_crash; if ( !rc ) - vmx_propagate_intr(intr_info); + { + if ( trap_type == X86_EVENTTYPE_HW_EXCEPTION ) + { + /* Updates DR6 where debugger can peek. */ + hvm_inject_debug_exception(exit_pending_dbg); + } + else + vmx_propagate_intr(intr_info); + } } else domain_pause_for_debugger();