From patchwork Mon Oct 4 14:32:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30896 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6506:0:0:0:0:0 with SMTP id z6csp4379222iob; Mon, 4 Oct 2021 07:33:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyYIV2krSBc2AQaLa74ipSYDJNFWZQ6ayjYSbSDzwtrFQOCxuBkS043jAf6A2hdhY+3MRd X-Received: by 2002:a05:6402:4d1:: with SMTP id n17mr19109388edw.337.1633358000828; Mon, 04 Oct 2021 07:33:20 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id i18si23392269edc.436.2021.10.04.07.33.19; Mon, 04 Oct 2021 07:33:20 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=ag8PKAkn; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B9F0D68A842; Mon, 4 Oct 2021 17:33:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-oln040092074096.outbound.protection.outlook.com [40.92.74.96]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7571A68A842 for ; Mon, 4 Oct 2021 17:33:09 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gCWDkB6RXfZkISi35nAb8U23V9lU1Vae752KimACUGoBLDOBtPVBce9Lt6tLk5n+ZqekFB2Y3QtsGFU+dIky8ffC8JzVPTNXEGstqF7o2FxLOYJIzxVCumTlaUWNjJLaO052tCzF4Lbay9L/G6nKsiYQZ/FMz9bGaZ1T14xnQTPYNS+5FtVjzrrYHUfX0tSMUaqDMt2yzSjAfk/38ydDUK9Bctzj8Nu5LurJo4gBXmBgZQCGL+47VkSJZ1PblDWss/6Si+s7nmqp2Qtnbff+YFuEA3EwJNVNP9wUNKBNp1wzdpWzawUBnvqvXBOcZ5M/SS4iLNr8I+s3LHyiNSUXqQ== 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=Ryt8n2KENNO01/tvEwH4Pway9Y+5KvtWZj93qvRMuYY=; b=TP/v2cWkXkU3hvTT42WqyURB5o05KODrYCV82ZrT8J/kqQmy/G+lHISTN+zc+yVkW0dEn+GHX9SBSdubr8WxH5/+8TeyYItUHQ4YlLpAx7Q6JxWZKY3kspF1KKpGPLcHb0/JeFBirQNgGtD2ojGut3i2F7gJusLxjP4lKivRrOY5+qsIar7Vv/+uKcruOEnJjS7qASIzGCgweEytNu0CHPZr/BTc92vAgLa8jSfDHov+F4IUNBNA+lswpBZLZsUQulpaQjH37vJqiNFjBJ3nH5XzgpNDKbPjQ7wFsfmSyQsNynPHYcgnLT6aiU7i9Y6p9gHd4XFRT9bgwTKgn9ck2Q== 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=Ryt8n2KENNO01/tvEwH4Pway9Y+5KvtWZj93qvRMuYY=; b=ag8PKAknO9m+GKdeBZCI/gUeOmnt0kS09MC+smFKA432sFEKXo8YOeMUo1NT7eBvFCF2GFuv2i3jX9D+/gnFUJtqBjsP8q4Lc0GuZrKv6YfCBpJjd+O+4l7AX6VR97Qw6WjCjMAerBUKjyJoSud7tOFcQdrdY3lXLYaMeIttUgKNpG2Jm3X04T/s+leoJZboI5WDos8IyfWiGKUz6qkrAFKjDrKFirKC7b5LO52gSVINVtfDEI2plM3TmG8reb+ssmLvjzHCnCWL+wV74sH7H3ML8SZFiI+5RZK8Ok5Mo5ahOoY5MzGA6yQ6Hf4xuS6MtAwk9U+o6XT7EQU3MsakYw== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM7PR03MB6433.eurprd03.prod.outlook.com (2603:10a6:20b:1b8::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.19; Mon, 4 Oct 2021 14:33:07 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::700f:d70b:3bb8:4d51]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::700f:d70b:3bb8:4d51%7]) with mapi id 15.20.4566.022; Mon, 4 Oct 2021 14:33:07 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 4 Oct 2021 16:32:56 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 X-TMN: [u1oAE9tRJkXBpPdcV6ib016xGs3B4nY/] X-ClientProxiedBy: AM5PR1001CA0038.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:206:15::15) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20211004143258.3984048-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM5PR1001CA0038.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:206:15::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14 via Frontend Transport; Mon, 4 Oct 2021 14:33:06 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 375db1f0-3572-4b5a-1a6b-08d98743e1a1 X-MS-Exchange-SLBlob-MailProps: f36zkjAOy3W26mEFCZoYm9EYgzQtB7wrZ/Z9F6QnAzX0ECmuhsIkUqvs4KD7uILoGrV3S6M3RU3usETtUOpmflmp5jRMDRlSxAL00mvRmpOB1uILOSUufccmy37Dq0PQ66G00NfOUKoH3VN30yUGC36yTtSgKCgvk0z0Yzv6MEQMxppwPrITAS9DSEIhMBH3T/kawk2Ch7VNn2tUqnXharR0q+L0bdloFTjo3rHWjeYcZSZDTYVdDRcuB9wYHfzgaTE7BLgJBpv8/Tu7tZPTh5SSSeZn0oUgHEEKhKbHHm16q/yRTjzpG/CJGEKqha9dPoZxEcookPA5dkbEgPbOsU9t5EGV/KF7bQ7xOPs4xa1pN+8poD2rJ3PKf+0zgheFeygJhThPKW5NhipKrp0lQF8CxZF+x8WmlhxpWdSOP0h5hvlhCzBXR2TMnBNX+7pvBYhA6z76knGAWUzzBSmsWpvgnYzNoP2bCECjJ/6+8QdwXWNIa6zgKlqpjjsv7NW/UdHT17IPWQ+CodddtSMnsFDT8/daQTJRsjwmpCLIVp3JumBbNsUM8BkrXJ71wVgcRu8cF0OCo7qNKpehOxBM6CAFBqZQPnRkVMiirXMHwFbGa+D0S/SJpkze9MK7ONsQ+b9a+zdlPp7XFyeXKURxKH3oNy6LxXvG4Kaqbrs8r5pE5oiFD5zBchaOc8HkY1/A0sQzW1yrIA0xU0ik9ToIXKqsTOEcedxPCVmdKl3pWHY= X-MS-TrafficTypeDiagnostic: AM7PR03MB6433: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YibiF80duflIXrVFPnUUV4FiA/R4LkxH+g85TDLiKhfCfIKy6hv9AfPHGnSPdjOI2IqzDmqkTj9ArF8FlX+sp8A+AaQAviJJAqNBO+zmrs8X3P7NCV6P2ipch0bonRhtVWIG6ixiOlYtIYcy/fgzHNdcz4eFcOqgSZkLfU/2Ig9/jDT7LpL9UQxQPjiV1x+1tVyRUIoVqKcM6njvEcPF5VXaYLVyNi1uN+t7LnViEfH9prkf5kxiY8UuUa5NYK3nFqbAYc6xgVKqGjTkRAFK0327oxVYnbZSnXUp8TV0j0RSDMqU8mwnYj3m06Vi7N7nK5N/Q51woYdn76MKHqGcKvfaKPSyVNdK+a/vea4MJdiYJePT8ndvGz08ur/yOkrbJSfo1Jr0wMM56+fmpAjYPrXQfme/4Q6AgCUIJTppajSl+lcVDhkBPeB5gDhiXR3/ X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rEwuyJhNVm/3wyWjfMaRwrXNJcOokMfvcpKEr8qhmzNyetEc4qiC2EWGpDEaoW/167sw86u0QZ1r5eJw88Ic+JANYjLqiDJYzc6ewSn+4ECW5Rew1iOfrDa0IImqZRBBH+OnFrK5MN02cVYEMi65qA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 375db1f0-3572-4b5a-1a6b-08d98743e1a1 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Oct 2021 14:33:07.5660 (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: AM7PR03MB6433 Subject: [FFmpeg-devel] [PATCH 1/3] avutil/hwcontext_vaapi: Abuse the AVBuffer API a bit less 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: gGCjTdj4l3mz In this case there is no underlying data at all; the actual data has been shoe-horned into the pointer, which does not point to any storage owned by us. So use a size of zero as buffer pool size. (This fixes segfaults if one uses vaapi with memory poisoning enabled; but the memset call in pool_release_buffer() still receives an invalid pointer, so it is still undefined behaviour.) Signed-off-by: Andreas Rheinhardt --- libavutil/hwcontext_vaapi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c index 83e542876d..3578d49da3 100644 --- a/libavutil/hwcontext_vaapi.c +++ b/libavutil/hwcontext_vaapi.c @@ -490,7 +490,7 @@ static AVBufferRef *vaapi_pool_alloc(void *opaque, size_t size) av_log(hwfc, AV_LOG_DEBUG, "Created surface %#x.\n", surface_id); ref = av_buffer_create((uint8_t*)(uintptr_t)surface_id, - sizeof(surface_id), &vaapi_buffer_free, + 0, &vaapi_buffer_free, hwfc, AV_BUFFER_FLAG_READONLY); if (!ref) { vaDestroySurfaces(hwctx->display, &surface_id, 1); @@ -593,7 +593,7 @@ static int vaapi_frames_init(AVHWFramesContext *hwfc) } hwfc->internal->pool_internal = - av_buffer_pool_init2(sizeof(VASurfaceID), hwfc, + av_buffer_pool_init2(0, hwfc, &vaapi_pool_alloc, NULL); if (!hwfc->internal->pool_internal) { av_log(hwfc, AV_LOG_ERROR, "Failed to create VAAPI surface pool.\n"); From patchwork Mon Oct 4 14:44:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30897 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6506:0:0:0:0:0 with SMTP id z6csp4390718iob; Mon, 4 Oct 2021 07:45:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqst8I+/pYgBrmNCPC4GYReIrwycDxYOU8VUjCL6cD5ZIr3DQUt8J0OuES/j1U212c/DlP X-Received: by 2002:a17:906:a0da:: with SMTP id bh26mr17403177ejb.505.1633358709348; Mon, 04 Oct 2021 07:45:09 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id q6si5391285edj.430.2021.10.04.07.45.08; Mon, 04 Oct 2021 07:45:09 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b="pZy2vUN/"; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id ED0BA68A776; Mon, 4 Oct 2021 17:45:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-oln040092067080.outbound.protection.outlook.com [40.92.67.80]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 91A0D68A776 for ; Mon, 4 Oct 2021 17:44:57 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kHG5+f7h97CNM3nrYr0X95OIvIsXImFrCxpqJYo5C3Ef3mCQ88VaqKgNavSzZu/pxgK55S4Ql03LyozLnX0ab44q/WtNsiCz5ivf9ypDCTSuZJW9gVNb79NBX+lajD8gRnaNkll7VdmyDlLs0Ut5CRfKslM4+fGE1dOhq4Kna6z3x3AwU+nEkdS+NriLSIe6muacUEdhzBJ85vO5Rwlz2BfuFwUk1DkXJpEUWP15iLrdxo229uB+VQYKhwGEFiONbB2WLE4UkXjOjIkWq11uBj0q84UnFPnYQt1py40XcHGtkwxyWZ7b81f6iGyeknH+tImEmw8c6ECKr4YhblwYMA== 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=yYwsXj9zijvggVnQDNjNnrocJd7b07cuJ96ZBLhMe5o=; b=VrJtSvt4o+FHRfXX/fGEgrE+yiV3FU9I8MOSIwc1j4hMmPAXz1vCkbEI6sCrHUrGN9cb5bpw457MtxDnHR+kFu4tiFEPcw1pBkbSrwUnUAmg9tZ5rFgzKRel4fWTym5XGY2Jj2Xgb+mAn2XkgIpOVlbKvsPsu2dDSOvYWm/R1Yck3ftieBire8FvW0nycalbsGePKPVcCKinj6blWEYWtNQLfsbIhhuvwJtaG96YHBaQbSY+IBX6A0awSMn3AXuGsz1cTSiLQTAk/cofF895F+3kfFGSS6ooX9lG45onBXYA3q59LM+w2qz3DOysp4ASAr1UMAaaTomYH+lbstGAXQ== 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=yYwsXj9zijvggVnQDNjNnrocJd7b07cuJ96ZBLhMe5o=; b=pZy2vUN/JofPHuGEzKQ8utWBl69Bem6ztT3m4k/wqGHXoM/H2Hv7kistab5b92+l2ib/UKzaF6Tg0TOPOR4O2BW57aQUQKpF7R1lx8hwlSf+lQ/No6JNMRHcQCKO2Sgg/xsfJKHlWhmlpS4Wt04OgszP1pcR5s2V9OWiz1IeCV91HjdDdvJulyW1UcPsPSSWfGT6tl35EWvWu7KN6EnMgodAHPVDyzi9PWoiRihHuxOmPUf5NiQuFwOjgCXwFM0l/Xyijk/WHf7lQT330KRFG3+Utxhi4DJUKUGXMRp630RdejEti419BkxAlyfs4183ZBeJxTmhSvlYj4ycmS8Q0A== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB5379.eurprd03.prod.outlook.com (2603:10a6:20b:c1::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.19; Mon, 4 Oct 2021 14:44:55 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::700f:d70b:3bb8:4d51]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::700f:d70b:3bb8:4d51%7]) with mapi id 15.20.4566.022; Mon, 4 Oct 2021 14:44:55 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 4 Oct 2021 16:44:46 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [LNtVtrp7U79Fn/rwss8z8oWVP8vHm/tK] X-ClientProxiedBy: AM6P191CA0044.EURP191.PROD.OUTLOOK.COM (2603:10a6:209:7f::21) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20211004144447.3984261-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM6P191CA0044.EURP191.PROD.OUTLOOK.COM (2603:10a6:209:7f::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.15 via Frontend Transport; Mon, 4 Oct 2021 14:44:54 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5c74b7e9-3d9b-4ca1-5932-08d9874587cc X-MS-Exchange-SLBlob-MailProps: EpEO96k6Wond71G3Ekn5Zra0hKkmyBNjf9OwK3zHYZYBP5mnwfbyulCPX4+li14QnHiP9gQdrZy41kdpyz6kFACiIEY67/mTydC78QnQVs/ywrWI7+nqXHYgWFyb/lyxHueGkh2tLkU8oK1cyCj/LFaqdmWk/MvnlCxL6MQEyfx+I4W3/8LmReIKv2DNeJ97UyGNStHhtWJe2ciVnbpwpB3J1Pym/raoz8pAZ3HpCnphkUYYeRR8ciC2/UsBb1tn+3Cf27Xzr5m5J+73T0670CFu5d6Q1GCgRuG6/ESo0xwgTNAUfEqgAmgh5JegcU2BcQn1cFcELkhyWmeZVbYSppzbIw7tZBDszJUUkoKi/x9j+o14uRZCrpbWEy07DgX9x7BtvZnB9zQYxdnKwh0Smim+6qNc2Kcx2/U2ZYo9sH2a4X8MfpJbVwkVtUhf+joRf6eIOOhuv+LZqiqtw7KLBsiLJy9zVlj4EmBwheF+LteQ5UZ0+hkQ7lnAowpirMN77N3PWrYdhOyXv/jHLUsnVPKW45fVrSaJjNKTqsBTahzFEx0P2hp04kI3KWcjbyYapK2hbvZi5FiwriYfOrOZ1YoGW/lnuugMXnI5czUxDqGKgaeYVwEfRIH5zs2I3AS3qje4Y+Mwwph3mYUP+cCEWTQLRbvs/kFsEIkg27dhbnxC/5d7z/zFlyiri1bnKNEpVdYvYXtjVJyI8n6WWyau5bVYnqVjdQjIxLMf/faxqs2719AXuuBNTLRYkxApRmqkVFsoXXJeFaw= X-MS-TrafficTypeDiagnostic: AM6PR03MB5379: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QMigTOrP8dQyafsn6vC+3cVpiAiGxnHcmHQYxHORuUIo+eO8WEWLEwBsmpGk7OAJST/Km2a+KVyqhCf0o7nAq6ppAdPdGgHzmU/jqv+zf5IbPc3588XnLLwZ8LOD2pA2gqVAgJrKGs/uoapxmtXQW2mcarPKFxJS3L3cljN/ZkYX3kBuozq+9qPvM2a29JpBp0axoo0u8lSZtNppABKJ4IfyoFX5P1l41np5RBC3pmfD5G3Thsnh7KkDpjnreHoFA8V7Y0bsdBV3u8XsrWBcjpbAunMfjFUhQblK8WJ/bY1bS4c1dRs+iglJ2MLMZILQGGKUE28aWc81Kwc4es2VAiEekDPdEALju3B9m7/VKl1Scb/av3bHOEJ3KBnWj1B6iqbbyziA1z+Ww5Lp3NOeazG7B0z/uHxDRrgF9NkzzB/GdrDx2HE+kzHjgkf3iJOZ X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Xi/kzaJ5BWtvReHmfGQyFTzR79l1L5q06+HmxGUYuPI0JEuKXJuG44KvKbDZTeql6ugZ7SsEEXJzIjKPETGhrEv1Ii+dhguMSEoOHY7woMQQcjHLly6hrM3Q2+IWuMftGpDxlXTBTytYSs0LEpq2/w== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5c74b7e9-3d9b-4ca1-5932-08d9874587cc X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Oct 2021 14:44:55.3193 (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: AM6PR03MB5379 Subject: [FFmpeg-devel] [PATCH 2/3] avutil/buffer: Never poison returned buffers 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: /URezv9VTp5S Poisoning returned buffers is based around the implicit assumption that the contents of said buffers are transient. Yet this is not true for the buffer pools used by the various hardware contexts which store important state in there that needs to be preserved. Furthermore, the current code is also based around the assumption that the complete buffer pointed to by AVBuffer->data coincides with AVBufferRef->data; yet an implementation might store some data of its own before the actual user-visible data (accessible via AVBufferRef) which would be broken by the current code. (This is of course yet more proof that the AVBuffer API is not the right tool for the hardware contexts.) Signed-off-by: Andreas Rheinhardt --- Another thing that our current API is missing is a reset function that is called when a buffer is returned to the pool. If there were such a thing, one could use it for FrameDecodeData. But before this can be addressed the original sin of using AVBuffer for everything needs to be fixed. libavutil/buffer.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/libavutil/buffer.c b/libavutil/buffer.c index 54590be566..e4562a79b1 100644 --- a/libavutil/buffer.c +++ b/libavutil/buffer.c @@ -341,9 +341,6 @@ static void pool_release_buffer(void *opaque, uint8_t *data) BufferPoolEntry *buf = opaque; AVBufferPool *pool = buf->pool; - if(CONFIG_MEMORY_POISONING) - memset(buf->data, FF_MEMORY_POISON, pool->size); - ff_mutex_lock(&pool->mutex); buf->next = pool->pool; pool->pool = buf; From patchwork Mon Oct 4 14:44:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30898 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6506:0:0:0:0:0 with SMTP id z6csp4390916iob; Mon, 4 Oct 2021 07:45:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCgznHfKEof3AYeuqSyQlS2PxXn6k+AwzqGohk4b/59uCp+pIJ0Woe3TTlqugiYVmtUtNZ X-Received: by 2002:a50:eb9a:: with SMTP id y26mr8653758edr.186.1633358719790; Mon, 04 Oct 2021 07:45:19 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id l8si17255162edb.67.2021.10.04.07.45.19; Mon, 04 Oct 2021 07:45:19 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=Oy++lJHv; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EE47868A940; Mon, 4 Oct 2021 17:45:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-oln040092067080.outbound.protection.outlook.com [40.92.67.80]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A9C1B68A8D9 for ; Mon, 4 Oct 2021 17:45:02 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FGuhUFW65omC8+qjD4/TfOcW27BajnvgS3rHdZ+kRIg7A1aF9AHykGyV1lYKBURhorTRNhIncvdskcfXlgLz21EQzD2yFANv43be24I/eD7s0BOp0xD56pN50/GV/6FoXBSeWF9QV+kjFzXXcqp6LD5IC3DPqZo3x0N219CVeRsvuigT05+caqbGZZQeJaEo6zac+5mOZjXzjccLHoNu3zFUmgSj8qfg7GzXtb+AF+vYz1YdCUaGA/WlqJoxd2t0V5Uu03nU1IoEbxBnKXmPMKZs9jgCNfvIGM2Vhc8TLsg/LYNu/w8H/vUv/ngextUeL8KSjICc9RK/PB1lx76Rkg== 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=+wKSw3PO+tsDRcz/41Y/PVsDmn7BsJb5XZqmTfnqi9Y=; b=Amsz642ugqR1sEms5jOLKJU5QDV/AUhQMO/YHnpATz8wzRiujiEzgc/pE9t+Df7kq8JCdvozKXbLRs4sF6yiZodHGEB6D397zmuz8JpSmWlJP4O9hebL5wpkgDIqYo+db4TRymNCzUssLzqe8+FpEx0hpHXSOtmqpUXD0Y/BdTj3eENFXpvkehJqkGFtJ7wXw/e9z+U0y1ltbdiqupabDHwr6N7X5hY58UBGoO4BLuWRSYirLjiElgBJ20fbtB6EoncOKhf9ccHcRsVfP+/FUaiysbxtjLW2o/Kb2gVZGp1zrUFhW5mUuyEF+Eq0jQjL1OX621YaaWn5TanLUDmwew== 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=+wKSw3PO+tsDRcz/41Y/PVsDmn7BsJb5XZqmTfnqi9Y=; b=Oy++lJHvoyI2z4tavPEnuU5Tb4RVRuc8dk1+ji5vJJoMnqlyKHnhF1/4p691f9dkI2EckBOHM5snObccjDUx3wEasJV0zwoVH6z71xcYmyTrMygloikI/21+NXMfEXU6uqbjrtOzfb4wsjH9ecM1xN5RZ6xE356xG3Y+XrxaMgbFbPjCbQmrns0gIpzmGREMzGbAsVKmu8kxOAC2AmxLMMRPHsr1stx/6uY9mTwNmHreY34GbNiE24lUgUlcABqrU9eV/AXKs6CPI5QZizjNirch0DGNjolW9YCzS17ruQIG1MShdFeBRRZV9dYrqjBXA3ZXv4l+dPJqHjTvdzC2zA== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB5379.eurprd03.prod.outlook.com (2603:10a6:20b:c1::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.19; Mon, 4 Oct 2021 14:44:58 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::700f:d70b:3bb8:4d51]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::700f:d70b:3bb8:4d51%7]) with mapi id 15.20.4566.022; Mon, 4 Oct 2021 14:44:58 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 4 Oct 2021 16:44:47 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [vBUOX1IFIEgFbkvh1Omko0TZfy8hJpDl] X-ClientProxiedBy: AM6P191CA0044.EURP191.PROD.OUTLOOK.COM (2603:10a6:209:7f::21) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20211004144447.3984261-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM6P191CA0044.EURP191.PROD.OUTLOOK.COM (2603:10a6:209:7f::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.15 via Frontend Transport; Mon, 4 Oct 2021 14:44:58 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 909a3d8f-a090-4928-6040-08d9874589b0 X-MS-Exchange-SLBlob-MailProps: +LiGfBxqLEvCnas31JGWNUANaS7a1JYubGX+jHl3kVI0FBquqVmJfMpHkkRWGC0UoB7MRb0nrbvzLi5Eq/nXMHeSprt4himlGD0e5eP+vFhsNxNovVH3ZZz0cV0sPfqkp/UODqmlaUCR/cTnUlQ1nmYGrwiBE532kXsrneM5pqyQs4QJGXaXmDjhV/kv2xNDiuDuQ4C2e20XCLH68auPUtNbGmWmvzPE+pRLcXzJKX/LPrnmjB7Zuajz/FzMjqoP7BC4rMK04ZEKedzexcWTpc+m3RNTX6dcRmenoCKGisDpeGFzHtnvdC4x27gKpi+gPeGpFnr/8gL6Lgb4QtggdC17LzwLCMV2q70fOWBnrTcQm7NkDEICJsb6JI+7qj5NoOVn9053b3J31FOe5qho1R17nnYMiZTNnixAaawFpPXVJuOyl3Auq/yIompc1TINnQdz+TUDKE00lKSRwMbOYDhkXF5QlVvd0UedYgODyvpvo50ZgIUjDY3iSmuZfsGyAQAEIAKAlodVWTvTfL4OX4Wc380n9AXbIBftlE8XRWVuGtvvtQO0LKogBX9UZR/vDTeIQ92eJahya1ypTJ7T8luF+30nZROQaKSOxDiel4CF1ponvclqB0lV6bojWCx1zRBcU+vjiLIxuoihHkoydivQO/IvY4TYkG34mIxBC7lBxcgCEmMONHuKMbp9MaW0xO2Hsuv73/s29sxhcH2usByPGrDrbWmt1C1GYlxsTrbzaEEaQuav9cT5aZX6/IERoxhkIBejfinCAVqIwK2rxKV7LOwPnWg0 X-MS-TrafficTypeDiagnostic: AM6PR03MB5379: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DWuTGM3MJ7QTJXB78dQWIl7X53GvpSZMQirCucYA0vfhM9H9MbEiiCA0BaFg9Z715XPiQtKb1h63FhBMy7p93e2wMSPk6jI72rkv5LSxfF8rvpkydf3FpvIB3WOqOBvyPKE94eCkWln/Qh0KQgeg6BWwF0FEjTnwWJnx6KcM7+FEYQUYaw3eFDDYwKNKPecIebsLScrxGZwDVNnP0ggP71a9laB8HJIkSsucAdQF8hN99VH/aKz2+4aKOIruvRDy3OKa4I18BuBM5y3a7F1/hSPafSSgR1yPZtlPLOz8CKP/o4L3T7AjsMvwcvP42eTWsmkC1pNDF2jBS3ina2pMD4FqJ9e/FTMqWNDg6ofR7nII4yd6eIfZV9Ryyq2VfQip7fZZyL61f87YQWNQlSCysG2YDNCICh0ItwbRrj0/G91iPXevgbCsPfDd87U16t/L X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: P2A8Jj7teIyRK05brErcRvcNp3uQOzQUPY/vEdBF1oO2WP9X9fDx++gosjtYvPGqFIRL/xvlzPGS7hbL4vi76TnJ5hqUguCrYImbeVqHwu4mKJVfepm8ODcZZTpjTucEouTf2RpW6pZINcWpxpvlWg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 909a3d8f-a090-4928-6040-08d9874589b0 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Oct 2021 14:44:58.4446 (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: AM6PR03MB5379 Subject: [FFmpeg-devel] [PATCH 3/3] avutil/buffer: Don't use atomics for AVBufferPool.refcount 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 3oDb7Egz0rNQ The AVBufferPool is already guarded by a mutex, so one can just move use said mutex to also protect modifying the refcount. Doing so yields a minor decrease in complexity. Signed-off-by: Andreas Rheinhardt --- Currently freeing the entries is serialized; the API documentation does not force us to do so ("is thread-safe as long as either the default alloc callback is used, or the user-supplied one is thread-safe"). I could easily implement unserializing it if desired, yet it would be incompatible with this patch. libavutil/buffer.c | 17 ++++++++++------- libavutil/buffer_internal.h | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/libavutil/buffer.c b/libavutil/buffer.c index e4562a79b1..2335a99e9f 100644 --- a/libavutil/buffer.c +++ b/libavutil/buffer.c @@ -272,7 +272,7 @@ AVBufferPool *av_buffer_pool_init2(size_t size, void *opaque, pool->alloc = av_buffer_alloc; // fallback pool->pool_free = pool_free; - atomic_init(&pool->refcount, 1); + pool->refcount = 1; return pool; } @@ -288,7 +288,7 @@ AVBufferPool *av_buffer_pool_init(size_t size, AVBufferRef* (*alloc)(size_t size pool->size = size; pool->alloc = alloc ? alloc : av_buffer_alloc; - atomic_init(&pool->refcount, 1); + pool->refcount = 1; return pool; } @@ -322,6 +322,7 @@ static void buffer_pool_free(AVBufferPool *pool) void av_buffer_pool_uninit(AVBufferPool **ppool) { AVBufferPool *pool; + unsigned refcount; if (!ppool || !*ppool) return; @@ -330,9 +331,10 @@ void av_buffer_pool_uninit(AVBufferPool **ppool) ff_mutex_lock(&pool->mutex); buffer_pool_flush(pool); + refcount = --pool->refcount; ff_mutex_unlock(&pool->mutex); - if (atomic_fetch_sub_explicit(&pool->refcount, 1, memory_order_acq_rel) == 1) + if (!refcount) buffer_pool_free(pool); } @@ -340,13 +342,15 @@ static void pool_release_buffer(void *opaque, uint8_t *data) { BufferPoolEntry *buf = opaque; AVBufferPool *pool = buf->pool; + unsigned refcount; ff_mutex_lock(&pool->mutex); buf->next = pool->pool; pool->pool = buf; + refcount = --pool->refcount; ff_mutex_unlock(&pool->mutex); - if (atomic_fetch_sub_explicit(&pool->refcount, 1, memory_order_acq_rel) == 1) + if (!refcount) buffer_pool_free(pool); } @@ -400,10 +404,9 @@ AVBufferRef *av_buffer_pool_get(AVBufferPool *pool) } else { ret = pool_alloc_buffer(pool); } - ff_mutex_unlock(&pool->mutex); - if (ret) - atomic_fetch_add_explicit(&pool->refcount, 1, memory_order_relaxed); + pool->refcount++; + ff_mutex_unlock(&pool->mutex); return ret; } diff --git a/libavutil/buffer_internal.h b/libavutil/buffer_internal.h index bdff1b5b32..a726e5e865 100644 --- a/libavutil/buffer_internal.h +++ b/libavutil/buffer_internal.h @@ -99,7 +99,7 @@ struct AVBufferPool { * buffers have been released, then it's safe to free the pool and all * the buffers in it. */ - atomic_uint refcount; + unsigned refcount; size_t size; void *opaque;