From patchwork Wed Nov 14 08:10:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Ivanov X-Patchwork-Id: 997509 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cambridgegreys.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="FYfegRvI"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="m4UlSt5J"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42vxyg1y94z9s7h for ; Wed, 14 Nov 2018 19:11:07 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=C4Dl1Mq9OOQ1cFb3H8cxfBOLkTILq6nYl9ERbQ6gWKg=; b=FYfegRvINUc4cEw4b5Y+G3kseC A/SAziH+E+HU0Jeqa0P4LlE3g9XxPaIXfVebRWKbuYKXFu0b5kY5srkEo6Uob2PLrat5ChnxCEeC6 MJEeyknJeK3e6uR505rqlEcKBBFr2xkzN+/odUiTLfRhObxZdACA4jXsEz3eBg019Xb43k7sm1la1 9493zBNcJQ8k+/x4kpv75dea2J4+ChBHcGwr7D8pz/uMG+2Equ4x+Mt1OrGXpFuLNB+QE8DFkQf/8 k12yGc+ftTDR2ksXwWQO5925DnevUignCUa9bAIoIloU0CVR1X/vDBad0EDVkSnpDcybj0CTyze8x C2NEmAKw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMqGI-0008Sx-9S; Wed, 14 Nov 2018 08:10:58 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMqGA-0008Ju-03 for linux-um@bombadil.infradead.org; Wed, 14 Nov 2018 08:10:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: 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=DcK9cu1r5J5Cm579qKT6gR6Ruoi+TgQDCuFD8kcq9zM=; b=m4UlSt5JEARc1eOqMJRPgszO1 APW+gz6Fe+LAjtSeyWWPRbIeGy232UDysTLuT3eiBKdbfm44wN9Yempv0KKoPkqFMMvvEpfLE3AET kQs2LH0xF8OSEtdwHldTJk8qnjayxBdJRv02US2DVifnUq7B55d9Z60i4u3bN+t/hq5uOdXO2oaJR dW6bLXwCtLQCtwVcuUykLAWgUyDV8A4CDJl57anDh0DV87X6decy6mzKiW9g0kKJV/9gLGtzWMOkL Z4jmXiIk3lb5OmoqtB8Q9NCoK1DOiTON0LDwsAYmDOlcQKfqnc47+RuV/+ffvLJT3yWViMBY/2msQ u6UCSq0Gw==; Received: from ivanoab6.miniserver.com ([5.153.251.140] helo=www.kot-begemot.co.uk) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMqG5-0003E9-AN for linux-um@lists.infradead.org; Wed, 14 Nov 2018 08:10:46 +0000 Received: from [192.168.17.6] (helo=smaug.kot-begemot.co.uk) by www.kot-begemot.co.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gMqFr-0002XZ-C3; Wed, 14 Nov 2018 08:10:31 +0000 Received: from amistad.kot-begemot.co.uk ([192.168.3.89]) by smaug.kot-begemot.co.uk with esmtp (Exim 4.89) (envelope-from ) id 1gMqFj-0001i5-Gg; Wed, 14 Nov 2018 08:10:25 +0000 From: anton.ivanov@cambridgegreys.com To: linux-um@lists.infradead.org Subject: [PATCH 3/4] um: Remove unsafe printks from the io thread Date: Wed, 14 Nov 2018 08:10:16 +0000 Message-Id: <20181114081017.10508-3-anton.ivanov@cambridgegreys.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181114081017.10508-1-anton.ivanov@cambridgegreys.com> References: <20181114081017.10508-1-anton.ivanov@cambridgegreys.com> X-Spam-Score: -1.0 X-Spam-Score: -1.0 X-Clacks-Overhead: GNU Terry Pratchett X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181114_031045_508432_65291DEB X-CRM114-Status: GOOD ( 14.22 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: axboe@kernel.dk, richard@nod.at, hch@lst.de, Anton Ivanov MIME-Version: 1.0 Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Anton Ivanov Printk out of the io thread has been proven to be unsafe. This is not surprising as the thread is part of the UML hypervisor code. It is not supposed to invoke any kernel code/resources. It is necesssary to pass the error to the block IO layer and let it process it and print any relevant messages. Signed-off-by: Anton Ivanov --- arch/um/drivers/ubd_kern.c | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c index 0f02373ef632..c08d162f5dc9 100644 --- a/arch/um/drivers/ubd_kern.c +++ b/arch/um/drivers/ubd_kern.c @@ -1,4 +1,5 @@ /* + * Copyright (C) 2018 Cambridge Greys Ltd * Copyright (C) 2015-2016 Anton Ivanov (aivanov@brocade.com) * Copyright (C) 2000 Jeff Dike (jdike@karaya.com) * Licensed under the GPL @@ -1438,6 +1439,19 @@ static int map_error(int error_code) return BLK_STS_IOERR; } +/* + * Everything from here onwards *IS NOT PART OF THE KERNEL* + * + * The following functions are part of UML hypervisor code. + * All functions from here onwards are executed as a helper + * thread and are not allowed to execute any kernel functions. + * + * Any communication must occur strictly via shared memory and IPC. + * + * Do not add printks, locks, kernel memory operations, etc - it + * will result in unpredictable behaviour and/or crashes. + */ + static int update_bitmap(struct io_thread_req *req) { int n; @@ -1447,11 +1461,8 @@ static int update_bitmap(struct io_thread_req *req) n = os_pwrite_file(req->fds[1], &req->bitmap_words, sizeof(req->bitmap_words), req->cow_offset); - if(n != sizeof(req->bitmap_words)){ - printk("do_io - bitmap update failed, err = %d fd = %d\n", -n, - req->fds[1]); + if(n != sizeof(req->bitmap_words)) return map_error(-n); - } return map_error(0); } @@ -1465,12 +1476,7 @@ static void do_io(struct io_thread_req *req) if (req_op(req->req) == REQ_OP_FLUSH) { /* fds[0] is always either the rw image or our cow file */ - n = os_sync_file(req->fds[0]); - if (n != 0) { - printk("do_io - sync failed err = %d " - "fd = %d\n", -n, req->fds[0]); - req->error = map_error(-n); - } + req->error = map_error(-os_sync_file(req->fds[0])); return; } @@ -1495,9 +1501,7 @@ static void do_io(struct io_thread_req *req) buf = &buf[n]; len -= n; n = os_pread_file(req->fds[bit], buf, len, off); - if (n < 0) { - printk("do_io - read failed, err = %d " - "fd = %d\n", -n, req->fds[bit]); + if(n < 0){ req->error = map_error(-n); return; } @@ -1506,8 +1510,6 @@ static void do_io(struct io_thread_req *req) } else { n = os_pwrite_file(req->fds[bit], buf, len, off); if(n != len){ - printk("do_io - write failed err = %d " - "fd = %d\n", -n, req->fds[bit]); req->error = map_error(-n); return; } @@ -1545,11 +1547,6 @@ int io_thread(void *arg) if (n == -EAGAIN) { ubd_read_poll(-1); continue; - } else { - printk("io_thread - read failed, fd = %d, " - "err = %d," - "reminder = %d\n", - kernel_fd, -n, io_remainder_size); } } @@ -1564,11 +1561,6 @@ int io_thread(void *arg) res = os_write_file(kernel_fd, ((char *) io_req_buffer) + written, n); if (res >= 0) { written += res; - } else { - if (res != -EAGAIN) { - printk("io_thread - write failed, fd = %d, " - "err = %d\n", kernel_fd, -n); - } } if (written < n) { ubd_write_poll(-1);