From 4f02b73d10ac8645d414f7440ec8be3e4b6034fa Mon Sep 17 00:00:00 2001 From: Zhiqiang Tu Date: Wed, 2 Dec 2020 09:54:23 +0800 Subject: [PATCH] soc: qcom: hab: Add HAB fixes, and workarounds, for GHS Fix kernel shutdown callback crash in HAB by removing commdev freeing in pchan free. Add stub functions for dump_hab_wq and hab_pipe_read_dump. Change-Id: I176085600e3ec3a40eb2f181491405c6bf4ac7bb Signed-off-by: Anant Goel Signed-off-by: Zhiqiang Tu Signed-off-by: Yong Ding --- drivers/soc/qcom/hab/ghs_comm.c | 22 +++++++++++++++++++--- drivers/soc/qcom/hab/hab_ghs.c | 5 ++++- drivers/soc/qcom/hab/hab_ghs_linux.c | 3 +++ drivers/soc/qcom/hab/hab_pchan.c | 3 +-- drivers/soc/qcom/hab/khab_test.c | 2 +- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/drivers/soc/qcom/hab/ghs_comm.c b/drivers/soc/qcom/hab/ghs_comm.c index 3d3826b2b12d..645a92299d12 100644 --- a/drivers/soc/qcom/hab/ghs_comm.c +++ b/drivers/soc/qcom/hab/ghs_comm.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved. + * Copyright (c) 2018-2020, The Linux Foundation. All rights reserved. */ #include "hab.h" #include "hab_ghs.h" @@ -34,7 +34,15 @@ int physical_channel_send(struct physical_channel *pchan, struct ghs_vdev *dev = (struct ghs_vdev *)pchan->hyp_data; GIPC_Result result; uint8_t *msg; - int irqs_disabled = irqs_disabled(); + int irqs_disabled; + + if (!dev) { + pr_err("no send pchan %s has been de-alloced msg for %zd bytes\n", + pchan->name); + return -ENODEV; + } + + irqs_disabled = irqs_disabled(); hab_spin_lock(&dev->io_lock, irqs_disabled); @@ -94,7 +102,15 @@ void physical_channel_rx_dispatch_common(unsigned long physical_channel) (struct physical_channel *)physical_channel; struct ghs_vdev *dev = (struct ghs_vdev *)pchan->hyp_data; GIPC_Result result; - int irqs_disabled = irqs_disabled(); + int irqs_disabled; + + if (!dev) { + pr_err("no recv pchan %s has been de-alloced msg for %zd bytes\n", + pchan->name); + return; + } + + irqs_disabled = irqs_disabled(); hab_spin_lock(&pchan->rxbuf_lock, irqs_disabled); while (1) { diff --git a/drivers/soc/qcom/hab/hab_ghs.c b/drivers/soc/qcom/hab/hab_ghs.c index 0708c27ac009..e4d7a823bd28 100644 --- a/drivers/soc/qcom/hab/hab_ghs.c +++ b/drivers/soc/qcom/hab/hab_ghs.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved. + * Copyright (c) 2018-2020, The Linux Foundation. All rights reserved. */ #include "hab.h" #include "hab_ghs.h" @@ -164,6 +164,9 @@ int habhyp_commdev_dealloc(void *commdev) kfree(dev->os_data); kfree(dev); + pchan->closed = 1; + pchan->hyp_data = NULL; + if (get_refcnt(pchan->refcount) > 1) { pr_warn("potential leak pchan %s vchans %d refcnt %d\n", pchan->name, pchan->vcnt, get_refcnt(pchan->refcount)); diff --git a/drivers/soc/qcom/hab/hab_ghs_linux.c b/drivers/soc/qcom/hab/hab_ghs_linux.c index b505f5136405..80e2d4c30711 100644 --- a/drivers/soc/qcom/hab/hab_ghs_linux.c +++ b/drivers/soc/qcom/hab/hab_ghs_linux.c @@ -150,3 +150,6 @@ int hab_hypervisor_register_os(void) return 0; } + +void dump_hab_wq(void *hyp_data) {}; +void hab_pipe_read_dump(struct physical_channel *pchan) {}; diff --git a/drivers/soc/qcom/hab/hab_pchan.c b/drivers/soc/qcom/hab/hab_pchan.c index 70ebf6dac895..54df304641a2 100644 --- a/drivers/soc/qcom/hab/hab_pchan.c +++ b/drivers/soc/qcom/hab/hab_pchan.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved. + * Copyright (c) 2016-2020, The Linux Foundation. All rights reserved. */ #include "hab.h" @@ -59,7 +59,6 @@ static void hab_pchan_free(struct kref *ref) } read_unlock(&pchan->vchans_lock); - kfree(pchan->hyp_data); kfree(pchan); } diff --git a/drivers/soc/qcom/hab/khab_test.c b/drivers/soc/qcom/hab/khab_test.c index ea061e555383..8f0d263d171c 100644 --- a/drivers/soc/qcom/hab/khab_test.c +++ b/drivers/soc/qcom/hab/khab_test.c @@ -3,10 +3,10 @@ * Copyright (c) 2018-2020, The Linux Foundation. All rights reserved. */ #include "hab.h" +#include #if !defined CONFIG_GHS_VMM && defined(CONFIG_QTI_QUIN_GVM) #include #include -#include #include "hab_pipe.h" #include "hab_qvm.h" #include "khab_test.h"