Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2309954imm; Mon, 28 May 2018 05:51:43 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpCJnv/luhP4/xfBAKr1I11FovSb6NPRRTwXScx6ac5q09QIXc6dwCbqVuxLsaxKkEZdiZL X-Received: by 2002:a17:902:b409:: with SMTP id x9-v6mr13777766plr.180.1527511903659; Mon, 28 May 2018 05:51:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527511903; cv=none; d=google.com; s=arc-20160816; b=FDEWdQl04CKZqlY1EvjYVTIkCQKLl6T9CtvFgzl8X7XqagbxjD3QZ1j3Xdoqqq79n1 +GvURRbSJ1xYiPhJSbQEBN/4gtWOeuXLE5X8aVBlp1p+hIptwSaTnghnB1opUMaBnzKE Cw/erGa/Lahx69BrSYFFDAKSFW/1jot1uF7/qK5CQZo4/Mr547sTLNWMoOsC5t5HRl5s iEq/qTszi/pJTJgLloNB41jktQS4GbyJXOIgpxMqHmSlY8yRu3zwAc/vBmMu2qRqwPAf NhiIBvjLvHXcZaDgR/TxzQJHOPXTD4K+0Mjk8sAYP/o0GyuFD/61HlDxlxNry3sc2JoS 36HA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=yZjeHM43ALlMYC6gPaN9c6MogXWTLq/b+lk2Rc7lY24=; b=ZXQUoK+hzQVj7etrsqyRaHlppKCXokgMtv29ULmOJtOyutNdg7QXJ1GEqA4lgFG0Rv pCpPJ+CO0GhrsJWz39IB4ecD1tAzu+XLNRNpPgC6vhpj/4Nstz99CZA0cQURrJeP0mgr OSaXNzyDh0EnrPp325LwAc+jrW6Me9gs+r3kACedky3SN+3z3oilc9n/jLVQCffdspHS Ly2oWMlgpXlglupqf0pBqVEDqyYHVY0ZgpX85ODVNyb/9qmozRZO8DVYKI/CRMMgC5HK fr7Bm4sNBE7bmy8d8mj4++azqCKU4kMxGNAbVagzJszQDqF2HmViPkI3ISBa4rIE4Q6o WlfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=knNA7g7A; 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 j123-v6si31494192pfd.207.2018.05.28.05.51.29; Mon, 28 May 2018 05:51:43 -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=@kernel.org header.s=default header.b=knNA7g7A; 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 S938981AbeE1Mug (ORCPT + 99 others); Mon, 28 May 2018 08:50:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:44666 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1164480AbeE1K4N (ORCPT ); Mon, 28 May 2018 06:56:13 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CE108208A4; Mon, 28 May 2018 10:56:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527504973; bh=tc0ZuFgEiQhv9Y0yBYUH1WvCqGfb/fudb2g+c2oqQik=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=knNA7g7A9t+ayxORXdad5x3dxT5kxp878T7Xn7oV5ku/X1zuNthziqqB2dKFJhrbT YsBnSJ5HaSq91QmLlHA6xsNe7ltHjXGVLKW3YiTxmQJ9a3hNU6Eb1mxy5MUFydxgxQ DjRgAYnZVcR37sgJioJ3V4ZllcN5AxhgwFITN1TU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Anshuman Khandual , Michael Ellerman , Sasha Levin Subject: [PATCH 4.14 330/496] powerpc/fscr: Enable interrupts earlier before calling get_user() Date: Mon, 28 May 2018 12:01:55 +0200 Message-Id: <20180528100333.722729839@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100319.498712256@linuxfoundation.org> References: <20180528100319.498712256@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Anshuman Khandual [ Upstream commit 709b973c844c0b4d115ac3a227a2e5a68722c912 ] The function get_user() can sleep while trying to fetch instruction from user address space and causes the following warning from the scheduler. BUG: sleeping function called from invalid context Though interrupts get enabled back but it happens bit later after get_user() is called. This change moves enabling these interrupts earlier covering the function get_user(). While at this, lets check for kernel mode and crash as this interrupt should not have been triggered from the kernel context. Signed-off-by: Anshuman Khandual Signed-off-by: Michael Ellerman Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/kernel/traps.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) --- a/arch/powerpc/kernel/traps.c +++ b/arch/powerpc/kernel/traps.c @@ -1379,6 +1379,22 @@ void facility_unavailable_exception(stru value = mfspr(SPRN_FSCR); status = value >> 56; + if ((hv || status >= 2) && + (status < ARRAY_SIZE(facility_strings)) && + facility_strings[status]) + facility = facility_strings[status]; + + /* We should not have taken this interrupt in kernel */ + if (!user_mode(regs)) { + pr_emerg("Facility '%s' unavailable (%d) exception in kernel mode at %lx\n", + facility, status, regs->nip); + die("Unexpected facility unavailable exception", regs, SIGABRT); + } + + /* We restore the interrupt state now */ + if (!arch_irq_disabled_regs(regs)) + local_irq_enable(); + if (status == FSCR_DSCR_LG) { /* * User is accessing the DSCR register using the problem @@ -1445,25 +1461,11 @@ void facility_unavailable_exception(stru return; } - if ((hv || status >= 2) && - (status < ARRAY_SIZE(facility_strings)) && - facility_strings[status]) - facility = facility_strings[status]; - - /* We restore the interrupt state now */ - if (!arch_irq_disabled_regs(regs)) - local_irq_enable(); - pr_err_ratelimited("%sFacility '%s' unavailable (%d), exception at 0x%lx, MSR=%lx\n", hv ? "Hypervisor " : "", facility, status, regs->nip, regs->msr); out: - if (user_mode(regs)) { - _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); - return; - } - - die("Unexpected facility unavailable exception", regs, SIGABRT); + _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); } #endif