From nobody Fri Apr 4 21:41:25 2025 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD14C1FC0E6 for ; Wed, 8 Jan 2025 11:46:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736336783; cv=none; b=kHT3x1B44gkx6d5rGGbl/fPZ00fBrRuLLACjDjFSgw8Zd6NkBptdLmGJWmxm7hqPMsJEqQsbWDqhviBb4VGxrMtltqIItE5zwUH+rFGXNlmaXaN9/JTGUpKRHqAeLcMjBOpHxQqD28TckWm3NbmneV4/ytSy8VMUBjy8fDibHeU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736336783; c=relaxed/simple; bh=lDl5drBkYzVy9toQq6HEzUqIT/PGvzU0P07pQal1y5M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=onvsMkI1SJakywsSpDVtOgsVGnyIlxMc30eCNJhGwvLgpUnK5IrbZRzRLGeR/A+tGXr4U5c25QpY3M327c9KKO/NgSDEKr2TaProjDBfvvL7nQcUNvQJrOhUpN9pHdoNcEWsMt0hEZnXiNyVhUvHBk+SdKeY4sbMjjA8c1KgojE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vdonnefort.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=vaf2Sy2N; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--vdonnefort.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="vaf2Sy2N" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-436723db6c4so96116675e9.3 for ; Wed, 08 Jan 2025 03:46:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736336780; x=1736941580; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=d8iCsJo5WR6KzxB92gJlgV5iV2uqY4fo13qrdsq5Log=; b=vaf2Sy2NRVW9SDmWFu+CNDCm3ISrggsQioK155BQZhxAdBqBYdsEWLNss1LanAbRMV ULvPl9WwOGQlLhVW/lFb+tuYVz6lK/25YbtVxiMt/RIjJSSWThK1LjGdbo5wyNf4sqj2 DpqiFw822Y3Rf7s8YxVkPLSidSt+R2CKE+kK5RWC3EXLH26zmEP6N83aFJxmn4WSlDa2 Em5pEgDwjzvCl9lXfVcFajwDBTJ/lB0VFMhCds4ZiRz2cJyzSUHd9iuV9J4ckhytGw3k 0ULI1k6GW/EnJsGDEbinvEisD+v2nW0CBSMdW4QTajnagaWQW2R+C9NS2AJHB0eqOSTS MlXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736336780; x=1736941580; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=d8iCsJo5WR6KzxB92gJlgV5iV2uqY4fo13qrdsq5Log=; b=B1O5lYHoNZrtCTyKlEZnssubeuL2emWRiPED9wFusu0EVvMckGEBy0KmRlpYdVRGkX KisP1Vo1+Gh+29n11S8WWGdQNkrgDlT0QTsCna7imegmXlZ3hQfDiN2aWmLRhfqwckk9 /+koSOUmRWY+hKwZJI3R5wOPpOuJV3zFGWcusQU/DqzrjAOnIltRfqsFaXu23H6lhwxq MmazMELvfj9rJIU9WmeETGLfgdL9QbnJ6wkyBX8c51hQwJocQMj+L77dsDhh4HJHzNOJ oewWqyR6j1MH/vkkLo6pQ55l59aRdsKZgpIzep9/pkdPjMoebOMqJidCcwySbrzmHZad be0A== X-Forwarded-Encrypted: i=1; AJvYcCVphK+I3l3ZT0tMpDn6sRMbQRMwOCL3wi8RlPBBChiLjLxkLVncYtEWWI6AumEGaM+V7zcObGGXHOdgSZQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yw7h2bFCmXSTjRJ/2hYpcw7PorsDYv0fj0UEGn2c+4qfraWrRrC qUFVoPKRfOo3hqTNmDAZ/7sP8rAaG3tIdsFjQyZ0krxdtKlLmPfO6PaVSwJPLk+1m580WZiY9zu +DhMNw9o4Y2X/uLAFmQ== X-Google-Smtp-Source: AGHT+IHXMIUN4Xu/0FCutrVo30LeA75reWr3RoI+cwLisNRBI4gx5AnZfMZi4bJ3gkUBjuYDzu4HpZhou3JnhYMl X-Received: from wmpz19.prod.google.com ([2002:a05:600c:a13:b0:435:dde5:2c3b]) (user=vdonnefort job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4751:b0:435:23c:e23e with SMTP id 5b1f17b1804b1-436e26af4b4mr21060665e9.12.1736336780098; Wed, 08 Jan 2025 03:46:20 -0800 (PST) Date: Wed, 8 Jan 2025 11:45:33 +0000 In-Reply-To: <20250108114536.627715-1-vdonnefort@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250108114536.627715-1-vdonnefort@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20250108114536.627715-10-vdonnefort@google.com> Subject: [PATCH v2 09/12] KVM: arm64: Add raw interface for hyp tracefs From: Vincent Donnefort To: rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, linux-trace-kernel@vger.kernel.org, maz@kernel.org, oliver.upton@linux.dev, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, jstultz@google.com, qperret@google.com, will@kernel.org, kernel-team@android.com, linux-kernel@vger.kernel.org, Vincent Donnefort Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The raw interface enables userspace tools such as trace-cmd to directly read the ring-buffer without any decoding by the kernel. Signed-off-by: Vincent Donnefort diff --git a/arch/arm64/kvm/hyp_trace.c b/arch/arm64/kvm/hyp_trace.c index 78193dbd8a33..3d2a58977442 100644 --- a/arch/arm64/kvm/hyp_trace.c +++ b/arch/arm64/kvm/hyp_trace.c @@ -749,6 +749,85 @@ static const struct file_operations hyp_trace_pipe_fop= s =3D { .release =3D hyp_trace_pipe_release, }; =20 +static ssize_t +hyp_trace_raw_read(struct file *file, char __user *ubuf, + size_t cnt, loff_t *ppos) +{ + struct ht_iterator *iter =3D (struct ht_iterator *)file->private_data; + size_t size; + int ret; + + if (iter->copy_leftover) + goto read; + +again: + ret =3D ring_buffer_read_page(iter->trace_buffer, + (struct buffer_data_read_page *)iter->spare, + cnt, iter->cpu, 0); + if (ret < 0) { + if (!ring_buffer_empty_cpu(iter->trace_buffer, iter->cpu)) + return 0; + + ret =3D ring_buffer_wait(iter->trace_buffer, iter->cpu, 0, NULL, + NULL); + if (ret < 0) + return ret; + + goto again; + } + + iter->copy_leftover =3D 0; + +read: + size =3D PAGE_SIZE - iter->copy_leftover; + if (size > cnt) + size =3D cnt; + + ret =3D copy_to_user(ubuf, iter->spare + PAGE_SIZE - size, size); + if (ret =3D=3D size) + return -EFAULT; + + size -=3D ret; + *ppos +=3D size; + iter->copy_leftover =3D ret; + + return size; +} + +static int hyp_trace_raw_open(struct inode *inode, struct file *file) +{ + int ret =3D hyp_trace_pipe_open(inode, file); + struct ht_iterator *iter; + + if (ret) + return ret; + + iter =3D file->private_data; + iter->spare =3D ring_buffer_alloc_read_page(iter->trace_buffer, iter->cpu= ); + if (IS_ERR(iter->spare)) { + ret =3D PTR_ERR(iter->spare); + iter->spare =3D NULL; + return ret; + } + + return 0; +} + +static int hyp_trace_raw_release(struct inode *inode, struct file *file) +{ + struct ht_iterator *iter =3D file->private_data; + + ring_buffer_free_read_page(iter->trace_buffer, iter->cpu, iter->spare); + + return hyp_trace_pipe_release(inode, file); +} + +static const struct file_operations hyp_trace_raw_fops =3D { + .open =3D hyp_trace_raw_open, + .read =3D hyp_trace_raw_read, + .release =3D hyp_trace_raw_release, +}; + static int hyp_trace_clock_show(struct seq_file *m, void *v) { seq_puts(m, "[boot]\n"); @@ -803,6 +882,9 @@ int hyp_trace_init_tracefs(void) =20 tracefs_create_file("trace_pipe", TRACEFS_MODE_READ, per_cpu_dir, (void *)cpu, &hyp_trace_pipe_fops); + + tracefs_create_file("trace_pipe_raw", TRACEFS_MODE_READ, per_cpu_dir, + (void *)cpu, &hyp_trace_pipe_fops); } =20 return 0; --=20 2.47.1.613.gc27f4b7a9f-goog