Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp16981ybh; Mon, 20 Jul 2020 09:17:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzcW+uXCOV9SC7Eb6k5Crjb5k5+306z4qYVxyLrqTC8EIV3qCKpKLsz5RBUeFTbxWAjS7da X-Received: by 2002:aa7:da8a:: with SMTP id q10mr22269976eds.139.1595261868828; Mon, 20 Jul 2020 09:17:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595261868; cv=none; d=google.com; s=arc-20160816; b=1IvjAkjxE0WRd6Nvk1g2mxL18NdTd8HkjSC4XVN9ye+zeZYuf/FXFg2OAKT2q4kiRH +t3MLtl892CKKaAbD4D73NKzoLe7BVjCxytcNRd6Jghbj9yjss4tys/RKYkt/3+6FPX1 Ro8NcPksgO3dNqqLXDgavivNW4miXJME+qxl/vR2WrVxE2cl3/u55YwBuzPX8I3kKWm1 egPc6jNkSJMh/D81bIPzvOscljcRIve7UyJmYPLu6dpBKHfhyzzCMqlBKQXy1mL3qm/K 6NK0AYxJRjKW2EfGBpeb6bUaPYJ8z+8mxsRsTbJgYnQg3aSwsAkkHKRPCOG1Cve9vfGH kTQQ== 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=cFCkBg9cEesqwkARLHWaWmLI9n1bU79s4PX0nCLhJvU=; b=JNp+qzNu9wzrBSTWYjMmatK6zJmHmw+Hxhv3X+iTZ0JmUl4rKCN+RufZTAWfKuw4fH to+ib2nX+VStGsvJZI9uQLUlpv9vlnoDqj91OMhoDY+l9may9q9nDf+Tq4hdr2baEWzg yDtesvP+46wuk9HDd3EPcDMs7RTGzMW9iXhij5UVC4VWmhy2zrBolK8XBd7lgBKi7qM3 nAvV+ojHdlU6fRTvLL1S74ERmwW7/s/8wr4W2DLWEO4eW9DDOwiTXegcGyXgX7v8gOzh 9dFRAtRk0nB814/Kw7t/0IQUZ95CxAOYGRO6y/CD7kZ9TF4r3Cj3TXAdFq80z2ia1XX4 FRkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BDWpv3nM; 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 u30si167677edc.466.2020.07.20.09.17.26; Mon, 20 Jul 2020 09:17:48 -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=pass header.i=@kernel.org header.s=default header.b=BDWpv3nM; 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 S2388504AbgGTQQI (ORCPT + 99 others); Mon, 20 Jul 2020 12:16:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:57140 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388496AbgGTQQE (ORCPT ); Mon, 20 Jul 2020 12:16:04 -0400 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 319A42064B; Mon, 20 Jul 2020 16:16:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595261763; bh=2WIqrrjZ5dFloCIxE6c280prt6aRS9BfBvTLbxVQrkM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BDWpv3nM9k2sllut/5i50l32BX5qMKMbV9fMrO+M+TpihzGuZZJEsJSVOKEsYQkv1 TpCgi+6zfYF34TRX20sszJh/oQznRwTp7aZ2AKrZGpcLX1vXnxW91XaCHR/Dbo7+G1 ZyIb6dRCcy2rLpmCk4Aw69bruy7hTxPOftQg4rJ8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Atish Patra , Michel Lespinasse , Zong Li , Palmer Dabbelt Subject: [PATCH 5.7 233/244] RISC-V: Acquire mmap lock before invoking walk_page_range Date: Mon, 20 Jul 2020 17:38:24 +0200 Message-Id: <20200720152836.926007002@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200720152825.863040590@linuxfoundation.org> References: <20200720152825.863040590@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Atish Patra commit 0e2c09011d4de4161f615ff860a605a9186cf62a upstream. As per walk_page_range documentation, mmap lock should be acquired by the caller before invoking walk_page_range. mmap_assert_locked gets triggered without that. The details can be found here. http://lists.infradead.org/pipermail/linux-riscv/2020-June/010335.html Fixes: 395a21ff859c(riscv: add ARCH_HAS_SET_DIRECT_MAP support) Signed-off-by: Atish Patra Reviewed-by: Michel Lespinasse Reviewed-by: Zong Li Signed-off-by: Palmer Dabbelt Signed-off-by: Greg Kroah-Hartman --- arch/riscv/mm/pageattr.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) --- a/arch/riscv/mm/pageattr.c +++ b/arch/riscv/mm/pageattr.c @@ -151,6 +151,7 @@ int set_memory_nx(unsigned long addr, in int set_direct_map_invalid_noflush(struct page *page) { + int ret; unsigned long start = (unsigned long)page_address(page); unsigned long end = start + PAGE_SIZE; struct pageattr_masks masks = { @@ -158,11 +159,16 @@ int set_direct_map_invalid_noflush(struc .clear_mask = __pgprot(_PAGE_PRESENT) }; - return walk_page_range(&init_mm, start, end, &pageattr_ops, &masks); + mmap_read_lock(&init_mm); + ret = walk_page_range(&init_mm, start, end, &pageattr_ops, &masks); + mmap_read_unlock(&init_mm); + + return ret; } int set_direct_map_default_noflush(struct page *page) { + int ret; unsigned long start = (unsigned long)page_address(page); unsigned long end = start + PAGE_SIZE; struct pageattr_masks masks = { @@ -170,7 +176,11 @@ int set_direct_map_default_noflush(struc .clear_mask = __pgprot(0) }; - return walk_page_range(&init_mm, start, end, &pageattr_ops, &masks); + mmap_read_lock(&init_mm); + ret = walk_page_range(&init_mm, start, end, &pageattr_ops, &masks); + mmap_read_unlock(&init_mm); + + return ret; } void __kernel_map_pages(struct page *page, int numpages, int enable)