Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2231707ybi; Thu, 20 Jun 2019 11:16:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqwIPkD5IJcpjTsqRyDLEBcXLIQBuKp92653cve/gT8AV839qVEAVbw9Mmq8z6oV6eu9sXu1 X-Received: by 2002:a63:fe51:: with SMTP id x17mr14686032pgj.61.1561054604454; Thu, 20 Jun 2019 11:16:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561054604; cv=none; d=google.com; s=arc-20160816; b=W0UoaSNSjax8+AZQ/BFjvk/11/uwcFCrQFSxLgLwnC61XIDph2wH+hvl5z5P3u5UXv fEPWHk8gSA2V5J04RGDM/Eib0XuNdn+YPIGYy2cIHE6ApM48cTI4Jte1ArHaHJvKj6PD d5/Ifrr4uvxZoqg2Fdd6dIGVXtw+BtZ06Qws12oJj+pQAflJuajBbwqMdqNyfT6j5kji D7UNpZKFIIxQ3ub1QhrFsKGoRCXG7EzzGB6uGIq5PpL3Iok4NpakUhf9A8xFFGDxK7dg fy+dRPUfvrai8t6RKQdiL8ZTuAWcLPX2k7TuN4r3K/q2u2oP7lApnv/32YX2wp8h1LbB AJeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GOBiwrwywTaLYTwsENxpefAPH7GEnyWi2YUWU3Qawts=; b=DtlaGErzm3nPXXUFm96YE2MrDuZLltnwqKmcyXEFjXFlSC0GZzSbkC2cBBW3htYbnX ATsSDsvBGlisAryaFvf0Vfni4nDoF4mB5h/sx2rlNFzSOc79QuhCY2S3v1+icLmLXkP/ TuCe9g+0vW9sc34kh8J1WGd/WMP/aI/kal5jwxi4fo0nOuxZMpIyA4g2aC80j/V16qxs OZNGkyUEbm+JoOoAE04ZA4xdnCbPry8LGjaZeOJzHFuxz48Ng7pSW4E/ssEwTT0Vy5cO Su+qj88RNkPDX0bX975bISRmEG87t7M9IqLcSMNGEiZvWCga1ZReoa4h7Iui9p2qP9DF 5nBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="QIbK1j/O"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j23si140082pfh.215.2019.06.20.11.16.29; Thu, 20 Jun 2019 11:16:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="QIbK1j/O"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729555AbfFTSQZ (ORCPT + 99 others); Thu, 20 Jun 2019 14:16:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:45526 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729766AbfFTSQX (ORCPT ); Thu, 20 Jun 2019 14:16:23 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AC33121537; Thu, 20 Jun 2019 18:16:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561054582; bh=cdbMbd2xPMxy28IF8dLqeKRuQYbE9LCL365zB0QDSCA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QIbK1j/O1qD+CTAjni3VFBg1iNRVNtPWUwExdaykqgioLYko7ynuFFtmovKbJdqxv EaC962AkkNNRgFdhzVlcnEtWERhFXw/sGy3NZzQhRWA7znelhNQelfEw0LSkfaw9JC MhEkXemAaBObgNco9+kZuPVgJwavzvJpWKCDVn58= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yabin Cui , "Peter Zijlstra (Intel)" , Alexander Shishkin , Arnaldo Carvalho de Melo , Jiri Olsa , Linus Torvalds , Stephane Eranian , Thomas Gleixner , Vince Weaver , acme@kernel.org, mark.rutland@arm.com, namhyung@kernel.org, Ingo Molnar , Sasha Levin Subject: [PATCH 5.1 50/98] perf/ring-buffer: Always use {READ,WRITE}_ONCE() for rb->user_page data Date: Thu, 20 Jun 2019 19:57:17 +0200 Message-Id: <20190620174351.533977697@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190620174349.443386789@linuxfoundation.org> References: <20190620174349.443386789@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 4d839dd9e4356bbacf3eb0ab13a549b83b008c21 ] We must use {READ,WRITE}_ONCE() on rb->user_page data such that concurrent usage will see whole values. A few key sites were missing this. Suggested-by: Yabin Cui Signed-off-by: Peter Zijlstra (Intel) Cc: Alexander Shishkin Cc: Arnaldo Carvalho de Melo Cc: Jiri Olsa Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Stephane Eranian Cc: Thomas Gleixner Cc: Vince Weaver Cc: acme@kernel.org Cc: mark.rutland@arm.com Cc: namhyung@kernel.org Fixes: 7b732a750477 ("perf_counter: new output ABI - part 1") Link: http://lkml.kernel.org/r/20190517115418.394192145@infradead.org Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- kernel/events/ring_buffer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c index 4b5f8d932400..7a0c73e4b3eb 100644 --- a/kernel/events/ring_buffer.c +++ b/kernel/events/ring_buffer.c @@ -100,7 +100,7 @@ static void perf_output_put_handle(struct perf_output_handle *handle) * See perf_output_begin(). */ smp_wmb(); /* B, matches C */ - rb->user_page->data_head = head; + WRITE_ONCE(rb->user_page->data_head, head); /* * We must publish the head before decrementing the nest count, @@ -496,7 +496,7 @@ void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size) perf_event_aux_event(handle->event, aux_head, size, handle->aux_flags); - rb->user_page->aux_head = rb->aux_head; + WRITE_ONCE(rb->user_page->aux_head, rb->aux_head); if (rb_need_aux_wakeup(rb)) wakeup = true; @@ -528,7 +528,7 @@ int perf_aux_output_skip(struct perf_output_handle *handle, unsigned long size) rb->aux_head += size; - rb->user_page->aux_head = rb->aux_head; + WRITE_ONCE(rb->user_page->aux_head, rb->aux_head); if (rb_need_aux_wakeup(rb)) { perf_output_wakeup(handle); handle->wakeup = rb->aux_wakeup + rb->aux_watermark; -- 2.20.1