From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7FD291547FE for ; Wed, 18 Dec 2024 18:39:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734547154; cv=none; b=PhMn/xk5zSlyYtbhb7GHT2c9SYJ5GtL4DbGR+aBiPD/ldH2/MgMj5gm5K1IVsIfPKYt2pcH30R7iXJAH8Lun///mCp8Q4d50dHDWS7PC1pbvX+h8p9ElMDhhil7F/Vvp6VbDgw3qsddgbl0/9otqDJfGK00SmUw8DDjNt3wfgeM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734547154; c=relaxed/simple; bh=54aEEBZXu5l8G8dSNrScl0HgsJCU88tBZMrBdnnGc+M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Vk0kAPvM+vnwzWd9B3Mu822qQZ4W5aLADBVZWpEo/u5pdIxjXF02lXIp1Fp1IZ7j/HvEs9LZ/fS+dHZ/bIrwrJtEYRsa7oZJcgRBucOPu8KaPPGI8fLCW1j2gbsu9CUGtNClHi6nsxAkAF9N5RRCDVSIr+A9zlmiru+rhHkwyr0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=JGjqn4li; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="JGjqn4li" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2eedd15c29eso6025304a91.3 for ; Wed, 18 Dec 2024 10:39:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734547153; x=1735151953; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ThSbZiShkgu5e03SVywCH9ZkF+kD7172meNNyMCsukQ=; b=JGjqn4lizOb4Okc/2AXyWxF/IDjq5ZRuWbQCp2V/hbWGyRm64wbnTGPdsCJ9dXkwDA UzyBEKNMiUlD9LJlnQdYyBkTmnrJ4EgZBKDsQ0BusZB0OUX+F5VXtggo/y3e7Nz7CId5 kDFlBjJUjzEd+TfIi7O/s33BbKyBPKhkHpwE/QvctS5uri5FW5a+lj/0BRKa5RhNFBW6 KwJ7ha0CPaNtDWEeXNDQjJLGyl/usiPpqRVQpnprnVFESThLvKIPAH5kumXpobkkv5jM /nBWLqaLsLv1rebskGlQxAmI0ZJFHGZr64sF65n/dfXjzDoNP1HLYKgeKn9tn7xIDMV8 zOOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734547153; x=1735151953; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ThSbZiShkgu5e03SVywCH9ZkF+kD7172meNNyMCsukQ=; b=nMgw8B54L4ipp+uTI8YM3KFsoMc8PRh/drcssPrBSrboqPnGyCKxN9Pc0tAMPZwE7J UGPZU0/oMvWANuGBNUbbwKYEpy3d9QXLBK82M9A8edfbyYfErwBIgxGB+V8+DrtVJxAZ LWMjuHxJPgDZQbBcSbEofjogSLE6jNmLqbBQArm+27ksNNSFIseAvLas6OEwmxJ32tXY QZf5l8aE9LHQzSJtHhYkkuJXcc5o5QxAtXDYv+ZoPR2ZA/jGxnAXCROoWsb7x0QNDMC/ wjGMD97IxM4IK1XP9/kQXZHPG0XQloZJMWQfb1XK+wVF652KItWz3M920F+XOBC6S90y wCBQ== X-Forwarded-Encrypted: i=1; AJvYcCVc12Fk8xIkg+7/Ebixn7hWZzWKfo2ZksW1p0NHjKObRhTgxSNx/wPtIxiWhhXBzST42/CogK/bxYDOpbo=@vger.kernel.org X-Gm-Message-State: AOJu0YwIgeVF42GoLqIl/T7fXEIC2PFN7F6vXqcvDl+c2bJ8p9iMrQnT +TyiAj6d6V2g0dlYllKRSWpW2d4KKm6dbmEXvPuLcvZCUs21WppuKBX9Y4b9YC2Ikv4fLINnr8h Gzw== X-Google-Smtp-Source: AGHT+IGexWYaZ1SI4kjhNWXK7opgvllRMgRXEQRWmGX9yzNrM6pDTH6/xNiTrW2iL7iCndhz2fxMorhYmOU= X-Received: from pjuw4.prod.google.com ([2002:a17:90a:d604:b0:2da:5868:311c]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:270a:b0:2f2:a664:df33 with SMTP id 98e67ed59e1d1-2f2e91ad917mr5094136a91.1.1734547152868; Wed, 18 Dec 2024 10:39:12 -0800 (PST) Date: Wed, 18 Dec 2024 10:39:11 -0800 In-Reply-To: <20241217181458.68690-5-iorlov@amazon.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241217181458.68690-1-iorlov@amazon.com> <20241217181458.68690-5-iorlov@amazon.com> Message-ID: Subject: Re: [PATCH v3 4/7] KVM: VMX: Handle vectoring error in check_emulate_instruction From: Sean Christopherson To: Ivan Orlov Cc: bp@alien8.de, dave.hansen@linux.intel.com, mingo@redhat.com, pbonzini@redhat.com, shuah@kernel.org, tglx@linutronix.de, hpa@zytor.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, x86@kernel.org, dwmw@amazon.co.uk, pdurrant@amazon.co.uk, jalliste@amazon.co.uk Content-Type: text/plain; charset="us-ascii" On Tue, Dec 17, 2024, Ivan Orlov wrote: > Move unhandleable vmexit during vectoring error detection > into check_emulate_instruction. Implement the function which prohibits > the emulation if EMULTYPE_PF is set when vectoring, otherwise such a > situation may occur: I definitely think it's worth explaining that moving the detection covers new emulation cases, and also calling out that handle_ept_misconfig() consults vmx_check_emulate_instruction(), i.e. that moving the detection shouldn't affect KVM's overall handlng of EPT Misconfig. -- Move handling of emulation during event vectoring, which KVM doesn't support, into VMX's check_emulate_instruction(), so that KVM detects all unsupported emulation, not just cached emulated MMIO (EPT misconfig). E.g. on emulated MMIO that isn't cached (EPT Violation) or occurs with legacy shadow paging (#PF). Rejecting emulation on other sources of emulation also fixes a largely theoretical flaw (thanks to the "unprotect and retry" logic), where KVM could incorrectly inject a #DF: 1. CPU executes an instruction and hits a #GP 2. While vectoring the #GP, a shadow #PF occurs 3. On the #PF VM-Exit, KVM re-injects #GP 4. KVM emulates because of the write-protected page 5. KVM "successfully" emulates and also detects the #GP 6. KVM synthesizes a #GP, and since #GP has already been injected, incorrectly escalates to a #DF. Fix the comment about EMULTYPE_PF as this flag doesn't necessarily mean MMIO anymore: it can also be set due to the write protection violation. Note, handle_ept_misconfig() checks vmx_check_emulate_instruction() before attempting emulation of any kind.