From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 0F0614859F for ; Fri, 8 Dec 2023 10:00:32 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 731EF68D002; Fri, 8 Dec 2023 12:00:29 +0200 (EET) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2049.outbound.protection.outlook.com [40.92.89.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3C38868CD3F for ; Fri, 8 Dec 2023 12:00:23 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Eg/LJ91N1t2ooaFPl9O5vM6rPgv7ezEnANM7O4gTLtIjqr9c6yXSuofbk5cB8EMfi4zYc7wGJ2eJELIA7aUIJZ9snR9VPMPODZhTjjqGHn7oRP2QAxleQr17fjLto8U3Q0XlBwYHWYrPUINqQpMzPTloyTTvsVZNNaNpJ6Nxj7I1Naq3zHEWt4UuY6xy5tupeg+Ya7xRDsxqa6mv3yBcycreZyrIS7DUqFHRp7Rx3CTf2HmhCHicnkcqeLjfsU1iVweMFTuMPWxVOxVleqrZNmQ/5gNPd/La3lvpeDQtp4TXI9Gikpna1NMB2rJzlQwbQl6bzGxbV6KLSUdebGgT5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Jq97hMaffh+NLMJEivpyE4KMliC38pEIclOfjfMHA+4=; b=fNhNTXXqeL3OAAGQeqcvuAlW2Fse/mEgYQZTXVvVdPnBwQHnzkAyGmT/Ye1/cVlThAe4kiIUW7irOSKMfGfCKqmAb5w9VgNGZMdlHh8mMNkJbo0F+XhaHLIOp+aFpADVbK4vAuVet+eVA9dninWoC5coIRMa+yaj2+uL16GJJTFTmoW1oJche6nLOCbxjiaex4Ms5i15gKCOGheUfimKiM4AFKwH+376O7ykVGFOigmfbE8YIGRTW7S1noP9QUKthd8+NHMsDXjTFNS2ABdBUDT0N/oSLBzy+z+H8sJhUBPVBQhR2rvtaQTFTvdmC/alhKtmQgedLCjYdlj3PchpHw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Jq97hMaffh+NLMJEivpyE4KMliC38pEIclOfjfMHA+4=; b=GzQOJjjoEbD21xmHdunCAhU7BnQ4zAe50rpe7Jm/r4045ZhwLMmDjsshkawfBpWCtLuY8aHc7zan0X80rd66Wg3JxNNFE6Fs6fdtAiQ0GNKTQZVVevhIhcuqywpT/auKeowpUjs9LQXwSSLkj1IFxE71Sznhxtig0WuXOx+d4GEa2lg1C50BLaxH/e7MIdairwBNWbfEZttbC5wbvJrMqYnXn6ZIdjG9OWrbMALRHapKlLMK0C4LXSyHdHYVCdafxFUtvu5Y8+RIgOVsQFT99zPKhQqxSRk8Vt2lXTDyhBiBSFvvEbQRJzxvyXHqwzR0S3OoMc+t72vI9RcJF2QWzw== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by PR3P250MB0097.EURP250.PROD.OUTLOOK.COM (2603:10a6:102:170::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.28; Fri, 8 Dec 2023 10:00:20 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::f59c:9cff:a42d:bde]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::f59c:9cff:a42d:bde%3]) with mapi id 15.20.7068.028; Fri, 8 Dec 2023 10:00:20 +0000 Message-ID: Date: Fri, 8 Dec 2023 11:01:51 +0100 User-Agent: Mozilla Thunderbird To: ffmpeg-devel@ffmpeg.org References: <20231203201027.2255-1-timo@rothenpieler.org> Content-Language: en-US From: Andreas Rheinhardt In-Reply-To: <20231203201027.2255-1-timo@rothenpieler.org> X-TMN: [aoIny/WlLjRDpoluNqwf9Cj7LMGmMCpjwuRPH3a+XKs=] X-ClientProxiedBy: ZR2P278CA0085.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:65::7) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|PR3P250MB0097:EE_ X-MS-Office365-Filtering-Correlation-Id: 759873ba-ce65-468a-2f09-08dbf7d47c4f X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WoDSvBoc3hsriDX5ImvPRz4aPpIkD2nqpzPGzgB9XDunwBYwrgPq7AlOOWcpElWqtbWHn7qqTIxuv5Y4/yCWwPoSyYgoyxCzio53jwIV2t6fSzUtgppHL6fmgV1cTMFq4UtZWKJABR/1nqZ/bimGB7Re+nWUZX9y+461lVv5wuovDfhsz1O11DTpTGefeNIl/qSmL9waDIfFMiFW14cq3Ty+rj0ay6c8eT3aV7NrDO0+rCUVXRxbXORFQzeA9evC6KLRc1mYdoodsOAZSjHZzxyr2sZFf4Tphf6DcRi/TE/WGOkj6C7gWoTB145Rmt8i+SbMW8qJj9xfPCzp501rIb6bEj4vuFY16yV/gmuFSFJBeXEfR+caKgxRqbw6AgmBcSmF8MerVX5VY8zY3eR8hEf2zutmyj54GyXCtjsiNcgOiGKmmxB19xIi8BJ0Nvmn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a241a3owMUlVSWdvMVY4aWNqbXZ1YW9GS29WcnRpWjBYMkhCM1p5VnEySlB0?= =?utf-8?Q?I4bMtvy3s3UIXt0CH2q2?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 759873ba-ce65-468a-2f09-08dbf7d47c4f X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2023 10:00:19.9982 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3P250MB0097 Subject: Re: [FFmpeg-devel] [PATCH] avutil/mem: always align by at least 32 bytes X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Timo Rothenpieler: > FFmpeg has instances of DECLARE_ALIGNED(32, ...) in a lot of structs, > which then end up heap-allocated. > By declaring any variable in a struct, or tree of structs, to be 32 byte > aligned, it allows the compiler to safely assume the entire struct > itself is also 32 byte aligned. > > This might make the compiler emit code which straight up crashes or > misbehaves in other ways, and at least in one instances is now > documented to actually do (see ticket 10549 on trac). > The issue there is that an unrelated variable in SingleChannelElement is > declared to have an alignment of 32 bytes. So if the compiler does a copy > in decode_cpe() with avx instructions, but ffmpeg is built with > --disable-avx, this results in a crash, since the memory is only 16 byte > aligned. > Mind you, even if the compiler does not emit avx instructions, the code > is still invalid and could misbehave. It just happens not to. Declaring > any variable in a struct with a 32 byte alignment promises 32 byte > alignment of the whole struct to the compiler. > > Instead of now going through all instances of variables in structs > being declared as 32 byte aligned, this patch bumps the minimum alignment > to 32 bytes. > --- > libavutil/mem.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/libavutil/mem.c b/libavutil/mem.c > index 36b8940a0c..26a9b9753b 100644 > --- a/libavutil/mem.c > +++ b/libavutil/mem.c > @@ -62,7 +62,7 @@ void free(void *ptr); > > #endif /* MALLOC_PREFIX */ > > -#define ALIGN (HAVE_AVX512 ? 64 : (HAVE_AVX ? 32 : 16)) > +#define ALIGN (HAVE_AVX512 ? 64 : 32) > > /* NOTE: if you want to override these functions with your own > * implementations (not recommended) you have to link libav* as 1. There is another way in which this can be triggered: Namely if one uses a build with AVX, but combines it with a lavu built without it; it is also triggerable on non-x86 (having an insufficiently aligned pointer is always UB even if the CPU does not have instructions that would benefit from the additional alignment). You should mention this in the commit message. 2. This topic gave me headaches when creating RefStruct. I "solved" it by (ab)using STRIDE_ALIGN which mimicks the alignment of av_malloc(), thereby ensuring that RefStruct does not break lavc builds built with the avx dsp functions enabled (but it does not guard against using a lavu whose av_malloc() only provides less alignment). 3. There is a downside to your patch: It bumps alignment for non-x86 arches which wastes memory (and may make allocators slower). We could fix this by modifying the 32-byte-alignment macros to only provide 16 byte alignment if the ARCH_ (and potentially the HAVE_) defines indicate that no alignment bigger than 16 is needed. - Andreas _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".