TLB Question

TLB Question

am 05.02.2008 07:04:09 von Rick Brown

Hi,

I'm trying to understand the MMU operations & am wondering where is
the kernel code where the kernel interfaces with the this piece of
hardware?

Can some one help me in understanding that what all are the
responsibilities of the kernel, and what is it the hardware takes care
of automatically? E.g. who fills, flushes & refills the TLB entries?
What all initializations need to be performed by kernel (And where is
the code?)

TIA,

Rick
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" 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.linux-learn.org/faqs

Re: TLB Question

am 05.02.2008 08:08:02 von sahlot arvind

------=_Part_8672_29209428.1202195282105
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

> E.g. who fills, flushes & refills the TLB entries?
TLB entries are filled by H/W and not explicitly by kernel. Whenever MMU
translates VA to PA it caches that translation into TLB. If TLB is full then
MMU uses its own algorithms to replace some entry in TLB e.g. MMU might
consider TLB as circular buffer and replace first entry once TLB is full.

>What all initializations need to be performed by kernel (And where is
>the code?)
Kernel bascially has to set up the page tables and set the Page Table Base
register and enbale MMU.

Regards
- A.

On 2/5/08, Rick Brown wrote:
>
> Hi,
>
> I'm trying to understand the MMU operations & am wondering where is
> the kernel code where the kernel interfaces with the this piece of
> hardware?
>
> Can some one help me in understanding that what all are the
> responsibilities of the kernel, and what is it the hardware takes care
> of automatically? E.g. who fills, flushes & refills the TLB entries?
> What all initializations need to be performed by kernel (And where is
> the code?)
>
> TIA,
>
> Rick
>
> --
> To unsubscribe from this list: send an email with
> "unsubscribe kernelnewbies" to ecartis@nl.linux.org
> Please read the FAQ at http://kernelnewbies.org/FAQ
>
>

------=_Part_8672_29209428.1202195282105
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

> E.g. who fills, flushes & refills the TLB entries?

TLB entries are filled by H/W and not explicitly by kernel. Whenever MMU translates VA to PA it caches that translation into TLB. If TLB is full then MMU uses its own algorithms to replace some entry in TLB e.g. MMU might consider TLB as circular buffer and replace first entry once TLB is full.



>What all initializations need to be performed by kernel (And where is
>the code?)

Kernel bascially has to set up the page tables and set the Page Table Base register and enbale MMU.

 

Regards

- A.
 

On 2/5/08, Rick Brown <> wrote:
Hi,

I'm trying to understand the MMU operations & am wondering where is
the kernel code where the kernel interfaces with the this piece of

hardware?

Can some one help me in understanding that what all are the
responsibilities of the kernel, and what is it the hardware takes care
of automatically? E.g. who fills, flushes & refills the TLB entries?

What all initializations need to be performed by kernel (And where is
the code?)

TIA,

Rick

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to

Please read the FAQ at




------=_Part_8672_29209428.1202195282105--

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ

Re: TLB Question

am 05.02.2008 12:45:42 von Mulyadi Santosa

Hi...

On 2/5/08, sahlot arvind wrote:

> TLB entries are filled by H/W and not explicitly by kernel. Whenever MMU
> translates VA to PA it caches that translation into TLB. If TLB is full then
> MMU uses its own algorithms to replace some entry in TLB e.g. MMU might
> consider TLB as circular buffer and replace first entry once TLB is full.

AFAIK, by using certain instructions...you can manually insert
entry/entries to TLB. Same thing to deleting TLB entries. This kind of
technique is used for example on security related software such as
PaX/grsecurity

regards,

Mulyadi.
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" 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.linux-learn.org/faqs

Re: TLB Question

am 05.02.2008 13:29:31 von sahlot arvind

------=_Part_9339_15740412.1202214571894
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

>AFAIK, by using certain instructions...you can manually insert
>entry/entries to TLB. Same thing to deleting TLB entries.

Yes you can insert/delete entries in TLB manually. Though I am not sure but
AFAIK, linux kernel does do this.
Please correct if I am wrong.

Regards


On 2/5/08, Mulyadi Santosa wrote:
>
> Hi...
>
> On 2/5/08, sahlot arvind wrote:
>
> > TLB entries are filled by H/W and not explicitly by kernel. Whenever MMU
> > translates VA to PA it caches that translation into TLB. If TLB is full
> then
> > MMU uses its own algorithms to replace some entry in TLB e.g. MMU might
> > consider TLB as circular buffer and replace first entry once TLB is
> full.
>
> AFAIK, by using certain instructions...you can manually insert
> entry/entries to TLB. Same thing to deleting TLB entries. This kind of
> technique is used for example on security related software such as
> PaX/grsecurity
>
> regards,
>
> Mulyadi.
>

------=_Part_9339_15740412.1202214571894
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

>AFAIK, by using certain instructions...you can manually insert
>entry/entries to TLB. Same thing to deleting TLB entries.

 

Yes you can insert/delete entries in TLB manually. Though I am not sure but AFAIK, linux kernel does do this.

Please correct if I am wrong.

 

Regards

 

On 2/5/08, Mulyadi Santosa <> wrote:
Hi...

On 2/5/08, sahlot arvind <> wrote:


> TLB entries are filled by H/W and not explicitly by kernel. Whenever MMU
> translates VA to PA it caches that translation into TLB. If TLB is full then
> MMU uses its own algorithms to replace some entry in TLB e.g. MMU might

> consider TLB as circular buffer and replace first entry once TLB is full.

AFAIK, by using certain instructions...you can manually insert
entry/entries to TLB. Same thing to deleting TLB entries. This kind of

technique is used for example on security related software such as
PaX/grsecurity

regards,

Mulyadi.



------=_Part_9339_15740412.1202214571894--

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ

