Commit Graph
100 Commits
Author SHA1 Message Date
Prarit Bhargava afadb51220 dma-mapping: fix missing clear bdr in check_ram_in_range_map()
JIRA: https://issues.redhat.com/browse/RHEL-128293

commit 8324993f60305e50f27b98358b01b9837e10d159
Author: Baochen Qiang <quic_bqiang@quicinc.com>
Date:   Fri Mar 7 11:03:50 2025 +0800

    dma-mapping: fix missing clear bdr in check_ram_in_range_map()

    As discussed in [1], if 'bdr' is set once, it would never get
    cleared, hence 0 is always returned.

    Refactor the range check hunk into a new helper dma_find_range(),
    which allows 'bdr' to be cleared in each iteration.

    Link: https://lore.kernel.org/all/64931fac-085b-4ff3-9314-84bac2fa9bdb@quicinc.com/ # [1]
    Fixes: a409d9600959 ("dma-mapping: fix dma_addressing_limited() if dma_range_map can't cover all system RAM")
    Suggested-by: Christoph Hellwig <hch@lst.de>
    Signed-off-by: Baochen Qiang <quic_bqiang@quicinc.com>
    Link: https://lore.kernel.org/r/20250307030350.69144-1-quic_bqiang@quicinc.com
    Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2025-11-13 10:20:44 -05:00
Prarit Bhargava 1f2bcdbb14 dma/mapping.c: dev_dbg support for dma_addressing_limited
JIRA: https://issues.redhat.com/browse/RHEL-117031

