All of lore.kernel.org
 help / color / mirror / Atom feed
From: Scott Pakin <pakin-YOWKrPYUwWM@public.gmane.org>
To: "Zhang, Xiantao" <xiantao.zhang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
	qemu-devel-qX2TKyscuCcdnm+yROfE0A@public.gmane.org,
	kvm-ia64-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: Re: [PATCH] Making SLIRP code more 64-bit clean
Date: Wed, 30 Jan 2008 09:42:51 -0700	[thread overview]
Message-ID: <47A0A90B.50407@lanl.gov> (raw)
In-Reply-To: <42DFA526FC41B1429CE7279EF83C6BDCD31A15-wq7ZOvIWXbMAbVU2wMM1CrfspsVTdybXVpNB7YpNyf8@public.gmane.org>

Zhang, Xiantao wrote:
> Scott Pakin wrote:
>> The attached patch corrects a bug in qemu/slirp/tcp_var.h that defines
>> the seg_next field in struct tcpcb to be 32 bits wide regardless of
>> 32/64-bitness.  seg_next is assigned a pointer value in
>> qemu/slirp/tcp_subr.c, then cast back to a pointer in
>> qemu/slirp/tcp_input.c and dereferenced.  That produces a SIGSEGV on
>> my system. 
> 
> 
> I still hit it on IA64 platform with your patch, once configured with
> slirp.  

Okay, here's a more thorough patch that fixes *all* of the "cast from/to
pointer to/from integer of a different size" mistakes that gcc warns
about.  Does it also solve the SIGSEGV problem on IA64?

-- Scott

================== BEGIN tcp_int32_pointer_cast.patch ==================
diff -Naur kvm-60-ORIG/qemu/exec-all.h kvm-60/qemu/exec-all.h
--- kvm-60-ORIG/qemu/exec-all.h	2008-01-20 05:35:04.000000000 -0700
+++ kvm-60/qemu/exec-all.h	2008-01-29 19:19:45.000000000 -0700
@@ -169,7 +169,7 @@
  #ifdef USE_DIRECT_JUMP
      uint16_t tb_jmp_offset[4]; /* offset of jump instruction */
  #else
-    uint32_t tb_next[2]; /* address of jump generated code */
+    uintptr_t tb_next[2]; /* address of jump generated code */
  #endif
      /* list of TBs jumping to this one. This is a circular list using
         the two least significant bits of the pointers to tell what is
diff -Naur kvm-60-ORIG/qemu/slirp/ip.h kvm-60/qemu/slirp/ip.h
--- kvm-60-ORIG/qemu/slirp/ip.h	2008-01-20 05:35:04.000000000 -0700
+++ kvm-60/qemu/slirp/ip.h	2008-01-29 19:13:09.000000000 -0700
@@ -183,23 +183,9 @@

  #define	IP_MSS		576		/* default maximum segment size */

-#ifdef HAVE_SYS_TYPES32_H  /* Overcome some Solaris 2.x junk */
-#include <sys/types32.h>
-#else
-#if SIZEOF_CHAR_P == 4
  typedef caddr_t caddr32_t;
-#else
-typedef u_int32_t caddr32_t;
-#endif
-#endif
-
-#if SIZEOF_CHAR_P == 4
  typedef struct ipq *ipqp_32;
  typedef struct ipasfrag *ipasfragp_32;
