Re: [PATCH 1/1] x86/gart/kcore: Exclude GART aperture from kcore

From: Jiri Bohac
Date: Fri Dec 21 2018 - 09:56:47 EST

On Fri, Dec 21, 2018 at 09:38:12AM +0800, Kairui Song wrote:
> On machines where the GART aperture is mapped over physical RAM,
> /proc/kcore contains the GART aperture range and reading it may lead
> to kernel panic.
> In 'commit 2a3e83c6f96c ("x86/gart: Exclude GART aperture from vmcore")',
> a special workaround is applied for vmcore to let /proc/vmcore return
> zeroes when attempting to read the aperture region, as vmcore and kcore
> have the same issue, and after 'commit 707d4eefbdb3 ("Revert "[PATCH]
> Insert GART region into resource map"")', userspace tools can't detect and
> exclude GART region.
> This patch applies the same workaround for kcore. Let /proc/kcore return
> zeroes too when trying to read the aperture region to fix the issue that
> reading GART region may raise unexpected exceptions.
> This applies to both first and second kernels as GART may get
> initialized in the first and second kernels.
> To get the same workaround work for kcore, this patch implement a hook
> infrastructure for kcore which is same as the hook infrastructure for
> vmcore introduced in 'commit 997c136f518c ("fs/proc/vmcore.c: add hook
> to read_from_oldmem() to check for non-ram pages")'', and reuses the
> checking function gart_oldmem_pfn_is_ram introduced in
> 'commit 2a3e83c6f96c ("x86/gart: Exclude GART aperture from vmcore"),'
> as the hook function, but rename to gart_mem_pfn_is_ram as now it's
> for a more generic use.
> Suggested-by: Baoquan He <bhe@xxxxxxxxxx>
> Signed-off-by: Kairui Song <kasong@xxxxxxxxxx>

Reviewed-by: Jiri Bohac <jbohac@xxxxxxx>

> ---
> arch/x86/kernel/aperture_64.c | 6 ++++--
> fs/proc/kcore.c | 34 ++++++++++++++++++++++++++++++++++
> include/linux/kcore.h | 3 +++
> 3 files changed, 41 insertions(+), 2 deletions(-)

Jiri Bohac <jbohac@xxxxxxx>
SUSE Labs, Prague, Czechia