Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3917654imm; Mon, 25 Jun 2018 06:50:31 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJH9E2qWQUTK6e2aOLzl1BKIMh0ETqhYjG3QftBb9oEVz2s+q74FLuF6DQT5EBAYnmonBh4 X-Received: by 2002:a63:7d06:: with SMTP id y6-v6mr10796194pgc.356.1529934631668; Mon, 25 Jun 2018 06:50:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529934631; cv=none; d=google.com; s=arc-20160816; b=Oy2rZ2JT0u/1S/xBc6IE11rMFaHCQTxiAY02fxQdto+7I95OF/tYQCN6oQBeIqj/XB MRou/XAW88BI8trOZZ3A68EdP7Fk8XFoFAJwvCK9diJR8+wDKVG2QfNFP7gmy2zDRV/t RwXUFvr+e5QbLl3hEsjbnzecQXPbXsksPyk3k8PfWRuWVcv3IDYCr4+f+9yMsbyxlTnN vvWQDuR8Hs1U8YkPw8S37FdURZginv1pnuVGwmNjvlORMzCpewwaaeDKY6EalybqvbEG N9UvL7HSQHGigRP12CkaLR7j0QS8NcHONz72C4ZJTZt7BJMg3NfPQSfRpBIdAYav5IXg SSHA== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=rJrcEJWv2SyO0fTBpNPxZM6DdoMUkg2ZxTOUkjJVMJE=; b=gjeAQXB7Yp1I/fjVxO1rxpG9oEJ/Cs8VpH8UWbCW8hhtjxDQXYius0WhU/O59Skf1E oEPPyr0c1LYTHceaf6LKFWFiLNirqpL1yzCt+EWhg+EQoVgm5TRkdqU2JL9LGmAN1Yme SPWpW1kzI1M/oKYhsJiLYjAZ22RuQ+CYZ87YH/9IJHYaR69bz4CcL66JVXrmLaxd1OKY ts5bKzx8ud6w93Ap0GL/tUjuJCNKbWE254SVZx4PnEFaZGVoa7jywS1nPOPlhPrTpsQe /phEPpHW2AKrUBZ9biasBUJ8ZqEYbxbyyLzQdZvb8Xk75GwYMWjxC127gMV2Lc4nHZ8s WUtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=ZE4HAxWu; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r11-v6si827263plj.40.2018.06.25.06.50.17; Mon, 25 Jun 2018 06:50:31 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=ZE4HAxWu; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934023AbeFYNtP (ORCPT + 99 others); Mon, 25 Jun 2018 09:49:15 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:45698 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933983AbeFYNtO (ORCPT ); Mon, 25 Jun 2018 09:49:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=rJrcEJWv2SyO0fTBpNPxZM6DdoMUkg2ZxTOUkjJVMJE=; b=ZE4HAxWupcHxqyybM5uNyvb0B JQ9xniAbkNFd4TTcfZ6zuS1cNZyeTOH9cTNxMVaeEMqkNHuhbooaHK0t19Q1S588+T45/Vj6YMFN6 FHrA37oN3poenroLdIVZDWzHFNNa2IEVD8wb/JRrnM3eCv0/vQjfbge8KAwvQeRniD0piF7b9XYpl VsrpCmnPWVq4vvY/Z8AkZ3/6bJnOD+gzSL/803I+feKIiwrVN5OG2swwpjOEeQEcfXkB8bmtsZ68N MiYeNhh9zzHvimr2l1WomESWTUZGA6rpc9q+o5sqqmBsOt4hGExLr2DhskQiA8628/bEaWtbd6uAp em+z6f5bw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fXRrQ-0006TM-V2; Mon, 25 Jun 2018 13:48:53 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 5EC722029F1DB; Mon, 25 Jun 2018 15:48:51 +0200 (CEST) Date: Mon, 25 Jun 2018 15:48:51 +0200 From: Peter Zijlstra To: Pavel Tatashin Cc: tglx@linutronix.de, Steven Sistare , Daniel Jordan , linux@armlinux.org.uk, schwidefsky@de.ibm.com, Heiko Carstens , John Stultz , sboyd@codeaurora.org, x86@kernel.org, LKML , mingo@redhat.com, hpa@zytor.com, douly.fnst@cn.fujitsu.com, prarit@redhat.com, feng.tang@intel.com, Petr Mladek , gnomes@lxorguk.ukuu.org.uk, linux-s390@vger.kernel.org, Steven Rostedt Subject: Re: [PATCH v12 01/11] x86: text_poke() may access uninitialized struct pages Message-ID: <20180625134851.GB2494@hirez.programming.kicks-ass.net> References: <20180621212518.19914-1-pasha.tatashin@oracle.com> <20180621212518.19914-2-pasha.tatashin@oracle.com> <20180625081429.GS2494@hirez.programming.kicks-ass.net> <20180625090915.GV2494@hirez.programming.kicks-ass.net> <20180625092229.GW2494@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 25, 2018 at 08:32:41AM -0400, Pavel Tatashin wrote: > > It _should_ all work.. but scary, who knows where this early stuff ends > > up being used. > > I have tested this patch Sure,.. but call me paranoid. > However, the other way to fix this bug is to change: > arch/x86/kernel/jump_label.c > > -void arch_jump_label_transform(struct jump_entry *entry, > +void __ref arch_jump_label_transform(struct jump_entry *entry, > enum jump_label_type type) > { > + void *(*poker)(void *, const void *, size_t) = NULL; > + > + if (unlikely(!after_bootmem)) > + poker = text_poke_early; > + > mutex_lock(&text_mutex); > - __jump_label_transform(entry, type, NULL, 0); > + __jump_label_transform(entry, type, poker, 0); > mutex_unlock(&text_mutex); > } No need to elide that mutex I think, by going through the normal static_key_enable() stuff you already take a whole bunch of them, and they should work early just fine (no contention etc.). Also, I think the better condition is @early_boot_irqs_disabled, until we enable IRQs for the first time, text_poke_early() should be fine. And once we enable interrupts, all that other crud should really be working. This gives: diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c index e56c95be2808..425ba6102828 100644 --- a/arch/x86/kernel/jump_label.c +++ b/arch/x86/kernel/jump_label.c @@ -46,6 +46,9 @@ static void __jump_label_transform(struct jump_entry *entry, const unsigned char default_nop[] = { STATIC_KEY_INIT_NOP }; const unsigned char *ideal_nop = ideal_nops[NOP_ATOMIC5]; + if (early_boot_irqs_disabled) + poker = text_poke_early; + if (type == JUMP_LABEL_JMP) { if (init) { /* > Also, modify text_poke_early to call sync_core(). and that.