The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Operating Systems > Linux
.
google unix.com



Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
EZFB Linux Frame Buffer API 10.00 (Default branch) iBot Software Releases - RSS News 0 03-21-2008 08:40 PM
Make a Web page lydia98 UNIX for Dummies Questions & Answers 1 03-16-2007 07:39 PM
Frame buffer implementation in Linux chandra80 High Level Programming 0 10-25-2005 01:15 PM
How to mount/make a FAT system on Linux kyoist Filesystems, Disks and Memory 2 10-23-2005 03:37 AM
how do i make a web page Neil Peart UNIX for Dummies Questions & Answers 3 10-13-2005 12:04 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-15-2009
hahai hahai is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 2
Read data of a page frame (linux) make freeze the system

Hello,

I'm writing a linux driver that reading the data of a page frame of an process. But when I use it, it make immediately freeze the system. Can you help me? Thank for reading my question!

system: Ubuntu 9.04, kernel 2.6.28.15, Intel Duo


Code:
static int read_addr(int pid, unsigned long linear_addr, unsigned int n_bytes, char* buff){
    /* 
    pid: id of process
    linear_addr: linear address of memory region to be read
    n_bytes: nombre bytes to be read
    buff: the buffer containing the result
    */
    
    struct task_struct *task;
       struct mm_struct *mm = NULL;

    pgd_t *pgd;
    pmd_t *pmd; 
    pte_t *pte; 
    unsigned long pteval;

    int ret = 0;    

    for_each_process(task) {
        if ( task->pid == pid) {
            mm = task->mm;
        }
    }
    if(mm == NULL)
        return 1;
 
    spin_lock(&mm->page_table_lock); 
    
    pgd = pgd_offset(mm, linear_addr); 
    if (pgd_none(*pgd)) { ret = 2; goto out; }
    
    pmd = pmd_offset(pgd, linear_addr); 
    if (pmd_none(*pmd)) { ret = 3; goto out; }
    
    pte = pte_offset_map(pmd, linear_addr);
    
    if (pte_present(*pte)){
        unsigned long pteid = pte_index(linear_addr);
        pteval = pte_val(*pte);
        memcpy(buff, pteval + pteid, n_bytes);     
    } else { 
        ret = 4;
        goto out;
    } 
    pte_unmap(pte);
    spin_unlock(&mm->page_table_lock);
    return 0; 

 out:
     printk("error: %d\n", ret); 
    spin_unlock(&mm->page_table_lock);
    return ret;        
}


Last edited by hahai; 09-15-2009 at 09:47 AM..
  #2 (permalink)  
Old 09-15-2009
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,972
I'm not a kernel programmer, but this seems like a deadlock; I'd be concerned about pte_offset_map trying to do the same lock you made earlier.
  #3 (permalink)  
Old 09-15-2009
hahai hahai is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 2
Thank Corona688.

I think that the problem does not locate at the pte_offset_map because it gives a positive result. In the code above, the command that make freeze the system is the memcpy

memcpy(buff, pteval + pteid, n_bytes);

But I don't know why.
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:52 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0