commit 2042c352e21d19eaf5f9e22fb6afce72293ef28c
Author: Balbir Singh <balbirs@nvidia.com>
Date:   Mon Apr 14 21:37:52 2025 +1000

    dma/mapping.c: dev_dbg support for dma_addressing_limited

    In the debug and resolution of an issue involving forced use of bounce
    buffers, 7170130e4c72 ("x86/mm/init: Handle the special case of device
    private pages in add_pages(), to not increase max_pfn and trigger
    dma_addressing_limited() bounce buffers"). It would have been easier
    to debug the issue if dma_addressing_limited() had debug information
    about the device not being able to address all of memory and thus forcing
    all accesses through a bounce buffer. Please see[2]

    Implement dev_dbg to debug the potential use of bounce buffers
    when we hit the condition. When swiotlb is used,
    dma_addressing_limited() is used to determine the size of maximum dma
    buffer size in dma_direct_max_mapping_size(). The debug prints could be
    triggered in that check as well (when enabled).

    Link: https://lore.kernel.org/lkml/20250401000752.249348-1-balbirs@nvidia.com/ [1]
    Link: https://lore.kernel.org/lkml/20250310112206.4168-1-spasswolf@web.de/ [2]

    Cc: Marek Szyprowski <m.szyprowski@samsung.com>
    Cc: Robin Murphy <robin.murphy@arm.com>
    Cc: "Christian König" <christian.koenig@amd.com>
    Cc: Ingo Molnar <mingo@kernel.org>
    Cc: Kees Cook <kees@kernel.org>
    Cc: Bjorn Helgaas <bhelgaas@google.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Andy Lutomirski <luto@kernel.org>
    Cc: Alex Deucher <alexander.deucher@amd.com>
    Cc: Bert Karwatzki <spasswolf@web.de>
    Cc: Christoph Hellwig <hch@infradead.org>

    Signed-off-by: Balbir Singh <balbirs@nvidia.com>
    Reviewed-by: Christoph Hellwig <hch@lst.de>
    Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
    Link: https://lore.kernel.org/r/20250414113752.3298276-1-balbirs@nvidia.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2025-10-09 09:51:17 -04:00
Prarit Bhargava 468ad76bdc x86/mm/init: Handle the special case of device private pages in add_pages(), to not increase max_pfn and trigger dma_addressing_limited() bounce buffers
JIRA: https://issues.redhat.com/browse/RHEL-117031

commit 7170130e4c72ce0caa0cb42a1627c635cc262821
Author: Balbir Singh <balbirs@nvidia.com>
Date:   Tue Apr 1 11:07:52 2025 +1100

    x86/mm/init: Handle the special case of device private pages in add_pages(), to not increase max_pfn and trigger dma_addressing_limited() bounce buffers

    As Bert Karwatzki reported, the following recent commit causes a
    performance regression on AMD iGPU and dGPU systems:

      7ffb791423c7 ("x86/kaslr: Reduce KASLR entropy on most x86 systems")

    It exposed a bug with nokaslr and zone device interaction.

    The root cause of the bug is that, the GPU driver registers a zone
    device private memory region. When KASLR is disabled or the above commit
    is applied, the direct_map_physmem_end is set to much higher than 10 TiB
    typically to the 64TiB address. When zone device private memory is added
    to the system via add_pages(), it bumps up the max_pfn to the same
    value. This causes dma_addressing_limited() to return true, since the
    device cannot address memory all the way up to max_pfn.

    This caused a regression for games played on the iGPU, as it resulted in
    the DMA32 zone being used for GPU allocations.

    Fix this by not bumping up max_pfn on x86 systems, when pgmap is passed
    into add_pages(). The presence of pgmap is used to determine if device
    private memory is being added via add_pages().

    More details:

    devm_request_mem_region() and request_free_mem_region() request for
    device private memory. iomem_resource is passed as the base resource
    with start and end parameters. iomem_resource's end depends on several
    factors, including the platform and virtualization. On x86 for example
    on bare metal, this value is set to boot_cpu_data.x86_phys_bits.
    boot_cpu_data.x86_phys_bits can change depending on support for MKTME.
    By default it is set to the same as log2(direct_map_physmem_end) which
    is 46 to 52 bits depending on the number of levels in the page table.
    The allocation routines used iomem_resource's end and
    direct_map_physmem_end to figure out where to allocate the region.

    [ arch/powerpc is also impacted by this problem, but this patch does not fix
      the issue for PowerPC. ]

    Testing:

     1. Tested on a virtual machine with test_hmm for zone device inseration

     2. A previous version of this patch was tested by Bert, please see:
        https://lore.kernel.org/lkml/d87680bab997fdc9fb4e638983132af235d9a03a.camel@web.de/

    [ mingo: Clarified the comments and the changelog. ]

    Reported-by: Bert Karwatzki <spasswolf@web.de>
    Tested-by: Bert Karwatzki <spasswolf@web.de>
    Fixes: 7ffb791423c7 ("x86/kaslr: Reduce KASLR entropy on most x86 systems")
    Signed-off-by: Balbir Singh <balbirs@nvidia.com>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Cc: Brian Gerst <brgerst@gmail.com>
    Cc: Juergen Gross <jgross@suse.com>
    Cc: H. Peter Anvin <hpa@zytor.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: Christoph Hellwig <hch@lst.de>
    Cc: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
    Cc: Alex Deucher <alexander.deucher@amd.com>
    Cc: Christian König <christian.koenig@amd.com>
    Cc: David Airlie <airlied@gmail.com>
    Cc: Simona Vetter <simona@ffwll.ch>
    Link: https://lore.kernel.org/r/20250401000752.249348-1-balbirs@nvidia.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2025-10-09 09:51:16 -04:00
Prarit Bhargava 1c159eea87 x86/kaslr: Reduce KASLR entropy on most x86 systems
JIRA: https://issues.redhat.com/browse/RHEL-117031

commit 7ffb791423c7c518269a9aad35039ef824a40adb
Author: Balbir Singh <balbirs@nvidia.com>
Date:   Fri Feb 7 10:42:34 2025 +1100

    x86/kaslr: Reduce KASLR entropy on most x86 systems

    When CONFIG_PCI_P2PDMA=y (which is basically enabled on all
    large x86 distros), it maps the PFN's via a ZONE_DEVICE
    mapping using devm_memremap_pages(). The mapped virtual
    address range corresponds to the pci_resource_start()
    of the BAR address and size corresponding to the BAR length.

    When KASLR is enabled, the direct map range of the kernel is
    reduced to the size of physical memory plus additional padding.
    If the BAR address is beyond this limit, PCI peer to peer DMA
    mappings fail.

    Fix this by not shrinking the size of the direct map when
    CONFIG_PCI_P2PDMA=y.

    This reduces the total available entropy, but it's better than
    the current work around of having to disable KASLR completely.

    [ mingo: Clarified the changelog to point out the broad impact ... ]

    Signed-off-by: Balbir Singh <balbirs@nvidia.com>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Reviewed-by: Kees Cook <kees@kernel.org>
    Acked-by: Bjorn Helgaas <bhelgaas@google.com> # drivers/pci/Kconfig
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Andy Lutomirski <luto@kernel.org>
    Link: https://lore.kernel.org/lkml/20250206023201.1481957-1-balbirs@nvidia.com/
    Link: https://lore.kernel.org/r/20250206234234.1912585-1-balbirs@nvidia.com
    --
     arch/x86/mm/kaslr.c | 10 ++++++++--
     drivers/pci/Kconfig |  6 ++++++
     2 files changed, 14 insertions(+), 2 deletions(-)

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2025-10-09 09:51:16 -04:00
Prarit Bhargava c26709452f redhat/self-test: Remove --all from git query
JIRA: INTERNAL
Upstream status: RHEL Only

It was reported that executing this test on an older tag failed.  This
occurs because the git query to find the most recent "[redhat] kernel"
commit looks at the entire git history instead of the branch's history.

Removing the '--all' from the "[redhat] kernel" lookup resolves this
problem.

Testing:

There are 3 cases that I considered which all succeed with this change:

1.  running on os-build or ark-latest

        git co origin/os-build
        RHEL_MAJOR=9 RHEL_MINOR=99 bats redhat/self-test/2001-dist-release.bats

2.  a new branch based on os-build/ark-latest

        git co origin/ark-latest
        git checkout -b junk
        /# make some changes
        RHEL_MAJOR=9 RHEL_MINOR=99 bats redhat/self-test/2001-dist-release.bats

3.  an older branch based on a tag

        git co kernel-6.6.0-0.rc7.56567a20b22b.59
        RHEL_MAJOR=9 RHEL_MINOR=99 bats redhat/self-test/2001-dist-release.bats

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
(cherry picked from commit b1e1a63126003b829e28e012e1b8f87eafbbae4d)
Signed-off-by: Patrick Talbert <ptalbert@redhat.com>
2025-03-05 05:58:50 -05:00
Prarit Bhargava a1b258207d Merge branch 'switch_prarit_to_reviewer' into 'main'
info/owners.yaml: switch prarit to reviewer

See merge request redhat/centos-stream/src/kernel/documentation!682
2024-05-08 13:18:25 +00:00
Prarit Bhargava 8c0d1f9e2d info/owners.yaml: switch prarit to reviewer
Switch prarit to reviewer for many areas.

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-05-07 14:48:08 -04:00
Prarit Bhargava 9345940d07 Merge branch 'remove_prarit_from_disabled' into 'main'
info/owners.yaml: Remove prarit from certain areas

See merge request redhat/centos-stream/src/kernel/documentation!681
2024-05-07 18:42:32 +00:00
Prarit Bhargava c68fb883e8 info/owners.yaml: Remove prarit from certain areas
Remove prarit from certain areas of maintainership.

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-05-07 14:39:15 -04:00
Prarit Bhargava 072b860946 x86/tsc: Trust initial offset in architectural TSC-adjust MSRs
JIRA: https://issues.redhat.com/browse/RHEL-29437
Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git

commit 455f9075f14484f358b3c1d6845b4a438de198a7
Author: Daniel J Blueman <daniel@quora.org>
Date:   Fri Apr 19 16:51:46 2024 +0800

    x86/tsc: Trust initial offset in architectural TSC-adjust MSRs

    When the BIOS configures the architectural TSC-adjust MSRs on secondary
    sockets to correct a constant inter-chassis offset, after Linux brings the
    cores online, the TSC sync check later resets the core-local MSR to 0,
    triggering HPET fallback and leading to performance loss.

    Fix this by unconditionally using the initial adjust values read from the
    MSRs. Trusting the initial offsets in this architectural mechanism is a
    better approach than special-casing workarounds for specific platforms.

    Signed-off-by: Daniel J Blueman <daniel@quora.org>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Reviewed-by: Steffen Persvold <sp@numascale.com>
    Reviewed-by: James Cleverdon <james.cleverdon.external@eviden.com>
    Reviewed-by: Dimitri Sivanich <sivanich@hpe.com>
    Reviewed-by: Prarit Bhargava <prarit@redhat.com>
    Link: https://lore.kernel.org/r/20240419085146.175665-1-daniel@quora.org

Omitted-fix: 7598293ab37c ("Merge branch into tip/master: 'x86/timers'")
	- only a mention of the commit being merged, not a bug or patch

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-05-07 09:51:02 -04:00
Prarit Bhargava a8f718748f arch/x86: Fix XSAVE check for x86_64-v2 check
JIRA: https://issues.redhat.com/browse/RHEL-22439
Upstream Status: RHEL only, https://gitlab.com/cki-project/kernel-ark

commit e178d550963b1ae5f80cf21e7ebb0ea4a8371ec5
Author: Prarit Bhargava <prarit@redhat.com>
Date:   Tue Apr 2 07:39:22 2024 -0400

    arch/x86: Fix XSAVE check for x86_64-v2 check

    The flag check should be XSAVE, not OSXSAVE.

    Signed-off-by: Prarit Bhargava <prarit@redhat.com>

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-05-01 09:19:40 -04:00
Prarit Bhargava 60addc769a arch/x86: mark x86_64-v1 and x86_64-v2 processors as deprecated
JIRA: https://issues.redhat.com/browse/RHEL-22439
Upstream Status: RHEL only, https://gitlab.com/cki-project/kernel-ark

commit 917edb952c84e83066447f2dae05c2a92d93c702
Author: Prarit Bhargava <prarit@redhat.com>
Date:   Thu Jan 25 14:47:16 2024 -0500

    arch/x86: mark x86_64-v1 and x86_64-v2 processors as deprecated

    Upstream Status: RHEL only

    The x86 industry has defined microarchitecture levels x86_64-v1 and
    x86_64-v2 as defined here:

            https://en.wikipedia.org/wiki/X86-64#Microarchitecture_levels

    RHEL9 has a minimum of the x86_64-v2 microarchitecture and RHEL10 has a
    minimum of the x86_64-v3 microarchitecture.

    Mark x86_64-v1 and x86_64-v2 processors as deprecated.

    Signed-off-by: Prarit Bhargava <prarit@redhat.com>

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-05-01 09:19:18 -04:00
Prarit Bhargava 207cd23bb4 info/owners.yaml: Add Intel CET entry
Add an entry for Intel Control-flow Enforcement (CET).

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-04-23 10:30:54 -04:00
Prarit Bhargava 9f4c3ed1a7 Merge branch 'remove_mr_testing_requirement' into 'main'
CommitRules.adoc: Remove testing requirement in MR description

See merge request redhat/centos-stream/src/kernel/documentation!666
2024-04-19 16:51:13 +00:00
Prarit Bhargava 16aa5be0ea CommitRules.adoc: Remove testing requirement in MR description
With the new process of using Jira to track testing, there is no longer a
requirement to include testing results in the MR description.  MR authors
could include them but with the well-defined testing procedure outlined in
Jira tickets it's no longer necessary.

Remove the testing requirement in the MR description.  This results in a
reorganization of the links in the CommitRules.

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-04-12 13:05:51 -04:00
Prarit Bhargava eaa810531a Merge branch 'depends_tag' into 'main'
CommitRules: limit Depends: tag references to MR URLs only

See merge request redhat/centos-stream/src/kernel/documentation!663
2024-04-10 12:28:56 +00:00
Prarit Bhargava abad7b8840 x86/nmi: Fix the inverse "in NMI handler" check
JIRA: https://issues.redhat.com/browse/RHEL-30106

commit d54e56f31a34fa38fcb5e91df609f9633419a79a
Author: Breno Leitao <leitao@debian.org>
Date:   Wed Feb 7 08:52:35 2024 -0800

    x86/nmi: Fix the inverse "in NMI handler" check

    Commit 344da544f177 ("x86/nmi: Print reasons why backtrace NMIs are
    ignored") creates a super nice framework to diagnose NMIs.

    Every time nmi_exc() is called, it increments a per_cpu counter
    (nsp->idt_nmi_seq). At its exit, it also increments the same counter.  By
    reading this counter it can be seen how many times that function was called
    (dividing by 2), and, if the function is still being executed, by checking
    the idt_nmi_seq's least significant bit.

    On the check side (nmi_backtrace_stall_check()), that variable is queried
    to check if the NMI is still being executed, but, there is a mistake in the
    bitwise operation. That code wants to check if the least significant bit of
    the idt_nmi_seq is set or not, but does the opposite, and checks for all
    the other bits, which will always be true after the first exc_nmi()
    executed successfully.

    This appends the misleading string to the dump "(CPU currently in NMI
    handler function)"

    Fix it by checking the least significant bit, and if it is set, append the
    string.

    Fixes: 344da544f177 ("x86/nmi: Print reasons why backtrace NMIs are ignored")
    Signed-off-by: Breno Leitao <leitao@debian.org>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Reviewed-by: Paul E. McKenney <paulmck@kernel.org>
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20240207165237.1048837-1-leitao@debian.org

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-27 14:04:41 -04:00
Prarit Bhargava 3f5dbfac57 serial: 8250: Toggle IER bits on only after irq has been set up
JIRA: https://issues.redhat.com/browse/RHEL-30355

commit 039d4926379b1d1c17b51cf21c500a5eed86899e
Author: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date:   Thu Sep 22 10:00:05 2022 +0300

    serial: 8250: Toggle IER bits on only after irq has been set up

    Invoking TIOCVHANGUP on 8250_mid port on Ice Lake-D and then reopening
    the port triggers these faults during serial8250_do_startup():

      DMAR: DRHD: handling fault status reg 3
      DMAR: [DMA Write NO_PASID] Request device [00:1a.0] fault addr 0x0 [fault reason 0x05] PTE Write access is not set

    If the IRQ hasn't been set up yet, the UART will have zeroes in its MSI
    address/data registers. Disabling the IRQ at the interrupt controller
    won't stop the UART from performing a DMA write to the address programmed
    in its MSI address register (zero) when it wants to signal an interrupt.

    The UARTs (in Ice Lake-D) implement PCI 2.1 style MSI without masking
    capability, so there is no way to mask the interrupt at the source PCI
    function level, except disabling the MSI capability entirely, but that
    would cause it to fall back to INTx# assertion, and the PCI specification
    prohibits disabling the MSI capability as a way to mask a function's
    interrupt service request.

    The MSI address register is zeroed by the hangup as the irq is freed.
    The interrupt is signalled during serial8250_do_startup() performing a
    THRE test that temporarily toggles THRI in IER. The THRE test currently
    occurs before UART's irq (and MSI address) is properly set up.

    Refactor serial8250_do_startup() such that irq is set up before the
    THRE test. The current irq setup code is intermixed with the timer
    setup code. As THRE test must be performed prior to the timer setup,
    extract it into own function and call it only after the THRE test.

    The ->setup_timer() needs to be part of the struct uart_8250_ops in
    order to not create circular dependency between 8250 and 8250_base
    modules.

    Fixes: 40b36daad0 ("[PATCH] 8250 UART backup timer")
    Reported-by: Lennert Buytenhek <buytenh@arista.com>
    Tested-by: Lennert Buytenhek <buytenh@arista.com>
    Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
    Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
    Link: https://lore.kernel.org/r/20220922070005.2965-1-ilpo.jarvinen@linux.intel.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-26 12:11:41 -04:00
Prarit Bhargava 08de1f2c82 Merge branch '240312+193927' into 'main'
facelift jira cli and menu

See merge request redhat/centos-stream/src/kernel/documentation!647
2024-03-25 19:10:36 +00:00
Prarit Bhargava 9039f87431 KVM: x86: Add X86EMUL_F_INVLPG and pass it in em_invlpg()
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 538ac9a92d669c4ccfc64739a32efab2793cea1d
Author: Binbin Wu <binbin.wu@linux.intel.com>
Date:   Wed Sep 13 20:42:15 2023 +0800

    KVM: x86: Add X86EMUL_F_INVLPG and pass it in em_invlpg()

    Add an emulation flag X86EMUL_F_INVLPG, which is used to identify an
    instruction that does TLB invalidation without true memory access.

    Only invlpg & invlpga implemented in emulator belong to this kind.
    invlpga doesn't need additional information for emulation. Just pass
    the flag to em_invlpg().

    Linear Address Masking (LAM) and Linear Address Space Separation (LASS)
    don't apply to addresses that are inputs to TLB invalidation. The flag
    will be consumed to support LAM/LASS virtualization.

    Signed-off-by: Binbin Wu <binbin.wu@linux.intel.com>
    Tested-by: Xuelian Guo <xuelian.guo@intel.com>
    Link: https://lore.kernel.org/r/20230913124227.12574-5-binbin.wu@linux.intel.com
    Signed-off-by: Sean Christopherson <seanjc@google.com>

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:37 -04:00
Prarit Bhargava 5d469bedb8 KVM: x86: Add an emulation flag for implicit system access
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 3963c52df42231f72277cd138994ac94f1183d2b
Author: Binbin Wu <binbin.wu@linux.intel.com>
Date:   Wed Sep 13 20:42:14 2023 +0800

    KVM: x86: Add an emulation flag for implicit system access

    Add an emulation flag X86EMUL_F_IMPLICIT to identify implicit system access
    in instruction emulation.  Don't bother wiring up any usage at this point,
    as Linear Address Space Separation (LASS) will be the first "real" consumer
    of the flag and LASS support will require dedicated hooks, i.e. there
    aren't any existing calls where passing X86EMUL_F_IMPLICIT is meaningful.

    Add the IMPLICIT flag even though there's no imminent usage so that
    Linear Address Masking (LAM) support can reference the flag to document
    that addresses for implicit accesses aren't untagged.

    Signed-off-by: Binbin Wu <binbin.wu@linux.intel.com>
    Tested-by: Xuelian Guo <xuelian.guo@intel.com>
    Link: https://lore.kernel.org/r/20230913124227.12574-4-binbin.wu@linux.intel.com
    Signed-off-by: Sean Christopherson <seanjc@google.com>

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:37 -04:00
Prarit Bhargava 6164743be3 KVM: x86: Consolidate flags for __linearize()
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 7b0dd9430cf0c1ae19645d2a6608a5fb57faffe4
Author: Binbin Wu <binbin.wu@linux.intel.com>
Date:   Wed Sep 13 20:42:12 2023 +0800

    KVM: x86: Consolidate flags for __linearize()

    Consolidate @write and @fetch of __linearize() into a set of flags so that
    additional flags can be added without needing more/new boolean parameters,
    to precisely identify the access type.

    No functional change intended.

    Signed-off-by: Binbin Wu <binbin.wu@linux.intel.com>
    Reviewed-by: Chao Gao <chao.gao@intel.com>
    Acked-by: Kai Huang <kai.huang@intel.com>
    Tested-by: Xuelian Guo <xuelian.guo@intel.com>
    Link: https://lore.kernel.org/r/20230913124227.12574-2-binbin.wu@linux.intel.com
    Signed-off-by: Sean Christopherson <seanjc@google.com>

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:37 -04:00
Prarit Bhargava 273a8a4874 x86/MCE/AMD: Add new MA_LLC, USR_DP, and USR_CP bank types
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 47b744ea5e3cf855087951a74ba9f89180fa1ba5
Author: Muralidhara M K <muralidhara.mk@amd.com>
Date:   Thu Nov 2 11:42:23 2023 +0000

    x86/MCE/AMD: Add new MA_LLC, USR_DP, and USR_CP bank types

    Add HWID and McaType values for new SMCA bank types.

    Signed-off-by: Muralidhara M K <muralidhara.mk@amd.com>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231102114225.2006878-3-muralimk@amd.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:37 -04:00
Prarit Bhargava e9d5e0c82f x86/Kconfig: Remove obsolete config X86_32_SMP
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit c64545594daf748422fa083389b062d0a16fb477
Author: Lukas Bulwahn <lukas.bulwahn@gmail.com>
Date:   Tue Nov 28 10:00:16 2023 +0100

    x86/Kconfig: Remove obsolete config X86_32_SMP

    Commit

      0f08c3b229 ("x86/smp: Reduce code duplication")

    removed the only use of CONFIG_X86_32_SMP.

    Remove the now obsolete config X86_32_SMP too.

    Signed-off-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231128090016.29676-1-lukas.bulwahn@gmail.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:37 -04:00
Prarit Bhargava 582571c027 x86/xen: add CPU dependencies for 32-bit build
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 93cd0597649844a0fe7989839a3202735fb3ae67
Author: Arnd Bergmann <arnd@arndb.de>
Date:   Mon Dec 4 09:47:01 2023 +0100

    x86/xen: add CPU dependencies for 32-bit build

    Xen only supports modern CPUs even when running a 32-bit kernel, and it now
    requires a kernel built for a 64 byte (or larger) cache line:

    In file included from <command-line>:
    In function 'xen_vcpu_setup',
        inlined from 'xen_vcpu_setup_restore' at arch/x86/xen/enlighten.c:111:3,
        inlined from 'xen_vcpu_restore' at arch/x86/xen/enlighten.c:141:3:
    include/linux/compiler_types.h:435:45: error: call to '__compiletime_assert_287' declared with attribute error: BUILD_BUG_ON failed: sizeof(*vcpup) > SMP_CACHE_BYTES
    arch/x86/xen/enlighten.c:166:9: note: in expansion of macro 'BUILD_BUG_ON'
      166 |         BUILD_BUG_ON(sizeof(*vcpup) > SMP_CACHE_BYTES);
          |         ^~~~~~~~~~~~

    Enforce the dependency with a whitelist of CPU configurations. In normal
    distro kernels, CONFIG_X86_GENERIC is enabled, and this works fine. When this
    is not set, still allow Xen to be built on kernels that target a 64-bit
    capable CPU.

    Fixes: db2832309a82 ("x86/xen: fix percpu vcpu_info allocation")
    Signed-off-by: Arnd Bergmann <arnd@arndb.de>
    Reviewed-by: Juergen Gross <jgross@suse.com>
    Tested-by: Alyssa Ross <hi@alyssa.is>
    Link: https://lore.kernel.org/r/20231204084722.3789473-1-arnd@kernel.org
    Signed-off-by: Juergen Gross <jgross@suse.com>

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:37 -04:00
Prarit Bhargava 6b9eb90a88 x86/xen: fix percpu vcpu_info allocation
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit db2832309a82b9acc4b8cc33a1831d36507ec13e
Author: Juergen Gross <jgross@suse.com>
Date:   Fri Nov 24 08:48:52 2023 +0100

    x86/xen: fix percpu vcpu_info allocation

    Today the percpu struct vcpu_info is allocated via DEFINE_PER_CPU(),
    meaning that it could cross a page boundary. In this case registering
    it with the hypervisor will fail, resulting in a panic().

    This can easily be fixed by using DEFINE_PER_CPU_ALIGNED() instead,
    as struct vcpu_info is guaranteed to have a size of 64 bytes, matching
    the cache line size of x86 64-bit processors (Xen doesn't support
    32-bit processors).

    Fixes: 5ead97c84f ("xen: Core Xen implementation")
    Signed-off-by: Juergen Gross <jgross@suse.com>
    Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.con>
    Link: https://lore.kernel.org/r/20231124074852.25161-1-jgross@suse.com
    Signed-off-by: Juergen Gross <jgross@suse.com>

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:36 -04:00
Prarit Bhargava 470205195c x86/mce/amd, EDAC/mce_amd: Move long names to decoder module
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit ff03ff328fbd0a2b3a43e8b9bbc2a1d84265e77e
Author: Yazen Ghannam <yazen.ghannam@amd.com>
Date:   Sat Nov 18 13:32:32 2023 -0600

    x86/mce/amd, EDAC/mce_amd: Move long names to decoder module

    The long names of the SMCA banks are only used by the MCE decoder
    module.

    Move them out of the arch code and into the decoder module.

      [ bp: Name the long names array "smca_long_names", drop local ptr in
        decode_smca_error(), constify arrays. ]

    Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231118193248.1296798-5-yazen.ghannam@amd.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:36 -04:00
Prarit Bhargava bf34a2135f x86/cpu/intel_epb: Don't rely on link order
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 5bfa0e45e9e7212b87fe1564ab45f146c7d56e5f
Author: James Morse <james.morse@arm.com>
Date:   Fri Nov 24 09:38:53 2023 +0000

    x86/cpu/intel_epb: Don't rely on link order

    intel_epb_init() is called as a subsys_initcall() to register cpuhp
    callbacks. The callbacks make use of get_cpu_device() which will return
    NULL unless register_cpu() has been called. register_cpu() is called
    from topology_init(), which is also a subsys_initcall().

    This is fragile. Moving the register_cpu() to a different
    subsys_initcall() leads to a NULL dereference during boot.

    Make intel_epb_init() a late_initcall(), user-space can't provide a
    policy before this point anyway.

    Signed-off-by: James Morse <james.morse@arm.com>
    Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Reviewed-by: Gavin Shan <gshan@redhat.com>
    Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:36 -04:00
Prarit Bhargava 802d722b80 x86/ioapic: Remove unfinished sentence from comment
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 5e1c8a47fc6ec6251ddd126f4245279fc072f1c0
Author: Adrian Huang <ahuang12@lenovo.com>
Date:   Thu Nov 23 12:13:37 2023 +0800

    x86/ioapic: Remove unfinished sentence from comment

    [ mingo: Refine changelog. ]

    Signed-off-by: Adrian Huang <ahuang12@lenovo.com>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Cc: linux-kernel@vger.kernel.org

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:36 -04:00
Prarit Bhargava 294afc0d03 x86/io: Remove the unused 'bw' parameter from the BUILDIO() macro
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 03f111710af9ea9cd5a08ecc98e456d1cc0c2284
Author: Yuntao Wang <ytcoode@gmail.com>
Date:   Thu Nov 23 11:49:11 2023 +0800

    x86/io: Remove the unused 'bw' parameter from the BUILDIO() macro

    Commit 1e8f93e18379 ("x86: Consolidate port I/O helpers") moved some
    port I/O helpers to <asm/shared/io.h>, which caused the 'bw' parameter
    in the BUILDIO() macro to become unused. Remove it.

    Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Link: https://lore.kernel.org/r/20231123034911.217791-1-ytcoode@gmail.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:36 -04:00
Prarit Bhargava 2f96eefadc x86/apic: Drop struct local_apic
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 5a7d6d26af7714718b673e40bdc97f9f207e265a
Author: Andrew Cooper <andrew.cooper3@citrix.com>
Date:   Thu Nov 2 12:26:21 2023 +0000

    x86/apic: Drop struct local_apic

    This type predates recorded history in tglx/history.git, making it older
    than Feb 5th 2002.

    This structure is literally old enough to drink in most juristictions in
    the world, and has not been used once in that time.

    Lay it to rest in /dev/null.

    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Reviewed-by: Steve Wahl <steve.wahl@hpe.com>
    Link: https://lore.kernel.org/r/20231102-x86-apic-v1-3-bf049a2a0ed6@citrix.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:36 -04:00
Prarit Bhargava ae83dc3bd0 x86/apic: Drop enum apic_delivery_modes
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 855da7cdf974f3902397e5bf9423c7442bdfd75f
Author: Andrew Cooper <andrew.cooper3@citrix.com>
Date:   Thu Nov 2 12:26:20 2023 +0000

    x86/apic: Drop enum apic_delivery_modes

    The type is not used any more.

    Replace the constants with plain defines so they can live outside of an
    __ASSEMBLY__ block, allowing for more cleanup in subsequent changes.

    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Reviewed-by: Steve Wahl <steve.wahl@hpe.com>
    Link: https://lore.kernel.org/r/20231102-x86-apic-v1-2-bf049a2a0ed6@citrix.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:36 -04:00
Prarit Bhargava fc9eefa57f x86/apic: Drop apic::delivery_mode
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 07e8f88568f558fb0f9529f49b3ab120cbe750fe
Author: Andrew Cooper <andrew.cooper3@citrix.com>
Date:   Thu Nov 2 12:26:19 2023 +0000

    x86/apic: Drop apic::delivery_mode

    This field is set to APIC_DELIVERY_MODE_FIXED in all cases, and is read
    exactly once.  Fold the constant in uv_program_mmr() and drop the field.

    Searching for the origin of the stale HyperV comment reveals commit
    a31e58e129 ("x86/apic: Switch all APICs to Fixed delivery mode") which
    notes:

      As a consequence of this change, the apic::irq_delivery_mode field is
      now pointless, but this needs to be cleaned up in a separate patch.

    6 years is long enough for this technical debt to have survived.

      [ bp: Fold in
        https://lore.kernel.org/r/20231121123034.1442059-1-andrew.cooper3@citrix.com
      ]

    Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Reviewed-by: Steve Wahl <steve.wahl@hpe.com>
    Link: https://lore.kernel.org/r/20231102-x86-apic-v1-1-bf049a2a0ed6@citrix.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:36 -04:00
Prarit Bhargava b2d04a2fca x86/microcode/intel: Set new revision only after a successful update
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 9c21ea53e6bd1104c637b80a0688040f184cc761
Author: Borislav Petkov (AMD) <bp@alien8.de>
Date:   Fri Dec 1 14:35:06 2023 +0100

    x86/microcode/intel: Set new revision only after a successful update

    This was meant to be done only when early microcode got updated
    successfully. Move it into the if-branch.

    Also, make sure the current revision is read unconditionally and only
    once.

    Fixes: 080990aa3344 ("x86/microcode: Rework early revisions reporting")
    Reported-by: Ashok Raj <ashok.raj@intel.com>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Tested-by: Ashok Raj <ashok.raj@intel.com>
    Link: https://lore.kernel.org/r/ZWjVt5dNRjbcvlzR@a4bf019067fa.jf.intel.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:36 -04:00
Prarit Bhargava 3b187980a1 x86/microcode: Rework early revisions reporting
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 080990aa3344123673f686cda2df0d1b0deee046
Author: Borislav Petkov (AMD) <bp@alien8.de>
Date:   Wed Nov 15 22:02:12 2023 +0100

    x86/microcode: Rework early revisions reporting

    The AMD side of the loader issues the microcode revision for each
    logical thread on the system, which can become really noisy on huge
    machines. And doing that doesn't make a whole lot of sense - the
    microcode revision is already in /proc/cpuinfo.

    So in case one is interested in the theoretical support of mixed silicon
    steppings on AMD, one can check there.

    What is also missing on the AMD side - something which people have
    requested before - is showing the microcode revision the CPU had
    *before* the early update.

    So abstract that up in the main code and have the BSP on each vendor
    provide those revision numbers.

    Then, dump them only once on driver init.

    On Intel, do not dump the patch date - it is not needed.

    Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
    Link: https://lore.kernel.org/r/CAHk-=wg=%2B8rceshMkB4VnKxmRccVLtBLPBawnewZuuqyx5U=3A@mail.gmail.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:36 -04:00
Prarit Bhargava 1bbc857d3e x86/microcode: Remove the driver announcement and version
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 2e569ada424c40ce27c99bfab4f9780619061c83
Author: Borislav Petkov (AMD) <bp@alien8.de>
Date:   Wed Nov 15 22:02:11 2023 +0100

    x86/microcode: Remove the driver announcement and version

    First of all, the print is useless. The driver will either load and say
    which microcode revision the machine has or issue an error.

    Then, the version number is meaningless and actively confusing, as Yazen
    mentioned recently: when a subset of patches are backported to a distro
    kernel, one can't assume the driver version is the same as the upstream
    one. And besides, the version number of the loader hasn't been used and
    incremented for a long time. So drop it.

    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
    Link: https://lore.kernel.org/r/20231115210212.9981-2-bp@alien8.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:36 -04:00
Prarit Bhargava 772b27d127 x86/entry: Harden return-to-user
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 1e4d3001f59fb7a9917cb746544b65e616b5f809
Author: Peter Zijlstra <peterz@infradead.org>
Date:   Mon Nov 20 15:33:46 2023 +0100

    x86/entry: Harden return-to-user

    Make the CONFIG_DEBUG_ENTRY=y check that validates CS is a user segment
    unconditional and move it nearer to IRET.

      PRE:
           140,026,608      cycles:k                                                      ( +-  0.01% )
           236,696,176      instructions:k            #    1.69  insn per cycle           ( +-  0.00% )

      POST:
           139,957,681      cycles:k                                                      ( +-  0.01% )
           236,681,819      instructions:k            #    1.69  insn per cycle           ( +-  0.00% )

    (this is with --repeat 100 and the run-to-run variance is bigger than
    the difference shown)

    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Link: https://lore.kernel.org/r/20231120143626.753200755@infradead.org

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:36 -04:00
Prarit Bhargava 06c04a3a47 x86/entry: Optimize common_interrupt_return()
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit c516213726fb572700cce4a5909aa8d82b77192a
Author: Peter Zijlstra <peterz@infradead.org>
Date:   Mon Nov 20 15:33:45 2023 +0100

    x86/entry: Optimize common_interrupt_return()

    The code in common_interrupt_return() does a bunch of unconditional
    work that is really only needed on PTI kernels. Specifically it
    unconditionally copies the IRET frame back onto the entry stack,
    swizzles onto the entry stack and does IRET from there.

    However, without PTI we can simply IRET from whatever stack we're on.

      ivb-ep, mitigations=off, gettid-1m:

      PRE:
           140,118,538      cycles:k                                                      ( +-  0.01% )
           236,692,878      instructions:k            #    1.69  insn per cycle           ( +-  0.00% )

      POST:
           140,026,608      cycles:k                                                      ( +-  0.01% )
           236,696,176      instructions:k            #    1.69  insn per cycle           ( +-  0.00% )

    (this is with --repeat 100 and the run-to-run variance is bigger than
    the difference shown)

    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Link: https://lore.kernel.org/r/20231120143626.638107480@infradead.org

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:35 -04:00
Prarit Bhargava 198dfcf478 perf/x86/intel: Correct incorrect 'or' operation for PMU capabilities
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit e8df9d9f4209c04161321d8c12640ae560f65939
Author: Dapeng Mi <dapeng1.mi@linux.intel.com>
Date:   Tue Nov 21 09:46:28 2023 +0800

    perf/x86/intel: Correct incorrect 'or' operation for PMU capabilities

    When running perf-stat command on Intel hybrid platform, perf-stat
    reports the following errors:

      sudo taskset -c 7 ./perf stat -vvvv -e cpu_atom/instructions/ sleep 1

      Opening: cpu/cycles/:HG
      ------------------------------------------------------------
      perf_event_attr:
        type                             0 (PERF_TYPE_HARDWARE)
        config                           0xa00000000
        disabled                         1
      ------------------------------------------------------------
      sys_perf_event_open: pid 0  cpu -1  group_fd -1  flags 0x8
      sys_perf_event_open failed, error -16

       Performance counter stats for 'sleep 1':

           <not counted>      cpu_atom/instructions/

    It looks the cpu_atom/instructions/ event can't be enabled on atom PMU
    even when the process is pinned on atom core. Investigation shows that
    exclusive_event_init() helper always returns -EBUSY error in the perf
    event creation. That's strange since the atom PMU should not be an
    exclusive PMU.

    Further investigation shows the issue was introduced by commit:

      97588df87b56 ("perf/x86/intel: Add common intel_pmu_init_hybrid()")

    The commit originally intents to clear the bit PERF_PMU_CAP_AUX_OUTPUT
    from PMU capabilities if intel_cap.pebs_output_pt_available is not set,
    but it incorrectly uses 'or' operation and leads to all PMU capabilities
    bits are set to 1 except bit PERF_PMU_CAP_AUX_OUTPUT.

    Testing this fix on Intel hybrid platforms, the observed issues
    disappear.

    Fixes: 97588df87b56 ("perf/x86/intel: Add common intel_pmu_init_hybrid()")
    Signed-off-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20231121014628.729989-1-dapeng1.mi@linux.intel.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:35 -04:00
Prarit Bhargava 930e76477c x86/mtrr: Document missing function parameters in kernel-doc
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 4e15b91c5b7919c530c27f39c7f2d392bf0a95e3
Author: Borislav Petkov (AMD) <bp@alien8.de>
Date:   Mon Nov 13 14:52:52 2023 +0100

    x86/mtrr: Document missing function parameters in kernel-doc

    Add text explaining what they do.

    No functional changes.

    Closes: https://lore.kernel.org/oe-kbuild-all/202311130104.9xKAKzke-lkp@intel.com/
    Reported-by: kernel test robot <lkp@intel.com>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/202311130104.9xKAKzke-lkp@intel.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:35 -04:00
Prarit Bhargava d15c6ae003 x86/lib: Fix overflow when counting digits
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit a24d61c609813963aacc9f6ec8343f4fcaac7243
Author: Colin Ian King <colin.i.king@gmail.com>
Date:   Thu Nov 2 17:49:01 2023 +0000

    x86/lib: Fix overflow when counting digits

    tl;dr: The num_digits() function has a theoretical overflow issue.
    But it doesn't affect any actual in-tree users.  Fix it by using
    a larger type for one of the local variables.

    Long version:

    There is an overflow in variable m in function num_digits when val
    is >= 1410065408 which leads to the digit calculation loop to
    iterate more times than required. This results in either more
    digits being counted or in some cases (for example where val is
    1932683193) the value of m eventually overflows to zero and the
    while loop spins forever).

    Currently the function num_digits is currently only being used for
    small values of val in the SMP boot stage for digit counting on the
    number of cpus and NUMA nodes, so the overflow is never encountered.
    However it is useful to fix the overflow issue in case the function
    is used for other purposes in the future. (The issue was discovered
    while investigating the digit counting performance in various
    kernel helper functions rather than any real-world use-case).

    The simplest fix is to make m a long long, the overhead in
    multiplication speed for a long long is very minor for small values
    of val less than 10000 on modern processors. The alternative
    fix is to replace the multiplication with a constant division
    by 10 loop (this compiles down to an multiplication and shift)
    without needing to make m a long long, but this is slightly slower
    than the fix in this commit when measured on a range of x86
    processors).

    [ dhansen: subject and changelog tweaks ]

    Fixes: 646e29a178 ("x86: Improve the printout of the SMP bootup CPU table")
    Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
    Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
    Link: https://lore.kernel.org/all/20231102174901.2590325-1-colin.i.king%40gmail.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:35 -04:00
