From nobody Tue Nov 26 14:24:06 2024 Received: from out-181.mta0.migadu.com (out-181.mta0.migadu.com [91.218.175.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E85551DE89A for ; Thu, 17 Oct 2024 15:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729177880; cv=none; b=dkY/xf4WjUCU/ZEb3K4bJPxv0WggfKMFNWy65ZJPPwyCipDbAn7fRM76EAzGzmuqU61n2t5m/iwXMKW8TVnQdxdRHqDU8/ZX59a8Dmb842nuazIN+pH+muV3V84NYGJhua7NKZjxuA/OplEWEaL1On5ERxFaF7QWQENXmzkIQ4I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729177880; c=relaxed/simple; bh=78VbEsJzL1vYUh50WA71jPZOLp0Ba1kPP5FVnPu22Cw=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=B0wvG2Nqxm0kkQXif9v33j7xWNwFlDVGHLs4TFruuyY+7QTHVJyYqZSrwlWVzxr6acGht1zMBYn4/8C86JWmHbe5eK2+XfUtL0Tlo4oRM0k6OfU1vzorgres3HpiTbl+QN9HqBDhcy93BZcLmmEblnqAgfG7sx0cIN4UhC172XE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=xr/JJiBx; arc=none smtp.client-ip=91.218.175.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="xr/JJiBx" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1729177872; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=a6q+RnpFBDPOiiiJDLMbcTS8++Kxh6v+wmc4kW9JV3E=; b=xr/JJiBxBP5miVm69oGUzNxiIzpRhwDHISb9zNH7SKWhiEaskO9G1dsxI1S7vSc7Zbm4fk LbhHT6kivnlYdEUWKLUQ5gdk53qrQtpDsB8Mj3ho6eXP8csgsb366ISYdCfv6BueoyGCzg bsyBQKfCQQtfATsshvHTIOtwqHswLNw= From: Sean Anderson To: Christoph Hellwig , iommu@lists.linux.dev Cc: linux-trace-kernel@vger.kernel.org, Robin Murphy , linux-kernel@vger.kernel.org, Mathieu Desnoyers , Steven Rostedt , Marek Szyprowski , Masami Hiramatsu , Sean Anderson , syzbot+b4bfacdec173efaa8567@syzkaller.appspotmail.com Subject: [PATCH] dma-mapping: Fix tracing dma_alloc/free with vmalloc'd memory Date: Thu, 17 Oct 2024 11:10:55 -0400 Message-Id: <20241017151055.2806066-1-sean.anderson@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Not all virtual addresses have physical addresses, such as if they were vmalloc'd. Just trace the virtual address instead of trying to trace a physical address. This aligns with the API, and is good enough to associate dma_alloc with dma_free. Fixes: 038eb433dc14 ("dma-mapping: add tracing for dma-mapping API calls") Reported-by: syzbot+b4bfacdec173efaa8567@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/670ebde5.050a0220.d9b66.0154.GAE@google= .com/ Signed-off-by: Sean Anderson --- %p obfuscates virtual addresses when tracing just like with printk. include/trace/events/dma.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/include/trace/events/dma.h b/include/trace/events/dma.h index 569f86a44aaa..b0f41265191c 100644 --- a/include/trace/events/dma.h +++ b/include/trace/events/dma.h @@ -121,7 +121,7 @@ TRACE_EVENT(dma_alloc, =20 TP_STRUCT__entry( __string(device, dev_name(dev)) - __field(u64, phys_addr) + __field(void *, virt_addr) __field(u64, dma_addr) __field(size_t, size) __field(gfp_t, flags) @@ -130,18 +130,18 @@ TRACE_EVENT(dma_alloc, =20 TP_fast_assign( __assign_str(device); - __entry->phys_addr =3D virt_to_phys(virt_addr); + __entry->virt_addr =3D virt_addr; __entry->dma_addr =3D dma_addr; __entry->size =3D size; __entry->flags =3D flags; __entry->attrs =3D attrs; ), =20 - TP_printk("%s dma_addr=3D%llx size=3D%zu phys_addr=3D%llx flags=3D%s attr= s=3D%s", + TP_printk("%s dma_addr=3D%llx size=3D%zu virt_addr=3D%p flags=3D%s attrs= =3D%s", __get_str(device), __entry->dma_addr, __entry->size, - __entry->phys_addr, + __entry->virt_addr, show_gfp_flags(__entry->flags), decode_dma_attrs(__entry->attrs)) ); @@ -153,7 +153,7 @@ TRACE_EVENT(dma_free, =20 TP_STRUCT__entry( __string(device, dev_name(dev)) - __field(u64, phys_addr) + __field(void *, virt_addr) __field(u64, dma_addr) __field(size_t, size) __field(unsigned long, attrs) @@ -161,17 +161,17 @@ TRACE_EVENT(dma_free, =20 TP_fast_assign( __assign_str(device); - __entry->phys_addr =3D virt_to_phys(virt_addr); + __entry->virt_addr =3D virt_addr; __entry->dma_addr =3D dma_addr; __entry->size =3D size; __entry->attrs =3D attrs; ), =20 - TP_printk("%s dma_addr=3D%llx size=3D%zu phys_addr=3D%llx attrs=3D%s", + TP_printk("%s dma_addr=3D%llx size=3D%zu virt_addr=3D%p attrs=3D%s", __get_str(device), __entry->dma_addr, __entry->size, - __entry->phys_addr, + __entry->virt_addr, decode_dma_attrs(__entry->attrs)) ); =20 --=20 2.35.1.1320.gc452695387.dirty