From patchwork Sun Jul 4 07:16:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12357223 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72CD9C07E95 for ; Sun, 4 Jul 2021 07:20:06 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2CDB561936 for ; Sun, 4 Jul 2021 07:20:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2CDB561936 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Umq2exi3lbU77HMZf7Gh9xA6qWF7amTbsrGZKsJjwGQ=; b=j21CCOSAAhEBmC j4TSiUfqSqXeyfo6+iiOqpWo7AxVrryK2DVsyGEhUVZiXR7kTStjWDobF4MU2Ti+UWMV62yYJKJ5V MM+h/HLMIlW1BMeGTIK5FZXR7VMs3Wxahid4n0+YWvgGlpzj5o9mTnnA/hxVfibIz7/GBZ3M7GZyY 0jfD+RhD9WhRIbWp2PI0v+j1T3ISzk8Bj8HRFuTR0VifcCB3pWVdnnstlol33ENPe6sNCJSlhgwlD IyDqVsqAgWycWvz25xUOuaSdqTkN1npJrbOuCm95EVRo/lDv5z4gXqyvmZOBdLbxV/0QtotffvyLo 2qbNzuxXpzZYq/lWaCgg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lzwNX-005rOX-VT; Sun, 04 Jul 2021 07:17:24 +0000 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lzwNK-005rJz-9W for linux-arm-kernel@lists.infradead.org; Sun, 04 Jul 2021 07:17:12 +0000 Received: by mail-pg1-x536.google.com with SMTP id m26so14909890pgb.8 for ; Sun, 04 Jul 2021 00:17:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mUfdU9WBYmi8/NBmndyLWLFFhQ6mqBUwjCh/GuP5qb8=; b=HF78Ns2KJ94lBFHkqHHYvCYHD4XrlhN8LrnvJOs4SzJEbXQLwLgpWDt0zU6kv9thCu gdLazU3mmrvpTorsHnLibdESJswhC7Ied5jYBfhzPiW58xbfw5eAPfe1mVMpniRzfofV +J+ihmTl+sjPqr720iwqV6ZqP6s0SpNdLr3sGr1iz5fVo1rh3ib+OWocNyxehHC6ZL8t oquO+TcF2/bdRIX+rLF/ytpAptqJ7/eBCGJxFrTa0XwsX4tLt95P1Xd2bg1/jOn2osH2 tSVXGkxAjKtOsk2uUj3BWHJt5y4nI42fVH36oP0b7Pnyt8+b+M5gqyaWIBA3vLVmE+30 aHmg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=mUfdU9WBYmi8/NBmndyLWLFFhQ6mqBUwjCh/GuP5qb8=; b=S4zkDjCjOCm8DD65BF6UN6zGRSLi1ZWJqf1Szgn4l06AjdCdRnutARXI0mXl9vOqhT 1pHkKifGlYRKSJf7/FomoGnkY9ajY2KnFF+hiWGhfjID/ECrQoqf+6FDuDpo7rroLgMe q2aeOL7rQIDGx0T78KstpLgYCLUY7OfXuZEYUcCjapRPXBtXLF3IAnjDUOsBoPkOmIs2 zvXBDuW49b6vCj1MYyAJ3hmYUkqLate6j/oMGbajChdhDJXT0K/jb3WMLkhwE2LHvyOI 37U0W6RB4m7ob/C9YX0mfDxDRE7TSr3TLqSBsBfeBVOI4ScYpQ5F2vxi9ZjkqGf+IeTu 4YJA== X-Gm-Message-State: AOAM531Y7MlZUZZcuhzvDygo61d5etEylNE4E3K0EQsyUo+zaKKoCkT4 1YGcD+6aGZWGnZ60WJiphxIUZQ== X-Google-Smtp-Source: ABdhPJxikogZ+NeiWmhynh68p62mZPKUnJOdPzdcYP2HqwkcqPAR8k719kBsv+JqyjlFHGxFOLDWGA== X-Received: by 2002:a63:f515:: with SMTP id w21mr9167878pgh.343.1625383029524; Sun, 04 Jul 2021 00:17:09 -0700 (PDT) Received: from localhost ([103.207.71.35]) by smtp.gmail.com with ESMTPSA id d2sm9657731pgh.59.2021.07.04.00.17.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Jul 2021 00:17:09 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Adrian Hunter , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Mathieu Poirier , Suzuki K Poulose , Mike Leach , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v3 01/10] perf/ring_buffer: Add comment for barriers on AUX ring buffer Date: Sun, 4 Jul 2021 15:16:35 +0800 Message-Id: <20210704071644.107397-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210704071644.107397-1-leo.yan@linaro.org> References: <20210704071644.107397-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210704_001710_378705_E048ED4F X-CRM114-Status: GOOD ( 15.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org AUX ring buffer applies almost the same barriers as perf ring buffer, but there has an exception for ordering between writing the AUX trace data and updating user_page::aux_head. This patch adds comment for how to use the barriers on AUX ring buffer, and gives comment to ask the drivers to flush the trace data into AUX ring buffer prior to updating user_page::aux_head. Signed-off-by: Leo Yan Acked-by: Peter Zijlstra (Intel) --- kernel/events/ring_buffer.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c index 52868716ec35..5cf6579be05e 100644 --- a/kernel/events/ring_buffer.c +++ b/kernel/events/ring_buffer.c @@ -509,6 +509,15 @@ 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); + /* + * See perf_output_put_handle(), AUX ring buffer applies the same + * barrier pairing as the perf ring buffer; except for B, since + * AUX ring buffer is written by hardware trace, we cannot simply + * use the generic memory barrier (like smp_wmb()) prior to update + * user_page::aux_head, the hardware trace driver takes the + * responsibility to ensure the trace data has been flushed into + * the AUX buffer before calling perf_aux_output_end(). + */ WRITE_ONCE(rb->user_page->aux_head, rb->aux_head); if (rb_need_aux_wakeup(rb)) wakeup = true; From patchwork Sun Jul 4 07:16:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12357227 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65B03C07E95 for ; Sun, 4 Jul 2021 07:20:25 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3846461879 for ; Sun, 4 Jul 2021 07:20:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3846461879 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=LBGHnhE+zRJI1qPjd2jcqywIU2jUE5MQeyFi9Wr7E+c=; b=NBanjjI8PVytZ8 XIMKdXB1eoBE8nzOe2NmSGujcjWxpiwDJZIJ7DGLP00acBqKRRDoqpHiuddtzjGFb1L7zOy62CBhk tuBBpm6C35RHDq/SkRRR9zb0jC6ELh5r3z8MoDerOJ6lCgKnyWhNS5V1qjMyxUyHIAN8xTHjEzaoR Oq2vZseoXJYfUdfkD0hxXMM0x54kguueAMAPBTzovhL5INq4XFAB8nzMqomC3qccco7WtJOaIsOBn /rv/U5DVejKruLdI1ccUTnJn1EEHYiAjKnzTuJwppwBrofHUqM5/2mamgK+PBuZjBY9qMuikc8ojB hUZH/6GzjdM8fNvNtksg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lzwNi-005rSU-N5; Sun, 04 Jul 2021 07:17:34 +0000 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lzwNN-005rLY-Uk for linux-arm-kernel@lists.infradead.org; Sun, 04 Jul 2021 07:17:15 +0000 Received: by mail-pj1-x1033.google.com with SMTP id x21-20020a17090aa395b029016e25313bfcso9403660pjp.2 for ; Sun, 04 Jul 2021 00:17:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tvAJvuDnRJDe9YMY5R2L+q2C0nSKQeIr4jFz4M7hp0E=; b=TZxJVJis8rrNqPFI2hPub+IQfdfSZOkJvS/N4Qc2wxUB09wr1MfwYw1dKN+vYgsgxl +Mw6TONqRDqKeND/1XROo+0oJBqtXUbdgINfQoBXo4dBxDewpTNZdUI9j/6aKcpmSgM3 iHoBfBgzdrgEKW1w9eEw/yo9n68nOGSRzFaBYfz8+xj/UsFgdQdIuyIyhKsFcFBvK5SS hZGglCMveOrpWRvzb2l4gaI6UDMU6bnGi4zzkAtZoFuJzYDoxDBKV9iIQIPDWg7q21uf 79funWYO59ZfD/q9HuDmV5JenmxPZK414wjMSav5wpCdUR0h+ZPJ/O0vA1pfYA7sRXcx +chw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=tvAJvuDnRJDe9YMY5R2L+q2C0nSKQeIr4jFz4M7hp0E=; b=Fvyszfbl78ki/v9cmFMZXrI+j9MsUUX+VwiBPZMoaHnOpyR6FNzrAHClWTCme5PO7z /JkBrmKTuv/RYpFzTFko9zXjCLUUqj+rB3hEd8Di4SA9AvemAoT1Er2vMK55A8gtO56y YwRnpU0iJVNgSUtL3K0+b3A+EWNSb6CiHfRaL6WwVjF+BsjemHDx/HFpP6lH9dJRpOBm 8nqx/wEtou/iysG/IMG2SHwcw5RR4+nOSo5h/Zc3kZUGDlOTcHAzxXGouyMel5AmDAIF 3MisGIyWx7/us0tvzRhFKr6R727pGs1WnyU0Fbn50jeZZwq4KykhF4ebli0nTgCVI5T7 4GSQ== X-Gm-Message-State: AOAM530pt2ArQ6jpANS0yLSnlmU0b/YrqATj7EZnfD6rLoa7kKEU4cQ+ xe2/5JHuFticzpv0m0avYRSqiA== X-Google-Smtp-Source: ABdhPJziL8cAnRjboZ1UlxOOR0Cvu9NdT7Stl0UJiINuPwjmGxQlpm2Sj8AWQP4DU4sVlQP2iThQ2A== X-Received: by 2002:a17:90a:5903:: with SMTP id k3mr8545239pji.104.1625383032314; Sun, 04 Jul 2021 00:17:12 -0700 (PDT) Received: from localhost ([103.207.71.35]) by smtp.gmail.com with ESMTPSA id i18sm553232pgb.83.2021.07.04.00.17.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Jul 2021 00:17:11 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Adrian Hunter , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Mathieu Poirier , Suzuki K Poulose , Mike Leach , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v3 02/10] coresight: tmc-etr: Add barrier after updating AUX ring buffer Date: Sun, 4 Jul 2021 15:16:36 +0800 Message-Id: <20210704071644.107397-3-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210704071644.107397-1-leo.yan@linaro.org> References: <20210704071644.107397-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210704_001714_042116_98CF2BE1 X-CRM114-Status: GOOD ( 13.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Since a memory barrier is required between AUX trace data store and aux_head store, and the AUX trace data is filled with memcpy(), it's sufficient to use smp_wmb() so can ensure the trace data is visible prior to updating aux_head. Signed-off-by: Leo Yan --- drivers/hwtracing/coresight/coresight-tmc-etr.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index acdb59e0e661..713205db15a1 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -1563,6 +1563,14 @@ tmc_update_etr_buffer(struct coresight_device *csdev, */ if (etr_perf->snapshot) handle->head += size; + + /* + * It requires the ordering between the AUX trace data and aux_head + * store, below smp_wmb() ensures the AUX trace data is visible prior + * to updating aux_head. + */ + smp_wmb(); + out: /* * Don't set the TRUNCATED flag in snapshot mode because 1) the From patchwork Sun Jul 4 07:16:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12357229 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5FF2FC07E96 for ; Sun, 4 Jul 2021 07:20:27 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 316956192E for ; Sun, 4 Jul 2021 07:20:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 316956192E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=VTIDxAXKVOF15iKPwM7JwRWuhlgvoW+b79dVI1gb3p8=; b=v4aZR8ukVWcmVn xbU8z6Iwbti9Xl8prmwZ5FkXBGtiQF5FxQXV5pRH4yZY9NaJL2iI4F6S6cG+PRSID26k4rAj1t5EZ 9btaGvoMO9dcyn1MqhhrBGcArE5vIBhhExS5TscoX3AMu9Ii4ffwxe4un4qTJn5vx3b369vnHiOUZ kYmIL399SI5yG4gLeubE+na5tAIrW31E79ksmhaO1Tp0joZRtjpU6h4JUoKhdsiu+XH69Ug4GyKyM doTl5HpwSaaasbywU46PrrD9jE9+qB4gv301auQAmWw0KG7C3+xrTrdV/kaM4Fvzpbk7fj22lE19O t10OBI8lCzNSID0WdLvw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lzwNv-005rX8-4y; Sun, 04 Jul 2021 07:17:47 +0000 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lzwNQ-005rMj-3T for linux-arm-kernel@lists.infradead.org; Sun, 04 Jul 2021 07:17:17 +0000 Received: by mail-pg1-x533.google.com with SMTP id u14so14889679pga.11 for ; Sun, 04 Jul 2021 00:17:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MxgwZHP/NxGkiYvHiVeQZZDAd7piMTreovHUTu3tJE4=; b=F1Cm5HUe/W4qcO/YZMWcovyfhoTTd7gdBbhgFkxstFf0BT+ShATGv4q4OrsnJaIrpy G4hBHinkVsHh9Cfi4t7lXKwp5Oxp9ulth8gE3AIWRBetNA5chQJnCJiQvuemKUVHuRbe n0wOB5of97stC16+0L9Omkrn0PANT9WTrxCCu0YAkC2y8zgYlpDzcjMJCdW8dgPW9exy jJFzAoQSAkB35DvhbQtr8+GytWS5knvOXGvmCHZMucdYoV2PvCimYoGHVZxDSmDOZndZ LSQX4DwreOLmKwZYR3Nnikg/vk+UqtTmzHo34jmqqdyoIqKfxd2J+rzWJEchXwCUteoI NSnQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=MxgwZHP/NxGkiYvHiVeQZZDAd7piMTreovHUTu3tJE4=; b=a6HVnfc7RXCXo4oFLzzTVMLQTZbkLXzC/9zdhvzdeflMQCwq93LpLWJgv7UPtvFUEJ SXtEnxTVYFeepegTOQlHxhtlatqJxCzAFAjRveU0o6ot+D04pk42FZxIdrnUPEn+vwLX 0rx776cmhU5i/R+NsQ1eaE0QGMyDdQMmvvzwOd9ahq9C9R9WbJ6avrwkfwzFRwdN1ar4 1EcIyXWqsdIm+xyTNxq06sl6aYKmOJo9H/5kuri65G1ia1drE8hID5kPexCm6enVMfIM zQP/dhDmnvQnTMIr/JnzSiQeoFDlSarBqumMTQ1ULLP4pfRahwbBu7/n/Md9apHCzDPK AZ1Q== X-Gm-Message-State: AOAM531MDF4ilC+imJhRy3gk6UNhFzVxsn8Q+B0n5xaRkvfbrwVqCGOf CdTRL0WkWxF88L0tgnHxq5kk2A== X-Google-Smtp-Source: ABdhPJxEg+L08YtRvHwbnJK9hTdwmsSSxA7M6/KGLxIa5RV8pIXUL0HVBWpIwu5ahxkZusKImzIv+Q== X-Received: by 2002:a65:62d8:: with SMTP id m24mr9309521pgv.150.1625383035208; Sun, 04 Jul 2021 00:17:15 -0700 (PDT) Received: from localhost ([103.207.71.35]) by smtp.gmail.com with ESMTPSA id la17sm6983974pjb.34.2021.07.04.00.17.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Jul 2021 00:17:14 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Adrian Hunter , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Mathieu Poirier , Suzuki K Poulose , Mike Leach , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v3 03/10] coresight: tmc-etf: Add comment for store ordering Date: Sun, 4 Jul 2021 15:16:37 +0800 Message-Id: <20210704071644.107397-4-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210704071644.107397-1-leo.yan@linaro.org> References: <20210704071644.107397-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210704_001716_222085_9AA85D17 X-CRM114-Status: GOOD ( 14.01 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org AUX ring buffer is required to separate the data store and aux_head store, since the function CS_LOCK() has contained memory barrier mb(), mb() is a more conservative barrier than smp_wmb() on Arm32/Arm64, thus it's needless to add any explicit barrier anymore. Add comment to make clear for the barrier usage for ETF. Signed-off-by: Leo Yan --- drivers/hwtracing/coresight/coresight-tmc-etf.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/hwtracing/coresight/coresight-tmc-etf.c b/drivers/hwtracing/coresight/coresight-tmc-etf.c index 45b85edfc690..9a42ee689921 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etf.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etf.c @@ -553,6 +553,12 @@ static unsigned long tmc_update_etf_buffer(struct coresight_device *csdev, if (buf->snapshot) handle->head += to_read; + /* + * AUX ring buffer requires to use memory barrier to separate the trace + * data store and aux_head store, because CS_LOCK() contains mb() which + * gives more heavy barrier than smp_wmb(), it's not necessary to + * explicitly invoke any barrier. + */ CS_LOCK(drvdata->base); out: spin_unlock_irqrestore(&drvdata->spinlock, flags); From patchwork Sun Jul 4 07:16:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12357231 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18188C07E95 for ; Sun, 4 Jul 2021 07:20:44 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D450D6192E for ; Sun, 4 Jul 2021 07:20:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D450D6192E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=fDxD3wdzpM0hp2cxqHu4CtfvR2D32UTPe7gtfPEVSYE=; b=JAJuxxvhGWz+cF sHTWQ4V/5t+NidVd6C4sRpEwdLlHVZQbwkW7Pux4SBhoAbAPILfA+5QiI0TNneFwoqgoeIXLPRe5c xzdp/Bzmm5GMI+pG2+GqyYVgA+3y42kVnGEHJ4DRZ0uwu1jmFdj0ttN9Jh5x/uYKtsgX4J7O4ZPqD 4KHj7DoHsBnJOdzV5webHtA3sa13dNSkR1oHYZDKmIObc5dX4vqrdeFNxkds4V8IOP4nO1Nngozp6 BibVYk/2XGrch4KuZ33YyYpstl+MY6adRZSTr4MZCWznQarOa8P2I7vfD7iu/8NzwYnbKkALMrmwh ++kdasDXCBJKZGdrP9xw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lzwO5-005rYg-Ha; Sun, 04 Jul 2021 07:17:57 +0000 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lzwNV-005rNb-AZ for linux-arm-kernel@lists.infradead.org; Sun, 04 Jul 2021 07:17:22 +0000 Received: by mail-pj1-x1030.google.com with SMTP id l11so9488588pji.5 for ; Sun, 04 Jul 2021 00:17:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Q5Wf8ghZ23c6vSvSmNVjb2NVOeSumBPmpt+tM4X+4G0=; b=sPPIAp6bykeHv8kNEiNQSCH3ZxxoXifu1yRZOpcwWPNEr0fyMcMBODJMeCbSdX3rQR wjMbs3m5gsKDPv5lyx/QgE5e2gxb+9Dzh2piLOFCcTLAPDOMc6lo3y1SidC97ncjri4o 39iHTnXCslYQiJVFWKaSbc0leC98lBqCqkszir2CJHxzKPpOCX7EAm3Xo99jF5HyZGBZ 95CLan0JYfl6yZNUYfl8UaQgFQxYilZgLOZNB4SjbzRYJ5Nt5jcJiXgb1jZLKZDRsk80 iatwVhlW8M9/y6n7k8g5bLXC+MUMOGRCNBcy+fsRX4q+lU/H4Zb9fWXiW5tIloDKZd2U Pi6Q== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=Q5Wf8ghZ23c6vSvSmNVjb2NVOeSumBPmpt+tM4X+4G0=; b=P6bM5IADPIk/SvLxDTEIfugtVvEjcLOW8JEyyxS9y4xs1unCLfNieC7Nic1dvWUa8+ OdhB5y6tYnQqKw8v28tb9A82GaA+e06hOh7b2QFLse6owCbxaL/u1RZbYfrMSygwPLxb Beo61zQXFkskEh2TcVsSym5VXg1ETae67F44Ly4w46F1m8vaG1SoProKFKiw4UmifNQd FYcFJKdKt2j4AEkhhNXjaTgOUoMUcAyc3N/2sk1XW6RAcBqV7GbGN5zzY7kQQpZbNG4r pn7W6JH/GSUKrAr5JirHsozQLvi9oYa64DXN4PmfWcVQQjfps5LcmSL+odjrtdLrtV/q wzFQ== X-Gm-Message-State: AOAM5304tJ8Pubjh0a+/hzkTdLv4mFoS1DzGa1u5QTCsN5S9nLxMzDWC LCSN/+3dm2Uogmge0TUvRxrrDw== X-Google-Smtp-Source: ABdhPJzUFCWdKrT5LqvA16eca5FTWrFAEQFxu73CU4ERAiEVgUNZaIdSuqJv3g3yMzx1OBcIywsEvg== X-Received: by 2002:a17:90b:1284:: with SMTP id fw4mr8381195pjb.74.1625383038146; Sun, 04 Jul 2021 00:17:18 -0700 (PDT) Received: from localhost ([103.207.71.35]) by smtp.gmail.com with ESMTPSA id z7sm8588734pfn.36.2021.07.04.00.17.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Jul 2021 00:17:17 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Adrian Hunter , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Mathieu Poirier , Suzuki K Poulose , Mike Leach , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v3 04/10] perf/x86: Add barrier after updating bts Date: Sun, 4 Jul 2021 15:16:38 +0800 Message-Id: <20210704071644.107397-5-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210704071644.107397-1-leo.yan@linaro.org> References: <20210704071644.107397-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210704_001721_393208_F94638FF X-CRM114-Status: GOOD ( 12.74 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add barrier wmb() to separate the AUX data store and aux_head store. Signed-off-by: Leo Yan --- arch/x86/events/intel/bts.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/events/intel/bts.c b/arch/x86/events/intel/bts.c index 6320d2cfd9d3..4a015d160bc5 100644 --- a/arch/x86/events/intel/bts.c +++ b/arch/x86/events/intel/bts.c @@ -209,6 +209,9 @@ static void bts_update(struct bts_ctx *bts) } else { local_set(&buf->data_size, head); } + + /* The WMB separates data store and aux_head store matches. */ + wmb(); } static int From patchwork Sun Jul 4 07:16:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12357235 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2F5EC07E95 for ; Sun, 4 Jul 2021 07:21:00 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 73FEF6192E for ; Sun, 4 Jul 2021 07:21:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 73FEF6192E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=BCyKgbvw/MiKk1uR+HzNoSk77GYZAlQMEhVgOx+fzMk=; b=RVJXMJxMpCGj4U psZh70V2szOA2BY18z/eTSKo3yqOphQgispcsEi2Ta1+p2Iaqy6PXsZrKKPzGHRGKhEq+Zx4P303f C70eD9Mpc0YoIijzjQUXYtFkmu4yARpNEe6qhgakFXPPxelsdDZ6I8JZZQPbopfOtAPwR6YQgwZaq 0UYbU2TTulmGGkSonDlvNpkG+Ohu0/rArnSjcbWzM3L2ozDsCdqgBSwqf2+cF4XEXBG1ngkyMepdS 9TlY+Q67tD+S3o7z8QV/XfXvBLRRh1uyNYEq1D4vhWSLpnpQp50IlHpMqbezLzCElhRvcuEeJsz6A eicVKTI3wIDzDsh9fAmQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lzwOH-005rbM-Ac; Sun, 04 Jul 2021 07:18:09 +0000 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lzwNX-005rOR-7h for linux-arm-kernel@lists.infradead.org; Sun, 04 Jul 2021 07:17:26 +0000 Received: by mail-pf1-x430.google.com with SMTP id j199so13102057pfd.7 for ; Sun, 04 Jul 2021 00:17:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WFlg3CrTgiWrG/82i995qBaU4/AO+LdpNtCrOYN1iqs=; b=QVgopcqfesqC5fY1wcmSf5gnpsauKXSHgKNJZceLPwM1aXq7HJiQqYvyDSoMhLMLeE wxkxqKMR5V+x8xP6vRCukKWI2wGeYOnw6b00FKJ9Y/6IYG/digiEsV7zPgMa12mlmlcC 8dch0uuVbojMIaTa0+ydQ15ROgkvOdhcmjayGRwznQaGvKOgvYqZWeuksjGLuRWyK+43 jFKSRVQEn17tGhfRo8vFcPYuHECVlzd8xQ5tnF5/W9CHF/gcMTjtv3uel+UYDq/Omz7Y +xWAKfuMfu6D+Bi7lsusb0RTndv7hzCBwtMSqE6UQtfDlgodkMf9XWWQLmtWTqlwgkIQ davg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=WFlg3CrTgiWrG/82i995qBaU4/AO+LdpNtCrOYN1iqs=; b=H3ugjVArGKC7p+zrKMda6NaVQOJOhlGBn3r8Tk/Gh1j76KYtUa0APWvKThygGgBUbI cjMshbDRtrr9P67rBipVCexYYbNbFSUQkET4/RC2raSUJrLgrPXh7PxU3BvKCmue7ql6 SBBklB+uJObga5jegCndu+xg4Rm16D03yUZUKCNcX/fz5fyEMXDMOlAa1b+VOOWUDyol bMmE0mbXU3R0/XIHkOkkJvzdreWnSQybb6VRA07PvrTEywIGrAufd8kuJ4TSeXXFM2Ft r8+2u8rXc3NfBXgSUq5BU2DhqCCnAnp8891M4i2Tie3LgrL5uijnpjL1z4DrMbSdtFHX sSCg== X-Gm-Message-State: AOAM5310sfOCiHyIzeSJfipAkR2UNQjdTsztLtUS8KgnY1vIb90Jpt3s as8TK7wZRaVQDckwYm2q9ddDZA== X-Google-Smtp-Source: ABdhPJw4Ra53dPv9PE6oo6mR5bJRHgZPZzLtHOc/9HREWmLKUbBaYPlBu4O7ENkyOoZeSjr3VWB4iQ== X-Received: by 2002:a63:5513:: with SMTP id j19mr9083313pgb.192.1625383042400; Sun, 04 Jul 2021 00:17:22 -0700 (PDT) Received: from localhost ([103.207.71.35]) by smtp.gmail.com with ESMTPSA id z3sm9823033pgl.77.2021.07.04.00.17.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Jul 2021 00:17:21 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Adrian Hunter , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Mathieu Poirier , Suzuki K Poulose , Mike Leach , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v3 05/10] perf auxtrace: Drop legacy __sync functions Date: Sun, 4 Jul 2021 15:16:39 +0800 Message-Id: <20210704071644.107397-6-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210704071644.107397-1-leo.yan@linaro.org> References: <20210704071644.107397-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210704_001723_359713_3B89F666 X-CRM114-Status: GOOD ( 18.64 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The main purpose for using __sync built-in functions is to support compat mode for 32-bit perf with 64-bit kernel. But using these built-in functions might cause couple potential issues. Firstly, __sync functions originally support Intel Itanium processoer [1] but it cannot promise to support all 32-bit archs. Now these functions have become the legacy functions. As Peter also pointed out the logic issue in the function auxtrace_mmap__write_tail(), it does a cmpxchg with 0 values to load old_tail, and then executes a further cmpxchg with old_tail to write the new tail. If consider the aux_tail might be assigned to '0' in the middle of loops, this can introduce mess for AUX buffer if the kernel fetches the temporary value '0'. Considering __sync functions cannot really fix the 64-bit value atomicity on 32-bit archs, thus this patch drops __sync functions. Credits to Peter for detailed analysis. [1] https://gcc.gnu.org/onlinedocs/gcc/_005f_005fsync-Builtins.html#g_t_005f_005fsync-Builtins Suggested-by: Peter Zijlstra Signed-off-by: Leo Yan --- tools/perf/util/auxtrace.h | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h index cc1c1b9cec9c..f489ca159997 100644 --- a/tools/perf/util/auxtrace.h +++ b/tools/perf/util/auxtrace.h @@ -440,12 +440,6 @@ struct auxtrace_cache; #ifdef HAVE_AUXTRACE_SUPPORT -/* - * In snapshot mode the mmapped page is read-only which makes using - * __sync_val_compare_and_swap() problematic. However, snapshot mode expects - * the buffer is not updated while the snapshot is made (e.g. Intel PT disables - * the event) so there is not a race anyway. - */ static inline u64 auxtrace_mmap__read_snapshot_head(struct auxtrace_mmap *mm) { struct perf_event_mmap_page *pc = mm->userpg; @@ -459,11 +453,7 @@ static inline u64 auxtrace_mmap__read_snapshot_head(struct auxtrace_mmap *mm) static inline u64 auxtrace_mmap__read_head(struct auxtrace_mmap *mm) { struct perf_event_mmap_page *pc = mm->userpg; -#if BITS_PER_LONG == 64 || !defined(HAVE_SYNC_COMPARE_AND_SWAP_SUPPORT) u64 head = READ_ONCE(pc->aux_head); -#else - u64 head = __sync_val_compare_and_swap(&pc->aux_head, 0, 0); -#endif /* Ensure all reads are done after we read the head */ smp_rmb(); @@ -473,19 +463,10 @@ static inline u64 auxtrace_mmap__read_head(struct auxtrace_mmap *mm) static inline void auxtrace_mmap__write_tail(struct auxtrace_mmap *mm, u64 tail) { struct perf_event_mmap_page *pc = mm->userpg; -#if BITS_PER_LONG != 64 && defined(HAVE_SYNC_COMPARE_AND_SWAP_SUPPORT) - u64 old_tail; -#endif /* Ensure all reads are done before we write the tail out */ smp_mb(); -#if BITS_PER_LONG == 64 || !defined(HAVE_SYNC_COMPARE_AND_SWAP_SUPPORT) pc->aux_tail = tail; -#else - do { - old_tail = __sync_val_compare_and_swap(&pc->aux_tail, 0, 0); - } while (!__sync_bool_compare_and_swap(&pc->aux_tail, old_tail, tail)); -#endif } int auxtrace_mmap__mmap(struct auxtrace_mmap *mm, From patchwork Sun Jul 4 07:16:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12357233 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2B96C07E95 for ; Sun, 4 Jul 2021 07:20:51 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8F1BA61879 for ; Sun, 4 Jul 2021 07:20:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8F1BA61879 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8dJxXdfY69U3P5PJDlyUhSv6J2vBrwEMNo9tFGlSye4=; b=CdtdrWzv9i35PH 1NvMArzemCHzjkkJ030YU3hmXJwG4AkiK8462HhhlMeGBvu9syz/BFEyb/hPuZzdz398b2zPm7Sou gEJcEhEVm9shGqcaaptGAYHJhTyE5WULzd6et+DvJ1X5VKuAZqmj4/h08QJRIC+8tjhvCWS0FkEMh wnuI9g1SzB5kLczydPQ9ooN4qqReY15gl5XtgdnRgjXA0xUFhuCxOZH4ms6YW8MxHSXqIMY+lMJOm F+UWGUx2rlIFcNz2/JSIJL3t2DGXEflpJsy3yM2TaCUneo7o6xC/Ga/5uPSNVVjp14A/rTT2c0NIn hBp0S19WhumnW93qpahg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lzwOU-005rfV-6l; Sun, 04 Jul 2021 07:18:22 +0000 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lzwNa-005rPV-AO for linux-arm-kernel@lists.infradead.org; Sun, 04 Jul 2021 07:17:27 +0000 Received: by mail-pj1-x102a.google.com with SMTP id cx9-20020a17090afd89b0290170a3e085edso9420462pjb.0 for ; Sun, 04 Jul 2021 00:17:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cqZ3/8qRJ0T11IxZy6/iUe0ZOS4dBLD3FIlV5usicsM=; b=E3UX6x54x8lZhJxaCXtRbUP78eBR4I+u4kodpswYImEgDSGt5OsPpK6aig1cAPUsXW kGOyxg1euP+NI63PmPk3bax3UXoPbvCL4fY+7Yrxtec2/mcYxFDBcvjEkew+Z0LgD2Ke 1JC8cnvg+TxOs/q06D+FZnf1x7Z0HSb+QFoHhPP1utkSIEuwI+Fttfbkc5fJ3KjWWpFT erb3my3THxDLnWwFHi/xusawcMjuE4iGWIRpqNkM2lAZ8uBd2vN1BUXxLjndkH1Cbiw6 8wvnZ5X4WiApZ9Zm99zqorutI1O6Yirntyp/q6zjhnGbgKqWsYQMKvdJKEMXLY7n91Am uBLg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=cqZ3/8qRJ0T11IxZy6/iUe0ZOS4dBLD3FIlV5usicsM=; b=P8UEJBEIQ4sBb13Un9VQWOm/wuGANxy5KjlYfQh5GlRFEXGEzrLPYwvW/3aTF149fH /G5QaEzCC9D1F1IVNmz9sguQTuOHIqQgLNsu5O4jMPEiyJI7nkFlWLIQpa9v+61zZST3 eNmkEGgkciLXBfPP+c0QktEJoQEseum9AcihTS7lHKvRzLBtRFvuw++L7Anw537zFOlI 1scsFA6Id3aYbz3DEtKk1eDm0V5+nPw6m3+W7YkTbafVMJn/ZklZSrUuD/9Jp0lj/IQL rsYMvEw+S5taUSlPgNVyBrgz5lb1qy3AzHX2t1RYUjUoKjPZhKpEHQnVKcow50a975YO +JFQ== X-Gm-Message-State: AOAM532j3RPpetyEbUDWM48Dj81M0rGcuTTrUxxw+/SKsa//dEadVSWL rAahIJ1mZMmJRrZE0SKo6RORog== X-Google-Smtp-Source: ABdhPJxxP1J0v8GY7Te1DQbveJ8mV/KCKQeQTcGZB4JU9I32dUshft2tWw6YxwA1immL4jEh56ilbg== X-Received: by 2002:a17:90a:e415:: with SMTP id hv21mr8509138pjb.178.1625383045501; Sun, 04 Jul 2021 00:17:25 -0700 (PDT) Received: from localhost ([103.207.71.35]) by smtp.gmail.com with ESMTPSA id s20sm18870464pjn.23.2021.07.04.00.17.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Jul 2021 00:17:24 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Adrian Hunter , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Mathieu Poirier , Suzuki K Poulose , Mike Leach , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v3 06/10] perf auxtrace: Remove auxtrace_mmap__read_snapshot_head() Date: Sun, 4 Jul 2021 15:16:40 +0800 Message-Id: <20210704071644.107397-7-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210704071644.107397-1-leo.yan@linaro.org> References: <20210704071644.107397-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210704_001726_394208_1CF22E1C X-CRM114-Status: GOOD ( 15.84 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Since the function auxtrace_mmap__read_snapshot_head() is exactly same with auxtrace_mmap__read_head(), whether the session is in snapshot mode or not, it's unified to use function auxtrace_mmap__read_head() for reading AUX buffer head. And the function auxtrace_mmap__read_snapshot_head() is unused so this patch removes it. Signed-off-by: Leo Yan --- tools/perf/util/auxtrace.c | 5 ++--- tools/perf/util/auxtrace.h | 10 ---------- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c index 9350eeb3a3fc..44bd04dbb6d6 100644 --- a/tools/perf/util/auxtrace.c +++ b/tools/perf/util/auxtrace.c @@ -1686,13 +1686,12 @@ static int __auxtrace_mmap__read(struct mmap *map, union perf_event ev; void *data1, *data2; + head = auxtrace_mmap__read_head(mm); + if (snapshot) { - head = auxtrace_mmap__read_snapshot_head(mm); if (auxtrace_record__find_snapshot(itr, mm->idx, mm, data, &head, &old)) return -1; - } else { - head = auxtrace_mmap__read_head(mm); } if (old == head) diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h index f489ca159997..1a2f42980e3f 100644 --- a/tools/perf/util/auxtrace.h +++ b/tools/perf/util/auxtrace.h @@ -440,16 +440,6 @@ struct auxtrace_cache; #ifdef HAVE_AUXTRACE_SUPPORT -static inline u64 auxtrace_mmap__read_snapshot_head(struct auxtrace_mmap *mm) -{ - struct perf_event_mmap_page *pc = mm->userpg; - u64 head = READ_ONCE(pc->aux_head); - - /* Ensure all reads are done after we read the head */ - smp_rmb(); - return head; -} - static inline u64 auxtrace_mmap__read_head(struct auxtrace_mmap *mm) { struct perf_event_mmap_page *pc = mm->userpg; From patchwork Sun Jul 4 07:16:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12357237 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A67AFC07E95 for ; Sun, 4 Jul 2021 07:21:18 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6E39761879 for ; Sun, 4 Jul 2021 07:21:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6E39761879 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=RXU9KzsHfEPDv+wamdzh06zb4kG971kF1jt8jJDeabo=; b=Ko2sXG59kw48wZ sMvjhM3Vat8lI+PD8J09iGB/B9R1cnUq15gTGvhaN8n153KNnT4vPhRS0Xz57unVwfG0flhtM+ic/ oW8yRqJvhTl/RYBe2/DEXmF9w85AcRMbuiKwUjq8+wc+Ffu+iPCfQFrmeeforEf1s4gDFRuS7fFra u71FzJwrYBzcwYkEGjc5r+s8hYYzgJD5ljxPSCj7+gQPjHVh9OJRWileIkyvZY+klmIjkWmcFCCv/ kahuL90+ZwITs2b5e/7QE7ntdYWsuoEtq51EP64ivvrpl4tWudV3RIbCmNZZbsLg7Ldd6oJ+oeE4w Ua3HTIyfl6LzHaPKC34Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lzwOj-005rkF-EX; Sun, 04 Jul 2021 07:18:38 +0000 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lzwNc-005rQX-NB for linux-arm-kernel@lists.infradead.org; Sun, 04 Jul 2021 07:17:30 +0000 Received: by mail-pj1-x1029.google.com with SMTP id p4-20020a17090a9304b029016f3020d867so9393392pjo.3 for ; Sun, 04 Jul 2021 00:17:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YkRHt/y85aRyuOITrbWmeb01ZivbHBgtl/nAPj+TUR8=; b=VqLcGl8QRMM/MjvqsraNlWRi+4GDw1LQPmsLJDG4wxwq7VIDTaZbX3jxX6j2TiaLHh kMaAjr4tCheZ7DMiYNj/TfHTUW3J1uUuynVSoSkDRWXsLxR6HstwKSZeviP5EyYv8lwP ZwcpE0hBWWgrDTNzNDPzz8FyBzx5RcM5TXPGShZWL3TEL2kPlaTqYkImabz5LngV/e/n h7A/tt4M7neREizVTiLzQ+NpelDKtbGdhfbEgQX6anFZBIr7N2J/QqWOBazToo9pbLXd ofrRlOAEsaBCtF7M2tkRwm9UWzphdkUnRqwGH4Pc8qNaeXmo8MRAurDwdKUKjwa1js7r mKHQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=YkRHt/y85aRyuOITrbWmeb01ZivbHBgtl/nAPj+TUR8=; b=jfuhfZlDPW8eQEaig+yKvz3II5iV1NlYBFvoXV9lx3b9oSAc8A2FyeTohLoeIIYXUX Uiphwc2JymKRceFLtLJypFkoBY7Xj74KA1/nzFPBKw6KOmrvDoV2sfKQY9Kj1iZBYipg 3NF0lJnMFGE/r9p0pXVDW15BYX8DH91s4e5AebozrVD4aQQghr/VAWTIKdjO6rT1bfWD z5kbr4WyKQqSn2m6iI19lPcFRyo3drVrG7aYt/Fup+LiJsXpoqIqGyq3ekojIq3yMLMQ e6TE2qZ1enFd/3hBiCHK5+Rzl6W0/uVjeU1ueb5xO81yzRZZKAtjtS35/MZuKZ67QnME Tf4Q== X-Gm-Message-State: AOAM531XOD4dUJg5cmZZkIcfMZ+olZItN/8hJd4FB2ouZKd0ozDVu+51 dRfDOQ639MCnHtLbT6tc575Suw== X-Google-Smtp-Source: ABdhPJxo7pvqsWUeTkUMmxlymc5HCjtuwR5SLuy5pNg+DlTa+bWG1beuCHQp9yxO4juHyAs2G4tu8Q== X-Received: by 2002:a17:90a:5d92:: with SMTP id t18mr8097252pji.221.1625383048279; Sun, 04 Jul 2021 00:17:28 -0700 (PDT) Received: from localhost ([103.207.71.35]) by smtp.gmail.com with ESMTPSA id e4sm8655505pfa.29.2021.07.04.00.17.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Jul 2021 00:17:27 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Adrian Hunter , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Mathieu Poirier , Suzuki K Poulose , Mike Leach , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v3 07/10] perf: Cleanup for HAVE_SYNC_COMPARE_AND_SWAP_SUPPORT Date: Sun, 4 Jul 2021 15:16:41 +0800 Message-Id: <20210704071644.107397-8-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210704071644.107397-1-leo.yan@linaro.org> References: <20210704071644.107397-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210704_001728_801214_E43F1FD3 X-CRM114-Status: GOOD ( 14.19 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Since the __sync functions have been dropped, This patch removes unused build and checking for HAVE_SYNC_COMPARE_AND_SWAP_SUPPORT in perf tool. Note, there have a test for SYNC_COMPARE_AND_SWAP and the test file is located in build/feature/test-sync-compare-and-swap.c. Since there still has several components using the sync functions, it's deliberately to not be removed. $ cd linux/tools $ git grep __sync_val_compare_and_swap | awk '{ printf $1"\n" }' build/feature/test-sync-compare-and-swap.c: include/asm-generic/atomic-gcc.h: testing/selftests/bpf/progs/atomics.c: testing/selftests/bpf/progs/atomics.c: testing/selftests/bpf/progs/atomics.c: testing/selftests/bpf/progs/atomics.c: testing/selftests/futex/include/atomic.h: testing/selftests/futex/include/futextest.h: Signed-off-by: Leo Yan --- tools/perf/Makefile.config | 4 ---- tools/perf/util/auxtrace.c | 5 ----- 2 files changed, 9 deletions(-) diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index eb8e487ef90b..4a0d9a6defc7 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config @@ -349,10 +349,6 @@ CXXFLAGS += $(INC_FLAGS) LIBPERF_CFLAGS := $(CORE_CFLAGS) $(EXTRA_CFLAGS) -ifeq ($(feature-sync-compare-and-swap), 1) - CFLAGS += -DHAVE_SYNC_COMPARE_AND_SWAP_SUPPORT -endif - ifeq ($(feature-pthread-attr-setaffinity-np), 1) CFLAGS += -DHAVE_PTHREAD_ATTR_SETAFFINITY_NP endif diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c index 44bd04dbb6d6..db6255b55c90 100644 --- a/tools/perf/util/auxtrace.c +++ b/tools/perf/util/auxtrace.c @@ -130,11 +130,6 @@ int auxtrace_mmap__mmap(struct auxtrace_mmap *mm, return 0; } -#if BITS_PER_LONG != 64 && !defined(HAVE_SYNC_COMPARE_AND_SWAP_SUPPORT) - pr_err("Cannot use AUX area tracing mmaps\n"); - return -1; -#endif - pc->aux_offset = mp->offset; pc->aux_size = mp->len; From patchwork Sun Jul 4 07:16:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12357239 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A407C07E95 for ; Sun, 4 Jul 2021 07:21:24 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 68FA26192E for ; Sun, 4 Jul 2021 07:21:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 68FA26192E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=k3SmVjbd8gvDJHCjf4gxo8VP8YpfgI9kB7pDsGXVIBo=; b=Ugyk9Raq2DrsfV rD7hSQEt1F6R7E4g6Z30MGgaSvbStOU9PIDtCa/h6ePPnhwCjGD6XprYiDncIiwMYWnxGojmR7BEr QkVtduxSKxNQynPV/Gd/5IIO6RmSKLp7m0v/loWuk39P3tLjdgxasFotIZdLdY35xO48l8eDrRQfY Yskcmnvfgyph7M1RlpF7sHHuYolbI/pc5msx8wrJjTao4PWZmAbMD4HWZs1xHWDHJJusq98EVm4jX EUP241aYJdz9cDAtijpmwDo4r+vB6dk89D4y4lBitdGSop5H9rZhfktr0+8zWYPWtq8HB7B6PjjaF 59BLW4YRL54SEoz3W0LA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lzwPA-005rvg-0k; Sun, 04 Jul 2021 07:19:04 +0000 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lzwNf-005rRb-UM for linux-arm-kernel@lists.infradead.org; Sun, 04 Jul 2021 07:17:34 +0000 Received: by mail-pf1-x433.google.com with SMTP id w22so9907106pff.5 for ; Sun, 04 Jul 2021 00:17:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kCQzQNUYho/r8d2unDfjM9CEfsvPEczKr8vsttMJnd8=; b=pGJGBIEcKP1v98r9fkfW8D3gn5kEVOQ2tcNe7vRZ9woJExO1ntTVeLbMgMtMwJ1UYg CZcI1vzj+wtUb8hHrRiEko7miZUZ4Hv3O5iCFse4PI6SKhVNasQ772ZJKMcgUSp5HFho 1WuvnbPOS0pqZ4VpvHcChWEZPKNGxYsjIhbK4z1uho/+T3OKZMmuV0t3MqQ1zhJ5Fe4L WRlYFSFx2psp9RZIkPWM957bfv2tQASWkYo3PFNYkVYK1AouAEHx2swR7X4paGZbWEGZ wr8j1xjQoKMA+TkSyc+DfS4cI30Szw2nUfVC7EnoQLFpqvZKIovexoBgd+obHTjzgCJN YjPg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=kCQzQNUYho/r8d2unDfjM9CEfsvPEczKr8vsttMJnd8=; b=tvydmu1FqReEDDut2011vNhpEQCMj37NLLRhOEDagXMrzK78q9r9TFhE2ULKYez9g2 vGsaFx0tRUWFLwJfCyBY7oaRd5Fcu9XmM4Jm7lXTt4TOmAEkFqsiQ8eRtpFrGKlV08Zl cx2J3sf3DMGUUNOlnxN+ju/vIIqJPa1Sf0HGwe2tRYMVa2/ISwv9kZOpqTB4laQ/6Aos KcwJkp3vZPqUakSpO+P5N7+VfggD9K9GAApDILxzj+7UVuBHfon9Wznp7591tJPtCX3Q cqI8xfChJmOef+gjOOal/AzegJPQaKB1O930Lwwx+AG7tyy82nDNegnZrLtQvT/RkNIH BjfQ== X-Gm-Message-State: AOAM532bWQOjiTbyeZAZhRu9ARFS6PXCGObqG/bGGqwY/ZX0mVcpWZYo UPn+ykEk/IniCEwphVJ8PJOJJA== X-Google-Smtp-Source: ABdhPJy/0lUUGEPuTONMJGU3vs7xq5nWAKNr4/oXiN3xxNG/2XrE5GcCMZpOwGHpAVm/Oh7WcB7i1g== X-Received: by 2002:a05:6a00:13a7:b029:309:bfd1:a3f5 with SMTP id t39-20020a056a0013a7b0290309bfd1a3f5mr8464357pfg.66.1625383051124; Sun, 04 Jul 2021 00:17:31 -0700 (PDT) Received: from localhost ([103.207.71.35]) by smtp.gmail.com with ESMTPSA id m24sm3092470pgd.60.2021.07.04.00.17.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Jul 2021 00:17:30 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Adrian Hunter , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Mathieu Poirier , Suzuki K Poulose , Mike Leach , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v3 08/10] perf auxtrace: Use WRITE_ONCE() for updating aux_tail Date: Sun, 4 Jul 2021 15:16:42 +0800 Message-Id: <20210704071644.107397-9-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210704071644.107397-1-leo.yan@linaro.org> References: <20210704071644.107397-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210704_001732_029189_020EFE6F X-CRM114-Status: GOOD ( 14.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Use WRITE_ONCE() for updating aux_tail, so can avoid unexpected memory behaviour. Signed-off-by: Leo Yan Acked-by: Adrian Hunter Acked-by: Peter Zijlstra (Intel) --- tools/perf/util/auxtrace.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h index 1a2f42980e3f..d68a5e80b217 100644 --- a/tools/perf/util/auxtrace.h +++ b/tools/perf/util/auxtrace.h @@ -456,7 +456,7 @@ static inline void auxtrace_mmap__write_tail(struct auxtrace_mmap *mm, u64 tail) /* Ensure all reads are done before we write the tail out */ smp_mb(); - pc->aux_tail = tail; + WRITE_ONCE(pc->aux_tail, tail); } int auxtrace_mmap__mmap(struct auxtrace_mmap *mm, From patchwork Sun Jul 4 07:16:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12357241 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52D58C07E95 for ; Sun, 4 Jul 2021 07:21:49 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0380361879 for ; Sun, 4 Jul 2021 07:21:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0380361879 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=yl/5IlVv4OBRdnvUAAnNU9AxD/kRhsVlAySzv42Kyks=; b=4YNJ/vjDuOhx/8 wKJYqK+yZnbDqCcncXgfufmlrf98etIZVkzxhbKOsPnSLuurqAI4w2/mA3oHps3K0nU2OwDDoQl4N qffYPsQWsnZUaRGaXMNoalcS5KffL99akLQPp5q+20mnBNjTz1RuHTW/h2tzjewN+A8BvBdyIZ5Dv ZbcG/KEaTgpktwke+R0Ut6ypj2/Nm5Z3dVdGXMxP8juXBo2cyy27AKsSVKzF7+tM1/ftQNWALzNXC DydBewQXb1MoYsBzSnKQuuCYhOzod/aV+puUodLKyPvyQdMPmXNrAG0PooDImrDntzz2xOjKxXXS6 O5xEe/uVe0bbAoBIr9Qg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lzwPk-005sCk-8O; Sun, 04 Jul 2021 07:19:40 +0000 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lzwNi-005rSZ-MH for linux-arm-kernel@lists.infradead.org; Sun, 04 Jul 2021 07:17:36 +0000 Received: by mail-pl1-x62b.google.com with SMTP id c15so8340443pls.13 for ; Sun, 04 Jul 2021 00:17:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=brLMJrOwQbG83P71X9VPeuY9tvE7zleojiqdMG48VEY=; b=dAw3luOtdje26JAgPM3asmsdnTkplFoo7KvC7H2I/C61UvF35Nzg2HweTqvr7niy3w ys2DktQwpbPTEFPl0Gr/LGVnnmdjqAiSgtMTBegUSKLAKijAFCJfajwQv+Cd5RGAzHmG 2ZW/bq9w3dRLhP013Ef9EVJCV6lTlgAqzoLTcD3ESWEF+uKS4NoXNviD/aH9X6UWQgP4 lKlBL6ss0GmwsSwpyv9rWMl+w6krPT1lD+UF+xJGHDeWJoTZ1dDm97Y8zYPIZ48dL6lL I1eIWQPqDSjVmyb1U+uhUS9Ut5csTpmxVqHZDKDqkYDlt9PLsEW4HsM6wfuSYs0J9fbw IQSQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=brLMJrOwQbG83P71X9VPeuY9tvE7zleojiqdMG48VEY=; b=S53ZDlA2QjfN9M1/emK5BtaTZepoNMVl3Os95AL0ZdtV9udkzXI1R2/Cq7lWI2RZXH XwrQCXyhXR765MNgvRdHD+LQinJR4B/n38oouLo2cYirlP3bxee5TKnO3eZP02ARJybC KDXWxQ/hV9BexdNI3ecN9zaw3I49Fq4zEJ008OHaEWLG7EUfo7hub9qW9Eeat2ICByMp FDFe2tLGPmICAR++VdeyRS+P+t+zyzFTie06GBp5IZt/BpjI5OjhIAck6NWxKKNyxlW6 CHSKxEEHZkhJPcLzkS73nKy+BRK/U5RGSpkpMmurHeUSxUFRR9cspY5Wct6XeYNrTTae BgBw== X-Gm-Message-State: AOAM532vpz3y6ld0hgW4teMmAmri5EyIGFy1aCI6g1H321ZWaEmWTyxm 84kgTopM7tWybz9EnJdEpEfv0g== X-Google-Smtp-Source: ABdhPJzEIeBGPpbSgBBcebonFiiSAj58V7y8TRazuYUDjwzJmrKKnWu6NqjrWvwDYuhHUmwXg3kOVg== X-Received: by 2002:a17:902:9006:b029:107:394a:387 with SMTP id a6-20020a1709029006b0290107394a0387mr7069924plp.35.1625383053898; Sun, 04 Jul 2021 00:17:33 -0700 (PDT) Received: from localhost ([103.207.71.35]) by smtp.gmail.com with ESMTPSA id s43sm983678pfw.50.2021.07.04.00.17.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Jul 2021 00:17:33 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Adrian Hunter , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Mathieu Poirier , Suzuki K Poulose , Mike Leach , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v3 09/10] perf env: Set kernel bit mode Date: Sun, 4 Jul 2021 15:16:43 +0800 Message-Id: <20210704071644.107397-10-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210704071644.107397-1-leo.yan@linaro.org> References: <20210704071644.107397-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210704_001734_784921_CB551037 X-CRM114-Status: GOOD ( 18.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org It's useful to know that the kernel is running in 32-bit or 64-bit mode. E.g. We can decide perf tool is running in compat mode when detects kernel is running in 64-bit mode and the tool is in 32-bit mode with the compiler macro BITS_PER_LONG is 32. This patch adds a global variable "kernel_is_64_bit", during the environment initialization for the session, the kernel running mode is decided by checking the architecture string. Signed-off-by: Leo Yan --- tools/perf/util/env.c | 17 ++++++++++++++++- tools/perf/util/env.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index ebc5e9ad35db..345635a2e842 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -11,6 +11,7 @@ #include #include +int kernel_is_64_bit; struct perf_env perf_env; #ifdef HAVE_LIBBPF_SUPPORT @@ -172,6 +173,19 @@ static void perf_env__purge_bpf(struct perf_env *env __maybe_unused) } #endif // HAVE_LIBBPF_SUPPORT +static void perf_env__init_kernel_mode(struct perf_env *env) +{ + const char *arch = perf_env__raw_arch(env); + + if (!strncmp(arch, "x86_64", 6) || !strncmp(arch, "aarch64", 7) || + !strncmp(arch, "arm64", 5) || !strncmp(arch, "mips64", 6) || + !strncmp(arch, "parisc64", 8) || !strncmp(arch, "riscv64", 7) || + !strncmp(arch, "s390x", 5) || !strncmp(arch, "sparc64", 7)) + kernel_is_64_bit = 1; + else + kernel_is_64_bit = 0; +} + void perf_env__exit(struct perf_env *env) { int i; @@ -217,13 +231,14 @@ void perf_env__exit(struct perf_env *env) zfree(&env->hybrid_cpc_nodes); } -void perf_env__init(struct perf_env *env __maybe_unused) +void perf_env__init(struct perf_env *env) { #ifdef HAVE_LIBBPF_SUPPORT env->bpf_progs.infos = RB_ROOT; env->bpf_progs.btfs = RB_ROOT; init_rwsem(&env->bpf_progs.lock); #endif + perf_env__init_kernel_mode(env); } int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]) diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h index 6824a7423a2d..cc989ff49740 100644 --- a/tools/perf/util/env.h +++ b/tools/perf/util/env.h @@ -139,6 +139,7 @@ enum perf_compress_type { struct bpf_prog_info_node; struct btf_node; +extern int kernel_is_64_bit; extern struct perf_env perf_env; void perf_env__exit(struct perf_env *env); From patchwork Sun Jul 4 07:16:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12357243 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A399C07E95 for ; Sun, 4 Jul 2021 07:22:40 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 089E06192E for ; Sun, 4 Jul 2021 07:22:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 089E06192E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mYHCpCwh+xY2k7LV+ibQfbRfi2l2mSzoq1+AY9iHmYk=; b=02BaZRzsJrb7KC tMKXau0k27+iJPasHqy6LwAb0mlZOKn5yDAVTkTTgfcUiSkeTsjCwuN8MuicF/tJz5/3xLjFkSk1i jAuF/vBqBSP0Ue0THnI40fwUYkOl8ut8QThqu57VfSovkRlacV6h2qF6ZO8uQun1XTeUl48zA8HpH sMCBWfh6Z6JamcgxjKfXV/Am61xMGpZjptWzibkd9HXdDVvG7wTMF7M3fsYPra/yfg02se9iHFvAC mmd9vfLpsGc1cEXKM9VMTJHelBA2Ntbyzs5amDqydkuEm3nX9KdTv6xE1IsvZc95qVYVMzzw796AD Y8tFgSX4qhYj+lcRxdaQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lzwQj-005shB-OU; Sun, 04 Jul 2021 07:20:43 +0000 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lzwNl-005rUh-Op for linux-arm-kernel@lists.infradead.org; Sun, 04 Jul 2021 07:17:40 +0000 Received: by mail-pg1-x535.google.com with SMTP id o18so14293145pgu.10 for ; Sun, 04 Jul 2021 00:17:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gwprV+HEULsEJDwZz52p62rJDy8elyvDLwuO5n6hP4M=; b=NgdnPOfd6b3O96H8aRbeIKmk+vH5RfMp2Nx3nRMWfJpHyBi8GKXwu7s38mdKLr/Gh4 EkyVIEinvkCfBMH5Bm8zc4O3xeWmLnIw++hX6GlkQ1P6cXneJacsnmxsbswoyq/C+7hD iUnX5NIAASXCNNfOhyDskBZ/LUOsuCBQhbDDVjDPOMXLBtZtgFJSahSHXFSN6ZYu+vsg DtJpW1vOCS8mnBjSEmFlaiV9/14LVtriCLtG+aP7ikdJyAOOOxfQJuRJjD5bju3XD8xt XfpOHF6JVDEsubuEKt3P3jJ1sey12d6+zJGzvd3X93nAEobsnPvHA6Csz5+QCca/clMm CaPQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=gwprV+HEULsEJDwZz52p62rJDy8elyvDLwuO5n6hP4M=; b=WS0Kb2HFKVUhJ75aB3/yHG8AYTBIRMfF7NC4232DQ46cKSO844Z5/ilacCjRYQebQJ AnsQtAsgdtkEgWGymiFlmCXNb+r1EiIfJQTRBRHDhKv8Vq8ycS5JR0iRTgUN338QPuB7 yaWXVLKu2tDxBnynyWkzB6WZHcXfYDH0nnfpAwargs1txtl9yBBSVMQQsqws78p/d8uy hq2QVX1SRX0bvYnZTbn6USdrVvHiyWCLAak3udPUh+R1J8SX5jlHlvBBjS05ll5dVdYu RoaiVNiIQBDfZd5MhkUd42RApMhjN4z9f4c8ExRuXPqsgRX2fCO/LgIVc8zUsG3eHp2K Mn8A== X-Gm-Message-State: AOAM531VPLEjwr0wSEPasNgt4vHOwYW+HWuRiOLvz2M1HKnU7p+C5sS4 oP/Q5WwBRHnY5m/3ghNS9Ut1LA== X-Google-Smtp-Source: ABdhPJwi978cbAVtSkaJxDburLnX4Nsgf0DoJyTtLrWIgWNd8EQiH46mWics+JvO2UBcivpRgXdwFw== X-Received: by 2002:aa7:8284:0:b029:312:1c62:cc0f with SMTP id s4-20020aa782840000b02903121c62cc0fmr8568364pfm.75.1625383056872; Sun, 04 Jul 2021 00:17:36 -0700 (PDT) Received: from localhost ([103.207.71.35]) by smtp.gmail.com with ESMTPSA id 9sm8834236pfv.42.2021.07.04.00.17.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Jul 2021 00:17:36 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Adrian Hunter , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Mathieu Poirier , Suzuki K Poulose , Mike Leach , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v3 10/10] perf auxtrace: Add compat_auxtrace_mmap__{read_head|write_tail} Date: Sun, 4 Jul 2021 15:16:44 +0800 Message-Id: <20210704071644.107397-11-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210704071644.107397-1-leo.yan@linaro.org> References: <20210704071644.107397-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210704_001737_824180_503FE6D5 X-CRM114-Status: GOOD ( 31.99 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When perf runs in compat mode (kernel in 64-bit mode and the perf is in 32-bit mode), the 64-bit value atomicity in the user space cannot be assured, E.g. on some architectures, the 64-bit value accessing is split into two instructions, one is the low 32-bit accessing and another is for the high 32-bit. This patch introduces two functions compat_auxtrace_mmap__read_head() and compat_auxtrace_mmap__write_tail(), as their naming indicates, when perf tool works in compat mode, it uses these two functions to access the AUX head and tail. These two functions can allow the perf tool to work properly in certain conditions, e.g. when perf tool works in snapshot mode with only using AUX head pointer, or perf tool uses the AUX buffer and the tail is not bigger than 4GB. When the perf tool cannot handle the case when the AUX tail is overflow for 4GB, the function compat_auxtrace_mmap__write_tail() returns -1 and the caller is changed to bail out for the overflow error. Suggested-by: Adrian Hunter Signed-off-by: Leo Yan --- tools/perf/util/auxtrace.c | 9 ++-- tools/perf/util/auxtrace.h | 94 +++++++++++++++++++++++++++++++++++++- 2 files changed, 98 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c index db6255b55c90..a430d74b279f 100644 --- a/tools/perf/util/auxtrace.c +++ b/tools/perf/util/auxtrace.c @@ -1766,10 +1766,13 @@ static int __auxtrace_mmap__read(struct mmap *map, mm->prev = head; if (!snapshot) { - auxtrace_mmap__write_tail(mm, head); - if (itr->read_finish) { - int err; + int err; + err = auxtrace_mmap__write_tail(mm, head); + if (err < 0) + return err; + + if (itr->read_finish) { err = itr->read_finish(itr, mm->idx); if (err < 0) return err; diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h index d68a5e80b217..66de7b6e65ec 100644 --- a/tools/perf/util/auxtrace.h +++ b/tools/perf/util/auxtrace.h @@ -18,6 +18,8 @@ #include #include +#include "env.h" + union perf_event; struct perf_session; struct evlist; @@ -440,23 +442,111 @@ struct auxtrace_cache; #ifdef HAVE_AUXTRACE_SUPPORT +/* + * In the compat mode kernel runs in 64-bit and perf tool runs in 32-bit mode, + * 32-bit perf tool cannot access 64-bit value atomically, which might lead to + * the issues caused by the below sequence on multiple CPUs: when perf tool + * accesses either the load operation or the store operation for 64-bit value, + * on some architectures the operation is divided into two instructions, one + * is for accessing the low 32-bit value and another is for the high 32-bit; + * thus these two user operations can give the kernel chances to access the + * 64-bit value, and thus leads to the unexpected load values. + * + * kernel (64-bit) user (32-bit) + * + * if (LOAD ->aux_tail) { --, LOAD ->aux_head_lo + * STORE $aux_data | ,---> + * FLUSH $aux_data | | LOAD ->aux_head_hi + * STORE ->aux_head --|-------` smp_rmb() + * } | LOAD $data + * | smp_mb() + * | STORE ->aux_tail_lo + * `-----------> + * STORE ->aux_tail_hi + * + * For this reason, it's impossible for the perf tool to work correctly when + * the AUX head or tail is bigger than 4GB (more than 32 bits length); and we + * can not simply limit the AUX ring buffer to less than 4GB, the reason is + * the pointers can be increased monotonically (e.g in snapshot mode), whatever + * the buffer size it is, at the end the head and tail can be bigger than 4GB + * and carry out to the high 32-bit. + * + * To mitigate the issues and improve the user experience, we can allow the + * perf tool working in certain conditions and bail out with error if detect + * any overflow cannot be handled. + * + * For reading the AUX head, it reads out the values for three times, and + * compares the high 4 bytes of the values between the first time and the last + * time, if there has no change for high 4 bytes injected by the kernel during + * the user reading sequence, it's safe for use the second value. + * + * When update the AUX tail and detects any carrying in the high 32 bits, it + * means there have two store operations in user space and it cannot promise + * the atomicity for 64-bit write, so return '-1' in this case to tell the + * caller an overflow error has happened. + */ +static inline u64 compat_auxtrace_mmap__read_head(struct auxtrace_mmap *mm) +{ + struct perf_event_mmap_page *pc = mm->userpg; + u64 first, second, last; + u64 mask = (u64)(UINT32_MAX) << 32; + + do { + first = READ_ONCE(pc->aux_head); + /* Ensure all reads are done after we read the head */ + smp_rmb(); + second = READ_ONCE(pc->aux_head); + /* Ensure all reads are done after we read the head */ + smp_rmb(); + last = READ_ONCE(pc->aux_head); + } while ((first & mask) != (last & mask)); + + return second; +} + +static inline int compat_auxtrace_mmap__write_tail(struct auxtrace_mmap *mm, + u64 tail) +{ + struct perf_event_mmap_page *pc = mm->userpg; + u64 mask = (u64)(UINT32_MAX) << 32; + + if (tail & mask) + return -1; + + /* Ensure all reads are done before we write the tail out */ + smp_mb(); + WRITE_ONCE(pc->aux_tail, tail); + return 0; +} + static inline u64 auxtrace_mmap__read_head(struct auxtrace_mmap *mm) { struct perf_event_mmap_page *pc = mm->userpg; - u64 head = READ_ONCE(pc->aux_head); + u64 head; + +#if BITS_PER_LONG == 32 + if (kernel_is_64_bit) + return compat_auxtrace_mmap__read_head(mm); +#endif + head = READ_ONCE(pc->aux_head); /* Ensure all reads are done after we read the head */ smp_rmb(); return head; } -static inline void auxtrace_mmap__write_tail(struct auxtrace_mmap *mm, u64 tail) +static inline int auxtrace_mmap__write_tail(struct auxtrace_mmap *mm, u64 tail) { struct perf_event_mmap_page *pc = mm->userpg; +#if BITS_PER_LONG == 32 + if (kernel_is_64_bit) + return compat_auxtrace_mmap__write_tail(mm, tail); +#endif /* Ensure all reads are done before we write the tail out */ smp_mb(); WRITE_ONCE(pc->aux_tail, tail); + return 0; } int auxtrace_mmap__mmap(struct auxtrace_mmap *mm,