Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp652604lqt; Thu, 6 Jun 2024 14:21:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXKe7ZBa/fYW7IOFi/aPWmKXsMqChp1RyvstiVGiTuvXVv3KqCaZDSfXEzxOU7V8S1tHzobIKZhZ/x5Xs+shU+xeKISR+fHy0aWcTJyKw== X-Google-Smtp-Source: AGHT+IEQJNtTLHrn2f1X9GoYjpRCc9jJDpLRp8Wl1ZjdYUyYXu9afjndPfxYXUU9IFAbYL367Be0 X-Received: by 2002:a05:6a20:3ca9:b0:1b0:225:2b2c with SMTP id adf61e73a8af0-1b2f9698749mr830081637.13.1717708907867; Thu, 06 Jun 2024 14:21:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717708907; cv=pass; d=google.com; s=arc-20160816; b=b/pcE0yoBUxVion80uGKIHnAlTuZq+bpO1iPnup1dxPuopmwkn1BdgFEFVZ3D5ldnF RI4oIdSLUojABl2NtQ3ensfEcA1hHMDr7Rod8P+hjsi4WTjJeYOQlgL6rWL8SnEq7JLv gN4c3I6qmbXxTNXEZYVWjMKAYoPYYocIbaoZY6i/bkhR1gqo9Dysbf8FN6JtXIVzK6R7 587gOGPqU41hDHsZTKsNpLRSVIJa9yMGL4Xy2cwpzAWU3tyTWFd1VYPKjQR47t/d8ZV8 H8B4UzflIyJCFuNzIyb/33iL6+93/q0ei5OhoDFcpU5ypEsSJLhVWAJt3JyygL4nnBqy s+UA== 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=GOxR0gSJJXw3ueOL38TptaZog1+kFdfzFZ+BVWk4ek6/RJjcnE5AJgTIXgKf9Ty1eW ayxXHvcpMFYXy1Mx8DyNiwFkE59n8P8z/gtVGSBqJza048wN4k+YY5OLSDD7CbJJz6yp tyHAe7dEohw2wd9mhE66OapEuuhPoOGN3q2QkMBt1rXTeUdyWbuFVVNqH14kri3XaZBh TjrReQWhGg6coS9cVXe1wfqYW3uoW3HCxRfDB3WlSNvsV/grtGg0TmDCWURZyIlEHUW6 XqE8GvqRW85DEW6f+6mHahtDAljMTjp7ugXn8KLEdIbs2VdlI/R7mQ3cU6ivsA7uw3jj V5aw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-205041-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205041-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6de262c006fsi1351198a12.366.2024.06.06.14.21.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 14:21:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-205041-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-205041-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205041-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id BAD18284D99 for ; Thu, 6 Jun 2024 21:21:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ED7EF19750B; Thu, 6 Jun 2024 21:21:31 +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 678234C622; Thu, 6 Jun 2024 21:21:31 +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=1717708891; cv=none; b=RU+K9jxoks66U9xpFi5L9zgqzZl1P43Sk09R4kOVoCeJoBM5PbB+dvmSSGmkonH52EKY7BA98qc2FmjnyhdnjDIi8B4ddWqEWf8tjAruiaoi8jhw14jGHQiH1JOUXgmoUcOWsNXuGSgp7gs44LpZpkUv+oSwBsPLSfWBRj1FpHc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717708891; c=relaxed/simple; bh=0lLeJ9L6obuUbihPoov7/e8fbffmXhCAKt5nfOzmqgM=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=O7PdobTqYRp14iLc8kMNYh2irDlyJL3ONRdNf6KOkeQ24BqwgrqMweFFnGwh8MSRRlpdVCDIgxA+IspJxX4uDzY4Go+UnDbUbLEHbvKXjStKVHyGHdBsx83hhp2p8X5rZ7qHVdOmp0Z4hK1kUgAd3Pky8TZ++yxXpXjHlpSuY44= 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 06F7AC3277B; Thu, 6 Jun 2024 21:21:31 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1sFKYC-00000000qHm-1Tg3; Thu, 06 Jun 2024 17:21:36 -0400 Message-ID: <20240606212136.207093084@goodmis.org> User-Agent: quilt/0.68 Date: Thu, 06 Jun 2024 17:17:36 -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 v3 01/13] ring-buffer: Allow mapped field to be set without mapping References: <20240606211735.684785459@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