diff mbox

[v5,03/14] KVM: ARM: Initial skeleton to compile KVM support

Message ID CANM98qLHao0dJU57MbAtopVpTJDOVdqNtw5JT-DXyQNa7iD_qw@mail.gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Christoffer Dall Jan. 14, 2013, 5:33 p.m. UTC
On Mon, Jan 14, 2013 at 11:24 AM, Russell King - ARM Linux
<linux@arm.linux.org.uk> wrote:
> On Tue, Jan 08, 2013 at 01:38:55PM -0500, Christoffer Dall wrote:
>> +     /* -ENOENT for unknown features, -EINVAL for invalid combinations. */
>> +     for (i = 0; i < sizeof(init->features)*8; i++) {
>> +             if (init->features[i / 32] & (1 << (i % 32))) {
>
> Isn't this an open-coded version of test_bit() ?

indeed, nicely spotted:

commit 608588674144e403ad0ea3c93066f3175bd5cf88
Author: Christoffer Dall <c.dall@virtualopensystems.com>
Date:   Mon Jan 14 12:30:07 2013 -0500

    KVM: ARM: Use test-bit instead of open-coded version

    Makes the code more readable, also adds spaces around the asterisk.

    Cc: Russell King <linux@arm.linux.org.uk>
    Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com>

--

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

Comments

Rusty Russell Jan. 16, 2013, 2:56 a.m. UTC | #1
Christoffer Dall <c.dall@virtualopensystems.com> writes:

> On Mon, Jan 14, 2013 at 11:24 AM, Russell King - ARM Linux
> <linux@arm.linux.org.uk> wrote:
>> On Tue, Jan 08, 2013 at 01:38:55PM -0500, Christoffer Dall wrote:
>>> +     /* -ENOENT for unknown features, -EINVAL for invalid combinations. */
>>> +     for (i = 0; i < sizeof(init->features)*8; i++) {
>>> +             if (init->features[i / 32] & (1 << (i % 32))) {
>>
>> Isn't this an open-coded version of test_bit() ?
>
> indeed, nicely spotted:

BTW, I wrote it that was out of excessive paranoia: it's a userspace
API, and test_bit() won't be right on 64 bit BE systems.

Cheers,
Rusty.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Russell King - ARM Linux Jan. 16, 2013, 9:44 a.m. UTC | #2
On Wed, Jan 16, 2013 at 01:26:01PM +1030, Rusty Russell wrote:
> Christoffer Dall <c.dall@virtualopensystems.com> writes:
> 
> > On Mon, Jan 14, 2013 at 11:24 AM, Russell King - ARM Linux
> > <linux@arm.linux.org.uk> wrote:
> >> On Tue, Jan 08, 2013 at 01:38:55PM -0500, Christoffer Dall wrote:
> >>> +     /* -ENOENT for unknown features, -EINVAL for invalid combinations. */
> >>> +     for (i = 0; i < sizeof(init->features)*8; i++) {
> >>> +             if (init->features[i / 32] & (1 << (i % 32))) {
> >>
> >> Isn't this an open-coded version of test_bit() ?
> >
> > indeed, nicely spotted:
> 
> BTW, I wrote it that was out of excessive paranoia: it's a userspace
> API, and test_bit() won't be right on 64 bit BE systems.

So why is this a concern for 32-bit systems (which are, by definition,
only in arch/arm) ?
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Rusty Russell Jan. 17, 2013, 2:11 a.m. UTC | #3
Russell King - ARM Linux <linux@arm.linux.org.uk> writes:
> On Wed, Jan 16, 2013 at 01:26:01PM +1030, Rusty Russell wrote:
>> Christoffer Dall <c.dall@virtualopensystems.com> writes:
>> 
>> > On Mon, Jan 14, 2013 at 11:24 AM, Russell King - ARM Linux
>> > <linux@arm.linux.org.uk> wrote:
>> >> On Tue, Jan 08, 2013 at 01:38:55PM -0500, Christoffer Dall wrote:
>> >>> +     /* -ENOENT for unknown features, -EINVAL for invalid combinations. */
>> >>> +     for (i = 0; i < sizeof(init->features)*8; i++) {
>> >>> +             if (init->features[i / 32] & (1 << (i % 32))) {
>> >>
>> >> Isn't this an open-coded version of test_bit() ?
>> >
>> > indeed, nicely spotted:
>> 
>> BTW, I wrote it that was out of excessive paranoia: it's a userspace
>> API, and test_bit() won't be right on 64 bit BE systems.
>
> So why is this a concern for 32-bit systems (which are, by definition,
> only in arch/arm) ?

Because this feature bitmap system is the same code which other archs
*should* be using for specifying kvm cpus :)

Cheers,
Rusty.


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

Patch

diff --git a/arch/arm/kvm/guest.c b/arch/arm/kvm/guest.c
index 65ae563..2339d96 100644
--- a/arch/arm/kvm/guest.c
+++ b/arch/arm/kvm/guest.c
@@ -193,8 +193,8 @@  int kvm_vcpu_set_target(struct kvm_vcpu *vcpu,
 	bitmap_zero(vcpu->arch.features, KVM_VCPU_MAX_FEATURES);

 	/* -ENOENT for unknown features, -EINVAL for invalid combinations. */
-	for (i = 0; i < sizeof(init->features)*8; i++) {
-		if (init->features[i / 32] & (1 << (i % 32))) {
+	for (i = 0; i < sizeof(init->features) * 8; i++) {
+		if (test_bit(i, (void *)init->features)) {
 			if (i >= KVM_VCPU_MAX_FEATURES)
 				return -ENOENT;
 			set_bit(i, vcpu->arch.features);