static ulong reg_read(struct x86_emulate_ctxt *ctxt, unsigned nr)
 {
-       if (WARN_ON_ONCE(nr >= 16))
-               nr &= 16 - 1;
+       if (WARN_ON_ONCE(nr >= NR_EMULATOR_GPRS))
+               nr &= NR_EMULATOR_GPRS - 1;
 
        if (!(ctxt->regs_valid & (1 << nr))) {
                ctxt->regs_valid |= 1 << nr;
 
 static ulong *reg_write(struct x86_emulate_ctxt *ctxt, unsigned nr)
 {
-       if (WARN_ON_ONCE(nr >= 16))
-               nr &= 16 - 1;
+       if (WARN_ON_ONCE(nr >= NR_EMULATOR_GPRS))
+               nr &= NR_EMULATOR_GPRS - 1;
 
        ctxt->regs_valid |= 1 << nr;
        ctxt->regs_dirty |= 1 << nr;
        unsigned long dirty = ctxt->regs_dirty;
        unsigned reg;
 
-       for_each_set_bit(reg, &dirty, 16)
+       for_each_set_bit(reg, &dirty, NR_EMULATOR_GPRS)
                ctxt->ops->write_gpr(ctxt, reg, ctxt->_regs[reg]);
 }
 
 
 
 typedef void (*fastop_t)(struct fastop *);
 
+/*
+ * The emulator's _regs array tracks only the GPRs, i.e. excludes RIP.  RIP is
+ * tracked/accessed via _eip, and except for RIP relative addressing, which
+ * also uses _eip, RIP cannot be a register operand nor can it be an operand in
+ * a ModRM or SIB byte.
+ *
+ * TODO: this is technically wrong for 32-bit KVM, which only supports 8 GPRs;
+ * R8-R15 don't exist.
+ */
+#define NR_EMULATOR_GPRS       16
+
 struct x86_emulate_ctxt {
        void *vcpu;
        const struct x86_emulate_ops *ops;
        struct operand src2;
        struct operand dst;
        struct operand memop;
-       unsigned long _regs[NR_VCPU_REGS];
+       unsigned long _regs[NR_EMULATOR_GPRS];
        struct operand *memopp;
        struct fetch_cache fetch;
        struct read_cache io_read;