Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp508395pxj; Wed, 2 Jun 2021 04:56:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhl2D4bv9V80ES+k26bnVsdxYgbuDwor6o4byroXH096nRhYOHXQ72OnuD77MvHPlfWZ2G X-Received: by 2002:a05:6e02:1648:: with SMTP id v8mr24987159ilu.289.1622635004067; Wed, 02 Jun 2021 04:56:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622635004; cv=none; d=google.com; s=arc-20160816; b=GKrgSqBeKkH7Jt6Cw4+HLKkquLYn9zkc81sLGruBSQKhyCAAdOdZJAgCg4fSinytFQ m/531itsCn4CW7ZEWZFQp+pU+tWb+PIZaeSy+wKP3zGfkAtrU4MtIIv7NFFEka4A1ny6 xBF52YepgfA1ESoXRZ9PTn1hVVAA79a4RtLUdsR4oEHPr7AoxpvQ7daWmwK0er+womGr p9pFZb0PArZzOR8xzMkXy6vSnCE55E+COexjzCGDFMuT1TrP1nIyMSni5wN+ZdhkC/DJ w4N52ANL+yQtC+RfBb2MmtiXu76aQzmjwFlrL4pTEVNIaw2mEALQUshqWKrysRu2lCP4 Xa1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CUGVcjWHAFZiSQpFiWcs46u9/hPtHfCUkPW2QO50s/E=; b=NsX3sDR3DRtg6mh+9Z015T0RgdTmVGvt445h9aDR43n9QYGkpybuJ6GwMS8msYJ786 BfoUU21MhfZbXee1UM5AEt/O3ClNfp6cBeAWXhebiJlt8Oq7CEfVYO9HCxheEdhflzwh u7K07G94BcSynlBmq+p8zjFZC/Go/DFbYPZ880hsBebkVUr4EJ474UzyAhu06j/tJL3G jYiRTAfjM8HhGbFqfMwOzrrQCV93GAJykE9N7l0ZROmp2XvPm/g9RFiWlFlmVDCQ291z 0iPX64aAft7/+hDfv1B/OyaNgFenl3eiQlS2UwrMjrLAOhp3bw3LhTr1hKZs/KiI2GUB e9OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qWBMODYk; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h17si21165441ila.72.2021.06.02.04.56.31; Wed, 02 Jun 2021 04:56:44 -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=@linaro.org header.s=google header.b=qWBMODYk; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232778AbhFBKcZ (ORCPT + 99 others); Wed, 2 Jun 2021 06:32:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232579AbhFBKcS (ORCPT ); Wed, 2 Jun 2021 06:32:18 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1197FC061763 for ; Wed, 2 Jun 2021 03:30:35 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id g24so1405593pji.4 for ; Wed, 02 Jun 2021 03:30:35 -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=CUGVcjWHAFZiSQpFiWcs46u9/hPtHfCUkPW2QO50s/E=; b=qWBMODYkIE7TtEUAD2cnjvNDYoN9T6k+wDhbdTbYweTRWm0/BluYjDGdJ3RtKnWRxA ZoIDaE4fheb8TK7/Z36LlFC/X8bcaNNj9jP1FBjpnknsKIPQXtsDAdCc0wPwyxspEkXe 9kt9HLXb4abGreF5MiG6kU1qeYe2tPZpBKdL4f3GN2TTX41IDdyKu3dQhXkMeyIKQOSj cxlzxyp5JwtElocmliTV6usnPMu4s4vInem5hafNKawKcAtgMIHjzHdUNA24lNNDIU4K big+EhLIxSoP5BjeOw7SkD+8vOOnIBymiw8ZyqSRSnYj2w4TZVz0Wp+HRxRiSKu8t369 WmpA== 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=CUGVcjWHAFZiSQpFiWcs46u9/hPtHfCUkPW2QO50s/E=; b=CyAzMAvjCtQPcdfjU+BMBbvO5Z+EtG3z2KKEzgkk2wwQr2MNY3e2FspT+aA7BB+iNo xolxJ7l9LVhnkQQMoAm5lIQoYXe2YjqWM/kUcNTchOzb5BxGzrVuSGOiaCm44ys1wpwL 6r9yLap7cEfLTi6zjzMCTTMDIbp0+GsIKju3cv3F3Bwqxutvo49N841UMfNRgZ2VK6P0 AadTGzuPjgkdvn2EtLTaFJywXzR1+PaZO4uJEUlXPB82SfCKJ6VAsHhG0nHbL7M72fKC jfhRavGz0o4njDxha9f1O0G9kpdpIizL840jz4tzjV8qQq49ERYKdfozSOs5dh+WaDG+ xyOg== X-Gm-Message-State: AOAM533vSlJbKpWSJE1p3ZIOODtMkZ1as8diiwqnE63apw5uaeNLQFPj wgIm4XXAZ4DHRfqNDB0dVhoqBQ== X-Received: by 2002:a17:902:7244:b029:f5:2ffd:37f9 with SMTP id c4-20020a1709027244b02900f52ffd37f9mr30314548pll.26.1622629834563; Wed, 02 Jun 2021 03:30:34 -0700 (PDT) Received: from localhost (ec2-18-167-84-74.ap-east-1.compute.amazonaws.com. [18.167.84.74]) by smtp.gmail.com with ESMTPSA id j16sm2094111pgi.73.2021.06.02.03.30.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 03:30:34 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , x86@kernel.org, "H. Peter Anvin" , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Adrian Hunter , Andi Kleen , 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 v2 6/8] perf auxtrace: Drop legacy __sync functions Date: Wed, 2 Jun 2021 18:30:05 +0800 Message-Id: <20210602103007.184993-7-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210602103007.184993-1-leo.yan@linaro.org> References: <20210602103007.184993-1-leo.yan@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 42b7ef811bde..e625bc76cdde 100644 --- a/tools/perf/util/auxtrace.h +++ b/tools/perf/util/auxtrace.h @@ -432,12 +432,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; @@ -451,11 +445,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(); @@ -465,19 +455,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, -- 2.25.1