From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) (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 4DBAA3C3F55 for ; Wed, 26 Aug 2026 23:39:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787787569; cv=none; b=WnuSxMcLQBk2X/268NWqpOH+Z9X6Mk+pJUZusaW39y7gbYFsM0mLj2aNzptJxDxiltg9Zv7WuKrKEcBtmjjmQB27bRFSNrTzMmePJ6PnvjvJqZilDZ1IotpNBDaFBhpEFDDXEDrpIFV+AkaM+2tKyC7nT5zX4ag94tX9S8lnedA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787787569; c=relaxed/simple; bh=T2cASy/A5gmcwzlkeCr8k/+0qt1+e/cVRhWTFQSgJ94=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=B47FMXFf+4J72Jh6amrsUXWGvMhLsibiy9+8Lff9+9cWdK8xrPbJ6OrLp4q33tNazVmH4YFzJnIvtqjTOMVRAbxLl+0ljBmF/VHOzfzW/I3HfKaA0jv/I3JbdOHyd19DOU5Zrp7v2OLrvMBdly/rJz3+rU+dG+x2GIMjItxw7Og= 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=JsovOSfR; arc=none smtp.client-ip=209.85.210.199 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="JsovOSfR" Received: by mail-pf1-f199.google.com with SMTP id d2e1a72fcca58-84e048a801dso2205025b3a.3 for ; Wed, 26 Aug 2026 16:39:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1787787565; x=1788392365; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:reply-to:from:to:cc:subject:date:message-id :reply-to:content-type; bh=AWa0fIdmVto+y2WP+GJGN8aDkmGU1CjNONs+72349AE=; b=JsovOSfRR6SVRX/2WRCMEBCk/mIAPIGH88bjX2Fmpan13tEZGMDAGKCOeCYkTOT6Mz VqBLUxkHDwgD0mjRK2Swwlts+yr8EUqRJVrPrcG9PPyX2ZznrgeyjXEe/5PS83Kmi5yV K5oAILCwxoW+EIG0n4EC7+5q/8OOuptXEjJlhlxpKRAm3rojRfpUP6Yj42PkVenw2fT/ 8e7e4rEfFvGQStrFbWcbkDvqoy3MqkQBZNPALb4bEgaW+uC61BHavO7/V5QtjWCV/51J yI9vnOsyM7e8dI+lhP2ez9qESbZ42U4trfdCa+L6V/F0uyb9LRJY3sKFPIJeFdqfw54b 1yWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787787565; x=1788392365; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:reply-to:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=AWa0fIdmVto+y2WP+GJGN8aDkmGU1CjNONs+72349AE=; b=Qt2xP2hsHWJEE3Ih8jKenagNxlIAiipxedfGuH8y8Dtq4WUYFHfiDhGHAnxDnqLp20 N3hu9n1OCrNufLdvoRACJNDhn5nw7OtEk43VGB11L5tg+WO+eUbBQ4jFSMjq2fLHp9yf jePvYxbl2NyPkFNykGTQf1iBgs7mKeY3QfrzRognEY8cMliitgk9aJ5VPKmsm0dstPhF +eD9tbRnwn+RXDgWNpMYhEv/hy+R4jwJR/6waVE1nFHUbcSjuPVmHrCwijwRE6RvJ07N OO5ZP76qrU5WpcrgdXJRdsxUv8W7LK7GKx5RI2XcbIi/iBSRNvTohAODxDpVMzF0VpA2 w3fQ== X-Forwarded-Encrypted: i=1; AHgh+RpRga1uQtvwaFg616Su62Rim/LjCNWCIr851/iS7JWa60XNxjCJTU8F2WawTEqQeNEau1pRY++nHbCXmmg=@vger.kernel.org X-Gm-Message-State: AFuF++kxImK7MH+RhBUozJQSw/ixeC8XDyMYp1CqSewNCYtTP7ao5Czb diWNeCwRuKM/35qm2xw7PeHUUpEMOtB9mFPqDhz9wQE0GtNpwhjx2kDz+YYeJGWW+K5VajfJXyz vpnICVQ== X-Received: from pgkp18.prod.google.com ([2002:a63:f452:0:b0:c92:11a5:bbce]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:2da3:b0:84f:5cd7:e3c6 with SMTP id d2e1a72fcca58-853721a6aecmr16693779b3a.5.1787787564303; Wed, 26 Aug 2026 16:39:24 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 26 Aug 2026 16:39:09 -0700 In-Reply-To: <20260826233919.998904-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260826233919.998904-1-seanjc@google.com> X-Mailer: git-send-email 2.55.0.887.g758fc8c411-goog Message-ID: <20260826233919.998904-4-seanjc@google.com> Subject: [PATCH v3 03/13] KVM: selftests: Don't clobber RFLAGS in happy path of __KVM_ASM_SAFE() From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, f734222792@gmail.com, Vitaly Kuznetsov , Sashiko Bot , Yosry Ahmed Content-Type: text/plain; charset="UTF-8" Use a straight MOV instead of an XOR to zero R9 in the non-faulting path of __KVM_ASM_SAFE() so as not to clobber RFLAGS. XOR generates smaller code, but optimizing performance by minimizing the code footprint is just about the last thing that KVM selftests care about. The bug is relatively benign in the current code base, e.g. it marginally degrades the coverage in the fastops test, but otherwise does no harm. But the bug will become actively problematic if/when the "safe assembly" macros are used for instructions that communicate results via RFLAGS, e.g. for VMX instructions, which signal failure via RFLAGS.CF and RFLAGS.ZF. Opportunistically use R9D instead of the full R9, as bits 63:32 of GPRs are zeroed on writes to bit 31:0. Reported-by: Sashiko Bot Closes: https://lore.kernel.org/all/20260818165258.2613603-5-vkuznets@redhat.com Cc: Vitaly Kuznetsov Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/include/x86/processor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/include/x86/processor.h b/tools/testing/selftests/kvm/include/x86/processor.h index 6e6f70035508..282b8aaff799 100644 --- a/tools/testing/selftests/kvm/include/x86/processor.h +++ b/tools/testing/selftests/kvm/include/x86/processor.h @@ -1318,7 +1318,7 @@ gva_t vm_alloc_stack(struct kvm_vm *vm, int nr_pages); "lea 1f(%%rip), %%r10\n\t" \ "lea 2f(%%rip), %%r11\n\t" \ fep "1: " insn "\n\t" \ - "xor %%r9, %%r9\n\t" \ + "mov $0, %%r9d\n\t" \ "2:\n\t" \ "mov %%r9b, %[vector]\n\t" \ "mov %%r10, %[error_code]\n\t" -- 2.55.0.887.g758fc8c411-goog