mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: 管雪涛 <gxt@pku.edu.cn>
To: Chen Gang <gang.chen.5i5j@gmail.com>
Cc: Guan Xuetao <gxt@mprc.pku.edu.cn>,
	akpm@linux-foundation.org, liuj97@gmail.com, rientjes@google.com,
	dhowells@redhat.com, mhocko@suse.cz, mgorman@suse.de,
	linux-kernel@vger.kernel.org
Subject: 回复: [PATCH] arch:unicore32:mm: add devmem_is_allowed() to support STRICT_DEVMEM
Date: Tue, 8 Apr 2014 11:20:16 +0800 (CST)	[thread overview]
Message-ID: <629583968.18592.1396927216694.JavaMail.root@bj-mail03.pku.edu.cn> (raw)
In-Reply-To: <53428BC9.3070001@gmail.com>

I'd like to put the code into asm/io.h, and make it static.

> +#ifdef CONFIG_STRICT_DEVMEM
> +/*
> + * devmem_is_allowed() checks to see if /dev/mem access to a certain
> + * address is valid. The argument is a physical page number.
> + * We mimic x86 here by disallowing access to system RAM as well as
> + * device-exclusive MMIO regions. This effectively disable read()/write()
> + * on /dev/mem.
> + */
> +static int devmem_is_allowed(unsigned long pfn)
> +{
> +	if (iomem_is_exclusive(pfn << PAGE_SHIFT))
> +		return 0;
> +	if (!page_is_ram(pfn))
> +		return 1;
> +	return 0;
> +}
> +#endif /* CONFIG_STRICT_DEVMEM */

Thanks,

Acked-by: Xuetao Guan <gxt@mprc.pku.edu.cn>


----- Chen Gang <gang.chen.5i5j@gmail.com> 写道:
> unicore32 supports STRICT_DEVMEM, so it needs devmem_is_allowed(), like
> some of other architectures have done (e.g. arm, powerpc, x86 ...).
> 
> The related error with allmodconfig:
> 
>     CC      drivers/char/mem.o
>   drivers/char/mem.c: In function ‘range_is_allowed’:
>   drivers/char/mem.c:69: error: implicit declaration of function ‘devmem_is_allowed’
>   make[2]: *** [drivers/char/mem.o] Error 1
>   make[1]: *** [drivers/char] Error 2
>   make: *** [drivers] Error 2
> 
> 
> Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
> ---
>  arch/unicore32/include/asm/page.h |    4 ++++
>  arch/unicore32/mm/init.c          |   18 ++++++++++++++++++
>  2 files changed, 22 insertions(+)
> 
> diff --git a/arch/unicore32/include/asm/page.h b/arch/unicore32/include/asm/page.h
> index 594b322..231cb89 100644
> --- a/arch/unicore32/include/asm/page.h
> +++ b/arch/unicore32/include/asm/page.h
> @@ -68,6 +68,10 @@ typedef struct page *pgtable_t;
>  
>  extern int pfn_valid(unsigned long);
>  
> +#ifdef CONFIG_STRICT_DEVMEM
> +extern int devmem_is_allowed(unsigned long pfn);
> +#endif /* CONFIG_STRICT_DEVMEM */
> +
>  #include <asm/memory.h>
>  
>  #endif /* !__ASSEMBLY__ */
> diff --git a/arch/unicore32/mm/init.c b/arch/unicore32/mm/init.c
> index be2bde9..3bc3a59 100644
> --- a/arch/unicore32/mm/init.c
> +++ b/arch/unicore32/mm/init.c
> @@ -449,3 +449,21 @@ static int __init keepinitrd_setup(char *__unused)
>  
>  __setup("keepinitrd", keepinitrd_setup);
>  #endif
> +
> +#ifdef CONFIG_STRICT_DEVMEM
> +/*
> + * devmem_is_allowed() checks to see if /dev/mem access to a certain
> + * address is valid. The argument is a physical page number.
> + * We mimic x86 here by disallowing access to system RAM as well as
> + * device-exclusive MMIO regions. This effectively disable read()/write()
> + * on /dev/mem.
> + */
> +int devmem_is_allowed(unsigned long pfn)
> +{
> +	if (iomem_is_exclusive(pfn << PAGE_SHIFT))
> +		return 0;
> +	if (!page_is_ram(pfn))
> +		return 1;
> +	return 0;
> +}
> +#endif /* CONFIG_STRICT_DEVMEM */
> -- 
> 1.7.9.5

  reply	other threads:[~2014-04-08  3:20 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-07 11:28 Chen Gang
2014-04-08  3:20 ` 管雪涛 [this message]
2014-04-08  4:54   ` 回复: " Chen Gang
2014-04-15  0:14     ` Chen Gang
2014-04-15  0:28       ` [PATCH v2] " Chen Gang
2014-04-15  0:42         ` Chen Gang
2014-04-15  1:21           ` [PATCH v3] " Chen Gang
2014-04-16  5:15             ` 回复: " 管雪涛
2014-04-16  5:43               ` Chen Gang
2014-04-16  9:05             ` Michal Hocko
2014-04-16 10:11               ` Chen Gang

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=629583968.18592.1396927216694.JavaMail.root@bj-mail03.pku.edu.cn \
    --to=gxt@pku.edu.cn \
    --cc=akpm@linux-foundation.org \
    --cc=dhowells@redhat.com \
    --cc=gang.chen.5i5j@gmail.com \
    --cc=gxt@mprc.pku.edu.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liuj97@gmail.com \
    --cc=mgorman@suse.de \
    --cc=mhocko@suse.cz \
    --cc=rientjes@google.com \
    /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

Powered by JetHome