On 1/19/22 9:47 AM, Alexei Starovoitov wrote:
On Wed, Jan 12, 2022 at 12:16 PM Yonghong Song <yhs@xxxxxx> wrote:
+
+ /* check __user tag */
+ t = btf_type_by_id(btf, mtype->type);
+ if (btf_type_is_type_tag(t)) {
+ tag_value = __btf_name_by_offset(btf, t->name_off);
+ if (strcmp(tag_value, "user") == 0)
+ tmp_flag = MEM_USER;
+ }
+
stype = btf_type_skip_modifiers(btf, mtype->type, &id);
Does LLVM guarantee that btf_tag will be the first in the modifiers?
Looking at the selftest:
+struct bpf_testmod_btf_type_tag_2 {
+ struct bpf_testmod_btf_type_tag_1 __user *p;
+};
What if there are 'const' or 'volatile' modifiers on that pointer too?
And in different order with btf_tag?
BTF gets normalized or not?
I wonder whether we should introduce something like
btf_type_collect_modifiers() instead of btf_type_skip_modifiers() ?
Yes, LLVM guarantees that btf_tag will be the first in the modifiers.
The type chain format looks like below:
ptr -> [btf_type_tag ->]* (zero or more btf_type_tag's)
-> [other modifiers: const and/or volatile and/or restrict]
-> base_type
I only handled zero/one btf_type_tag case as we don't have use case
in kernel with two btf_type_tags for one pointer yet.