Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp595532pxu; Thu, 15 Oct 2020 11:27:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLKJPqFgh0xMDjCU4FBZVYOcYP43hVg/80Lmw+QS7UGiW0WOWgLtn+rpF2oqYB4tHZrPuq X-Received: by 2002:a17:906:3bc9:: with SMTP id v9mr5748457ejf.340.1602786436344; Thu, 15 Oct 2020 11:27:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602786436; cv=none; d=google.com; s=arc-20160816; b=syMX3O6nqjrRLQc1JhE6buSTpDZNjktB4v0N+tRkKNBI50KOCbiXc7NvQsL7lZvRWI QQI+r7oh7v1MBLosqsfJQ5uYzs5ASNpZi146fUqtSyz51N7dHiqmZ4A61AKEsijX+XyY paGlFwh/n/WTIYCatzzwAaw82kKRCM3tq9cw3fvGUA33ws07Z0v9OXrr/+qOEYGAD4HO zjvD4maNXpWg6jtHDDihg32JY+G/FqKRopfqzPaoewpog4uie9Q2V9Adc0yhLXhJUb3F KawwTtId1nOBX3rZh9ddTD870YJBg38Xz8/gdExv/gjAx4uJDIMKmQ1S2pCnIQ5a9jHA s+NQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=oEgg+GHnVI81ERsOazeaUpRhipuhfwL3QLYTnBaZSHc=; b=g4mUrudn9HLq32u2H9Yi6VDU1/NfrCLLRV+D6XlY9i5gA0PFI8g82wPc5nLHMUz4eJ kpEEtIqf5W9RuDe4C6MKpmBeao/RAmmbhCjiGprPXZQSgXTM2mAbDGPiXpFz9k+uhWvb R/SqHu/N1yzd6iHi+x5XnSj8LQO7Ntk1PwF8l+D6qxMNxvd+h4o8chKRA9+d6gUMFIIs /kY3tOWpEHW5uVXqA4oMMsZ0eCSh4qtXwZ+BYidJeQhc+jQwADePkYw+6VLqFME91qsN JrNcDQm4u722TcUTYS3ViBujhUSfErjH/HSP/7vLyq3FMEbP7vA6qFZevz03+hcpQXR6 QITw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jXOtdFFw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s26si2620495eds.49.2020.10.15.11.26.49; Thu, 15 Oct 2020 11:27:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jXOtdFFw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729790AbgJOLiv (ORCPT + 99 others); Thu, 15 Oct 2020 07:38:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728596AbgJOLiv (ORCPT ); Thu, 15 Oct 2020 07:38:51 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7C61C061755 for ; Thu, 15 Oct 2020 04:38:50 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id az3so1675150pjb.4 for ; Thu, 15 Oct 2020 04:38:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=oEgg+GHnVI81ERsOazeaUpRhipuhfwL3QLYTnBaZSHc=; b=jXOtdFFwUpA768CjCKDDMA8HIkYgeCyhyz8srEb8G/oQ3qanocKPpPVV9f856M+SRL If0aH1xF5lNVV/vcStmnsaNKU/3jJXVvDLDM4tDmlOI8AG67YNkYHvKmiJlx10JY7icc owncJ0C0G2ZuPPtlKx5a/TDQ1gvgIP3e2FjNcJmbOJ3rRTqBTiRczFGbpnnyzjS9Wtq5 eC8KEVsQDkDJJKQVEQqlrSB6xLl3c7hpemyc7ctRleaP5oan8LZzs1RJwjBtfyFlp1eX W+f9gHkalo7S6+NHtHm4sIsfQyySuaUXerS5XluSU4GFLBhWtrgrVpW9nDbIY/rLPchb MyBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=oEgg+GHnVI81ERsOazeaUpRhipuhfwL3QLYTnBaZSHc=; b=IfUXYgBozC7CkQwNy0OtBTTz6uX19pXJ7fD6KpdkurohZwsc64VSpay8OoIqgeOEM1 2slXY2kUEpuQdwGaGWRj57TFqxIKAOpT+T2IOOGzXgXbfRpUvatZuQlhTqvk2S/Oxspl Xazohe5yGnK5D49kBoKh1o3kPsNl3fRxkY/pei85/9V9yEOEYZdymoMt/zFC5WpHCL+T V5/jnumyyCEwPgxP/A5/ZC3Je9bEcW0Cl96yT9XyeSGLPqCv0VKdy3WsX31TE/302OYW B+jT5OMpaBu5cv6arymqWKr0KpTQdfvaxz+DVIwsp5qR1FCM3H3mH/Jg3qccfORCxNJU 4DDA== X-Gm-Message-State: AOAM533WnB2i6ei2QOKvIGzCOxVKY5VVEHp2HfCswq7y7/NDuwb4DLR1 ATXR5Ym3FQgk3vpPqN2uJOg= X-Received: by 2002:a17:90a:7303:: with SMTP id m3mr4159986pjk.190.1602761930219; Thu, 15 Oct 2020 04:38:50 -0700 (PDT) Received: from localhost ([13.94.42.177]) by smtp.gmail.com with ESMTPSA id cv15sm3212211pjb.20.2020.10.15.04.38.49 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 15 Oct 2020 04:38:49 -0700 (PDT) From: Qiujun Huang To: rostedt@goodmis.org, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: Qiujun Huang Subject: [PATCH v2] ring-buffer: Add rb_check_bpage in __rb_allocate_pages Date: Thu, 15 Oct 2020 19:38:42 +0800 Message-Id: <20201015113842.2921-1-hqjagain@gmail.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It may be better to check each page is aligned by 4 bytes. The 2 least significant bits of the address will be used as flags. Signed-off-by: Qiujun Huang --- v2: remove passing the int cpu to __rb_allocate_pages. --- kernel/trace/ring_buffer.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 93ef0ab6ea20..b2c6f2546d69 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -1420,7 +1420,8 @@ static int rb_check_pages(struct ring_buffer_per_cpu *cpu_buffer) return 0; } -static int __rb_allocate_pages(long nr_pages, struct list_head *pages, int cpu) +static int __rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer, + long nr_pages, struct list_head *pages) { struct buffer_page *bpage, *tmp; bool user_thread = current->mm != NULL; @@ -1460,13 +1461,15 @@ static int __rb_allocate_pages(long nr_pages, struct list_head *pages, int cpu) struct page *page; bpage = kzalloc_node(ALIGN(sizeof(*bpage), cache_line_size()), - mflags, cpu_to_node(cpu)); + mflags, cpu_to_node(cpu_buffer->cpu)); if (!bpage) goto free_pages; + rb_check_bpage(cpu_buffer, bpage); + list_add(&bpage->list, pages); - page = alloc_pages_node(cpu_to_node(cpu), mflags, 0); + page = alloc_pages_node(cpu_to_node(cpu_buffer->cpu), mflags, 0); if (!page) goto free_pages; bpage->page = page_address(page); @@ -1498,7 +1501,7 @@ static int rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer, WARN_ON(!nr_pages); - if (__rb_allocate_pages(nr_pages, &pages, cpu_buffer->cpu)) + if (__rb_allocate_pages(cpu_buffer, nr_pages, &pages)) return -ENOMEM; /* @@ -2007,8 +2010,8 @@ int ring_buffer_resize(struct trace_buffer *buffer, unsigned long size, * allocated without receiving ENOMEM */ INIT_LIST_HEAD(&cpu_buffer->new_pages); - if (__rb_allocate_pages(cpu_buffer->nr_pages_to_update, - &cpu_buffer->new_pages, cpu)) { + if (__rb_allocate_pages(cpu_buffer, cpu_buffer->nr_pages_to_update, + &cpu_buffer->new_pages)) { /* not enough memory for new pages */ err = -ENOMEM; goto out_err; @@ -2073,8 +2076,8 @@ int ring_buffer_resize(struct trace_buffer *buffer, unsigned long size, INIT_LIST_HEAD(&cpu_buffer->new_pages); if (cpu_buffer->nr_pages_to_update > 0 && - __rb_allocate_pages(cpu_buffer->nr_pages_to_update, - &cpu_buffer->new_pages, cpu_id)) { + __rb_allocate_pages(cpu_buffer, cpu_buffer->nr_pages_to_update, + &cpu_buffer->new_pages)) { err = -ENOMEM; goto out_err; } -- 2.17.1