* Re: sound/pci/asihpi/hpioctl.c:125:6: warning: cast to pointer from integer of different size [not found] <51143ca4.bNX7TobZ2rDrz0zj%fengguang.wu@intel.com> @ 2013-02-08 2:19 ` H. Peter Anvin 2013-02-08 15:28 ` Russell King - ARM Linux 0 siblings, 1 reply; 5+ messages in thread From: H. Peter Anvin @ 2013-02-08 2:19 UTC (permalink / raw) To: kbuild test robot Cc: Ville Syrjälä, Russell King, Linux Kernel Mailing List On 02/07/2013 03:45 PM, kbuild test robot wrote: > tree: git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/mm > head: 6fcddf474ae1c8e2fb5f14c850c8aa018e7a5034 > commit: 6fcddf474ae1c8e2fb5f14c850c8aa018e7a5034 x86-32: Add support for 64bit get_user() > date: 2 hours ago > config: make ARCH=i386 allmodconfig > > All warnings: > > sound/pci/asihpi/hpioctl.c: In function 'asihpi_hpi_ioctl': >>> sound/pci/asihpi/hpioctl.c:125:6: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] >>> sound/pci/asihpi/hpioctl.c:126:6: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] > -- > net/atm/resources.c: In function 'atm_dev_ioctl': >>> net/atm/resources.c:223:8: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] >>> net/atm/resources.c:274:7: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] > -- [... and so on ...] Now I remember this problem. I believe I discussed it with rmk in the context of ARM, too. Russell, did we ever find any way to implement 8-byte get_user() on 32 bits without massive warning spewage? -hpa ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: sound/pci/asihpi/hpioctl.c:125:6: warning: cast to pointer from integer of different size 2013-02-08 2:19 ` sound/pci/asihpi/hpioctl.c:125:6: warning: cast to pointer from integer of different size H. Peter Anvin @ 2013-02-08 15:28 ` Russell King - ARM Linux 2013-02-08 17:06 ` H. Peter Anvin 0 siblings, 1 reply; 5+ messages in thread From: Russell King - ARM Linux @ 2013-02-08 15:28 UTC (permalink / raw) To: H. Peter Anvin Cc: kbuild test robot, Ville Syrjälä, Linux Kernel Mailing List On Thu, Feb 07, 2013 at 06:19:35PM -0800, H. Peter Anvin wrote: > On 02/07/2013 03:45 PM, kbuild test robot wrote: > > tree: git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/mm > > head: 6fcddf474ae1c8e2fb5f14c850c8aa018e7a5034 > > commit: 6fcddf474ae1c8e2fb5f14c850c8aa018e7a5034 x86-32: Add support for 64bit get_user() > > date: 2 hours ago > > config: make ARCH=i386 allmodconfig > > > > All warnings: > > > > sound/pci/asihpi/hpioctl.c: In function 'asihpi_hpi_ioctl': > >>> sound/pci/asihpi/hpioctl.c:125:6: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] > >>> sound/pci/asihpi/hpioctl.c:126:6: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] > > -- > > net/atm/resources.c: In function 'atm_dev_ioctl': > >>> net/atm/resources.c:223:8: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] > >>> net/atm/resources.c:274:7: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] > > -- > > [... and so on ...] > > Now I remember this problem. I believe I discussed it with rmk in the > context of ARM, too. Russell, did we ever find any way to implement > 8-byte get_user() on 32 bits without massive warning spewage? My last attempt for ARM that I can find (though it wasn't my last email) was: #define __get_user_x(__r2,__p,__e,__s,__i...) \ __asm__ __volatile__ ( \ "bl __get_user_" #__s \ : "=&r" (__e), "=r" (__r2) \ : "0" (__p) \ : __i, "cc") #ifdef BIG_ENDIAN #define __get_user_xb(__r2,__p,__e,__s,__i...) \ __get_user_x(__r2,(uintptr_t)__p + 4,__s,__i) #else #define __get_user_xb __get_user_x #endif #define get_user(x,p) \ ({ \ register const typeof(*(p)) __user *__p asm("r0") = (p);\ register int __e asm("r0"); \ register typeof(x) __r2 asm("r2"); \ switch (sizeof(*(__p))) { \ case 1: \ __get_user_x(__r2, __p, __e, 1, "lr"); \ break; \ case 2: \ __get_user_x(__r2, __p, __e, 2, "r3", "lr"); \ break; \ case 4: \ __get_user_x(__r2, __p, __e, 4, "lr"); \ break; \ case 8: \ if (sizeof((x)) < 8) \ __get_user_xb(__r2, __p, __e, 4, "lr"); \ else \ __get_user_x(__r2, __p, __e, 8, "lr"); \ break; \ default: __e = __get_user_bad(); break; \ } \ x = (typeof(*(__p))) __r2; \ __e; \ }) which I claimed did work for ARM, but I doubted it'd work everywhere because it relies upon there being no 8-bit or 16-bit "registers" being available - iow, it replies upon a register for byte and half-word variables being a full register where the value gets sign-extended to the full register. This is important because of the "typeof(x) __r2 asm("r2")" which may end up being a char, short or int-sized, but __get_user_x() effectively writing to the whole word. Consider the case where 'x' and '*p' are two different sizes. Whether that's safe for x86 or not, I don't know, but my suspicions are that it's unsafe on x86 as it's possible to refer to the various bytes/ half-words of eax separately. So, I came to the conclusion that if x86 remains a problem, there's little point supporting it on ARM. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: sound/pci/asihpi/hpioctl.c:125:6: warning: cast to pointer from integer of different size 2013-02-08 15:28 ` Russell King - ARM Linux @ 2013-02-08 17:06 ` H. Peter Anvin 2013-02-08 18:50 ` Ville Syrjälä 0 siblings, 1 reply; 5+ messages in thread From: H. Peter Anvin @ 2013-02-08 17:06 UTC (permalink / raw) To: Russell King - ARM Linux Cc: kbuild test robot, Ville Syrjälä, Linux Kernel Mailing List On 02/08/2013 07:28 AM, Russell King - ARM Linux wrote: > > Whether that's safe for x86 or not, I don't know, but my suspicions are > that it's unsafe on x86 as it's possible to refer to the various bytes/ > half-words of eax separately. > > So, I came to the conclusion that if x86 remains a problem, there's > little point supporting it on ARM. > It is possible to access bytes separately, but gcc generally doesn't. However, whether or not that can be relied upon safely is a tricky question. It *is* also worth nothing that the x86 ABI does allow two words to be returned in registers from a normal C function, simply by returning a structure. That doesn't solve the problem at hand, though, which is how to make a type-neutral macro which can handle doublewords... -hpa ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: sound/pci/asihpi/hpioctl.c:125:6: warning: cast to pointer from integer of different size 2013-02-08 17:06 ` H. Peter Anvin @ 2013-02-08 18:50 ` Ville Syrjälä 2013-02-08 22:57 ` Russell King - ARM Linux 0 siblings, 1 reply; 5+ messages in thread From: Ville Syrjälä @ 2013-02-08 18:50 UTC (permalink / raw) To: H. Peter Anvin Cc: Russell King - ARM Linux, kbuild test robot, Linux Kernel Mailing List [-- Attachment #1: Type: text/plain, Size: 1519 bytes --] On Fri, Feb 08, 2013 at 09:06:52AM -0800, H. Peter Anvin wrote: > On 02/08/2013 07:28 AM, Russell King - ARM Linux wrote: > > > > Whether that's safe for x86 or not, I don't know, but my suspicions are > > that it's unsafe on x86 as it's possible to refer to the various bytes/ > > half-words of eax separately. > > > > So, I came to the conclusion that if x86 remains a problem, there's > > little point supporting it on ARM. > > > > It is possible to access bytes separately, but gcc generally doesn't. > However, whether or not that can be relied upon safely is a tricky question. > > It *is* also worth nothing that the x86 ABI does allow two words to be > returned in registers from a normal C function, simply by returning a > structure. That doesn't solve the problem at hand, though, which is how > to make a type-neutral macro which can handle doublewords... I just tried to compare a couple of options: 1) unsigned long __val_gu; unsigned long long __val_gu8; 2) register typeof(x) __val_gu asm("eax"); I was still using a test app based on my orignal patch which used eax and edx for the value. 3) typeof(x) __val_gu; While options 2 and 3 get rid of the warnings, they unfortunately produce different results as well. I've attached my test app in case you want to see it. One other note is that if I include the memtest() call in the test, option 1 and 2 produce the same results, but w/o the memtest() the results differ. I didn't look into it any further. -- Ville Syrjälä Intel OTC [-- Attachment #2: get_user.S --] [-- Type: text/x-asm, Size: 701 bytes --] #ifdef AMD64 #define _ASM_AX rax #define _ASM_CX rcx #define _ASM_DX rdx #else #define _ASM_AX eax #define _ASM_CX ecx #define _ASM_DX edx #endif .text .globl __get_user_1 .globl __get_user_2 .globl __get_user_4 #ifdef AMD64 .globl __get_user_8 #else .globl __get_user_8_32 #endif __get_user_1: movzb (%_ASM_CX),%eax xor %ecx,%ecx ret __get_user_2: add $1,%_ASM_CX movzwl -1(%_ASM_CX),%eax xor %ecx,%ecx ret __get_user_4: add $3,%_ASM_CX mov -3(%_ASM_CX),%eax xor %ecx,%ecx ret #ifdef AMD64 __get_user_8: add $7,%_ASM_CX movq -7(%_ASM_CX),%_ASM_AX xor %ecx,%ecx ret #else __get_user_8_32: add $7,%_ASM_CX movl -7(%_ASM_CX),%eax movl -3(%_ASM_CX),%edx xor %ecx,%ecx ret #endif [-- Attachment #3: Makefile --] [-- Type: text/plain, Size: 204 bytes --] CFLAGS:=-std=gnu99 -O2 CPPFLAGS:=-DAMD64 #CFLAGS+=-m32 #ASFLAGS+=-m32 CPPFLAGS+=-Wint-to-pointer-cast .PHONY: all clean all: test test: uaccess.o get_user.o $(CC) $(CFLAGS) -o $@ $^ clean: rm *.o [-- Attachment #4: uaccess.c --] [-- Type: text/x-c, Size: 3710 bytes --] #include <stdio.h> #include <stdint.h> #include <inttypes.h> #include <string.h> #define OPT 1 #define __get_user_x(size, ret, x, ptr) \ asm volatile("call __get_user_" #size \ : "=c" (ret), "=a" (x) \ : "0" (ptr)) #ifdef AMD64 #define __get_user_8(__ret_gu, __val_gu, ptr) \ __get_user_x(8, __ret_gu, __val_gu, ptr) #else #define __get_user_8(ret, x, ptr) \ asm volatile("call __get_user_8_32" \ : "=c" (ret), "=A" (x) \ : "0" (ptr)) #endif #if OPT == 1 #define get_user(x, ptr) \ ({ \ int __ret_gu; \ unsigned long __val_gu; \ unsigned long long __val_gu8; \ switch (sizeof(*(ptr))) { \ case 1: \ __get_user_x(1, __ret_gu, __val_gu, ptr); \ break; \ case 2: \ __get_user_x(2, __ret_gu, __val_gu, ptr); \ break; \ case 4: \ __get_user_x(4, __ret_gu, __val_gu, ptr); \ break; \ case 8: \ __get_user_8(__ret_gu, __val_gu8, ptr); \ break; \ default: \ __get_user_x(X, __ret_gu, __val_gu, ptr); \ break; \ } \ if (sizeof(*(ptr)) == 8) \ (x) = (typeof(*(ptr)))__val_gu8; \ else \ (x) = (typeof(*(ptr)))__val_gu; \ __ret_gu; \ }) #endif #if OPT == 2 #define get_user(x, ptr) \ ({ \ int __ret_gu; \ register typeof(x) __val_gu asm("eax"); \ switch (sizeof(*(ptr))) { \ case 1: \ __get_user_x(1, __ret_gu, __val_gu, ptr); \ break; \ case 2: \ __get_user_x(2, __ret_gu, __val_gu, ptr); \ break; \ case 4: \ __get_user_x(4, __ret_gu, __val_gu, ptr); \ break; \ case 8: \ __get_user_8(__ret_gu, __val_gu, ptr); \ break; \ default: \ __get_user_x(X, __ret_gu, __val_gu, ptr); \ break; \ } \ (x) = (typeof(*(ptr)))__val_gu; \ __ret_gu; \ }) #endif #if OPT == 3 #define get_user(x, ptr) \ ({ \ int __ret_gu; \ typeof(x) __val_gu; \ switch (sizeof(*(ptr))) { \ case 1: \ __get_user_x(1, __ret_gu, __val_gu, ptr); \ break; \ case 2: \ __get_user_x(2, __ret_gu, __val_gu, ptr); \ break; \ case 4: \ __get_user_x(4, __ret_gu, __val_gu, ptr); \ break; \ case 8: \ __get_user_8(__ret_gu, __val_gu, ptr); \ break; \ default: \ __get_user_x(X, __ret_gu, __val_gu, ptr); \ break; \ } \ (x) = (typeof(*(ptr)))__val_gu; \ __ret_gu; \ }) #endif int main(void) { uint64_t foo = 0x89abcdef76543210; printf(" foo: %"PRIx64"\n", foo); struct { uint8_t sika1; uint16_t sika2; uint32_t sika4; uint64_t sika8; } __attribute__((__packed__)) x; if (get_user(x.sika8, (const uint64_t*)&foo)) return 1; if (get_user(x.sika4, (const uint64_t*)&foo)) return 1; if (get_user(x.sika2, (const uint64_t*)&foo)) return 1; if (get_user(x.sika1, (const uint64_t*)&foo)) return 1; printf("sika8: %"PRIx64"\n", x.sika8); printf("sika4: %x\n", x.sika4); printf("sika2: %x\n", x.sika2); printf("sika1: %x\n", x.sika1); //memset(&x, 0, sizeof(x)); if (get_user(x.sika1, (const uint64_t*)&foo)) return 1; if (get_user(x.sika2, (const uint64_t*)&foo)) return 1; if (get_user(x.sika4, (const uint64_t*)&foo)) return 1; if (get_user(x.sika8, (const uint64_t*)&foo)) return 1; printf("sika8: %"PRIx64"\n", x.sika8); printf("sika4: %x\n", x.sika4); printf("sika2: %x\n", x.sika2); printf("sika1: %x\n", x.sika1); return 0; } ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: sound/pci/asihpi/hpioctl.c:125:6: warning: cast to pointer from integer of different size 2013-02-08 18:50 ` Ville Syrjälä @ 2013-02-08 22:57 ` Russell King - ARM Linux 0 siblings, 0 replies; 5+ messages in thread From: Russell King - ARM Linux @ 2013-02-08 22:57 UTC (permalink / raw) To: Ville Syrjälä Cc: H. Peter Anvin, kbuild test robot, Linux Kernel Mailing List On Fri, Feb 08, 2013 at 08:50:57PM +0200, Ville Syrjälä wrote: > struct { > uint8_t sika1; > uint16_t sika2; > uint32_t sika4; > uint64_t sika8; Note - you also need to check what the behaviour is with a pointer type too - that's the one that gets ARM if you try this. My test set on ARM was: int test_8(unsigned char *v, unsigned char *p) { return get_user(*v, p); } int test_16(unsigned short *v, unsigned short *p) { return get_user(*v, p); } int test_32(unsigned int *v, unsigned int *p) { return get_user(*v, p); } int test_32_constp(unsigned int *v, const unsigned int *p) { return get_user(*v, p); } int test_64(unsigned long long *v, unsigned long long *p) { return get_user(*v, p); } int test_64_narrow(unsigned long *v, unsigned long long *p) { return get_user(*v, p); } int test_ptr(unsigned int **v, unsigned int **p) { return get_user(*v, p); } int test_wrong(char **v, const char **p) { return get_user(*v, p); } All but the last should build cleanly and correctly. The last should issue a warning. ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-02-08 22:57 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <51143ca4.bNX7TobZ2rDrz0zj%fengguang.wu@intel.com> 2013-02-08 2:19 ` sound/pci/asihpi/hpioctl.c:125:6: warning: cast to pointer from integer of different size H. Peter Anvin 2013-02-08 15:28 ` Russell King - ARM Linux 2013-02-08 17:06 ` H. Peter Anvin 2013-02-08 18:50 ` Ville Syrjälä 2013-02-08 22:57 ` Russell King - ARM Linux
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).