* Re: [mm/debug_vm_pgtable] a97a171093: BUG:unable_to_handle_page_fault_for_address
From: Anshuman Khandual @ 2020-07-10 6:47 UTC (permalink / raw)
To: kernel test robot
Cc: Benjamin Herrenschmidt, Heiko Carstens, linux-mm, Paul Mackerras,
H. Peter Anvin, linux-riscv, Will Deacon, linux-arch, linux-s390,
Michael Ellerman, x86, Mike Rapoport, Christian Borntraeger,
Ingo Molnar, Catalin Marinas, linux-snps-arc, Vasily Gorbik, lkp,
Borislav Petkov, Paul Walmsley, Kirill A . Shutemov,
Thomas Gleixner, linux-arm-kernel, Vineet Gupta, linux-kernel,
Palmer Dabbelt, Andrew Morton, linuxppc-dev
In-Reply-To: <20200709061122.GN3874@shao2-debian>
On 07/09/2020 11:41 AM, kernel test robot wrote:
> [ 94.349598] BUG: unable to handle page fault for address: ffffed10a7ffddff
> [ 94.351039] #PF: supervisor read access in kernel mode
> [ 94.352172] #PF: error_code(0x0000) - not-present page
> [ 94.353256] PGD 43ffed067 P4D 43ffed067 PUD 43fdee067 PMD 0
> [ 94.354484] Oops: 0000 [#1] SMP KASAN
> [ 94.355238] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 5.8.0-rc4-00002-ga97a17109332c #1
> [ 94.360456] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-1 04/01/2014
> [ 94.361950] RIP: 0010:hugetlb_advanced_tests+0x137/0x699
> [ 94.363026] Code: 8b 13 4d 85 f6 75 0b 48 ff 05 2c e4 6a 01 31 ed eb 41 bf f8 ff ff ff ba ff ff 37 00 4c 01 f7 48 c1 e2 2a 48 89 f9 48 c1 e9 03 <80> 3c 11 00 74 05 e8 cd c0 67 fa ba f8 ff ff ff 49 8b 2c 16 48 85
> [ 94.366592] RSP: 0000:ffffc90000047d30 EFLAGS: 00010a06
> [ 94.367693] RAX: 1ffffffff1049b80 RBX: ffff888380525308 RCX: 1ffff110a7ffddff
> [ 94.369215] RDX: dffffc0000000000 RSI: 1ffff11087ffdc00 RDI: ffff88853ffeeff8
> [ 94.370693] RBP: 000000000018e510 R08: 0000000000000025 R09: 0000000000000001
> [ 94.372165] R10: ffff888380523c07 R11: ffffed10700a4780 R12: ffff88843208e510
> [ 94.373674] R13: 0000000000000025 R14: ffff88843ffef000 R15: 000031e01ae61000
> [ 94.375147] FS: 0000000000000000(0000) GS:ffff8883a3800000(0000) knlGS:0000000000000000
> [ 94.376883] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> [ 94.378051] CR2: ffffed10a7ffddff CR3: 0000000004e15000 CR4: 00000000000406a0
> [ 94.379522] Call Trace:
> [ 94.380073] debug_vm_pgtable+0xd81/0x2029
> [ 94.380871] ? pmd_advanced_tests+0x621/0x621
> [ 94.381819] do_one_initcall+0x1eb/0xbd0
> [ 94.382551] ? trace_event_raw_event_initcall_finish+0x240/0x240
> [ 94.383634] ? rcu_read_lock_sched_held+0xb9/0x110
> [ 94.388727] ? rcu_read_lock_held+0xd0/0xd0
> [ 94.389604] ? __kasan_check_read+0x1d/0x30
> [ 94.390485] kernel_init_freeable+0x430/0x4f8
> [ 94.391416] ? rest_init+0x3f8/0x3f8
> [ 94.392185] kernel_init+0x14/0x1e8
> [ 94.392918] ret_from_fork+0x22/0x30
> [ 94.393662] Modules linked in:
> [ 94.394289] CR2: ffffed10a7ffddff
> [ 94.395000] ---[ end trace 8ca5a1655dfb8c39 ]---
This bug is caused from here.
static inline struct mem_section *__nr_to_section(unsigned long nr)
{
#ifdef CONFIG_SPARSEMEM_EXTREME
if (!mem_section)
return NULL;
#endif
if (!mem_section[SECTION_NR_TO_ROOT(nr)]) <-------- BUG
return NULL;
return &mem_section[SECTION_NR_TO_ROOT(nr)][nr & SECTION_ROOT_MASK];
}
static inline struct mem_section *__pfn_to_section(unsigned long pfn)
{
return __nr_to_section(pfn_to_section_nr(pfn));
}
#define __pfn_to_page(pfn) \
({ unsigned long __pfn = (pfn); \
struct mem_section *__sec = __pfn_to_section(__pfn); \
__section_mem_map_addr(__sec) + __pfn; \
})
which is called via hugetlb_advanced_tests().
paddr = (__pfn_to_phys(pfn) | RANDOM_ORVALUE) & PMD_MASK;
pte = pte_mkhuge(mk_pte(pfn_to_page(PHYS_PFN(paddr)), prot));
Primary reason being RANDOM_ORVALUE, which is added to the paddr before
being masked with PMD_MASK. This clobbers up the pfn value which cannot
be searched in relevant memory sections. This problem stays hidden on
other configs where pfn_to_page() does not go via memory section search.
Dropping off RANDOM_ORVALUE solves the problem. Probably, just wanted to
drop that off during V2 series (https://lkml.org/lkml/2020/4/8/997) but
dont remember why ended up keeping it again.
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply
* Re: [PATCH 1/5] lib: Add a generic version of devmem_is_allowed()
From: Nick Kossifidis @ 2020-07-10 5:48 UTC (permalink / raw)
To: Christoph Hellwig
Cc: mark.rutland, steve, davidgow, catalin.marinas, linus.walleij,
Palmer Dabbelt, elver, glider, willy, zong.li, mchehab+samsung,
linux-riscv, alex.shi, will, ardb, linux-arch, Arnd Bergmann,
alex, takahiro.akashi, masahiroy, linux, krzk, Mike Rapoport,
bgolaszewski, Palmer Dabbelt, kernel-team, pmladek, zaslonko, aou,
keescook, paulmck, rostedt, uwe, broonie, matti.vaittinen,
gregory.0xf0, Paul Walmsley, dan.j.williams, andriy.shevchenko,
gxt, linux-arm-kernel, tglx, rdunlap, Nick Desaulniers,
linux-kernel, mcgrof, james.morse, mhiramat, akpm, davem
In-Reply-To: <20200710053850.GA27019@infradead.org>
Στις 2020-07-10 08:38, Christoph Hellwig έγραψε:
> On Thu, Jul 09, 2020 at 11:49:21PM +0300, Mike Rapoport wrote:
>> > +#ifndef CONFIG_GENERIC_DEVMEM_IS_ALLOWED
>> > +extern int devmem_is_allowed(unsigned long pfn);
>> > +#endif
>
> Nit: no need for the extern here.
>
>> > +config GENERIC_LIB_DEVMEM_IS_ALLOWED
>> > + bool
>> > + select ARCH_HAS_DEVMEM_IS_ALLOWED
>>
>> This seems to work the other way around from the usual Kconfig chains.
>> In the most cases ARCH_HAS_SOMETHING selects GENERIC_SOMETHING.
>>
>> I believe nicer way would be to make
>>
>> config STRICT_DEVMEM
>> bool "Filter access to /dev/mem"
>> depends on MMU && DEVMEM
>> depends on ARCH_HAS_DEVMEM_IS_ALLOWED ||
>> GENERIC_LIB_DEVMEM_IS_ALLOWED
>>
>> config GENERIC_LIB_DEVMEM_IS_ALLOWED
>> bool
>>
>> and then s/select ARCH_HAS_DEVMEM_IS_ALLOWED/select
>> GENERIC_LIB_DEVMEM_IS_ALLOWED/
>> in the arch Kconfigs and drop ARCH_HAS_DEVMEM_IS_ALLOWED in the end.
>
> To take a step back: Is there any reason to not just always
> STRICT_DEVMEM? Maybe for a few architectures that don't currently
> support a strict /dev/mem the generic version isn't quite correct, but
> someone selecting the option and finding the issue is the best way to
> figure that out..
>
During prototyping / testing having full access to all physical memory
through /dev/mem is very useful. We should have it enabled by default
but leave the config option there so that users / developers can disable
it if needed IMHO.
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply
* Re: [PATCH 1/5] lib: Add a generic version of devmem_is_allowed()
From: Christoph Hellwig @ 2020-07-10 5:51 UTC (permalink / raw)
To: Nick Kossifidis
Cc: mark.rutland, steve, davidgow, catalin.marinas, linus.walleij,
Palmer Dabbelt, elver, glider, willy, zong.li, mchehab+samsung,
linux-riscv, alex.shi, will, ardb, linux-arch, Arnd Bergmann,
alex, takahiro.akashi, masahiroy, linux, krzk, Mike Rapoport,
Christoph Hellwig, bgolaszewski, Palmer Dabbelt, kernel-team,
pmladek, zaslonko, aou, keescook, paulmck, rostedt, uwe, broonie,
matti.vaittinen, gregory.0xf0, Paul Walmsley, dan.j.williams,
andriy.shevchenko, gxt, linux-arm-kernel, tglx, rdunlap,
Nick Desaulniers, linux-kernel, mcgrof, james.morse, mhiramat,
akpm, davem
In-Reply-To: <a037dac961c989d027eab293a0280643@mailhost.ics.forth.gr>
On Fri, Jul 10, 2020 at 08:48:17AM +0300, Nick Kossifidis wrote:
> ???????? 2020-07-10 08:38, Christoph Hellwig ????????????:
> > On Thu, Jul 09, 2020 at 11:49:21PM +0300, Mike Rapoport wrote:
> > > > +#ifndef CONFIG_GENERIC_DEVMEM_IS_ALLOWED
> > > > +extern int devmem_is_allowed(unsigned long pfn);
> > > > +#endif
> >
> > Nit: no need for the extern here.
> >
> > > > +config GENERIC_LIB_DEVMEM_IS_ALLOWED
> > > > + bool
> > > > + select ARCH_HAS_DEVMEM_IS_ALLOWED
> > >
> > > This seems to work the other way around from the usual Kconfig chains.
> > > In the most cases ARCH_HAS_SOMETHING selects GENERIC_SOMETHING.
> > >
> > > I believe nicer way would be to make
> > >
> > > config STRICT_DEVMEM
> > > bool "Filter access to /dev/mem"
> > > depends on MMU && DEVMEM
> > > depends on ARCH_HAS_DEVMEM_IS_ALLOWED ||
> > > GENERIC_LIB_DEVMEM_IS_ALLOWED
> > >
> > > config GENERIC_LIB_DEVMEM_IS_ALLOWED
> > > bool
> > >
> > > and then s/select ARCH_HAS_DEVMEM_IS_ALLOWED/select
> > > GENERIC_LIB_DEVMEM_IS_ALLOWED/
> > > in the arch Kconfigs and drop ARCH_HAS_DEVMEM_IS_ALLOWED in the end.
> >
> > To take a step back: Is there any reason to not just always
> > STRICT_DEVMEM? Maybe for a few architectures that don't currently
> > support a strict /dev/mem the generic version isn't quite correct, but
> > someone selecting the option and finding the issue is the best way to
> > figure that out..
> >
>
> During prototyping / testing having full access to all physical memory
> through /dev/mem is very useful. We should have it enabled by default but
> leave the config option there so that users / developers can disable it if
> needed IMHO.
I did not suggest to take the config option away. Just to
unconditionally allow enabling the option on all architectures.
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply
* Re: [PATCH 1/5] lib: Add a generic version of devmem_is_allowed()
From: Christoph Hellwig @ 2020-07-10 5:38 UTC (permalink / raw)
To: Mike Rapoport
Cc: mark.rutland, steve, gregory.0xf0, catalin.marinas, linus.walleij,
Palmer Dabbelt, zaslonko, glider, krzk, zong.li, mchehab+samsung,
linux-riscv, alex.shi, will, ardb, linux-arch, paulmck, alex,
bgolaszewski, masahiroy, linux, willy, takahiro.akashi,
james.morse, kernel-team, Arnd Bergmann, pmladek, elver, aou,
keescook, uwe, rostedt, broonie, davidgow, Paul Walmsley,
dan.j.williams, andriy.shevchenko, gxt, linux-arm-kernel,
Nick Desaulniers, tglx, rdunlap, matti.vaittinen, linux-kernel,
mcgrof, Palmer Dabbelt, mhiramat, akpm, davem
In-Reply-To: <20200709204921.GJ781326@linux.ibm.com>
On Thu, Jul 09, 2020 at 11:49:21PM +0300, Mike Rapoport wrote:
> > +#ifndef CONFIG_GENERIC_DEVMEM_IS_ALLOWED
> > +extern int devmem_is_allowed(unsigned long pfn);
> > +#endif
Nit: no need for the extern here.
> > +config GENERIC_LIB_DEVMEM_IS_ALLOWED
> > + bool
> > + select ARCH_HAS_DEVMEM_IS_ALLOWED
>
> This seems to work the other way around from the usual Kconfig chains.
> In the most cases ARCH_HAS_SOMETHING selects GENERIC_SOMETHING.
>
> I believe nicer way would be to make
>
> config STRICT_DEVMEM
> bool "Filter access to /dev/mem"
> depends on MMU && DEVMEM
> depends on ARCH_HAS_DEVMEM_IS_ALLOWED || GENERIC_LIB_DEVMEM_IS_ALLOWED
>
> config GENERIC_LIB_DEVMEM_IS_ALLOWED
> bool
>
> and then s/select ARCH_HAS_DEVMEM_IS_ALLOWED/select GENERIC_LIB_DEVMEM_IS_ALLOWED/
> in the arch Kconfigs and drop ARCH_HAS_DEVMEM_IS_ALLOWED in the end.
To take a step back: Is there any reason to not just always
STRICT_DEVMEM? Maybe for a few architectures that don't currently
support a strict /dev/mem the generic version isn't quite correct, but
someone selecting the option and finding the issue is the best way to
figure that out..
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply
* Re: Random, rare, but reproducible segmentation faults
From: Alex Ghiti @ 2020-07-10 5:15 UTC (permalink / raw)
To: Aurelien Jarno, linux-riscv
In-Reply-To: <b7de2a27-d3b4-194e-2f80-664406055494@ghiti.fr>
Hi Aurélien,
Le 7/9/20 à 6:49 AM, Alex Ghiti a écrit :
> Hi Aurélien,
>
> Le 7/8/20 à 4:28 PM, Aurelien Jarno a écrit :
>> Hi all,
>>
>> For some time I have seen random but relatively rare segmentation faults
>> when building Debian packages, either in a QEMU virtual machine or an
>> Hifive Unleashed board. I have recently been able to reproduce the issue
>> by building Qt [1]. It usually fails after roughly one hour of build,
>> not always on the same C++ file, but always on the same set of files.
>> Trying to run make again the build is usually successful. When it
>> happens one get the following error from GCC:
>>
>> | g++: internal compiler error: Segmentation fault signal terminated
>> program cc1plus
>> | Please submit a full bug report,
>> | with preprocessed source if appropriate.
>>
>> And the following kernel error:
>>
>> | [267054.967857] cc1plus[1171618]: unhandled signal 11 code 0x1 at
>> 0x000000156888a430 in cc1plus[10000+e0e000]
>> | [267054.976759] CPU: 3 PID: 1171618 Comm: cc1plus Not tainted 5.7.7+ #1
>> | [267054.983101] epc: 0000000000a70e3e ra : 0000000000a71dbe sp :
>> 0000003ffff3c870
>> | [267054.990293] gp : 0000000000e33158 tp : 000000156a0f0720 t0 :
>> 0000001569feb0d0
>> | [267054.997593] t1 : 0000000000182a2c t2 : 0000000000e30620 s0 :
>> 000000000003b7c0
>> | [267055.004880] s1 : 000000000003b7c0 a0 : 000000156888a420 a1 :
>> 000000000003b7c0
>> | [267055.012176] a2 : 0000000000000002 a3 : 000000000003b7c0 a4 :
>> 000000000003b7c0
>> | [267055.019473] a5 : 0000000000000001 a6 : 61746e656d676553 a7 :
>> 73737350581f0402
>> | [267055.026763] s2 : 0000003ffff3c8c8 s3 : 000000156888a420 s4 :
>> 000000007fffffff
>> | [267055.034052] s5 : 0000000070000000 s6 : 0000000000000000 s7 :
>> 0000003ffff3d638
>> | [267055.041345] s8 : 0000000000e9ab18 s9 : 0000000000000000 s10:
>> 0000000000e9a9d0
>> | [267055.048636] s11: 0000000000000000 t3 : 000000156888a420 t4 :
>> 0000000000000001
>> | [267055.055930] t5 : 0000000000000001 t6 : 0000000000000000
>> | [267055.061311] status: 8000000200006020 badaddr: 000000156888a430
>> cause: 000000000000000d
>>
>> I have been able to bisect the issue and found it has been introduced by
>> this commit:
>>
>> | commit 54c95a11cc1b5e1d578209e027adf5775395dafd
>> | Author: Alexandre Ghiti <alex@ghiti.fr>
>> | Date: Mon Sep 23 15:39:21 2019 -0700
>> |
>> | riscv: make mmap allocation top-down by default
>> |
>> | In order to avoid wasting user address space by using bottom-up
>> mmap
>> | allocation scheme, prefer top-down scheme when possible.
>>
>> Reverting this commit, even on 5.7.7, fixes the issue. I debugged things
>> a bit more, and found that the problem doesn't come from the top-down
>> allocation (i.e. setting vm.legacy_va_layout to 1 doesn't change
>> anything). However I have found it comes from the randomization, I mean
>> that the following patch is enough to fix (or workaround?) the issue:
>>
>> | --- a/mm/util.c
>> | +++ b/mm/util.c
>> | @@ -397,8 +397,8 @@ void arch_pick_mmap_layout(struct mm_struct *mm,
>> struct rlimit *rlim_stack)
>> | {
>> | unsigned long random_factor = 0UL;
>> |
>> | - if (current->flags & PF_RANDOMIZE)
>> | - random_factor = arch_mmap_rnd();
>> | +/* if (current->flags & PF_RANDOMIZE)
>> | + random_factor = arch_mmap_rnd();*/
>> |
>> | if (mmap_is_legacy(rlim_stack)) {
>> | mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
>>
>> I have also tried to play with vm.mmap_rnd_bits, but it seems that it
>> doesn't have any real effect.
>
> That's too bad because this is the only riscv specific thing in this
> feature. And it is used by arm, arm64 and mips so we should be looking
> at something riscv specific here, but right now I don't know what.
>
> I will take a look at that.
>
> Thanks,
>
> Alex
>
> I however noticed that setting this value
>> to 24 (the maximum) might move the heap next to the stack in some cases,
>> although it seems unrelated to the original issue:
>>
>> | $ cat /proc/self/maps
>> | 340fde4000-340fe06000 rw-p 00000000 00:00 0
>> | 340fe06000-340ff08000 r-xp 00000000 fe:01
>> 1835219 /lib/riscv64-linux-gnu/libc-2.30.so
>> | 340ff08000-340ff09000 ---p 00102000 fe:01
>> 1835219 /lib/riscv64-linux-gnu/libc-2.30.so
>> | 340ff09000-340ff0c000 r--p 00102000 fe:01
>> 1835219 /lib/riscv64-linux-gnu/libc-2.30.so
>> | 340ff0c000-340ff0f000 rw-p 00105000 fe:01
>> 1835219 /lib/riscv64-linux-gnu/libc-2.30.so
>> | 340ff0f000-340ff14000 rw-p 00000000 00:00 0
>> | 340ff1d000-340ff1f000 r-xp 00000000 00:00
>> 0 [vdso]
>> | 340ff1f000-340ff36000 r-xp 00000000 fe:01
>> 1835039 /lib/riscv64-linux-gnu/ld-2.30.so
>> | 340ff36000-340ff37000 r--p 00016000 fe:01
>> 1835039 /lib/riscv64-linux-gnu/ld-2.30.so
>> | 340ff37000-340ff38000 rw-p 00017000 fe:01
>> 1835039 /lib/riscv64-linux-gnu/ld-2.30.so
>> | 340ff38000-340ff39000 rw-p 00000000 00:00 0
>> | 3924505000-392450b000 r-xp 00000000 fe:01
>> 1048640 /bin/cat
>> | 392450b000-392450c000 r--p 00005000 fe:01
>> 1048640 /bin/cat
>> | 392450c000-392450d000 rw-p 00006000 fe:01
>> 1048640 /bin/cat
>> | 3955e23000-3955e44000 rw-p 00000000 00:00
>> 0 [heap]
>> | 3fffa2b000-3fffa4c000 rw-p 00000000 00:00
>> 0 [stack]
>>
>> To come back to the original issue, I don't know how to debug it
>> further. I have already tried to get a core dump and analyze it with
>> GDB, but the code triggering the failure is not part of the binary. Any
>> hint or help would be welcomed.
>>
>> Thanks,
>> Aurelien
>>
>>
>> [1] Technically the qtbase-opensource-src Debian package:
>> https://packages.debian.org/source/sid/qtbase-opensource-src
>>
>
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv
I have a debian kernel downloaded from here
https://people.debian.org/~gio/dqib/ that runs using the following qemu
command:
qemu-system-riscv64 -machine virt -cpu rv64 -m 1G -device
virtio-blk-device,drive=hd -drive file=image.qcow2,if=none,id=hd -device
virtio-net-device,netdev=net -netdev user,id=net,hostfwd=tcp::2222-:22
-bios ~/wip/lpc/buildroot/build_rv64/images/fw_jump.elf -kernel kernel
-initrd initrd -object rng-random,filename=/dev/urandom,id=rng -device
virtio-rng-device,rng=rng -nographic -append "root=/dev/vda1 console=ttyS0"
First is this kernel version ok to reproduce the bug ? Or should I
download another image ? I'd like to avoid having to rebuild the kernel
myself if possible.
Now I would like to reproduce the bug: can you give me instructions on
how to compile the qt package ?
Is the page fault address always in the same area ? It might be
interesting to find some pattern in those addresses, maybe you could
also print the random offset to try to link both ? Also print the entire
virtual memory mapping at the time of the fault (I don't know how to do
that) to check what the address is close to ? The 0xd cause implies that
the virtual address does not exist at all, which is weird, my guess is
that the randomization "reveals" the bug but that the bug is still there
once the randomization is disabled.
I'm sorry I don't have much more to propose here :(
Alex
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply
* Re: [PATCH 2/2] riscv: Support CONFIG_STRICT_DEVMEM
From: Zong Li @ 2020-07-10 2:43 UTC (permalink / raw)
To: Palmer Dabbelt
Cc: linux-riscv, linux-kernel@vger.kernel.org List, Paul Walmsley
In-Reply-To: <mhng-d4637494-2072-41f6-9a8a-1b222d89d6c4@palmerdabbelt-glaptop1>
On Fri, Jul 10, 2020 at 4:08 AM Palmer Dabbelt <palmer@dabbelt.com> wrote:
>
> On Tue, 16 Jun 2020 00:45:47 PDT (-0700), zong.li@sifive.com wrote:
> > Implement the 'devmem_is_allowed()' interface for RISC-V, like some of
> > other architectures have done. It will be called from range_is_allowed()
> > when userpsace attempts to access /dev/mem.
>
> In fact, it's exactly the same (down to a few words of the comment) to the
> others that I checked. I'm going to put a generic version in lib/ instead,
> I've sent out the patches.
>
OK, no problem, thanks for improving it.
> > Access to exclusive IOMEM and kernel RAM is denied unless
> > CONFIG_STRICT_DEVMEM is set to 'n'.
> >
> > Test it by devmem, the result as follows:
> >
> > - CONFIG_STRICT_DEVMEM=y
> > $ devmem 0x10010000
> > 0x00000000
> > $ devmem 0x80200000
> > 0x0000106F
> >
> > - CONFIG_STRICT_DEVMEM is not set
> > $ devmem 0x10010000
> > devmem: mmap: Operation not permitted
> > $ devmem 0x80200000
> > devmem: mmap: Operation not permitted
> >
> > Signed-off-by: Zong Li <zong.li@sifive.com>
> > ---
> > arch/riscv/Kconfig | 1 +
> > arch/riscv/include/asm/io.h | 2 ++
> > arch/riscv/mm/init.c | 19 +++++++++++++++++++
> > 3 files changed, 22 insertions(+)
> >
> > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> > index 128192e14ff2..ffd7841ede4c 100644
> > --- a/arch/riscv/Kconfig
> > +++ b/arch/riscv/Kconfig
> > @@ -16,6 +16,7 @@ config RISCV
> > select ARCH_HAS_BINFMT_FLAT
> > select ARCH_HAS_DEBUG_VIRTUAL if MMU
> > select ARCH_HAS_DEBUG_WX
> > + select ARCH_HAS_DEVMEM_IS_ALLOWED
> > select ARCH_HAS_GCOV_PROFILE_ALL
> > select ARCH_HAS_GIGANTIC_PAGE
> > select ARCH_HAS_MMIOWB
> > diff --git a/arch/riscv/include/asm/io.h b/arch/riscv/include/asm/io.h
> > index 3835c3295dc5..04ac65ab93ce 100644
> > --- a/arch/riscv/include/asm/io.h
> > +++ b/arch/riscv/include/asm/io.h
> > @@ -147,4 +147,6 @@ __io_writes_outs(outs, u64, q, __io_pbr(), __io_paw())
> >
> > #include <asm-generic/io.h>
> >
> > +extern int devmem_is_allowed(unsigned long pfn);
> > +
> > #endif /* _ASM_RISCV_IO_H */
> > diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> > index bbe816e03b2f..5e7e61519acc 100644
> > --- a/arch/riscv/mm/init.c
> > +++ b/arch/riscv/mm/init.c
> > @@ -517,6 +517,25 @@ void mark_rodata_ro(void)
> > }
> > #endif
> >
> > +#ifdef CONFIG_STRICT_DEVMEM
> > +#include <linux/ioport.h>
> > +/*
> > + * devmem_is_allowed() checks to see if /dev/mem access to a certain address
> > + * is valid. The argument is a physical page number.
> > + *
> > + * Disallow 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
> > +
> > void __init resource_init(void)
> > {
> > struct memblock_region *region;
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply
* [PATCH] riscv: kasan: use local_tlb_flush_all() to avoid uninitialized __sbi_rfence
From: Vincent Chen @ 2020-07-10 2:40 UTC (permalink / raw)
To: aryabinin, glider, dvyukov, paul.walmsley, palmer
Cc: Vincent Chen, linux-riscv, nickhu
It fails to boot the v5.8-rc4 kernel with CONFIG_KASAN because kasan_init
and kasan_early_init use uninitialized __sbi_rfence as executing the
tlb_flush_all(). Actually, at this moment, only the CPU which is
responsible for the system initialization enables the MMU. Other CPUs are
parking at the .Lsecondary_start. Hence the tlb_flush_all() is able to be
replaced by local_tlb_flush_all() to avoid using uninitialized
__sbi_rfence.
Signed-off-by: Vincent Chen <vincent.chen@sifive.com>
---
arch/riscv/mm/kasan_init.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/riscv/mm/kasan_init.c b/arch/riscv/mm/kasan_init.c
index 4a8b61806633..87b4ab3d3c77 100644
--- a/arch/riscv/mm/kasan_init.c
+++ b/arch/riscv/mm/kasan_init.c
@@ -44,7 +44,7 @@ asmlinkage void __init kasan_early_init(void)
(__pa(((uintptr_t) kasan_early_shadow_pmd))),
__pgprot(_PAGE_TABLE)));
- flush_tlb_all();
+ local_flush_tlb_all();
}
static void __init populate(void *start, void *end)
@@ -79,7 +79,7 @@ static void __init populate(void *start, void *end)
pfn_pgd(PFN_DOWN(__pa(&pmd[offset])),
__pgprot(_PAGE_TABLE)));
- flush_tlb_all();
+ local_flush_tlb_all();
memset(start, 0, end - start);
}
--
2.7.4
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related
* Re: [PATCH 1/2] riscv: Register System RAM as iomem resources
From: Nick Kossifidis @ 2020-07-10 2:05 UTC (permalink / raw)
To: Palmer Dabbelt; +Cc: linux-riscv, linux-kernel, zong.li, Paul Walmsley
In-Reply-To: <mhng-cd7e19bb-859a-45a4-90e8-7851c4fb3083@palmerdabbelt-glaptop1>
Στις 2020-07-09 21:27, Palmer Dabbelt έγραψε:
> On Tue, 16 Jun 2020 00:45:46 PDT (-0700), zong.li@sifive.com wrote:
>> Add System RAM to /proc/iomem, various tools expect it such as kdump.
>> It is also needed for page_is_ram API which checks the specified
>> address
>> whether registered as System RAM in iomem_resource list.
>>
>> Signed-off-by: Zong Li <zong.li@sifive.com>
>> ---
>> arch/riscv/mm/init.c | 22 ++++++++++++++++++++++
>> 1 file changed, 22 insertions(+)
>>
>> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
>> index f4adb3684f3d..bbe816e03b2f 100644
>> --- a/arch/riscv/mm/init.c
>> +++ b/arch/riscv/mm/init.c
>> @@ -517,6 +517,27 @@ void mark_rodata_ro(void)
>> }
>> #endif
>>
>> +void __init resource_init(void)
>> +{
>> + struct memblock_region *region;
>> +
>> + for_each_memblock(memory, region) {
>> + struct resource *res;
>> +
>> + res = memblock_alloc(sizeof(struct resource), SMP_CACHE_BYTES);
>> + if (!res)
>> + panic("%s: Failed to allocate %zu bytes\n", __func__,
>> + sizeof(struct resource));
>> +
>> + res->name = "System RAM";
>> + res->start =
>> __pfn_to_phys(memblock_region_memory_base_pfn(region));
>> + res->end = __pfn_to_phys(memblock_region_memory_end_pfn(region)) -
>> 1;
>> + res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
>
> Looks like everyone else is checking MEMBLOCK_NOMAP before registering
> memory
> regions. I've added that and put this on for-next. Thanks!
>
> commit 11dc632bf515874c84887727614e8044452f1f28
> gpg: Signature made Thu 09 Jul 2020 11:24:08 AM PDT
> gpg: using RSA key
> 2B3C3747446843B24A943A7A2E1319F35FBB1889
> gpg: issuer "palmer@dabbelt.com"
> gpg: Good signature from "Palmer Dabbelt <palmer@dabbelt.com>"
> [ultimate]
> gpg: aka "Palmer Dabbelt <palmerdabbelt@google.com>"
> [ultimate]
> Author: Zong Li <zong.li@sifive.com>
> Date: Tue Jun 16 15:45:46 2020 +0800
>
> riscv: Register System RAM as iomem resources
> Add System RAM to /proc/iomem, various tools expect it such as
> kdump.
> It is also needed for page_is_ram API which checks the specified
> address
> whether registered as System RAM in iomem_resource list.
> Signed-off-by: Zong Li <zong.li@sifive.com>
> [Palmer: check MEMBLOCK_NOMAP]
> Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
>
> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> index f4adb3684f3d..8b78fd23713e 100644
> --- a/arch/riscv/mm/init.c
> +++ b/arch/riscv/mm/init.c
> @@ -517,6 +517,32 @@ void mark_rodata_ro(void)
> }
> #endif
>
> +void __init resource_init(void)
> +{
> + struct memblock_region *region;
> +
> + for_each_memblock(memory, region) {
> + struct resource *res;
> +
> + res = memblock_alloc(sizeof(struct resource), SMP_CACHE_BYTES);
> + if (!res)
> + panic("%s: Failed to allocate %zu bytes\n", __func__,
> + sizeof(struct resource));
> +
> + if (memblock_is_nomap(region) {
> + res->name = "reserved";
> + res->flags = IORESOURCE_MEM;
> + } else {
> + res->name = "System RAM";
> + res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
> + }
> + res->start = __pfn_to_phys(memblock_region_memory_base_pfn(region));
> + res->end = __pfn_to_phys(memblock_region_memory_end_pfn(region)) -
> 1;
> +
> + request_resource(&iomem_resource, res);
> + }
> +}
> +
> void __init paging_init(void)
> {
> setup_vm_final();
> @@ -524,6 +550,7 @@ void __init paging_init(void)
> sparse_init();
> setup_zero_page();
> zone_sizes_init();
> + resource_init();
> }
>
> #ifdef CONFIG_SPARSEMEM_VMEMMAP
>
>
>> +
>> + request_resource(&iomem_resource, res);
>> + }
>> +}
>> +
>> void __init paging_init(void)
>> {
>> setup_vm_final();
>> @@ -524,6 +545,7 @@ void __init paging_init(void)
>> sparse_init();
>> setup_zero_page();
>> zone_sizes_init();
>> + resource_init();
>> }
>>
>> #ifdef CONFIG_SPARSEMEM_VMEMMAP
>
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv
Zong Li sent a newer version of this series without this patch, since
I'm handling this on the kexec/kdump series as well where other sections
needed for kdump are also registered.
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply
* Re: [PATCH V2 0/3] riscv: Enable LOCKDEP
From: Guo Ren @ 2020-07-09 23:15 UTC (permalink / raw)
To: Palmer Dabbelt
Cc: Tycho Andersen, Albert Ou, Nick Hu, Anup Patel,
Linux Kernel Mailing List, linux-csky, Guo Ren, Zong Li,
Paul Walmsley, Greentime Hu, Thomas Gleixner, linux-riscv
In-Reply-To: <mhng-af022fcc-7dce-4d1b-9204-d31241538412@palmerdabbelt-glaptop1>
Thank you, Palmer
On Fri, Jul 10, 2020 at 6:06 AM Palmer Dabbelt <palmerdabbelt@google.com> wrote:
>
> On Sat, 27 Jun 2020 06:57:05 PDT (-0700), guoren@kernel.org wrote:
> > From: Guo Ren <guoren@linux.alibaba.com>
> >
> > Lockdep is needed by proving the spinlocks and rwlocks. To support it,
> > we need to add TRACE_IRQFLAGS codes in kernel/entry.S. These patches
> > follow Documentation/irqflags-tracing.txt.
> >
> > Fixup 2 bugs that block the lockdep implementation.
> >
> > ---
> > Changes in v2
> > - Remove sX regs recovery codes which are unnecessary, because
> > callee will handle them. Thx Greentime :)
> >
> > - Move "restore a0 - a7" to handle_syscall, but if _TIF_SYSCALL_WORK
> > is set, "restore a1 - a7" is still duplicated. I prefer a C wrapper
> > for syscall.
> >
> > Guo Ren (2):
> > riscv: Fixup static_obj() fail
> > riscv: Enable LOCKDEP_SUPPORT & fixup TRACE_IRQFLAGS_SUPPORT
> >
> > Zong Li (1):
> > riscv: Fixup lockdep_assert_held with wrong param cpu_running
> >
> > arch/riscv/Kconfig | 3 +++
> > arch/riscv/kernel/entry.S | 33 ++++++++++++++++++++++++++++++++-
> > arch/riscv/kernel/smpboot.c | 1 -
> > arch/riscv/kernel/vmlinux.lds.S | 2 +-
> > 4 files changed, 36 insertions(+), 3 deletions(-)
>
> These are on for-next. As far as I can tell lockdep is working, but I'm just
> doing some simple boot tests.
>
> Thanks!
--
Best Regards
Guo Ren
ML: https://lore.kernel.org/linux-csky/
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply
* Re: [PATCH v2 1/2] riscv: Add STACKPROTECTOR supported
From: Guo Ren @ 2020-07-09 23:14 UTC (permalink / raw)
To: kernel test robot
Cc: Patrick Stählin, kbuild-all, Anup Patel, Palmer Dabbelt,
Linux Kernel Mailing List, Atish Patra, Zong Li, Paul Walmsley,
Greentime Hu, linux-riscv, Björn Töpel
In-Reply-To: <202007100213.k2Bq4lQ3%lkp@intel.com>
Yes, I didn't test riscv32-gcc and it needs to be 16UL.
On Fri, Jul 10, 2020 at 2:37 AM kernel test robot <lkp@intel.com> wrote:
>
> Hi,
>
> I love your patch! Perhaps something to improve:
>
> [auto build test WARNING on linus/master]
> [also build test WARNING on v5.8-rc4 next-20200709]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use as documented in
> https://git-scm.com/docs/git-format-patch]
>
> url: https://github.com/0day-ci/linux/commits/guoren-kernel-org/riscv-Add-STACKPROTECTOR-supported/20200709-153112
> base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 0bddd227f3dc55975e2b8dfa7fc6f959b062a2c7
> config: riscv-randconfig-s031-20200709 (attached as .config)
> compiler: riscv32-linux-gcc (GCC) 9.3.0
> reproduce:
> wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> chmod +x ~/bin/make.cross
> # apt-get install sparse
> # sparse version: v0.6.2-37-gc9676a3b-dirty
> # save the attached .config to linux build tree
> COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=riscv
>
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
>
> All warnings (new ones prefixed by >>):
>
> In file included from include/linux/stackprotector.h:10,
> from arch/riscv/kernel/process.c:28:
> arch/riscv/include/asm/stackprotector.h: In function 'boot_init_stack_canary':
> >> arch/riscv/include/asm/stackprotector.h:26:23: warning: left shift count >= width of type [-Wshift-count-overflow]
> 26 | canary += tsc + (tsc << 32UL);
> | ^~
> arch/riscv/kernel/process.c: At top level:
> arch/riscv/kernel/process.c:42:6: warning: no previous prototype for 'show_regs' [-Wmissing-prototypes]
> 42 | void show_regs(struct pt_regs *regs)
> | ^~~~~~~~~
> arch/riscv/kernel/process.c:103:5: warning: no previous prototype for 'arch_dup_task_struct' [-Wmissing-prototypes]
> 103 | int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
> | ^~~~~~~~~~~~~~~~~~~~
>
> vim +26 arch/riscv/include/asm/stackprotector.h
>
> 11
> 12 /*
> 13 * Initialize the stackprotector canary value.
> 14 *
> 15 * NOTE: this must only be called from functions that never return,
> 16 * and it must always be inlined.
> 17 */
> 18 static __always_inline void boot_init_stack_canary(void)
> 19 {
> 20 unsigned long canary;
> 21 unsigned long tsc;
> 22
> 23 /* Try to get a semi random initial value. */
> 24 get_random_bytes(&canary, sizeof(canary));
> 25 tsc = get_cycles();
> > 26 canary += tsc + (tsc << 32UL);
>
> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
--
Best Regards
Guo Ren
ML: https://lore.kernel.org/linux-csky/
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply
* Re: [PATCH V2 0/3] riscv: Enable LOCKDEP
From: Palmer Dabbelt @ 2020-07-09 22:06 UTC (permalink / raw)
To: guoren
Cc: tycho, aou, nickhu, anup, linux-kernel, linux-csky, guoren,
zong.li, Paul Walmsley, greentime.hu, tglx, linux-riscv
In-Reply-To: <1593266228-61125-1-git-send-email-guoren@kernel.org>
On Sat, 27 Jun 2020 06:57:05 PDT (-0700), guoren@kernel.org wrote:
> From: Guo Ren <guoren@linux.alibaba.com>
>
> Lockdep is needed by proving the spinlocks and rwlocks. To support it,
> we need to add TRACE_IRQFLAGS codes in kernel/entry.S. These patches
> follow Documentation/irqflags-tracing.txt.
>
> Fixup 2 bugs that block the lockdep implementation.
>
> ---
> Changes in v2
> - Remove sX regs recovery codes which are unnecessary, because
> callee will handle them. Thx Greentime :)
>
> - Move "restore a0 - a7" to handle_syscall, but if _TIF_SYSCALL_WORK
> is set, "restore a1 - a7" is still duplicated. I prefer a C wrapper
> for syscall.
>
> Guo Ren (2):
> riscv: Fixup static_obj() fail
> riscv: Enable LOCKDEP_SUPPORT & fixup TRACE_IRQFLAGS_SUPPORT
>
> Zong Li (1):
> riscv: Fixup lockdep_assert_held with wrong param cpu_running
>
> arch/riscv/Kconfig | 3 +++
> arch/riscv/kernel/entry.S | 33 ++++++++++++++++++++++++++++++++-
> arch/riscv/kernel/smpboot.c | 1 -
> arch/riscv/kernel/vmlinux.lds.S | 2 +-
> 4 files changed, 36 insertions(+), 3 deletions(-)
These are on for-next. As far as I can tell lockdep is working, but I'm just
doing some simple boot tests.
Thanks!
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply
* [PATCH v2 5/5] unicore32: Use the generic devmem_is_allowed()
From: Palmer Dabbelt @ 2020-07-09 21:19 UTC (permalink / raw)
To: zong.li, linux-riscv, rppt
Cc: mark.rutland, steve, davidgow, catalin.marinas, linus.walleij,
Palmer Dabbelt, brendanhiggins, elver, glider, mchehab+samsung,
linux-riscv, alex.shi, will, dan.j.williams, linux-arch, uwe,
alex, takahiro.akashi, paulmck, masahiroy, linux, krzk, ardb,
bgolaszewski, clabbe, james.morse, kernel-team, pmladek, zaslonko,
aou, keescook, Arnd Bergmann, rostedt, broonie, matti.vaittinen,
gregory.0xf0, Paul Walmsley, tglx, andriy.shevchenko, gxt,
linux-arm-kernel, Greg KH, rdunlap, Nick Desaulniers,
linux-kernel, changbin.du, mcgrof, Palmer Dabbelt, mhiramat, akpm,
davem
In-Reply-To: <20200709211925.1926557-1-palmer@dabbelt.com>
From: Palmer Dabbelt <palmerdabbelt@google.com>
Aside from being inlineable, this is exactly the same as the arm64
version, which I recently copied into lib/ for use by the RISC-V port.
[I haven't even build tested this. The lib/ patch is on riscv/for-next,
which I'm targeting for 5.9, so this won't work alone. See the cover
letter for more details.]
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
---
arch/unicore32/Kconfig | 2 +-
arch/unicore32/include/asm/io.h | 23 -----------------------
2 files changed, 1 insertion(+), 24 deletions(-)
diff --git a/arch/unicore32/Kconfig b/arch/unicore32/Kconfig
index 11ba1839d198..7610571044f4 100644
--- a/arch/unicore32/Kconfig
+++ b/arch/unicore32/Kconfig
@@ -2,7 +2,6 @@
config UNICORE32
def_bool y
select ARCH_32BIT_OFF_T
- select ARCH_HAS_DEVMEM_IS_ALLOWED
select ARCH_HAS_KEEPINITRD
select ARCH_MIGHT_HAVE_PC_PARPORT
select ARCH_MIGHT_HAVE_PC_SERIO
@@ -12,6 +11,7 @@ config UNICORE32
select HAVE_KERNEL_LZO
select HAVE_KERNEL_LZMA
select HAVE_PCI
+ select GENERIC_LIB_DEVMEM_IS_ALLOWED
select VIRT_TO_BUS
select ARCH_HAVE_CUSTOM_GPIO_H
select GENERIC_FIND_FIRST_BIT
diff --git a/arch/unicore32/include/asm/io.h b/arch/unicore32/include/asm/io.h
index bd4e7c332f85..4560d2531655 100644
--- a/arch/unicore32/include/asm/io.h
+++ b/arch/unicore32/include/asm/io.h
@@ -42,28 +42,5 @@ extern void __uc32_iounmap(volatile void __iomem *addr);
#define PIO_MASK (unsigned int)(IO_SPACE_LIMIT)
#define PIO_RESERVED (PIO_OFFSET + PIO_MASK + 1)
-#ifdef CONFIG_STRICT_DEVMEM
-
-#include <linux/ioport.h>
-#include <linux/mm.h>
-
-/*
- * 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 inline 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 */
-
#endif /* __KERNEL__ */
#endif /* __UNICORE_IO_H__ */
--
2.27.0.383.g050319c2ae-goog
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related
* [PATCH v2 3/5] arm: Use the generic devmem_is_allowed()
From: Palmer Dabbelt @ 2020-07-09 21:19 UTC (permalink / raw)
To: zong.li, linux-riscv, rppt
Cc: mark.rutland, steve, davidgow, catalin.marinas, linus.walleij,
Palmer Dabbelt, brendanhiggins, elver, glider, mchehab+samsung,
linux-riscv, alex.shi, will, dan.j.williams, linux-arch, uwe,
alex, takahiro.akashi, paulmck, masahiroy, linux, krzk, ardb,
bgolaszewski, clabbe, james.morse, kernel-team, pmladek, zaslonko,
aou, keescook, Arnd Bergmann, rostedt, broonie, matti.vaittinen,
gregory.0xf0, Paul Walmsley, tglx, andriy.shevchenko, gxt,
linux-arm-kernel, Greg KH, rdunlap, Nick Desaulniers,
linux-kernel, changbin.du, mcgrof, Palmer Dabbelt, mhiramat, akpm,
davem
In-Reply-To: <20200709211925.1926557-1-palmer@dabbelt.com>
From: Palmer Dabbelt <palmerdabbelt@google.com>
This is exactly the same as the arm64 version, which I recently copied
into lib/ for use by the RISC-V port.
[I haven't even build tested this. The lib/ patch is on riscv/for-next,
which I'm targeting for 5.9, so this won't work alone. See the cover
letter for more details.]
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
---
arch/arm/Kconfig | 2 +-
arch/arm/include/asm/io.h | 1 -
arch/arm/mm/mmap.c | 22 ----------------------
3 files changed, 1 insertion(+), 24 deletions(-)
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 2ac74904a3ce..da0f88f6c196 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -5,7 +5,6 @@ config ARM
select ARCH_32BIT_OFF_T
select ARCH_HAS_BINFMT_FLAT
select ARCH_HAS_DEBUG_VIRTUAL if MMU
- select ARCH_HAS_DEVMEM_IS_ALLOWED
select ARCH_HAS_DMA_WRITE_COMBINE if !ARM_DMA_MEM_BUFFERABLE
select ARCH_HAS_ELF_RANDOMIZE
select ARCH_HAS_FORTIFY_SOURCE
@@ -54,6 +53,7 @@ config ARM
select GENERIC_IRQ_PROBE
select GENERIC_IRQ_SHOW
select GENERIC_IRQ_SHOW_LEVEL
+ select GENERIC_LIB_DEVMEM_IS_ALLOWED
select GENERIC_PCI_IOMAP
select GENERIC_SCHED_CLOCK
select GENERIC_SMP_IDLE_THREAD
diff --git a/arch/arm/include/asm/io.h b/arch/arm/include/asm/io.h
index ab2b654084fa..fc748122f1e0 100644
--- a/arch/arm/include/asm/io.h
+++ b/arch/arm/include/asm/io.h
@@ -441,7 +441,6 @@ extern void pci_iounmap(struct pci_dev *dev, void __iomem *addr);
#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
extern int valid_phys_addr_range(phys_addr_t addr, size_t size);
extern int valid_mmap_phys_addr_range(unsigned long pfn, size_t size);
-extern int devmem_is_allowed(unsigned long pfn);
#endif
/*
diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
index b8d912ac9e61..a0f8a0ca0788 100644
--- a/arch/arm/mm/mmap.c
+++ b/arch/arm/mm/mmap.c
@@ -165,25 +165,3 @@ int valid_mmap_phys_addr_range(unsigned long pfn, size_t size)
{
return (pfn + (size >> PAGE_SHIFT)) <= (1 + (PHYS_MASK >> PAGE_SHIFT));
}
-
-#ifdef CONFIG_STRICT_DEVMEM
-
-#include <linux/ioport.h>
-
-/*
- * 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
--
2.27.0.383.g050319c2ae-goog
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related
* [PATCH v2 4/5] arm64: Use the generic devmem_is_allowed()
From: Palmer Dabbelt @ 2020-07-09 21:19 UTC (permalink / raw)
To: zong.li, linux-riscv, rppt
Cc: mark.rutland, steve, davidgow, catalin.marinas, linus.walleij,
Palmer Dabbelt, brendanhiggins, elver, glider, mchehab+samsung,
linux-riscv, alex.shi, will, dan.j.williams, linux-arch, uwe,
alex, takahiro.akashi, paulmck, masahiroy, linux, krzk, ardb,
bgolaszewski, clabbe, james.morse, kernel-team, pmladek, zaslonko,
aou, keescook, Arnd Bergmann, rostedt, broonie, matti.vaittinen,
gregory.0xf0, Paul Walmsley, tglx, andriy.shevchenko, gxt,
linux-arm-kernel, Greg KH, rdunlap, Nick Desaulniers,
linux-kernel, changbin.du, mcgrof, Palmer Dabbelt, mhiramat, akpm,
davem
In-Reply-To: <20200709211925.1926557-1-palmer@dabbelt.com>
From: Palmer Dabbelt <palmerdabbelt@google.com>
I recently copied this into lib/ for use by the RISC-V port.
[I haven't even build tested this. The lib/ patch is on riscv/for-next,
which I'm targeting for 5.9, so this won't work alone. See the cover
letter for more details.]
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
---
arch/arm64/Kconfig | 2 +-
arch/arm64/include/asm/io.h | 2 --
arch/arm64/mm/mmap.c | 21 ---------------------
3 files changed, 1 insertion(+), 24 deletions(-)
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 66dc41fd49f2..0682672cb244 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -13,7 +13,6 @@ config ARM64
select ARCH_BINFMT_ELF_STATE
select ARCH_HAS_DEBUG_VIRTUAL
select ARCH_HAS_DEBUG_VM_PGTABLE
- select ARCH_HAS_DEVMEM_IS_ALLOWED
select ARCH_HAS_DMA_PREP_COHERENT
select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI
select ARCH_HAS_FAST_MULTIPLIER
@@ -110,6 +109,7 @@ config ARM64
select GENERIC_IRQ_PROBE
select GENERIC_IRQ_SHOW
select GENERIC_IRQ_SHOW_LEVEL
+ select GENERIC_LIB_DEVMEM_IS_ALLOWED
select GENERIC_PCI_IOMAP
select GENERIC_PTDUMP
select GENERIC_SCHED_CLOCK
diff --git a/arch/arm64/include/asm/io.h b/arch/arm64/include/asm/io.h
index ff50dd731852..c53eba1a7fd2 100644
--- a/arch/arm64/include/asm/io.h
+++ b/arch/arm64/include/asm/io.h
@@ -200,6 +200,4 @@ extern void __iomem *ioremap_cache(phys_addr_t phys_addr, size_t size);
extern int valid_phys_addr_range(phys_addr_t addr, size_t size);
extern int valid_mmap_phys_addr_range(unsigned long pfn, size_t size);
-extern int devmem_is_allowed(unsigned long pfn);
-
#endif /* __ASM_IO_H */
diff --git a/arch/arm64/mm/mmap.c b/arch/arm64/mm/mmap.c
index 3028bacbc4e9..07937b49cb88 100644
--- a/arch/arm64/mm/mmap.c
+++ b/arch/arm64/mm/mmap.c
@@ -47,24 +47,3 @@ int valid_mmap_phys_addr_range(unsigned long pfn, size_t size)
{
return !(((pfn << PAGE_SHIFT) + size) & ~PHYS_MASK);
}
-
-#ifdef CONFIG_STRICT_DEVMEM
-
-#include <linux/ioport.h>
-
-/*
- * 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
--
2.27.0.383.g050319c2ae-goog
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related
* [PATCH v2 2/5] RISC-V: Use the new generic devmem_is_allowed()
From: Palmer Dabbelt @ 2020-07-09 21:19 UTC (permalink / raw)
To: zong.li, linux-riscv, rppt
Cc: mark.rutland, steve, davidgow, catalin.marinas, linus.walleij,
Palmer Dabbelt, brendanhiggins, elver, glider, mchehab+samsung,
linux-riscv, alex.shi, will, dan.j.williams, linux-arch, uwe,
alex, takahiro.akashi, paulmck, masahiroy, linux, krzk, ardb,
bgolaszewski, clabbe, james.morse, kernel-team, pmladek, zaslonko,
aou, keescook, Arnd Bergmann, rostedt, broonie, matti.vaittinen,
gregory.0xf0, Paul Walmsley, tglx, andriy.shevchenko, gxt,
linux-arm-kernel, Greg KH, rdunlap, Nick Desaulniers,
linux-kernel, changbin.du, mcgrof, Palmer Dabbelt, mhiramat, akpm,
davem
In-Reply-To: <20200709211925.1926557-1-palmer@dabbelt.com>
From: Palmer Dabbelt <palmerdabbelt@google.com>
This allows us to enable STRICT_DEVMEM.
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
---
arch/riscv/Kconfig | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 089293e4ad46..8ff368a65a07 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -37,6 +37,7 @@ config RISCV
select GENERIC_IOREMAP
select GENERIC_IRQ_MULTI_HANDLER
select GENERIC_IRQ_SHOW
+ select GENERIC_LIB_DEVMEM_IS_ALLOWED
select GENERIC_PCI_IOMAP
select GENERIC_PTDUMP if MMU
select GENERIC_SCHED_CLOCK
--
2.27.0.383.g050319c2ae-goog
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related
* [PATCH v2 1/5] lib: Add a generic version of devmem_is_allowed()
From: Palmer Dabbelt @ 2020-07-09 21:19 UTC (permalink / raw)
To: zong.li, linux-riscv, rppt
Cc: mark.rutland, steve, davidgow, catalin.marinas, linus.walleij,
Palmer Dabbelt, brendanhiggins, elver, glider, mchehab+samsung,
linux-riscv, alex.shi, will, dan.j.williams, linux-arch, uwe,
alex, takahiro.akashi, paulmck, masahiroy, linux, krzk, ardb,
bgolaszewski, clabbe, james.morse, kernel-team, pmladek, zaslonko,
aou, keescook, Arnd Bergmann, rostedt, broonie, matti.vaittinen,
gregory.0xf0, Paul Walmsley, tglx, andriy.shevchenko, gxt,
linux-arm-kernel, Greg KH, rdunlap, Nick Desaulniers,
linux-kernel, changbin.du, mcgrof, Palmer Dabbelt, mhiramat, akpm,
davem
In-Reply-To: <20200709211925.1926557-1-palmer@dabbelt.com>
From: Palmer Dabbelt <palmerdabbelt@google.com>
As part of adding support for STRICT_DEVMEM to the RISC-V port, Zong
provided a devmem_is_allowed() implementation that's exactly the same as
all the others I checked. Instead I'm adding a generic version, which
will soon be used.
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
---
include/asm-generic/io.h | 4 ++++
lib/Kconfig | 3 +++
lib/Kconfig.debug | 2 +-
lib/Makefile | 2 ++
lib/devmem_is_allowed.c | 27 +++++++++++++++++++++++++++
5 files changed, 37 insertions(+), 1 deletion(-)
create mode 100644 lib/devmem_is_allowed.c
diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
index 8b1e020e9a03..69e3db65fba0 100644
--- a/include/asm-generic/io.h
+++ b/include/asm-generic/io.h
@@ -1122,6 +1122,10 @@ static inline void memcpy_toio(volatile void __iomem *addr, const void *buffer,
}
#endif
+#ifndef CONFIG_GENERIC_DEVMEM_IS_ALLOWED
+extern int devmem_is_allowed(unsigned long pfn);
+#endif
+
#endif /* __KERNEL__ */
#endif /* __ASM_GENERIC_IO_H */
diff --git a/lib/Kconfig b/lib/Kconfig
index df3f3da95990..610c16ecbb7c 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -676,3 +676,6 @@ config GENERIC_LIB_CMPDI2
config GENERIC_LIB_UCMPDI2
bool
+
+config GENERIC_LIB_DEVMEM_IS_ALLOWED
+ bool
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 9ad9210d70a1..e095bd631ba1 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1577,7 +1577,7 @@ config ARCH_HAS_DEVMEM_IS_ALLOWED
config STRICT_DEVMEM
bool "Filter access to /dev/mem"
depends on MMU && DEVMEM
- depends on ARCH_HAS_DEVMEM_IS_ALLOWED
+ depends on ARCH_HAS_DEVMEM_IS_ALLOWED || GENERIC_LIB_DEVMEM_IS_ALLOWED
default y if PPC || X86 || ARM64
help
If this option is disabled, you allow userspace (root) access to all
diff --git a/lib/Makefile b/lib/Makefile
index b1c42c10073b..554ef14f9be5 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -318,3 +318,5 @@ obj-$(CONFIG_OBJAGG) += objagg.o
# KUnit tests
obj-$(CONFIG_LIST_KUNIT_TEST) += list-test.o
obj-$(CONFIG_LINEAR_RANGES_TEST) += test_linear_ranges.o
+
+obj-$(CONFIG_GENERIC_LIB_DEVMEM_IS_ALLOWED) += devmem_is_allowed.o
diff --git a/lib/devmem_is_allowed.c b/lib/devmem_is_allowed.c
new file mode 100644
index 000000000000..c0d67c541849
--- /dev/null
+++ b/lib/devmem_is_allowed.c
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * A generic version of devmem_is_allowed.
+ *
+ * Based on arch/arm64/mm/mmap.c
+ *
+ * Copyright (C) 2020 Google, Inc.
+ * Copyright (C) 2012 ARM Ltd.
+ */
+
+#include <linux/mm.h>
+#include <linux/ioport.h>
+
+/*
+ * 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;
+}
--
2.27.0.383.g050319c2ae-goog
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related
* Add and use a generic version of devmem_is_allowed()
From: Palmer Dabbelt @ 2020-07-09 21:19 UTC (permalink / raw)
To: zong.li, linux-riscv, rppt
Cc: mark.rutland, steve, davidgow, catalin.marinas, linus.walleij,
brendanhiggins, elver, glider, mchehab+samsung, linux-riscv,
alex.shi, will, dan.j.williams, linux-arch, uwe, alex,
takahiro.akashi, paulmck, masahiroy, linux, krzk, ardb,
bgolaszewski, clabbe, james.morse, kernel-team, pmladek, zaslonko,
aou, keescook, Arnd Bergmann, rostedt, broonie, matti.vaittinen,
gregory.0xf0, Paul Walmsley, tglx, andriy.shevchenko, gxt,
linux-arm-kernel, Greg KH, rdunlap, Nick Desaulniers,
linux-kernel, changbin.du, mcgrof, Palmer Dabbelt, mhiramat, akpm,
davem
As part of adding STRICT_DEVMEM support to the RISC-V port, Zong provided an
implementation of devmem_is_allowed() that's exactly the same as the version in
a handful of other ports. Rather than duplicate code, I've put a generic
version of this in lib/ and used it for the RISC-V port.
I've put those first two patches on riscv/for-next, which I'm targeting for 5.9
(though this is the first version, so they're unreviewed). The other three
obviously depend on the first one going on, but I'm not putting them in the
RISC-V tree as I don't want to step on anyone's toes. If you want me to take
yours along with the others then please say something, as otherwise I'll
probably forget.
I've put the whole thing at
ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/palmer/linux.git -b
generic-devmem .
Changes since v1 [<20200709200552.1910298-1-palmer@dabbelt.com]:
* Don't have GENERIC_LIB_DEVMEM_IS_ALLOWED select ARCH_HAS_DEVMEM_IS_ALLOWED,
instead just adapt the users.
* Remove ARCH_HAS_DEVMEM_IS_ALLOWED from the arch Kconfigs, as I forgot to do
so the first time.
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply
* Re: [PATCH 2/2] riscv: Support CONFIG_STRICT_DEVMEM
From: Palmer Dabbelt @ 2020-07-09 20:08 UTC (permalink / raw)
To: zong.li; +Cc: linux-riscv, linux-kernel, zong.li, Paul Walmsley
In-Reply-To: <7faa60aa4a606b5c5c1ae374d82a7eee6c764b38.1592292685.git.zong.li@sifive.com>
On Tue, 16 Jun 2020 00:45:47 PDT (-0700), zong.li@sifive.com wrote:
> Implement the 'devmem_is_allowed()' interface for RISC-V, like some of
> other architectures have done. It will be called from range_is_allowed()
> when userpsace attempts to access /dev/mem.
In fact, it's exactly the same (down to a few words of the comment) to the
others that I checked. I'm going to put a generic version in lib/ instead,
I've sent out the patches.
> Access to exclusive IOMEM and kernel RAM is denied unless
> CONFIG_STRICT_DEVMEM is set to 'n'.
>
> Test it by devmem, the result as follows:
>
> - CONFIG_STRICT_DEVMEM=y
> $ devmem 0x10010000
> 0x00000000
> $ devmem 0x80200000
> 0x0000106F
>
> - CONFIG_STRICT_DEVMEM is not set
> $ devmem 0x10010000
> devmem: mmap: Operation not permitted
> $ devmem 0x80200000
> devmem: mmap: Operation not permitted
>
> Signed-off-by: Zong Li <zong.li@sifive.com>
> ---
> arch/riscv/Kconfig | 1 +
> arch/riscv/include/asm/io.h | 2 ++
> arch/riscv/mm/init.c | 19 +++++++++++++++++++
> 3 files changed, 22 insertions(+)
>
> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> index 128192e14ff2..ffd7841ede4c 100644
> --- a/arch/riscv/Kconfig
> +++ b/arch/riscv/Kconfig
> @@ -16,6 +16,7 @@ config RISCV
> select ARCH_HAS_BINFMT_FLAT
> select ARCH_HAS_DEBUG_VIRTUAL if MMU
> select ARCH_HAS_DEBUG_WX
> + select ARCH_HAS_DEVMEM_IS_ALLOWED
> select ARCH_HAS_GCOV_PROFILE_ALL
> select ARCH_HAS_GIGANTIC_PAGE
> select ARCH_HAS_MMIOWB
> diff --git a/arch/riscv/include/asm/io.h b/arch/riscv/include/asm/io.h
> index 3835c3295dc5..04ac65ab93ce 100644
> --- a/arch/riscv/include/asm/io.h
> +++ b/arch/riscv/include/asm/io.h
> @@ -147,4 +147,6 @@ __io_writes_outs(outs, u64, q, __io_pbr(), __io_paw())
>
> #include <asm-generic/io.h>
>
> +extern int devmem_is_allowed(unsigned long pfn);
> +
> #endif /* _ASM_RISCV_IO_H */
> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> index bbe816e03b2f..5e7e61519acc 100644
> --- a/arch/riscv/mm/init.c
> +++ b/arch/riscv/mm/init.c
> @@ -517,6 +517,25 @@ void mark_rodata_ro(void)
> }
> #endif
>
> +#ifdef CONFIG_STRICT_DEVMEM
> +#include <linux/ioport.h>
> +/*
> + * devmem_is_allowed() checks to see if /dev/mem access to a certain address
> + * is valid. The argument is a physical page number.
> + *
> + * Disallow 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
> +
> void __init resource_init(void)
> {
> struct memblock_region *region;
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply
* Re: [PATCH 1/5] lib: Add a generic version of devmem_is_allowed()
From: Palmer Dabbelt @ 2020-07-09 20:54 UTC (permalink / raw)
To: rppt
Cc: mark.rutland, steve, davidgow, catalin.marinas, linus.walleij,
elver, glider, willy, zong.li, mchehab+samsung, linux-riscv,
alex.shi, will, dan.j.williams, linux-arch, uwe, alex,
takahiro.akashi, paulmck, masahiroy, linux, krzk, ardb,
bgolaszewski, kernel-team, pmladek, zaslonko, aou, keescook,
Arnd Bergmann, rostedt, broonie, matti.vaittinen, gregory.0xf0,
Paul Walmsley, tglx, andriy.shevchenko, gxt, linux-arm-kernel,
rdunlap, Nick Desaulniers, linux-kernel, mcgrof, james.morse,
mhiramat, akpm, davem
In-Reply-To: <20200709204921.GJ781326@linux.ibm.com>
On Thu, 09 Jul 2020 13:49:21 PDT (-0700), rppt@linux.ibm.com wrote:
> Hi Palmer,
>
> On Thu, Jul 09, 2020 at 01:05:48PM -0700, Palmer Dabbelt wrote:
>> From: Palmer Dabbelt <palmerdabbelt@google.com>
>>
>> As part of adding support for STRICT_DEVMEM to the RISC-V port, Zong
>> provided a devmem_is_allowed() implementation that's exactly the same as
>> all the others I checked. Instead I'm adding a generic version, which
>> will soon be used.
>>
>> Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
>> ---
>> include/asm-generic/io.h | 4 ++++
>> lib/Kconfig | 4 ++++
>> lib/Makefile | 2 ++
>> lib/devmem_is_allowed.c | 27 +++++++++++++++++++++++++++
>> 4 files changed, 37 insertions(+)
>> create mode 100644 lib/devmem_is_allowed.c
>>
>> diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
>> index 8b1e020e9a03..69e3db65fba0 100644
>> --- a/include/asm-generic/io.h
>> +++ b/include/asm-generic/io.h
>> @@ -1122,6 +1122,10 @@ static inline void memcpy_toio(volatile void __iomem *addr, const void *buffer,
>> }
>> #endif
>>
>> +#ifndef CONFIG_GENERIC_DEVMEM_IS_ALLOWED
>> +extern int devmem_is_allowed(unsigned long pfn);
>> +#endif
>> +
>> #endif /* __KERNEL__ */
>>
>> #endif /* __ASM_GENERIC_IO_H */
>> diff --git a/lib/Kconfig b/lib/Kconfig
>> index df3f3da95990..3b1b6481e073 100644
>> --- a/lib/Kconfig
>> +++ b/lib/Kconfig
>> @@ -676,3 +676,7 @@ config GENERIC_LIB_CMPDI2
>>
>> config GENERIC_LIB_UCMPDI2
>> bool
>> +
>> +config GENERIC_LIB_DEVMEM_IS_ALLOWED
>> + bool
>> + select ARCH_HAS_DEVMEM_IS_ALLOWED
>
> This seems to work the other way around from the usual Kconfig chains.
> In the most cases ARCH_HAS_SOMETHING selects GENERIC_SOMETHING.
Ya, it seemed kind of odd.
>
> I believe nicer way would be to make
>
> config STRICT_DEVMEM
> bool "Filter access to /dev/mem"
> depends on MMU && DEVMEM
> depends on ARCH_HAS_DEVMEM_IS_ALLOWED || GENERIC_LIB_DEVMEM_IS_ALLOWED
>
> config GENERIC_LIB_DEVMEM_IS_ALLOWED
> bool
>
> and then s/select ARCH_HAS_DEVMEM_IS_ALLOWED/select GENERIC_LIB_DEVMEM_IS_ALLOWED/
> in the arch Kconfigs and drop ARCH_HAS_DEVMEM_IS_ALLOWED in the end.
There's some arches that can't be converted to the generic version, at least
not trivially, so we wouldn't drop it. I think it's still cleaner, though.
I'll send a v2.
>
>> diff --git a/lib/Makefile b/lib/Makefile
>> index b1c42c10073b..554ef14f9be5 100644
>> --- a/lib/Makefile
>> +++ b/lib/Makefile
>> @@ -318,3 +318,5 @@ obj-$(CONFIG_OBJAGG) += objagg.o
>> # KUnit tests
>> obj-$(CONFIG_LIST_KUNIT_TEST) += list-test.o
>> obj-$(CONFIG_LINEAR_RANGES_TEST) += test_linear_ranges.o
>> +
>> +obj-$(CONFIG_GENERIC_LIB_DEVMEM_IS_ALLOWED) += devmem_is_allowed.o
>> diff --git a/lib/devmem_is_allowed.c b/lib/devmem_is_allowed.c
>> new file mode 100644
>> index 000000000000..c0d67c541849
>> --- /dev/null
>> +++ b/lib/devmem_is_allowed.c
>> @@ -0,0 +1,27 @@
>> +// SPDX-License-Identifier: GPL-2.0-only
>> +/*
>> + * A generic version of devmem_is_allowed.
>> + *
>> + * Based on arch/arm64/mm/mmap.c
>> + *
>> + * Copyright (C) 2020 Google, Inc.
>> + * Copyright (C) 2012 ARM Ltd.
>> + */
>> +
>> +#include <linux/mm.h>
>> +#include <linux/ioport.h>
>> +
>> +/*
>> + * 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;
>> +}
>> --
>> 2.27.0.383.g050319c2ae-goog
>>
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply
* Re: [PATCH 1/5] lib: Add a generic version of devmem_is_allowed()
From: Mike Rapoport @ 2020-07-09 20:49 UTC (permalink / raw)
To: Palmer Dabbelt
Cc: mark.rutland, steve, davidgow, catalin.marinas, linus.walleij,
Palmer Dabbelt, elver, glider, willy, zong.li, mchehab+samsung,
linux-riscv, alex.shi, will, dan.j.williams, linux-arch, uwe,
alex, takahiro.akashi, paulmck, masahiroy, linux, krzk, ardb,
bgolaszewski, kernel-team, pmladek, zaslonko, aou, keescook,
Arnd Bergmann, rostedt, broonie, matti.vaittinen, gregory.0xf0,
Paul Walmsley, tglx, andriy.shevchenko, gxt, linux-arm-kernel,
rdunlap, Nick Desaulniers, linux-kernel, mcgrof, james.morse,
mhiramat, akpm, davem
In-Reply-To: <20200709200552.1910298-2-palmer@dabbelt.com>
Hi Palmer,
On Thu, Jul 09, 2020 at 01:05:48PM -0700, Palmer Dabbelt wrote:
> From: Palmer Dabbelt <palmerdabbelt@google.com>
>
> As part of adding support for STRICT_DEVMEM to the RISC-V port, Zong
> provided a devmem_is_allowed() implementation that's exactly the same as
> all the others I checked. Instead I'm adding a generic version, which
> will soon be used.
>
> Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
> ---
> include/asm-generic/io.h | 4 ++++
> lib/Kconfig | 4 ++++
> lib/Makefile | 2 ++
> lib/devmem_is_allowed.c | 27 +++++++++++++++++++++++++++
> 4 files changed, 37 insertions(+)
> create mode 100644 lib/devmem_is_allowed.c
>
> diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
> index 8b1e020e9a03..69e3db65fba0 100644
> --- a/include/asm-generic/io.h
> +++ b/include/asm-generic/io.h
> @@ -1122,6 +1122,10 @@ static inline void memcpy_toio(volatile void __iomem *addr, const void *buffer,
> }
> #endif
>
> +#ifndef CONFIG_GENERIC_DEVMEM_IS_ALLOWED
> +extern int devmem_is_allowed(unsigned long pfn);
> +#endif
> +
> #endif /* __KERNEL__ */
>
> #endif /* __ASM_GENERIC_IO_H */
> diff --git a/lib/Kconfig b/lib/Kconfig
> index df3f3da95990..3b1b6481e073 100644
> --- a/lib/Kconfig
> +++ b/lib/Kconfig
> @@ -676,3 +676,7 @@ config GENERIC_LIB_CMPDI2
>
> config GENERIC_LIB_UCMPDI2
> bool
> +
> +config GENERIC_LIB_DEVMEM_IS_ALLOWED
> + bool
> + select ARCH_HAS_DEVMEM_IS_ALLOWED
This seems to work the other way around from the usual Kconfig chains.
In the most cases ARCH_HAS_SOMETHING selects GENERIC_SOMETHING.
I believe nicer way would be to make
config STRICT_DEVMEM
bool "Filter access to /dev/mem"
depends on MMU && DEVMEM
depends on ARCH_HAS_DEVMEM_IS_ALLOWED || GENERIC_LIB_DEVMEM_IS_ALLOWED
config GENERIC_LIB_DEVMEM_IS_ALLOWED
bool
and then s/select ARCH_HAS_DEVMEM_IS_ALLOWED/select GENERIC_LIB_DEVMEM_IS_ALLOWED/
in the arch Kconfigs and drop ARCH_HAS_DEVMEM_IS_ALLOWED in the end.
> diff --git a/lib/Makefile b/lib/Makefile
> index b1c42c10073b..554ef14f9be5 100644
> --- a/lib/Makefile
> +++ b/lib/Makefile
> @@ -318,3 +318,5 @@ obj-$(CONFIG_OBJAGG) += objagg.o
> # KUnit tests
> obj-$(CONFIG_LIST_KUNIT_TEST) += list-test.o
> obj-$(CONFIG_LINEAR_RANGES_TEST) += test_linear_ranges.o
> +
> +obj-$(CONFIG_GENERIC_LIB_DEVMEM_IS_ALLOWED) += devmem_is_allowed.o
> diff --git a/lib/devmem_is_allowed.c b/lib/devmem_is_allowed.c
> new file mode 100644
> index 000000000000..c0d67c541849
> --- /dev/null
> +++ b/lib/devmem_is_allowed.c
> @@ -0,0 +1,27 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * A generic version of devmem_is_allowed.
> + *
> + * Based on arch/arm64/mm/mmap.c
> + *
> + * Copyright (C) 2020 Google, Inc.
> + * Copyright (C) 2012 ARM Ltd.
> + */
> +
> +#include <linux/mm.h>
> +#include <linux/ioport.h>
> +
> +/*
> + * 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;
> +}
> --
> 2.27.0.383.g050319c2ae-goog
>
--
Sincerely yours,
Mike.
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply
* Re: [PATCH 0/3] Dynamic CPU frequency switching for the HiFive
From: Palmer Dabbelt @ 2020-07-09 20:48 UTC (permalink / raw)
To: schwab
Cc: devicetree, aou, david.abdurachmanov, anup, lollivier,
linux-kernel, green.wan, Atish Patra, yash.shah, robh+dt,
Alistair Francis, sachin.ghadi, Paul Walmsley, linux-riscv,
bmeng.cn, deepa.kernel
In-Reply-To: <mvmtuylcb4h.fsf@suse.de>
On Mon, 06 Jul 2020 01:15:42 PDT (-0700), schwab@suse.de wrote:
> On Jul 03 2020, Yash Shah wrote:
>
>> Yes, you are right. The userspace governor is the only one supported.
>
> That doesn't make sense to me. How is the userspace governor different
> from any other governor?
It's not.
The issue here is that pretty much everything is on one clock, including all
the cores and the simple IO devices. These IO devices have programmable clock
dividers that need to mesh up with the input clock rate in order to operate
correctly. There's no way to do that atomicly WRT the device's clock, so we
have to pause device IO while messing with the clocks.
I bet there's some issue with 4cbd7814bbd5 ("tty: sifive: Finish transmission
before changing the clock") that's causing the serial to get corrupted, and I
guess I'd start with all the issues I pointed out in the patch text :).
Presumably we need to fix the SPI driver as well, in much the same fashion
(though hopefully with fewer hardware surprises to work around). I'd be way
more worried about ChipLink, as I don't know how that's clocked. IIRC Ethernet
has its own clock so it should be safe.
I'd be very skeptical about turning on dynamic frequency scaling for the HiFive
Unleashed, as it's probably just not worth chasing the long tail of bugs. Even
allowing the userspace governor is a bit sketchy, but given that it's a very
early dev board I assume these sorts of problems are expected.
If we do ever turn dynamic frequency scaling on it's not going to default to
allowing 1.4GHz, from what I saw speeds much over 1GHz don't work for most
people.
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply
* [PATCH 3/5] arm: Use the generic devmem_is_allowed()
From: Palmer Dabbelt @ 2020-07-09 20:05 UTC (permalink / raw)
To: linux-riscv, zong.li
Cc: mark.rutland, steve, davidgow, ardb, catalin.marinas,
linus.walleij, Palmer Dabbelt, elver, glider, willy,
mchehab+samsung, linux-riscv, alex.shi, will, dan.j.williams,
linux-arch, uwe, alex, takahiro.akashi, paulmck, masahiroy, linux,
krzk, rppt, bgolaszewski, james.morse, kernel-team, pmladek,
zaslonko, aou, keescook, Arnd Bergmann, rostedt, broonie,
matti.vaittinen, gregory.0xf0, Paul Walmsley, tglx,
andriy.shevchenko, gxt, linux-arm-kernel, rdunlap,
Nick Desaulniers, linux-kernel, mcgrof, Palmer Dabbelt, mhiramat,
akpm, davem
In-Reply-To: <20200709200552.1910298-1-palmer@dabbelt.com>
From: Palmer Dabbelt <palmerdabbelt@google.com>
This is exactly the same as the arm64 version, which I recently copied
into lib/ for use by the RISC-V port.
[I haven't even build tested this. The lib/ patch is on riscv/for-next,
which I'm targeting for 5.9, so this won't work alone. See the cover
letter for more details.]
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
---
arch/arm/Kconfig | 1 +
arch/arm/include/asm/io.h | 1 -
arch/arm/mm/mmap.c | 22 ----------------------
3 files changed, 1 insertion(+), 23 deletions(-)
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 2ac74904a3ce..0c9da68835c2 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -54,6 +54,7 @@ config ARM
select GENERIC_IRQ_PROBE
select GENERIC_IRQ_SHOW
select GENERIC_IRQ_SHOW_LEVEL
+ select GENERIC_LIB_DEVMEM_IS_ALLOWED
select GENERIC_PCI_IOMAP
select GENERIC_SCHED_CLOCK
select GENERIC_SMP_IDLE_THREAD
diff --git a/arch/arm/include/asm/io.h b/arch/arm/include/asm/io.h
index ab2b654084fa..fc748122f1e0 100644
--- a/arch/arm/include/asm/io.h
+++ b/arch/arm/include/asm/io.h
@@ -441,7 +441,6 @@ extern void pci_iounmap(struct pci_dev *dev, void __iomem *addr);
#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
extern int valid_phys_addr_range(phys_addr_t addr, size_t size);
extern int valid_mmap_phys_addr_range(unsigned long pfn, size_t size);
-extern int devmem_is_allowed(unsigned long pfn);
#endif
/*
diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
index b8d912ac9e61..a0f8a0ca0788 100644
--- a/arch/arm/mm/mmap.c
+++ b/arch/arm/mm/mmap.c
@@ -165,25 +165,3 @@ int valid_mmap_phys_addr_range(unsigned long pfn, size_t size)
{
return (pfn + (size >> PAGE_SHIFT)) <= (1 + (PHYS_MASK >> PAGE_SHIFT));
}
-
-#ifdef CONFIG_STRICT_DEVMEM
-
-#include <linux/ioport.h>
-
-/*
- * 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
--
2.27.0.383.g050319c2ae-goog
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related
* [PATCH 2/5] RISC-V: Use the new generic devmem_is_allowed()
From: Palmer Dabbelt @ 2020-07-09 20:05 UTC (permalink / raw)
To: linux-riscv, zong.li
Cc: mark.rutland, steve, davidgow, ardb, catalin.marinas,
linus.walleij, Palmer Dabbelt, elver, glider, willy,
mchehab+samsung, linux-riscv, alex.shi, will, dan.j.williams,
linux-arch, uwe, alex, takahiro.akashi, paulmck, masahiroy, linux,
krzk, rppt, bgolaszewski, james.morse, kernel-team, pmladek,
zaslonko, aou, keescook, Arnd Bergmann, rostedt, broonie,
matti.vaittinen, gregory.0xf0, Paul Walmsley, tglx,
andriy.shevchenko, gxt, linux-arm-kernel, rdunlap,
Nick Desaulniers, linux-kernel, mcgrof, Palmer Dabbelt, mhiramat,
akpm, davem
In-Reply-To: <20200709200552.1910298-1-palmer@dabbelt.com>
From: Palmer Dabbelt <palmerdabbelt@google.com>
This allows us to enable STRICT_DEVMEM.
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
---
arch/riscv/Kconfig | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 089293e4ad46..8ff368a65a07 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -37,6 +37,7 @@ config RISCV
select GENERIC_IOREMAP
select GENERIC_IRQ_MULTI_HANDLER
select GENERIC_IRQ_SHOW
+ select GENERIC_LIB_DEVMEM_IS_ALLOWED
select GENERIC_PCI_IOMAP
select GENERIC_PTDUMP if MMU
select GENERIC_SCHED_CLOCK
--
2.27.0.383.g050319c2ae-goog
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related
* [PATCH 4/5] arm64: Use the generic devmem_is_allowed()
From: Palmer Dabbelt @ 2020-07-09 20:05 UTC (permalink / raw)
To: linux-riscv, zong.li
Cc: mark.rutland, steve, davidgow, ardb, catalin.marinas,
linus.walleij, Palmer Dabbelt, elver, glider, willy,
mchehab+samsung, linux-riscv, alex.shi, will, dan.j.williams,
linux-arch, uwe, alex, takahiro.akashi, paulmck, masahiroy, linux,
krzk, rppt, bgolaszewski, james.morse, kernel-team, pmladek,
zaslonko, aou, keescook, Arnd Bergmann, rostedt, broonie,
matti.vaittinen, gregory.0xf0, Paul Walmsley, tglx,
andriy.shevchenko, gxt, linux-arm-kernel, rdunlap,
Nick Desaulniers, linux-kernel, mcgrof, Palmer Dabbelt, mhiramat,
akpm, davem
In-Reply-To: <20200709200552.1910298-1-palmer@dabbelt.com>
From: Palmer Dabbelt <palmerdabbelt@google.com>
I recently copied this into lib/ for use by the RISC-V port.
[I haven't even build tested this. The lib/ patch is on riscv/for-next,
which I'm targeting for 5.9, so this won't work alone. See the cover
letter for more details.]
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
---
arch/arm64/Kconfig | 1 +
arch/arm64/include/asm/io.h | 2 --
arch/arm64/mm/mmap.c | 21 ---------------------
3 files changed, 1 insertion(+), 23 deletions(-)
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 66dc41fd49f2..0770ed21a8c4 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -110,6 +110,7 @@ config ARM64
select GENERIC_IRQ_PROBE
select GENERIC_IRQ_SHOW
select GENERIC_IRQ_SHOW_LEVEL
+ select GENERIC_LIB_DEVMEM_IS_ALLOWED
select GENERIC_PCI_IOMAP
select GENERIC_PTDUMP
select GENERIC_SCHED_CLOCK
diff --git a/arch/arm64/include/asm/io.h b/arch/arm64/include/asm/io.h
index ff50dd731852..c53eba1a7fd2 100644
--- a/arch/arm64/include/asm/io.h
+++ b/arch/arm64/include/asm/io.h
@@ -200,6 +200,4 @@ extern void __iomem *ioremap_cache(phys_addr_t phys_addr, size_t size);
extern int valid_phys_addr_range(phys_addr_t addr, size_t size);
extern int valid_mmap_phys_addr_range(unsigned long pfn, size_t size);
-extern int devmem_is_allowed(unsigned long pfn);
-
#endif /* __ASM_IO_H */
diff --git a/arch/arm64/mm/mmap.c b/arch/arm64/mm/mmap.c
index 3028bacbc4e9..07937b49cb88 100644
--- a/arch/arm64/mm/mmap.c
+++ b/arch/arm64/mm/mmap.c
@@ -47,24 +47,3 @@ int valid_mmap_phys_addr_range(unsigned long pfn, size_t size)
{
return !(((pfn << PAGE_SHIFT) + size) & ~PHYS_MASK);
}
-
-#ifdef CONFIG_STRICT_DEVMEM
-
-#include <linux/ioport.h>
-
-/*
- * 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
--
2.27.0.383.g050319c2ae-goog
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related
* [PATCH 5/5] unicore32: Use the generic devmem_is_allowed()
From: Palmer Dabbelt @ 2020-07-09 20:05 UTC (permalink / raw)
To: linux-riscv, zong.li
Cc: mark.rutland, steve, davidgow, ardb, catalin.marinas,
linus.walleij, Palmer Dabbelt, elver, glider, willy,
mchehab+samsung, linux-riscv, alex.shi, will, dan.j.williams,
linux-arch, uwe, alex, takahiro.akashi, paulmck, masahiroy, linux,
krzk, rppt, bgolaszewski, james.morse, kernel-team, pmladek,
zaslonko, aou, keescook, Arnd Bergmann, rostedt, broonie,
matti.vaittinen, gregory.0xf0, Paul Walmsley, tglx,
andriy.shevchenko, gxt, linux-arm-kernel, rdunlap,
Nick Desaulniers, linux-kernel, mcgrof, Palmer Dabbelt, mhiramat,
akpm, davem
In-Reply-To: <20200709200552.1910298-1-palmer@dabbelt.com>
From: Palmer Dabbelt <palmerdabbelt@google.com>
Aside from being inlineable, this is exactly the same as the arm64
version, which I recently copied into lib/ for use by the RISC-V port.
[I haven't even build tested this. The lib/ patch is on riscv/for-next,
which I'm targeting for 5.9, so this won't work alone. See the cover
letter for more details.]
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
---
arch/unicore32/Kconfig | 1 +
arch/unicore32/include/asm/io.h | 23 -----------------------
2 files changed, 1 insertion(+), 23 deletions(-)
diff --git a/arch/unicore32/Kconfig b/arch/unicore32/Kconfig
index 11ba1839d198..5334f51614a5 100644
--- a/arch/unicore32/Kconfig
+++ b/arch/unicore32/Kconfig
@@ -12,6 +12,7 @@ config UNICORE32
select HAVE_KERNEL_LZO
select HAVE_KERNEL_LZMA
select HAVE_PCI
+ select GENERIC_LIB_DEVMEM_IS_ALLOWED
select VIRT_TO_BUS
select ARCH_HAVE_CUSTOM_GPIO_H
select GENERIC_FIND_FIRST_BIT
diff --git a/arch/unicore32/include/asm/io.h b/arch/unicore32/include/asm/io.h
index bd4e7c332f85..4560d2531655 100644
--- a/arch/unicore32/include/asm/io.h
+++ b/arch/unicore32/include/asm/io.h
@@ -42,28 +42,5 @@ extern void __uc32_iounmap(volatile void __iomem *addr);
#define PIO_MASK (unsigned int)(IO_SPACE_LIMIT)
#define PIO_RESERVED (PIO_OFFSET + PIO_MASK + 1)
-#ifdef CONFIG_STRICT_DEVMEM
-
-#include <linux/ioport.h>
-#include <linux/mm.h>
-
-/*
- * 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 inline 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 */
-
#endif /* __KERNEL__ */
#endif /* __UNICORE_IO_H__ */
--
2.27.0.383.g050319c2ae-goog
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox