From nobody Sun Nov 10 01:30:35 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1727772523; cv=none; d=zohomail.com; s=zohoarc; b=YS4gRT1VjdZpDcOOhQavDIHdiMLz5GrTQesVbkoBrZ00FTCtX8Wq7YUQhdnA9yRYc9iD/PTaGMGYSnpt9E2sc1LGSo35fYdytT+24LulX2CGr/VtnsPp8IFvs7WIjX1+EgTdYtsY/7LYFAnlVWWDR7XierAYWo4HA/rVuM69ZjA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727772523; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=JsdkVH+X0fQ3rqwF8jUU29eSJxEXcZhVYOG6vCFDcVQ=; b=Gva/vxeP95DmwU0NCfqUXI9pFjqQ/GqYOnmMv+SaYc7UO9OlOM7WxDT3iGtC+BgeJBDbWWbu4ij0gb7vFrGtiPXWQX95Kcw5ndBykoJ0Vy47knI59N2VWdnmUuqUoBYtYJkySZCi2rhFBRwzeZCAv1Op9KrGUZbX2fbA6j/VBUA= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1727772523950132.94919498566185; Tue, 1 Oct 2024 01:48:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.807825.1219498 (Exim 4.92) (envelope-from ) id 1svYYS-0005Z4-Lk; Tue, 01 Oct 2024 08:48:24 +0000 Received: by outflank-mailman (output) from mailman id 807825.1219498; Tue, 01 Oct 2024 08:48:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1svYYS-0005Yx-HS; Tue, 01 Oct 2024 08:48:24 +0000 Received: by outflank-mailman (input) for mailman id 807825; Tue, 01 Oct 2024 08:48:23 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1svYYR-0005SS-AU for xen-devel@lists.xenproject.org; Tue, 01 Oct 2024 08:48:23 +0000 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [2a00:1450:4864:20::22e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e9ac109a-7fd1-11ef-99a2-01e77a169b0f; Tue, 01 Oct 2024 10:48:21 +0200 (CEST) Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2facf481587so17435401fa.1 for ; Tue, 01 Oct 2024 01:48:21 -0700 (PDT) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c88245e9a9sm5725263a12.45.2024.10.01.01.48.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Oct 2024 01:48:20 -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: e9ac109a-7fd1-11ef-99a2-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1727772501; x=1728377301; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=JsdkVH+X0fQ3rqwF8jUU29eSJxEXcZhVYOG6vCFDcVQ=; b=H7zTi2EG24CyP4nES8R2CQYbNevenAxRFdWLwyJyqKNov0duQwdM0dNKzFwynyFet/ OXw1lIviDgLAE1oOZHMP8qU8l/GS8uTxDbD1MwA6ZhEmgrbzOAnZCTM0+oNUjTNLCda8 pxpgh9nuNTNs2KDhuZURQY+yS+cr/Vxk6gGrY49ADMUNGhREazv7IHDBBdVaLGsnGluz qSmqtYm9lTdd3KnxyuOrBa5TATDmH0aPNEsdSuYU78ZNd7/85k1Q4S4pRnlTR0fUk4El w4mJgZe/CdVvFeCGJ60FuhrJTC/nv6jD5DqG0wD3nna9nV+iu9iKS0okBykZPagQjpGN /qPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727772501; x=1728377301; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JsdkVH+X0fQ3rqwF8jUU29eSJxEXcZhVYOG6vCFDcVQ=; b=TtVybr2juXmkMroH0kL7ZkJf9t18Bxy7sUBrYdUTqp+XnKdsFGN32Q8sotNyqVEGjt FLWP473LjG08xWTMjmF3g53dydMGQBv1SwSObLbEp+x710lOsBLrXsuTj0XAJGx/dF30 zf+lBYkKeSJlR/kLFufw4jPWynfPVUx7hcw3lKskeDgKR2CbgAXN7d/TuwAmLr2E0DSa k7gp2hyZYmnT8ZtTrOxPlEJUd1/ZHRT3+9+znaighreGyIebnZt/hhUTca/eTyWNGJig ddpI9V2P07HEWCZe6VDuLscaLdkwczRxKlw0VB7YxYxX2r7CKk+Xd10hjD4nRJMrU6fE 7iHg== X-Gm-Message-State: AOJu0Yz1ExfKpRHBgyLcgF4RyyqMgSVbVZHgQ5Rr5ZiUrx0lRQlSEi/e Y3QRTk8Oa++bLM9mC6UhyI4NVLkCdW1HG26c+JTO6OLWoOjCDyY5lg2T7js/DfKng+WUFodtgys = X-Google-Smtp-Source: AGHT+IGanKpX2xFoj2bmLlkMMYkH3lGBJI+CvYWvEEARMiaH8VhUZE63n7rEvefc4wnlZsd4hjBUmA== X-Received: by 2002:a2e:4e11:0:b0:2f3:f7cf:2f01 with SMTP id 38308e7fff4ca-2f9d419888fmr60033161fa.41.1727772501003; Tue, 01 Oct 2024 01:48:21 -0700 (PDT) Message-ID: Date: Tue, 1 Oct 2024 10:48:20 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 1/5] x86/HVM: correct MMIO emulation cache bounds check From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= References: <3294f629-f91f-4b5d-9eb0-40a34aa2ec3e@suse.com> Content-Language: en-US Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <3294f629-f91f-4b5d-9eb0-40a34aa2ec3e@suse.com> Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1727772526450116600 Content-Type: text/plain; charset="utf-8" To avoid overrunning the internal buffer we need to take the offset into the buffer into account. Fixes: d95da91fb497 ("x86/HVM: grow MMIO cache data size to 64 bytes") Signed-off-by: Jan Beulich --- v2: New. --- a/xen/arch/x86/hvm/emulate.c +++ b/xen/arch/x86/hvm/emulate.c @@ -935,7 +935,7 @@ static int hvmemul_phys_mmio_access( } =20 /* Accesses must not overflow the cache's buffer. */ - if ( size > sizeof(cache->buffer) ) + if ( offset + size > sizeof(cache->buffer) ) { ASSERT_UNREACHABLE(); return X86EMUL_UNHANDLEABLE; From nobody Sun Nov 10 01:30:35 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1727772570; cv=none; d=zohomail.com; s=zohoarc; b=OtutWQb2bEtbkJgnkgenB1LS4aEI+a59sincOyzDXH41qL0GujT0cIJLxNIthRdzxra75Eo+5V3nK06Z25GWEHbnREnQgJtb8T6oSNCa20eXRT2FdGV+QNcWOVGlLr59bXz0QdERve9VfJyQxWw6Qj4uJXn5gybZx5BLdh1cPJQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727772570; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3YQovV+n3e2iZoKriHprGKyGT3fX/RYDEQo1G3heG+M=; b=dGbUSmDHVzaGSRWYjH/Zz6sVPRhnn5uCYP68c5FqO5TPVJJzRYeXzYAiXzMSOiD/knMB5gl3oGqUNwSzoyFYwMyfgL9ZfXtZDWVXKMi3ZCL3rDwRoB7AR7nnJzvdrAuepWTsNC0hWB9eaIy7VbEgQLMckS+2WYmJ2bYlZIPgtqc= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1727772570721435.7175891681118; Tue, 1 Oct 2024 01:49:30 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.807830.1219507 (Exim 4.92) (envelope-from ) id 1svYZF-00068y-0l; Tue, 01 Oct 2024 08:49:13 +0000 Received: by outflank-mailman (output) from mailman id 807830.1219507; Tue, 01 Oct 2024 08:49:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1svYZE-00068r-UI; Tue, 01 Oct 2024 08:49:12 +0000 Received: by outflank-mailman (input) for mailman id 807830; Tue, 01 Oct 2024 08:49:12 +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 1svYZE-0005xu-GF for xen-devel@lists.xenproject.org; Tue, 01 Oct 2024 08:49:12 +0000 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [2a00:1450:4864:20::634]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 077e39b4-7fd2-11ef-a0ba-8be0dac302b0; Tue, 01 Oct 2024 10:49:11 +0200 (CEST) Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-a8d43657255so2723566b.0 for ; Tue, 01 Oct 2024 01:49:11 -0700 (PDT) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c297bceesm667113466b.187.2024.10.01.01.49.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Oct 2024 01:49:10 -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: 077e39b4-7fd2-11ef-a0ba-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1727772551; x=1728377351; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=3YQovV+n3e2iZoKriHprGKyGT3fX/RYDEQo1G3heG+M=; b=VeICNJFLWJRLDHSf8G3YvQabsiASW8ilGMieXUgts7KZyQL/YOk3HP0TTHHQqZVCLX 7QPnh8ISgCP/rPM+IOxO9/QbZLy2EA7MGNZ2FVcDIx9bQjpZdXYtmI/BXqfKDv1Clu/k hE8ugXBIt78pg5DiGXh3kwm+NiS1EtCGedVOCgDUWgBKIfrDmPw77WyfRpLxjRkIgl6Y 5ejehbmdmgYZPduMM5TYYlK3g+fFHoCsarhtyUVdibeTmo0JIiQckBp8BzIH5gcjeWzB z2UxIsYMqT/qA3TFUTi5RWXggPVNd4ef8b9nltmOFWDP6ITNxjHVo2jZsFsTS1O9dT+1 LfkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727772551; x=1728377351; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3YQovV+n3e2iZoKriHprGKyGT3fX/RYDEQo1G3heG+M=; b=FnambsO4GkDfGId3FE868L8IMetrIdfLy0ED8YSN4Yszyuie335P/HWIth5r13CjYG 51GQEYWmzzSzZtYheStplHO85TTli5VcoJd+uokFIyFGYdHlw7xebAAeGszcmT99P+g8 PJY8zJxCd0LJmzwd3bPB6on8MEHs8kPELA9rGDNcAUfxHR44Lu7af1wrMPBDWNvQZ1N8 pHFvl9lPEOo02nFukbZvUjkuvQi3T2Nl55YAlc0g6RRJv7ZIv/Js5pXQJIl5DKPiP4Yp q6ixdJcYrdgoUcTBahu90uMeuB1yYuto5oATeCygQWz0ftqEEiWi3URVOv7cGkX2yyPD eOWQ== X-Gm-Message-State: AOJu0Yzdp1OsK58fUIaKeJfcKy1YUvwtR9/EUlPCLmmiRU5paJVS5Pvy msPN6Ah+fa2orUmXR/ed1s6kjvSTvpDH0hZaT5ToPPzmWIFB70wv6dBK9o86FY1b9dRrUAepmHA = X-Google-Smtp-Source: AGHT+IGyNaxk4OM2kTSilCgOMgWlxucjmHDanSRs6cLmLVChamA1zxHSl//IbDUHLBjvrDA7Miy/Dw== X-Received: by 2002:a17:907:3e86:b0:a90:d1e1:eeb3 with SMTP id a640c23a62f3a-a93c4a60d33mr1767106666b.44.1727772551088; Tue, 01 Oct 2024 01:49:11 -0700 (PDT) Message-ID: <93967ab8-a472-475a-bdd6-41dfc3afa895@suse.com> Date: Tue, 1 Oct 2024 10:49:10 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 2/5] x86/HVM: allocate emulation cache entries dynamically From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= References: <3294f629-f91f-4b5d-9eb0-40a34aa2ec3e@suse.com> Content-Language: en-US Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <3294f629-f91f-4b5d-9eb0-40a34aa2ec3e@suse.com> Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1727772572315116600 Content-Type: text/plain; charset="utf-8" Both caches may need higher capacity, and the upper bound will need to be determined dynamically based on CPUID policy (for AMX'es TILELOAD / TILESTORE at least). Signed-off-by: Jan Beulich --- This is a patch taken from the AMX series, but wasn't part of the v3 submission. All I did is strip out the actual AMX bits (from hvmemul_cache_init()), plus of course change the description. As a result some local variables there may look unnecessary, but this way it's going to be less churn when the AMX bits are added. The next patch pretty strongly depends on the changed approach (contextually, not so much functionally), and I'd really like to avoid rebasing that one ahead of this one, and then this one on top of that. TBD: For AMX hvmemul_cache_init() will become CPUID policy dependent. We could of course take the opportunity and also reduce overhead when AVX-512 (and maybe even AVX) is unavailable (in the future: to the guest). --- v2: Split off cache bounds check fix. --- a/xen/arch/x86/hvm/emulate.c +++ b/xen/arch/x86/hvm/emulate.c @@ -26,6 +26,18 @@ #include #include =20 +/* + * We may read or write up to m512 or up to a tile row as a number of + * device-model transactions. + */ +struct hvm_mmio_cache { + unsigned long gla; + unsigned int size; + unsigned int space:31; + unsigned int dir:1; + uint8_t buffer[] __aligned(sizeof(long)); +}; + struct hvmemul_cache { /* The cache is disabled as long as num_ents > max_ents. */ @@ -935,7 +947,7 @@ static int hvmemul_phys_mmio_access( } =20 /* Accesses must not overflow the cache's buffer. */ - if ( offset + size > sizeof(cache->buffer) ) + if ( offset + size > cache->space ) { ASSERT_UNREACHABLE(); return X86EMUL_UNHANDLEABLE; @@ -1011,7 +1023,7 @@ static struct hvm_mmio_cache *hvmemul_fi =20 for ( i =3D 0; i < hvio->mmio_cache_count; i ++ ) { - cache =3D &hvio->mmio_cache[i]; + cache =3D hvio->mmio_cache[i]; =20 if ( gla =3D=3D cache->gla && dir =3D=3D cache->dir ) @@ -1027,10 +1039,11 @@ static struct hvm_mmio_cache *hvmemul_fi =20 ++hvio->mmio_cache_count; =20 - cache =3D &hvio->mmio_cache[i]; - memset(cache, 0, sizeof (*cache)); + cache =3D hvio->mmio_cache[i]; + memset(cache->buffer, 0, cache->space); =20 cache->gla =3D gla; + cache->size =3D 0; cache->dir =3D dir; =20 return cache; @@ -2978,16 +2991,21 @@ void hvm_dump_emulation_state(const char int hvmemul_cache_init(struct vcpu *v) { /* - * No insn can access more than 16 independent linear addresses (AVX51= 2F - * scatters/gathers being the worst). Each such linear range can span a - * page boundary, i.e. may require two page walks. Account for each in= sn - * byte individually, for simplicity. + * AVX512F scatter/gather insns can access up to 16 independent linear + * addresses, up to 8 bytes size. Each such linear range can span a pa= ge + * boundary, i.e. may require two page walks. + */ + unsigned int nents =3D 16 * 2 * (CONFIG_PAGING_LEVELS + 1); + unsigned int i, max_bytes =3D 64; + struct hvmemul_cache *cache; + + /* + * Account for each insn byte individually, both for simplicity and to + * leave some slack space. */ - const unsigned int nents =3D (CONFIG_PAGING_LEVELS + 1) * - (MAX_INST_LEN + 16 * 2); - struct hvmemul_cache *cache =3D xmalloc_flex_struct(struct hvmemul_cac= he, - ents, nents); + nents +=3D MAX_INST_LEN * (CONFIG_PAGING_LEVELS + 1); =20 + cache =3D xvmalloc_flex_struct(struct hvmemul_cache, ents, nents); if ( !cache ) return -ENOMEM; =20 @@ -2997,6 +3015,15 @@ int hvmemul_cache_init(struct vcpu *v) =20 v->arch.hvm.hvm_io.cache =3D cache; =20 + for ( i =3D 0; i < ARRAY_SIZE(v->arch.hvm.hvm_io.mmio_cache); ++i ) + { + v->arch.hvm.hvm_io.mmio_cache[i] =3D + xmalloc_flex_struct(struct hvm_mmio_cache, buffer, max_bytes); + if ( !v->arch.hvm.hvm_io.mmio_cache[i] ) + return -ENOMEM; + v->arch.hvm.hvm_io.mmio_cache[i]->space =3D max_bytes; + } + return 0; } =20 --- a/xen/arch/x86/include/asm/hvm/emulate.h +++ b/xen/arch/x86/include/asm/hvm/emulate.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include =20 @@ -119,7 +120,11 @@ int hvmemul_do_pio_buffer(uint16_t port, int __must_check hvmemul_cache_init(struct vcpu *v); static inline void hvmemul_cache_destroy(struct vcpu *v) { - XFREE(v->arch.hvm.hvm_io.cache); + unsigned int i; + + for ( i =3D 0; i < ARRAY_SIZE(v->arch.hvm.hvm_io.mmio_cache); ++i ) + XFREE(v->arch.hvm.hvm_io.mmio_cache[i]); + XVFREE(v->arch.hvm.hvm_io.cache); } bool hvmemul_read_cache(const struct vcpu *v, paddr_t gpa, void *buffer, unsigned int size); --- a/xen/arch/x86/include/asm/hvm/vcpu.h +++ b/xen/arch/x86/include/asm/hvm/vcpu.h @@ -22,17 +22,6 @@ struct hvm_vcpu_asid { uint32_t asid; }; =20 -/* - * We may read or write up to m512 as a number of device-model - * transactions. - */ -struct hvm_mmio_cache { - unsigned long gla; - unsigned int size; - uint8_t dir; - uint8_t buffer[64] __aligned(sizeof(long)); -}; - struct hvm_vcpu_io { /* * HVM emulation: @@ -48,7 +37,7 @@ struct hvm_vcpu_io { * We may need to handle up to 3 distinct memory accesses per * instruction. */ - struct hvm_mmio_cache mmio_cache[3]; + struct hvm_mmio_cache *mmio_cache[3]; unsigned int mmio_cache_count; =20 /* For retries we shouldn't re-fetch the instruction. */ From nobody Sun Nov 10 01:30:35 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1727772601; cv=none; d=zohomail.com; s=zohoarc; b=AhUeL1l2giq8cTD3pETWeSg/zQR/9is49ggDvUplnWEx7Ma8I6CBwM5UBrjFoniahbCOsz0dPON8DI+y85PO1PR9ab+vSEmSLp9VnUSjkLKzbhdf6x9t1gG1jYunv5ddPYfJaGAyx2gjDDdPqMQwF7feCM3/ku+qQuekH+CMuDQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727772601; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5sy4Y2cQJ7dlapUfnU+5xbF/96+httzMJp8tshXNPzQ=; b=ZK80tr9JlJltoYrf8O5It1ZJlgm9S3wADLPmlBltP/33yfYQ/TXHMLlF8Kz4gGzjdqFEQRtzYMTPEyV+K1W+ilTifG4dYHCTxCus03nssf8YA/+RlkuEJOjtSgVDwzUr64E3GIp/JkgLj8gkMZnzd7Q+RXGv54FPGV6e0rdxKmE= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1727772601625955.2099996338048; Tue, 1 Oct 2024 01:50:01 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.807835.1219516 (Exim 4.92) (envelope-from ) id 1svYZl-0006e3-9N; Tue, 01 Oct 2024 08:49:45 +0000 Received: by outflank-mailman (output) from mailman id 807835.1219516; Tue, 01 Oct 2024 08:49:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1svYZl-0006dw-6k; Tue, 01 Oct 2024 08:49:45 +0000 Received: by outflank-mailman (input) for mailman id 807835; Tue, 01 Oct 2024 08:49:43 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1svYZj-0006bI-OX for xen-devel@lists.xenproject.org; Tue, 01 Oct 2024 08:49:43 +0000 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [2a00:1450:4864:20::533]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 197e047e-7fd2-11ef-99a2-01e77a169b0f; Tue, 01 Oct 2024 10:49:42 +0200 (CEST) Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-5c8967dd2c7so2508712a12.1 for ; Tue, 01 Oct 2024 01:49:42 -0700 (PDT) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c882405127sm5817163a12.5.2024.10.01.01.49.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Oct 2024 01:49:40 -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: 197e047e-7fd2-11ef-99a2-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1727772581; x=1728377381; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=5sy4Y2cQJ7dlapUfnU+5xbF/96+httzMJp8tshXNPzQ=; b=Bqp6OcdzGw4arrgufQrkve60975UYBeamfSyt9Xx3lH0HdGS6+5MjPXeBBREOgv8gP T/CEKMLLwgu/c07ecPAcgZZkwzTW2pR4QosveJCjD0IHFUredHEVGHrLCv2tAzjS49Lp IUbgxKetT6ilaUSBRSuLhoJsyNyxM9zIg0EXreZnXPyMSlph/Hbd01/CIOtPrGDfCy5D vYPgdHOIw5m6rUG9iPVvKh89BZnIGm8HL2RChGpi6Zg6vuLzGeB6o2Dt23sNvq4gbqeO KVeoeVzdOVulBPEZPPRdRL1EKrE7O3EyKuqX3XurXI53AsCBqWE6GXc2lIg2VNUghhLe zLDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727772581; x=1728377381; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5sy4Y2cQJ7dlapUfnU+5xbF/96+httzMJp8tshXNPzQ=; b=tWv+/QJg5Vn/OYhvjacZHenh6hgFe3kMVBw2CoDEvPk1c6/lJLhOPw5OOZeLqbHWPZ 7sWKrlniLbbT56VswlNMD6sfMN7VNzlExFRX2KgRxXxpX7FTtoQgmnUQkNKDlvhIJn4e BsIRzbzN3j17I8HdWPsYcLJYtIQ+NY2ye+T2zO0aZgvw/y3IQzOk/JzFO3xdGw33lzXY jU480hVbFykgES45rUS6S5N5JieWLaN9ZeFrJ4W9Xg25HXbAWWgBTD1SVcWpMH55BcZV wrDsnA9WaiLLOCP11WxpWrmlFxi1rPBxAJ0Skzdd8mUYgOMQiJ++jREdhywdXOJfNanD nIkA== X-Gm-Message-State: AOJu0YwvnlkcLgkAdEo1RGILyG1InESU3a/5YhvZk+1PF04yZlxQna2O rbyqa4TFFiXvcdoNIOHtZD1X1g4MiL4Otjejp1D5sHtMFOsOlJAIo4eW5OpcQtMAmsa6On4cPMo = X-Google-Smtp-Source: AGHT+IGQPlGi3cNhIbxFtM3X3YFSx+ml3Hlc8kElg5Kvq4VXtnFPQLN5L2zIQlBR/8DKM+2HiKHXOQ== X-Received: by 2002:a05:6402:1ecf:b0:5c8:7a90:6a71 with SMTP id 4fb4d7f45d1cf-5c8824d4d54mr13893482a12.13.1727772581331; Tue, 01 Oct 2024 01:49:41 -0700 (PDT) Message-ID: Date: Tue, 1 Oct 2024 10:49:40 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 3/5] x86/HVM: correct read/write split at page boundaries From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Manuel Andreas References: <3294f629-f91f-4b5d-9eb0-40a34aa2ec3e@suse.com> Content-Language: en-US Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <3294f629-f91f-4b5d-9eb0-40a34aa2ec3e@suse.com> Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1727772602484116600 Content-Type: text/plain; charset="utf-8" The MMIO cache is intended to have one entry used per independent memory access that an insn does. This, in particular, is supposed to be ignoring any page boundary crossing. Therefore when looking up a cache entry, the access'es starting (linear) address is relevant, not the one possibly advanced past a page boundary. In order for the same offset-into-buffer variable to be usable in hvmemul_phys_mmio_access() for both the caller's buffer and the cache entry's it is further necessary to have the un-adjusted caller buffer passed into there. Fixes: 2d527ba310dc ("x86/hvm: split all linear reads and writes at page bo= undary") Reported-by: Manuel Andreas Signed-off-by: Jan Beulich --- This way problematic overlaps are only reduced (to ones starting at the same address), not eliminated: Assumptions in hvmemul_phys_mmio_access() go further - if a subsequent access is larger than an earlier one, but the splitting results in a chunk to cross the end "boundary" of the earlier access, an assertion will still trigger. Explicit memory accesses (ones encoded in an insn by explicit or implicit memory operands) match the assumption afaict (i.e. all those accesses are of uniform size, and hence they either fully overlap or are mapped to distinct cache entries). Insns accessing descriptor tables, otoh, don't fulfill these expectations: The selector read (if coming from memory) will always be smaller than the descriptor being read, and if both (insanely) start at the same linear address (in turn mapping MMIO), said assertion will kick in. (The same would be true for an insn trying to access itself as data, as long as certain size "restrictions" between insn and memory operand are met. Except that linear_read() disallows insn fetches from MMIO.) To deal with such, I expect we will need to further qualify (tag) cache entries, such that reads/writes won't use insn fetch entries, and implicit-supervisor-mode accesses won't use entries of ordinary accesses. (Page table accesses don't need considering here for now, as our page walking code demands page tables to be mappable, implying they're in guest RAM; such accesses also don't take the path here.) Thoughts anyone, before I get to making another patch? Considering the insn fetch aspect mentioned above I'm having trouble following why the cache has 3 entries. With insn fetches permitted, descriptor table accesses where the accessed bit needs setting may also fail because of that limited capacity of the cache, due to the way the accesses are done. The read and write (cmpxchg) are independent accesses from the cache's perspective, and hence we'd need another entry there. If, otoh, the 3 entries are there to account for precisely this (which seems unlikely with commit e101123463d2 ["x86/hvm: track large memory mapped accesses by buffer offset"] not saying anything at all), then we should be fine in this regard. If we were to permit insn fetches, which way to overcome this (possibly by allowing the write to re-use the earlier read's entry in this special situation) would remain to be determined. --- a/xen/arch/x86/hvm/emulate.c +++ b/xen/arch/x86/hvm/emulate.c @@ -31,8 +31,9 @@ * device-model transactions. */ struct hvm_mmio_cache { - unsigned long gla; - unsigned int size; + unsigned long gla; /* Start of original access (e.g. insn operand)= */ + unsigned int skip; /* Offset to start of MMIO */ + unsigned int size; /* Populated space, including @skip */ unsigned int space:31; unsigned int dir:1; uint8_t buffer[] __aligned(sizeof(long)); @@ -953,6 +954,13 @@ static int hvmemul_phys_mmio_access( return X86EMUL_UNHANDLEABLE; } =20 + /* Accesses must not be to the unused leading space. */ + if ( offset < cache->skip ) + { + ASSERT_UNREACHABLE(); + return X86EMUL_UNHANDLEABLE; + } + /* * hvmemul_do_io() cannot handle non-power-of-2 accesses or * accesses larger than sizeof(long), so choose the highest power @@ -1010,13 +1018,15 @@ static int hvmemul_phys_mmio_access( =20 /* * Multi-cycle MMIO handling is based upon the assumption that emulation - * of the same instruction will not access the same MMIO region more - * than once. Hence we can deal with re-emulation (for secondary or - * subsequent cycles) by looking up the result or previous I/O in a - * cache indexed by linear MMIO address. + * of the same instruction will not access the exact same MMIO region + * more than once in exactly the same way (if it does, the accesses will + * be "folded"). Hence we can deal with re-emulation (for secondary or + * subsequent cycles) by looking up the result of previous I/O in a cache + * indexed by linear address and access type. */ static struct hvm_mmio_cache *hvmemul_find_mmio_cache( - struct hvm_vcpu_io *hvio, unsigned long gla, uint8_t dir, bool create) + struct hvm_vcpu_io *hvio, unsigned long gla, uint8_t dir, + unsigned int skip) { unsigned int i; struct hvm_mmio_cache *cache; @@ -1030,7 +1040,11 @@ static struct hvm_mmio_cache *hvmemul_fi return cache; } =20 - if ( !create ) + /* + * Bail if a new entry shouldn't be allocated, utilizing that ->space = has + * the same value for all entries. + */ + if ( skip >=3D hvio->mmio_cache[0]->space ) return NULL; =20 i =3D hvio->mmio_cache_count; @@ -1043,7 +1057,8 @@ static struct hvm_mmio_cache *hvmemul_fi memset(cache->buffer, 0, cache->space); =20 cache->gla =3D gla; - cache->size =3D 0; + cache->skip =3D skip; + cache->size =3D skip; cache->dir =3D dir; =20 return cache; @@ -1064,12 +1079,14 @@ static void latch_linear_to_phys(struct =20 static int hvmemul_linear_mmio_access( unsigned long gla, unsigned int size, uint8_t dir, void *buffer, - uint32_t pfec, struct hvm_emulate_ctxt *hvmemul_ctxt, bool known_gpfn) + uint32_t pfec, struct hvm_emulate_ctxt *hvmemul_ctxt, + unsigned long start, bool known_gpfn) { struct hvm_vcpu_io *hvio =3D ¤t->arch.hvm.hvm_io; unsigned long offset =3D gla & ~PAGE_MASK; - struct hvm_mmio_cache *cache =3D hvmemul_find_mmio_cache(hvio, gla, di= r, true); - unsigned int chunk, buffer_offset =3D 0; + unsigned int chunk, buffer_offset =3D gla - start; + struct hvm_mmio_cache *cache =3D hvmemul_find_mmio_cache(hvio, start, = dir, + buffer_offset); paddr_t gpa; unsigned long one_rep =3D 1; int rc; @@ -1117,19 +1134,19 @@ static int hvmemul_linear_mmio_access( static inline int hvmemul_linear_mmio_read( unsigned long gla, unsigned int size, void *buffer, uint32_t pfec, struct hvm_emulate_ctxt *hvmemul_ctxt, - bool translate) + unsigned long start, bool translate) { return hvmemul_linear_mmio_access(gla, size, IOREQ_READ, buffer, - pfec, hvmemul_ctxt, translate); + pfec, hvmemul_ctxt, start, translate= ); } =20 static inline int hvmemul_linear_mmio_write( unsigned long gla, unsigned int size, void *buffer, uint32_t pfec, struct hvm_emulate_ctxt *hvmemul_ctxt, - bool translate) + unsigned long start, bool translate) { return hvmemul_linear_mmio_access(gla, size, IOREQ_WRITE, buffer, - pfec, hvmemul_ctxt, translate); + pfec, hvmemul_ctxt, start, translate= ); } =20 static bool known_gla(unsigned long addr, unsigned int bytes, uint32_t pfe= c) @@ -1158,7 +1175,10 @@ static int linear_read(unsigned long add { pagefault_info_t pfinfo; struct hvm_vcpu_io *hvio =3D ¤t->arch.hvm.hvm_io; + void *buffer =3D p_data; + unsigned long start =3D addr; unsigned int offset =3D addr & ~PAGE_MASK; + const struct hvm_mmio_cache *cache; int rc; =20 if ( offset + bytes > PAGE_SIZE ) @@ -1182,8 +1202,17 @@ static int linear_read(unsigned long add * an access that was previously handled as MMIO. Thus it is imperativ= e that * we handle this access in the same way to guarantee completion and h= ence * clean up any interim state. + * + * Care must be taken, however, to correctly deal with crossing RAM/MM= IO or + * MMIO/RAM boundaries. While we want to use a single cache entry (tag= ged + * by the starting linear address), we need to continue issuing (i.e. = also + * upon replay) the RAM access for anything that's ahead of or past MM= IO, + * i.e. in RAM. */ - if ( !hvmemul_find_mmio_cache(hvio, addr, IOREQ_READ, false) ) + cache =3D hvmemul_find_mmio_cache(hvio, start, IOREQ_READ, ~0); + if ( !cache || + addr + bytes <=3D start + cache->skip || + addr >=3D start + cache->size ) rc =3D hvm_copy_from_guest_linear(p_data, addr, bytes, pfec, &pfin= fo); =20 switch ( rc ) @@ -1199,8 +1228,8 @@ static int linear_read(unsigned long add if ( pfec & PFEC_insn_fetch ) return X86EMUL_UNHANDLEABLE; =20 - return hvmemul_linear_mmio_read(addr, bytes, p_data, pfec, - hvmemul_ctxt, + return hvmemul_linear_mmio_read(addr, bytes, buffer, pfec, + hvmemul_ctxt, start, known_gla(addr, bytes, pfec)); =20 case HVMTRANS_gfn_paged_out: @@ -1217,7 +1246,10 @@ static int linear_write(unsigned long ad { pagefault_info_t pfinfo; struct hvm_vcpu_io *hvio =3D ¤t->arch.hvm.hvm_io; + void *buffer =3D p_data; + unsigned long start =3D addr; unsigned int offset =3D addr & ~PAGE_MASK; + const struct hvm_mmio_cache *cache; int rc; =20 if ( offset + bytes > PAGE_SIZE ) @@ -1236,13 +1268,11 @@ static int linear_write(unsigned long ad =20 rc =3D HVMTRANS_bad_gfn_to_mfn; =20 - /* - * If there is an MMIO cache entry for the access then we must be re-i= ssuing - * an access that was previously handled as MMIO. Thus it is imperativ= e that - * we handle this access in the same way to guarantee completion and h= ence - * clean up any interim state. - */ - if ( !hvmemul_find_mmio_cache(hvio, addr, IOREQ_WRITE, false) ) + /* See commentary in linear_read(). */ + cache =3D hvmemul_find_mmio_cache(hvio, start, IOREQ_WRITE, ~0); + if ( !cache || + addr + bytes <=3D start + cache->skip || + addr >=3D start + cache->size ) rc =3D hvm_copy_to_guest_linear(addr, p_data, bytes, pfec, &pfinfo= ); =20 switch ( rc ) @@ -1255,8 +1285,8 @@ static int linear_write(unsigned long ad return X86EMUL_EXCEPTION; =20 case HVMTRANS_bad_gfn_to_mfn: - return hvmemul_linear_mmio_write(addr, bytes, p_data, pfec, - hvmemul_ctxt, + return hvmemul_linear_mmio_write(addr, bytes, buffer, pfec, + hvmemul_ctxt, start, known_gla(addr, bytes, pfec)); =20 case HVMTRANS_gfn_paged_out: @@ -1643,7 +1673,7 @@ static int cf_check hvmemul_cmpxchg( { /* Fix this in case the guest is really relying on r-m-w atomicity= . */ return hvmemul_linear_mmio_write(addr, bytes, p_new, pfec, - hvmemul_ctxt, + hvmemul_ctxt, addr, hvio->mmio_access.write_access && hvio->mmio_gla =3D=3D (addr & PAG= E_MASK)); } From nobody Sun Nov 10 01:30:35 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1727772621; cv=none; d=zohomail.com; s=zohoarc; b=IbQIapvy+PwiZ0F6jUUiu2gkz4eJ5e8e5rcAp2hDWhM7STSlCbtBd4sQYLKmGPIRu8LY62S/Z/X8H1KpKQMmfZyhntCLZCD6zDmoLlhSVyhM/mGsQn2vtdNmaYBXLjTeDCZNmo6BeeIZM7TcaT524sTlfASKCzAFqATtMDyN5yQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727772621; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=GkPtOo84ZGrBaC3bJPX3VZcUrguvma+CLYeb6XeRzK8=; b=XZygP7q4iAMfY61AuaM7CNYRxsLNjmSGBxbkjAM2uun2KaPShWQ3Rpmib5mPQWC2bOxfbKeL513/Iz5ltKyNhBbYI1yiBIlBiCKelalPODAkBsYnsAmZwFVXsSr2UPzHxYo3WgWT1WDB1T36SxS/6pTaXLSfRMK+wJgyh/gZ2OU= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1727772621728141.95889819545812; Tue, 1 Oct 2024 01:50:21 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.807837.1219527 (Exim 4.92) (envelope-from ) id 1svYa5-0007iO-J8; Tue, 01 Oct 2024 08:50:05 +0000 Received: by outflank-mailman (output) from mailman id 807837.1219527; Tue, 01 Oct 2024 08:50:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1svYa5-0007hw-Ez; Tue, 01 Oct 2024 08:50:05 +0000 Received: by outflank-mailman (input) for mailman id 807837; Tue, 01 Oct 2024 08:50:03 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1svYa3-0006bI-RB for xen-devel@lists.xenproject.org; Tue, 01 Oct 2024 08:50:03 +0000 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [2a00:1450:4864:20::631]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2594c7fa-7fd2-11ef-99a2-01e77a169b0f; Tue, 01 Oct 2024 10:50:02 +0200 (CEST) Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-a8a897bd4f1so793412066b.3 for ; Tue, 01 Oct 2024 01:50:02 -0700 (PDT) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c2947fbesm670219666b.128.2024.10.01.01.50.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Oct 2024 01:50:01 -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: 2594c7fa-7fd2-11ef-99a2-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1727772602; x=1728377402; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=GkPtOo84ZGrBaC3bJPX3VZcUrguvma+CLYeb6XeRzK8=; b=dv1cfrWlDJoUIYzZwiHYlkC12QAv2G45xytWcLc6+x0XrMjvhLy1CHVc7+dw76dREe 2IHbLNUuPRBydlhOudebG9DiYiaZlVKREiukR96J+BjvxuuIevrypqK/hX4FfCL0u3ep jrILkBUkw1ZDDVec2AlP+sq4/YYhS9kDAcL2abbOjXDkZb1VwFyvnayUVZfWcnezVO8L IH1t5p8Jm1ViH9jyQzE362fLTTHkGc8VKvHifmJViEwXuPgXMbSWMUakznIRiZGFkLSF Ki3X9x8b+R/fnisInAOtOCDFstfxJwwARaYieCa+CYQrzgRmzNuoP2wSV1WIftSqFC3l JYng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727772602; x=1728377402; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=GkPtOo84ZGrBaC3bJPX3VZcUrguvma+CLYeb6XeRzK8=; b=DT5pvxlaPakwbfnWx+Tm+rGJoD0eqN81k7Z+7CV+LEs/vIh2tJXxSnJEKzZ6+GSIBo 4qDSsKeEuCqIN8dvmkgW58dQYyCtziTVKXFEHMkGudHzQJfhS/ibnrkcJ8O/BBp/0Dzw nb5u7O0s2YIM+g8/TtIcRCj7Wp5M3ou7G0rGdeBZ2JddaFPV72GCuQEhsrFnA2r4vAQf L53jH+vgOX+WfVaBUyagSO36+fzl48kNapaC4fq+OTkRUBR15mQ0UcdcjC7RO46Q9738 XInSde3bQ0fUrv5fgCseRjlEjVMZx+RAF5ILE9OFQlQQOAOgEyLl5xyGWz+hgsHvH6RA G95g== X-Gm-Message-State: AOJu0YwOAj9Y0SyvmwCbWcOgJlDyHRJrVGRFi1LxYLVLlV6hSsPZLijO fyb/tdXhlOCFbobaJSOnDmzPqdKobJ+G9FnYsXdPTlD3sCPexB7/R3473v6LAPg/spT0/PHlvms = X-Google-Smtp-Source: AGHT+IHYhewCLx3i4KL7jhtK7CRblhqhwGSI+ZXE8ao/Mp72DnePL2E5exZZNGhbYERJUCgWbYAlnA== X-Received: by 2002:a17:906:dc92:b0:a86:8b7b:7880 with SMTP id a640c23a62f3a-a93c4aab863mr1531947766b.63.1727772601745; Tue, 01 Oct 2024 01:50:01 -0700 (PDT) Message-ID: <3cfb6c97-26c4-4914-ac3c-2c0f39e8659e@suse.com> Date: Tue, 1 Oct 2024 10:50:01 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 4/5] x86/HVM: slightly improve CMPXCHG16B emulation From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= References: <3294f629-f91f-4b5d-9eb0-40a34aa2ec3e@suse.com> Content-Language: en-US Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <3294f629-f91f-4b5d-9eb0-40a34aa2ec3e@suse.com> Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1727772622483116600 Content-Type: text/plain; charset="utf-8" Using hvmemul_linear_mmio_write() directly (as fallback when mapping the memory operand isn't possible) won't work properly when the access crosses a RAM/MMIO boundary. Use linear_write() instead, which splits at such boundaries as necessary. Signed-off-by: Jan Beulich Acked-by: Andrew Cooper --- a/xen/arch/x86/hvm/emulate.c +++ b/xen/arch/x86/hvm/emulate.c @@ -1645,10 +1645,8 @@ static int cf_check hvmemul_cmpxchg( { struct hvm_emulate_ctxt *hvmemul_ctxt =3D container_of(ctxt, struct hvm_emulate_ctxt, ctxt); - struct vcpu *curr =3D current; unsigned long addr; uint32_t pfec =3D PFEC_page_present | PFEC_write_access; - struct hvm_vcpu_io *hvio =3D &curr->arch.hvm.hvm_io; int rc; void *mapping =3D NULL; =20 @@ -1672,10 +1670,7 @@ static int cf_check hvmemul_cmpxchg( if ( !mapping ) { /* Fix this in case the guest is really relying on r-m-w atomicity= . */ - return hvmemul_linear_mmio_write(addr, bytes, p_new, pfec, - hvmemul_ctxt, addr, - hvio->mmio_access.write_access && - hvio->mmio_gla =3D=3D (addr & PAG= E_MASK)); + return linear_write(addr, bytes, p_new, pfec, hvmemul_ctxt); } =20 switch ( bytes ) From nobody Sun Nov 10 01:30:35 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1727772645; cv=none; d=zohomail.com; s=zohoarc; b=J8Wb5ms3XHjabTtF5Rcpuc9lCJjbBbJwExGThLoBqKBQk6gqfFqV9dCqxG6H9KbyCL9wUY9u9311xJUpyXNLK3IU0kGW3bznvEbaNkUA6wb3witL824DLbb2t+GzMPL3K+yzKPgKL8fzBxp106Ihw8sDa3q8n6n+9vceY0YE9vg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727772645; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=LME1v2y5K47DGz0uUCZNveBYET3FXFVivr3ZLArlZP4=; b=LYqvBpNUmiSjXWYrl4AJ8OouiAhAwi9DBJDuDKosUDVQ/YXySe2PMzjFXQPlkzt097/d4Kk3dF4yuCL5m28Eg6NfQ4L4V4s6y6bappxMTA1Mcao/XInbOp7i8TPSwv7sk8irhZAZvu/HvdlffuTPkri9HUdd39B6axiglFbp7Zo= 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=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1727772645183791.4412894106927; Tue, 1 Oct 2024 01:50:45 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.807843.1219537 (Exim 4.92) (envelope-from ) id 1svYaT-00007p-UR; Tue, 01 Oct 2024 08:50:29 +0000 Received: by outflank-mailman (output) from mailman id 807843.1219537; Tue, 01 Oct 2024 08:50:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1svYaT-00007i-RW; Tue, 01 Oct 2024 08:50:29 +0000 Received: by outflank-mailman (input) for mailman id 807843; Tue, 01 Oct 2024 08:50:27 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1svYaR-0006bI-SH for xen-devel@lists.xenproject.org; Tue, 01 Oct 2024 08:50:27 +0000 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [2a00:1450:4864:20::632]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 33e95ba1-7fd2-11ef-99a2-01e77a169b0f; Tue, 01 Oct 2024 10:50:26 +0200 (CEST) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-a8d60e23b33so785864566b.0 for ; Tue, 01 Oct 2024 01:50:26 -0700 (PDT) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c2775b3csm668996866b.27.2024.10.01.01.50.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Oct 2024 01:50:25 -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: 33e95ba1-7fd2-11ef-99a2-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1727772626; x=1728377426; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=LME1v2y5K47DGz0uUCZNveBYET3FXFVivr3ZLArlZP4=; b=TkOrNyykSRdOgaoDKVVAjI61rudCr4SdDLjU29ABOjfMkkuRGqjSdyccxAO7cdBNcP gY4wFdU39114owEj+nd3gXmr2dnAXz0dlldyGmq/FK13DzAme0rdWe5MK1D0jYgSd1eK r6UdkPbu8JJvVKWV0F2cASdTQkBsz9D9YWQufsTrXC7BErJtiv4crqcmRdpIk0vcWF21 pPy5NPrtAzwQU6HIidXHJWUk3PAmfOqzVyGfijq2aKqq4TXrh+Yo2d8mjg1ohLo75gIm SnZV6G88HHnRI9hlNyyzpNkx9Rtf+51IuMT6hk4Mjuxef7bZg1m5JA4oYaEQVFIXXM3o xc4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727772626; x=1728377426; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=LME1v2y5K47DGz0uUCZNveBYET3FXFVivr3ZLArlZP4=; b=B8Zi6S5Sqa9PLMj0s6p843pBLozjc6pHs5I/q1UuGlxdAzbNUrxf3Y+gRJgFVRe27u Oq3ll2wUX6EnavvVmMnhBV78NA1qoUAN2MHAffpWr1enF0kezM5TgdIcO0UG+y40eUrW fMrbaHB8X1QJ/9O3rNiiXD8CWorv8WOhkdHtKo2WAUoVsdIHdXYunXJfm3cmf9GvX5Cp i+h2iWwBZiFtfMDJHghGUDzwgp2qaXt4VXupjlQxS52BHzzpa5r40GwH0DYCMPhVV4i2 OvSglkdz4Tt4LmKk1bFAEV0n4f4jjFjzPWVUF2VhaGhDOIOerSY19w1NgDC/ZKsj07Xj lObA== X-Gm-Message-State: AOJu0Yy8ipGaOgCflMniQS++RcjDJ6J1SP7dmfclFhGTuCClBct1aSPR m1v6+D6Uo7xfmlAR/lwVpBGOuxpUAKKf6OoK5GwKIhMwmoGURz+yB8HsMatsGIbXY6iUFp4uHq0 = X-Google-Smtp-Source: AGHT+IGRvliJJXGYn8enUcuI2BUAJAWEKNN1SLxvmIKQ4ZJBZ8WCEKTZ8tZ54H0cF+46lkmtTHWbww== X-Received: by 2002:a17:907:2cc5:b0:a86:a1cd:5a8c with SMTP id a640c23a62f3a-a93c49218b7mr1624745366b.22.1727772625801; Tue, 01 Oct 2024 01:50:25 -0700 (PDT) Message-ID: <7d73f0c5-3d16-4cf3-b8de-e45f539e8916@suse.com> Date: Tue, 1 Oct 2024 10:50:25 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 5/5] x86/HVM: drop redundant access splitting From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= References: <3294f629-f91f-4b5d-9eb0-40a34aa2ec3e@suse.com> Content-Language: en-US Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <3294f629-f91f-4b5d-9eb0-40a34aa2ec3e@suse.com> Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1727772646588116600 Content-Type: text/plain; charset="utf-8" With all paths into hvmemul_linear_mmio_access() coming through linear_{read,write}(), there's no need anymore to split accesses at page boundaries there. Leave an assertion, though. Signed-off-by: Jan Beulich --- v2: Replace ASSERT() by more safe construct. --- a/xen/arch/x86/hvm/emulate.c +++ b/xen/arch/x86/hvm/emulate.c @@ -1084,7 +1084,7 @@ static int hvmemul_linear_mmio_access( { struct hvm_vcpu_io *hvio =3D ¤t->arch.hvm.hvm_io; unsigned long offset =3D gla & ~PAGE_MASK; - unsigned int chunk, buffer_offset =3D gla - start; + unsigned int buffer_offset =3D gla - start; struct hvm_mmio_cache *cache =3D hvmemul_find_mmio_cache(hvio, start, = dir, buffer_offset); paddr_t gpa; @@ -1094,13 +1094,17 @@ static int hvmemul_linear_mmio_access( if ( cache =3D=3D NULL ) return X86EMUL_UNHANDLEABLE; =20 - chunk =3D min_t(unsigned int, size, PAGE_SIZE - offset); + if ( size > PAGE_SIZE - offset ) + { + ASSERT_UNREACHABLE(); + return X86EMUL_UNHANDLEABLE; + } =20 if ( known_gpfn ) gpa =3D pfn_to_paddr(hvio->mmio_gpfn) | offset; else { - rc =3D hvmemul_linear_to_phys(gla, &gpa, chunk, &one_rep, pfec, + rc =3D hvmemul_linear_to_phys(gla, &gpa, size, &one_rep, pfec, hvmemul_ctxt); if ( rc !=3D X86EMUL_OKAY ) return rc; @@ -1108,27 +1112,8 @@ static int hvmemul_linear_mmio_access( latch_linear_to_phys(hvio, gla, gpa, dir =3D=3D IOREQ_WRITE); } =20 - for ( ;; ) - { - rc =3D hvmemul_phys_mmio_access(cache, gpa, chunk, dir, buffer, bu= ffer_offset); - if ( rc !=3D X86EMUL_OKAY ) - break; - - gla +=3D chunk; - buffer_offset +=3D chunk; - size -=3D chunk; - - if ( size =3D=3D 0 ) - break; - - chunk =3D min_t(unsigned int, size, PAGE_SIZE); - rc =3D hvmemul_linear_to_phys(gla, &gpa, chunk, &one_rep, pfec, - hvmemul_ctxt); - if ( rc !=3D X86EMUL_OKAY ) - return rc; - } - - return rc; + return hvmemul_phys_mmio_access(cache, gpa, size, dir, buffer, + buffer_offset); } =20 static inline int hvmemul_linear_mmio_read(