On a Xen dom0 boot, this feature does not behave, and we end up
calculating:
num_roots = 1
num_nodes = 2
roots_per_node = 0
This causes a divide-by-zero in the modulus inside the loop.
This change adds a couple of guards for invalid states where we might
get a divide-by-zero.
Signed-off-by: Steven Noonan <steven(a)uplinklabs.net>
Signed-off-by: Ariadne Conill <ariadne(a)ariadne.space>
CC: Yazen Ghannam <yazen.ghannam(a)amd.com>
CC: x86(a)vger.kernel.org
CC: stable(a)vger.kernel.org
---
arch/x86/kernel/amd_node.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/arch/x86/kernel/amd_node.c b/arch/x86/kernel/amd_node.c
index 3d0a4768d603c..cdc6ba224d4ad 100644
--- a/arch/x86/kernel/amd_node.c
+++ b/arch/x86/kernel/amd_node.c
@@ -282,6 +282,17 @@ static int __init amd_smn_init(void)
return -ENODEV;
num_nodes = amd_num_nodes();
+
+ if (!num_nodes)
+ return -ENODEV;
+
+ /* Possibly a virtualized environment (e.g. Xen) where we wi
ll get
+ * roots_per_node=0 if the number of roots is fewer than number of
+ * nodes
+ */
+ if (num_roots < num_nodes)
+ return -ENODEV;
+
amd_roots = kcalloc(num_nodes, sizeof(*amd_roots), GFP_KERNEL);
if (!amd_roots)
return -ENOMEM;
--
2.51.2
From: Maciej Wieczor-Retman <maciej.wieczor-retman(a)intel.com>
A KASAN tag mismatch, possibly causing a kernel panic, can be observed
on systems with a tag-based KASAN enabled and with multiple NUMA nodes.
It was reported on arm64 and reproduced on x86. It can be explained in
the following points:
1. There can be more than one virtual memory chunk.
2. Chunk's base address has a tag.
3. The base address points at the first chunk and thus inherits
the tag of the first chunk.
4. The subsequent chunks will be accessed with the tag from the
first chunk.
5. Thus, the subsequent chunks need to have their tag set to
match that of the first chunk.
Use the new vmalloc flag that disables random tag assignment in
__kasan_unpoison_vmalloc() - pass the same random tag to all the
vm_structs by tagging the pointers before they go inside
__kasan_unpoison_vmalloc(). Assigning a common tag resolves the pcpu
chunk address mismatch.
Fixes: 1d96320f8d53 ("kasan, vmalloc: add vmalloc tagging for SW_TAGS")
Cc: stable(a)vger.kernel.org # 6.1+
Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman(a)intel.com>
Reviewed-by: Andrey Konovalov <andreyknvl(a)gmail.com>
---
Changelog v4:
- Add WARN_ON_ONCE() if the new flag is already set in the helper.
(Andrey)
- Remove pr_warn() since the comment should be enough. (Andrey)
Changelog v3:
- Redo the patch by using a flag instead of a new argument in
__kasan_unpoison_vmalloc() (Andrey Konovalov)
Changelog v2:
- Revise the whole patch to match the fixed refactorization from the
first patch.
Changelog v1:
- Rewrite the patch message to point at the user impact of the issue.
- Move helper to common.c so it can be compiled in all KASAN modes.
mm/kasan/common.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/mm/kasan/common.c b/mm/kasan/common.c
index 1ed6289d471a..589be3d86735 100644
--- a/mm/kasan/common.c
+++ b/mm/kasan/common.c
@@ -591,11 +591,26 @@ void __kasan_unpoison_vmap_areas(struct vm_struct **vms, int nr_vms,
unsigned long size;
void *addr;
int area;
+ u8 tag;
+
+ /*
+ * If KASAN_VMALLOC_KEEP_TAG was set at this point, all vms[] pointers
+ * would be unpoisoned with the KASAN_TAG_KERNEL which would disable
+ * KASAN checks down the line.
+ */
+ if (WARN_ON_ONCE(flags & KASAN_VMALLOC_KEEP_TAG))
+ return;
+
+ size = vms[0]->size;
+ addr = vms[0]->addr;
+ vms[0]->addr = __kasan_unpoison_vmalloc(addr, size, flags);
+ tag = get_tag(vms[0]->addr);
- for (area = 0 ; area < nr_vms ; area++) {
+ for (area = 1 ; area < nr_vms ; area++) {
size = vms[area]->size;
- addr = vms[area]->addr;
- vms[area]->addr = __kasan_unpoison_vmalloc(addr, size, flags);
+ addr = set_tag(vms[area]->addr, tag);
+ vms[area]->addr =
+ __kasan_unpoison_vmalloc(addr, size, flags | KASAN_VMALLOC_KEEP_TAG);
}
}
#endif
--
2.52.0
From: Maciej Wieczor-Retman <maciej.wieczor-retman(a)intel.com>
A KASAN tag mismatch, possibly causing a kernel panic, can be observed
on systems with a tag-based KASAN enabled and with multiple NUMA nodes.
It was reported on arm64 and reproduced on x86. It can be explained in
the following points:
1. There can be more than one virtual memory chunk.
2. Chunk's base address has a tag.
3. The base address points at the first chunk and thus inherits
the tag of the first chunk.
4. The subsequent chunks will be accessed with the tag from the
first chunk.
5. Thus, the subsequent chunks need to have their tag set to
match that of the first chunk.
Refactor code by reusing __kasan_unpoison_vmalloc in a new helper in
preparation for the actual fix.
Fixes: 1d96320f8d53 ("kasan, vmalloc: add vmalloc tagging for SW_TAGS")
Cc: stable(a)vger.kernel.org # 6.1+
Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman(a)intel.com>
Reviewed-by: Andrey Konovalov <andreyknvl(a)gmail.com>
---
Changelog v1: (after splitting of from the KASAN series)
- Rewrite first paragraph of the patch message to point at the user
impact of the issue.
- Move helper to common.c so it can be compiled in all KASAN modes.
Changelog v2:
- Redo the whole patch so it's an actual refactor.
Changelog v3:
- Redo the patch after applying Andrey's comments to align the code more
with what's already in include/linux/kasan.h
include/linux/kasan.h | 15 +++++++++++++++
mm/kasan/common.c | 17 +++++++++++++++++
mm/vmalloc.c | 4 +---
3 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/include/linux/kasan.h b/include/linux/kasan.h
index 6d7972bb390c..cde493cb7702 100644
--- a/include/linux/kasan.h
+++ b/include/linux/kasan.h
@@ -615,6 +615,16 @@ static __always_inline void kasan_poison_vmalloc(const void *start,
__kasan_poison_vmalloc(start, size);
}
+void __kasan_unpoison_vmap_areas(struct vm_struct **vms, int nr_vms,
+ kasan_vmalloc_flags_t flags);
+static __always_inline void
+kasan_unpoison_vmap_areas(struct vm_struct **vms, int nr_vms,
+ kasan_vmalloc_flags_t flags)
+{
+ if (kasan_enabled())
+ __kasan_unpoison_vmap_areas(vms, nr_vms, flags);
+}
+
#else /* CONFIG_KASAN_VMALLOC */
static inline void kasan_populate_early_vm_area_shadow(void *start,
@@ -639,6 +649,11 @@ static inline void *kasan_unpoison_vmalloc(const void *start,
static inline void kasan_poison_vmalloc(const void *start, unsigned long size)
{ }
+static __always_inline void
+kasan_unpoison_vmap_areas(struct vm_struct **vms, int nr_vms,
+ kasan_vmalloc_flags_t flags)
+{ }
+
#endif /* CONFIG_KASAN_VMALLOC */
#if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \
diff --git a/mm/kasan/common.c b/mm/kasan/common.c
index d4c14359feaf..1ed6289d471a 100644
--- a/mm/kasan/common.c
+++ b/mm/kasan/common.c
@@ -28,6 +28,7 @@
#include <linux/string.h>
#include <linux/types.h>
#include <linux/bug.h>
+#include <linux/vmalloc.h>
#include "kasan.h"
#include "../slab.h"
@@ -582,3 +583,19 @@ bool __kasan_check_byte(const void *address, unsigned long ip)
}
return true;
}
+
+#ifdef CONFIG_KASAN_VMALLOC
+void __kasan_unpoison_vmap_areas(struct vm_struct **vms, int nr_vms,
+ kasan_vmalloc_flags_t flags)
+{
+ unsigned long size;
+ void *addr;
+ int area;
+
+ for (area = 0 ; area < nr_vms ; area++) {
+ size = vms[area]->size;
+ addr = vms[area]->addr;
+ vms[area]->addr = __kasan_unpoison_vmalloc(addr, size, flags);
+ }
+}
+#endif
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 22a73a087135..33e705ccafba 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -4872,9 +4872,7 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
* With hardware tag-based KASAN, marking is skipped for
* non-VM_ALLOC mappings, see __kasan_unpoison_vmalloc().
*/
- for (area = 0; area < nr_vms; area++)
- vms[area]->addr = kasan_unpoison_vmalloc(vms[area]->addr,
- vms[area]->size, KASAN_VMALLOC_PROT_NORMAL);
+ kasan_unpoison_vmap_areas(vms, nr_vms, KASAN_VMALLOC_PROT_NORMAL);
kfree(vas);
return vms;
--
2.52.0
The acpi_get_first_physical_node() function can return NULL, in which
case the get_device() function also returns NULL, but this value is
then dereferenced without checking,so add a check to prevent a crash.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Fixes: 7b2f3eb492da ("ALSA: hda: cs35l41: Add support for CS35L41 in HDA systems")
Cc: stable(a)vger.kernel.org
Signed-off-by: Denis Arefev <arefev(a)swemel.ru>
---
sound/hda/codecs/side-codecs/cs35l41_hda.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/sound/hda/codecs/side-codecs/cs35l41_hda.c b/sound/hda/codecs/side-codecs/cs35l41_hda.c
index c0f2a3ff77a1..21e00055c0c4 100644
--- a/sound/hda/codecs/side-codecs/cs35l41_hda.c
+++ b/sound/hda/codecs/side-codecs/cs35l41_hda.c
@@ -1901,6 +1901,8 @@ static int cs35l41_hda_read_acpi(struct cs35l41_hda *cs35l41, const char *hid, i
cs35l41->dacpi = adev;
physdev = get_device(acpi_get_first_physical_node(adev));
+ if (!physdev)
+ return -ENODEV;
sub = acpi_get_subsystem_id(ACPI_HANDLE(physdev));
if (IS_ERR(sub))
--
2.43.0
From: Maciej Wieczor-Retman <maciej.wieczor-retman(a)intel.com>
A KASAN tag mismatch, possibly causing a kernel panic, can be observed
on systems with a tag-based KASAN enabled and with multiple NUMA nodes.
It was reported on arm64 and reproduced on x86. It can be explained in
the following points:
1. There can be more than one virtual memory chunk.
2. Chunk's base address has a tag.
3. The base address points at the first chunk and thus inherits
the tag of the first chunk.
4. The subsequent chunks will be accessed with the tag from the
first chunk.
5. Thus, the subsequent chunks need to have their tag set to
match that of the first chunk.
Use the new vmalloc flag that disables random tag assignment in
__kasan_unpoison_vmalloc() - pass the same random tag to all the
vm_structs by tagging the pointers before they go inside
__kasan_unpoison_vmalloc(). Assigning a common tag resolves the pcpu
chunk address mismatch.
Fixes: 1d96320f8d53 ("kasan, vmalloc: add vmalloc tagging for SW_TAGS")
Cc: <stable(a)vger.kernel.org> # 6.1+
Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman(a)intel.com>
---
Changelog v3:
- Redo the patch by using a flag instead of a new argument in
__kasan_unpoison_vmalloc() (Andrey Konovalov)
Changelog v2:
- Revise the whole patch to match the fixed refactorization from the
first patch.
Changelog v1:
- Rewrite the patch message to point at the user impact of the issue.
- Move helper to common.c so it can be compiled in all KASAN modes.
mm/kasan/common.c | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/mm/kasan/common.c b/mm/kasan/common.c
index 1ed6289d471a..496bb2c56911 100644
--- a/mm/kasan/common.c
+++ b/mm/kasan/common.c
@@ -591,11 +591,28 @@ void __kasan_unpoison_vmap_areas(struct vm_struct **vms, int nr_vms,
unsigned long size;
void *addr;
int area;
+ u8 tag;
+
+ /*
+ * If KASAN_VMALLOC_KEEP_TAG was set at this point, all vms[] pointers
+ * would be unpoisoned with the KASAN_TAG_KERNEL which would disable
+ * KASAN checks down the line.
+ */
+ if (flags & KASAN_VMALLOC_KEEP_TAG) {
+ pr_warn("KASAN_VMALLOC_KEEP_TAG flag shouldn't be already set!\n");
+ return;
+ }
+
+ size = vms[0]->size;
+ addr = vms[0]->addr;
+ vms[0]->addr = __kasan_unpoison_vmalloc(addr, size, flags);
+ tag = get_tag(vms[0]->addr);
- for (area = 0 ; area < nr_vms ; area++) {
+ for (area = 1 ; area < nr_vms ; area++) {
size = vms[area]->size;
- addr = vms[area]->addr;
- vms[area]->addr = __kasan_unpoison_vmalloc(addr, size, flags);
+ addr = set_tag(vms[area]->addr, tag);
+ vms[area]->addr =
+ __kasan_unpoison_vmalloc(addr, size, flags | KASAN_VMALLOC_KEEP_TAG);
}
}
#endif
--
2.52.0
Xorg fails to start with defaults on AMD KV260, /var/log/Xorg.0.log:
[ 23.491] (II) Loading /usr/lib/xorg/modules/drivers/fbdev_drv.so
[ 23.491] (II) Module fbdev: vendor="X.Org Foundation"
[ 23.491] compiled for 1.21.1.18, module version = 0.5.1
[ 23.491] Module class: X.Org Video Driver
[ 23.491] ABI class: X.Org Video Driver, version 25.2
[ 23.491] (II) modesetting: Driver for Modesetting Kernel Drivers:
kms
[ 23.491] (II) FBDEV: driver for framebuffer: fbdev
[ 23.510] (II) modeset(0): using drv /dev/dri/card1
[ 23.511] (WW) Falling back to old probe method for fbdev
[ 23.511] (II) Loading sub module "fbdevhw"
[ 23.511] (II) LoadModule: "fbdevhw"
[ 23.511] (II) Loading /usr/lib/xorg/modules/libfbdevhw.so
[ 23.511] (II) Module fbdevhw: vendor="X.Org Foundation"
[ 23.511] compiled for 1.21.1.18, module version = 0.0.2
[ 23.511] ABI class: X.Org Video Driver, version 25.2
[ 23.512] (II) modeset(0): Creating default Display subsection in
Screen section
"Default Screen Section" for depth/fbbpp 24/32
[ 23.512] (==) modeset(0): Depth 24, (==) framebuffer bpp 32
[ 23.512] (==) modeset(0): RGB weight 888
[ 23.512] (==) modeset(0): Default visual is TrueColor
...
[ 23.911] (II) Loading sub module "fb"
[ 23.911] (II) LoadModule: "fb"
[ 23.911] (II) Module "fb" already built-in
[ 23.911] (II) UnloadModule: "fbdev"
[ 23.911] (II) Unloading fbdev
[ 23.912] (II) UnloadSubModule: "fbdevhw"
[ 23.912] (II) Unloading fbdevhw
[ 24.238] (==) modeset(0): Backing store enabled
[ 24.238] (==) modeset(0): Silken mouse enabled
[ 24.249] (II) modeset(0): Initializing kms color map for depth 24, 8
bpc.
[ 24.250] (==) modeset(0): DPMS enabled
[ 24.250] (II) modeset(0): [DRI2] Setup complete
[ 24.250] (II) modeset(0): [DRI2] DRI driver: kms_swrast
[ 24.250] (II) modeset(0): [DRI2] VDPAU driver: kms_swrast
...
[ 24.770] (II) modeset(0): Disabling kernel dirty updates, not
required.
[ 24.770] (EE) modeset(0): failed to set mode: Invalid argument
xorg tries to use 24 and 32 bpp which pass on the fb API but which
don't actually work on AMD KV260 when Xorg starts. As a workaround
Xorg config can set color depth to 16 using /etc/X11/xorg.conf snippet:
Section "Screen"
Identifier "Default Screen"
Monitor "Configured Monitor"
Device "Configured Video Device"
DefaultDepth 16
EndSection
But this is cumbersome on images meant for multiple different arm64
devices and boards. So instead set 16 bpp as preferred depth
in zynqmp_kms fb driver which is used by Xorg in the logic to find
out a working depth.
Now Xorg startup and bpp query using fb API works and HDMI display
shows graphics. /var/log/Xorg.0.log shows:
[ 23.219] (II) LoadModule: "fbdev"
[ 23.219] (II) Loading /usr/lib/xorg/modules/drivers/fbdev_drv.so
[ 23.219] (II) Module fbdev: vendor="X.Org Foundation"
[ 23.219] compiled for 1.21.1.18, module version = 0.5.1
[ 23.219] Module class: X.Org Video Driver
[ 23.219] ABI class: X.Org Video Driver, version 25.2
[ 23.219] (II) modesetting: Driver for Modesetting Kernel Drivers:
kms
[ 23.219] (II) FBDEV: driver for framebuffer: fbdev
[ 23.238] (II) modeset(0): using drv /dev/dri/card1
[ 23.238] (WW) Falling back to old probe method for fbdev
[ 23.238] (II) Loading sub module "fbdevhw"
[ 23.238] (II) LoadModule: "fbdevhw"
[ 23.239] (II) Loading /usr/lib/xorg/modules/libfbdevhw.so
[ 23.239] (II) Module fbdevhw: vendor="X.Org Foundation"
[ 23.239] compiled for 1.21.1.18, module version = 0.0.2
[ 23.239] ABI class: X.Org Video Driver, version 25.2
[ 23.240] (II) modeset(0): Creating default Display subsection in Screen section
"Default Screen Section" for depth/fbbpp 16/16
[ 23.240] (==) modeset(0): Depth 16, (==) framebuffer bpp 16
[ 23.240] (==) modeset(0): RGB weight 565
[ 23.240] (==) modeset(0): Default visual is TrueColor
...
[ 24.015] (==) modeset(0): Backing store enabled
[ 24.015] (==) modeset(0): Silken mouse enabled
[ 24.027] (II) modeset(0): Initializing kms color map for depth 16, 6 bpc.
[ 24.028] (==) modeset(0): DPMS enabled
[ 24.028] (II) modeset(0): [DRI2] Setup complete
[ 24.028] (II) modeset(0): [DRI2] DRI driver: kms_swrast
[ 24.028] (II) modeset(0): [DRI2] VDPAU driver: kms_swrast
Cc: Bill Mills <bill.mills(a)linaro.org>
Cc: Ilias Apalodimas <ilias.apalodimas(a)linaro.org>
Cc: Anatoliy Klymenko <anatoliy.klymenko(a)amd.com>
Cc: stable(a)vger.kernel.org
Signed-off-by: Mikko Rapeli <mikko.rapeli(a)linaro.org>
---
drivers/gpu/drm/xlnx/zynqmp_kms.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/gpu/drm/xlnx/zynqmp_kms.c b/drivers/gpu/drm/xlnx/zynqmp_kms.c
index ccc35cacd10cb..a42192c827af0 100644
--- a/drivers/gpu/drm/xlnx/zynqmp_kms.c
+++ b/drivers/gpu/drm/xlnx/zynqmp_kms.c
@@ -506,6 +506,7 @@ int zynqmp_dpsub_drm_init(struct zynqmp_dpsub *dpsub)
drm->mode_config.min_height = 0;
drm->mode_config.max_width = ZYNQMP_DISP_MAX_WIDTH;
drm->mode_config.max_height = ZYNQMP_DISP_MAX_HEIGHT;
+ drm->mode_config.preferred_depth = 16;
ret = drm_vblank_init(drm, 1);
if (ret)
--
2.34.1
From: Anatoliy Klymenko <anatoliy.klymenko(a)amd.com>
Use RG16 buffer format for fbdev emulation. Fbdev backend is being used
by Mali 400 userspace driver which expects 16 bit RGB pixel color format.
This change should not affect console or other fbdev applications as we
still have plenty of colors left.
Cc: Bill Mills <bill.mills(a)linaro.org>
Cc: Ilias Apalodimas <ilias.apalodimas(a)linaro.org>
Cc: stable(a)vger.kernel.org
Signed-off-by: Anatoliy Klymenko <anatoliy.klymenko(a)amd.com>
Signed-off-by: Mikko Rapeli <mikko.rapeli(a)linaro.org>
---
drivers/gpu/drm/xlnx/zynqmp_kms.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/xlnx/zynqmp_kms.c b/drivers/gpu/drm/xlnx/zynqmp_kms.c
index 2bee0a2275ede..ccc35cacd10cb 100644
--- a/drivers/gpu/drm/xlnx/zynqmp_kms.c
+++ b/drivers/gpu/drm/xlnx/zynqmp_kms.c
@@ -525,7 +525,7 @@ int zynqmp_dpsub_drm_init(struct zynqmp_dpsub *dpsub)
goto err_poll_fini;
/* Initialize fbdev generic emulation. */
- drm_client_setup_with_fourcc(drm, DRM_FORMAT_RGB888);
+ drm_client_setup_with_fourcc(drm, DRM_FORMAT_RGB565);
return 0;
--
2.34.1