Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp795777pxa; Wed, 5 Aug 2020 13:00:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCz9XyOz5ITMHFVLWy/23wkC20AefT6s8AI4//Pp+GuqhffXCV2BMwBQ3tfiCC4QjZhjA1 X-Received: by 2002:a17:906:68b:: with SMTP id u11mr1006995ejb.143.1596657621355; Wed, 05 Aug 2020 13:00:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596657621; cv=none; d=google.com; s=arc-20160816; b=d7VrI/MSOCdMgrDcifejt1JXiGOmxWasrCBVyhVWF30PC8/CVi6/z06/YW4wDulvF3 Do4NCzaKlZmXk42PGuy+nG6RN7K02LsOg2O3/MbN918lWFRX8qT9Pgcie2gPl5e3sT07 PQ2gQKn21NlQrbeAXo0WkE1NyNOL0gH4Zfm6a3ADWUaRaspY6DaJjWVx6AKPunts9Q6/ 0NNT3MhY4Z5wNu3V+iMjW7pegThFCjrSL0ZpGN6bwBdwyjz9gjre6/NXJ7ApXXJXKEsE hHLfNZegbzT+6WiFZw8Alu+FKvCjlmxM1fwEbc35j3hoH53uq7PLHfW9eCS3FtQPpBEo B04w== 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:dkim-signature; bh=rz+460zN+OkszOn8+vBru36XCbCu8scZ/4ePoWYVtUg=; b=rrD31TEmIymCRRBBzGaCps1DL6ZUbF9fWKwm9BHeAA8RmSFdEWh9G9MzkBej9sw5jc i7cTMm40LA7pFINmOCmhSjk2I8pzFGK/GyktTMqF/bmzUgEqUN2ucR97Vc5f95yLRPmi MasEfXgHE/jzGv8j21Maa7H3WsUXNp7L0g5/LWnOaCREPZPsLBVVtCMlW8hlRftgOB+n cqb9LOxi9lv9udmF+qvYmPZQ58qJPzF2582dGSjgT1/6wuTnMyAcxCxnPJuzgIelo0Yk Oq3l1IIvlZIwPKQg92puwtEahrV3dy3XmxUrhc9+TZJV4qPwjPQ2BjC5nQNeXAJEXsbF mymg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=F7rF0IMW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cb1si1753603edb.88.2020.08.05.12.59.58; Wed, 05 Aug 2020 13:00:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=F7rF0IMW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729756AbgHET6z (ORCPT + 99 others); Wed, 5 Aug 2020 15:58:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727920AbgHEQmM (ORCPT ); Wed, 5 Aug 2020 12:42:12 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 267E1C094244 for ; Wed, 5 Aug 2020 06:26:40 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id p20so5798446wrf.0 for ; Wed, 05 Aug 2020 06:26:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=rz+460zN+OkszOn8+vBru36XCbCu8scZ/4ePoWYVtUg=; b=F7rF0IMWYFHctSXsi4L5jkI7s2rDEICofDZEIFb/Mnc0olQ1F9dR20+N7FHkksIJge SmA4W+izSWd2xpr3HvHbsiAy+2J1K2AMgrnaQYZfVaf/c7SlSw0yYJXZZUv7p6LI3a9x D3IL3vF8GSwDnq/h9THfUWuSperQHqsQwJvjVuh5vhouVgLuNqrJ899nDX2jWX6RbkR1 63wyQypBQ963B/M2vWSesAEOtHwCqDpsPef7QwKCS2VITQpHYr0zVrx+NxMd6fDsFBHA rHmBhDoDO4Y4D9FJa9440x3SsTx2KeUrt7UW4Rc8UBLwgdJz5Jsph0fgwQqOakfu3+FB QZ1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=rz+460zN+OkszOn8+vBru36XCbCu8scZ/4ePoWYVtUg=; b=G5ik7JP//DytjiDkyFf3qJowtQz5zWa7IofNbSW8Sj5gmF40cj5aMPS4BEpeKTUjoj GIMETKCBXsTNb+LwBEeND47xoQiwhghTYyU1UwFZUcYpDK3Mcwt4EvmguE0yQ9mkiFo9 rNuFpEvO775uuXt/eNtuJvazTziGvtGx6lsAeTqx3l3KUWn5J1Dw8qjAyduES+qN2De1 td+lGdC0u2cbUk1ZNpsYVUREv17Q9ec2bEdq5nKy1HeevTzfGojx6nbqV0nWZCCg/Dtm nF335uAKjO9ztwUL9VkPy+SlimnsNwVt3+8oC/+qeGFwnXalKWC52tm9BltGNlT+nAHH D0iw== X-Gm-Message-State: AOAM533ZhL5PMSdLjCVSJoA1IpHpIdULxHwHCA3uM8RAz9t5IMKxW4WT lciJrA+VHxLxfwq32niZZVUH8Q== X-Received: by 2002:adf:cf10:: with SMTP id o16mr2613948wrj.380.1596633996070; Wed, 05 Aug 2020 06:26:36 -0700 (PDT) Received: from elver.google.com ([100.105.32.75]) by smtp.gmail.com with ESMTPSA id p15sm2718271wrj.61.2020.08.05.06.26.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Aug 2020 06:26:34 -0700 (PDT) Date: Wed, 5 Aug 2020 15:26:29 +0200 From: Marco Elver To: bp@alien8.de, dave.hansen@linux.intel.com, fenghua.yu@intel.com, hpa@zytor.com, linux-kernel@vger.kernel.org, mingo@redhat.com, syzkaller-bugs@googlegroups.com, tglx@linutronix.de, tony.luck@intel.com, x86@kernel.org, yu-cheng.yu@intel.com, peterz@infradead.org, jgross@suse.com, sdeep@vmware.com, virtualization@lists.linux-foundation.org, kasan-dev@googlegroups.com Cc: syzbot Subject: [PATCH] x86/paravirt: Add missing noinstr to arch_local*() helpers Message-ID: <20200805132629.GA87338@elver.google.com> References: <0000000000007d3b2d05ac1c303e@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: <0000000000007d3b2d05ac1c303e@google.com> User-Agent: Mutt/1.14.4 (2020-06-18) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add missing noinstr to arch_local*() helpers, as they may be called from noinstr code. On a KCSAN config with CONFIG_PARAVIRT=3Dy, syzbot stumbled across corrupt IRQ trace state, with lockdep_assert_irqs_enabled() failing spuriously. When enabling CONFIG_DEBUG_LOCKDEP=3Dy, we get a warning about DEBUG_LOCKS_WARN_ON(!lockdep_hardirqs_enabled()) which we had seen before due to KCSAN-lockdep recursion. Due to "lockdep: Prepare for NMI IRQ state tracking", KCSAN was changed to use non-raw local_irq_{save,restore}(), assuming there is no more KCSAN-lockdep recursion. It turns out that the arch_local*() helpers in paravirt.h were missing noinstr, as they themselves are used from noinstr code that is called =66rom lockdep. When inserting debug-code that warns us if lockdep is in the stacktrace from KCSAN, we get, RIP: 0010:kcsan_setup_watchpoint[...] [...] Call Trace: arch_local_save_flags+0x11/0x30 arch/x86/include/asm/paravirt.h:765 check_preemption_disabled+0x51/0x140 lib/smp_processor_id.c:19 __this_cpu_preempt_check+0x18/0x20 lib/smp_processor_id.c:65 lockdep_hardirqs_off+0xaa/0x130 kernel/locking/lockdep.c:3801 trace_hardirqs_off+0x14/0x80 kernel/trace/trace_preemptirq.c:76 __raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:108 [inline] _raw_spin_lock_irqsave+0x48/0x90 kernel/locking/spinlock.c:159 wake_up_new_task+0x2c/0x270 kernel/sched/core.c:3338 _do_fork+0x27b/0x4f0 kernel/fork.c:2474 kernel_thread+0x85/0xb0 kernel/fork.c:2502 create_kthread kernel/kthread.c:315 [inline] kthreadd+0x427/0x500 kernel/kthread.c:634 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:294 pointing to arch_local_save_flags() in paravirt.h, which is called from noinstr functions in smp_processor_id.c, which in turn are called from lockdep. Link: https://lkml.kernel.org/r/0000000000007d3b2d05ac1c303e@google.com Reported-by: syzbot+8db9e1ecde74e590a657@syzkaller.appspotmail.com Signed-off-by: Marco Elver --- arch/x86/include/asm/paravirt.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravir= t.h index 3d2afecde50c..a606f2ba2b5e 100644 --- a/arch/x86/include/asm/paravirt.h +++ b/arch/x86/include/asm/paravirt.h @@ -760,27 +760,27 @@ bool __raw_callee_save___native_vcpu_is_preempted(lon= g cpu); ((struct paravirt_callee_save) { func }) =20 #ifdef CONFIG_PARAVIRT_XXL -static inline notrace unsigned long arch_local_save_flags(void) +static inline noinstr unsigned long arch_local_save_flags(void) { return PVOP_CALLEE0(unsigned long, irq.save_fl); } =20 -static inline notrace void arch_local_irq_restore(unsigned long f) +static inline noinstr void arch_local_irq_restore(unsigned long f) { PVOP_VCALLEE1(irq.restore_fl, f); } =20 -static inline notrace void arch_local_irq_disable(void) +static inline noinstr void arch_local_irq_disable(void) { PVOP_VCALLEE0(irq.irq_disable); } =20 -static inline notrace void arch_local_irq_enable(void) +static inline noinstr void arch_local_irq_enable(void) { PVOP_VCALLEE0(irq.irq_enable); } =20 -static inline notrace unsigned long arch_local_irq_save(void) +static inline noinstr unsigned long arch_local_irq_save(void) { unsigned long f; =20 --=20 2.28.0.163.g6104cc2f0b6-goog