From nobody Thu Aug 10 18:14:03 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RMFRv6myLz4psLb; Thu, 10 Aug 2023 18:14:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RMFRv4vwGz4TLZ; Thu, 10 Aug 2023 18:14:03 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691691243; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Z/lDKXV7jrZlZg5I1kLWO5lmUvQ4sg/khjXaKHjfl0Q=; b=rHxkk5rEkXL2RimsALL4f9z044s/YNybqIfsHbY0I21mjVoIXW5auuCsUB8YUNUFNDpK5C Bew06Oh/1FCl9L/rwR0OSyVzkdKLEk/71umtnAG8WI63BQ4LvKs/OBZUDbXn8SJHTNd7Is OWUWQXUrUzeR8KVP9TsQt3DfgM6wmFYXXXHDr7SQoTfRr47PJdwUtEAy1FQYgE6GZ4ufcy HhSbRcJqEg/cBHYp2QuIYAzaMiE6myaYkVBtMV8C8vUNxHw6jFHsbxkUcp1qD7/825i2oB OmBIFhxwSXZtiqwVtgw09jmS0QJJvSuAcz9ku+7oDKtYACjW1AFvDohxNBTx0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691691243; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Z/lDKXV7jrZlZg5I1kLWO5lmUvQ4sg/khjXaKHjfl0Q=; b=wHewvByJTwsm9fH2QXcD/zf5cfYjspXai6+UJD71xjaORFXdW/NdnxoQ7H9ehPIGcKrDma 1+MuoeCiXi2n1gDjP3fYqCQMAdYVDDisuTlG64+4SlCj2o3AtzIUfDhlzbjHAEsOOXwIiU nYr5AjbB8UirkFGbllX9UJDY4SgpRt5F0E5AWpRuX9zR/3Ofof1D1oSjC8FUUAd1FRQuS4 ByCq0L4WztQsCjNN1w5OlnDkDCDASWA8Vvi9GfBXaUgwQRGE14DBY7SRXN2ouZ4YwC+XfM NdxgE/BSddOIpSia3ofO+lHv6JEPSG8meqUHpU+pfaN0NU2tMVZ05Am8JHsJDw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1691691243; a=rsa-sha256; cv=none; b=me5jrln5I0zKbwgkidp3l60hnRW6NI+GUc+tnqH8eoFhHPubaD6y6qrRSnDnL980GTDUa1 Do8qRR/HA6/TLm+1qfuFtb+q12tJJX0DmmqhZKyO9XYjuNroZQytiQrWr0uxHIBUw7EEtV +nKUZ4dHia8WF0i8kqYieJ1d1PYiMRtzF62bj+z0BdST1M0fQrXX/PEJumkhC6LjxibtIi kXhebYZPUg7u4XrWGl5Z6eRLVWDljdfOguRt3Bj/MAIkwR3VnUWX69vkR8gZk+keWf2Vnd 0wJwmfb/nxxuXZz7r4pdkgMLVz5Vvwc4FLaTchrvamHI2Y3OKNHF2Jq0AbWHQw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RMFRv40jLz16Tg; Thu, 10 Aug 2023 18:14:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 37AIE3kR010379; Thu, 10 Aug 2023 18:14:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37AIE3gK010376; Thu, 10 Aug 2023 18:14:03 GMT (envelope-from git) Date: Thu, 10 Aug 2023 18:14:03 GMT Message-Id: <202308101814.37AIE3gK010376@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 9795f14ec40a - main - netlink: Align allocations on __max_align_t, not uint64_t. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9795f14ec40acbab93aabedf05d70e0256ce9bf5 Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=9795f14ec40acbab93aabedf05d70e0256ce9bf5 commit 9795f14ec40acbab93aabedf05d70e0256ce9bf5 Author: John Baldwin AuthorDate: 2023-08-10 18:12:52 +0000 Commit: John Baldwin CommitDate: 2023-08-10 18:12:52 +0000 netlink: Align allocations on __max_align_t, not uint64_t. uint64_t is not sufficient alignment for allocators on all platforms. On a CHERI platform pointers require 16 byte alignment, but also if a type contained a uint128_t or long double it would not be aligned correctly either. C11 added max_align_t precisely to provide a portable type for allocators to use. Reviewed by: melifaro Obtained from: CheriBSD Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D41301 --- sys/netlink/netlink_message_parser.h | 4 ++-- sys/netlink/netlink_snl.h | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/sys/netlink/netlink_message_parser.h b/sys/netlink/netlink_message_parser.h index 0934057ac49f..0242177fdd26 100644 --- a/sys/netlink/netlink_message_parser.h +++ b/sys/netlink/netlink_message_parser.h @@ -41,12 +41,12 @@ struct linear_buffer { char *base; /* Base allocated memory pointer */ uint32_t offset; /* Currently used offset */ uint32_t size; /* Total buffer size */ -}; +} __aligned(_Alignof(__max_align_t)); static inline void * lb_alloc(struct linear_buffer *lb, int len) { - len = roundup2(len, sizeof(uint64_t)); + len = roundup2(len, _Alignof(__max_align_t)); if (lb->offset + len > lb->size) return (NULL); void *data = (void *)(lb->base + lb->offset); diff --git a/sys/netlink/netlink_snl.h b/sys/netlink/netlink_snl.h index 0292725bd135..8bb7b076b7b7 100644 --- a/sys/netlink/netlink_snl.h +++ b/sys/netlink/netlink_snl.h @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -74,7 +75,7 @@ struct linear_buffer { uint32_t offset; /* Currently used offset */ uint32_t size; /* Total buffer size */ struct linear_buffer *next; /* Buffer chaining */ -}; +} __aligned(alignof(__max_align_t)); static inline struct linear_buffer * lb_init(uint32_t size) @@ -98,7 +99,7 @@ lb_free(struct linear_buffer *lb) static inline char * lb_allocz(struct linear_buffer *lb, int len) { - len = roundup2(len, sizeof(uint64_t)); + len = roundup2(len, alignof(__max_align_t)); if (lb->offset + len > lb->size) return (NULL); void *data = (void *)(lb->base + lb->offset);