Prarit Bhargava 59e91b4937 perf/x86/intel/cstate: Add Grand Ridge support
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit bbb968696d0f3442ab823598def3b756cf4735c6
Author: Kan Liang <kan.liang@linux.intel.com>
Date:   Thu Nov 16 06:22:45 2023 -0800

    perf/x86/intel/cstate: Add Grand Ridge support

    The same as the Sierra Forest, the Grand Ridge supports core C1/C6 and
    module C6. But it doesn't support pkg C6 residency counter.

    Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Link: https://lore.kernel.org/r/20231116142245.1233485-4-kan.liang@linux.intel.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:35 -04:00
Prarit Bhargava 365b605413 perf/x86/intel/cstate: Add Sierra Forest support
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 3877d55a0db2688c2e4ab8a319614a0c81f8e2d2
Author: Kan Liang <kan.liang@linux.intel.com>
Date:   Thu Nov 16 06:22:44 2023 -0800

    perf/x86/intel/cstate: Add Sierra Forest support

    A new module C6 Residency Counter is introduced in the Sierra Forest.
    The scope of the new counter is module (A cluster of cores shared L2
    cache). Create a brand new cstate_module PMU to profile the new counter.
    The only differences between the new cstate_module PMU and the existing
    cstate PMU are the scope and events.

    Regarding the choice of the new cstate_module PMU name, the current
    naming rule of a cstate PMU is "cstate_" + the scope of the PMU. The
    scope of the PMU is the cores shared L2. On SRF, Intel calls it
    "module", while the internal Linux sched code calls it "cluster". The
    "cstate_module" is used as the new PMU name, because
    - The Cstate PMU driver is a Intel specific driver. It doesn't impact
      other ARCHs. The name makes it consistent with the documentation.
    - The "cluster" mainly be used by the scheduler developer, while the
      user of cstate PMU is more likely a researcher reading HW docs and
      optimizing power.
    - In the Intel's SDM, the "cluster" has a different meaning/scope for
      topology. Using it will mislead the end users.

    Besides the module C6, the core C1/C6 and pkg C6 residency counters are
    supported in the Sierra Forest as well.

    Suggested-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
    Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Link: https://lore.kernel.org/r/20231116142245.1233485-3-kan.liang@linux.intel.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:35 -04:00
