From patchwork Fri Oct 25 15:11:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13850918 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6936DD0C61F for ; Fri, 25 Oct 2024 15:12:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F256E6B0083; Fri, 25 Oct 2024 11:12:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ED6776B0085; Fri, 25 Oct 2024 11:12:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D9E036B0088; Fri, 25 Oct 2024 11:12:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id BBD856B0083 for ; Fri, 25 Oct 2024 11:12:04 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8CCE9AC6D3 for ; Fri, 25 Oct 2024 15:11:25 +0000 (UTC) X-FDA: 82712464380.22.12DBB17 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 833BA4001B for ; Fri, 25 Oct 2024 15:11:53 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fgJhnSnE; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf12.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729869082; a=rsa-sha256; cv=none; b=E4GkRV2Z2jmSpUoNZamkgrFXVxiiHOHYPdj5J9q3U8oQboMJpomc+Ax/k64flnOU238XK3 VuD6u3CB9RwVrrnZeUTXISVS3+ift/xULNc3UbY3/xzTrCRDwd+P1gDS9r6LyT9GffiZc7 Gu11V/zWvJFD6LH7zAbOGfEbnBAaf4o= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fgJhnSnE; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf12.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729869082; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=VrMChLaTWQQV1P3cCXF0g4Mb1STd5YPEt4ibYFFJxW4=; b=1QQz4Bo1SG6iVGOFjyGol2LuBSG/70CAtz5YBcY2y1U/atBMTF1iLMyDh2KizWT8FmKGzZ hRRE+VblGzmtnrBvYjMnod3McmpY69Fo43Pdy4auFYpbqZwQ+nJQLWZl0fTEP+B8sf8V9O iMBAMpam017jcF8sHsD0r/9jWm8lVrg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729869121; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VrMChLaTWQQV1P3cCXF0g4Mb1STd5YPEt4ibYFFJxW4=; b=fgJhnSnEQSTql4I4+FerEDjUXmI19VK+NxbhKXl3Hq6GJ/HQv1ipTufu8pTDSZv2RyjO2B WctAAgGWqxj+/xDsNihW+2AwG5llF5XDzMQS+8l8jTskh8afRSaXlhu0eUowl7xRdruy6a o2epJmpChMRnBbUAjXp/xWUjtESmFg0= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-35-oROdk647PWOwfbs1qWmB5g-1; Fri, 25 Oct 2024 11:11:58 -0400 X-MC-Unique: oROdk647PWOwfbs1qWmB5g-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1D5A8193585B; Fri, 25 Oct 2024 15:11:53 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.22.65.27]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1F17D3000198; Fri, 25 Oct 2024 15:11:44 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-s390@vger.kernel.org, virtualization@lists.linux.dev, kvm@vger.kernel.org, linux-fsdevel@vger.kernel.org, kexec@lists.infradead.org, David Hildenbrand , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , =?utf-8?q?Eugenio_P=C3=A9rez?= , Baoquan He , Vivek Goyal , Dave Young , Thomas Huth , Cornelia Huck , Janosch Frank , Claudio Imbrenda , Eric Farman , Andrew Morton Subject: [PATCH v1 01/11] fs/proc/vmcore: convert vmcore_cb_lock into vmcore_mutex Date: Fri, 25 Oct 2024 17:11:23 +0200 Message-ID: <20241025151134.1275575-2-david@redhat.com> In-Reply-To: <20241025151134.1275575-1-david@redhat.com> References: <20241025151134.1275575-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Rspam-User: X-Stat-Signature: c6xs7uggk6d437hhj853tgfgg6fbypyt X-Rspamd-Queue-Id: 833BA4001B X-Rspamd-Server: rspam02 X-HE-Tag: 1729869113-484944 X-HE-Meta: U2FsdGVkX19d0jhD0laZlf+ab8R7c80mRZ/x8DOu8tp8vNrLX/ZWSyJU7KNEKzuFmL1Wm2XQ8mNdXt48Y6MMXVxnGP0SdJ6L1tS9L+lbG3UdUJ4os4HM2pM73KQTf3n0k+z1r4106w7ZBNUyIDf/N2bgmBKZrJynB98aYftbBDBcJYzhguL9DmWVe6UHpsmKH7j0EXlAOzptOcGwJ+x+uzkcm1K/khfGcW4DjeqCXDkG6ftUaXEf2Ek/TIZy5mf0jB2+P/hialcmnB4jiLzByV4ItJnaezAKpIBpwnGt3LNRGmL0GJOMVc9r7ExvT3B1nQRR/KNt3PjPWGqiuiGT/gCa3iURrvZR2bsiVTGVipBTWpMeNrmkFR6AbhMRhvPc5PlE6rth1auW90pIaGDo7mQJAh0blvITyyuh5zBE7sJbYsf1pVLzVeM6n4pHESLGcCluinFTZ7Chlg/13zonz39GhNICtG9fMod38kzoIUYMLWVLoGSyb7rDxQnnUCP5I1G2hgbl4zHA/akpXJfg5F833ypCjDo7/Ho5cfGIxveBp/F8QnvIXMXTltSfm0Gpi3fRkf4PPZ/1TPl8UDApQx7+gGjpI7MlQ2hKqBT4Wz1btKG1gokE2TrgBU2XfDgD1vP3Fwt0PrUS5xN7MulE3jrWxuDUK0BDcHzzoRGcrigvTF8Fflo/V8vhsAWNd8qGzo7zNhUTb8QjHfMypcSltrzcTA4KDHMi02FwJjtugOSoUj72mbJEivf/Xuqk4IEiZEjldNCId2FPHoGHofOvvk0y0AqjWpRoHO3k8nIvQf/8B0qPXZ508KWRiFDC3OCUPvAOLlH+1Kz/F3PtADInCVrUt2nqb5AqpmxyGVXvrnxPusRJ1F2PXHlQBO+9Ai09qb7c6FqNeX0lm082mcp+5U1hx6yhItuGv+aKN+qiRgcX1kxkceyoVGOgyNkDGPGeZLXQzGhnwaPurw7RclZ hZiutQpD aC6Rgi2cOK3ZLb2yGJs1jNCBH2K4sMbzotEsYIR5eM4RJcBWPJ7dsIgjlfHIoi7vZ2GIs1GUhBFCcnwI+B/HCkwfojR9dsyrzjpCDK+13GqnEXTFjxSEX+IC2nG9+0+6mTcw8B32hUzUoQZtFvZWyjTgxBeqetMFveLU4El86J0VTmgZMP730F0FAM76tUIK5oCwqVp1959oTmdvubUkoLcSO01//XYg0+xhu/Fagg6JOyArxD+DGvSqQzYGPTgXFAV3wny0monLD87BeSgZA+1gb5YG+AFsNBBg87dC2Uxhiebci30dUqMLi0wRQ9E1aHAfj11Ec8BvLxYjjnUtIJ3FP+j8w84NmezjqpsBZuMVbhcpMefBfx2yBHw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: We want to protect vmcore modifications from concurrent opening of the vmcore, and also serialize vmcore modiciations. Let's convert the spinlock into a mutex, because some of the operations we'll be protecting might sleep (e.g., memory allocations) and might take a bit longer. Signed-off-by: David Hildenbrand --- fs/proc/vmcore.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index b52d85f8ad59..110ce193d20f 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c @@ -62,7 +62,8 @@ core_param(novmcoredd, vmcoredd_disabled, bool, 0); /* Device Dump Size */ static size_t vmcoredd_orig_sz; -static DEFINE_SPINLOCK(vmcore_cb_lock); +static DEFINE_MUTEX(vmcore_mutex); + DEFINE_STATIC_SRCU(vmcore_cb_srcu); /* List of registered vmcore callbacks. */ static LIST_HEAD(vmcore_cb_list); @@ -72,7 +73,7 @@ static bool vmcore_opened; void register_vmcore_cb(struct vmcore_cb *cb) { INIT_LIST_HEAD(&cb->next); - spin_lock(&vmcore_cb_lock); + mutex_lock(&vmcore_mutex); list_add_tail(&cb->next, &vmcore_cb_list); /* * Registering a vmcore callback after the vmcore was opened is @@ -80,13 +81,13 @@ void register_vmcore_cb(struct vmcore_cb *cb) */ if (vmcore_opened) pr_warn_once("Unexpected vmcore callback registration\n"); - spin_unlock(&vmcore_cb_lock); + mutex_unlock(&vmcore_mutex); } EXPORT_SYMBOL_GPL(register_vmcore_cb); void unregister_vmcore_cb(struct vmcore_cb *cb) { - spin_lock(&vmcore_cb_lock); + mutex_lock(&vmcore_mutex); list_del_rcu(&cb->next); /* * Unregistering a vmcore callback after the vmcore was opened is @@ -95,7 +96,7 @@ void unregister_vmcore_cb(struct vmcore_cb *cb) */ if (vmcore_opened) pr_warn_once("Unexpected vmcore callback unregistration\n"); - spin_unlock(&vmcore_cb_lock); + mutex_unlock(&vmcore_mutex); synchronize_srcu(&vmcore_cb_srcu); } @@ -120,9 +121,9 @@ static bool pfn_is_ram(unsigned long pfn) static int open_vmcore(struct inode *inode, struct file *file) { - spin_lock(&vmcore_cb_lock); + mutex_lock(&vmcore_mutex); vmcore_opened = true; - spin_unlock(&vmcore_cb_lock); + mutex_unlock(&vmcore_mutex); return 0; }