Re: Linux 5.1-rc5

Linus Torvalds
2019-04-16T16:49:46Z

[-- Attachment #1: Type: text/plain, Size: 739 bytes --]

On Tue, Apr 16, 2019 at 9:16 AM Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> We actually already *have* this function.
>
> It's called "gup_fast_permitted()" and it's used by x86-64 to verify
> the proper address range. Exactly like s390 needs..
>
> Could you please use that instead?

IOW, something like the attached.

Obviously untested. And maybe 'current' isn't declared in
<asm/pgtable.h>, in which case you'd need to modify it to instead make
the inline function be "s390_gup_fast_permitted()" that takes a
pointer to the mm, and do something like

#define gup_fast_permitted(start, pages) \
s390_gup_fast_permitted(current->mm, start, pages)

instead.

But I think you get the idea..

Linus

[-- Attachment #2: patch.diff --]
[-- Type: text/x-patch, Size: 724 bytes --]

arch/s390/include/asm/pgtable.h | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h
index 76dc344edb8c..a08248995f50 100644
--- a/arch/s390/include/asm/pgtable.h
+++ b/arch/s390/include/asm/pgtable.h
@@ -1659,4 +1659,16 @@ static inline void check_pgt_cache(void) { }

#include <asm-generic/pgtable.h>

+static inline bool gup_fast_permitted(unsigned long start, int nr_pages)
+{
+ unsigned long len, end;
+
+ len = (unsigned long)nr_pages << PAGE_SHIFT;
+ end = start + len;
+ if (end < start)
+ return false;
+ return end <= current->mm->context.asce_limit;
+}
+#define gup_fast_permitted gup_fast_permitted
+
#endif /* _S390_PAGE_H */