From nobody Sun May 5 19:38:04 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 158203206195160.86091425056043; Tue, 18 Feb 2020 05:21:01 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j42nf-0003s2-W9; Tue, 18 Feb 2020 13:20:31 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j42nf-0003rx-8e for xen-devel@lists.xenproject.org; Tue, 18 Feb 2020 13:20:31 +0000 Received: from us-smtp-1.mimecast.com (unknown [205.139.110.61]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 6f1cca1b-5251-11ea-8180-12813bfff9fa; Tue, 18 Feb 2020 13:20:29 +0000 (UTC) Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-344-r6XED1IzMIaMQBy-wHi--A-1; Tue, 18 Feb 2020 08:20:28 -0500 Received: by mail-wr1-f71.google.com with SMTP id u8so10809049wrp.10 for ; Tue, 18 Feb 2020 05:20:27 -0800 (PST) Received: from x1w.redhat.com (78.red-88-21-202.staticip.rima-tde.net. [88.21.202.78]) by smtp.gmail.com with ESMTPSA id m68sm3531219wme.48.2020.02.18.05.20.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Feb 2020 05:20:24 -0800 (PST) X-Inumbo-ID: 6f1cca1b-5251-11ea-8180-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582032029; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/sFMMkb4e3qwBsA4b31ISSU5c6HT2zaacb/ZY1KC50I=; b=ZXpTxiqFGD/E408VgFbdmF1ylp4y+2zsPKD/OaQRnDUcMgTKAvlAoFQu9NmCSXLxbiTM00 8fUPabku5zm89weaMJK9N0J/vUX9Mu9jz/TDjQ322XGgfkqFP++OBQaubOx1RFXxM45r39 6pGphNZgFykP207t4wePAH36FFOoXbI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Q0b3JmegZIBOrzOx6D2WeXg3Fr4IgL8v1odhEcx6GCw=; b=pP8lpKXRiVcpavEp74MUJDZhN5gdcJBYji1cYWS+MRab52TQq+yOGG57SsI94nZQi/ y8ClBwBBXZiiJhgd1JDf5HEchWxhrhuc7n2Ki+d6fA4QlNQVbYy9/Itkg8sCOsX+VlhO WtaKb3kw1PXmz0Dkc9jwDhf1QZvjplfifphtmSHNEMpavT10HCV5mdFw6hR+TN5++NPx RO/KExb/4bNO8gNebEfbEW8DAp4FIfHtLcSg4ndxxwxHgWINRdCpkvYVycjfEbgPnLG0 kGu3JK3pTq7tFswJpnl+0qYzS8MOvhPQid9uJ61Mn6n+lBZMcdmpK9fmjAWZlSvjzS8r WHuQ== X-Gm-Message-State: APjAAAWs9wJv8b4zxXOD03d4mglvGGpardwR7TGMtq5Eyv3/XPVoBGyB pmfpKFijHMUMuOgkoovfgi35s4Dv/jRFYnBBt7CUNZsjHYN2Xbvx5/yKAWtMxdrXeg4ptoXY7EF ZnzHxBHSjCgwqtPgK1d6CTNcyWFw= X-Received: by 2002:adf:f491:: with SMTP id l17mr31157132wro.149.1582032025092; Tue, 18 Feb 2020 05:20:25 -0800 (PST) X-Google-Smtp-Source: APXvYqyKkQEDaHDISgH6qvq3pjfhjQ41Yebtgf20dAvgvUG3VIO2Qwt5nwgZHZ29Nv8QGZy+aHbmpw== X-Received: by 2002:adf:f491:: with SMTP id l17mr31157097wro.149.1582032024834; Tue, 18 Feb 2020 05:20:24 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Date: Tue, 18 Feb 2020 14:20:23 +0100 Message-Id: <20200218132023.22936-1-philmd@redhat.com> X-Mailer: git-send-email 2.21.1 MIME-Version: 1.0 X-MC-Unique: r6XED1IzMIaMQBy-wHi--A-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [Xen-devel] [PATCH] Avoid cpu_physical_memory_rw() with a constant is_write argument X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stefano Stabellini , Eduardo Habkost , Paul Durrant , Paolo Bonzini , Anthony Perard , xen-devel@lists.xenproject.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This commit was produced with the included Coccinelle script scripts/coccinelle/as-rw-const.patch. Inspired-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- Based-on: <20200218112457.22712-1-peter.maydell@linaro.org> Maybe can be squashed in Peter's patch? Cocci script can be written as: @@ expression E1, E2, E3, E4, E5; symbol true, false; @@ ( - address_space_rw(E1, E2, E3, E4, E5, false) + address_space_read(E1, E2, E3, E4, E5) | - address_space_rw(E1, E2, E3, E4, E5, 0) + address_space_read(E1, E2, E3, E4, E5) | - address_space_rw(E1, E2, E3, E4, E5, true) + address_space_write(E1, E2, E3, E4, E5) | - address_space_rw(E1, E2, E3, E4, E5, 1) + address_space_write(E1, E2, E3, E4, E5) ) @@ expression E1, E2, E3; @@ ( - cpu_physical_memory_rw(E1, E2, E3, false) + cpu_physical_memory_read(E1, E2, E3) | - cpu_physical_memory_rw(E1, E2, E3, 0) + cpu_physical_memory_read(E1, E2, E3) | - cpu_physical_memory_rw(E1, E2, E3, true) + cpu_physical_memory_write(E1, E2, E3) | - cpu_physical_memory_rw(E1, E2, E3, 1) + cpu_physical_memory_write(E1, E2, E3) ) --- hw/xen/xen_pt_graphics.c | 2 +- target/i386/hax-all.c | 4 ++-- scripts/coccinelle/as_rw_const.cocci | 20 +++++++++++++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/hw/xen/xen_pt_graphics.c b/hw/xen/xen_pt_graphics.c index b69732729b..a3bc7e3921 100644 --- a/hw/xen/xen_pt_graphics.c +++ b/hw/xen/xen_pt_graphics.c @@ -222,7 +222,7 @@ void xen_pt_setup_vga(XenPCIPassthroughState *s, XenHos= tPCIDevice *dev, } =20 /* Currently we fixed this address as a primary for legacy BIOS. */ - cpu_physical_memory_rw(0xc0000, bios, bios_size, 1); + cpu_physical_memory_write(0xc0000, bios, bios_size); } =20 uint32_t igd_read_opregion(XenPCIPassthroughState *s) diff --git a/target/i386/hax-all.c b/target/i386/hax-all.c index a8b6e5aeb8..f5971ccc74 100644 --- a/target/i386/hax-all.c +++ b/target/i386/hax-all.c @@ -376,8 +376,8 @@ static int hax_handle_fastmmio(CPUArchState *env, struc= t hax_fastmmio *hft) * hft->direction =3D=3D 2: gpa =3D=3D> gpa2 */ uint64_t value; - cpu_physical_memory_rw(hft->gpa, (uint8_t *) &value, hft->size, 0); - cpu_physical_memory_rw(hft->gpa2, (uint8_t *) &value, hft->size, 1= ); + cpu_physical_memory_read(hft->gpa, (uint8_t *)&value, hft->size); + cpu_physical_memory_write(hft->gpa2, (uint8_t *)&value, hft->size); } =20 return 0; diff --git a/scripts/coccinelle/as_rw_const.cocci b/scripts/coccinelle/as_r= w_const.cocci index 30da707701..c9a39f1abe 100644 --- a/scripts/coccinelle/as_rw_const.cocci +++ b/scripts/coccinelle/as_rw_const.cocci @@ -1,6 +1,6 @@ // Avoid uses of address_space_rw() with a constant is_write argument. // Usage: -// spatch --sp-file as-rw-const.spatch --dir . --in-place +// spatch --sp-file scripts/coccinelle/as_rw_const.cocci --dir . --in-pla= ce =20 @@ expression E1, E2, E3, E4, E5; @@ -28,3 +28,21 @@ expression E1, E2, E3, E4, E5; =20 - address_space_rw(E1, E2, E3, E4, E5, 1) + address_space_write(E1, E2, E3, E4, E5) + +// Avoid uses of cpu_physical_memory_rw() with a constant is_write argumen= t. +@@ +expression E1, E2, E3; +@@ +( +- cpu_physical_memory_rw(E1, E2, E3, false) ++ cpu_physical_memory_read(E1, E2, E3) +| +- cpu_physical_memory_rw(E1, E2, E3, 0) ++ cpu_physical_memory_read(E1, E2, E3) +| +- cpu_physical_memory_rw(E1, E2, E3, true) ++ cpu_physical_memory_write(E1, E2, E3) +| +- cpu_physical_memory_rw(E1, E2, E3, 1) ++ cpu_physical_memory_write(E1, E2, E3) +) --=20 2.21.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel