From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: "ira.weiny@intel.com" <ira.weiny@intel.com>,
"linux-api@vger.kernel.org" <linux-api@vger.kernel.org>
Cc: Florian Weimer <fweimer@redhat.com>,
"x86@kernel.org" <x86@kernel.org>,
"clemensb@chromium.org" <clemensb@chromium.org>,
"jkummerow@chromium.org" <jkummerow@chromium.org>,
"Aneesh Kumar K . V" <aneesh.kumar@linux.ibm.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>,
"ahaas@chromium.org" <ahaas@chromium.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"gdeepti@chromium.org" <gdeepti@chromium.org>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
"linux-kselftest@vger.kernel.org"
<linux-kselftest@vger.kernel.org>,
Sohil Mehta <sohil.mehta@intel.com>,
Andrew Morton <akpm@linux-foundation.org>,
"manoskouk@chromium.org" <manoskouk@chromium.org>,
"thibaudm@chromium.org" <thibaudm@chromium.org>
Subject: Re: [RFC PATCH 5/6] pkeys: Up level pkey_free() checks
Date: Mon, 13 Jun 2022 09:14:33 +0000 [thread overview]
Message-ID: <e4d447cc-b9f7-97a7-83d4-b41978f656d3@csgroup.eu> (raw)
In-Reply-To: <20220610233533.3649584-6-ira.weiny@intel.com>
Le 11/06/2022 à 01:35, ira.weiny@intel.com a écrit :
> From: Ira Weiny <ira.weiny@intel.com>
>
> x86 is missing a hardware check for pkey support in pkey_free(). While
> the net result is the same (-EINVAL returned), pkey_free() has well
> defined behavior which will be easier to maintain in one place.
>
> For powerpc the return code is -1 rather than -EINVAL. This changes
> that behavior slightly but this is very unlikely to break any user
> space.
>
> Lift the checks for pkey_free() to the core mm code and ensure
> consistency with returning -EINVAL.
>
> Cc: ahaas@chromium.org
> Cc: clemensb@chromium.org
> Cc: gdeepti@chromium.org
> Cc: jkummerow@chromium.org
> Cc: manoskouk@chromium.org
> Cc: thibaudm@chromium.org
> Cc: Florian Weimer <fweimer@redhat.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: linux-api@vger.kernel.org
> Cc: Sohil Mehta <sohil.mehta@intel.com>
> Cc: Dave Hansen <dave.hansen@linux.intel.com>
> Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
> Signed-off-by: Ira Weiny <ira.weiny@intel.com>
>
> ---
> Thanks to Sohil for suggesting I mention the powerpc return value in the
> commit message.
>
> Also Sohil suggested changing mm_pkey_free() from int to void. This is
> added as a separate patch with his suggested by.
> ---
> arch/powerpc/include/asm/pkeys.h | 6 ------
> arch/x86/include/asm/pkeys.h | 3 ---
> mm/mprotect.c | 8 ++++++--
> 3 files changed, 6 insertions(+), 11 deletions(-)
>
> diff --git a/arch/powerpc/include/asm/pkeys.h b/arch/powerpc/include/asm/pkeys.h
> index 2c8351248793..e96aa91f817b 100644
> --- a/arch/powerpc/include/asm/pkeys.h
> +++ b/arch/powerpc/include/asm/pkeys.h
> @@ -107,12 +107,6 @@ static inline int mm_pkey_alloc(struct mm_struct *mm)
>
> static inline int mm_pkey_free(struct mm_struct *mm, int pkey)
> {
> - if (!mmu_has_feature(MMU_FTR_PKEY))
> - return -1;
> -
> - if (!mm_pkey_is_allocated(mm, pkey))
> - return -EINVAL;
> -
> __mm_pkey_free(mm, pkey);
>
> return 0;
If it returns always 0, the return value is pointless and the function
mm_pkey_free() should be changed to return void.
> diff --git a/arch/x86/include/asm/pkeys.h b/arch/x86/include/asm/pkeys.h
> index 2e6c04d8a45b..da02737cc4d1 100644
> --- a/arch/x86/include/asm/pkeys.h
> +++ b/arch/x86/include/asm/pkeys.h
> @@ -107,9 +107,6 @@ int mm_pkey_alloc(struct mm_struct *mm)
> static inline
> int mm_pkey_free(struct mm_struct *mm, int pkey)
> {
> - if (!mm_pkey_is_allocated(mm, pkey))
> - return -EINVAL;
> -
> mm_set_pkey_free(mm, pkey);
>
> return 0;
Same.
> diff --git a/mm/mprotect.c b/mm/mprotect.c
> index 56d35de33725..41458e729c27 100644
> --- a/mm/mprotect.c
> +++ b/mm/mprotect.c
> @@ -803,10 +803,14 @@ SYSCALL_DEFINE2(pkey_alloc, unsigned long, flags, unsigned long, init_val)
>
> SYSCALL_DEFINE1(pkey_free, int, pkey)
> {
> - int ret;
> + int ret = -EINVAL;
Don't initialise 'ret'
> +
> + if (!arch_pkeys_enabled())
> + return ret;
Make it explicit, do 'return -EINVAL'
Once that is done, is there any point in having a fallback version of
mm_pkey_free() which returns -EINVAL ?
>
> mmap_write_lock(current->mm);
> - ret = mm_pkey_free(current->mm, pkey);
> + if (mm_pkey_is_allocated(current->mm, pkey))
> + ret = mm_pkey_free(current->mm, pkey);
Add:
else
ret = -EINVAL;
> mmap_write_unlock(current->mm);
>
> /*
next prev parent reply other threads:[~2022-06-13 9:14 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-10 23:35 [RFC PATCH 0/6] User pkey minor bug fixes ira.weiny
2022-06-10 23:35 ` [RFC PATCH 1/6] testing/pkeys: Add command line options ira.weiny
2022-06-13 22:31 ` Sohil Mehta
2022-06-13 23:41 ` Ira Weiny
2022-06-10 23:35 ` [RFC PATCH 2/6] testing/pkeys: Don't use uninitialized variable ira.weiny
2022-06-13 22:48 ` Sohil Mehta
2022-06-13 23:59 ` Ira Weiny
2022-06-10 23:35 ` [RFC PATCH 3/6] testing/pkeys: Add additional test for pkey_alloc() ira.weiny
2022-06-16 19:25 ` Sohil Mehta
2022-06-16 20:24 ` Dave Hansen
2022-06-10 23:35 ` [RFC PATCH 4/6] pkeys: Lift pkey hardware check " ira.weiny
2022-06-16 19:31 ` Sohil Mehta
2022-06-10 23:35 ` [RFC PATCH 5/6] pkeys: Up level pkey_free() checks ira.weiny
2022-06-13 9:14 ` Christophe Leroy [this message]
2022-06-10 23:35 ` [RFC PATCH 6/6] pkeys: Change mm_pkey_free() to void ira.weiny
2022-06-13 9:17 ` Christophe Leroy
2022-06-13 16:16 ` Ira Weiny
2022-06-13 22:05 ` [RFC PATCH 0/6] User pkey minor bug fixes Sohil Mehta
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=e4d447cc-b9f7-97a7-83d4-b41978f656d3@csgroup.eu \
--to=christophe.leroy@csgroup.eu \
--cc=ahaas@chromium.org \
--cc=akpm@linux-foundation.org \
--cc=aneesh.kumar@linux.ibm.com \
--cc=clemensb@chromium.org \
--cc=dave.hansen@linux.intel.com \
--cc=fweimer@redhat.com \
--cc=gdeepti@chromium.org \
--cc=ira.weiny@intel.com \
--cc=jkummerow@chromium.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=manoskouk@chromium.org \
--cc=sohil.mehta@intel.com \
--cc=thibaudm@chromium.org \
--cc=x86@kernel.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;
as well as URLs for NNTP newsgroup(s).