From nobody Sat Feb 7 17:19:48 2026 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E9F22620D1 for ; Wed, 30 Apr 2025 21:40:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746049258; cv=none; b=o5uab15/9mU/2ImeKvlEAUYd9U0d9HEib9AY6KPKoHotVLt1sGIl30NE75jknOUpS5rKDmagNqsfx6HlKWe6LUHpdtMYLifXWI9vvRB0LAKlBK6o6uPMp2sXV+NsEUKI73HVUtocZA86dFMsC4QTso2C8KTysKfnodOz0i5EUzc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746049258; c=relaxed/simple; bh=lVxGh1Tg5qZOItTVY+YP5B9couXEWcM6CbGBMFoCOD8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=OcHi2zDSoGh5B3Cqazpxz4itemdA+WrNPUzMvlXpw6L+j306QjhgHqYbejCZVjKEQZwUZZH8/tsEvCBdNeX7WYpllH1H+7k2Af2UA3jfgIyENHsDa09vlbW1+ZUeCncsLjnAOFaK3xVGyTNCy4cslJNWFBbs3NgqGwJEIgo7VF8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--samitolvanen.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=0JkSnkMe; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--samitolvanen.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="0JkSnkMe" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-736d64c5e16so277524b3a.3 for ; Wed, 30 Apr 2025 14:40:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1746049256; x=1746654056; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=PwsYz8d681oyODeIoah8TShz0oIpsZYiEqpJ1PpWgd0=; b=0JkSnkMeKVfsPbCZ4Md7Oq3OCLB0zuXdbtNcq0enO2R3Bx732s/61uTCN1AkNJPVdY Y4F4BU90isrByXsTEASwBqY00JagGYW2sWMk1i3NxWJrCYN+nauc9Y1qSDR292R/tMoK ZWKUpv8RncTJjto6u4S967zqTdrY4Hi8XDH7nxlWC560mi5zGsPu28c7FS8W/N3+uwq+ s96aYZzeZK5ohFd6R5SYKVnPAkCOgJLvx8y/0XVQO3m80B4/Z7JkG/8qnkQK1f12AsDX JNzHvKR2OKL0EjR3Nfy3tR4GzQD7rwU1MSH5ZB0pQWMERRH0EitMdDsFI2jVjHOfWskP LT2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746049256; x=1746654056; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PwsYz8d681oyODeIoah8TShz0oIpsZYiEqpJ1PpWgd0=; b=GZhAaVyaZUX2HsLwXMwlSLt6TMoR3etR9P9RpC4wYjc+k2k6aDFmABp+TK88ytb5hf SbH8zK5O9lixS+eWvXNFYOCfAJs3GTz6hGBTXBkloAaG2tR0+/oO81y1EYhEMrROf6Qd 3j1bjZWuu5frfCDsK0CkEjAPX8LzH2C4L+tA3wWYGEqYXCsgRtARCQwj3/oXCVZEMiDp 9AWUZxrVZ9uIYEK3ppiBEOzI6RaXqwRLlM7Ktj8I7eEusnYiCREjBaPY5Ix47uPuWQoG arOGol0V3lz4/rX0qLmGV3NJlw8xPx6VYLSlq+1RBUlg2apwWw/6lTcY338PClaoj1hP LS0g== X-Forwarded-Encrypted: i=1; AJvYcCXv+I4PpCG11y/Ay+GvPT+DWv0ee0f+CkhVyhd/akJECdvm41oDDYVk4GajznPCKSAzKVPGUypJ2ivOsPg=@vger.kernel.org X-Gm-Message-State: AOJu0YzKkYyRQLTZ0UVlFMDfcALg2UJiMQ/9cdU5cSuS3R/HSCOVSupG 0hrP3Ulrr90oLzudff61Gd8EHo0EilsRiuQAUUZRS0JH82N+dAYOQRCvhRO7OSOqHXmaOncat34 Mle8KzfiJUch+PHhhXINxpkkGAA== X-Google-Smtp-Source: AGHT+IH+89xWZb8Xbnsxtd0BCqDPM754+OwOdR/0Y0+acRvMkTR/2yTU2G9VVFNxNl9dFxKF9iUAE+KkoTKUo2oMBVo= X-Received: from pfble21.prod.google.com ([2002:a05:6a00:4fd5:b0:732:858a:729f]) (user=samitolvanen job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:1149:b0:736:ab1e:7775 with SMTP id d2e1a72fcca58-7404764c42bmr691100b3a.0.1746049256424; Wed, 30 Apr 2025 14:40:56 -0700 (PDT) Date: Wed, 30 Apr 2025 21:40:51 +0000 In-Reply-To: <20250430214049.2658716-6-samitolvanen@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250430214049.2658716-6-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=3880; i=samitolvanen@google.com; h=from:subject; bh=lVxGh1Tg5qZOItTVY+YP5B9couXEWcM6CbGBMFoCOD8=; b=owGbwMvMwCEWxa662nLh8irG02pJDBlCMx5+MvrBfN+dmaH1iLOYWZyrTWFB5UzrsNXSCve+p 87LtajqKGVhEONgkBVTZGn5unrr7u9Oqa8+F0nAzGFlAhnCwMUpABPRbWVkuCeW/nvl6Yc7KoR/ xWco3GzTaZJrXWW2OoAxyDng9/JfQYwMvTqsNYGn7s53atr9tD/ASnXltoSTJzN3X17LVZRvUX6 HBwA= X-Mailer: git-send-email 2.49.0.906.g1f30a19c02-goog Message-ID: <20250430214049.2658716-7-samitolvanen@google.com> Subject: [PATCH 1/4] gendwarfksyms: Clean up kABI rule look-ups From: Sami Tolvanen To: Masahiro Yamada Cc: Luis Chamberlain , Petr Pavlu , Daniel Gomez , linux-modules@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Sami Tolvanen Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Reduce code duplication by moving kABI rule look-ups to separate functions. Signed-off-by: Sami Tolvanen Reviewed-by: Petr Pavlu --- scripts/gendwarfksyms/kabi.c | 101 +++++++++++++++-------------------- 1 file changed, 44 insertions(+), 57 deletions(-) diff --git a/scripts/gendwarfksyms/kabi.c b/scripts/gendwarfksyms/kabi.c index 66f01fcd1607..badf8d46b154 100644 --- a/scripts/gendwarfksyms/kabi.c +++ b/scripts/gendwarfksyms/kabi.c @@ -222,33 +222,55 @@ void kabi_read_rules(int fd) check(elf_end(elf)); } =20 -bool kabi_is_declonly(const char *fqn) +static char *get_enumerator_target(const char *fqn, const char *field) +{ + char *target =3D NULL; + + if (asprintf(&target, "%s %s", fqn, field) < 0) + error("asprintf failed for '%s %s'", fqn, field); + + return target; +} + +static struct rule *find_rule(enum kabi_rule_type type, const char *target) { struct rule *rule; =20 if (!stable) - return false; - if (!fqn || !*fqn) - return false; + return NULL; + if (!target || !*target) + return NULL; =20 hash_for_each_possible(rules, rule, hash, - rule_values_hash(KABI_RULE_TYPE_DECLONLY, fqn)) { - if (rule->type =3D=3D KABI_RULE_TYPE_DECLONLY && - !strcmp(fqn, rule->target)) - return true; + rule_values_hash(type, target)) { + if (rule->type =3D=3D type && !strcmp(target, rule->target)) + return rule; } =20 - return false; + return NULL; } =20 -static char *get_enumerator_target(const char *fqn, const char *field) +static struct rule *find_enumerator_rule(enum kabi_rule_type type, + const char *fqn, const char *field) { - char *target =3D NULL; + struct rule *rule; + char *target; =20 - if (asprintf(&target, "%s %s", fqn, field) < 0) - error("asprintf failed for '%s %s'", fqn, field); + if (!stable) + return NULL; + if (!fqn || !*fqn || !field || !*field) + return NULL; =20 - return target; + target =3D get_enumerator_target(fqn, field); + rule =3D find_rule(type, target); + + free(target); + return rule; +} + +bool kabi_is_declonly(const char *fqn) +{ + return !!find_rule(KABI_RULE_TYPE_DECLONLY, fqn); } =20 static unsigned long get_ulong_value(const char *value) @@ -267,58 +289,23 @@ static unsigned long get_ulong_value(const char *valu= e) =20 bool kabi_is_enumerator_ignored(const char *fqn, const char *field) { - bool match =3D false; - struct rule *rule; - char *target; - - if (!stable) - return false; - if (!fqn || !*fqn || !field || !*field) - return false; - - target =3D get_enumerator_target(fqn, field); - - hash_for_each_possible( - rules, rule, hash, - rule_values_hash(KABI_RULE_TYPE_ENUMERATOR_IGNORE, target)) { - if (rule->type =3D=3D KABI_RULE_TYPE_ENUMERATOR_IGNORE && - !strcmp(target, rule->target)) { - match =3D true; - break; - } - } - - free(target); - return match; + return !!find_enumerator_rule(KABI_RULE_TYPE_ENUMERATOR_IGNORE, fqn, + field); } =20 bool kabi_get_enumerator_value(const char *fqn, const char *field, unsigned long *value) { - bool match =3D false; struct rule *rule; - char *target; =20 - if (!stable) - return false; - if (!fqn || !*fqn || !field || !*field) - return false; - - target =3D get_enumerator_target(fqn, field); - - hash_for_each_possible(rules, rule, hash, - rule_values_hash(KABI_RULE_TYPE_ENUMERATOR_VALUE, - target)) { - if (rule->type =3D=3D KABI_RULE_TYPE_ENUMERATOR_VALUE && - !strcmp(target, rule->target)) { - *value =3D get_ulong_value(rule->value); - match =3D true; - break; - } + rule =3D find_enumerator_rule(KABI_RULE_TYPE_ENUMERATOR_VALUE, fqn, + field); + if (rule) { + *value =3D get_ulong_value(rule->value); + return true; } =20 - free(target); - return match; + return false; } =20 void kabi_free(void) --=20 2.49.0.906.g1f30a19c02-goog From nobody Sat Feb 7 17:19:48 2026 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBC5F29AAE5 for ; Wed, 30 Apr 2025 21:40:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746049260; cv=none; b=Uk1IiwhUnNB71vjBAlnvtFXTSM8reIgqGuodirlmayQ72+M1Aj6dp/MVFbn3qdehIxGJtoct/8d9gBQ88HU6/yMsa1IFebanRoSrmHk3LPlxfZL7HJIfiJXD+/LdfkP9lu9WyPOaaECh9VXlSOkxVL/vrwBm6PtJP6rq9L1/MB8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746049260; c=relaxed/simple; bh=NugwJ2EAbfyS2hOmEh53DRrt4jtmrUq5uiPJk9sMyvs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LklwAm5NkWJQTHyoQHaqMs+l3/muYgdNjgQkFW+5++LY+OmmCP7R7r9YVsEAy4HcP3mIqPVrUOWy1vgzFxvLy/2MVEy9qQdJfyDxiABHYYy9w05EI5kgsAYazXETrUy9BKe4P0/mjI1vESNfFzibLJdLgRMDTsCHqoooXsr32wg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--samitolvanen.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=mLHeSiyy; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--samitolvanen.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="mLHeSiyy" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2254e500a73so1936445ad.0 for ; Wed, 30 Apr 2025 14:40:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1746049258; x=1746654058; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=E0wg72VP+xfWBCWqXGdsH9xJWL3ReO7P3OtwjDvLDRA=; b=mLHeSiyyDHcGsdJJQD8xbeh7UJVQ3FLXxle3PoY4UFnjTl6Uj11mzE3K3qu0YZ77ew 8EKF1DZntdHItT/DqK4OPRQdVq8/rRfL/OoZSkCQjcemX3ScnYQgkoyOiVxDa25J4cIk K9voNXffvptWB4PM6bzAIJuFbJZSPEaJruWbmdKsJBJ8XIvHkpLxFkg2VKwu522sa+8J IUUfDbhH5LA0zgLNXnnN9/t/g2GHE3TZK2tu22gsN3U/LM3MXNk+xmzOqAOjEBSk72ec kwhKFWzmEKFbDQvvhll8NHeGhgrg1WqEm9Pl3a2Hg/Wbv4Nm18BHEQaZWSqIwtQtM8SB Vthg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746049258; x=1746654058; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=E0wg72VP+xfWBCWqXGdsH9xJWL3ReO7P3OtwjDvLDRA=; b=P17Ei3+mMEpx0BmV+W2pZ7WREP0WCqgUKfVkbnmRH1QEQUc4I5gaK1PThl1Ht0iTRu iCxAbcxf4Mx/Dab69wdtN+5fbnZag9jn0g0EVns0n2FxIR0QnzjbA2iSQBq6kaYEnU1a 83mgyulx1a0hzjxfeFXGrAB2EithFaF6D+RkVi1fMnZSzBJl34epcnpoOZ4+wYjx4MiU RSEJCcUmpbNT72etK/f3HGWPgzbQk3Fe+4kNa+V5RHuqVv3l64eLyRBGZX6gYZeTLhB9 +xNr2HSkpRzemDmVjk6COv9IFF5AWrl/FPe6O8swKU3v4+GNigLtfotBm6q8MpRZuf3B lMBw== X-Forwarded-Encrypted: i=1; AJvYcCWbx2EPT8yAxxH/yY5XdeT+MpefBk466gd7pUrEJvGxO0Ydbjzlx5RXlzo8hXCH9kb2WYjINuZ070+1cbU=@vger.kernel.org X-Gm-Message-State: AOJu0YxwX8/Pbh13vTZP4y3JlffVS9Oxkp9gyr0H01QHEiiYjTTLKeEn EYjuSHMV5nzn+qCOlwTLa2jqvuAqtXnFKDwtxZ6ycBvzIbog49LnmHcWv9SkwDKuvOU6i8QkZoN 9YrQ+Ze1o2BSwVn1sfEP5LG/gQQ== X-Google-Smtp-Source: AGHT+IFmNjTg46QUuI9pZ6ComxQoEkoxNQLVPQK6W2Q4FMpSU0ZrS5Vkdowl6cN4/D79sGMc5bh05TwdGSTrVoEB/4k= X-Received: from plrp19.prod.google.com ([2002:a17:902:b093:b0:21f:56e1:c515]) (user=samitolvanen job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:da90:b0:223:66bb:8995 with SMTP id d9443c01a7336-22e08429875mr1067655ad.20.1746049258046; Wed, 30 Apr 2025 14:40:58 -0700 (PDT) Date: Wed, 30 Apr 2025 21:40:52 +0000 In-Reply-To: <20250430214049.2658716-6-samitolvanen@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250430214049.2658716-6-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=7551; i=samitolvanen@google.com; h=from:subject; bh=NugwJ2EAbfyS2hOmEh53DRrt4jtmrUq5uiPJk9sMyvs=; b=owGbwMvMwCEWxa662nLh8irG02pJDBlCMx4lHvCbeSsn2naTzbyTf9QmFW+ce+hW8sLFG7drZ buabu+O6yhlYRDjYJAVU2Rp+bp66+7vTqmvPhdJwMxhZQIZwsDFKQATUfjN8D97QdVMlX7meZOm zTo7b6Z55VmTOiXWpi0R81Yz2eZaSfxlZHjf865blmFbfPmTpJOraoKsT1adUmlfU/oic5HWVP3 fm5gA X-Mailer: git-send-email 2.49.0.906.g1f30a19c02-goog Message-ID: <20250430214049.2658716-8-samitolvanen@google.com> Subject: [PATCH 2/4] gendwarfksyms: Add a kABI rule to override byte_size attributes From: Sami Tolvanen To: Masahiro Yamada Cc: Luis Chamberlain , Petr Pavlu , Daniel Gomez , linux-modules@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Sami Tolvanen Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A data structure can be partially opaque to modules if its allocation is handled by the core kernel, and modules only need to access some of its members. In this situation, it's possible to append new members to the structure without breaking the ABI, as long as the layout for the original members remains unchanged. For example, consider the following struct: struct s { unsigned long a; void *p; }; gendwarfksyms --stable --dump-dies produces the following type expansion: variable structure_type s { member base_type long unsigned int byte_size(8) encoding(7) a data_member_location(0) , member pointer_type { base_type void } byte_size(8) p data_member_location(8) } byte_size(16) To append new members, we can use the KABI_IGNORE() macro to hide them from gendwarfksyms --stable: struct s { /* old members with unchanged layout */ unsigned long a; void *p; /* new members not accessed by modules */ KABI_IGNORE(0, unsigned long n); }; However, we can't hide the fact that adding new members changes the struct size, as seen in the updated type string: variable structure_type s { member base_type long unsigned int byte_size(8) encoding(7) a data_member_location(0) , member pointer_type { base_type void } byte_size(8) p data_member_location(8) } byte_size(24) In order to support this use case, add a kABI rule that makes it possible to override the byte_size attribute for types: /* * struct s allocation is handled by the kernel, so * appending new members without changing the original * layout won't break the ABI. */ KABI_BYTE_SIZE(s, 16); This results in a type string that's unchanged from the original and therefore, won't change versions for symbols that reference the changed structure. Signed-off-by: Sami Tolvanen Reviewed-by: Petr Pavlu --- scripts/gendwarfksyms/dwarf.c | 14 ++++++++++++- scripts/gendwarfksyms/examples/kabi.h | 7 +++++++ scripts/gendwarfksyms/examples/kabi_ex.c | 2 ++ scripts/gendwarfksyms/examples/kabi_ex.h | 22 +++++++++++++++++++++ scripts/gendwarfksyms/gendwarfksyms.h | 1 + scripts/gendwarfksyms/kabi.c | 25 ++++++++++++++++++++++++ 6 files changed, 70 insertions(+), 1 deletion(-) diff --git a/scripts/gendwarfksyms/dwarf.c b/scripts/gendwarfksyms/dwarf.c index eed247d8abfc..13ea7bf1ae7d 100644 --- a/scripts/gendwarfksyms/dwarf.c +++ b/scripts/gendwarfksyms/dwarf.c @@ -228,12 +228,24 @@ static void process_fqn(struct die *cache, Dwarf_Die = *die) DEFINE_PROCESS_UDATA_ATTRIBUTE(accessibility) DEFINE_PROCESS_UDATA_ATTRIBUTE(alignment) DEFINE_PROCESS_UDATA_ATTRIBUTE(bit_size) -DEFINE_PROCESS_UDATA_ATTRIBUTE(byte_size) DEFINE_PROCESS_UDATA_ATTRIBUTE(encoding) DEFINE_PROCESS_UDATA_ATTRIBUTE(data_bit_offset) DEFINE_PROCESS_UDATA_ATTRIBUTE(data_member_location) DEFINE_PROCESS_UDATA_ATTRIBUTE(discr_value) =20 +static void process_byte_size_attr(struct die *cache, Dwarf_Die *die) +{ + Dwarf_Word value; + unsigned long override; + + if (get_udata_attr(die, DW_AT_byte_size, &value)) { + if (stable && kabi_get_byte_size(cache->fqn, &override)) + value =3D override; + + process_fmt(cache, " byte_size(%" PRIu64 ")", value); + } +} + /* Match functions -- die_match_callback_t */ #define DEFINE_MATCH(type) \ static bool match_##type##_type(Dwarf_Die *die) \ diff --git a/scripts/gendwarfksyms/examples/kabi.h b/scripts/gendwarfksyms/= examples/kabi.h index 97a5669b083d..86f4428e0479 100644 --- a/scripts/gendwarfksyms/examples/kabi.h +++ b/scripts/gendwarfksyms/examples/kabi.h @@ -89,6 +89,13 @@ #define KABI_ENUMERATOR_VALUE(fqn, field, value) \ __KABI_RULE(enumerator_value, fqn field, value) =20 +/* + * KABI_BYTE_SIZE(fqn, value) + * Set the byte_size attribute for the struct/union/enum fqn to + * value bytes. + */ +#define KABI_BYTE_SIZE(fqn, value) __KABI_RULE(byte_size, fqn, value) + /* * KABI_RESERVE * Reserve some "padding" in a structure for use by LTS backports. diff --git a/scripts/gendwarfksyms/examples/kabi_ex.c b/scripts/gendwarfksy= ms/examples/kabi_ex.c index 0b7ffd830541..b73ee5399a59 100644 --- a/scripts/gendwarfksyms/examples/kabi_ex.c +++ b/scripts/gendwarfksyms/examples/kabi_ex.c @@ -28,3 +28,5 @@ struct ex2c ex2c; struct ex3a ex3a; struct ex3b ex3b; struct ex3c ex3c; + +struct ex4a ex4a; diff --git a/scripts/gendwarfksyms/examples/kabi_ex.h b/scripts/gendwarfksy= ms/examples/kabi_ex.h index 1736e0f65208..092c8cb7bcd7 100644 --- a/scripts/gendwarfksyms/examples/kabi_ex.h +++ b/scripts/gendwarfksyms/examples/kabi_ex.h @@ -260,4 +260,26 @@ _Static_assert(sizeof(struct ex3a) =3D=3D sizeof(struc= t ex3c), "ex3a size doesn't ma * STABLE-NEXT: } byte_size(16) */ =20 +/* + * Example: An ignored field added to an end of a partially opaque struct, + * while keeping the byte_size attribute unchanged. + */ + +struct ex4a { + unsigned long a; + KABI_IGNORE(0, unsigned long b); +}; + +/* + * This may be safe if the structure allocation is managed by the core ker= nel + * and the layout remains unchanged except for appended new members. + */ +KABI_BYTE_SIZE(ex4a, 8); + +/* + * STABLE: variable structure_type ex4a { + * STABLE-NEXT: member base_type [[ULONG]] byte_size(8) encoding(7) a da= ta_member_location(0) + * STABLE-NEXT: } byte_size(8) + */ + #endif /* __KABI_EX_H__ */ diff --git a/scripts/gendwarfksyms/gendwarfksyms.h b/scripts/gendwarfksyms/= gendwarfksyms.h index 2feec168bf73..2db49c2ad50e 100644 --- a/scripts/gendwarfksyms/gendwarfksyms.h +++ b/scripts/gendwarfksyms/gendwarfksyms.h @@ -287,6 +287,7 @@ void generate_symtypes_and_versions(FILE *file); * kabi.c */ =20 +bool kabi_get_byte_size(const char *fqn, unsigned long *value); bool kabi_is_enumerator_ignored(const char *fqn, const char *field); bool kabi_get_enumerator_value(const char *fqn, const char *field, unsigned long *value); diff --git a/scripts/gendwarfksyms/kabi.c b/scripts/gendwarfksyms/kabi.c index badf8d46b154..61620ff647bd 100644 --- a/scripts/gendwarfksyms/kabi.c +++ b/scripts/gendwarfksyms/kabi.c @@ -54,11 +54,19 @@ */ #define KABI_RULE_TAG_ENUMERATOR_VALUE "enumerator_value" =20 +/* + * Rule: byte_size + * - For the fqn_field in the target field, set the byte_size + * attribute to the value in the value field. + */ +#define KABI_RULE_TAG_BYTE_SIZE "byte_size" + enum kabi_rule_type { KABI_RULE_TYPE_UNKNOWN, KABI_RULE_TYPE_DECLONLY, KABI_RULE_TYPE_ENUMERATOR_IGNORE, KABI_RULE_TYPE_ENUMERATOR_VALUE, + KABI_RULE_TYPE_BYTE_SIZE, }; =20 #define RULE_HASH_BITS 7 @@ -127,6 +135,10 @@ void kabi_read_rules(int fd) .type =3D KABI_RULE_TYPE_ENUMERATOR_VALUE, .tag =3D KABI_RULE_TAG_ENUMERATOR_VALUE, }, + { + .type =3D KABI_RULE_TYPE_BYTE_SIZE, + .tag =3D KABI_RULE_TAG_BYTE_SIZE, + }, }; =20 if (!stable) @@ -308,6 +320,19 @@ bool kabi_get_enumerator_value(const char *fqn, const = char *field, return false; } =20 +bool kabi_get_byte_size(const char *fqn, unsigned long *value) +{ + struct rule *rule; + + rule =3D find_rule(KABI_RULE_TYPE_BYTE_SIZE, fqn); + if (rule) { + *value =3D get_ulong_value(rule->value); + return true; + } + + return false; +} + void kabi_free(void) { struct hlist_node *tmp; --=20 2.49.0.906.g1f30a19c02-goog From nobody Sat Feb 7 17:19:48 2026 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 401DC2C1E32 for ; Wed, 30 Apr 2025 21:41:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746049262; cv=none; b=uIpsFoY1E0581eDinaTnAROoodQyoWkcvlFFXbtfGst0jyYcjw9Fxr0fnAt/ypsuyiYi5HuSMdCZ/Rjy4nW7YF+0nOoeA64Oxf8haD3M4L4IdINFBL/O8X2eXbY5iaFXUnmUGjx/QSP3hoGypaaCQzwZNBQnX27CivIF1LBQqlA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746049262; c=relaxed/simple; bh=2hStC6Yklh+1qwsUrGlRRm5HFuMX58ZlhIKJnCjK60k=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=VbUP77V8Gx4+VSKwGmXkwHV0GOYzPRg9UlM5ifY32awNlqcKBmJeUb0Juu+lAKp11qjWu1nb5f+bAXJcXj0tcfThdmnAp3bKydwkQEWtaQuI0CM0MV8sHAoIw56uJu9leLbIbXcMm91OHPt46VfaMs2UoxivAACNUHchEI/zS+Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--samitolvanen.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=hJKT/fU7; arc=none smtp.client-ip=209.85.215.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--samitolvanen.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="hJKT/fU7" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b1b2fa98c39so311898a12.2 for ; Wed, 30 Apr 2025 14:41:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1746049259; x=1746654059; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=B4MwziIJriRxNCEbgYnxfmxqMDeuyh2hz5nqjLVljO8=; b=hJKT/fU7Gge1GqBSzqwIBeuIjoKiZZJhgO+4y1KDzXKKUg/pD5WmstOtRj3ZFvNFpO 4ySMIP1ccbWNfhjGc9UCqPETmqeBNdWh1C84fE+ldYL6LMcpV//pDq7OCyyZojktMcDB W5ipO68Qx8AdgRPDUSEEg5V4sYYe+R8pGufWyw6IVu2XWyRv/qB5OBEJS7bvWEa0TmIF dsXq2pfAfRkN1/kJzx51kGmnx+sF4cfaXfLA15Z7vohlbTqLIZBMWYzKha0lvm+TK2LY zNIGLXiFvgKXpfKsdhlbsT9e136LTnpZm2RDjzHqmKalEA5Ej3HGK+3n7UDeGU1nfaWw /MNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746049259; x=1746654059; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=B4MwziIJriRxNCEbgYnxfmxqMDeuyh2hz5nqjLVljO8=; b=AMg81a7eQ6ek1fABYNjbw8Dn5NCLZXlhrzE1sfj9xF2d4tbDPOvpP7bYibkJCyyFAi XJ/Z+0Yat1JxBcKQIIib4FBvdPiAcMU5zYSTPTwK3biMmZBc0DfbCD/Orx5GPEGWItQZ CYUaUQ/LFnUw326BCfmPbmjo8uprybG/bCBr4SYNdNu2gLIzTnpdr81BUXVhaK+KmB2/ 7kTuCGKft2IzH3yrYyISmpO7hIBpxP1ZyEJlKUq27pkVtOiQ6J9ETqV1kCKVrIbJehVa E7tCVt817llH8hDhyXdBOOEV3g5J4hCG7RM6WgBF5GHqTd9Dr7WM+jWhwRus13ETTijR o6xg== X-Forwarded-Encrypted: i=1; AJvYcCUPqWXR/fNpVh6IZUE+Qd2nKo4YzE+XnJtGcZr7oH8/88Er6z41uj5yJm2EHAOKtgV5f0YJ71CCBVtJ1N0=@vger.kernel.org X-Gm-Message-State: AOJu0YzcNBvrS2LrGGFW15Ccu61Z/ORbvZdys7zqC+BIRu6ZCMAHuVI4 ia+9mjmkIQoD9e958+u23h1+dtE+zeSpElLxIWvX3nIHIAPDtpWKd+9m+wKPC9QaXvFvpeWW/Wi L+6B8NmPO+BLZzB2RuJr2yFE04w== X-Google-Smtp-Source: AGHT+IFUEejToslW3e93peg3yrDcUAQ21dGGf71ZxD8RxhINDMiTrt1kWujDIigQwV7Uo5VoKPw6uj5JIwjvGchhDho= X-Received: from pfua19.prod.google.com ([2002:a05:6a00:11d3:b0:730:8e17:ed13]) (user=samitolvanen job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:8cc7:b0:1f5:67c2:e3eb with SMTP id adf61e73a8af0-20ba8e4bd94mr1234073637.41.1746049259596; Wed, 30 Apr 2025 14:40:59 -0700 (PDT) Date: Wed, 30 Apr 2025 21:40:53 +0000 In-Reply-To: <20250430214049.2658716-6-samitolvanen@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250430214049.2658716-6-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=16738; i=samitolvanen@google.com; h=from:subject; bh=2hStC6Yklh+1qwsUrGlRRm5HFuMX58ZlhIKJnCjK60k=; b=owGbwMvMwCEWxa662nLh8irG02pJDBlCMx5NP/D67t5UpTfnfk4/MrmnXkVC9vK7Wx3lfV/6v znqJvD7dJSyMIhxMMiKKbK0fF29dfd3p9RXn4skYOawMoEMYeDiFICJ7PjA8L9CW+TVjvm/+Tf0 fxDqfHU8hSWv9+QBgfkech0/Xx3uqmFk+Ct7M9Gd07fcf5vdKa2IsCeZKw905iksKmTdGdp+qs9 nCysA X-Mailer: git-send-email 2.49.0.906.g1f30a19c02-goog Message-ID: <20250430214049.2658716-9-samitolvanen@google.com> Subject: [PATCH 3/4] gendwarfksyms: Add a kABI rule to override type strings From: Sami Tolvanen To: Masahiro Yamada Cc: Luis Chamberlain , Petr Pavlu , Daniel Gomez , linux-modules@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Sami Tolvanen , Giuliano Procida Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In rare situations where distributions must make significant changes to otherwise opaque data structures that have inadvertently been included in the published ABI, keeping symbol versions stable using the existing kABI macros can become tedious. For example, Android decided to switch to a newer io_uring implementation in the 5.10 GKI kernel "to resolve a huge number of potential, and known, problems with the codebase," requiring "horrible hacks" with genksyms: "A number of the io_uring structures get used in other core kernel structures, only as "opaque" pointers, so there is not any real ABI breakage. But, due to the visibility of the structures going away, the CRC values of many scheduler variables and functions were changed." -- https://r.android.com/2425293 While these specific changes probably could have been hidden from gendwarfksyms using the existing kABI macros, this may not always be the case. Add a last resort kABI rule that allows distribution maintainers to fully override a type string for a symbol or a type. Also add a more informative error message in case we find a non-existent type references when calculating versions. Suggested-by: Giuliano Procida Signed-off-by: Sami Tolvanen --- scripts/gendwarfksyms/examples/kabi.h | 14 ++- scripts/gendwarfksyms/examples/kabi_ex.c | 5 + scripts/gendwarfksyms/examples/kabi_ex.h | 79 ++++++++++++- scripts/gendwarfksyms/gendwarfksyms.h | 1 + scripts/gendwarfksyms/kabi.c | 25 ++++ scripts/gendwarfksyms/types.c | 141 ++++++++++++++++++++--- 6 files changed, 247 insertions(+), 18 deletions(-) diff --git a/scripts/gendwarfksyms/examples/kabi.h b/scripts/gendwarfksyms/= examples/kabi.h index 86f4428e0479..170733a3fba4 100644 --- a/scripts/gendwarfksyms/examples/kabi.h +++ b/scripts/gendwarfksyms/examples/kabi.h @@ -37,11 +37,14 @@ #define __stringify(x...) __stringify_1(x) #endif =20 -#define __KABI_RULE(hint, target, value) \ +#define ___KABI_RULE(hint, target, value) \ static const char __PASTE(__gendwarfksyms_rule_, \ __COUNTER__)[] __used __aligned(1) \ __section(".discard.gendwarfksyms.kabi_rules") =3D \ - "1\0" #hint "\0" #target "\0" #value + "1\0" #hint "\0" target "\0" value + +#define __KABI_RULE(hint, target, value) \ + ___KABI_RULE(hint, #target, #value) =20 #define __KABI_NORMAL_SIZE_ALIGN(_orig, _new) = \ union { = \ @@ -96,6 +99,13 @@ */ #define KABI_BYTE_SIZE(fqn, value) __KABI_RULE(byte_size, fqn, value) =20 +/* + * KABI_TYPE_STRING(type, str) + * For the given type, override the type string used in symtypes + * output and version calculation with str. + */ +#define KABI_TYPE_STRING(type, str) ___KABI_RULE(type_string, type, str) + /* * KABI_RESERVE * Reserve some "padding" in a structure for use by LTS backports. diff --git a/scripts/gendwarfksyms/examples/kabi_ex.c b/scripts/gendwarfksy= ms/examples/kabi_ex.c index b73ee5399a59..1f799eb7c756 100644 --- a/scripts/gendwarfksyms/examples/kabi_ex.c +++ b/scripts/gendwarfksyms/examples/kabi_ex.c @@ -30,3 +30,8 @@ struct ex3b ex3b; struct ex3c ex3c; =20 struct ex4a ex4a; + +struct ex5a ex5a; +struct ex5b ex5b; + +int ex6a; diff --git a/scripts/gendwarfksyms/examples/kabi_ex.h b/scripts/gendwarfksy= ms/examples/kabi_ex.h index 092c8cb7bcd7..785b211d9c58 100644 --- a/scripts/gendwarfksyms/examples/kabi_ex.h +++ b/scripts/gendwarfksyms/examples/kabi_ex.h @@ -21,6 +21,12 @@ * ./gendwarfksyms --stable --dump-dies \ * examples/kabi_ex.o 2>&1 >/dev/null | \ * FileCheck examples/kabi_ex.h --check-prefix=3DSTABLE + + * $ nm examples/kabi_ex.o | awk '{ print $NF }' | \ + * ./gendwarfksyms --stable --dump-versions \ + * examples/kabi_ex.o 2>&1 >/dev/null | \ + * sort | \ + * FileCheck examples/kabi_ex.h --check-prefix=3DVERSIONS */ =20 #ifndef __KABI_EX_H__ @@ -170,7 +176,7 @@ struct ex2a { /* * STABLE: variable structure_type ex2a { * STABLE-NEXT: member base_type int byte_size(4) encoding(5) a data_mem= ber_location(0) , - * STABLE-NEXT: member base_type [[ULONG:long unsigned int|unsigned long= ]] byte_size(8) encoding(7) b data_member_location(8) + * STABLE-NEXT: member base_type [[ULONG]] byte_size(8) encoding(7) b da= ta_member_location(8) * STABLE-NEXT: member base_type int byte_size(4) encoding(5) c data_mem= ber_location(16) , * STABLE-NEXT: member base_type [[ULONG]] byte_size(8) encoding(7) d da= ta_member_location(24) * STABLE-NEXT: } byte_size(32) @@ -227,7 +233,7 @@ struct ex3a { =20 /* * STABLE: variable structure_type ex3a { - * STABLE-NEXT: member base_type [[ULONG:long unsigned int|unsigned long= ]] byte_size(8) encoding(7) a data_member_location(0) + * STABLE-NEXT: member base_type [[ULONG]] byte_size(8) encoding(7) a da= ta_member_location(0) * STABLE-NEXT: member base_type [[ULONG]] byte_size(8) encoding(7) unus= ed data_member_location(8) * STABLE-NEXT: } byte_size(16) */ @@ -282,4 +288,73 @@ KABI_BYTE_SIZE(ex4a, 8); * STABLE-NEXT: } byte_size(8) */ =20 +/* + * Example: A type string override. + */ + +struct ex5a { + unsigned long a; +}; + +/* + * This may be safe if the structure is fully opaque to modules, even thou= gh + * its definition has inadvertently become part of the ABI. + */ +KABI_TYPE_STRING( + "s#ex5a", + "structure_type ex5a { member pointer_type { s#ex4a } byte_size(8) p data= _member_location(0) } byte_size(8)"); + +/* + * Make sure the fully expanded type string includes ex4a. + * + * VERSIONS: ex5a variable structure_type ex5a { + * VERSIONS-SAME: member pointer_type { + * VERSIONS-SAME: structure_type ex4a { + * VERSIONS-SAME: member base_type [[ULONG:long unsigned int|unsigne= d long]] byte_size(8) encoding(7) a data_member_location(0) + * VERSIONS-SAME: } byte_size(8) + * VERSIONS-SAME: } byte_size(8) p data_member_location(0) + * VERSIONS-SAME: } byte_size(8) + */ + +/* + * Example: A type string definition for a non-existent type. + */ + +struct ex5b { + unsigned long a; +}; + +/* Replace the type string for struct ex5b */ +KABI_TYPE_STRING( + "s#ex5b", + "structure_type ex5b { member pointer_type { s#ex5c } byte_size(8) p data= _member_location(0) } byte_size(8)"); + +/* Define a type string for a non-existent struct ex5c */ +KABI_TYPE_STRING( + "s#ex5c", + "structure_type ex5c { member base_type int byte_size(4) encoding(5) n da= ta_member_location(0) } byte_size(8)"); + +/* + * Make sure the fully expanded type string includes the definition for ex= 5c. + * + * VERSIONS: ex5b variable structure_type ex5b { + * VERSIONS-SAME: member pointer_type { + * VERSIONS-SAME: structure_type ex5c { + * VERSIONS-SAME: member base_type int byte_size(4) encoding(5) n da= ta_member_location(0) + * VERSIONS-SAME: } byte_size(8) + * VERSIONS-SAME: } byte_size(8) p data_member_location(0) + * VERSIONS-SAME: } byte_size(8) + */ + +/* + * Example: A type string override for a symbol. + */ + +KABI_TYPE_STRING("ex6a", "variable s#ex5c"); + +/* + * VERSIONS: ex6a variable structure_type ex5c { + * VERSIONS-SAME: member base_type int byte_size(4) encoding(5) n data_m= ember_location(0) + * VERSIONS-SAME: } byte_size(8) + */ #endif /* __KABI_EX_H__ */ diff --git a/scripts/gendwarfksyms/gendwarfksyms.h b/scripts/gendwarfksyms/= gendwarfksyms.h index 2db49c2ad50e..7dd03ffe0c5c 100644 --- a/scripts/gendwarfksyms/gendwarfksyms.h +++ b/scripts/gendwarfksyms/gendwarfksyms.h @@ -292,6 +292,7 @@ bool kabi_is_enumerator_ignored(const char *fqn, const = char *field); bool kabi_get_enumerator_value(const char *fqn, const char *field, unsigned long *value); bool kabi_is_declonly(const char *fqn); +bool kabi_get_type_string(const char *type, const char **str); =20 void kabi_read_rules(int fd); void kabi_free(void); diff --git a/scripts/gendwarfksyms/kabi.c b/scripts/gendwarfksyms/kabi.c index 61620ff647bd..b3ade713778f 100644 --- a/scripts/gendwarfksyms/kabi.c +++ b/scripts/gendwarfksyms/kabi.c @@ -61,12 +61,20 @@ */ #define KABI_RULE_TAG_BYTE_SIZE "byte_size" =20 +/* + * Rule: type_string + * - For the type reference in the fqn field, use the type string + * in the value field. + */ +#define KABI_RULE_TAG_TYPE_STRING "type_string" + enum kabi_rule_type { KABI_RULE_TYPE_UNKNOWN, KABI_RULE_TYPE_DECLONLY, KABI_RULE_TYPE_ENUMERATOR_IGNORE, KABI_RULE_TYPE_ENUMERATOR_VALUE, KABI_RULE_TYPE_BYTE_SIZE, + KABI_RULE_TYPE_TYPE_STRING, }; =20 #define RULE_HASH_BITS 7 @@ -139,6 +147,10 @@ void kabi_read_rules(int fd) .type =3D KABI_RULE_TYPE_BYTE_SIZE, .tag =3D KABI_RULE_TAG_BYTE_SIZE, }, + { + .type =3D KABI_RULE_TYPE_TYPE_STRING, + .tag =3D KABI_RULE_TAG_TYPE_STRING, + }, }; =20 if (!stable) @@ -333,6 +345,19 @@ bool kabi_get_byte_size(const char *fqn, unsigned long= *value) return false; } =20 +bool kabi_get_type_string(const char *type, const char **str) +{ + struct rule *rule; + + rule =3D find_rule(KABI_RULE_TYPE_TYPE_STRING, type); + if (rule) { + *str =3D rule->value; + return true; + } + + return false; +} + void kabi_free(void) { struct hlist_node *tmp; diff --git a/scripts/gendwarfksyms/types.c b/scripts/gendwarfksyms/types.c index 6f37289104ff..0702569ff58c 100644 --- a/scripts/gendwarfksyms/types.c +++ b/scripts/gendwarfksyms/types.c @@ -100,7 +100,7 @@ static void type_expansion_append(struct type_expansion= *type, const char *s, #define TYPE_HASH_BITS 12 static HASHTABLE_DEFINE(type_map, 1 << TYPE_HASH_BITS); =20 -static int type_map_get(const char *name, struct type_expansion **res) +static int __type_map_get(const char *name, struct type_expansion **res) { struct type_expansion *e; =20 @@ -114,11 +114,12 @@ static int type_map_get(const char *name, struct type= _expansion **res) return -1; } =20 -static void type_map_add(const char *name, struct type_expansion *type) +static struct type_expansion *type_map_add(const char *name, + struct type_expansion *type) { struct type_expansion *e; =20 - if (type_map_get(name, &e)) { + if (__type_map_get(name, &e)) { e =3D xmalloc(sizeof(struct type_expansion)); type_expansion_init(e); e->name =3D xstrdup(name); @@ -130,7 +131,7 @@ static void type_map_add(const char *name, struct type_= expansion *type) } else { /* Use the longest available expansion */ if (type->len <=3D e->len) - return; + return e; =20 type_list_free(&e->expanded); =20 @@ -148,6 +149,34 @@ static void type_map_add(const char *name, struct type= _expansion *type) type_list_write(&e->expanded, stderr); checkp(fputs("\n", stderr)); } + + return e; +} + +static void type_parse(const char *name, const char *str, + struct type_expansion *type); + +static int type_map_get(const char *name, struct type_expansion **res) +{ + struct type_expansion type; + const char *override; + + if (!__type_map_get(name, res)) + return 0; + + /* + * If die_map didn't contain a type, we might still have + * a type_string kABI rule that defines it. + */ + if (stable && kabi_get_type_string(name, &override)) { + type_expansion_init(&type); + type_parse(name, override, &type); + *res =3D type_map_add(name, &type); + type_expansion_free(&type); + return 0; + } + + return -1; } =20 static void type_map_write(FILE *file) @@ -267,15 +296,18 @@ static char *get_type_name(struct die *cache) return name; } =20 -static void __calculate_version(struct version *version, struct list_head = *list) +static void __calculate_version(struct version *version, + struct type_expansion *type) { struct type_list_entry *entry; struct type_expansion *e; =20 /* Calculate a CRC over an expanded type string */ - list_for_each_entry(entry, list, list) { + list_for_each_entry(entry, &type->expanded, list) { if (is_type_prefix(entry->str)) { - check(type_map_get(entry->str, &e)); + if (type_map_get(entry->str, &e)) + error("unknown type reference to '%s' when expanding '%s'", + entry->str, type->name); =20 /* * It's sufficient to expand each type reference just @@ -285,7 +317,7 @@ static void __calculate_version(struct version *version= , struct list_head *list) version_add(version, entry->str); } else { cache_mark_expanded(&expansion_cache, e); - __calculate_version(version, &e->expanded); + __calculate_version(version, e); } } else { version_add(version, entry->str); @@ -293,10 +325,11 @@ static void __calculate_version(struct version *versi= on, struct list_head *list) } } =20 -static void calculate_version(struct version *version, struct list_head *l= ist) +static void calculate_version(struct version *version, + struct type_expansion *type) { version_init(version); - __calculate_version(version, list); + __calculate_version(version, type); cache_free(&expansion_cache); } =20 @@ -372,9 +405,81 @@ static void type_expand(struct die *cache, struct type= _expansion *type, cache_free(&expansion_cache); } =20 +static void type_parse(const char *name, const char *str, + struct type_expansion *type) +{ + char *fragment; + size_t start =3D 0; + size_t end; + size_t pos; + + if (!*str) + error("empty type string override for '%s'", name); + + type_expansion_init(type); + + for (pos =3D 1; str[pos]; ++pos) { + bool empty; + char marker =3D ' '; + + if (!is_type_prefix(&str[pos - 1])) + continue; + + end =3D pos + 1; + + /* + * Find the end of the type reference. If the type name contains + * spaces, it must be in single quotes. + */ + if (str[end] =3D=3D '\'') { + marker =3D '\''; + ++end; + } + while (str[end] && str[end] !=3D marker) + ++end; + + /* Check that we have a non-empty type name */ + if (marker =3D=3D '\'') { + if (str[end] !=3D marker) + error("incomplete %c# type reference for '%s' (string : '%s')", + str[pos - 1], name, str); + empty =3D end =3D=3D pos + 2; + ++end; + } else { + empty =3D end =3D=3D pos + 1; + } + if (empty) + error("empty %c# type name for '%s' (string: '%s')", + str[pos - 1], name, str); + + /* Append the part of the string before the type reference */ + if (pos > start + 1) { + fragment =3D xstrndup(&str[start], pos - start - 1); + type_expansion_append(type, fragment, fragment); + } + + /* + * Append the type reference -- note that if the reference + * is invalid, i.e. points to a non-existent type, we will + * print out an error when calculating versions. + */ + fragment =3D xstrndup(&str[pos - 1], end - pos + 1); + type_expansion_append(type, fragment, fragment); + + pos =3D start =3D end; + if (!str[pos]) + break; + } + + /* Append the rest of the type string, if there's any left */ + if (str[start]) + type_expansion_append(type, &str[start], NULL); +} + static void expand_type(struct die *cache, void *arg) { struct type_expansion type; + const char *override; char *name; =20 if (cache->mapped) @@ -399,9 +504,13 @@ static void expand_type(struct die *cache, void *arg) return; =20 debug("%s", name); - type_expand(cache, &type, true); - type_map_add(name, &type); =20 + if (stable && kabi_get_type_string(name, &override)) + type_parse(name, override, &type); + else + type_expand(cache, &type, true); + + type_map_add(name, &type); type_expansion_free(&type); free(name); } @@ -410,6 +519,7 @@ static void expand_symbol(struct symbol *sym, void *arg) { struct type_expansion type; struct version version; + const char *override; struct die *cache; =20 /* @@ -423,11 +533,14 @@ static void expand_symbol(struct symbol *sym, void *a= rg) if (__die_map_get(sym->die_addr, DIE_SYMBOL, &cache)) return; /* We'll warn about missing CRCs later. */ =20 - type_expand(cache, &type, false); + if (stable && kabi_get_type_string(sym->name, &override)) + type_parse(sym->name, override, &type); + else + type_expand(cache, &type, false); =20 /* If the symbol already has a version, don't calculate it again. */ if (sym->state !=3D SYMBOL_PROCESSED) { - calculate_version(&version, &type.expanded); + calculate_version(&version, &type); symbol_set_crc(sym, version.crc); debug("%s =3D %lx", sym->name, version.crc); =20 --=20 2.49.0.906.g1f30a19c02-goog From nobody Sat Feb 7 17:19:48 2026 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1C672D026D for ; Wed, 30 Apr 2025 21:41:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746049263; cv=none; b=id0UTv2qbZPM9u/RyeA6xBx1y0gSpbhxO5SgnAiR+npmRDk44Bx4tqwJJvB1dAq1CvnnpwCQIKS79OPK/JWf3oN28c+2qafb2lDM+rz1eg+bIsGG0r4WcGSOil/QDv3FEErsl640/3dLeCoOCAGsZGnu8LlSFurs5Gqcgecel1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746049263; c=relaxed/simple; bh=BXxzO4skt6xJol8bYXVYkap2MgomdSVnQvJsmZd5Rv4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=k7D6i9iqb4UtpBuQ5vX7aZ6RdGG4Ltu68yxbEMLZs9eTuxepsZMV3J9z0T5nTpX4WipRi38eK2g3Ow6ArHAb1MqJTWvlmgv55IiJ5OVnwQ2rBqVSnBU6gb3qWDDF5LzJ1Y/mQR7g/50iVvZ87tBq7HqSAQuLLuIpYCaYVRXTqYg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--samitolvanen.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=i3EOgRSu; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--samitolvanen.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="i3EOgRSu" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-22650077995so4278215ad.3 for ; Wed, 30 Apr 2025 14:41:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1746049261; x=1746654061; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=2CKngrC6O9cGcVCCxaaxP3YTy+M2SG0vauU8yNbnhDM=; b=i3EOgRSufBc/N5ThQuZ5iT154iaFRHxunyWoD6+bPGsfaIjwvndU7BZCXVD/QMqzes VqR5Vj7Nyd9Qqggvjtg3oegkZGIJ+66iaCzQHuIeJxCv7x+TdTFLBZ+ZQ9gTHOl0S89C bb94zg6vaqo9dPM92VpXFw/bw1Vyd/MdB5amNOYk7jJux+tsZLy9EPI/r2D7r6p2Utfz iRQbFZu/9f98Rx/bEixN62N0aqKX7DshPu5rWy4xyy9Un1AN04wIeuWKTYXQoJwKRprf O3nH5ESnC1flnx2X8fXJujCoIXMgJ+TEWvTVBC2t+vAGJuWhP3Z2oO6eV756eyyc2Gci Aepg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746049261; x=1746654061; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2CKngrC6O9cGcVCCxaaxP3YTy+M2SG0vauU8yNbnhDM=; b=baKqKgtxAMRKltbyZfhzzRfa0HwVGXtB/lhjw7fkEtqD6620zGAX9+HovQrZM/RH3g /bIy0HGdBqoFb4FNhQJX5m0YxUrXxe8RvB6vpK3Pc7q5sYNSBOdp9MJCvOBZydxWOjs0 3CoNpKzPI/Rx+PriRvo3abRIudk4w/pxpH/dFXFsP+PGEazHIOhHVcdJf2v6VNN61ylC H0eF7B2mJ06qW3flcSDVpfyT4uBhZJqJ1WKZBWkdW0X9kapJkZ3ZubFzWvPMd3bBPvCp E7w+OUaZRdd/gM/2V9H30qE+RMRlVK/CPqUb0RTYfmWxGiPHWf68PEgUTGp36wB/9/kI 876A== X-Forwarded-Encrypted: i=1; AJvYcCWaHw0GQ6LvpOgSc8WfxptpgXScAJi26j6AD4TfX1hKnLS6NA8sboK9kNdYAbbAkYQVVI9hyS3k7ZUZN+g=@vger.kernel.org X-Gm-Message-State: AOJu0YwOGi4sri9Jzw6hU2xnZrjmPgJufduMn+m12Y7qjL8WSGmrlW/j 1HIoejiWwO4Fk9CEdRkG31vNrlyjrGu85DikO6otx6WXf2BMt8PJPbi4D8dI/eksAlEueLEQ8w6 udszeFyPXfCW54fgq4u2s29OPLA== X-Google-Smtp-Source: AGHT+IETLi4YUB9i3nzd3B7QsdSWK9DWkyN6lL+7n7jW5K1EkSKzr6FtERyyusMh4VkNLRFF1ZSS0b66BdWXyA6THqM= X-Received: from pll21.prod.google.com ([2002:a17:902:c215:b0:223:6c8e:eaf1]) (user=samitolvanen job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:4407:b0:224:8bf:6d81 with SMTP id d9443c01a7336-22e04127919mr10994115ad.46.1746049261149; Wed, 30 Apr 2025 14:41:01 -0700 (PDT) Date: Wed, 30 Apr 2025 21:40:54 +0000 In-Reply-To: <20250430214049.2658716-6-samitolvanen@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250430214049.2658716-6-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=5930; i=samitolvanen@google.com; h=from:subject; bh=BXxzO4skt6xJol8bYXVYkap2MgomdSVnQvJsmZd5Rv4=; b=owGbwMvMwCEWxa662nLh8irG02pJDBlCMx5L2m+O0vn6QC11ve2dbb5Sd9Vef4ss0pZaZnfww 47frSpvO0pZGMQ4GGTFFFlavq7euvu7U+qrz0USMHNYmUCGMHBxCsBELmcxMlxZOVv5iVGJ59kZ H693pRRfjF1hXKdzLvP+Yh2Lot0z5bYx/E/co1qW9LmpM79BQHUru7xa2MX3N65OrxM81/efnef aNHYA X-Mailer: git-send-email 2.49.0.906.g1f30a19c02-goog Message-ID: <20250430214049.2658716-10-samitolvanen@google.com> Subject: [PATCH 4/4] Documentation/kbuild: Add new gendwarfksyms kABI rules From: Sami Tolvanen To: Masahiro Yamada Cc: Luis Chamberlain , Petr Pavlu , Daniel Gomez , linux-modules@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Sami Tolvanen Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Document byte_size and type_string kABI stability rules. Also fix the section numbers while we're at it. Signed-off-by: Sami Tolvanen --- Documentation/kbuild/gendwarfksyms.rst | 103 +++++++++++++++++++++++-- 1 file changed, 95 insertions(+), 8 deletions(-) diff --git a/Documentation/kbuild/gendwarfksyms.rst b/Documentation/kbuild/= gendwarfksyms.rst index e4beaae7e456..8b0d7ebbb084 100644 --- a/Documentation/kbuild/gendwarfksyms.rst +++ b/Documentation/kbuild/gendwarfksyms.rst @@ -125,14 +125,17 @@ the rules. The fields are as follows: qualified name of the DWARF Debugging Information Entry (DIE). - `value`: Provides rule-specific data. =20 -The following helper macro, for example, can be used to specify rules +The following helper macros, for example, can be used to specify rules in the source code:: =20 - #define __KABI_RULE(hint, target, value) \ - static const char __PASTE(__gendwarfksyms_rule_, \ + #define ___KABI_RULE(hint, target, value) \ + static const char __PASTE(__gendwarfksyms_rule_, \ __COUNTER__)[] __used __aligned(1) \ __section(".discard.gendwarfksyms.kabi_rules") =3D \ - "1\0" #hint "\0" #target "\0" #value + "1\0" #hint "\0" target "\0" value + + #define __KABI_RULE(hint, target, value) \ + ___KABI_RULE(hint, #target, #value) =20 =20 Currently, only the rules discussed in this section are supported, but @@ -223,7 +226,88 @@ Example usage:: KABI_ENUMERATOR_IGNORE(e, C); KABI_ENUMERATOR_VALUE(e, LAST, 2); =20 -4.3. Adding structure members +4.1.3. Managing structure size changes +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +A data structure can be partially opaque to modules if its allocation is +handled by the core kernel, and modules only need to access some of its +members. In this situation, it's possible to append new members to the +structure without breaking the ABI, as long as the layout for the original +members remains unchanged. + +To append new members, we can hide them from symbol versioning as +described in section :ref:`Hiding members `, but we can't +hide the increase in structure size. The `byte_size` rule allows us to +override the structure size used for symbol versioning. + +The rule fields are expected to be as follows: + +- `type`: "byte_size" +- `target`: The fully qualified name of the target data structure + (as shown in **--dump-dies** output). +- `value`: A positive decimal number indicating the structure size + in bytes. + +Using the `__KABI_RULE` macro, this rule can be defined as:: + + #define KABI_BYTE_SIZE(fqn, value) \ + __KABI_RULE(byte_size, fqn, value) + +Example usage:: + + struct s { + /* Unchanged original members */ + unsigned long a; + void *p; + + /* Appended new members */ + KABI_IGNORE(0, unsigned long n); + }; + + KABI_BYTE_SIZE(s, 16); + +4.1.4. Overriding type strings +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D + +In rare situations where distributions must make significant changes to +otherwise opaque data structures that have inadvertently been included +in the published ABI, keeping symbol versions stable using the more +targeted kABI rules can become tedious. The `type_string` rule allows us +to override the full type string for a type or a symbol, and even add +types for versioning that no longer exist in the kernel. + +The rule fields are expected to be as follows: + +- `type`: "type_string" +- `target`: The fully qualified name of the target data structure + (as shown in **--dump-dies** output) or symbol. +- `value`: A valid type string (as shown in **--symtypes**) output) + to use instead of the real type. + +Using the `__KABI_RULE` macro, this rule can be defined as:: + + #define KABI_TYPE_STRING(type, str) \ + ___KABI_RULE("type_string", type, str) + +Example usage:: + + /* Override type for a structure */ + KABI_TYPE_STRING("s#s", + "structure_type s { " + "member base_type int byte_size(4) " + "encoding(5) n " + "data_member_location(0) " + "} byte_size(8)"); + + /* Override type for a symbol */ + KABI_TYPE_STRING("my_symbol", "variable s#s"); + +The `type_string` rule should be used only as a last resort if maintaining +a stable symbol versions cannot be reasonably achieved using other +means. Overriding a type string increases the risk of actual ABI breakages +going unnoticed as it hides all changes to the type. + +4.2. Adding structure members =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D =20 Perhaps the most common ABI compatible change is adding a member to a @@ -237,7 +321,7 @@ natural method. This section describes gendwarfksyms su= pport for using reserved space in data structures and hiding members that don't change the ABI when calculating symbol versions. =20 -4.3.1. Reserving space and replacing members +4.2.1. Reserving space and replacing members =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 Space is typically reserved for later use by appending integer types, or @@ -276,7 +360,9 @@ The examples include `KABI_(RESERVE|USE|REPLACE)*` macr= os that help simplify the process and also ensure the replacement member is correctly aligned and its size won't exceed the reserved space. =20 -4.3.2. Hiding members +.. _hiding_members: + +4.2.2. Hiding members =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 Predicting which structures will require changes during the support @@ -305,4 +391,5 @@ member to a union where one of the fields has a name st= arting with unsigned long b; }; =20 -With **--stable**, both versions produce the same symbol version. +With **--stable**, both versions produce the same symbol version. The +examples include a `KABI_IGNORE` macro to simplify the code. --=20 2.49.0.906.g1f30a19c02-goog