Prarit Bhargava b4a0791752 x86/smp: Export symbol cpu_clustergroup_mask()
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit c3dd1995620cdcd65cf4944c4164b0dbc16e557c
Author: Kan Liang <kan.liang@linux.intel.com>
Date:   Thu Nov 16 06:22:43 2023 -0800

    x86/smp: Export symbol cpu_clustergroup_mask()

    Intel cstate PMU driver will invoke the topology_cluster_cpumask() to
    retrieve the CPU mask of a cluster. A modpost error is triggered since
    the symbol cpu_clustergroup_mask is not exported.

    Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Link: https://lore.kernel.org/r/20231116142245.1233485-2-kan.liang@linux.intel.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:35 -04:00
Prarit Bhargava 4d1363d6b9 perf/x86/intel/cstate: Cleanup duplicate attr_groups
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 243218ca93037631f0224fdbefea045912cb761a
Author: Kan Liang <kan.liang@linux.intel.com>
Date:   Thu Nov 16 06:22:42 2023 -0800

    perf/x86/intel/cstate: Cleanup duplicate attr_groups

    The events of the cstate_core and cstate_pkg PMU have the same format.
    They both need to create a "events" group (with empty attrs). The
    attr_groups can be shared.

    Remove the dedicated attr_groups for each cstate PMU. Use the shared
    cstate_attr_groups to replace.

    Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Link: https://lore.kernel.org/r/20231116142245.1233485-1-kan.liang@linux.intel.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:35 -04:00
Prarit Bhargava 29e20da76e x86/mce: Remove redundant check from mce_device_create()
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 612905e13b8769caca7ec4194a8aceb24efa4d5c
Author: Nikolay Borisov <nik.borisov@suse.com>
Date:   Tue Nov 7 18:55:29 2023 +0200

    x86/mce: Remove redundant check from mce_device_create()

    mce_device_create() is called only from mce_cpu_online() which in turn
    will be called iff MCA support is available. That is, at the time of
    mce_device_create() call it's guaranteed that MCA support is available.
    No need to duplicate this check so remove it.

      [ bp: Massage commit message. ]

    Signed-off-by: Nikolay Borisov <nik.borisov@suse.com>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231107165529.407349-1-nik.borisov@suse.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:35 -04:00
Prarit Bhargava 91b90297e6 x86/paravirt: Make the struct paravirt_patch_site packed
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit fe22bc430c9d24394e541e16e0941a075f02fcb7
Author: Hou Wenlong <houwenlong.hwl@antgroup.com>
Date:   Fri Jun 9 17:45:32 2023 +0800

    x86/paravirt: Make the struct paravirt_patch_site packed

    Similar to struct alt_instr, make the struct paravirt_patch_site packed
    and get rid of all the .align directives and save 2 bytes for one
    PARA_SITE entry on X86_64.

      [ bp: Massage commit message. ]

    Suggested-by: Nadav Amit <namit@vmware.com>
    Signed-off-by: Hou Wenlong <houwenlong.hwl@antgroup.com>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Reviewed-by: Juergen Gross <jgross@suse.com>
    Link: https://lore.kernel.org/r/6dcb20159ded36586c5f7f2ae159e4e030256627.1686301237.git.houwenlong.hwl@antgroup.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:35 -04:00
Prarit Bhargava 227c9811b2 x86/paravirt: Use relative reference for the original instruction offset
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 5c22c4726e4a9c6b2e182c0b21c2d3dd63f608c4
Author: Hou Wenlong <houwenlong.hwl@antgroup.com>
Date:   Fri Jun 9 17:45:31 2023 +0800

    x86/paravirt: Use relative reference for the original instruction offset

    Similar to the alternative patching, use a relative reference for original
    instruction offset rather than absolute one, which saves 8 bytes for one
    PARA_SITE entry on x86_64.  As a result, a R_X86_64_PC32 relocation is
    generated instead of an R_X86_64_64 one, which also reduces relocation
    metadata on relocatable builds. Hardcode the alignment to 4 now.

      [ bp: Massage commit message. ]

    Signed-off-by: Hou Wenlong <houwenlong.hwl@antgroup.com>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Reviewed-by: Juergen Gross <jgross@suse.com>
    Link: https://lore.kernel.org/r/9e6053107fbaabc0d33e5d2865c5af2c67ec9925.1686301237.git.houwenlong.hwl@antgroup.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:35 -04:00
Prarit Bhargava 39ff4d84cc tools headers x86 cpufeatures: Sync with the kernel sources to pick TDX, Zen, APIC MSR fence changes
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 15d6daad8f8add8ef99b6e4e2b5bf0db48e1a8db
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
Date:   Tue Jan 30 10:09:18 2024 -0300

    tools headers x86 cpufeatures: Sync with the kernel sources to pick TDX, Zen, APIC MSR fence changes

    To pick the changes from:

      1e536e10689700e0 ("x86/cpu: Detect TDX partial write machine check erratum")
      765a0542fdc7aad7 ("x86/virt/tdx: Detect TDX during kernel boot")
      30fa92832f405d5a ("x86/CPU/AMD: Add ZenX generations flags")
      04c3024560d3a14a ("x86/barrier: Do not serialize MSR accesses on AMD")

    This causes these perf files to be rebuilt and brings some X86_FEATURE
    that will be used when updating the copies of
    tools/arch/x86/lib/mem{cpy,set}_64.S with the kernel sources:

          CC       /tmp/build/perf/bench/mem-memcpy-x86-64-asm.o
          CC       /tmp/build/perf/bench/mem-memset-x86-64-asm.o

    And addresses this perf build warning:

      Warning: Kernel ABI header differences:
        diff -u tools/arch/x86/include/asm/cpufeatures.h arch/x86/include/asm/cpufeatures.h

    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Borislav Petkov <bp@alien8.de>
    Cc: Dave Hansen <dave.hansen@linux.intel.com>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Kai Huang <kai.huang@intel.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Link: https://lore.kernel.org/lkml/
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:35 -04:00
Prarit Bhargava ffb1b3e64f x86/barrier: Do not serialize MSR accesses on AMD
JIRA: https://issues.redhat.com/browse/RHEL-25415

Conflicts: Minor drift issues.

