Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796061161; b=cUlrOurjf0r4O5ymG1/mik2hczcXDQulazGfBXUg4YyLxd0rqn3Bp+ZIim5KohdMO207 zGoEGtBzWAV351F4BkzN3y5bEzdEMT5Gw//MTGqRv9b9ZfZgRNIrB5/Adpmwly/vSebf6 bu0/OXABA4GgUmXrN9kRrT8KmoU62/l04PiAvgqrBWzBRZnsQ2Bw9EVvFWVoNItVvqhGL KUFdAB1cuAGXTfvHELBooGaxKXWMyK+4fHOd2RaSI8R2CR8XV9S8qs/GYm/Da18MLwMDJ 3NIMjC9Ru+B1MvsycR2CUCgvyzpMj+3hF7cUYIUJSR0sz+B3RCEcKTUo5N0iF9MQfOA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796061161; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=z/fgwrx5guy9RDtthQnbLSaRknq4LOXSvZfsvSqq3BI=; b=ui+GFEky16PRRjIux2D2+3RMQlE4J30vbuONaykz6LbMyv/20dgzymd49TNCUgY/ZIXT N0wcB9WVx+CJzbh7Gt1SoVjatbMHrSm+qiOVuFWA6HlYAfU6KU7+ImuSTbWjcP++YWK7u 8IcbeVSBW7+kzqKc/K8REv3PUYkKN1Dq3c9Iwfh7jnEcKyhZgO83tV9ujsYWCCqRo9w73 uoi663g3hMPyuCr43PfGtaw3cXb3qkhGFYZX3RQ7MWxJlxAcKTMqsdfDLmxJj5esjdwHj r6Xogn12ZHFeUqyPm9q/hZfYTLrayMrUXeFhqJ81vknBSiRon8jh5DLuMy3joPSbjcA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=dFcfq3RA; arc=none smtp.remote-ip=209.85.221.48 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F3002606A329 for ; Mon, 30 Nov 2026 17:52:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F3002606A329 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=dFcfq3RA Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-4a68190a2a7so9270929f8f.1 for ; Mon, 30 Nov 2026 09:52:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796061159; x=1796665959; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=z/fgwrx5guy9RDtthQnbLSaRknq4LOXSvZfsvSqq3BI=; b=dFcfq3RA4w4lyDo/4g7IcFSNBAmVfdAhRCC/VApDRiADa11SeYX4JCuxgv46VJnY+z pwp19miVMxzIOwDAvwPknbn1BnYMnQuWxqeLm1Ursu9BmIYZKjmhjnJmBLazUAHgcCou xnQzmLi95M8lbAuz2Ckg93aNu+phBfsqSQWIxOp9s+4pahBX8W2KDOxGO1isyi5njAfL QuF+x3jgBDs5hZy71uunwSQkMJFg1N+Hm2/4Qc6zlQFO1cRtI9KEtUs/ZS4tJ8QfcNKx MpvCqzfrDT3qIaje5DEED+1rZ3ilcP+oyXvZs86Q0T4PUInTYOrGzJM1Gu1K6opEQhaL ESeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796061159; x=1796665959; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=z/fgwrx5guy9RDtthQnbLSaRknq4LOXSvZfsvSqq3BI=; b=or0RmP4zg7195ORIozcUuCVmsSASjw0HW4Me08QqN4/+1yQcmkAUnB4k89CbYIS4Xc IInXq+B/UUnR653jk687X+w2Va7XM2XgLRklUCh9ETGWyBSMwGzWtl0YrKFcJIL9DFHO c5TsoFP2zNeVNH4P8YggjlzodFcbUAxy9+2HVR9XgRNFEwytkxBeCWLiyVkoFo5zjHN3 R3PV7BHDs+vA8eVGaYV4+nxswZw/ZeQdw27l3g231HOfxmtm5zmP2/Gx3nTAEFXVb90C T2t+dx+IL8i7TzHkk1fvSSwz8m0SUe+MF8mH8IEcEWUSPhTWLewogIZiW7fx4mloWmpB XPqw== X-Forwarded-Encrypted: i=1; AL+hErGHFCMKMk/LFsl+5s4DOBFvZgpyzgZsebgBBe5S6FIfb5nSKSh403LspkRfPhQuLigyms8=@vger.kernel.org X-Gm-Message-State: APuU4Z+bGTVjWhLnOgtFDF6HXN/LFqgZ5vcewrIvgMp14iVXcwsc8Rgy 6OZwx+Oyz71VnPQAk90uBlHkQWQoZBS/lV7Op6ikcwsM6NqYunSO2vF5 X-Gm-Gg: AZFdTZc1WD8ubZgJclcVDl8LU1ykyFImIUO55slqzfnYJVnqluOM525rqmy5Sw4Omod 53lfPD6PK+oRRWx72Kz1XhrdebSWx3Jr2D8DZUDZwqbRA+nxXCT6V8Xo/uaPemcvwkpntAwNnxh o+m/bH99Lx36uldpGEaQF4kM3n7BTtcKWT/KE2Gl6YiAO2097kqEeOz9Bwyj8tFo9KBNFRyYD0r MnpPAqVI5/r1fr9I85LdY94Mvtn40G/InT7xBFTsPjq4Ec0prpmZx14yxJE9IaCsZtg3uwIHUCx CXgCrqHJJDofwHHvqSWoUMJo4TQNyOnzYZLuISdy/Krf5LPtD73ZdbeNSChehvhwZTOFsXVF89X 6gn7m9vOVsxP60G3m2Ezaj7ggpe8FGdS1KsIPXAbsEdsXx0dEMii1uTHySd4er7NbPGK7wlmAIn QZPHeWxYSwWzcmpOaimSjB/b6hts8cd4SZmzldTqpbH8/R1tFBPVvQ9So24uR9k8MrmoUjvULyX OzPFuJl6koW33mnEPL+SczIzLzB3Oa65+c16VFGYEr7x46uiDZu76wppmahsO64zqQ8sVyjhMSG MZl40TcwlXQNcmlO+UPrbuuptjO1qQOCyY7R5Y+n/z26/PA= X-Received: by 2002:adf:e886:0:b0:48e:3ebc:d242 with SMTP id ffacd0b85a97d-4abb2dda339mr51332459f8f.37.1796061159117; Mon, 30 Nov 2026 09:52:39 -0800 (PST) Received: from localhost.localdomain ([2a04:ee41:4:b2de:1ac0:4dff:fe0f:3782]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab9cf005f2sm55159452f8f.45.2026.11.30.09.52.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 09:52:38 -0800 (PST) From: Anton Protopopov To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Alan Maguire , John Fastabend , bpf@vger.kernel.org Cc: Anton Protopopov Subject: [PATCH v2 bpf-next 1/5] resolve_btfids: Do not count errors translated to NULL Date: Mon, 30 Nov 2026 18:04:18 +0000 Message-ID: <20261130180425.150703-2-a.s.protopopov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261130180425.150703-1-a.s.protopopov@gmail.com> References: <20261130180425.150703-1-a.s.protopopov@gmail.com> X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit A function may test a value with IS_ERR() and return it only if it is not an error: return IS_ERR(prev) ? NULL : prev; The scanner does not evaluate conditions and counts the errors which the value may hold. For a function which returns a pointer the tag would let a program return an error which the callers do not expect. They test only for NULL and dereference the error pointer. inet_frag_find() on x86-64 is an example: mov $-12, %rbp; ...; cmp $-0xfff, %rbp mov %rbp, %rax; cmovae %r14, %rax Describe a compare of a register with an immediate on x86-64 and arm64. A 64-bit compare with -MAX_ERRNO or -MAX_ERRNO - 1 is the test of IS_ERR(). The errors which the register holds there do not count. Losing an error is safe, but for -EINPROGRESS: with it -EBUSY is no failure, see means_failure(). So count -EINPROGRESS if the function loads it anywhere, whether it is left out or not. Signed-off-by: Anton Protopopov --- tools/bpf/resolve_btfids/fmodret.c | 18 +++++++++--------- tools/bpf/resolve_btfids/fmodret_scan.c | 5 ++++- tools/bpf/resolve_btfids/fmodret_scan.h | 5 ++++- tools/bpf/resolve_btfids/text_flow.c | 12 ++++++++++-- tools/bpf/resolve_btfids/text_flow.h | 3 +++ tools/bpf/resolve_btfids/text_insn.h | 1 + tools/bpf/resolve_btfids/text_mc.cpp | 9 ++++++--- tools/bpf/resolve_btfids/text_mc.h | 4 ++++ tools/bpf/resolve_btfids/text_mc_arm64.c | 6 ++++++ tools/bpf/resolve_btfids/text_mc_x86.c | 6 ++++++ 10 files changed, 53 insertions(+), 16 deletions(-) diff --git a/tools/bpf/resolve_btfids/fmodret.c b/tools/bpf/resolve_btfids/fmodret.c index b950d6b52554..34085d944718 100644 --- a/tools/bpf/resolve_btfids/fmodret.c +++ b/tools/bpf/resolve_btfids/fmodret.c @@ -140,9 +140,10 @@ static bool *find_bpf_funcs(const struct btf *btf) * wait, not that the function failed. Their numbers are those of the kernel, in * asm-generic/errno.h. The errno.h of the build host can have other numbers. * - * ASYNC: the function returns -EINPROGRESS too. Then its -EBUSY is no failure + * ASYNC: the function may return -EINPROGRESS too. Then its -EBUSY is no failure * either. In the crypto API it says that the request is queued on the backlog: - * crypto_wait_req() waits after both. + * crypto_wait_req() waits after both. scan_func() may leave out an -EINPROGRESS + * which the function returns, so any one which it loads counts. */ static bool means_failure(int error, bool async) { @@ -158,20 +159,18 @@ static int cmp_error(const void *va, const void *vb) /* * Write the tag for a function which returns SIZE bytes, and in them one of the - * NR VALUES of the return value register. In 8 bytes an error is sign extended. + * NR VALUES of the return value register. For ASYNC see means_failure(). In 8 + * bytes an error is sign extended. * Return false if there is nothing to tag. * * The machine code cannot tell the -EPERM of a permission check from the -1 of a * comparator or of "no such index": a function whose only error is -1 has none. */ -static bool format_tag(char *tag, const int64_t *values, size_t nr, __u32 size) +static bool format_tag(char *tag, const int64_t *values, size_t nr, __u32 size, bool async) { - bool async = false; size_t i, n = 0; int errors[nr]; - for (i = 0; i < nr; i++) - async |= (int)values[i] == -115; for (i = 0; i < nr; i++) { int error = values[i]; @@ -332,6 +331,7 @@ int fmodret_tag(Elf *elf, struct btf *btf, const char *deny_path, int verbose) const struct btf_type *t = btf__type_by_id(btf, id); const struct image_func *func; const int64_t *values; + bool async; const char *name; __u32 size; @@ -360,7 +360,7 @@ int fmodret_tag(Elf *elf, struct btf *btf, const char *deny_path, int verbose) if (denied && denied[func - img.funcs]) continue; nr_scanned++; - err = scan_func(scan, func, &values); + err = scan_func(scan, func, &values, &async); if (err == -EINVAL) { nr_undecodable++; err = 0; @@ -368,7 +368,7 @@ int fmodret_tag(Elf *elf, struct btf *btf, const char *deny_path, int verbose) if (err > 0) { char tag[sizeof(TAG) + 6 * err]; - if (!format_tag(tag, values, err, size)) + if (!format_tag(tag, values, err, size, async)) continue; if (verbose > 1) fprintf(stderr, "fmodret: %s %s\n", name, tag + strlen(TAG)); diff --git a/tools/bpf/resolve_btfids/fmodret_scan.c b/tools/bpf/resolve_btfids/fmodret_scan.c index 3753aa1e50c3..4dd0b8947812 100644 --- a/tools/bpf/resolve_btfids/fmodret_scan.c +++ b/tools/bpf/resolve_btfids/fmodret_scan.c @@ -201,7 +201,7 @@ static int add_value(struct scan *s, int64_t v) return 0; } -int scan_func(struct scan *s, const struct image_func *f, const int64_t **values) +int scan_func(struct scan *s, const struct image_func *f, const int64_t **values, bool *async) { const struct text_flow *flow = &s->flow; int err = decode_func(s, f); @@ -217,6 +217,7 @@ int scan_func(struct scan *s, const struct image_func *f, const int64_t **values text_flow_solve(&s->flow); s->nr_values = 0; + *async = false; for (i = 0; i < flow->nr_insns && !err; i++) { const struct text_insn *insn = &flow->insns[i]; uint64_t imm[2] = { insn->imm, insn->imm2 }; @@ -225,6 +226,8 @@ int scan_func(struct scan *s, const struct image_func *f, const int64_t **values if (insn->kind != TEXT_MOV_IMM && insn->kind != TEXT_SELECT_IMM) continue; + /* -EINPROGRESS of the kernel, not of the build host */ + *async |= (int32_t)imm[0] == -115 || (int32_t)imm[1] == -115; if (flow->reach[i].path == TEXT_EFFECT_PATH) continue; out = text_flow_out(flow, i); diff --git a/tools/bpf/resolve_btfids/fmodret_scan.h b/tools/bpf/resolve_btfids/fmodret_scan.h index f390ab7f5956..f3ae6e9cc5f3 100644 --- a/tools/bpf/resolve_btfids/fmodret_scan.h +++ b/tools/bpf/resolve_btfids/fmodret_scan.h @@ -24,8 +24,11 @@ void scan_set_proto(struct scan *scan, const struct image_func *func, unsigned i * Leave out a constant if each path from the entry to its return has an effect * on an object which FUNC gets a pointer to, see text_flow.h. * A function which ftrace cannot patch has none: no program can attach to it. + * Set ASYNC if any instruction of FUNC loads -EINPROGRESS, whether it is left + * out or not. * Return how many there are, or -EINVAL if the code cannot be decoded. */ -int scan_func(struct scan *scan, const struct image_func *func, const int64_t **values); +int scan_func(struct scan *scan, const struct image_func *func, const int64_t **values, + bool *async); #endif diff --git a/tools/bpf/resolve_btfids/text_flow.c b/tools/bpf/resolve_btfids/text_flow.c index d7d3f9d1c6c1..44e772e2deb2 100644 --- a/tools/bpf/resolve_btfids/text_flow.c +++ b/tools/bpf/resolve_btfids/text_flow.c @@ -5,6 +5,7 @@ #include #include +#include #include "text_flow.h" @@ -56,7 +57,8 @@ void text_flow_fold(struct text_flow *flow) defs = TEXT_ALL_REGS; else if (insn->kind == TEXT_CALL) defs |= flow->arch->caller_saved; - else if (insn->kind != TEXT_OTHER && insn->kind != TEXT_COND_BRANCH) + else if (insn->kind != TEXT_OTHER && insn->kind != TEXT_CMP_IMM && + insn->kind != TEXT_COND_BRANCH) defs |= BIT(insn->dst); for (r = 0; defs && r < TEXT_MAX_REGS; r++) if (defs & BIT(r)) @@ -156,6 +158,12 @@ static struct text_facts transfer(const struct text_flow *flow, u32 i) if (insn->kind == TEXT_SELECT) copy(&in, &out, insn->dst, insn->src2, cast); break; + case TEXT_CMP_IMM: + /* IS_ERR(src) ? NULL : src. Count no error which the function tests itself */ + if (!insn->is32 && + (insn->imm == -(u64)MAX_ERRNO || insn->imm == -(u64)MAX_ERRNO - 1)) + kill(&in, BIT(insn->src)); + break; } return in; } @@ -170,7 +178,7 @@ static u32 transfer_based(const struct text_flow *flow, const struct text_insn * return based; if (insn->kind == TEXT_CALL) return based & ~(defs | flow->arch->caller_saved); - if (insn->kind != TEXT_OTHER && insn->kind < TEXT_BRANCH) + if (insn->kind != TEXT_OTHER && insn->kind != TEXT_CMP_IMM && insn->kind < TEXT_BRANCH) defs |= BIT(insn->dst); if (insn->kind == TEXT_MOV_IMM || insn->load || !(insn->uses & based)) return based & ~defs; diff --git a/tools/bpf/resolve_btfids/text_flow.h b/tools/bpf/resolve_btfids/text_flow.h index 56cd13c277f3..beff2bc45538 100644 --- a/tools/bpf/resolve_btfids/text_flow.h +++ b/tools/bpf/resolve_btfids/text_flow.h @@ -14,6 +14,9 @@ * join is the union. Branches are not evaluated, calls write what the ABI lets * them write, memory is not tracked. * + * Only one condition counts: a register which is compared with -MAX_ERRNO, as + * by IS_ERR(), leaves the set. The function returns no error which it tests. + * * A copy may convert the value, and only the last conversion counts. So there * are three sets. */ diff --git a/tools/bpf/resolve_btfids/text_insn.h b/tools/bpf/resolve_btfids/text_insn.h index e498245a5b73..561cf152a7a2 100644 --- a/tools/bpf/resolve_btfids/text_insn.h +++ b/tools/bpf/resolve_btfids/text_insn.h @@ -23,6 +23,7 @@ enum text_insn_kind { TEXT_SEXT32, /* dst = (s32)src */ TEXT_SELECT, /* dst = src or src2 */ TEXT_SELECT_IMM, /* dst = src or imm */ + TEXT_CMP_IMM, /* the flags = src compared with imm, dst is not written */ TEXT_BRANCH, /* to imm, 0 if it is computed */ TEXT_COND_BRANCH, /* to imm or to the next instruction */ TEXT_CALL, /* of imm, 0 if it is computed */ diff --git a/tools/bpf/resolve_btfids/text_mc.cpp b/tools/bpf/resolve_btfids/text_mc.cpp index 69668f8b12d7..ffb3b6d54b2e 100644 --- a/tools/bpf/resolve_btfids/text_mc.cpp +++ b/tools/bpf/resolve_btfids/text_mc.cpp @@ -250,8 +250,8 @@ bool holds(const MCInst &inst, const mc_predicate &p) /* Describe INST as PATTERN says. Return false, and leave TI alone, if it does not match */ bool match(const MCInst &inst, const Opcode &o, const mc_pattern &pattern, text_insn *ti) { - const Reg &dst = reg_of(inst, o, pattern.dst, true); u8 kind = pattern.kind, src = 0, src2 = 0; + const Reg &dst = reg_of(inst, o, pattern.dst, kind != TEXT_CMP_IMM); bool is32 = dst.bits == 32; u64 imm = pattern.value; @@ -271,6 +271,8 @@ bool match(const MCInst &inst, const Opcode &o, const mc_pattern &pattern, text_ imm <<= inst.getOperand(pattern.shift).getImm(); if (pattern.invert) imm = ~imm; + if (pattern.negate) + imm = -imm; if (is32) imm = (u32)imm; } @@ -288,7 +290,7 @@ bool match(const MCInst &inst, const Opcode &o, const mc_pattern &pattern, text_ } ti->kind = kind; ti->is32 = is32; - ti->dst = dst.nr; + ti->dst = kind == TEXT_CMP_IMM ? 0 : dst.nr; ti->src = src; ti->src2 = src2; ti->op = pattern.op; @@ -370,7 +372,8 @@ int decode(const void *code, unsigned int len, u64 addr, text_insn *ti) ti->load = d.MII->get(inst.getOpcode()).mayLoad(); for (const mc_pattern *pattern : o.patterns) { if (match(inst, o, *pattern, ti)) { - ti->defs &= ~(1U << ti->dst); + if (ti->kind != TEXT_CMP_IMM) + ti->defs &= ~(1U << ti->dst); return 0; } } diff --git a/tools/bpf/resolve_btfids/text_mc.h b/tools/bpf/resolve_btfids/text_mc.h index 574d4a94afa6..23478eb7d8b2 100644 --- a/tools/bpf/resolve_btfids/text_mc.h +++ b/tools/bpf/resolve_btfids/text_mc.h @@ -55,6 +55,9 @@ struct mc_predicate { * from another one in some release, while the pattern of the old one stays * for the releases before. The tests show that one of the two matches. * + * A pattern of kind TEXT_CMP_IMM writes no register: DST is the register which + * gives the width of the compare. + * * A pattern of kind TEXT_RETURN names a return to the caller. isReturn() holds * for a return from an exception as well, which does not hand the return value * register to a caller. Without such a pattern it is an opcode like any other, @@ -71,6 +74,7 @@ struct mc_pattern { u8 shift; /* the operand which says how far the immediate is shifted left */ u8 op; /* of TEXT_ALU_IMM */ bool invert; /* the immediate */ + bool negate; /* the immediate */ bool or_zero; /* TEXT_MOV_IMM: the immediate or 0 */ bool fixed; /* the immediate is VALUE, not an operand */ s64 value; diff --git a/tools/bpf/resolve_btfids/text_mc_arm64.c b/tools/bpf/resolve_btfids/text_mc_arm64.c index 9cc41900fa4a..24e66a330852 100644 --- a/tools/bpf/resolve_btfids/text_mc_arm64.c +++ b/tools/bpf/resolve_btfids/text_mc_arm64.c @@ -22,6 +22,9 @@ static const struct mc_pattern arm64_patterns[] = { { "CSINCWr", TEXT_SELECT, .src = 1, .src2 = 1 }, /* and rd, rn, rm, asr #31: rn or 0 */ { "ANDWrs", TEXT_SELECT, .src = 1, .src2 = 1, .predicates = { IMM(3, 2 << 6 | 31) } }, + /* cmn of IS_ERR() */ + { "ADDSXri", TEXT_CMP_IMM, .dst = 1, .src = 1, .imm = 2, .shift = 3, .negate = true, + .predicates = { ZERO_REG(0) } }, /* HINT: nop, bti, yield, wfe ... */ { "HINT", TEXT_OTHER }, { "AUTIASP", TEXT_OTHER }, { "PRFMui", TEXT_OTHER }, { "HINT", TEXT_OTHER, .nop = true, .predicates = { IMM(0, 0) } }, /* nop */ @@ -59,6 +62,9 @@ static const struct mc_test arm64_tests[] = { T("00 05 89 1a", TEXT_SELECT, .is32 = true, SRC(8)), /* csinc w0, w8, w9, eq */ T("00 7d 89 0a", TEXT_SELECT, .is32 = true, SRC(8)), /* and w0, w8, w9, asr #31 */ T("00 01 09 0a", TEXT_OTHER, .defs = BIT(0)), /* and w0, w8, w9 */ + T("7f fe 3f b1", TEXT_CMP_IMM, SRC(19), IMMS(-4095, -4095)), /* cmn x19, #4095 */ + T("1f 04 40 b1", TEXT_CMP_IMM, IMMS(-4096, -4096)), /* cmn x0, #1, lsl #12 */ + T("60 fe 3f b1", TEXT_OTHER, .defs = BIT(0)), /* adds x0, x19, #4095 */ T("1f 20 03 d5", TEXT_OTHER, .nop = true), /* nop */ T("5f 24 03 d5", TEXT_OTHER), /* bti c */ T("bf 23 03 d5", TEXT_OTHER, .defs = BIT(30)), /* autiasp */ diff --git a/tools/bpf/resolve_btfids/text_mc_x86.c b/tools/bpf/resolve_btfids/text_mc_x86.c index 4f60a8f3263c..d0ced79c2e27 100644 --- a/tools/bpf/resolve_btfids/text_mc_x86.c +++ b/tools/bpf/resolve_btfids/text_mc_x86.c @@ -32,6 +32,9 @@ static const struct mc_pattern x86_patterns[] = { { "SUB32ri8", TEXT_ALU_IMM, .src = 1, .imm = 2, .op = TEXT_SUB }, { "SUB64ri8", TEXT_ALU_IMM, .src = 1, .imm = 2, .op = TEXT_SUB }, { "NOT32r", TEXT_ALU_IMM, .src = 1, .op = TEXT_XOR, VALUE(-1) }, + /* The compares of IS_ERR() */ + { "CMP64ri32", TEXT_CMP_IMM, .imm = 1 }, + { "CMP64i32", TEXT_CMP_IMM, .dst = I, .src = I }, { "LOCK_PREFIX", TEXT_OTHER }, { "NOOPL", TEXT_OTHER, .nop = true }, /* A rep prefix is not a part of the MCInst */ @@ -70,6 +73,9 @@ static const struct mc_test x86_tests[] = { T("83 eb 0e", TEXT_ALU_IMM, .is32 = true, .dst = RBX, SRC(RBX), .op = TEXT_SUB, IMMS(14, 14)), /* sub $14, %ebx */ T("48 83 eb 0e", TEXT_ALU_IMM, .dst = RBX, SRC(RBX), .op = TEXT_SUB, IMMS(14, 14)), /* sub $14, %rbx */ T("f7 d0", TEXT_ALU_IMM, .is32 = true, .op = TEXT_XOR, IMMS(0xffffffff, 0xffffffff)), /* not %eax */ + T("48 81 fd 01 f0 ff ff", TEXT_CMP_IMM, SRC(RBP), IMMS(-4095, -4095)), /* cmp $-4095, %rbp */ + T("48 3d 00 f0 ff ff", TEXT_CMP_IMM, IMMS(-4096, -4096)), /* cmp $-4096, %rax */ + T("3d 01 f0 ff ff", TEXT_OTHER), /* cmp $-4095, %eax */ T("f0", TEXT_OTHER), /* lock */ T("0f 1f 44 00 00", TEXT_OTHER, .nop = true), /* nopl 0x0(%rax,%rax,1) */ T("f3 48 ab", TEXT_OTHER, .defs = BIT(RCX) | BIT(RDI)), /* rep stosq */ -- 2.43.0