Re: TLB Question

am 05.02.2008 17:32:17 von mahaveer darade

hadling tlb is architecture specific thing, so its better to search
the manuals of corresponding processor to find out appropriate
instructions to manipulate TLB entries.
AFAI can recall INVLPG is used to invalidate specific pte in TLB.

regards,
mahaveer darade

On 2/5/08, sahlot arvind wrote:
> >AFAIK, by using certain instructions...you can manually insert
> >entry/entries to TLB. Same thing to deleting TLB entries.
>
> Yes you can insert/delete entries in TLB manually. Though I am not sure but
> AFAIK, linux kernel does do this.
> Please correct if I am wrong.
>
> Regards
>
>
> On 2/5/08, Mulyadi Santosa wrote:
> >
> > Hi...
> >
> > On 2/5/08, sahlot arvind wrote:
> >
> > > TLB entries are filled by H/W and not explicitly by kernel. Whenever MMU
> > > translates VA to PA it caches that translation into TLB. If TLB is full
> > then
> > > MMU uses its own algorithms to replace some entry in TLB e.g. MMU might
> > > consider TLB as circular buffer and replace first entry once TLB is
> > full.
> >
> > AFAIK, by using certain instructions...you can manually insert
> > entry/entries to TLB. Same thing to deleting TLB entries. This kind of
> > technique is used for example on security related software such as
> > PaX/grsecurity
> >
> > regards,
> >
> > Mulyadi.
> >
>


--
---------------------------
Thanks & Regards,
Mahaveer Darade
mah.darade@gmail.com
Mobile - 9970365267


--- Dream it , Code it.

---The "silly question" is the first intimation of some totally new development
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" 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.linux-learn.org/faqs

Re: TLB Question

am 06.02.2008 15:24:32 von Peter Teoh

I found one header file for x86 that implement the TLB flushing -
include/asm-x86/tlbflush.h (the different implementation are used are
used because of the diff generation of x86:

static inline void __native_flush_tlb(void)
{
write_cr3(read_cr3());
}

(my questions: WHAT IS THE DIFF BETWEEN FLUSH VIA flush_tlb() above
vs flush_tlb_global() below?)

static inline void __native_flush_tlb_global(void)
{
unsigned long cr4 = read_cr4();

/* clear PGE */
write_cr4(cr4 & ~X86_CR4_PGE);
/* write old PGE again and flush TLBs */
write_cr4(cr4);
}

(question: what is this single - does it flush only ONE SINGLE ENTRY
IN THE TLB that map this particular addr value?)

static inline void __native_flush_tlb_single(unsigned long addr)
{
__asm__ __volatile__("invlpg (%0)" ::"r" (addr) : "memory");
}
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" 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.linux-learn.org/faqs

Re: TLB Question

am 06.02.2008 15:49:07 von mahaveer darade

------=_Part_18808_26293286.1202309347478
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On Feb 6, 2008 7:54 PM, Peter Teoh wrote:

> I found one header file for x86 that implement the TLB flushing -
> include/asm-x86/tlbflush.h (the different implementation are used are
> used because of the diff generation of x86:
>
> static inline void __native_flush_tlb(void)
> {
> write_cr3(read_cr3());
> }
>
> (my questions: WHAT IS THE DIFF BETWEEN FLUSH VIA flush_tlb() above
> vs flush_tlb_global() below?)



below function is used to handle tlb entires of global pages as they do not
get flushed from TLB on task switch or writing to cr3


>
> static inline void __native_flush_tlb_global(void)
> {
> unsigned long cr4 = read_cr4();
>
> /* clear PGE */
> write_cr4(cr4 & ~X86_CR4_PGE);
> /* write old PGE again and flush TLBs */
> write_cr4(cr4);
> }
>
> (question: what is this single - does it flush only ONE SINGLE ENTRY
> IN THE TLB that map this particular addr value?)


yes thats right !! its used to invalidate particular PTE entry in TLB.


>
>
> static inline void __native_flush_tlb_single(unsigned long addr)
> {
> __asm__ __volatile__("invlpg (%0)" ::"r" (addr) : "memory");
> }
>



--
---------------------------
Thanks & Regards,
Mahaveer Darade
mah.darade@gmail.com
Mobile - 9970365267


--- Dream it , Code it.

---The "silly question" is the first intimation of some totally new
development

------=_Part_18808_26293286.1202309347478
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline



On Feb 6, 2008 7:54 PM, Peter Teoh <> wrote:

I found one header file for x86 that implement the TLB flushing -
include/asm-x86/tlbflush.h (the different implementation are used are
used because of the diff generation of x86:

static inline void __native_flush_tlb(void)

{
       write_cr3(read_cr3());
}

(my questions:   WHAT IS THE DIFF BETWEEN FLUSH VIA flush_tlb() above
vs flush_tlb_global() below?)


below function is used to handle tlb entires of global pages as they do not get flushed from TLB on task switch or writing to cr3




static inline void __native_flush_tlb_global(void)
{
       unsigned long cr4 = read_cr4();


       /* clear PGE */
       write_cr4(cr4 & ~X86_CR4_PGE);
       /* write old PGE again and flush TLBs */
       write_cr4(cr4);
}

(question:   what is this single - does it flush only ONE SINGLE ENTRY

IN THE TLB that map this particular addr value?)

yes thats right !! its used to invalidate particular PTE entry in TLB.
 



static inline void __native_flush_tlb_single(unsigned long addr)
{
       __asm__ __volatile__("invlpg (%0)" ::"r" (addr) : "memory");
}




--
---------------------------
Thanks & Regards,
Mahaveer Darade

Mobile - 9970365267


--- Dream it , Code it.

---The "silly question" is the first intimation of some totally new development

------=_Part_18808_26293286.1202309347478--

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