From nobody Thu Oct 2 22:52:48 2025 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 3C49235CED5 for ; Tue, 9 Sep 2025 20:28:41 +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=1757449722; cv=none; b=DmPwIDxIAm05MyCg53comntlN6/FkT0kutGqGI7jOH1Nee1ZgGrt2mJaclWSa6AM13q37vXBRKoy/9HdSS94ss593TC2tsBwg3b/a1RNvtbXdfeUvpZG1NAhqN4599e61hRp8oPlALIwi+t6fpCSQGG2tHE3zbcfFEUGIveUw2s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757449722; c=relaxed/simple; bh=uesFM1+MkFYhqTVfFaRpSNhPDaP6s1tVBFcYtshWXQ0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ePywAnWZzZY441gKZN5iSES2+C7RHrBV2/0QXHlAovtOu6bcQjPjd2etFE+yvuh2v4X4nx3cACYmOeqQNHIFovjX0mk9Sg0L2UdEE12yQKdvTrrU3BlmYOdNNrR5M+B5QTTGh0q7/RDTadQ1K1tMy1W4PMlfAV45q1/3amEIbnQ= 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=Z7wUgZS8; 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="Z7wUgZS8" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-329745d6960so6377116a91.0 for ; Tue, 09 Sep 2025 13:28:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1757449720; x=1758054520; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=VMcYZjELujYMlNUJYw4687AkNxPwf+pUCFf//dDPyoQ=; b=Z7wUgZS8w6muK/WkjnTz/HucNmRoESMpnkvxels+ns2l5GBftTFGZqyBTfDNnsYA/z sMlVwqxp3SUyw6cVewohwj1AnkL55UTxzy5Bh4lTse3lsnnfZvB8eQ0efYOfoscu3GmS L9oDBtWZkwCZDpg0JoE4KRWJtngexzo2vPYrJUFhmIvxqJ1khtZqqR7zajoefhLZQiDq Wd9aZ4R6k5kLvfZVk8oump2GNPTZiaAyPA7N2IHuX59CvA6GneW5i0qjR7XDKUdWqGnC 4dlIkK1QidvR53BjDi0yVSToL3xOI2PSAcROsA1pTmB0rtnIpaJwBY78gjuromypKWSV 4JDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757449720; x=1758054520; h=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; bh=VMcYZjELujYMlNUJYw4687AkNxPwf+pUCFf//dDPyoQ=; b=cbdZrEAc5NGABrXOeksuXtSXWk+HG3ckq+7VdKr+ioLu0pwCKYFLN0sI2pRJsPl15n Kox3XGTqiTtU58d5IUErpsvLODTIJLCTyf6YsCHWbtGUG9iM/d+H82auBEemAADSyu/+ 7vfe2UYmvJGjRMnHmN1/+OjWBlTGzIJBxQXa5eNIHDVbpjYmIKyLKHshMAQDEVMklDwN g4glUisvVzjd3UME4aoHFROvozHLiqdFoZtFeCLNjmehHcaYptF+kESxA3OJNlw7dgA2 SgVOCkNllx/P6NVYSlFfvOvzTn3Bd8RQzWk0lrBqWppc2tvpRuMeOoM1CXVBSUHKWmWC f2Eg== X-Forwarded-Encrypted: i=1; AJvYcCXv29dMD4lgkG5Ru9oCu5WTobczhzkvOq+/C+6oEMyp1yVnDi+vrEoxKrrpXUxUcsB/+LxpReQpdmDgki0=@vger.kernel.org X-Gm-Message-State: AOJu0YzkNSLZOl7iAtT8Wax+4OLJERWtbIk+pL+Z45L5ezXoe/giXGFM vbc9wbkBdz4eUHG4DWW6wIiCgezfmgP2UaRt66MChIZunrYs2QcRN+e6j4l8YCb6sk0r0Z1s4of LRrJfIg== X-Google-Smtp-Source: AGHT+IFBc+/15LTsqqJoc86kYHdS0+jzidyjkL/wyrFVCs4AAea75O4UJ8H3qPsHcOQvsjR0n0AGJWirWhU= X-Received: from pjhu5.prod.google.com ([2002:a17:90a:5185:b0:32d:a0b1:2b03]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2fd0:b0:329:f535:6e3c with SMTP id 98e67ed59e1d1-32d43f9338cmr16979804a91.35.1757449720561; Tue, 09 Sep 2025 13:28:40 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 9 Sep 2025 13:28:32 -0700 In-Reply-To: <20250909202835.333554-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: <20250909202835.333554-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.384.g4c02a37b29-goog Message-ID: <20250909202835.333554-2-seanjc@google.com> Subject: [PATCH 1/4] KVM: selftests: Add support for #DE exception fixup From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for handling #DE (divide error) exceptions in KVM selftests so that the fastops test can verify KVM correctly handles #DE when emulating DIV or IDIV on behalf of the guest. Morph #DE to 0xff (i.e. to -1) as a mostly-arbitrary vector to indicate #DE, so that '0' (the real #DE vector) can still be used to indicate "no exception". Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/include/x86/processor.h | 6 ++++++ tools/testing/selftests/kvm/lib/x86/processor.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/include/x86/processor.h b/tools/te= sting/selftests/kvm/include/x86/processor.h index 2efb05c2f2fb..5142d1bf15a2 100644 --- a/tools/testing/selftests/kvm/include/x86/processor.h +++ b/tools/testing/selftests/kvm/include/x86/processor.h @@ -1179,6 +1179,12 @@ struct idt_entry { void vm_install_exception_handler(struct kvm_vm *vm, int vector, void (*handler)(struct ex_regs *)); =20 +/* + * Exception fixup morphs #DE to an arbitrary magic vector so that '0' can= be + * used to signal "no expcetion". + */ +#define KVM_MAGIC_DE_VECTOR 0xff + /* If a toddler were to say "abracadabra". */ #define KVM_EXCEPTION_MAGIC 0xabacadabaULL =20 diff --git a/tools/testing/selftests/kvm/lib/x86/processor.c b/tools/testin= g/selftests/kvm/lib/x86/processor.c index d4c19ac885a9..3b63c99f7b96 100644 --- a/tools/testing/selftests/kvm/lib/x86/processor.c +++ b/tools/testing/selftests/kvm/lib/x86/processor.c @@ -557,7 +557,7 @@ static bool kvm_fixup_exception(struct ex_regs *regs) return false; =20 if (regs->vector =3D=3D DE_VECTOR) - return false; + regs->vector =3D KVM_MAGIC_DE_VECTOR; =20 regs->rip =3D regs->r11; regs->r9 =3D regs->vector; --=20 2.51.0.384.g4c02a37b29-goog From nobody Thu Oct 2 22:52:48 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 E8DBD35FC3D for ; Tue, 9 Sep 2025 20:28:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757449724; cv=none; b=fngFnzmom9HqJ/o2bkdXDA6QjWhkUEyIdHii42jXCF4hRBHNCLlWzza5qpxbNESFBmfknGWPBtP7OOKqkAmD3bkYkTfyOUuYBOsO074vRng+aItezk4SzWqTYW6n8TgNANLWnlp70thLyEzUkWx+mUjlWVPQEBPqIKJcDMt5jmk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757449724; c=relaxed/simple; bh=QmVux2JvmbyMClzeW5DTZk69kxWxw7C1UcmEM9nW6Yg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=uy4Qmk01YRPEzcyk3eGxcgxPoQ0kGHvCQVDUr4ksfXjC1wxTAUpQM+ENwE9nrtWAZJHZhl3xv8HMiM2/ZHIUKaC6gn1GkUmNKskg9Y8rHKlDDMMbzNS/dWTkp8A/YaEMiw7HgVmE8Yf9DTJwjeqXWmoVKq6PYZXsN2ptg+sZPOg= 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=Riz+xrg3; arc=none smtp.client-ip=209.85.216.74 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="Riz+xrg3" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-32b698861d8so5860835a91.2 for ; Tue, 09 Sep 2025 13:28:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1757449722; x=1758054522; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=zFN18xXBIM875rVGUIf15K3R2MElVqiHDd3tbRot1Bc=; b=Riz+xrg3dr2pq//vhyCd7kXwtvqfF1bmWCUj8QgpjBB9UqpRkutDZ8KqOXH6UEtcpo beh0GT7gRG5CdOWscU00RxMoCutPB884pAiBlqty6N3jqsVbc4EH034QzvA7DMYA3ILp cOuvYfCa96ziC0LjYxuN2CxIFtyzbXdlHz36jU5bcSqsPbNbNRKB5pCR9GZ6RrbUHlOe IpGZuI3tNkIQ94AE2aQQU275xe8jFaS36AzIDM4iYZ4QrLSTP2uW6ysXrKSsdIFppndy AsvzNxJsLPbTQgkVJrTKgZK4JgfwfILSt9d+aHs/Dv3tvJYotZzd1LoCWlp3IDOLcLyZ OtOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757449722; x=1758054522; h=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; bh=zFN18xXBIM875rVGUIf15K3R2MElVqiHDd3tbRot1Bc=; b=Pp7Hfi+GPz7zpTbyrltUA2CMFTXCl+5h3RqqOEQ5dsXIFZSwnok07JFLQMhaXOduIK apfOi7ebsWTuhy6d62ZVZRqWrtBgoub+cRCFZ+ZbdBCUnZyD7T/pyOozccDAdZiGGaGz hQ6md0cJF0Yoppi2B0S7LdSlg6CsG+9dYRjbEJKYP53FA+ayatLRACim9ctcGVxmtyLC Mqk8HRFDd08uJiseIA5X15lIR7GqzVQfxvJtJWq6wqF8lVG5zCYIniYa/y8Uysigkn2+ QR8ZZXaJ4gxoZc2V+cpMLEbNgWdxSf0bYrXfAugGK3ysj+67F9MNFlBo/yeACY9AJJfx bNfQ== X-Forwarded-Encrypted: i=1; AJvYcCVHo9kgO8VmZLT9Xi7L2uzWOhiE2UfZkAhxqMIj61CmLaZ1uUgqx1u7p0l/sJ1a/OJY1l5fldjeyB/lCyI=@vger.kernel.org X-Gm-Message-State: AOJu0YwSX0CnMgd2nqavSXU2EDshLBLC5rvZaXjnPOuBUcV8jb6cbEHb tYsA2vVRnWknogeNlgJ6YNq1StgFyJiH+EITQ+YN6jnY9nWh3EMFpAO6Q05Rlyvbye8mospw7pq naYe00Q== X-Google-Smtp-Source: AGHT+IG1LDhj9gttCv49esypEKAYUt6EpytM/C97fa1pwQVwmJjr1csJL3R4A2vjMmiXLxHRd+2zLC5q0+Q= X-Received: from pjbov13.prod.google.com ([2002:a17:90b:258d:b0:32d:a359:8e4d]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1dcb:b0:32b:ca6f:123f with SMTP id 98e67ed59e1d1-32d43ee718dmr15415029a91.5.1757449722107; Tue, 09 Sep 2025 13:28:42 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 9 Sep 2025 13:28:33 -0700 In-Reply-To: <20250909202835.333554-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: <20250909202835.333554-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.384.g4c02a37b29-goog Message-ID: <20250909202835.333554-3-seanjc@google.com> Subject: [PATCH 2/4] KVM: selftests: Add coverage for 'b' (byte) sized fastops emulation From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Extend the fastops test to cover instructions that operate on 8-bit data. Support for 8-bit instructions was omitted from the original commit purely due to complications with BT not having a r/m8 variant. To keep the RFLAGS.CF behavior deterministic and not heavily biased to '0' or '1', continue using BT, but cast and load the to-be-tested value into a dedicated 32-bit constraint. Supporting 8-bit operations will allow using guest_test_fastops() as-is to provide full coverage for DIV and IDIV. For divide operations, covering all operand sizes _is_ interesting, because KVM needs provide exception fixup for each size (failure to handle a #DE could panic the host). Link: https://lore.kernel.org/all/aIF7ZhWZxlkcpm4y@google.com Signed-off-by: Sean Christopherson --- .../testing/selftests/kvm/x86/fastops_test.c | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/kvm/x86/fastops_test.c b/tools/testing= /selftests/kvm/x86/fastops_test.c index 2ac89d6c1e46..6c9a2dbf6365 100644 --- a/tools/testing/selftests/kvm/x86/fastops_test.c +++ b/tools/testing/selftests/kvm/x86/fastops_test.c @@ -10,12 +10,13 @@ */ #define guest_execute_fastop_1(FEP, insn, __val, __flags) \ ({ \ - __asm__ __volatile__("bt $0, %[val]\n\t" \ + __asm__ __volatile__("bt $0, %[ro_val]\n\t" \ FEP insn " %[val]\n\t" \ "pushfq\n\t" \ "pop %[flags]\n\t" \ : [val]"+r"(__val), [flags]"=3Dr"(__flags) \ - : : "cc", "memory"); \ + : [ro_val]"rm"((uint32_t)__val) \ + : "cc", "memory"); \ }) =20 #define guest_test_fastop_1(insn, type_t, __val) \ @@ -36,12 +37,13 @@ =20 #define guest_execute_fastop_2(FEP, insn, __input, __output, __flags) \ ({ \ - __asm__ __volatile__("bt $0, %[output]\n\t" \ + __asm__ __volatile__("bt $0, %[ro_val]\n\t" \ FEP insn " %[input], %[output]\n\t" \ "pushfq\n\t" \ "pop %[flags]\n\t" \ : [output]"+r"(__output), [flags]"=3Dr"(__flags) \ - : [input]"r"(__input) : "cc", "memory"); \ + : [input]"r"(__input), [ro_val]"rm"((uint32_t)__output) \ + : "cc", "memory"); \ }) =20 #define guest_test_fastop_2(insn, type_t, __val1, __val2) \ @@ -63,12 +65,13 @@ =20 #define guest_execute_fastop_cl(FEP, insn, __shift, __output, __flags) \ ({ \ - __asm__ __volatile__("bt $0, %[output]\n\t" \ + __asm__ __volatile__("bt $0, %[ro_val]\n\t" \ FEP insn " %%cl, %[output]\n\t" \ "pushfq\n\t" \ "pop %[flags]\n\t" \ : [output]"+r"(__output), [flags]"=3Dr"(__flags) \ - : "c"(__shift) : "cc", "memory"); \ + : "c"(__shift), [ro_val]"rm"((uint32_t)__output) \ + : "cc", "memory"); \ }) =20 #define guest_test_fastop_cl(insn, type_t, __val1, __val2) \ @@ -115,14 +118,16 @@ do { \ guest_test_fastop_2("add" suffix, type_t, vals[i], vals[j]); \ guest_test_fastop_2("adc" suffix, type_t, vals[i], vals[j]); \ guest_test_fastop_2("and" suffix, type_t, vals[i], vals[j]); \ +if (sizeof(type_t) !=3D 1) { \ guest_test_fastop_2("bsf" suffix, type_t, vals[i], vals[j]); \ guest_test_fastop_2("bsr" suffix, type_t, vals[i], vals[j]); \ guest_test_fastop_2("bt" suffix, type_t, vals[i], vals[j]); \ guest_test_fastop_2("btc" suffix, type_t, vals[i], vals[j]); \ guest_test_fastop_2("btr" suffix, type_t, vals[i], vals[j]); \ guest_test_fastop_2("bts" suffix, type_t, vals[i], vals[j]); \ - guest_test_fastop_2("cmp" suffix, type_t, vals[i], vals[j]); \ guest_test_fastop_2("imul" suffix, type_t, vals[i], vals[j]); \ +} \ + guest_test_fastop_2("cmp" suffix, type_t, vals[i], vals[j]); \ guest_test_fastop_2("or" suffix, type_t, vals[i], vals[j]); \ guest_test_fastop_2("sbb" suffix, type_t, vals[i], vals[j]); \ guest_test_fastop_2("sub" suffix, type_t, vals[i], vals[j]); \ @@ -142,6 +147,7 @@ do { \ =20 static void guest_code(void) { + guest_test_fastops(uint8_t, "b"); guest_test_fastops(uint16_t, "w"); guest_test_fastops(uint32_t, "l"); guest_test_fastops(uint64_t, "q"); --=20 2.51.0.384.g4c02a37b29-goog From nobody Thu Oct 2 22:52:48 2025 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 A6DF436299D for ; Tue, 9 Sep 2025 20:28:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757449726; cv=none; b=L6DvFelEy5o0B7WZSQZA0GfAS47GSoSPvBFlZu1xWi+25N5/aJp0wvkscBijP7WSj364QNiATTlCqnW+xeiQlwYjd+TxrLckSZ8Nfeg2T43d9FU4SlCS99AfK0ieI5BEoGHJlaZQlo46KWpmK8lxuFRCtZI9/0fKvcZUBn2LIbc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757449726; c=relaxed/simple; bh=vtdJbK7wreG5s5RioxYrcTeNIZaeOWo9M19O9uJimxs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=T4PVwZO692oArdMn1Fg5aY63zXAOus7yA2cIPoeNDyrbucx+FYvoef3IdyEAnxppFwjrHmGjg43bqJHNqDdidVAyFLxgmYCoS2rexSFWmDtz+FtnqKJ7KRk+sz/J1xuNHKjy0TCeWCbs0AJT02tE5vYN8690IDxZqokyIMKMtmA= 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=KcckoLpY; arc=none smtp.client-ip=209.85.215.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="KcckoLpY" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b52047b3f21so2991948a12.2 for ; Tue, 09 Sep 2025 13:28:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1757449724; x=1758054524; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=CMiFM11/UgOTiqujCsfr58bBaclwwZCG3bf7Rw+V6nY=; b=KcckoLpYDUPBtj1YzWWlCH2w03HGbPWxrGwAWPZRQPaw/AYeEY6SwdzPC+VneTyAPF lp/QVrbHRNflioj3BsppEVwieBc6vL0DMXu0ebS2wp9HFf2CsnJiqVoKCoL7Uu+Qowu/ I2wInPl8IFQux3XoyQN4S7bmgnIOgxb5Pc+epMIHKVyqP2DdMNyi+TNidvckf7eafXJ9 /0KDc/oAMPJVaiLzrq/gfpT5GJA/YbE+yqPWAirr7NrnMlYVQAMfQefiWf2F6ykyJRc3 UuhiVSEeD4HBDHDdnz5qMgBFh1ibDg/7IjwzkexVhkK4askRtGrAqiwXxTJMXVOn8/6y 5WIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757449724; x=1758054524; h=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; bh=CMiFM11/UgOTiqujCsfr58bBaclwwZCG3bf7Rw+V6nY=; b=KMQIt7WAH/o3wmW+d/WIdxQGzmOY17eQRzTBeEgj04u2nholZvfb3jqxG9g+GvJ8FZ 5uzGj0Dj2WEgYZxGc/HijHew53VlPJt5Q6CZQ1TQV27MZIifXVhvf7rbeEWy1HzhRY3P 1xo5y5p/MT5ezzBYKmrnmRetyZMuow0OnKYAZlJGN87Y+kw1D3troPx2bvPgdx+h/3mc UqkK9CZQTX0UJFx9LBzqygFmZHT+C8jLKWGCZP96YSlbAjbjfkGPqhWkUX88rYg2IMVQ fQYrjCrK7+5xnoxjON6aEKd2PBGPBdLNY7Mw02ncjnIplp6Jk7uM+qhuZE3Av1q1Dwcn NAMA== X-Forwarded-Encrypted: i=1; AJvYcCW+fcw0fZJs5Nmhkzn6tO2NabxRbHF8xnULq+AoNx4bGQb9mj23aBXaZ/2ljBhyApvv60X02gnTYJy+fZc=@vger.kernel.org X-Gm-Message-State: AOJu0YxQ6XuecwPHyZQXWSpt9etOXlRVbLjdljx+S34x2C++cwlB4h0c GAMXuss5gcDw7meLGLrz5aynydMwraNW+VG38IpCgUVy+F+8F9bG3XZTalLMVstudtKLKMsYtSb 4XWk9TQ== X-Google-Smtp-Source: AGHT+IGtmVKP/LwQkTqqYTi72JKKi44xEFgNIfHXbNe2MHRDjv1vB5/IxJ0ew/FNcnhQLmQE78maXbxcXAk= X-Received: from pjx15.prod.google.com ([2002:a17:90b:568f:b0:329:7040:8862]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:f78f:b0:240:3eb9:5363 with SMTP id d9443c01a7336-2516e69aedamr155274045ad.27.1757449723965; Tue, 09 Sep 2025 13:28:43 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 9 Sep 2025 13:28:34 -0700 In-Reply-To: <20250909202835.333554-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: <20250909202835.333554-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.384.g4c02a37b29-goog Message-ID: <20250909202835.333554-4-seanjc@google.com> Subject: [PATCH 3/4] KVM: selftests: Dedup the gnarly constraints of the fastops tests (more macros!) From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a fastop() macro along with macros to define its required constraints, and use the macros to dedup the innermost guts of the fastop testcases. No functional change intended. Signed-off-by: Sean Christopherson --- .../testing/selftests/kvm/x86/fastops_test.c | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/tools/testing/selftests/kvm/x86/fastops_test.c b/tools/testing= /selftests/kvm/x86/fastops_test.c index 6c9a2dbf6365..26a381c8303a 100644 --- a/tools/testing/selftests/kvm/x86/fastops_test.c +++ b/tools/testing/selftests/kvm/x86/fastops_test.c @@ -8,14 +8,20 @@ * to set RFLAGS.CF based on whether or not the input is even or odd, so t= hat * instructions like ADC and SBB are deterministic. */ +#define fastop(__insn) \ + "bt $0, %[bt_val]\n\t" \ + __insn "\n\t" \ + "pushfq\n\t" \ + "pop %[flags]\n\t" + +#define flags_constraint(flags_val) [flags]"=3Dr"(flags_val) +#define bt_constraint(__bt_val) [bt_val]"rm"((uint32_t)__bt_val) + #define guest_execute_fastop_1(FEP, insn, __val, __flags) \ ({ \ - __asm__ __volatile__("bt $0, %[ro_val]\n\t" \ - FEP insn " %[val]\n\t" \ - "pushfq\n\t" \ - "pop %[flags]\n\t" \ - : [val]"+r"(__val), [flags]"=3Dr"(__flags) \ - : [ro_val]"rm"((uint32_t)__val) \ + __asm__ __volatile__(fastop(FEP insn " %[val]") \ + : [val]"+r"(__val), flags_constraint(__flags) \ + : bt_constraint(__val) \ : "cc", "memory"); \ }) =20 @@ -37,12 +43,9 @@ =20 #define guest_execute_fastop_2(FEP, insn, __input, __output, __flags) \ ({ \ - __asm__ __volatile__("bt $0, %[ro_val]\n\t" \ - FEP insn " %[input], %[output]\n\t" \ - "pushfq\n\t" \ - "pop %[flags]\n\t" \ - : [output]"+r"(__output), [flags]"=3Dr"(__flags) \ - : [input]"r"(__input), [ro_val]"rm"((uint32_t)__output) \ + __asm__ __volatile__(fastop(FEP insn " %[input], %[output]") \ + : [output]"+r"(__output), flags_constraint(__flags) \ + : [input]"r"(__input), bt_constraint(__output) \ : "cc", "memory"); \ }) =20 @@ -65,12 +68,9 @@ =20 #define guest_execute_fastop_cl(FEP, insn, __shift, __output, __flags) \ ({ \ - __asm__ __volatile__("bt $0, %[ro_val]\n\t" \ - FEP insn " %%cl, %[output]\n\t" \ - "pushfq\n\t" \ - "pop %[flags]\n\t" \ - : [output]"+r"(__output), [flags]"=3Dr"(__flags) \ - : "c"(__shift), [ro_val]"rm"((uint32_t)__output) \ + __asm__ __volatile__(fastop(FEP insn " %%cl, %[output]") \ + : [output]"+r"(__output), flags_constraint(__flags) \ + : "c"(__shift), bt_constraint(__output) \ : "cc", "memory"); \ }) =20 --=20 2.51.0.384.g4c02a37b29-goog From nobody Thu Oct 2 22:52:48 2025 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 45F013680AF for ; Tue, 9 Sep 2025 20:28:46 +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=1757449727; cv=none; b=Rymw/hmkdeu0VfDmhJCAxLm1AIADI8ucREE9zjmBeC2Wf0g5bf8q1M1Aj34l4d8T19ilZRtcQ398p4I2GYogECCWbQHQmcqMnGrA7JJch1sSHWBgSrfW0GDIj+hR1sya1CFPZ05qT/Ws5ot4QyQenhVqZVx6aGgKZySQxFz9FO8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757449727; c=relaxed/simple; bh=l1p+ajwaVGWFswKTwWM0EkrL8pc+SEJVITkZ4XN4ybI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=kyzaM7U2ETyTXMnpWqQctvTkXKcbY4eC4RLUoTX4Krd82r+jW0wWsqLfI0he/6Vfz8ZoIQJURmUtXeyn2Gc43V6pX+JXfaSHubv6297mWtv7GIYn+CdwcaJXC4Ng8d4aiNec5qwsKnwP8xWAlf8s8HbNjLswgIvIHgZBHHbFoJU= 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=UgTRwrzG; 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="UgTRwrzG" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-7723d779674so5502913b3a.3 for ; Tue, 09 Sep 2025 13:28:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1757449725; x=1758054525; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=TVVFhn/odeLoh98SYAt/1c5wREWCW1GdBR24cmSPAxM=; b=UgTRwrzGbzYZdVTNztHQsx564NlIwwqYEm9xFoEH+tpVgsEyaKKSdwBYvX8jOV5mTY nXXCNMbHP2kxNt0p3PKPpPD+QzcqbqjL3d7UhavP8COua5rfpysQ1zI9UMTUQOHK5mK4 Rg4mc/f21k/h/pcL4qdfbDVGDWsZgZyXGcEq6k0zW206fP+3iCHy9og6g7przEc8URB9 1UyLaq77PuDaqxDxx1sLecAObLS7j+lXAK5rrnANc5Ep2Ki2GjXscOTW67uat+IAkD0J DFWJLBSkNGbQeKXrEEIty0lSdFBhpaHSXy35gF4tYVGLbHvks8+J0qKjk59MZbguiCTX vaGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757449725; x=1758054525; h=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; bh=TVVFhn/odeLoh98SYAt/1c5wREWCW1GdBR24cmSPAxM=; b=PT7UqTZEhAnFnrmaebZzB8/3nBW1vY0ShsxTbREr9JQpHHqKY8b1R+5WVaUvQBxukc yCkjrJEOXsB62XT6wayn4kiTr9K2d3gDa/JHaErsOKb8gmVH0r7oz08cFxBRXWDpotzC KSt1mlQlDDm9lI0O57G5p8zEuAeS0zzlZJLl1BrRLK9ZUHlF83/p7IdW4ThXFZKVnFYz GhyCtFo8eXcKrlU8CZGVRjpNE7ziMYPPRF44vkmhJOW23haqAmfBOGNY6rkYHjVS3yJO J2cYycadi0Y26KC08jp74DNn1Tsi9TyEWBJWILNnNEZ0/VyqbniO7DG7Keg+tV/osKBB a/lw== X-Forwarded-Encrypted: i=1; AJvYcCUXgF+9IEsfQ8J9C+hJl9UK3z+GeHzRGxACeteqOCZHeGj2J3JYBoBrBliFClRvOfnDytZfiyEr59RXy7s=@vger.kernel.org X-Gm-Message-State: AOJu0Yx+QJxpNB0MWt3hDZDNQiZ9em2qrEKi0CAu79mWqU70Fgy5E+Gs aWrtG+g1jTdsz7U1zbySXySqR8J8mAw6hmvZbETE931zVoAWzi5XUxJOREE5C2J/9QxutELHjI0 MYeTKXw== X-Google-Smtp-Source: AGHT+IH8uNMlu5Y0TjLA9EVWSsLg10Gx/gLxUasJpNUgiCjgYV16KpeaSDIBsZoEG0G6FLCAc+Hh4TDudAk= X-Received: from pjl8.prod.google.com ([2002:a17:90b:2f88:b0:327:e697:7bdf]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:2583:b0:250:c76d:1cd8 with SMTP id adf61e73a8af0-2533f8c9498mr19873101637.20.1757449725604; Tue, 09 Sep 2025 13:28:45 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 9 Sep 2025 13:28:35 -0700 In-Reply-To: <20250909202835.333554-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: <20250909202835.333554-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.384.g4c02a37b29-goog Message-ID: <20250909202835.333554-5-seanjc@google.com> Subject: [PATCH 4/4] KVM: selftests: Add support for DIV and IDIV in the fastops test From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Extend the fastops test coverage to DIV and IDIV, specifically to provide coverage for #DE (divide error) exceptions, as #DE is the only exception that can occur in KVM's fastops path, i.e. that requires exception fixup. Signed-off-by: Sean Christopherson --- .../testing/selftests/kvm/x86/fastops_test.c | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tools/testing/selftests/kvm/x86/fastops_test.c b/tools/testing= /selftests/kvm/x86/fastops_test.c index 26a381c8303a..8926cfe0e209 100644 --- a/tools/testing/selftests/kvm/x86/fastops_test.c +++ b/tools/testing/selftests/kvm/x86/fastops_test.c @@ -92,6 +92,42 @@ ex_flags, insn, shift, (uint64_t)input, flags); \ }) =20 +#define guest_execute_fastop_div(__KVM_ASM_SAFE, insn, __a, __d, __rm, __f= lags) \ +({ \ + uint64_t ign_error_code; \ + uint8_t vector; \ + \ + __asm__ __volatile__(fastop(__KVM_ASM_SAFE(insn " %[denom]")) \ + : "+a"(__a), "+d"(__d), flags_constraint(__flags), \ + KVM_ASM_SAFE_OUTPUTS(vector, ign_error_code) \ + : [denom]"rm"(__rm), bt_constraint(__rm) \ + : "cc", "memory", KVM_ASM_SAFE_CLOBBERS); \ + vector; \ +}) + +#define guest_test_fastop_div(insn, type_t, __val1, __val2) \ +({ \ + type_t _a =3D __val1, _d =3D __val1, rm =3D __val2; \ + type_t a =3D _a, d =3D _d, ex_a =3D _a, ex_d =3D _d; \ + uint64_t flags, ex_flags; \ + uint8_t v, ex_v; \ + \ + ex_v =3D guest_execute_fastop_div(KVM_ASM_SAFE, insn, ex_a, ex_d, rm, ex_= flags); \ + v =3D guest_execute_fastop_div(KVM_ASM_SAFE_FEP, insn, a, d, rm, flags); = \ + \ + GUEST_ASSERT_EQ(v, ex_v); \ + __GUEST_ASSERT(v =3D=3D ex_v, \ + "Wanted vector 0x%x for '%s 0x%lx:0x%lx/0x%lx', got 0x%x", \ + ex_v, insn, (uint64_t)_a, (uint64_t)_d, (uint64_t)rm, v); \ + __GUEST_ASSERT(a =3D=3D ex_a && d =3D=3D ex_d, \ + "Wanted 0x%lx:0x%lx for '%s 0x%lx:0x%lx/0x%lx', got 0x%lx:0x%lx",\ + (uint64_t)ex_a, (uint64_t)ex_d, insn, (uint64_t)_a, \ + (uint64_t)_d, (uint64_t)rm, (uint64_t)a, (uint64_t)d); \ + __GUEST_ASSERT(v || ex_v || (flags =3D=3D ex_flags), \ + "Wanted flags 0x%lx for '%s 0x%lx:0x%lx/0x%lx', got 0x%lx", \ + ex_flags, insn, (uint64_t)_a, (uint64_t)_d, (uint64_t)rm, flags);\ +}) + static const uint64_t vals[] =3D { 0, 1, @@ -141,6 +177,8 @@ if (sizeof(type_t) !=3D 1) { \ guest_test_fastop_cl("sar" suffix, type_t, vals[i], vals[j]); \ guest_test_fastop_cl("shl" suffix, type_t, vals[i], vals[j]); \ guest_test_fastop_cl("shr" suffix, type_t, vals[i], vals[j]); \ + \ + guest_test_fastop_div("div" suffix, type_t, vals[i], vals[j]); \ } \ } \ } while (0) --=20 2.51.0.384.g4c02a37b29-goog