Re: [PATCH 1/3] KVM: x86 emulator: fix negative bit offset BitOp instruction emulation

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

 



 On 08/06/2010 03:17 AM, Wei Yongjun wrote:
> If bit offset operands is a negative number, BitOp instruction
> will return wrong value. This patch fix it.
>
> +static void fetch_bit_operand(struct decode_cache *c)
> +{
> +	unsigned long mask, byte_offset;
> +
> +	if (c->dst.type == OP_MEM) {
> +		if (c->src.bytes == 2)
> +			c->src.val = (s16)c->src.val;
> +		else if (c->src.bytes == 4)
> +			c->src.val = (s32)c->src.val;

Better not to update in place, but instead use a local signed variable.

> +
> +		mask = ~(c->dst.bytes * 8 - 1);
> +
> +		if ((long)c->src.val < 0) {
> +			/* negative bit offset */
> +			byte_offset = c->dst.bytes +
> +				      ((-c->src.val - 1) & mask) / 8;
> +			c->dst.addr.mem -= byte_offset;
> +		} else {
> +			/* positive bit offset */
> +			c->dst.addr.mem += (c->src.val & mask) / 8;
> +		}
> +	}

Is the if () really necessary? If division translates to arithmetic
shift right, it might not be needed.

> +}
> +

-- 
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux