Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp233797lqo; Tue, 7 May 2024 19:34:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW14gqH+gaMdjcijc8bK1BJqF3icBGFVvTru82l2qVQ8PZw7jSgEM6x8O+OcTZXY6nyFwldMkRDwG+yQWtydtq7Mt3/Ek1J/yXZzLJW6g== X-Google-Smtp-Source: AGHT+IEXVjHquEUdDMZVtL99wbDUJmz8Q7CLMBJ1ue6MEvMpvucP+0c8qKSw3J4uHPd/UC7c1Gcp X-Received: by 2002:a05:6218:2604:b0:18e:3ec:94cb with SMTP id e5c5f4694b2df-192d2e42035mr178396755d.14.1715135651407; Tue, 07 May 2024 19:34:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715135651; cv=pass; d=google.com; s=arc-20160816; b=UHUAZZJn4PQ7N8wQ5NUGUJKJagQY06pGLKrtamBVk6a9rPoyF7aUuOOI1UABybl16R 9cxVIbBCMx//IbO8x/xLM+4WWuB62ZJ46TRktf/QXsvUCRUEOx9QnJZgwe+H5bABAqTK vkN9p2D/ChxcaM0NfsYX9XLorWkhTB5S432C9upAtpdu+U72ce2/mk1HXOHUwAY3vNoX 2CJJMJSPWYfA7xbMogxi8Tg4CYRAcTpBygTvN4FdBYBev2qOQ3LKiPuPD6FQwwGqbiEE bOPMFYBHwctjM/IWfixfctlK/9mnOyU3oUzdFXQtp0iqccOAxPoDxvvYzq+Cp+XfTeQs 3EXA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date; bh=0iuBlgr0tCgQeORWxOjmhj/uy7hu26Z6cbXw4AUTKMI=; fh=PUiEWzpcP2cENS86NssQwAZspV2rpgt9HD4h+watWWQ=; b=Icd/YGsQWk55ic7FFDUmjh1HRwQEQ+aS/U6V/pS258z5lwY+tMLc8TTd5z3fkHR5ci mz1D1KmSdd9dHzm1mcH/qQ7xAdyprJPeK7qfuSsQ8uc1KcXND77158UkrCCCfwFVl4I+ VnjUVZHF6WvCP8z1zZKn+lLE9FjKemuVMXvmWlMQOzz04Cy6ETOLsS6W3xPTuxaXu8sr 1lkMquX2DYL5rkvZSc06SoIC7MOvooEoUnx+017SOs+ngAX5PDfOl1ekmjdDlnKWgOdF 6ZmLDeL7lrExzxHifx9jZs5kXNWbikrlSsmVqYe9gYMtu2+NmopeUUeb/6o9N+NfklRh P+jQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-172629-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172629-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 o23-20020a639217000000b0061d6e144a90si9536535pgd.261.2024.05.07.19.34.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 19:34:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-172629-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; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-172629-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172629-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 02A95284CE2 for ; Wed, 8 May 2024 02:34:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A2971385; Wed, 8 May 2024 02:34:05 +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 26A6933F6; Wed, 8 May 2024 02:34:04 +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=1715135645; cv=none; b=GYsyQWc2XASXFHvsgt2cH7fZeZz/lcXn/0D3Yy8ZFH9RYsft9UZv1Dmb8vnhj0opqupgRLWkKsz5DncRW/VBKmKYqqGX77s8nS6FQuOpfBkAvC2Cc1Mrmg1BAdAnUbK4Jwd6xc2rfMj5U+IKR5GZ7bmGE8we29785Xb2GX+LsBI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715135645; c=relaxed/simple; bh=XqLmS+NnYzieGgIHHNfIjpnIZWhpWQO/SKwBKozBE3M=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hHd7yReiz9OlnBCkY/OKERF1dg3Ju4+lGSg6DG5OkNkd4jZruQr6p2omHd7EdeD/xWXkrdplzcnDHfu9AlsVRkbGM1gTsf9UY0FScV7Y+BNDTJvlc9C3DsMZ63gfBFchEllv7ks2XdxgNGKBinZtd6zqOdM3VUVBgXdLHbE56Uw= 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 5434DC2BBFC; Wed, 8 May 2024 02:34:04 +0000 (UTC) Date: Tue, 7 May 2024 22:34:02 -0400 From: Steven Rostedt To: Vincent Donnefort Cc: mhiramat@kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, mathieu.desnoyers@efficios.com, kernel-team@android.com, rdunlap@infradead.org, rppt@kernel.org, david@redhat.com, linux-mm@kvack.org Subject: Re: [PATCH v22 2/5] ring-buffer: Introducing ring-buffer mapping functions Message-ID: <20240507223402.206d6ddc@rorschach.local.home> In-Reply-To: <20240430111354.637356-3-vdonnefort@google.com> References: <20240430111354.637356-1-vdonnefort@google.com> <20240430111354.637356-3-vdonnefort@google.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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=US-ASCII Content-Transfer-Encoding: 7bit On Tue, 30 Apr 2024 12:13:51 +0100 Vincent Donnefort wrote: > +#ifdef CONFIG_MMU > +static int __rb_map_vma(struct ring_buffer_per_cpu *cpu_buffer, > + struct vm_area_struct *vma) > +{ > + unsigned long nr_subbufs, nr_pages, vma_pages, pgoff = vma->vm_pgoff; > + unsigned int subbuf_pages, subbuf_order; > + struct page **pages; > + int p = 0, s = 0; > + int err; > + > + /* Refuse MP_PRIVATE or writable mappings */ > + if (vma->vm_flags & VM_WRITE || vma->vm_flags & VM_EXEC || > + !(vma->vm_flags & VM_MAYSHARE)) > + return -EPERM; > + > + /* > + * Make sure the mapping cannot become writable later. Also tell the VM > + * to not touch these pages (VM_DONTCOPY | VM_DONTEXPAND). Finally, > + * prevent migration, GUP and dump (VM_IO). > + */ > + vm_flags_mod(vma, VM_DONTCOPY | VM_DONTEXPAND | VM_IO, VM_MAYWRITE); Do we really need the VM_IO? When testing this in gdb, I would get: (gdb) p tmap->map->subbuf_size Cannot access memory at address 0x7ffff7fc2008 It appears that you can't ptrace IO memory. When I removed that flag, gdb has no problem reading that memory. I think we should drop that flag. Can you send a v23 with that removed, Shuah's update, and also the change below: > + > + lockdep_assert_held(&cpu_buffer->mapping_lock); > + > + subbuf_order = cpu_buffer->buffer->subbuf_order; > + subbuf_pages = 1 << subbuf_order; > + > + nr_subbufs = cpu_buffer->nr_pages + 1; /* + reader-subbuf */ > + nr_pages = ((nr_subbufs) << subbuf_order) - pgoff + 1; /* + meta-page */ > + > + vma_pages = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT; > + if (!vma_pages || vma_pages > nr_pages) > + return -EINVAL; > + > + nr_pages = vma_pages; > + > + pages = kcalloc(nr_pages, sizeof(*pages), GFP_KERNEL); > + if (!pages) > + return -ENOMEM; > + > + if (!pgoff) { > + pages[p++] = virt_to_page(cpu_buffer->meta_page); > + > + /* > + * TODO: Align sub-buffers on their size, once > + * vm_insert_pages() supports the zero-page. > + */ > + } else { > + /* Skip the meta-page */ > + pgoff--; > + > + if (pgoff % subbuf_pages) { > + err = -EINVAL; > + goto out; > + } > + > + s += pgoff / subbuf_pages; > + } > + > + while (s < nr_subbufs && p < nr_pages) { > + struct page *page = virt_to_page(cpu_buffer->subbuf_ids[s]); > + int off = 0; > + > + for (; off < (1 << (subbuf_order)); off++, page++) { > + if (p >= nr_pages) > + break; > + > + pages[p++] = page; > + } > + s++; > + } The above can be made to: while (p < nr_pages) { struct page *page; int off = 0; if (WARN_ON_ONCE(s >= nr_subbufs)) break; page = virt_to_page(cpu_buffer->subbuf_ids[s]); for (; off < (1 << (subbuf_order)); off++, page++) { if (p >= nr_pages) break; pages[p++] = page; } s++; } Thanks. -- Steve > + > + err = vm_insert_pages(vma, vma->vm_start, pages, &nr_pages); > + > +out: > + kfree(pages); > + > + return err; > +} > +#else > +static int __rb_map_vma(struct ring_buffer_per_cpu *cpu_buffer, > + struct vm_area_struct *vma) > +{ > + return -EOPNOTSUPP; > +} > +#endif