Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp82370lqp; Tue, 11 Jun 2024 15:44:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU9K55KkAIBz1bTw2w0ykdiRqEneClbOh+vMaB8xEjJMudAx0F/4liUbkU0I+t5Azt8xoRTjAukiVUXe51h7nWjC+8pPqXUxdgJ3LdWDA== X-Google-Smtp-Source: AGHT+IFbbvDGmNwcgpwsmdNLehWCA3VNtedo1BdVPbv7kFKNvx0rhhVo0p9K+bSIr14+PaJvVCRB X-Received: by 2002:a17:906:35d8:b0:a6f:1b5b:2acb with SMTP id a640c23a62f3a-a6f4800b1femr3284866b.59.1718145854163; Tue, 11 Jun 2024 15:44:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718145854; cv=pass; d=google.com; s=arc-20160816; b=jAJkxcUd3dlLdOtDsnqyhNX+fcj9XmPrtXNmhs55Wix361BRKG/ndxb/T7nHkyKPY/ 5SA1pL5I9cpS7EagCLpkelVdpfnF1sOs3I5cPYnDpDltE4kPbgaAu74+ZTruanUPRUWS 4NNzKCO1pLJ5DjVpFh5lPWVcH8D/QVowAyu13OB93GlRv8VOkIcoQzHgXbXOhmcHOGdm XXOxLSPRXzcYvxnRFL8JB9WzOMdIBhpGbHDuemKQfBOrB/ZIyBs5e4mlFQdL8xXUNFUl l1RoxTV5EJoMp12Vu1YNKrEtAIJBontn4EQa7sazfGAopDga0Ra5ZkA5ij1xGl+7EK4o wi6g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :sender:dkim-signature; bh=JjJgoNErYdG8LWeuzJrz+S/8auNsee/95pEsFxHhxCY=; fh=F1nv0eJT3tzwr5mK7bsnt1oyPoLlKkbUVYBbgUmLxM0=; b=OSO/urRz3u61ccJDZd5Fbr96rUE1A+dSImbSJ0etNmOipYezSwDdH+eZNIZNYHFHwf yKbq269+/6TfQ5zt3vDn5ocltkI0rZlnVAKcjWksj2LJ9qOlWRlxyjrTJ5D+qdLJFFCd 8xsMh9uBHkq7ofzocVogkUcqqqkrCC5d00sF6lNSnao6k+jUb2O4B5Fit1UZCyjtw59S SaByx2pUpOunarrGL4tRFBQL/BlpXWZSTOv4LidO+STrfMROlejNATWsoyzY4ue17Zvg LZuMNn4wVTU0UM4P+sWJOevoetayCzPv/NGGrL743Dmuqx6WqSYrfQUBzZpTdkPvI8hr E1WQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="c/WPQiCj"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-210674-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210674-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 a640c23a62f3a-a6f1d91edaesi255118066b.397.2024.06.11.15.44.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 15:44:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-210674-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; dkim=pass header.i=@gmail.com header.s=20230601 header.b="c/WPQiCj"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-210674-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210674-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 B15AF1F25193 for ; Tue, 11 Jun 2024 22:44:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B6F661553BC; Tue, 11 Jun 2024 22:44:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c/WPQiCj" Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 435E718EAB; Tue, 11 Jun 2024 22:44:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718145844; cv=none; b=AXjyWRhMLW/Vp3nd/XVC839r4jBi7lFNJwM0n2pQwKYUigqsdQKUdvkR5bnbmNRDkRY8pmJfy9+R7RZwzHWUA6NTjYkmz3y9LAEKDJ0ysiNnDHupbY++05dgqLEI4tDEWRknLp5Ndu/TS3TPAvECRDEoxhgtsEtd/TD+QnfvoUk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718145844; c=relaxed/simple; bh=jkgGX6JhTSKc2JQ9lobIrsZ6+J2wG4/W1YxnzTSYc0M=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=jB4CqV1Q/n+3sJCiquo+60JZlRsTVugO+LJp95cNZsiPbL+Yze+Wd3Pss1eQXPBlzFEZpPDIp+qDxgUSBDpikbsXc98rQpPxDxjGVsLYIoDGCngtcg3T85C/z1QwI2ShZk5aBl8WJwSdL4whfvjEsUG+wjhRnmQv8c78qn0um20= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=c/WPQiCj; arc=none smtp.client-ip=209.85.210.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-7046211e455so2189226b3a.3; Tue, 11 Jun 2024 15:44:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718145842; x=1718750642; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:sender:from:to:cc:subject:date:message-id:reply-to; bh=JjJgoNErYdG8LWeuzJrz+S/8auNsee/95pEsFxHhxCY=; b=c/WPQiCjsaq+IstRIAk0LJcO6vQi1XDo/zCq+TxVNdwRS++x9Fk2B3TDmjz6W9BxY1 ADZhT48qQ1GjO/Le/0xWgO2YSLsRP2HrfDcnuNRlBB4goi1PlWT3KztOj+4fWs6jb42k S513tOdilHNojRIk7+LW1B1/Kk2fpuusDDuhtfcaHhmGk5JOoHwtCqSufd2OjjEqeD+H 4m9h1/uj/G64i3gviDoV3OK+mgdktke55GWsLe3pInKKYIrMQQdP2L6HyQeyfs0/ZC82 df5XUX7DmPnfOgme70YRGo2OQdaBTnOgvbd4RDJ+TkZz9tfzzdYNp673jKYQMqOgailw SWZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718145842; x=1718750642; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=JjJgoNErYdG8LWeuzJrz+S/8auNsee/95pEsFxHhxCY=; b=Yu0dULZzb5vTXERNhiccFgJsRoDQ661yTSbkuIkzArySRE8z2jLfAD+NyAqHY1yN9a 31qbNakEZWjPBiGk7p0lPNGIPqzH9elkMqD8p+VYSgQYP87nO/51tMi5M8CUJkf7YDah 6PsjnIK/UeJaUfmG01xg4VPNWG47m9xKv/9RG/nfvjyMilC8/sVQzrSS/nMal2ajTFp7 flmi+jvcG1w6MiruvxnB/YxQdhynxSqqp5OEEM2Cyo7QairXcNxRVBUROl/uDzwUzeDs PBNxSD6k8xd7QUzbjx6gRaI2Vy6EU6rSlk9c5Qg6LqN2otE+AkdO01JldHqMuBdJ33+C rUWg== X-Forwarded-Encrypted: i=1; AJvYcCXZVTlLi943Jvw9uveKhI4zLuiUPCCuMryroofOxjxAruLyo3m3lYsJifHaQiJFnlHHuhpDEAjHfeNFMSiNuxGG30kTrpk6dOGZchYABkM/SAWsGRSQaY2q18QzB4ML5thtW2Q8Y5eVArHqS8QUPQ3+ X-Gm-Message-State: AOJu0YxCCytsTvJ7W6ID/f+2AMTMQ/RCvo6iq6/fiJX2XJ/23NVu8A7T hAWHhjRkGHoMA35iZKvUUNovGVwBgGyqu8jSl6IPG2gTRIybVbnW X-Received: by 2002:a05:6a00:22cd:b0:704:1932:5604 with SMTP id d2e1a72fcca58-705bce75f56mr236329b3a.15.1718145842384; Tue, 11 Jun 2024 15:44:02 -0700 (PDT) Received: from ?IPV6:2600:1700:e321:62f0:329c:23ff:fee3:9d7c? ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70432977fe4sm5185237b3a.59.2024.06.11.15.44.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Jun 2024 15:44:01 -0700 (PDT) Sender: Guenter Roeck Message-ID: <5178e22b-0c00-48d2-8a6e-85510706f145@roeck-us.net> Date: Tue, 11 Jun 2024 15:43:59 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 01/13] ring-buffer: Allow mapped field to be set without mapping To: Steven Rostedt , 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 , Ross Zwisler , Kees Cook References: <20240611192828.691638177@goodmis.org> <20240611192907.402447387@goodmis.org> Content-Language: en-US From: Guenter Roeck Autocrypt: addr=linux@roeck-us.net; keydata= xsFNBE6H1WcBEACu6jIcw5kZ5dGeJ7E7B2uweQR/4FGxH10/H1O1+ApmcQ9i87XdZQiB9cpN RYHA7RCEK2dh6dDccykQk3bC90xXMPg+O3R+C/SkwcnUak1UZaeK/SwQbq/t0tkMzYDRxfJ7 nyFiKxUehbNF3r9qlJgPqONwX5vJy4/GvDHdddSCxV41P/ejsZ8PykxyJs98UWhF54tGRWFl 7i1xvaDB9lN5WTLRKSO7wICuLiSz5WZHXMkyF4d+/O5ll7yz/o/JxK5vO/sduYDIlFTvBZDh gzaEtNf5tQjsjG4io8E0Yq0ViobLkS2RTNZT8ICq/Jmvl0SpbHRvYwa2DhNsK0YjHFQBB0FX IdhdUEzNefcNcYvqigJpdICoP2e4yJSyflHFO4dr0OrdnGLe1Zi/8Xo/2+M1dSSEt196rXaC kwu2KgIgmkRBb3cp2vIBBIIowU8W3qC1+w+RdMUrZxKGWJ3juwcgveJlzMpMZNyM1jobSXZ0 VHGMNJ3MwXlrEFPXaYJgibcg6brM6wGfX/LBvc/haWw4yO24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rQOMv8lSRdjva++GT0VLXtHULdlzg8VjDnFZ3lfz5PWEOeIMk7Rj trjv82EZtrhLuLjHRCaG50OOm0hwPSk1J64R8O3HjSLdertmw7eyAYOo4RuWJguYMg5DRnBk WkRwrSuCn7UG+qVWZeKEsFKFOkynOs3pVbcbq1pxbhk3TRWCGRU5JolI4ohy/7JV1TVbjiDI HP/aVnm6NC8of26P40Pg8EdAhajZnHHjA7FrJXsy3cyIGqvg9os4rNkUWmrCfLLsZDHD8FnU mDW4+i+XlNFUPUYMrIKi9joBhu18ssf5i5Q= In-Reply-To: <20240611192907.402447387@goodmis.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 6/11/24 12:28, Steven Rostedt wrote: > 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); > + Picky again. Is that a leftover from something ? I don't see an immediate reason for the added newline. > 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--; This will wrap to UINT_MAX if it was 0. Is that intentional ? > > raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags); >