From patchwork Sat Nov 19 01:34:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 1937 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp510980wrr; Fri, 18 Nov 2022 17:55:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf7XWSIiiUb6roZLxm6PaED0TnjbwuY6IxVFvWQJZIAtBt3qTE5D0pqbsXFbv4+eCBpWa321 X-Received: by 2002:a17:903:40c5:b0:186:738e:5703 with SMTP id t5-20020a17090340c500b00186738e5703mr1985542pld.136.1668822921609; Fri, 18 Nov 2022 17:55:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668822921; cv=none; d=google.com; s=arc-20160816; b=GGNF3esjhy2xiBCQ4OrG71zH4NhWvnNCoPnq5KVg3VY7g+mGaTsm4eWSLRoJrOLsu9 oagUSucQDdTATAR8jIvzag2an88nLt+biyKXyFoAdwMbrW4v+W4YmgIWCgzumCXQ6K5R HXDapr2CZjcaXguY6u35F/3Uxxa10ggkzgOes8L0sOeDkBDU8kiXcFj44ZGinAznmymj vSGRPCxpBJ7wgtttRFRLcxvW7KO2ifdbrcxmLPrXrww9VgL4uXRrGPfvdJgUlDbpkIZR qZjQD1cMZcSnqA4qv44nKgzOkybYWY4Lj5tY0i1X3eUKzHso4KYuKCsKuWQ6ZvpOEXwp Bmdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :reply-to:dkim-signature; bh=CjK5nD/uvnQk7qUQi9oIboYcWNk4lZcV0pG+jDjHbYw=; b=fxPQbcpe+XXGv7kMCa8pRFkb7qKgpOqoEXr0RzmByocbXRPmszfvF3bb1c7bCqhv19 735CqoE0bUWRYnZ6/H4jVylEU5CIwOlqnve3pQ6aVeTfJYYoy20p93at/dLz/cJUONhc +25bJ6ah45E5TZYJ0K/GgXqXDMn/UiDjoWaTyMGyYN/rrLAXN58dKvQkpap0dfr9/nD5 abqMLtuC8DaUsCTOztckDV1SilyhF0WZYCcj3RqKKrFt20z0yAUoYvcTpgrebvODW9WY ouQ1linQUasMJFBchClKjp9Uz2y3SMQR8tbi4j16RGIkXcujJveyK8YCX5aBGhNVfH91 DkzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="sO/BixX+"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nl9-20020a17090b384900b0020940c79fc5si9398854pjb.51.2022.11.18.17.55.07; Fri, 18 Nov 2022 17:55:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="sO/BixX+"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232761AbiKSBw5 (ORCPT + 99 others); Fri, 18 Nov 2022 20:52:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233553AbiKSBwl (ORCPT ); Fri, 18 Nov 2022 20:52:41 -0500 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C475AA44F for ; Fri, 18 Nov 2022 17:34:54 -0800 (PST) Received: by mail-pl1-x64a.google.com with SMTP id b2-20020a170902d50200b001871a3c51afso4965051plg.8 for ; Fri, 18 Nov 2022 17:34:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:reply-to:from:to:cc :subject:date:message-id:reply-to; bh=CjK5nD/uvnQk7qUQi9oIboYcWNk4lZcV0pG+jDjHbYw=; b=sO/BixX+Fxa6IYPQU8TkdF+XFQ44C4ZySQ2iwNGf4nj3I51S8QIRUibkPiKNqU6bw1 j4PlnepiO1Ad8v/zZSnMeIBI68hxaFqyJGMZebX4cy3Jv14uXBvY/oT0aik++6OQL6oN DbLgAWDsPzUK72v+4dKMHKRTS+Pj0wR02zmTyQNbwMmm5J9cue1G73b6Acb3Oy+6Rqq7 SFCX3tIjVDK5Bkgwj3xiOgKx932eMjN+X5AA0/Lbv6Dl4c1cRTcxk/wdcfGn/cUpN1uD EJ0BOyIS/RA9GP99cIy1ORxMCIBlL+dVVmi0pQd37KDIkkhww3/YCplg0uN9lfWxW1qn tETw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:reply-to :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CjK5nD/uvnQk7qUQi9oIboYcWNk4lZcV0pG+jDjHbYw=; b=ckPZYC0qkM476GBKmZY8tyaVX9veRJ/HANTSG08dQ9gmbKSU+38CdTFCcTkItLUy4W QL7VJ54Ztre7UeSuRariyrp3XCkME7EFMbwdIpqO42Qi5e9VV+dKcFHpdVJM3YjazEn6 Jr69CeIq9DIj8P9bIKytlhva5ZmI+9zlbE1OZFpTHaCLvrmNNJbuPyURlgOqft7GvPOn jIM2hV0V2Ay0poDOzDxWJcaE1ahDUcahtNDHT6R6DI88kyzdqx8+Saycwpf2/I2mYZCc L4ZfCQkHiI7+WW59U/Ka7ewpe08iRznpqnBoyrIBgm+hjSpE/W49JOiMwVjqAjVWtq3+ bN+Q== X-Gm-Message-State: ANoB5pl21/M6IAuzNvUD0GmGD7jU6vlenEsJHBMtNb/UHLSnH/dv0Doh tyL7SY0b3V5feVzTZegkHZf5UmvsYAE= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a62:31c4:0:b0:56e:989d:7410 with SMTP id x187-20020a6231c4000000b0056e989d7410mr10648162pfx.1.1668821693609; Fri, 18 Nov 2022 17:34:53 -0800 (PST) Reply-To: Sean Christopherson Date: Sat, 19 Nov 2022 01:34:41 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog Message-ID: <20221119013450.2643007-1-seanjc@google.com> Subject: [PATCH 0/9] tools: Make {clear,set}_bit() atomic for reals From: Sean Christopherson To: Yury Norov , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Marc Zyngier , Paolo Bonzini Cc: Andy Shevchenko , Rasmus Villemoes , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , James Morse , Alexandru Elisei , Suzuki K Poulose , Oliver Upton , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, Sean Christopherson X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749887663630926936?= X-GMAIL-MSGID: =?utf-8?q?1749887663630926936?= For obvious reasons I'd like to route the this through Paolo's tree. In theory, taking just patch 5 through tip would work, but creating a topic branch seems like the way to go, though maybe I'm being overly paranoid. The current tip/perf/core doesn't have any conflicts, nor does it have new set_bit() or clear_bit() users. Code sitting in kvm/queue for 6.2 adds functionality that relies on clear_bit() being an atomic operation. Unfortunately, despite being implemented in atomic.h (among other strong hits that they should be atomic), clear_bit() and set_bit() aren't actually atomic (and of course I realized this _just_ after everything got queued up). Move current tools/ users of clear_bit() and set_bit() to the double-underscore versions (which tools/ already provides and documents as being non-atomic), and then implement clear_bit() and set_bit() as actual atomics to fix the KVM selftests bug. Perf and KVM are the only affected users. NVDIMM also has test code in tools/, but that builds against the kernel proper. The KVM code is well tested and fully audited. The perf code is lightly tested; if I understand the build system, it's probably not even fully compile tested. Patches 1 and 2 are completely unrelated and are fixes for patches sitting in kvm/queue. Paolo, they can be squashed if you want to rewrite history. Patch 3 fixes a hilarious collision in a KVM ARM selftest that will arise when clear_bit() is converted to an atomic. Patch 4 changes clear_bit() and set_bit() to take an "unsigned long" instead of an "int" so that patches 5-6 aren't accompanied by functional changes. I.e. if something in perf is somehow relying on "bit" being a signed int, failures will bisect to patch 4 and not to the supposed-to-be-a-nop conversion to __clear_bit() and __set_bit(). Patch 5-9 switch perf+KVM and complete the conversion. Applies on: git://git.kernel.org/pub/scm/virt/kvm/kvm.git queue Sean Christopherson (9): KVM: selftests: Add rdmsr_from_l2() implementation in Hyper-V eVMCS test KVM: selftests: Remove unused "vcpu" param to fix build error KVM: arm64: selftests: Enable single-step without a "full" ucall() tools: Take @bit as an "unsigned long" in {clear,set}_bit() helpers perf tools: Use dedicated non-atomic clear/set bit helpers KVM: selftests: Use non-atomic clear/set bit helpers in KVM tests tools: Drop conflicting non-atomic test_and_{clear,set}_bit() helpers tools: Drop "atomic_" prefix from atomic test_and_set_bit() tools: KVM: selftests: Convert clear/set_bit() to actual atomics tools/arch/x86/include/asm/atomic.h | 6 +++- tools/include/asm-generic/atomic-gcc.h | 13 ++++++- tools/include/asm-generic/bitops/atomic.h | 15 ++++---- tools/include/linux/bitmap.h | 34 ------------------- tools/perf/bench/find-bit-bench.c | 2 +- tools/perf/builtin-c2c.c | 6 ++-- tools/perf/builtin-kwork.c | 6 ++-- tools/perf/builtin-record.c | 6 ++-- tools/perf/builtin-sched.c | 2 +- tools/perf/tests/bitmap.c | 2 +- tools/perf/tests/mem2node.c | 2 +- tools/perf/util/affinity.c | 4 +-- tools/perf/util/header.c | 8 ++--- tools/perf/util/mmap.c | 6 ++-- tools/perf/util/pmu.c | 2 +- .../util/scripting-engines/trace-event-perl.c | 2 +- .../scripting-engines/trace-event-python.c | 2 +- tools/perf/util/session.c | 2 +- tools/perf/util/svghelper.c | 2 +- .../selftests/kvm/aarch64/arch_timer.c | 2 +- .../selftests/kvm/aarch64/debug-exceptions.c | 21 ++++++------ tools/testing/selftests/kvm/dirty_log_test.c | 34 +++++++++---------- .../selftests/kvm/include/ucall_common.h | 8 +++++ .../testing/selftests/kvm/lib/ucall_common.c | 2 +- .../selftests/kvm/x86_64/hyperv_evmcs.c | 13 +++++-- .../selftests/kvm/x86_64/hyperv_svm_test.c | 4 +-- .../selftests/kvm/x86_64/hyperv_tlb_flush.c | 2 +- 27 files changed, 102 insertions(+), 106 deletions(-) base-commit: 3321eef4acb51c303f0598d8a8493ca58528a054