From: Yonghong Song <yhs@fb.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>, <kernel-team@fb.com>,
<x86@kernel.org>, KP Singh <kpsingh@kernel.org>
Subject: Re: [PATCH bpf] x86/bpf: handle bpf-program-triggered exceptions properly
Date: Tue, 26 Jan 2021 11:21:01 -0800 [thread overview]
Message-ID: <66f46df5-8d47-8e4f-a6ab-ab794e57332d@fb.com> (raw)
In-Reply-To: <YA/dqup/752hHBI4@hirez.programming.kicks-ass.net>
On 1/26/21 1:15 AM, Peter Zijlstra wrote:
> On Mon, Jan 25, 2021 at 04:12:19PM -0800, Yonghong Song wrote:
>> When the test is run normally after login prompt, cpu_feature_enabled(X86_FEATURE_SMAP)
>> is true and bad_area_nosemaphore() is called and then fixup_exception() is called,
>> where bpf specific handler is able to fixup the exception.
>>
>> But when the test is run at /sbin/init time, cpu_feature_enabled(X86_FEATURE_SMAP) is
>> false, the control reaches
>
> That makes no sense, cpu features should be set in stone long before we
> reach userspace.
You are correct. Sorry for misleading description. The reason is I use
two qemu script, one from my local environment and the other from ci
test since they works respectively. I thought they should have roughly
the same kernel setup, but apparently they are not.
For my local qemu script, I have "-cpu host" option and with this,
X86_FEATURE_SMAP is set up probably in function get_cpu_cap(), file
arch/x86/kernel/cpu/common.c.
For CI qemu script (in
https://lore.kernel.org/bpf/20210123004445.299149-1-kpsingh@kernel.org/),
the "-cpu kvm64" is the qemu argument. This cpu does not
enable X86_FEATURE_SMAP, so we will see the kernel warning.
Changing CI script to use "-cpu host" resolved the issue. I think "-cpu
kvm64" may emulate old x86 cpus and ignore X86_FEATURE_SMAP.
Do we have any x64 cpus which does not support X86_FEATURE_SMAP?
For CI, with "-cpu kvm64" is good as it can specify the number
of cores with e.g. "-smp 4" regardless of underlying host # of cores.
I think we could change CI to use "-cpu host" by ensuring the CI host
having at least 4 cores.
Thanks.
>
>> To fix the issue, before the above mmap_read_trylock(), we will check
>> whether fault ip can be served by bpf exception handler or not, if
>> yes, the exception will be fixed up and return.
>
>
>
>> diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
>> index f1f1b5a0956a..e8182d30bf67 100644
>> --- a/arch/x86/mm/fault.c
>> +++ b/arch/x86/mm/fault.c
>> @@ -1317,6 +1317,15 @@ void do_user_addr_fault(struct pt_regs *regs,
>> if (emulate_vsyscall(hw_error_code, regs, address))
>> return;
>> }
>> +
>> +#ifdef CONFIG_BPF_JIT
>> + /*
>> + * Faults incurred by bpf program might need emulation, i.e.,
>> + * clearing the dest register.
>> + */
>> + if (fixup_bpf_exception(regs, X86_TRAP_PF, hw_error_code, address))
>> + return;
>> +#endif
>> #endif
>
> NAK, this is broken. You're now disallowing faults that should've gone
> through.
>
next prev parent reply other threads:[~2021-01-26 22:54 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-26 0:12 [PATCH bpf] x86/bpf: handle bpf-program-triggered exceptions properly Yonghong Song
2021-01-26 9:15 ` Peter Zijlstra
2021-01-26 19:21 ` Yonghong Song [this message]
2021-01-27 9:30 ` Peter Zijlstra
2021-01-27 21:07 ` Andrii Nakryiko
2021-01-27 21:47 ` Andy Lutomirski
2021-01-28 1:05 ` Yonghong Song
2021-01-28 23:51 ` Andy Lutomirski
2021-01-29 0:11 ` Alexei Starovoitov
2021-01-29 0:18 ` Andy Lutomirski
2021-01-29 0:26 ` Alexei Starovoitov
2021-01-29 0:29 ` Andy Lutomirski
2021-01-29 0:32 ` Andy Lutomirski
2021-01-29 0:41 ` Alexei Starovoitov
2021-01-29 0:45 ` Andy Lutomirski
2021-01-29 1:04 ` Alexei Starovoitov
2021-01-29 1:31 ` Andy Lutomirski
2021-01-29 1:53 ` Alexei Starovoitov
2021-01-29 2:18 ` Andy Lutomirski
2021-01-29 2:32 ` Alexei Starovoitov
2021-01-29 3:09 ` Andy Lutomirski
2021-01-29 3:26 ` Alexei Starovoitov
2021-01-29 0:35 ` Jann Horn
2021-01-29 0:43 ` Alexei Starovoitov
2021-01-29 1:03 ` Jann Horn
2021-01-29 1:08 ` Alexei Starovoitov
[not found] <YBPToXfWV1ekRo4q@hirez.programming.kicks-ass.net>
[not found] ` <97EF0157-F068-4234-B826-C08B7324F356@amacapital.net>
2021-01-29 23:11 ` Alexei Starovoitov
2021-01-29 23:30 ` Andy Lutomirski
2021-01-30 2:54 ` Alexei Starovoitov
2021-01-31 17:32 ` Andy Lutomirski
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=66f46df5-8d47-8e4f-a6ab-ab794e57332d@fb.com \
--to=yhs@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=kpsingh@kernel.org \
--cc=peterz@infradead.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