Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp120393lqg; Wed, 10 Apr 2024 18:26:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWm2+ZwelbuKx/iAUNtLK85FkciS/4+lz8uaXU8nXX40bp1SfEAFTR1s14uOPCy/WtEl9oabe3PPVNaUKH1lyZa8GCnlYYUx9twP1wadA== X-Google-Smtp-Source: AGHT+IGZG1rR7Yhs93yjIXiDQQKthHgkrsm+jEv7iiPt0Q1cUg4WUlEz44/ii45WOCidAw1L5GwB X-Received: by 2002:a2e:7a14:0:b0:2d2:3fac:5fc7 with SMTP id v20-20020a2e7a14000000b002d23fac5fc7mr2550540ljc.45.1712798798050; Wed, 10 Apr 2024 18:26:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712798798; cv=pass; d=google.com; s=arc-20160816; b=bd1Whi1SKJyVEtzKqUiSAWeGVXbXH//VqTMFin3JFqBXSIuiG5+n/CWPTUlIKkbTV5 c+BNx28W1j/gLPnLMg27Bb2lAcdX1ZMHXd1dK2JUMY7lZU6VAKOZfJn5un55l5wfz/eh uFQvomOM/lFgaOnMRJf2Rs4FwuUzZ5uJb7Ef8V5ZUziCdr/QDfZsri8qDKsQHKAfnrCV TBlgnvTNohAAHMqCfE+zgjacWbdpTclZJTF28jVqQamyZ3NGdgv0GM04PO5X2sW9UYgB 8BiQcv9+aBQMwCOuCkZ9Nj3I7tB/6hovQP3Y9UnLMkXhhqpKgatXKd501l8k38KCWsUv dHhQ== 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=BI1qRTQa9U/xAa/Y0BfsuvhNBv3RDTanrDUxzJ1gIfU=; fh=Ix7vUKcZB54T3hGcALQhA/BzgLD1qNEu9GE2SGoxGjs=; b=UBE9bZPERHAmAxjRMMmMuFbgNFyLj1iuIy8odeLzXBcB5318nTXjiV76MGtRDFynQF XoKzEwA6dvTmJSipgPE7dD2+4ipuSQG/pDiL9CRNJ2DwLRPXh00bvhA12Nl8J+ksKAVZ FaF0kTCYJM2Q3Rcnf0I7hqpm9zP4KJWc5e0yVC6Djeuhz9b8u7xH2ohkCwmBNG2DwgsV s1nR9iCe/CoxSMt/VH9ZFh+/SZbm0fw/LbfDBlbx2uk7PqPOJwreh/HNImCM/5mmWPm+ TBd784LcNM8zmFbDV9m6QUCDR4Vgcsj4Y3VGALBFrPSNxeBBbaL3IA6v5FKQo3laqHQc aipA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-139618-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139618-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id e2-20020a50d4c2000000b0056e55b5b0besi210433edj.554.2024.04.10.18.26.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 18:26:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-139618-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-139618-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139618-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 am.mirrors.kernel.org (Postfix) with ESMTPS id BC8F91F23BA2 for ; Thu, 11 Apr 2024 01:26:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EB74B626DD; Thu, 11 Apr 2024 01:26:26 +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 6A0329463; Thu, 11 Apr 2024 01:26:26 +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=1712798786; cv=none; b=TJbQ2EH6RnQg49VrmDrBbINZDVjiKYNOLPkJYrzEIe+yDd50lmOe7zM5T5+4QVdIjs9e+mdfx/oJx8NmpvfwCk5x1Q0eMDNZHmW74sU1TQPX98XMwoQGfCvBvtWGqzb6SnidXYb/D3PpIfO7qDXEjq25nFmUpMvN2YPahpcFphg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712798786; c=relaxed/simple; bh=IlPKCSnTXcWRdfMJfl+v4+6ZAFaukIF1oqLA7Iz3tPQ=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=dgFNw6jujPlUW0MTFLiGqZTkvg4jE2Dohzj/AbDKs8SlJovOeJd8o7KNRyM8PGMwxIHYt+9Cl2yiG/uHzc3Y30qqoPYsHjKXqYH7oyUhqFavhoCb3xn9imMLrHi0Fsv3W5qDpKizIX1ec7efzgIO3RZY+JzzejPTdO46Zj1Fx0Y= 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 F270DC433C7; Thu, 11 Apr 2024 01:26:25 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rujFQ-00000000nUT-1Z1D; Wed, 10 Apr 2024 21:29:04 -0400 Message-ID: <20240411012904.237435058@goodmis.org> User-Agent: quilt/0.67 Date: Wed, 10 Apr 2024 21:25:42 -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 Subject: [PATCH v2 01/11] ring-buffer: Allow mapped field to be set without mapping References: <20240411012541.285904543@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 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 793ecc454039..44b1d5f1a99a 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -5223,6 +5223,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); } @@ -6345,12 +6348,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); @@ -6388,7 +6392,7 @@ 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; + cpu_buffer->mapped--; raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags); -- 2.43.0