linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Creating a page struct for HIGHMEM pages
@ 2003-12-07 16:02 Amir Hermelin
  2003-12-07 16:22 ` William Lee Irwin III
  0 siblings, 1 reply; 6+ messages in thread
From: Amir Hermelin @ 2003-12-07 16:02 UTC (permalink / raw)
  To: linux-kernel

Hi,
Suppose I want to create a page struct pointing to high memory (e.g. IO
mapped memory), that is, allocate the memory for the page struct myself and
fill in the values, what are the necessary flags/values (other than the
'virtual' field) I must be sure to set?  Does the page* need to be located
anywhere specific?  Does the pte field need to be set in anyway? The
question is relevant to kernel versions 2.4.20 and up.

Thanks,
Amir.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Creating a page struct for HIGHMEM pages
  2003-12-07 16:02 Creating a page struct for HIGHMEM pages Amir Hermelin
@ 2003-12-07 16:22 ` William Lee Irwin III
  2003-12-07 17:56   ` Amir Hermelin
  0 siblings, 1 reply; 6+ messages in thread
From: William Lee Irwin III @ 2003-12-07 16:22 UTC (permalink / raw)
  To: Amir Hermelin; +Cc: linux-kernel

On Sun, Dec 07, 2003 at 06:02:46PM +0200, Amir Hermelin wrote:
> Suppose I want to create a page struct pointing to high memory (e.g. IO
> mapped memory), that is, allocate the memory for the page struct myself and
> fill in the values, what are the necessary flags/values (other than the
> 'virtual' field) I must be sure to set?  Does the page* need to be located
> anywhere specific?  Does the pte field need to be set in anyway? The
> question is relevant to kernel versions 2.4.20 and up.

I'm not entirely sure this is safe (I don't know of anything doing it off
the top of my head or any guarantee it should work), but PG_reserved is
an absolute requirement at the very least. ->virtual is likely irrelevant.
Also, COW userspace mappings of such beasts are illegal since the
physical address can't be calculated for do_wp_page() to do its copy.
Codepaths assuming it's in a zone and so on must also be avoided.
You'll need to set VM_RESERVED on the vma, since the page structure
can't be looked up via pte_page(). If you want faults handled on it,
you'll also have to define your own ->nopage() method.

I generally prefer setting VM_RESERVED and prefaulting in ->f_op->mmap(),
though that may not be feasible in some scenarios. Handling this would be
much easier if drivers could override fault handling methods and the like.

-- wli

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: Creating a page struct for HIGHMEM pages
  2003-12-07 16:22 ` William Lee Irwin III
@ 2003-12-07 17:56   ` Amir Hermelin
  2003-12-07 17:59     ` William Lee Irwin III
  0 siblings, 1 reply; 6+ messages in thread
From: Amir Hermelin @ 2003-12-07 17:56 UTC (permalink / raw)
  To: 'William Lee Irwin III'; +Cc: linux-kernel

Thanks William.
I may be missing something a little more basic: I have a contiguous physical
memory area (IO memory), and I want to manage it with struct pages.  If I'm
to write to the page I need to kmap it, therefore (as I understand it) I
need to zero the ->virtual field.   What I don't understand is how, given
the struct page I've allocated and filled out, is the page correlated with
the correct physical memory.  Where do I put the information that struct
page X points to physical address Y, so that when I kmap(X) I get a virtual
address pointing to Y?

Thanks,
Amir.


-----Original Message-----
From: William Lee Irwin III [mailto:wli@holomorphy.com] 
Sent: Sunday, December 07, 2003 6:22 PM
To: Amir Hermelin
Cc: linux-kernel@vger.kernel.org
Subject: Re: Creating a page struct for HIGHMEM pages


On Sun, Dec 07, 2003 at 06:02:46PM +0200, Amir Hermelin wrote:
> Suppose I want to create a page struct pointing to high memory (e.g. 
> IO mapped memory), that is, allocate the memory for the page struct 
> myself and fill in the values, what are the necessary flags/values 
> (other than the 'virtual' field) I must be sure to set?  Does the 
> page* need to be located anywhere specific?  Does the pte field need 
> to be set in anyway? The question is relevant to kernel versions 
> 2.4.20 and up.

