Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp108275lqp; Tue, 11 Jun 2024 16:53:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXRVxN/7ay75ecaPev2LwixE8aKQv6ukgMR5te5y0+gL9vhbSVXhwCq9T18pU9OJEtnzUFjuSh1AnefTsm2psaRNMv4eDjZ3AAQCxl4Iw== X-Google-Smtp-Source: AGHT+IHFr7xrJCE8GILAJVUpXnKTpy7fZkW4KdDmD1uh+vihg0BhdupGbFDml6y3OkhvDJjIj3aJ X-Received: by 2002:a17:903:40d2:b0:1f7:1a31:fb03 with SMTP id d9443c01a7336-1f83b719b46mr4735745ad.64.1718150035633; Tue, 11 Jun 2024 16:53:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718150035; cv=pass; d=google.com; s=arc-20160816; b=Qbvt6YJrshQYS687327yt7s1YFHn9NEt+j+x6QKYCv1PHPGWOI1/FuJbKxnRDl2Uga Y+IjO3KYnk5IbIa9uNZWo/8J88JNn8IQFHcgV75ufMwGg3gyJS2xgXIFizKb6cn18/fA L0OLXzuVZ+OfRl99S7sSdslbWxIK9ipwG7IY3W8136HQW5mSTHEuli1ZkbPq9YiDyk1O Vu3ob3btx5dwrwff6nqCCJEfAppbhqTzeJtTsjrJWtVMfndHO8PuvztZzNBovKXawGmU dFLvfCficW15OR1nVbiDwpbJSaUgb4RyWMZOVeiwb3W3oxaTmRs5EQ5RoEL6yBcok9+D U19g== 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=B2nCf1ZS5hyGT3Pv3PgsvdwOjQ/1NGLvLUu1cRiT+Bc=; fh=A/3RftPT6mcI6q4Pl0gmpQD3KdTUK+vYhkITwx6kUxI=; b=hyD44+qTGF9WqxxA81uilM2J/BgkNQEVUVKrxIuMrXK/zpfDOupOHviAUhJOfnaDr+ RS6pEKZdOs0ujqwFtFGkhGNWJg/SzRhiwvMa2wQTFZVEXDRFquSnwk6Ss+UmdM/az0ct EoE7QOikTCqN1q3q/w9aBDP7vWnbkH3wPlm3Etc8zK7r3aXbqtFMV7lqZ17u4Jr9ADtA UjPairvUr3zqVjDQx6scOiYdmC1AmyObtrqLnQu4L8Fm7gthCA41BMjjt2DrUXSQ69tt ISE1k7l9wNW5RIBEcfTf0h0ttrhg2iOaiEyGoyJFi32ujFA0A5ejCuvhVPIJAprkQZcV wBbQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Z+0RPiBw; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-210712-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210712-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f734beafcasi17824395ad.47.2024.06.11.16.53.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 16:53:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-210712-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Z+0RPiBw; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-210712-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210712-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 440E2284BCD for ; Tue, 11 Jun 2024 23:53:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1EA2C15624B; Tue, 11 Jun 2024 23:53:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Z+0RPiBw" Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (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 51776155A5C; Tue, 11 Jun 2024 23:53:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718150030; cv=none; b=klpQrQ6E8yUDVFrcEWNFsaChKeNEuNr7iqL5q2DJc50jmIQpL9LMWOfUY0EhczIgSJFNKOR2isV5pCvr4rHSkYuI86zMX3VQJ/sPjViAwaAgqiiHBvS885v16S3hwc5kKSiwqfd3cst36fIkesXTMn6cmj4zGaD7cCM1K66uNY4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718150030; c=relaxed/simple; bh=ixEi2EihRIVM1JgjBQh9oI5ZNtR8RSnwPtqwjLbu2Ms=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=bwXnP3AIN/p1P14ytwUyGgoMT5uOohBeuDWV6svZUTEpDp4qnKzX9IqA6UXso8YvR9+pP8585QeK+/d48ZuPNFTnpakwP0HXXMYXFrZwnA6t0ZoV75D9lmZYueV8xoKhcmIDjRYJuHecIune1KovD7+Dn+aG71LLE+aLc8HbE/k= 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=Z+0RPiBw; arc=none smtp.client-ip=209.85.210.181 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-f181.google.com with SMTP id d2e1a72fcca58-70423e8e6c9so3218057b3a.0; Tue, 11 Jun 2024 16:53:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718150027; x=1718754827; 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=B2nCf1ZS5hyGT3Pv3PgsvdwOjQ/1NGLvLUu1cRiT+Bc=; b=Z+0RPiBwgOtrZvSjOwHEKT3VkT9FbHv17W3ncZr5aRuBDXgnn6LV7jsUl9sAliCUit NY5bWC+JEzb0Dyb4GUZ9OuP1Eo8Jr77J0hug3ai5AHYoJOmEPv7Y93mWdeuGdTXBF6gT TPqZ8fhm38STHad0tXD/Z4BV8Ub0h5s5sAJ9h8zraNExFixAicX8q/SmF+NzRH5fEWJ9 HsNatBAvMi8fXlp+lAEn1as6h6zIm1uhYTQQ6/fN6ly1yT+dbqcHYAjpf0IcbhNy/0MZ a2OCwO5GkfdCAUs5m3FBpso2SUcM6KWdpmUPGY+fdsgOPK4B6qNvZPaVJnnuYb6D5mLO 166Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718150027; x=1718754827; 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=B2nCf1ZS5hyGT3Pv3PgsvdwOjQ/1NGLvLUu1cRiT+Bc=; b=drCKYA2wp/PGKDscG5v0zqxfMs6JTfqgAtQ7UG+/XAvrkGLm0yPaHjzdvsbJpQe1hq MgsujyFdzydunwi4zE036PneahXf/7v0ydnIXAOJj0kMvMEWVGhai9B3Z2oo/7TyMvn/ XuGYxbDnMttPzPzSPtCvL0ksWDoykBL91uMrEDIBfalj1n9HWVhNPDxi9fptwjvpAAM6 mOShkxTx+eWTJfvatYOzhYi7xCvArqFtwCjuvjJ2j2JELO7Cr/zQl13fHE/wCaC9+Ha/ JOaj/bsVtuSYAl9GXyWc3MRcZ2HQIGm8bf+3EHvZ/vpmWA4elqWWiwB6MikVguO8XOMa td3Q== X-Forwarded-Encrypted: i=1; AJvYcCV6g91eRrMI2GQDzq+7fdYweSXW/+A/QJtnvXTJKL5qHywGG8w+DE66LEyCJMdh92GbiZLJPO8QdHOLTYBk5yNssmTwUVA7Q2Kj01SEEXRDKnRF X-Gm-Message-State: AOJu0YxXfPI6IkJZ2n9VlQ3hBaMTAHvhnWg6cD/umgXQvsCOb5CqUyAq cSVt2o4ozFd/GHywy4H/y3h7p89knG9uroNKaUaGSHeMCXAlW+0x X-Received: by 2002:a05:6a21:2d8b:b0:1b1:fede:59cb with SMTP id adf61e73a8af0-1b8a99d637amr484362637.0.1718150027331; Tue, 11 Jun 2024 16:53:47 -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-704333cbd2asm5327628b3a.172.2024.06.11.16.53.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Jun 2024 16:53:46 -0700 (PDT) Sender: Guenter Roeck Message-ID: <1e74c6d8-ae74-49c2-bdc4-d9880110ab57@roeck-us.net> Date: Tue, 11 Jun 2024 16:53:43 -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 Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, 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> <5178e22b-0c00-48d2-8a6e-85510706f145@roeck-us.net> <20240611185319.58a52a1b@gandalf.local.home> 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 kwu2KgIgmkRBb3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Pjqp0CaztQ0H nsDLSLElVROxCd9m8CAUuHplgmR3seYCOrT4jriMFBtKNPtj2EE4DNV4s7k0Zy+6iRQ8G8ng QjsSqYJx8iAR8JRB7Gm2rQOMv8lSRdjva++GT0VLXtHULdlzg8VjDnFZ3lfz5PWEOeIMk7Rj trjv82EZtrhLuLjHRCaG50OOm0hwPSk1J64R8O3HjSLdertmw7eyAYOo4RuWJguYMg5DRnBk WkRwrSuCn7UG+qVWZeKEsFKFOkynOs3pVbcbq1pxbhk3TRWCGRU5JolI4ohy/7JV1TVbjiDI HP/aVnm6NC8of26P40Pg8EdAhajZnHHjA7FrJXsy3cyIGqvg9os4rNkUWmrCfLLsZDHD8FnU mDW4+i+XlNFUPUYMrIKi9joBhu18ssf5i5Q= In-Reply-To: <20240611185319.58a52a1b@gandalf.local.home> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 6/11/24 15:53, Steven Rostedt wrote: > On Tue, 11 Jun 2024 15:43:59 -0700 > Guenter Roeck wrote: > >> 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. > > Hmm, I could remove it. > >> >>> 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 ? > > If mapped is non zero, it limits what it can do. If it enters here as zero, > we are really in a unknown state, so yeah, wrapping will just keep it > limited. Which is a good thing. > > Do you want me to add a comment there? > Maybe. I just wondered if something like if (!WARN_ON_ONCE(!cpu_buffer->mapped)) cpu_buffer->mapped--; would be better than wrapping because 'mapped' is used as flag elsewhere, but then I can see that it is also manipulated in __rb_inc_dec_mapped(), and that it is checked against UINT_MAX there (and not decremented if it is 0). Maybe explain why sometimes __rb_inc_dec_mapped() is called to increment or decrement ->mapped, and sometimes it id done directly ? I can see that the function also acquires the buffer mutex, which isn't needed at the places where mapped is incremented/decremented directly, but common code would still be nice, and it is odd to see over/underflows handled sometimes but not always. Thanks, Guenter