Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3839465imm; Mon, 25 Jun 2018 05:34:21 -0700 (PDT) X-Google-Smtp-Source: ADUXVKISKJPkz8N/CforScDSwyNATfsaMEdgZl/gaS8XhJyYl+3ZzASFeSoTOClythso+EPv+kxk X-Received: by 2002:a63:8648:: with SMTP id x69-v6mr7105476pgd.172.1529930061613; Mon, 25 Jun 2018 05:34:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529930061; cv=none; d=google.com; s=arc-20160816; b=hlmrw6ExR/WJdQGcb056EAeBTKtwXqfzd8a9WEn8SdTw2ka1392vB2u2PhOMuFFFX6 QGgl3cQ7kS9yfndVKE7kfwWrjSfBRbbqz+yzY4rVAiZk7GdqTwX15S6e7sGT/2E0CZQ2 wmxeL17dwax+bW9F7dhfbPXcTnp2UN6AATfeR296OF591Yslw2uXAGnjToqsviOniw5F bNNCT2v/4VRHWAX+rF/kNVc1OdX2EI6yWgaa3KJd83NGk5WGDzcmPb8L52LJK+xbopI4 U35LYXtUAdqyh/BamuGCc0Ec3vnuFdKOXmsjDSA+2jPXfrkCIEmrREMBNpzkxR3gh5iv hPmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=hv9kgK4BvTix7pTyYy5PUrlPwxEkyZbVY8rE50tBZOU=; b=Nve6GiKcGbuprP1g4x+mk+L02LrTq/fXWGpWYhg0lPO7bUErAH47XmX59cwv+GfS1s nIIIctGNKwNdvIRZAOkY66fMpwOtDVn76LiorCOYvbTGaJlCrxqBULmTt41ihJKpbq5X HKmFrSEJoZhS2in/z/r7o4UU9wtfPSSyJ/KNZgE3/rw1ZrcCjcbIABl/bjYkn6gu7zZQ rQw3dcYFsqFa+cVsszZ4fRZG6myCOYvziJ8hEEdVOISm97Anj+nBbyJ5u+/qYfPfR5nq ZQ9bKFWTUhZMptCkcF/jI3yiiXos1Ua8p2m9xgXgou8wDd3MhCSKr1c5GYUl7nK5nAh5 L9AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=gDqrYbgK; 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=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d24-v6si13706576plr.302.2018.06.25.05.34.07; Mon, 25 Jun 2018 05:34:21 -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=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=gDqrYbgK; 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=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933678AbeFYMdY (ORCPT + 99 others); Mon, 25 Jun 2018 08:33:24 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:43722 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932404AbeFYMdW (ORCPT ); Mon, 25 Jun 2018 08:33:22 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w5PCSlqg148661; Mon, 25 Jun 2018 12:33:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : references : in-reply-to : from : date : message-id : subject : to : cc : content-type; s=corp-2017-10-26; bh=hv9kgK4BvTix7pTyYy5PUrlPwxEkyZbVY8rE50tBZOU=; b=gDqrYbgK09UD0ZxIGYhPekkzipcmY7oDZuUsbSwAw7gHgjoljw7v20buaYkNAdcHsnSp 4k0yRdhfYrfN1rP0HGqULysma6VMynPFwFuTVMgl+u2GooCvNcvanpUsv+xEXLTC5e+b nDkghRWZ/2dcnXa4T0aIIxaOnvoa5gGzv6bEkCoujR1XuKg87PkyMQm84IgEQBsXJbEL UxfpBL1Axk7WYRC9q08puLvUkYk9c3mh9LD9ySBAFvhUQXJkA0rPwBTev1RXUqfZgLQu r8ZnPgezRdyC7SCW2GAmJVbgpzi14+TCom9Jf0EOWhjrDynzXNPq4JmTWpHE5NGU63vH Jw== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2jt8a7jf8s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 25 Jun 2018 12:33:21 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w5PCXIN7026265 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 25 Jun 2018 12:33:18 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w5PCXIrq010631; Mon, 25 Jun 2018 12:33:18 GMT Received: from mail-ot0-f169.google.com (/74.125.82.169) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 25 Jun 2018 05:33:18 -0700 Received: by mail-ot0-f169.google.com with SMTP id w13-v6so14813920ote.11; Mon, 25 Jun 2018 05:33:18 -0700 (PDT) X-Gm-Message-State: APt69E0y1T7rYHLtsz65PjThkV/uN8uec0DBzj2uG0YOyR6HNwzK3KBb I16ueYgb4k3WXS1qfcBZg756jKWLoNoo30r9IWI= X-Received: by 2002:a9d:55d0:: with SMTP id z16-v6mr7700606oti.176.1529929997791; Mon, 25 Jun 2018 05:33:17 -0700 (PDT) MIME-Version: 1.0 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> In-Reply-To: <20180625092229.GW2494@hirez.programming.kicks-ass.net> From: Pavel Tatashin Date: Mon, 25 Jun 2018 08:32:41 -0400 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v12 01/11] x86: text_poke() may access uninitialized struct pages To: peterz@infradead.org 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 Content-Type: text/plain; charset="UTF-8" X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8934 signatures=668703 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1806250146 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Peter, > It _should_ all work.. but scary, who knows where this early stuff ends > up being used. I have tested this patch, and the following patch, which moves the jump label init early and it works as Thomas describes: on_each_cpu() ends up calling only the current CPU. Also, you mentioned: > And I added a sync_core() in text_poke_early(), which I think we need > for this. text_poke_bp() ends up calling on_each_cpu(do_sync_core, NULL, 1); which is called on boot CPU, and thus sync_core is called. If we keep this patch we can remove sync_core() change from the next patch. 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); } Also, modify text_poke_early to call sync_core(). Of course, this way won't prevent us from having some other code calling text_poke() in the future during boot where uninitialized memory access is possible. If text_poke() is called sufficiently early, it will fail because virt_to_page() will fail, but there is an interval, where virt_to_page() succeeds (after paging_init()), but pages are not yet initialized (before mem_init()). To safeguard us we could add: BUG_ON(!after_bootmem); To text_poke() Thank you, Pavel