Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1979465ybh; Tue, 14 Jul 2020 12:10:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGTf7QO/kyK/qytKNI8lClwQlmwk4Me7xZk4X0pR344LxZG62YObglxWRaiOe4fn7Oq9fE X-Received: by 2002:a50:ab53:: with SMTP id t19mr6092055edc.179.1594753829324; Tue, 14 Jul 2020 12:10:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594753829; cv=none; d=google.com; s=arc-20160816; b=Bzgx5aRVJId9eifSunO9KmzdJdWWr2wQ+oxoc7UxIQLsCds0T9OrZhFNsHDczZPGRQ eYss5Uz/XO3HApQvYlevlJwqBEMZFysnN4lEur58ZEzAnNxraRPi8pw4DZofySoFO5Q/ BK3D7au7vvAJOw1MfnftNDtGVkYBAj4Xvrja0Vw9EIRMtk+riHH/+m048KWeiMzDmvuE ykNvrn8Le6WEcrfVwW+1aWYK382l3CtHTRPXzTEYRL5u49s8rk2oJA5cDFlRD4CSvHg8 GGNqac91/5b/S2V1cNUEXkaEHZRBUyjQLET/E8h1ReTZ91YGBMTAxmiMaBvFvvVPXbNR QAAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nw4ihKopIpWaNCr5Y6kT67N/CHkCbR4jVRqwGCHV1nE=; b=l3og+IBFINTPmgaFSWx9N79qmKYcUOwCzpftqYxXFYVY+Lnusckepn1LqKBrQCDvQK WkMEaBp1qpYGwHH4mpNQ9GIJNuKqnZPt3zjKXSiJEX7VJ/egB/3xN3R1AipxT3rCWjXR sBuSzEsXVD6QIY5eLvYj9HGXy773r2EOqL5kI6A4m4G7I8EJHrTv+jKcMAuNP9VzGzI+ pUDdqII7FuIKj/2mqMxcnSnTW+AYhfYWT8J2Ihxt0OMc1v9rsvc/K/drh00gnwTFXwJ8 1EkJddGcgYSgg9xMXm0fn+/lqgUa0bNZosooU80cBknULZ0qigUEcceNkHaxwBRfJ+e+ jY4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=qqNHbLIR; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u29si11629991edi.469.2020.07.14.12.10.06; Tue, 14 Jul 2020 12:10:29 -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=fail header.i=@infradead.org header.s=casper.20170209 header.b=qqNHbLIR; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730710AbgGNTKA (ORCPT + 99 others); Tue, 14 Jul 2020 15:10:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730645AbgGNTJR (ORCPT ); Tue, 14 Jul 2020 15:09:17 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63755C061755; Tue, 14 Jul 2020 12:09:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=nw4ihKopIpWaNCr5Y6kT67N/CHkCbR4jVRqwGCHV1nE=; b=qqNHbLIRKZphbu96z3Z01iyAkK xtTx8ZQii1DUdG8kyK0YYXOcSXjEnHVyoj7Eg/NsGa90/rTkYyIqaKxMy9hCL+PXtwf2AFP/483ZQ LXEKQjAVEYA2SaW+de6+iJgle93ITzhc7DEkp2thdlvRDrICNez2U37jqNDEir0sZsMc/7tPeII+X BptAF25wpWXl0usrmNOOIp8tAxLssJ7MjcTSe9n4D4o6lWIyuWqGXJDgzu6b+QpM18bdc2Np+rren DZ7IkznmGYnLePINciciU0aV5f9qZeXCE85GMjO6I3eoNXGl2P0cI3tzt93UxQA5sP6bUvlUN9ong 9MiJpZ6g==; Received: from [2001:4bb8:188:5f50:f037:8cfe:627e:7028] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jvQIk-0005td-N3; Tue, 14 Jul 2020 19:09:15 +0000 From: Christoph Hellwig To: linux-kernel@vger.kernel.org Cc: "H. Peter Anvin" , Song Liu , Al Viro , Linus Torvalds , linux-raid@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 18/23] init: open code setting up stdin/stdout/stderr Date: Tue, 14 Jul 2020 21:04:22 +0200 Message-Id: <20200714190427.4332-19-hch@lst.de> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200714190427.4332-1-hch@lst.de> References: <20200714190427.4332-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Don't rely on the implicit set_fs(KERNEL_DS) for ksys_open to work, but instead open a struct file for /dev/console and then install it as FD 0/1/2 manually. Signed-off-by: Christoph Hellwig --- init/main.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/init/main.c b/init/main.c index 0ead83e86b5aa2..db0621dfbb0468 100644 --- a/init/main.c +++ b/init/main.c @@ -1457,15 +1457,19 @@ static int __ref kernel_init(void *unused) "See Linux Documentation/admin-guide/init.rst for guidance."); } +/* Open /dev/console, for stdin/stdout/stderr, this should never fail */ void console_on_rootfs(void) { - /* Open the /dev/console as stdin, this should never fail */ - if (ksys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0) - pr_err("Warning: unable to open an initial console.\n"); + struct file *file = filp_open("/dev/console", O_RDWR, 0); - /* create stdout/stderr */ - (void) ksys_dup(0); - (void) ksys_dup(0); + if (IS_ERR(file)) { + pr_err("Warning: unable to open an initial console.\n"); + return; + } + get_file_rcu_many(file, 2); + fd_install(get_unused_fd_flags(0), file); + fd_install(get_unused_fd_flags(0), file); + fd_install(get_unused_fd_flags(0), file); } static noinline void __init kernel_init_freeable(void) -- 2.27.0