From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.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 CF7D43B2FD5 for ; Thu, 12 Mar 2026 15:54:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773330882; cv=none; b=jM/C4/Jjq58cnIcGi/bxk2ZOD9/vs8TijwltTTR0afsBTygMGJ3wvw2xvJy0F1MAvLA6TXI3TXZUs/XJfuua/XvbU/sqM649OrBdKngm3gjoJrxaiTYaBOgvn4YEuHi8Bqf5SLuelC03DOazHFTBtHoOTuEjLufDKhWHX0uLsWU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773330882; c=relaxed/simple; bh=EzwWxXyr18y9/WLhPSXyVTO/E0MDxwC8co9A06bM940=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=P8+Pysj0SaOqJ51p0QbgLzXbnT0z5d5P2YHuSFCa8paI4W/nztVUUuodnSmb5XwKEF7S37WsfaJ4k5yawKY+dNyvE02vXkALMWEnrY91ugPiTRYzyD79Ad6yzV1guY4IxTC7cbC3tAKbEpH1V6CNvY8ZY/HWRq2TWGmVyQuv6YQ= 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=K2t3dcjN; arc=none smtp.client-ip=209.85.214.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="K2t3dcjN" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2aec6c572fbso24239615ad.1 for ; Thu, 12 Mar 2026 08:54:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1773330880; x=1773935680; 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=cgQPl3tY5OJK3ny0f4wh3X3LNjdt2+3T3Ndt2tt/3Dw=; b=K2t3dcjNV9nh1cZ8q89NK8K/49XhgMppIB2ImfDwn0GiaJlt6aIFU0kLIpqngQO/57 ycLMsXM5FFiH2Zt1XnmXzjPo3UbxpB7Y2/jOYjkaWZV/6hVaKqg6gEqsEpvDi7i6Zn6H raGC7Ttga8wWcYnNkPkpoTkOXaiQYeiQMTf7N6VgIRqlBWGdalk+nyVHLJrjUp7uvGf0 kyEK2rilxK+FqwsZ8x2zqflUV/ZBFEf/vj0Zh+1TYxMqRA3ybdhO4VtYyngte0AiEH5l yKELLy9T0Q09+qJw1Tvjntjbb9mXubQnld2vFKkZEEy2hiiYFjSQM1uXD9r5sRrLkwEz Ye8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773330880; x=1773935680; 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=cgQPl3tY5OJK3ny0f4wh3X3LNjdt2+3T3Ndt2tt/3Dw=; b=bM1Xp/mbxQguQudwlX8SjMSRawojW1w8SeTs3zysLYRLsMgnh9qELuVT1NIG3PyjT5 i0+sUYrNnYbLbRixIvPQ4F34rOzWmIyCbTxJ/+p2QPG3P8Mmxt+8mgKgNCECOP8l38DM zoHGU7Geb4wHMM+gpUarDXm+BmLy/3ucfyKjX5z/4qczITA6ishKS0BxawjV4twnWtx9 8dC+kElG9/ahw1oEsUC2Mok4dngK7WjtNJ5ZExFry2HnsPAw2hzLqFd8S8SyT4eN3GW2 QRkiLc1D62u2GyDhhvAGFymyFsJmgd5EhNwCP7qwjoPOnPMoSzaEx3GlbRXcNZ14m0IF aMAA== X-Forwarded-Encrypted: i=1; AJvYcCVnw5qwc2PrydudWr9BjRJiMPmnlhB64E9XFbCS3FeQEuZCbqKRoanmSjiNpv0zZOvNc5dmshOjKzvqhkA=@vger.kernel.org X-Gm-Message-State: AOJu0YyQbSvBq3QBBL14dQs1+3pRU1yrEc1vTgVWmcnDahCqgxrAoZQ1 +LvGW8iZs+GOgeULcZsb9eGBpMNZNccvIy9sF0k/5tHqeCSFIxYy5UI+mjORyz9qOCG5rZVdmGz o9xegJA== X-Received: from pgx11.prod.google.com ([2002:a63:174b:0:b0:c73:846d:a381]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:3984:b0:398:9ef1:fc5 with SMTP id adf61e73a8af0-398c5f3e1bfmr6183866637.25.1773330880020; Thu, 12 Mar 2026 08:54:40 -0700 (PDT) Date: Thu, 12 Mar 2026 08:54:38 -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: Message-ID: Subject: Re: [PATCH v2 1/6] KVM: SVM: Use maxphyaddr in emulator RAX check for VMRUN/VMLOAD/VMSAVE From: Sean Christopherson To: Yosry Ahmed Cc: Jim Mattson , Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="us-ascii" On Thu, Mar 12, 2026, Yosry Ahmed wrote: > > diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c > > index c8e292e9a24d..74df977a38ca 100644 > > --- a/arch/x86/kvm/emulate.c > > +++ b/arch/x86/kvm/emulate.c > > @@ -3867,18 +3867,10 @@ static int check_svme(struct x86_emulate_ctxt *ctxt) > > if (!(efer & EFER_SVME)) > > return emulate_ud(ctxt); > > > > - return X86EMUL_CONTINUE; > > -} > > - > > -static int check_svme_pa(struct x86_emulate_ctxt *ctxt) > > -{ > > - u64 rax = reg_read(ctxt, VCPU_REGS_RAX); > > - > > - /* Valid physical address? */ > > - if (rax & 0xffff000000000000ULL) > > + if (ctxt->ops->cpl(ctxt)) > > return emulate_gp(ctxt, 0); > > > > - return check_svme(ctxt); > > + return X86EMUL_CONTINUE; > > } > > > > static int check_rdtsc(struct x86_emulate_ctxt *ctxt) > > @@ -3984,10 +3976,10 @@ static const struct opcode group7_rm2[] = { > > }; > > > > static const struct opcode group7_rm3[] = { > > - DIP(SrcNone | Prot | Priv, vmrun, check_svme_pa), > > + DIP(SrcNone | Prot | Priv, vmrun, check_svme), > > II(SrcNone | Prot | EmulateOnUD, em_hypercall, vmmcall), > > - DIP(SrcNone | Prot | Priv, vmload, check_svme_pa), > > - DIP(SrcNone | Prot | Priv, vmsave, check_svme_pa), > > + DIP(SrcNone | Prot | Priv, vmload, check_svme), > > + DIP(SrcNone | Prot | Priv, vmsave, check_svme), > > DIP(SrcNone | Prot | Priv, stgi, check_svme), > > DIP(SrcNone | Prot | Priv, clgi, check_svme), > > DIP(SrcNone | Prot | Priv, skinit, check_svme), > > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > > index e6691c044913..e1223c07593b 100644 > > --- a/arch/x86/kvm/svm/svm.c > > +++ b/arch/x86/kvm/svm/svm.c > > @@ -2294,7 +2294,7 @@ static int gp_interception(struct kvm_vcpu *vcpu) > > EMULTYPE_VMWARE_GP | EMULTYPE_NO_DECODE); > > } else { > > /* All SVM instructions expect page aligned RAX */ > > - if (svm->vmcb->save.rax & ~PAGE_MASK) > > + if (!page_address_valid(vcpu, svm->vmcb->save.rax)) > > goto reinject; > > Final observation (hopefully), this check needs to be moved to the > VMRUN/VMLOAD/VMSAVE interception functions. Gah, yeah. I noticed that when initially typing up my response, but lost track of it when I got distracted by all the emulator crud. > As kvm_vcpu_map() failures will stop injecting #GP, we still need to handle > the case where allow_smaller_maxphyaddr is used and the GPA is illegal from > the vCPU's perspective but not the host. allow_smaller_maxphyaddr is irrelevant. My read of the APM is that the intercept has priority over the #GP due to a bad RAX. So with vls=0, KVM needs to check RAX irrespective of allow_smaller_maxphyaddr.