From nobody Fri May 17 08:39:14 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=1707221193; cv=none; d=zohomail.com; s=zohoarc; b=JY15U1JfZ4xVha5f+Wq17O1dvkHVPzzrgy2OYvFqFCw4cHIWhE62+cTDc4NaITALs3D6cPxEClDpBW3nBlB+hxk32LhSKTlgxLBiRI0067bzdNCKEjPGVay1h7BYQzqiaRWKtnX0htOBIY3vX/aBU3zpz3+e4AM9rri05Q7HEms= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1707221193; h=Content-Type: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=QO7nEsK9WdqbE5nV/bhuqZUjZzpr1P3VwDIWoHgSZCQ=; b=npNMMi2roo15gdHjlt9gTSYqkNoivOa5hLGtHq8HQjBzM8mT2P/8UiqzWodvfQ+GWNE3owPeNpNTw07LXj1ptjzkQyanJjdGNFOhPgrBqKkzqLc8WCY0cFeALfbY5ZNlxLll6OpNvjffiq2o4Er9WLu6XSop1fBDML0b5MKfUtc= 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 1707221193055535.4576589809024; Tue, 6 Feb 2024 04:06:33 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.676870.1053189 (Exim 4.92) (envelope-from ) id 1rXKDV-0007jy-6I; Tue, 06 Feb 2024 12:06:21 +0000 Received: by outflank-mailman (output) from mailman id 676870.1053189; Tue, 06 Feb 2024 12:06:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rXKDV-0007jr-2q; Tue, 06 Feb 2024 12:06:21 +0000 Received: by outflank-mailman (input) for mailman id 676870; Tue, 06 Feb 2024 12:06:20 +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 1rXKDU-0007ji-8o for xen-devel@lists.xenproject.org; Tue, 06 Feb 2024 12:06:20 +0000 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [2a00:1450:4864:20::433]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 223b6c45-c4e8-11ee-8a47-1f161083a0e0; Tue, 06 Feb 2024 13:06:18 +0100 (CET) Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-33b1d7f736bso3124846f8f.3 for ; Tue, 06 Feb 2024 04:06:18 -0800 (PST) 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 w17-20020a5d6811000000b0033afcc899c1sm1949748wru.13.2024.02.06.04.06.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 06 Feb 2024 04:06:17 -0800 (PST) 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: 223b6c45-c4e8-11ee-8a47-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1707221177; x=1707825977; darn=lists.xenproject.org; h=content-transfer-encoding:autocrypt:subject:from:cc:to :content-language:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=QO7nEsK9WdqbE5nV/bhuqZUjZzpr1P3VwDIWoHgSZCQ=; b=Kn1dNM82bq+hsNRFbX1G1ZQ7RIP12yWJyQO+5YEoStBpmehIKYARsWylpRBa41ykWU ddKjzJRrkdGVmbH6Syz8mN8/Q3zWFL4iIEdYqR6yXU2CiNFO/mmzZcU1JZvdUowO5HY6 dlYyypkD+Yv8MBisAeNLFCDUp6Py31FjiAJkA1uAwzsS7WywtFq1eSyzM4oZ6kamlFDx tuQLw3YWliF82lauZtHwn3GnZHcBCYOKr/3H0CcJb5ySv0rTAX+buz4gWsUhEYmTPFE1 MXhu1L0P+XJUcAFmvynVLQTD6EPS7gxEeMARARceryQ2J2QlRvgU4KHuzIbLZStLIc49 tBwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707221177; x=1707825977; h=content-transfer-encoding:autocrypt:subject:from:cc:to :content-language:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QO7nEsK9WdqbE5nV/bhuqZUjZzpr1P3VwDIWoHgSZCQ=; b=WsoPaDtsU8scjf2uf7atCSdXtjFSAHiOfeqtT2213GvtwrgcplFB0JvvAc3iMdjr/s r2O93QgZgnOPAOb5q/sd2iyHgIx2JuzRfZ0U7QK/JaWypk4cpzvqU4JTMXYmYOisBxse 6+qPuCmWsQ/PRp7JRqgc0kFjJReoLqrGjXZHCXemYTHJap6WiHg9NDlgpzaCmJwf1zMM 5n9DpJZEq9qS6fpebk0jm1GLlKAzVdQGdikS9uic/LUO/rPZt1qPz48CJh18Orx8ZRNK jn3hzZnNFiO7Znhatw496mtpv/UPENg+1m9wTJsc3MEuLLiEbIDpiBWWAnJrKOfSKjpF BLHg== X-Gm-Message-State: AOJu0YywpP8NtA5N+VfZoogDQC2btcXj65eGRei7pZeO7jkiDlsJkvFQ Dv1c2Ls1ceFY63UW2i6y99gBLDjdkDAwX2M2dc7F5QpRnOYXVcCRYaxoeZUkIaituoLWhHKS/J8 = X-Google-Smtp-Source: AGHT+IG67+2F1w5AhrZaA4fpFAV+ZWoU2Vs6fDG+S1kuGcd0rGh/P7cZDMYFO0apRdPhV+z0oP7wNA== X-Received: by 2002:a5d:4a85:0:b0:337:67e:a1ef with SMTP id o5-20020a5d4a85000000b00337067ea1efmr963429wrq.7.1707221177717; Tue, 06 Feb 2024 04:06:17 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCX/IYOHB6h//hf8a8dFuYOpxN2aQdMNxe6Svu9tx0jXgqXhGElNRm1QQPlhVc9TAtxTiA+fw7S+6hDdDi4ezsfDR21JNUirAZzWQh6aK1Sg50YQN+cJGiOprlbMY3sx2i1+kujDR5yD Message-ID: Date: Tue, 6 Feb 2024 13:06:16 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Wei Liu , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Manuel Andreas From: Jan Beulich Subject: [PATCH] x86/HVM: tidy state on hvmemul_map_linear_addr()'s error path Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drY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nB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1707221194711100001 Content-Type: text/plain; charset="utf-8" While in the vast majority of cases failure of the function will not be followed by re-invocation with the same emulation context, a few very specific insns - involving multiple independent writes, e.g. ENTER and PUSHA - exist where this can happen. Since failure of the function only signals to the caller that it ought to try an MMIO write instead, such failure also cannot be assumed to result in wholesale failure of emulation of the current insn. Instead we have to maintain internal state such that another invocation of the function with the same emulation context remains possible. To achieve that we need to reset MFN slots after putting page references on the error path. Note that all of this affects debugging code only, in causing an assertion to trigger (higher up in the function). There's otherwise no misbehavior - such a "leftover" slot would simply be overwritten by new contents in a release build. Also extend the related unmap() assertion, to further check for MFN 0. Fixes: 8cbd4fb0b7ea ("x86/hvm: implement hvmemul_write() using real mapping= s") Reported.by: Manuel Andreas Signed-off-by: Jan Beulich Acked-by: Paul Durrant --- While probably I could be convinced to omit the #ifndef, I'm really considering to extend the one in hvmemul_unmap_linear_addr(), to eliminate the zapping from release builds: Leaving MFN 0 in place is not much better than leaving a (presently) guest-owned one there. And we can't really put/leave INVALID_MFN there, as that would conflict with other debug checking. --- a/xen/arch/x86/hvm/emulate.c +++ b/xen/arch/x86/hvm/emulate.c @@ -696,7 +696,12 @@ static void *hvmemul_map_linear_addr( out: /* Drop all held references. */ while ( mfn-- > hvmemul_ctxt->mfn ) + { put_page(mfn_to_page(*mfn)); +#ifndef NDEBUG /* Clean slot for a subsequent map()'s error checking. */ + *mfn =3D _mfn(0); +#endif + } =20 return err; } @@ -718,7 +723,7 @@ static void hvmemul_unmap_linear_addr( =20 for ( i =3D 0; i < nr_frames; i++ ) { - ASSERT(mfn_valid(*mfn)); + ASSERT(mfn_x(*mfn) && mfn_valid(*mfn)); paging_mark_dirty(currd, *mfn); put_page(mfn_to_page(*mfn));