commit 04c3024560d3a14acd18d0a51a1d0a89d29b7eb5
Author: Borislav Petkov (AMD) <bp@alien8.de>
Date:   Fri Oct 27 14:24:16 2023 +0200

    x86/barrier: Do not serialize MSR accesses on AMD

    AMD does not have the requirement for a synchronization barrier when
    acccessing a certain group of MSRs. Do not incur that unnecessary
    penalty there.

    There will be a CPUID bit which explicitly states that a MFENCE is not
    needed. Once that bit is added to the APM, this will be extended with
    it.

    While at it, move to processor.h to avoid include hell. Untangling that
    file properly is a matter for another day.

    Some notes on the performance aspect of why this is relevant, courtesy
    of Kishon VijayAbraham <Kishon.VijayAbraham@amd.com>:

    On a AMD Zen4 system with 96 cores, a modified ipi-bench[1] on a VM
    shows x2AVIC IPI rate is 3% to 4% lower than AVIC IPI rate. The
    ipi-bench is modified so that the IPIs are sent between two vCPUs in the
    same CCX. This also requires to pin the vCPU to a physical core to
    prevent any latencies. This simulates the use case of pinning vCPUs to
    the thread of a single CCX to avoid interrupt IPI latency.

    In order to avoid run-to-run variance (for both x2AVIC and AVIC), the
    below configurations are done:

      1) Disable Power States in BIOS (to prevent the system from going to
         lower power state)

      2) Run the system at fixed frequency 2500MHz (to prevent the system
         from increasing the frequency when the load is more)

    With the above configuration:

    *) Performance measured using ipi-bench for AVIC:
      Average Latency:  1124.98ns [Time to send IPI from one vCPU to another vCPU]

      Cumulative throughput: 42.6759M/s [Total number of IPIs sent in a second from
                                         48 vCPUs simultaneously]

    *) Performance measured using ipi-bench for x2AVIC:
      Average Latency:  1172.42ns [Time to send IPI from one vCPU to another vCPU]

      Cumulative throughput: 40.9432M/s [Total number of IPIs sent in a second from
                                         48 vCPUs simultaneously]

    From above, x2AVIC latency is ~4% more than AVIC. However, the expectation is
    x2AVIC performance to be better or equivalent to AVIC. Upon analyzing
    the perf captures, it is observed significant time is spent in
    weak_wrmsr_fence() invoked by x2apic_send_IPI().

    With the fix to skip weak_wrmsr_fence()

    *) Performance measured using ipi-bench for x2AVIC:
      Average Latency:  1117.44ns [Time to send IPI from one vCPU to another vCPU]

      Cumulative throughput: 42.9608M/s [Total number of IPIs sent in a second from
                                         48 vCPUs simultaneously]

    Comparing the performance of x2AVIC with and without the fix, it can be seen
    the performance improves by ~4%.

    Performance captured using an unmodified ipi-bench using the 'mesh-ipi' option
    with and without weak_wrmsr_fence() on a Zen4 system also showed significant
    performance improvement without weak_wrmsr_fence(). The 'mesh-ipi' option ignores
    CCX or CCD and just picks random vCPU.

      Average throughput (10 iterations) with weak_wrmsr_fence(),
            Cumulative throughput: 4933374 IPI/s

      Average throughput (10 iterations) without weak_wrmsr_fence(),
            Cumulative throughput: 6355156 IPI/s

    [1] https://github.com/bytedance/kvm-utils/tree/master/microbenchmark/ipi-bench

    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20230622095212.20940-1-bp@alien8.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:35 -04:00
Prarit Bhargava 616da2927e x86/mce: Mark fatal MCE's page as poison to avoid panic in the kdump kernel
JIRA: https://issues.redhat.com/browse/RHEL-25415

Conflicts: Minor drift issues.

commit 9f3b130048bfa2e44a8cfb1b616f826d9d5d8188
Author: Zhiquan Li <zhiquan1.li@intel.com>
Date:   Thu Oct 26 08:39:03 2023 +0800

    x86/mce: Mark fatal MCE's page as poison to avoid panic in the kdump kernel

    Memory errors don't happen very often, especially fatal ones. However,
    in large-scale scenarios such as data centers, that probability
    increases with the amount of machines present.

    When a fatal machine check happens, mce_panic() is called based on the
    severity grading of that error. The page containing the error is not
    marked as poison.

    However, when kexec is enabled, tools like makedumpfile understand when
    pages are marked as poison and do not touch them so as not to cause
    a fatal machine check exception again while dumping the previous
    kernel's memory.

    Therefore, mark the page containing the error as poisoned so that the
    kexec'ed kernel can avoid accessing the page.

      [ bp: Rewrite commit message and comment. ]

    Co-developed-by: Youquan Song <youquan.song@intel.com>
    Signed-off-by: Youquan Song <youquan.song@intel.com>
    Signed-off-by: Zhiquan Li <zhiquan1.li@intel.com>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Reviewed-by: Naoya Horiguchi <naoya.horiguchi@nec.com>
    Link: https://lore.kernel.org/r/20231014051754.3759099-1-zhiquan1.li@intel.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:34 -04:00
Prarit Bhargava bc7593cf5b x86/setup: Make relocated_ramdisk a local variable of relocate_initrd()
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit f7a25cf1d4707da39b80df96a3be8a8abd07c35b
Author: Yuntao Wang <ytcoode@gmail.com>
Date:   Mon Nov 13 11:40:26 2023 +0800

    x86/setup: Make relocated_ramdisk a local variable of relocate_initrd()

    After

      0b62f6cb0773 ("x86/microcode/32: Move early loading after paging enable"),

    the global variable relocated_ramdisk is no longer used anywhere except
    for the relocate_initrd() function. Make it a local variable of that
    function.

    Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Reviewed-by: Baoquan He <bhe@redhat.com>
    Link: https://lore.kernel.org/r/20231113034026.130679-1-ytcoode@gmail.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:34 -04:00
Prarit Bhargava 5700166e7d x86/acpi: Handle bogus MADT APIC tables gracefully
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit d5a10b976ecb77fa49b95f3f1016ca2997c122cb
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Fri Dec 15 15:19:32 2023 +0100

    x86/acpi: Handle bogus MADT APIC tables gracefully

    The recent fix to ignore invalid x2APIC entries inadvertently broke
    systems with creative MADT APIC tables. The affected systems have APIC
    MADT tables where all entries have invalid APIC IDs (0xFF), which means
    they register exactly zero CPUs.

    But the condition to ignore the entries of APIC IDs < 255 in the X2APIC
    MADT table is solely based on the count of MADT APIC table entries.

    As a consequence, the affected machines enumerate no secondary CPUs at
    all because the APIC table has entries and therefore the X2APIC table
    entries with APIC IDs < 255 are ignored.

    Change the condition so that the APIC table preference for APIC IDs <
    255 only becomes effective when the APIC table has valid APIC ID
    entries.

    IOW, an APIC table full of invalid APIC IDs is considered to be empty
    which in consequence enables the X2APIC table entries with a APIC ID
    < 255 and restores the expected behaviour.

    Fixes: ec9aedb2aa1a ("x86/acpi: Ignore invalid x2APIC entries")
    Reported-by: John Sperbeck <jsperbeck@google.com>
    Reported-by: Andres Freund <andres@anarazel.de>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/169953729188.3135.6804572126118798018.tip-bot2@tip-bot2

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:34 -04:00
Prarit Bhargava d0246ab6e9 x86/acpi: Ignore invalid x2APIC entries
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit ec9aedb2aa1ab7ac420c00b31f5edc5be15ec167
Author: Zhang Rui <rui.zhang@intel.com>
Date:   Mon Jul 3 00:28:02 2023 +0800

    x86/acpi: Ignore invalid x2APIC entries

    Currently, the kernel enumerates the possible CPUs by parsing both ACPI
    MADT Local APIC entries and x2APIC entries. So CPUs with "valid" APIC IDs,
    even if they have duplicated APIC IDs in Local APIC and x2APIC, are always
    enumerated.

    Below is what ACPI MADT Local APIC and x2APIC describes on an
    Ivebridge-EP system,

    [02Ch 0044   1]                Subtable Type : 00 [Processor Local APIC]
    [02Fh 0047   1]                Local Apic ID : 00
    ...
    [164h 0356   1]                Subtable Type : 00 [Processor Local APIC]
    [167h 0359   1]                Local Apic ID : 39
    [16Ch 0364   1]                Subtable Type : 00 [Processor Local APIC]
    [16Fh 0367   1]                Local Apic ID : FF
    ...
    [3ECh 1004   1]                Subtable Type : 09 [Processor Local x2APIC]
    [3F0h 1008   4]                Processor x2Apic ID : 00000000
    ...
    [B5Ch 2908   1]                Subtable Type : 09 [Processor Local x2APIC]
    [B60h 2912   4]                Processor x2Apic ID : 00000077

    As a result, kernel shows "smpboot: Allowing 168 CPUs, 120 hotplug CPUs".
    And this wastes significant amount of memory for the per-cpu data.
    Plus this also breaks https://lore.kernel.org/all/87edm36qqb.ffs@tglx/,
    because __max_logical_packages is over-estimated by the APIC IDs in
    the x2APIC entries.

    According to https://uefi.org/specs/ACPI/6.5/05_ACPI_Software_Programming_Model.html#processor-local-x2apic-structure:

      "[Compatibility note] On some legacy OSes, Logical processors with APIC
       ID values less than 255 (whether in XAPIC or X2APIC mode) must use the
       Processor Local APIC structure to convey their APIC information to OSPM,
       and those processors must be declared in the DSDT using the Processor()
       keyword. Logical processors with APIC ID values 255 and greater must use
       the Processor Local x2APIC structure and be declared using the Device()
       keyword."

    Therefore prevent the registration of x2APIC entries with an APIC ID less
    than 255 if the local APIC table enumerates valid APIC IDs.

    [ tglx: Simplify the logic ]

    Signed-off-by: Zhang Rui <rui.zhang@intel.com>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Tested-by: Peter Zijlstra <peterz@infradead.org>
    Link: https://lore.kernel.org/r/20230702162802.344176-1-rui.zhang@intel.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:34 -04:00
Prarit Bhargava f1a3e0cb72 x86/i8259: Skip probing when ACPI/MADT advertises PCAT compatibility
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 128b0c9781c9f2651bea163cb85e52a6c7be0f9e
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Wed Oct 25 23:04:15 2023 +0200

    x86/i8259: Skip probing when ACPI/MADT advertises PCAT compatibility

    David and a few others reported that on certain newer systems some legacy
    interrupts fail to work correctly.

    Debugging revealed that the BIOS of these systems leaves the legacy PIC in
    uninitialized state which makes the PIC detection fail and the kernel
    switches to a dummy implementation.

    Unfortunately this fallback causes quite some code to fail as it depends on
    checks for the number of legacy PIC interrupts or the availability of the
    real PIC.

    In theory there is no reason to use the PIC on any modern system when
    IO/APIC is available, but the dependencies on the related checks cannot be
    resolved trivially and on short notice. This needs lots of analysis and
    rework.

    The PIC detection has been added to avoid quirky checks and force selection
    of the dummy implementation all over the place, especially in VM guest
    scenarios. So it's not an option to revert the relevant commit as that
    would break a lot of other scenarios.

    One solution would be to try to initialize the PIC on detection fail and
    retry the detection, but that puts the burden on everything which does not
    have a PIC.

    Fortunately the ACPI/MADT table header has a flag field, which advertises
    in bit 0 that the system is PCAT compatible, which means it has a legacy
    8259 PIC.

    Evaluate that bit and if set avoid the detection routine and keep the real
    PIC installed, which then gets initialized (for nothing) and makes the rest
    of the code with all the dependencies work again.

    Fixes: e179f69141 ("x86, irq, pic: Probe for legacy PIC and set legacy_pic appropriately")
    Reported-by: David Lazar <dlazar@gmail.com>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Tested-by: David Lazar <dlazar@gmail.com>
    Reviewed-by: Hans de Goede <hdegoede@redhat.com>
    Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
    Cc: stable@vger.kernel.org
    Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218003
    Link: https://lore.kernel.org/r/875y2u5s8g.ffs@tglx

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:34 -04:00
Prarit Bhargava 3231cdaa5c x86/defconfig: Enable CONFIG_DEBUG_ENTRY=y
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 70c8dc9104275037a39ab0b2a4ed6eaacac39e32
Author: Ingo Molnar <mingo@kernel.org>
Date:   Tue Oct 24 19:09:17 2023 +0200

    x86/defconfig: Enable CONFIG_DEBUG_ENTRY=y

    A bug was recently found via CONFIG_DEBUG_ENTRY=y, and the x86
    tree kinda is the main source of changes to the x86 entry code,
    so enable this debug option by default in our defconfigs.

    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Cc: linux-kernel@vger.kernel.org

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:34 -04:00
Prarit Bhargava 336fbef357 x86/microcode: Prepare for minimal revision check
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 9407bda845dd19756e276d4f3abc15a20777ba45
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Tue Oct 17 23:24:16 2023 +0200

    x86/microcode: Prepare for minimal revision check

    Applying microcode late can be fatal for the running kernel when the
    update changes functionality which is in use already in a non-compatible
    way, e.g. by removing a CPUID bit.

    There is no way for admins which do not have access to the vendors deep
    technical support to decide whether late loading of such a microcode is
    safe or not.

    Intel has added a new field to the microcode header which tells the
    minimal microcode revision which is required to be active in the CPU in
    order to be safe.

    Provide infrastructure for handling this in the core code and a command
    line switch which allows to enforce it.

    If the update is considered safe the kernel is not tainted and the annoying
    warning message not emitted. If it's enforced and the currently loaded
    microcode revision is not safe for late loading then the load is aborted.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231017211724.079611170@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:34 -04:00
