From: linux@arm.linux.org.uk (Russell King - ARM Linux)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v3] arm: Support for the PXN CPU feature on ARMv7
Date: Wed, 26 Nov 2014 13:52:10 +0000 [thread overview]
Message-ID: <20141126135210.GJ3836@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <1417008840-27591-1-git-send-email-js07.lee@gmail.com>
On Wed, Nov 26, 2014 at 10:34:00PM +0900, Jungseung Lee wrote:
> +/*
> + * Once this call has completed the variable @vmsa is set to 'VMSA support'
> + * in case of ARMv7.
> + */
> +static inline bool cpu_has_classic_pxn(void)
> +{
> + if (__LINUX_ARM_ARCH__ >= 6 && !IS_ENABLED(CONFIG_ARM_LPAE)) {
> + static unsigned int vmsa = ~0UL;
> +
> + if (cpu_architecture() != CPU_ARCH_ARMv7)
> + return false;
> + if (vmsa == 4)
> + return true;
> +
> + vmsa = (read_cpuid_ext(CPUID_EXT_MMFR0) & 0xf) >> 0;
> + return vmsa == 4;
> + } else
> + return false;
> +}
Take a moment to consider whether this should be an inline function. It's
rather complex, involves calling out to a function, reading a variable,
etc...
> static inline void
> pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
> {
> - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
> + pmdval_t pmdval = _PAGE_USER_TABLE;
> +
> + if (cpu_has_classic_pxn())
> + pmdval |= PMD_PXNTABLE;
> + __pmd_populate(pmdp, page_to_phys(ptep), pmdval);
> }
> #define pmd_pgtable(pmd) pmd_page(pmd)
It's also used in another inline function.
Now, consider if we did this:
extern pmdval_t user_pmd_table;
static inline void
pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
{
__pmd_populate(pmdp, page_to_phys(ptep), user_pmd_table);
}
This means that pmd_populate() only has to load the value instead, which
is far simpler. All the setup complexity can live in build_mem_type_table()
which means that it only happens once, and we don't have to have checks
in these paths to see whether we've done that.
What would also be acceptable is to have the constant tests here, so the
compiler can eliminate the unnecessary load when we have no hope of ever
supporting PXN:
static inline void
pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
{
pmdval_t prot;
if (__LINUX_ARM_ARCH__ >= 6 && !IS_ENABLED(CONFIG_ARM_LPAE))
prot = user_pmd_table;
else
prot = _PAGE_USER_TABLE;
__pmd_populate(pmdp, page_to_phys(ptep), prot);
}
--
FTTC broadband for 0.8mile line: currently at 9.5Mbps down 400kbps up
according to speedtest.net.
next prev parent reply other threads:[~2014-11-26 13:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-26 13:34 [PATCH v3] arm: Support for the PXN CPU feature on ARMv7 Jungseung Lee
2014-11-26 13:52 ` Russell King - ARM Linux [this message]
2014-11-27 1:32 ` Jungseung Lee
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=20141126135210.GJ3836@n2100.arm.linux.org.uk \
--to=linux@arm.linux.org.uk \
--cc=linux-arm-kernel@lists.infradead.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