From patchwork Mon Nov 11 18:26:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 179112 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp7041772ilf; Mon, 11 Nov 2019 10:48:13 -0800 (PST) X-Google-Smtp-Source: APXvYqwxvJINvxEbs2dXi2AF881zE02ekVILACA11ZHvZ/jHvxGfwEnxeZg7hoLRII9TMT5bQ/ZE X-Received: by 2002:a17:906:a457:: with SMTP id cb23mr24090231ejb.191.1573498093586; Mon, 11 Nov 2019 10:48:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573498093; cv=none; d=google.com; s=arc-20160816; b=JtuX1GOPHPvmPXjT2eoKYnSKDue6HZp4h5XbUmTsnwKjgRu3H0VyhQur4awwUlbO4t BVjyi7hG6xz3gtn+R3AmoCcJi9QB5uaG0/zmnVLVK9/HhnNGRNhUa1W4Ncc9mm3/Fg3T js61+EEMZt/+rh1wO1xBIblt3ywacj0cUmIJtUlkTUZ6jPQ6gKYrIgDFclMqUqpirUq/ 1Urtp9J8HNygB1cB8r9Wi/tQar4IwueDQNc0jLOa4JqJ8wRunjvnGPqAYvBo9NwlZKCj ZDdNRNWIbFjxiREjtyPIo5lyXj7gNn8juJQOxlYr0HOaveR8Q2o2jXB6mVffKcqH22on OwGA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=y6M5tSj9sVLpbN0vR6MRmzcDVnRD6RWpqkArJcore9Q=; b=Slti6n0PQeJV3YZbmi/E64HORTIegfHQoKfcfUROCXzAvKIOGlHkeoxgsAzEcmJyJQ OytiIApjw3BvLKrSJvp9DTy8Z1CIX1asTNTkJjqzOSZqnTZ9JmitDZmCMR62u2ru1tlJ FliZllK9jbDsQY89frg+yLVx07Wq1AISU8Qe3bpI8UBJygSxgTGH2ZN4RdKcg2PqbLzh tNz/lFNtHdh49wfKTR9FR77xTjJyBhnNLJwGVTHnG2sQ5XT78m5zz8u0TUu8JerPX4XU O1dsbfTcqL06JaxpUMdc2OAmpF2YIcqRhz647GilienhVuKYqqwzh0AnncaWXEZHd/5t /kpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WnrA3DB2; 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 c31si11273179edb.56.2019.11.11.10.48.13; Mon, 11 Nov 2019 10:48:13 -0800 (PST) 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=WnrA3DB2; 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 S1730225AbfKKSsK (ORCPT + 26 others); Mon, 11 Nov 2019 13:48:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:41150 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729395AbfKKSsI (ORCPT ); Mon, 11 Nov 2019 13:48:08 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 9831620674; Mon, 11 Nov 2019 18:48:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573498087; bh=cfOwdWDLTKNCONnjilnmJE7mx2diQahMlXAy85Yx6X8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WnrA3DB26vmSQ8kOPwJEcRhUwHr5PQ04iXxUeZ745FnVxeVpIKc969QPiLNE1/XeV e4sjCloQI7ZfHsfjjcvPCe2Lz1RJljRgYZ5d+3QWrbX5KfEvUz2gdbrHlaBAp1CfkQ gUa8E8/j4LVtZRMT+tpR8apJhYUe6eE+b+0Spnzg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, lipeng , Yisen Zhuang , Eric Dumazet , "David S. Miller" , Marc Zyngier , Salil Mehta Subject: [PATCH 5.3 019/193] net: hns: Fix the stray netpoll locks causing deadlock in NAPI path Date: Mon, 11 Nov 2019 19:26:41 +0100 Message-Id: <20191111181501.582573002@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191111181459.850623879@linuxfoundation.org> References: <20191111181459.850623879@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Salil Mehta [ Upstream commit bf5a6b4c474c589244dc25ee1af2c3c829228ef8 ] This patch fixes the problem of the spin locks, originally meant for the netpoll path of hns driver, causing deadlock in the normal NAPI poll path. The issue happened due to the presence of the stray leftover spin lock code related to the netpoll, whose support was earlier removed from the HNS[1], got activated due to enabling of NET_POLL_CONTROLLER switch. Earlier background: The netpoll handling code originally had this bug(as identified by Marc Zyngier[2]) of wrong spin lock API being used which did not disable the interrupts and hence could cause locking issues. i.e. if the lock were first acquired in context to thread like 'ip' util and this lock if ever got later acquired again in context to the interrupt context like TX/RX (Interrupts could always pre-empt the lock holding task and acquire the lock again) and hence could cause deadlock. Proposed Solution: 1. If the netpoll was enabled in the HNS driver, which is not right now, we could have simply used spin_[un]lock_irqsave() 2. But as netpoll is disabled, therefore, it is best to get rid of the existing locks and stray code for now. This should solve the problem reported by Marc. [1] https://git.kernel.org/torvalds/c/4bd2c03be7 [2] https://patchwork.ozlabs.org/patch/1189139/ Fixes: 4bd2c03be707 ("net: hns: remove ndo_poll_controller") Cc: lipeng Cc: Yisen Zhuang Cc: Eric Dumazet Cc: David S. Miller Reported-by: Marc Zyngier Acked-by: Marc Zyngier Tested-by: Marc Zyngier Signed-off-by: Salil Mehta Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/hisilicon/hns/hnae.c | 1 - drivers/net/ethernet/hisilicon/hns/hnae.h | 3 --- drivers/net/ethernet/hisilicon/hns/hns_enet.c | 22 +--------------------- 3 files changed, 1 insertion(+), 25 deletions(-) --- a/drivers/net/ethernet/hisilicon/hns/hnae.c +++ b/drivers/net/ethernet/hisilicon/hns/hnae.c @@ -199,7 +199,6 @@ hnae_init_ring(struct hnae_queue *q, str ring->q = q; ring->flags = flags; - spin_lock_init(&ring->lock); ring->coal_param = q->handle->coal_param; assert(!ring->desc && !ring->desc_cb && !ring->desc_dma_addr); --- a/drivers/net/ethernet/hisilicon/hns/hnae.h +++ b/drivers/net/ethernet/hisilicon/hns/hnae.h @@ -274,9 +274,6 @@ struct hnae_ring { /* statistic */ struct ring_stats stats; - /* ring lock for poll one */ - spinlock_t lock; - dma_addr_t desc_dma_addr; u32 buf_size; /* size for hnae_desc->addr, preset by AE */ u16 desc_num; /* total number of desc */ --- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c @@ -943,15 +943,6 @@ static int is_valid_clean_head(struct hn return u > c ? (h > c && h <= u) : (h > c || h <= u); } -/* netif_tx_lock will turn down the performance, set only when necessary */ -#ifdef CONFIG_NET_POLL_CONTROLLER -#define NETIF_TX_LOCK(ring) spin_lock(&(ring)->lock) -#define NETIF_TX_UNLOCK(ring) spin_unlock(&(ring)->lock) -#else -#define NETIF_TX_LOCK(ring) -#define NETIF_TX_UNLOCK(ring) -#endif - /* reclaim all desc in one budget * return error or number of desc left */ @@ -965,21 +956,16 @@ static int hns_nic_tx_poll_one(struct hn int head; int bytes, pkts; - NETIF_TX_LOCK(ring); - head = readl_relaxed(ring->io_base + RCB_REG_HEAD); rmb(); /* make sure head is ready before touch any data */ - if (is_ring_empty(ring) || head == ring->next_to_clean) { - NETIF_TX_UNLOCK(ring); + if (is_ring_empty(ring) || head == ring->next_to_clean) return 0; /* no data to poll */ - } if (!is_valid_clean_head(ring, head)) { netdev_err(ndev, "wrong head (%d, %d-%d)\n", head, ring->next_to_use, ring->next_to_clean); ring->stats.io_err_cnt++; - NETIF_TX_UNLOCK(ring); return -EIO; } @@ -994,8 +980,6 @@ static int hns_nic_tx_poll_one(struct hn ring->stats.tx_pkts += pkts; ring->stats.tx_bytes += bytes; - NETIF_TX_UNLOCK(ring); - dev_queue = netdev_get_tx_queue(ndev, ring_data->queue_index); netdev_tx_completed_queue(dev_queue, pkts, bytes); @@ -1055,16 +1039,12 @@ static void hns_nic_tx_clr_all_bufs(stru int head; int bytes, pkts; - NETIF_TX_LOCK(ring); - head = ring->next_to_use; /* ntu :soft setted ring position*/ bytes = 0; pkts = 0; while (head != ring->next_to_clean) hns_nic_reclaim_one_desc(ring, &bytes, &pkts); - NETIF_TX_UNLOCK(ring); - dev_queue = netdev_get_tx_queue(ndev, ring_data->queue_index); netdev_tx_reset_queue(dev_queue); } From patchwork Mon Nov 11 18:27:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 179113 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp7043629ilf; Mon, 11 Nov 2019 10:50:01 -0800 (PST) X-Google-Smtp-Source: APXvYqwVcSY7/C+tvOamMs8CPX1zW/9zyLbGxYs+qOFetNqlET2jzAPQ5oO0LsLx23HYElC9EJDn X-Received: by 2002:a17:906:c44f:: with SMTP id ck15mr24129861ejb.7.1573498201050; Mon, 11 Nov 2019 10:50:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573498201; cv=none; d=google.com; s=arc-20160816; b=VcbYriZjJYrWLktQHry6P5uYoHhL0h1xiCEHbBauxLIrRja+JTK9mTck2nlgZBOpfI JRrbcW4mzwPdG3YgznLyRJULea8FINhm6yqnawhq99e9f4toRCoUhYRF46sJRHIgE5Kk hcNuaSwjqGDm59UrKehcOO6q0kIwNG9v59JAEEP9D8RLYnJPWRyj881FlrKu4hjYM8lN 96HizyroidxuOFN84O+x5ykM5dKl8QDi8/cGTFH6QY5+uJCqLU9+nN6a/i0pGpT6fd+C d+QXvpVENx4b7fz8GUqtlu51fuR34LizdqDB/fKkgW3dLXoKBHmptgenHzDn42/LrHMX x8cA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=unmdQqN5KCNbCu6wHCKHdV+8syABtUDUnxtDW99/AWI=; b=hV8l68t9lG3VasGz6lvwpoppetwjeuhDP9S3tXzUmxZFa1ucScF7StZ0xluQIuZikG RX4DE2/9ziAiXWA+0SZBD+L4IaYagjI6i6kjm/fW/LH28BAz/Nk1EYo5l5yooK00lLUC OpGcT0OaJP3JEMoiHw8fK1Jh5ie/G0zIG0cEaMlvhuWkKwTHzj7K41b2NnYAJgys1Eo0 Y54tyGkybsD2GRZZ48X65NVYbJJWw7mIU0DdTBkibobr8YgyFB4KkBT7BA7S3HjG+Pt3 q96F/F+2MUPerLC8SPdFDZyGiCAWO2Rjzwe9Nhg+zrIDzJAz1K32DXlPvbIDjymBAmzB hb4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mB3pzccF; 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 v13si14240407eda.131.2019.11.11.10.50.00; Mon, 11 Nov 2019 10:50:01 -0800 (PST) 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=mB3pzccF; 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 S1730317AbfKKSt6 (ORCPT + 26 others); Mon, 11 Nov 2019 13:49:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:43358 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729344AbfKKStx (ORCPT ); Mon, 11 Nov 2019 13:49:53 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 BC5E421E6F; Mon, 11 Nov 2019 18:49:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573498192; bh=9FcN9T5Rfa+rfMnTwfI/2gS9KdF/tVXPP5ae4wU0P30=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mB3pzccFwK+biqhe3xMSAxRSoYLFmkBlPXcUWjmzKBOI67MvI/+VB8i9JutLLCgb9 o1dnB391KIEHTDsrMdbxYqk3hE9Rz6bvM469Fm9wMin5klDg/eREW8CqopEGUYfpVj NnsZSvaqY7ppPaPNGgSuaTWhwloaycNerzmAIXNY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Will Deacon , Steve Capper , John Stultz , Catalin Marinas Subject: [PATCH 5.3 049/193] arm64: Do not mask out PTE_RDONLY in pte_same() Date: Mon, 11 Nov 2019 19:27:11 +0100 Message-Id: <20191111181504.586119821@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191111181459.850623879@linuxfoundation.org> References: <20191111181459.850623879@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Catalin Marinas commit 6767df245f4736d0cf0c6fb7cf9cf94b27414245 upstream. Following commit 73e86cb03cf2 ("arm64: Move PTE_RDONLY bit handling out of set_pte_at()"), the PTE_RDONLY bit is no longer managed by set_pte_at() but built into the PAGE_* attribute definitions. Consequently, pte_same() must include this bit when checking two PTEs for equality. Remove the arm64-specific pte_same() function, practically reverting commit 747a70e60b72 ("arm64: Fix copy-on-write referencing in HugeTLB") Fixes: 73e86cb03cf2 ("arm64: Move PTE_RDONLY bit handling out of set_pte_at()") Cc: # 4.14.x- Cc: Will Deacon Cc: Steve Capper Reported-by: John Stultz Signed-off-by: Catalin Marinas Signed-off-by: Will Deacon Signed-off-by: Greg Kroah-Hartman --- arch/arm64/include/asm/pgtable.h | 17 ----------------- 1 file changed, 17 deletions(-) --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -283,23 +283,6 @@ static inline void set_pte_at(struct mm_ set_pte(ptep, pte); } -#define __HAVE_ARCH_PTE_SAME -static inline int pte_same(pte_t pte_a, pte_t pte_b) -{ - pteval_t lhs, rhs; - - lhs = pte_val(pte_a); - rhs = pte_val(pte_b); - - if (pte_present(pte_a)) - lhs &= ~PTE_RDONLY; - - if (pte_present(pte_b)) - rhs &= ~PTE_RDONLY; - - return (lhs == rhs); -} - /* * Huge pte definitions. */ From patchwork Mon Nov 11 18:29:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 179116 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp7051301ilf; Mon, 11 Nov 2019 10:57:24 -0800 (PST) X-Google-Smtp-Source: APXvYqyvbG26yZqncTq93nj6F2JVYJCzfKrFhMlkVa/0YHWE8aoN6jrez3MKTe1ShkMr1I/BRjoG X-Received: by 2002:a17:906:3053:: with SMTP id d19mr24660886ejd.109.1573498644420; Mon, 11 Nov 2019 10:57:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573498644; cv=none; d=google.com; s=arc-20160816; b=W7FaikHUSq3gG+ZC7Jixw3uVsm/q8Kgp7r7AxYCoZP0n0SSQtepVnakCHtxhfavsUm QU6qMz8el/wgUhaBpHPog4yAWAR9/YFSNHB5l4FCI8GiqUSZlMkrvlySSo5y6PGijv47 H42ZdCIxnjRZ3oSap1uA06WARsdGXM2BLMsR4nQIhv2fcfuCqc0DX5epzj7WLeMNBU3H NoPt6ms5zHQtDS0FR0dctRbqjyfOobjlpY/W8EZm1IDHAve3Wk05hyMum0x4Q558Jary NaqpC15QKpwakhC+k5zJvFTovd+RfStivTWjwv3vHJRPGxHs2YtRCaZGJRzPPkddlJW9 bL8g== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=WOv1x4rimo92eC9CZtpMog1XkcAIieI7LabCrENeIe8=; b=kDY87EffDkx9K+TztOM6GVedCQq/pqs3jsCP0KXSpwSaweDbcPS1vuzBskDtLQLvRE ZuT0YEWjVo27erMDAK8jUs//w2mPy1ORiRObb/fYdo/hRTL7p7TMHV149KuHl8WSjgFA 2HtDM2a3RSx7eESCqZeRov6i3kzoOtyDsmrbVzR3fLRUlvm6r29ZAUdphpf1WP+7DACA jTcRsDlyBLnKw/Rrgj2MveolZibYZ3vqMbmcLVooD7V0k6RS8rPjz/zgb2DC35l0HfJJ vcVE3l1gkfd1+zTFycwoLZz4zI37af+DSLF1aoMDL5bsKSNzHrPFdKt/HQ2ew9IuaF4n tD8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dyQYtVuN; 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 w1si11959499eda.433.2019.11.11.10.57.24; Mon, 11 Nov 2019 10:57:24 -0800 (PST) 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=dyQYtVuN; 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 S1730820AbfKKS5V (ORCPT + 26 others); Mon, 11 Nov 2019 13:57:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:56468 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730493AbfKKS5Q (ORCPT ); Mon, 11 Nov 2019 13:57:16 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 803FB21783; Mon, 11 Nov 2019 18:57:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573498635; bh=9VlzYfDK4xB2zu0xHS/uE7JswxMQCb8hawKUTinRw1c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dyQYtVuNTfoPQ1lQD8BK7Vd6byFvQ3M+4jUm/e3RQbNLwMdYM7mMEg0ssiHwh1KOZ 94BQYWyqgSDCb0bLaEaiBnj0giS2k+yJoiBTROxrqZe7FWhXnjtwhjMfd2JpsEz1U6 Voh3E0GvvECCkYpMD4RtBNRwU7ORxAo0643GjQhI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guillaume Gardet , Ard Biesheuvel , Chester Lin , Linus Torvalds , Peter Zijlstra , Thomas Gleixner , linux-efi@vger.kernel.org, Ingo Molnar , Sasha Levin Subject: [PATCH 5.3 176/193] efi: libstub/arm: Account for firmware reserved memory at the base of RAM Date: Mon, 11 Nov 2019 19:29:18 +0100 Message-Id: <20191111181514.101511069@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191111181459.850623879@linuxfoundation.org> References: <20191111181459.850623879@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ard Biesheuvel [ Upstream commit 41cd96fa149b29684ebd38759fefb07f9c7d5276 ] The EFI stubloader for ARM starts out by allocating a 32 MB window at the base of RAM, in order to ensure that the decompressor (which blindly copies the uncompressed kernel into that window) does not overwrite other allocations that are made while running in the context of the EFI firmware. In some cases, (e.g., U-Boot running on the Raspberry Pi 2), this is causing boot failures because this initial allocation conflicts with a page of reserved memory at the base of RAM that contains the SMP spin tables and other pieces of firmware data and which was put there by the bootloader under the assumption that the TEXT_OFFSET window right below the kernel is only used partially during early boot, and will be left alone once the memory reservations are processed and taken into account. So let's permit reserved memory regions to exist in the region starting at the base of RAM, and ending at TEXT_OFFSET - 5 * PAGE_SIZE, which is the window below the kernel that is not touched by the early boot code. Tested-by: Guillaume Gardet Signed-off-by: Ard Biesheuvel Acked-by: Chester Lin Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: linux-efi@vger.kernel.org Link: https://lkml.kernel.org/r/20191029173755.27149-5-ardb@kernel.org Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- drivers/firmware/efi/libstub/Makefile | 1 + drivers/firmware/efi/libstub/arm32-stub.c | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) -- 2.20.1 diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile index 0460c7581220e..ee0661ddb25bb 100644 --- a/drivers/firmware/efi/libstub/Makefile +++ b/drivers/firmware/efi/libstub/Makefile @@ -52,6 +52,7 @@ lib-$(CONFIG_EFI_ARMSTUB) += arm-stub.o fdt.o string.o random.o \ lib-$(CONFIG_ARM) += arm32-stub.o lib-$(CONFIG_ARM64) += arm64-stub.o +CFLAGS_arm32-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) CFLAGS_arm64-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) # diff --git a/drivers/firmware/efi/libstub/arm32-stub.c b/drivers/firmware/efi/libstub/arm32-stub.c index e8f7aefb6813d..ffa242ad0a82e 100644 --- a/drivers/firmware/efi/libstub/arm32-stub.c +++ b/drivers/firmware/efi/libstub/arm32-stub.c @@ -195,6 +195,7 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table, unsigned long dram_base, efi_loaded_image_t *image) { + unsigned long kernel_base; efi_status_t status; /* @@ -204,9 +205,18 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table, * loaded. These assumptions are made by the decompressor, * before any memory map is available. */ - dram_base = round_up(dram_base, SZ_128M); + kernel_base = round_up(dram_base, SZ_128M); - status = reserve_kernel_base(sys_table, dram_base, reserve_addr, + /* + * Note that some platforms (notably, the Raspberry Pi 2) put + * spin-tables and other pieces of firmware at the base of RAM, + * abusing the fact that the window of TEXT_OFFSET bytes at the + * base of the kernel image is only partially used at the moment. + * (Up to 5 pages are used for the swapper page tables) + */ + kernel_base += TEXT_OFFSET - 5 * PAGE_SIZE; + + status = reserve_kernel_base(sys_table, kernel_base, reserve_addr, reserve_size); if (status != EFI_SUCCESS) { pr_efi_err(sys_table, "Unable to allocate memory for uncompressed kernel.\n"); @@ -220,7 +230,7 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table, *image_size = image->image_size; status = efi_relocate_kernel(sys_table, image_addr, *image_size, *image_size, - dram_base + MAX_UNCOMP_KERNEL_SIZE, 0); + kernel_base + MAX_UNCOMP_KERNEL_SIZE, 0); if (status != EFI_SUCCESS) { pr_efi_err(sys_table, "Failed to relocate kernel.\n"); efi_free(sys_table, *reserve_size, *reserve_addr);