Prarit Bhargava 484bc6dec6 x86/microcode/intel: Add a minimum required revision for late loading
JIRA: https://issues.redhat.com/browse/RHEL-25415

Conflicts: force_minrev does not exist in RHEL9.

commit cf5ab01c87030a085e211a0a327535932ec6f719
Author: Ashok Raj <ashok.raj@intel.com>
Date:   Mon Oct 2 14:00:11 2023 +0200

    x86/microcode/intel: Add a minimum required revision for late loading

    In general users, don't have the necessary information to determine
    whether late loading of a new microcode version is safe and does not
    modify anything which the currently running kernel uses already, e.g.
    removal of CPUID bits or behavioural changes of MSRs.

    To address this issue, Intel has added a "minimum required version"
    field to a previously reserved field in the microcode header.  Microcode
    updates should only be applied if the current microcode version is equal
    to, or greater than this minimum required version.

    Thomas made some suggestions on how meta-data in the microcode file could
    provide Linux with information to decide if the new microcode is suitable
    candidate for late loading. But even the "simpler" option requires a lot of
    metadata and corresponding kernel code to parse it, so the final suggestion
    was to add the 'minimum required version' field in the header.

    When microcode changes visible features, microcode will set the minimum
    required version to its own revision which prevents late loading.

    Old microcode blobs have the minimum revision field always set to 0, which
    indicates that there is no information and the kernel considers it
    unsafe.

    This is a pure OS software mechanism. The hardware/firmware ignores this
    header field.

    For early loading there is no restriction because OS visible features
    are enumerated after the early load and therefore a change has no
    effect.

    The check is always enabled, but by default not enforced. It can be
    enforced via Kconfig or kernel command line.

    If enforced, the kernel refuses to late load microcode with a minimum
    required version field which is zero or when the currently loaded
    microcode revision is smaller than the minimum required revision.

    If not enforced the load happens independent of the revision check to
    stay compatible with the existing behaviour, but it influences the
    decision whether the kernel is tainted or not. If the check signals that
    the late load is safe, then the kernel is not tainted.

    Early loading is not affected by this.

    [ tglx: Massaged changelog and fixed up the implementation ]

    Suggested-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Ashok Raj <ashok.raj@intel.com>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231002115903.776467264@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:34 -04:00
Prarit Bhargava 1d984b176c x86/microcode: Handle "offline" CPUs correctly
JIRA: https://issues.redhat.com/browse/RHEL-25415

Conflicts: Minor drift issues.

commit 8f849ff63bcbc77670da03cb8f2b78b06257f455
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Mon Oct 2 14:00:08 2023 +0200

    x86/microcode: Handle "offline" CPUs correctly

    Offline CPUs need to be parked in a safe loop when microcode update is
    in progress on the primary CPU. Currently, offline CPUs are parked in
    mwait_play_dead(), and for Intel CPUs, its not a safe instruction,
    because the MWAIT instruction can be patched in the new microcode update
    that can cause instability.

      - Add a new microcode state 'UCODE_OFFLINE' to report status on per-CPU
      basis.
      - Force NMI on the offline CPUs.

    Wake up offline CPUs while the update is in progress and then return
    them back to mwait_play_dead() after microcode update is complete.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231002115903.660850472@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:34 -04:00
Prarit Bhargava 695c8f2720 x86/apic: Provide apic_force_nmi_on_cpu()
JIRA: https://issues.redhat.com/browse/RHEL-25415

Conflicts: Minor drift issues.

commit 9cab5fb776d4367e26950cf759211e948335288e
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Mon Oct 2 14:00:07 2023 +0200

    x86/apic: Provide apic_force_nmi_on_cpu()

    When SMT siblings are soft-offlined and parked in one of the play_dead()
    variants they still react on NMI, which is problematic on affected Intel
    CPUs. The default play_dead() variant uses MWAIT on modern CPUs, which is
    not guaranteed to be safe when updated concurrently.

    Right now late loading is prevented when not all SMT siblings are online,
    but as they still react on NMI, it is possible to bring them out of their
    park position into a trivial rendezvous handler.

    Provide a function which allows to do that. I does sanity checks whether
    the target is in the cpus_booted_once_mask and whether the APIC driver
    supports it.

    Mark X2APIC and XAPIC as capable, but exclude 32bit and the UV and NUMACHIP
    variants as that needs feedback from the relevant experts.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231002115903.603100036@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:34 -04:00
Prarit Bhargava ef22f1c2ad x86/microcode: Protect against instrumentation
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 1582c0f4a21303792f523fe2839dd8433ee630c0
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Mon Oct 2 14:00:06 2023 +0200

    x86/microcode: Protect against instrumentation

    The wait for control loop in which the siblings are waiting for the
    microcode update on the primary thread must be protected against
    instrumentation as instrumentation can end up in #INT3, #DB or #PF,
    which then returns with IRET. That IRET reenables NMI which is the
    opposite of what the NMI rendezvous is trying to achieve.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231002115903.545969323@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:34 -04:00
Prarit Bhargava b5d1c6ee73 x86/microcode: Rendezvous and load in NMI
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 7eb314a22800457396f541c655697dabd71e44a7
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Mon Oct 2 14:00:05 2023 +0200

    x86/microcode: Rendezvous and load in NMI

    stop_machine() does not prevent the spin-waiting sibling from handling
    an NMI, which is obviously violating the whole concept of rendezvous.

    Implement a static branch right in the beginning of the NMI handler
    which is nopped out except when enabled by the late loading mechanism.

    The late loader enables the static branch before stop_machine() is
    invoked. Each CPU has an nmi_enable in its control structure which
    indicates whether the CPU should go into the update routine.

    This is required to bridge the gap between enabling the branch and
    actually being at the point where it is required to enter the loader
    wait loop.

    Each CPU which arrives in the stopper thread function sets that flag and
    issues a self NMI right after that. If the NMI function sees the flag
    clear, it returns. If it's set it clears the flag and enters the
    rendezvous.

    This is safe against a real NMI which hits in between setting the flag
    and sending the NMI to itself. The real NMI will be swallowed by the
    microcode update and the self NMI will then let stuff continue.
    Otherwise this would end up with a spurious NMI.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231002115903.489900814@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:34 -04:00
Prarit Bhargava 2ffc7639e3 x86/microcode: Replace the all-in-one rendevous handler
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 0bf871651211b58c7b19f40b746b646d5311e2ec
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Mon Oct 2 14:00:03 2023 +0200

    x86/microcode: Replace the all-in-one rendevous handler

    with a new handler which just separates the control flow of primary and
    secondary CPUs.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231002115903.433704135@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:34 -04:00
Prarit Bhargava d3bdf095b4 x86/microcode: Provide new control functions
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 6067788f04b1020b316344fe34746f96d594a042
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Mon Oct 2 14:00:02 2023 +0200

    x86/microcode: Provide new control functions

    The current all in one code is unreadable and really not suited for
    adding future features like uniform loading with package or system
    scope.

    Provide a set of new control functions which split the handling of the
    primary and secondary CPUs. These will replace the current rendezvous
    all in one function in the next step. This is intentionally a separate
    change because diff makes an complete unreadable mess otherwise.

    So the flow separates the primary and the secondary CPUs into their own
    functions which use the control field in the per CPU ucode_ctrl struct.

       primary()                    secondary()
        wait_for_all()               wait_for_all()
        apply_ucode()                wait_for_release()
        release()                    apply_ucode()

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231002115903.377922731@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:33 -04:00
Prarit Bhargava 79463efce2 x86/microcode: Get rid of the schedule work indirection
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 2e1997335ceb6fc819862804f51d4fe83593c138
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Tue Oct 17 23:23:58 2023 +0200

    x86/microcode: Get rid of the schedule work indirection

    Scheduling work on all CPUs to collect the microcode information is just
    another extra step for no value. Let the CPU hotplug callback registration
    do it.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231017211723.354748138@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:33 -04:00
Prarit Bhargava 01736e3c58 x86/microcode: Mop up early loading leftovers
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 8529e8ab6c6fab8ebf06ead98e77d7646b42fc48
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Tue Oct 17 23:23:56 2023 +0200

    x86/microcode: Mop up early loading leftovers

    Get rid of the initrd_gone hack which was required to keep
    find_microcode_in_initrd() functional after init.

    As find_microcode_in_initrd() is now only used during init, mark it
    accordingly.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231017211723.298854846@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:33 -04:00
Prarit Bhargava 0063b52b53 x86/microcode/amd: Use cached microcode for AP load
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 5af05b8d51a8e3ff5905663655c0f46d1aaae44a
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Tue Oct 17 23:23:55 2023 +0200

    x86/microcode/amd: Use cached microcode for AP load

    Now that the microcode cache is initialized before the APs are brought
    up, there is no point in scanning builtin/initrd microcode during AP
    loading.

    Convert the AP loader to utilize the cache, which in turn makes the CPU
    hotplug callback which applies the microcode after initrd/builtin is
    gone, obsolete as the early loading during late hotplug operations
    including the resume path depends now only on the cache.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231017211723.243426023@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:33 -04:00
Prarit Bhargava 981b80e8dc x86/microcode/amd: Cache builtin/initrd microcode early
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit a7939f01672034a58ad3fdbce69bb6c665ce0024
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Tue Oct 17 23:23:53 2023 +0200

    x86/microcode/amd: Cache builtin/initrd microcode early

    There is no reason to scan builtin/initrd microcode on each AP.

    Cache the builtin/initrd microcode in an early initcall so that the
    early AP loader can utilize the cache.

    The existing fs initcall which invoked save_microcode_in_initrd_amd() is
    still required to maintain the initrd_gone flag. Rename it accordingly.
    This will be removed once the AP loader code is converted to use the
    cache.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231017211723.187566507@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:33 -04:00
Prarit Bhargava 24b7b292bf x86/microcode: Remove pointless apply() invocation
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit b48b26f992a3828b4ae274669f99ce68451d4904
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Tue Oct 17 23:23:49 2023 +0200

    x86/microcode: Remove pointless apply() invocation

    Microcode is applied on the APs during early bringup. There is no point
    in trying to apply the microcode again during the hotplug operations and
    neither at the point where the microcode device is initialized.

    Collect CPU info and microcode revision in setup_online_cpu() for now.
    This will move to the CPU hotplug callback later.

      [ bp: Leave the starting notifier for the following scenario:

        - boot, late load, suspend to disk, resume

        without the starting notifier, only the last core manages to update the
        microcode upon resume:

        # rdmsr -a 0x8b
        10000bf
        10000bf
        10000bf
        10000bf
        10000bf
        10000dc <----

        This is on an AMD F10h machine.

        For the future, one should check whether potential unification of
        the CPU init path could cover the resume path too so that this can
        be simplified even more.

      tglx: This is caused by the odd handling of APs which try to find the
      microcode blob in builtin or initrd instead of caching the microcode
      blob during early init before the APs are brought up. Will be cleaned
      up in a later step. ]

    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Link: https://lore.kernel.org/r/20231017211723.018821624@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:33 -04:00
Prarit Bhargava 4b3f6adfaf x86/microcode/amd: Cache builtin microcode too
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit d419d28261e72e1c9ec418711b3da41df2265139
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Tue Oct 10 17:08:43 2023 +0200

    x86/microcode/amd: Cache builtin microcode too

    save_microcode_in_initrd_amd() fails to cache builtin microcode and only
    scans initrd.

    Use find_blobs_in_containers() instead which covers both.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231010150702.495139089@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:33 -04:00
Prarit Bhargava bbdefc16a6 x86/microcode/amd: Use correct per CPU ucode_cpu_info
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit ecfd41089348fa4cc767dc588367e9fdf8cb6b9d
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Tue Oct 10 17:08:41 2023 +0200

    x86/microcode/amd: Use correct per CPU ucode_cpu_info

    find_blobs_in_containers() is invoked on every CPU but overwrites
    unconditionally ucode_cpu_info of CPU0.

    Fix this by using the proper CPU data and move the assignment into the
    call site apply_ucode_from_containers() so that the function can be
    reused.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231010150702.433454320@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:33 -04:00
