linux-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] riscv: Add pte bit to distinguish swap from invalid
@ 2018-12-16 18:03 Stefan O'Rear
  2018-12-17 18:37 ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan O'Rear @ 2018-12-16 18:03 UTC (permalink / raw)
  To: Palmer Dabbelt, Albert Ou, linux-riscv; +Cc: Stefan O'Rear, schwab

Previously, invalid PTEs and swap PTEs had the same binary
representation, causing errors when attempting to unmap PROT_NONE
mappings, including implicit unmap on exit.

Typical error:

swap_info_get: Bad swap file entry 40000000007a9879
BUG: Bad page map in process a.out  pte:3d4c3cc0 pmd:3e521401

Cc: stable@vger.kernel.org
Signed-off-by: Stefan O'Rear <sorear2@gmail.com>
---
 arch/riscv/include/asm/pgtable-bits.h | 6 ++++++
 arch/riscv/include/asm/pgtable.h      | 8 ++++----
 2 files changed, 10 insertions(+), 4 deletions(-)

Reproducer:

#include <sys/mman.h>

int
main (void)
{
  char *a = mmap (0, 4096, PROT_READ | PROT_WRITE,
                  MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  ++*a;
  mprotect (a, 4096, PROT_NONE);
}

diff --git a/arch/riscv/include/asm/pgtable-bits.h b/arch/riscv/include/asm/pgtable-bits.h
index 2fa2942..470755c 100644
--- a/arch/riscv/include/asm/pgtable-bits.h
+++ b/arch/riscv/include/asm/pgtable-bits.h
@@ -35,6 +35,12 @@
 #define _PAGE_SPECIAL   _PAGE_SOFT
 #define _PAGE_TABLE     _PAGE_PRESENT
 
+/*
+ * _PAGE_PROT_NONE is set on not-present pages (and ignored by the hardware) to
+ * distinguish them from swapped out pages
+ */
+#define _PAGE_PROT_NONE _PAGE_READ
+
 #define _PAGE_PFN_SHIFT 10
 
 /* Set of bits to preserve across pte_modify() */
diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
index 1630196..a8179a8 100644
--- a/arch/riscv/include/asm/pgtable.h
+++ b/arch/riscv/include/asm/pgtable.h
@@ -44,7 +44,7 @@
 /* Page protection bits */
 #define _PAGE_BASE	(_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_USER)
 
-#define PAGE_NONE		__pgprot(0)
+#define PAGE_NONE		__pgprot(_PAGE_PROT_NONE)
 #define PAGE_READ		__pgprot(_PAGE_BASE | _PAGE_READ)
 #define PAGE_WRITE		__pgprot(_PAGE_BASE | _PAGE_READ | _PAGE_WRITE)
 #define PAGE_EXEC		__pgprot(_PAGE_BASE | _PAGE_EXEC)
@@ -98,7 +98,7 @@ extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)];
 
 static inline int pmd_present(pmd_t pmd)
 {
-	return (pmd_val(pmd) & _PAGE_PRESENT);
+	return (pmd_val(pmd) & (_PAGE_PRESENT | _PAGE_PROT_NONE));
 }
 
 static inline int pmd_none(pmd_t pmd)
@@ -178,7 +178,7 @@ static inline pte_t *pte_offset_kernel(pmd_t *pmd, unsigned long addr)
 
 static inline int pte_present(pte_t pte)
 {
-	return (pte_val(pte) & _PAGE_PRESENT);
+	return (pte_val(pte) & (_PAGE_PRESENT | _PAGE_PROT_NONE));
 }
 
 static inline int pte_none(pte_t pte)