I'm not entirely sure this is safe (I don't know of anything doing it off
the top of my head or any guarantee it should work), but PG_reserved is an
absolute requirement at the very least. ->virtual is likely irrelevant.
Also, COW userspace mappings of such beasts are illegal since the physical
address can't be calculated for do_wp_page() to do its copy. Codepaths
assuming it's in a zone and so on must also be avoided. You'll need to set
VM_RESERVED on the vma, since the page structure can't be looked up via
pte_page(). If you want faults handled on it, you'll also have to define
your own ->nopage() method.

I generally prefer setting VM_RESERVED and prefaulting in ->f_op->mmap(),
though that may not be feasible in some scenarios. Handling this would be
much easier if drivers could override fault handling methods and the like.

-- wli



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Creating a page struct for HIGHMEM pages
  2003-12-07 17:56   ` Amir Hermelin
@ 2003-12-07 17:59     ` William Lee Irwin III
  2003-12-07 18:05       ` Amir Hermelin
  0 siblings, 1 reply; 6+ messages in thread
From: William Lee Irwin III @ 2003-12-07 17:59 UTC (permalink / raw)
  To: Amir Hermelin; +Cc: linux-kernel

On Sun, Dec 07, 2003 at 07:56:17PM +0200, Amir Hermelin wrote:
> I may be missing something a little more basic: I have a contiguous physical
> memory area (IO memory), and I want to manage it with struct pages.  If I'm
> to write to the page I need to kmap it, therefore (as I understand it) I
> need to zero the ->virtual field.   What I don't understand is how, given
> the struct page I've allocated and filled out, is the page correlated with
> the correct physical memory.  Where do I put the information that struct
> page X points to physical address Y, so that when I kmap(X) I get a virtual
> address pointing to Y?

You probably want ioremap(), not kmap().


-- wli

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: Creating a page struct for HIGHMEM pages
  2003-12-07 17:59     ` William Lee Irwin III
@ 2003-12-07 18:05       ` Amir Hermelin
  2003-12-07 18:08         ` William Lee Irwin III
  0 siblings, 1 reply; 6+ messages in thread
From: Amir Hermelin @ 2003-12-07 18:05 UTC (permalink / raw)
  To: 'William Lee Irwin III'; +Cc: linux-kernel

Yes, I've tried ioremap (and placed the address in the ->virtual field), but
had problems with pre-written code that used kmap.  So, basically, what
you're saying is that I must change my code that uses kmap, or
alternatively, allocated page* below the highmem_start_page address.  Is
this correct?


-----Original Message-----
From: William Lee Irwin III [mailto:wli@holomorphy.com] 
Sent: Sunday, December 07, 2003 7:59 PM
To: Amir Hermelin
Cc: linux-kernel@vger.kernel.org
Subject: Re: Creating a page struct for HIGHMEM pages


On Sun, Dec 07, 2003 at 07:56:17PM +0200, Amir Hermelin wrote:
> I may be missing something a little more basic: I have a contiguous 
> physical memory area (IO memory), and I want to manage it with struct 
> pages.  If I'm to write to the page I need to kmap it, therefore (as I
understand it) I
> need to zero the ->virtual field.   What I don't understand is how, given
> the struct page I've allocated and filled out, is the page correlated 
> with the correct physical memory.  Where do I put the information that 
> struct page X points to physical address Y, so that when I kmap(X) I 
> get a virtual address pointing to Y?

You probably want ioremap(), not kmap().


-- wli



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Creating a page struct for HIGHMEM pages
  2003-12-07 18:05       ` Amir Hermelin
@ 2003-12-07 18:08         ` William Lee Irwin III
  0 siblings, 0 replies; 6+ messages in thread
From: William Lee Irwin III @ 2003-12-07 18:08 UTC (permalink / raw)
  To: Amir Hermelin; +Cc: linux-kernel

On Sun, Dec 07, 2003 at 08:05:39PM +0200, Amir Hermelin wrote:
> Yes, I've tried ioremap (and placed the address in the ->virtual field), but
> had problems with pre-written code that used kmap.  So, basically, what
> you're saying is that I must change my code that uses kmap, or
> alternatively, allocated page* below the highmem_start_page address.  Is
> this correct?

You don't need struct pages at all; ioremap() will just map physical to
virtual without the things just fine.


-- wli

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-12-07 18:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-07 16:02 Creating a page struct for HIGHMEM pages Amir Hermelin
2003-12-07 16:22 ` William Lee Irwin III
2003-12-07 17:56   ` Amir Hermelin
2003-12-07 17:59     ` William Lee Irwin III
2003-12-07 18:05       ` Amir Hermelin
2003-12-07 18:08         ` William Lee Irwin III

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).