From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sean Christopherson Subject: Re: [RFC PATCH 1/6] x86/alternative: assert text_mutex is taken Date: Wed, 29 Aug 2018 13:13:10 -0700 Message-ID: <20180829201309.GA7142@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> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Content-Disposition: inline In-Reply-To: <2694AE6F-2212-46C6-A570-6BAF265364FB@vmware.com> Sender: linux-kernel-owner@vger.kernel.org To: Nadav Amit Cc: Masami Hiramatsu , Thomas Gleixner , LKML , Ingo Molnar , X86 ML , Arnd Bergmann , linux-arch , Andy Lutomirski , Kees Cook List-Id: linux-arch.vger.kernel.org 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. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga17.intel.com ([192.55.52.151]:34215 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727392AbeH3AZx (ORCPT ); Wed, 29 Aug 2018 20:25:53 -0400 Date: Wed, 29 Aug 2018 13:13:10 -0700 From: Sean Christopherson Subject: Re: [RFC PATCH 1/6] x86/alternative: assert text_mutex is taken Message-ID: <20180829201309.GA7142@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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <2694AE6F-2212-46C6-A570-6BAF265364FB@vmware.com> Sender: linux-arch-owner@vger.kernel.org List-ID: To: Nadav Amit Cc: Masami Hiramatsu , Thomas Gleixner , LKML , Ingo Molnar , X86 ML , Arnd Bergmann , linux-arch , Andy Lutomirski , Kees Cook Message-ID: <20180829201310.ZRlvO4dTHJDktp1A2yr-5ZYHcBkjaQluPt2vuGIrQ7Q@z> 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.