From nobody Mon Sep 29 20:19:08 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87635C25B0D for ; Tue, 16 Aug 2022 04:43:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231883AbiHPEng (ORCPT ); Tue, 16 Aug 2022 00:43:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232014AbiHPEkp (ORCPT ); Tue, 16 Aug 2022 00:40:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 524E0A50E2; Mon, 15 Aug 2022 13:31:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E452060EE9; Mon, 15 Aug 2022 20:31:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3466C433C1; Mon, 15 Aug 2022 20:31:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660595517; bh=pHZiJJno5N6PtNhBHdAXqpWTived2x+RtACMOKKshSQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IvknoBufSLhU41KEmv7PIh49E3gb6UZYxWQGRYWlOeAe38VQAJuXtVdHOw+Rgw6U+ NxNicyeB658Ti/RnsmjEgfEjETTCJv7pUbf9d1ufUMseNwf5+ViuIArVFjrmG2ZwtM NPlUfeXTUMkPIJyy+2aJutfO8JIv2BVgE1SIVr68= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Shevchenko , Alexander Shishkin , Sasha Levin Subject: [PATCH 5.19 0788/1157] intel_th: msu: Fix vmalloced buffers Date: Mon, 15 Aug 2022 20:02:24 +0200 Message-Id: <20220815180511.004417413@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Alexander Shishkin [ Upstream commit ac12ad3ccf6d386e64a9d6a890595a2509d24edd ] After commit f5ff79fddf0e ("dma-mapping: remove CONFIG_DMA_REMAP") there's a chance of DMA buffer getting allocated via vmalloc(), which messes up the mmapping code: > RIP: msc_mmap_fault [intel_th_msu] > Call Trace: > > __do_fault > do_fault ... Fix this by accounting for vmalloc possibility. Fixes: ba39bd830605 ("intel_th: msu: Switch over to scatterlist") Reviewed-by: Andy Shevchenko Signed-off-by: Alexander Shishkin Link: https://lore.kernel.org/r/20220705082637.59979-4-alexander.shishkin@l= inux.intel.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/hwtracing/intel_th/msu.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/hwtracing/intel_th/msu.c b/drivers/hwtracing/intel_th/= msu.c index 70a07b4e9967..6c8215a47a60 100644 --- a/drivers/hwtracing/intel_th/msu.c +++ b/drivers/hwtracing/intel_th/msu.c @@ -1067,6 +1067,16 @@ msc_buffer_set_uc(struct msc *msc) {} static inline void msc_buffer_set_wb(struct msc *msc) {} #endif /* CONFIG_X86 */ =20 +static struct page *msc_sg_page(struct scatterlist *sg) +{ + void *addr =3D sg_virt(sg); + + if (is_vmalloc_addr(addr)) + return vmalloc_to_page(addr); + + return sg_page(sg); +} + /** * msc_buffer_win_alloc() - alloc a window for a multiblock mode * @msc: MSC device @@ -1137,7 +1147,7 @@ static void __msc_buffer_win_free(struct msc *msc, st= ruct msc_window *win) int i; =20 for_each_sg(win->sgt->sgl, sg, win->nr_segs, i) { - struct page *page =3D sg_page(sg); + struct page *page =3D msc_sg_page(sg); =20 page->mapping =3D NULL; dma_free_coherent(msc_dev(win->msc)->parent->parent, PAGE_SIZE, @@ -1401,7 +1411,7 @@ static struct page *msc_buffer_get_page(struct msc *m= sc, unsigned long pgoff) pgoff -=3D win->pgoff; =20 for_each_sg(win->sgt->sgl, sg, win->nr_segs, blk) { - struct page *page =3D sg_page(sg); + struct page *page =3D msc_sg_page(sg); size_t pgsz =3D PFN_DOWN(sg->length); =20 if (pgoff < pgsz) --=20 2.35.1