LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] drm/xen-front: fix pointer casts
@ 2018-05-21 7:39 Oleksandr Andrushchenko
2018-05-23 9:19 ` Juergen Gross
0 siblings, 1 reply; 5+ messages in thread
From: Oleksandr Andrushchenko @ 2018-05-21 7:39 UTC (permalink / raw)
To: xen-devel, linux-kernel, dri-devel, daniel.vetter, jgross,
boris.ostrovsky
Cc: andr2000, Oleksandr Andrushchenko
From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Building for a 32-bit target results in warnings from casting
between a 32-bit pointer and a 64-bit integer. Fix the warnings
by casting those pointers to uintptr_t first.
Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
---
drivers/gpu/drm/xen/xen_drm_front.h | 4 ++--
drivers/gpu/drm/xen/xen_drm_front_shbuf.c | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/xen/xen_drm_front.h b/drivers/gpu/drm/xen/xen_drm_front.h
index 2c2479b571ae..8e15dbebc4ba 100644
--- a/drivers/gpu/drm/xen/xen_drm_front.h
+++ b/drivers/gpu/drm/xen/xen_drm_front.h
@@ -126,12 +126,12 @@ struct xen_drm_front_drm_info {
static inline u64 xen_drm_front_fb_to_cookie(struct drm_framebuffer *fb)
{
- return (u64)fb;
+ return (u64)(uintptr_t)fb;
}
static inline u64 xen_drm_front_dbuf_to_cookie(struct drm_gem_object *gem_obj)
{
- return (u64)gem_obj;
+ return (u64)(uintptr_t)gem_obj;
}
int xen_drm_front_mode_set(struct xen_drm_front_drm_pipeline *pipeline,
diff --git a/drivers/gpu/drm/xen/xen_drm_front_shbuf.c b/drivers/gpu/drm/xen/xen_drm_front_shbuf.c
index 8099cb343ae3..47fc93847765 100644
--- a/drivers/gpu/drm/xen/xen_drm_front_shbuf.c
+++ b/drivers/gpu/drm/xen/xen_drm_front_shbuf.c
@@ -122,7 +122,7 @@ static void guest_calc_num_grefs(struct xen_drm_front_shbuf *buf)
}
#define xen_page_to_vaddr(page) \
- ((phys_addr_t)pfn_to_kaddr(page_to_xen_pfn(page)))
+ ((phys_addr_t)(uintptr_t)pfn_to_kaddr(page_to_xen_pfn(page)))
static int backend_unmap(struct xen_drm_front_shbuf *buf)
{
--
2.17.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] drm/xen-front: fix pointer casts
2018-05-21 7:39 [PATCH] drm/xen-front: fix pointer casts Oleksandr Andrushchenko
@ 2018-05-23 9:19 ` Juergen Gross
2018-05-23 10:00 ` Oleksandr Andrushchenko
0 siblings, 1 reply; 5+ messages in thread
From: Juergen Gross @ 2018-05-23 9:19 UTC (permalink / raw)
To: Oleksandr Andrushchenko, xen-devel, linux-kernel, dri-devel,
daniel.vetter, boris.ostrovsky
Cc: Oleksandr Andrushchenko
On 21/05/18 09:39, Oleksandr Andrushchenko wrote:
> From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
>
> Building for a 32-bit target results in warnings from casting
> between a 32-bit pointer and a 64-bit integer. Fix the warnings
> by casting those pointers to uintptr_t first.
>
> Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
> ---
> drivers/gpu/drm/xen/xen_drm_front.h | 4 ++--
> drivers/gpu/drm/xen/xen_drm_front_shbuf.c | 2 +-
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/xen/xen_drm_front.h b/drivers/gpu/drm/xen/xen_drm_front.h
> index 2c2479b571ae..8e15dbebc4ba 100644
> --- a/drivers/gpu/drm/xen/xen_drm_front.h
> +++ b/drivers/gpu/drm/xen/xen_drm_front.h
> @@ -126,12 +126,12 @@ struct xen_drm_front_drm_info {
>
> static inline u64 xen_drm_front_fb_to_cookie(struct drm_framebuffer *fb)
> {
> - return (u64)fb;
> + return (u64)(uintptr_t)fb;
Do you really still need the cast to u64?
> }
>
> static inline u64 xen_drm_front_dbuf_to_cookie(struct drm_gem_object *gem_obj)
> {
> - return (u64)gem_obj;
> + return (u64)(uintptr_t)gem_obj;
> }
>
> int xen_drm_front_mode_set(struct xen_drm_front_drm_pipeline *pipeline,
> diff --git a/drivers/gpu/drm/xen/xen_drm_front_shbuf.c b/drivers/gpu/drm/xen/xen_drm_front_shbuf.c
> index 8099cb343ae3..47fc93847765 100644
> --- a/drivers/gpu/drm/xen/xen_drm_front_shbuf.c
> +++ b/drivers/gpu/drm/xen/xen_drm_front_shbuf.c
> @@ -122,7 +122,7 @@ static void guest_calc_num_grefs(struct xen_drm_front_shbuf *buf)
> }
>
> #define xen_page_to_vaddr(page) \
> - ((phys_addr_t)pfn_to_kaddr(page_to_xen_pfn(page)))
> + ((phys_addr_t)(uintptr_t)pfn_to_kaddr(page_to_xen_pfn(page)))
phys_addr_t for a virtual address?
Juergen
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] drm/xen-front: fix pointer casts
2018-05-23 9:19 ` Juergen Gross
@ 2018-05-23 10:00 ` Oleksandr Andrushchenko
2018-05-23 11:06 ` Juergen Gross
0 siblings, 1 reply; 5+ messages in thread
From: Oleksandr Andrushchenko @ 2018-05-23 10:00 UTC (permalink / raw)
To: Juergen Gross, xen-devel, linux-kernel, dri-devel, daniel.vetter,
boris.ostrovsky
Cc: Oleksandr Andrushchenko
On 05/23/2018 12:19 PM, Juergen Gross wrote:
> On 21/05/18 09:39, Oleksandr Andrushchenko wrote:
>> From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
>>
>> Building for a 32-bit target results in warnings from casting
>> between a 32-bit pointer and a 64-bit integer. Fix the warnings
>> by casting those pointers to uintptr_t first.
>>
>> Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
>> ---
>> drivers/gpu/drm/xen/xen_drm_front.h | 4 ++--
>> drivers/gpu/drm/xen/xen_drm_front_shbuf.c | 2 +-
>> 2 files changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/xen/xen_drm_front.h b/drivers/gpu/drm/xen/xen_drm_front.h
>> index 2c2479b571ae..8e15dbebc4ba 100644
>> --- a/drivers/gpu/drm/xen/xen_drm_front.h
>> +++ b/drivers/gpu/drm/xen/xen_drm_front.h
>> @@ -126,12 +126,12 @@ struct xen_drm_front_drm_info {
>>
>> static inline u64 xen_drm_front_fb_to_cookie(struct drm_framebuffer *fb)
>> {
>> - return (u64)fb;
>> + return (u64)(uintptr_t)fb;
> Do you really still need the cast to u64?
Indeed, I can remove (u64) now, thank you
>
>> }
>>
>> static inline u64 xen_drm_front_dbuf_to_cookie(struct drm_gem_object *gem_obj)
>> {
>> - return (u64)gem_obj;
>> + return (u64)(uintptr_t)gem_obj;
>> }
>>
>> int xen_drm_front_mode_set(struct xen_drm_front_drm_pipeline *pipeline,
>> diff --git a/drivers/gpu/drm/xen/xen_drm_front_shbuf.c b/drivers/gpu/drm/xen/xen_drm_front_shbuf.c
>> index 8099cb343ae3..47fc93847765 100644
>> --- a/drivers/gpu/drm/xen/xen_drm_front_shbuf.c
>> +++ b/drivers/gpu/drm/xen/xen_drm_front_shbuf.c
>> @@ -122,7 +122,7 @@ static void guest_calc_num_grefs(struct xen_drm_front_shbuf *buf)
>> }
>>
>> #define xen_page_to_vaddr(page) \
>> - ((phys_addr_t)pfn_to_kaddr(page_to_xen_pfn(page)))
>> + ((phys_addr_t)(uintptr_t)pfn_to_kaddr(page_to_xen_pfn(page)))
> phys_addr_t for a virtual address?
This is because the resulting value is then passed to gnttab_set_map_op/
gnttab_set_unmap_op which expects host address to be passed as
phys_addr_t addr :(
Please see [1], [2]: regardless of the fact that xen_page_to_vaddr does
produce host address I have to convert it to phys_addr_t then to pass to
[1] and [2].
Please also see [3], [4], [5] which either cast to phys_addr_t or
unsigned long or u64.
>
> Juergen
[1]
https://elixir.bootlin.com/linux/v4.17-rc6/source/include/xen/grant_table.h#L147
[2]
https://elixir.bootlin.com/linux/v4.17-rc6/source/include/xen/grant_table.h#L163
[3]
https://elixir.bootlin.com/linux/v4.17-rc6/source/drivers/block/xen-blkback/blkback.c#L845
[4]
https://elixir.bootlin.com/linux/v4.17-rc6/source/drivers/net/xen-netback/netback.c#L334
[5]
https://elixir.bootlin.com/linux/v4.17-rc6/source/drivers/xen/xenbus/xenbus_client.c#L478
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] drm/xen-front: fix pointer casts
2018-05-23 10:00 ` Oleksandr Andrushchenko
@ 2018-05-23 11:06 ` Juergen Gross
2018-05-23 11:27 ` Oleksandr Andrushchenko
0 siblings, 1 reply; 5+ messages in thread
From: Juergen Gross @ 2018-05-23 11:06 UTC (permalink / raw)
To: Oleksandr Andrushchenko, xen-devel, linux-kernel, dri-devel,
daniel.vetter, boris.ostrovsky
Cc: Oleksandr Andrushchenko
On 23/05/18 12:00, Oleksandr Andrushchenko wrote:
> On 05/23/2018 12:19 PM, Juergen Gross wrote:
>> On 21/05/18 09:39, Oleksandr Andrushchenko wrote:
>>> From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
>>>
>>> Building for a 32-bit target results in warnings from casting
>>> between a 32-bit pointer and a 64-bit integer. Fix the warnings
>>> by casting those pointers to uintptr_t first.
>>>
>>> Signed-off-by: Oleksandr Andrushchenko
>>> <oleksandr_andrushchenko@epam.com>
>>> ---
>>> drivers/gpu/drm/xen/xen_drm_front.h | 4 ++--
>>> drivers/gpu/drm/xen/xen_drm_front_shbuf.c | 2 +-
>>> 2 files changed, 3 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/xen/xen_drm_front.h
>>> b/drivers/gpu/drm/xen/xen_drm_front.h
>>> index 2c2479b571ae..8e15dbebc4ba 100644
>>> --- a/drivers/gpu/drm/xen/xen_drm_front.h
>>> +++ b/drivers/gpu/drm/xen/xen_drm_front.h
>>> @@ -126,12 +126,12 @@ struct xen_drm_front_drm_info {
>>> static inline u64 xen_drm_front_fb_to_cookie(struct
>>> drm_framebuffer *fb)
>>> {
>>> - return (u64)fb;
>>> + return (u64)(uintptr_t)fb;
>> Do you really still need the cast to u64?
> Indeed, I can remove (u64) now, thank you
>>
>>> }
>>> static inline u64 xen_drm_front_dbuf_to_cookie(struct
>>> drm_gem_object *gem_obj)
>>> {
>>> - return (u64)gem_obj;
>>> + return (u64)(uintptr_t)gem_obj;
>>> }
>>> int xen_drm_front_mode_set(struct xen_drm_front_drm_pipeline
>>> *pipeline,
>>> diff --git a/drivers/gpu/drm/xen/xen_drm_front_shbuf.c
>>> b/drivers/gpu/drm/xen/xen_drm_front_shbuf.c
>>> index 8099cb343ae3..47fc93847765 100644
>>> --- a/drivers/gpu/drm/xen/xen_drm_front_shbuf.c
>>> +++ b/drivers/gpu/drm/xen/xen_drm_front_shbuf.c
>>> @@ -122,7 +122,7 @@ static void guest_calc_num_grefs(struct
>>> xen_drm_front_shbuf *buf)
>>> }
>>> #define xen_page_to_vaddr(page) \
>>> - ((phys_addr_t)pfn_to_kaddr(page_to_xen_pfn(page)))
>>> + ((phys_addr_t)(uintptr_t)pfn_to_kaddr(page_to_xen_pfn(page)))
>> phys_addr_t for a virtual address?
> This is because the resulting value is then passed to gnttab_set_map_op/
> gnttab_set_unmap_op which expects host address to be passed as
> phys_addr_t addr :(
Okay, but this means the compiler should do the necessary cast when
you drop the cast to phys_addr_t in xen_page_to_vaddr(), as the cast
to uintptr_t is already producing an unsigned integer value which can
easily be promoted to more bits, right?
Juergen
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] drm/xen-front: fix pointer casts
2018-05-23 11:06 ` Juergen Gross
@ 2018-05-23 11:27 ` Oleksandr Andrushchenko
0 siblings, 0 replies; 5+ messages in thread
From: Oleksandr Andrushchenko @ 2018-05-23 11:27 UTC (permalink / raw)
To: Juergen Gross, xen-devel, linux-kernel, dri-devel, daniel.vetter,
boris.ostrovsky
Cc: Oleksandr Andrushchenko
On 05/23/2018 02:06 PM, Juergen Gross wrote:
> On 23/05/18 12:00, Oleksandr Andrushchenko wrote:
>> On 05/23/2018 12:19 PM, Juergen Gross wrote:
>>> On 21/05/18 09:39, Oleksandr Andrushchenko wrote:
>>>> From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
>>>>
>>>> Building for a 32-bit target results in warnings from casting
>>>> between a 32-bit pointer and a 64-bit integer. Fix the warnings
>>>> by casting those pointers to uintptr_t first.
>>>>
>>>> Signed-off-by: Oleksandr Andrushchenko
>>>> <oleksandr_andrushchenko@epam.com>
>>>> ---
>>>> drivers/gpu/drm/xen/xen_drm_front.h | 4 ++--
>>>> drivers/gpu/drm/xen/xen_drm_front_shbuf.c | 2 +-
>>>> 2 files changed, 3 insertions(+), 3 deletions(-)
>>>>
>>>> diff --git a/drivers/gpu/drm/xen/xen_drm_front.h
>>>> b/drivers/gpu/drm/xen/xen_drm_front.h
>>>> index 2c2479b571ae..8e15dbebc4ba 100644
>>>> --- a/drivers/gpu/drm/xen/xen_drm_front.h
>>>> +++ b/drivers/gpu/drm/xen/xen_drm_front.h
>>>> @@ -126,12 +126,12 @@ struct xen_drm_front_drm_info {
>>>> static inline u64 xen_drm_front_fb_to_cookie(struct
>>>> drm_framebuffer *fb)
>>>> {
>>>> - return (u64)fb;
>>>> + return (u64)(uintptr_t)fb;
>>> Do you really still need the cast to u64?
>> Indeed, I can remove (u64) now, thank you
>>>> }
>>>> static inline u64 xen_drm_front_dbuf_to_cookie(struct
>>>> drm_gem_object *gem_obj)
>>>> {
>>>> - return (u64)gem_obj;
>>>> + return (u64)(uintptr_t)gem_obj;
>>>> }
>>>> int xen_drm_front_mode_set(struct xen_drm_front_drm_pipeline
>>>> *pipeline,
>>>> diff --git a/drivers/gpu/drm/xen/xen_drm_front_shbuf.c
>>>> b/drivers/gpu/drm/xen/xen_drm_front_shbuf.c
>>>> index 8099cb343ae3..47fc93847765 100644
>>>> --- a/drivers/gpu/drm/xen/xen_drm_front_shbuf.c
>>>> +++ b/drivers/gpu/drm/xen/xen_drm_front_shbuf.c
>>>> @@ -122,7 +122,7 @@ static void guest_calc_num_grefs(struct
>>>> xen_drm_front_shbuf *buf)
>>>> }
>>>> #define xen_page_to_vaddr(page) \
>>>> - ((phys_addr_t)pfn_to_kaddr(page_to_xen_pfn(page)))
>>>> + ((phys_addr_t)(uintptr_t)pfn_to_kaddr(page_to_xen_pfn(page)))
>>> phys_addr_t for a virtual address?
>> This is because the resulting value is then passed to gnttab_set_map_op/
>> gnttab_set_unmap_op which expects host address to be passed as
>> phys_addr_t addr :(
> Okay, but this means the compiler should do the necessary cast when
> you drop the cast to phys_addr_t in xen_page_to_vaddr(), as the cast
> to uintptr_t is already producing an unsigned integer value which can
> easily be promoted to more bits, right?
Right, so I can safely use:
#define xen_page_to_vaddr(page) \
- ((phys_addr_t)(uintptr_t)pfn_to_kaddr(page_to_xen_pfn(page)))
+ ((uintptr_t)pfn_to_kaddr(page_to_xen_pfn(page)))
>
> Juergen
Thank you for your time and comments,
Oleksandr
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-05-23 11:27 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-21 7:39 [PATCH] drm/xen-front: fix pointer casts Oleksandr Andrushchenko
2018-05-23 9:19 ` Juergen Gross
2018-05-23 10:00 ` Oleksandr Andrushchenko
2018-05-23 11:06 ` Juergen Gross
2018-05-23 11:27 ` Oleksandr Andrushchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).