From: "Björn Töpel" <bjorn@kernel.org>
To: Alexandre Ghiti <alexghiti@rivosinc.com>
Cc: "Albert Ou" <aou@eecs.berkeley.edu>,
"David Hildenbrand" <david@redhat.com>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Paul Walmsley" <paul.walmsley@sifive.com>,
linux-riscv@lists.infradead.org,
"Oscar Salvador" <osalvador@suse.de>,
"Björn Töpel" <bjorn@rivosinc.com>,
"Andrew Bresticker" <abrestic@rivosinc.com>,
"Chethan Seshadri" <Chethan.Seshadri@catalinasystems.io>,
"Lorenzo Stoakes" <lstoakes@gmail.com>,
"Santosh Mamila" <santosh.mamila@catalinasystems.io>,
"Sivakumar Munnangi" <siva.munnangi@catalinasystems.io>,
"Sunil V L" <sunilvl@ventanamicro.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
virtualization@lists.linux-foundation.org
Subject: Re: [PATCH v3 9/9] riscv: mm: Add support for ZONE_DEVICE
Date: Tue, 21 May 2024 16:13:57 +0200 [thread overview]
Message-ID: <87pltfdzh6.fsf@all.your.base.are.belong.to.us> (raw)
In-Reply-To: <CAHVXubirHPj1pZhU7sFxFTzBWz_Psf5uts9y3Dji-a03nb=_iw@mail.gmail.com>
Alexandre Ghiti <alexghiti@rivosinc.com> writes:
> On Tue, May 21, 2024 at 1:49 PM Björn Töpel <bjorn@kernel.org> wrote:
>>
>> From: Björn Töpel <bjorn@rivosinc.com>
>>
>> ZONE_DEVICE pages need DEVMAP PTEs support to function
>> (ARCH_HAS_PTE_DEVMAP). Claim another RSW (reserved for software) bit
>> in the PTE for DEVMAP mark, add the corresponding helpers, and enable
>> ARCH_HAS_PTE_DEVMAP for riscv64.
>>
>> Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
>> ---
>> arch/riscv/Kconfig | 1 +
>> arch/riscv/include/asm/pgtable-64.h | 20 ++++++++++++++++++++
>> arch/riscv/include/asm/pgtable-bits.h | 1 +
>> arch/riscv/include/asm/pgtable.h | 17 +++++++++++++++++
>> 4 files changed, 39 insertions(+)
>>
>> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
>> index 2724dc2af29f..0b74698c63c7 100644
>> --- a/arch/riscv/Kconfig
>> +++ b/arch/riscv/Kconfig
>> @@ -36,6 +36,7 @@ config RISCV
>> select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
>> select ARCH_HAS_PMEM_API
>> select ARCH_HAS_PREPARE_SYNC_CORE_CMD
>> + select ARCH_HAS_PTE_DEVMAP if 64BIT && MMU
>> select ARCH_HAS_PTE_SPECIAL
>> select ARCH_HAS_SET_DIRECT_MAP if MMU
>> select ARCH_HAS_SET_MEMORY if MMU
>> diff --git a/arch/riscv/include/asm/pgtable-64.h b/arch/riscv/include/asm/pgtable-64.h
>> index 221a5c1ee287..c67a9bbfd010 100644
>> --- a/arch/riscv/include/asm/pgtable-64.h
>> +++ b/arch/riscv/include/asm/pgtable-64.h
>> @@ -400,4 +400,24 @@ static inline struct page *pgd_page(pgd_t pgd)
>> #define p4d_offset p4d_offset
>> p4d_t *p4d_offset(pgd_t *pgd, unsigned long address);
>>
>> +#ifdef CONFIG_TRANSPARENT_HUGEPAGE
>> +static inline int pte_devmap(pte_t pte);
>> +static inline pte_t pmd_pte(pmd_t pmd);
>> +
>> +static inline int pmd_devmap(pmd_t pmd)
>> +{
>> + return pte_devmap(pmd_pte(pmd));
>> +}
>> +
>> +static inline int pud_devmap(pud_t pud)
>> +{
>> + return 0;
>> +}
>> +
>> +static inline int pgd_devmap(pgd_t pgd)
>> +{
>> + return 0;
>> +}
>> +#endif
>> +
>> #endif /* _ASM_RISCV_PGTABLE_64_H */
>> diff --git a/arch/riscv/include/asm/pgtable-bits.h b/arch/riscv/include/asm/pgtable-bits.h
>> index 179bd4afece4..a8f5205cea54 100644
>> --- a/arch/riscv/include/asm/pgtable-bits.h
>> +++ b/arch/riscv/include/asm/pgtable-bits.h
>> @@ -19,6 +19,7 @@
>> #define _PAGE_SOFT (3 << 8) /* Reserved for software */
>>
>> #define _PAGE_SPECIAL (1 << 8) /* RSW: 0x1 */
>> +#define _PAGE_DEVMAP (1 << 9) /* RSW, devmap */
>> #define _PAGE_TABLE _PAGE_PRESENT
>>
>> /*
>> diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
>> index 7933f493db71..02fadc276064 100644
>> --- a/arch/riscv/include/asm/pgtable.h
>> +++ b/arch/riscv/include/asm/pgtable.h
>> @@ -387,6 +387,13 @@ static inline int pte_special(pte_t pte)
>> return pte_val(pte) & _PAGE_SPECIAL;
>> }
>>
>> +#ifdef CONFIG_ARCH_HAS_PTE_DEVMAP
>> +static inline int pte_devmap(pte_t pte)
>> +{
>> + return pte_val(pte) & _PAGE_DEVMAP;
>> +}
>> +#endif
>
> Not sure you need the #ifdef here.
W/o it 32b builds break (!defined(CONFIG_ARCH_HAS_PTE_DEVMAP) will have
a default implementation).. Maybe it's cleaner just to use that instead?
>> +
>> /* static inline pte_t pte_rdprotect(pte_t pte) */
>>
>> static inline pte_t pte_wrprotect(pte_t pte)
>> @@ -428,6 +435,11 @@ static inline pte_t pte_mkspecial(pte_t pte)
>> return __pte(pte_val(pte) | _PAGE_SPECIAL);
>> }
>>
>> +static inline pte_t pte_mkdevmap(pte_t pte)
>> +{
>> + return __pte(pte_val(pte) | _PAGE_DEVMAP);
>> +}
>> +
>> static inline pte_t pte_mkhuge(pte_t pte)
>> {
>> return pte;
>> @@ -711,6 +723,11 @@ static inline pmd_t pmd_mkdirty(pmd_t pmd)
>> return pte_pmd(pte_mkdirty(pmd_pte(pmd)));
>> }
>>
>> +static inline pmd_t pmd_mkdevmap(pmd_t pmd)
>> +{
>> + return pte_pmd(pte_mkdevmap(pmd_pte(pmd)));
>> +}
>> +
>> static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr,
>> pmd_t *pmdp, pmd_t pmd)
>> {
>> --
>> 2.40.1
>>
>
> Otherwise, you can add:
>
> Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Thank you!
Björn
prev parent reply other threads:[~2024-05-21 14:14 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-21 11:48 [PATCH v3 0/9] riscv: Memory Hot(Un)Plug support Björn Töpel
2024-05-21 11:48 ` [PATCH v3 1/9] riscv: mm: Properly forward vmemmap_populate() altmap parameter Björn Töpel
2024-05-21 12:22 ` Alexandre Ghiti
2024-05-21 11:48 ` [PATCH v3 2/9] riscv: mm: Pre-allocate vmemmap/direct map PGD entries Björn Töpel
2024-05-21 16:09 ` Björn Töpel
2024-05-21 11:48 ` [PATCH v3 3/9] riscv: mm: Change attribute from __init to __meminit for page functions Björn Töpel
2024-05-21 12:35 ` Alexandre Ghiti
2024-05-21 11:48 ` [PATCH v3 4/9] riscv: mm: Refactor create_linear_mapping_range() for memory hot add Björn Töpel
2024-05-21 11:48 ` [PATCH v3 5/9] riscv: mm: Add memory hotplugging support Björn Töpel
2024-05-21 13:19 ` Alexandre Ghiti
2024-05-21 14:18 ` Björn Töpel
2024-05-21 14:20 ` Oscar Salvador
2024-05-21 11:48 ` [PATCH v3 6/9] riscv: mm: Take memory hotplug read-lock during kernel page table dump Björn Töpel
2024-05-21 11:48 ` [PATCH v3 7/9] riscv: Enable memory hotplugging for RISC-V Björn Töpel
2024-05-21 13:23 ` Alexandre Ghiti
2024-05-21 11:48 ` [PATCH v3 8/9] virtio-mem: Enable virtio-mem " Björn Töpel
2024-05-21 11:48 ` [PATCH v3 9/9] riscv: mm: Add support for ZONE_DEVICE Björn Töpel
2024-05-21 13:41 ` Alexandre Ghiti
2024-05-21 14:13 ` Björn Töpel [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87pltfdzh6.fsf@all.your.base.are.belong.to.us \
--to=bjorn@kernel.org \
--cc=Chethan.Seshadri@catalinasystems.io \
--cc=abrestic@rivosinc.com \
--cc=alexghiti@rivosinc.com \
--cc=aou@eecs.berkeley.edu \
--cc=bjorn@rivosinc.com \
--cc=david@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-riscv@lists.infradead.org \
--cc=lstoakes@gmail.com \
--cc=osalvador@suse.de \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=santosh.mamila@catalinasystems.io \
--cc=siva.munnangi@catalinasystems.io \
--cc=sunilvl@ventanamicro.com \
--cc=virtualization@lists.linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox