Skip to contentSkip to conversation

qemu: target library, use it in msix

PATCH Superseded Michael S. Tsirkin 13 participants 63 messages Sep 23, 2009 – Oct 1, 2009 Kbuild

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 qemu: target library, use it in msix

This creates target.c, which builds per-target, and makes it possible for devices to become target-independent. Use it in msix, reverting part of 5e520a7d500ec2569d22d80f9ef4272a34cb3c80, as we no longer have to pass target page around.

---
 Makefile.target |    3 +++
 hw/msix.c       |   51 ++++++++++++++++++++++++++-------------------------
 hw/msix.h       |    5 ++---
 hw/pci.h        |    6 ------
 hw/virtio-pci.c |    3 +--
 target.c        |   17 +++++++++++++++++
 target.h        |    6 ++++++
 7 files changed, 55 insertions(+), 36 deletions(-)
 create mode 100644 target.c
 create mode 100644 target.h
Makefile.target +3 -0
index 0ebef17..c0f143a 100644
@@ -55,6 +55,9 @@ libobj-$(CONFIG_S390_DIS) += s390-dis.o
 libobj-$(CONFIG_SH4_DIS) += sh4-dis.o
 libobj-$(CONFIG_SPARC_DIS) += sparc-dis.o
 
+# Target library: makes devices target-independent
+libobj-y += target.o
+
 # libqemu
 
 libqemu.a: $(libobj-y)
hw/msix.c +26 -25

135 lines not on this page · raw message

hw/msix.h +2 -3
index 9367ba3..3427778 100644
@@ -3,9 +3,8 @@
 
 #include "qemu-common.h"
 
-int msix_init(struct PCIDevice *dev, unsigned short nentries,
-              unsigned bar_nr, unsigned bar_size,
-              target_phys_addr_t page_size);
+int msix_init(PCIDevice *pdev, unsigned short nentries,
+              unsigned bar_nr, unsigned bar_size);
 
 void msix_write_config(PCIDevice *pci_dev, uint32_t address,
                        uint32_t val, int len);
