Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1060374imm; Wed, 18 Jul 2018 16:00:28 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdRCYiBYz4HbBbrt0ldBcQQWbYtqzaX4DOngIcpEe4uGW805EZjWdtlXZATp6pbtlMTYUrC X-Received: by 2002:a63:1403:: with SMTP id u3-v6mr7539442pgl.13.1531954828922; Wed, 18 Jul 2018 16:00:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531954828; cv=none; d=google.com; s=arc-20160816; b=OLcVck9WPB6iPTxPgILtzbSBV3WBkv7Ro9+2Ws0xCqBYcre4Y4WBkBHYm1aMeVe+vB i0EiL30wGUKi8/gIhJiBLkGL6z2LFZk8h57civxx+h1hTaleNfGCxqnNEhyCmO9ZWEk3 U58AVrKUb785xm86zC1lrrzmjliwBgRdA8hQ48zaQYxhVBc7nA7tHi4sEoQEf7DE3dVA 5jM7maE98ZxrJ7mzmIKUNNWDJwH1owPpNEIA89nPmsp39tEobnB7uOPB0EGGggKP2KFh CE2a/BRrLykmypdlcZHnRpCyQRe2bu+A16Rlg8p2ACi5Om5MjBGejdaqAtGduBtxruQR +G6g== 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=OyWywDrz0yNlctIEZKfvqcYdJMHey6G7QhHf0bJ4Juc=; b=mr912JewFRwZZgvANBLmeRRldD9yWsgCtOAOePk/xAFQICxfKjaIPrGPkerzRrGur8 n2GQKVpHUajcacitDBxy4FpzjsCvEMj2qRR+NRyyre+nZBKFtgsh8bNopAA13Lqhj0SE jtcccr4hZxQZ7h8OHihoo50O4iVYGx5ivBYuV9gFcLvPvuJQsc6rrZ3NwAvivoJ4XoEO Aoj/StM1AiFL+wgirmKfLBfADTVVwEKW0/QiS+l2apuOs9C3kHlqvjSSpAbB0/zjbVW1 DsMGjh6qHsYCx5sGC2J2HbYdcKeGlQhg78+vY9eBKobkVuv1KHfZwoCczgNAT8SCPJ/6 t/wA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@osandov-com.20150623.gappssmtp.com header.s=20150623 header.b="WguY/AZ8"; 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 s199-v6si4821769pfs.255.2018.07.18.16.00.14; Wed, 18 Jul 2018 16:00:28 -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="WguY/AZ8"; 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 S1730600AbeGRXj2 (ORCPT + 99 others); Wed, 18 Jul 2018 19:39:28 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:46774 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729974AbeGRXjY (ORCPT ); Wed, 18 Jul 2018 19:39:24 -0400 Received: by mail-pl0-f68.google.com with SMTP id t17-v6so133181ply.13 for ; Wed, 18 Jul 2018 15:59:17 -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=OyWywDrz0yNlctIEZKfvqcYdJMHey6G7QhHf0bJ4Juc=; b=WguY/AZ84m4D8XPoyVlUMQMTq3NNwODswZZM74PzEWFGMhoYexh4LTJtvuBLfVvdoa t+flGWQe/fIJgGXDL9wC9tQrz3VXmKI+xozKNnvupLhGMUSIXXARvkw5dnz9Ebo9OZZs o3WmfMbSyBe3yWM4puk+frRnpluMaXVDgwKNsijokAJEpg9+2j3lM8oMVQnEXAXXGsIn BXopdo9HIXH9+Dxr60GZ1H5zBS2/4C38dhiWUPRVGGipuMrYrdVx+3MhpYHK+Pv7g+3B ilO6aXl7+YjjwEe81c0NBzMa65U0IbdJyLYFXpTabj9HY7raQkyH/tArkm85hixFdr0s BYQA== 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=OyWywDrz0yNlctIEZKfvqcYdJMHey6G7QhHf0bJ4Juc=; b=j9JvnA+8A/19nKIxqC3S2V7SsFZVtmuKjhDOn5hoT7aitqwMhFHnpQNoE6JuEagB+4 BOEkaDBKXlEHBYKiawwgPygN8K5dJO1BSNQMYuV6cJu4hgTdziYbJjjFCLzul2qYh5zE PM+P8ajTFIIWb2hpKWDG1oixqnWGPmVTE5dzpEdf25O+rjI0BhVRKLx7TKBBGRfHqvrd 85Gu5mLVXqEtddmNcMH+rKt1C6aglJLVnv1mPW1gwKb+J+uDFRZ7bbkFUXHulSKz3MzT sjM7v7sttNjrqFuKbetqtW8qv06eZkmGFYRSB116XgOkn3qZveFR1EXREi0ntXvzJJwT mRDg== X-Gm-Message-State: AOUpUlGBjbhefRfHR4YFf0PW5NBB4vqMOqLU47Jfv60d+wqDB7okWcLg MKt0ZuLpa6PFw1PFHQUO+NwRm/XKtxk= X-Received: by 2002:a17:902:a702:: with SMTP id w2-v6mr7763319plq.41.1531954756864; Wed, 18 Jul 2018 15:59:16 -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.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jul 2018 15:59:16 -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 3/8] proc/kcore: replace kclist_lock rwlock with rwsem Date: Wed, 18 Jul 2018 15:58:43 -0700 Message-Id: <521ba449ebe921d905177410fee9222d07882f0d.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 Now we only need kclist_lock from user context and at fs init time, and the following changes need to sleep while holding the kclist_lock. Signed-off-by: Omar Sandoval --- fs/proc/kcore.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c index e83f15a4f66d..ae43a97d511d 100644 --- a/fs/proc/kcore.c +++ b/fs/proc/kcore.c @@ -59,7 +59,7 @@ struct memelfnote }; static LIST_HEAD(kclist_head); -static DEFINE_RWLOCK(kclist_lock); +static DECLARE_RWSEM(kclist_lock); static int kcore_need_update = 1; /* This doesn't grab kclist_lock, so it should only be used at init time. */ @@ -117,7 +117,7 @@ static void __kcore_update_ram(struct list_head *list) struct kcore_list *tmp, *pos; LIST_HEAD(garbage); - write_lock(&kclist_lock); + down_write(&kclist_lock); if (xchg(&kcore_need_update, 0)) { list_for_each_entry_safe(pos, tmp, &kclist_head, list) { if (pos->type == KCORE_RAM @@ -128,7 +128,7 @@ static void __kcore_update_ram(struct list_head *list) } else list_splice(list, &garbage); proc_root_kcore->size = get_kcore_size(&nphdr, &size); - write_unlock(&kclist_lock); + up_write(&kclist_lock); free_kclist_ents(&garbage); } @@ -451,11 +451,11 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos) int nphdr; unsigned long start; - read_lock(&kclist_lock); + down_read(&kclist_lock); size = get_kcore_size(&nphdr, &elf_buflen); if (buflen == 0 || *fpos >= size) { - read_unlock(&kclist_lock); + up_read(&kclist_lock); return 0; } @@ -472,11 +472,11 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos) tsz = buflen; elf_buf = kzalloc(elf_buflen, GFP_ATOMIC); if (!elf_buf) { - read_unlock(&kclist_lock); + up_read(&kclist_lock); return -ENOMEM; } elf_kcore_store_hdr(elf_buf, nphdr, elf_buflen); - read_unlock(&kclist_lock); + up_read(&kclist_lock); if (copy_to_user(buffer, elf_buf + *fpos, tsz)) { kfree(elf_buf); return -EFAULT; @@ -491,7 +491,7 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos) if (buflen == 0) return acc; } else - read_unlock(&kclist_lock); + up_read(&kclist_lock); /* * Check to see if our file offset matches with any of @@ -504,12 +504,12 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos) while (buflen) { struct kcore_list *m; - read_lock(&kclist_lock); + down_read(&kclist_lock); list_for_each_entry(m, &kclist_head, list) { if (start >= m->addr && start < (m->addr+m->size)) break; } - read_unlock(&kclist_lock); + up_read(&kclist_lock); if (&m->list == &kclist_head) { if (clear_user(buffer, tsz)) -- 2.18.0