The upcoming new Idle HLT Intercept feature allows for the HLT
instruction execution by a vCPU to be intercepted by the hypervisor
only if there are no pending V_INTR and V_NMI events for the vCPU.
When the vCPU is expected to service the pending V_INTR and V_NMI
events, the Idle HLT intercept won’t trigger. The feature allows the
hypervisor to determine if the vCPU is actually idle and reduces
wasteful VMEXITs.
The Idle HLT intercept feature is used for enlightened guests who wish
to securely handle the events. When an enlightened guest does a HLT
while an interrupt is pending, hypervisor will not have a way to
figure out whether the guest needs to be re-entered or not. The Idle
HLT intercept feature allows the HLT execution only if there are no
pending V_INTR and V_NMI events.
Presence of the Idle HLT Intercept feature is indicated via CPUID
function Fn8000_000A_EDX[30].
Document for the Idle HLT intercept feature is available at [1].
This series is based on kvm-x86/next (eb723766b103) + [2].
Testing Done:
- Tested the functionality for the Idle HLT intercept feature
using selftest ipi_hlt_test.
- Tested on normal, SEV, SEV-ES, SEV-SNP guest for the Idle HLT intercept
functionality.
- Tested the Idle HLT intercept functionality on nested guest.
v5 -> v6
- Incorporated Neeraj's review comments on selftest.
v4 -> v5
- Incorporated Sean's review comments on nested Idle HLT intercept support.
- Make svm_idle_hlt_test independent of the Idle HLT to run on all hardware.
v3 -> v4
- Drop the patches to add vcpu_get_stat() into a new series [2].
- Added nested Idle HLT intercept support.
v2 -> v3
- Incorporated Andrew's suggestion to structure vcpu_stat_types in
a way that each architecture can share the generic types and also
provide its own.
v1 -> v2
- Did changes in svm_idle_hlt_test based on the review comments from Sean.
- Added an enum based approach to get binary stats in vcpu_get_stat() which
doesn't use string to get stat data based on the comments from Sean.
- Added safe_halt() and cli() helpers based on the comments from Sean.
[1]: AMD64 Architecture Programmer's Manual Pub. 24593, April 2024,
Vol 2, 15.9 Instruction Intercepts (Table 15-7: IDLE_HLT).
https://bugzilla.kernel.org/attachment.cgi?id=306251
[2]: https://lore.kernel.org/kvm/ee027335-f1b9-4637-bc79-27a610c1ab08@amd.com/T/…
---
V5: https://lore.kernel.org/kvm/20250103081828.7060-1-manali.shukla@amd.com/
V4: https://lore.kernel.org/kvm/20241022054810.23369-1-manali.shukla@amd.com/
V3: https://lore.kernel.org/kvm/20240528041926.3989-4-manali.shukla@amd.com/T/
V2: https://lore.kernel.org/kvm/20240501145433.4070-1-manali.shukla@amd.com/
V1: https://lore.kernel.org/kvm/20240307054623.13632-1-manali.shukla@amd.com/
Manali Shukla (3):
x86/cpufeatures: Add CPUID feature bit for Idle HLT intercept
KVM: SVM: Add Idle HLT intercept support
KVM: selftests: Add self IPI HLT test
arch/x86/include/asm/cpufeatures.h | 1 +
arch/x86/include/asm/svm.h | 1 +
arch/x86/include/uapi/asm/svm.h | 2 +
arch/x86/kvm/svm/svm.c | 13 ++-
tools/testing/selftests/kvm/Makefile.kvm | 1 +
.../selftests/kvm/include/x86/processor.h | 1 +
tools/testing/selftests/kvm/ipi_hlt_test.c | 81 +++++++++++++++++++
7 files changed, 97 insertions(+), 3 deletions(-)
create mode 100644 tools/testing/selftests/kvm/ipi_hlt_test.c
base-commit: eb723766b1030a23c38adf2348b7c3d1409d11f0
prerequisite-patch-id: cb345fc0d814a351df2b5788b76eee0eef9de549
prerequisite-patch-id: 71806f400cffe09f47d6231cb072cbdbd540de1b
prerequisite-patch-id: 9ea0412aab7ecd8555fcee3e9609dbfe8456d47b
prerequisite-patch-id: 3504df50cdd33958456f2e56139d76867273525c
prerequisite-patch-id: 674e56729a56cc487cb85be1a64ef561eb7bac8a
prerequisite-patch-id: 48e87354f9d6e6bd121ca32ab73cd0d7f1dce74f
prerequisite-patch-id: b32c21df6522a7396baa41d62bcad9479041d97a
prerequisite-patch-id: 0ff4b504e982db7c1dfa8ec6ac485c92a89f4af8
prerequisite-patch-id: 509018dc2fc1657debc641544e86f5a92d04bc1a
--
2.34.1
I never had much luck running mm selftests so I spent a couple of hours
digging into why.
Looks like most of the reason is missing SKIP checks, so this series is
just adding a bunch of those that I found. I did not do anything like
all of them, just the ones I spotted in gup_longterm, gup_test, mmap,
userfaultfd and memfd_secret.
It's a bit unfortunate to have to skip those tests when ftruncate()
fails, but I don't have time to dig deep enough into it to actually make
them pass - I observed these issues on both 9p and virtiofs. Probably
it requires digging into the filesystem implementation
(An alternative might just be to mount a tmpfs in the test script).
I am also seeing some failures to allocate hugetlb pages in
uffd-mp-mremap that I have not had time to fully understand, you can see
those here:
https://gist.github.com/bjackman/af74c3a6e60975e6ff0d760cba1e05d2#file-user…
Signed-off-by: Brendan Jackman <jackmanb(a)google.com>
---
Changes in v2 (Thanks to Dev for the reviews):
- Improve and cleanup some error messages
- Add some extra SKIPs
- Fix misnaming of nr_cpus variable in uffd tests
- Link to v1: https://lore.kernel.org/r/20250220-mm-selftests-v1-0-9bbf57d64463@google.com
---
Brendan Jackman (9):
selftests/mm: Report errno when things fail in gup_longterm
selftests/mm: Fix assumption that sudo is present
selftests/mm: Skip uffd-stress if userfaultfd not available
selftests/mm: Skip uffd-wp-mremap if userfaultfd not available
selftests/mm/uffd: Rename nr_cpus -> nr_threads
selftests/mm: Print some details when uffd-stress gets bad params
selftests/mm: Don't fail uffd-stress if too many CPUs
selftests/mm: Skip map_populate on weird filesystems
selftests/mm: Skip gup_longerm tests on weird filesystems
tools/testing/selftests/mm/gup_longterm.c | 45 ++++++++++++++++++----------
tools/testing/selftests/mm/map_populate.c | 7 +++++
tools/testing/selftests/mm/run_vmtests.sh | 22 +++++++++++---
tools/testing/selftests/mm/uffd-common.c | 8 ++---
tools/testing/selftests/mm/uffd-common.h | 2 +-
tools/testing/selftests/mm/uffd-stress.c | 42 ++++++++++++++++----------
tools/testing/selftests/mm/uffd-unit-tests.c | 2 +-
tools/testing/selftests/mm/uffd-wp-mremap.c | 5 +++-
8 files changed, 90 insertions(+), 43 deletions(-)
---
base-commit: a3daad8215143340c0870c5489e599fd059037e9
change-id: 20250220-mm-selftests-2d7d0542face
Best regards,
--
Brendan Jackman <jackmanb(a)google.com>
This series adds KVM selftests for Secure AVIC.
The Secure AVIC KVM support patch series is at:
https://lore.kernel.org/kvm/20250228085115.105648-1-Neeraj.Upadhyay@amd.com…
Git tree is available at:
https://github.com/AMDESE/linux-kvm/tree/savic-host-latest
This series depends on SNP Smoke tests patch series by Pratik:
https://lore.kernel.org/lkml/20250123220100.339867-1-prsampat@amd.com/
- Patch 1-6 are taken from Peter Gonda's patch series for GHCB support
for SEV-ES guests. GHCB support for SNP guests is added to these
patches.
https://lore.kernel.org/lkml/Ziln_Spd6KtgVqkr@google.com/T/#m6c0fc7e2b2e35f…
Patches 7-8 are fixes on top of Peter's series.
- Patch 9 fixes IDT vector for #VC exception (29) which has a valid
error code associated with the exception.
- Patch 10 adds #VC exception handling for rdmsr/wrmsr accesses of
SEV-ES guests.
- Patch 11 skips vm_is_gpa_protected() check for APIC MMIO base address
in __virt_pg_map() for VMs with protected memory. This is required
for xapic tests enablement for SEV VMs.
- Patch 12 and 13 are PoC patches to support MMIO #VC handling for SEV-ES
guests. They add x86 instruction decoding support.
- Patch 14 adds #VC handling for MMIO accesses by SEV-ES guests.
- Patch 15 adds movabs instruction decoding for cases where compiler
generates movabs for MMIO reads/writes.
- Patch 16 adds SEV guests testing support in xapic_state_test.
- Patch 17 adds x2apic mode support in xapic_ipi_test.
- Patch 18 adds SEV VMs support in xapic_ipi_test.
- Patch 19 adds a library for Secure AVIC backing page initialization
and enabling Secure AVIC for a SNP guest.
- Patch 20 adds support for SVM_EXIT_AVIC_UNACCELERATED_ACCESS #VC
exception handling for APIC msr reads/writes by Secure AVIC enabled
VM.
- Patch 21 adds support for SVM_EXIT_AVIC_INCOMPLETE_IPI #VC error
code handling for Secure AVIC enabled VM.
- Patch 22 adds args param to kvm_arch_vm_post_create() to pass
vmsa features to KVM_SEV_INIT2 ioctl for SEV VMs.
- Patch 23 adds an api for passing guest APIC page GPA to Hypervisor.
- Patch 24 adds Secure AVIC VM support to xapic_ipi_test test.
- Patch 25 adds a test for verifying APIC regs MMIO/msr accesses
for a Secure AVIC VM before it enables x2apic mode, in x2apic mode
and after enabling Secure AVIC in the Secure AVIC control msr.
- Patch 26 adds a msr access test to verify accelerated/unaccelerated
msr acceses for Secure AVIC enabled VM.
- Patch 27 tests idle hlt for Secure AVIC enabled VM.
- Patch 28 adds IOAPIC tests for Secure AVIC enabled VM.
- Patch 29 adds cross-vCPU IPI testing with various destination
shorthands for Secure AVIC enabled VM.
- Patch 30 adds Hypervisor NMI injection and cross-vCPU ICR based NMI
for Secure AVIC enabled VM.
- Patch 31 adds MSI injection test for Secure AVIC enabled VM.
Neeraj Upadhyay (25):
KVM: selftests: Fix ghcb_entry returned in ghcb_alloc()
KVM: selftests: Make GHCB entry page size aligned
KVM: selftests: Add support for #VC in x86 exception handlers
KVM: selftests: Add MSR VC handling support for SEV-ES VMs
KVM: selftests: Skip vm_is_gpa_protected() call for APIC MMIO base
KVM: selftests: Add instruction decoding support
KVM: selftests: Add instruction decoding support
KVM: selftests: Add MMIO VC exception handling for SEV-ES guests
KVM: selftests: Add instruction decoding for movabs instructions
KVM: selftests: Add SEV guests support in xapic_state_test
KVM: selftests: Add x2apic mode testing in xapic_ipi_test
KVM: selftests: Add SEV VM support in xapic_ipi_test
KVM: selftests: Add Secure AVIC lib
KVM: selftests: Add unaccelerated APIC msrs #VC handling
KVM: selftests: Add IPI handling support for Secure AVIC
KVM: selftests: Add args param to kvm_arch_vm_post_create()
KVM: selftests: Add SAVIC GPA notification GHCB call
KVM: selftests: Add Secure AVIC mode to xapic_ipi_test
KVM: selftests: Add Secure AVIC APIC regs test
KVM: selftests: Add test to verify APIC MSR accesses for SAVIC guest
KVM: selftests: Extend savic test with idle halt testing
KVM: selftests: Add IOAPIC tests for Secure AVIC
KVM: selftests: Add cross-vCPU IPI testing for SAVIC guests
KVM: selftests: Add NMI test for SAVIC guests
KVM: selftests: Add MSI injection test for SAVIC
Peter Gonda (6):
Add GHCB with setters and getters
Add arch specific additional guest pages
Add vm_vaddr_alloc_pages_shared()
Add GHCB allocations and helpers
Add is_sev_enabled() helpers
Add ability for SEV-ES guests to use ucalls via GHCB
tools/arch/x86/include/asm/msr-index.h | 4 +-
tools/testing/selftests/kvm/.gitignore | 3 +-
tools/testing/selftests/kvm/Makefile.kvm | 16 +-
.../testing/selftests/kvm/include/kvm_util.h | 14 +-
.../testing/selftests/kvm/include/x86/apic.h | 57 +
.../selftests/kvm/include/x86/ex_regs.h | 21 +
.../selftests/kvm/include/x86/insn-eval.h | 48 +
.../selftests/kvm/include/x86/processor.h | 18 +-
.../testing/selftests/kvm/include/x86/savic.h | 25 +
tools/testing/selftests/kvm/include/x86/sev.h | 15 +
tools/testing/selftests/kvm/include/x86/svm.h | 109 ++
tools/testing/selftests/kvm/lib/kvm_util.c | 109 +-
.../testing/selftests/kvm/lib/x86/handlers.S | 4 +-
.../testing/selftests/kvm/lib/x86/insn-eval.c | 1726 +++++++++++++++++
.../testing/selftests/kvm/lib/x86/processor.c | 24 +-
tools/testing/selftests/kvm/lib/x86/savic.c | 490 +++++
tools/testing/selftests/kvm/lib/x86/sev.c | 598 +++++-
tools/testing/selftests/kvm/lib/x86/ucall.c | 18 +
tools/testing/selftests/kvm/s390/cmma_test.c | 2 +-
tools/testing/selftests/kvm/x86/savic_test.c | 1549 +++++++++++++++
.../selftests/kvm/x86/sev_smoke_test.c | 40 +-
.../selftests/kvm/x86/xapic_ipi_test.c | 183 +-
.../selftests/kvm/x86/xapic_state_test.c | 117 +-
23 files changed, 5084 insertions(+), 106 deletions(-)
create mode 100644 tools/testing/selftests/kvm/include/x86/ex_regs.h
create mode 100644 tools/testing/selftests/kvm/include/x86/insn-eval.h
create mode 100644 tools/testing/selftests/kvm/include/x86/savic.h
create mode 100644 tools/testing/selftests/kvm/lib/x86/insn-eval.c
create mode 100644 tools/testing/selftests/kvm/lib/x86/savic.c
create mode 100644 tools/testing/selftests/kvm/x86/savic_test.c
base-commit: f7bafceba76e9ab475b413578c1757ee18c3e44b
--
2.34.1
Hi all,
This patch series continues the work to migrate the *.sh tests into
prog_tests framework.
The test_tunnel.sh script has already been partly migrated to
test_progs in prog_tests/test_tunnel.c so I add my work to it.
PATCH 1 & 2 create some helpers to avoid code duplication and ease the
migration in the following patches.
PATCH 3 to 9 migrate the tests of gre, ip6gre, erspan, ip6erspan,
geneve, ip6geneve and ip6tnl tunnels.
PATCH 10 removes test_tunnel.sh
Signed-off-by: Bastien Curutchet (eBPF Foundation) <bastien.curutchet(a)bootlin.com>
---
Bastien Curutchet (eBPF Foundation) (10):
selftests/bpf: test_tunnel: Add generic_attach* helpers
selftests/bpf: test_tunnel: Add ping helpers
selftests/bpf: test_tunnel: Move gre tunnel test to test_progs
selftests/bpf: test_tunnel: Move ip6gre tunnel test to test_progs
selftests/bpf: test_tunnel: Move erspan tunnel tests to test_progs
selftests/bpf: test_tunnel: Move ip6erspan tunnel test to test_progs
selftests/bpf: test_tunnel: Move geneve tunnel test to test_progs
selftests/bpf: test_tunnel: Move ip6geneve tunnel test to test_progs
selftests/bpf: test_tunnel: Move ip6tnl tunnel tests to test_progs
selftests/bpf: test_tunnel: Remove test_tunnel.sh
tools/testing/selftests/bpf/Makefile | 1 -
.../testing/selftests/bpf/prog_tests/test_tunnel.c | 627 +++++++++++++++++---
tools/testing/selftests/bpf/test_tunnel.sh | 645 ---------------------
3 files changed, 532 insertions(+), 741 deletions(-)
---
base-commit: 16566afa71143757b49fc4b2a331639f487d105a
change-id: 20250131-tunnels-59b641ea3f10
Best regards,
--
Bastien Curutchet (eBPF Foundation) <bastien.curutchet(a)bootlin.com>
1. Issue
Syzkaller reported this issue [1].
2. Reproduce
We can reproduce this issue by using the test_sockmap_with_close_on_write()
test I provided in selftest, also you need to apply the following patch to
ensure 100% reproducibility (sleep after checking sock):
'''
static void sk_psock_verdict_data_ready(struct sock *sk)
{
.......
if (unlikely(!sock))
return;
+ if (!strcmp("test_progs", current->comm)) {
+ printk("sleep 2s to wait socket freed\n");
+ mdelay(2000);
+ printk("sleep end\n");
+ }
ops = READ_ONCE(sock->ops);
if (!ops || !ops->read_skb)
return;
}
'''
Then running './test_progs -v sockmap_basic', and if the kernel has KASAN
enabled [2], you will see the following warning:
'''
BUG: KASAN: slab-use-after-free in sk_psock_verdict_data_ready+0x29b/0x2d0
Read of size 8 at addr ffff88813a777020 by task test_progs/47055
Tainted: [O]=OOT_MODULE
Call Trace:
<TASK>
dump_stack_lvl+0x53/0x70
print_address_description.constprop.0+0x30/0x420
? sk_psock_verdict_data_ready+0x29b/0x2d0
print_report+0xb7/0x270
? sk_psock_verdict_data_ready+0x29b/0x2d0
? kasan_addr_to_slab+0xd/0xa0
? sk_psock_verdict_data_ready+0x29b/0x2d0
kasan_report+0xca/0x100
? sk_psock_verdict_data_ready+0x29b/0x2d0
sk_psock_verdict_data_ready+0x29b/0x2d0
unix_stream_sendmsg+0x4a6/0xa40
? __pfx_unix_stream_sendmsg+0x10/0x10
? fdget+0x2c1/0x3a0
__sys_sendto+0x39c/0x410
'''
3. Reason
'''
CPU0 CPU1
unix_stream_sendmsg(sk):
other = unix_peer(sk)
other->sk_data_ready(other):
socket *sock = sk->sk_socket
if (unlikely(!sock))
return;
close(other):
...
other->close()
free(socket)
READ_ONCE(sock->ops)
^
use 'sock' after free
'''
For TCP, UDP, or other protocols, we have already performed
rcu_read_lock() when the network stack receives packets in ip_input.c:
'''
ip_local_deliver_finish():
rcu_read_lock()
ip_protocol_deliver_rcu()
xxx_rcv
rcu_read_unlock()
'''
However, for Unix sockets, sk_data_ready is called directly from the
process context without rcu_read_lock() protection.
4. Solution
Based on the fact that the 'struct socket' is released using call_rcu(),
We add rcu_read_{un}lock() at the entrance and exit of our sk_data_ready.
It will not increase performance overhead, at least for TCP and UDP, they
are already in a relatively large critical section.
Of course, we can also add a custom callback for Unix sockets and call
rcu_read_lock() before calling _verdict_data_ready like this:
'''
if (sk_is_unix(sk))
sk->sk_data_ready = sk_psock_verdict_data_ready_rcu;
else
sk->sk_data_ready = sk_psock_verdict_data_ready;
sk_psock_verdict_data_ready_rcu():
rcu_read_lock()
sk_psock_verdict_data_ready()
rcu_read_unlock()
'''
However, this will cause too many branches, and it's not suitable to
distinguish network protocols in skmsg.c.
[1] https://syzkaller.appspot.com/bug?extid=dd90a702f518e0eac072
[2] https://syzkaller.appspot.com/text?tag=KernelConfig&x=1362a5aee630ff34
Jiayuan Chen (3):
bpf, sockmap: avoid using sk_socket after free
selftests/bpf: Add socketpair to create_pair to support unix socket
selftests/bpf: Add edge case tests for sockmap
net/core/skmsg.c | 18 ++++--
.../selftests/bpf/prog_tests/socket_helpers.h | 13 ++++-
.../selftests/bpf/prog_tests/sockmap_basic.c | 57 +++++++++++++++++++
3 files changed, 82 insertions(+), 6 deletions(-)
--
2.47.1
The GRO selftests can flake and have some confusing behavior. These
changes make the output and return value of GRO behave as expected, then
deflake the tests.
v2:
- Split into multiple commits.
- Reduced napi_defer_hard_irqs to 1.
- Reduced gro_flush_timeout to 100us.
- Fixed comment that wasn't updated.
v1: https://lore.kernel.org/netdev/20250218164555.1955400-1-krakauer@google.com/
Kevin Krakauer (3):
selftests/net: have `gro.sh -t` return a correct exit code
selftests/net: only print passing message in GRO tests when tests pass
selftests/net: deflake GRO tests
tools/testing/selftests/net/gro.c | 8 +++++---
tools/testing/selftests/net/gro.sh | 7 ++++---
tools/testing/selftests/net/setup_veth.sh | 3 ++-
3 files changed, 11 insertions(+), 7 deletions(-)
--
2.48.1.658.g4767266eb4-goog
There is a spelling mistake in a ksft_test_result_skip message. Fix it.
Signed-off-by: Colin Ian King <colin.i.king(a)gmail.com>
---
tools/testing/selftests/kvm/s390/cpumodel_subfuncs_test.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/kvm/s390/cpumodel_subfuncs_test.c b/tools/testing/selftests/kvm/s390/cpumodel_subfuncs_test.c
index 27255880dabd..aded795d42be 100644
--- a/tools/testing/selftests/kvm/s390/cpumodel_subfuncs_test.c
+++ b/tools/testing/selftests/kvm/s390/cpumodel_subfuncs_test.c
@@ -291,7 +291,7 @@ int main(int argc, char *argv[])
ksft_test_result_pass("%s\n", testlist[idx].subfunc_name);
free(array);
} else {
- ksft_test_result_skip("%s feature is not avaialable\n",
+ ksft_test_result_skip("%s feature is not available\n",
testlist[idx].subfunc_name);
}
}
--
2.47.2