From nobody Tue Nov 26 10:32:36 2024 Received: from out-175.mta0.migadu.com (out-175.mta0.migadu.com [91.218.175.175]) (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 4C7B91D7E3D for ; Fri, 18 Oct 2024 15:01:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729263672; cv=none; b=Xw4ibabmrwRT9SPY4ZGF3fLedIK3jWjfeU9XcrNi6wr8jS9JxA52KyHOmondPXp3Qfxp9O5delF1mb2Q/MtHMYEGUe+y98XdvDCiTuWgNGIgOEyGGc3hCHTI6QZirzZyKl0kuuOekmlXo2KYJ72DyhGSgQ20d+pfb5WvoZ2NrSM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729263672; c=relaxed/simple; bh=7ZpSoewhKU7eN4frzrDG+nKfoYaE4waFluXDMv9yrEI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lhUECY3JGhBWG6q9oKcwfzdcBUMicSLxEmXgch+J59r0qLCsXXoGm145zdeVKX2vetPBMNSv36wwKKSpPuUzCqrV+6N8Ii3q+oszIZogMa4+j5/RFJRwgi4F5kSCgd1iTSwNb300kctn7ReMRlhh08S3aSV8kREd+A3pX7CDeBA= 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=AQ5e+kKl; arc=none smtp.client-ip=91.218.175.175 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="AQ5e+kKl" 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=1729263668; 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: in-reply-to:in-reply-to:references:references; bh=Ydd5/5k0GyzrDpIcMZoEJ/GlEO8PTBGwqqIyFBsrzJU=; b=AQ5e+kKlXfWgQ+4/9Qe5hKblGe0DBFgg0bHn+PuSb+c3ScIazmYfJik0xHBLc4vLDav9Na hZXEkGx89tT5pElf2ueAxaFrFdDknkVHsAPDC8N6BLT/FUxRNJM+zN3cdaxb3qBgGUtkAy bH7xvgYmroXdZstnQTMA5NtvUOopsWw= From: Sean Anderson To: Christoph Hellwig , iommu@lists.linux.dev Cc: Robin Murphy , linux-trace-kernel@vger.kernel.org, Mathieu Desnoyers , Steven Rostedt , Masami Hiramatsu , Marek Szyprowski , linux-kernel@vger.kernel.org, Sean Anderson Subject: [PATCH v2 1/4] dma-mapping: Use macros to define events in a class Date: Fri, 18 Oct 2024 11:00:34 -0400 Message-Id: <20241018150036.2878190-2-sean.anderson@linux.dev> In-Reply-To: <20241018150036.2878190-1-sean.anderson@linux.dev> References: <20241018150036.2878190-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" Use a macro to avoid repeating the parameters and arguments for each event in a class. Signed-off-by: Sean Anderson --- Changes in v2: - New include/trace/events/dma.h | 60 ++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/include/trace/events/dma.h b/include/trace/events/dma.h index b0f41265191c..3d348cea4d7c 100644 --- a/include/trace/events/dma.h +++ b/include/trace/events/dma.h @@ -65,15 +65,14 @@ DECLARE_EVENT_CLASS(dma_map, decode_dma_attrs(__entry->attrs)) ); =20 -DEFINE_EVENT(dma_map, dma_map_page, - TP_PROTO(struct device *dev, phys_addr_t phys_addr, dma_addr_t dma_addr, - size_t size, enum dma_data_direction dir, unsigned long attrs), - TP_ARGS(dev, phys_addr, dma_addr, size, dir, attrs)); +#define DEFINE_MAP_EVENT(name) \ +DEFINE_EVENT(dma_map, name, \ + TP_PROTO(struct device *dev, phys_addr_t phys_addr, dma_addr_t dma_addr, \ + size_t size, enum dma_data_direction dir, unsigned long attrs), \ + TP_ARGS(dev, phys_addr, dma_addr, size, dir, attrs)) =20 -DEFINE_EVENT(dma_map, dma_map_resource, - TP_PROTO(struct device *dev, phys_addr_t phys_addr, dma_addr_t dma_addr, - size_t size, enum dma_data_direction dir, unsigned long attrs), - TP_ARGS(dev, phys_addr, dma_addr, size, dir, attrs)); +DEFINE_MAP_EVENT(dma_map_page); +DEFINE_MAP_EVENT(dma_map_resource); =20 DECLARE_EVENT_CLASS(dma_unmap, TP_PROTO(struct device *dev, dma_addr_t addr, size_t size, @@ -104,15 +103,14 @@ DECLARE_EVENT_CLASS(dma_unmap, decode_dma_attrs(__entry->attrs)) ); =20 -DEFINE_EVENT(dma_unmap, dma_unmap_page, - TP_PROTO(struct device *dev, dma_addr_t addr, size_t size, - enum dma_data_direction dir, unsigned long attrs), - TP_ARGS(dev, addr, size, dir, attrs)); +#define DEFINE_UNMAP_EVENT(name) \ +DEFINE_EVENT(dma_unmap, name, \ + TP_PROTO(struct device *dev, dma_addr_t addr, size_t size, \ + enum dma_data_direction dir, unsigned long attrs), \ + TP_ARGS(dev, addr, size, dir, attrs)) =20 -DEFINE_EVENT(dma_unmap, dma_unmap_resource, - TP_PROTO(struct device *dev, dma_addr_t addr, size_t size, - enum dma_data_direction dir, unsigned long attrs), - TP_ARGS(dev, addr, size, dir, attrs)); +DEFINE_UNMAP_EVENT(dma_unmap_page); +DEFINE_UNMAP_EVENT(dma_unmap_resource); =20 TRACE_EVENT(dma_alloc, TP_PROTO(struct device *dev, void *virt_addr, dma_addr_t dma_addr, @@ -279,15 +277,14 @@ DECLARE_EVENT_CLASS(dma_sync_single, __entry->size) ); =20 -DEFINE_EVENT(dma_sync_single, dma_sync_single_for_cpu, - TP_PROTO(struct device *dev, dma_addr_t dma_addr, size_t size, - enum dma_data_direction dir), - TP_ARGS(dev, dma_addr, size, dir)); +#define DEFINE_SYNC_SINGLE_EVENT(name) \ +DEFINE_EVENT(dma_sync_single, name, \ + TP_PROTO(struct device *dev, dma_addr_t dma_addr, size_t size, \ + enum dma_data_direction dir), \ + TP_ARGS(dev, dma_addr, size, dir)) =20 -DEFINE_EVENT(dma_sync_single, dma_sync_single_for_device, - TP_PROTO(struct device *dev, dma_addr_t dma_addr, size_t size, - enum dma_data_direction dir), - TP_ARGS(dev, dma_addr, size, dir)); +DEFINE_SYNC_SINGLE_EVENT(dma_sync_single_for_cpu); +DEFINE_SYNC_SINGLE_EVENT(dma_sync_single_for_device); =20 DECLARE_EVENT_CLASS(dma_sync_sg, TP_PROTO(struct device *dev, struct scatterlist *sgl, int nents, @@ -326,15 +323,14 @@ DECLARE_EVENT_CLASS(dma_sync_sg, sizeof(unsigned int), sizeof(unsigned int))) ); =20 -DEFINE_EVENT(dma_sync_sg, dma_sync_sg_for_cpu, - TP_PROTO(struct device *dev, struct scatterlist *sg, int nents, - enum dma_data_direction dir), - TP_ARGS(dev, sg, nents, dir)); +#define DEFINE_SYNC_SG_EVENT(name) \ +DEFINE_EVENT(dma_sync_sg, name, \ + TP_PROTO(struct device *dev, struct scatterlist *sg, int nents, \ + enum dma_data_direction dir), \ + TP_ARGS(dev, sg, nents, dir)) =20 -DEFINE_EVENT(dma_sync_sg, dma_sync_sg_for_device, - TP_PROTO(struct device *dev, struct scatterlist *sg, int nents, - enum dma_data_direction dir), - TP_ARGS(dev, sg, nents, dir)); +DEFINE_SYNC_SG_EVENT(dma_sync_sg_for_cpu); +DEFINE_SYNC_SG_EVENT(dma_sync_sg_for_device); =20 #endif /* _TRACE_DMA_H */ =20 --=20 2.35.1.1320.gc452695387.dirty From nobody Tue Nov 26 10:32:36 2024 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (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 2DDCA200B96 for ; Fri, 18 Oct 2024 15:01:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729263675; cv=none; b=C9cRSjyzbCXB+3lgIGOmdDOMat0tid2ow/RYR+VpwSIgAm5B8cFAcrzwVe5aHmUyRls7VBxcJhsSJ1/PKnjfCKIcNcjPNuMPLOaSYlfk58ZriLBt/KDNeylXu40RjZaFoeVtrfQSqi/9XpbEtIsQ7/wpYKOMEZ92Ll1FhreEreQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729263675; c=relaxed/simple; bh=FflYoVmEaTfoCnf6mxw4dL6I4aSOsuk7qjziVsYvGTU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CJ0kk3XSUO6Wezhv2+BSV8EJVXWN2iMetoST/tuFzbVpJQsOc4eVJ/9Z22QZ5WD29jJxVrJVw26SlSraeE/1Bbcagovd0Cfffetu1GPtCZ/lO8GqnGdCZ1VvrdM8aYrAFsBzEQqIGzX0cb1ptYvj4E58TZziPN3vMoaok6bxAbs= 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=aNKTReZv; arc=none smtp.client-ip=91.218.175.188 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="aNKTReZv" 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=1729263670; 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: in-reply-to:in-reply-to:references:references; bh=sOhKEGCgokt7ixwC/an2TCJlA1cCJn4+x/GHCZN12d0=; b=aNKTReZvPtHFMoiSKdttb6UBVkvS4tbVOboc5A3UCOcTCQb+kmVQ+XmacglSSLXygWen0+ zgYEXOB8Zfol3Ii0V873EW+gQgmU8i2iCYnSTnB51DQMoWFA9hswdoi4Uz0aYgxaXddgq3 4FMzH5Rk03VMdjyGJr2lJYQq1zJiswo= From: Sean Anderson To: Christoph Hellwig , iommu@lists.linux.dev Cc: Robin Murphy , linux-trace-kernel@vger.kernel.org, Mathieu Desnoyers , Steven Rostedt , Masami Hiramatsu , Marek Szyprowski , linux-kernel@vger.kernel.org, Sean Anderson Subject: [PATCH v2 2/4] dma-mapping: Trace dma_alloc/free direction Date: Fri, 18 Oct 2024 11:00:35 -0400 Message-Id: <20241018150036.2878190-3-sean.anderson@linux.dev> In-Reply-To: <20241018150036.2878190-1-sean.anderson@linux.dev> References: <20241018150036.2878190-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" In preparation for using these tracepoints in a few more places, trace the DMA direction as well. For coherent allocations this is always bidirectional. Signed-off-by: Sean Anderson --- (no changes since v1) include/trace/events/dma.h | 18 ++++++++++++------ kernel/dma/mapping.c | 6 ++++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/include/trace/events/dma.h b/include/trace/events/dma.h index 3d348cea4d7c..267cfa49d9d5 100644 --- a/include/trace/events/dma.h +++ b/include/trace/events/dma.h @@ -114,8 +114,9 @@ DEFINE_UNMAP_EVENT(dma_unmap_resource); =20 TRACE_EVENT(dma_alloc, TP_PROTO(struct device *dev, void *virt_addr, dma_addr_t dma_addr, - size_t size, gfp_t flags, unsigned long attrs), - TP_ARGS(dev, virt_addr, dma_addr, size, flags, attrs), + size_t size, enum dma_data_direction dir, gfp_t flags, + unsigned long attrs), + TP_ARGS(dev, virt_addr, dma_addr, size, dir, flags, attrs), =20 TP_STRUCT__entry( __string(device, dev_name(dev)) @@ -123,6 +124,7 @@ TRACE_EVENT(dma_alloc, __field(u64, dma_addr) __field(size_t, size) __field(gfp_t, flags) + __field(enum dma_data_direction, dir) __field(unsigned long, attrs) ), =20 @@ -135,8 +137,9 @@ TRACE_EVENT(dma_alloc, __entry->attrs =3D attrs; ), =20 - TP_printk("%s dma_addr=3D%llx size=3D%zu virt_addr=3D%p flags=3D%s attrs= =3D%s", + TP_printk("%s dir=3D%s dma_addr=3D%llx size=3D%zu virt_addr=3D%p flags=3D= %s attrs=3D%s", __get_str(device), + decode_dma_data_direction(__entry->dir), __entry->dma_addr, __entry->size, __entry->virt_addr, @@ -146,14 +149,15 @@ TRACE_EVENT(dma_alloc, =20 TRACE_EVENT(dma_free, TP_PROTO(struct device *dev, void *virt_addr, dma_addr_t dma_addr, - size_t size, unsigned long attrs), - TP_ARGS(dev, virt_addr, dma_addr, size, attrs), + size_t size, enum dma_data_direction dir, unsigned long attrs), + TP_ARGS(dev, virt_addr, dma_addr, size, dir, attrs), =20 TP_STRUCT__entry( __string(device, dev_name(dev)) __field(void *, virt_addr) __field(u64, dma_addr) __field(size_t, size) + __field(enum dma_data_direction, dir) __field(unsigned long, attrs) ), =20 @@ -162,11 +166,13 @@ TRACE_EVENT(dma_free, __entry->virt_addr =3D virt_addr; __entry->dma_addr =3D dma_addr; __entry->size =3D size; + __entry->dir =3D dir; __entry->attrs =3D attrs; ), =20 - TP_printk("%s dma_addr=3D%llx size=3D%zu virt_addr=3D%p attrs=3D%s", + TP_printk("%s dir=3D%s dma_addr=3D%llx size=3D%zu virt_addr=3D%p attrs=3D= %s", __get_str(device), + decode_dma_data_direction(__entry->dir), __entry->dma_addr, __entry->size, __entry->virt_addr, diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c index 864a1121bf08..944ac835030a 100644 --- a/kernel/dma/mapping.c +++ b/kernel/dma/mapping.c @@ -619,7 +619,8 @@ void *dma_alloc_attrs(struct device *dev, size_t size, = dma_addr_t *dma_handle, else return NULL; =20 - trace_dma_alloc(dev, cpu_addr, *dma_handle, size, flag, attrs); + trace_dma_alloc(dev, cpu_addr, *dma_handle, size, DMA_BIDIRECTIONAL, + flag, attrs); debug_dma_alloc_coherent(dev, size, *dma_handle, cpu_addr, attrs); return cpu_addr; } @@ -644,7 +645,8 @@ void dma_free_attrs(struct device *dev, size_t size, vo= id *cpu_addr, if (!cpu_addr) return; =20 - trace_dma_free(dev, cpu_addr, dma_handle, size, attrs); + trace_dma_free(dev, cpu_addr, dma_handle, size, DMA_BIDIRECTIONAL, + attrs); debug_dma_free_coherent(dev, size, cpu_addr, dma_handle); if (dma_alloc_direct(dev, ops)) dma_direct_free(dev, size, cpu_addr, dma_handle, attrs); --=20 2.35.1.1320.gc452695387.dirty From nobody Tue Nov 26 10:32:36 2024 Received: from out-187.mta0.migadu.com (out-187.mta0.migadu.com [91.218.175.187]) (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 DF7652010EA for ; Fri, 18 Oct 2024 15:01:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729263675; cv=none; b=ulDSFkO6iBftK/N51fk5pUxF2WAyQBX4msBAzhiDY/JTexHuCG49j8z+YmsXRUtBWxYKWUdTX95GPMMAcBw93CMXxJwNZg3KAiAHQv9f1DCXP9/tVU/OHm/+3lhCXYIE4TfVE2JnBU7vLdN4H0z7Sgdw3iRZEEl/U6A1OBLqovU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729263675; c=relaxed/simple; bh=KXjgRjgViiBPoQ96NpbXV5Lg8af5ZYGzF262rMeCnRk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=D9zvU+6dW/drGQs2STwQBgOOrpHrBFrdmuKP/ptnAkmS1gfknl9sRwn6tjqQ8//F7IcH9lnbnPlN36Ffx1Rb2GQVm2imMPhecEbMxUXC/RThvFJ9KGAj9fkVZMsc0br0dgYc7HnzlP1SPajX13otuALmW5E7f35UOox5Dg9DzGI= 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=gUFQMugH; arc=none smtp.client-ip=91.218.175.187 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="gUFQMugH" 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=1729263672; 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: in-reply-to:in-reply-to:references:references; bh=K1hpfqv0IHftVKZCYJJVLIjVqOdtAFHDnh0O340ruFg=; b=gUFQMugHKbc35RgKuzv1+0W/jX1DIhYapkZndWqtCsctIFCEMAijSCIMgXI6dkZ0kyk6dX TbG0rVtS+IUTwXzfgOdUr+hzKI2NMWoUZnEtu2jiWgJR2mmduGBGaYu9vDEfVLiu/K+4+P GfI4DNYuvR+polvwwwK+a09aAxH3bC0= From: Sean Anderson To: Christoph Hellwig , iommu@lists.linux.dev Cc: Robin Murphy , linux-trace-kernel@vger.kernel.org, Mathieu Desnoyers , Steven Rostedt , Masami Hiramatsu , Marek Szyprowski , linux-kernel@vger.kernel.org, Sean Anderson Subject: [PATCH v2 3/4] dma-mapping: Use trace_dma_alloc for dma_alloc* instead of using trace_dma_map Date: Fri, 18 Oct 2024 11:00:36 -0400 Message-Id: <20241018150036.2878190-4-sean.anderson@linux.dev> In-Reply-To: <20241018150036.2878190-1-sean.anderson@linux.dev> References: <20241018150036.2878190-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" In some cases, we use trace_dma_map to trace dma_alloc* functions. This generally follows dma_debug. However, this does not record all of the relevant information for allocations, such as GFP flags. Create new dma_alloc tracepoints for these functions. Note that while dma_alloc_noncontiguous may allocate discontiguous pages (from the CPU's point of view), the device will only see one contiguous mapping. Therefore, we just need to trace dma_addr and size. Signed-off-by: Sean Anderson Reviewed-by: Steven Rostedt (Google) --- Changes in v2: - Use macros to define events in a class include/trace/events/dma.h | 99 +++++++++++++++++++++++++++++++++++++- kernel/dma/mapping.c | 10 ++-- 2 files changed, 102 insertions(+), 7 deletions(-) diff --git a/include/trace/events/dma.h b/include/trace/events/dma.h index 267cfa49d9d5..7a9606b8934e 100644 --- a/include/trace/events/dma.h +++ b/include/trace/events/dma.h @@ -112,7 +112,7 @@ DEFINE_EVENT(dma_unmap, name, \ DEFINE_UNMAP_EVENT(dma_unmap_page); DEFINE_UNMAP_EVENT(dma_unmap_resource); =20 -TRACE_EVENT(dma_alloc, +DECLARE_EVENT_CLASS(dma_alloc_class, TP_PROTO(struct device *dev, void *virt_addr, dma_addr_t dma_addr, size_t size, enum dma_data_direction dir, gfp_t flags, unsigned long attrs), @@ -147,7 +147,58 @@ TRACE_EVENT(dma_alloc, decode_dma_attrs(__entry->attrs)) ); =20 -TRACE_EVENT(dma_free, +#define DEFINE_ALLOC_EVENT(name) \ +DEFINE_EVENT(dma_alloc_class, name, \ + TP_PROTO(struct device *dev, void *virt_addr, dma_addr_t dma_addr, \ + size_t size, enum dma_data_direction dir, gfp_t flags, \ + unsigned long attrs), \ + TP_ARGS(dev, virt_addr, dma_addr, size, dir, flags, attrs)) + +DEFINE_ALLOC_EVENT(dma_alloc); +DEFINE_ALLOC_EVENT(dma_alloc_pages); + +TRACE_EVENT(dma_alloc_sgt, + TP_PROTO(struct device *dev, struct sg_table *sgt, size_t size, + enum dma_data_direction dir, gfp_t flags, unsigned long attrs), + TP_ARGS(dev, sgt, size, dir, flags, attrs), + + TP_STRUCT__entry( + __string(device, dev_name(dev)) + __dynamic_array(u64, phys_addrs, sgt->orig_nents) + __field(u64, dma_addr) + __field(size_t, size) + __field(enum dma_data_direction, dir) + __field(gfp_t, flags) + __field(unsigned long, attrs) + ), + + TP_fast_assign( + struct scatterlist *sg; + int i; + + __assign_str(device); + for_each_sg(sgt->sgl, sg, sgt->orig_nents, i) + ((u64 *)__get_dynamic_array(phys_addrs))[i] =3D sg_phys(sg); + __entry->dma_addr =3D sg_dma_address(sgt->sgl); + __entry->size =3D size; + __entry->dir =3D dir; + __entry->flags =3D flags; + __entry->attrs =3D attrs; + ), + + TP_printk("%s dir=3D%s dma_addr=3D%llx size=3D%zu phys_addrs=3D%s flags= =3D%s attrs=3D%s", + __get_str(device), + decode_dma_data_direction(__entry->dir), + __entry->dma_addr, + __entry->size, + __print_array(__get_dynamic_array(phys_addrs), + __get_dynamic_array_len(phys_addrs) / + sizeof(u64), sizeof(u64)), + show_gfp_flags(__entry->flags), + decode_dma_attrs(__entry->attrs)) +); + +DECLARE_EVENT_CLASS(dma_free_class, TP_PROTO(struct device *dev, void *virt_addr, dma_addr_t dma_addr, size_t size, enum dma_data_direction dir, unsigned long attrs), TP_ARGS(dev, virt_addr, dma_addr, size, dir, attrs), @@ -179,6 +230,50 @@ TRACE_EVENT(dma_free, decode_dma_attrs(__entry->attrs)) ); =20 +#define DEFINE_FREE_EVENT(name) \ +DEFINE_EVENT(dma_free_class, name, \ + TP_PROTO(struct device *dev, void *virt_addr, dma_addr_t dma_addr, \ + size_t size, enum dma_data_direction dir, unsigned long attrs), \ + TP_ARGS(dev, virt_addr, dma_addr, size, dir, attrs)) + +DEFINE_FREE_EVENT(dma_free); +DEFINE_FREE_EVENT(dma_free_pages); + +TRACE_EVENT(dma_free_sgt, + TP_PROTO(struct device *dev, struct sg_table *sgt, size_t size, + enum dma_data_direction dir), + TP_ARGS(dev, sgt, size, dir), + + TP_STRUCT__entry( + __string(device, dev_name(dev)) + __dynamic_array(u64, phys_addrs, sgt->orig_nents) + __field(u64, dma_addr) + __field(size_t, size) + __field(enum dma_data_direction, dir) + ), + + TP_fast_assign( + struct scatterlist *sg; + int i; + + __assign_str(device); + for_each_sg(sgt->sgl, sg, sgt->orig_nents, i) + ((u64 *)__get_dynamic_array(phys_addrs))[i] =3D sg_phys(sg); + __entry->dma_addr =3D sg_dma_address(sgt->sgl); + __entry->size =3D size; + __entry->dir =3D dir; + ), + + TP_printk("%s dir=3D%s dma_addr=3D%llx size=3D%zu phys_addrs=3D%s", + __get_str(device), + decode_dma_data_direction(__entry->dir), + __entry->dma_addr, + __entry->size, + __print_array(__get_dynamic_array(phys_addrs), + __get_dynamic_array_len(phys_addrs) / + sizeof(u64), sizeof(u64))) +); + TRACE_EVENT(dma_map_sg, TP_PROTO(struct device *dev, struct scatterlist *sgl, int nents, int ents, enum dma_data_direction dir, unsigned long attrs), diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c index 944ac835030a..b8a6bc492fae 100644 --- a/kernel/dma/mapping.c +++ b/kernel/dma/mapping.c @@ -685,8 +685,8 @@ struct page *dma_alloc_pages(struct device *dev, size_t= size, struct page *page =3D __dma_alloc_pages(dev, size, dma_handle, dir, gfp); =20 if (page) { - trace_dma_map_page(dev, page_to_phys(page), *dma_handle, size, - dir, 0); + trace_dma_alloc_pages(dev, page_to_virt(page), *dma_handle, + size, dir, gfp, 0); debug_dma_map_page(dev, page, 0, size, dir, *dma_handle, 0); } return page; @@ -710,7 +710,7 @@ static void __dma_free_pages(struct device *dev, size_t= size, struct page *page, void dma_free_pages(struct device *dev, size_t size, struct page *page, dma_addr_t dma_handle, enum dma_data_direction dir) { - trace_dma_unmap_page(dev, dma_handle, size, dir, 0); + trace_dma_free_pages(dev, page_to_virt(page), dma_handle, size, dir, 0); debug_dma_unmap_page(dev, dma_handle, size, dir); __dma_free_pages(dev, size, page, dma_handle, dir); } @@ -770,7 +770,7 @@ struct sg_table *dma_alloc_noncontiguous(struct device = *dev, size_t size, =20 if (sgt) { sgt->nents =3D 1; - trace_dma_map_sg(dev, sgt->sgl, sgt->orig_nents, 1, dir, attrs); + trace_dma_alloc_sgt(dev, sgt, size, dir, gfp, attrs); debug_dma_map_sg(dev, sgt->sgl, sgt->orig_nents, 1, dir, attrs); } return sgt; @@ -789,7 +789,7 @@ static void free_single_sgt(struct device *dev, size_t = size, void dma_free_noncontiguous(struct device *dev, size_t size, struct sg_table *sgt, enum dma_data_direction dir) { - trace_dma_unmap_sg(dev, sgt->sgl, sgt->orig_nents, dir, 0); + trace_dma_free_sgt(dev, sgt, size, dir); debug_dma_unmap_sg(dev, sgt->sgl, sgt->orig_nents, dir); =20 if (use_dma_iommu(dev)) --=20 2.35.1.1320.gc452695387.dirty From nobody Tue Nov 26 10:32:36 2024 Received: from out-178.mta0.migadu.com (out-178.mta0.migadu.com [91.218.175.178]) (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 A461B2022C2 for ; Fri, 18 Oct 2024 15:01:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729263677; cv=none; b=icZ/F+EkW+C3VOcNuYcUhNe/Ww79cjq4a9Ll7o67ho0DrmFaEwr3ZC1Ax9Z3D16cWCrfyF8kFP20DY6Z69Ce8yuNowFKkGE5K8lZBzN7VBB89ACopFs5ytCdLi4x5f0JaJcvcJBbNwDBnRWzPI11msfN00UonKxA5IFDFXP1UN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729263677; c=relaxed/simple; bh=A3Lz2IfVqiIipQitI8fDEdX8UYcXD7hjFScsNlsiR3s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IqAbw2pa/kVex4Yx6JmAYNyQ73W8xJdeVcxj+/JT+EWTetEzkY3NEvFySizOHLur6D3Cs6pAmxpzpqPTPB0z3oW9COcLl0ntr17Cm9CD+wev0YdwyG1HxyQ6+ai8madHddozZLMFR3pwfQ14VY052jfMzl7mS4FXq5bZ9U8dE8k= 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=NSps4bNO; arc=none smtp.client-ip=91.218.175.178 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="NSps4bNO" 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=1729263674; 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: in-reply-to:in-reply-to:references:references; bh=uBJJ7oPpaFz0LR7gPspJ9h0X3KUBu9OIrY8jq+HwuDc=; b=NSps4bNOHqkjB+tH585eG40awWL+idXl+7W8kpGcm7qVBQMN75wMIl8rALN1gAPnfr0Tgy YUcukIJvMtw89l2IUONyJnXoLVcn6UXZjIjt3EN9Ng4TkoyQvQP9T6VGwsl7I3JcFgY5Fi +QyeQI+MUbLK3mLJAIGPTUNe9gI3Svc= From: Sean Anderson To: Christoph Hellwig , iommu@lists.linux.dev Cc: Robin Murphy , linux-trace-kernel@vger.kernel.org, Mathieu Desnoyers , Steven Rostedt , Masami Hiramatsu , Marek Szyprowski , linux-kernel@vger.kernel.org, Sean Anderson Subject: [PATCH v2 4/4] dma-mapping: Trace more error paths Date: Fri, 18 Oct 2024 11:00:37 -0400 Message-Id: <20241018150036.2878190-5-sean.anderson@linux.dev> In-Reply-To: <20241018150036.2878190-1-sean.anderson@linux.dev> References: <20241018150036.2878190-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" It can be surprising to the user if DMA functions are only traced on success. On failure, it can be unclear what the source of the problem is. Fix this by tracing all functions even when they fail. Cases where we BUG/WARN are skipped, since those should be sufficiently noisy already. Signed-off-by: Sean Anderson --- Changes in v2: - Use macros to define events in a class include/trace/events/dma.h | 36 ++++++++++++++++++++++++++++++++++++ kernel/dma/mapping.c | 27 +++++++++++++++++++-------- 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/include/trace/events/dma.h b/include/trace/events/dma.h index 7a9606b8934e..d8ddc27b6a7c 100644 --- a/include/trace/events/dma.h +++ b/include/trace/events/dma.h @@ -156,6 +156,7 @@ DEFINE_EVENT(dma_alloc_class, name, \ =20 DEFINE_ALLOC_EVENT(dma_alloc); DEFINE_ALLOC_EVENT(dma_alloc_pages); +DEFINE_ALLOC_EVENT(dma_alloc_sgt_err); =20 TRACE_EVENT(dma_alloc_sgt, TP_PROTO(struct device *dev, struct sg_table *sgt, size_t size, @@ -320,6 +321,41 @@ TRACE_EVENT(dma_map_sg, decode_dma_attrs(__entry->attrs)) ); =20 +TRACE_EVENT(dma_map_sg_err, + TP_PROTO(struct device *dev, struct scatterlist *sgl, int nents, + int err, enum dma_data_direction dir, unsigned long attrs), + TP_ARGS(dev, sgl, nents, err, dir, attrs), + + TP_STRUCT__entry( + __string(device, dev_name(dev)) + __dynamic_array(u64, phys_addrs, nents) + __field(int, err) + __field(enum dma_data_direction, dir) + __field(unsigned long, attrs) + ), + + TP_fast_assign( + struct scatterlist *sg; + int i; + + __assign_str(device); + for_each_sg(sgl, sg, nents, i) + ((u64 *)__get_dynamic_array(phys_addrs))[i] =3D sg_phys(sg); + __entry->err =3D err; + __entry->dir =3D dir; + __entry->attrs =3D attrs; + ), + + TP_printk("%s dir=3D%s dma_addrs=3D%s err=3D%d attrs=3D%s", + __get_str(device), + decode_dma_data_direction(__entry->dir), + __print_array(__get_dynamic_array(phys_addrs), + __get_dynamic_array_len(phys_addrs) / + sizeof(u64), sizeof(u64)), + __entry->err, + decode_dma_attrs(__entry->attrs)) +); + TRACE_EVENT(dma_unmap_sg, TP_PROTO(struct device *dev, struct scatterlist *sgl, int nents, enum dma_data_direction dir, unsigned long attrs), diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c index b8a6bc492fae..636dbb0629a4 100644 --- a/kernel/dma/mapping.c +++ b/kernel/dma/mapping.c @@ -223,6 +223,7 @@ static int __dma_map_sg_attrs(struct device *dev, struc= t scatterlist *sg, debug_dma_map_sg(dev, sg, nents, ents, dir, attrs); } else if (WARN_ON_ONCE(ents !=3D -EINVAL && ents !=3D -ENOMEM && ents !=3D -EIO && ents !=3D -EREMOTEIO)) { + trace_dma_map_sg_err(dev, sg, nents, ents, dir, attrs); return -EIO; } =20 @@ -604,20 +605,26 @@ void *dma_alloc_attrs(struct device *dev, size_t size= , dma_addr_t *dma_handle, if (WARN_ON_ONCE(flag & __GFP_COMP)) return NULL; =20 - if (dma_alloc_from_dev_coherent(dev, size, dma_handle, &cpu_addr)) + if (dma_alloc_from_dev_coherent(dev, size, dma_handle, &cpu_addr)) { + trace_dma_alloc(dev, cpu_addr, *dma_handle, size, + DMA_BIDIRECTIONAL, flag, attrs); return cpu_addr; + } =20 /* let the implementation decide on the zone to allocate from: */ flag &=3D ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM); =20 - if (dma_alloc_direct(dev, ops)) + if (dma_alloc_direct(dev, ops)) { cpu_addr =3D dma_direct_alloc(dev, size, dma_handle, flag, attrs); - else if (use_dma_iommu(dev)) + } else if (use_dma_iommu(dev)) { cpu_addr =3D iommu_dma_alloc(dev, size, dma_handle, flag, attrs); - else if (ops->alloc) + } else if (ops->alloc) { cpu_addr =3D ops->alloc(dev, size, dma_handle, flag, attrs); - else + } else { + trace_dma_alloc(dev, NULL, 0, size, DMA_BIDIRECTIONAL, flag, + attrs); return NULL; + } =20 trace_dma_alloc(dev, cpu_addr, *dma_handle, size, DMA_BIDIRECTIONAL, flag, attrs); @@ -642,11 +649,11 @@ void dma_free_attrs(struct device *dev, size_t size, = void *cpu_addr, */ WARN_ON(irqs_disabled()); =20 - if (!cpu_addr) - return; - trace_dma_free(dev, cpu_addr, dma_handle, size, DMA_BIDIRECTIONAL, attrs); + if (!cpu_addr) + return; + debug_dma_free_coherent(dev, size, cpu_addr, dma_handle); if (dma_alloc_direct(dev, ops)) dma_direct_free(dev, size, cpu_addr, dma_handle, attrs); @@ -688,6 +695,8 @@ struct page *dma_alloc_pages(struct device *dev, size_t= size, trace_dma_alloc_pages(dev, page_to_virt(page), *dma_handle, size, dir, gfp, 0); debug_dma_map_page(dev, page, 0, size, dir, *dma_handle, 0); + } else { + trace_dma_alloc_pages(dev, NULL, 0, size, dir, gfp, 0); } return page; } @@ -772,6 +781,8 @@ struct sg_table *dma_alloc_noncontiguous(struct device = *dev, size_t size, sgt->nents =3D 1; trace_dma_alloc_sgt(dev, sgt, size, dir, gfp, attrs); debug_dma_map_sg(dev, sgt->sgl, sgt->orig_nents, 1, dir, attrs); + } else { + trace_dma_alloc_sgt_err(dev, NULL, 0, size, gfp, dir, attrs); } return sgt; } --=20 2.35.1.1320.gc452695387.dirty