From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.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 D178C38B131 for ; Mon, 15 Jun 2026 19:08:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781550525; cv=none; b=AMEI7elWgux1Dvr083qPHKveJZE06f0sR8f5WSAULqAy6KTjiObGPBMaAKLvgGaZXrwoXJDNOHy8oqJekWht4fV4vP9fxt8Wqz1Rwrjs/hZ2XQyV9ddnTYOAHaKqTY1FjeYbjD/8Ke3nrmVju+vCOq8MlFfvB3OOPkJM5qSgXFs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781550525; c=relaxed/simple; bh=xCjqAXLZY8rIMGbzZEEGmgRtoHf745poEoIsc8Gidac=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=oxtptsdMEWvpGHFh95CNbtKSLIdBg8GbpI/qgD0OuWNIkPXzefyIq8b9CbhxIognSFbNIxdkUzO8B0esZBobDappWPwfp3oUIynJCJ0Leiab88goZr5iDj7U6kkdavzkbOPeIEPhCqdtuiYM1himvG9vmQu6xm3UuJSOLD6GNBs= 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=QMCpDGR4; arc=none smtp.client-ip=209.85.210.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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QMCpDGR4" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-8425a9979e1so2449730b3a.2 for ; Mon, 15 Jun 2026 12:08:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1781550524; x=1782155324; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=APiDafiaML/mLGCJ3WCjYH//RgPqrmVNUKcSFkPFk/k=; b=QMCpDGR4LCYC2q3CSLYf6lzHj3VjUuK7JHq1oG5R4rBCBOmVu6MiqTd2Imn38AoZIt E5t+djZxmaycojd3GKo9JGVUva/I1YueJgy08OV42BC3gs6quA/2jbWO9/qE0IYfnSMs t3IXjepLFtFwUbg+NMuLgkIU3sp/M+g+eHGJ050Oylmn8ftw7FcvO95f72+da9ZW6YK+ bYOcfNK83biLf4P44mTp3khYvcQUxNO3zPkfw5fMf57bNIDJTgawSxwZ2p+X2alf0Olx dAexeamRdYmYc4zTAVHXtKK182rMKG7hFJ2qOL08HQc1wdzkBMnTyFYs0yTICqTE1tgX GG3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781550524; x=1782155324; h=content-transfer-encoding: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=APiDafiaML/mLGCJ3WCjYH//RgPqrmVNUKcSFkPFk/k=; b=NYzlQUdCkkAOAtbzUflziBSxe3GgIsrkDQBaKH+iq5HTOhuLKQZMf4KG0kqano6Z4G 1SnExDkfBBiahL7WSIaFObjZhGingmjdWPdYLbQDBDg6dR47I1pZDTa1ObRoXjNzodl7 TVtvO0CXOYZVqIvziuWqRjaYZVWDGuHK+5FUM5f1FuDLwjpToW70ldWYzbzy63iCJGOf CVBcybbSa6+Y1y1dGXNYr4D3gSV3Nt+LiEPWkAKPGp12dSMiJsl6EQrmpgvfmk/uIShq c73Lay8gfgzNJG7ZLJzWJtcAfOn17ZmWxQFReiAw9Wd/qk2YwiPgyXgU207Y4Eq0n/LU X/Nw== X-Forwarded-Encrypted: i=1; AFNElJ997r+GrfrfZ6H0BEwnrUaQ48u51fyyTC08xjKzzj2fyJFOVrx7Gflt9CCxQngog9C+o6ec4sammknHMk4=@vger.kernel.org X-Gm-Message-State: AOJu0YwpCcWQzJKXACJVGTdboZsZ64BkUKAmSZOxYVoTFt925vHAPugc D93LTI+lxGzaLHLSqDFU4jdy+EqTdWdyWAqXrGqAT25M5F8QJ4OSyaw98u5PyTVRLaNzTtWwU5z qpZxZIg== X-Received: from pfff14.prod.google.com ([2002:a05:6a00:bd0e:b0:842:3b07:6355]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:418c:b0:835:405a:7e6f with SMTP id d2e1a72fcca58-84515357f7emr204148b3a.14.1781550524032; Mon, 15 Jun 2026 12:08:44 -0700 (PDT) Date: Mon, 15 Jun 2026 12:08:43 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260612230113.684301-1-seanjc@google.com> <20260612230113.684301-8-seanjc@google.com> Message-ID: Subject: Re: [PATCH v3 7/8] KVM: x86: WARN if MOV DR emulation hits a "too late" #GP From: Sean Christopherson To: Jim Mattson Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, "Carlos =?utf-8?B?TMOzcGV6?=" , "Maciej W . Rozycki" Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Mon, Jun 15, 2026, Jim Mattson wrote: > On Fri, Jun 12, 2026 at 4:02=E2=80=AFPM Sean Christopherson wrote: > > > > WARN if ->set_dr() =3D> kvm_set_dr() fails when emulating a MOV DR writ= e, > > as the emulator _must_ pre-check for #GPs in order to get the event > > priority right when emulating MOV DR for L2 on SVM (all exceptions have > > higher priority than the instruction intercept). > > > > Opportunistically update the comment as the blurb about "#UD" being > > checked is incomplete and misleading. > > > > Signed-off-by: Sean Christopherson > > --- > > arch/x86/kvm/emulate.c | 8 ++++++-- > > 1 file changed, 6 insertions(+), 2 deletions(-) > > > > diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c > > index b1799ed01939..e030ef9b9744 100644 > > --- a/arch/x86/kvm/emulate.c > > +++ b/arch/x86/kvm/emulate.c > > @@ -3298,8 +3298,12 @@ static int em_dr_write(struct x86_emulate_ctxt *= ctxt) > > else > > val =3D ctxt->src.val & ~0U; > > > > - /* #UD condition is already handled. */ > > - if (ctxt->ops->set_dr(ctxt, ctxt->modrm_reg, val)) > > + /* > > + * A #GP due to an illegal value should be impossible at this p= oint, as > > + * such #GPs have priority over MOV DR intercepts on SVM, i.e. = KVM must > > + * manually check the value *before* emulating the write. > > + */ >=20 > This comment seems confusing to me. Isn't an illegal value impossible > simply because we already called check_dr_write()? Yeah. I'm trying to explain why KVM WARNs, and also to guard against dropp= ing the value checks in check_dr_write() as future "cleanups". Is this better? /* * Yell if the DR write is rejected, as all inputs have been validated. * KVM must manually check for exceptions *before* emulating the write, * as all exceptions have priority over MOV DR intercepts on SVM. */ > > + if (WARN_ON_ONCE(ctxt->ops->set_dr(ctxt, ctxt->modrm_reg, val))= ) > > return emulate_gp(ctxt, 0); > > > > /* Disable writeback. */ > > -- > > 2.54.0.1136.gdb2ca164c4-goog > > > >