Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp44163imm; Wed, 29 Aug 2018 13:28:52 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZQbRfloJtlw1U/HicrMPOQLRW3EHlOBsUPpV9PW2s+YF6zv8qBwTFQVb6/Vq5hmHpAHGiw X-Received: by 2002:a62:d1b:: with SMTP id v27-v6mr7216141pfi.87.1535574532662; Wed, 29 Aug 2018 13:28:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535574532; cv=none; d=google.com; s=arc-20160816; b=FuPNJUIviig6VsIbUtN5kXFxa7ZWVxuy5BieMNvWI7rmdJ4zuOF+dO090bXtHGc1S4 OZ7PbZ3oXnG3haAas9UJ4ZIfctFA+eNlWUNUywqoDGb11JQYRmVI56UJWw/78rSoCOMN aFahFS6unUQ3sza6cfFeC38aOyXFzhRxmlVPHb69U3D11QvNk+6ln05bjsM/TCRCcJaX /LIvEhF5co2jU/dBeZemPfRSOltQceo21PsvOhPZTSAla86fmuVcBUAa1KLhVkBUOOIq 5IU81iOzD6SCsAho+ymE01I3AM7EN8RCR8sdNmzlxidLhTJeXR9GA9dnblHjSSI5qD7A hK3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=q4haNGXYwS3ljh+8Fn0zv10vljxdRD9jpOD8nhIKZqA=; b=i7UYn9abgK9gUVuGmQQsVo8Wqr+8qZpdj11DXflPOKsNzFuP5cQ/YK8japta1a0xFY Ezc9U3mWxWJAUMMyYEtVaYYZ9Tz9P1QBbJIC/TDVA0usZcw9DWusHJ1sARKIZP/PHHP2 NqdhNHyQz7vEa9V8SUl5jRiy7ukE3Ludx1V+h4DEb28eu23qe71c8VpeWaTP1L8aRHLB ov5pjRArSivaoMG7CvF5CXZsYp8eZq3s+ybCAMbPtS/RW6TyMmH+TUhOWGQ8RnWTx9al KhSKpkBF4BqgghTx2aMjBB+K+QSl9SKkI6045AWVx+b/E5UA+EVWt6waZiyo6mWUFSBs +lXg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n7-v6si4279622plk.204.2018.08.29.13.28.37; Wed, 29 Aug 2018 13:28:52 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728645AbeH3AZy (ORCPT + 99 others); Wed, 29 Aug 2018 20:25:54 -0400 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 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Aug 2018 13:13:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,304,1531810800"; d="scan'208";a="84464412" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.20]) by fmsmga004.fm.intel.com with ESMTP; 29 Aug 2018 13:13:10 -0700 Date: Wed, 29 Aug 2018 13:13:10 -0700 From: Sean Christopherson To: Nadav Amit Cc: Masami Hiramatsu , Thomas Gleixner , LKML , Ingo Molnar , X86 ML , Arnd Bergmann , linux-arch , Andy Lutomirski , Kees Cook 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> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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.