Received: by 2002:a05:7208:c250:b0:86:f851:443 with SMTP id w16csp44806rbd; Tue, 11 Jun 2024 12:29:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVKyVHBhO0Myn1434/LOHHVwHCdS0QRqGNbKzoEDedIZj2GA0oQRIJpni5jxFCQR12lNmu1fVMMoiMzBBNZQy7cXT9e3ocR1KAlERPYAQ== X-Google-Smtp-Source: AGHT+IGmmCjnPpxWlaTpX/0eAl4KdPpnt2UdLwqEiJSchne2o9r/b347L0FLrnBQ8Uth/e1J3NaA X-Received: by 2002:a05:6214:4386:b0:6b0:861c:1227 with SMTP id 6a1803df08f44-6b0861c13damr48893396d6.31.1718134150485; Tue, 11 Jun 2024 12:29:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718134150; cv=pass; d=google.com; s=arc-20160816; b=PoW6HHZwbtsRmM2dXp0Fz3CUXWhq4PrDUNjNcivBGvauIg7zA7KrJz+RA/p8G8t1Am QwjM+eHQOzEcuRFq7ksN9rMp2G1/lTJA7gjU1FwC9FWI5GaDM4lGvlk94lC2mXMDwSLt DZDj0gloErR27QZoK32j2sgjNiaNxt3FtNpKgAH+GkasqYNYLAFrr2/dCrp8lmX30mQh ciKwchfvqFwjyRGIAti59l7GpcGskpKyrPCe2ZrNotPKb2HuJoI80Yi5OEkE9ZsOBxXC FiVtOblEVKDRtkB8lu9weSy1II/rQDXjETRgHRLFKG0UEDJ+bPfCiUKOZgUoEk3JZ78C RbTg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=fZyjcLPZbAa/nWM0Vg+4GEo0Vqk02SZzqzkRDut0UOk=; fh=VQi8WXJrSHXxsfwqC9oAfi6LEiQC0Qv/w+aqrHCHJLs=; b=E8FwbMuXsTOD5reATbfyW5ZRhMoK6wK1xYBy9jZAKq7okcQfizyozqEdWZTdNGuOpW +8robCFnaz0DjcBHKK8A5a/82t4JT5tLmY0TCgWPcmdcoloqwp5fHSfa6Wv+Urht+W59 UJtuvAFq1aJ0Ke19e9dixKRsyx4wzqkouM4JPkb8BEKha6rair1Xvdji5ti+YM1GQe+6 YgMSqovKAAuY47vm6oxziJ39lC0yreHqwHL+PPaxd6XPo9M7pIGN7sqiSf65J1Vyh3d5 AUdSq6GPnfDOVtlDXBYCjH6kwMW/pG4O0JsI85+P1H/wMF6cbvC8VgS4KcNfNN3yS1J1 +KXA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-210500-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210500-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6b07a8b34c4si59957796d6.7.2024.06.11.12.29.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 12:29:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-210500-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-210500-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210500-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 31F3C1C21EB3 for ; Tue, 11 Jun 2024 19:29:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 022FC143742; Tue, 11 Jun 2024 19:28:52 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6F8F67D3FA; Tue, 11 Jun 2024 19:28:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718134131; cv=none; b=DCkzrR0NmGizZqyDgU2cthb7z7dQpMT1yM8MgnzyO8Lo/98ahBBrlmEIe6CfVNwBzOJbT44r73GVkthR5dvaxLP5cdXq6RwOmZMc9wyqe3mDKr0Qlw3bZEP5TJ0FuVTmHnXixNZ/X3F5mbA3lSgJJXBq3aDscjvJ/fjGTtJt9pE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718134131; c=relaxed/simple; bh=0lLeJ9L6obuUbihPoov7/e8fbffmXhCAKt5nfOzmqgM=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=j255H8dcr8SGKyLfoV2n//txCzSH+4ty6BWm7irf7wrDjXNkFgUL5iHhYCwSeh4xzWgA/jMOkKeRyFYQ48N2neVS7ry3juPYZWiL8eKOAP66OJVwQmqFTJgCFWVWs4A592UgsVSNWF0AY/Ls8taIGF0mjDxXhJsOxvxeMCcEtQ0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C8A6C2BD10; Tue, 11 Jun 2024 19:28:51 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1sH7B5-00000001Tq0-2HqS; Tue, 11 Jun 2024 15:29:07 -0400 Message-ID: <20240611192907.402447387@goodmis.org> User-Agent: quilt/0.68 Date: Tue, 11 Jun 2024 15:28:29 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Vincent Donnefort , Joel Fernandes , Daniel Bristot de Oliveira , Ingo Molnar , Peter Zijlstra , suleiman@google.com, Thomas Gleixner , Vineeth Pillai , Youssef Esmat , Beau Belgrave , Alexander Graf , Baoquan He , Borislav Petkov , "Paul E. McKenney" , David Howells , Mike Rapoport , Dave Hansen , Tony Luck , Guenter Roeck , Ross Zwisler , Kees Cook Subject: [PATCH v4 01/13] ring-buffer: Allow mapped field to be set without mapping References: <20240611192828.691638177@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 From: "Steven Rostedt (Google)" In preparation for having the ring buffer mapped to a dedicated location, which will have the same restrictions as user space memory mapped buffers, allow it to use the "mapped" field of the ring_buffer_per_cpu structure without having the user space meta page mapping. When this starts using the mapped field, it will need to handle adding a user space mapping (and removing it) from a ring buffer that is using a dedicated memory range. Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ring_buffer.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 28853966aa9a..78beaccf9c8c 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -5224,6 +5224,9 @@ static void rb_update_meta_page(struct ring_buffer_per_cpu *cpu_buffer) { struct trace_buffer_meta *meta = cpu_buffer->meta_page; + if (!meta) + return; + meta->reader.read = cpu_buffer->reader_page->read; meta->reader.id = cpu_buffer->reader_page->id; meta->reader.lost_events = cpu_buffer->lost_events; @@ -6167,7 +6170,7 @@ rb_get_mapped_buffer(struct trace_buffer *buffer, int cpu) mutex_lock(&cpu_buffer->mapping_lock); - if (!cpu_buffer->mapped) { + if (!cpu_buffer->mapped || !cpu_buffer->meta_page) { mutex_unlock(&cpu_buffer->mapping_lock); return ERR_PTR(-ENODEV); } @@ -6359,12 +6362,13 @@ int ring_buffer_map(struct trace_buffer *buffer, int cpu, */ raw_spin_lock_irqsave(&cpu_buffer->reader_lock, flags); rb_setup_ids_meta_page(cpu_buffer, subbuf_ids); + raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags); err = __rb_map_vma(cpu_buffer, vma); if (!err) { raw_spin_lock_irqsave(&cpu_buffer->reader_lock, flags); - cpu_buffer->mapped = 1; + cpu_buffer->mapped++; raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags); } else { kfree(cpu_buffer->subbuf_ids); @@ -6403,7 +6407,8 @@ int ring_buffer_unmap(struct trace_buffer *buffer, int cpu) mutex_lock(&buffer->mutex); raw_spin_lock_irqsave(&cpu_buffer->reader_lock, flags); - cpu_buffer->mapped = 0; + WARN_ON_ONCE(!cpu_buffer->mapped); + cpu_buffer->mapped--; raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags); -- 2.43.0