Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp22946rwj; Thu, 22 Dec 2022 04:30:40 -0800 (PST) X-Google-Smtp-Source: AMrXdXuC20EG4KYDjfwMlqpnDwrD5sZ6R9TuBJN3QfTWFCPpCX0+Lf/UaDLmr/P2UOYkheto3dDp X-Received: by 2002:a05:6402:4011:b0:47d:b076:77fa with SMTP id d17-20020a056402401100b0047db07677famr6682614eda.10.1671712240518; Thu, 22 Dec 2022 04:30:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671712240; cv=none; d=google.com; s=arc-20160816; b=wL583IQzMJI5A3IAxbgP5P5NPZcwJ5l+KCkSezk/aSYnv23MpTawp6bekVVuTwlLTD RXQCnLwb2FDjosJ7D1Hjtg5YkM2dhDgP4TrxTy/1k7AuExxr5aH1w+3QkiqdPX1pXkCt AapJUFk3r+mD5/L/KRKUIWPtTgumT5mE+drW/KjRyu/Bx+s7kSWyHdTtECEFS0KRzOeV eobnla2zKwO+59q2NzpI1cLhtFaz0C4n79I7WhuRfjG9gi/3i+MSIiqtRdd0lYwBxTyf Ey2ffIzYtDT0p+WGul21KwHC8xcvfemkdctK5SzwHMk+2lJaxnslDRE1DsoLTKzCQ1T/ RmfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=/4Ai+7/9tsJEaKUGjCwWP2+aABMhRcTmi+u/34V2hQw=; b=eT8J7mpqjMz6iPy2g3RytCHfXXS60dc7c32QrYWQvBAYTM+/Rsp95T7dYxLS6FR7rK 78nDDDFWN1wfdEZk/PZO0V+xarqWJBp8T5xdwmr2vmj6OwCelNCUT2IrHd2+BlNLo2UM UCP/fbeIwpx6vVZW2wHzQmrjQGQvcOdflX7/94u90wT5C3/cLNQsrB0IUsz0LxpB4LXH mrX073TgCUPcnISVZBRsoc+GnHC/USVBJWQgETyJdpAxuOoZNpKFYSQg7eB8My+H7GgW UFM6VxNBe5L+WWgZzcqI8EYDDrepbYdQ/bH+i5jVaIeTUMI84kDNGBXjHtHL5kkgMZm/ A5iQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="nvZY/9Yp"; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u21-20020a50d515000000b0046bdcbd0057si589539edi.186.2022.12.22.04.30.24; Thu, 22 Dec 2022 04:30:40 -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=@gmail.com header.s=20210112 header.b="nvZY/9Yp"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235217AbiLVMWN (ORCPT + 67 others); Thu, 22 Dec 2022 07:22:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235038AbiLVMWL (ORCPT ); Thu, 22 Dec 2022 07:22:11 -0500 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6511118B24 for ; Thu, 22 Dec 2022 04:22:10 -0800 (PST) Received: by mail-pl1-x62e.google.com with SMTP id w20so1832313ply.12 for ; Thu, 22 Dec 2022 04:22:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=/4Ai+7/9tsJEaKUGjCwWP2+aABMhRcTmi+u/34V2hQw=; b=nvZY/9YpTr6jdTc70zjaWMLJZUKjioAcdLd/4C8tX6ze7rKLdE852vscXOkFqjlaF9 pLYIIy8ifrTQe4D2zsv5ltsg0oCwZ3z5qsDwuds5IV3RrFOB2/RiwXIBPYnPifCI3AEc VRT0rEkxIZBT9v4PExPhWXtNlfKkYqOqD222D4MRuvJYXjsS5JxNAK4W7oVZDeZoFeAs fx9jdR90hqF7s87xDjQCbnr/X+YNeLT6CywbuOVR1QuqtjKc3SpRtC9txaPtqdTqPGrL 8gQBIQRaMrKKgy20xASCXrna+tkY3p2xP1uR+mV3O4VXBS+NkrPvAp4LVsDIM9QnMW+y c7Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=/4Ai+7/9tsJEaKUGjCwWP2+aABMhRcTmi+u/34V2hQw=; b=El0wpjstlzdgUnu8tddJb79sf0VTPD6Z1KYWoXc/xa2QTNb86yVMUm2N/GgKeIDIR2 mZ2kdR/wfPa3Ig+d5xNxTjFCvE1ud+UsRzhxp4AuWPAMvdt+zEPS9j3fXuvH+3S6kUwn kpZ+QE6NSTAGFCYxidNuCXVIe6NmwX3MJBjGWkptigNkQzO9zrpQ2QWFXozhQCkakHRb bStckTqdSq8SkBpDopvhr2SB9fk6KRwrUd1a9BdNC+E3BDPpL79+AUrCCWcBD8BIS0Fz qkWfSeQkO7RQ96BSnuq/o2kUCXj6SFqBl2isJhQaKu8k4GmTgewBwRgyZPtyZp6lEsst 331w== X-Gm-Message-State: AFqh2krZWl5nvvUTirg2dWZ6+AATFuT1icPilnQJf75sFiKEW84/sGTO H3cKSfBB/a+NmFxlOkWAkAk= X-Received: by 2002:a17:902:9043:b0:189:bc50:b93b with SMTP id w3-20020a170902904300b00189bc50b93bmr4937485plz.3.1671711729735; Thu, 22 Dec 2022 04:22:09 -0800 (PST) Received: from mail.google.com ([103.135.102.144]) by smtp.gmail.com with ESMTPSA id b8-20020a1709027e0800b00189a7fbfd44sm378005plm.211.2022.12.22.04.22.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Dec 2022 04:22:09 -0800 (PST) Date: Thu, 22 Dec 2022 20:22:07 +0800 From: Changbin Du To: guoren@kernel.org Cc: palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu, mhiramat@kernel.org, changbin.du@intel.com, zong.li@sifive.com, rostedt@goodmis.org, boqun.feng@gmail.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Changbin Du Subject: Re: [PATCH V2] riscv: patch: Fixup lockdep warning in stop_machine Message-ID: <20221222122207.3ycdew6azfg6cqwy@mail.google.com> References: <20221120101049.2078117-1-guoren@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221120101049.2078117-1-guoren@kernel.org> X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * 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 On Sun, Nov 20, 2022 at 05:10:49AM -0500, guoren@kernel.org wrote: > From: Changbin Du > > The task of ftrace_arch_code_modify(_post)_prepare() caller is > stop_machine, whose caller and work thread are different tasks. The > lockdep checker needs the same task context, or it's wrong. That means > it's a bug here to use lockdep_assert_held because we don't guarantee > the same task context. > > kernel/locking/lockdep.c: > int __lock_is_held(const struct lockdep_map *lock, int read) > { > struct task_struct *curr = current; > int i; > > for (i = 0; i < curr->lockdep_depth; i++) { > ^^^^^^^^^^^^^^^^^^^ > struct held_lock *hlock = curr->held_locks + i; > ^^^^^^^^^^^^^^^^ > if (match_held_lock(hlock, lock)) { > if (read == -1 || !!hlock->read == read) > return LOCK_STATE_HELD; > > The __lock_is_held depends on current held_locks records; if > stop_machine makes the checker runing on another task, that's wrong. > > Here is the log: > [ 15.761523] ------------[ cut here ]------------ > [ 15.762125] WARNING: CPU: 0 PID: 15 at arch/riscv/kernel/patch.c:63 patch_insn_write+0x72/0x364 > [ 15.763258] Modules linked in: > [ 15.764154] CPU: 0 PID: 15 Comm: migration/0 Not tainted 6.1.0-rc1-00014-g66924be85884-dirty #377 > [ 15.765339] Hardware name: riscv-virtio,qemu (DT) > [ 15.765985] Stopper: multi_cpu_stop+0x0/0x192 <- stop_cpus.constprop.0+0x90/0xe2 > [ 15.766711] epc : patch_insn_write+0x72/0x364 > [ 15.767011] ra : patch_insn_write+0x70/0x364 > [ 15.767276] epc : ffffffff8000721e ra : ffffffff8000721c sp : ff2000000067bca0 > [ 15.767622] gp : ffffffff81603f90 tp : ff60000002432a00 t0 : 7300000000000000 > [ 15.767919] t1 : 0000000000000000 t2 : 73695f6b636f6c5f s0 : ff2000000067bcf0 > [ 15.768238] s1 : 0000000000000008 a0 : 0000000000000000 a1 : 0000000000000000 > [ 15.768537] a2 : 0000000000000000 a3 : 0000000000000000 a4 : 0000000000000000 > [ 15.768837] a5 : 0000000000000000 a6 : 0000000000000000 a7 : 0000000000000000 > [ 15.769139] s2 : ffffffff80009faa s3 : ff2000000067bd10 s4 : ffffffffffffffff > [ 15.769447] s5 : 0000000000000001 s6 : 0000000000000001 s7 : 0000000000000003 > [ 15.769740] s8 : 0000000000000002 s9 : 0000000000000004 s10: 0000000000000003 > [ 15.770027] s11: 0000000000000002 t3 : 0000000000000000 t4 : ffffffff819af097 > [ 15.770323] t5 : ffffffff819af098 t6 : ff2000000067ba28 > [ 15.770574] status: 0000000200000100 badaddr: 0000000000000000 cause: 0000000000000003 > [ 15.771102] [] patch_text_nosync+0x10/0x3a > [ 15.771421] [] ftrace_update_ftrace_func+0x74/0x10a > [ 15.771704] [] ftrace_modify_all_code+0xb0/0x16c > [ 15.771958] [] __ftrace_modify_code+0x12/0x1c > [ 15.772196] [] multi_cpu_stop+0x14a/0x192 > [ 15.772454] [] cpu_stopper_thread+0x96/0x14c > [ 15.772699] [] smpboot_thread_fn+0xf8/0x1cc > [ 15.772945] [] kthread+0xe2/0xf8 > [ 15.773160] [] ret_from_exception+0x0/0x14 > [ 15.773471] ---[ end trace 0000000000000000 ]--- > > Fixes: 0ff7c3b33127 ("riscv: Use text_mutex instead of patch_lock") > Cc: Changbin Du > Co-developed-by: Guo Ren > Signed-off-by: Guo Ren > Cc: Zong Li > Cc: Palmer Dabbelt > --- > Changes in v2: > - Rewrite commit log with lockdep explanation [Guo Ren] > - Rebase on v6.1 [Guo Ren] > > v1: > https://lore.kernel.org/linux-riscv/20210417023532.354714-1-changbin.du@gmail.com/ > --- > arch/riscv/kernel/patch.c | 7 ------- > 1 file changed, 7 deletions(-) > > diff --git a/arch/riscv/kernel/patch.c b/arch/riscv/kernel/patch.c > index 765004b60513..8619706f8dfd 100644 > --- a/arch/riscv/kernel/patch.c > +++ b/arch/riscv/kernel/patch.c > @@ -55,13 +55,6 @@ static int patch_insn_write(void *addr, const void *insn, size_t len) > bool across_pages = (((uintptr_t) addr & ~PAGE_MASK) + len) > PAGE_SIZE; > int ret; > > - /* > - * Before reaching here, it was expected to lock the text_mutex > - * already, so we don't need to give another lock here and could > - * ensure that it was safe between each cores. > - */ > - lockdep_assert_held(&text_mutex); > - > if (across_pages) > patch_map(addr + len, FIX_TEXT_POKE1); > > -- > 2.36.1 > Signed-off-by: Changbin Du Thanks!