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,