Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp230900imm; Wed, 29 Aug 2018 19:28:14 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZkyCSbOTx/PT2i2bnEYpleFqgDwHM96/lNqptbA03jYHXYRdj3APyw+d6Go951iP6LdWVo X-Received: by 2002:a62:868b:: with SMTP id x133-v6mr5458538pfd.252.1535596094677; Wed, 29 Aug 2018 19:28:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535596094; cv=none; d=google.com; s=arc-20160816; b=0k6Ly1pLA4+bukZgoaz2LsV08olw1BLrV8zHEHuR3NuBXtbTMZOPRp1VZB7ZK2q2sL i2bgq0XF8Qt6GdGm7MywJunjTbHAXX2gDh9F4dcYJcp+4lvR0kKY0PeyTkhusx3JbFHm sAaC8NWG3TOF86yzK4g7Lk2VGuezl9MdXJVC0AC0qKpbH6LQO4aVq6ggXhZCNEyjeJcZ JPba4e892xvK0Wi2jxCDKNCWWYZvm++2ghvpqgRtdjFXwFjHUZig7IkjQyiipFtojFOq TWQeW+NRm4PlahkcmXbkD7ELbr233VGM9I36IzVduqekZNsEjxrZor+iWyY1W6gfkTFw tu4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature:arc-authentication-results; bh=8tQoMPAp0HllvfOSzmV+JMLqoZKp4O6RsTkx6NVEzFw=; b=yPTcoaDBwJ8Vzg99MFrWnjS4yg80XDCSfxRiR/tyxr7algJTz6HxzCh04vr9UiSnaP yPUehi8U+b9uI4U0MhtUVdMgpOOKKTF7GSvf7OLiBmaaA66fWp/LmsLQMJUh43HBlKZv IOL/rvi5Fz68JlD3BuYvB55N39SQexBqbG85oOzrMvgvjN4eSB/zOIzJeETPtn6tifpK 8WDXisa3rUj15lkLCjhl+gv64z1IFlL2dzhWMBkg6eA39TMx4Lqf5OXlwTurKn/LGoyX wBvtlyFYGpzOS69i/DQ+hK6CbLxfDgIeyyZ/9WPQ1ZRjsm9Hts+rkF3fMr5WcYu/ja3p WYPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2cbHO+YN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k2-v6si4846477pgq.503.2018.08.29.19.27.59; Wed, 29 Aug 2018 19:28:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2cbHO+YN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727278AbeH3G0m (ORCPT + 99 others); Thu, 30 Aug 2018 02:26:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:60510 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727178AbeH3G0m (ORCPT ); Thu, 30 Aug 2018 02:26:42 -0400 Received: from devbox (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D40722054F; Thu, 30 Aug 2018 02:26:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1535596012; bh=oJHadjBXSG1yLxCcf1sLQxT3FxQrZsBJi6liTeaeSKk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=2cbHO+YNiuqjCmjX0Gkxk26veXwxOlWZl4eMuR62We1YgG2+5g2+2uop7InQs4EOd Cs7UCsPa3u5pqD7HWMVjk1KkiEDHjGbfqFlS2MZvaBjwf04X9DDM75IjaoVZpZyIhX oMh9rio4k+HyGBqllpwTzh7l3kkTFfZWhMsI8qUE= Date: Thu, 30 Aug 2018 11:26:49 +0900 From: Masami Hiramatsu To: Sean Christopherson Cc: Nadav Amit , Masami Hiramatsu , Thomas Gleixner , LKML , Ingo Molnar , X86 ML , Arnd Bergmann , linux-arch , Andy Lutomirski , Kees Cook , Jason Wessel Subject: Re: [RFC PATCH 1/6] x86/alternative: assert text_mutex is taken Message-Id: <20180830112649.4b774f401d99a8b98e12008c@kernel.org> In-Reply-To: <20180829210006.GA7166@linux.intel.com> References: <20180829081147.184610-1-namit@vmware.com> <20180829081147.184610-2-namit@vmware.com> <20180829175936.fb27b3bf13da819a9a971f07@kernel.org> <1F547CEE-B5D9-42A0-8093-2C5555BACE26@vmware.com> <2694AE6F-2212-46C6-A570-6BAF265364FB@vmware.com> <20180829201309.GA7142@linux.intel.com> <58345C1F-8FF3-4F49-AF2F-B4789DF50CC7@vmware.com> <20180829210006.GA7166@linux.intel.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 29 Aug 2018 14:00:06 -0700 Sean Christopherson wrote: > On Wed, Aug 29, 2018 at 08:44:47PM +0000, Nadav Amit wrote: > > at 1:13 PM, Sean Christopherson wrote: > > > > > On Wed, Aug 29, 2018 at 07:36:22PM +0000, Nadav Amit wrote: > > >> at 10:11 AM, Nadav Amit wrote: > > >> > > >>> at 1:59 AM, Masami Hiramatsu wrote: > > >>> > > >>>> On Wed, 29 Aug 2018 01:11:42 -0700 > > >>>> Nadav Amit wrote: > > >>>> > > >>>>> Use lockdep to ensure that text_mutex is taken when text_poke() is > > >>>>> called. > > >>>>> > > >>>>> Actually it is not always taken, specifically when it is called by kgdb, > > >>>>> so take the lock in these cases. > > >>>> > > >>>> Can we really take a mutex in kgdb context? > > >>>> > > >>>> kgdb_arch_remove_breakpoint > > >>>> <- dbg_deactivate_sw_breakpoints > > >>>> <- kgdb_reenter_check > > >>>> <- kgdb_handle_exception > > >>>> <- __kgdb_notify > > >>>> <- kgdb_ll_trap > > >>>> <- do_int3 > > >>>> <- kgdb_notify > > >>>> <- die notifier > > >>>> > > >>>> kgdb_arch_set_breakpoint > > >>>> <- dbg_activate_sw_breakpoints > > >>>> <- kgdb_reenter_check > > >>>> <- kgdb_handle_exception > > >>>> ... > > >>>> > > >>>> Both seems called in exception context, so we can not take a mutex lock. > > >>>> I think kgdb needs a special path. > > >>> > > >>> You are correct, but I don’t want a special path. Presumably text_mutex is > > >>> guaranteed not to be taken according to the code. > > >>> > > >>> So I guess the only concern is lockdep. Do you see any problem if I change > > >>> mutex_lock() into mutex_trylock()? It should always succeed, and I can add a > > >>> warning and a failure path if it fails for some reason. > > >> > > >> Err.. This will not work. I think I will drop this patch, since I cannot > > >> find a proper yet simple assertion. Creating special path just for the > > >> assertion seems wrong. > > > > > > It's probably worth expanding the comment for text_poke() to call out > > > the kgdb case and reference kgdb_arch_{set,remove}_breakpoint(), whose > > > code and comments make it explicitly clear why its safe for them to > > > call text_poke() without acquiring the lock. Might prevent someone > > > from going down this path again in the future. > > > > I thought that the whole point of the patch was to avoid comments, and > > instead enforce the right behavior. I don’t understand well enough kgdb > > code, so I cannot attest it does the right thing. What happens if > > kgdb_do_roundup==0? > > As is, the comment is wrong because there are obviously cases where > text_poke() is called without text_mutex being held. I can't attest > to the kgdb code either. My thought was to document the exception so > that if someone does want to try and enforce the right behavior they > can dive right into the problem instead of having to learn of the kgdb > gotcha the hard way. Maybe a FIXME is the right approach? No, kgdb ensures that the text_mutex has not been held right before calling text_poke. So they also take care the text_mutex. I guess kgdb_arch_{set,remove}_breakpoint() is supposed to be run under a special circumstance, like stopping all other threads/cores. In that case, we can just check the text_mutex is not locked. Anyway, kgdb is a very rare courner case. I think if CONFIG_KGDB is enabled, lockdep and any assertion should be disabled, since kgdb can tweak anything in the kernel with unexpected ways... Thank you, -- Masami Hiramatsu