From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761491AbYDPV1w (ORCPT ); Wed, 16 Apr 2008 17:27:52 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751190AbYDPV1o (ORCPT ); Wed, 16 Apr 2008 17:27:44 -0400 Received: from tomts43-srv.bellnexxia.net ([209.226.175.110]:54863 "EHLO tomts43-srv.bellnexxia.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753122AbYDPV1n (ORCPT ); Wed, 16 Apr 2008 17:27:43 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Aq8EAHsMBkhMROPA/2dsb2JhbACBYKxh Date: Wed, 16 Apr 2008 17:22:41 -0400 From: Mathieu Desnoyers To: Ingo Molnar Cc: Peter Zijlstra , prasad@linux.vnet.ibm.com, linux-kernel@vger.kernel.org, tglx@linutronix.de, Christoph Hellwig , "Frank Ch. Eigler" , Arjan van de Ven Subject: Re: text_poke, vmap and vmalloc on x86_64 Message-ID: <20080416212241.GA2621@Krystal> References: <20080415115314.GA6975@in.ibm.com> <1208260942.6395.6.camel@twins> <20080415123233.GA19797@Krystal> <1208264190.6395.21.camel@twins> <20080415131744.GA5248@elte.hu> <20080415134705.GB22351@Krystal> <20080415164814.GA15842@elte.hu> <20080415213832.GC7873@Krystal> <20080416131751.GI6304@elte.hu> <20080416201045.GA31199@Krystal> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline In-Reply-To: <20080416201045.GA31199@Krystal> X-Editor: vi X-Info: http://krystal.dyndns.org:8080 X-Operating-System: Linux/2.6.21.3-grsec (i686) X-Uptime: 17:20:34 up 47 days, 17:31, 5 users, load average: 0.07, 0.18, 0.37 User-Agent: Mutt/1.5.16 (2007-06-11) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca) wrote: > Hi, > > I am trying to figure out why the following code seems to work fine on > x86_32, but the update fails to happen on x86_64. Any idea why ? From > what I see the memcpy seems to fall in a memory area which is not the > same as the one I test at the end of the function. It only fails for > module addresses, which are vmalloc'd. Once I fix this, I'll be able to > send the patchset. > Ah, found it. the is_vmalloc_addr() is somewhat misleading because it does not include the vmalloc'd memory for modules, which is in a different address space. I wonder if it has other unknown side-effects. I used !core_kernel_text() instead. Mathieu > (from my own alternative.c) : > > void *__kprobes text_poke(void *addr, const void *opcode, size_t len) > { > unsigned long flags; > char *vaddr; > int nr_pages = 2; > struct page *pages[2]; > int i; > > if (*((uint8_t *)addr - 1) != BREAKPOINT_INSTRUCTION) { > BUG_ON(len > sizeof(long)); > BUG_ON((((long)addr + len - 1) & ~(sizeof(long) - 1)) > - ((long)addr & ~(sizeof(long) - 1))); > } > if (is_vmalloc_addr(addr)) { > pages[0] = vmalloc_to_page(addr); > pages[1] = vmalloc_to_page(addr + PAGE_SIZE); > } else { > pages[0] = virt_to_page(addr); > pages[1] = virt_to_page(addr + PAGE_SIZE); > } > BUG_ON(!pages[0]); > if (!pages[1]) > nr_pages = 1; > vaddr = vmap(pages, nr_pages, VM_MAP, PAGE_KERNEL); > BUG_ON(!vaddr); > local_irq_save(flags); > memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len); > local_irq_restore(flags); > vunmap(vaddr); > sync_core(); > /* Could also do a CLFLUSH here to speed up CPU recovery; but > that causes hangs on some VIA CPUs. */ > for (i = 0; i < len; i++) > BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]); > return addr; > } > > Mathieu > > -- > Mathieu Desnoyers > Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal > OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F BA06 3F25 A8FE 3BAE 9A68 -- Mathieu Desnoyers Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F BA06 3F25 A8FE 3BAE 9A68