[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 3/8] x86/emul: Add pending_dbg field to x86_event


  • To: Jan Beulich <jbeulich@xxxxxxxx>, Jinoh Kang <jinoh.kang.kr@xxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Wed, 30 Aug 2023 14:51:00 +0100
  • 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=91OXY1DoIUE5Y42/bGq0w6nZAhgPs6qUAlIYq4nHpiI=; b=iPQEWRBWnaIpzFMfBoZc+xQECWHYyyeysFKCNWCiBO0eAIbDJd4RO7eMHyiFEAVEHuO2w5DM9ftQqPE4kMlvs42DdsDz3RY0grPdra1RsIYqtBRZQ99e43cpwSTW+aVOFXrpcBUoMJNVQkd8JTaqaY8eLIITQUcuX7re2aQYSvsfbZDfuQMN/UavU9CAYqjXW4V4onhs3M9yOijgTctAbyhVTfLpezRlKt89dOXJQ8ktOLz4zxf8sXUwc1K7CiV4diYOgsl0osXsEfEkRmN2dO7mZnMUxEWdy3Olp8uAaMOERYTE9TgBq7SBvweAtrBYnRJgzAMMjS3sFdRwuqs8NQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GZGfJHNmQxUu+SbG0Tcz15YXZYLGyaF6UJB50C6DsKGBpUvcV76sgsfNikGTLHkgJYYDRUZLVkk5v1Qlmv6sXLzwBW6gixux3QLo4wVpkbHr1qeWNrHGEEou8m9ajxoOqwZvwAhgPAnBXtyTuewWMlwUF43DVjmDfqYzJcFLoIuw+RIptaFFjPhQal3X68SLFAW75nX+7tGnYbdFL94VdS10HfuubNitr5qE8Ivs4TCNat6ynMwPofjODD/I5vrNlSp6+n400jxtEKLxi+at52J3BBrjhY0aEhiB95HAy91ZGaKczrQm/4iMK3bVhbfEGenag/BaBtO53HPh3UGVWA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Jun Nakajima <jun.nakajima@xxxxxxxxx>, Kevin Tian <kevin.tian@xxxxxxxxx>, Tim Deegan <tim@xxxxxxx>, Tamas K Lengyel <tamas@xxxxxxxxxxxxx>, Alexandru Isaila <aisaila@xxxxxxxxxxxxxxx>, Petre Pircalabu <ppircalabu@xxxxxxxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Wed, 30 Aug 2023 13:51:15 +0000
  • Ironport-data: A9a23:QyQ6dKqmoDcZ7gatlKRiZ+QzFbheBmJbZRIvgKrLsJaIsI4StFCzt garIBmDbv7ZY2fzc41zYYS1oEkBu5TWn9Y3QFRurX9hRC4apZuZCYyVIHmrMnLJJKUvbq7FA +Y2MYCccZ9uHhcwgj/3b9ANeFEljfngqoLUUbKCYWYpA1c/Ek/NsDo788YhmIlknNOlNA2Ev NL2sqX3NUSsnjV5KQr40YrawP9UlKq04GlwUmAWP6gR5weOzCFNVvrzGInqR5fGatgMdgKFb 76rIIGRpgvx4xorA9W5pbf3GmVirmn6ZFXmZtJ+AsBOszAazsAA+v9T2Mk0MC+7vw6hjdFpo OihgLTrIesf0g8gr8xGO/VQO3kW0aSrY9YrK1Dn2SCY5xWun3cBX5yCpaz5VGEV0r8fPI1Ay RAXABZQUD+kusGu/LK2DexSgfUfPpniDapK7xmMzRmBZRonabbqZvyQoPN9gnI3jM0IGuvCb c0EbzYpdA7HfxBEJlYQDtQ5gfusgX78NTZfrTp5p4JuuzSVkFM3jemraYSEEjCJbZw9ckKwj 2TK5WnmRDodM8SS02Gt+XOwnO7f2yj8Xer+EZXhrKU62wXJnTZ75Bs+ZVq9gtfjsG2EdflfK k4M4RgIrqJp+xn+JjX6d1jiyJKehTYeUddNF+wx6CmW17HZpQ2eAwAsTD9Hb9xgt8YwSnopz HeGmtroAXpkt7j9YW2Z3qeZq3W1Iyd9BW0fY2kCRAgM4djmqakyiA7CSpBoF6vdpt74BzD2h SyLpS4WhrMPgMpN3KK+lXjbgjeEtpXPCAkv6W3/Qmug5xhReI2haoqn+FXfq/1HKe6xR1iat XkAkuCU7fwCAJ+AkiCAWqMGG7TBz+6dMSfXiFpmFYQJ/TWx93OtcIZc7Ss4L0BsWu4UdDmsb ELNtAd54J5IIGDsfaJxe5i2Cckh0e7nD9uNaxzPRt9HY5w0eArZ+ihrPBSUxzq0zhlqlrwjM 5CGd8rqFWwdFals0DuxQaEazKMvwSc9g2jUQPgX0iia7FZXX1bNIZ9tDbdERrpRAH+syOkNz +tiCg==
  • Ironport-hdrordr: A9a23:3WdUja/kbyJsFO4dgEJuk+AKI+orL9Y04lQ7vn2ZHyYlDvBws/ re58jzsiWE8Ar5OUtQ4OxoXZPrfZqyz+8X3WB8B9eftUzdyQ6VxeJZnO3fKl/bak/DH7VmpN 1dmsFFYbWaMbE5t7ef3ODSKadG/DDoysGVrNab52txSxpncqRxhj0Jdzpz0XcbeOCFP/cE/V anifavbgDPRUgq
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 30/08/2023 2:30 pm, Jan Beulich wrote:
> On 24.08.2023 17:26, Jinoh Kang wrote:
>> From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
>>
>> All #DB exceptions result in an update of %dr6, but this isn't captured in
>> Xen's handling.
>>
>> PV guests generally work by modifying %dr6 before raising #DB, whereas HVM
>> guests do nothing and have a single-step special case in the lowest levels of
>> {vmx,svm}_inject_event().  All of this is buggy, but in particular, task
>> switches with the trace flag never end up signalling BT in %dr6.
>>
>> To begin resolving this issue, add a new pending_dbg field to x86_event
>> (unioned with cr2 to avoid taking any extra space), and introduce
>> {pv,hvm}_inject_debug_exn() helpers to replace the current callers using
>> {pv,hvm}_inject_hw_exception().
>>
>> A key property is that pending_dbg is taken with positive polarity to deal
>> with RTM sensibly.  Most callers pass in a constant, but callers passing in a
>> hardware %dr6 value need to xor the value with X86_DR6_DEFAULT to flip the
>> polarity of RTM and reserved fields.
>>
>> For PV guests, move the ad-hoc updating of %dr6 into pv_inject_event().  This
>> in principle breaks the handing of RTM in do_debug(), but PV guests can't
>> actually enable MSR_DEBUGCTL.RTM yet, so this doesn't matter in practice.
>>
>> Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
>> Reviewed-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
>> Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
>> [ jinoh: Rebase onto staging, forward declare struct vcpu ]
>> Signed-off-by: Jinoh Kang <jinoh.kang.kr@xxxxxxxxx>
>> ---
>> CC: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
>> CC: Jan Beulich <JBeulich@xxxxxxxx>
>> CC: Wei Liu <wl@xxxxxxx>
>> CC: Roger Pau Monné <roger.pau@xxxxxxxxxx>
>> CC: Jun Nakajima <jun.nakajima@xxxxxxxxx>
>> CC: Kevin Tian <kevin.tian@xxxxxxxxx>
>> CC: Tim Deegan <tim@xxxxxxx>
>> CC: Tamas K Lengyel <tamas@xxxxxxxxxxxxx>
>> CC: Alexandru Isaila <aisaila@xxxxxxxxxxxxxxx>
>> CC: Petre Pircalabu <ppircalabu@xxxxxxxxxxxxxxx>
>>
>> v1 -> v2: [S-o-b fixes. More details below.]
>>
>> - Update DR6 for gdbsx when trapped in PV guest kernel mode
> I take it that this refers to ...
>
>> --- a/xen/arch/x86/traps.c
>> +++ b/xen/arch/x86/traps.c
>> @@ -1989,17 +1989,17 @@ void do_debug(struct cpu_user_regs *regs)
>>          return;
>>      }
>>  
>> -    /* Save debug status register where guest OS can peek at it */
>> -    v->arch.dr6 |= (dr6 & ~X86_DR6_DEFAULT);
>> -    v->arch.dr6 &= (dr6 | ~X86_DR6_DEFAULT);
>> -
>>      if ( guest_kernel_mode(v, regs) && v->domain->debugger_attached )
>>      {
>> +        /* Save debug status register where gdbsx can peek at it */
>> +        v->arch.dr6 |= (dr6 & ~X86_DR6_DEFAULT);
>> +        v->arch.dr6 &= (dr6 | ~X86_DR6_DEFAULT);
>> +
>>          domain_pause_for_debugger();
>>          return;
>>      }
> ... this code movement. I'm afraid this should have resulted in you
> dropping the earlier R-b, and I'm further afraid I'm not convinced 
> this is correct, despite seeing why you would want to do this. The
> issue is that this way you also alter guest-visible state, when the
> intention is that such now happen via ...
>
>> -    pv_inject_hw_exception(X86_EXC_DB, X86_EVENT_NO_EC);
>> +    pv_inject_debug_exn(dr6 ^ X86_DR6_DEFAULT);
>>  }
> ... this call alone. I fear I can't currently see how to get both
> aspects right, other than by breaking up

I think it was wrongly broken up in my RFC series too.

With hindsight, I think the series wants rearranging to introduce
x86_merge_dr6() first, and then fix up PV and HVM separately.  They're
independent logic paths.

~Andrew



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.