hw/pci.h +0 -6
index dddd599..8cfc38d 100644
@@ -214,12 +214,6 @@ struct PCIDevice {
     uint32_t msix_bar_size;
     /* Version id needed for VMState */
     int32_t version_id;
-    /* How much space does an MSIX table need. */
-    /* The spec requires giving the table structure
-     * a 4K aligned region all by itself. Align it to
-     * target pages so that drivers can do passthrough
-     * on the rest of the region. */
-    target_phys_addr_t msix_page_size;
 };
 
 PCIDevice *pci_register_device(PCIBus *bus, const char *name,
hw/virtio-pci.c +1 -2
index 1f14c5e..3a0231e 100644
@@ -410,8 +410,7 @@ static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev,
 
     config[0x3d] = 1;
 
-    if (vdev->nvectors && !msix_init(&proxy->pci_dev, vdev->nvectors, 1, 0,
-                                     TARGET_PAGE_SIZE)) {
+    if (vdev->nvectors && !msix_init(&proxy->pci_dev, vdev->nvectors, 1, 0)) {
         pci_register_bar(&proxy->pci_dev, 1,
                          msix_bar_size(&proxy->pci_dev),
                          PCI_ADDRESS_SPACE_MEM,
target.c new file +17 -0
new file mode 100644
index 0000000..3287eea
@@ -0,0 +1,17 @@
+/* 
+ * Target definitions for use by devices.
+ *
+ * Author: Michael S. Tsirkin <[email protected]>
+ *
+ * Copyright (c) 2009, Red Hat Inc, Michael S. Tsirkin ([email protected])
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+#include "qemu-common.h"
+#include "target.h"
+
+unsigned target_page_align(unsigned value)
+{
+	return TARGET_PAGE_ALIGN(value);
+}
target.h new file +6 -0
new file mode 100644
index 0000000..0e01e47
@@ -0,0 +1,6 @@
+#ifndef QEMU_TARGET_H
+#define QEMU_TARGET_H
+
+unsigned target_page_align(unsigned value);
+
+#endif
Signature · 1 line
1.6.5.rc2
#1 lore raw

target.c line 17

Quoted 9 lines · Michael S. Tsirkin

This creates target.c, which builds per-target, and makes it possible for devices to become target-independent.  Use it in msix, reverting part of 5e520a7d500ec2569d22d80f9ef4272a34cb3c80, as we no longer have to pass target page around.

target.c new file +4 -0
+unsigned target_page_align(unsigned value)
+{
+       return TARGET_PAGE_ALIGN(value);
+}

This must be:
target_phys_addr_t target_page_align(target_phys_addr_t value)

As this is not a clean revert anyway, please don't revert the part changing if (x)
y;
else
z;

to

if (x) {
y;
} else {
z;
}

#2 lore raw
Quoted 6 lines · Blue Swirl
Quoted 4 lines · Michael S. Tsirkin

This creates target.c, which builds per-target, and makes it possible for devices to become target-independent.  Use it in msix, reverting part of 5e520a7d500ec2569d22d80f9ef4272a34cb3c80, as we no longer have to pass target page around.

Quoted 7 lines

target.c line 17

Quoted 4 lines
target.c new file +4 -0
+unsigned target_page_align(unsigned value)
+{
+       return TARGET_PAGE_ALIGN(value);
+}

This must be:
target_phys_addr_t target_page_align(target_phys_addr_t value)

what's the point then? It has to be target independent. Let's make it unsigned long long, should be good enough.

Quoted 6 lines

As this is not a clean revert anyway, please don't revert the part changing if (x)
y;
else
z;

Quoted 7 lines

to

if (x) {
y;
} else {
z;
}

Did I mention I hate this style? But okay :).

Signature · 1 line
MST
#3 lore raw
Quoted 15 lines · Michael S. Tsirkin
Quoted 6 lines · Blue Swirl
Quoted 4 lines · Michael S. Tsirkin

This creates target.c, which builds per-target, and makes it possible for devices to become target-independent.  Use it in msix, reverting part of 5e520a7d500ec2569d22d80f9ef4272a34cb3c80, as we no longer have to pass target page around.

Quoted 7 lines

target.c line 17

Quoted 4 lines
target.c new file +4 -0
+unsigned target_page_align(unsigned value)
+{
+       return TARGET_PAGE_ALIGN(value);
+}

This must be:
target_phys_addr_t target_page_align(target_phys_addr_t value)

Quoted 2 lines

what's the point then? It has to be target independent. Let's make it unsigned long long, should be good enough.

target_phys_addr_t is handled by hwlib definitions, so it can be used for hwlib devices. If you can remove all target_phys_addr_t uses, then the compilation of the file could be moved from Makefile.hw to Makefile.

One day the bus addresses should be decoupled from the target CPU addresses, but for now we are stick with target_phys_addr_t.

Quoted 8 lines
Quoted 8 lines

As this is not a clean revert anyway, please don't revert the part changing if (x)
 y;
else
 z;

to

Quoted 7 lines
Quoted 5 lines

if (x) {
 y;
} else {
 z;
}

Did I mention I hate this style? But okay :).

I'm not a great fan of this either, but this is the CODING_STYLE.

#4 lore raw

[Qemu-devel] CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix)

Quoted 14 lines · Blue Swirl
Quoted 14 lines
Quoted 13 lines

As this is not a clean revert anyway, please don't revert the part changing if (x)
 y;
else
 z;

to

if (x) {
 y;
} else {
 z;
}

Quoted 3 lines
Quoted 1 line

Did I mention I hate this style? But okay :).

I'm not a great fan of this either, but this is the CODING_STYLE.

Maybe we can all vote to change this?

Signature · 1 line
MST
#5 lore raw

[Qemu-devel] Re: CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix)

Quoted 15 lines · Michael S. Tsirkin
Quoted 14 lines · Blue Swirl
Quoted 14 lines
Quoted 13 lines

As this is not a clean revert anyway, please don't revert the part changing if (x)
 y;
else
 z;

to

if (x) {
 y;
} else {
 z;
}

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Did I mention I hate this style? But okay :).

I'm not a great fan of this either, but this is the CODING_STYLE.

Maybe we can all vote to change this?

Actually, I tried to tweak 'indent' to match QEMU style without much success.

We could also select a new style, like Linux kernel one. I'm also not a great fan of that either. But at least 'indent' could be used very easily and I think there would be other benefits, like reuse of Git hooks, patch checking scripts and Emacs configs. With full 'indent' support all sources could be massaged mechanically to make the switch less painful.

Then there are K&R and GNU styles, but I like them even less.

#6 lore raw

[Qemu-devel] Re: CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix)

Quoted 24 lines · Blue Swirl
Quoted 15 lines · Michael S. Tsirkin
Quoted 14 lines · Blue Swirl
Quoted 14 lines
Quoted 13 lines

As this is not a clean revert anyway, please don't revert the part changing if (x)
 y;
else
 z;

to

if (x) {
 y;
} else {
 z;
}

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Did I mention I hate this style? But okay :).

I'm not a great fan of this either, but this is the CODING_STYLE.

Maybe we can all vote to change this?

Actually, I tried to tweak 'indent' to match QEMU style without much success.

Quoted 8 lines

We could also select a new style, like Linux kernel one. I'm also not a great fan of that either. But at least 'indent' could be used very easily and I think there would be other benefits, like reuse of Git hooks, patch checking scripts and Emacs configs. With full 'indent' support all sources could be massaged mechanically to make the switch less painful.

Then there are K&R and GNU styles, but I like them even less.

So ... Linux kernel style wins? What do others think?

Signature · 1 line
MST
#7 lore raw

Re: [Qemu-devel] Re: CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix)

Quoted 32 lines · Michael S. Tsirkin
Quoted 31 lines · Blue Swirl
Quoted 15 lines · Michael S. Tsirkin
Quoted 14 lines · Blue Swirl
Quoted 14 lines
Quoted 13 lines

As this is not a clean revert anyway, please don't revert the part changing if (x)
 y;
else
 z;

to

if (x) {
 y;
} else {
 z;
}

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Did I mention I hate this style? But okay :).

I'm not a great fan of this either, but this is the CODING_STYLE.

Maybe we can all vote to change this?

Actually, I tried to tweak 'indent' to match QEMU style without much success.

We could also select a new style, like Linux kernel one. I'm also not a great fan of that either. But at least 'indent' could be used very easily and I think there would be other benefits, like reuse of Git hooks, patch checking scripts and Emacs configs. With full 'indent' support all sources could be massaged mechanically to make the switch less painful.

Quoted 3 lines
Quoted 1 line

Then there are K&R and GNU styles, but I like them even less.

So ... Linux kernel style wins? What do others think?

I don't think so.

Signature · 1 line
mailto:[email protected]
#8 lore raw

Re: [Qemu-devel] Re: CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix)

In reply to Michael S. Tsirkin
Quoted 2 lines · Michael S. Tsirkin

So ... Linux kernel style wins? What do others think?

Any change is going to cause a large amount of pain if implemented.

Signature · 1 line
error compiling committee.c: too many arguments to function
#9 lore raw

Re: [Qemu-devel] Re: CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix)

Quoted 7 lines · Avi Kivity
Quoted 3 lines · Michael S. Tsirkin

So ... Linux kernel style wins? What do others think?

Any change is going to cause a large amount of pain if implemented.

True, but with 'indent' support the pain would be brief.

#10 lore raw

Re: [Qemu-devel] Re: CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix)

Quoted 4 lines · Blue Swirl
Quoted 2 lines · Avi Kivity

On 09/30/2009 03:51 PM, Michael S. Tsirkin wrote:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

So ... Linux kernel style wins? What do others think?

Any change is going to cause a large amount of pain if implemented.

True, but with 'indent' support the pain would be brief.

It's equivalent to losing a massive amount of revision history which hurts debugging.

Regards,

Anthony Liguori

#11 lore raw

Re: [Qemu-devel] Re: CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix)

Quoted 8 lines · Anthony Liguori
Quoted 7 lines · Blue Swirl
Quoted 5 lines · Avi Kivity
Quoted 3 lines · Michael S. Tsirkin

So ... Linux kernel style wins? What do others think?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Any change is going to cause a large amount of pain if implemented.

True, but with 'indent' support the pain would be brief.

It's equivalent to losing a massive amount of revision history which hurts debugging.

It is? Why is it? git bisect still works. what else do you use for debugging that gets broken?

Quoted 4 lines

Regards,

Anthony Liguori

#12 lore raw

Re: [Qemu-devel] Re: CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix)

Am 01.10.2009 08:17, schrieb Michael S. Tsirkin:

Quoted 12 lines · Anthony Liguori
Quoted 11 lines
Quoted 10 lines · Blue Swirl
Quoted 7 lines · Avi Kivity
Quoted 3 lines · Michael S. Tsirkin

So ... Linux kernel style wins? What do others think?

Any change is going to cause a large amount of pain if implemented.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

True, but with 'indent' support the pain would be brief.

It's equivalent to losing a massive amount of revision history which hurts debugging.

It is? Why is it? git bisect still works. what else do you use for debugging that gets broken?

git blame.

Kevin

#13 lore raw

Re: [Qemu-devel] Re: CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix)

Quoted 19 lines · Kevin Wolf

Am 01.10.2009 08:17, schrieb Michael S. Tsirkin:

Quoted 18 lines · Anthony Liguori
Quoted 16 lines
Quoted 4 lines · Blue Swirl
Quoted 2 lines · Avi Kivity

On 09/30/2009 03:51 PM, Michael S. Tsirkin wrote:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

So ... Linux kernel style wins? What do others think?

Any change is going to cause a large amount of pain if implemented.

True, but with 'indent' support the pain would be brief.

It's equivalent to losing a massive amount of revision history which hurts debugging.

Quoted 6 lines
Quoted 2 lines

It is? Why is it? git bisect still works. what else do you use for debugging that gets broken?

git blame.

Kevin

I think git blame has "-w" flag to ignore whitespace changes.

#14 lore raw

Re: [Qemu-devel] Re: CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix)

Am 01.10.2009 10:58, schrieb Michael S. Tsirkin:

Quoted 20 lines · Kevin Wolf
Quoted 19 lines

Am 01.10.2009 08:17, schrieb Michael S. Tsirkin:

Quoted 18 lines · Anthony Liguori
Quoted 16 lines
Quoted 4 lines · Blue Swirl
Quoted 2 lines · Avi Kivity

On 09/30/2009 03:51 PM, Michael S. Tsirkin wrote:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

So ... Linux kernel style wins? What do others think?

Any change is going to cause a large amount of pain if implemented.

True, but with 'indent' support the pain would be brief.

It's equivalent to losing a massive amount of revision history which hurts debugging.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

It is? Why is it? git bisect still works. what else do you use for debugging that gets broken?

git blame.

Kevin

I think git blame has "-w" flag to ignore whitespace changes.

Are we only talking about changing the indentation? Switching from 4 spaces to tabs of 8 characters also means additional line breaks and so on (or does it handle these, too?). And I thought I read in this thread about braces, typedefs and probably some more things. Can -w really handle all of them?

Kevin

#15 lore raw

Re: [Qemu-devel] Re: CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix)

Quoted 30 lines · Kevin Wolf

Am 01.10.2009 10:58, schrieb Michael S. Tsirkin:

Quoted 20 lines · Kevin Wolf
Quoted 19 lines

Am 01.10.2009 08:17, schrieb Michael S. Tsirkin:

Quoted 18 lines · Anthony Liguori
Quoted 16 lines
Quoted 4 lines · Blue Swirl
Quoted 2 lines · Avi Kivity

On 09/30/2009 03:51 PM, Michael S. Tsirkin wrote:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

So ... Linux kernel style wins? What do others think?

Any change is going to cause a large amount of pain if implemented.

True, but with 'indent' support the pain would be brief.

It's equivalent to losing a massive amount of revision history which hurts debugging.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

It is? Why is it? git bisect still works. what else do you use for debugging that gets broken?

git blame.

Kevin

I think git blame has "-w" flag to ignore whitespace changes.

Quoted 7 lines

Are we only talking about changing the indentation? Switching from 4 spaces to tabs of 8 characters also means additional line breaks and so on (or does it handle these, too?). And I thought I read in this thread about braces, typedefs and probably some more things. Can -w really handle all of them?

Kevin

No. But if a line is very long, any code refactoring will create the same effect. Most lines arent that long.

Signature · 1 line
MST
#16 lore raw

Re: [Qemu-devel] Re: CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix)

In reply to Blue Swirl
Quoted 4 lines · Blue Swirl
Quoted 2 lines · Avi Kivity

On 09/30/2009 03:51 PM, Michael S. Tsirkin wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

So ... Linux kernel style wins? What do others think?

Any change is going to cause a large amount of pain if implemented.

True, but with 'indent' support the pain would be brief.

External trees (qemu-kvm, the Xen tree, distros which carry patches) will all have to adapt, just so that we can reach 80 columns twice as quickly.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#17 lore raw

Re: [Qemu-devel] Re: CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix)

Quoted 9 lines · Avi Kivity
Quoted 8 lines · Blue Swirl
Quoted 6 lines · Avi Kivity
Quoted 3 lines · Michael S. Tsirkin

So ... Linux kernel style wins? What do others think?

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Any change is going to cause a large amount of pain if implemented.

True, but with 'indent' support the pain would be brief.

External trees (qemu-kvm, the Xen tree, distros which carry patches) will all have to adapt, just so that we can reach 80 columns twice as quickly.

Can external trees just run indent themselves before merging upstream?

Quoted 2 lines
Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#18 lore raw

[Qemu-devel] Re: CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix)

Quoted 9 lines
Quoted 7 lines
Quoted 3 lines

True, but with 'indent' support the pain would be brief.

External trees (qemu-kvm, the Xen tree, distros which carry patches) will all have to adapt, just so that we can reach 80 columns twice as quickly.

Can external trees just run indent themselves before merging upstream?

That does not help merging. You have "git blame -w" but not "git merge -w".

You can run a huge "git merge -s ours" (or add a jumbo patch to the distribution), but you still have to make sure you do not introduce spacing differences WRT upstream, or _future_ conflicts will be even worse.

Personally I believe it is not worth it. I think that incremental updates to the coding style are enough, and not too bad if we go on with 4-space soft tabs; whipping up a version of checkpatch that supports 4-space indent should not be hard.

Which means, you do not need to do much besides deciding how you want the braces.

Paolo

#19 lore raw

Re: [Qemu-devel] Re: CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix)

In reply to Avi Kivity
Quoted 6 lines · Avi Kivity
Quoted 2 lines · Michael S. Tsirkin

So ... Linux kernel style wins? What do others think?

Any change is going to cause a large amount of pain if implemented.

First thing would be to start running checkpatch on submissions. This way, we gradually convert. Current style does not have automated checker, so new code constantly deviates from it.

Quoted 2 lines
Signature · 1 line
error compiling committee.c: too many arguments to function
#20 lore raw

[Qemu-devel] Re: CODING_STYLE

In reply to Michael S. Tsirkin

"Michael S. Tsirkin" <[email protected]> wrote:

....

Quoted 9 lines
Quoted 9 lines

Actually, I tried to tweak 'indent' to match QEMU style without much success.

We could also select a new style, like Linux kernel one. I'm also not a great fan of that either. But at least 'indent' could be used very easily and I think there would be other benefits, like reuse of Git hooks, patch checking scripts and Emacs configs. With full 'indent' support all sources could be massaged mechanically to make the switch less painful.

Quoted 3 lines
Quoted 1 line

Then there are K&R and GNU styles, but I like them even less.

So ... Linux kernel style wins? What do others think?

Where do I have to sign?

I very much prefer Linux kernel style, but that is a preference. Having an style that indent understands is a great idea, as it makes trivial to make sure that you are not going againsnt CodingStyle. Bigger advantage of Linux Kernel one is the infrastructure/hooks already again.

Later, Juan.

PD. I am also in the team that dislikes K&R and GNU (speciall GNU).

Quoted 1 line

From linux-2.6/Documentation/CodingStyle

Linux kernel coding style

.....

First off, I'd suggest printing out a copy of the GNU coding standards, and NOT read it. Burn them, it's a great symbolic gesture.

#21 lore raw

Re: [Qemu-devel] Re: CODING_STYLE

Quoted 13 lines · Juan Quintela

"Michael S. Tsirkin" <[email protected]> wrote:

....

Quoted 9 lines
Quoted 9 lines

Actually, I tried to tweak 'indent' to match QEMU style without much success.

We could also select a new style, like Linux kernel one. I'm also not a great fan of that either. But at least 'indent' could be used very easily and I think there would be other benefits, like reuse of Git hooks, patch checking scripts and Emacs configs. With full 'indent' support all sources could be massaged mechanically to make the switch less painful.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Then there are K&R and GNU styles, but I like them even less.

So ... Linux kernel style wins? What do others think?

Where do I have to sign?

Yeah.

I really don't care very much. I've changed my CRIS and MicroBlaze code from style to style a couple of times but the only style regardless of style I find offensive is the:

if (x) {
x=1;
} else {
x=0;
}

TBH, the extra curley braceys are just pure nonsense.

Remove those and I'm happy with tab or 2 or 4 or 8 or whatever amount of indentation spaces.

Cheers

#22 lore raw

Re: [Qemu-devel] Re: CODING_STYLE

Quoted 32 lines · Edgar E. Iglesias
Quoted 13 lines · Juan Quintela

"Michael S. Tsirkin" <[email protected]> wrote:

....

Quoted 9 lines
Quoted 9 lines

Actually, I tried to tweak 'indent' to match QEMU style without much success.

We could also select a new style, like Linux kernel one. I'm also not a great fan of that either. But at least 'indent' could be used very easily and I think there would be other benefits, like reuse of Git hooks, patch checking scripts and Emacs configs. With full 'indent' support all sources could be massaged mechanically to make the switch less painful.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Then there are K&R and GNU styles, but I like them even less.

So ... Linux kernel style wins? What do others think?

Where do I have to sign?

Yeah.

I really don't care very much. I've changed my CRIS and MicroBlaze code from style to style a couple of times but the only style regardless of style I find offensive is the:

if (x) {
x=1;
} else {
x=0;
}

Quoted 6 lines

TBH, the extra curley braceys are just pure nonsense.

Remove those and I'm happy with tab or 2 or 4 or 8 or whatever amount of indentation spaces.

Cheers

The advantage of following linux kernel is you get automatic code checking/correction tools.
Most importantly scripts/checkpatch.pl

Deviate from it and you have to maintain your own.

Signature · 1 line
MST
#23 lore raw

Re: [Qemu-devel] Re: CODING_STYLE

Quoted 38 lines · Michael S. Tsirkin
Quoted 37 lines · Edgar E. Iglesias
Quoted 13 lines · Juan Quintela

"Michael S. Tsirkin" <[email protected]> wrote:

....

Quoted 9 lines
Quoted 9 lines

Actually, I tried to tweak 'indent' to match QEMU style without much success.

We could also select a new style, like Linux kernel one. I'm also not a great fan of that either. But at least 'indent' could be used very easily and I think there would be other benefits, like reuse of Git hooks, patch checking scripts and Emacs configs. With full 'indent' support all sources could be massaged mechanically to make the switch less painful.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Then there are K&R and GNU styles, but I like them even less.

So ... Linux kernel style wins? What do others think?

Where do I have to sign?

Yeah.

I really don't care very much. I've changed my CRIS and MicroBlaze code from style to style a couple of times but the only style regardless of style I find offensive is the:

if (x) {
x=1;
} else {
x=0;
}

TBH, the extra curley braceys are just pure nonsense.

Remove those and I'm happy with tab or 2 or 4 or 8 or whatever amount of indentation spaces.

Quoted 7 lines
Quoted 1 line

Cheers

The advantage of following linux kernel is you get automatic code checking/correction tools.
Most importantly scripts/checkpatch.pl

Deviate from it and you have to maintain your own.

Add flag to checkpatch.pl to use different indentation an submit it upstream.

--
Gleb.

#24 lore raw

Re: [Qemu-devel] Re: CODING_STYLE

In reply to Edgar E. Iglesias

Am 01.10.2009 03:25, schrieb Edgar E. Iglesias:

Quoted 26 lines · Juan Quintela
Quoted 13 lines

"Michael S. Tsirkin" <[email protected]> wrote:

....

Quoted 9 lines
Quoted 9 lines

Actually, I tried to tweak 'indent' to match QEMU style without much success.

We could also select a new style, like Linux kernel one. I'm also not a great fan of that either. But at least 'indent' could be used very easily and I think there would be other benefits, like reuse of Git hooks, patch checking scripts and Emacs configs. With full 'indent' support all sources could be massaged mechanically to make the switch less painful.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Then there are K&R and GNU styles, but I like them even less.

So ... Linux kernel style wins? What do others think?

Where do I have to sign?

Yeah.

I really don't care very much. I've changed my CRIS and MicroBlaze code from style to style a couple of times but the only style regardless of style I find offensive is the:

Quoted 7 lines

if (x) {
x=1;
} else {
x=0;
}

TBH, the extra curley braceys are just pure nonsense.

Except that when adding another line after x=1; the patch doesn't contain a change to the if line (with a possibly long condition and the possibility of introducing typos that nobody will see because everybody assumes it's just the new brace).

But then, you could say the ugliness of braces is more important and I really don't care too much about the braces. However, I don't think we should change the coding style radically like switching to the Linux kernel style.

Kevin

#25 lore raw

Re: [Qemu-devel] Re: CODING_STYLE

Quoted 33 lines · Kevin Wolf

Am 01.10.2009 03:25, schrieb Edgar E. Iglesias:

Quoted 32 lines · Juan Quintela
Quoted 13 lines

"Michael S. Tsirkin" <[email protected]> wrote:

....

Quoted 9 lines
Quoted 9 lines

Actually, I tried to tweak 'indent' to match QEMU style without much success.

We could also select a new style, like Linux kernel one. I'm also not a great fan of that either. But at least 'indent' could be used very easily and I think there would be other benefits, like reuse of Git hooks, patch checking scripts and Emacs configs. With full 'indent' support all sources could be massaged mechanically to make the switch less painful.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Then there are K&R and GNU styles, but I like them even less.

So ... Linux kernel style wins? What do others think?

Where do I have to sign?

Yeah.

I really don't care very much. I've changed my CRIS and MicroBlaze code from style to style a couple of times but the only style regardless of style I find offensive is the:

if (x) {
x=1;
} else {
x=0;
}

Quoted 6 lines
Quoted 1 line

TBH, the extra curley braceys are just pure nonsense.

Except that when adding another line after x=1; the patch doesn't contain a change to the if line (with a possibly long condition and the possibility of introducing typos that nobody will see because everybody assumes it's just the new brace).

I don't think I saw a bug introduced this way in ages. The absense of braces is easy enough to spot.

Quoted 6 lines

But then, you could say the ugliness of braces is more important and I really don't care too much about the braces. However, I don't think we should change the coding style radically like switching to the Linux kernel style.

Kevin

I think this is the only way to get a consistent style, for 3 reasons:
- a lot of people hack at both projects, they just keep mixing styles
- linux has automatic checkers that are maintained and improved over time
- linux style is just better ;)

Signature · 1 line
MST
#26 lore raw

Re: [Qemu-devel] Re: CODING_STYLE

Quoted 36 lines · Michael S. Tsirkin
Quoted 35 lines · Kevin Wolf

Am 01.10.2009 03:25, schrieb Edgar E. Iglesias:

Quoted 33 lines · Juan Quintela
Quoted 13 lines

"Michael S. Tsirkin" <[email protected]> wrote:

....

Quoted 9 lines
Quoted 9 lines

Actually, I tried to tweak 'indent' to match QEMU style without much success.

We could also select a new style, like Linux kernel one. I'm also not a great fan of that either. But at least 'indent' could be used very easily and I think there would be other benefits, like reuse of Git hooks, patch checking scripts and Emacs configs. With full 'indent' support all sources could be massaged mechanically to make the switch less painful.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Then there are K&R and GNU styles, but I like them even less.

So ... Linux kernel style wins? What do others think?

Where do I have to sign?

Yeah.

I really don't care very much. I've changed my CRIS and MicroBlaze code from style to style a couple of times but the only style regardless of style I find offensive is the:

if (x) {
x=1;
} else {
x=0;
}

TBH, the extra curley braceys are just pure nonsense.

Quoted 8 lines
Quoted 4 lines

Except that when adding another line after x=1; the patch doesn't contain a change to the if line (with a possibly long condition and the possibility of introducing typos that nobody will see because everybody assumes it's just the new brace).

I don't think I saw a bug introduced this way in ages. The absense of braces is easy enough to spot.

With modern editors that indent automatically it's impossible not to spot.

Quoted 5 lines
Quoted 5 lines

But then, you could say the ugliness of braces is more important and I really don't care too much about the braces. However, I don't think we should change the coding style radically like switching to the Linux kernel style.

Quoted 7 lines
Quoted 1 line

Kevin

I think this is the only way to get a consistent style, for 3 reasons:
- a lot of people hack at both projects, they just keep mixing styles
- linux has automatic checkers that are maintained and improved over time
- linux style is just better ;)

Real men's editor (TM) is able to switch style depending on what you edit.

--
Gleb.

#27 lore raw

Re: [Qemu-devel] Re: CODING_STYLE

Quoted 64 lines · Gleb Natapov
Quoted 36 lines · Michael S. Tsirkin
Quoted 35 lines · Kevin Wolf

Am 01.10.2009 03:25, schrieb Edgar E. Iglesias:

Quoted 33 lines · Juan Quintela
Quoted 13 lines

"Michael S. Tsirkin" <[email protected]> wrote:

....

Quoted 9 lines
Quoted 9 lines

Actually, I tried to tweak 'indent' to match QEMU style without much success.

We could also select a new style, like Linux kernel one. I'm also not a great fan of that either. But at least 'indent' could be used very easily and I think there would be other benefits, like reuse of Git hooks, patch checking scripts and Emacs configs. With full 'indent' support all sources could be massaged mechanically to make the switch less painful.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Then there are K&R and GNU styles, but I like them even less.

So ... Linux kernel style wins? What do others think?

Where do I have to sign?

Yeah.

I really don't care very much. I've changed my CRIS and MicroBlaze code from style to style a couple of times but the only style regardless of style I find offensive is the:

if (x) {
x=1;
} else {
x=0;
}

TBH, the extra curley braceys are just pure nonsense.

Quoted 8 lines
Quoted 4 lines

Except that when adding another line after x=1; the patch doesn't contain a change to the if line (with a possibly long condition and the possibility of introducing typos that nobody will see because everybody assumes it's just the new brace).

I don't think I saw a bug introduced this way in ages. The absense of braces is easy enough to spot.

With modern editors that indent automatically it's impossible not to spot.

Quoted 5 lines
Quoted 5 lines

But then, you could say the ugliness of braces is more important and I really don't care too much about the braces. However, I don't think we should change the coding style radically like switching to the Linux kernel style.

Quoted 7 lines
Quoted 1 line

Kevin

I think this is the only way to get a consistent style, for 3 reasons:
- a lot of people hack at both projects, they just keep mixing styles
- linux has automatic checkers that are maintained and improved over time
- linux style is just better ;)

Real men's editor (TM) is able to switch style depending on what you edit.
--
Gleb.

#28 lore raw

Re: [Qemu-devel] Re: CODING_STYLE

In reply to Edgar E. Iglesias
Quoted 32 lines · Edgar E. Iglesias
Quoted 13 lines · Juan Quintela

"Michael S. Tsirkin" <[email protected]> wrote:

....

Quoted 9 lines
Quoted 9 lines

Actually, I tried to tweak 'indent' to match QEMU style without much success.

We could also select a new style, like Linux kernel one. I'm also not a great fan of that either. But at least 'indent' could be used very easily and I think there would be other benefits, like reuse of Git hooks, patch checking scripts and Emacs configs. With full 'indent' support all sources could be massaged mechanically to make the switch less painful.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Then there are K&R and GNU styles, but I like them even less.

So ... Linux kernel style wins? What do others think?

Where do I have to sign?

Yeah.

I really don't care very much. I've changed my CRIS and MicroBlaze code from style to style a couple of times but the only style regardless of style I find offensive is the:

if (x) {
x=1;
} else {
x=0;
}

Quoted 5 lines

TBH, the extra curley braceys are just pure nonsense.

Remove those and I'm happy with tab or 2 or 4 or 8 or whatever amount of indentation spaces.

This is me to thread, so:
+1

--
Gleb.

#29 lore raw

Re: [Qemu-devel] Re: CODING_STYLE

In reply to Michael S. Tsirkin
Quoted 32 lines · Michael S. Tsirkin
Quoted 31 lines · Blue Swirl
Quoted 15 lines · Michael S. Tsirkin
Quoted 14 lines · Blue Swirl
Quoted 14 lines
Quoted 13 lines

As this is not a clean revert anyway, please don't revert the part changing if (x)
 y;
else
 z;

to

if (x) {
 y;
} else {
 z;
}

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Did I mention I hate this style? But okay :).

I'm not a great fan of this either, but this is the CODING_STYLE.

Maybe we can all vote to change this?

Actually, I tried to tweak 'indent' to match QEMU style without much success.

We could also select a new style, like Linux kernel one. I'm also not a great fan of that either. But at least 'indent' could be used very easily and I think there would be other benefits, like reuse of Git hooks, patch checking scripts and Emacs configs. With full 'indent' support all sources could be massaged mechanically to make the switch less painful.

Quoted 3 lines
Quoted 1 line

Then there are K&R and GNU styles, but I like them even less.

So ... Linux kernel style wins? What do others think?

I find certain aspects of QEMU style rather distasteful, too. Linux kernel style is okay. It can push deeply indented code far to the right and over the cliff, though. Some claim the only correct way to format such code is to indent six feet downward and cover with dirt, but that's not always practical. Nevertheless, I'd favor adopting Linux kernel style. The world doesn't need more indentation styles.

#30 lore raw

Re: [Qemu-devel] Re: CODING_STYLE

Quoted 5 lines · Markus Armbruster
Quoted 1 line

So ... Linux kernel style wins? What do others think?

I find certain aspects of QEMU style rather distasteful, too. Linux kernel style is okay. It can push deeply indented code far to the right and over the cliff, though.

The point it is that way is that if your code is indented so much that it overflows, things are better rearranged in separate functions.

There are many such examples in qemu where splitting things off in separate functions would make the code a lot more readable (and maintainable).

Amit

#31 lore raw

[Qemu-devel] Re: CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix)

In reply to Michael S. Tsirkin
Quoted 11 lines
Quoted 9 lines

We could also select a new style, like Linux kernel one. I'm also not a great fan of that either. But at least 'indent' could be used very easily and I think there would be other benefits, like reuse of Git hooks, patch checking scripts and Emacs configs. With full 'indent' support all sources could be massaged mechanically to make the switch less painful.

Then there are K&R and GNU styles, but I like them even less.

So ... Linux kernel style wins? What do others think?

Linux kernel with 4-char indent? That would avoid the need to run indent (indent requires knowledge of all the names of the types, so a mechanical pass through the sources is more easily said than done).

Paolo

#32 lore raw

[Qemu-devel] Re: CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix)

Quoted 8 lines · Paolo Bonzini
Quoted 8 lines
Quoted 8 lines

We could also select a new style, like Linux kernel one. I'm also not a great fan of that either. But at least 'indent' could be used very easily and I think there would be other benefits, like reuse of Git hooks, patch checking scripts and Emacs configs. With full 'indent' support all sources could be massaged mechanically to make the switch less painful.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Then there are K&R and GNU styles, but I like them even less.

So ... Linux kernel style wins? What do others think?

Linux kernel with 4-char indent? That would avoid the need to run indent

That loses the benefit of automatic style checkers/formatters developed for kernel.

Quoted 4 lines

(indent requires knowledge of all the names of the types, so a mechanical pass through the sources is more easily said than done).

Paolo

vim does a decent job typically.

Signature · 1 line
MST
#33 lore raw

[Qemu-devel] Re: CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix)

In reply to Paolo Bonzini
Quoted 2 lines · Paolo Bonzini

(indent requires knowledge of all the names of the types, so a mechanical pass through the sources is more easily said than done).

How do you tell it the names of the types?

Signature · 1 line
MST
#34 lore raw

[Qemu-devel] Re: CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix)

Quoted 5 lines · Michael S. Tsirkin
Quoted 2 lines · Paolo Bonzini

(indent requires knowledge of all the names of the types, so a mechanical pass through the sources is more easily said than done).

How do you tell it the names of the types?

You use the -T' option. -T' can be specified more than once, and all names specified are used. For example, if your program contains

     typedef unsigned long CODE_ADDR;
     typedef enum {red, blue, green} COLOR;

you would use the options `-T CODE_ADDR -T COLOR'.

Actually, you only need that for types that are used in arguments and declared in .h files (as opposed to the same .c file). Example:

typedef struct color color;
void f(color* p)

works, but if you remove the typedef you get

void f (color * p)

Paolo

#35 lore raw

[Qemu-devel] Re: CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix)

Quoted 18 lines · Paolo Bonzini
Quoted 5 lines · Michael S. Tsirkin
Quoted 2 lines · Paolo Bonzini

(indent requires knowledge of all the names of the types, so a mechanical pass through the sources is more easily said than done).

How do you tell it the names of the types?

You use the -T' option. -T' can be specified more than once, and all names specified are used. For example, if your program contains

     typedef unsigned long CODE_ADDR;
     typedef enum {red, blue, green} COLOR;

you would use the options `-T CODE_ADDR -T COLOR'.

Actually, you only need that for types that are used in arguments and declared in .h files (as opposed to the same .c file). Example:

Quoted 8 lines

typedef struct color color;
void f(color* p)

works, but if you remove the typedef you get

void f (color * p)

Paolo

I see. Well, as we switch to linux CodingStyle we'll cut the number of typedefs dramatically, making this less of an issue :)

Signature · 1 line
MST
#36 lore raw

Re: [Qemu-devel] Re: CODING_STYLE

In reply to Michael S. Tsirkin
Quoted 5 lines · Michael S. Tsirkin
Quoted 2 lines · Paolo Bonzini

(indent requires knowledge of all the names of the types, so a mechanical pass through the sources is more easily said than done).

How do you tell it the names of the types?

-T

#37 lore raw

Re: [Qemu-devel] Re: CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix)

In reply to Paolo Bonzini
Quoted 8 lines · Paolo Bonzini
Quoted 8 lines
Quoted 8 lines

We could also select a new style, like Linux kernel one. I'm also not a great fan of that either. But at least 'indent' could be used very easily and I think there would be other benefits, like reuse of Git hooks, patch checking scripts and Emacs configs. With full 'indent' support all sources could be massaged mechanically to make the switch less painful.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Then there are K&R and GNU styles, but I like them even less.

So ... Linux kernel style wins? What do others think?

Linux kernel with 4-char indent? That would avoid the need to run indent (indent requires knowledge of all the names of the types, so a mechanical pass through the sources is more easily said than done).

I strongly disagree with running indent against the source tree. Indentation is purely cosmetic and honestly is something people get too upset about. Doing something like a flag day indent run would result in git annotate becoming more or less useless.

I prefer having tools that we can use to debug real code instead of worry about indentation.

Regards,

Anthony Liguori

#38 lore raw

Re: [Qemu-devel] Re: CODING_STYLE

Quoted 4 lines · Anthony Liguori

I strongly disagree with running indent against the source tree. Indentation is purely cosmetic and honestly is something people get too upset about. Doing something like a flag day indent run would result in git annotate becoming more or less useless.

FWIW, git-blame -w exists.

[...]

#39 lore raw

Re: [Qemu-devel] Re: CODING_STYLE

Quoted 11 lines · Markus Armbruster
Quoted 5 lines · Anthony Liguori

I strongly disagree with running indent against the source tree. Indentation is purely cosmetic and honestly is something people get too upset about. Doing something like a flag day indent run would result in git annotate becoming more or less useless.

FWIW, git-blame -w exists.

That's pretty useful.

It's still a merge nightmare though. Anyone carrying patches or downstream is going to have a massive headache due to conflicts.

Regards,

Anthony Liguori

Quoted 2 lines

[...]

#40 lore raw

Re: [Qemu-devel] Re: CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix)

In reply to Blue Swirl
Quoted 8 lines · Blue Swirl

We could also select a new style, like Linux kernel one. I'm also not a great fan of that either. But at least 'indent' could be used very easily and I think there would be other benefits, like reuse of Git hooks, patch checking scripts and Emacs configs. With full 'indent' support all sources could be massaged mechanically to make the switch less painful.

Then there are K&R and GNU styles, but I like them even less.

Everything but GNU obsfucation :) Seriously, something resembling Linux CodingStyle or style(9) in the various BSDs would probably help a lot of people avoiding to context switch too much.

#41 lore raw

Re: [Qemu-devel] Re: CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix)

Quoted 8 lines · Christoph Hellwig
Quoted 7 lines · Blue Swirl

We could also select a new style, like Linux kernel one. I'm also not a great fan of that either. But at least 'indent' could be used very easily and I think there would be other benefits, like reuse of Git hooks, patch checking scripts and Emacs configs. With full 'indent' support all sources could be massaged mechanically to make the switch less painful.

Quoted 5 lines
Quoted 1 line

Then there are K&R and GNU styles, but I like them even less.

Everything but GNU obsfucation :) Seriously, something resembling Linux CodingStyle or style(9) in the various BSDs would probably help a lot of people avoiding to context switch too much.

OK, thats 3 people in favor of switching to linux CodingStyle so far.

Signature · 1 line
MST
#42 lore raw

Re: [Qemu-devel] Re: CODING_STYLE (was Re: [PATCHv2] qemu: target library, use it in msix)

Quoted 11 lines · Michael S. Tsirkin
Quoted 9 lines · Christoph Hellwig
Quoted 7 lines · Blue Swirl

We could also select a new style, like Linux kernel one. I'm also not a great fan of that either. But at least 'indent' could be used very easily and I think there would be other benefits, like reuse of Git hooks, patch checking scripts and Emacs configs. With full 'indent' support all sources could be massaged mechanically to make the switch less painful.

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

Then there are K&R and GNU styles, but I like them even less.

Everything but GNU obsfucation :) Seriously, something resembling Linux CodingStyle or style(9) in the various BSDs would probably help a lot of people avoiding to context switch too much.

OK, thats 3 people in favor of switching to linux CodingStyle so far.

I don't think switching coding style is an option on the table. We're long, long past the point where something like that would make sense at all.

Regards,

Anthony Liguori

#43 lore raw
In reply to Blue Swirl
Quoted 6 lines · Blue Swirl
Quoted 4 lines · Michael S. Tsirkin

This creates target.c, which builds per-target, and makes it possible for devices to become target-independent.  Use it in msix, reverting part of 5e520a7d500ec2569d22d80f9ef4272a34cb3c80, as we no longer have to pass target page around.

Quoted 7 lines

target.c line 17

Quoted 4 lines
target.c new file +4 -0
+unsigned target_page_align(unsigned value)
+{
+       return TARGET_PAGE_ALIGN(value);
+}

This must be:
target_phys_addr_t target_page_align(target_phys_addr_t value)

Thinking about this some more, this function just says "align a value to page size". The value might not be a bus address at all, and indeed with msix use, it is not. Makes sense?

Signature · 1 line
MST
#44 lore raw
Quoted 18 lines · Michael S. Tsirkin
Quoted 8 lines · Blue Swirl
Quoted 5 lines · Michael S. Tsirkin

This creates target.c, which builds per-target, and makes it possible for devices to become target-independent. Use it in msix, reverting part of 5e520a7d500ec2569d22d80f9ef4272a34cb3c80, as we no longer have to pass target page around.

Quoted 8 lines

target.c line 17

Quoted 5 lines
target.c new file +4 -0
+unsigned target_page_align(unsigned value)
+{
+       return TARGET_PAGE_ALIGN(value);
+}

This must be:
target_phys_addr_t target_page_align(target_phys_addr_t value)

Quoted 4 lines

Thinking about this some more, this function just says "align a value to page size". The value might not be a bus address at all, and indeed with msix use, it is not. Makes sense?

In any case restricting it to unsigned invites truncation. We can have

   target_phys_addr_t target_phys_page_align();
   target_ulong_t target_virt_page_align();

or just

  uint64_t target_page_align();

(which is wasteful on 32/32 guests and 32 hosts).

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#45 lore raw
Quoted 19 lines · Avi Kivity
Quoted 18 lines · Michael S. Tsirkin
Quoted 16 lines · Blue Swirl

target.c line 17

Quoted 11 lines · Michael S. Tsirkin

This creates target.c, which builds per-target, and makes it possible for devices to become target-independent. Use it in msix, reverting part of 5e520a7d500ec2569d22d80f9ef4272a34cb3c80, as we no longer have to pass target page around.

target.c new file +4 -0
+unsigned target_page_align(unsigned value)
+{
+       return TARGET_PAGE_ALIGN(value);
+}

This must be:
target_phys_addr_t target_page_align(target_phys_addr_t value)

Quoted 6 lines
Quoted 4 lines

Thinking about this some more, this function just says "align a value to page size". The value might not be a bus address at all, and indeed with msix use, it is not. Makes sense?

In any case restricting it to unsigned invites truncation.

If the value we are aligning fits in 32 bit, so does the aligned value.

Quoted 4 lines

We can have

   target_phys_addr_t target_phys_page_align();
   target_ulong_t target_virt_page_align();

Right. And also
target_page_align32();
target_page_align64();

We only use a 32 bit version now (passed value is a constant), so I think I'll only implement it, and we'll add more when they are used.

Quoted 6 lines

or just

uint64_t target_page_align();
(which is wasteful on 32/32 guests and 32 hosts).

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#46 lore raw
Quoted 11 lines · Michael S. Tsirkin
Quoted 9 lines
Quoted 7 lines

Thinking about this some more, this function just says "align a value to page size". The value might not be a bus address at all, and indeed with msix use, it is not. Makes sense?

In any case restricting it to unsigned invites truncation.

If the value we are aligning fits in 32 bit, so does the aligned value.

It's perfectly reasonable to call a such a function with a target_ulong_t or target_phys_addr_t input and expect it to work.

Quoted 5 lines
Quoted 5 lines

We can have

    target_phys_addr_t target_phys_page_align();
    target_ulong_t target_virt_page_align();
Quoted 8 lines

Right. And also

    target_page_align32();
    target_page_align64();

We only use a 32 bit version now (passed value is a constant), so I think I'll only implement it, and we'll add more when they are used.

How would the caller know what size argument they have? They usually have a target_phys_addr_t or a target_ulong_t.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#47 lore raw
Quoted 8 lines · Avi Kivity
Quoted 7 lines · Michael S. Tsirkin
Quoted 7 lines
Quoted 7 lines

Thinking about this some more, this function just says "align a value to page size". The value might not be a bus address at all, and indeed with msix use, it is not. Makes sense?

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

In any case restricting it to unsigned invites truncation.

If the value we are aligning fits in 32 bit, so does the aligned value.

It's perfectly reasonable to call a such a function with a target_ulong_t

[mst@tuck qemu]$ grep -rIi target_ulong_t .
[mst@tuck qemu]$

?

Quoted 1 line

or target_phys_addr_t input and expect it to work.

Not if it's called target_page_align32 :)

Quoted 9 lines
Quoted 9 lines
Quoted 5 lines

We can have

    target_phys_addr_t target_phys_page_align();
    target_ulong_t target_virt_page_align();

Right. And also

    target_page_align32();
    target_page_align64();
Quoted 7 lines
Quoted 4 lines

We only use a 32 bit version now (passed value is a constant), so I think I'll only implement it, and we'll add more when they are used.

How would the caller know what size argument they have? They usually have a target_phys_addr_t or a target_ulong_t.

In practice, the only user is now msix and it does not. It has 0x1000 as a constant parameter. For target_phys_addr_t users if we ever have them, we'll just add target_phys_page_align. Generally it's unusual for devices to care about size of target physical page.

Quoted 2 lines
Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#48 lore raw
Quoted 18 lines · Michael S. Tsirkin
Quoted 16 lines · Avi Kivity
Quoted 14 lines · Michael S. Tsirkin
Quoted 11 lines
Quoted 8 lines

Thinking about this some more, this function just says "align a value to page size". The value might not be a bus address at all, and indeed with msix use, it is not. Makes sense?

In any case restricting it to unsigned invites truncation.

If the value we are aligning fits in 32 bit, so does the aligned value.

Quoted 9 lines
Quoted 3 lines

It's perfectly reasonable to call a such a function with a target_ulong_t

[mst@tuck qemu]$ grep -rIi target_ulong_t .
[mst@tuck qemu]$

?

target_ulong.

Quoted 4 lines
Quoted 2 lines

or target_phys_addr_t input and expect it to work.

Not if it's called target_page_align32 :)

You generally don't know the size of quantities you align.

Quoted 8 lines
Quoted 3 lines

How would the caller know what size argument they have? They usually have a target_phys_addr_t or a target_ulong_t.

In practice, the only user is now msix and it does not. It has 0x1000 as a constant parameter. For target_phys_addr_t users if we ever have them, we'll just add target_phys_page_align. Generally it's unusual for devices to care about size of target physical page.

I'd fill better with uint64_t, at least that won't truncate.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#49 lore raw
Quoted 41 lines · Avi Kivity
Quoted 18 lines · Michael S. Tsirkin
Quoted 16 lines · Avi Kivity
Quoted 14 lines · Michael S. Tsirkin
Quoted 11 lines
Quoted 8 lines

Thinking about this some more, this function just says "align a value to page size". The value might not be a bus address at all, and indeed with msix use, it is not. Makes sense?

In any case restricting it to unsigned invites truncation.

If the value we are aligning fits in 32 bit, so does the aligned value.

Quoted 9 lines
Quoted 3 lines

It's perfectly reasonable to call a such a function with a target_ulong_t

[mst@tuck qemu]$ grep -rIi target_ulong_t .
[mst@tuck qemu]$

?

target_ulong.

Quoted 4 lines
Quoted 2 lines

or target_phys_addr_t input and expect it to work.

Not if it's called target_page_align32 :)

You generally don't know the size of quantities you align.

Quoted 3 lines
Quoted 3 lines

How would the caller know what size argument they have? They usually have a target_phys_addr_t or a target_ulong_t.

Quoted 7 lines
Quoted 5 lines

In practice, the only user is now msix and it does not. It has 0x1000 as a constant parameter. For target_phys_addr_t users if we ever have them, we'll just add target_phys_page_align. Generally it's unusual for devices to care about size of target physical page.

I'd fill better with uint64_t, at least that won't truncate.

Doesn't naming it target_page_align32 address this concern?

Quoted 2 lines
Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#50 lore raw
Quoted 8 lines · Michael S. Tsirkin
Quoted 8 lines
Quoted 8 lines

In practice, the only user is now msix and it does not. It has 0x1000 as a constant parameter. For target_phys_addr_t users if we ever have them, we'll just add target_phys_page_align. Generally it's unusual for devices to care about size of target physical page.

Quoted 4 lines
Quoted 2 lines

I'd fill better with uint64_t, at least that won't truncate.

Doesn't naming it target_page_align32 address this concern?

How can the caller (except in your special case) know if it has a quantity that will fit in 32 bits?

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#51 lore raw
Quoted 9 lines · Avi Kivity
Quoted 8 lines · Michael S. Tsirkin
Quoted 8 lines
Quoted 8 lines

In practice, the only user is now msix and it does not. It has 0x1000 as a constant parameter. For target_phys_addr_t users if we ever have them, we'll just add target_phys_page_align. Generally it's unusual for devices to care about size of target physical page.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

I'd fill better with uint64_t, at least that won't truncate.

Doesn't naming it target_page_align32 address this concern?

How can the caller (except in your special case) know if it has a quantity that will fit in 32 bits?

It's actually not unusual for devices to limit addressing to 32 bit, whatever the bus supports. For example, the value might come from a 32 bit pci bar, even on a 64 bit system this will get values 0 to 4G.

Quoted 3 lines
Signature · 2 lines
-- 
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#52 lore raw
Quoted 12 lines · Michael S. Tsirkin
Quoted 11 lines · Avi Kivity
Quoted 10 lines · Michael S. Tsirkin
Quoted 10 lines
Quoted 8 lines

In practice, the only user is now msix and it does not. It has 0x1000 as a constant parameter. For target_phys_addr_t users if we ever have them, we'll just add target_phys_page_align. Generally it's unusual for devices to care about size of target physical page.

I'd fill better with uint64_t, at least that won't truncate.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Doesn't naming it target_page_align32 address this concern?

How can the caller (except in your special case) know if it has a quantity that will fit in 32 bits?

It's actually not unusual for devices to limit addressing to 32 bit, whatever the bus supports.

I would say that devices normally have a specific addressing, and should not be using target specific types at all. This alignment to target page size is actually an unusual thing.

Quoted 6 lines

For example, the value might come from a 32 bit pci
bar, even on a 64 bit system this will get values 0 to 4G.

Quoted 3 lines
Signature · 2 lines
-- 
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#53 lore raw
Quoted 19 lines · Michael S. Tsirkin
Quoted 18 lines · Michael S. Tsirkin
Quoted 16 lines · Avi Kivity
Quoted 8 lines · Michael S. Tsirkin
Quoted 8 lines
Quoted 8 lines

In practice, the only user is now msix and it does not.  It has 0x1000 as a constant parameter.  For target_phys_addr_t users if we ever have them, we'll just add target_phys_page_align. Generally it's unusual for devices to care about size of target physical page.

Quoted 4 lines
Quoted 2 lines

I'd fill better with uint64_t, at least that won't truncate.

Doesn't naming it target_page_align32 address this concern?

How can the caller (except in your special case) know if it has a quantity that will fit in 32 bits?

Quoted 6 lines
Quoted 2 lines

It's actually not unusual for devices to limit addressing to 32 bit, whatever the bus supports.

I would say that devices normally have a specific addressing, and should not be using target specific types at all.  This alignment to target page size is actually an unusual thing.

Actually, AFAICT MSI-X spec (6.8.2, from the MSI entry in Wikipedia) only requires a QWORD alignment. There is some blurb about 4k alignment, but I think it only describes how software should use the structure. If this is the case, we could drop the whole target page stuff.

#54 lore raw
Quoted 27 lines · Blue Swirl
Quoted 19 lines · Michael S. Tsirkin
Quoted 18 lines · Michael S. Tsirkin
Quoted 16 lines · Avi Kivity
Quoted 8 lines · Michael S. Tsirkin
Quoted 8 lines
Quoted 8 lines

In practice, the only user is now msix and it does not.  It has 0x1000 as a constant parameter.  For target_phys_addr_t users if we ever have them, we'll just add target_phys_page_align. Generally it's unusual for devices to care about size of target physical page.

Quoted 4 lines
Quoted 2 lines

I'd fill better with uint64_t, at least that won't truncate.

Doesn't naming it target_page_align32 address this concern?

How can the caller (except in your special case) know if it has a quantity that will fit in 32 bits?

Quoted 6 lines
Quoted 2 lines

It's actually not unusual for devices to limit addressing to 32 bit, whatever the bus supports.

I would say that devices normally have a specific addressing, and should not be using target specific types at all.  This alignment to target page size is actually an unusual thing.

Quoted 6 lines

Actually, AFAICT MSI-X spec (6.8.2, from the MSI entry in Wikipedia) only requires a QWORD alignment. There is some blurb about 4k alignment, but I think it only describes how software should use the structure.
If this is the case, we could drop the whole target page stuff.

The variable MSIX_PAGE_SIZE actually specifies the size of the space allocated for MSIX in the memory region. Spec requires locating MSI-X tables in a 4K region separate from any other device register, so from that point of view we could just have had
#define MSIX_PAGE_SIZE 0x1000

The main reason I round the space for MSI-X tables up to cpu page size, is because I have to call cpu_register_physical_memory on it, which requires that size is a multiple of target page size.

Signature · 1 line
MST
#55 lore raw
Quoted 35 lines · Michael S. Tsirkin
Quoted 27 lines · Blue Swirl
Quoted 19 lines · Michael S. Tsirkin
Quoted 18 lines · Michael S. Tsirkin
Quoted 16 lines · Avi Kivity
Quoted 8 lines · Michael S. Tsirkin
Quoted 8 lines
Quoted 8 lines

In practice, the only user is now msix and it does not.  It has 0x1000 as a constant parameter.  For target_phys_addr_t users if we ever have them, we'll just add target_phys_page_align. Generally it's unusual for devices to care about size of target physical page.

Quoted 4 lines
Quoted 2 lines

I'd fill better with uint64_t, at least that won't truncate.

Doesn't naming it target_page_align32 address this concern?

How can the caller (except in your special case) know if it has a quantity that will fit in 32 bits?

Quoted 6 lines
Quoted 2 lines

It's actually not unusual for devices to limit addressing to 32 bit, whatever the bus supports.

I would say that devices normally have a specific addressing, and should not be using target specific types at all.  This alignment to target page size is actually an unusual thing.

Quoted 6 lines

Actually, AFAICT MSI-X spec (6.8.2, from the MSI entry in Wikipedia) only requires a QWORD alignment. There is some blurb about 4k alignment, but I think it only describes how software should use the structure.
If this is the case, we could drop the whole target page stuff.

Quoted 5 lines

The variable MSIX_PAGE_SIZE actually specifies the size of the space allocated for MSIX in the memory region.  Spec requires locating MSI-X tables in a 4K region separate from any other device register, so from that point of view we could just have had
#define MSIX_PAGE_SIZE 0x1000

Can you cite the spec, I only found the QWORD stuff.

Quoted 3 lines

The main reason I round the space for MSI-X tables up to cpu page size, is because I have to call cpu_register_physical_memory on it, which requires that size is a multiple of target page size.

There is no such requirement anymore (since r2868 in 2007), devices can register regions of arbitrary size and multiple devices can share a page.

#56 lore raw
Quoted 36 lines · Blue Swirl
Quoted 35 lines · Michael S. Tsirkin
Quoted 33 lines · Blue Swirl
Quoted 19 lines · Michael S. Tsirkin
Quoted 18 lines · Michael S. Tsirkin
Quoted 16 lines · Avi Kivity
Quoted 8 lines · Michael S. Tsirkin
Quoted 8 lines
Quoted 8 lines

In practice, the only user is now msix and it does not.  It has 0x1000 as a constant parameter.  For target_phys_addr_t users if we ever have them, we'll just add target_phys_page_align. Generally it's unusual for devices to care about size of target physical page.

Quoted 4 lines
Quoted 2 lines

I'd fill better with uint64_t, at least that won't truncate.

Doesn't naming it target_page_align32 address this concern?

How can the caller (except in your special case) know if it has a quantity that will fit in 32 bits?

Quoted 6 lines
Quoted 2 lines

It's actually not unusual for devices to limit addressing to 32 bit, whatever the bus supports.

I would say that devices normally have a specific addressing, and should not be using target specific types at all.  This alignment to target page size is actually an unusual thing.

Actually, AFAICT MSI-X spec (6.8.2, from the MSI entry in Wikipedia) only requires a QWORD alignment. There is some blurb about 4k alignment, but I think it only describes how software should use the structure.
If this is the case, we could drop the whole target page stuff.

Quoted 7 lines
Quoted 5 lines

The variable MSIX_PAGE_SIZE actually specifies the size of the space allocated for MSIX in the memory region.  Spec requires locating MSI-X tables in a 4K region separate from any other device register, so from that point of view we could just have had
#define MSIX_PAGE_SIZE 0x1000

Can you cite the spec, I only found the QWORD stuff.

In spec revision 3.0, see this text:

6.8.2. MSI-X Capability and Table Structures

...

If a Base Address register that maps address space for the MSI-X Table or MSI-X PBA also maps other usable address space that is not associated with MSI-X structures, locations (e.g., for CSRs) used in the other address space must not share any naturally aligned 4-KB address range with one where either MSI-X structure resides. This allows system software where applicable to use different processor attributes for MSI-X structures and the other address

Quoted 7 lines
Quoted 3 lines

The main reason I round the space for MSI-X tables up to cpu page size, is because I have to call cpu_register_physical_memory on it, which requires that size is a multiple of target page size.

There is no such requirement anymore (since r2868 in 2007), devices can register regions of arbitrary size and multiple devices can share a page.

Why does the comment on top of cpu_register_physical_memory_offset say otherwise then? Also, this function seems to call kvm_set_phys_mem, which also, apparently, assumes target page alignment.

Signature · 1 line
MST
#57 lore raw
Quoted 9 lines · Michael S. Tsirkin
Quoted 5 lines

There is no such requirement anymore (since r2868 in 2007), devices can register regions of arbitrary size and multiple devices can share a page.

Why does the comment on top of cpu_register_physical_memory_offset say otherwise then? Also, this function seems to call kvm_set_phys_mem, which also, apparently, assumes target page alignment.

That's only for RAM, which the msix area isn't.

Signature · 1 line
error compiling committee.c: too many arguments to function
#58 lore raw
Quoted 6 lines · Avi Kivity
Quoted 5 lines · Michael S. Tsirkin
Quoted 5 lines

There is no such requirement anymore (since r2868 in 2007), devices can register regions of arbitrary size and multiple devices can share a page.

Quoted 6 lines
Quoted 4 lines

Why does the comment on top of cpu_register_physical_memory_offset say otherwise then? Also, this function seems to call kvm_set_phys_mem, which also, apparently, assumes target page alignment.

That's only for RAM, which the msix area isn't.

OK, looks like things should just work defining MSIX_PAGE_SIZE to 0x1000 then. Unsurprisingly, this works fine on intel here.

Quoted 2 lines
Signature · 1 line
error compiling committee.c: too many arguments to function
#59 lore raw
In reply to Michael S. Tsirkin
Quoted 49 lines · Michael S. Tsirkin
Quoted 36 lines · Blue Swirl
Quoted 35 lines · Michael S. Tsirkin
Quoted 33 lines · Blue Swirl
Quoted 19 lines · Michael S. Tsirkin
Quoted 18 lines · Michael S. Tsirkin
Quoted 16 lines · Avi Kivity
Quoted 8 lines · Michael S. Tsirkin
Quoted 8 lines
Quoted 8 lines

In practice, the only user is now msix and it does not.  It has 0x1000 as a constant parameter.  For target_phys_addr_t users if we ever have them, we'll just add target_phys_page_align. Generally it's unusual for devices to care about size of target physical page.

Quoted 4 lines
Quoted 2 lines

I'd fill better with uint64_t, at least that won't truncate.

Doesn't naming it target_page_align32 address this concern?

How can the caller (except in your special case) know if it has a quantity that will fit in 32 bits?

Quoted 6 lines
Quoted 2 lines

It's actually not unusual for devices to limit addressing to 32 bit, whatever the bus supports.

I would say that devices normally have a specific addressing, and should not be using target specific types at all.  This alignment to target page size is actually an unusual thing.

Actually, AFAICT MSI-X spec (6.8.2, from the MSI entry in Wikipedia) only requires a QWORD alignment. There is some blurb about 4k alignment, but I think it only describes how software should use the structure.
If this is the case, we could drop the whole target page stuff.

Quoted 7 lines
Quoted 5 lines

The variable MSIX_PAGE_SIZE actually specifies the size of the space allocated for MSIX in the memory region.  Spec requires locating MSI-X tables in a 4K region separate from any other device register, so from that point of view we could just have had
#define MSIX_PAGE_SIZE 0x1000

Can you cite the spec, I only found the QWORD stuff.

In spec revision 3.0, see this text:

       6.8.2.  MSI-X Capability and Table Structures

Quoted 7 lines

       ...

       If a Base Address register that maps address space for the MSI-X Table or MSI-X PBA also maps other usable address space that is not associated with MSI-X structures, locations (e.g., for CSRs) used in the other address space must not share any naturally aligned 4-KB address range with one where either MSI-X structure resides. This allows system software where applicable to use different processor attributes for MSI-X structures and the other address

I think these are instructions for writing system software, not description on how MSI-X hardware needs the tables laid out. That means, the tables should use page alignment (in order to support some CPU attributes), but the hardware only cares that the data is QWORD aligned.

#60 lore raw
Quoted 58 lines · Blue Swirl
Quoted 49 lines · Michael S. Tsirkin
Quoted 36 lines · Blue Swirl
Quoted 35 lines · Michael S. Tsirkin
Quoted 33 lines · Blue Swirl
Quoted 19 lines · Michael S. Tsirkin
Quoted 18 lines · Michael S. Tsirkin
Quoted 16 lines · Avi Kivity
Quoted 8 lines · Michael S. Tsirkin
Quoted 8 lines
Quoted 8 lines

In practice, the only user is now msix and it does not.  It has 0x1000 as a constant parameter.  For target_phys_addr_t users if we ever have them, we'll just add target_phys_page_align. Generally it's unusual for devices to care about size of target physical page.

Quoted 4 lines
Quoted 2 lines

I'd fill better with uint64_t, at least that won't truncate.

Doesn't naming it target_page_align32 address this concern?

How can the caller (except in your special case) know if it has a quantity that will fit in 32 bits?

Quoted 6 lines
Quoted 2 lines

It's actually not unusual for devices to limit addressing to 32 bit, whatever the bus supports.

I would say that devices normally have a specific addressing, and should not be using target specific types at all.  This alignment to target page size is actually an unusual thing.

Actually, AFAICT MSI-X spec (6.8.2, from the MSI entry in Wikipedia) only requires a QWORD alignment. There is some blurb about 4k alignment, but I think it only describes how software should use the structure.
If this is the case, we could drop the whole target page stuff.

Quoted 7 lines
Quoted 5 lines

The variable MSIX_PAGE_SIZE actually specifies the size of the space allocated for MSIX in the memory region.  Spec requires locating MSI-X tables in a 4K region separate from any other device register, so from that point of view we could just have had
#define MSIX_PAGE_SIZE 0x1000

Can you cite the spec, I only found the QWORD stuff.

In spec revision 3.0, see this text:

       6.8.2.  MSI-X Capability and Table Structures

Quoted 7 lines

       ...

       If a Base Address register that maps address space for the MSI-X Table or MSI-X PBA also maps other usable address space that is not associated with MSI-X structures, locations (e.g., for CSRs) used in the other address space must not share any naturally aligned 4-KB address range with one where either MSI-X structure resides. This allows system software where applicable to use different processor attributes for MSI-X structures and the other address

Quoted 5 lines

I think these are instructions for writing system software, not description on how MSI-X hardware needs the tables laid out. That means, the tables should use page alignment (in order to support some CPU attributes), but the hardware only cares that the data is QWORD aligned.

Yes. All I do is make sure tables are page aligned.

Signature · 1 line
MST
#61 lore raw
In reply to Michael S. Tsirkin
Quoted 8 lines · Michael S. Tsirkin
Quoted 4 lines

How can the caller (except in your special case) know if it has a quantity that will fit in 32 bits?

It's actually not unusual for devices to limit addressing to 32 bit, whatever the bus supports. For example, the value might come from a 32 bit pci bar, even on a 64 bit system this will get values 0 to 4G.

What if the caller is a device that doesn't intentionally cripple itself?

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#62 lore raw
Quoted 11 lines · Avi Kivity
Quoted 8 lines · Michael S. Tsirkin
Quoted 4 lines

How can the caller (except in your special case) know if it has a quantity that will fit in 32 bits?

It's actually not unusual for devices to limit addressing to 32 bit, whatever the bus supports. For example, the value might come from a 32 bit pci bar, even on a 64 bit system this will get values 0 to 4G.

What if the caller is a device that doesn't intentionally cripple itself?

That will need a 64 bit version, even if target is 32 bit.

Quoted 2 lines
Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.