[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] x86/emul: Use existing X86_EXC_* constants
- To: Jan Beulich <jbeulich@xxxxxxxx>
- From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
- Date: Tue, 27 Apr 2021 19:56:41 +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-SenderADCheck; bh=UNba0iWHx+8tnNGEoXRZkYz9+FAmFBLwR09IWBw4wGs=; b=BELf1WkwlPEdBrTVjbew9Xi7xqBye59Exwp3oiiGqz0MLWX5FJSt1OzXJj6sZKEv7cGmMalzBbyktPJT5t/cnUvFE4vIF48aXsl9yaZu/V9qavr1nejsCXx1JwgTE7NocfEkjBFxr5pu/cX91jWFcVSnvokXWDSKM4ieM6ITwUITJzOmLn2WJDivVBeiqcZWilTyaZ8Q5yqduWudOA7s3uE3q52MOzxjsIhPx3cLtn4JZ1sWc7bw8M+gJqbOiockBL4n4hGiaPBzJ0zqBu5dDAi9DSbIYgCKydJ0wqr8vnYdf6YqyxnjaRcg/6mZAfQlDm8aq3NQf5TscOakkRpZCg==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EhoNKBm7CJlQZT5mKI9tNzaW9ZcX0Q8uP6CIIZUYbcTUNf0DRXa2kVUEzwayOALw0BWFBHSfuUUwzAaGfwEXs7rsTaACYMjl3LBsyYc3A0qX4wkWXec9Gs2GvlcL0AA2OlYd2W2a/TP8JZlmjXiSm5sBE1UL2K5D7VMEVpR//FyqjcnjMmAikvbzMkchYQQFkdx30cLoQwmT/kv5ywiq8A7rk103hdLlUrx0bCF/ZVpuISgHDolK4kjqTKLELgQl4wcwXCbppE/ZhDaeBvwljsruwtBbnWNowPdPzE6IR11kPdSdydZDEHBtoxePsE51mc78FcLygmhc9YDZbXfRIA==
- Authentication-results: esa6.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
- Cc: Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
- Delivery-date: Tue, 27 Apr 2021 18:57:00 +0000
- Ironport-hdrordr: A9a23:WuP1iqHjiM7m7OA9pLqFR5TXdLJzesId70hD6mlYcjYQWtCEls yogfQQ3QL1jjFUY307hdWcIsC7L0/03aVepa0cJ62rUgWjgmunK4l+8ZDvqgeOJwTXzcQY76 tpdsFFZOHYJURmjMr8/QmzG8shxt7Cy6yzmeLC1R5WLT1CQYsI1XYcNi+wFEpqSA5aQb8wE5 SB7sRKzgDQB0g/RMK9G3UDQqz/vNXNjp3relorABQg5QmIg1qTmcHHOjKf2QoTVC4K/Kc6/Q H+4nDEz4iAk9X+8B/T0GfP849b8eGB9vJvDNGB4/JlUQnEpR2vYO1aKtu/lRAz5Nqi8VM71O TLyi1QQvhbz1P0UiWLrQD22w/muQxemUPK7VODm3PsrYjYaVsBerJ8rLlUeBfY9EYs1esUuM kgshP7xvgneS/opyjz68PFUBtnjCOP0B0fuNUekmBFVs8mYKJRxLZvj399KosKHy7x9ekcYZ BTJfzbjcwmFG+yU2rUpS1GztCqQx0Ib227a3lHkMmU3z9KpWt+3ksVyecO901whK4Vet1q4f /JPb9vk6wLZsgKbbhlDONEesevDHfRKCi8fl66EBDCLuUqKnjNo5n47PEc4/yrQoUByN8XlI 7aWF1VmGYucyvVeIyz9awO1iqIbHS2XDzrxM0bzYN+oKfASL3iNjDGYEwykuO7ys9vQPHzar KWAtZ7EvXjJWzhFcJixAvlQaRfLnEYTYk8pss7YVSTucjGQ7ea9dDzQbL2Hv7AADwkUmTwDj 8oRz7oPvhN6UitRzvWmx7Ud3TxelHu3J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UKsgNiuc58 TQ3rMPYKmJlaY9ElTyaKBS/xcKy14dkY/ZnPf8Er0zuAdxW4teELgDVZo4CipbvL/Ljvu7lzWB s63wvBbomJ2H81wTPT/6Uq8YGFt+HVwScWRzEJshzh+cD0MaWp8WtlUDknhnHhdMdIDTRAzTMu GNY=
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On 27/04/2021 08:09, Jan Beulich wrote:
> On 26.04.2021 14:45, Andrew Cooper wrote:
>> ... rather than having separate definitions locally. EXC_HAS_EC in
>> particular
>> is missing #CP, #VC and #SX vs X86_EXC_HAVE_EC.
>>
>> Also switch a raw 14 for X86_EXC_PF in x86_emul_pagefault().
>>
>> No functional change.
>>
>> Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
>> ---
>> CC: Jan Beulich <JBeulich@xxxxxxxx>
>> CC: Roger Pau Monné <roger.pau@xxxxxxxxxx>
>> CC: Wei Liu <wl@xxxxxxx>
>> ---
>> xen/arch/x86/x86_emulate/x86_emulate.c | 739
>> ++++++++++++++++-----------------
>> xen/arch/x86/x86_emulate/x86_emulate.h | 4 +-
>> 2 files changed, 361 insertions(+), 382 deletions(-)
> This is a lot of code churn (almost all some slight growth) for this
> kind of a change.
Interestingly, no lines needed re-wrapping as a consequence.
[Answering out of order]
> The other option,
> not reducing churn but reducing rather than increasing code volume (and
> hence imo helping readability), would be to have shorthands for at
> least some frequently raised exceptions like #UD and #GP - e.g.
> generate_ud_if(). Thougths?
#UD and #GP[0] are the overwhelming majority of cases. If you want to
reduce code volume further, I've always found the "generate" on the
front rather gratuitous. "raise" is a more common expression to use
with exceptions.
> I'm not opposed, but I'd like to explore alternatives
> first. I know you often dislike token concatenation in macros, which
> would be my first suggestion to get churn down here.
Outside of a few specific cases, yes, but as you can see in XTF,
exception handling is one area where IMO clarity can be improved with
certain limited macro magic.
In the emulator, I could get behind a single #define RAISE() along the
lines of:
#define RAISE(e, ...)
do {
BUILD_BUG_ON(((X86_EXC_HAS_EC & (1u << X86_EXC_##e)) !=
__count_args(__VA_ARGS__));
x86_emul_hw_exception(X86_EXC_##e, __count_args(__VA_ARGS__) ?
__VA_ARGS__ : X86_EVENT_NO_EC, ctxt);
rc = X86EMUL_EXCEPTION;
goto done;
} while ( 0 )
It's obviously playing behind your back, unlike generate_exception(),
and does build-time checking that error codes are handled correctly
(unlike mkec() which has a substantial quantity of code bloat to not
actually handle it correctly at runtime).
I dislike _if() suffixed macros, again for obfuscation reasons.
if ( foo )
RAISE(UD);
is far more normal C than
RAISE_IF(UD, foo);
or
RAISE_IF(foo, UD);
neither if which is a natural reading order. The reduction in line
count does not equate to improved code clarity. Frankly, areas of
x86_emulate() would benefit greatly from extra spacing per our normal
coding style.
~Andrew
|