From patchwork Tue Mar 9 14:40:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Edmondson X-Patchwork-Id: 12125775 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 C16A3C433DB for ; Tue, 9 Mar 2021 15:17:20 +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 73675651AE for ; Tue, 9 Mar 2021 15:17:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 73675651AE 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]:32920 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lJe6o-0002Mv-CQ for qemu-devel@archiver.kernel.org; Tue, 09 Mar 2021 10:17:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46556) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJdXI-0002ok-C4; Tue, 09 Mar 2021 09:40:40 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:37304) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJdXB-0003nO-M0; Tue, 09 Mar 2021 09:40:36 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 129Edwd5153306; Tue, 9 Mar 2021 14:40:25 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-type : content-transfer-encoding : mime-version; s=corp-2020-01-29; bh=6X00bJZSU8oM4dFY4zWwMUXZMkp/GRsK7l1Po9JrRgA=; b=i9qHtUkUgQJ5KEkbzkwGufQGPcq25rpFdBf2y7YtAU16aYcrdeuWOZlNW1/j7zfMkuku HthN3KiyxwdUSuwBR19RC2dVIg2T6ZsYFuHuCJtdTj3vyeH2lTVZJ5WKbcDqG7Z8vJO/ yzhDV+zR2wvGQ7/KtrdhAB/GoFre4tdCD8+hxCxmLBriQzeDRtJ0vauJpj5z7ogo6929 PZJJple7KbK1Azkaa+I+dMy/0HWaay3mABk+W/PxrSuEYjx+TQLHei+XxZxvnI3ebObT 41xY6oxWbooxMdCXhrpEnLwDkswMP+EKA9Oljmc9AYZz7e0xX070nbE7JkC8Gy9Ez43p mA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 37415r7gh6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 09 Mar 2021 14:40:25 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 129EVOYn193150; Tue, 9 Mar 2021 14:40:24 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2046.outbound.protection.outlook.com [104.47.66.46]) by userp3030.oracle.com with ESMTP id 374knwwjvh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 09 Mar 2021 14:40:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nYfSuX7p5GiGsoFwkGPgc3XLzKc3S8TLQvdp4WeI1YQhtIPvMjuOjLSsNW9cD8kbkArzptsy2u/8yy7p+3RvV1NK0ziMlZmLmierEsRFYId5PzSp81+0wYhOXnfxDcR4BXEUKiWQNA94WZiKL2b1nfvMLi7cu5V3iV68SjLops3l5LHfgHGMr9i83SddAa5a2hUs532KB3odHwlbxhBh3d3Bfs3wOchlVilJk72tIM4whRCI66lmI6v+8+znph/UnSrl5ox0fq2sVqw7PVliv89U3P8LUDUJwJq0EVpQLUj8sH7MLRMKtxK7iOqxo5SYvUQd2dBolvlDUgk7MVm04g== 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=6X00bJZSU8oM4dFY4zWwMUXZMkp/GRsK7l1Po9JrRgA=; b=GQWtQ59tUqRx8AALPmSHAVFenQsTQ5gCf2+qvbt2UvdlbQqGo4ytUPDNbL/lU4gZSVNJyPVHbMzpepF2vZxnsmpGaofjvANPog6BC9XJdDv5w2C6g47hDqP9QwBQT4Mxowbmn9DndkyiYQy97hchydKJFhje8DPltlvqfLwUpFoAgxZf9UArcvg3meMX6hJ0N5uVZVeSVFi8iQVUGi6/b7hmOBrjpmUr/NgcTfUpViACAz3Qju66kgfY3BgaAgI2ePGRm1asxuMc4XitqSGqZ/vc8PFnuCB+Q29iBdmAdFk9f2YkcPI2HqiALEU0PH1ECvarDsL7VKc9JmWyCEHPFw== 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=6X00bJZSU8oM4dFY4zWwMUXZMkp/GRsK7l1Po9JrRgA=; b=OfOvzPK/+bPm0Vl0XRCslvPpJFXaD+x1Y1m1v1y4AtKXP6M1Kemwg+uStGEBGyQAS4mR/3qZDFPIcPczRiC+PCneyUr9JNx4gCwdUbXZBkQ/t+4Wwi45nv4rD/2M7Voj5dhhzpgJ73mYJ945JL3EwiWDYuAu8nzlZoaIMFU08oM= 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 DM5PR10MB1771.namprd10.prod.outlook.com (2603:10b6:4:8::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.29; Tue, 9 Mar 2021 14:40:22 +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 14:40:22 +0000 From: David Edmondson To: qemu-devel@nongnu.org Subject: [PATCH v2 1/6] block/vdi: When writing new bmap entry fails, don't leak the buffer Date: Tue, 9 Mar 2021 14:40:10 +0000 Message-Id: <20210309144015.557477-2-david.edmondson@oracle.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210309144015.557477-1-david.edmondson@oracle.com> References: <20210309144015.557477-1-david.edmondson@oracle.com> X-Originating-IP: [2001:8b0:bb71:7140:64::1] X-ClientProxiedBy: LO2P265CA0214.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9e::34) 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 LO2P265CA0214.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9e::34) 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 14:40:21 +0000 Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 4b3c2d4d; Tue, 9 Mar 2021 14:40:15 +0000 (UTC) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 18c55d63-0723-4e30-a91e-08d8e3094505 X-MS-TrafficTypeDiagnostic: DM5PR10MB1771: 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: 4s5oCH6ZnLIGgLo2jnr8Ru+YrJhsX+esCAEJeX+qnOTps09E68h5gvB9G8AwuzRO58I04uhPsu6SjKM3fnSMU2jdx+PLtNKcJmURBkUeX8dSIA1OoDLJVB4xUXF9iJOma2joLyFB4K5odwgdLIHPpgtYHgIFQm8ZgaAcqzHo1eyXkTxe1Ns9pCaqnTOkkUsmB+RlT+ZcaVIuGpREKjXPdmCCiQR1oq0HbXqCgAiY+qHrVb6UtgnHLAXJlnFRFA9I3WQ2J/7LjRMYbhiriY4PPVpkGAoKg4PyIHeOyn3zbHhO5ArGkqWKaLYZKJFjH76ihFMczwVxzbInFZ2qUqIhJqw/JXjqq/RT9/rS+VP2ee7hmMUmg3QlWzFHoH1H1Hliburj0jSXYgeAWj6Al1Cuuc06Q9g59WQRpBz+3a++RpyFYiB/B9Dc63YJtptWMp7c1Z2CFl14SHNF1ZTJkjW+WiXN5dlLamI1JehxZ2Cbfh0omtpoqRVFvznveFb2Gr/bH1dDUAP2cSvnQyinmrRH8Q== 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:(366004)(39860400002)(346002)(396003)(376002)(136003)(86362001)(186003)(83380400001)(66946007)(44832011)(316002)(52116002)(1076003)(36756003)(8676002)(8936002)(54906003)(66556008)(6916009)(478600001)(2616005)(4744005)(5660300002)(4326008)(2906002)(6666004)(66476007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?+/lWq7nLwT/pJfxbkyJUv+EAh2lDfS?= =?utf-8?q?VY6Xd+raRHMvsK7dVyIswu2NzrXi0l6/wbpcadbKbj4E5sEliKBQEOj9j8UUwswlO?= =?utf-8?q?ljcMJ9ZibYmD2JJV4TzSFba5vaKr/fnz4bTsZeVif7KiRAqP3MDH6pVK2jzOKVM/Q?= =?utf-8?q?Fvk1qIYImES6WVhqObgTll1k2HKLH/Qk7HisiWlsSMCK/wJWaq7MTxcCPWmOw2rtr?= =?utf-8?q?h5fTGwSJjRdn3nnRKqFg5Ds8Y8o6h/KAu7Sp32AXnSsaUv4+DdIF9biCIEtCLUlff?= =?utf-8?q?Xwt3n1GhvbiIuIYUh99jwm/hvXT9VK/XOJAoITNnVOAEKmlcwahJXWeyCeibHnhL1?= =?utf-8?q?m9SZLXvCA6/+QuyC2b4vh8YHgeIS9LQmgxyGC+o3KsPtabUseaAGHM9eriyqOsgpb?= =?utf-8?q?azcKhGBmERaiZYtMJgsJodkgZqu0Ng67bYoCcJKPRUdg0lxIDECQN46V8aK8c5oIt?= =?utf-8?q?FsXHZWe0Qb2S0kUdfb1cayRhQaWs56uZ3lf/14H4paRRXKJZ5q4E/FN93Tiqw0ewg?= =?utf-8?q?TjFOGhFhLuLhXz0GCXbACGfP6TmMeb3hIbtg8ft7CLCHdTxesmR24OYlP3rD1qhqT?= =?utf-8?q?z3qe6Sh82ezPsu04a4p4mc3JT5Mgcwp01Pi0TATGB0JqJijOdDbAROHdg1/8Jj+gv?= =?utf-8?q?wAkvQ7f3uJS1OtXww2plq0JlwgnHNLXGXN1cBuCLihCn55yKLTLgzRVmWR0lZHCmL?= =?utf-8?q?qKLiJGIsSZFQgh1hNeWNUqO+dh4UDPrZT2kW/vCzhSpuIRHiYYnWpKX6NAjQ9wQJ8?= =?utf-8?q?p+wWo9ofJL+NIss62lOCS1NY+M5mm5xTOmrFPhYHS6bTiWbRzmt8diGl2Yca96hWT?= =?utf-8?q?55xHvM9SI3jQo0F9JB6gvMHX2vmFjGtA6JpmfGyVn3VDKv+ylWPKKau1QdK4Wsq2K?= =?utf-8?q?4g5RdKzw5qMN5p2A6HvmYtZp8Ikdq5gO8IkvN4B7ep1y4Wt2K+SUCw0RoW5llJRp8?= =?utf-8?q?qGQZ/e/U/Pfu3AWjF3iRYrSYY3YzVT56sbAbFJ+DhlY949y1Ph7BZeYrC/LWiTT4i?= =?utf-8?q?or/KuIzV5ClD3hTu3ZJrEBT3Pc2vuyG5lTWeRMMdheNxCzjhql9E5Rv2iIgHHRadP?= =?utf-8?q?GciGpbdtsMNA/oK5uAjgnOnzBIxsob6kfb98xjtVubtUNyZMHHZnwfxR8UWjbUCl8?= =?utf-8?q?F61TkHNkX2HfygQeL+uDsU+KYRtm5Cuqso97WP0hw2lQUTSAqIIowG6gYg7alGo+V?= =?utf-8?q?8V7wrj2HXQw1dRdeaZtDj6++Jm4Q3hVkqbY4R96314T+QHs7YFk1YEOoDRijHJ1MB?= =?utf-8?q?uXWMtixXpZELcGjYZZO9sZdc9j41AuOOST3Q=3D=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 18c55d63-0723-4e30-a91e-08d8e3094505 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB3148.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2021 14:40:22.7643 (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: URhhzJvYNwgQNSlxZSnFWHRxQ9KvCd7aq5EMPZAmfD8I5brupoBdX78wa9D7s1keTB2NCBSlDF1eKe6mlvLusxqaGuGc/WVgBSastqrYono= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR10MB1771 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 adultscore=0 phishscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103090074 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9917 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=999 malwarescore=0 suspectscore=0 adultscore=0 phishscore=0 spamscore=0 priorityscore=1501 bulkscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103090075 Received-SPF: pass client-ip=156.151.31.86; envelope-from=david.edmondson@oracle.com; helo=userp2130.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 , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= 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. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: David Edmondson --- 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 14:40:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Edmondson X-Patchwork-Id: 12125741 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 9FA55C433DB for ; Tue, 9 Mar 2021 15:11: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 03D576521D for ; Tue, 9 Mar 2021 15:11:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 03D576521D 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]:43690 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lJe1M-0003Mn-UV for qemu-devel@archiver.kernel.org; Tue, 09 Mar 2021 10:11:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46538) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJdXH-0002nn-2d; Tue, 09 Mar 2021 09:40:35 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:47294) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJdXC-0003sH-PF; Tue, 09 Mar 2021 09:40:34 -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 129EdtEF002644; Tue, 9 Mar 2021 14:40:29 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=jlWL8VLoTEUmQNMgPktwAX4ibymeWTXLWSIZnsLqGQI64ReLlxXBCYBgfOf6vln/yUMR xOvi7fkFRyIoAMs5IVBBqAYwEzInVFdJ/LkBcWh9Q5kNCa/fxbiUk8Vqq4rJIMXREtBT zOJUdcnpvIXKo3YSvx++SlPI9UNBGylB2bDULbRxQw5wikNTkwzSALV/S/i2eVOqiCug o1k9aba12m1RZul3kLHDOXECB2a1E7lmNX3uoTZdqgwc5+Iqz7bWBBKSkcy7wkUf2QsI IoqgeKMylYRrj3yWb46BabDsW322s9jRReqqRhIZTPAnMO7INewrTsoBTL0ZMVqnUkvL Kw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2130.oracle.com with ESMTP id 373y8bqmnc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 09 Mar 2021 14:40:29 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 129EVOYq193150; Tue, 9 Mar 2021 14:40:28 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2046.outbound.protection.outlook.com [104.47.66.46]) by userp3030.oracle.com with ESMTP id 374knwwjvh-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 09 Mar 2021 14:40:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X6Fmd1qr3Gv6IgjaZ7vKKIbiJaNT8JTjYAqkrReNF9IGoRAwai7ejTgw5ttHRUlykBR2IJsrwFklJ2pbyOVlXDVKtMNGms4SVZ8Tnqpo/27cLBPa2bapw6C7HRInvTG+vBDC51iOd+fNgsFtDOda72B4NxR7gziYNSHduyviQIINtSwr361evKpRKoGv91mLzv297OO2VrcL32hBz6vFDgQ4Czdc0ywnMtZJVWPoFoAqNuPOPEsfUTFW4gcty1snTluTMfe4qy0E36I+mIC7XXPxUTfy76cnBecuirO48xq98OD2a3Ern39vREqTucC1Pfa6JV2kgekIDp8YmqcB8w== 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=eGtAp1NwEyAm+MPsr9NVdie2i9c1i1NJ3JOGG3JVmTWRVl+KmVyB3VuFuMoEkhwtsVTWbI5+fVxPC93RSnf3MJ8dIX/N5BKE4hPQHV9yRck++I5qeqt5kQdPaCX3RuVu4fFk2vGksI7i3NHO67w2sDnUwTROxc1JHmiZcjVFTHS4UxAD19NGv3CMjM/giwpX6kEwx94pIRFG9YFs57XpGfFnltMUL/FGqa2q5F8gqSDeCGySJZ/F+I47XJvdJWr3Nt7P5ATvOmYPSWTgB0SzNpCbQ9eZED64/lbB3jR06I+UfVzr1bULvHDsNOA+5MlDXt8oSVN0D3y1Y5C9KPknMQ== 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=MeYwFPf1dbTmMTp9Z7ftye5s5B7cA+5NKfUX7KSV0CoB1VcooERIYNKb1YQowYFia6qLkli/t9bS1w9pDvJGfcKMvlptKIYxdkhZQjIbx0ROMhOa0pWAPMs28nH1suvsxAkGngiIKA8XRPk3QojvW+eL5n5A9dVrlhuDUPaSEg4= 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 DM5PR10MB1771.namprd10.prod.outlook.com (2603:10b6:4:8::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.29; Tue, 9 Mar 2021 14:40:23 +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 14:40:23 +0000 From: David Edmondson To: qemu-devel@nongnu.org Subject: [PATCH v2 2/6] block/vdi: Don't assume that blocks are larger than VdiHeader Date: Tue, 9 Mar 2021 14:40:11 +0000 Message-Id: <20210309144015.557477-3-david.edmondson@oracle.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210309144015.557477-1-david.edmondson@oracle.com> References: <20210309144015.557477-1-david.edmondson@oracle.com> X-Originating-IP: [2001:8b0:bb71:7140:64::1] X-ClientProxiedBy: LO4P123CA0438.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a9::11) 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 LO4P123CA0438.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a9::11) 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 14:40:21 +0000 Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 095b5918; Tue, 9 Mar 2021 14:40:15 +0000 (UTC) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5d4663a1-f6d8-4aab-b689-08d8e309453c X-MS-TrafficTypeDiagnostic: DM5PR10MB1771: 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: F1dQskkn7y0AXDm+AaH+Fe+YpNDvxbTpxt4L8+/iVAN3EcKmAkoaQEvznYutU0HF9D2BPY4o9BjDvZMNlA1lGO54Vrisplcp/MwXcj+YubLibiGRKIu/073s8QFekOjvsVOObvX4h6lriZxlTOBrPC9ez/iZpw2Tr9CwOW+moAkoTme/DHErfWgVIpLjXskumau2ptiDbr0RBY1MMD1WqZR+kQK4U0yewLly2EPYtZCMuD+2qtmkD+ItwIk6xjtS0YP283oEWCxE3+W1/gQv1DIVWgxrKQ5L1lQ4kTmQOAoLPaMzhqiuNd6JuSnAQRk7hHc/U+pfSzjh9b4TowLwtqf50HKSeOITYar5pJhh2yIKBTtkdmEvmIbnuG/ymPOriPtqjGYITiARqewCLMZohrPJOZ2k8Y+DQwcMGYyFuJYnob3cJH8wjjdjlx09acRchMYE6YN2s4cwDmfjGDnhLyoog9gXwQ672OgudDDTVyEwzZfD1d3ySiVJSlUB5HdDBUG8+7AaPH+vZ2QLMVmsKA== 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:(366004)(39860400002)(346002)(396003)(376002)(136003)(86362001)(186003)(83380400001)(66946007)(44832011)(316002)(52116002)(1076003)(36756003)(8676002)(8936002)(107886003)(54906003)(66556008)(6916009)(478600001)(2616005)(5660300002)(4326008)(2906002)(6666004)(66476007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 78KExhegtJqtUrxFEEAC+tC8C/tTaRO/zAP33zG/XWgspl98DCAuX6zBxK7NB4AEQsv2DFLRIEDbmyNLD/SxjbOc1GL5cL0Ql4hM6FqvMrOrtg7O2Xsor8hzQ4mosGG6oxnTJk9XgrJnPlxZs/xyPjsZNbImsP/1xLPi6vEA+krsNt2rkzp/c1jQi3lS6/zPRWyRlq785o6KShLUeWctLcHuGPVD81WbZtOKDJOe61R1tHXYix8gfKZDtNEzJvJk/o/eTZ6R08sqm/U/T3jtA5AkNQ2P3DwPROyRRKdd5o83O2nI36wBpaxPBraM3WPSb19HJbY4ilwSV/2prNsPS3vFwXT3zQiAhYEPXIPMBix0waFJYc3swGaWf81o4wC6pDy0l8esqx5VyUJrvYYcApj3kSeeTip84maNyneIEIqqTOm6PlvXOgdAs2DvM42qDjKUsMM2LD1HZj3Mn1kC/kCM7jgJ7OcNqSOO+Dbi5sfq6oTWFEsDgwKrK+M0TY6iFxMzc7uJkj5LEcPuVVICzktw4Sieb4ZTsJMFGdnFVW+SOy6urHbqFpvhWz3kuh/I3kQUsCOesdGWSBP9fXDI4Gv74wDQVNHghwZctCPhJ/sIrwgLbjf0l4XC2A7RzisuLiDRwLQMAWAbQAm764F6PA/H7Ufgy64dGQ3R7q82qgZgcoZ2OkMgtNF5PxnrCgRqRFf7wq3CzEeGr3AqdaikKVVZ0jIXc9ioXHCvO1p2ldEacO9ZvGkDni5SGsMj2WLHWTa5OpoKWuiOD5IhWTZFhYBZjawG1KKRBx1I/uHwsBcX2UDMXc+dtmyun9dsKKrGK+HOaS0UIerxGZtCRyJZROB6F/17KHYyGVgUIQseESvOFxFW49df0d/cnPrKJPIo/UdDWS4I0cnYeVg5qAnRJcQotvgIugIg7Tz/TXA35JJqyL9ahoMIHExoQRKfVVw++uWHjhvH2S2c8xlxB8vKH8Ob6Kq0FE1X3CmqMCcycpsUyToZYuyaqthDhafsYys93kLFcGWk9TmJtf7KXl4Kr0KTAvBPkjVr1cYmXrMhV2so6eMQj9JYktOAr+1y9Jwa1Uz24A0PwxQOIntWLV+SL+/uoKnXoRUra1kTrVDZaLsumPFSYNvqOZhBSMzo+udonnIlxspbIHepdhy1A8YzPzXLjDY0eBrXAKmRsYKsdIv3CT2ZA5gvloznH8ymCbiXaYYni6NUrNrVF/KJ/eiCsg7sKGx/6prp25q0YKNl1BxQOJV0x5a8q+/rOloQx5G+gp8h9Cl8IksFfkILxrwoVm7sCGR07M59cMFS2/XbEgAUzdZbtM9QAc8Gyto+28YQaUO0EK0NPsLuTmuTTYttVw== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5d4663a1-f6d8-4aab-b689-08d8e309453c X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB3148.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2021 14:40:23.2830 (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: /6aYvGytB5Jq0CpYqxCU2QhQHDobHwhdkpZbUQ4b53jQIgk1bI1mzuOzFD4dKSJSbsuHuh2SyiOAxIWYIRmxglyTAOvUiUacov2mIq5FHJs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR10MB1771 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 adultscore=0 phishscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103090074 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-2103090075 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" 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 14:40:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Edmondson X-Patchwork-Id: 12125771 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 ED0A7C433E0 for ; Tue, 9 Mar 2021 15:15:09 +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 697DF651BB for ; Tue, 9 Mar 2021 15:15:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 697DF651BB 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]:53412 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lJe4i-0007Tf-6h for qemu-devel@archiver.kernel.org; Tue, 09 Mar 2021 10:15:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46582) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJdXM-0002ph-NY; Tue, 09 Mar 2021 09:40:40 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:37356) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJdXD-0003sW-Ab; Tue, 09 Mar 2021 09:40:40 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 129EeCwP153600; Tue, 9 Mar 2021 14:40:29 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-type : content-transfer-encoding : mime-version; s=corp-2020-01-29; bh=D9mVPDGiI7A0cK7HlpOiZ4Ww6H8cT2FDX1LOWmzKMrg=; b=ICSyRpPpA72o3QuW8JH9RRaXdZ6PPCcZw8nHfJaTfEGDYmRpdLK5VnkPGNC+4wfh3bun d5XqWmNg2aVWZucg0aGHLn8SszUwczbD32+Myy54XJ2P0GxtYCHv+bH3Y+G/jlDaTK7n k2rjJEmGT5X99V3zAOpmV8oqQioyIL/mrlA9Yu4KEvAqGS5n0DqiON0N9yOV50IwvzmP OtDS76e45LcTW6d4jJDzSPMpYw5GtLUvaVp6bblRQV6zKWrzr2UIBl68+J7ylpMcZ2AJ Pop3K/8O06H1Mu8g1mFVVRYwX6O4Y14C2U+rVPrgQpPlmlmmvG/IRGjGnTUBGOQtXtwQ LQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 37415r7gh8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 09 Mar 2021 14:40:29 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 129EVOYr193150; Tue, 9 Mar 2021 14:40:29 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2046.outbound.protection.outlook.com [104.47.66.46]) by userp3030.oracle.com with ESMTP id 374knwwjvh-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 09 Mar 2021 14:40:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZbQXWX1gT4ynho9Xiom+cOoPd4Sk3A+6NzeDYvitu1GzkG80yASwMNPG6QPjmp5unl6UX8UxKSC7FUwv9UElxoFk0kc5I+jI8AOQdE0ujCqX50WGEueJuw53bvtObxUr88OYOQiFP6zqPt4dQfCE+nl01WiMMWcOhn8HF6q8vxN1i3v3zUkf5M2Fa2gy2J0rxqk89WtexxPrZpVctt4tgwwp88ixAYAMSQmJZ8mEW7vGbcwaiiDE2zFsaykGTR0EbajYAd+Gk0o+oM2PFiOwkvlusCIvvEEMZn6YU8FennAPyaazdnqOD5EJNIPKrF8TAn0HCWBHAiQkX4X+iCBPSA== 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=D9mVPDGiI7A0cK7HlpOiZ4Ww6H8cT2FDX1LOWmzKMrg=; b=actxkTm4Yagms481jgstwC38IZbtH4+2zUEg6NenfskI4LBHe1LN0fSYeiAbUnZ39hdjBFSGm64qkVRNX3p64FVV5hLy2GydIg7wUeKUIJ4wrXxBpBbYAxo6QwKuLyjm8zigBnSl0wXS13iyO08BcL0TZ7w8EsvnOapiRhD19Z7OAD72MiVEtd/FQPsnZFQyxcF+GBBY4W91CMqsU+aVGUXl9rYFZsirYYNFx3VxTUH8e9ZLEz5W7qCjIg6B93rZoQEOBWmOQ52wA72MtsQAyEUKW7bwQS6gOSYQEvF3DxYI/ChqWlnf0tUJMLZ+NIRX+WHu37cXfGJ6tiv97qhTeQ== 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=D9mVPDGiI7A0cK7HlpOiZ4Ww6H8cT2FDX1LOWmzKMrg=; b=XmLvLgOKCwpK0fSTNdZFYeXl+jBi5+Jry5Lk34O9GeT/Ti2IOhJDpP8TlqtMApHpwY+4iwl+/NS76Ag2h6e2+b/6nE818LDIP6DpdgmLEzZWRWos8XSBL2mU9TjX0oWB1vEex1Rpt77nbUP3FGBxa1iSoZqQ6B3JYTpSWspCyo8= 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 DM5PR10MB1771.namprd10.prod.outlook.com (2603:10b6:4:8::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.29; Tue, 9 Mar 2021 14:40:24 +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 14:40:24 +0000 From: David Edmondson To: qemu-devel@nongnu.org Subject: [PATCH v2 3/6] coroutine/mutex: Store the coroutine in the CoWaitRecord only once Date: Tue, 9 Mar 2021 14:40:12 +0000 Message-Id: <20210309144015.557477-4-david.edmondson@oracle.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210309144015.557477-1-david.edmondson@oracle.com> References: <20210309144015.557477-1-david.edmondson@oracle.com> X-Originating-IP: [2001:8b0:bb71:7140:64::1] X-ClientProxiedBy: LO2P265CA0214.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9e::34) 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 LO2P265CA0214.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9e::34) 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 14:40:23 +0000 Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 16c664e3; Tue, 9 Mar 2021 14:40:15 +0000 (UTC) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 01b315d6-211c-43e5-e173-08d8e3094637 X-MS-TrafficTypeDiagnostic: DM5PR10MB1771: 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: hAN/ZpC6z8DJpko2Racloa2aW2MhwnVLyanQ8//DLRMKlWtYQB/0HBok/UysRh1I2Jq5PdbcERVIRBnNdm8zDt1ZcNWbZme3mJ93WQ17o8g9EzjNwiGfI4EEAYdqIbXAwJAIKJ384CNTjOsLMb0bOH59jcC6W8j8n+hrRVIY3EL/JT5ugOKgEJBGNVviqj1q3Q71FsM+Mfp2wKgBOF7hNWKeUgoidwB9+/wqOEiFAMK+Spx37CxY+mL8zg6X4xTdb735bBT+nJQHyFU1O5V9jjXii3SLoMQ8J/f7RtIYxuyawyu6HA7d/wvA0JMfst58pzcUBiBB/EJsN2cwxMKajeiJ+XQv/g35/+Wrb43tD4ZzuDW/SqL5eIvFsaOMOAIn7AwSREJhff4Gw1l6y5xBRMssHKTMxc9Y1UNNtJc2jHtWN9c/iePe6BZNeSDexTME/yeXh8K2kkHnoYB1iV6nMhUWxluL3uty4ExtBn1UoWgZa4+5wRTYw/YYg0S8V39NEDyd2thdqVJtwuOGnMWrNw== 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)(366004)(39860400002)(346002)(396003)(376002)(136003)(86362001)(186003)(83380400001)(66946007)(44832011)(316002)(52116002)(1076003)(36756003)(8676002)(8936002)(54906003)(66556008)(6916009)(478600001)(2616005)(4744005)(5660300002)(4326008)(2906002)(6666004)(66476007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?s5hBq9bPnTWkmetgEJcLQHvl9wDF+w?= =?utf-8?q?27uMtG4EDU975gzAZS3j/ittY9bqYCX6kabpGN/capAkNGPCk1NMZR0RKWy9KgsWr?= =?utf-8?q?8a7aou3JANBGdwgleWdycv3kpmPcebq5VhLrbT/fk5r7vEjcM5NY84NoHZY9gi/Sx?= =?utf-8?q?Qf7fQCyDnY6fKjAiXRnk1kJVMFOoCPovSI3xwVKMcLSs4o7LwTvOaVT5P9+afzGAi?= =?utf-8?q?f3cNLLwVsGBQH0z/3zcAWa8H9HzokLQ+1iJ5l23EnBWy4nICtBHjfFJd2C/uMM6FR?= =?utf-8?q?YuiQgGPm8nCXeOhaReMrV7V9nu05BujCClZsTunYRUDq5KHi62KrDET7lhTwbGiOG?= =?utf-8?q?zXkGmiSLweeJRqUSqUFGRv69eG1KIeTGD8tQ+YGCZIWlw3/sr4xG6D0FOJtkFihWr?= =?utf-8?q?OdlxRVGSF7d3ywjxMTuxzUNx1eiZ71RVxmVWPXtIwkpMVXEeoRbXLtTFlnDskocdh?= =?utf-8?q?rIO7qehhPeRKJA9Y9gkHcB55Rn9PRqadIEnG6Etx4uvuo+izInS4DB45Vqk58sirP?= =?utf-8?q?EsBpF0sIF4EUDaMI2DdSCEDBvJEvZFXiq3iT8TEBUhG0Qx7/zRKbZpnhjNoxjhGtA?= =?utf-8?q?z5JebTpwEdwBhBg5eCKAW0Cp4ECEcuo1R8GEc03Wm3Z0d3u9HtA0jdxw1SOkD0qea?= =?utf-8?q?EGvApfSfBmAh8gHIlM1D9TOLuocmA/h4mYSNXdHSSisChbcNULKoYwIllefNPEo6k?= =?utf-8?q?JkjGdccModQTec9JA8jFdkReiE1uUVOKufCt4+0TdvyZg+ifGn6bCIIdJyYTjmq8W?= =?utf-8?q?OCV8tLdIS3bmC0jQ4oMNhDcjkDci/ZZxPGvthRIUpyPeKJOZqlxcsEJnHmH1WjGBn?= =?utf-8?q?JAiikuNgTwMJl8hzjwV4E2RLledbUqaBqb0dUUK+0CFTkl0QWGktAEGfNbOs4/Oht?= =?utf-8?q?R/ZQntQyginc6z8JntT9aCoBROIJkHeksQ0VPfHfeFWeT7tOuUPRNNbyVQwiHRiQT?= =?utf-8?q?3GqbhZN5i6B3mbA8bJ+IYR6M/6hNJUnSpiQLY2Bs/ylMN8J5ugLpR4wOZ4MMjRuZF?= =?utf-8?q?WhQ5JtNNx+fuKoLo8TcSv4jjwls5ymPI49v1fWnWgN5KkQKt0zBz+qvg75fCTtq51?= =?utf-8?q?GEfu9t88AjHTTQhbwc/CjzRXQhaZ/1Gwvz4/Rjb6wbbICe5tx5dYrh+8gu6WdaA95?= =?utf-8?q?KHVn2IpfDlZW7obUv/9n9q4Rrew8AEUasbpTwTcJFEZSCMB6PNOQeIO8OnAUfwjiJ?= =?utf-8?q?p4tv2HcQh82LC7FlpHQldY5A4vFo1Y5u6L97gnTWVVWUWCNDoisWhuyOXeHyTEr/m?= =?utf-8?q?gITgpjWDo6DQ7gb+B3W2TOeZ28JhiVYdS+Cg=3D=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 01b315d6-211c-43e5-e173-08d8e3094637 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB3148.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2021 14:40:24.7561 (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: uSt8duDHqZKvQtHuSpZPwEgG5EsCvn2GpWtIoYkTHxQFTES1g1X5oStV7lhONdSjGNa0oUr/sdYPVu65vg4gB9XDW1iqnTuQ6eZlCO9MXk8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR10MB1771 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 adultscore=0 phishscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103090074 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9917 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=999 malwarescore=0 suspectscore=0 adultscore=0 phishscore=0 spamscore=0 priorityscore=1501 bulkscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103090075 Received-SPF: pass client-ip=156.151.31.86; envelope-from=david.edmondson@oracle.com; helo=userp2130.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 , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= 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. Reviewed-by: Paolo Bonzini Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: David Edmondson --- 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 14:40:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Edmondson X-Patchwork-Id: 12125785 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 7C69DC433DB for ; Tue, 9 Mar 2021 15:20:54 +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 2375365274 for ; Tue, 9 Mar 2021 15:20:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2375365274 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]:43652 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lJeAH-0006k3-8E for qemu-devel@archiver.kernel.org; Tue, 09 Mar 2021 10:20:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46630) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJdXQ-0002wf-5m; Tue, 09 Mar 2021 09:40:44 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:52522) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJdXE-0003so-AW; Tue, 09 Mar 2021 09:40:43 -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 129EdG9n174401; Tue, 9 Mar 2021 14:40:30 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=pvrIToVSpar3E6aZZeMOPhI7q+h/49M50w+RUBHTSDM=; b=p+B7aLvkXOkzdetpQUWs+o5Y0Xn7pmb4On4VGjshvNz2aDAGmpLYexf2LH776acl+7SI BL0yK/Us9uKffJ3o52Y8BYudOh72uD4QrJYwvHPPm/bLOrCqaxUBSV6VYpZ/Qg7ftaGx uFah2+txIDlyBqrQEvA8CSlAudgw6ZI0+cKKHD+9zHGM4nQnL3n7nU5A64gBVg32aSCA EKfXlKjmB7af9EMum0CqO8tkPmI2V6a8aBDYDv9G1v20KKlvNMDD0q9V/0UW5pnd6PrO tfo2g7kRiw/WAEihXqtRXiyYjKnE1qB8TD0OTuwh7T7CMoX05UmX2Y+Dmm7qVlChnoPx BQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 3742cn7fe2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 09 Mar 2021 14:40:30 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 129EVOYs193150; Tue, 9 Mar 2021 14:40:29 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2046.outbound.protection.outlook.com [104.47.66.46]) by userp3030.oracle.com with ESMTP id 374knwwjvh-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 09 Mar 2021 14:40:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ULl4soq0tdMWBfj2bYxSI4oWrEDkuNOilaW11cfkaRrndZxhLr6whoIOERzbH2cQbX3gZm0b0IcMrb6n00Lr7tQC1H1e1d1+Qcr8GAEONOUc95LSx6SPGuoZl7IB8xYtGZ+/z0BBrFoFfbjKGOr+8miCyvDT9rCmt6Ts5oD/SZQTlbU375z7sHdra1GOs14bdSZMDBVqqUpnGMFA/bPrb1InM+xDD4g5bZhzTZMKo1MYYpwQgCtmrAs/DcwmrrzylS50V7V9V3ytfoWlA/RdFj810VkgJMg6RYH9wX2PLB4lO/AvHR0eo+1SBaIPKZz7vVoRUAR5BZutRSHblrwryA== 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=pvrIToVSpar3E6aZZeMOPhI7q+h/49M50w+RUBHTSDM=; b=GnE8/zzL95Yc+BMeSdGoauLNuGzO7cKqCGkOFtt37lwIcvC24MgGVUvTDdp4Easg1Nryddij9YN7SdWdFHwk7O6QierC1rHu/HOtFBjvPGLAW+cLOIP2BfG41IYNW+MekY1SJLuuL9rlOcqrcaLXG+2+mdsb6TPuqbuN6o8H27iKYhZGax8bkkQLcnnkFuXtA/XZXXdTVTkJ6PTf5Kt3/j4M//RDzSbD8wGHOZG1Au1TRTZrZWjR5SzLVyTwmdAiciG145uxrK1uKZkGAfvCMEaBwC5gkaGVD2mkVpU/eYKJJGWfQHOOeb2EcNRn6Q5DylzYOl2dEAc0mUfuF+ZWQg== 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=pvrIToVSpar3E6aZZeMOPhI7q+h/49M50w+RUBHTSDM=; b=uEWvoIdPCP+lHgD9ToObt4zUu+BCcepqwz1SSNqQ/lBlBQqMWXuSHB5bJwhANTTb+i/1vTqh0Q6dcr8sLi3H6n7exM+hqGbDUNAYC7QFH6i0yNyMoRkmsyW+vLdLgVlsjHCKmnkXWkkfgRca22xOcxCLezP8hqsUZ1jXzHRE0/4= 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 DM5PR10MB1771.namprd10.prod.outlook.com (2603:10b6:4:8::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.29; Tue, 9 Mar 2021 14:40:25 +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 14:40:25 +0000 From: David Edmondson To: qemu-devel@nongnu.org Subject: [PATCH v2 4/6] test-coroutine: Add rwlock downgrade test Date: Tue, 9 Mar 2021 14:40:13 +0000 Message-Id: <20210309144015.557477-5-david.edmondson@oracle.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210309144015.557477-1-david.edmondson@oracle.com> References: <20210309144015.557477-1-david.edmondson@oracle.com> X-Originating-IP: [2001:8b0:bb71:7140:64::1] X-ClientProxiedBy: LO4P123CA0438.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a9::11) 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 LO4P123CA0438.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a9::11) 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 14:40:23 +0000 Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 4a6187d0; Tue, 9 Mar 2021 14:40:15 +0000 (UTC) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 83b06348-a26c-46d3-aee3-08d8e309465f X-MS-TrafficTypeDiagnostic: DM5PR10MB1771: 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: jtVmiYuFmqBee05eYiyD/AnWGzH5l2OcGhm/L201AjOf0liADoYeOwfa721ZhZCnMtDr0rvM/ZVIrRUZbgPlZ9xBpqsAiS7Of70alwkVlm/YBxd6mXdyq2cEIPKRygDcjidoazprXdJn+Vs8i1qDfJumnGSth5GsTE7ZBAPTGpOJpABRvqMicBErxbZxPw/Gz40p/GJJ/YFCTwjtEOZVt8+UYtD6ojziP9o6Cr+THn5y1Nb/v/LhGEExzgkUFhCItiKrQ6I9PJputGfWVcVf32EnYyAe5QBOyW1Xvd1yMwJYMmfth7TFn0E3vIKQXnPr7cZikygVv9X95s2kEMGJJwKWMBfHmTj2UUkyUnu9aXtmRW+NyJNPyqGBKtiZm+Ej3s/QoA8pI3j9kdeLi96a6BaQo4dBqFg156jG2aFkKlvrKYkfjy+zoqGN6CVhO/phZUBCLSlwqLY3ggjZfX6XefSooLyBeDmf9FS/42/iX5nRRTiSn+x+3BzqCpwIWr+mk9FcyAeFd41h3wcnKRwa7A== 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:(366004)(39860400002)(346002)(396003)(376002)(136003)(86362001)(186003)(83380400001)(66946007)(44832011)(316002)(52116002)(1076003)(36756003)(8676002)(8936002)(107886003)(54906003)(66556008)(6916009)(478600001)(2616005)(5660300002)(4326008)(2906002)(66476007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: pfTQM7KLxUTzZwMMULsqBh+snBHQHgJgryj+Z/LgwjiCKmWq2jTnt5AcibeljKKU53hqPYdh3jb0fScto0Ip+LQO0jRmmVk+d2F/ziHcV+hTlZDb5Bw2E7Mdug3tUuePS1ARvAURfpzJf+IBzWygSwE9FDl75eQNkez4hzQcTP7rchyimZeyE2G8GqbdbozA9SYp3bZMmNnVMEvSfjMoMHrOoOtktlh1LVnSR7tOfef6ifNLWrfnuD1fvFBDXZRN/WmQ+sjI4Zwz9Gqa+UqWJS3rwxrfDwrN2uZEmrSAbujOyP+doXw3VMZNCScQXZuE4CGuHGKHJfG2umyGyfgrJwxEcXkHzxnVcrQvr4usMLAl35Xj8Fd8Qmdo1f5WVdXqOoCM5XaW96Emk0mSG9lahOY0ftJZHJFn33r9/6jjUmI9VlSfgWBNTdjQa5AqYR78aojB3qAESbIUQ/fBd6FHO9skkOobO4JySEh198q66UgV0vhNeqHCPfAH+yYLYnV1vQ8E3EWsu+sde1pJw+IP5ABS+lkX8f70iOjertf7jqjdwg+tUUdATvDfwtBX2TgXu7x8Gqk1jsNsG8+dcODFVuGOv/JxxGBrEox9fNVNBGfna4nKe0TJryJbof6myt2V9zEM186rFZrigJZFWiY6GfNVYrJ0o5JgnZ06Z95jNgF3c1M/NEH52K4OO9HW+gyhRc1bRZos3hdyjjlTOUDwAG4qsqx7io1sdgzPsSWXgRH40KFlLS/t1zf9o4LWBrRht76yztrE08GyiwNmS7LanxKC54n1n8aUtpPEuw+OYTAguaob8J/slJ2mKUWZiJGWt9w4eNZiYpWbQEfqB1+ZVHKD5il8To2QW1d07AMxRCO3wZaTvutjLSan4DlAOQ/S2eN6DXpXISyxPo3DEKG5T1eCzvKM3i3BPI0jcYjtDTyZpKHCWKAwRU04tUHAS+3ETPCFQcERPBKPoInqGRr+uNfVdSUYyYQfTRB2VmhHddL0yQC+HwW7jLaYmqULw2X3+tq3WdserPvueQUl5i/sqgCv4qCijr+i0pw3sQ3/kwVkyvUdfe6iM05KjWWg2a7TFCCbhU3QOpu3G/0B5sLpOkvjtIHlbOKm+yuc63TDaGaEHwoYKxHwBlYGpZkDM7Xi5bEYZoAE+AKukUvbmjiVRAu5r/khguoKdsyuLunnw5nZLTnRmB7D/q4BfyxYbQc/U7WWQxRSirgerJObpLS2BJ8yWYmTbya9XC4AL/nVGn1GqMHFJyXeb7LZF4St35XWB4ylZPcYbwlvRiWRZeGfzy6J3HJYHN66rSwV2lo1jWCy/rdwXtdKwulbZhfRcws8ulhXNfblVueny+Lph5coMg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 83b06348-a26c-46d3-aee3-08d8e309465f X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB3148.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2021 14:40:25.3118 (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: xsbZXzFJ+O52+pxBFfVf54gyEMg/qkkEHgee/BHih30NaTmbrChQQAjC5DdI4uoqZhtSFB0gdI2HzkHcwrFw4ROXhoB2GpW7Wwwa6xrhs2Y= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR10MB1771 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 adultscore=0 phishscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103090074 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-2103090075 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" Test that downgrading an rwlock does not result in a failure to schedule coroutines queued on the rwlock. The diagram associated with test_co_rwlock_downgrade() describes the intended behaviour, but what is observed currently corresponds to: | c1 | c2 | c3 | c4 | |--------+------------+------------+----------| | rdlock | | | | | yield | | | | | | wrlock | | | | | | | | | | | rdlock | | | | | | | | | | | wrlock | | | | | | | unlock | | | | | yield | | | | | | | | | | | downgrade | | | | | ... | | | | | unlock | | | | | | | | | | | | | In the test, this results in a failure... ERROR:../tests/test-coroutine.c:369:test_co_rwlock_downgrade: assertion failed: (c3_done) Bail out! ERROR:../tests/test-coroutine.c:369:test_co_rwlock_downgrade: assertion failed: (c3_done) ...as a result of the c3 coroutine failing to run to completion. Signed-off-by: David Edmondson --- tests/test-coroutine.c | 112 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/tests/test-coroutine.c b/tests/test-coroutine.c index e946d93a65..62b0092721 100644 --- a/tests/test-coroutine.c +++ b/tests/test-coroutine.c @@ -264,6 +264,117 @@ static void test_co_mutex_lockable(void) g_assert(QEMU_MAKE_LOCKABLE(null_pointer) == NULL); } +static bool c1_done; +static bool c2_done; +static bool c3_done; +static bool c4_done; + +static void coroutine_fn rwlock_c1(void *opaque) +{ + CoRwlock *l = opaque; + + qemu_co_rwlock_rdlock(l); + qemu_coroutine_yield(); + + qemu_co_rwlock_unlock(l); + qemu_coroutine_yield(); + + c1_done = true; +} + +static void coroutine_fn rwlock_c2(void *opaque) +{ + CoRwlock *l = opaque; + + qemu_co_rwlock_wrlock(l); + + qemu_co_rwlock_downgrade(l); + qemu_co_rwlock_unlock(l); + c2_done = true; +} + +static void coroutine_fn rwlock_c3(void *opaque) +{ + CoRwlock *l = opaque; + + qemu_co_rwlock_rdlock(l); + + qemu_co_rwlock_unlock(l); + c3_done = true; +} + +static void coroutine_fn rwlock_c4(void *opaque) +{ + CoRwlock *l = opaque; + + qemu_co_rwlock_wrlock(l); + + qemu_co_rwlock_unlock(l); + c4_done = true; +} + +/* + * Check that downgrading a reader-writer lock does not cause a hang. + * + * Four coroutines are used to produce a situation where there are + * both reader and writer hopefuls waiting to acquire an rwlock that + * is held by a reader. + * + * The correct sequence of operations we aim to provoke can be + * represented as: + * + * | c1 | c2 | c3 | c4 | + * |--------+------------+------------+------------| + * | rdlock | | | | + * | yield | | | | + * | | wrlock | | | + * | | | | | + * | | | rdlock | | + * | | | | | + * | | | | wrlock | + * | | | | | + * | unlock | | | | + * | yield | | | | + * | | | | | + * | | downgrade | | | + * | | ... | | | + * | | unlock | | | + * | | | | | + * | | | | unlock | + * | | | | | + * | | | unlock | | + * + * Significantly, when c2 unlocks the downgraded lock, it should be c4 + * that is run rather than c3. + */ +static void test_co_rwlock_downgrade(void) +{ + CoRwlock l; + Coroutine *c1, *c2, *c3, *c4; + + qemu_co_rwlock_init(&l); + + c1 = qemu_coroutine_create(rwlock_c1, &l); + c2 = qemu_coroutine_create(rwlock_c2, &l); + c3 = qemu_coroutine_create(rwlock_c3, &l); + c4 = qemu_coroutine_create(rwlock_c4, &l); + + qemu_coroutine_enter(c1); + qemu_coroutine_enter(c2); + qemu_coroutine_enter(c3); + qemu_coroutine_enter(c4); + + qemu_coroutine_enter(c1); + + g_assert(c2_done); + g_assert(c3_done); + g_assert(c4_done); + + qemu_coroutine_enter(c1); + + g_assert(c1_done); +} + /* * Check that creation, enter, and return work */ @@ -501,6 +612,7 @@ int main(int argc, char **argv) g_test_add_func("/basic/order", test_order); g_test_add_func("/locking/co-mutex", test_co_mutex); g_test_add_func("/locking/co-mutex/lockable", test_co_mutex_lockable); + g_test_add_func("/locking/co-rwlock/downgrade", test_co_rwlock_downgrade); if (g_test_perf()) { g_test_add_func("/perf/lifecycle", perf_lifecycle); g_test_add_func("/perf/nesting", perf_nesting); From patchwork Tue Mar 9 14:40:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Edmondson X-Patchwork-Id: 12125833 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 25134C433E0 for ; Tue, 9 Mar 2021 15:32:25 +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 9171565253 for ; Tue, 9 Mar 2021 15:32:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9171565253 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]:49204 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lJeLP-0004Mv-7i for qemu-devel@archiver.kernel.org; Tue, 09 Mar 2021 10:32:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46616) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJdXO-0002tr-Nq; Tue, 09 Mar 2021 09:40:42 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:47316) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJdXG-0003tN-RY; Tue, 09 Mar 2021 09:40:42 -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 129EdqYc002614; Tue, 9 Mar 2021 14:40:32 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=unA6L9KYmYDz8mrirVWlfPlUsvbHPvPP07jHUz5/GnkMqaSQ/TinBXVq9V03IWQ4ltqQ Agv+Lnbpl7BY0Q0RXVCXny4qPIGjdtcFP6L7N6lFAsGJw5C+ODeo/tisEv898HA8tYN6 aqMY36P7xHBVKdyDURHOfMwtYIrNnukYacBSQpZdzfK9cwe5ExbxU+koXcZdkUclQs90 Jxl7QnKoks0bhvnoxJzV0pppVwm/Y+EtWu9adSUYVzLRHChTHgsVGnpTa4AJimz5uN2d oHIpmgTvHtwasO7LB/2VdCiZWiO59YUepJushscpCC4VgAkK2BOcVxsQJOL8tcNv5NvF gg== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2130.oracle.com with ESMTP id 373y8bqmnf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 09 Mar 2021 14:40:32 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 129EVPrI193285; Tue, 9 Mar 2021 14:40:31 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2041.outbound.protection.outlook.com [104.47.66.41]) by userp3030.oracle.com with ESMTP id 374knwwk0y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 09 Mar 2021 14:40:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Zrqy2mJzm2+MdKVzyH9fEwE/UV4fMYS9NP34isWbVufm3ev/+Np8fO2SIDl+k3Ra+rYRZzebAuAWCWRTVSey87w0QZ4MMQHJ/P2TeL5moeHK/SLgZaUEDA0Q4frDZ0O2rRwBpfVfWBDrgmkU0N2+9MR2a+KBw/nugqJzHa3pDk52cLoQHwCA6RRKQYTRnMi73tbhoawLWSdukBiNX02vCJnpb4j7pbklr6frvfEQ3O+XXMUqslyqVaGhUBVbUevGUS9c16J9CwJ3NbM6Wmx6NGo/4koiX6t9/6TtssZbAEG95AnhPh44DF1owlC5M/msaaLIOc0v0htQyJuc7dVU3Q== 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=i1Mv0rINN4z2iji9H55Y2/E+Jn5RYPIzlzuOiU0jwYK0sJadgkVn3n63A5usJ300+wQJFJ0utoSRrECqH/0047U1d88sqcHbcAqhsqcpdt0+f2mb78IPGb3E3JhreKNfG3HoCwxheBq5ePClPDmqZ7TiSmGqDEvLvFANM302048tZ71rUoZy+buYf9cNoai789GvHn0GyJZ6JJ/AqcvMY51ZSwvoYLzdwIQX3PlnpV/hKOCYuTcbFHmuF913ILePbDQQhSRH30gnKu5Hj0sav78LOw/TvH6MDdGAZxSRSFPgsiO+mLI479pEdbhoVZQbpjVtCin68Bh7ZW/5X14wLA== 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=djnDnAn4Wtr86eX5HcRoXOZ3iVsidTj4wPGAJ9mbDxglUjKml590BPVN3HwTROoN/pHOFP6sdHBzHm5zxt8/QRFOFF0ToHIxuQcMHrJBmlseSF+OnMHIM/y8Qm9zSIoqInE3KJfffpoYbfAun7dKgVctae2ToV01a7fB9M0z1BU= 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 DM5PR10MB1771.namprd10.prod.outlook.com (2603:10b6:4:8::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.29; Tue, 9 Mar 2021 14:40:25 +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 14:40:25 +0000 From: David Edmondson To: qemu-devel@nongnu.org Subject: [PATCH v2 5/6] coroutine/rwlock: Wake writers in preference to readers Date: Tue, 9 Mar 2021 14:40:14 +0000 Message-Id: <20210309144015.557477-6-david.edmondson@oracle.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210309144015.557477-1-david.edmondson@oracle.com> References: <20210309144015.557477-1-david.edmondson@oracle.com> X-Originating-IP: [2001:8b0:bb71:7140:64::1] X-ClientProxiedBy: LO2P265CA0075.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:8::15) 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 LO2P265CA0075.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:8::15) 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 14:40:24 +0000 Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 310e39f4; Tue, 9 Mar 2021 14:40:15 +0000 (UTC) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 601b82e2-11d6-4b4f-1408-08d8e309468a X-MS-TrafficTypeDiagnostic: DM5PR10MB1771: 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: bCCbkhJoXQoATrhEzVP6erwJS8gTPGL3UtKCo8V1O5vJctouFJ2ty52Rm93EurvGtCJo6nd0PIPKLqCDM2TtNABU+X1zVxXjw25rov4cwGwHfwt+LoSTWbk/M22OreXmX0uTNFIM3WtT8VfB8swus/pkyGaLUh7UQQ9CQzxTxYYyBgjaKhF8nFn/Xs9Wcu4bqDL/JTcG6HIkmC672YaaG3IDhAv3ANIXVg5KKHnevX8tRQbO0fqSycyI0OwblEnyHEA38i50FVlwfYQgtcMhsyO4a+BD45s/IV/dMl8osGOXA4v/2wN+FsI8pdzzBsY4wJuw2x6rh+oAfDASr0NlLUNsstEQLaDpZ5jY0+zChCzF+bhDSCBGjEbGVXc5jBJ49lkcMtTtdaMwEWeVChncaS/hSaYSGmhah19c2mqaL1BIN45MBCkYKXZuEsKWyydsZ5ioyxg2iX2O6k/OMuVcvw3l7C2Uux5OMdt0J2sDFfOAP1kyG/BrGk9MQgSwcUra1Eip9Pf0X5jZzN2jh/jKGw== 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:(366004)(39860400002)(346002)(396003)(376002)(136003)(86362001)(186003)(83380400001)(66946007)(44832011)(316002)(52116002)(1076003)(36756003)(8676002)(8936002)(107886003)(54906003)(66556008)(6916009)(478600001)(2616005)(5660300002)(4326008)(2906002)(66476007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 4OzbFY3B0biJig7AHH2gX/R4aGd3s23QqEQblPDX9vPU85+WPsd61GXxCK1beAeACt5vcvdniOCtNR2eCC4WZphvEWfiW4ku1EG/KbPCtGgivkHQMbU1Ob7UlpmpGJ0MOOENwHkiSPRJDZEj8xTPLxpj6pzYDNbL20Y8m+6J/+XBMySzyow8HFfvwAwU0/nA7/vG/3CbBDJg41sbBfxj+I8Cydy4uKr1HJr2EfOi84uBI12c5Y+0JsNYFiktuax9HZsoYl2uCuJgZGno14pnpMP3CAsVC+WZbOdpttSK5/PmcqAO4BONAFM08fPyllUSksXuWo7DwEjrTYCZXt4fiuY4z+CeuULVB5XIPRf1KOFnSOUrakswYOEVhAYH6LyxQpL2g8cnci59N10BEwkUKmRsY8ovenuqBiZPlPdnAoI+y1LUOBGT/+qUeaJ0+ydFJg9VxXPmvOstAh+/oY/BmaoMqdIqi76m6+RbsP5Lb884ekKwo4Pd0grDwpjj2tJlHM3NZNjMv3FeSHRKmgBhxeq1Q3mpluSYXcsCibwcGpL5ZAYxpRS97Q79Pg62HtV6w4BJbxd6z44T/2D70mWmXtIP/UjC+X9WPXW95RrKGJTGHZeojunUpD3wOovKZdxd+lllw9e6RUER9xwGjrdxfzGN9Lk/lsjMJT0P8JofJy8EB+JhVcGJR3vU2Y9afwOyPApKaUWRd+PPIhHJllO0uoCQZ1soR3QfpZJbse0MQtJ24gSABkUjSlnE2XaYzebH2Prgea6QW3U3OlFjEHSFqwfLD0jqDJJEiS2XMHFlapaP4YDjQaJewOeETtLOS9CSQaTqqqSFvdzw0XqaHOrOvIfmxIdr3UHlbBP/MEOB5FXBAUzJX6H+JS0kyIkCgUNJwJIuFg/F5dVw8ZcFUtGvwjp6iKFC7BcdZS2PFElzPm9pyMp4vBMzphmQDhVmKmqGY8pTs7KE0FcusQ4AONmZXdF9jC7n+HlK6J/JNTeQPwlCi1Y5MLIs53mThHSG92V/RgLWN4uPz2DYP2eyxnWwLwwmUK+t52dz4Ols2Ep76ZPtQbb2WIRHzCdVwI66c7svdLfUB2g/NGUfQKjWW8akpd2/VpRLJfsBSyvjVs8qJrYnYlOcPzIz5Mol2HmkcYZsOJNSqCAiND8SmXL6boUO2/Fsgs6GZRHTvdFZJVYdSJ41rIfAKueqHrEt5SkCTV1kBgPIJY1KAPgmIMjeJpkkJ24FxxvGBurgJOZphYU9o5ZjSxxCv9Tql1aoTsVOYdoew8SnpGyu1U4MMQohn4k11eg/7/O9U44LQtfxwgtWFysyO4PPmX+qHQJNyQ2pjH4QSKevowFqS8RsccScXucw4Q== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 601b82e2-11d6-4b4f-1408-08d8e309468a X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB3148.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2021 14:40:25.4338 (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: N8c1XQSy4DqGOzK4knRCcctB9XLjtdBB5AbzbnM/uSQaGsmmexV6tuVQGQVSJByGYRc1jyx5KpbGs3B1zRfb3jn3K0APsYC83k4mO3Lao0I= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR10MB1771 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 adultscore=0 phishscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103090074 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-2103090075 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--; From patchwork Tue Mar 9 14:40:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Edmondson X-Patchwork-Id: 12125777 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 D72CAC433DB for ; Tue, 9 Mar 2021 15:18:13 +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 433EC65272 for ; Tue, 9 Mar 2021 15:18:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 433EC65272 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]:34806 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lJe7g-00037R-6y for qemu-devel@archiver.kernel.org; Tue, 09 Mar 2021 10:18:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46602) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJdXN-0002s0-QP; Tue, 09 Mar 2021 09:40:41 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:47322) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJdXG-0003tx-TV; Tue, 09 Mar 2021 09:40:41 -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 129EdwBl002657; Tue, 9 Mar 2021 14:40:32 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=WvKAGLn/qJdpTe2hqGSeJIeYv20Z9uAexuyoo8qy01c=; b=PLiJh/54MVLa/tJUt4sO4H5dGCFDcWC+4bt/SoR6AnUYabSFRLYtnyyYDWHtjPuD5C0B wXz6J3M2+7V/Rg0o5ZyjyOQRXT2m+TMuGAZkWzUyZ4X+sod+I+Svms12Yp3OzZ2RWHq4 bW3CE6TH1t+PBX2azTQSHxseNmuNhrfYcRzKptQ6pywXcoXN1rd9xWN8R37Z0lzsa2HU V9f/1+N5Xcg4bkLGeUieki6nIc54d53GwaN4fVNr8CpR0GFYcqngj/TwDzdcuR2duXDS xrj6/32H4ApUFP4v1jxFlWskHplsLVKEahveFIOGkxu0QCY9rsuqzHGJLrtQ1n4mA+cJ wA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2130.oracle.com with ESMTP id 373y8bqmnh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 09 Mar 2021 14:40:32 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 129EVPrJ193285; Tue, 9 Mar 2021 14:40:31 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2041.outbound.protection.outlook.com [104.47.66.41]) by userp3030.oracle.com with ESMTP id 374knwwk0y-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 09 Mar 2021 14:40:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gPyr73gQcAmf5liA4GEoxaEh85Pwt0nPYxkp0EQCed1zHRmlD93ejwaFpif/X0sEtxaoI4j8EYzCO1xbXRDw9CtwaDdjLF1qcUOm7tVsZ3qL/xe4FUfVtcm1MTdSa8xqHTRAz+u29SlDgu7wb6MmjPWkjccU7Q3njU0IymhXgNefyoHNx1wPiZTsuboKCRY0yHsk8Aoo2YFp/Kf2363z+cobV4l3mkqMFPXw+f4Xxpkt1UB/I2F0N3lbdn6Gw43QQaijcasqUZyiVK7ht0PwRNKHqZho3obGc2VWiUaiIxYrdslgLi8F9+/1MJk23tEnIfFjngikEw3zajM/HnhP6A== 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=WvKAGLn/qJdpTe2hqGSeJIeYv20Z9uAexuyoo8qy01c=; b=SyoFog5IDvpf2VkhbbK85u1sNtud/ZfGh5+UvNdgmSjGTT8ust131lYzYcAGXgpBYE7Q4asLmRkaa3cVT9ZlK8JEows28jqgV0M3NCRQsxC/8Gj0l0Y3ee3i4yaEQqPDDuysvMPPwY9zWNqrLbYp/q6N4Pece25VchIZ5zar63QLzWHjpPw8EJiWG5a7d/k92/an0QEdIbDE1ini4rDTR4wRaE7fg/0CktUTiEMLkafRWymdORm3gza8ZoX/mqcHVCj4pLFZNjuPXMNjmqIBYuXt3AC8QiStBEwIIF38qRXlwFxvsOMBIE+jwxCahZCWrePOCK9qcxXMLDJ+q18D+Q== 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=WvKAGLn/qJdpTe2hqGSeJIeYv20Z9uAexuyoo8qy01c=; b=gK2YGlnGAqLY4l6QyfLsdyxT0y/lSdFKnqbxytB2MkYzYmOrhcbIoIiYc9XxaLMLVbwiCbWGIdq2bhzwhP0IYX6ZRJ/qq2to6IY3Nwq7niz5tfIm5fzlmCYktebol6XYMIFcIwA+Ab/3WSc876leFII2JftHs9f53mAkV9G8I4Q= 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 DM5PR10MB1771.namprd10.prod.outlook.com (2603:10b6:4:8::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.29; Tue, 9 Mar 2021 14:40:26 +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 14:40:26 +0000 From: David Edmondson To: qemu-devel@nongnu.org Subject: [PATCH v2 6/6] coroutine/rwlock: Avoid thundering herd when unlocking Date: Tue, 9 Mar 2021 14:40:15 +0000 Message-Id: <20210309144015.557477-7-david.edmondson@oracle.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210309144015.557477-1-david.edmondson@oracle.com> References: <20210309144015.557477-1-david.edmondson@oracle.com> X-Originating-IP: [2001:8b0:bb71:7140:64::1] X-ClientProxiedBy: LO2P265CA0214.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9e::34) 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 LO2P265CA0214.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9e::34) 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 14:40:25 +0000 Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 04a79c41; Tue, 9 Mar 2021 14:40:16 +0000 (UTC) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 24aced05-801f-4f06-354d-08d8e3094755 X-MS-TrafficTypeDiagnostic: DM5PR10MB1771: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LV5B2BrHASLf+TUkqqZPO2uwfHsCOPYsyR8bmboCwKP7s1baDLdFos3XY+gDKHnhnJkpxOs1MASnbMbG7AMBZsvceaWmmUu7CaRfYKfseVxgm6MffEphbi7UaCDbQWLgStBS3HzOvRG3bZ+BFny6drN5ht9OxYslRSCjxqTBIihhzIC1jr+QpkckVUGbiIAAXb4pdE7exJ+002grZHd/tTLEfBJohbfGw43rN8N5P8oOhHvuK81oBjFNo+jcPeMeV4uktbaTslVVRgLCNFBqmld83gZ8fkLxC3UAVeColQXm8GL5WiWEvhv0F/wiHixRWlhtvb85DNNTveI3mul2wOjFhsHBUzltZBo00yOqLZR5/uEI3qF7fPi/RBjGmqymoSFP/PZi5C6yKfYG8uyr16ojpmcSQfc4hKmKe5RsvMVgqTBSZ7asBSAm4YB0jN2aVjWNw2I9VIBfDOO+8lkJt4l97zqjWsBNra2nNGWo1//t8nvnhdtBpu7zeUM+2+2xpHFfcq36cgdKWLDhaZQw/w== 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:(366004)(39860400002)(346002)(396003)(376002)(136003)(86362001)(186003)(83380400001)(66946007)(44832011)(316002)(52116002)(1076003)(36756003)(8676002)(8936002)(54906003)(66556008)(6916009)(478600001)(2616005)(5660300002)(4326008)(2906002)(66476007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: lyUW2eipo2qaMCncevLxghZYp6DN9eUGmOBXZy/2ULwQLrVEn6cTIw2XmVvcIQ5EJYO06QCJj9qj5v8YlGc/Xfxrs0Bxchy2hzN6yBg+eS+zIrG8lbVCRSSfNzM9fXb8LwmlKxwApJo9TPwvnkZKW4IJJtx0WiWAbFwfq6xWFUzqSZXA9+h4i9KUlTtxuckBaUb3kdf869bLCUoh4PJiVoRBfokMywJ372HwfQD/PDBdpNofJTn+8sPSI8HM3nSuz3+t1764lkcCQ9QTtR/RPclcsLEixOXz4QMVTM1qGF1wT4M5xycACKBHBWwRqDQLgPlNwI5OJEuKYP06/kmkpUM9HbymuAihlnZd4ufmBZUPRlRN9awxLo2q9jmzCQZ49n/akRzr8FEEeg0IHPMXBQsqHhhxHGdOGzlVeAaMzbOcfT4XF14DkM6tTY9JmuNH6U0uSctBuREA+NlcuMM08QT1w/YiPGiAUvYKVuUBOvFqxSeOi1s2HmDS0no/czKsSrX4HI0iK7bGzwgwbNsYRw7ZqCZFC0+P9u0c1ENzHCyfrs9xCFG13kkXYN9fbZWjElxlYuDukG9wmO/yrlMdETtXUeF4j5gfi4MOVSiRWPOSrwJ6y0XHcqlQIZblNgj7XmPaCTvbCr3CBbPi0meGrHYwLwKmQq4/Rk/zcfT4SyNo5P4mygvJkQyEr0HO6mlvaOfZaJ0OixV2qMwv4ferZfLt0w9SccrDFBKy4EvihM6VE8144IP9vg/ZUr22zYFNo8XJc9uT0oXkD0G+yfEYs+Twsab9gUKTTttjp8zNsV6EVIEk27zDaeb9K1WX5Wr+De082avUaoUVXKpWhyT5ywrEuAEbolP3T6W7mEs5Qt8TpVmijmLWGn6lQypKahX9tfviJtsPdJ7+33xR/Ts0eXo65j2+BsP7xK9C8PZQ5Cyd2OO/e4N8BjvRHFwut2L4K6xBVK+IJFsOyp18FOFGQdEyiHC+66VKF4q/hvXIvG3CmFVCOzRrhweCGj0zh/KEGhGcy5giFmzHOn51DQ80byeRtdP1H7kdLU18NPxCupAXALhPM9ybSLiaoIVDC7H29B4FcJO4FZakJqoCHFroprnF7Hg0VlT4KRoT/kHF6Xr57I4ECAE0itBCRfdIQX038luGVYlRsPa26GH6LG7Qw++PecP9APkEcTIkQv5igaL1ZqnrQNQXltWEb/Wgy2Y6hDCFxF8pijXiEisBd0MI1WggSrf2SiNBw3xOFzzRI8/TL5F2GYgNg2Id/HeveZUDiF6FtX0tlf3BKWpZ/wSin9MTSwq047dvSR1JfhjJOsFsTFa9O9o/Km6w/uCQyOn8+Uex0WbIVU57ZscjRkubOg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 24aced05-801f-4f06-354d-08d8e3094755 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB3148.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2021 14:40:26.6251 (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: IDBcO+EyLR4VL7Apr6YN83dkbFdJCmjoLAklLK0PpA59z+gvvOy+J5sVAcSi4XogUXKuGbdW3lhHnq4fvZ7GkAAz32f3qPXm7Ydi0Wwpco8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR10MB1771 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 adultscore=0 phishscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103090074 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9917 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 clxscore=1011 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-2103090075 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 , Paolo Bonzini Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Given that we know whether the queued coroutines are reader hopefuls or writer hopefuls, avoid marking all of the queued coroutines as runnable when unlocking, choosing instead to wake a single queued writer or all queued readers. Suggested-by: Paolo Bonzini Signed-off-by: David Edmondson --- util/qemu-coroutine-lock.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c index c05c143142..6e399f28c1 100644 --- a/util/qemu-coroutine-lock.c +++ b/util/qemu-coroutine-lock.c @@ -356,24 +356,20 @@ void qemu_co_rwlock_unlock(CoRwlock *lock) Coroutine *self = qemu_coroutine_self(); assert(qemu_in_coroutine()); - if (!lock->reader) { - /* 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 { + if (lock->reader) { self->locks_held--; + /* Read-side critical sections do not hold lock->mutex. */ qemu_co_mutex_lock(&lock->mutex); lock->reader--; assert(lock->reader >= 0); - /* 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); - } + } + + /* 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); }