Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9089882pxu; Mon, 28 Dec 2020 06:23:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJyF1023aXmZ/BQ6fAG/cIinS9Lu93FEUu3iUUFzsVyKOZZImDVGLPxCUVUyOxJjMu2zj0Kd X-Received: by 2002:a05:6402:404:: with SMTP id q4mr43422849edv.295.1609165398222; Mon, 28 Dec 2020 06:23:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609165398; cv=none; d=google.com; s=arc-20160816; b=CZbTeZdC1PVqlavA6jKnWXf4kpG2RcVFMd7pXOZOR7ZLyK5nqeicrUm/4ykCC9+6w9 vIHF3H1kLbCV3M9KqCjsUIgoJ2xQoKaZQgZUBlILZhbmekIGT7gmDRbPQ/87TAjCdt8+ Iq1LFDEwmtswBSPdZkz/bE+dOBMoRBYowm26SOfJn91y+FyCyUVZUPi9fDoyFAsjx1bY NQCuayir+lNB2trqkj5wMqBOEqEZwxk227FR7P20nKRpFJQi1ij4NzB+5lzIFKRrMjv7 2xfeQ/f5xmYgEvVXUf1kC3lq1H0YKabd0NFtwqxAmxQ5gp4TYMjPnQz5RNhIOcJprMX8 k4Sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=S07rvFqNuRp0o45omD5yLFWQrXO3DTomgR5ehzq7p1Q=; b=xgWnS9DeLe6ejtWSnXIL4+oSOWtCDq7yHmZyRt8v1EDUWIt36hDfgiNimsRoNTdGun PV+bSiw17lp20+OILnK5lPQVWpUzpTxEmiswdc8+fD3JvVCr8b+iXYGrr9d3lwOmqCVJ 8pan37+caLjnrCOnDgESxt1Bo9v5I59Dgu3a7tFa6BNKiqHR+chuOmqokNAK2gTYxPee zcraLPYXPuqmbhyVsE6ErQ9FeNO+bgp/RLsaSBz27NTtDiMJjz1Qb/VG4HRBe1eOijYn wF7j0gpCHSEYvABaFh507WpVdIhEaKl4CWPS9kpeea59SMB0I5c9+KWnF2+Dgk5sWu1d mBiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BqoK8EUm; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h8si18265436ejq.268.2020.12.28.06.22.55; Mon, 28 Dec 2020 06:23:18 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=BqoK8EUm; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392062AbgL1OUh (ORCPT + 99 others); Mon, 28 Dec 2020 09:20:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:55632 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2437756AbgL1OU3 (ORCPT ); Mon, 28 Dec 2020 09:20:29 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1901422573; Mon, 28 Dec 2020 14:20:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609165213; bh=rKV0l2xULBjUrg/Gg+dr5a6PsKtl/a8O48oMgT0Uwhk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BqoK8EUm9MxnTE0ibFG9ZyDqRZiVzoNHVR8v0SBFPx3HBHbxCYt+K2MIyujHkQ5rv EzdiOEUzY2DL/VaK9grQhpuv8CHoyHaVHpKCZ21oAUvWV1WiuisSdFY+O0uCMSZfWP VeO/FauYORnoPmc9CNld4jb0+qdQMC1y4BMCxbis= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Waiman Long , "Uladzislau Rezki (Sony)" , David Hildenbrand , Matthew Wilcox , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 5.10 453/717] mm/vmalloc: Fix unlock order in s_stop() Date: Mon, 28 Dec 2020 13:47:31 +0100 Message-Id: <20201228125042.672572617@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Waiman Long [ Upstream commit 0a7dd4e901b8a4ee040ba953900d1d7120b34ee5 ] When multiple locks are acquired, they should be released in reverse order. For s_start() and s_stop() in mm/vmalloc.c, that is not the case. s_start: mutex_lock(&vmap_purge_lock); spin_lock(&vmap_area_lock); s_stop : mutex_unlock(&vmap_purge_lock); spin_unlock(&vmap_area_lock); This unlock sequence, though allowed, is not optimal. If a waiter is present, mutex_unlock() will need to go through the slowpath of waking up the waiter with preemption disabled. Fix that by releasing the spinlock first before the mutex. Link: https://lkml.kernel.org/r/20201213180843.16938-1-longman@redhat.com Fixes: e36176be1c39 ("mm/vmalloc: rework vmap_area_lock") Signed-off-by: Waiman Long Reviewed-by: Uladzislau Rezki (Sony) Reviewed-by: David Hildenbrand Cc: Matthew Wilcox Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/vmalloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 6ae491a8b210f..75913f685c71e 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3448,11 +3448,11 @@ static void *s_next(struct seq_file *m, void *p, loff_t *pos) } static void s_stop(struct seq_file *m, void *p) - __releases(&vmap_purge_lock) __releases(&vmap_area_lock) + __releases(&vmap_purge_lock) { - mutex_unlock(&vmap_purge_lock); spin_unlock(&vmap_area_lock); + mutex_unlock(&vmap_purge_lock); } static void show_numa_info(struct seq_file *m, struct vm_struct *v) -- 2.27.0