From patchwork Tue Mar 9 10:21:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Edmondson X-Patchwork-Id: 12124621 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09AA3C433DB for ; Tue, 9 Mar 2021 10:25:42 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8979965268 for ; Tue, 9 Mar 2021 10:25:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8979965268 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:42540 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lJZYa-0000In-Ie for qemu-devel@archiver.kernel.org; Tue, 09 Mar 2021 05:25:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47174) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJZVF-0006Sy-9f; Tue, 09 Mar 2021 05:22:13 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:54628) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJZVA-00026f-2Z; Tue, 09 Mar 2021 05:22:13 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 129AJd4Z010915; Tue, 9 Mar 2021 10:22:06 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=OQ6LuMZKmrZe2Rsv9g4XWMsLyPmUbJE7R8shR7N8T+g=; b=KEy4nw+THe8x3uaahi8U61wKIsv1HpA0drQ0TxPZcDo0gL/aiWs9xTTCF0BW9LvWcLU0 zKxnKXJkn08GNy08nOrBXqSDS69LYCWoX/dOm28UiqK/Qrkcho3lrsH9/khi6gX9JV+G VpuOH9kf+ckPCnHTQL1k/vl+ZV1rQptn54JUW+VCM9UYBJANA3y4rl2+sTi0FkxDzGMB 2r1LQrzydjumwqfVZVtOletg+snDgKKdxhJwVGkk15DWpf8IPisXCY2iEf28JATXgB6F oSotxkXQUz+Lz5w3hBv0H5GnIH/W07q++l0ABL0VM54wBEEiwp2uIrXdIqYF5FIeZiCa 3A== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2130.oracle.com with ESMTP id 373y8bpx0a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 09 Mar 2021 10:22:06 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 129ALUa3158580; Tue, 9 Mar 2021 10:22:06 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2177.outbound.protection.outlook.com [104.47.56.177]) by aserp3020.oracle.com with ESMTP id 374kmy995w-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 09 Mar 2021 10:22:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hB7zmvm4l6URo4/LEahkXhJ2PXWn2cwZUPIZ9lCoadwOjZ5AqF1MJe+k1uG1eZZUjmC3xWZGdQDGLmB4Z6gY0sZL6XzoysvTUqwjbl+fSNVrTRYJWdtf73TZy3LSSWUjSP31upkFee54JxoqieHedfmsB8OzgbSrnnBd3pDpxClSFq+uiN5cBmPkJh0LInKDlHWfnK6U72JM4ddjr1XhCzxS61gS77VPvXWrsYo1X2tWsUThXkDWrK2kwt3hRuLEkXflmUN52q+mb/xFiMvLFonIRJY/+Jb/dlPOYeD+/8l/R4sFOYrbarjDcEot0xc2pp8WJ+TyxE7dgDWD64pe3w== 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-SenderADCheck; bh=OQ6LuMZKmrZe2Rsv9g4XWMsLyPmUbJE7R8shR7N8T+g=; b=lknpsNj8Ddj9EVezWlVa0XFjRzl6sIEc+hY97IFHqUVfH5A7Yk20V07OP9klQUf2ffeZ6NFfDALM3LwwHmHlHzOuqHpNsgqpa8GzKVssgBKrkM06DimEGefaiox+Elae5T51Qej5LxobC8osGUAePEBOl6zAtPmeUYRjb49ivvTuHwFXiwmNjC5UrEmhv90DD/j2N50mH4XCk5ExBeHidNrhahD1cHhsy0neKEiDNFib8CNX8EsZbOFW1KUSzlfyCx9G5LHMEHB4D/9KLudcC8Vu/kNnYW34dmbMLElSqncCKLgdtUrbsnniyWD2IAP0ng6BNjp4/NjijhkWkNDHlg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OQ6LuMZKmrZe2Rsv9g4XWMsLyPmUbJE7R8shR7N8T+g=; b=Uzlt1tNZm81D1o380BVpUbGIom9HzCyyqRz18oZQV4SJwlkyRUKiRxUOav41cDfIHqPf7aSZnRMFpBd+DviQosjuCeI2laD+DMmb9j5paIs3GaERir5/UDj2eX5caticNNse6qXFCuZP0t/xhW1fYSzJcyzk1dGLnjjNxT+mS30= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=oracle.com; Received: from DM6PR10MB3148.namprd10.prod.outlook.com (2603:10b6:5:1a4::21) by DS7PR10MB5184.namprd10.prod.outlook.com (2603:10b6:5:38e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.17; Tue, 9 Mar 2021 10:22:04 +0000 Received: from DM6PR10MB3148.namprd10.prod.outlook.com ([fe80::f871:5965:2081:3934]) by DM6PR10MB3148.namprd10.prod.outlook.com ([fe80::f871:5965:2081:3934%5]) with mapi id 15.20.3890.038; Tue, 9 Mar 2021 10:22:04 +0000 From: David Edmondson To: qemu-devel@nongnu.org Subject: [RFC PATCH 1/4] block/vdi: When writing new bmap entry fails, don't leak the buffer Date: Tue, 9 Mar 2021 10:21:54 +0000 Message-Id: <20210309102157.365356-2-david.edmondson@oracle.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210309102157.365356-1-david.edmondson@oracle.com> References: <20210309102157.365356-1-david.edmondson@oracle.com> X-Originating-IP: [2001:8b0:bb71:7140:64::1] X-ClientProxiedBy: LO4P123CA0297.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:196::14) To DM6PR10MB3148.namprd10.prod.outlook.com (2603:10b6:5:1a4::21) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from disaster-area.hh.sledj.net (2001:8b0:bb71:7140:64::1) by LO4P123CA0297.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:196::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.26 via Frontend Transport; Tue, 9 Mar 2021 10:22:03 +0000 Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id afa22f67; Tue, 9 Mar 2021 10:21:57 +0000 (UTC) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2fb77d77-113c-43ae-3185-08d8e2e52f64 X-MS-TrafficTypeDiagnostic: DS7PR10MB5184: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3968; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6T3Tvpfqz+ngiTWpLfPyEObFMSQOh/ENZR9Hm0MQC6uSti3TVSWw/QRhNcF7UgAIexXmeOk0Lqn21nkoPS++HCQXhRzvqr6cSYO1W3VMzQhQpuiu0RG2KnIvCvyW0GP6VD3f7EDBdjHEf+TUPZZGC/ZUrIYVJkj6HPWer8zkTsFYoI3Ynm8E1NcBKqiLEhMoJ3Axnj+7PKHv8wxLVTjndef8q7xVgeW+709Os6KyjqG9/VDY5TBLVaNsaAmw6vGbyQSEw7YT/AglLtw1hbtd2+8WAwypj+gH2ZhbdyXxRlkDyQBVkfM85J6gURTxFJq+U5B2rigXCHcH/gq+y05jvlbw1ra+6zr7x9LuMrJGXtZSv9ANJxLDgbZP8L56LAgbwC7M5C4GULdHW+iWnlb3BMU29SxgtfF8f57CCneq/0fZasXVw11UOxNZpUlfmCjDt/nnNJjKZJ7h//klmS/wOWEJt2SUKGohAcxvvvgqH2UaCZagx7feQFrnEZ8qM1mhGNiGD6z0zQKnLYnVJwDgXA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR10MB3148.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(376002)(396003)(39860400002)(346002)(366004)(136003)(2616005)(66946007)(6666004)(4744005)(478600001)(107886003)(86362001)(1076003)(6916009)(66556008)(54906003)(66476007)(8936002)(8676002)(186003)(5660300002)(316002)(44832011)(52116002)(2906002)(4326008)(83380400001)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 4gPlYhdccfOFaB4lRpIe5acmeFuzCe8HnIw4HURhM4gSwJFVQRouFqdxwI7O1s3vmPeN586HyCRLWCLSUMFH2g47YkQcMLJhdf7EquCDF6SaE21r1xzjxEhY/Yvp5hQ8iKwy1z5k9uUDnUQEacrApf1pKWcKGe9i16X1FuO7MLP8f/WWqM0DEeF6S/WDQNaZfUXG6cXSXuf+t02r3/iD5LfAlz1O8rKuPMbW6qQ6ZBCYXy956mVfO16kUITN7XXNdZNsJ3MJVmfcLTYzvUTZ8EsZTl2m1lpiZ0afnhcH6DA1CROA0QbfPVUgXxINtw2XnNBiZBeLWZvvLCsPByioeJfiAAP5+k93WiQn22iP8YyqAXFA7Lr9hmJtJVWZadJsSOeR1Gdbqp7S7/cVpqjRtaSOPlORhET+13vilddjgJzV0y/aV4M5kmrO5t4DBYztJ3CaIgiX9hF7xyAYvPPlL0Wjj5d3qEyXVfPjMqiprSouRmGfQZ4mZhh+PRqLWOOitU7xFjTBWuE6WbXxryZzIu76EC7dTWVo3u4eB2GtcVavIuAKamF22x95xv1Pi1zUWvyvtZ0gkoUJT7B+832l75Dr5DxYqx0PoPxs86aWwi/Qot6G3VKBZkIj6dRyDGQqIuRDmCdPJzaBhx5v+nXjc74/AAedtlOhR0lh6k6Q1GusdFHHjjRjpJf4GuCLkhwpro6DMHGiNIhWzmfbt5E/IeFBssxVET684ObWiBsOGjwPVJvai+gA2ph6a2BjBglAf2n7pD8MCZw6Q/WgYExnXlBHWSpPPLHHgDjjzfGcGGMcqOByFlmlopSm5chWTpVkES0wCkgHCcfad4I0sLfyStULQB6pP9xLoVbO6ZhMrqgYJwvN7aQkOcTrdN+Od94b9qoDtkN12iXgbqHb4Mt5KYxxXrpUP944w4zH6FkkbHeLp4E/WJiiMguE8mmndNh13yYhhZPRsSDneTMh+r4H/A7eBvaiTnEdDqLV3JhFXUDzMvQhs8jyvJqqgZLSiVnSpZajUc1qL5R0GTLT6MNYsX9gMbjP9D8KictUHxY7+Hk8ZUnRMuksPLyjpV68TWJsdxVsY/Vj/ZiKm71twcEJJCjE6h/LxVI7Ew9sh2W5gyfI/2UQvaaLWu206x7DWKNxuiZpRRFAmhyrW9EYNADZqiBzlrPjHMIqQQl6Pg4K+q4kWBOTLSbKMwpK27l+XZjQpfAPCLnj1sYHuTCPqovvBEWS2ZNVWLoRF1qFioXvyUlaAZMX4Hu4RwspXNxCil26j/O+V6bFmEQHMF77Aetqb9Zkj2Qxm29Nj4ziILkenYT3GunPXbtir+EYJXMA1tiZbmN1ZFRszHFOE4WhlbU8drkoQVr99ro/DN0FQwMGsuY= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2fb77d77-113c-43ae-3185-08d8e2e52f64 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB3148.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2021 10:22:04.6556 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: EtxJ6fdK6+W/aeNs99fFBRXCbco1O7l/YCkUigKfRq3UaPk8ybaXoaAqgtKiL8vCmyOAl6yosCtxHMBC0OPNnKCh3Z0SwOKKfh5WC/CpS5A= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR10MB5184 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9917 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 bulkscore=0 malwarescore=0 spamscore=0 mlxlogscore=999 phishscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103090049 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9917 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 mlxscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 suspectscore=0 adultscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103090049 Received-SPF: pass client-ip=141.146.126.79; envelope-from=david.edmondson@oracle.com; helo=aserp2130.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-block@nongnu.org, Stefan Weil , Max Reitz , David Edmondson , Stefan Hajnoczi Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" If a new bitmap entry is allocated, requiring the entire block to be written, avoiding leaking the buffer allocated for the block should the write fail. Signed-off-by: David Edmondson Reviewed-by: Philippe Mathieu-Daudé --- block/vdi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/vdi.c b/block/vdi.c index 5627e7d764..2a6dc26124 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -690,6 +690,7 @@ nonallocating_write: logout("finished data write\n"); if (ret < 0) { + g_free(block); return ret; } From patchwork Tue Mar 9 10:21:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Edmondson X-Patchwork-Id: 12124615 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1F96C433E0 for ; Tue, 9 Mar 2021 10:25:01 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 841446526C for ; Tue, 9 Mar 2021 10:25:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 841446526C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:41214 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lJZXw-0008B9-L8 for qemu-devel@archiver.kernel.org; Tue, 09 Mar 2021 05:25:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47172) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJZVE-0006Sr-Vj; Tue, 09 Mar 2021 05:22:13 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:58262) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJZVB-00027Q-H0; Tue, 09 Mar 2021 05:22:12 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 129AJNnW177928; Tue, 9 Mar 2021 10:22:07 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=y/vM4CRvXGH+73nZ87JEj4spvUrwBEeg5m0WJqwfRHk=; b=gxxFjHnz01dcg8+FFKQx3A/IynMl8SYxoGPaLRwdzObeywQwkB9lRMsupCxLVrstrADW 3Z1wVWjzESvU0QaCiIe+iYVUwixjfXiOrD56Co9TLGs2jJWlT0TaHifaD1pOV+dLiRLM itRmHgL+a3UMTZ5bgi5/ybLuATGq1GkmMp4lRMWlGz0VBcxEslDcmhk2unui+OJY11TK JFc7XaxzLDwixiPDRk/3S+0/8V8AuCkeXiyzfS+1JU8XCZxzIDBIPVe7P7cNDQsOXanY h39SL67TZ3NtkwcsQPnv02vioZwn46AgsS9XYVZZ3/wBYurGadFts07BSFuS9Hr6fItJ 4Q== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 3742cn6rdq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 09 Mar 2021 10:22:07 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 129ALUa4158580; Tue, 9 Mar 2021 10:22:06 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2177.outbound.protection.outlook.com [104.47.56.177]) by aserp3020.oracle.com with ESMTP id 374kmy995w-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 09 Mar 2021 10:22:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G4ZNsyKB+n4BdLG5GB2zrSrxevF3fT56VFJ7hwuaP9W+ERpkMTE56nY2IQWFTHkJ+y3Xp0LFbcJKjg3MI1HqvSJZPd2SW5QZL2UPU0Vd7Gw1DN89YL0JIhHf/VHSavGV9ha+dfhHDAjPB6HyyntCjXINP6Z5r5Xz9Ps/X3icTW9vY28KJmOD+86KjGH8t7PSC3pCVW44+iS74tS4xAND2nXiIGtiqxGUo3+SC66hYlOw3J0B5sVxHLyZYeV/+aKxhW2gQpGEihNdE4j1tGnBCi9Pj5BOXcshczawmgJl3cuzPbCtlhs+BcWinB3LMuy08vd3+kYicCJtDF6aqfz3iQ== 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-SenderADCheck; bh=y/vM4CRvXGH+73nZ87JEj4spvUrwBEeg5m0WJqwfRHk=; b=kXVX/9djN77ZScsqwiul5NPUcAl7RX2ozdTB3mD7ZuCjLzgQXW7wb6/Z+BaPsFCuRqazNeYTCj/qyXMpybJB6RXWHq8NalwJXAeQcEnJkgdfj8tmkj5wASlvbqKBPh5IPuQ/iNINff7ZTPXc9KQzDjhYKiBZJ+kJvfQSEUgDuLSIDYkaMs5svd2SaAnCyWjYNJmfr097VlU9doJw3qz6jNrqYrZOCaxkfBUVsKRT5HS2LYASdWfpmlEs9HEHBN5jbP3qvBVJETGYfChmXabTOgIfIpb4EZDIFJ4hrSDcrg7GGQewBId5JvoQltnPAk31BbHTpoyLs3DEwzajdyACqg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=y/vM4CRvXGH+73nZ87JEj4spvUrwBEeg5m0WJqwfRHk=; b=CpcVe6SknC5XBz7R3TLRsPJQeeM4q/IxZnGNDSrfTTLGid3a6OLMbKbnkxBx0Cr2nKAPuerjfBSi4tN5zmDW8MxVIvT2/odidotWP7QrCvSeq9DCjd4wnw847tS8ThRZ5CaXUOcqHlQH6Bj4lgVEYfqcETR+a+4sXu4lqoVnwv8= Received: from DM6PR10MB3148.namprd10.prod.outlook.com (2603:10b6:5:1a4::21) by DS7PR10MB5184.namprd10.prod.outlook.com (2603:10b6:5:38e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.17; Tue, 9 Mar 2021 10:22:05 +0000 Received: from DM6PR10MB3148.namprd10.prod.outlook.com ([fe80::f871:5965:2081:3934]) by DM6PR10MB3148.namprd10.prod.outlook.com ([fe80::f871:5965:2081:3934%5]) with mapi id 15.20.3890.038; Tue, 9 Mar 2021 10:22:05 +0000 From: David Edmondson To: qemu-devel@nongnu.org Subject: [RFC PATCH 2/4] block/vdi: Don't assume that blocks are larger than VdiHeader Date: Tue, 9 Mar 2021 10:21:55 +0000 Message-Id: <20210309102157.365356-3-david.edmondson@oracle.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210309102157.365356-1-david.edmondson@oracle.com> References: <20210309102157.365356-1-david.edmondson@oracle.com> X-Originating-IP: [2001:8b0:bb71:7140:64::1] X-ClientProxiedBy: LNXP123CA0017.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:d2::29) To DM6PR10MB3148.namprd10.prod.outlook.com (2603:10b6:5:1a4::21) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from disaster-area.hh.sledj.net (2001:8b0:bb71:7140:64::1) by LNXP123CA0017.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:d2::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.26 via Frontend Transport; Tue, 9 Mar 2021 10:22:03 +0000 Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 3d98f9e3; Tue, 9 Mar 2021 10:21:57 +0000 (UTC) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4b11762c-eff5-4aac-a933-08d8e2e52f7d X-MS-TrafficTypeDiagnostic: DS7PR10MB5184: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1002; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NBd1UBTeLf/g6MT1yAIdlHrSaatRsmKnoiZj6uTcHo2hzDXwhWjguX+B4r86rSC7WM3cbElmdjL5+007GLiR+il424mnD7OQu7L/YFBaLdZ+IfVauDDxTkYrKqLqCp6J9q5qGuijcJGBDdhZBWqOr8xFcfQhRqvt91A0Wt99PGZZaRjNXDwnfTkP4uxI1VTeEtWip0c0scmug5rkO7NPA+E9z31swWbnyuwHJB0hMwzSTYFIjP5wVuH1amPT6YfYOSVxCgbaGVEwTLBI8xW/ofIX99LnDnwUPGnT2AwDSqMTlC4KRyvoh27Qlb1eZ3thL53uGjfw2Npi00heLzzNakEJYYEwYWCS3MrMDPCcHOgK9FXI6hF8Zq17WIUVt0Z6UPA8w3x6tWrObt2QlOz5F0/Umx1xn7jt3psaueJcHcwdlddoSnPa/VAswXLxx31XdWg0Nm3+iPW9TrHw/NLAP7Zy2T/UvhK/BLrA3BHBxjnID16CA975UIJ6wffl658qFOsrb9XE1doHJbdWysuO9w== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR10MB3148.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(376002)(396003)(39860400002)(346002)(366004)(136003)(2616005)(66946007)(478600001)(107886003)(86362001)(1076003)(6916009)(66556008)(54906003)(66476007)(8936002)(8676002)(186003)(5660300002)(316002)(44832011)(52116002)(2906002)(4326008)(83380400001)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 5qmntLQfTkxd4pwTgXlpEpUYabE375Ev5MMgJiIl2wp4HVJRdWeUG9QdjolL+JqtMq46ifr60ImdSC7TFN9Mr2xiO1J7z8HaAjmDm2gFGW0yeb60PSRc+ISedgLPJo9v9KzGrimAFiNTgstrCsx0PcpmElbZUIrOSI5WDHHss4+cr3bXSCVO6intXRSkwQBXfYR1vddWU3fcxqvwZ5ji1vlM5vcG3Rwl9y/mF8sE2sqihtyBYBIf9U7vDLo1uT/cFMi/sd7V+chhBRRGt2Biayl/wg8YXPT2HLHiYoj/QgZDtWwFyZxw0iyUo6sPruheiiT4z/XxDF/HvDsmqPgeF64mYICC4xHDETLX4YuM7XwGMhn0vQ35NesnnI8m6NeIG/HmrNRMkWt6MgtdM2Nh/X+XdGYg9/ugFCmYqR7CHomGbdYRp5/jIR9qG4spC1EBSglPH1oA1Zpki9uMOX9UxSpm3MpJ38B0SOjEjBiH91asPvG+qxTus8q5BQdkEGwdDZzHUjlEEQUnNJ6f0fKbIzA4lgqWcDKXAczidoxLgUFPmy1PyIlFTxs/INs5cHVPNX4HRPXNpl/B+Pxz06Dv3Df23fqMknacp7LvgYkJz5xgqhw26mSulTNDqGoWN6NcGHC879BISoyYuXRw8RE8vE2e9ASPYqIN3OPjzVs53wcgyHm31E3c6+CvbaLUQClAghDqryeKJp97nbztf8SL1PHV65YBoeLwq/1anBlqfpSbYs0/eiKtebk1e2+MhZIK+h64snOR2TwwJX6N5l7Z8+14/f3XV7DOUDV9Tex+mANeP3TkvuOhCaOTImlnhTkGGhFHTAn7cjJEfKWGNbgN9023V1FSvnFQSI4pDWbo6CYc6W8Z0TrwwT8lz2Xeg4Rx0/994WM5tvjELg9qMz4JmbDenkOKgu4M5+fW3mRFh8ef/m67sZ9nNVlV2+RPTXFyajO1eaT0FzQl1sFK17xxS2XwJu3sWijGdPPHeknpyibFeFuA93A++iSzyQSnSACR+I/RF+hqpRWRiUme5jtFQpdQ0MEZ/q/5GrpVWBpgwb0VJeyV6dVGeS1fzuF5vpjYUrEdHBxQV9BWMLIcUo75/3XfLOAbG4Jw1F7iluXJcS0tuxIqOh6e0Q3IIXKD/xIZsYw/uv3VD2iEAsUvHEPvgD7so0sZvaVbCdPHyuRCnoJlGmVu1e6rHDz3geXOug/zIpKkdd7sRs7pU5/PBhUBLwEBIZjSTuUHWy/IqMbWYc9gJR/J/Yzl4yTfeUejQ66qFeypu0jwFjj7YXNHACuIlGSuW5BfS+Mgs3iKUkaGGehGHQoyTa9tFJuoN1+KbCPAR8dWZ+H4ns5lUXqd+O+N7g== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4b11762c-eff5-4aac-a933-08d8e2e52f7d X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB3148.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2021 10:22:04.8285 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 9a0prXYHpORs3JSNt/vLEaf1iwppyE/uo3Ejf5Ezo9j14sXt1HFpUP/3CrhvYG8y0JTEpC+27NWsCaqBSC09uDY32fVr5I9eKYPzxHNEBt0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR10MB5184 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9917 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 bulkscore=0 malwarescore=0 spamscore=0 mlxlogscore=999 phishscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103090049 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9917 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=0 clxscore=1015 phishscore=0 adultscore=0 mlxlogscore=999 priorityscore=1501 lowpriorityscore=0 bulkscore=0 mlxscore=0 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103090049 Received-SPF: pass client-ip=156.151.31.85; envelope-from=david.edmondson@oracle.com; helo=userp2120.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-block@nongnu.org, Stefan Weil , Max Reitz , David Edmondson , Stefan Hajnoczi Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Given that the block size is read from the header of the VDI file, a wide variety of sizes might be seen. Rather than re-using a block sized memory region when writing the VDI header, allocate an appropriately sized buffer. Signed-off-by: David Edmondson --- block/vdi.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/block/vdi.c b/block/vdi.c index 2a6dc26124..548f8a057b 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -696,18 +696,20 @@ nonallocating_write: if (block) { /* One or more new blocks were allocated. */ - VdiHeader *header = (VdiHeader *) block; + VdiHeader *header; uint8_t *base; uint64_t offset; uint32_t n_sectors; + g_free(block); + header = g_malloc(sizeof(*header)); + logout("now writing modified header\n"); assert(VDI_IS_ALLOCATED(bmap_first)); *header = s->header; vdi_header_to_le(header); - ret = bdrv_pwrite(bs->file, 0, block, sizeof(VdiHeader)); - g_free(block); - block = NULL; + ret = bdrv_pwrite(bs->file, 0, header, sizeof(*header)); + g_free(header); if (ret < 0) { return ret; From patchwork Tue Mar 9 10:21:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Edmondson X-Patchwork-Id: 12124619 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 373F4C433E0 for ; Tue, 9 Mar 2021 10:25:07 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C9ACF65268 for ; Tue, 9 Mar 2021 10:25:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C9ACF65268 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:41318 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lJZY1-0008DZ-UA for qemu-devel@archiver.kernel.org; Tue, 09 Mar 2021 05:25:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47178) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJZVF-0006TG-Tg; Tue, 09 Mar 2021 05:22:13 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:41646) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJZVB-00028Y-S2; Tue, 09 Mar 2021 05:22:13 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 129AJRbE064315; Tue, 9 Mar 2021 10:22:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=P5pVq2cofdt/N/W3R0Lvus5sEULtpEmWq+jruztvHs0=; b=QJYH18inV4I3IQBiQ6GONuKdbYyH/7ihnFHD1b2usUl1Y+CNXrKHmHv8FK+9Ywm7R4o8 VGmHB3JISffxeu/9uNX3AsZzU7OIQ6e00vM9HPDn4LJxtwppL7EPbWBHyrCZVVMDZx9u rQGlIopY9MUNu3BTtHCzikAlugFVEAYNhxNu1Edt/Ig4Q6qFHCfePFQd9OX1rDLnNG8Q CELyQH9CUu80EV+OSXLhtofg+CzMn06L8PUsB2trOYV056RZoHfvi5NRV7c9KvYef3Rf YuuMbc9uxNSuU7jaV9zXuqSeEbcnbDvxtTeknJbwZmheTR0yH6pvAFS2Tf2CGATe8v7c hg== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 3741pmesh6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 09 Mar 2021 10:22:08 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 129ALUa6158580; Tue, 9 Mar 2021 10:22:08 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2177.outbound.protection.outlook.com [104.47.56.177]) by aserp3020.oracle.com with ESMTP id 374kmy995w-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 09 Mar 2021 10:22:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SIVgEQryqMxUiiqJkDoW8hD5EPVXKYEjwKWDp7qROGgVYE+CmXKZmAY/c4qOntXqUqZ2FxkkPmzpm5wN6SzbgWTjB3Li39iRy4fWqrfZNZKLNP1aMTzOkPRVfwcPP+2KsOMk/PW1o7GnO91eLNwaHWkYTVdiqz3e5+hjI4tjbmRJY78m1XRLS4KfyMuOddMUpXyseutDcoY+fqzaOTG9RVGhjf6iqsACH3q3dCFfky//pcAx1568ZVYeLzFK0QXULWL8kuwL/dKyTu+LDwKmpjWiUFjHJXrfN2eJIiwT9EsXzxXyJuS7iwR49OzuW8dsvgB0eEpkZ/H0D+xYKH2BJw== 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-SenderADCheck; bh=P5pVq2cofdt/N/W3R0Lvus5sEULtpEmWq+jruztvHs0=; b=U76MRX6FXwNhANWJiay4S7iT+ASeMNixyRo25RNzaAiBvMFq/14k0ZxJjlFhOnjPF3FOkWo0tlxc9BOkIKRJZZU9XYBjVqO+9olIEDJ0VTgd4BqYGgs33Z4UOho5TllijUENToWOKHiZP+0bh/0ZPHcP+6IeEsuvCUDpv22Wn7iTxGlAfajkWmIpdPAXiFeA4RjDQfXHIS4h920F9Rwb3cWoYEO3bixekQ0n//+5xdcETYpxpuamuEpjhpPKt4e9f1RJRr1rJ7XfcIUehdVkfEuSYIv1oZ0cK26YrhBEzm+pM48t7vi2I88k92KYO4L2yzwck3nDqugDu+iab8uE6w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=P5pVq2cofdt/N/W3R0Lvus5sEULtpEmWq+jruztvHs0=; b=zSBM1m4tR6sOPDOreJOAwloSFwI2jybE79LhMuj9fLs0Npaw/bpbPSbr/gNzu619f0PATeJfJnOsAlLxIQE/tbZLicqOn4VVHteFQzfgg9Igzl3waduPZIimD8zRiJXH6hYdWtpFS50melmsdZJ5dB44mz9plzKV1cMMAF5KXbw= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from DM6PR10MB3148.namprd10.prod.outlook.com (2603:10b6:5:1a4::21) by DS7PR10MB5184.namprd10.prod.outlook.com (2603:10b6:5:38e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.17; Tue, 9 Mar 2021 10:22:06 +0000 Received: from DM6PR10MB3148.namprd10.prod.outlook.com ([fe80::f871:5965:2081:3934]) by DM6PR10MB3148.namprd10.prod.outlook.com ([fe80::f871:5965:2081:3934%5]) with mapi id 15.20.3890.038; Tue, 9 Mar 2021 10:22:06 +0000 From: David Edmondson To: qemu-devel@nongnu.org Subject: [RFC PATCH 3/4] coroutine/mutex: Store the coroutine in the CoWaitRecord only once Date: Tue, 9 Mar 2021 10:21:56 +0000 Message-Id: <20210309102157.365356-4-david.edmondson@oracle.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210309102157.365356-1-david.edmondson@oracle.com> References: <20210309102157.365356-1-david.edmondson@oracle.com> X-Originating-IP: [2001:8b0:bb71:7140:64::1] X-ClientProxiedBy: LO4P123CA0297.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:196::14) To DM6PR10MB3148.namprd10.prod.outlook.com (2603:10b6:5:1a4::21) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from disaster-area.hh.sledj.net (2001:8b0:bb71:7140:64::1) by LO4P123CA0297.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:196::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.26 via Frontend Transport; Tue, 9 Mar 2021 10:22:04 +0000 Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 6d14312f; Tue, 9 Mar 2021 10:21:57 +0000 (UTC) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0a0836d4-ed4d-43aa-4b31-08d8e2e5305e X-MS-TrafficTypeDiagnostic: DS7PR10MB5184: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4714; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dN9sL62fkYNchDajhRhZCeDcR0HYMDAR/vB/Mqx+CZDG0YzBBztRMfCFeLs/f+ULjQ0Tg3aRHNfSkCrB8Hm7XvMyJKB9L6VZuZ1NhGlitLAsZ+Gi7EqzlD+RcAzxUcdVMjof1InRfSjCZXA5OsbwEIEnK4nR3BHBbb274kmmChmoCGqZQcuUQ6C/Icp8vmLy79qTkHkCjK4DxWsMs/S1oI+1pPmheQHvCsYCRD8xTnFQGZ0fS5kyaM3bKjYwQC9uPHwP9qbKjVt0EfSadGjncpnwyGylNRuL+Gl8xQ9ICmzVC0qEa+hEa1zMD+TzAk2he7TkXGb7RAQhwlmmmRjtR+dH+XVomM40BrTECmQI0uhUI6RCgq9LPZwWmDQ0IF6P85gs6flyn7iqmMv9tsYQdR9aGL5ZGBqVsjvzQ8UWlaE+0orqSpmSF6Q8BBcFgnvgunR7QHcv+ynBszeLBkmq4sx7wpRC4j4GVk5seCDe8p38gDrSsxF3j2cdUBKLjYgvS0U9AnZfGP0Zk8qQ5qva/Q== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR10MB3148.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(6029001)(376002)(396003)(39860400002)(346002)(366004)(136003)(2616005)(66946007)(4744005)(478600001)(107886003)(86362001)(1076003)(6916009)(66556008)(54906003)(66476007)(8936002)(8676002)(186003)(5660300002)(316002)(44832011)(52116002)(2906002)(4326008)(83380400001)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: JXMSBNEXLNOQHYtUUi+ZAB8I5e5w5Ae2QmShFA8n5fcWtxfhAQTKdo8Ohg93AGX51YcivJXIyAWJc1XiPwPWDSROwUY/UYTiSExMyTXPXbLILe2tPSHP5fPEmBXa1S7XgL2831lUWLR0aFW6m6lyJ6fdLYeYsUBb7PwIgBqf8vVEDgPXsRVxS0yNINVBRdwXdoYdz+/z0UpuvCHRDXvXfStygl9gNN7GUWJu5F3x7bYJSD76d+cSxxbueS6EHRiWGxNgOi5n2WfQb84TKZGZnXezeMCphkQ9Mbbq11SAajbeT31D0gulqWzApo+gMZDz9XectJhG6EFppu8Cm+UCZeIw/miEem9Hyd+k7RVBu47vdtQErVpNBCog9TxjpRGyg3j0wpt6t+4hit5ThlCcU44DgqJEM1UF5wLMEeo5m6dMIwKhjGYbhfNb8ejOuWg1UwJUlvRq/ExPHu19jZdVmaUPUq3kTsUOD/2n8XG4fiA8avQ4TVmRfAhSfhFpzzSmTxVNRUUz0hJwjstpLPLMJzTA62xdRTfEXiKsHdiVA+SSm8a5C5DG7r3ZyAXybGH1VvO0pHLPeigYSAXtOqLOLhgfJJ92XDjJYCqrks4K7oQa0n95fOI5TaCWxHs5NotanMMouMd8w6BO7cyvCGK3UfCwlrL9fcc1MFDbvrFuCcQ1Lt3rudqlQ4OU61xy03QF1blxLzZznjH0Xi7TOBL+4CerP95/e870jI/NBOcbZOeI/nVDjt//PuTU1dtWYm7fGkdo66DoMUfVrVsLWNx1q5ehbam2dT67uS8QbeYM79UJvElGChxuMDZthiV5IfMh85dVT4FJMMMlUUy845Sx33N76i2BmLnzQWUNrnjxq1VJnFo1CmJpncdX55QVhcr7ZPL29/rdCWqRoD5skbnfP2XBYf7NHcC/zr0oYJ8G7azYmBLLsCQpthtyLyDXqiPok+TcgQCvVMcbQssvRy73ObnTdPQt949/dPl3wf6IX3IMiMu1vfgKH4rhl4iZWhzI4uNQIiTw0vrFoAEASyOeOEbLTCEzhF4wr6/34I8mFHfB65Hx1/KWYat2wk1UEfOXJzxor/4mjMtHt7ue9m73JPsq/ZMtryexyA+i1yD7iA5Q0aZi+1gGg6n2xu/FIe5NcVZUWzTmUYa+hEtKIARmblaqzMWlba+PQqLQkMhga6QnGHyFJDtcMPoqAahOrSx02a0Oopj1FVVqiT4lXMaEMZIUqehIhkOIbhmBC5jsUnumeXYbdTNIUJPOeKyMMrNFeAxNBE8Un7FbCfIO6neSTsILfeyU8FMs01HFunoDVAu1xnDXkb4vrXqogcRjIxEH9oOIy2cS1nSlNie9YPTF/g== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0a0836d4-ed4d-43aa-4b31-08d8e2e5305e X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB3148.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2021 10:22:06.2997 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xGqO4IEOiSipSBWI32hk3Nfw0a+EibRClse6CcXiKGoaH+hfLecEoVhADbeFcitE4AxNEH+IbA9ucX6gmEz11fy0pwF6uo1WW+CnXxHOKIA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR10MB5184 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9917 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 bulkscore=0 malwarescore=0 spamscore=0 mlxlogscore=999 phishscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103090049 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9917 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 impostorscore=0 suspectscore=0 clxscore=1015 malwarescore=0 priorityscore=1501 phishscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103090049 Received-SPF: pass client-ip=141.146.126.78; envelope-from=david.edmondson@oracle.com; helo=aserp2120.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-block@nongnu.org, Stefan Weil , Max Reitz , David Edmondson , Stefan Hajnoczi Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" When taking the slow path for mutex acquisition, set the coroutine value in the CoWaitRecord in push_waiter(), rather than both there and in the caller. Signed-off-by: David Edmondson Reviewed-by: Paolo Bonzini Reviewed-by: Philippe Mathieu-Daudé --- util/qemu-coroutine-lock.c | 1 - 1 file changed, 1 deletion(-) diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c index 5816bf8900..eb73cf11dc 100644 --- a/util/qemu-coroutine-lock.c +++ b/util/qemu-coroutine-lock.c @@ -204,7 +204,6 @@ static void coroutine_fn qemu_co_mutex_lock_slowpath(AioContext *ctx, unsigned old_handoff; trace_qemu_co_mutex_lock_entry(mutex, self); - w.co = self; push_waiter(mutex, &w); /* This is the "Responsibility Hand-Off" protocol; a lock() picks from From patchwork Tue Mar 9 10:21:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Edmondson X-Patchwork-Id: 12124617 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CAD1DC433DB for ; Tue, 9 Mar 2021 10:25:04 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6C94165267 for ; Tue, 9 Mar 2021 10:25:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6C94165267 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:41264 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lJZXz-0008CH-Jo for qemu-devel@archiver.kernel.org; Tue, 09 Mar 2021 05:25:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47152) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJZVE-0006Sb-DA; Tue, 09 Mar 2021 05:22:12 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:54638) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJZVB-00027b-12; Tue, 09 Mar 2021 05:22:11 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 129AJaNZ010906; Tue, 9 Mar 2021 10:22:07 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=BXTbCtTYcn3t2F8btCOF+eLRzGsVxXTM+YyqUiPmZBM=; b=vRwaAy3g8DA3QSwlpWAsgbHpFIP7b0fJ/FVph4ZsFY+MqbB9PxyhkxdvFgKMwXcZ4dRB zAIm02qxwunb4xfSO7D+ojjYPA/gdIwFttSZiFwbbvgDH29Zq/q4SODhQtc8O9LFTn5X lJLQZK0UfS/pbxlnqk4uZ517PleESqLG2I4CRkfhWvNAbMqE9NbJdxzenNDILn9vabwN jte3x00ACUPltX1cPYfwg/GujQRUsJLwjBb08Uy8A2az/JgGbw+V77ELEaXUfE64rKN7 jVKre9Vt576xMvWYdPdUM5vBzxq5R2Nc/tnu7Xwa5/mU7z83KnbDZIxkTlWtL17krgUp QA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2130.oracle.com with ESMTP id 373y8bpx0e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 09 Mar 2021 10:22:07 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 129ALUa5158580; Tue, 9 Mar 2021 10:22:07 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2177.outbound.protection.outlook.com [104.47.56.177]) by aserp3020.oracle.com with ESMTP id 374kmy995w-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 09 Mar 2021 10:22:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SCQjn1UZOw62axdsDRO557ZBaoYd7dzl9SyU7MOrgbbnLkeNkJxMaEll3dnNRk9P+1g5Ygw83FGNgC0LCmZDAshw3hlqlLLZOdx4IHaHlfgoQ8Yn02FtMdHVZNM4vwMwjjaSwKAfdK4pZSzhF9EDI/SxlICfWlz0x0KitJ9fWjQsbqmTIUhyXfjrts9aab+NAjYzqJPblA0lGqIg6/8Hc2nSdcwLZA9h6oFxH8yC1M0ZEEJn2XI9ZUI7XQolksvsNF1L4fBsY6woFatOXtQqZV9Pj7yRvdRv2Z5I758n8IP2pQ55B404HGnjRPvgTjszSYQPlmaEpON3py2BUTvEXA== 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-SenderADCheck; bh=BXTbCtTYcn3t2F8btCOF+eLRzGsVxXTM+YyqUiPmZBM=; b=PTk5hNAdnJ/dPg84GC+N/g0WDXM01gRvTFS4uoePICC+rG9BsFBwzVcz35s+n1yJAsPx1DsF6KgbYC9ADqQrRVvd9Ur7HoDR//73WOnW6oGYpJ3VB3C5C+aoOVCMd/1eq5L9ZZvh0pUj/8qHQ411/9oGTKZjI4mQ7bdXPjdeytZjnOQnY98IGFVEAnTPgbhSPC7sMMkXua4nhGgT9R1sg/1QYM53fAmHWEia7+nlITv8HUvQ8BAR+RseR15bJkTjZj4mtwiXf8aKGJKbxDaK1y8OcRU/bbh9bA3v57XUvs3dV39K+HnVmvC9G1q4ctg96UKHU3zDd2aJ5J56sIl4yg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BXTbCtTYcn3t2F8btCOF+eLRzGsVxXTM+YyqUiPmZBM=; b=l88LslK0bZo90GBujIj/DFB1lkJBqr5u8gvqiws7UXbeoQWNZlhbokYc5sS3bpxmTKjk8TnT96h5xTZqAxzm93mIs+x+vn+K7JRJ3fr+rp2irOvIyiHiYmKcauk+kY8914QkYWSLDQGIONYQTaIS5ktLkBy3bmjFa3XMSqu+qO4= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=oracle.com; Received: from DM6PR10MB3148.namprd10.prod.outlook.com (2603:10b6:5:1a4::21) by DS7PR10MB5184.namprd10.prod.outlook.com (2603:10b6:5:38e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.17; Tue, 9 Mar 2021 10:22:06 +0000 Received: from DM6PR10MB3148.namprd10.prod.outlook.com ([fe80::f871:5965:2081:3934]) by DM6PR10MB3148.namprd10.prod.outlook.com ([fe80::f871:5965:2081:3934%5]) with mapi id 15.20.3890.038; Tue, 9 Mar 2021 10:22:06 +0000 From: David Edmondson To: qemu-devel@nongnu.org Subject: [RFC PATCH 4/4] coroutine/rwlock: Wake writers in preference to readers Date: Tue, 9 Mar 2021 10:21:57 +0000 Message-Id: <20210309102157.365356-5-david.edmondson@oracle.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210309102157.365356-1-david.edmondson@oracle.com> References: <20210309102157.365356-1-david.edmondson@oracle.com> X-Originating-IP: [2001:8b0:bb71:7140:64::1] X-ClientProxiedBy: LNXP123CA0017.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:d2::29) To DM6PR10MB3148.namprd10.prod.outlook.com (2603:10b6:5:1a4::21) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from disaster-area.hh.sledj.net (2001:8b0:bb71:7140:64::1) by LNXP123CA0017.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:d2::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.26 via Frontend Transport; Tue, 9 Mar 2021 10:22:05 +0000 Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 3d9f5ce7; Tue, 9 Mar 2021 10:21:57 +0000 (UTC) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2bda7950-e54d-4d93-0dc0-08d8e2e53068 X-MS-TrafficTypeDiagnostic: DS7PR10MB5184: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aphtz5cwYoyfWmYJUnUxmJ7hcqqqVTwnFzvIZCNB7kQ4uCJretO01njZ4cyYRdgb+GWBHtdl+m+He3lzjnM3zhUAtVsDm8vp/exkYlLpU/9OoeJvMl/dEv+I9Ndv5dbAeeOdW4ECwEBjQQeKFl5rcReORRDAWebYh3OfBQMjbvN5Ytq68nsKhcrQpbTQp6B0ZknqehgQuUVggoEo/782ckjh8EE09/6znWR8+S+ErenrMPH5vK8utwtcoCDDP8vcJwY+AW3q9D2pv/slFrZveUEfYSGOdmglydE3VlOhiJfyKlIzfrkmCQ3abLjd+PacH1EjgXT5eI4iWLeaIjtAufA0G/4r/sZuwMrrveZMe77HX1RPqvrtsNQ5iuZE2bdJ+dUQ6m+p/KUY0koHADdiM18QOW138L0cCq5/r3oGtGRfvsfVa0IKX2G/+gPVM6LNF/a0qXJD6WMQb3/qYLLdegsC/cMfqTdB+Y3KD/4LzxeCboHYNSmSjtJnl5dIDU+aqraBD6cE4m2XJCUHVpNEQQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR10MB3148.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(376002)(396003)(39860400002)(346002)(366004)(136003)(2616005)(66946007)(478600001)(107886003)(86362001)(1076003)(6916009)(66556008)(54906003)(66476007)(8936002)(8676002)(186003)(5660300002)(316002)(44832011)(52116002)(2906002)(4326008)(83380400001)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: WDOwxVNDs8Fl8/qSNctjhorTibDLb3SYz/utCNU+a2q7xVosDC986iMCcXV7mP3xvEBBGVD8k3GFDfId572/UfIJQy5o78BmlnhLeJDAlN3dL6yAyOTUSs6wTyzBRWhAF7s/XuNNZuHwExcaQOG2xyXkdjIf6HrQAkUW1lfmAjlh+G8LYxaUzDfb8jJPxMlIcmdaZ+O1uiVOlLUFlMzahu3jiP5LRMdllD3eg0WwTOZQhEE6aPszLolmyqyW+HeRWtGYkhk9y8E5ysUwgt5X1CdRt51pxjZY0AR5uGARZqh3Dle7n08HJf6LM13Qb3H6uFno5fWHruXR25yh3hxeHQbkP+coc/LkokQk6mrEO0euLwfksgs2oN39Esy//fXFbckc3/D5EVmPF9X91u0IfUkPpS2H/lgbBknRn5hLafwC8bTh9GXtYSW7/XGk4FIYdrE/D9cFS2g92JNtFz36swotNa7ByWQjQCE/uIaCiXvLCoQPgBi+8eyAFEFEaNXJoNIFd42Bl3ONuD+ogwTwguN/hJ9Euz4LFGGsJ06bl8uX8qn8goj25ANwJPv09GzbbLvmMXcnbkcK4vk92Q1JdfylmEoW1mNsNwZKbYfnpNOVCRWQu7M3wBbTT+69tIBFW69yoVpyn9tYr2kbege5lLKZBWOqRsI1YR0co2ERO5LmXmHEiF6z5F55gfsCL6kjdhTit20U3OYidaqfHjgnzW2Wyv46jW6X2cOfOOfQXUEa7GzV/0NDj1pTMe5APqm+sUQjJRcHy65tDbbA3fGs/Hn1PizaI+OSeq/auAfkcB1/nv5+RydpXeLAu1RApBdaLpR5qku4Q+Z4siJ9hOj4QvcCi5mM+n0kn09l982RJ10BNW/SmPvxAOIxV5ShqxAWH6jNXnTI8xXbtBaUWCvMmE2O994jw2ZWSt8GPKOtbkKvk6HS3kfWrLSVMqyMV8pJfYFCKVJCJ5BSqMDmBqThAhKYGALdM5mb90sKMcU3qWTHm92Aq7xMaG6z13Npa5xwvipBpF2pIQtaFpDKyLFn5DmywV8ZBFE46zeF/OqS1umNDfbXgY0NhGKVbcKeI4rAef5cX3+aXtKAhNEADbHX7ovBnBRxzu70ygbV6AEvrHmUOCH4TttqmQ8v7VPfssAdD8751KZqQ5uVQwQt1V1DDF0bHLbCP6Qeuba6gdOs0diAD7v2y8x0+p0Mi7JKbRvC1GVmZQpaNgfOmwUdCFVBIVce99Yd01K+rcLbr3gDtahWHhDeiEvLhpv4ZQ4VWRZIAaVCLT/GD7o85KVl/yChQT958XR7hNFQE1ekXljrYUcEmWFAZf8DLHL1FbJIFTgyahGdcazMn2s7RxD90eAEQw== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2bda7950-e54d-4d93-0dc0-08d8e2e53068 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB3148.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2021 10:22:06.2367 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: tcikEkZauK+dgYIyjD8YRQ/GAP8HkJtsGLrj0ptlH3d01ZX9G6mg385tk47c8ur/nTVRX6qERpCWGppMPcH6IO7Cud1lgTAqd0XMpMI8yYE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR10MB5184 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9917 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 bulkscore=0 malwarescore=0 spamscore=0 mlxlogscore=999 phishscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103090049 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9917 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1015 mlxscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 suspectscore=0 adultscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103090049 Received-SPF: pass client-ip=141.146.126.79; envelope-from=david.edmondson@oracle.com; helo=aserp2130.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-block@nongnu.org, Stefan Weil , Max Reitz , David Edmondson , Stefan Hajnoczi Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" A feature of the current rwlock is that if multiple coroutines hold a reader lock, all must be runnable. The unlock implementation relies on this, choosing to wake a single coroutine when the final read lock holder exits the critical section, assuming that it will wake a coroutine attempting to acquire a write lock. The downgrade implementation violates this assumption by creating a read lock owning coroutine that is exclusively runnable - any other coroutines that are waiting to acquire a read lock are *not* made runnable when the write lock holder converts its ownership to read only. As a result of this, a coroutine that downgrades a write lock can later cause unlock to wake a coroutine that is attempting to acquire a read lock rather than one aiming for a write lock, should the coroutines be so ordered in the wait queue. If the wait queue contains both read hopefuls and write hopefuls, any read hopeful coroutine that is woken will immediately go back onto the wait queue when it attempts to acquire the rwlock, due to the pending write acquisition. At this point there are no coroutines holding either read or write locks and no way for the coroutines in the queue to be made runnable. A hang ensues. Address this by using separate queues for coroutines attempting to acquire read and write ownership of the rwlock. When unlocking, prefer to make runnable a coroutine that is waiting for a write lock, but if none is available, make all coroutines waiting to take a read lock runnable. Signed-off-by: David Edmondson --- include/qemu/coroutine.h | 8 +++++--- util/qemu-coroutine-lock.c | 24 +++++++++++++++--------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h index 84eab6e3bf..3dfbf57faf 100644 --- a/include/qemu/coroutine.h +++ b/include/qemu/coroutine.h @@ -241,7 +241,8 @@ typedef struct CoRwlock { int pending_writer; int reader; CoMutex mutex; - CoQueue queue; + CoQueue rqueue; + CoQueue wqueue; } CoRwlock; /** @@ -283,8 +284,9 @@ void qemu_co_rwlock_downgrade(CoRwlock *lock); void qemu_co_rwlock_wrlock(CoRwlock *lock); /** - * Unlocks the read/write lock and schedules the next coroutine that was - * waiting for this lock to be run. + * Unlocks the read/write lock and schedules the next coroutine that + * was waiting for this lock to be run, preferring to wake one + * attempting to take a write lock over those taking a read lock. */ void qemu_co_rwlock_unlock(CoRwlock *lock); diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c index eb73cf11dc..c05c143142 100644 --- a/util/qemu-coroutine-lock.c +++ b/util/qemu-coroutine-lock.c @@ -330,7 +330,8 @@ void coroutine_fn qemu_co_mutex_unlock(CoMutex *mutex) void qemu_co_rwlock_init(CoRwlock *lock) { memset(lock, 0, sizeof(*lock)); - qemu_co_queue_init(&lock->queue); + qemu_co_queue_init(&lock->rqueue); + qemu_co_queue_init(&lock->wqueue); qemu_co_mutex_init(&lock->mutex); } @@ -341,7 +342,7 @@ void qemu_co_rwlock_rdlock(CoRwlock *lock) qemu_co_mutex_lock(&lock->mutex); /* For fairness, wait if a writer is in line. */ while (lock->pending_writer) { - qemu_co_queue_wait(&lock->queue, &lock->mutex); + qemu_co_queue_wait(&lock->rqueue, &lock->mutex); } lock->reader++; qemu_co_mutex_unlock(&lock->mutex); @@ -356,17 +357,22 @@ void qemu_co_rwlock_unlock(CoRwlock *lock) assert(qemu_in_coroutine()); if (!lock->reader) { - /* The critical section started in qemu_co_rwlock_wrlock. */ - qemu_co_queue_restart_all(&lock->queue); + /* The critical section started in qemu_co_rwlock_wrlock or + * qemu_co_rwlock_upgrade. + */ + qemu_co_queue_restart_all(&lock->wqueue); + qemu_co_queue_restart_all(&lock->rqueue); } else { self->locks_held--; qemu_co_mutex_lock(&lock->mutex); lock->reader--; assert(lock->reader >= 0); - /* Wakeup only one waiting writer */ - if (!lock->reader) { - qemu_co_queue_next(&lock->queue); + /* If there are no remaining readers wake one waiting writer + * or all waiting readers. + */ + if (!lock->reader && !qemu_co_queue_next(&lock->wqueue)) { + qemu_co_queue_restart_all(&lock->rqueue); } } qemu_co_mutex_unlock(&lock->mutex); @@ -392,7 +398,7 @@ void qemu_co_rwlock_wrlock(CoRwlock *lock) qemu_co_mutex_lock(&lock->mutex); lock->pending_writer++; while (lock->reader) { - qemu_co_queue_wait(&lock->queue, &lock->mutex); + qemu_co_queue_wait(&lock->wqueue, &lock->mutex); } lock->pending_writer--; @@ -411,7 +417,7 @@ void qemu_co_rwlock_upgrade(CoRwlock *lock) lock->reader--; lock->pending_writer++; while (lock->reader) { - qemu_co_queue_wait(&lock->queue, &lock->mutex); + qemu_co_queue_wait(&lock->wqueue, &lock->mutex); } lock->pending_writer--;