lkml.org 
[lkml]   [2022]   [Jan]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH V8 37/44] memremap_pages: Set PKS PKey in PTEs if PGMAP_PROTECTIONS is requested
    Date
    From: Ira Weiny <ira.weiny@intel.com>

    When the user requests protections the dev_pagemap mappings need to have
    a PKEY set.

    Define devmap_protection_adjust_pgprot() to add the PKey to the page
    protections. Call it when PGMAP_PROTECTIONS is requested when remapping
    pages.

    Signed-off-by: Ira Weiny <ira.weiny@intel.com>
    ---
    mm/memremap.c | 13 +++++++++++++
    1 file changed, 13 insertions(+)

    diff --git a/mm/memremap.c b/mm/memremap.c
    index a74d985a1908..d3e6f328a711 100644
    --- a/mm/memremap.c
    +++ b/mm/memremap.c
    @@ -83,6 +83,14 @@ static void devmap_protection_enable(void)
    static_branch_inc(&dev_pgmap_protection_static_key);
    }

    +static pgprot_t devmap_protection_adjust_pgprot(pgprot_t prot)
    +{
    + pgprotval_t val;
    +
    + val = pgprot_val(prot);
    + return __pgprot(val | _PAGE_PKEY(PKS_KEY_PGMAP_PROTECTION));
    +}
    +
    static void devmap_protection_disable(void)
    {
    static_branch_dec(&dev_pgmap_protection_static_key);
    @@ -99,6 +107,10 @@ EXPORT_SYMBOL_GPL(pgmap_protection_available);
    static void devmap_protection_enable(void) { }
    static void devmap_protection_disable(void) { }

    +static pgprot_t devmap_protection_adjust_pgprot(pgprot_t prot)
    +{
    + return prot;
    +}
    #endif /* CONFIG_DEVMAP_ACCESS_PROTECTION */

    static void pgmap_array_delete(struct range *range)
    @@ -353,6 +365,7 @@ void *memremap_pages(struct dev_pagemap *pgmap, int nid)
    if (!pgmap_protection_available())
    return ERR_PTR(-EINVAL);
    devmap_protection_enable();
    + params.pgprot = devmap_protection_adjust_pgprot(params.pgprot);
    }

    switch (pgmap->type) {
    --
    2.31.1
    \
     
     \ /
      Last update: 2022-01-27 18:56    [W:2.232 / U:0.060 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site