Commit Graph

11 Commits

Author SHA1 Message Date
Benjamin Poirier dc96adbf39 lib: cpu_rmap: Fix potential use-after-free in irq_cpu_rmap_release()
JIRA: https://issues.redhat.com/browse/RHEL-47128
Upstream-status: v6.4-rc6

commit 7c5d4801ecf0564c860033d89726b99723c55146
Author: Ben Hutchings <ben@decadent.org.uk>
Date:   Fri Jun 2 20:28:15 2023 +0200

    lib: cpu_rmap: Fix potential use-after-free in irq_cpu_rmap_release()

    irq_cpu_rmap_release() calls cpu_rmap_put(), which may free the rmap.
    So we need to clear the pointer to our glue structure in rmap before
    doing that, not after.

    Fixes: 4e0473f1060a ("lib: cpu_rmap: Avoid use after free on rmap->obj array entries")
    Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
    Reviewed-by: Simon Horman <simon.horman@corigine.com>
    Link: https://lore.kernel.org/r/ZHo0vwquhOy3FaXc@decadent.org.uk
    Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Signed-off-by: Benjamin Poirier <bpoirier@redhat.com>
2024-12-12 11:53:07 -05:00
Benjamin Poirier 2de91d5286 lib: cpu_rmap: Use allocator for rmap entries
JIRA: https://issues.redhat.com/browse/RHEL-47128
Upstream-status: v6.4-rc1

commit 9821d8d4628e630ab56f47a8e6b878a2576e069b
Author: Eli Cohen <elic@nvidia.com>
Date:   Tue Feb 14 09:29:46 2023 +0200

    lib: cpu_rmap: Use allocator for rmap entries

    Use a proper allocator for rmap entries using a naive for loop. The
    allocator relies on whether an entry is NULL to be considered free.
    Remove the used field of rmap which is not needed.

    Also, avoid crashing the kernel if an entry is not available.

    Cc: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Eli Cohen <elic@nvidia.com>
    Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
    Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>

Signed-off-by: Benjamin Poirier <bpoirier@redhat.com>
2024-12-12 11:53:07 -05:00
Benjamin Poirier c91dcf4016 lib: cpu_rmap: Avoid use after free on rmap->obj array entries
JIRA: https://issues.redhat.com/browse/RHEL-47128
Upstream-status: v6.4-rc1

commit 4e0473f1060aa49621d40a113afde24818101d37
Author: Eli Cohen <elic@nvidia.com>
Date:   Wed Feb 8 07:51:02 2023 +0200

    lib: cpu_rmap: Avoid use after free on rmap->obj array entries

    When calling irq_set_affinity_notifier() with NULL at the notify
    argument, it will cause freeing of the glue pointer in the
    corresponding array entry but will leave the pointer in the array. A
    subsequent call to free_irq_cpu_rmap() will try to free this entry again
    leading to possible use after free.

    Fix that by setting NULL to the array entry and checking that we have
    non-zero at the array entry when iterating over the array in
    free_irq_cpu_rmap().

    The current code does not suffer from this since there are no cases
    where irq_set_affinity_notifier(irq, NULL) (note the NULL passed for the
    notify arg) is called, followed by a call to free_irq_cpu_rmap() so we
    don't hit and issue. Subsequent patches in this series excersize this
    flow, hence the required fix.

    Cc: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Eli Cohen <elic@nvidia.com>
    Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
    Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>

Signed-off-by: Benjamin Poirier <bpoirier@redhat.com>
2024-12-12 11:53:07 -05:00
Petr Oros 00210f3493 lib: cpu_rmap: Add irq_cpu_rmap_remove to complement irq_cpu_rmap_add
JIRA: https://issues.redhat.com/browse/RHEL-5076

Upstream commit(s):
commit 71f0a2478605c100358a9f9e174849fa643bf8a7
Author: Eli Cohen <elic@nvidia.com>
Date:   Tue Feb 14 11:05:46 2023 +0200

    lib: cpu_rmap: Add irq_cpu_rmap_remove to complement irq_cpu_rmap_add

    Add a function to complement irq_cpu_rmap_add(). It removes the irq from
    the reverse mapping by setting the notifier to NULL. The function calls
    irq_set_affinity_notifier() with NULL at the notify argument which then
    cancel any pending notifier work and decrement reference on the
    notifier. When ref count reaches zero, the glue pointer is kfree and the
    rmap entry is set to NULL serving both to avoid second attempt to
    release it and also making the rmap entry available for subsequent
    mapping.

    It should be noted the drivers usually creates the reverse mapping at
    initialization time and remove it at unload time so we do not expect
    failures in allocating rmap due to kref holding the glue entry.

    Cc: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Eli Cohen <elic@nvidia.com>
    Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
    Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>

