[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [XEN PATCH v4] x86/monitor: Add new monitor event to catch I/O instructions
- To: Jan Beulich <jbeulich@xxxxxxxx>, Dmitry Isaykin <isaikin-dmitry@xxxxxxxxx>
- From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
- Date: Tue, 21 Mar 2023 11:11:51 +0000
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=MbVTdAGfEFnddb7vG3JmWr0SevDNGKZ1xcz8GRHgQUw=; b=SGJ/MUuqQ4YFsntwkD3eDRdlPOTVw1DTv1Z8EgCrYOkP834nHL2zeYTX04TmlZWIpZj1/yP8h3zsDqprGyGgn3LRMAWTUp7wDjcpbcW9sfJK5ep1VRHvLlXtDS0otgTyZHOtT8hkIvwYbYbQ6huwmZAMTp77ghnYbgfCn0vOUF06jNjefVdIjpRjqH52ZCVXqvkQKXrIoa3C2zw3satTX8kn/iL/zvJpQITplW5+MkUNkDB2KUqWY2eZTrJiQf3uM8mCHoz3ygg+yTZRWcHo9Jx4GE/zoaZvUpkWH9Q2JP8dRnwQrcjpWKulitGpwDsduknWl8yiYbfKSnPWXHC6vQ==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Jm4UxFqv/QOaJ04mKVOU94/U0z17TRiF4Rug8cIROAnuvtcDQPjd+PNWi7xqPbkyBy4fQq4AsGxdPRATS21SIJAcIAAvofq2wKAP7cG3qpSLTfoc9yuVzUbtPjXlrNyyrQfxKZAWRd2g7Z27l6erXnW5e2YNo/ELlEPPktKi4kISgEEJrJXu4ADXzLgRBQe95JKTw61ICkpJ6fn5wD1mZQMOj/6cfrJs09FxScleKap2USdAFyHB0a1LOlGrgZ6wSIvVBU2G1v1wDRhMQdkpcVCl+OlsIt0dZM7bbPR8xavGTZk00fHSKW6NBe34xGqLk49ugpI1lIxhaU+4DDzHkg==
- Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
- Cc: Wei Liu <wl@xxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Tamas K Lengyel <tamas@xxxxxxxxxxxxx>, Alexandru Isaila <aisaila@xxxxxxxxxxxxxxx>, Petre Pircalabu <ppircalabu@xxxxxxxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Jun Nakajima <jun.nakajima@xxxxxxxxx>, Kevin Tian <kevin.tian@xxxxxxxxx>, Anton Belousov <abelousov@xxxxxxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
- Delivery-date: Tue, 21 Mar 2023 11:12:26 +0000
- Ironport-data: A9a23:zBbUfKNIdIxkEFXvrR2tl8FynXyQoLVcMsEvi/4bfWQNrUp23zdUx mYbD2iAa6rZZWf0eIskb47l9UIHsZaBztNjGgto+SlhQUwRpJueD7x1DKtS0wC6dZSfER09v 63yTvGacajYm1eF/k/F3oDJ9CU6jufQAOKnUoYoAwgpLSd8UiAtlBl/rOAwh49skLCRDhiE/ Nj/uKUzAnf8s9JPGj9SuvLrRC9H5qyo42tD5AVmPJingXeF/5UrJMNHTU2OByOQrrl8RoaSW +vFxbelyWLVlz9F5gSNy+uTnuUiG9Y+DCDW4pZkc/HKbitq/0Te5p0TJvsEAXq7vh3S9zxHJ HehgrTrIeshFvWkdO3wyHC0GQkmVUFN0OevzXRSLaV/ZqAJGpfh66wGMa04AWEX0uBTK1hk1 eAgE2sQPjKih/+33+yxDeY506zPLOGzVG8ekldJ6GiASN0BGNXESaiM4sJE1jAtgMwIBezZe 8cSdTtoalLHfgFLPVAUTpk5mY9EhFGmK2Ee9A3T+PRxujeIpOBy+OGF3N79U9qGX8hK2G2fo XrL5T/RCRAGLt2PjzGC9xpAg8eWxXqjBdhMReTQGvhChwSN9DUtAhgqR17rs9efqGKYVNhcN BlBksYphe1onKCxdfH/VRClpH+PvjYHRsFdVeY97Wmly7Hd4gWYAC0ISz9dcs0OpcYwSTE6k EWU9/v2ARR/vbvTTmiSnp+Woim1IjM9NnIZaGkPSg5ty9v+pIA+iDrfQ9AlF7S65vXuAi35y T2OqCk4hp0QgNQN2qH9+krI6xqwr53AVSYp5QHaWG204wc/b4mgD6Sh6EPS7PJJBIyYUlWMs nUCl8WEqusJCPmljDSMWu4EGLij+t6PMSHQjFBiGZUs7XKm/HvLVYJN5nd4LURgMMcBcBfoZ lPevUVa45o7FHinc65xJZ6wAsICzK78GNCjXffRBvJHaJV1cxKc+z9GfVKL0mvwikkwgOc0P pLzWdahCzMWBLpqyBKyRvwByvk7yyYm32TRSJvniRO93tKjiGW9TL4ENB6Fabk/5abd+QHNq Y8AbI2N1glVV/D4bm/P64kPIFsWLH89Q5frt8hQce3FKQ1jcI08N8LsLXoaU9QNt8xoei3gp xlRhmcwJILDuED6
- Ironport-hdrordr: A9a23:JCGDiKh+wPiM1C4M8kKyyd6opnBQXgUji2hC6mlwRA09TyX4rb HToB1/73TJYVkqOU3I5urwXpVoLUmxyXc32/hpAV7aZnidhILwFvAe0WKA+UyeJ8SdzI5gPP xbAtBD4bTLZDARsS+d2maF+r0breVvnprHuQ+ip00dNj2Cv5sQjTuQdm6gYypLrXF9dPkE/W 2nl656TpObCBEqUvg=
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On 21/03/2023 11:06 am, Jan Beulich wrote:
> On 21.03.2023 11:51, Andrew Cooper wrote:
>> On 20/03/2023 9:56 pm, Dmitry Isaykin wrote:
>>> diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
>>> index 00b531f76c..0b7a302928 100644
>>> --- a/xen/arch/x86/hvm/vmx/vmx.c
>>> +++ b/xen/arch/x86/hvm/vmx/vmx.c
>>> @@ -4560,8 +4560,24 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs)
>>> break;
>>>
>>> case EXIT_REASON_IO_INSTRUCTION:
>>> + {
>>> + unsigned int port, bytes;
>>> + bool in, str;
>>> + int rc;
>>> +
>>> __vmread(EXIT_QUALIFICATION, &exit_qualification);
>>> - if ( exit_qualification & 0x10 )
>>> +
>>> + port = (exit_qualification >> 16) & 0xFFFF;
>>> + bytes = (exit_qualification & 0x07) + 1;
>>> + in = (exit_qualification & 0x08);
>>> + str = (exit_qualification & 0x10);
>>> + rc = hvm_monitor_io(port, bytes, in, str);
>>> + if ( rc < 0 )
>>> + goto exit_and_crash;
>>> + if ( rc )
>>> + break;
>>> +
>>> + if ( str )
>>> {
>>> /* INS, OUTS */
>>> if ( !hvm_emulate_one_insn(x86_insn_is_portio, "port I/O") )
>>> @@ -4570,13 +4586,11 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs)
>>> else
>>> {
>>> /* IN, OUT */
>>> - uint16_t port = (exit_qualification >> 16) & 0xFFFF;
>>> - int bytes = (exit_qualification & 0x07) + 1;
>>> - int dir = (exit_qualification & 0x08) ? IOREQ_READ :
>>> IOREQ_WRITE;
>>> - if ( handle_pio(port, bytes, dir) )
>>> + if ( handle_pio(port, bytes, in ? IOREQ_READ : IOREQ_WRITE) )
>>> update_guest_eip(); /* Safe: IN, OUT */
>>> }
>>> break;
>>> + }
>> Sorry for the delay. I've got the Intel side sorted now too with
>> https://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=f71f8e95c34fedb0d9ae21a100bfa9f012543abf
>>
>> The rebase is:
>>
>> diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
>> index 78ac9ece6ff2..7233e805a905 100644
>> --- a/xen/arch/x86/hvm/vmx/vmx.c
>> +++ b/xen/arch/x86/hvm/vmx/vmx.c
>> @@ -4578,6 +4578,14 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs)
>> __vmread(EXIT_QUALIFICATION, &io_qual.raw);
>> bytes = io_qual.size + 1;
>>
>> + rc = hvm_monitor_io(io_qual.port, bytes,
>> + io_qual.in ? IOREQ_READ : IOREQ_WRITE,
> Here the conditional operator needs dropping; it just "io_qual.in" which
> wants passing.
Oh, of course. In which case the delta is even smaller:
diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index 78ac9ece6ff2..076752d9e84b 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -4578,6 +4578,12 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs)
__vmread(EXIT_QUALIFICATION, &io_qual.raw);
bytes = io_qual.size + 1;
+ rc = hvm_monitor_io(io_qual.port, bytes, io_qual.in, io_qual.str);
+ if ( rc < 0 )
+ goto exit_and_crash;
+ if ( rc )
+ break;
+
if ( io_qual.str )
{
if ( !hvm_emulate_one_insn(x86_insn_is_portio, "port I/O") )
~Andrew
|