• Ricardo Neri's avatar
    x86/insn-eval: Add support to resolve 32-bit address encodings · 7a6daf79
    Ricardo Neri authored
    32-bit and 64-bit address encodings are identical. Thus, the same logic
    could be used to resolve the effective address. However, there are two key
    differences: address size and enforcement of segment limits.
    
    If running a 32-bit process on a 64-bit kernel, it is best to perform
    the address calculation using 32-bit data types. In this manner hardware
    is used for the arithmetic, including handling of signs and overflows.
    
    32-bit addresses are generally used in protected mode; segment limits are
    enforced in this mode. This implementation obtains the limit of the
    segment associated with the instruction operands and prefixes. If the
    computed address is outside the segment limits, an error is returned. It
    is also possible to use 32-bit address in long mode and virtual-8086 mode
    by using an address override prefix. In such cases, segment limits are not
    enforced.
    
    Support to use 32-bit arithmetic is added to the utility functions that
    compute effective addresses. However, the end result is stored in a
    variable of type long (which has a width of 8 bytes in 64-bit builds).
    Hence, once a 32-bit effective address is computed, the 4 most significant
    bytes are masked out to avoid sign extension.
    
    The newly added function get_addr_ref_32() is almost identical to the
    existing function insn_get_addr_ref() (used for 64-bit addresses). The only
    difference is that it verifies that the effective address is within the
    limits of the segment.
    Signed-off-by: default avatarRicardo Neri <ricardo.neri-calderon@linux.intel.com>
    Reviewed-by: default avatarThomas Gleixner <tglx@linutronix.de>
    Cc: Adam Buchbinder <adam.buchbinder@gmail.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: Andy Lutomirski <luto@kernel.org>
    Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Borislav Petkov <bp@alien8.de>
    Cc: Borislav Petkov <bp@suse.de>
    Cc: Brian Gerst <brgerst@gmail.com>
    Cc: Chen Yucong <slaoub@gmail.com>
    Cc: Chris Metcalf <cmetcalf@mellanox.com>
    Cc: Colin Ian King <colin.king@canonical.com>
    Cc: Dave Hansen <dave.hansen@linux.intel.com>
    Cc: Denys Vlasenko <dvlasenk@redhat.com>
    Cc: Dmitry Vyukov <dvyukov@google.com>
    Cc: H. Peter Anvin <hpa@zytor.com>
    Cc: Huang Rui <ray.huang@amd.com>
    Cc: Jiri Slaby <jslaby@suse.cz>
    Cc: Jonathan Corbet <corbet@lwn.net>
    Cc: Josh Poimboeuf <jpoimboe@redhat.com>
    Cc: Kees Cook <keescook@chromium.org>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Lorenzo Stoakes <lstoakes@gmail.com>
    Cc: Masami Hiramatsu <mhiramat@kernel.org>
    Cc: Michael S. Tsirkin <mst@redhat.com>
    Cc: Paolo Bonzini <pbonzini@redhat.com>
    Cc: Paul Gortmaker <paul.gortmaker@windriver.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Qiaowei Ren <qiaowei.ren@intel.com>
    Cc: Ravi V. Shankar <ravi.v.shankar@intel.com>
    Cc: Shuah Khan <shuah@kernel.org>
    Cc: Thomas Garnier <thgarnie@google.com>
    Cc: Tony Luck <tony.luck@intel.com>
    Cc: Vlastimil Babka <vbabka@suse.cz>
    Cc: ricardo.neri@intel.com
    Link: http://lkml.kernel.org/r/1509935277-22138-3-git-send-email-ricardo.neri-calderon@linux.intel.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
    7a6daf79
insn-eval.c 29.8 KB