Received: by 2002:ab2:3b09:0:b0:1ed:14ea:9113 with SMTP id b9csp207799lqc; Thu, 29 Feb 2024 15:08:22 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVGkD4R96U/PizI5rcGAQM2ZqJ+7+RbbpZJmpJKPMTIr2R1jmI02hNHaomNRf3n8soXHVEQLyWTFiWFXPcg1riUYvu0c4tnPQzNNuYVog== X-Google-Smtp-Source: AGHT+IHT1PfsuGaXnGu5vgTrZgezvJ/N62yLdALC3vEyORewxw2hYhWYWP75Q9q8AwgSfcIjrHq+ X-Received: by 2002:ac2:539a:0:b0:513:1a44:61e2 with SMTP id g26-20020ac2539a000000b005131a4461e2mr25475lfh.10.1709248102232; Thu, 29 Feb 2024 15:08:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709248102; cv=pass; d=google.com; s=arc-20160816; b=sZlMwjyCUwGi8zZ4KWEYgawmVLAXBlpoSfU7gQnANN5eUISgeoH/iCCHU5WMeIlrHb Zk8JCM6hdY//of5I3JEOuhMHVlLSP0fxIP6xZhD92Vj2kuf5NRHNNg9YGbuUYK2FIH6A gI9i4uv6DGXUlibfzcQDVC8iDnUWRcUAs1tBFhCtOJwWF7lW1qqP4No+zCYokbnNouhS EU0p1WQ+vWhgw+xitFW707DExQrroeLr3bsw8lhTBg7h3p2Wel7FFBJ/8WxrnftdDwQj s/rzl3oCPA/rMtUZotMDD4npDjE6YKiC2ynFPSHbLzi/gvuMjIP1980VP5KJs0B9j1f0 6BOQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=tONzLipD7XoMDHe1nP9IUEdoxrUsyW7/+yWAsS/QFWs=; fh=6Fe5oUYhEvnKa4uPbRdvziZ0Rp6ZLlWv6no5N4QO1MQ=; b=ZI+ZZe1r5HeyaoGzqJv9C/gHlw6316PmVtAt59/FtZHJ00FSU/1CVWCBmMeL4aadOX V/h6NXPIENkPrtLOgNsPqAlUnY8BTnhGkc1Go1xuMl3kMmF/WXuIhY1ivJqRmI9PHzDi 00xXKt+WBjqpJPxfrGkzXc9456EDLkhYWh6+SKq0DiF032g7+9Om6x4B0gFh/kcDRruJ cmqEH3YXn2P0WV/tFUlL4jZ8GHKE448Z1/zk/vZSxdFHrIWTXgBZFVGdM4hJk9DAdaIZ IUgUcOtMGsXNlQ26iFJUECLqYzgVTkbg7V+vcVfKPABsG72SjaETTZw1j/u6hyzt4Ch/ t98g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=E0KGTJ8T; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-87665-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87665-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id eb14-20020a0564020d0e00b00564c7885268si955045edb.103.2024.02.29.15.08.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 15:08:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-87665-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=E0KGTJ8T; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-87665-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87665-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id C51541F23805 for ; Thu, 29 Feb 2024 23:08:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 007C97A15F; Thu, 29 Feb 2024 23:08:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="E0KGTJ8T" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 9C62816FF21 for ; Thu, 29 Feb 2024 23:08:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709248083; cv=none; b=YFMCWq1Z4if6WguKN3NE1+uG89dK1SrxYyFwzL1O0MvaGo0RjejqzM64QP0JePLxftBelJwpCEcl0BNeWeoJ6tR1pga7TseLiYX2f6EVJPtnlXfS6aKzKvBtcHBJ93dd5mF+jjkTpEAXWhVbrQJhdVg2SGh6cBC/dNFV/8M93Lk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709248083; c=relaxed/simple; bh=zJhWfx7GK1YysklElLdHCde42C/JNXRPYOyOMcUqrT4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Avwc1outHExQ7NnCnfMeVRlcKrj/ckIu7//JH9OlhWWPmpfRrSkZbF8ILdNoXpg7uzbk8j8xc214EQ8qI3JIAYrztCs0uXmGTrSN/+1ZJ65sMWWuubr/IDB0iMIkeTnSoMbgcmXySTWZtZ9Oetl6j89MQMFy9QqjKPuJR5x87mo= 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=E0KGTJ8T; arc=none smtp.client-ip=209.85.128.202 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 Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60942936e31so25903527b3.1 for ; Thu, 29 Feb 2024 15:08:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709248080; x=1709852880; 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=tONzLipD7XoMDHe1nP9IUEdoxrUsyW7/+yWAsS/QFWs=; b=E0KGTJ8TDUeJP1LUkVFUr2hHL1ecIukLv10FwScQBF1h8v+vP7uUwOQgGMT8Qd+Z9B z4prci/rHGC52jogvSK+CSZBTks/5/YDUKpjupifNURLdRID6aKMRwi3fYD8kvZfBTjX oyHD5h7oRY/oFkLF1T+8XtMfrgDKSGjO8dcMaFa4u93c867n/e48RgCQ7pT1FvKsTyCB +8c2Fc9va1/lPI/2KTj0oIaV/9L7w+aRvGrmMYW0vZq9NK4QWS/NLOX9SR6bXh60Khdq MbgZv3590P+l/dhylFDiMjihBsFoLpZoaePRoyuZ/w96vN3xx3sEgkMMHNYtCAcmYOB4 DbwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709248080; x=1709852880; 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=tONzLipD7XoMDHe1nP9IUEdoxrUsyW7/+yWAsS/QFWs=; b=pnaosgj1uQrq9edrjxf7ry0dY92N1cyj8sYAS+HijQ4RQzf6RRlwOViq+LYTb8lOjS awwnj6VTHwEMArejoddj2hz20ODNyZPBDBxHSu2/ox1NbUr+c7nkaOEtRCvC4yBHCV2u 8mcOcbXTHnKWb8vy6Ds25JzF78oLqk0YjZX1gIYTlQEdOuRzNegh2GxVt2Jk6nxSp6C/ raKzEqW++hSnUAWc+R7b5g7vwUrTDu7WKkDx47mVCT5DcmVZR8f6pznDx1prUkEI0eDq A1K6dB6XNDTEWL9aso5KxjHV1JSO0NUXSyBQY1ullJ+QwZuPeaySu+MqjxfU0/x9WxcY ZTtQ== X-Forwarded-Encrypted: i=1; AJvYcCXlfivcI0UZO1RMzNnD8jIv9LezeIDdZG2TbeSDHWs4ORTFa3MKxtGF0YcXKR5SSmMZv+7xkZoZ6c1xdxVYeI3Zobh5sMujpczo5z4t X-Gm-Message-State: AOJu0Ywd+ocu0EXR4yYaWLqgJ5F6Z4fqbR08XXyDdH5Lxf7uzP1A8e+m SJTLyYo8M4UauQkZa4HcgvO4FitfuqAICHfKKfhYwffqN1DvDd/BRVf9yJgr0qOmj2Z1M1WVstr ApQ== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a81:98cf:0:b0:609:2031:1e09 with SMTP id p198-20020a8198cf000000b0060920311e09mr124141ywg.6.1709248080639; Thu, 29 Feb 2024 15:08:00 -0800 (PST) Date: Thu, 29 Feb 2024 15:07:59 -0800 In-Reply-To: <3779953f-4d07-41d7-b450-bbc2afffaa43@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240228024147.41573-1-seanjc@google.com> <20240228024147.41573-7-seanjc@google.com> <3779953f-4d07-41d7-b450-bbc2afffaa43@intel.com> Message-ID: Subject: Re: [PATCH 06/16] KVM: x86/mmu: WARN if upper 32 bits of legacy #PF error code are non-zero From: Sean Christopherson To: Kai Huang Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yan Zhao , Isaku Yamahata , Michael Roth , Yu Zhang , Chao Peng , Fuad Tabba , David Matlack Content-Type: text/plain; charset="us-ascii" On Fri, Mar 01, 2024, Kai Huang wrote: > > > On 28/02/2024 3:41 pm, Sean Christopherson wrote: > > WARN if bits 63:32 are non-zero when handling an intercepted legacy #PF, > > I found "legacy #PF" is a little bit confusing but I couldn't figure out a > better name either :-) > > > as the error code for #PF is limited to 32 bits (and in practice, 16 bits > > on Intel CPUS). This behavior is architectural, is part of KVM's ABI > > (see kvm_vcpu_events.error_code), and is explicitly documented as being > > preserved for intecerpted #PF in both the APM: > > > > The error code saved in EXITINFO1 is the same as would be pushed onto > > the stack by a non-intercepted #PF exception in protected mode. > > > > and even more explicitly in the SDM as VMCS.VM_EXIT_INTR_ERROR_CODE is a > > 32-bit field. > > > > Simply drop the upper bits of hardware provides garbage, as spurious > > "of" -> "if" ? > > > information should do no harm (though in all likelihood hardware is buggy > > and the kernel is doomed). > > > > Handling all upper 32 bits in the #PF path will allow moving the sanity > > check on synthetic checks from kvm_mmu_page_fault() to npf_interception(), > > which in turn will allow deriving PFERR_PRIVATE_ACCESS from AMD's > > PFERR_GUEST_ENC_MASK without running afoul of the sanity check. > > > > Note, this also why Intel uses bit 15 for SGX (highest bit on Intel CPUs) > > "this" -> "this is" ? > > > and AMD uses bit 31 for RMP (highest bit on AMD CPUs); using the highest > > bit minimizes the probability of a collision with the "other" vendor, > > without needing to plumb more bits through microcode. > > > > Signed-off-by: Sean Christopherson > > --- > > arch/x86/kvm/mmu/mmu.c | 7 +++++++ > > 1 file changed, 7 insertions(+) > > > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > > index 7807bdcd87e8..5d892bd59c97 100644 > > --- a/arch/x86/kvm/mmu/mmu.c > > +++ b/arch/x86/kvm/mmu/mmu.c > > @@ -4553,6 +4553,13 @@ int kvm_handle_page_fault(struct kvm_vcpu *vcpu, u64 error_code, > > if (WARN_ON_ONCE(fault_address >> 32)) > > return -EFAULT; > > #endif > > + /* > > + * Legacy #PF exception only have a 32-bit error code. Simply drop the > > "have" -> "has" ? This one I'll fix by making "exception" plural. Thanks much for the reviews! > > > + * upper bits as KVM doesn't use them for #PF (because they are never > > + * set), and to ensure there are no collisions with KVM-defined bits. > > + */ > > + if (WARN_ON_ONCE(error_code >> 32)) > > + error_code = lower_32_bits(error_code); > > vcpu->arch.l1tf_flush_l1d = true; > > if (!flags) { > Reviewed-by: Kai Huang