Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1061024imm; Wed, 18 Jul 2018 16:01:00 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfteLp3xguNN7ipbTxajb9Jrf4U4AoH2z5lCQk/BX2oJpXJ+jTMe7OXhO095HLl6OFV4n64 X-Received: by 2002:a63:6b86:: with SMTP id g128-v6mr7674417pgc.344.1531954860336; Wed, 18 Jul 2018 16:01:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531954860; cv=none; d=google.com; s=arc-20160816; b=GSJFVSU9SnJlVdCVLte98fwzmwMfnzOO+v+Dx0B/lTDA8BFb9l1SWzI8Z2nnxahGmD 9ISmEbEUnPd/V7qf8zctLpD3SBVOEkIIGf+4fw34yRoQSWC8pzqA6XAFim4AImMV8mj8 llOKarjOoLhE3ZWsU0hv9AHVW96f0JpUqVDKwKTIPjQ9gA7CkAN3QKig5DpAhOOXlFcv dchhq43xuLGMnd3tcVO415308490/yfoMPrsAvJS6Cj+ZPdw0ghw3UrPyy5hBer61jZT g5tfcdKtW7lPnIj48W7nu+c+EPkTfU1rzVINFsRs/iOTs3a8lXG5r4b4ybep/tUMZajy LO8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=lnhh2st4VX6fehK5+kTz/Y62FrZVJOTwdJg1BYsX/0s=; b=ROq4/5Ktg5bvMyi4uNNhhtP/m9rbaAG2F/rawaL75hJZPXl7HPNZ1IRH0GVuwSgTT/ BwZqUODgBRTnTSVPm3pETvtshB9c6YpcbmbtXEAz1EED5vD3WZ8XDXRwQkeCmjQt02b8 ujFWZEFU8vJi65YuVFR50rVeOc0CtLoRYMYuwM2x+Tx91QOXRlv+qn5aR5qxPt0Zkt2c /CvUY6JukyKB8nZ2DD3MXCuDD87PZrDTplxrd69wFcAgwpzKwmmtT0muG5jHkVkP/dgh VES8QEwbF9aZKNHGEzH4+L3slNJUtWf2/8aUs8QviFbEleTG8HyHXfA7b7hzwtygQQ6g eDXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@osandov-com.20150623.gappssmtp.com header.s=20150623 header.b=gKKSfyFh; 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 128-v6si4459217pge.444.2018.07.18.16.00.45; Wed, 18 Jul 2018 16:01:00 -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=@osandov-com.20150623.gappssmtp.com header.s=20150623 header.b=gKKSfyFh; 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 S1730304AbeGRXjX (ORCPT + 99 others); Wed, 18 Jul 2018 19:39:23 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:40207 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729974AbeGRXjW (ORCPT ); Wed, 18 Jul 2018 19:39:22 -0400 Received: by mail-pl0-f68.google.com with SMTP id s17-v6so2684726plp.7 for ; Wed, 18 Jul 2018 15:59:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=lnhh2st4VX6fehK5+kTz/Y62FrZVJOTwdJg1BYsX/0s=; b=gKKSfyFh/FCLHtCMA0kiqlE5CiijuIkzB+rU0uXmOJkm8MWdAonRtkDeAeTojl5eKV G5jChoGSvQhFrIFPthuvPZLAt944+xJ9e/0NOa6KLae4Bkb/Nu8R9xfXXJUlLadxMQUD kRXwJIF2vkxhoRn7Kv09R4V5N4bdAgZYKqKPW2Zw6Y1f4+C7krfhzg3OG9+IS/AAjA+j DLPCEJerGHgLBYC6UX0Kj8tj8F+uptRsub6+S5cLJQ73Nk7e+N2nFQdHadEABdSV/sJX m531CksYuv6BXdup7P81hbz6eGU+pgiksyJz74Q0qiFMRQ8OLkeA2pNCsF2fiJoXEx97 Ej5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=lnhh2st4VX6fehK5+kTz/Y62FrZVJOTwdJg1BYsX/0s=; b=TkF8GlORz46/4pdE7E/vVt9OrN1hicAThOqTjUceu5UBvpt3SnCdXnQ8JNFhe+mDor bDCyXWqLo0vDnDOnDcrX63R9IQrREedJ1VzkdBpBBC88LHDgdFiePMCUwlm5v3ZJbPp9 WEmn5uL/TNuv2JfUgO/5Gly0UVIZlnWhAjWPJjWJ+UtVTcWbKk3Yh2XRQUQd2sawWQOB o8CbYMNz2FywVrro19QVJjWm9BcvIR2eVACyyNAVQObuL6UaDp+rfOjlAqeQ33XgjnAy i7wGduQdumEV5ib6XLJhebSeS+IL7b2X2b+4cPJ/nVb3QyNTcTLKpIadcJtifySaOpDL 2V9w== X-Gm-Message-State: AOUpUlHP1FoM5ULvXA+Naqp1nlXCZObRtVCEGXSNNycmIQvgVm3pjJuV euvP2XWzL+kE3R0/JAi/2RTEkkp2BuY= X-Received: by 2002:a17:902:599b:: with SMTP id p27-v6mr7562887pli.191.1531954755568; Wed, 18 Jul 2018 15:59:15 -0700 (PDT) Received: from vader.hsd1.wa.comcast.net ([2601:602:8800:a9a9:e6a7:a0ff:fe0b:c9a8]) by smtp.gmail.com with ESMTPSA id s16-v6sm6377946pfm.114.2018.07.18.15.59.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jul 2018 15:59:15 -0700 (PDT) From: Omar Sandoval To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Andrew Morton Cc: Alexey Dobriyan , Eric Biederman , James Morse , Bhupesh Sharma , kernel-team@fb.com Subject: [PATCH v3 2/8] proc/kcore: don't grab lock for memory hotplug notifier Date: Wed, 18 Jul 2018 15:58:42 -0700 Message-Id: <0a4bc89f4dbde8b5b2ea309f7b4fb6a85fe29df2.1531953780.git.osandov@fb.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Omar Sandoval The memory hotplug notifier kcore_callback() only needs kclist_lock to prevent races with __kcore_update_ram(), but we can easily eliminate that race by using an atomic xchg() in __kcore_update_ram(). This is preparation for converting kclist_lock to an rwsem. Signed-off-by: Omar Sandoval --- fs/proc/kcore.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c index b0b9a76f28d6..e83f15a4f66d 100644 --- a/fs/proc/kcore.c +++ b/fs/proc/kcore.c @@ -118,7 +118,7 @@ static void __kcore_update_ram(struct list_head *list) LIST_HEAD(garbage); write_lock(&kclist_lock); - if (kcore_need_update) { + if (xchg(&kcore_need_update, 0)) { list_for_each_entry_safe(pos, tmp, &kclist_head, list) { if (pos->type == KCORE_RAM || pos->type == KCORE_VMEMMAP) @@ -127,7 +127,6 @@ static void __kcore_update_ram(struct list_head *list) list_splice_tail(list, &kclist_head); } else list_splice(list, &garbage); - kcore_need_update = 0; proc_root_kcore->size = get_kcore_size(&nphdr, &size); write_unlock(&kclist_lock); @@ -593,9 +592,8 @@ static int __meminit kcore_callback(struct notifier_block *self, switch (action) { case MEM_ONLINE: case MEM_OFFLINE: - write_lock(&kclist_lock); kcore_need_update = 1; - write_unlock(&kclist_lock); + break; } return NOTIFY_OK; } -- 2.18.0