From nobody Sat May 18 18:27:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1684773188; cv=none; d=zohomail.com; s=zohoarc; b=n1mhf/sNoWvCepOnr1gDMY4nehrdFa9oGz7qacc8k6wRtxjkHgKwhB+OaxenG3PNhzMZ5ZUc8HEH0mv7ofFOZ2yjTsy9Kl0ewaB5RfKC9RtMzlbXYukCsVgMkjsDG5GGbDdgtuUDCzOQsW976C1Tv6ORipg20HeE/Levg5Ld/Us= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684773188; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=x8tlFNuQZN9Wi00C4ghMAR+1duem5K1cRwccOkliQOI=; b=OndnWpcP6uGzCbZx81FYBHi5EbQVZcl4ZGNLjXj7nkt6lReTpeJ0yInmt66yp31zSA+nvLKSJuHSnPHxN8l86l0dy9vg0LxKltkcRlmw4TIFQdSDagqlngLlJoeW5BtkND+lXyazf+DaK5aU2Cr3V4Xj4UL4afvOuoa9gYRv48Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1684773188588188.03405220310697; Mon, 22 May 2023 09:33:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q18SR-0007xN-Eh; Mon, 22 May 2023 12:32:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q18SP-0007x3-1d for qemu-devel@nongnu.org; Mon, 22 May 2023 12:32:25 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q18SM-00073X-Rl for qemu-devel@nongnu.org; Mon, 22 May 2023 12:32:24 -0400 Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-2554696544cso1392195a91.2 for ; Mon, 22 May 2023 09:32:21 -0700 (PDT) Received: from localhost.localdomain ([113.173.119.15]) by smtp.googlemail.com with ESMTPSA id s5-20020a17090a2f0500b0025393752cd5sm12293253pjd.1.2023.05.22.09.32.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 May 2023 09:32:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684773140; x=1687365140; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=x8tlFNuQZN9Wi00C4ghMAR+1duem5K1cRwccOkliQOI=; b=lgSXRRn8HlfKOfvPzRwsWpwSCgP8umQEq6rfKU+2aRCVf28T1EI1PF5WATq0ZrrXp0 YBquZWynfMCEw0ZSHI3DaI+SDs2uH0NL9UvHH5s7VRBdaF5U1+DNLZflDp9zB8aEiz/o IedIuY5XtO4Oxd+d3CjOQjtDbo8bnKHKmUJcizCmUQDjuJgQ2Qac+tEf4nkX6GVjB8ua Vv0Z7hQTF8e6BB9XJcLG7Sy7ZS8zFKfGyd4ivVCvPvhYhHoL+pN6x6Gewc5+yX27HC2C pqZEbQQoihBWui1uOtkjPrftaWzVb7xkzzelsPI3JZtuH3iHO9N+oG3L5Awmv77WJzmV I2FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684773140; x=1687365140; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=x8tlFNuQZN9Wi00C4ghMAR+1duem5K1cRwccOkliQOI=; b=TsfnkjdFdHL88sP8EzUwS6yGgUO1k+EjFb4QPQu5X91nLwxik7dws7nqbpqRmqirI/ vhXsZjAxKwVdF7y8kzcitLtbZiYElYI+i7/FewFMm143ZqUszseqZHP7013wPOQjAJKj 8DZnnM0Q+GocR8G53jVHB00jErqDdRlGkjOVeFtmH1rit4iQwDGfbSH1FonFOGUACY+P sOJupFKZY1jxUfAB84Q3jKjYSjVE2KBkQ6LgYDOPJ1I13SHJ5JfbZvlCl+PfSN3MIhRR leGDXFD58YHyRcG/wRlxCM3ag4+zMJ0V1Rd9UqyHze+u31ck958sbjhvQRbhFGmoLBZ1 fttg== X-Gm-Message-State: AC+VfDywcKZ6242zwlJiuv53M6sGGjfG31L3P78igEoq2owZq2GqcMAc DCdelZm+KCmVm1xmA5QISUQ8Nlqlntk= X-Google-Smtp-Source: ACHHUZ5ctRWAQhfPX0WqrlMNvHzppzlVSXBm4oHIY2ZQJPqu51zWy+C4XApnudYtH9sR/tSs3lONWg== X-Received: by 2002:a17:90a:e150:b0:253:8260:f9aa with SMTP id ez16-20020a17090ae15000b002538260f9aamr9377188pjb.6.1684773139930; Mon, 22 May 2023 09:32:19 -0700 (PDT) From: Bui Quang Minh To: qemu-devel@nongnu.org Cc: David Woodhouse , Paolo Bonzini , Richard Henderson , Eduardo Habkost , "Michael S . Tsirkin" , Marcel Apfelbaum , Igor Mammedov , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Bui Quang Minh Subject: [PATCH v4 0/5] Support x2APIC mode with TCG accelerator Date: Mon, 22 May 2023 23:31:52 +0700 Message-Id: <20230522163157.9754-1-minhquangbui99@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=minhquangbui99@gmail.com; helo=mail-pj1-x1035.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1684773189454100001 Content-Type: text/plain; charset="utf-8" Hi everyone, This series implements x2APIC mode in userspace local APIC and the RDMSR/WRMSR helper to access x2APIC registers in x2APIC mode. Intel iommu and AMD iommu are adjusted to support x2APIC interrupt remapping. With this series, we can now boot Linux kernel into x2APIC mode with TCG accelerator using either Intel or AMD iommu. Testing to boot my own built Linux 6.3.0-rc2, the kernel successfully boot with enabled x2APIC and can enumerate CPU with APIC ID 257 Using Intel IOMMU qemu/build/qemu-system-x86_64 \ -smp 2,maxcpus=3D260 \ -cpu qemu64,x2apic=3Don \ -machine q35 \ -device intel-iommu,intremap=3Don,eim=3Don \ -device qemu64-x86_64-cpu,x2apic=3Don,core-id=3D257,socket-id=3D0,thread-= id=3D0 \ -m 2G \ -kernel $KERNEL_DIR \ -append "nokaslr console=3DttyS0 root=3D/dev/sda earlyprintk=3Dserial net= .ifnames=3D0" \ -drive file=3D$IMAGE_DIR,format=3Draw \ -nographic \ -s Using AMD IOMMU qemu/build/qemu-system-x86_64 \ -smp 2,maxcpus=3D260 \ -cpu qemu64,x2apic=3Don \ -machine q35 \ -device amd-iommu,intremap=3Don,xtsup=3Don \ -device qemu64-x86_64-cpu,x2apic=3Don,core-id=3D257,socket-id=3D0,thread-= id=3D0 \ -m 2G \ -kernel $KERNEL_DIR \ -append "nokaslr console=3DttyS0 root=3D/dev/sda earlyprintk=3Dserial net= .ifnames=3D0" \ -drive file=3D$IMAGE_DIR,format=3Draw \ -nographic \ -s Testing the emulated userspace APIC with kvm-unit-tests, disable test device with this patch diff --git a/lib/x86/fwcfg.c b/lib/x86/fwcfg.c index 1734afb..f56fe1c 100644 --- a/lib/x86/fwcfg.c +++ b/lib/x86/fwcfg.c @@ -27,6 +27,7 @@ static void read_cfg_override(void) =20 if ((str =3D getenv("TEST_DEVICE"))) no_test_device =3D !atol(str); + no_test_device =3D true; =20 if ((str =3D getenv("MEMLIMIT"))) fw_override[FW_CFG_MAX_RAM] =3D atol(str) * 1024 * 1024; ~ env QEMU=3D/home/minh/Desktop/oss/qemu/build/qemu-system-x86_64 ACCEL=3Dt= cg \ ./run_tests.sh -v -g apic=20 TESTNAME=3Dapic-split TIMEOUT=3D90s ACCEL=3Dtcg ./x86/run x86/apic.flat -sm= p 2 -cpu qemu64,+x2apic,+tsc-deadline -machine kernel_irqchip=3Dsplit FAIL apic-split (54 tests, 8 unexpected failures, 1 skipped) TESTNAME=3Dioapic-split TIMEOUT=3D90s ACCEL=3Dtcg ./x86/run x86/ioapic.flat= -smp 1 -cpu qemu64 -machine kernel_irqchip=3Dsplit PASS ioapic-split (19 tests) TESTNAME=3Dx2apic TIMEOUT=3D30 ACCEL=3Dtcg ./x86/run x86/apic.flat -smp 2 -= cpu qemu64,+x2apic,+tsc-deadline FAIL x2apic (54 tests, 8 unexpected failures, 1 skipped) TESTNAME=3Dxapic TIMEOUT=3D60 ACCEL=3Dtcg ./x86/run x86/apic.fla= t -smp 2 -cpu qemu64,-x2apic,+tsc-deadline -machine pit=3Doff FAIL xapic (43 tests, 6 unexpected failures, 2 skipped) FAIL: apic_disable: *0xfee00030: 50014 FAIL: apic_disable: *0xfee00080: f0 FAIL: apic_disable: *0xfee00030: 50014 FAIL: apic_disable: *0xfee00080: f0=20 FAIL: apicbase: relocate apic These errors are because we don't disable MMIO region when switching to x2APIC and don't support relocate MMIO region yet. This is a problem because, MMIO region is the same for all CPUs, in order to support these we need to figure out how to allocate and manage different MMIO regions for each CPUs. This can be an improvement in the future. FAIL: nmi-after-sti FAIL: multiple nmi These errors are in the way we handle CPU_INTERRUPT_NMI in core TCG. FAIL: TMCCT should stay at zero This error is related to APIC timer which should be addressed in separate patch. Version 4 changes, - Patch 5: + Instead of replacing IVHD type 0x10 with type 0x11, export both types for backward compatibility with old guest operating system + Flip the xtsup feature check condition in amdvi_int_remap_ga for readability Version 3 changes, - Patch 2: + Allow APIC ID > 255 only when x2APIC feature is supported on CPU + Make physical destination mode IPI which has destination id 0xffffffff a broadcast to xAPIC CPUs + Make cluster address 0xf in cluster model of xAPIC logical destination mode a broadcast to all clusters + Create new extended_log_dest to store APIC_LDR information in x2APIC instead of extending log_dest for backward compatibility in vmstate Version 2 changes, - Add support for APIC ID larger than 255 - Adjust AMD iommu for x2APIC suuport - Reorganize and split patch 1,2 into patch 1,2,3 in version 2 Thanks, Quang Minh. Bui Quang Minh (5): i386/tcg: implement x2APIC registers MSR access apic: add support for x2APIC mode apic, i386/tcg: add x2apic transitions intel_iommu: allow Extended Interrupt Mode when using userspace APIC amd_iommu: report x2APIC support to the operating system hw/i386/acpi-build.c | 127 +++++---- hw/i386/amd_iommu.c | 21 +- hw/i386/amd_iommu.h | 16 +- hw/i386/intel_iommu.c | 11 - hw/i386/x86.c | 8 +- hw/intc/apic.c | 395 +++++++++++++++++++++------ hw/intc/apic_common.c | 16 +- hw/intc/trace-events | 4 +- include/hw/i386/apic.h | 6 +- include/hw/i386/apic_internal.h | 7 +- target/i386/cpu-sysemu.c | 18 +- target/i386/cpu.c | 5 +- target/i386/cpu.h | 9 + target/i386/tcg/sysemu/misc_helper.c | 31 +++ 14 files changed, 500 insertions(+), 174 deletions(-) --=20 2.25.1