Signed-off-by: Petr Oros <poros@redhat.com>
2023-09-22 09:42:13 +02:00
Kefeng Wang 256339d602 lib: cpu_rmap: Use pr_warn instead of pr_warning
As said in commit f2c2cbcc35 ("powerpc: Use pr_warn instead of
pr_warning"), removing pr_warning so all logging messages use a
consistent <prefix>_warn style. Let's do it.

Link: http://lkml.kernel.org/r/20191018031850.48498-27-wangkefeng.wang@huawei.com
To: linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
2019-10-18 15:01:57 +02:00
Thomas Gleixner d2912cb15b treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500
Based on 2 normalized pattern(s):

  this program is free software you can redistribute it and or modify
  it under the terms of the gnu general public license version 2 as
  published by the free software foundation

  this program is free software you can redistribute it and or modify
  it under the terms of the gnu general public license version 2 as
  published by the free software foundation #

extracted by the scancode license scanner the SPDX license identifier

  GPL-2.0-only

has been chosen to replace the boilerplate/reference in 4122 file(s).

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Enrico Weigelt <info@metux.net>
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Allison Randal <allison@lohutok.net>
Cc: linux-spdx@vger.kernel.org
Link: https://lkml.kernel.org/r/20190604081206.933168790@linutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-06-19 17:09:55 +02:00
Bartosz Golaszewski 06931e6224 sched/topology: Rename topology_thread_cpumask() to topology_sibling_cpumask()
Rename topology_thread_cpumask() to topology_sibling_cpumask()
for more consistency with scheduler code.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Russell King <rmk+kernel@arm.linux.org.uk>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Cc: Benoit Cousson <bcousson@baylibre.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Jean Delvare <jdelvare@suse.de>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Drokin <oleg.drokin@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Link: http://lkml.kernel.org/r/1432645896-12588-2-git-send-email-bgolaszewski@baylibre.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-27 15:22:15 +02:00
Martin Schwidefsky 0244ad004a Remove GENERIC_HARDIRQ config option
After the last architecture switched to generic hard irqs the config
options HAVE_GENERIC_HARDIRQS & GENERIC_HARDIRQS and the related code
for !CONFIG_GENERIC_HARDIRQS can be removed.

Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
2013-09-13 15:09:52 +02:00
David Decotigny 896f97ea95 lib: cpu_rmap: avoid flushing all workqueues
In some cases, free_irq_cpu_rmap() is called while holding a lock (eg
rtnl).  This can lead to deadlocks, because it invokes
flush_scheduled_work() which ends up waiting for whole system workqueue
to flush, but some pending works might try to acquire the lock we are
already holding.

This commit uses reference-counting to replace
irq_run_affinity_notifiers().  It also removes
irq_run_affinity_notifiers() altogether.

[akpm@linux-foundation.org: eliminate free_cpu_rmap, rename cpu_rmap_reclaim() to cpu_rmap_release(), propagate kref_put() retval from cpu_rmap_put()]
Signed-off-by: David Decotigny <decot@googlers.com>
Reviewed-by: Ben Hutchings <bhutchings@solarflare.com>
Acked-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Josh Triplett <josh@joshtriplett.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Or Gerlitz <ogerlitz@mellanox.com>
Acked-by: Amir Vadai <amirv@mellanox.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-01-11 14:54:54 -08:00
Paul Gortmaker 8bc3bcc93a lib: reduce the use of module.h wherever possible
For files only using THIS_MODULE and/or EXPORT_SYMBOL, map
them onto including export.h -- or if the file isn't even
using those, then just delete the include.  Fix up any implicit
include dependencies that were being masked by module.h along
the way.

Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
2012-03-07 15:04:04 -05:00
Ben Hutchings c39649c331 lib: cpu_rmap: CPU affinity reverse-mapping
When initiating I/O on a multiqueue and multi-IRQ device, we may want
to select a queue for which the response will be handled on the same
or a nearby CPU.  This requires a reverse-map of IRQ affinity.  Add
library functions to support a generic reverse-mapping from CPUs to
objects with affinity and the specific case where the objects are
IRQs.

Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-01-24 14:51:56 -08:00