On Tue, May 19, 2020 at 6:45 AM Christoph Hellwig <hch@xxxxxx> wrote: > > + > + if (IS_ENABLED(CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE) && > + compat && (unsigned long)unsafe_ptr < TASK_SIZE) > + ret = probe_user_read(dst, user_ptr, size); > + else > + ret = probe_kernel_read(dst, unsafe_ptr, size); ... > - ret = probe_kernel_read(&c, (u8 *)addr + len, 1); > + if (IS_ENABLED(CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE) && > + (unsigned long)addr < TASK_SIZE) { > + ret = probe_user_read(&c, > + (__force u8 __user *)addr + len, 1); > + } else { > + ret = probe_kernel_read(&c, (u8 *)addr + len, 1); > + } ... > + if (IS_ENABLED(CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE) && > + (unsigned long)src < TASK_SIZE) { > + return probe_user_read(dest, (__force const void __user *)src, > + size); If you can't make the conditional legible and fit on a single line and make it obvious _why_ you have that conditional, just use a helper function. Either for just the conditional itself, or for the whole operation. And at least for the bpf case, since you want the whole operation for that error handling and clearing of the result buffer anyway, I suspect it would be cleaner to have that kind of "bpf_copy_legacy_nofault()" function or whatever. (And see previous email why I dislike that "compat" naming in the bpf case) Linus