@@ -380,7 +380,7 @@ static inline int ptep_clear_flush_young(struct vm_area_struct *vma,
  *
  * Format of swap PTE:
  *	bit            0:	_PAGE_PRESENT (zero)
- *	bit            1:	reserved for future use (zero)
+ *	bit            1:	_PAGE_PROT_NONE (zero)
  *	bits      2 to 6:	swap type
  *	bits 7 to XLEN-1:	swap offset
  */
-- 
2.8.0


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

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

* Re: [PATCH] riscv: Add pte bit to distinguish swap from invalid
  2018-12-16 18:03 [PATCH] riscv: Add pte bit to distinguish swap from invalid Stefan O'Rear
@ 2018-12-17 18:37 ` Christoph Hellwig
  2019-02-08 17:36   ` David Abdurachmanov
  0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2018-12-17 18:37 UTC (permalink / raw)
  To: Stefan O'Rear; +Cc: schwab, linux-riscv, Palmer Dabbelt, Albert Ou

On Sun, Dec 16, 2018 at 01:03:36PM -0500, Stefan O'Rear wrote:
> Previously, invalid PTEs and swap PTEs had the same binary
> representation, causing errors when attempting to unmap PROT_NONE
> mappings, including implicit unmap on exit.
> 
> Typical error:
> 
> swap_info_get: Bad swap file entry 40000000007a9879
> BUG: Bad page map in process a.out  pte:3d4c3cc0 pmd:3e521401
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Stefan O'Rear <sorear2@gmail.com>

Looks fine:

Reviewed-by: Christoph Hellwig <hch@lst.de>

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

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

* Re: [PATCH] riscv: Add pte bit to distinguish swap from invalid
  2018-12-17 18:37 ` Christoph Hellwig
@ 2019-02-08 17:36   ` David Abdurachmanov
  2019-02-08 17:46     ` Palmer Dabbelt
  0 siblings, 1 reply; 4+ messages in thread
From: David Abdurachmanov @ 2019-02-08 17:36 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Stefan O'Rear, schwab, linux-riscv, Palmer Dabbelt, Albert Ou

Palmer, could you review/consider this patch for next rcX or next merge window?

david

On Mon, Dec 17, 2018 at 7:37 PM Christoph Hellwig <hch@infradead.org> wrote:
>
> On Sun, Dec 16, 2018 at 01:03:36PM -0500, Stefan O'Rear wrote:
> > Previously, invalid PTEs and swap PTEs had the same binary
> > representation, causing errors when attempting to unmap PROT_NONE
> > mappings, including implicit unmap on exit.
> >
> > Typical error:
> >
> > swap_info_get: Bad swap file entry 40000000007a9879
> > BUG: Bad page map in process a.out  pte:3d4c3cc0 pmd:3e521401
> >
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Stefan O'Rear <sorear2@gmail.com>
>
> Looks fine:
>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
>
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

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

* Re: [PATCH] riscv: Add pte bit to distinguish swap from invalid
  2019-02-08 17:36   ` David Abdurachmanov
@ 2019-02-08 17:46     ` Palmer Dabbelt
  0 siblings, 0 replies; 4+ messages in thread
From: Palmer Dabbelt @ 2019-02-08 17:46 UTC (permalink / raw)
  To: david.abdurachmanov; +Cc: Christoph Hellwig, sorear2, linux-riscv, aou, schwab

On Fri, 08 Feb 2019 09:36:19 PST (-0800), david.abdurachmanov@gmail.com wrote:
> Palmer, could you review/consider this patch for next rcX or next merge window?

I'll include this in next week's PR.

>
> david
>
> On Mon, Dec 17, 2018 at 7:37 PM Christoph Hellwig <hch@infradead.org> wrote:
>>
>> On Sun, Dec 16, 2018 at 01:03:36PM -0500, Stefan O'Rear wrote:
>> > Previously, invalid PTEs and swap PTEs had the same binary
>> > representation, causing errors when attempting to unmap PROT_NONE
>> > mappings, including implicit unmap on exit.
>> >
>> > Typical error:
>> >
>> > swap_info_get: Bad swap file entry 40000000007a9879
>> > BUG: Bad page map in process a.out  pte:3d4c3cc0 pmd:3e521401
>> >
>> > Cc: stable@vger.kernel.org
>> > Signed-off-by: Stefan O'Rear <sorear2@gmail.com>
>>
>> Looks fine:
>>
>> Reviewed-by: Christoph Hellwig <hch@lst.de>
>>
>> _______________________________________________
>> linux-riscv mailing list
>> linux-riscv@lists.infradead.org
>> http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

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

end of thread, other threads:[~2019-02-08 17:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-16 18:03 [PATCH] riscv: Add pte bit to distinguish swap from invalid Stefan O'Rear
2018-12-17 18:37 ` Christoph Hellwig
2019-02-08 17:36   ` David Abdurachmanov
2019-02-08 17:46     ` Palmer Dabbelt

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