[PATCH 7/9] accel/kvm: avoid using predefined PAGE_SIZE

Jiaxun Yang posted 9 patches 3 years, 10 months ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, Fam Zheng <fam@euphon.net>, Alistair Francis <alistair@alistair23.me>, Greg Kurz <groug@kaod.org>, Thomas Huth <thuth@redhat.com>, Kevin Wolf <kwolf@redhat.com>, "Alex Bennée" <alex.bennee@linaro.org>, "Philippe Mathieu-Daudé" <philmd@redhat.com>, Wainer dos Santos Moschetta <wainersm@redhat.com>, Laurent Vivier <lvivier@redhat.com>, Max Reitz <mreitz@redhat.com>, David Gibson <david@gibson.dropbear.id.au>, Viktor Prutyanov <viktor.prutyanov@phystech.edu>
There is a newer version of this series
[PATCH 7/9] accel/kvm: avoid using predefined PAGE_SIZE
Posted by Jiaxun Yang 3 years, 10 months ago
As per POSIX specification of limits.h [1], OS libc may define
PAGE_SIZE in limits.h.

To prevent collosion of definition, we discard PAGE_SIZE from
defined by libc and take QEMU's variable.

[1]: https://pubs.opengroup.org/onlinepubs/7908799/xsh/limits.h.html

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
---
 accel/kvm/kvm-all.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 389eaace72..3feb17d965 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -58,6 +58,9 @@
 /* KVM uses PAGE_SIZE in its definition of KVM_COALESCED_MMIO_MAX. We
  * need to use the real host PAGE_SIZE, as that's what KVM will use.
  */
+#ifdef PAGE_SIZE
+#undef PAGE_SIZE
+#endif
 #define PAGE_SIZE qemu_real_host_page_size
 
 //#define DEBUG_KVM
-- 
2.29.2


Re: [PATCH 7/9] accel/kvm: avoid using predefined PAGE_SIZE
Posted by Thomas Huth 3 years, 9 months ago
On 21/12/2020 01.53, Jiaxun Yang wrote:
> As per POSIX specification of limits.h [1], OS libc may define
> PAGE_SIZE in limits.h.
> 
> To prevent collosion of definition, we discard PAGE_SIZE from
> defined by libc and take QEMU's variable.
> 
> [1]: https://pubs.opengroup.org/onlinepubs/7908799/xsh/limits.h.html
> 
> Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
> ---
>   accel/kvm/kvm-all.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> index 389eaace72..3feb17d965 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -58,6 +58,9 @@
>   /* KVM uses PAGE_SIZE in its definition of KVM_COALESCED_MMIO_MAX. We
>    * need to use the real host PAGE_SIZE, as that's what KVM will use.
>    */
> +#ifdef PAGE_SIZE
> +#undef PAGE_SIZE
> +#endif
>   #define PAGE_SIZE qemu_real_host_page_size

If I get that right, the PAGE_SIZE macro is only used one time in this 
file... so it's maybe easier to get rid of the macro completely and replace 
the single occurance with qemu_real_host_page_size directly?

  Thomas


Re: [PATCH 7/9] accel/kvm: avoid using predefined PAGE_SIZE
Posted by Jiaxun Yang 3 years, 9 months ago

On Wed, Jan 13, 2021, at 3:19 PM, Thomas Huth wrote:
> On 21/12/2020 01.53, Jiaxun Yang wrote:
> > As per POSIX specification of limits.h [1], OS libc may define
> > PAGE_SIZE in limits.h.
> > 
> > To prevent collosion of definition, we discard PAGE_SIZE from
> > defined by libc and take QEMU's variable.
> > 
> > [1]: https://pubs.opengroup.org/onlinepubs/7908799/xsh/limits.h.html
> > 
> > Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
> > ---
> >   accel/kvm/kvm-all.c | 3 +++
> >   1 file changed, 3 insertions(+)
> > 
> > diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> > index 389eaace72..3feb17d965 100644
> > --- a/accel/kvm/kvm-all.c
> > +++ b/accel/kvm/kvm-all.c
> > @@ -58,6 +58,9 @@
> >   /* KVM uses PAGE_SIZE in its definition of KVM_COALESCED_MMIO_MAX. We
> >    * need to use the real host PAGE_SIZE, as that's what KVM will use.
> >    */
> > +#ifdef PAGE_SIZE
> > +#undef PAGE_SIZE
> > +#endif
> >   #define PAGE_SIZE qemu_real_host_page_size
> 
> If I get that right, the PAGE_SIZE macro is only used one time in this 
> file... so it's maybe easier to get rid of the macro completely and replace 
> the single occurance with qemu_real_host_page_size directly?

It is also used in kernel headers included here.

Thanks.

- Jiaxun

> 
>   Thomas
> 
>

-- 
- Jiaxun