From nobody Thu Nov 21 19:53:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1722872209; cv=none; d=zohomail.com; s=zohoarc; b=gVLGt9wp+f1hCeu1SvYQzTdft4U6aykztEZtHjNISGqWAHGlbdS8Pq2mYxEjPCPbd0MVpEY2UyX0MsazIiL3AnT5ATBc8yKii/803HsLdFOJk/XG5htsrh7XOKuTqU+eRWKzDzX+X/Qs90lIWnly44+zeRWmTN8KZUTpRAXjjyY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1722872209; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+MMMGxN2ape1bNpYFITLCt9gyz15hVErQ7V7ZB8BCQc=; b=Nc5r3JjKQ/i25+Tv2VbF8EDFHcCaXvN9I0IcshWZ/+V9vb9NGxx9tgX5ItNIqaPIr15JeBvTjJbo1j6XYSFYbw/FWcEVMfx4JsNgIjhc+6LlJSe4dXV5XQ3WjSpKqXx5wVynMHyl3mJjK7eplyLVt2+uSiwSI2raAla0L8OuiYw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1722872208848742.293558837148; Mon, 5 Aug 2024 08:36:48 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.772252.1182694 (Exim 4.92) (envelope-from ) id 1sazl4-0006iu-2Q; Mon, 05 Aug 2024 15:36:26 +0000 Received: by outflank-mailman (output) from mailman id 772252.1182694; Mon, 05 Aug 2024 15:36:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sazl3-0006in-WC; Mon, 05 Aug 2024 15:36:26 +0000 Received: by outflank-mailman (input) for mailman id 772252; Mon, 05 Aug 2024 15:36:24 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sazl2-0006g7-Jv for xen-devel@lists.xenproject.org; Mon, 05 Aug 2024 15:36:24 +0000 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [2a00:1450:4864:20::534]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 787c8cc6-5340-11ef-bc03-fd08da9f4363; Mon, 05 Aug 2024 17:36:23 +0200 (CEST) Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-5a156557029so15359430a12.2 for ; Mon, 05 Aug 2024 08:36:23 -0700 (PDT) Received: from EMEAENGAAD91498.citrite.net ([217.156.233.154]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5b839c24084sm5034957a12.30.2024.08.05.08.36.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Aug 2024 08:36:22 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 787c8cc6-5340-11ef-bc03-fd08da9f4363 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1722872183; x=1723476983; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=+MMMGxN2ape1bNpYFITLCt9gyz15hVErQ7V7ZB8BCQc=; b=MaDZlG7q5pbg3uQC5DOi18/DRTVkVxj9/GYqdKSoMtJEDc1cV/d0n78b84JgjbpdCm GPc+hRPYWe/OkfZXgZgplTWtqbQydwIWUk8/lPFZDkRkfMF00i3UNpE28jeckNQ/UBxX xHDPfLPrtuCKq4LTw8SuZ3ORO1dHsNmP/na1Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722872183; x=1723476983; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+MMMGxN2ape1bNpYFITLCt9gyz15hVErQ7V7ZB8BCQc=; b=h7xCqNdWNLHmZgbGEExv7aW09dwoPoHIJbWR7kTheRzOWbcCYB69h3PnqJFNQRqkfT YmZ5R/Sbn75IG9bttki/c6EbnScA0wXvSLZeclY3eGoVbpDBhWihkBDMGfo5mRmgiURv G2aJVIh2PkwLH6LRIezDzRsWpLXqYoWFMc2wPDFXGpVjVZpNmmlccbDH7yjD+ElMUKl8 DSDp9XHGNTvBNVykkHY4gZeYTEAS0JYk70ncRJd/HYRnmMad4Y/vXkZOMoLbMtPx/Gmn CL5RIXnCe0zJvd++vy2bGbnODXPSBO6bEP25NPCaVNFii+70kH/QI5gHDNOm/OfU9khe A/Vg== X-Gm-Message-State: AOJu0Yxx0tom3ZWpN/XZzvND+3EuMQAs6O7rqjE1y6rwPk8X3XLm14nW tc6qWlUIyvRS9GWPrMtAeG3sBgvX4hO/S3V/FKZPXWGiDVeSiIdAA+ndCk6tpuIm8LHOwJ/m43q H X-Google-Smtp-Source: AGHT+IEaxLbhD+/3nmdFqwJz0D5GFn1XhsnekeUBQTH+EmFNhLQROZ27ebimh8f7yKMhQgbpHmdkUw== X-Received: by 2002:a50:e602:0:b0:5a2:1b9d:1d3d with SMTP id 4fb4d7f45d1cf-5b7f5414380mr8359471a12.29.1722872182592; Mon, 05 Aug 2024 08:36:22 -0700 (PDT) From: Matthew Barnes To: Xen-devel Cc: Matthew Barnes , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [XEN PATCH] x86/emul: Fix misaligned IO breakpoint behaviour in PV guests Date: Mon, 5 Aug 2024 16:36:08 +0100 Message-Id: <88d0c78e7fecac79d4ef958962c59836c966cc91.1722871218.git.matthew.barnes@cloud.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Bcc: Matthew Barnes Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1722872210290116600 Content-Type: text/plain; charset="utf-8" When hardware breakpoints are configured on misaligned IO ports, the hardware will mask the addresses based on the breakpoint width during comparison. For PV guests, misaligned IO breakpoints do not behave the same way, and therefore yield different results. This patch tweaks the emulation of IO breakpoints for PV guests such that they reproduce the same behaviour as hardware. Signed-off-by: Matthew Barnes --- xen/arch/x86/pv/emul-priv-op.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c index f101510a1bab..02901a379b2a 100644 --- a/xen/arch/x86/pv/emul-priv-op.c +++ b/xen/arch/x86/pv/emul-priv-op.c @@ -324,7 +324,7 @@ static unsigned int check_guest_io_breakpoint(struct vc= pu *v, unsigned int len) { unsigned int width, i, match =3D 0; - unsigned long start; + unsigned long start, debug_mask; =20 if ( !v->arch.pv.dr7_emul || !(v->arch.pv.ctrlreg[4] & X86_CR4_DE) ) return 0; @@ -346,7 +346,9 @@ static unsigned int check_guest_io_breakpoint(struct vc= pu *v, case DR_LEN_8: width =3D 8; break; } =20 - if ( (start < (port + len)) && ((start + width) > port) ) + debug_mask =3D (~(width - 1u)); + + if ( ((start & debug_mask) < (port + len)) && (((start & debug_mas= k) + width) > port) ) match |=3D 1u << i; } =20 --=20 2.34.1