Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1126581imm; Sun, 2 Sep 2018 10:37:44 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaIeMMqdrxigVLxIRwkYmewR7zclpLQvUp0pUHVRMLul6Yf3uz+iluLSSgsedC7q25Uvabs X-Received: by 2002:a62:d113:: with SMTP id z19-v6mr25459676pfg.98.1535909864397; Sun, 02 Sep 2018 10:37:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535909864; cv=none; d=google.com; s=arc-20160816; b=e4R6P1z7L46bEpIe+CKKYzfGzzZ52Vjq0xbKZilY2zgXKKKp+THXEYCT7f4kLianqa TpA7aIccecQK2c+5JzYQAB6F5iJT0o0Kr3LMg4t5pISSTbjVjdNnaogiQ79HHU5yck/j 8fVTyuAMU2FyT4bVAw2Ybqx+/wcdQQpdy7hjhFgvBfLE0VYLa6X7rM2k5ctnTM/yqIkP WeXMJQmHelcRU4ET9eFbjCxr5KadAKCfaGRH4julUKp+4MXfUEp/KV5TSyKYAHgsv4ig IbjSZn4S7h6wT2BN1Wo+tYURSPlxjMdsCcw6QQBHzdLBsmEeQeiSUu302uD3RbVv1VBg qscQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=KzW1/874wc9ZLTkeYalfokhAA0Qbsblk/wRnOR8lsoo=; b=xCavD/Zoya2JaaV1ZbLoafd7HmpI3qsb8WFY/rlfSuuKmn5iSa3JbmvvaAopXMMe3o /scH3qJy/M9n/pa1IFMD9DPOQb2mOcxThLN5c9/v3r+NtZric8El40FPW2o37lIu2yRX OR9t7VzWr738stDaXv9/zo53StISU71jHau0Vt0zKPeUe4wpC5rFBWmyZH0qemfSepLY lgCtKtC/v8q0j9ipBR9vqcK7FZN2mKYIoB2Dsz6FMggnl7Bi3kuiWxWlS9qBN/aSjiVH fUxR76VOHRfIN+sSZcIHGpyBbSx6WN2JxNhirpWJOjfoexC95jbOVw8LIh/2bQI9F3KX z33A== 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=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 21-v6si15552611pgg.588.2018.09.02.10.37.29; Sun, 02 Sep 2018 10:37:44 -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=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726963AbeIBVuO (ORCPT + 99 others); Sun, 2 Sep 2018 17:50:14 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:36915 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726065AbeIBVuN (ORCPT ); Sun, 2 Sep 2018 17:50:13 -0400 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Sun, 2 Sep 2018 10:33:40 -0700 Received: from sc2-haas01-esx0118.eng.vmware.com (sc2-haas01-esx0118.eng.vmware.com [10.172.44.118]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id B4F1540713; Sun, 2 Sep 2018 10:33:42 -0700 (PDT) From: Nadav Amit To: Thomas Gleixner CC: , Ingo Molnar , , Arnd Bergmann , , Dave Hansen , Nadav Amit , Nadav Amit , Jiri Kosina , Andy Lutomirski , Kees Cook , Dave Hansen Subject: [PATCH v2 1/6] Fix "x86/alternatives: Lockdep-enforce text_mutex in text_poke*()" Date: Sun, 2 Sep 2018 10:32:19 -0700 Message-ID: <20180902173224.30606-2-namit@vmware.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180902173224.30606-1-namit@vmware.com> References: <20180902173224.30606-1-namit@vmware.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: None (EX13-EDG-OU-002.vmware.com: namit@vmware.com does not designate permitted sender hosts) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org text_mutex is expected to be held before text_poke() is called, but we cannot add a lockdep assertion since kgdb does not take it, and instead *supposedly* ensures the lock is not taken and will not be acquired by any other core while text_poke() is running. The reason for the "supposedly" comment is that it is not entirely clear that this would be the case if gdb_do_roundup is zero. Add a comment to clarify this behavior, and restore the assertions as they were before the recent commit. This partially reverts commit 9222f606506c ("x86/alternatives: Lockdep-enforce text_mutex in text_poke*()") Cc: Jiri Kosina Cc: Andy Lutomirski Cc: Kees Cook Cc: Dave Hansen Fixes: 9222f606506c ("x86/alternatives: Lockdep-enforce text_mutex in text_poke*()") Reviewed-by: Masami Hiramatsu Tested-by: Masami Hiramatsu Suggested-by: Peter Zijlstra Signed-off-by: Nadav Amit --- arch/x86/kernel/alternative.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index b9d5e7c9ef43..e9be18245698 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -684,6 +684,11 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode, * It means the size must be writable atomically and the address must be aligned * in a way that permits an atomic write. It also makes sure we fit on a single * page. + * + * Context: Must be called under text_mutex. kgdb is an exception: it does not + * hold the mutex, as it *supposedly* ensures that no other core is + * holding the mutex and ensures that none of them will acquire the + * mutex while the code runs. */ void *text_poke(void *addr, const void *opcode, size_t len) { @@ -698,8 +703,6 @@ void *text_poke(void *addr, const void *opcode, size_t len) */ BUG_ON(!after_bootmem); - lockdep_assert_held(&text_mutex); - if (!core_kernel_text((unsigned long)addr)) { pages[0] = vmalloc_to_page(addr); pages[1] = vmalloc_to_page(addr + PAGE_SIZE); -- 2.17.1