From patchwork Mon Jul 22 04:07:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Xingtao Yao (Fujitsu)" X-Patchwork-Id: 13738244 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id C0BD7C3DA59 for ; Mon, 22 Jul 2024 04:09:28 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sVkMJ-0002PM-Q9; Mon, 22 Jul 2024 00:09:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVkMA-0002MR-BE for qemu-devel@nongnu.org; Mon, 22 Jul 2024 00:09:03 -0400 Received: from esa2.hc1455-7.c3s2.iphmx.com ([207.54.90.48]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVkM8-0001rj-6O for qemu-devel@nongnu.org; Mon, 22 Jul 2024 00:09:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1721621340; x=1753157340; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UDslaKUR+DRFaE92mJx4H+c111qYhgBVTy9nFE54RmQ=; b=pynGatR1SmGG5p8yozX3uDbo63Q/L7B4oKTJ6AOeIRNJ536QySR3UaTn OVE85evbqY2BVIutMRDGZ/v09HqZgstfESEjpCgtsqyMZ/ZYR3j0l4ebk zGIGjaad/gUeH2GBFf1C7Ah/KibiFnzJOAxOVdL4dYqpg0GCG1WGyXtv6 /CvRlXS3um6H7l9Fb3lkSZEtFD+I0CvsviKExtL1q+pXMo5nzzD85UxUi TWWkfcaetB6Uwutxs2tgFV/z2UBndPg+wobK0W4B7OGggt5CaAhAMcZaQ NXj/iaciG3R1QCdVebU/dd795eE8jHTVor5a7BR5kMPbHHjQMeIlpWLwG g==; X-IronPort-AV: E=McAfee;i="6700,10204,11140"; a="168119006" X-IronPort-AV: E=Sophos;i="6.09,227,1716217200"; d="scan'208";a="168119006" Received: from unknown (HELO oym-r1.gw.nic.fujitsu.com) ([210.162.30.89]) by esa2.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jul 2024 13:08:57 +0900 Received: from oym-m1.gw.nic.fujitsu.com (oym-nat-oym-m1.gw.nic.fujitsu.com [192.168.87.58]) by oym-r1.gw.nic.fujitsu.com (Postfix) with ESMTP id DC4A2C1490 for ; Mon, 22 Jul 2024 13:08:54 +0900 (JST) Received: from kws-ab4.gw.nic.fujitsu.com (kws-ab4.gw.nic.fujitsu.com [192.51.206.22]) by oym-m1.gw.nic.fujitsu.com (Postfix) with ESMTP id 2CC2AD8B83 for ; Mon, 22 Jul 2024 13:08:54 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by kws-ab4.gw.nic.fujitsu.com (Postfix) with ESMTP id A7EA46BEE3 for ; Mon, 22 Jul 2024 13:08:53 +0900 (JST) Received: from localhost.localdomain (unknown [10.167.225.88]) by edo.cn.fujitsu.com (Postfix) with ESMTP id 2116C1A000A; Mon, 22 Jul 2024 12:08:53 +0800 (CST) To: qemu-devel@nongnu.org, Eric Auger , "Michael S. Tsirkin" , =?utf-8?q?C=C3=A9dric_Le_Goater?= Cc: Yao Xingtao Subject: [PATCH 01/13] range: Make ranges_overlap() return bool Date: Mon, 22 Jul 2024 00:07:30 -0400 Message-ID: <20240722040742.11513-2-yaoxt.fnst@fujitsu.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240722040742.11513-1-yaoxt.fnst@fujitsu.com> References: <20240722040742.11513-1-yaoxt.fnst@fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-28544.004 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-28544.004 X-TMASE-Result: 10--3.417800-10.000000 X-TMASE-MatchedRID: LS8Ewxiu6UeFWCPo3rDAcEhwlOfYeSqxwTlc9CcHMZerwqxtE531VCzy bVqWyY2NJJArHl5VS02AUraeY8ICeR8TzIzimOwP0C1sQRfQzEHEQdG7H66TyHEqm8QYBtMO9FJ AdpFUlrB2LtNrXJElM1Ksmmiq2t19j9BGIA5QpFP71ApFFkEr+ZdcdiYEU7jbm9sclzcg8O/reN M0X2JgtZcrrAYC2hl1W4wbpXTb5DJKKve1kh3RY37qSWrndbmQn0bOriG5BVc= X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 Received-SPF: pass client-ip=207.54.90.48; envelope-from=yaoxt.fnst@fujitsu.com; helo=esa2.hc1455-7.c3s2.iphmx.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Yao Xingtao X-Patchwork-Original-From: Yao Xingtao via From: "Xingtao Yao (Fujitsu)" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Just like range_overlaps_range(), use the returned bool value to check whether 2 given ranges overlap. Signed-off-by: Yao Xingtao Reviewed-by: Philippe Mathieu-Daudé --- include/qemu/range.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/qemu/range.h b/include/qemu/range.h index 4ce694a39831..d446ad885d2d 100644 --- a/include/qemu/range.h +++ b/include/qemu/range.h @@ -210,8 +210,8 @@ static inline int range_covers_byte(uint64_t offset, uint64_t len, /* Check whether 2 given ranges overlap. * Undefined if ranges that wrap around 0. */ -static inline int ranges_overlap(uint64_t first1, uint64_t len1, - uint64_t first2, uint64_t len2) +static inline bool ranges_overlap(uint64_t first1, uint64_t len1, + uint64_t first2, uint64_t len2) { uint64_t last1 = range_get_last(first1, len1); uint64_t last2 = range_get_last(first2, len2); From patchwork Mon Jul 22 04:07:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Xingtao Yao (Fujitsu)" X-Patchwork-Id: 13738246 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 59A26C3DA5D for ; Mon, 22 Jul 2024 04:09:45 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sVkMb-000371-V1; Mon, 22 Jul 2024 00:09:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVkML-0002X6-Jw; Mon, 22 Jul 2024 00:09:14 -0400 Received: from esa6.hc1455-7.c3s2.iphmx.com ([68.232.139.139]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVkMK-0001tO-0R; Mon, 22 Jul 2024 00:09:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1721621352; x=1753157352; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ThRdQS8GfgTXHrFzjsZjoCSjLl0BRfNH9DOAJNL1M4g=; b=ipnpYfD+Cvq0ZnWGxy8uNNWFuf/DsBcSxHbuveNK2X7APWiDNhbFOXzg uyr3VobUmANzwC/smE7wXhrGe/BwsgFlqhnuiHvrZ/fxBbh3ICLYGpqN6 sxyqaN0pUCExhVPpG/QkL9lrLyztYUS5lJg04cZycByFz6TnOEdE7ZPiA +GLsKZPveg1Bt7VfTlH9JIdcVrR/pB5ERNXUjd7fq0VYqbnG9tph3IzUl c7PGBk+ckCHodZDyTf6jTl9KMY3ZGtXl3B6eC+wKhNg7A3mS/kuLSlcCG DBhMZmZ46Ek1AOyV7PS3qO5b0hMmVjIwe4xFvChP2K7RkpYxrrQpXbEBi w==; X-IronPort-AV: E=McAfee;i="6700,10204,11140"; a="169998063" X-IronPort-AV: E=Sophos;i="6.09,227,1716217200"; d="scan'208";a="169998063" Received: from unknown (HELO oym-r1.gw.nic.fujitsu.com) ([210.162.30.89]) by esa6.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jul 2024 13:09:09 +0900 Received: from oym-m3.gw.nic.fujitsu.com (oym-nat-oym-m3.gw.nic.fujitsu.com [192.168.87.60]) by oym-r1.gw.nic.fujitsu.com (Postfix) with ESMTP id 81FC6C13CD; Mon, 22 Jul 2024 13:09:06 +0900 (JST) Received: from kws-ab4.gw.nic.fujitsu.com (kws-ab4.gw.nic.fujitsu.com [192.51.206.22]) by oym-m3.gw.nic.fujitsu.com (Postfix) with ESMTP id 49B1ED7494; Mon, 22 Jul 2024 13:09:03 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by kws-ab4.gw.nic.fujitsu.com (Postfix) with ESMTP id D9A966BEE3; Mon, 22 Jul 2024 13:09:02 +0900 (JST) Received: from localhost.localdomain (unknown [10.167.225.88]) by edo.cn.fujitsu.com (Postfix) with ESMTP id 5AFDF1A000A; Mon, 22 Jul 2024 12:09:02 +0800 (CST) To: qemu-devel@nongnu.org, Peter Maydell Cc: Yao Xingtao , qemu-arm@nongnu.org Subject: [PATCH 02/13] arm/boot: make range overlap check more readable Date: Mon, 22 Jul 2024 00:07:31 -0400 Message-ID: <20240722040742.11513-3-yaoxt.fnst@fujitsu.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240722040742.11513-1-yaoxt.fnst@fujitsu.com> References: <20240722040742.11513-1-yaoxt.fnst@fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-28544.004 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-28544.004 X-TMASE-Result: 10-2.602800-10.000000 X-TMASE-MatchedRID: 79qQreYAxVdrFdvBEmTnvKekGZXOwUBuwTlc9CcHMZerwqxtE531VNnf JrUSEbFDcfrBpTCbnFHQ1eGkfrkoDhNSYeRE3U64ueYB1mSXzr/QxDD776KHL3O+fW3rC5pr4nP T8jZv1NHi8zVgXoAltuJ5hXsnxp7jC24oEZ6SpSmcfuxsiY4QFEefxKz+lqKeRBH8Txz8pnTjZH 4udmlbmJ1nGLbWF2Mf/I2DASliqu9RQEieGkuV+JuQqgIFLrgWXoVg+nWV3m2MQipNdyIFc5sNE GpLafrrLM/nEDLP056e+TDiyH/49wxfkLAfkNNSaAZk0sEcY14= X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 Received-SPF: pass client-ip=68.232.139.139; envelope-from=yaoxt.fnst@fujitsu.com; helo=esa6.hc1455-7.c3s2.iphmx.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, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Yao Xingtao X-Patchwork-Original-From: Yao Xingtao via From: "Xingtao Yao (Fujitsu)" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org use ranges_overlap() instead of open-coding the overlap check to improve the readability of the code. Signed-off-by: Yao Xingtao Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé --- hw/arm/boot.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/arm/boot.c b/hw/arm/boot.c index d480a7da02cf..a004a90e87be 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -26,6 +26,7 @@ #include "qemu/config-file.h" #include "qemu/option.h" #include "qemu/units.h" +#include "qemu/range.h" /* Kernel boot protocol is specified in the kernel docs * Documentation/arm/Booting and Documentation/arm64/booting.txt @@ -238,8 +239,8 @@ void arm_write_secure_board_setup_dummy_smc(ARMCPU *cpu, assert((mvbar_addr & 0x1f) == 0 && (mvbar_addr >> 4) < 0x100); /* check that these blobs don't overlap */ - assert((mvbar_addr + sizeof(mvbar_blob) <= info->board_setup_addr) - || (info->board_setup_addr + sizeof(board_setup_blob) <= mvbar_addr)); + assert(!ranges_overlap(mvbar_addr, sizeof(mvbar_blob), + info->board_setup_addr, sizeof(board_setup_blob))); for (n = 0; n < ARRAY_SIZE(mvbar_blob); n++) { mvbar_blob[n] = tswap32(mvbar_blob[n]); From patchwork Mon Jul 22 04:07:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xingtao Yao (Fujitsu)" X-Patchwork-Id: 13738245 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 920A9C3DA5D for ; Mon, 22 Jul 2024 04:09:33 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sVkMT-0002q6-Rx; Mon, 22 Jul 2024 00:09:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVkMO-0002bW-Ne for qemu-devel@nongnu.org; Mon, 22 Jul 2024 00:09:17 -0400 Received: from esa6.hc1455-7.c3s2.iphmx.com ([68.232.139.139]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVkMM-0001tO-KY for qemu-devel@nongnu.org; Mon, 22 Jul 2024 00:09:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1721621355; x=1753157355; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YCrC8JJcGzGageWxlfj5NoWgHUEu+F7i677Gb/aAwpI=; b=i6E7JRWflIYA7f7Ngu3j0kgsWDpiukkrutYHXXC2sqg/htyHt8xzTU+1 D81WW/0naEl4CV4QTRNdWmXF5JLA80yF8Hqb54cAKRc9a84aVBP2iDyi+ MvRXVLSM/E/fikEQf6ZwU9X6EsX93igh4YzCasqUOPB7FDr8WLwdJ7Waq 9Iq61Caq/9R1KEZW+BIibgKMioVG7a3l19qqpKCT/d4DxcuZs4kMpSn+A W89DS+J3pjzrD4rcGxCvyjmNtz53JHZfp2xuYDuRWlLvzVWBL1vmM0jRP csWe7JXzyvIPSowEaeC52QgOorMGEWQ3pzi0/QVm4/PFXxlj9MQdUQ3zv g==; X-IronPort-AV: E=McAfee;i="6700,10204,11140"; a="169998077" X-IronPort-AV: E=Sophos;i="6.09,227,1716217200"; d="scan'208";a="169998077" Received: from unknown (HELO yto-r2.gw.nic.fujitsu.com) ([218.44.52.218]) by esa6.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jul 2024 13:09:14 +0900 Received: from yto-m2.gw.nic.fujitsu.com (yto-nat-yto-m2.gw.nic.fujitsu.com [192.168.83.65]) by yto-r2.gw.nic.fujitsu.com (Postfix) with ESMTP id 06D69C68E2 for ; Mon, 22 Jul 2024 13:09:11 +0900 (JST) Received: from kws-ab3.gw.nic.fujitsu.com (kws-ab3.gw.nic.fujitsu.com [192.51.206.21]) by yto-m2.gw.nic.fujitsu.com (Postfix) with ESMTP id 45F9ED5085 for ; Mon, 22 Jul 2024 13:09:10 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by kws-ab3.gw.nic.fujitsu.com (Postfix) with ESMTP id C5D2820076D0D for ; Mon, 22 Jul 2024 13:09:09 +0900 (JST) Received: from localhost.localdomain (unknown [10.167.225.88]) by edo.cn.fujitsu.com (Postfix) with ESMTP id 529F81A000A; Mon, 22 Jul 2024 12:09:09 +0800 (CST) To: qemu-devel@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Richard Henderson , Peter Maydell Cc: Yao Xingtao Subject: [PATCH 03/13] core/loader: make range overlap check more readable Date: Mon, 22 Jul 2024 00:07:32 -0400 Message-ID: <20240722040742.11513-4-yaoxt.fnst@fujitsu.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240722040742.11513-1-yaoxt.fnst@fujitsu.com> References: <20240722040742.11513-1-yaoxt.fnst@fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-28544.005 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-28544.005 X-TMASE-Result: 10-3.619200-10.000000 X-TMASE-MatchedRID: aX2W24vmfqtrFdvBEmTnvE7nLUqYrlslFIuBIWrdOeOcbyawsiRjd6PF jJEFr+olAmPpbGBYlhvkwjHXXC/4I8ZW5ai5WKlygW5PvEaGA6Yn0KAVDcV68t64DZDbEIQS8dq RFpgLKwiJztRg9U5K6c4klx51aoIoe4ziUfDZ/rr1KF0d0T7BDIk8hr35r8xREWW0bEJOTAVAdU D6vW8Z1mZAMQMIyK6zB8/x9JIi8hKhgLRzA45JPQ== X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 Received-SPF: pass client-ip=68.232.139.139; envelope-from=yaoxt.fnst@fujitsu.com; helo=esa6.hc1455-7.c3s2.iphmx.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, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Yao Xingtao X-Patchwork-Original-From: Yao Xingtao via From: "Xingtao Yao (Fujitsu)" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org use ranges_overlap() instead of open-coding the overlap check to improve the readability of the code. Signed-off-by: Yao Xingtao --- hw/core/loader.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/core/loader.c b/hw/core/loader.c index 31593a117171..dac0df561b16 100644 --- a/hw/core/loader.c +++ b/hw/core/loader.c @@ -63,6 +63,7 @@ #include "qemu/cutils.h" #include "sysemu/runstate.h" #include "tcg/debuginfo.h" +#include "qemu/range.h" #include @@ -1278,7 +1279,8 @@ static bool roms_overlap(Rom *last_rom, Rom *this_rom) return false; } return last_rom->as == this_rom->as && - last_rom->addr + last_rom->romsize > this_rom->addr; + ranges_overlap(last_rom->addr, last_rom->romsize, + this_rom->addr, this_rom->romsize); } static const char *rom_as_name(Rom *rom) From patchwork Mon Jul 22 04:07:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Xingtao Yao (Fujitsu)" X-Patchwork-Id: 13738247 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 6C8B5C3DA59 for ; Mon, 22 Jul 2024 04:10:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sVkMl-0003od-U8; Mon, 22 Jul 2024 00:09:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVkMZ-0003FA-7Z for qemu-devel@nongnu.org; Mon, 22 Jul 2024 00:09:29 -0400 Received: from esa9.hc1455-7.c3s2.iphmx.com ([139.138.36.223]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVkMX-0001uQ-D5 for qemu-devel@nongnu.org; Mon, 22 Jul 2024 00:09:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1721621365; x=1753157365; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1S+uLU4M1bz23lQZv9KvoQgTqNV7fhGmAEQi5Fa/Q9s=; b=kJktTUFkFxWLBNahKUhrIrf58ORJXuy5iZt1LFYOGWSkQgiQi2mQfSqc hU/fTSaxfSv4EtvcAN5SnNX7NFfiNCWrLlROutSEfLOHv2FO4B8d68F/G FRHnOTmoDuB6Pf+ysP59zLtI/qxTMjS0AkWYW7ka00y9G07jYz48iq9I/ 1RHkyV1n/+W+cSmaodvuLk33HqTlrRm7i05SfkAnyNVzt30n/q9l2gtax Oy8jXSYguT9xgoQwWziDpw/DK2j1DTCFdhkmTXnp13sAWj2NG53g7n++T xlBOvGJfc7dHkxSVy/4Omevr9tsRP2q9qUD9ltDJpBVrfuvaiTyN2q7iD g==; X-IronPort-AV: E=McAfee;i="6700,10204,11140"; a="156365923" X-IronPort-AV: E=Sophos;i="6.09,227,1716217200"; d="scan'208";a="156365923" Received: from unknown (HELO oym-r1.gw.nic.fujitsu.com) ([210.162.30.89]) by esa9.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jul 2024 13:09:22 +0900 Received: from oym-m4.gw.nic.fujitsu.com (oym-nat-oym-m4.gw.nic.fujitsu.com [192.168.87.61]) by oym-r1.gw.nic.fujitsu.com (Postfix) with ESMTP id E70C1E7521 for ; Mon, 22 Jul 2024 13:09:20 +0900 (JST) Received: from kws-ab4.gw.nic.fujitsu.com (kws-ab4.gw.nic.fujitsu.com [192.51.206.22]) by oym-m4.gw.nic.fujitsu.com (Postfix) with ESMTP id 39A77D4BF7 for ; Mon, 22 Jul 2024 13:09:20 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by kws-ab4.gw.nic.fujitsu.com (Postfix) with ESMTP id D07956BEE3 for ; Mon, 22 Jul 2024 13:09:19 +0900 (JST) Received: from localhost.localdomain (unknown [10.167.225.88]) by edo.cn.fujitsu.com (Postfix) with ESMTP id 43A661A000A; Mon, 22 Jul 2024 12:09:19 +0800 (CST) To: qemu-devel@nongnu.org, Jonathan Cameron , Fan Ni Cc: Yao Xingtao Subject: [PATCH 04/13] cxl/mailbox: make range overlap check more readable Date: Mon, 22 Jul 2024 00:07:33 -0400 Message-ID: <20240722040742.11513-5-yaoxt.fnst@fujitsu.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240722040742.11513-1-yaoxt.fnst@fujitsu.com> References: <20240722040742.11513-1-yaoxt.fnst@fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-28544.004 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-28544.004 X-TMASE-Result: 10-8.191900-10.000000 X-TMASE-MatchedRID: ugBf8Q6n0CxnpJOZcTss/UhwlOfYeSqxoYPqi9eoDbfAuQ0xDMaXkH4q tYI9sRE/jqQ82yy1I7TAkg7CB3yudJH0YXYnbGozFEUknJ/kEl5lVdRvgpNpe/oLR4+zsDTtoSB RDpzc4nBTIhEBXNI5aqO5GuoY629glS+unzcbs/k1CJIE/9zH1gw3830maoNlfuUkC4A/hNCjPM wLVKwCR6CCN9KKKznu4vM2xBdXMyY= X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 Received-SPF: pass client-ip=139.138.36.223; envelope-from=yaoxt.fnst@fujitsu.com; helo=esa9.hc1455-7.c3s2.iphmx.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, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Yao Xingtao X-Patchwork-Original-From: Yao Xingtao via From: "Xingtao Yao (Fujitsu)" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org use ranges_overlap() instead of open-coding the overlap check to improve the readability of the code. Signed-off-by: Yao Xingtao Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé --- hw/cxl/cxl-mailbox-utils.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c index 74eeb6fde739..507690c0dd16 100644 --- a/hw/cxl/cxl-mailbox-utils.c +++ b/hw/cxl/cxl-mailbox-utils.c @@ -1086,8 +1086,8 @@ static CXLRetCode cmd_media_get_poison_list(const struct cxl_cmd *cmd, QLIST_FOREACH(ent, poison_list, node) { /* Check for no overlap */ - if (ent->start >= query_start + query_length || - ent->start + ent->length <= query_start) { + if (!ranges_overlap(ent->start, ent->length, + query_start, query_length)) { continue; } record_count++; @@ -1100,8 +1100,8 @@ static CXLRetCode cmd_media_get_poison_list(const struct cxl_cmd *cmd, uint64_t start, stop; /* Check for no overlap */ - if (ent->start >= query_start + query_length || - ent->start + ent->length <= query_start) { + if (!ranges_overlap(ent->start, ent->length, + query_start, query_length)) { continue; } From patchwork Mon Jul 22 04:07:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xingtao Yao (Fujitsu)" X-Patchwork-Id: 13738261 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id A00F7C3DA5D for ; Mon, 22 Jul 2024 04:12:56 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sVkMp-0004Jl-Sv; Mon, 22 Jul 2024 00:09:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVkMf-0003Z6-Mn; Mon, 22 Jul 2024 00:09:35 -0400 Received: from esa5.hc1455-7.c3s2.iphmx.com ([68.232.139.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVkMd-0001ub-EU; Mon, 22 Jul 2024 00:09:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1721621372; x=1753157372; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3zVcKBQCKQbvaThp7mSbptK5oDFKcWVd925E3jJP5MQ=; b=pQbULxcYRTaCQ32QB3byZaYuFqU4f7gqwKiCS9tENFL32kYvJ6Yn83S0 +ATCYzTMfyyi4xGE1xgr2SIawJZ5pA83CrTGCKP5WB/SHMfr1Y2+01D2a AgBFUNwLbvseHqS3gXieC/Sd9UjRx6kUVunexXCHlOBDdYOj+SNkO44G9 MuxKF8dOF+H5YJDH+7WkVdV0AsfikKFY1sB0nQi64gWXG0MIxPdbA8HWx a+SlfrstXO7Sk81C+4v457u9qDy1/A5KRFRMabFwtf6oS2noDFZ2zlC01 xq3eIYUIQ83WbgdizVGohksKeiLRaZwlLV7q7mwT5hy4iNggOetbaWb/y w==; X-IronPort-AV: E=McAfee;i="6700,10204,11140"; a="167294580" X-IronPort-AV: E=Sophos;i="6.09,227,1716217200"; d="scan'208";a="167294580" Received: from unknown (HELO oym-r1.gw.nic.fujitsu.com) ([210.162.30.89]) by esa5.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jul 2024 13:09:26 +0900 Received: from oym-m1.gw.nic.fujitsu.com (oym-nat-oym-m1.gw.nic.fujitsu.com [192.168.87.58]) by oym-r1.gw.nic.fujitsu.com (Postfix) with ESMTP id 336F3E7521; Mon, 22 Jul 2024 13:09:24 +0900 (JST) Received: from kws-ab3.gw.nic.fujitsu.com (kws-ab3.gw.nic.fujitsu.com [192.51.206.21]) by oym-m1.gw.nic.fujitsu.com (Postfix) with ESMTP id 6493CD8B73; Mon, 22 Jul 2024 13:09:23 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by kws-ab3.gw.nic.fujitsu.com (Postfix) with ESMTP id E4DF220076D0B; Mon, 22 Jul 2024 13:09:22 +0900 (JST) Received: from localhost.localdomain (unknown [10.167.225.88]) by edo.cn.fujitsu.com (Postfix) with ESMTP id 70DC81A000A; Mon, 22 Jul 2024 12:09:22 +0800 (CST) To: qemu-devel@nongnu.org, BALATON Zoltan Cc: Yao Xingtao , qemu-ppc@nongnu.org Subject: [PATCH 05/13] display/sm501: make range overlap check more readable Date: Mon, 22 Jul 2024 00:07:34 -0400 Message-ID: <20240722040742.11513-6-yaoxt.fnst@fujitsu.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240722040742.11513-1-yaoxt.fnst@fujitsu.com> References: <20240722040742.11513-1-yaoxt.fnst@fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-28544.005 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-28544.005 X-TMASE-Result: 10-3.907200-10.000000 X-TMASE-MatchedRID: YE84GSk4VaxrFdvBEmTnvE7nLUqYrlslFIuBIWrdOePfUZT83lbkEHzG fWdtXBUcVgkik3UNgnmAMuqetGVetnyef22ep6XYxlblqLlYqXKnsjrxQufrpl/fbfaC05sQJgJ MYulwEmOxobjbDXd9COjQp20eagu8yA7p08E6TtS2npsOz8/fH1ODQFKIHmX6dhlnmRDifkgRZb RsQk5MBUB1QPq9bxnWZkAxAwjIrrMHz/H0kiLyEqGAtHMDjkk9 X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 Received-SPF: pass client-ip=68.232.139.130; envelope-from=yaoxt.fnst@fujitsu.com; helo=esa5.hc1455-7.c3s2.iphmx.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, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Yao Xingtao X-Patchwork-Original-From: Yao Xingtao via From: "Xingtao Yao (Fujitsu)" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org use ranges_overlap() instead of open-coding the overlap check to improve the readability of the code. Signed-off-by: Yao Xingtao --- hw/display/sm501.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hw/display/sm501.c b/hw/display/sm501.c index 26dc8170d89b..c25b2574e447 100644 --- a/hw/display/sm501.c +++ b/hw/display/sm501.c @@ -823,15 +823,15 @@ static void sm501_2d_operation(SM501State *s) } /* If reverse blit do simple check for overlaps */ if (rtl && src_base == dst_base && src_pitch == dst_pitch) { - overlap = (src_x < dst_x + width && src_x + width > dst_x && - src_y < dst_y + height && src_y + height > dst_y); + overlap = (ranges_overlap(src_x, width, dst_x, width) && + ranges_overlap(src_y, height, dst_y, height)); } else if (rtl) { - unsigned int sb, se, db, de; + unsigned int sb, sl, db, dl; sb = src_base + (src_x + src_y * src_pitch) * bypp; - se = sb + (width + (height - 1) * src_pitch) * bypp; + sl = (width + (height - 1) * src_pitch) * bypp; db = dst_base + (dst_x + dst_y * dst_pitch) * bypp; - de = db + (width + (height - 1) * dst_pitch) * bypp; - overlap = (db < se && sb < de); + dl = (width + (height - 1) * dst_pitch) * bypp; + overlap = ranges_overlap(sb, sl, db, dl); } #ifdef CONFIG_PIXMAN if (overlap && (s->use_pixman & BIT(2))) { From patchwork Mon Jul 22 04:07:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Xingtao Yao (Fujitsu)" X-Patchwork-Id: 13738264 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id AF51CC3DA5D for ; Mon, 22 Jul 2024 04:20:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sVkX5-0006q0-UH; Mon, 22 Jul 2024 00:20:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVkMe-0003SN-B2; Mon, 22 Jul 2024 00:09:35 -0400 Received: from esa8.hc1455-7.c3s2.iphmx.com ([139.138.61.253]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVkMc-0001uh-Hh; Mon, 22 Jul 2024 00:09:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1721621370; x=1753157370; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qumiivx2cCD24Q53qJBJyPxD9WtGoUxPGPzrxWorQfM=; b=jGzb39muqxAbdS3v3MhiskhTQFxfMiVrZ6VT35vET03mcGwDK/87QazE WdiIBdt6Fymg58s0r1X67ik+wEAgYCBVnqT/hquM3xHadQXgxynDj2OZb KsuSOshDapWdppQTD6o4G0T+5ENCqFc6Wr0PX2PLPZtV+M4GJ1Z20a1e2 Kf/bA8+uIEPOY3O/zPs8AU1qIjx7SQUzFP4QSEvNxXcn5udm3M9ruIBC7 /vDkBmhzWJf+QiFr2fhQ/oI/4J7eecvBksuByIswCe2/3Y4xEMzJbwn+Q kCDoiEFLgcy/jblRsSlfirkxXKyNamNwKMl5nPJHNWCFM7yqPTxsYE27G w==; X-IronPort-AV: E=McAfee;i="6700,10204,11140"; a="156091037" X-IronPort-AV: E=Sophos;i="6.09,227,1716217200"; d="scan'208";a="156091037" Received: from unknown (HELO oym-r2.gw.nic.fujitsu.com) ([210.162.30.90]) by esa8.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jul 2024 13:09:27 +0900 Received: from oym-m2.gw.nic.fujitsu.com (oym-nat-oym-m2.gw.nic.fujitsu.com [192.168.87.59]) by oym-r2.gw.nic.fujitsu.com (Postfix) with ESMTP id 51761D922F; Mon, 22 Jul 2024 13:09:25 +0900 (JST) Received: from kws-ab3.gw.nic.fujitsu.com (kws-ab3.gw.nic.fujitsu.com [192.51.206.21]) by oym-m2.gw.nic.fujitsu.com (Postfix) with ESMTP id 93CB1BF3C5; Mon, 22 Jul 2024 13:09:24 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by kws-ab3.gw.nic.fujitsu.com (Postfix) with ESMTP id E8A642007CAAE; Mon, 22 Jul 2024 13:09:23 +0900 (JST) Received: from localhost.localdomain (unknown [10.167.225.88]) by edo.cn.fujitsu.com (Postfix) with ESMTP id C7D5A1A000C; Mon, 22 Jul 2024 12:09:22 +0800 (CST) To: qemu-devel@nongnu.org, Alistair Francis , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Peter Maydell , Steven Lee , Troy Lee , Jamin Lin , Andrew Jeffery , Joel Stanley Cc: Yao Xingtao , qemu-arm@nongnu.org Subject: [PATCH 06/13] aspeed_smc: make range overlap check more readable Date: Mon, 22 Jul 2024 00:07:35 -0400 Message-ID: <20240722040742.11513-7-yaoxt.fnst@fujitsu.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240722040742.11513-1-yaoxt.fnst@fujitsu.com> References: <20240722040742.11513-1-yaoxt.fnst@fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-28544.005 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-28544.005 X-TMASE-Result: 10-0.560200-10.000000 X-TMASE-MatchedRID: iXIp5h8ckINrFdvBEmTnvE7nLUqYrlslFIuBIWrdOeMiB3Nk/d/KPzAz xXEecc9kbP/Ei6ZWBVl8AX8i9OoygDcpdZ3fQiLdFEUknJ/kEl6YwzE9E8g5OfoLR4+zsDTtlu/ VKvCjKPWWCMgTNY5uqT6CF6AS8uspkU5FLuKEMQ7Xp+P1fQuP4cA3SWsItEgwlLQfiHD2BsVPwx Md7ySvYSQ4JrCfa4jMZO2i7mevsWiGk+xUaqdMDwHEKwHwYevbwUSxXh+jiUgkww/gwY7hMA== X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 Received-SPF: pass client-ip=139.138.61.253; envelope-from=yaoxt.fnst@fujitsu.com; helo=esa8.hc1455-7.c3s2.iphmx.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, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Yao Xingtao X-Patchwork-Original-From: Yao Xingtao via From: "Xingtao Yao (Fujitsu)" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org use ranges_overlap() instead of open-coding the overlap check to improve the readability of the code. Signed-off-by: Yao Xingtao Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé --- hw/ssi/aspeed_smc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/ssi/aspeed_smc.c b/hw/ssi/aspeed_smc.c index 49205ab76d38..cdca359e1d88 100644 --- a/hw/ssi/aspeed_smc.c +++ b/hw/ssi/aspeed_smc.c @@ -31,6 +31,7 @@ #include "qemu/error-report.h" #include "qapi/error.h" #include "qemu/units.h" +#include "qemu/range.h" #include "trace.h" #include "hw/irq.h" @@ -246,8 +247,7 @@ static bool aspeed_smc_flash_overlap(const AspeedSMCState *s, asc->reg_to_segment(s, s->regs[R_SEG_ADDR0 + i], &seg); - if (new->addr + new->size > seg.addr && - new->addr < seg.addr + seg.size) { + if (ranges_overlap(new->addr, new->size, seg.addr, seg.size)) { aspeed_smc_error("new segment CS%d [ 0x%" HWADDR_PRIx" - 0x%"HWADDR_PRIx" ] overlaps with " "CS%d [ 0x%"HWADDR_PRIx" - 0x%"HWADDR_PRIx" ]", From patchwork Mon Jul 22 04:07:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Xingtao Yao (Fujitsu)" X-Patchwork-Id: 13738262 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 7EC46C3DA59 for ; Mon, 22 Jul 2024 04:12:56 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sVkMr-0004Yv-Vl; Mon, 22 Jul 2024 00:09:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVkMn-00048k-Hh for qemu-devel@nongnu.org; Mon, 22 Jul 2024 00:09:41 -0400 Received: from esa7.hc1455-7.c3s2.iphmx.com ([139.138.61.252]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVkMl-0001wx-PE for qemu-devel@nongnu.org; Mon, 22 Jul 2024 00:09:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1721621379; x=1753157379; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GA4nPORIGQjzZVaVYEJiQuZjbCyqq1kZkMjn0l4f0HM=; b=rJ3FcGhDZ0penx6139hdWFVrVi7+PiwT/8qAoo6Z3k35Yp6lrt+V+Duk naEL5u3OSplpGfQ3VYrZZV28yiH84l4/oYQwTe+Ec0ynR9kdeOvlmZ5KC dIRls92pGaZj9pyq7A0OnAOMCEgUfcwHTqOI1I9XFl82I+UJWfmNj+IzF 0GrY74DOsnJPMhwOaLLzfZCIqJoGpfcrnnvjfGZVHgtJMCeaYVZA+pQQz k1+Za3Ethhw15ju5OV9LzToTVqevMuGchasPnorMob34sf92LbjSiYVjG WowCEGc5O/hjXY6PK469fkP9h0dVlU6Sc7xZ9GPsjFXkoIPf2xZHc9VYz A==; X-IronPort-AV: E=McAfee;i="6700,10204,11140"; a="146958168" X-IronPort-AV: E=Sophos;i="6.09,227,1716217200"; d="scan'208";a="146958168" Received: from unknown (HELO oym-r2.gw.nic.fujitsu.com) ([210.162.30.90]) by esa7.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jul 2024 13:09:37 +0900 Received: from oym-m2.gw.nic.fujitsu.com (oym-nat-oym-m2.gw.nic.fujitsu.com [192.168.87.59]) by oym-r2.gw.nic.fujitsu.com (Postfix) with ESMTP id CAD05D9223 for ; Mon, 22 Jul 2024 13:09:35 +0900 (JST) Received: from kws-ab3.gw.nic.fujitsu.com (kws-ab3.gw.nic.fujitsu.com [192.51.206.21]) by oym-m2.gw.nic.fujitsu.com (Postfix) with ESMTP id 0F7F1BF3C5 for ; Mon, 22 Jul 2024 13:09:25 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by kws-ab3.gw.nic.fujitsu.com (Postfix) with ESMTP id 9642F20076D0D for ; Mon, 22 Jul 2024 13:09:24 +0900 (JST) Received: from localhost.localdomain (unknown [10.167.225.88]) by edo.cn.fujitsu.com (Postfix) with ESMTP id BB8B81A000A; Mon, 22 Jul 2024 12:09:23 +0800 (CST) To: qemu-devel@nongnu.org, Alexander Bulekov , Paolo Bonzini , Bandan Das , Stefan Hajnoczi , Thomas Huth , Darren Kenny , Qiuhao Li , Laurent Vivier Cc: Yao Xingtao Subject: [PATCH 07/13] qtest/fuzz: make range overlap check more readable Date: Mon, 22 Jul 2024 00:07:36 -0400 Message-ID: <20240722040742.11513-8-yaoxt.fnst@fujitsu.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240722040742.11513-1-yaoxt.fnst@fujitsu.com> References: <20240722040742.11513-1-yaoxt.fnst@fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-28544.005 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-28544.005 X-TMASE-Result: 10-0.713900-10.000000 X-TMASE-MatchedRID: alxK4aWrxwlrFdvBEmTnvDyjd/AizytBAZn/4A9db2TAuQ0xDMaXkH4q tYI9sRE/3BlBvFCka9sboCivyaDEEgdrD3O6lkawngIgpj8eDcBpkajQR5gb3mn0m688Eo38Kra uXd3MZDVhghmdIrP4RYGHOnE1bLKai1k/2x9BxsnjSkboDGTSyiplNLSwFcg5nYfGVyys98Q+/a BNVcwpcBVYRtxXPf7JWHxhTISq8s7/I8o6mB5zERXFEH92Kf64nTtPxlIuIBW9Hzj86YHXBCnif x5AGfCL X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 Received-SPF: pass client-ip=139.138.61.252; envelope-from=yaoxt.fnst@fujitsu.com; helo=esa7.hc1455-7.c3s2.iphmx.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, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Yao Xingtao X-Patchwork-Original-From: Yao Xingtao via From: "Xingtao Yao (Fujitsu)" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org use ranges_overlap() instead of open-coding the overlap check to improve the readability of the code. Signed-off-by: Yao Xingtao Reviewed-by: Alexander Bulekov Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé --- tests/qtest/fuzz/generic_fuzz.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/qtest/fuzz/generic_fuzz.c b/tests/qtest/fuzz/generic_fuzz.c index ec842e03c5e6..d107a496da63 100644 --- a/tests/qtest/fuzz/generic_fuzz.c +++ b/tests/qtest/fuzz/generic_fuzz.c @@ -11,6 +11,7 @@ */ #include "qemu/osdep.h" +#include "qemu/range.h" #include @@ -211,7 +212,7 @@ void fuzz_dma_read_cb(size_t addr, size_t len, MemoryRegion *mr) i < dma_regions->len && (avoid_double_fetches || qtest_log_enabled); ++i) { region = g_array_index(dma_regions, address_range, i); - if (addr < region.addr + region.size && addr + len > region.addr) { + if (ranges_overlap(addr, len, region.addr, region.size)) { double_fetch = true; if (addr < region.addr && avoid_double_fetches) { From patchwork Mon Jul 22 04:07:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Xingtao Yao (Fujitsu)" X-Patchwork-Id: 13738252 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 91C7BC3DA5D for ; Mon, 22 Jul 2024 04:12:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sVkMn-00046d-K8; Mon, 22 Jul 2024 00:09:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVkMe-0003Rt-72 for qemu-devel@nongnu.org; Mon, 22 Jul 2024 00:09:33 -0400 Received: from esa12.hc1455-7.c3s2.iphmx.com ([139.138.37.100]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVkMc-0001uo-IT for qemu-devel@nongnu.org; Mon, 22 Jul 2024 00:09:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1721621370; x=1753157370; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TzS+8fbFrs/6a4tdNbLjGDjHpaHfpFFVeETZgZcEgFg=; b=R64l3glnXGC10kDcLcYvdkNndRevS2Mo1QOJXQmn16cClIknS8mK5zmb 0P925Wy5Lbw1k4PFwusha65PKY16RrzQLh/D3ROFde149+Dqr4Jzo96V5 11uPzCSfEweaUDWB9CAc0PrPZymUBc3M47ofRX2aUxiJXetTlpSDPq3hf +VGgHmxdceLsZ/k/RVzJFI1od2Wd7cRLWPgbkoVmBgKlPkWG96aldnYls enmoq9Rb3t0J6j7sWcYp7YRCxl0GoytkEi0h3tTCR9w7VTS8cEw8rowbT 7bAhKsXgpvrQg+1edeg4LrzeQ/xzH5v6ai7vCJEl/cqQDIhK8DkzZmq9h Q==; X-IronPort-AV: E=McAfee;i="6700,10204,11140"; a="147100670" X-IronPort-AV: E=Sophos;i="6.09,227,1716217200"; d="scan'208";a="147100670" Received: from unknown (HELO oym-r1.gw.nic.fujitsu.com) ([210.162.30.89]) by esa12.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jul 2024 13:09:28 +0900 Received: from oym-m4.gw.nic.fujitsu.com (oym-nat-oym-m4.gw.nic.fujitsu.com [192.168.87.61]) by oym-r1.gw.nic.fujitsu.com (Postfix) with ESMTP id 188F1E753A for ; Mon, 22 Jul 2024 13:09:26 +0900 (JST) Received: from kws-ab3.gw.nic.fujitsu.com (kws-ab3.gw.nic.fujitsu.com [192.51.206.21]) by oym-m4.gw.nic.fujitsu.com (Postfix) with ESMTP id 67311D4C1C for ; Mon, 22 Jul 2024 13:09:25 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by kws-ab3.gw.nic.fujitsu.com (Postfix) with ESMTP id 004072007CAB2 for ; Mon, 22 Jul 2024 13:09:25 +0900 (JST) Received: from localhost.localdomain (unknown [10.167.225.88]) by edo.cn.fujitsu.com (Postfix) with ESMTP id 7602D1A000C; Mon, 22 Jul 2024 12:09:24 +0800 (CST) To: qemu-devel@nongnu.org, Mark Cave-Ayland , Artyom Tarasenko Cc: Yao Xingtao Subject: [PATCH 08/13] sparc/ldst_helper: make range overlap check more readable Date: Mon, 22 Jul 2024 00:07:37 -0400 Message-ID: <20240722040742.11513-9-yaoxt.fnst@fujitsu.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240722040742.11513-1-yaoxt.fnst@fujitsu.com> References: <20240722040742.11513-1-yaoxt.fnst@fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-28544.005 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-28544.005 X-TMASE-Result: 10--2.279800-10.000000 X-TMASE-MatchedRID: iXIp5h8ckINrFdvBEmTnvE7nLUqYrlslFIuBIWrdOePfUZT83lbkEJCl VuR6WzhZ5hXzidezaCB8AX8i9OoygDcpdZ3fQiLdFEUknJ/kEl5lVdRvgpNpe/oLR4+zsDTtoub v1b7BWh2J22Yz0L2Is774ZOp8MSm1gMIpLIwKjjXB55t1PoDsghIJghcZKNkL4YG1k8zNzrK+Xv 0nAhvdkI94LsuYe6JJrSGd+JHfa+iGk+xUaqdMDwHEKwHwYevbwUSxXh+jiUgkww/gwY7hMA== X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 Received-SPF: pass client-ip=139.138.37.100; envelope-from=yaoxt.fnst@fujitsu.com; helo=esa12.hc1455-7.c3s2.iphmx.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, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Yao Xingtao X-Patchwork-Original-From: Yao Xingtao via From: "Xingtao Yao (Fujitsu)" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org use ranges_overlap() instead of open-coding the overlap check to improve the readability of the code. Signed-off-by: Yao Xingtao Reviewed-by: Philippe Mathieu-Daudé --- target/sparc/ldst_helper.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/target/sparc/ldst_helper.c b/target/sparc/ldst_helper.c index 2d48e98bf468..d92c9f15934e 100644 --- a/target/sparc/ldst_helper.c +++ b/target/sparc/ldst_helper.c @@ -19,6 +19,7 @@ #include "qemu/osdep.h" #include "qemu/log.h" +#include "qemu/range.h" #include "cpu.h" #include "tcg/tcg.h" #include "exec/helper-proto.h" @@ -240,9 +241,7 @@ static void replace_tlb_1bit_lru(SparcTLBEntry *tlb, if (new_ctx == ctx) { uint64_t vaddr = tlb[i].tag & ~0x1fffULL; uint64_t size = 8192ULL << 3 * TTE_PGSIZE(tlb[i].tte); - if (new_vaddr == vaddr - || (new_vaddr < vaddr + size - && vaddr < new_vaddr + new_size)) { + if (ranges_overlap(new_vaddr, new_size, vaddr, size)) { DPRINTF_MMU("auto demap entry [%d] %lx->%lx\n", i, vaddr, new_vaddr); replace_tlb_entry(&tlb[i], tlb_tag, tlb_tte, env1); From patchwork Mon Jul 22 04:07:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Xingtao Yao (Fujitsu)" X-Patchwork-Id: 13738248 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 3AB54C3DA5D for ; Mon, 22 Jul 2024 04:11:27 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sVkMo-0004CK-K0; Mon, 22 Jul 2024 00:09:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVkMf-0003ZO-Ow for qemu-devel@nongnu.org; Mon, 22 Jul 2024 00:09:35 -0400 Received: from esa6.hc1455-7.c3s2.iphmx.com ([68.232.139.139]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVkMc-0001uq-UZ for qemu-devel@nongnu.org; Mon, 22 Jul 2024 00:09:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1721621371; x=1753157371; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AFWX7oe4e/py8/GcIXfzLu5/oY6d0nTsj9DRGpkoYDg=; b=oxD96JM5cf8InlZ8nB5awfpdfw4gEgCUuajP/p0hK1fv/cIpDdbtqpTH BKbVquF50BFiPFQAvgFFsxw5DSsL+uFTVWG2dDlf1jX2UMRz9RL7rzw/A rM/cCfEw6/pYKgQ5icmuhq1IHR86l8UtWs6be+tsxfDt8DeIBrpv/yw+r 7b7PE00ZXBal/2TesH2sILmRojf6AlaiHeVo1vzfppkXJqLyrUznuUvSe h/fU69ww4GI7fxaw+M66AStzOasLEqTjme7J5q/IhotJtSHZ+HZqpEgp4 ruOyBeD0jFECXvDiP0RKMXbcEsTF2/0dVNG7GEpOR4KlePo+vcEpIDr5W Q==; X-IronPort-AV: E=McAfee;i="6700,10204,11140"; a="169998105" X-IronPort-AV: E=Sophos;i="6.09,227,1716217200"; d="scan'208";a="169998105" Received: from unknown (HELO oym-r3.gw.nic.fujitsu.com) ([210.162.30.91]) by esa6.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jul 2024 13:09:29 +0900 Received: from oym-m2.gw.nic.fujitsu.com (oym-nat-oym-m2.gw.nic.fujitsu.com [192.168.87.59]) by oym-r3.gw.nic.fujitsu.com (Postfix) with ESMTP id 7DA1DD64AF for ; Mon, 22 Jul 2024 13:09:26 +0900 (JST) Received: from kws-ab4.gw.nic.fujitsu.com (kws-ab4.gw.nic.fujitsu.com [192.51.206.22]) by oym-m2.gw.nic.fujitsu.com (Postfix) with ESMTP id C8DD0BF3D1 for ; Mon, 22 Jul 2024 13:09:25 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by kws-ab4.gw.nic.fujitsu.com (Postfix) with ESMTP id 5CCBB6CB34 for ; Mon, 22 Jul 2024 13:09:25 +0900 (JST) Received: from localhost.localdomain (unknown [10.167.225.88]) by edo.cn.fujitsu.com (Postfix) with ESMTP id D4A201A000A; Mon, 22 Jul 2024 12:09:24 +0800 (CST) To: qemu-devel@nongnu.org, Paolo Bonzini , Peter Xu , David Hildenbrand , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Cc: Yao Xingtao Subject: [PATCH 09/13] system/memory_mapping: make range overlap check more readable Date: Mon, 22 Jul 2024 00:07:38 -0400 Message-ID: <20240722040742.11513-10-yaoxt.fnst@fujitsu.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240722040742.11513-1-yaoxt.fnst@fujitsu.com> References: <20240722040742.11513-1-yaoxt.fnst@fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-28544.004 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-28544.004 X-TMASE-Result: 10-4.578200-10.000000 X-TMASE-MatchedRID: x/wzmLbLaAVrFdvBEmTnvE7nLUqYrlslFIuBIWrdOeM3ZbGC9oP/O34O FrQCV6cJPE7FMRuDJPKAMuqetGVetk6N1CbkSyKE3QfwsVk0UbvqwGfCk7KUs6TLRbQb4IgNSKe N5H+uitBo6pnXeuP4iIaPtB0U19+SuFhJm7N3ILWb91fmSdHviCr4ymhFUnjPPn+4l+IOCsn2yu uu62RRliHJp2UYVccqxOB8J0pRLhyJxKSZiwBX6QtRTXOqKmFVftwZ3X11IV0= X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 Received-SPF: pass client-ip=68.232.139.139; envelope-from=yaoxt.fnst@fujitsu.com; helo=esa6.hc1455-7.c3s2.iphmx.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, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Yao Xingtao X-Patchwork-Original-From: Yao Xingtao via From: "Xingtao Yao (Fujitsu)" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org use ranges_overlap() instead of open-coding the overlap check to improve the readability of the code. Signed-off-by: Yao Xingtao Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Reviewed-by: David Hildenbrand --- system/memory_mapping.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/memory_mapping.c b/system/memory_mapping.c index 6f884c5b90c9..ca2390eb8044 100644 --- a/system/memory_mapping.c +++ b/system/memory_mapping.c @@ -12,6 +12,7 @@ */ #include "qemu/osdep.h" +#include "qemu/range.h" #include "qapi/error.h" #include "sysemu/memory_mapping.h" @@ -353,8 +354,7 @@ void memory_mapping_filter(MemoryMappingList *list, int64_t begin, MemoryMapping *cur, *next; QTAILQ_FOREACH_SAFE(cur, &list->head, next, next) { - if (cur->phys_addr >= begin + length || - cur->phys_addr + cur->length <= begin) { + if (!ranges_overlap(cur->phys_addr, cur->length, begin, length)) { QTAILQ_REMOVE(&list->head, cur, next); g_free(cur); list->num--; From patchwork Mon Jul 22 04:07:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xingtao Yao (Fujitsu)" X-Patchwork-Id: 13738249 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 429A1C3DA59 for ; Mon, 22 Jul 2024 04:11:27 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sVkNE-000652-E7; Mon, 22 Jul 2024 00:10:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVkMh-0003e8-0U; Mon, 22 Jul 2024 00:09:35 -0400 Received: from esa3.hc1455-7.c3s2.iphmx.com ([207.54.90.49]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVkMd-0001uv-OD; Mon, 22 Jul 2024 00:09:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1721621373; x=1753157373; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=F5ChYdPZM2RGJKn48h9r2WBfiqQ8M0QNQ/FSXybAwHA=; b=oRHulWbPGYJiVZlBdEVj4jSGE/edbXgmuvOhZXt5IWKTr8L42tsEUKFH IO6SUW4ybCEY4u6LMzPp4+h7+Yk0TsPy7SutE3T8fAS+GpDtP9M8z6NFr LmdYjbQk6QjyqoP96PvkSZr9jkg0dvPzo4XClwvTS/SdCoPyqrfg6LB64 PJvoRXoPG649LxxNqbnGTGTHXevKC0NpTF48CvztXEJW7pxUjnu1SuhxU P2YYmmo3ofhqICLjlinWMl+xC9RtHn6/E2Z0GTu7uzBWCfq97HljsOoA0 mKh3nvUtnodB2XzwSwTRKGCOkENY/4GvH7JlPgUw/7eQriB7KCsePqRCL g==; X-IronPort-AV: E=McAfee;i="6700,10204,11140"; a="168068754" X-IronPort-AV: E=Sophos;i="6.09,227,1716217200"; d="scan'208";a="168068754" Received: from unknown (HELO oym-r2.gw.nic.fujitsu.com) ([210.162.30.90]) by esa3.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jul 2024 13:09:30 +0900 Received: from oym-m2.gw.nic.fujitsu.com (oym-nat-oym-m2.gw.nic.fujitsu.com [192.168.87.59]) by oym-r2.gw.nic.fujitsu.com (Postfix) with ESMTP id C2341D9227; Mon, 22 Jul 2024 13:09:26 +0900 (JST) Received: from kws-ab3.gw.nic.fujitsu.com (kws-ab3.gw.nic.fujitsu.com [192.51.206.21]) by oym-m2.gw.nic.fujitsu.com (Postfix) with ESMTP id 1ED36BF3CE; Mon, 22 Jul 2024 13:09:26 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by kws-ab3.gw.nic.fujitsu.com (Postfix) with ESMTP id B0C3A2007CAAE; Mon, 22 Jul 2024 13:09:25 +0900 (JST) Received: from localhost.localdomain (unknown [10.167.225.88]) by edo.cn.fujitsu.com (Postfix) with ESMTP id 3E8911A000C; Mon, 22 Jul 2024 12:09:25 +0800 (CST) To: qemu-devel@nongnu.org, Jeff Cody , Kevin Wolf , Hanna Reitz Cc: Yao Xingtao , qemu-block@nongnu.org Subject: [PATCH 10/13] block/vhdx: make range overlap check more readable Date: Mon, 22 Jul 2024 00:07:39 -0400 Message-ID: <20240722040742.11513-11-yaoxt.fnst@fujitsu.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240722040742.11513-1-yaoxt.fnst@fujitsu.com> References: <20240722040742.11513-1-yaoxt.fnst@fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-28544.005 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-28544.005 X-TMASE-Result: 10-6.119200-10.000000 X-TMASE-MatchedRID: x/wzmLbLaAVrFdvBEmTnvE7nLUqYrlslFIuBIWrdOePfUZT83lbkEKRV r7nyVRs2TuaHtZS0liiAMuqetGVetsgO3bswsOnS3QfwsVk0UbuGrPnef/I+ersPurXJ/Jd+c9f FCs3N06jHTBjQFZuitxfyaog4dF1iwXweWJLhLSPy8FPuj0a6XdcJHibXPW41cND6xqjxBBo6Vi EPIPnfcw== X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 Received-SPF: pass client-ip=207.54.90.49; envelope-from=yaoxt.fnst@fujitsu.com; helo=esa3.hc1455-7.c3s2.iphmx.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Yao Xingtao X-Patchwork-Original-From: Yao Xingtao via From: "Xingtao Yao (Fujitsu)" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org use range_overlaps_range() instead of open-coding the overlap check to improve the readability of the code. Signed-off-by: Yao Xingtao --- block/vhdx.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/block/vhdx.c b/block/vhdx.c index 5aa1a1350626..c31661b946b6 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -32,6 +32,7 @@ #include "qapi/qmp/qdict.h" #include "qapi/qobject-input-visitor.h" #include "qapi/qapi-visit-block-core.h" +#include "qemu/range.h" /* Options for VHDX creation */ @@ -231,15 +232,16 @@ void vhdx_guid_generate(MSGUID *guid) static int vhdx_region_check(BDRVVHDXState *s, uint64_t start, uint64_t length) { int ret = 0; - uint64_t end; VHDXRegionEntry *r; + Range range1, range2; - end = start + length; + range_init_nofail(&range1, start, length); QLIST_FOREACH(r, &s->regions, entries) { - if (!((start >= r->end) || (end <= r->start))) { + range_init_nofail(&range2, r->start, r->end - r->start); + if (range_overlaps_range(&range1, &range2)) { error_report("VHDX region %" PRIu64 "-%" PRIu64 " overlaps with " - "region %" PRIu64 "-%." PRIu64, start, end, r->start, - r->end); + "region %" PRIu64 "-%." PRIu64, start, start + length, + r->start, r->end); ret = -EINVAL; goto exit; } From patchwork Mon Jul 22 04:07:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Xingtao Yao (Fujitsu)" X-Patchwork-Id: 13738251 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id D0F37C3DA5D for ; Mon, 22 Jul 2024 04:11:36 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sVkMp-0004Hc-95; Mon, 22 Jul 2024 00:09:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVkMf-0003ZG-OK for qemu-devel@nongnu.org; Mon, 22 Jul 2024 00:09:35 -0400 Received: from esa1.hc1455-7.c3s2.iphmx.com ([207.54.90.47]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVkMd-0001uw-9H for qemu-devel@nongnu.org; Mon, 22 Jul 2024 00:09:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1721621372; x=1753157372; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3eyeJQCSyvZboVov/rz+7Pynbeobdgv9WyZcGZymbCM=; b=NtfXz1EGiPKH5xuJxZW3xm9MJY3UkNnfkp00Is61eIL9h5MsiWJGfSrW f9S3GIgq4wtNCqJnvGSWbTTgS6bRbLQbOnHF1Nc3DlyvxULY1uxl9CaYP N0orrRUGIraXkOjJPED4LPGR41aC5YoeObfC9VNOHh5CGUweuyGRbH4h5 1v93XnDQH2bMgLPvn7W0aEiGU7Ye5OaORJsjnEZOjFbnUboZcbzI1rJTf ta1kI+Q8yHITcepkryFR3LOOPYQb3QGraXEeoQUvZayxzI/Hj50qjJ7zS FHCQccQRGByYw4PTyGMNYolwWKKe8bxKbfCl8NBnUcn8cAeWlyV2xOOZ2 A==; X-IronPort-AV: E=McAfee;i="6700,10204,11140"; a="168040033" X-IronPort-AV: E=Sophos;i="6.09,227,1716217200"; d="scan'208";a="168040033" Received: from unknown (HELO yto-r3.gw.nic.fujitsu.com) ([218.44.52.219]) by esa1.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jul 2024 13:09:30 +0900 Received: from yto-m1.gw.nic.fujitsu.com (yto-nat-yto-m1.gw.nic.fujitsu.com [192.168.83.64]) by yto-r3.gw.nic.fujitsu.com (Postfix) with ESMTP id 281CBD46CC for ; Mon, 22 Jul 2024 13:09:27 +0900 (JST) Received: from kws-ab3.gw.nic.fujitsu.com (kws-ab3.gw.nic.fujitsu.com [192.51.206.21]) by yto-m1.gw.nic.fujitsu.com (Postfix) with ESMTP id 68ABBCF7C2 for ; Mon, 22 Jul 2024 13:09:26 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by kws-ab3.gw.nic.fujitsu.com (Postfix) with ESMTP id 0668120076D0F for ; Mon, 22 Jul 2024 13:09:26 +0900 (JST) Received: from localhost.localdomain (unknown [10.167.225.88]) by edo.cn.fujitsu.com (Postfix) with ESMTP id 905F81A000A; Mon, 22 Jul 2024 12:09:25 +0800 (CST) To: qemu-devel@nongnu.org, =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= Cc: Yao Xingtao Subject: [PATCH 11/13] crypto/block-luks: make range overlap check more readable Date: Mon, 22 Jul 2024 00:07:40 -0400 Message-ID: <20240722040742.11513-12-yaoxt.fnst@fujitsu.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240722040742.11513-1-yaoxt.fnst@fujitsu.com> References: <20240722040742.11513-1-yaoxt.fnst@fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-28544.005 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-28544.005 X-TMASE-Result: 10-5.537200-10.000000 X-TMASE-MatchedRID: alxK4aWrxwlrFdvBEmTnvJXi1z8zt1TRwTlc9CcHMZerwqxtE531VIPc XuILVCbasWlJXtA6pzily6awGSvbQP+rgDQQ6Eo3ngIgpj8eDcBpkajQR5gb3mn0m688Eo38Kra uXd3MZDUOfvaOrdl4gu4Zvr7PIH5ler360JD+IHd5rtcULOTTv2FjtwS2QCHaObxhn2yfSebkvG Bl1+gWAx5XWBJ6dWGv1duwvC6IliMfwV6sBPR0lg== X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 Received-SPF: pass client-ip=207.54.90.47; envelope-from=yaoxt.fnst@fujitsu.com; helo=esa1.hc1455-7.c3s2.iphmx.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Yao Xingtao X-Patchwork-Original-From: Yao Xingtao via From: "Xingtao Yao (Fujitsu)" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org use ranges_overlap() instead of open-coding the overlap check to improve the readability of the code. Signed-off-by: Yao Xingtao Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Reviewed-by: Daniel P. Berrangé --- crypto/block-luks.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crypto/block-luks.c b/crypto/block-luks.c index 5b777c15d3cd..45347adeeb71 100644 --- a/crypto/block-luks.c +++ b/crypto/block-luks.c @@ -33,6 +33,7 @@ #include "qemu/uuid.h" #include "qemu/bitmap.h" +#include "qemu/range.h" /* * Reference for the LUKS format implemented here is @@ -572,7 +573,7 @@ qcrypto_block_luks_check_header(const QCryptoBlockLUKS *luks, header_sectors, slot2->stripes); - if (start1 + len1 > start2 && start2 + len2 > start1) { + if (ranges_overlap(start1, len1, start2, len2)) { error_setg(errp, "Keyslots %zu and %zu are overlapping in the header", i, j); From patchwork Mon Jul 22 04:07:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Xingtao Yao (Fujitsu)" X-Patchwork-Id: 13738263 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 98E51C3DA59 for ; Mon, 22 Jul 2024 04:17:24 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sVkU2-00032x-0q; Mon, 22 Jul 2024 00:17:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVkMf-0003ZH-Oh for qemu-devel@nongnu.org; Mon, 22 Jul 2024 00:09:35 -0400 Received: from esa4.hc1455-7.c3s2.iphmx.com ([68.232.139.117]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVkMd-0001v6-K5 for qemu-devel@nongnu.org; Mon, 22 Jul 2024 00:09:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1721621371; x=1753157371; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=J16J3bUUCCZz8SNQ1pnXVC0f4NBP6OpuoE09JYT9tFk=; b=rUdIVEDMApJ3CMBwHAUHFznrzvmbeXdAwf7FhQoXYLPLYQX+JexeVjga VDc38TPnLdi5z3j/JkXgPnLX4kUULqPSICQefiz/IDIoo7AAaftsC0XZE kQ5Xst55VqWoPw1B5014edYPds2sf9EXW4DgcxSwW+2GTL2aI7jmPf1kL vJZZxFq1gVfpVmew0k5kB4BwHOdneNbz+GphmbEbq/JWSNchSiIAjFlE9 PZpudbJAB+r9F8eNz/Pe6B9jeBcACkwHAiKWws2AvYYaq1GxUxKBE5lni MbIVBBjIT4+5cbR0fZj01NtkHKJRQOsBAplcQyEag94jLZa9KpVPsArvX g==; X-IronPort-AV: E=McAfee;i="6700,10204,11140"; a="168189032" X-IronPort-AV: E=Sophos;i="6.09,227,1716217200"; d="scan'208";a="168189032" Received: from unknown (HELO yto-r2.gw.nic.fujitsu.com) ([218.44.52.218]) by esa4.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jul 2024 13:09:29 +0900 Received: from yto-m2.gw.nic.fujitsu.com (yto-nat-yto-m2.gw.nic.fujitsu.com [192.168.83.65]) by yto-r2.gw.nic.fujitsu.com (Postfix) with ESMTP id 6791DC68E1 for ; Mon, 22 Jul 2024 13:09:27 +0900 (JST) Received: from kws-ab4.gw.nic.fujitsu.com (kws-ab4.gw.nic.fujitsu.com [192.51.206.22]) by yto-m2.gw.nic.fujitsu.com (Postfix) with ESMTP id A78EDD5084 for ; Mon, 22 Jul 2024 13:09:26 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by kws-ab4.gw.nic.fujitsu.com (Postfix) with ESMTP id 411E06BEE3 for ; Mon, 22 Jul 2024 13:09:26 +0900 (JST) Received: from localhost.localdomain (unknown [10.167.225.88]) by edo.cn.fujitsu.com (Postfix) with ESMTP id DA7011A000C; Mon, 22 Jul 2024 12:09:25 +0800 (CST) To: qemu-devel@nongnu.org, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Cc: Yao Xingtao Subject: [PATCH 12/13] dump: make range overlap check more readable Date: Mon, 22 Jul 2024 00:07:41 -0400 Message-ID: <20240722040742.11513-13-yaoxt.fnst@fujitsu.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240722040742.11513-1-yaoxt.fnst@fujitsu.com> References: <20240722040742.11513-1-yaoxt.fnst@fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-28544.004 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-28544.004 X-TMASE-Result: 10-1.466200-10.000000 X-TMASE-MatchedRID: aX2W24vmfqtrFdvBEmTnvE7nLUqYrlslFIuBIWrdOePfUZT83lbkEMJ0 8DtUl59d4vM1YF6AJbbCCfuIMF6xLSdET58jp62S9M5PwAWtc78/e8WetA82gR8A5FKx/2CwHoy 9hRvP6ZHWc/yVdeVbB9+rXFOMnFgVcT8bxD7i6R6YlW8M/ovaPK9ZlES3lzEjwGC8e6520fKw0P Jt06oJaHpaQl5xviY7wxgWdRvK9Un9g+oMf9KM6Q== X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 Received-SPF: pass client-ip=68.232.139.117; envelope-from=yaoxt.fnst@fujitsu.com; helo=esa4.hc1455-7.c3s2.iphmx.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, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Yao Xingtao X-Patchwork-Original-From: Yao Xingtao via From: "Xingtao Yao (Fujitsu)" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org use ranges_overlap() instead of open-coding the overlap check to improve the readability of the code. Signed-off-by: Yao Xingtao Reviewed-by: Marc-André Lureau --- dump/dump.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index 84064d890d2c..45e84428aea5 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -30,6 +30,7 @@ #include "migration/blocker.h" #include "hw/core/cpu.h" #include "win_dump.h" +#include "qemu/range.h" #include #ifdef CONFIG_LZO @@ -574,8 +575,10 @@ static void get_offset_range(hwaddr phys_addr, QTAILQ_FOREACH(block, &s->guest_phys_blocks.head, next) { if (dump_has_filter(s)) { - if (block->target_start >= s->filter_area_begin + s->filter_area_length || - block->target_end <= s->filter_area_begin) { + if (!ranges_overlap(block->target_start, + block->target_end - block->target_start, + s->filter_area_begin, + s->filter_area_length)) { /* This block is out of the range */ continue; } @@ -734,8 +737,9 @@ int64_t dump_filtered_memblock_start(GuestPhysBlock *block, { if (filter_area_length) { /* return -1 if the block is not within filter area */ - if (block->target_start >= filter_area_start + filter_area_length || - block->target_end <= filter_area_start) { + if (!ranges_overlap(block->target_start, + block->target_end - block->target_start, + filter_area_start, filter_area_length)) { return -1; } From patchwork Mon Jul 22 04:07:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xingtao Yao (Fujitsu)" X-Patchwork-Id: 13738250 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 8778FC3DA59 for ; Mon, 22 Jul 2024 04:11:30 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sVkMq-0004PF-I6; Mon, 22 Jul 2024 00:09:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVkMh-0003e6-0J; Mon, 22 Jul 2024 00:09:35 -0400 Received: from esa11.hc1455-7.c3s2.iphmx.com ([207.54.90.137]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sVkMe-0001vH-NN; Mon, 22 Jul 2024 00:09:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1721621373; x=1753157373; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0cOZ6dmCMUB1Ol69mJi10wVRsPCmuhLIXW65Q+KR5LE=; b=Ng2u27FFZIdOx5lo8+GWqdNp7yCb/MJYP59HlbjfMVJ0Eak9LRLfxctS H6JFvAsYf2k8ORfE9cOjGKeKB7ORSDQU1wkMHrLPq97F9WlvyNDGY+Rv+ olXhuE6SRNoO8bB6F5QKSBEPxSnswfUH9Zgtc3HFRfcq7DmmAtZf9uBHk nE2uIUPI1Qpgd4gmGXpCZbWiWu5jNTlYe58CAWfvPScPIVqZCGZL8lS/1 j1BiyefBw/y8S3Ip7mXS8S32/s6OFXvvFLjQjQW5hGQMLl58Gahq1tUJb iKiFsnOs16BuKgI15pK/WZvn8mEj7yVzFR5biHcbibFI3EnOeb/DUeDzj g==; X-IronPort-AV: E=McAfee;i="6700,10204,11140"; a="147511123" X-IronPort-AV: E=Sophos;i="6.09,227,1716217200"; d="scan'208";a="147511123" Received: from unknown (HELO yto-r1.gw.nic.fujitsu.com) ([218.44.52.217]) by esa11.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jul 2024 13:09:30 +0900 Received: from yto-m4.gw.nic.fujitsu.com (yto-nat-yto-m4.gw.nic.fujitsu.com [192.168.83.67]) by yto-r1.gw.nic.fujitsu.com (Postfix) with ESMTP id AFE35DB3C7; Mon, 22 Jul 2024 13:09:27 +0900 (JST) Received: from kws-ab3.gw.nic.fujitsu.com (kws-ab3.gw.nic.fujitsu.com [192.51.206.21]) by yto-m4.gw.nic.fujitsu.com (Postfix) with ESMTP id EFD66D3F05; Mon, 22 Jul 2024 13:09:26 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by kws-ab3.gw.nic.fujitsu.com (Postfix) with ESMTP id 710A020076D0F; Mon, 22 Jul 2024 13:09:26 +0900 (JST) Received: from localhost.localdomain (unknown [10.167.225.88]) by edo.cn.fujitsu.com (Postfix) with ESMTP id 23FF31A000A; Mon, 22 Jul 2024 12:09:26 +0800 (CST) To: qemu-devel@nongnu.org, Kevin Wolf , Hanna Reitz Cc: Yao Xingtao , qemu-block@nongnu.org Subject: [PATCH 13/13] block/qcow2-cluster: make range overlap check more readable Date: Mon, 22 Jul 2024 00:07:42 -0400 Message-ID: <20240722040742.11513-14-yaoxt.fnst@fujitsu.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240722040742.11513-1-yaoxt.fnst@fujitsu.com> References: <20240722040742.11513-1-yaoxt.fnst@fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-28544.005 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-28544.005 X-TMASE-Result: 10-7.902800-10.000000 X-TMASE-MatchedRID: JWe69+O0c4hrFdvBEmTnvE7nLUqYrlslFIuBIWrdOePfUZT83lbkEMcs 3d4syBEpsd2TAMah+1Oc9VtzZ7deqLiv2sGf+QjZ8bgAAlufLFeGiafRvCBWaVc5Utg/MIXwo8W MkQWv6iXBcIE78YqRWo6HM5rqDwqtq07ChqDSzUR/AUnRd27tEbV8V3fsPbIehXxY2kjWQ9HjPV 4ZEr2BS29hgKLNrGQOazqzMNfnhu3d6fL/EodwzMLaGOV0GygEftwZ3X11IV0= X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 Received-SPF: pass client-ip=207.54.90.137; envelope-from=yaoxt.fnst@fujitsu.com; helo=esa11.hc1455-7.c3s2.iphmx.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Yao Xingtao X-Patchwork-Original-From: Yao Xingtao via From: "Xingtao Yao (Fujitsu)" Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org use range_overlaps_range() instead of open-coding the overlap check to improve the readability of the code. Signed-off-by: Yao Xingtao --- block/qcow2-cluster.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index ce8c0076b3b5..88d65c4b99e6 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -30,6 +30,7 @@ #include "qcow2.h" #include "qemu/bswap.h" #include "qemu/memalign.h" +#include "qemu/range.h" #include "trace.h" int coroutine_fn qcow2_shrink_l1_table(BlockDriverState *bs, @@ -1408,23 +1409,25 @@ static int coroutine_fn handle_dependencies(BlockDriverState *bs, BDRVQcow2State *s = bs->opaque; QCowL2Meta *old_alloc; uint64_t bytes = *cur_bytes; + Range range1, range2, range3; + range_init_nofail(&range1, guest_offset, bytes); QLIST_FOREACH(old_alloc, &s->cluster_allocs, next_in_flight) { - uint64_t start = guest_offset; - uint64_t end = start + bytes; - uint64_t old_start = start_of_cluster(s, l2meta_cow_start(old_alloc)); - uint64_t old_end = ROUND_UP(l2meta_cow_end(old_alloc), s->cluster_size); + uint64_t cow_start = l2meta_cow_start(old_alloc); + uint64_t cow_end = l2meta_cow_end(old_alloc); + uint64_t start = start_of_cluster(s, cow_start); + uint64_t end = ROUND_UP(cow_end, s->cluster_size); - if (end <= old_start || start >= old_end) { + range_init_nofail(&range2, start, end - start); + if (!range_overlaps_range(&range1, &range2)) { /* No intersection */ continue; } + range_init_nofail(&range3, cow_start, cow_end - cow_start); if (old_alloc->keep_old_clusters && - (end <= l2meta_cow_start(old_alloc) || - start >= l2meta_cow_end(old_alloc))) - { + !range_overlaps_range(&range1, &range3)) { /* * Clusters intersect but COW areas don't. And cluster itself is * already allocated. So, there is no actual conflict. @@ -1434,9 +1437,9 @@ static int coroutine_fn handle_dependencies(BlockDriverState *bs, /* Conflict */ - if (start < old_start) { + if (guest_offset < start) { /* Stop at the start of a running allocation */ - bytes = old_start - start; + bytes = start - guest_offset; } else { bytes = 0; }