Prarit Bhargava 5a9dd0e273 x86/microcode: Add per CPU control field
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit ba3aeb97cb2c53025356f31c5a0a294385194115
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Mon Oct 2 14:00:01 2023 +0200

    x86/microcode: Add per CPU control field

    Add a per CPU control field to ucode_ctrl and define constants for it
    which are going to be used to control the loading state machine.

    In theory this could be a global control field, but a global control does
    not cover the following case:

     15 primary CPUs load microcode successfully
      1 primary CPU fails and returns with an error code

    With global control the sibling of the failed CPU would either try again or
    the whole operation would be aborted with the consequence that the 15
    siblings do not invoke the apply path and end up with inconsistent software
    state. The result in dmesg would be inconsistent too.

    There are two additional fields added and initialized:

    ctrl_cpu and secondaries. ctrl_cpu is the CPU number of the primary thread
    for now, but with the upcoming uniform loading at package or system scope
    this will be one CPU per package or just one CPU. Secondaries hands the
    control CPU a CPU mask which will be required to release the secondary CPUs
    out of the wait loop.

    Preparatory change for implementing a properly split control flow for
    primary and secondary CPUs.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231002115903.319959519@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:33 -04:00
Prarit Bhargava 00fab0f2bd x86/microcode: Add per CPU result state
JIRA: https://issues.redhat.com/browse/RHEL-25415

Conflict: For some reason this shows up as a conflict but the end code
is the same in RHEL9 and upstream.

commit 4b753955e9151ad2f722137a7bcbafda756186b3
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Tue Oct 17 23:24:05 2023 +0200

    x86/microcode: Add per CPU result state

    The microcode rendezvous is purely acting on global state, which does
    not allow to analyze fails in a coherent way.

    Introduce per CPU state where the results are written into, which allows to
    analyze the return codes of the individual CPUs.

    Initialize the state when walking the cpu_present_mask in the online
    check to avoid another for_each_cpu() loop.

    Enhance the result print out with that.

    The structure is intentionally named ucode_ctrl as it will gain control
    fields in subsequent changes.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231017211723.632681010@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:33 -04:00
Prarit Bhargava 6601d798bd x86/microcode: Sanitize __wait_for_cpus()
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 0772b9aa1a8f7322dce8588c231cff8b57298a53
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Mon Oct 2 13:59:59 2023 +0200

    x86/microcode: Sanitize __wait_for_cpus()

    The code is too complicated for no reason:

     - The return value is pointless as this is a strict boolean.

     - It's way simpler to count down from num_online_cpus() and check for
       zero.

      - The timeout argument is pointless as this is always one second.

      - Touching the NMI watchdog every 100ns does not make any sense, neither
        does checking every 100ns. This is really not a hotpath operation.

    Preload the atomic counter with the number of online CPUs and simplify the
    whole timeout logic. Delay for one microsecond and touch the NMI watchdog
    once per millisecond.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231002115903.204251527@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:33 -04:00
Prarit Bhargava 715220da5a x86/microcode: Clarify the late load logic
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 6f059e634dcd0d725854514c94c114bbdd83950d
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Mon Oct 2 13:59:57 2023 +0200

    x86/microcode: Clarify the late load logic

    reload_store() is way too complicated. Split the inner workings out and
    make the following enhancements:

     - Taint the kernel only when the microcode was actually updated. If. e.g.
       the rendezvous fails, then nothing happened and there is no reason for
       tainting.

     - Return useful error codes

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Reviewed-by: Nikolay Borisov <nik.borisov@suse.com>
    Link: https://lore.kernel.org/r/20231002115903.145048840@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:33 -04:00
Prarit Bhargava 79f8bcee31 x86/microcode: Handle "nosmt" correctly
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 634ac23ad609b3ddd9e0e478bd5afbf49d3a2556
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Mon Oct 2 13:59:56 2023 +0200

    x86/microcode: Handle "nosmt" correctly

    On CPUs where microcode loading is not NMI-safe the SMT siblings which
    are parked in one of the play_dead() variants still react to NMIs.

    So if an NMI hits while the primary thread updates the microcode the
    resulting behaviour is undefined. The default play_dead() implementation on
    modern CPUs is using MWAIT which is not guaranteed to be safe against
    a microcode update which affects MWAIT.

    Take the cpus_booted_once_mask into account to detect this case and
    refuse to load late if the vendor specific driver does not advertise
    that late loading is NMI safe.

    AMD stated that this is safe, so mark the AMD driver accordingly.

    This requirement will be partially lifted in later changes.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231002115903.087472735@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:33 -04:00
Prarit Bhargava 5ae14d719c x86/microcode: Clean up mc_cpu_down_prep()
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit ba48aa32388ac652256baa8d0a6092d350160da0
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Mon Oct 2 13:59:55 2023 +0200

    x86/microcode: Clean up mc_cpu_down_prep()

    This function has nothing to do with suspend. It's a hotplug
    callback. Remove the bogus comment.

    Drop the pointless debug printk. The hotplug core provides tracepoints
    which track the invocation of those callbacks.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231002115903.028651784@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:32 -04:00
Prarit Bhargava 63fbee917b x86: Enable IBT in Rust if enabled in C
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 6a5c032c4b7e4262488703086ab280406dc51298
Author: Matthew Maurer <mmaurer@google.com>
Date:   Mon Oct 9 22:42:54 2023 +0000

    x86: Enable IBT in Rust if enabled in C

    These flags are not made conditional on compiler support because at the
    moment exactly one version of rustc supported, and that one supports
    these flags.

    Building without these additional flags will manifest as objtool
    printing a large number of errors about missing ENDBR and if CFI is
    enabled (not currently possible) will result in incorrectly structured
    function prefixes.

    Signed-off-by: Matthew Maurer <mmaurer@google.com>
    Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
    Acked-by: "Peter Zijlstra (Intel)" <peterz@infradead.org>
    Link: https://lore.kernel.org/r/20231009224347.2076221-1-mmaurer@google.com
    Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:32 -04:00
Prarit Bhargava 7bd942dd86 x86/callthunks: Delete unused "struct thunk_desc"
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 321a145137653188b8bf9a6b6fc60e8ccb184392
Author: Alexey Dobriyan <adobriyan@gmail.com>
Date:   Sat Oct 14 19:05:28 2023 +0300

    x86/callthunks: Delete unused "struct thunk_desc"

    It looks like it was never used.

    Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: linux-kernel@vger.kernel.org
    Link: https://lore.kernel.org/r/843bf596-db67-4b33-a865-2bae4a4418e5@p183

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:32 -04:00
Prarit Bhargava 2543b8eca8 x86/vdso: Run objtool on vdso32-setup.o
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit b587fef124f98f3ab1322dba8e37cdff660acd8c
Author: David Kaplan <david.kaplan@amd.com>
Date:   Tue Oct 10 12:10:19 2023 -0500

    x86/vdso: Run objtool on vdso32-setup.o

    vdso32-setup.c is part of the main kernel image and should not be
    excluded from objtool.  Objtool is necessary in part for ensuring that
    returns in this file are correctly patched to the appropriate return
    thunk at runtime.

    Signed-off-by: David Kaplan <david.kaplan@amd.com>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Acked-by: Borislav Petkov (AMD) <bp@alien8.de>
    Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Link: https://lore.kernel.org/r/20231010171020.462211-3-david.kaplan@amd.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:32 -04:00
Prarit Bhargava 262085ae03 x86/pti: Fix kernel warnings for pti= and nopti cmdline options
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 0bd7feb2df7ef092c6b8914acca706fb21826f80
Author: Jo Van Bulck <jo.vanbulck@cs.kuleuven.be>
Date:   Sat Aug 19 10:09:21 2023 +0200

    x86/pti: Fix kernel warnings for pti= and nopti cmdline options

    Parse the pti= and nopti cmdline options using early_param to fix 'Unknown
    kernel command line parameters "nopti", will be passed to user space'
    warnings in the kernel log when nopti or pti= are passed to the kernel
    cmdline on x86 platforms.

    Additionally allow the kernel to warn for malformed pti= options.

    Signed-off-by: Jo Van Bulck <jo.vanbulck@cs.kuleuven.be>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Reviewed-by: Sohil Mehta <sohil.mehta@intel.com>
    Link: https://lore.kernel.org/r/20230819080921.5324-2-jo.vanbulck@cs.kuleuven.be

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:32 -04:00
Prarit Bhargava a4b3e22bac x86/mm: Drop the 4 MB restriction on minimal NUMA node memory size
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit a1e2b8b36820d8c91275f207e77e91645b7c6836
Author: Mike Rapoport (IBM) <rppt@kernel.org>
Date:   Wed Oct 18 12:42:50 2023 +0200

    x86/mm: Drop the 4 MB restriction on minimal NUMA node memory size

    Qi Zheng reported crashes in a production environment and provided a
    simplified example as a reproducer:

     |  For example, if we use Qemu to start a two NUMA node kernel,
     |  one of the nodes has 2M memory (less than NODE_MIN_SIZE),
     |  and the other node has 2G, then we will encounter the
     |  following panic:
     |
     |    BUG: kernel NULL pointer dereference, address: 0000000000000000
     |    <...>
     |    RIP: 0010:_raw_spin_lock_irqsave+0x22/0x40
     |    <...>
     |    Call Trace:
     |      <TASK>
     |      deactivate_slab()
     |      bootstrap()
     |      kmem_cache_init()
     |      start_kernel()
     |      secondary_startup_64_no_verify()

    The crashes happen because of inconsistency between the nodemask that
    has nodes with less than 4MB as memoryless, and the actual memory fed
    into the core mm.

    The commit:

      9391a3f9c7 ("[PATCH] x86_64: Clear more state when ignoring empty node in SRAT parsing")

    ... that introduced minimal size of a NUMA node does not explain why
    a node size cannot be less than 4MB and what boot failures this
    restriction might fix.

    Fixes have been submitted to the core MM code to tighten up the
    memory topologies it accepts and to not crash on weird input:

      mm: page_alloc: skip memoryless nodes entirely
      mm: memory_hotplug: drop memoryless node from fallback lists

    Andrew has accepted them into the -mm tree, but there are no
    stable SHA1's yet.

    This patch drops the limitation for minimal node size on x86:

      - which works around the crash without the fixes to the core MM.
      - makes x86 topologies less weird,
      - removes an arbitrary and undocumented limitation on NUMA topologies.

    [ mingo: Improved changelog clarity. ]

    Reported-by: Qi Zheng <zhengqi.arch@bytedance.com>
    Tested-by: Mario Casquero <mcasquer@redhat.com>
    Signed-off-by: Mike Rapoport (IBM) <rppt@kernel.org>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Acked-by: David Hildenbrand <david@redhat.com>
    Acked-by: Michal Hocko <mhocko@suse.com>
    Cc: Dave Hansen <dave.hansen@linux.intel.com>
    Cc: Rik van Riel <riel@surriel.com>
    Link: https://lore.kernel.org/r/ZS+2qqjEO5/867br@gmail.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:32 -04:00
