From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1791FC4361B for ; Sun, 13 Dec 2020 19:44:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CF6CB239FE for ; Sun, 13 Dec 2020 19:44:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388988AbgLMToW (ORCPT ); Sun, 13 Dec 2020 14:44:22 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:50464 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728530AbgLMToW (ORCPT ); Sun, 13 Dec 2020 14:44:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607888575; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4PybtF7w1Lh4LKher9Pdy6RACSnKlX1ExGTMf/b4q00=; b=R7EnDWL5mRudewuKPWOQNW3J43IsOjyg/8msd8ayYhHfKPmrxWDIJBc9saZMu4tFt8ydyD Wl/Z399YB7FtslOQKn4AkNyE+L6cABSQs495iQapI2LFPgVdAkMiuZOn7QomHdv7Flns44 kb30uoHwDSQ2n2q0wh2iPmWzJY8UyD8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-569-YhqXPidyOvmi-F4vVw-m6Q-1; Sun, 13 Dec 2020 14:42:53 -0500 X-MC-Unique: YhqXPidyOvmi-F4vVw-m6Q-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4D4C1180A094; Sun, 13 Dec 2020 19:42:52 +0000 (UTC) Received: from llong.remote.csb (ovpn-112-248.rdu2.redhat.com [10.10.112.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id B193A62461; Sun, 13 Dec 2020 19:42:51 +0000 (UTC) Subject: Re: [PATCH] mm/vmalloc: Fix unlock order in s_stop() To: Uladzislau Rezki Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20201213180843.16938-1-longman@redhat.com> <20201213183936.GA20007@pc636> From: Waiman Long Organization: Red Hat Message-ID: Date: Sun, 13 Dec 2020 14:42:51 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.3.1 MIME-Version: 1.0 In-Reply-To: <20201213183936.GA20007@pc636> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/13/20 1:39 PM, Uladzislau Rezki wrote: > On Sun, Dec 13, 2020 at 01:08:43PM -0500, Waiman Long wrote: >> 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. >> >> Fixes: e36176be1c39 ("mm/vmalloc: rework vmap_area_lock") >> Signed-off-by: Waiman Long >> --- >> mm/vmalloc.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/mm/vmalloc.c b/mm/vmalloc.c >> index 6ae491a8b210..75913f685c71 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) > BTW, if navigation over both list is an issue, for example when there > are multiple heavy readers of /proc/vmallocinfo, i think, it make sense > to implement RCU safe lists iteration and get rid of both locks. Making it lockless is certainly better, but doing lockless the right way is tricky. I will probably keep it as it unless there is a significant advantage of doing so. Cheers, Longman > > As for the patch: Reviewed-by: Uladzislau Rezki (Sony) > > Thanks! > > -- > Vlad Rezki >