-#else
-typedef caddr32_t ipqp_32;
-typedef caddr32_t ipasfragp_32;
-#endif

  /*
   * Overlay for ip header used by other protocols (tcp, udp).
diff -Naur kvm-60-ORIG/qemu/slirp/misc.c kvm-60/qemu/slirp/misc.c
--- kvm-60-ORIG/qemu/slirp/misc.c	2008-01-20 05:35:04.000000000 -0700
+++ kvm-60/qemu/slirp/misc.c	2008-01-29 11:36:15.000000000 -0700
@@ -97,39 +97,6 @@
              our_addr.s_addr = loopback_addr.s_addr;
  }

-#if SIZEOF_CHAR_P == 8
-
-struct quehead_32 {
-	u_int32_t qh_link;
-	u_int32_t qh_rlink;
-};
-
-inline void
-insque_32(a, b)
-	void *a;
-	void *b;
-{
-	register struct quehead_32 *element = (struct quehead_32 *) a;
-	register struct quehead_32 *head = (struct quehead_32 *) b;
-	element->qh_link = head->qh_link;
-	head->qh_link = (u_int32_t)element;
-	element->qh_rlink = (u_int32_t)head;
-	((struct quehead_32 *)(element->qh_link))->qh_rlink
-	= (u_int32_t)element;
-}
-
-inline void
-remque_32(a)
-	void *a;
-{
-	register struct quehead_32 *element = (struct quehead_32 *) a;
-	((struct quehead_32 *)(element->qh_link))->qh_rlink = element->qh_rlink;
-	((struct quehead_32 *)(element->qh_rlink))->qh_link = element->qh_link;
-	element->qh_rlink = 0;
-}
-
-#endif /* SIZEOF_CHAR_P == 8 */
-
  struct quehead {
  	struct quehead *qh_link;
  	struct quehead *qh_rlink;
diff -Naur kvm-60-ORIG/qemu/slirp/slirp.h kvm-60/qemu/slirp/slirp.h
--- kvm-60-ORIG/qemu/slirp/slirp.h	2008-01-20 05:35:04.000000000 -0700
+++ kvm-60/qemu/slirp/slirp.h	2008-01-29 11:37:19.000000000 -0700
@@ -265,13 +265,8 @@

  void lprint _P((const char *, ...));

-#if SIZEOF_CHAR_P == 4
-# define insque_32 insque
-# define remque_32 remque
-#else
- inline void insque_32 _P((void *, void *));
- inline void remque_32 _P((void *));
-#endif
+#define insque_32 insque
+#define remque_32 remque

  #ifndef _WIN32
  #include <netdb.h>
diff -Naur kvm-60-ORIG/qemu/slirp/tcp_var.h kvm-60/qemu/slirp/tcp_var.h
--- kvm-60-ORIG/qemu/slirp/tcp_var.h	2008-01-20 05:35:04.000000000 -0700
+++ kvm-60/qemu/slirp/tcp_var.h	2008-01-28 21:12:22.000000000 -0700
@@ -40,11 +40,7 @@
  #include "tcpip.h"
  #include "tcp_timer.h"

-#if SIZEOF_CHAR_P == 4
- typedef struct tcpiphdr *tcpiphdrp_32;
-#else
- typedef u_int32_t tcpiphdrp_32;
-#endif
+typedef struct tcpiphdr *tcpiphdrp_32;

  /*
   * Tcp control block, one per tcp; fields:
@@ -178,11 +174,7 @@
   * port numbers (which are no longer needed once we've located the
   * tcpcb) are overlayed with an mbuf pointer.
   */
-#if SIZEOF_CHAR_P == 4
  typedef struct mbuf *mbufp_32;
-#else
-typedef u_int32_t mbufp_32;
-#endif
  #define REASS_MBUF(ti) (*(mbufp_32 *)&((ti)->ti_t))

  #ifdef LOG_ENABLED
=================== END tcp_int32_pointer_cast.patch ===================

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

WARNING: multiple messages have this Message-ID (diff)
From: Scott Pakin <pakin@lanl.gov>
To: "Zhang, Xiantao" <xiantao.zhang@intel.com>
Cc: kvm-devel@lists.sourceforge.net, qemu-devel@nongnu.org,
	kvm-ia64-devel@lists.sourceforge.net
Subject: [Qemu-devel] Re: [kvm-devel] [PATCH] Making SLIRP code more 64-bit clean
Date: Wed, 30 Jan 2008 09:42:51 -0700	[thread overview]
Message-ID: <47A0A90B.50407@lanl.gov> (raw)
In-Reply-To: <42DFA526FC41B1429CE7279EF83C6BDCD31A15@pdsmsx415.ccr.corp.intel.com>

Zhang, Xiantao wrote:
> Scott Pakin wrote:
>> The attached patch corrects a bug in qemu/slirp/tcp_var.h that defines
>> the seg_next field in struct tcpcb to be 32 bits wide regardless of
>> 32/64-bitness.  seg_next is assigned a pointer value in
>> qemu/slirp/tcp_subr.c, then cast back to a pointer in
>> qemu/slirp/tcp_input.c and dereferenced.  That produces a SIGSEGV on
>> my system. 
> 
> 
> I still hit it on IA64 platform with your patch, once configured with
> slirp.  

Okay, here's a more thorough patch that fixes *all* of the "cast from/to
pointer to/from integer of a different size" mistakes that gcc warns
about.  Does it also solve the SIGSEGV problem on IA64?

-- Scott

================== BEGIN tcp_int32_pointer_cast.patch ==================
diff -Naur kvm-60-ORIG/qemu/exec-all.h kvm-60/qemu/exec-all.h
--- kvm-60-ORIG/qemu/exec-all.h	2008-01-20 05:35:04.000000000 -0700
+++ kvm-60/qemu/exec-all.h	2008-01-29 19:19:45.000000000 -0700
@@ -169,7 +169,7 @@
  #ifdef USE_DIRECT_JUMP
      uint16_t tb_jmp_offset[4]; /* offset of jump instruction */
  #else
-    uint32_t tb_next[2]; /* address of jump generated code */
+    uintptr_t tb_next[2]; /* address of jump generated code */
  #endif
      /* list of TBs jumping to this one. This is a circular list using
         the two least significant bits of the pointers to tell what is
diff -Naur kvm-60-ORIG/qemu/slirp/ip.h kvm-60/qemu/slirp/ip.h
--- kvm-60-ORIG/qemu/slirp/ip.h	2008-01-20 05:35:04.000000000 -0700
+++ kvm-60/qemu/slirp/ip.h	2008-01-29 19:13:09.000000000 -0700
@@ -183,23 +183,9 @@

  #define	IP_MSS		576		/* default maximum segment size */

-#ifdef HAVE_SYS_TYPES32_H  /* Overcome some Solaris 2.x junk */
-#include <sys/types32.h>
-#else
-#if SIZEOF_CHAR_P == 4
  typedef caddr_t caddr32_t;
-#else
-typedef u_int32_t caddr32_t;
-#endif
-#endif
-
-#if SIZEOF_CHAR_P == 4
  typedef struct ipq *ipqp_32;
  typedef struct ipasfrag *ipasfragp_32;
-#else
-typedef caddr32_t ipqp_32;
-typedef caddr32_t ipasfragp_32;
-#endif

  /*
   * Overlay for ip header used by other protocols (tcp, udp).
diff -Naur kvm-60-ORIG/qemu/slirp/misc.c kvm-60/qemu/slirp/misc.c
--- kvm-60-ORIG/qemu/slirp/misc.c	2008-01-20 05:35:04.000000000 -0700
+++ kvm-60/qemu/slirp/misc.c	2008-01-29 11:36:15.000000000 -0700
@@ -97,39 +97,6 @@
              our_addr.s_addr = loopback_addr.s_addr;
  }

-#if SIZEOF_CHAR_P == 8
-
-struct quehead_32 {
-	u_int32_t qh_link;
-	u_int32_t qh_rlink;
-};
-
-inline void
-insque_32(a, b)
-	void *a;
-	void *b;
-{
-	register struct quehead_32 *element = (struct quehead_32 *) a;
-	register struct quehead_32 *head = (struct quehead_32 *) b;
-	element->qh_link = head->qh_link;
-	head->qh_link = (u_int32_t)element;
-	element->qh_rlink = (u_int32_t)head;
-	((struct quehead_32 *)(element->qh_link))->qh_rlink
-	= (u_int32_t)element;
-}
-
-inline void
-remque_32(a)
-	void *a;
-{
-	register struct quehead_32 *element = (struct quehead_32 *) a;
-	((struct quehead_32 *)(element->qh_link))->qh_rlink = element->qh_rlink;
-	((struct quehead_32 *)(element->qh_rlink))->qh_link = element->qh_link;
-	element->qh_rlink = 0;
-}
-
-#endif /* SIZEOF_CHAR_P == 8 */
-
  struct quehead {
  	struct quehead *qh_link;
  	struct quehead *qh_rlink;
diff -Naur kvm-60-ORIG/qemu/slirp/slirp.h kvm-60/qemu/slirp/slirp.h
--- kvm-60-ORIG/qemu/slirp/slirp.h	2008-01-20 05:35:04.000000000 -0700
+++ kvm-60/qemu/slirp/slirp.h	2008-01-29 11:37:19.000000000 -0700
@@ -265,13 +265,8 @@

  void lprint _P((const char *, ...));

-#if SIZEOF_CHAR_P == 4
-# define insque_32 insque
-# define remque_32 remque
-#else
- inline void insque_32 _P((void *, void *));
- inline void remque_32 _P((void *));
-#endif
+#define insque_32 insque
+#define remque_32 remque

  #ifndef _WIN32
  #include <netdb.h>
diff -Naur kvm-60-ORIG/qemu/slirp/tcp_var.h kvm-60/qemu/slirp/tcp_var.h
--- kvm-60-ORIG/qemu/slirp/tcp_var.h	2008-01-20 05:35:04.000000000 -0700
+++ kvm-60/qemu/slirp/tcp_var.h	2008-01-28 21:12:22.000000000 -0700
@@ -40,11 +40,7 @@
  #include "tcpip.h"
  #include "tcp_timer.h"

-#if SIZEOF_CHAR_P == 4
- typedef struct tcpiphdr *tcpiphdrp_32;
-#else
- typedef u_int32_t tcpiphdrp_32;
-#endif
+typedef struct tcpiphdr *tcpiphdrp_32;

  /*
   * Tcp control block, one per tcp; fields:
@@ -178,11 +174,7 @@
   * port numbers (which are no longer needed once we've located the
   * tcpcb) are overlayed with an mbuf pointer.
   */
-#if SIZEOF_CHAR_P == 4
  typedef struct mbuf *mbufp_32;
-#else
-typedef u_int32_t mbufp_32;
-#endif
  #define REASS_MBUF(ti) (*(mbufp_32 *)&((ti)->ti_t))

  #ifdef LOG_ENABLED
=================== END tcp_int32_pointer_cast.patch ===================

  parent reply	other threads:[~2008-01-30 16:42 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-29 17:11 [PATCH] Making SLIRP code more 64-bit clean Scott Pakin
2008-01-29 17:11 ` [Qemu-devel] " Scott Pakin
     [not found] ` <479F5E3A.6030506-YOWKrPYUwWM@public.gmane.org>
2008-01-30  4:27   ` Zhang, Xiantao
2008-01-30  4:27     ` [Qemu-devel] RE: [kvm-devel] " Zhang, Xiantao
     [not found]     ` <42DFA526FC41B1429CE7279EF83C6BDCD31A15-wq7ZOvIWXbMAbVU2wMM1CrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2008-01-30 16:42       ` Scott Pakin [this message]
2008-01-30 16:42         ` [Qemu-devel] " Scott Pakin
     [not found]         ` <47A0A90B.50407-YOWKrPYUwWM@public.gmane.org>
2008-01-30 17:10           ` [Qemu-devel] " Blue Swirl
2008-01-30 17:10             ` [Qemu-devel] Re: [kvm-devel] " Blue Swirl
     [not found]             ` <f43fc5580801300910w583f39br18d2c6e60e2370a3-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-02-01  1:26               ` [kvm-ia64-devel] [Qemu-devel] Re: [PATCH] MakingSLIRP " Zhang, Xiantao
2008-02-01  1:26                 ` [kvm-ia64-devel] [Qemu-devel] Re: [kvm-devel] " Zhang, Xiantao
2008-01-31  8:24           ` [PATCH] Making SLIRP " Zhang, Xiantao
2008-01-31  8:24             ` [Qemu-devel] RE: [kvm-devel] " Zhang, Xiantao
     [not found]             ` <42DFA526FC41B1429CE7279EF83C6BDCD31F4E-wq7ZOvIWXbMAbVU2wMM1CrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2008-01-31 18:38               ` Scott Pakin
2008-01-31 18:38                 ` [Qemu-devel] Re: [kvm-devel] " Scott Pakin
     [not found]                 ` <47A215A2.4070407-YOWKrPYUwWM@public.gmane.org>
2008-02-01  1:37                   ` Scott Pakin
2008-02-01  1:37                     ` [Qemu-devel] Re: [kvm-devel] " Scott Pakin
2008-02-01  2:44           ` [kvm-ia64-devel] [PATCH] Making SLIRP code more64-bit clean Zhang, Xiantao
2008-02-01  2:44             ` [Qemu-devel] RE: [kvm-ia64-devel] [kvm-devel] " Zhang, Xiantao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47A0A90B.50407@lanl.gov \
    --to=pakin-yowkrpyuwwm@public.gmane.org \
    --cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    --cc=kvm-ia64-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    --cc=qemu-devel-qX2TKyscuCcdnm+yROfE0A@public.gmane.org \
    --cc=xiantao.zhang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.