Prarit Bhargava eec32909ea KVM: x86: remove the unused assigned_dev_head from kvm_arch
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 122ae01c5159eb1584e07907aec89e2470622baa
Author: Liang Chen <liangchen.linux@gmail.com>
Date:   Thu Oct 19 12:33:36 2023 +0800

    KVM: x86: remove the unused assigned_dev_head from kvm_arch

    Legacy device assignment was dropped years ago. This field is not used
    anymore.

    Signed-off-by: Liang Chen <liangchen.linux@gmail.com>
    Link: https://lore.kernel.org/r/20231019043336.8998-1-liangchen.linux@gmail.com
    Signed-off-by: Sean Christopherson <seanjc@google.com>

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:32 -04:00
Prarit Bhargava 840d142e7e KVM: x86/mmu: Remove unnecessary ‘NULL’ values from sptep
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 1de9992f9de0a92b6e11133aba0e2be833c11084
Author: Li zeming <zeming@nfschina.com>
Date:   Wed Sep 6 02:20:06 2023 +0800

    KVM: x86/mmu: Remove unnecessary ‘NULL’ values from sptep

    Don't initialize "spte" and "sptep" in fast_page_fault() as they are both
    guaranteed (for all intents and purposes) to be written at the start of
    every loop iteration.  Add a sanity check that "sptep" is non-NULL after
    walking the shadow page tables, as encountering a NULL root would result
    in "spte" not being written, i.e. would lead to uninitialized data or the
    previous value being consumed.

    Signed-off-by: Li zeming <zeming@nfschina.com>
    Link: https://lore.kernel.org/r/20230905182006.2964-1-zeming@nfschina.com
    [sean: rewrite changelog with --verbose]
    Signed-off-by: Sean Christopherson <seanjc@google.com>

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:32 -04:00
Prarit Bhargava b3f9007e50 KVM: x86: remove always-false condition in kvmclock_sync_fn
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 2081a8450ef803e2e1136a80975eebc8682879b5
Author: Dongli Zhang <dongli.zhang@oracle.com>
Date:   Sun Oct 1 14:36:37 2023 -0700

    KVM: x86: remove always-false condition in kvmclock_sync_fn

    The 'kvmclock_periodic_sync' is a readonly param that cannot change after
    bootup.

    The kvm_arch_vcpu_postcreate() is not going to schedule the
    kvmclock_sync_work if kvmclock_periodic_sync == false.

    As a result, the "if (!kvmclock_periodic_sync)" can never be true if the
    kvmclock_sync_work = kvmclock_sync_fn() is scheduled.

    Link: https://lore.kernel.org/kvm/a461bf3f-c17e-9c3f-56aa-726225e8391d@oracle.com
    Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
    Link: https://lore.kernel.org/r/20231001213637.76686-1-dongli.zhang@oracle.com
    Signed-off-by: Sean Christopherson <seanjc@google.com>

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:32 -04:00
Prarit Bhargava 017b9287f3 x86/boot/32: Temporarily map initrd for microcode loading
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 4c585af7180c147062c636a927a2fc2b6a7072f5
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Tue Oct 17 23:23:31 2023 +0200

    x86/boot/32: Temporarily map initrd for microcode loading

    Early microcode loading on 32-bit runs in physical address mode because
    the initrd is not covered by the initial page tables. That results in
    a horrible mess all over the microcode loader code.

    Provide a temporary mapping for the initrd in the initial page tables by
    appending it to the actual initial mapping starting with a new PGD or
    PMD depending on the configured page table levels ([non-]PAE).

    The page table entries are located after _brk_end so they are not
    permanently using memory space. The mapping is invalidated right away in
    i386_start_kernel() after the early microcode loader has run.

    This prepares for removing the physical address mode oddities from all
    over the microcode loader code, which in turn allows further cleanups.

    Provide the map and unmap code and document the place where the
    microcode loader needs to be invoked with a comment.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231017211722.292291436@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:32 -04:00
Prarit Bhargava 4b1c5022a3 x86/microcode: Provide CONFIG_MICROCODE_INITRD32
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit fdbd43819400e74c1c20a646969ea8f71706eb2b
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Tue Oct 17 23:23:29 2023 +0200

    x86/microcode: Provide CONFIG_MICROCODE_INITRD32

    Create an aggregate config switch which covers X86_32, MICROCODE and
    BLK_DEV_INITRD to avoid lengthy #ifdeffery in upcoming code.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231017211722.236208250@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:32 -04:00
Prarit Bhargava 4cde6bd2af x86/boot/32: Restructure mk_early_pgtbl_32()
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 69ba866db281c768d5ecca909361ea4c4e71d57e
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Tue Oct 17 23:23:28 2023 +0200

    x86/boot/32: Restructure mk_early_pgtbl_32()

    Prepare it for adding a temporary initrd mapping by splitting out the
    actual map loop.

    No functional change.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231017211722.175910753@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:32 -04:00
Prarit Bhargava 7b0b20c3cc x86/boot/32: De-uglify the 2/3 level paging difference in mk_early_pgtbl_32()
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit a62f4ca106fd250e9247decd100f3905131fc1fe
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Tue Oct 17 23:23:26 2023 +0200

    x86/boot/32: De-uglify the 2/3 level paging difference in mk_early_pgtbl_32()

    Move the ifdeffery out of the function and use proper typedefs to make it
    work for both 2 and 3 level paging.

    No functional change.

      [ bp: Move mk_early_pgtbl_32() declaration into a header. ]

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231017211722.111059491@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:31 -04:00
Prarit Bhargava 6bbf379b0d x86/boot: Use __pa_nodebug() in mk_early_pgtbl_32()
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 1e2dd572d2b773b5b8882aae66e5f0328d562aa9
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Tue Oct 17 23:23:25 2023 +0200

    x86/boot: Use __pa_nodebug() in mk_early_pgtbl_32()

    Use the existing macro instead of undefining and redefining __pa().

    No functional change.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231017211722.051625827@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:31 -04:00
Prarit Bhargava 439145e2a3 x86/boot/32: Disable stackprotector and tracing for mk_early_pgtbl_32()
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 242db7589460ca94e28c51ffbddd621756f97e11
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Mon Oct 2 13:59:36 2023 +0200

    x86/boot/32: Disable stackprotector and tracing for mk_early_pgtbl_32()

    Stackprotector cannot work before paging is enabled. The read from the per
    CPU variable __stack_chk_guard is always accessing the virtual address
    either directly on UP or via FS on SMP. In physical address mode this
    results in an access to memory above 3GB.

    So this works by chance as the hardware returns the same value when there
    is no RAM at this physical address. When there is RAM populated above 3G
    then the read is by chance the same as nothing changes that memory during
    the very early boot stage.

    Stop relying on pure luck and disable the stack protector for the only C
    function which is called during early boot before paging is enabled.

    Remove function tracing from the whole source file as there is no way to
    trace this at all, but in case of CONFIG_DYNAMIC_FTRACE=n
    mk_early_pgtbl_32() would access global function tracer variables in
    physical address mode which again might work by chance.

    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20231002115902.156063939@linutronix.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:31 -04:00
Prarit Bhargava 6270b23ce2 UML: remove unused cmd_vdso_install
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 7aef8f76d1f944288eafda1a9eb285fa18383121
Author: Masahiro Yamada <masahiroy@kernel.org>
Date:   Mon Oct 9 21:42:07 2023 +0900

    UML: remove unused cmd_vdso_install

    You cannot run this code because arch/um/Makefile does not define the
    vdso_install target.

    It appears that this code was blindly copied from another architecture.

    Remove the dead code.

    Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
    Acked-by: Richard Weinberger <richard@nod.at>

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:31 -04:00
Prarit Bhargava 16a5e82ac7 KVM: x86: Update the variable naming in kvm_x86_ops.sched_in()
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 5a989bbead4cc9cd67c3911226ad857d293643d8
Author: Mingwei Zhang <mizhang@google.com>
Date:   Tue Oct 17 23:26:10 2023 +0000

    KVM: x86: Update the variable naming in kvm_x86_ops.sched_in()

    Update the variable with name 'kvm' in kvm_x86_ops.sched_in() to 'vcpu' to
    avoid confusions. Variable naming in KVM has a clear convention that 'kvm'
    refers to pointer of type 'struct kvm *', while 'vcpu' refers to pointer of
    type 'struct kvm_vcpu *'.

    Fix this 9-year old naming issue for fun.

    Signed-off-by: Mingwei Zhang <mizhang@google.com>
    Link: https://lore.kernel.org/r/20231017232610.4008690-1-mizhang@google.com
    Signed-off-by: Sean Christopherson <seanjc@google.com>

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:31 -04:00
Prarit Bhargava 3fd55937fa x86/microcode/amd: Fix snprintf() format string warning in W=1 build
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 2e9064faccd1a5b9de8c6f4b23d9f4948901cbe9
Author: Paolo Bonzini <pbonzini@redhat.com>
Date:   Mon Oct 16 18:48:58 2023 -0400

    x86/microcode/amd: Fix snprintf() format string warning in W=1 build

    Building with GCC 11.x results in the following warning:

      arch/x86/kernel/cpu/microcode/amd.c: In function ‘find_blobs_in_containers’:
      arch/x86/kernel/cpu/microcode/amd.c:504:58: error: ‘h.bin’ directive output may be truncated writing 5 bytes into a region of size between 1 and 7 [-Werror=format-truncation=]
      arch/x86/kernel/cpu/microcode/amd.c:503:17: note: ‘snprintf’ output between 35 and 41 bytes into a destination of size 36

    The issue is that GCC does not know that the family can only be a byte
    (it ultimately comes from CPUID).  Suggest the right size to the compiler
    by marking the argument as char-size ("hh").  While at it, instead of
    using the slightly more obscure precision specifier use the width with
    zero padding (over 23000 occurrences in kernel sources, vs 500 for
    the idiom using the precision).

    Reported-by: kernel test robot <lkp@intel.com>
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Closes: https://lore.kernel.org/oe-kbuild-all/202308252255.2HPJ6x5Q-lkp@intel.com/
    Link: https://lore.kernel.org/r/20231016224858.2829248-1-pbonzini@redhat.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:31 -04:00
Prarit Bhargava 4ed733cd80 KVM: x86: Use octal for file permission
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 26951ec8623e915823985e86d2c428213f110659
Author: Peng Hao <flyingpeng@tencent.com>
Date:   Fri Oct 13 19:30:20 2023 +0800

    KVM: x86: Use octal for file permission

    Convert all module params to octal permissions to improve code readability
    and to make checkpatch happy:

      WARNING: Symbolic permissions 'S_IRUGO' are not preferred. Consider using
               octal permissions '0444'.

    Signed-off-by: Peng Hao <flyingpeng@tencent.com>
    Link: https://lore.kernel.org/r/20231013113020.77523-1-flyingpeng@tencent.com
    Signed-off-by: Sean Christopherson <seanjc@google.com>

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:31 -04:00
Prarit Bhargava 1c4b11d6b4 x86/head/64: Move the __head definition to <asm/init.h>
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit d2a285d65bfde3218fd0c3b88794d0135ced680b
Author: Hou Wenlong <houwenlong.hwl@antgroup.com>
Date:   Tue Oct 17 15:08:06 2023 +0800

    x86/head/64: Move the __head definition to <asm/init.h>

    Move the __head section definition to a header to widen its use.

    An upcoming patch will mark the code as __head in mem_encrypt_identity.c too.

    Signed-off-by: Hou Wenlong <houwenlong.hwl@antgroup.com>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Link: https://lore.kernel.org/r/0583f57977be184689c373fe540cbd7d85ca2047.1697525407.git.houwenlong.hwl@antgroup.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:31 -04:00
Prarit Bhargava a5691889cd vgacon: remove screen_info dependency
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit acfc788233263fee9413434d39d4201a8de592ba
Author: Arnd Bergmann <arnd@arndb.de>
Date:   Mon Oct 9 23:18:41 2023 +0200

    vgacon: remove screen_info dependency

    The vga console driver is fairly self-contained, and only used by
    architectures that explicitly initialize the screen_info settings.

    Chance every instance that picks the vga console by setting conswitchp
    to call a function instead, and pass a reference to the screen_info
    there.

    Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
    Acked-by: Khalid Azzi <khalid@gonehiking.org>
    Acked-by: Helge Deller <deller@gmx.de>
    Signed-off-by: Arnd Bergmann <arnd@arndb.de>
    Link: https://lore.kernel.org/r/20231009211845.3136536-6-arnd@kernel.org
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:31 -04:00
Prarit Bhargava d1faccec1a x86/mce: Cleanup mce_usable_address()
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 1bae0cfe4a171ccc5f731426296e45beafa096b8
Author: Yazen Ghannam <yazen.ghannam@amd.com>
Date:   Tue Jun 13 09:11:42 2023 -0500

    x86/mce: Cleanup mce_usable_address()

    Move Intel-specific checks into a helper function.

    Explicitly use "bool" for return type.

    No functional change intended.

    Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20230613141142.36801-4-yazen.ghannam@amd.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:31 -04:00
Prarit Bhargava 531d060c18 x86/mce: Define amd_mce_usable_address()
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 48da1ad8ba95ecd35d76355594c629f3ef2a954a
Author: Yazen Ghannam <yazen.ghannam@amd.com>
Date:   Tue Jun 13 09:11:41 2023 -0500

    x86/mce: Define amd_mce_usable_address()

    Currently, all valid MCA_ADDR values are assumed to be usable on AMD
    systems. However, this is not correct in most cases. Notifiers expecting
    usable addresses may then operate on inappropriate values.

    Define a helper function to do AMD-specific checks for a usable memory
    address. List out all known cases.

      [ bp: Tone down the capitalized words. ]

    Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/20230613141142.36801-3-yazen.ghannam@amd.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:31 -04:00
Prarit Bhargava 7dec0f92c2 x86/MCE/AMD: Split amd_mce_is_memory_error()
JIRA: https://issues.redhat.com/browse/RHEL-25415

commit 495a91d0998367f4f079593f491bdfe8ef06838e
Author: Yazen Ghannam <yazen.ghannam@amd.com>
Date:   Tue Jun 13 09:11:40 2023 -0500

    x86/MCE/AMD: Split amd_mce_is_memory_error()

    Define helper functions for legacy and SMCA systems in order to reuse
    individual checks in later changes.

    Describe what each function is checking for, and correct the XEC bitmask
    for SMCA.

    No functional change intended.

      [ bp: Use "else in amd_mce_is_memory_error() to make the conditional
        balanced, for readability. ]

    Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Reviewed-by: Shuai Xue <xueshuai@linux.alibaba.com>
    Link: https://lore.kernel.org/r/20230613141142.36801-2-yazen.ghannam@amd.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:31 -04:00