From patchwork Fri May 19 23:07:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beau Belgrave X-Patchwork-Id: 96670 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp20233vqo; Fri, 19 May 2023 16:13:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Kltp/1uwt479n1HXcsMDCVPyRG19RXF4ti09CdqvXxqHKLPJcTvazQ86EDFFphruyAm5Q X-Received: by 2002:a17:903:18b:b0:1ac:82bb:ebdf with SMTP id z11-20020a170903018b00b001ac82bbebdfmr4505419plg.58.1684538032987; Fri, 19 May 2023 16:13:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684538032; cv=none; d=google.com; s=arc-20160816; b=ziD4o2KSDEyOEhcUvgjv05ysneJlXmNO9y8sCcTRsYXQpEbIU6YxntLPF6fPXGJKvw MPwsDJmiy0zDIUY5/m164F8JSWmN/yNf/H8Yj0iM7RPpcn23th4pplARWBaKP9FiJCR/ OStxJ8/jlzcX6JO0bpGvqV3JTEk5Ujfz05rIbcZ2bWyIdix6iRCCnAH807Gz/ao/SBSR SfA54xwbkqiPiULRqZmMyLNB/AE5mFOF1ktoFJwCstq5pLLiwbMnXF+k0+UKRKu8Y7za 15eznU+TenEPwYfqNOw0VR/+NN6y0DLpGNlYKQl+8V6NcI4WVhkqJO3LZzjiQWg8+KwV 9ytQ== 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:dkim-filter; bh=OvAh3RxmXpSVUBx65Lv/5RIU5rX4bGiaYEjcJRexHGA=; b=S31ppCUSHovfFv6DQ3ou0Ec+OKaqg6WSPq02PmKTOIewh3I/65e9NfjgvlpBNYgWei iJXTxOaPLYmnQvnJwCeGgTWPwwYHezT4ZusjtbwYu6t6q67Z7LSqqdjQe8Y+GpV5EfZq iwmQRW6QKzviWn2Ar+Q0DtXB3XhdCnAsR/rmJEf1r1ODokFgNmS3sw8c2MuTQTCmhTn8 Apw9atl/a1+9DCZBwqFM21SoYwjzy2MB2Zxjk0ZmSsHSSCxRqBawZLKPKyOzSghJ9/dV quGVqTGVDq3XoMyoxDWNSx0/9xHXuUHOexscHRG7dUAFV+MOmQzJ1J+FjAKfGdxzWahs 8ulA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="io/kAOLF"; 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=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jf5-20020a170903268500b001aaf91ae3acsi235267plb.485.2023.05.19.16.13.40; Fri, 19 May 2023 16:13:52 -0700 (PDT) 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=@linux.microsoft.com header.s=default header.b="io/kAOLF"; 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=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231786AbjESXId (ORCPT + 99 others); Fri, 19 May 2023 19:08:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231671AbjESXI0 (ORCPT ); Fri, 19 May 2023 19:08:26 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0DB081B0; Fri, 19 May 2023 16:08:24 -0700 (PDT) Received: from W11-BEAU-MD.localdomain (unknown [76.135.27.212]) by linux.microsoft.com (Postfix) with ESMTPSA id 69CF220FB611; Fri, 19 May 2023 16:08:24 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 69CF220FB611 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1684537704; bh=OvAh3RxmXpSVUBx65Lv/5RIU5rX4bGiaYEjcJRexHGA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=io/kAOLFf4UK4zU96lsgT4gbEmhCH7ceePCd+Ojb3H1Tg2OGEKDmwmqngfGech18X Jgk+s6ji0vF58grp4NaNtecL4aqvvN3N9sfnDvlkr4sdglmwerLj0XFAQo85Ciwn4T LNGkzJhEkJK2onr+1gV460KxFEMbvlAYAEsBNg/Y= From: Beau Belgrave To: rostedt@goodmis.org, mhiramat@kernel.org Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, torvalds@linux-foundation.org, ast@kernel.org Subject: [PATCH v3 2/4] tracing/user_events: Remove RCU lock while pinning pages Date: Fri, 19 May 2023 16:07:39 -0700 Message-Id: <20230519230741.669-3-beaub@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230519230741.669-1-beaub@linux.microsoft.com> References: <20230519230741.669-1-beaub@linux.microsoft.com> MIME-Version: 1.0 X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=ham 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?1766366152124681490?= X-GMAIL-MSGID: =?utf-8?q?1766366152124681490?= From: Linus Torvalds pin_user_pages_remote() can reschedule which means we cannot hold any RCU lock while using it. Now that enablers are not exposed out to the tracing register callbacks during fork(), there is clearly no need to require the RCU lock as event_mutex is enough to protect changes. Remove unneeded RCU usages when pinning pages and walking enablers with event_mutex held. Cleanup a misleading "safe" list walk that is not needed. During fork() duplication, remove unneeded RCU list add, since the list is not exposed yet. Link: https://lore.kernel.org/linux-trace-kernel/CAHk-=wiiBfT4zNS29jA0XEsy8EmbqTH1hAPdRJCDAJMD8Gxt5A@mail.gmail.com/ Fixes: 7235759084a4 ("tracing/user_events: Use remote writes for event enablement") Signed-off-by: Linus Torvalds [ change log written by Beau Belgrave ] Signed-off-by: Beau Belgrave --- kernel/trace/trace_events_user.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c index b2aecbfbbd24..2f70dabb0f71 100644 --- a/kernel/trace/trace_events_user.c +++ b/kernel/trace/trace_events_user.c @@ -437,9 +437,8 @@ static bool user_event_enabler_exists(struct user_event_mm *mm, unsigned long uaddr, unsigned char bit) { struct user_event_enabler *enabler; - struct user_event_enabler *next; - list_for_each_entry_safe(enabler, next, &mm->enablers, link) { + list_for_each_entry(enabler, &mm->enablers, link) { if (enabler->addr == uaddr && (enabler->values & ENABLE_VAL_BIT_MASK) == bit) return true; @@ -455,19 +454,19 @@ static void user_event_enabler_update(struct user_event *user) struct user_event_mm *next; int attempt; + lockdep_assert_held(&event_mutex); + while (mm) { next = mm->next; mmap_read_lock(mm->mm); - rcu_read_lock(); - list_for_each_entry_rcu(enabler, &mm->enablers, link) { + list_for_each_entry(enabler, &mm->enablers, link) { if (enabler->event == user) { attempt = 0; user_event_enabler_write(mm, enabler, true, &attempt); } } - rcu_read_unlock(); mmap_read_unlock(mm->mm); user_event_mm_put(mm); mm = next; @@ -495,7 +494,9 @@ static bool user_event_enabler_dup(struct user_event_enabler *orig, enabler->values = orig->values & ENABLE_VAL_DUP_MASK; refcount_inc(&enabler->event->refcnt); - list_add_rcu(&enabler->link, &mm->enablers); + + /* Enablers not exposed yet, RCU not required */ + list_add(&enabler->link, &mm->enablers); return true; }