[PATCH] correct AT_PLATFORM for HT cpus

From: J.A. Magallon (jamagallon_at_able.es)
Date: 08/31/03

  • Next message: Adam Lackorzynski: "Linux-2.4.22: crypto compile on Alpha"
    Date:	Sun, 31 Aug 2003 11:21:27 +0200
    To: Marcelo Tosatti <marcelo@conectiva.com.br>
    
    

    On 08.30, Marcelo Tosatti wrote:
    >
    > Hello,
    >
    > Here goes -pre2. It contains an USB update, PPC merge, m68k merge, IDE
    > changes from Alan, network drivers update from Jeff, amongst other fixes
    > and updates.
    >

    In shortest: Pentium4 with HT do not realize they are themselves an i686.
    Even, they do not know what they are. This makes P4HT select i386 libraries
    at runtime, instead of i686 ones.

    In short: binfmt_elf::create_elf_tables() copies the AT_PLATFORM in the
    place pointed by u_platform, and then copies the pointer to elf tables.
    But, in the HT case, u_platform gets changed in the middle, beacuse it
    is also used as the beginning of the stack, that is shifted for HT
    processors to avoid cache collisions. So then
    it puts a pointer to garbage in the elf tables:

        if (k_platform) {
            platform_len = strlen(k_platform) + 1;
            u_platform = p - platform_len;
            __copy_to_user(u_platform, k_platform, platform_len);
        } else
            u_platform = p;
    ...
        if(smp_num_siblings > 1)
            u_platform = u_platform - ((current->pid % 64) << 7);
    ...
        if (k_platform) {
            sp -= 2;
            NEW_AUX_ENT(0, AT_PLATFORM, (elf_addr_t)(unsigned long) u_platform);
        }

    Solution is to use separate variables to store u_platform and the stack_top:

    --- linux/fs/binfmt_elf.c.orig 2002-12-28 00:12:32.000000000 +0100
    +++ linux/fs/binfmt_elf.c 2002-12-28 00:32:37.000000000 +0100
    @@ -116,11 +116,14 @@
             elf_caddr_t *argv;
             elf_caddr_t *envp;
             elf_addr_t *sp, *csp;
    + char *stack_top;
             char *k_platform, *u_platform;
             long hwcap;
             size_t platform_len = 0;
             size_t len;
     
    + stack_top = p;
    +
             /*
              * Get hold of platform and hardware capabilities masks for
              * the machine we are running on. In some cases (Sparc),
    @@ -135,8 +138,8 @@
                     platform_len = strlen(k_platform) + 1;
                     u_platform = p - platform_len;
                     __copy_to_user(u_platform, k_platform, platform_len);
    - } else
    - u_platform = p;
    + stack_top = u_platform;
    + }
     
     #if defined(__i386__) && defined(CONFIG_SMP)
             /*
    @@ -149,15 +152,14 @@
              * processors. This keeps Mr Marcelo Person happier but should be
              * removed for 2.5
              */
    -
             if(smp_num_siblings > 1)
    - u_platform = u_platform - ((current->pid % 64) << 7);
    + stack_top -= ((current->pid % 64) << 7);
     #endif
     
             /*
              * Force 16 byte _final_ alignment here for generality.
              */
    - sp = (elf_addr_t *)(~15UL & (unsigned long)(u_platform));
    + sp = (elf_addr_t *)(~15UL & (unsigned long)(stack_top));
             csp = sp;
             csp -= (1+DLINFO_ITEMS)*2 + (k_platform ? 2 : 0);
     #ifdef DLINFO_ARCH_ITEMS

    As other patches, tested by myself. And Mandrake kernel includes it.
    Comments ?

    -- 
    J.A. Magallon <jamagallon@able.es>      \                 Software is like sex:
    werewolf.able.es                         \           It's better when it's free
    Mandrake Linux release 9.2 (Cooker) for i586
    Linux 2.4.22-jam1m (gcc 3.3.1 (Mandrake Linux 9.2 3.3.1-1mdk))
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at  http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at  http://www.tux.org/lkml/
    

  • Next message: Adam Lackorzynski: "Linux-2.4.22: crypto compile on Alpha"

    Relevant Pages

    • Re: [PATCH] check_gcc for i386
      ... >>changes from Alan, network drivers update from Jeff, amongst other fixes ... This can be a potentially harmful change, suddenly exposing compiler ... some gcc versions, something that's giving me a feeling those gcc ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • [PATCH] check_gcc for i386
      ... > changes from Alan, network drivers update from Jeff, amongst other fixes ... Plz, could you include this on your queue? ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)