From patchwork Wed Dec 4 12:54:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13893712 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 55A09E7716B for ; Wed, 4 Dec 2024 12:55:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D847B6B009D; Wed, 4 Dec 2024 07:55:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C985A6B009E; Wed, 4 Dec 2024 07:55:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE6996B00A0; Wed, 4 Dec 2024 07:55:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 8E0446B009D for ; Wed, 4 Dec 2024 07:55:18 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3E80EC0FC9 for ; Wed, 4 Dec 2024 12:54:56 +0000 (UTC) X-FDA: 82857271098.04.70636FE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf19.hostedemail.com (Postfix) with ESMTP id 3FFC21A0015 for ; Wed, 4 Dec 2024 12:54:38 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IAhxVp0f; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733316887; a=rsa-sha256; cv=none; b=ntFYx0YDpeH35WIjACeRAdynu5K+BQBeuxx6zcnogdORqKfsGvG+nWS4Hb2sTVgV4n9cp8 JNBYVozc921hQEfGCJvyKbicmjkh37yXykuEmImpj1YiO9tZu9JGf4TESU86q4hj4zU4qe 9Cg8RnGt6oFXEIFEfT+//pInxtURqL8= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IAhxVp0f; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf19.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733316887; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=OXGsdvv3AOb25EXWN4EjEJfR5qBP9EzuVcsjQaH9awM=; b=DEzH1PiJmKFMuise7IThv7FAw6WH8FJdSERxAv++SlzhTMUf36a5o8RNEfv2h0QyRsZGUi YQ2AhUk9hfABcgv9Y4/fwU4p43Z43bkqH+VLDLEbOferh40bUoza14eVVLxUQyuE5YvTnW bIxcteMRpY7EZ7x36/+0Vna4tAgZfOM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733316893; 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=OXGsdvv3AOb25EXWN4EjEJfR5qBP9EzuVcsjQaH9awM=; b=IAhxVp0fexhZ947AJcGDXY7ludCbn/KFqfedFYeQlyvSfNM9HdtCtYYCXrE1DwUFLuKpEJ t3IW6qBTerM5XRE16JzrGgrQf0RXZjOTrGWCk2dj0SqzW+Ms9iXiG92tGq9PP1jKsIGvfJ AcjQBLdb8BRJZvV9SK4ftPKGMXWrs4k= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-93-lSUD_DFkObKVQNDSbmPpMQ-1; Wed, 04 Dec 2024 07:54:52 -0500 X-MC-Unique: lSUD_DFkObKVQNDSbmPpMQ-1 X-Mimecast-MFC-AGG-ID: lSUD_DFkObKVQNDSbmPpMQ Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-385dcadffebso2594993f8f.0 for ; Wed, 04 Dec 2024 04:54:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733316891; x=1733921691; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OXGsdvv3AOb25EXWN4EjEJfR5qBP9EzuVcsjQaH9awM=; b=lEP3B7YdgY49D8ri8s1IQ38aj7r4QgeczafITNWHRbdj7tt8j7g6GlfkojM0sibz0w lF8s7ojl0JQ7nNRvu2eKLpNO6XF5Ku2KLAXoLcIruwXZoal9olOKlXsG18loBcbV+MOa PM3CRwGD7kfZ3Q2qYDHgkZwabSi31Q9xJJnr/e30mIjHf74waT4R/WMe0btOolpxT/t6 Wa+j80TRs4qCCQLh4lwTOPZB+J+cfxYKY0IY1zt5s1ryytYaMARjxDHKoRsCrOHCgIlw 5GWZSfZrxZBDil4e7vTNvbxPGHvXFSEeKCP8UBgGmR7CkxKxjurkkfCvms4nWtpy0RJD KINQ== X-Gm-Message-State: AOJu0YxIAxT+coxujwlkQLEh3WjW5CPC4IJK/G+5jm+5YVsnpUajYIX1 ZAeYbaPHPlbBVTRl+CV+1/Fbzy/qHhTpLAkxGalE0dxrec3JNjIzldlBn/6m8sadF9PMZna7g+v uRjhDcYPFwVz7C153Uv2e52tBKT8aeBS2ccHhErl5hqmgBayU X-Gm-Gg: ASbGncsr0k8BxJ1sVaEmu90n/XM5uHnKdwW5YezQsqtv/plO5qWcwXyyD+otmT7Ume9 HIROSWNIX23f21nfDIsVJgj4/KCfza2Sm1Who/WrawyXXypQrDYQ0mYdqCzJ5gictTEssWbnbcu 94fd51ZVA+D17Sr8+c7UFGJ/BX2dk+XM/kBXMlL8o6DV4fA3wWAX6uZp5Z0YQ4h1MMFjOTMiGHx zzY2B94J91wpUoYki8wI9qxiP8b8Tw+ahl6WMBvtgULl3S5WpcfK49KW7kNm1zyYeptVW08r7DU 8zWWXaD9lortqNGljUdYgNDAa5kgdquR/sY= X-Received: by 2002:a5d:6d08:0:b0:385:f280:d55 with SMTP id ffacd0b85a97d-385fd418db2mr5360103f8f.37.1733316890968; Wed, 04 Dec 2024 04:54:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IHGOcFoEjkEw+PoNC+LLaws3waLwovX9iW85k260HP1nxTmH4H7ZaUgV85wmWvqw6YlLZ08+Q== X-Received: by 2002:a5d:6d08:0:b0:385:f280:d55 with SMTP id ffacd0b85a97d-385fd418db2mr5360063f8f.37.1733316890620; Wed, 04 Dec 2024 04:54:50 -0800 (PST) Received: from localhost (p200300cbc70be10038d68aa111b0a20a.dip0.t-ipconnect.de. [2003:cb:c70b:e100:38d6:8aa1:11b0:a20a]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-385ea9c5952sm11045422f8f.67.2024.12.04.04.54.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Dec 2024 04:54:49 -0800 (PST) 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 v2 01/12] fs/proc/vmcore: convert vmcore_cb_lock into vmcore_mutex Date: Wed, 4 Dec 2024 13:54:32 +0100 Message-ID: <20241204125444.1734652-2-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241204125444.1734652-1-david@redhat.com> References: <20241204125444.1734652-1-david@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: aNtf4zRSv8OrOyOWxkiLBc2UOJ_nRNtheKxkMtgbQ2w_1733316891 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 3FFC21A0015 X-Stat-Signature: n6xswhrqmy56tharhmyg7kqto8abgzkq X-HE-Tag: 1733316878-59967 X-HE-Meta: U2FsdGVkX1/99yl3ycnXJVY3j/PM9jK/j876pl4MkbIXmV4vEhLEh7IaJgZnuER18IPAoOyoHtj1m5iCIYJp+cI9FkKdhBFmrePuFrOdIPsk7zo4BOWDo8v8q5UTqfNLU5KTesYcAnyvUSvCMhg6ytG3VWQDu81Wi58AwL1ImvU5p9XuGrJ4CUCmC6GMVA1w73X4a+XrJypKcvZs+KCWiMILA/cpJ5y9fFgllJ2bm0wkNNgJ8/UoFNFjCYYzJOopmyDn/lfuOOHsonfP67bR46TcjDW4t9fkZui0qCdcDoZe0tgd5AbVdaV3dXh8PEWx0lVcH1NVg0+04TBxeCZawYEvvURhDbsKIj6AQw1Ofbc7Bbr2AnA3TfsdDPqS6vwwsAvFC01LZAWA10IJepZb1jg8OlzhODyCKWNUUNOzk9/66FbgEy96svf9zAt9qIiF5Qbill8XtAJTcxBmlCpnindb+heN3jhyigi6kLYNv58OvmOHqfq1yQq7ma8mWVddjoxe5mE/X9p5BmFwo1LWicXZw5XoyHI/mB75ZDBDD5DtOhe7PW9M+6xGTeIu8LhDXfp6or1jpaHbbqiHz5Bj2rgmBiiGPABUxGIeWmrP2niTFPAYpyysJSP0WpzIPGsTsdd3hYVnFsfV2Wcg69Wz4f15WfvADq7opz1/uD3udkzvwOR9UubIkrmqr/dTLq82TZilVxWRV/y2Ro+SWojRXTHf/CCZ2KLg4g/+eUEjfJXqjfnIIJ/XZfXu7PWV6fIDPuucOJXCUt9OZ/dgxiZAEeP0+ZXddUvVqE0Glm9JlaCLnwv8IyC+UUyeRHOCZO6X5MIiSdCJFaPAdo7m5s6/U0qyAubriLsbU3uk2+kToMhFdHcwB76w4+AFF2iDEdp0+tvDDNjPuQPI3JzSyqNLJVYV2mQAE10th+hIsuYVef7qNcl7XXLGAKfi2TDudwiezNHmBgbqYMtXCjg8BYH mgz+beqJ 5MMnxo5/0e3qEinPKhHKW2lMCq1jY4rrpV4TvzQzOb6nAvMXxjWpibmBWVpzNEEDVb4i20jenM5tPX3dMrqDSEgAcPlS++k9CY/B8BVckLcSR2mT/QmfcezmTF/pAxDH3ic7LK744bHXljkO6n2d4Nyjau7i79bJ3R+FO5+W4aqZMpr6AUwgiojJIkXsT7Wkd0uuOnLFSGs8ei+NvGfbTjUCH1k9FXUw7p+74lN2bwpqrWc7aTAL5yXHsAXz4OYkIIJUBt+vLT0zm6DshhwIJV3DJ1/JMbw4wzKc75dB4cgdyZC6DsW2OzmzqBBcCcSQ32PqQ/YKDYoPAKg0+uv5pmPsdc9fa823go55+lx+TvwdGA0b7EYdA6ciw6dn25H4/OI6eHNvH8W1w2d2k6VkmqBEad469tbz27DoKYKtnzYdM4nhWGg4MydVmfM+uo3eXAzxNlG0qHDmohpX+NfTfzwJexLQVKDnUuVvP 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 modification. (a) We can currently modify the vmcore after it was opened. This can happen if a vmcoredd is added after the vmcore module was initialized and already opened by user space. We want to fix that and prepare for new code wanting to serialize against concurrent opening. (b) To handle it cleanly we need to protect the modifications against concurrent opening. As the modifications end up allocating memory and can sleep, we cannot rely on the spinlock. Let's convert the spinlock into a mutex to prepare for further changes. 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 b4521b096058..586f84677d2f 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; } From patchwork Wed Dec 4 12:54:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13893705 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 3E6E3E7716B for ; Wed, 4 Dec 2024 12:55:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C6E8A6B0088; Wed, 4 Dec 2024 07:54:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C1DC26B0089; Wed, 4 Dec 2024 07:54:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A970B6B008A; Wed, 4 Dec 2024 07:54:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8B3216B0088 for ; Wed, 4 Dec 2024 07:54:59 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 3060A1A093D for ; Wed, 4 Dec 2024 12:54:59 +0000 (UTC) X-FDA: 82857270846.01.2FF8D3E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf02.hostedemail.com (Postfix) with ESMTP id 7350180008 for ; Wed, 4 Dec 2024 12:54:29 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GunmxSy9; spf=pass (imf02.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733316886; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=EkAK23ba+nOdc62V3txwBduSNZiyWl3c9gCUE/mLOOA=; b=IznWpz7Uq5yjyOpdIQHT+x0g1ZIdkZJX0pPmMj0JfU8GwKBu+n3WRg2naGjCKijH6pZ4/v wEP8wJ2dEePgaZri4XMqv9EGM8fK0I/tzvabTOKoMvt+tESim1z6rj4UyAA56n1UudKqZk ppPPNxcRarUrHHC9DXVPhprHAt/07r4= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GunmxSy9; spf=pass (imf02.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733316886; a=rsa-sha256; cv=none; b=P3VVi6bIUqUbmbdvWkub8s/qe6ieJqEjN4ymXCYdXqwnVeJx5t9nrEU62e4Zu2Hmqn5vPx ibpJlBp0BDdmS/cRgRGDJ6Sf3VVp55J9drgs/J9iCuByBrwhYMMVVSwHo3KF1TTCH97jgQ wggfX5Wm761sslnEn1M0fZa6D3OYbgs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733316896; 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=EkAK23ba+nOdc62V3txwBduSNZiyWl3c9gCUE/mLOOA=; b=GunmxSy90/g6QePWMgtggml73as1tWEu180Cbn8AQmHvZ6Rz1eCZ6Oq2R9fGFcbgf2Swe1 t+sQFoCP9O27BX5VgG5LyQNjsOVN6bmfLHjv2VjWyQd47WWPqz6SPaE9YK62Au29s9nbyA 6cewNXD9bJ+wDleyZPwpITZc2Y3Wmaw= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-56-hMo7VIA5No-Hk1sj11BEyg-1; Wed, 04 Dec 2024 07:54:55 -0500 X-MC-Unique: hMo7VIA5No-Hk1sj11BEyg-1 X-Mimecast-MFC-AGG-ID: hMo7VIA5No-Hk1sj11BEyg Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-385e0f3873cso2818184f8f.0 for ; Wed, 04 Dec 2024 04:54:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733316894; x=1733921694; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EkAK23ba+nOdc62V3txwBduSNZiyWl3c9gCUE/mLOOA=; b=NZfPyybIQYSQ7guUBsdJTqhYHe7cNHvVRsyvE5G5jOiEVRq6eMEzfao3zqsqy1KbS5 5X4vQrTtVJbKx9mj/Td+2qRABKQFrh8en1FayhbjJD4s80lI2fA/9uPAOYR1LPkSOBzB osfLO4H8Tt2nHKtA+PC2OLpmCW/+uuHqO6ICypj+6ekxBEm0RR3gFSMtsZoCKD4vvaOc 4UNOeVWm8xhn6fr+iSvzy1tQYGRjAMcjNhaYadB5IVyJkd/YjLoCm+ptt7/klhVckF7A bb9tM+T8MbPcjVSVzrlsX6KoP2DR2Z6MgmeLq18Gt9DGAIAH8NUi/aNs6xZk93L6B3yZ 5CVA== X-Gm-Message-State: AOJu0YzjTG0HA1dbsnzCA8NElLdP6LqMlJVpF+Nw3TJ9L+5gYjf+64HG KBk/f8sephBh0GNyVzeu0gYHAWhkgLtT14hzWodhdeWmPBR40+vbLPoAIiSgUCIvheJbfYwRK6Z xapmsmWTJ7xSrC3ItvuzXyXhzQEk8oVRct9c1YA1PghBE2Ld2k7hn7KlCA0Y= X-Gm-Gg: ASbGncsUCk+ze7eKEN2vGWW8gyJLi74L9Yw+mPpx+hp2hFWL6t9aqGPQIOlN6POE6KY wZOQGoLRDB/uF2ed05Dnl8A04SHJlHQTTE7d71UahG9vXAa9mdG9BMaFSvzXvGzFc20qhBaDlXH OOMz36/RWX0z7qr6REbWeVjMaEVb7Oyau5I+x41aCw5+/1eLPTUqt64Bs3DCIeMe40d9rZWcWiO O7s5HIdYe1oBPeHesocrFuLEXwZZUUW8e3BA+tS8e2RLNwVw+cQeVytoZ3DiMCShk3KYJCopmPO tgs1kwksUzR2+p1MrdKtY9OtRUYraBEVJms= X-Received: by 2002:a05:6000:1847:b0:385:ecdf:a30a with SMTP id ffacd0b85a97d-385fd3ee334mr5400373f8f.33.1733316893948; Wed, 04 Dec 2024 04:54:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IFvdtkWkEwxi8mpcTLDx5Tk+eqhyWjoc+BX5ypLCUE7CH8mOKCeowIphEqt4hXFtq1npl/2WQ== X-Received: by 2002:a05:6000:1847:b0:385:ecdf:a30a with SMTP id ffacd0b85a97d-385fd3ee334mr5400356f8f.33.1733316893544; Wed, 04 Dec 2024 04:54:53 -0800 (PST) Received: from localhost (p200300cbc70be10038d68aa111b0a20a.dip0.t-ipconnect.de. [2003:cb:c70b:e100:38d6:8aa1:11b0:a20a]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-434d52c12a4sm23880495e9.30.2024.12.04.04.54.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Dec 2024 04:54:52 -0800 (PST) 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 v2 02/12] fs/proc/vmcore: replace vmcoredd_mutex by vmcore_mutex Date: Wed, 4 Dec 2024 13:54:33 +0100 Message-ID: <20241204125444.1734652-3-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241204125444.1734652-1-david@redhat.com> References: <20241204125444.1734652-1-david@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: O7eCnxnp2jgfvjyVoLJH1c5vnqgHYR3_MD60zY8MGc0_1733316894 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Rspamd-Queue-Id: 7350180008 X-Rspamd-Server: rspam12 X-Stat-Signature: jksj3wfkzp7ddrsu3ii7m9ycx88ksyhi X-Rspam-User: X-HE-Tag: 1733316869-805824 X-HE-Meta: U2FsdGVkX1+LP1nme4AZCTeOCs6exRReSmMppuetXqRoXUHGZyLgad5Ms3pJNL2gQ03tKw6ttZn7aeeQ6gjQ2EF0oekyiB//eD8uxYKBYekQLQvgcjZrKZZaq7mH8e+bMyGMHgOZaEQdgJavLgeCh6U3+hWCr/sz4FrI0DuU76/LcrHA6+q5XA0HqSKxtE8eEa4tsVDJOvDBZDnN0p2wiocFutmeN4Q9qidmFyWu+9WsliG/8O8kTjc+9E7IKTO4UCOPSFDDHsUpflrOBHsoa+pLDabvXxuRBuGA+SQj0XHiOEVik8kTJS0i540iylt3Y/7I1RAZ3FlgLby+T1DFRfFeTNu7EvYjwKzX1OFXKK9fLaQdrwvlL39Yh5ExJriItQcoPFOiotSMkcvNhVdrZ/wGS4QeU/SLWI0NxtzY7y4I6R8gKKbFIJvv4dhDD2GloYbaVFF1ifkt672TK+ugXYc+35rh1P4vetkFpy6M05yO84CLZD3vEQorlsspuebQST4E1w/DJOPlKNySiMaCMe0damowkdxbwZ7ROAXcN8IPq8xmGkjOt65uOZqWdSQ1jV1VrMPYHBrbR1mjaYJYHU2RFOmz4UVrtVi4OYQIICV2a0WpdufgGedNAK8QBpwTPmhGBehDYbFulhZQxncvOugpbteYCW4vaTBVw7uzHIahnufXq6+8h2atY0JK/fppWw39PiB0KtXCHLieTYx5yLzoo1JtAEq4myI1AiA2hcoDTcn20+roN8fpbpgF5ric5W6H+UfLMhooXI7cL/6AF3MXg0lIOVCBYIm1u3IGyR6XR6C1Jpb0rJ5XZ/LOqW/JREMUhF96r9OEfom551PHC+4og3hfbrtg35YhPB7sOVFsfbtaDGHx6mGz/t4t/GEBMDrw8wHjS6jpKKDpux8DTZf0btkt5fq2dswKGT/PkCa38n1JE0ngUqnAG9YjrBTnVZtNqCBD9ERCMq7k9ko jsvjO9Wq +pTBNmB828eZX8wkzfcINrzJuHOyH6J5UfoFqe2dfqTwmRxuQGTv19BNBZq7MI8G8rwq+oeTtuJ7c47pMwupxQRbV2aGqfCFtoIYnSTLwfchcbL23VPanJPlS/1fkP0cUAnfZPb+Oi7q5qqU7NZcla+PhJvBM8TgJAZa99YU98mETS/eixB1sB+UPUedb/DBiE2c2IYz8eZrs6YmDQNoTWMlDX0gtDC9+KtzgfAbIBoI4UftPq2AqQ3Ef5pgsqpfflQw05cbV0uVzaGomATvXwzVLmbumLQ92E7LOxnot3jniwM/GYzzkX1jOEMhfMceSrWvy7DlQyVEg+kLvn197KI7x4rrS0a5VQcbbIdki+m/H+Wdad7c/zPXnQmwQNur4U+o5wOHMua+WwMQd4rQthnlQbHKrY40JhREooVMJohhIes+aD0MYOaupdZw4DN08Xuj7v1N14VufChgxGsW1gp3OYVD8INcIoKEq 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: Now that we have a mutex that synchronizes against opening of the vmcore, let's use that one to replace vmcoredd_mutex: there is no need to have two separate ones. This is a preparation for properly preventing vmcore modifications after the vmcore was opened. Signed-off-by: David Hildenbrand --- fs/proc/vmcore.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index 586f84677d2f..e5a7e302f91f 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c @@ -53,7 +53,6 @@ static struct proc_dir_entry *proc_vmcore; #ifdef CONFIG_PROC_VMCORE_DEVICE_DUMP /* Device Dump list and mutex to synchronize access to list */ static LIST_HEAD(vmcoredd_list); -static DEFINE_MUTEX(vmcoredd_mutex); static bool vmcoredd_disabled; core_param(novmcoredd, vmcoredd_disabled, bool, 0); @@ -248,7 +247,7 @@ static int vmcoredd_copy_dumps(struct iov_iter *iter, u64 start, size_t size) size_t tsz; char *buf; - mutex_lock(&vmcoredd_mutex); + mutex_lock(&vmcore_mutex); list_for_each_entry(dump, &vmcoredd_list, list) { if (start < offset + dump->size) { tsz = min(offset + (u64)dump->size - start, (u64)size); @@ -269,7 +268,7 @@ static int vmcoredd_copy_dumps(struct iov_iter *iter, u64 start, size_t size) } out_unlock: - mutex_unlock(&vmcoredd_mutex); + mutex_unlock(&vmcore_mutex); return ret; } @@ -283,7 +282,7 @@ static int vmcoredd_mmap_dumps(struct vm_area_struct *vma, unsigned long dst, size_t tsz; char *buf; - mutex_lock(&vmcoredd_mutex); + mutex_lock(&vmcore_mutex); list_for_each_entry(dump, &vmcoredd_list, list) { if (start < offset + dump->size) { tsz = min(offset + (u64)dump->size - start, (u64)size); @@ -306,7 +305,7 @@ static int vmcoredd_mmap_dumps(struct vm_area_struct *vma, unsigned long dst, } out_unlock: - mutex_unlock(&vmcoredd_mutex); + mutex_unlock(&vmcore_mutex); return ret; } #endif /* CONFIG_MMU */ @@ -1518,9 +1517,9 @@ int vmcore_add_device_dump(struct vmcoredd_data *data) dump->size = data_size; /* Add the dump to driver sysfs list */ - mutex_lock(&vmcoredd_mutex); + mutex_lock(&vmcore_mutex); list_add_tail(&dump->list, &vmcoredd_list); - mutex_unlock(&vmcoredd_mutex); + mutex_unlock(&vmcore_mutex); vmcoredd_update_size(data_size); return 0; @@ -1538,7 +1537,7 @@ EXPORT_SYMBOL(vmcore_add_device_dump); static void vmcore_free_device_dumps(void) { #ifdef CONFIG_PROC_VMCORE_DEVICE_DUMP - mutex_lock(&vmcoredd_mutex); + mutex_lock(&vmcore_mutex); while (!list_empty(&vmcoredd_list)) { struct vmcoredd_node *dump; @@ -1548,7 +1547,7 @@ static void vmcore_free_device_dumps(void) vfree(dump->buf); vfree(dump); } - mutex_unlock(&vmcoredd_mutex); + mutex_unlock(&vmcore_mutex); #endif /* CONFIG_PROC_VMCORE_DEVICE_DUMP */ } From patchwork Wed Dec 4 12:54:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13893706 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 312E0E7716E for ; Wed, 4 Dec 2024 12:55:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B36266B008A; Wed, 4 Dec 2024 07:55:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AE5386B008C; Wed, 4 Dec 2024 07:55:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 985E86B0092; Wed, 4 Dec 2024 07:55:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 76D1E6B008A for ; Wed, 4 Dec 2024 07:55:06 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 33F1A41A78 for ; Wed, 4 Dec 2024 12:55:06 +0000 (UTC) X-FDA: 82857271476.05.E352D0F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf13.hostedemail.com (Postfix) with ESMTP id 60C6220021 for ; Wed, 4 Dec 2024 12:54:48 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=B+oZdiwb; spf=pass (imf13.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733316890; a=rsa-sha256; cv=none; b=FpMZpPX3mYcn4vgC9qRKTvK5PVlrnx6jp00j4MsrnxfmjFyiEYqsXHxY47tVEjPu9/26yL Kze6mFBCbn/ogvm+T3R1nD5GWQu7UlbiCBGRaOEVKITXa32TRrGFoDPI53xXLPdga6L2Mt 3myVY/4t33jZc16s1oHZZnN10RzxqHA= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=B+oZdiwb; spf=pass (imf13.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733316890; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9g+9cVRXvhHLgxGSqrQTBE7Bw6RR/sxdLnnaInZE9Y8=; b=AL0m4U9vjDohByjgme0ilGGeVylFZkUzIfPdFkpjMtBt9LEPimhKiYMHiH0dM/hUZ4arMa xI+R/qvTuljVzaDVnSbKOF/X03qPHemVjX1tI926IJoI4QHbHZSZScVc4terCeTkDFR+tK Sn9PN7mr8Ok9vcfydQ5Ke2LGn8TIAgg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733316901; 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=9g+9cVRXvhHLgxGSqrQTBE7Bw6RR/sxdLnnaInZE9Y8=; b=B+oZdiwb5JlndyQaQ9mUUlqUyKFLrgfc8DKFmCMX9ph4M4T21A0p0ie/ECoiljRwqOzGVW p4CO3Df+AVTiNzQ8CJRnDOzXu46eJIRsIAHGAIPGAT+D1p8EVM33YTmzCb/q2LH3LBRszj RYHpxwjhKbN/T37bYkQlk0gt+4T2ztw= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-595-MAjf6BCiN3687gIuUdj4sQ-1; Wed, 04 Dec 2024 07:55:00 -0500 X-MC-Unique: MAjf6BCiN3687gIuUdj4sQ-1 X-Mimecast-MFC-AGG-ID: MAjf6BCiN3687gIuUdj4sQ Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-434941aa9c2so38551295e9.3 for ; Wed, 04 Dec 2024 04:55:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733316899; x=1733921699; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9g+9cVRXvhHLgxGSqrQTBE7Bw6RR/sxdLnnaInZE9Y8=; b=mhOT/pQgzZYsbZM9gUrDzn7QVtZ/JzVGcXPDoS6BYDoI6uPfhQmGLYAUx1iJeAguc5 f7/VL3gePsq5ObNjiwSzacKHIcpV3dmglbhSxDk7zRAuRdWhAdVtW8CFSY+On2RFqs3t r9r8DWQDNqKUpaIJjp9wa6hbN0hRcjOAPV4EtY6oO+rWw9+ebQX7qrKk2LY9IVkwV3dr kAp2Bo8nh+aDnSbNguXLmT78HVEsFffdFhZUZ+jppEG1slLc+b10Cm254Ctft6arpHx/ ccABDPqTNu3A9uycFooAP9ijIorRBIjiB43r8ZT8gIR3NMW5iizOVO9SA+5h3SnDWJ3m N3hw== X-Gm-Message-State: AOJu0Yyh/0DCH5NaLQ3xlLLCBrqqGuFVEpg5MJngt+X2U6OwlZqxuSZ+ 2Coj7WJN3XQEufDgmq674cKOPqwD560+J7MoYvpPTdo9nTDaj1owLLKMk/OKnQoPmIXmleclaGq VxYq8CG622iPs9+HPS50Xps6+mDwp15LEk2uxLJBKNRiVWPB/ X-Gm-Gg: ASbGnct9hnxwoRP81rH0j6NCllPpIDF/YHTN6NdsyuYl1BVhUWdUKePd04BkJB1FIRk jvmHZUu1np46BCAjrbWCAtK3v595F5zEL7sW8bIveWca+8a3vqhFNsoyFZ5IgvIqtKjghhv1nfe PmOMvqdQkRJ3YjjDMNFzT1TS/mAowR8IsNbPDqlGJ09yEO8VkhYgY09aod3tZqGL75eIGEQUcej 0QDP8fZ4A6QF5AaJOOof8PXrXr/v4S42GkeR64/E/XJ/UQZR8RzT3lqf2N4iJK57M/zOnt2WFKL tvA27Eb72yb1+nEDlhDhOurGRd7jsAVRZpA= X-Received: by 2002:a05:600c:a46:b0:434:9e17:18e5 with SMTP id 5b1f17b1804b1-434d3f015c9mr39711675e9.0.1733316899003; Wed, 04 Dec 2024 04:54:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IHeFWcM8kn1L8FVMwX9bQLaSRcl3tsS9Ol6XIyBOc2az2VjBMSNXd7wAhtLStmYUmhz8yBnag== X-Received: by 2002:a05:600c:a46:b0:434:9e17:18e5 with SMTP id 5b1f17b1804b1-434d3f015c9mr39710705e9.0.1733316897137; Wed, 04 Dec 2024 04:54:57 -0800 (PST) Received: from localhost (p200300cbc70be10038d68aa111b0a20a.dip0.t-ipconnect.de. [2003:cb:c70b:e100:38d6:8aa1:11b0:a20a]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-434d52c0dc8sm23581375e9.27.2024.12.04.04.54.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Dec 2024 04:54:55 -0800 (PST) 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 v2 03/12] fs/proc/vmcore: disallow vmcore modifications while the vmcore is open Date: Wed, 4 Dec 2024 13:54:34 +0100 Message-ID: <20241204125444.1734652-4-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241204125444.1734652-1-david@redhat.com> References: <20241204125444.1734652-1-david@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: IUn4c9r97zpcd22sC5mDIvaAybLaAZo7uDp-6GsRjqc_1733316899 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Rspamd-Queue-Id: 60C6220021 X-Stat-Signature: 8f4pies6qobguwes96cfxswmfnpzgwcs X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1733316888-500733 X-HE-Meta: U2FsdGVkX19ktNk5BxyCpf7mpHp4YYjKl0LDJDUv3iMjVmGw765UUXry4nXRnXzcdickH5YbQV5n0xbGAkzWFdG80e2WdVJOKODfrAqL9bTLic/ffBz76QXW77avJJJkdtHIZX0nvWEX/uAkWZt56oOdHdkVhiYSs8nBRgaM5XqpFz8a7PTgwOHGgE3QCZdBXvvwtGmr4A/o7SHvg90dYcFS2fcbnEnVpZIoB9M3ZI//+yQPfI+2K9O2wlQgigzT6EHWafMJtQCSxlVOMBmMPrxH2nytpZyNda7Xzgw1VtWKRtNTi04bNbsxJfp9XT0vh9ikagckhLmGQwH0l/bJxLf9h1N1MJ9OzsHSaj1k5dkyCiGhXSOgWyZVLuM2lRFr8Wcdcu2BnJOyBZwqf1UC4mADLOD01/XWX/StYvJR+VxtPm5N1fyTTyJws0yuhXkVcKr/J1hz/mK4DmI3tvRPl8KzBLB/rqCKzKXtBvxGC5JM4rGNpbxPlRDGKnIq4zXUXq7o7n/hJkP0uZhbssxvUF2xIjjwU9ihEVTl63hzEXxuCPID+RAKBiytYEKH70OlZjoPIjhsCvqBrBwtLvDUzEvyd242MlZTUJkU6Dnq1IsTxv1J24bvh7KGqaytkDEBTWOvyk7iRQbVZj8l+qgJEvPKsUB/msj/b/2iH668W/UBw3/n9T/yTaY5eKgT9RBw1oYwcqNhnPySa7CG7/e7IhtyQS7w5pjIQ4pQbYx2dzDYbBiakWam4mlGXTQoiKTZ02W14vrSl1s4hfpoS0bMSy9S3ybVlllgERarakR01OiBdxWwDdZOLcaHQNKOsgCIJEdJ0xmBFrq7TfalzCdkLOPoVi7zFeoR3UqG9iNpfb46FHBzevJnVqOUmP069ZwRR3LpMUajgTFv+JhcdON719z6CIKMXqcw4wxNXgyjim1b4DvD108sPW1f9p1y4byhQXY/OsDZTRSxdGaXs4p X7rCZ4KJ GWH3ODFC8eWsJQ8TihW5A7c3PYul7LTGEydqpnmuAjKwCo+7rl1oirJIC8TRmTWIF9nxjKJ0zEAODiL3Ss1TiGgw3cfYZ10ULppIJzGgbD1s5ZKj/cH95Fn+/8xoQcc7Nn2sKWVI1e9K4lTez3Em67GeOFp7hCLAGqM3PNAZpH0OkzUlEFR/9jzqV+ok72SlD6X5pEP3PgilWwJPUl8qb6N0rJxFrsd114uaxybjJAEb85QVVQ4hJig5I0HJUYpHCz8BdBw9Ej0uKx/CkmcOU+plTzAvxshtJYlvEVotfKp4LH0KL387QAmDnrIkbZZ4CXXqnlM2Lk+yUOtpe2Fr3GPlyc8tgLnPOa1CNOh6j1z0vhAlUBo1873r2Ce75bQIGh9bCoivFZnansvHqbWqAqdCcnRfQzaTWc60GYBWuO7zZvrdlUVFvWnSxSw== 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: The vmcoredd_update_size() call and its effects (size/offset changes) are currently completely unsynchronized, and will cause trouble when performed concurrently, or when done while someone is already reading the vmcore. Let's protect all vmcore modifications by the vmcore_mutex, disallow vmcore modifications while the vmcore is open, and warn on vmcore modifications after the vmcore was already opened once: modifications while the vmcore is open are unsafe, and modifications after the vmcore was opened indicates trouble. Properly synchronize against concurrent opening of the vmcore. No need to grab the mutex during mmap()/read(): after we opened the vmcore, modifications are impossible. It's worth noting that modifications after the vmcore was opened are completely unexpected, so failing if open, and warning if already opened (+closed again) is good enough. This change not only handles concurrent adding of device dumps + concurrent reading of the vmcore properly, it also prepares for other mechanisms that will modify the vmcore. Signed-off-by: David Hildenbrand --- fs/proc/vmcore.c | 57 +++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index e5a7e302f91f..16faabe5ea30 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c @@ -68,6 +68,8 @@ DEFINE_STATIC_SRCU(vmcore_cb_srcu); static LIST_HEAD(vmcore_cb_list); /* Whether the vmcore has been opened once. */ static bool vmcore_opened; +/* Whether the vmcore is currently open. */ +static unsigned int vmcore_open; void register_vmcore_cb(struct vmcore_cb *cb) { @@ -122,6 +124,20 @@ static int open_vmcore(struct inode *inode, struct file *file) { mutex_lock(&vmcore_mutex); vmcore_opened = true; + if (vmcore_open + 1 == 0) { + mutex_unlock(&vmcore_mutex); + return -EBUSY; + } + vmcore_open++; + mutex_unlock(&vmcore_mutex); + + return 0; +} + +static int release_vmcore(struct inode *inode, struct file *file) +{ + mutex_lock(&vmcore_mutex); + vmcore_open--; mutex_unlock(&vmcore_mutex); return 0; @@ -243,33 +259,27 @@ static int vmcoredd_copy_dumps(struct iov_iter *iter, u64 start, size_t size) { struct vmcoredd_node *dump; u64 offset = 0; - int ret = 0; size_t tsz; char *buf; - mutex_lock(&vmcore_mutex); list_for_each_entry(dump, &vmcoredd_list, list) { if (start < offset + dump->size) { tsz = min(offset + (u64)dump->size - start, (u64)size); buf = dump->buf + start - offset; - if (copy_to_iter(buf, tsz, iter) < tsz) { - ret = -EFAULT; - goto out_unlock; - } + if (copy_to_iter(buf, tsz, iter) < tsz) + return -EFAULT; size -= tsz; start += tsz; /* Leave now if buffer filled already */ if (!size) - goto out_unlock; + return 0; } offset += dump->size; } -out_unlock: - mutex_unlock(&vmcore_mutex); - return ret; + return 0; } #ifdef CONFIG_MMU @@ -278,20 +288,16 @@ static int vmcoredd_mmap_dumps(struct vm_area_struct *vma, unsigned long dst, { struct vmcoredd_node *dump; u64 offset = 0; - int ret = 0; size_t tsz; char *buf; - mutex_lock(&vmcore_mutex); list_for_each_entry(dump, &vmcoredd_list, list) { if (start < offset + dump->size) { tsz = min(offset + (u64)dump->size - start, (u64)size); buf = dump->buf + start - offset; if (remap_vmalloc_range_partial(vma, dst, buf, 0, - tsz)) { - ret = -EFAULT; - goto out_unlock; - } + tsz)) + return -EFAULT; size -= tsz; start += tsz; @@ -299,14 +305,12 @@ static int vmcoredd_mmap_dumps(struct vm_area_struct *vma, unsigned long dst, /* Leave now if buffer filled already */ if (!size) - goto out_unlock; + return 0; } offset += dump->size; } -out_unlock: - mutex_unlock(&vmcore_mutex); - return ret; + return 0; } #endif /* CONFIG_MMU */ #endif /* CONFIG_PROC_VMCORE_DEVICE_DUMP */ @@ -691,6 +695,7 @@ static int mmap_vmcore(struct file *file, struct vm_area_struct *vma) static const struct proc_ops vmcore_proc_ops = { .proc_open = open_vmcore, + .proc_release = release_vmcore, .proc_read_iter = read_vmcore, .proc_lseek = default_llseek, .proc_mmap = mmap_vmcore, @@ -1516,12 +1521,18 @@ int vmcore_add_device_dump(struct vmcoredd_data *data) dump->buf = buf; dump->size = data_size; - /* Add the dump to driver sysfs list */ + /* Add the dump to driver sysfs list and update the elfcore hdr */ mutex_lock(&vmcore_mutex); - list_add_tail(&dump->list, &vmcoredd_list); - mutex_unlock(&vmcore_mutex); + if (vmcore_opened) + pr_warn_once("Unexpected adding of device dump\n"); + if (vmcore_open) { + ret = -EBUSY; + goto out_err; + } + list_add_tail(&dump->list, &vmcoredd_list); vmcoredd_update_size(data_size); + mutex_unlock(&vmcore_mutex); return 0; out_err: From patchwork Wed Dec 4 12:54:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13893707 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 AED9DE7716B for ; Wed, 4 Dec 2024 12:55:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2353F6B0092; Wed, 4 Dec 2024 07:55:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 198DE6B008C; Wed, 4 Dec 2024 07:55:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F07106B0095; Wed, 4 Dec 2024 07:55:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id D37E86B008C for ; Wed, 4 Dec 2024 07:55:07 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 672671A0F5E for ; Wed, 4 Dec 2024 12:55:07 +0000 (UTC) X-FDA: 82857271686.02.8EE1C57 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf05.hostedemail.com (Postfix) with ESMTP id D4B39100009 for ; Wed, 4 Dec 2024 12:54:37 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Y61/oog4"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf05.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733316891; a=rsa-sha256; cv=none; b=Xr5yjBAjovCNmJ+X6+aDrQL6DfUXpt72kO5AywoIUR4kL/QzwqG1syhkxOaGHdfjF05/xQ A9nkg+EKR/LCXA+7ZOEA1Z3lrLi6VgCCg21s8RzkXQz4A4j2v5M2EwU1QeAqkkRXq6xjbS 8RlkRW0e3I9ovQouURDx9psoGFMgsNk= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Y61/oog4"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf05.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733316891; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=WYRTkbcHet+ClCO8Q7Li/qxr/6/P0nWlLIIrfww7Knk=; b=lSm/l+ddvqSZwrFqArCfjx7svKVkK6Oq5Y3yPpge94OpoX4tIUJRG7DUTRTi/dBJTZT5s0 OO0L+s3Bql23rn7FXVhEafvUX2RZttDeVmC/g2IvfeLC+T11EY689MZrE4z4U8tVyUll7l 4mWI1066I8Z4Kybg0rk0MWnwzh3keOk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733316904; 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=WYRTkbcHet+ClCO8Q7Li/qxr/6/P0nWlLIIrfww7Knk=; b=Y61/oog44c9mfWK/9Lb1pXrmZs1Bv79yc8ORNxSdf+MHUI6xkgPQ+5OK9ZXO/RigbCDjuV 4qfEPCfBVI+RNQsma/hCzzRHLemuKdOBZkE/1j+HvDp4j/ItrjAEJt7fPlF9QiswFVZfiE YOzyShuA3CuddSYRqe5g0xTDHVTKS44= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-621-0KvyXhe8OWSR-t2u2L7d0A-1; Wed, 04 Dec 2024 07:55:01 -0500 X-MC-Unique: 0KvyXhe8OWSR-t2u2L7d0A-1 X-Mimecast-MFC-AGG-ID: 0KvyXhe8OWSR-t2u2L7d0A Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-434a467e970so47936795e9.2 for ; Wed, 04 Dec 2024 04:55:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733316900; x=1733921700; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WYRTkbcHet+ClCO8Q7Li/qxr/6/P0nWlLIIrfww7Knk=; b=AnW9v8BfEXMvwkv3jvi9fILNEYnDqFnr3+yiMWmi0t2ce44bIXxEUylIRfxDEL7O9C RTLEhJfqgFk1Zmo/MuyOBVuECieb4cIdJBKmw3XguN6oECIHB1pERUzU3/Rrhl96RgFx lkWExBS3D1DXqLpBID/eLIB1nzunlb62tQkk9lelc6aMtRGijqsJGtr2A6sB4dS6F6L/ MpVzX0ICalhAdhVPuT7hVzruQBKnnE717MYCLRtP4sXVJVYEStcPqpnoLpsaHSOf4Y0B QTMrxnHCRT/aKxS4CV0X+muvoHM4FbMCFbiQv2AFulhTceMLH0JpS9IISs2DYOzxMKKJ wxCw== X-Gm-Message-State: AOJu0Yw3EgmhYKHr+pUGoeTDX/JPw6Ci3lMQ0Rt6yKwRflRPDDvKnN9V 4u25WDl3BeRUDxW/tWZGPxOtbMNHPWoc21pyMInpP5RJA5KLe6fZVYWtmAMTrV8bZhu87U9omeC cqMO1irUKcve/He9LVpfwGXRzOpqmKQYf3bv8Ayvj8BQPcn5bfELZNd575w0= X-Gm-Gg: ASbGncvkeoBq+7yF9o5BSdmFzijNwRBMf3j+P6ABMV8acbZbUqGjxVse7V09ZUVBaNC fhzPlegiSpLrJl7uZiD6kDPdNkcC9tUOWf9z5nEHlXWQI6/U6pp7Wu5UYDQHAsYJJcK5SQ1oXOI pbk5K8J2frsuMOsf5cLtnM2JI10PLXEVrKRR05MPBb7fjfG4Ze3KSK2938qzWYG8XwgjSBvQc+x 8RstdnYtvWk6EUfQ8YVVBn6hUuP5xxpvv+/n9nhYrJx/UAkLL7tuOPADPKrBaQTamiLEvVG4KgG 7n69REbHaT2sO3r5osW6TBv40dXWyB55NJY= X-Received: by 2002:a5d:6c62:0:b0:385:f677:85af with SMTP id ffacd0b85a97d-385fd53ee5fmr5431758f8f.47.1733316900237; Wed, 04 Dec 2024 04:55:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IGkIZLfFS9dd4mzise8YhuqVkFTd47qC7aw9US3336mGUo5e0+UH/rIIT1Petk2to7fPbudFQ== X-Received: by 2002:a5d:6c62:0:b0:385:f677:85af with SMTP id ffacd0b85a97d-385fd53ee5fmr5431725f8f.47.1733316899810; Wed, 04 Dec 2024 04:54:59 -0800 (PST) Received: from localhost (p200300cbc70be10038d68aa111b0a20a.dip0.t-ipconnect.de. [2003:cb:c70b:e100:38d6:8aa1:11b0:a20a]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-385ccd2e1bdsm18785865f8f.9.2024.12.04.04.54.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Dec 2024 04:54:58 -0800 (PST) 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 v2 04/12] fs/proc/vmcore: prefix all pr_* with "vmcore:" Date: Wed, 4 Dec 2024 13:54:35 +0100 Message-ID: <20241204125444.1734652-5-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241204125444.1734652-1-david@redhat.com> References: <20241204125444.1734652-1-david@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: hcgpTp4vsPff7omPDCFvH0m5nZXXCDp06Iqd0xrgpt8_1733316900 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: D4B39100009 X-Stat-Signature: qxu3akb9y5wm7km5rj65p8gf3g3kdnts X-Rspam-User: X-HE-Tag: 1733316877-214501 X-HE-Meta: U2FsdGVkX1+qR1JB6WX7+9MHEwtIO/TkSjo7iOgwREuQK6z7hTkUhhWb2aR7HTZigzRi122a7A0pUriuDFoYNRFM0p0SYcllUw77hZxo/q1Wii+4/+fZRDc81ofpg8A8C9esajXYlgaiCrMvoEy5t2ZAIDetm3qtT15CwOOpXU7Wr2XUjz6GOMjv9gtR9uLFS3wQTGtvFVkgO6DdtaPUz514413lBp0KBwAbnHkJ5yGYIBgAkvAujv5B5EUpKTeDzm3KCBIYb6KnO3AJ4Eveld/2wOqWz4K9kWJZ1khUhY9xUPUMJkgiELZIrUlGpDmxkabDU1OwNGJt5gO0IzGXjp1wfsqrzR2uQzzcR2SEUHZ53+n1fHlR6zvUTQ1fE0x4wdYO1XpNpuW+q49NaN9F2zwRp7nUcvGgNri52xtuk64o+lfwN7FpaXk03moSl0TG8S0mvpqtByru3X2UaKbix4A/O8Dv1pn+gBvpy2WZUcSoWQi6FKeZgqoZvObgVcgXrhRqGWhKA1KhwLxXqq6ovtc3+2EIWDsA8z0lWIdS7W9UdEbjp/4oJueNxtct9tRIHlFqEUcQirOIfHaROdKqlyrj4qzUUYP0A7m7x0oX79ZeszEhDK0WImwjQH207ycCMYDzSqpOQ/kUuhrIPeuyLdkR25jnIPPNMotlXGjGVf218BYO/WyFPf0/E8ebnOml7977kMNdKhu2Qz5ObHXKQJpVu7kjtRgUezYxuXX6Omkcp3SK/KTLroD2MxyC17Ww27UstBrJ91N3touhlmGOUAeBxSZ4iAyKq1GFvYgssbIdlmyYXKlKcr5l7Xug7pyLFdF1+cTyHzLOG93vrpXhPPxJLhoBFWZrThjDwhRXV21ERAS8ADP1HduG03aiAfn9M0wuuI+v8KnTGQB9cihBJwpi0WM6fbs/e6Z5RAkV9QpDAQWh/sHHY928sfkNkl5Aa/y4DKiHlJS/n3WKDqU AMHpbkVA EK9g6B5yFLGPoi/uyyadDrbmgJaNeSwuGn3EZ3hWAgGLeGhMzBP/RNWaQFN2+XU6vpwjJpeBopJ5AMcRbWKclCpky8jULaQtnWuXkGjVwhpj1tGG8M3eotQ2LXWqixOxcdSic+kfB0DB1w6gDmAz3Yrq4GU5L9hXv/v1VuTzgyAj8JYZTkx/LGJeNSssO2rNlsiJcncz5d2jbCxDhRd0cy6MPt97b+hK7F6GzMk4MYI/NkFizQ86vE9PBaGyGuvseAGETshrmWlKDI7V7Fx0A/JGQUrrOPn76hjG+ughU7HqL+M8CxWG8+z+0mA7My6DkmRXPrecvh90LdXOuzqodP3jL28XVOgLsXsNdFP9Ri2A6MnrvbH7dZ+MNgO+vAzOgjzIFVc+kSYKFP+ijMk2Iw61fmc67K43RDw/Z31eDfph0JKUOJkmCS4DP4eMjJC4w66O3bAGokgoEoGoWensVOnorJmX/CA4cnqaq 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: Let's use "vmcore: " as a prefix, converting the single "Kdump: vmcore not initialized" one to effectively be "vmcore: not initialized". Signed-off-by: David Hildenbrand --- fs/proc/vmcore.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index 16faabe5ea30..13dfc128d07e 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c @@ -8,6 +8,8 @@ * */ +#define pr_fmt(fmt) "vmcore: " fmt + #include #include #include @@ -1580,7 +1582,7 @@ static int __init vmcore_init(void) rc = parse_crash_elf_headers(); if (rc) { elfcorehdr_free(elfcorehdr_addr); - pr_warn("Kdump: vmcore not initialized\n"); + pr_warn("not initialized\n"); return rc; } elfcorehdr_free(elfcorehdr_addr); From patchwork Wed Dec 4 12:54:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13893709 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 EA2A1E7716B for ; Wed, 4 Dec 2024 12:55:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7DBD36B0095; Wed, 4 Dec 2024 07:55:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 78E0A6B0098; Wed, 4 Dec 2024 07:55:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 590756B0099; Wed, 4 Dec 2024 07:55:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 3176A6B0095 for ; Wed, 4 Dec 2024 07:55:10 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D1130140AF4 for ; Wed, 4 Dec 2024 12:55:09 +0000 (UTC) X-FDA: 82857271686.16.3DFA7DE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 21B062000B for ; Wed, 4 Dec 2024 12:55:00 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dhDYX9yu; spf=pass (imf03.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733316892; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=AVSVbg92vBS9ECQ/qpyBYmAQmSQp+EsDoLv4fB2tW0Q=; b=unX2rDbrbgy0mmONiOR3+P3oPqLda+pt267Vn6LuO5iMpEnZOoEocinoSEcGI+/Jnh7v36 DGqvCDWUoNerTBmXUoAnmpayLLYcrZzh4O85MX4Rus1zm4DE3hwmMjpFskoNO5+2XL2A37 UQZCxiQO/8rJyY7qxpb19n0MG2UeWOU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733316892; a=rsa-sha256; cv=none; b=4UXm41hvAsc1sFCCClpMx5ZUhEIUXA3wt0hZof8pNRA26a0S9fhNQFhg26f0OYiX8MTqQ4 NpoH1eB6Y86dlg+I1/69f6DuFF16pkYfNdLWOe2v39sEAWw4vUuhJ4gb+vbqXU7DR5UN6O 8k7g9n+0qI4fWy0dr2ncRfpXrpFX8Ao= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dhDYX9yu; spf=pass (imf03.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733316906; 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=AVSVbg92vBS9ECQ/qpyBYmAQmSQp+EsDoLv4fB2tW0Q=; b=dhDYX9yu3TDYq4KYGDXG+DYAuSCNuabLgdEZOocFaMMM3bFTl0J58nYQqTCrjiSLsXjTGp edqyBQkkSgQAAtvyfigoe9QFymPWXf/cw9JEmH33YEKPr5bkm3SKMB5NyGTMq97PbMbK5f x70Znfu7oksw/x1Ahne4x0ihMG6BYmc= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-629-TJKGIPHkMeW8PpNB6OvNWg-1; Wed, 04 Dec 2024 07:55:04 -0500 X-MC-Unique: TJKGIPHkMeW8PpNB6OvNWg-1 X-Mimecast-MFC-AGG-ID: TJKGIPHkMeW8PpNB6OvNWg Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-434941aa9c2so38551885e9.3 for ; Wed, 04 Dec 2024 04:55:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733316904; x=1733921704; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AVSVbg92vBS9ECQ/qpyBYmAQmSQp+EsDoLv4fB2tW0Q=; b=Bd2wSNZ+3yMISBHaGKHSWHUK7I3xXaffoEWSYlXqOx06r8Nk1J0dayOS5rrarxrEsV mtidcDbxa+hFd4BoqDBCzfNq0D0RlFPjIflcEVllL+oDf0qyxWZ3/9xlnPsXObECbMUP B/q18lyKRk6W/tQOO3hzvP1e/pnW48T+OIGE0lZiYdyP8iy/NjV1wVwUkT1fi+Cf/r9N VPAqWi2xUc13R67XZ7eqNCkdl2XduYseTLzNleihVAHuaXV7TAFLUxD4Mve+/R+emk/9 yyykP/wN0k/Cmcj7Z096+7qd1XH4Q0Fk39weU62TTPqiXx+0GuRCwZ6d5uMtu31hAFID 81Dw== X-Gm-Message-State: AOJu0Yz3GgUds0ipsAHTp4qtqpaOF4v0iLHtTr4a2vnuk61OujAth/cJ Ms/nc2pLQzMfqQHEtv+1AgCast6T6/aM/ObI9ZYovTBfNRwG4Tm7l2b1uDxg6uy8cZ5ipK44yhR Xw8rNy/XpdMZPcom0Yg+J6z/Ht0eMKGso6IZhsz38EyxNkEZ/ X-Gm-Gg: ASbGncvuFu3H3mkc4GiPWxdeW3t1q1M3Qp65W00LpgcM3X+NU/HxZTJNvvviyRHQVqq WlVR2oTBVTAw92wVP5h/KZR8jB1Nq/5jPygEmPQVqbnb38arsS2qca0+ksfbFVxRYZqQ/+ny4NC K7IDg4nhpHn+qr9PJL3PrmhqFJfg8KSJf+82scRJAX/yJQKWdu7lGZKAsb1Pg61fqBCJel9nU0v JlTkevWiJbMSZCQFrnel5teHdn4cavex7Z0b6OKkZ3RHfYMbmBR6U/slwT+cbfBMFiyzZeGLr4j PiXE0uq32Lk239Xwoe5o/MGl1tiS7/BqS2s= X-Received: by 2002:a05:600c:1906:b0:434:942c:1466 with SMTP id 5b1f17b1804b1-434d3fe3665mr34089915e9.29.1733316903708; Wed, 04 Dec 2024 04:55:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IHp2zQuzmhokkabZpnrzoR4CmRg7d0WsOdBj322Nwyq7pIMtC1YAe5DPX1PH/Wsn3EpBmq5yA== X-Received: by 2002:a05:600c:1906:b0:434:942c:1466 with SMTP id 5b1f17b1804b1-434d3fe3665mr34089715e9.29.1733316903376; Wed, 04 Dec 2024 04:55:03 -0800 (PST) Received: from localhost (p200300cbc70be10038d68aa111b0a20a.dip0.t-ipconnect.de. [2003:cb:c70b:e100:38d6:8aa1:11b0:a20a]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-434d52b66ecsm23469265e9.39.2024.12.04.04.55.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Dec 2024 04:55:02 -0800 (PST) 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 v2 05/12] fs/proc/vmcore: move vmcore definitions out of kcore.h Date: Wed, 4 Dec 2024 13:54:36 +0100 Message-ID: <20241204125444.1734652-6-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241204125444.1734652-1-david@redhat.com> References: <20241204125444.1734652-1-david@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: HqQ6vWDVNfNnUy-mHNH5nCzRNxyrSATmpPlm5Z0gV8Y_1733316904 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Rspamd-Queue-Id: 21B062000B X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: pqc7niwqnj6ufd4gq6yoo9fqykn3o8nc X-HE-Tag: 1733316900-204922 X-HE-Meta: U2FsdGVkX1/mB+hap6BntZ7mEj2tRr8Az2sorBp8WeZkiBaJP7jgvvE122v3nFB+irs/9v/MvTusCbXEdNB44A/VX9o6pzoIPWId9AXzBXw01VqMUhQcHpeaNuDG4rjPdBv6YCISuIDJrRDpBaIVG6E7zx+qFW6bgAtUsUtF1EfBrzGd5xhNUUWXbLssBqiBvrR+m/PeoFYDlr3TSpZglX/PiNkiOxzGJJLOepLnnYMncpP0hNAzgrlUN8PNJNOt2rDWhre6RYQU/Kdbxkz7tfB2i0ibEkQLbOUagfm+EbjdQHNmoqNe7FzpesckSRJpWeeohgJ8bohGVlBPwNG7Nm3xK578Tx99x8lNEQfhsJRIZdwK71uUcnHRHuccX66JrP+RPa8Gkwdse8Q90AbnHk0VvcbhSaGUmymSLIJMzYME5y6aOFwT127ngG1jMSvqt3a872hTkIm8iBjWDX+duDieiLu+NcfTIKY2ITWl0CPZNlYmO5f64zRSkT4EMwYf0fCkubijRuXdxzEn4qrD/1CbMvM+1y2BZ2FCfOkT1M0y/5JymZJDYUt29M5D6Ef+QU0Mb2wdO+BTeUe0rdEC3qOSUCO3i9hFYZsvKFB1Dr8YOZ96h8Ko3BtffRr/kZi0kRrdXI7mdBgv3CfdepcjCMp6VneNuH2Q7wQa2qujbTLIkvQjDSTpw7EjIwcjH38qPsXgkZL+WhtCkkf89Q1HS2FlmYLKXLJ+A2sziTUvhKdLmhyEsiCapp9a/1S5UdxF2pVQk3qQQAMLG9d6c4TDDpLEf+1DL9cWZ+WOHY9zS/J8A4hOVl0olUr4/Si9IlW5z41cs7IO+8Gl9TkftG5tlhYcM/PutC/bBO+KJvp16np88gmtIAT0hplj0iA06GsjfRsfeC3I6f4LBGmQaMIx+dJR4bd4tDIhzyz+zAK6Nlmvd/yGNAfCgb4uevJWfvCO+i22LbgCW6K0LiTLL5Y R3Yc5QEY BB6Yj29QP8eZj/qYKLCUdYxVPvpzIgHmHraFGhnZDRYIlfrMJykzAI2DlVpKphZ+AHygiSJ5NixlOewj0WJez2Lu9BsgsxiQThZ5TG4KBmDd33o/Jiv9Z6We/jLBz4g3vbNM/ITm8xnhovehN3LluREp9gS4ga0/3cROZOBH0c2tZ3gXMb+E/CAZlrIvI+chBZ3C0Tdhh46pRX7HZ7rQPFqPH+SDviOG1WrdE1LvtGGMP5S2UGgkmsZHj14aOeHZ+w6Ih0GqulUDeZ9lRZcH/qdQrkSMU8FzKgcJ5lhN9Ak83eng/XEYyxLI39II57fP+DfYXGZM69vkkcQlO6NGgXSU7yvZmCMM5s/Dm2P6n2NNMC25PMIvfZm2SkHuoKGoND9RNJ5pReDZ9dELbqvVDH9k6TQoxprx5+GrOygVuZJ1r3NaiPFB+10FxaA== 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: These vmcore defines are not related to /proc/kcore, move them out. We'll move "struct vmcoredd_node" to vmcore.c, because it is only used internally. While "struct vmcore" is only used internally for now, we're planning on using it from inline functions in crash_dump.h next, so move it to crash_dump.h. While at it, rename "struct vmcore" to "struct vmcore_range", which is a more suitable name and will make the usage of it outside of vmcore.c clearer. Signed-off-by: David Hildenbrand --- fs/proc/vmcore.c | 26 ++++++++++++++++---------- include/linux/crash_dump.h | 7 +++++++ include/linux/kcore.h | 13 ------------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index 13dfc128d07e..8d262017ca11 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c @@ -53,6 +53,12 @@ static u64 vmcore_size; static struct proc_dir_entry *proc_vmcore; #ifdef CONFIG_PROC_VMCORE_DEVICE_DUMP +struct vmcoredd_node { + struct list_head list; /* List of dumps */ + void *buf; /* Buffer containing device's dump */ + unsigned int size; /* Size of the buffer */ +}; + /* Device Dump list and mutex to synchronize access to list */ static LIST_HEAD(vmcoredd_list); @@ -322,10 +328,10 @@ static int vmcoredd_mmap_dumps(struct vm_area_struct *vma, unsigned long dst, */ static ssize_t __read_vmcore(struct iov_iter *iter, loff_t *fpos) { + struct vmcore_range *m = NULL; ssize_t acc = 0, tmp; size_t tsz; u64 start; - struct vmcore *m = NULL; if (!iov_iter_count(iter) || *fpos >= vmcore_size) return 0; @@ -580,7 +586,7 @@ static int mmap_vmcore(struct file *file, struct vm_area_struct *vma) { size_t size = vma->vm_end - vma->vm_start; u64 start, end, len, tsz; - struct vmcore *m; + struct vmcore_range *m; start = (u64)vma->vm_pgoff << PAGE_SHIFT; end = start + size; @@ -703,16 +709,16 @@ static const struct proc_ops vmcore_proc_ops = { .proc_mmap = mmap_vmcore, }; -static struct vmcore* __init get_new_element(void) +static struct vmcore_range * __init get_new_element(void) { - return kzalloc(sizeof(struct vmcore), GFP_KERNEL); + return kzalloc(sizeof(struct vmcore_range), GFP_KERNEL); } static u64 get_vmcore_size(size_t elfsz, size_t elfnotesegsz, struct list_head *vc_list) { + struct vmcore_range *m; u64 size; - struct vmcore *m; size = elfsz + elfnotesegsz; list_for_each_entry(m, vc_list, list) { @@ -1110,11 +1116,11 @@ static int __init process_ptload_program_headers_elf64(char *elfptr, size_t elfnotes_sz, struct list_head *vc_list) { + struct vmcore_range *new; int i; Elf64_Ehdr *ehdr_ptr; Elf64_Phdr *phdr_ptr; loff_t vmcore_off; - struct vmcore *new; ehdr_ptr = (Elf64_Ehdr *)elfptr; phdr_ptr = (Elf64_Phdr*)(elfptr + sizeof(Elf64_Ehdr)); /* PT_NOTE hdr */ @@ -1153,11 +1159,11 @@ static int __init process_ptload_program_headers_elf32(char *elfptr, size_t elfnotes_sz, struct list_head *vc_list) { + struct vmcore_range *new; int i; Elf32_Ehdr *ehdr_ptr; Elf32_Phdr *phdr_ptr; loff_t vmcore_off; - struct vmcore *new; ehdr_ptr = (Elf32_Ehdr *)elfptr; phdr_ptr = (Elf32_Phdr*)(elfptr + sizeof(Elf32_Ehdr)); /* PT_NOTE hdr */ @@ -1195,8 +1201,8 @@ static int __init process_ptload_program_headers_elf32(char *elfptr, static void set_vmcore_list_offsets(size_t elfsz, size_t elfnotes_sz, struct list_head *vc_list) { + struct vmcore_range *m; loff_t vmcore_off; - struct vmcore *m; /* Skip ELF header, program headers and ELF note segment. */ vmcore_off = elfsz + elfnotes_sz; @@ -1605,9 +1611,9 @@ void vmcore_cleanup(void) /* clear the vmcore list. */ while (!list_empty(&vmcore_list)) { - struct vmcore *m; + struct vmcore_range *m; - m = list_first_entry(&vmcore_list, struct vmcore, list); + m = list_first_entry(&vmcore_list, struct vmcore_range, list); list_del(&m->list); kfree(m); } diff --git a/include/linux/crash_dump.h b/include/linux/crash_dump.h index acc55626afdc..788a45061f35 100644 --- a/include/linux/crash_dump.h +++ b/include/linux/crash_dump.h @@ -114,6 +114,13 @@ struct vmcore_cb { extern void register_vmcore_cb(struct vmcore_cb *cb); extern void unregister_vmcore_cb(struct vmcore_cb *cb); +struct vmcore_range { + struct list_head list; + unsigned long long paddr; + unsigned long long size; + loff_t offset; +}; + #else /* !CONFIG_CRASH_DUMP */ static inline bool is_kdump_kernel(void) { return false; } #endif /* CONFIG_CRASH_DUMP */ diff --git a/include/linux/kcore.h b/include/linux/kcore.h index 86c0f1d18998..9a2fa013c91d 100644 --- a/include/linux/kcore.h +++ b/include/linux/kcore.h @@ -20,19 +20,6 @@ struct kcore_list { int type; }; -struct vmcore { - struct list_head list; - unsigned long long paddr; - unsigned long long size; - loff_t offset; -}; - -struct vmcoredd_node { - struct list_head list; /* List of dumps */ - void *buf; /* Buffer containing device's dump */ - unsigned int size; /* Size of the buffer */ -}; - #ifdef CONFIG_PROC_KCORE void __init kclist_add(struct kcore_list *, void *, size_t, int type); From patchwork Wed Dec 4 12:54:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13893710 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 EDAFFE7716B for ; Wed, 4 Dec 2024 12:55:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 93B306B0098; Wed, 4 Dec 2024 07:55:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C2C86B0099; Wed, 4 Dec 2024 07:55:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 716F66B009A; Wed, 4 Dec 2024 07:55:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 4D8D86B0098 for ; Wed, 4 Dec 2024 07:55:11 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id EF47C1A0F5E for ; Wed, 4 Dec 2024 12:55:10 +0000 (UTC) X-FDA: 82857271854.02.213EBE6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 8C6F14000E for ; Wed, 4 Dec 2024 12:55:02 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZXB0Qe3S; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf12.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733316902; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3TMBFu0zsYs/BK8mI3BuEemyVvVnFxsrbDwOUtwonV0=; b=FmE1nZi7R4pOBI2ePjpsHLOxqgTEi5KJO1WbKLUH1dlODD/XNOO6qzsZAuC+mnFCymPykk RmQerk1MDGtS5OhCoF6Gqa29Tn9eIO2ZSJOP747BZtLHJjrfoEIT20sDLp/ZaSAX7h3bE4 IbvjzmfuhofZarRCyhZKKpPHnYfI7Z8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733316902; a=rsa-sha256; cv=none; b=f7CQt+ySUyTpLfOXrAIKPVEGdg67rghf799t7hx9L3SFx6M3zp5ZzEV0MX5SrgD6U7pWCa nDhkpJl9bpEpQiyVrZ6QJu7Jsw2evIrHNskA/t7xVUrtIDi87ZS+FvDnlLcYe66ikylNSd 9r3nAu1elo4HVrt66AnfXyWGZrthiHc= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZXB0Qe3S; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf12.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733316908; 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=3TMBFu0zsYs/BK8mI3BuEemyVvVnFxsrbDwOUtwonV0=; b=ZXB0Qe3SDwA17RUnOpcp43lo8CjYMTnbwYhE0Mn+TFbXoj1bmgn1pROo6WcPntOt3C5hGs /AbhT01j6InMCpUNxK36PG5W2ehXOFWS+EMzkvMZ1ZX0BHCSEoRNNuD5z9YjlAsxciA4VA nIH5QDabJZXgJKAMRVOMZQl09TeagLQ= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-470-tqBpXxNOMmu0WgDst4DU-A-1; Wed, 04 Dec 2024 07:55:07 -0500 X-MC-Unique: tqBpXxNOMmu0WgDst4DU-A-1 X-Mimecast-MFC-AGG-ID: tqBpXxNOMmu0WgDst4DU-A Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-385dcae001fso2825622f8f.1 for ; Wed, 04 Dec 2024 04:55:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733316906; x=1733921706; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3TMBFu0zsYs/BK8mI3BuEemyVvVnFxsrbDwOUtwonV0=; b=PaN3U4e9ZwH4+GJ848fqsW8r0tc/7LPZhZkmxR6MXhT6Lvmy0ALVLh/m2GNKz0T+nX 1hXpfXcCX+C1JkbiPtKjNnENzuROQgJY249M5KMBua8YZeaV3VSJ5bxiysaTiOBPwr0b xF/lUXEETf8qdTjNwIxoNujhtLu80GNPehIEyeg3gRzRxvfZvZUh1ORTXx7hLm/OxrPW nahif1p08xwaw8g9zLlcp/zXQFols3zJLiCzTOGMJNqnEbNTIpb7yoAJWqiM9QO3xoc4 TCuLshal2uq1SMwVOYvlCRQ3wpXKY6HqB1iGFgY/ZytQKsyB0hQbT1AkadWhWyQFINs0 xiCQ== X-Gm-Message-State: AOJu0YxAUZybIVPvTgPz7PkV189DicKqnH02K5NYj5ct9tP3BXmHlWdM QnY7kL0u6zZxcP+6U6AC7kmZ2dXrfhDSmwlpoP/LQw6sbdauA8LNuwtYA7YA3OhLdniGybsu5Eb fgh7dP0yFdXV2cRzENXL7fKdAwM2KiKo6i6m4RzInO+0F5BZA X-Gm-Gg: ASbGnctwSXOSA64DuM+Ktx+9Hf0yzidOw8bvEYXbRfzcH1d5ec73zeXOTcsS+diMhw1 KW9a+D6ECt+3hAak0Nv36InTSK/1IGTQ9TcP4UU09GKPWrhEFatvbNdgsf0zUHCBUtLjBHNetYn SEBuda3nXPOECRqRHijrwObFQTkWtU6aAb7HmAPQep4pZgKBZn+HTj1/wMCCXLERSMNPm4sZ1Mc Khue4NndHrdhdmvuIEvdD5w3JsJIwkYwVmzlJMAVTypY8LutGesSfc39zw5AtYg0EEK/SqazMh2 StS+z4qiCd+MKqWJ6aGKCShHpal4Zc1y6c0= X-Received: by 2002:a05:6000:156e:b0:385:fa2e:a33e with SMTP id ffacd0b85a97d-38607c0e1e7mr3561607f8f.43.1733316905759; Wed, 04 Dec 2024 04:55:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IH3Vs5XvVpD9wVjl4Do+O4dwdUFKsmLeUCgsK0LBk5udBDNdRPox9DV3gXL42llKQONJirIJg== X-Received: by 2002:a05:6000:156e:b0:385:fa2e:a33e with SMTP id ffacd0b85a97d-38607c0e1e7mr3561572f8f.43.1733316905408; Wed, 04 Dec 2024 04:55:05 -0800 (PST) Received: from localhost (p200300cbc70be10038d68aa111b0a20a.dip0.t-ipconnect.de. [2003:cb:c70b:e100:38d6:8aa1:11b0:a20a]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-385ed8dee66sm10241947f8f.104.2024.12.04.04.55.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Dec 2024 04:55:04 -0800 (PST) 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 v2 06/12] fs/proc/vmcore: factor out allocating a vmcore range and adding it to a list Date: Wed, 4 Dec 2024 13:54:37 +0100 Message-ID: <20241204125444.1734652-7-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241204125444.1734652-1-david@redhat.com> References: <20241204125444.1734652-1-david@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: G0SOST6jghLeFlVXIYDtywo0TdRcW4IuFgaVnJtssyk_1733316906 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Stat-Signature: y5fxqz56bswtm3hqsxa1uaeqe3aw9yoq X-Rspamd-Queue-Id: 8C6F14000E X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1733316902-380828 X-HE-Meta: U2FsdGVkX18zOG1EUaPnsrxTp9D8wkuhLP4FYbHndGEuocvE9k+jyX9aWfoIo0X34+cGF+1OozKzkDv0B6OL80kTq1AoQrg1GfDVvaX0cvHeJsJZQTCY9ntJzpGU0ZZ23H+JJhY9Wc+Impcu77JTLEGTLC8OyzCFbke7uEgABK09+HO4qe9HQLHTbD1AY8hlCOIOYLSsYK9IosIhNGyeyp9qCDAlZP0/X5RK+KbAmlR8zFEVByk/tuuoz/HHHyg0svb3hZAYlTaqe7qLIaWviKdqStjR6H/SvGg4Zia0YB79nqAKjRZyA5v6oQ66dT/bBjJ0OZUAtAsUsYFx42Yryq4RvnHFrpWZQl8xBCjLcxCOp+rCt/KJqQgnYbzFMqmm6y7m7BfymotnWX1WBY9Njn0nP6ELoAD7fWxiKFKTmS8x9J/9vYo0CMzLWNU361FE85FqJJmdBzflvjzlneWT2sa6wwj0e5F9rPu/8fyMGT33Wf6IoBN3RguxQ175TyTIf2w0H4HRhNDRkkKnI1BApBW+1QughY0UzxRWAUpt3oAEFLeoTVqZW1j8GQ5CM9jKyA4fPHyOhtxNAceJaNpuBaGmA9gI8ohXjKO31zeMChyuMkPxtD+U5e4u1clpMjgkQResgFiZJk4Zs63ay9uSgNvdFdFSBaVcDup3lWsF2uVyOscMAojfKY3Z/ehA3tH8exC/63gbTM5tz1BfDgKpoZQa0Nyw71qwCCplzDYYFwNcF/AphSqiaF04XkvFXvaChhP9uMenGC9Rt/6rQYam3rZdL2kSoRbrG6Mkriygo3Kux8w/HQGycjEwCtHhBDXhKjVWXJ0SwdTV8Sy/SJVadLmSGLADZlj1lDHnPVKyT311QE60IAZvwMFY2XjFRTwUIkObZIb3o/t8eK9hjfNXxmPIeQbNxwune4avO8ugLG/96xU78vE9lh3J1ZMncToxrgnJpNjC1F0ESWmHOBQ K9XLD20Z 0SFvaQCqOAwznL10ZOLT6zL8wyUIkoBUhlLSvSVUj5cPX3+kkN3ELVrIoXZljqSLStmZElhrz+9dLWrCxHh/7N01ywIUi56CUdfBuvHxqyAhdqelApN5+KOqW7/6d0Rxnx5igXgNnHAHCz+OevIHrBHGZAeoO4KfikAGg3DeWVs6n8ZcQ69uhMH9iVRtIHfvrmzQUFkura18NUlcCTaHk3v167YoeKTBN6y/lS3gglcKKeCaeqhBRpOBL556unfLN1LcLiLHJMnpPbDLwAQSutX3T2WPQz+ci31xEc1V28hM20xrk0dFReckMB7eZCJ0YCsTrLYF9XUiTAusv/AhTcQ8V6uW8TJ0CRdM/VXJZA3Tr6UUoNI7nOuRf6IkKEiBHbwNE5JxNffVurIyZ85f2hlvfN4tkaOaRaGjdf1XXL2SX9QUYBZIj6sE77yrDdVN9rO26+o9/d3CTYDdYcfaxf7E/Lg== 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: Let's factor it out into include/linux/crash_dump.h, from where we can use it also outside of vmcore.c later. Acked-by: Baoquan He Signed-off-by: David Hildenbrand --- fs/proc/vmcore.c | 21 ++------------------- include/linux/crash_dump.h | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index 8d262017ca11..9b72e255dd03 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c @@ -709,11 +709,6 @@ static const struct proc_ops vmcore_proc_ops = { .proc_mmap = mmap_vmcore, }; -static struct vmcore_range * __init get_new_element(void) -{ - return kzalloc(sizeof(struct vmcore_range), GFP_KERNEL); -} - static u64 get_vmcore_size(size_t elfsz, size_t elfnotesegsz, struct list_head *vc_list) { @@ -1116,7 +1111,6 @@ static int __init process_ptload_program_headers_elf64(char *elfptr, size_t elfnotes_sz, struct list_head *vc_list) { - struct vmcore_range *new; int i; Elf64_Ehdr *ehdr_ptr; Elf64_Phdr *phdr_ptr; @@ -1139,13 +1133,8 @@ static int __init process_ptload_program_headers_elf64(char *elfptr, end = roundup(paddr + phdr_ptr->p_memsz, PAGE_SIZE); size = end - start; - /* Add this contiguous chunk of memory to vmcore list.*/ - new = get_new_element(); - if (!new) + if (vmcore_alloc_add_range(vc_list, start, size)) return -ENOMEM; - new->paddr = start; - new->size = size; - list_add_tail(&new->list, vc_list); /* Update the program header offset. */ phdr_ptr->p_offset = vmcore_off + (paddr - start); @@ -1159,7 +1148,6 @@ static int __init process_ptload_program_headers_elf32(char *elfptr, size_t elfnotes_sz, struct list_head *vc_list) { - struct vmcore_range *new; int i; Elf32_Ehdr *ehdr_ptr; Elf32_Phdr *phdr_ptr; @@ -1182,13 +1170,8 @@ static int __init process_ptload_program_headers_elf32(char *elfptr, end = roundup(paddr + phdr_ptr->p_memsz, PAGE_SIZE); size = end - start; - /* Add this contiguous chunk of memory to vmcore list.*/ - new = get_new_element(); - if (!new) + if (vmcore_alloc_add_range(vc_list, start, size)) return -ENOMEM; - new->paddr = start; - new->size = size; - list_add_tail(&new->list, vc_list); /* Update the program header offset */ phdr_ptr->p_offset = vmcore_off + (paddr - start); diff --git a/include/linux/crash_dump.h b/include/linux/crash_dump.h index 788a45061f35..9717912ce4d1 100644 --- a/include/linux/crash_dump.h +++ b/include/linux/crash_dump.h @@ -121,6 +121,20 @@ struct vmcore_range { loff_t offset; }; +/* Allocate a vmcore range and add it to the list. */ +static inline int vmcore_alloc_add_range(struct list_head *list, + unsigned long long paddr, unsigned long long size) +{ + struct vmcore_range *m = kzalloc(sizeof(*m), GFP_KERNEL); + + if (!m) + return -ENOMEM; + m->paddr = paddr; + m->size = size; + list_add_tail(&m->list, list); + return 0; +} + #else /* !CONFIG_CRASH_DUMP */ static inline bool is_kdump_kernel(void) { return false; } #endif /* CONFIG_CRASH_DUMP */ From patchwork Wed Dec 4 12:54:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13893713 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 5E08AE7716B for ; Wed, 4 Dec 2024 12:55:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 89F866B009E; Wed, 4 Dec 2024 07:55:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 828FA6B00A0; Wed, 4 Dec 2024 07:55:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 678DA6B00A2; Wed, 4 Dec 2024 07:55:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 47E5B6B009E for ; Wed, 4 Dec 2024 07:55:19 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B0A6CC0FC1 for ; Wed, 4 Dec 2024 12:55:13 +0000 (UTC) X-FDA: 82857271644.21.E45EE6A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf22.hostedemail.com (Postfix) with ESMTP id D362FC0017 for ; Wed, 4 Dec 2024 12:54:55 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cQUBjrHC; spf=pass (imf22.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733316901; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/hPjJFLUCb0ZdSDAqGVI3uh+hCPNkczr7XmzIQmCEzE=; b=YsBmkYYGAdUNLHwXkGTxOc+J0str3/w8NcymdAN4hx81cFIVsI/PAzvVWyD4oJ7qobxGl5 Bt40/V7oHGo35fXkARbtv30ti5UyjClRaAr41LvoBSfKuu8BSXbbVdlfQSYQYiPRqB5UO1 WRMI5bECVeIeHa31u7wB2phMhFGYKHI= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cQUBjrHC; spf=pass (imf22.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733316901; a=rsa-sha256; cv=none; b=Na4r8y1P/gXq4Maf7AN3jzhIGoTGnR+FfSfSiR81XJHmayY44UKYSahSjKQlbIWkbSANkS bZraMuBtbkLC2gNbRFXTXGMahhBcqoWyClLgSiIBvD/vgKdcEejFCVP0bOaCAUOEY86mWl m5SY4SLRv+s/CtiJaF5+lq34jhw33V4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733316911; 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=/hPjJFLUCb0ZdSDAqGVI3uh+hCPNkczr7XmzIQmCEzE=; b=cQUBjrHC6vuua6YJh3h/w0XCrGusBAG31hO28IrWKXTd4iOjlDk08wjUFqtKMOZYhNoWPn Xu51WI2LXGXFKEID26X8TYgt54osLNucZs38bIBtskdHdIEKlxEtBbedI+bJv313Vkpf7G VstWXl2cUnPdSvxmIE0rmakzlBcJMWs= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-99-CX8u_T5BM6Wj1oeSMImkgw-1; Wed, 04 Dec 2024 07:55:09 -0500 X-MC-Unique: CX8u_T5BM6Wj1oeSMImkgw-1 X-Mimecast-MFC-AGG-ID: CX8u_T5BM6Wj1oeSMImkgw Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4349e97bfc4so62389435e9.3 for ; Wed, 04 Dec 2024 04:55:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733316909; x=1733921709; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/hPjJFLUCb0ZdSDAqGVI3uh+hCPNkczr7XmzIQmCEzE=; b=KARU309MKiNMZfcmiV9/E8hCUj1ZWdLfC7JPL75RPtRhH278MXukAc+2B3L18UPRAm wwGiZcc2qmcDmBxu7djPKSvjthhNgpv3NsilNsI/8N/OQLLJRa8SFytKSxT5ZTJoqz/4 gQT5aBXsBS4+bC/mDHttfzDlO1iyk6fTf+DR0KKd0yj2NQ8MOJTcLgWXqViKU6hvWI6l SoHtHFMjFXly2RA0LLNQU7Ftg1uviUDXhfc6bQbglst01y/0mX0+xKyB7rbdeWRpt1nk qpWZRaoRgT//TfYONXP8AK9XLwFlSMBA533BRlTzU+D0tUAiWUZTRoZtamaYHEKenYlJ kW5g== X-Gm-Message-State: AOJu0YzH4zYeikVqfSj/9WKEd2IZJJ2MNGYbl8yUDwlKZNWjSCA5m9KD 0IJsIsyv4BpsHZrx64rzXyIf/FkaRJWR8I5YN0xGYIImCyQMJ92Lv9JlCyL2L3Omwk+1EbovOJJ Uts0I+bBREf1UTSpelonD351kc0dZ/AUwfYaBysyxPuXPWJpd X-Gm-Gg: ASbGncstkMmMTz3ExZIGyTsmk/KDwdiWhr0CXcUc5UPqvWCI6oLLn7YbYRtOz3Eezu5 YkJGTCzX0zH8fos6/5As2p93qsZoeSKEYXDUPaQSe3ZwNmmKV6cfbaIM/9fspf9IQq/ujqj9m0m IRNmH0dtuBRJEWCUtb3BlPfu7AxV8ctt2xVoclFzMBlxvgx+kbzpOqNos1wm6javMYAuGQoxH3u Kh009D6RV2F41gX+w1SHgMoRxo298lvnPn7gyfmP9SVeOe6miepQdMCVX5jTz5BVmfDmHDvuyjs 7tOs55VaUoJxJjTurxig8C2TVyK3boW1WE4= X-Received: by 2002:a05:600c:1989:b0:431:6083:cd30 with SMTP id 5b1f17b1804b1-434d09b2a75mr60274915e9.6.1733316908761; Wed, 04 Dec 2024 04:55:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IFKlYOU/tZlshqWyJGjVsl03zkEzffSPE/+D71b9Tfd5+g4TqcfXtmwO5t6x/22DC/lF4E/bA== X-Received: by 2002:a05:600c:1989:b0:431:6083:cd30 with SMTP id 5b1f17b1804b1-434d09b2a75mr60274425e9.6.1733316908112; Wed, 04 Dec 2024 04:55:08 -0800 (PST) Received: from localhost (p200300cbc70be10038d68aa111b0a20a.dip0.t-ipconnect.de. [2003:cb:c70b:e100:38d6:8aa1:11b0:a20a]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-385db7f86dasm16267209f8f.66.2024.12.04.04.55.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Dec 2024 04:55:06 -0800 (PST) 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 v2 07/12] fs/proc/vmcore: factor out freeing a list of vmcore ranges Date: Wed, 4 Dec 2024 13:54:38 +0100 Message-ID: <20241204125444.1734652-8-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241204125444.1734652-1-david@redhat.com> References: <20241204125444.1734652-1-david@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: RcgopBNDSGLMDfkA5n1L-9909PVr2M3DdDZfAxvtrI8_1733316909 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Rspamd-Server: rspam05 X-Stat-Signature: d5h83z1bra81ktfnxxdumxg9cm6patqz X-Rspamd-Queue-Id: D362FC0017 X-Rspam-User: X-HE-Tag: 1733316895-864789 X-HE-Meta: U2FsdGVkX1+ANg8NBaNk5IHpOp64ee+qT1RqoXM3QGrcuoaWtTux4ranckLWExYMPn41QQW5M5Dqip4Jb4rccxgsLzgYOH5kGSBfzbt5s3onGSMkLmnGHy++64p0zmE11LnGR9w+6ZRN/ZD7LLsbUXTjf9ZWztbtFJLU33I8ekRo0N148vVYD8LLmYTiDrBU8mW8Vt/oAIllVdI1k06kzngvJ3pqD8CvQET89oOaC6F/tsEfXKQAvAbdYiTortN1LBvD+yvSdy6vSnJGJd3DZPFZeDSEONyyFuKFtAlEj8+JPbIhSsM4K7bEF5N1Lzs4Rv1AWTHOtwVsJNheNQ2zWNB06HO9ofAzpjHKZwtjzOt6mFK8HXnXTzatOYtCjPWEkZaw1fOwNIg9P6A9+05U6xAZ4MNxvc2NfoMlMGWy+HQbaEoOSMuWAx70VqQCcfpFkMRqzC3TAlUTGnLrprzjYZW/R9lxro4b9aExudYmzTkkX/yWWaJaioC+J+yJcuhjuZTaXvyNawGWXZT/j/5LxJpAbNlI5W2cMLAVZcjsIE2XXm16I3U3BPjxMMs+7CXV4WDPt5p3EK/1wk5ekQM5MEl/tI9VV3Kv0EwtMJjQCzQz0a3gDRr2/VfPoKrQqhGRUyaJrnS747kU9kUIsPxs5/b1IKdtLiInVz/y6/hNunay/E2QopHXR28FNRt1V8ia2BpNbMYsecZwM8kJ9XA3EN3TuWi8KJLAUsvUXqZ5nTIaYzCPiQ8ts77qEnn8Gw+lGMq/yP0RcqxnL6kY+hNwwUUrSW7k/4MFL6QHz5jS9fokf0VbJQGIVE8HRT+ViDiPXmK7+E8kdMB8jQ+4FU8Tc43Y6mrSL1X1UvNcwJ9GLTatZC46Nb02+VVuqZaVCmGYBxwpTcGJO0jRZNJm1CxjrVMho3fyLZ9WT4dHY6UYfHzByFVy7p1K2O9x8t5uiWS5IVg7HISzk7OZHv0v9K7 FtsLCd+z H4s0vmwSqGXbZSAiy+FgX5FPXkeQKRsubH1WF0ndbQbk+KpALbChxoXrnISeZxNAURu+Inc24lqMWxPab4kDVpRelAz+gJ9IdPZZdwAzP1ZqF/pQJFLdtEAM9IuiCf/FH3/Ur/Uf/cyPB0hSBsEXlaY2vNFSKLSXMtmdtnbp4z3uEPPRtaWJmwkp8yyHOwnszP3J9pANCu8S4TpDKGkQ9kSmtbXQcPpmpDb9Tmfbk+1902L3w0JA0d70I4IZ4qhiBQhaku3aKjnsuVSxvG0OHoyteqq90qtdtSy+89j0sn0SDLMKqmVhMdipIbMjdr1/qjvYY2/8hpQKJyuvKwhdHaCMW6WwGMJOnKlm3xXL0wHH9GyTlmcR6G2YC7r4Yks7cfUAOpv9n7OEAuVD3pcjsokr6Z+Qw3FpDSnX5bjQFVmLJ8WmK8KS9FEjqZg== 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: Let's factor it out into include/linux/crash_dump.h, from where we can use it also outside of vmcore.c later. Acked-by: Baoquan He Signed-off-by: David Hildenbrand --- fs/proc/vmcore.c | 9 +-------- include/linux/crash_dump.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index 9b72e255dd03..e7b3cde44890 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c @@ -1592,14 +1592,7 @@ void vmcore_cleanup(void) proc_vmcore = NULL; } - /* clear the vmcore list. */ - while (!list_empty(&vmcore_list)) { - struct vmcore_range *m; - - m = list_first_entry(&vmcore_list, struct vmcore_range, list); - list_del(&m->list); - kfree(m); - } + vmcore_free_ranges(&vmcore_list); free_elfcorebuf(); /* clear vmcore device dump list */ diff --git a/include/linux/crash_dump.h b/include/linux/crash_dump.h index 9717912ce4d1..5d61c7454fd6 100644 --- a/include/linux/crash_dump.h +++ b/include/linux/crash_dump.h @@ -135,6 +135,17 @@ static inline int vmcore_alloc_add_range(struct list_head *list, return 0; } +/* Free a list of vmcore ranges. */ +static inline void vmcore_free_ranges(struct list_head *list) +{ + struct vmcore_range *m, *tmp; + + list_for_each_entry_safe(m, tmp, list, list) { + list_del(&m->list); + kfree(m); + } +} + #else /* !CONFIG_CRASH_DUMP */ static inline bool is_kdump_kernel(void) { return false; } #endif /* CONFIG_CRASH_DUMP */ From patchwork Wed Dec 4 12:54:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13893711 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 ECC58E7716B for ; Wed, 4 Dec 2024 12:55:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 45C0A6B009B; Wed, 4 Dec 2024 07:55:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 407CF6B009C; Wed, 4 Dec 2024 07:55:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 25EA66B009D; Wed, 4 Dec 2024 07:55:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 049796B009B for ; Wed, 4 Dec 2024 07:55:15 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C03011C7839 for ; Wed, 4 Dec 2024 12:55:15 +0000 (UTC) X-FDA: 82857271728.30.D3F8038 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf23.hostedemail.com (Postfix) with ESMTP id E712A140011 for ; Wed, 4 Dec 2024 12:55:03 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XzIKmk5J; spf=pass (imf23.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733316906; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=DHduTfm8MEvatODJJecU9qsghwDNoQQYbaQi+lekCuQ=; b=zU16vxTWLzwvFVDKmmdgJOpo+GzFRwfOr6umCZW18iJNoKuCO0X5+hjyEKhnfwmD+4QMEl hOIlDjrKdREf235nggeRuJyNiu0IJJYaRF1aJNgFgZ91GNH1os+FIE03flen3H4VrSV2Wa csj6SBEdYaUCiqGFxjV9PVmNC+JCalE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733316906; a=rsa-sha256; cv=none; b=y7dh1I20CVGliuJqdBixDcVjClnmACYsk2nzGLxVPiP2pdexAVpEoXXqo4T26gJjmlXjdh yLEXCUCKsVvrapDEr8eqL/4LkCK3T+OPb4YAYGT7c0cMgjAXPg9bV7D8rGYzNw22dJlYUl uLI1vSPVtqaNcPPfI7IZ3S5sQKj43zU= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XzIKmk5J; spf=pass (imf23.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733316912; 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=DHduTfm8MEvatODJJecU9qsghwDNoQQYbaQi+lekCuQ=; b=XzIKmk5Jhco7eFHj3ybrbAKNEJpZWutsGPg01UuLnAfQ2IunfsyLctBL/9bLGktGbx8E9h zCHSfiwfSydljhTWmOOndNd9eRK5WNyHDqP6QlSb3fw0vN05e2KR+vp4Gy3AT7suzZ2NES SZzQMs+8P0DpGytKw4nxrNxt+PF4TY0= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-212-UaT15q45OaKvutlMJs2OpQ-1; Wed, 04 Dec 2024 07:55:11 -0500 X-MC-Unique: UaT15q45OaKvutlMJs2OpQ-1 X-Mimecast-MFC-AGG-ID: UaT15q45OaKvutlMJs2OpQ Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-434a51e44d0so55172555e9.3 for ; Wed, 04 Dec 2024 04:55:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733316910; x=1733921710; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DHduTfm8MEvatODJJecU9qsghwDNoQQYbaQi+lekCuQ=; b=nDVy1RqvQO1JBCF5R1+QWnmtzcARZ5zVR38dmVx8yysPbqXlXmGsjCarmEdbAKPJON TALs6SXWApCIvK4bw2pQLiUlI2Xg91y/TgxL1Hf81nHdBcxVsQMEYiuN2va38pNZYWRv 3/hM6FswmxctXA143EZLCfdId4v0IB4xD/2oX/sStuIUMoa0wx7P+ZM/Xn7kg2/m1qVn D2JaeHdDwCUjjwEUtPjhdBelLzBHugIDjsfWV7uAZMAVzB1kn4g7uWgxGJEzdV9y9AAn r75pn8GdDeUg2TBJZQtlmDAc8bRdzVIsYB7qKY4Y40/TYzKYAZsIFbmFcQi0+qx64LNd bacA== X-Gm-Message-State: AOJu0YxycwardW6GCyT/6AG0YpODCqmJnAOFARfPh9HxQRA0yCMDK/ha w4mMP5UPKZ00SvaqcDMyCmBnThFIomTy3okS2DoBOe5kMeLNr+sz5sUgsNcD6FBHOVk7O/dpNoe 7iWu3MUW0H4oqELbqvUx6Sp+vApsM6GWFE20pldSR0yHmT3BQ X-Gm-Gg: ASbGnctvv2McP1rmF2tPvoj4+AdNSKi2cfzvEgV+wXEDC9uCJaNNnDNcAvuBtZk1ncH uXIbCjhM7G5muHLZUIxfIg3YXSsP/xnjwb299j3PwGPkLm6QdjBKicWnkYVs/Ah9DnhxrRv3LoA gGN9lJnmVZ/bTW/4ZOdx6FwAoR+hxgU+a7QcfI0R2iRh/DxKBvU5UXYDB54pk490kHRDf9dlKen Cwv55jCaddsqP5UVuji4dEJEmdP6NQpW6qaD6XBC/bd97lsrb4NZwxlXI5pFlZiciYPOCAp42Uo LJLSuJfEQfwC5iMZJ3i2FI3TG/Sbpe/tYLY= X-Received: by 2002:a05:600c:1c88:b0:434:9df4:5472 with SMTP id 5b1f17b1804b1-434d0a15068mr60073465e9.31.1733316910496; Wed, 04 Dec 2024 04:55:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IGWq3Nj3w3HYlBbZnRWgOzE8l6L8boPfRZN2lwS+xZGCeTjU6KZId+aHdXHdM4P1FN9VEFBqg== X-Received: by 2002:a05:600c:1c88:b0:434:9df4:5472 with SMTP id 5b1f17b1804b1-434d0a15068mr60073175e9.31.1733316910084; Wed, 04 Dec 2024 04:55:10 -0800 (PST) Received: from localhost (p200300cbc70be10038d68aa111b0a20a.dip0.t-ipconnect.de. [2003:cb:c70b:e100:38d6:8aa1:11b0:a20a]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-434d5280746sm23704445e9.21.2024.12.04.04.55.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Dec 2024 04:55:09 -0800 (PST) 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 v2 08/12] fs/proc/vmcore: introduce PROC_VMCORE_DEVICE_RAM to detect device RAM ranges in 2nd kernel Date: Wed, 4 Dec 2024 13:54:39 +0100 Message-ID: <20241204125444.1734652-9-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241204125444.1734652-1-david@redhat.com> References: <20241204125444.1734652-1-david@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: _9qO7NWANqpxFjKsN6O157lKt_iJnX8MP8v7CDRwb98_1733316911 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: E712A140011 X-Stat-Signature: 97fuuibucb95bjhxmciz9j4jr3bg8kzo X-Rspam-User: X-HE-Tag: 1733316903-272011 X-HE-Meta: U2FsdGVkX1+qscgoLbXCK+02IHWAHFRf7YL5PBwObQSqT/iIeUnWSrOI9o0ambf/mTRSEzlPjsW1/LdmT4VPjbe0Dj4UZNwHjbZkdj/S3rl7RxIBjvAXoL/Uyh1QwOzFrXspkQw7+ziYyTAb8ScDmNTQTpxoR5s84QcjVg+yT4UAD/0fRLz3O885NCCDsrbR7cpMSAtZMnHz5Rh/zPKpU4ltMZ/NerNuljdkQFvYTUkLytvJL7MoEp5mqRnlDG9TVtdzPgyS2dgHLsitlhqbzI126wFFp7wdXlurYz13xFfgoBSNr0W4QBx4IEsBFkXtgYeno27B1eUATG59t5XeqntjpJ+kZikTxfuYKOKo7QLf6iX8p4kr1owl9yNk1r9csRuuLdGwahhPPu2Jeg5sBLNXa36TWa7lC0bOb0T+Z/mDDxs+zw50fZ49A+x7vaWGVJGJZlgWFe28U8SdRf9pslxVHvsLMQ72Y/5Z6XENQMGlkSwPt9k12nyNTgXOPpc8BYV5/JhYfc9vDYRVd/6r3n/Wu9NuLRHzBf8GgBj4LFp+eYF2zAF4Qb0uBBKh/29t1JnnU8Dsk+1X2nmyj4Zqv83EH+7tbjlIyAwZWCsqlNvBcy1M+iDs/c7h9zz6rTOa+uJS3Ixwoeslo/eWnljpaqQH/DVkmptPAHb/VsOyBza8W8OQMlJ2+QRgdx2SJwx6a/x3mjxP8DEe6MA0Xbf3BjofCH2jmrZYse9f7czDH2Xh9Uk4fGupHHxEi4xT6oKPR/w5NI2BiqihNKoykEKvG237KlrIHumM1DXRpEdfVc2Khvi4NEKJKcs/l39/73sJqLii2SJwxrzCVVrOgg2ujb9QucQq/RsxABN0OnsLrr6lDsaP4L7PoLdqZwTvXJ6PPXMPTuwZFxEZSIDQXd6puMbP0TPqkdjnTDAAXnJnGo6k5PlQJchCdZPtbesTqrob4dVEBEuh1c/rvIhJZXx HbmN6nr/ 30ywWGDk7hoO+2AWRfyA9mDoxukoNOatvx7wVkYjNT8WWx4I8W6tZvfBkPjWLw5fLNvk+vE4jBVuVil2AW1AkOQSrMiXomYFryaWPxjh4x9FORWcFb/cw5z1oQdeiQOJh/BVdncde8Y4P8gbNLYkeo3UNVq4UA1OfHR3eBmcEzxJX5Ad3IlgauBXQxv3xSmUh7XzF7vH3Ib+6De1/Vu3//t4ADw3NlmbM0QXWVww3EY83O8GCB5+XcOSpiyfdykXPsqVyw5iydEW6D68kIcpJe3rWetZ1KF/BzjoZ/nWLRZp/iB+waoriwMn2AJ1C+6GI7QlUNPYaMSX5hPhJN5EP+RiOUM7jT2oSd7KKVX3LZy+JwOAXPS1uH0RRBY2u0yqEQ0Wlt75C9Ea6PZf5qPjAb2LUxbGJLvYDM93JhB1i1yHW198M48fF5t4nSohYCD0eunll9fD9tbADj3ixNiUAH2MPjN2VY3USXM6DrRm0mF2OZAQ= 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: s390 allocates+prepares the elfcore hdr in the dump (2nd) kernel, not in the crashed kernel. RAM provided by memory devices such as virtio-mem can only be detected using the device driver; when vmcore_init() is called, these device drivers are usually not loaded yet, or the devices did not get probed yet. Consequently, on s390 these RAM ranges will not be included in the crash dump, which makes the dump partially corrupt and is unfortunate. Instead of deferring the vmcore_init() call, to an (unclear?) later point, let's reuse the vmcore_cb infrastructure to obtain device RAM ranges as the device drivers probe the device and get access to this information. Then, we'll add these ranges to the vmcore, adding more PT_LOAD entries and updating the offsets+vmcore size. Use a separate Kconfig option to be set by an architecture to include this code only if the arch really needs it. Further, we'll make the config depend on the relevant drivers (i.e., virtio_mem) once they implement support (next). The alternative of having a PROVIDE_PROC_VMCORE_DEVICE_RAM config option was dropped for now for simplicity. The current target use case is s390, which only creates an elf64 elfcore, so focusing on elf64 is sufficient. Signed-off-by: David Hildenbrand --- fs/proc/Kconfig | 18 +++++ fs/proc/vmcore.c | 156 +++++++++++++++++++++++++++++++++++++ include/linux/crash_dump.h | 9 +++ 3 files changed, 183 insertions(+) diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig index d80a1431ef7b..5668620ab34d 100644 --- a/fs/proc/Kconfig +++ b/fs/proc/Kconfig @@ -61,6 +61,24 @@ config PROC_VMCORE_DEVICE_DUMP as ELF notes to /proc/vmcore. You can still disable device dump using the kernel command line option 'novmcoredd'. +config NEED_PROC_VMCORE_DEVICE_RAM + bool + +config PROC_VMCORE_DEVICE_RAM + def_bool y + depends on PROC_VMCORE && NEED_PROC_VMCORE_DEVICE_RAM + help + If the elfcore hdr is allocated and prepared by the dump kernel + ("2nd kernel") instead of the crashed kernel, RAM provided by memory + devices such as virtio-mem will not be included in the dump + image, because only the device driver can properly detect them. + + With this config enabled, these RAM ranges will be queried from the + device drivers once the device gets probed, so they can be included + in the crash dump. + + Relevant architectures should select NEED_PROC_VMCORE_DEVICE_RAM. + config PROC_SYSCTL bool "Sysctl support (/proc/sys)" if EXPERT depends on PROC_FS diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index e7b3cde44890..6dc293d0eb5b 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c @@ -79,6 +79,8 @@ static bool vmcore_opened; /* Whether the vmcore is currently open. */ static unsigned int vmcore_open; +static void vmcore_process_device_ram(struct vmcore_cb *cb); + void register_vmcore_cb(struct vmcore_cb *cb) { INIT_LIST_HEAD(&cb->next); @@ -90,6 +92,8 @@ void register_vmcore_cb(struct vmcore_cb *cb) */ if (vmcore_opened) pr_warn_once("Unexpected vmcore callback registration\n"); + if (!vmcore_open && cb->get_device_ram) + vmcore_process_device_ram(cb); mutex_unlock(&vmcore_mutex); } EXPORT_SYMBOL_GPL(register_vmcore_cb); @@ -1535,6 +1539,158 @@ int vmcore_add_device_dump(struct vmcoredd_data *data) EXPORT_SYMBOL(vmcore_add_device_dump); #endif /* CONFIG_PROC_VMCORE_DEVICE_DUMP */ +#ifdef CONFIG_PROC_VMCORE_DEVICE_RAM +static int vmcore_realloc_elfcore_buffer_elf64(size_t new_size) +{ + char *elfcorebuf_new; + + if (WARN_ON_ONCE(new_size < elfcorebuf_sz)) + return -EINVAL; + if (get_order(elfcorebuf_sz_orig) == get_order(new_size)) { + elfcorebuf_sz_orig = new_size; + return 0; + } + + elfcorebuf_new = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, + get_order(new_size)); + if (!elfcorebuf_new) + return -ENOMEM; + memcpy(elfcorebuf_new, elfcorebuf, elfcorebuf_sz); + free_pages((unsigned long)elfcorebuf, get_order(elfcorebuf_sz_orig)); + elfcorebuf = elfcorebuf_new; + elfcorebuf_sz_orig = new_size; + return 0; +} + +static void vmcore_reset_offsets_elf64(void) +{ + Elf64_Phdr *phdr_start = (Elf64_Phdr *)(elfcorebuf + sizeof(Elf64_Ehdr)); + loff_t vmcore_off = elfcorebuf_sz + elfnotes_sz; + Elf64_Ehdr *ehdr = (Elf64_Ehdr *)elfcorebuf; + Elf64_Phdr *phdr; + int i; + + for (i = 0, phdr = phdr_start; i < ehdr->e_phnum; i++, phdr++) { + u64 start, end; + + /* + * After merge_note_headers_elf64() we should only have a single + * PT_NOTE entry that starts immediately after elfcorebuf_sz. + */ + if (phdr->p_type == PT_NOTE) { + phdr->p_offset = elfcorebuf_sz; + continue; + } + + start = rounddown(phdr->p_offset, PAGE_SIZE); + end = roundup(phdr->p_offset + phdr->p_memsz, PAGE_SIZE); + phdr->p_offset = vmcore_off + (phdr->p_offset - start); + vmcore_off = vmcore_off + end - start; + } + set_vmcore_list_offsets(elfcorebuf_sz, elfnotes_sz, &vmcore_list); +} + +static int vmcore_add_device_ram_elf64(struct list_head *list, size_t count) +{ + Elf64_Phdr *phdr_start = (Elf64_Phdr *)(elfcorebuf + sizeof(Elf64_Ehdr)); + Elf64_Ehdr *ehdr = (Elf64_Ehdr *)elfcorebuf; + struct vmcore_range *cur; + Elf64_Phdr *phdr; + size_t new_size; + int rc; + + if ((Elf32_Half)(ehdr->e_phnum + count) != ehdr->e_phnum + count) { + pr_err("too many device ram ranges\n"); + return -ENOSPC; + } + + /* elfcorebuf_sz must always cover full pages. */ + new_size = sizeof(Elf64_Ehdr) + + (ehdr->e_phnum + count) * sizeof(Elf64_Phdr); + new_size = roundup(new_size, PAGE_SIZE); + + /* + * Make sure we have sufficient space to include the new PT_LOAD + * entries. + */ + rc = vmcore_realloc_elfcore_buffer_elf64(new_size); + if (rc) { + pr_err("resizing elfcore failed\n"); + return rc; + } + + /* Modify our used elfcore buffer size to cover the new entries. */ + elfcorebuf_sz = new_size; + + /* Fill the added PT_LOAD entries. */ + phdr = phdr_start + ehdr->e_phnum; + list_for_each_entry(cur, list, list) { + WARN_ON_ONCE(!IS_ALIGNED(cur->paddr | cur->size, PAGE_SIZE)); + elfcorehdr_fill_device_ram_ptload_elf64(phdr, cur->paddr, cur->size); + + /* p_offset will be adjusted later. */ + phdr++; + ehdr->e_phnum++; + } + list_splice_tail(list, &vmcore_list); + + /* We changed elfcorebuf_sz and added new entries; reset all offsets. */ + vmcore_reset_offsets_elf64(); + + /* Finally, recalculate the total vmcore size. */ + vmcore_size = get_vmcore_size(elfcorebuf_sz, elfnotes_sz, + &vmcore_list); + proc_vmcore->size = vmcore_size; + return 0; +} + +static void vmcore_process_device_ram(struct vmcore_cb *cb) +{ + unsigned char *e_ident = (unsigned char *)elfcorebuf; + struct vmcore_range *first, *m; + LIST_HEAD(list); + int count; + + /* We only support Elf64 dumps for now. */ + if (WARN_ON_ONCE(e_ident[EI_CLASS] != ELFCLASS64)) { + pr_err("device ram ranges only support Elf64\n"); + return; + } + + if (cb->get_device_ram(cb, &list)) { + pr_err("obtaining device ram ranges failed\n"); + return; + } + count = list_count_nodes(&list); + if (!count) + return; + + /* + * For some reason these ranges are already know? Might happen + * with unusual register->unregister->register sequences; we'll simply + * sanity check using the first range. + */ + first = list_first_entry(&list, struct vmcore_range, list); + list_for_each_entry(m, &vmcore_list, list) { + unsigned long long m_end = m->paddr + m->size; + unsigned long long first_end = first->paddr + first->size; + + if (first->paddr < m_end && m->paddr < first_end) + goto out_free; + } + + /* If adding the mem nodes succeeds, they must not be freed. */ + if (!vmcore_add_device_ram_elf64(&list, count)) + return; +out_free: + vmcore_free_ranges(&list); +} +#else /* !CONFIG_PROC_VMCORE_DEVICE_RAM */ +static void vmcore_process_device_ram(struct vmcore_cb *cb) +{ +} +#endif /* CONFIG_PROC_VMCORE_DEVICE_RAM */ + /* Free all dumps in vmcore device dump list */ static void vmcore_free_device_dumps(void) { diff --git a/include/linux/crash_dump.h b/include/linux/crash_dump.h index 5d61c7454fd6..2f2555e6407c 100644 --- a/include/linux/crash_dump.h +++ b/include/linux/crash_dump.h @@ -20,6 +20,8 @@ extern int elfcorehdr_alloc(unsigned long long *addr, unsigned long long *size); extern void elfcorehdr_free(unsigned long long addr); extern ssize_t elfcorehdr_read(char *buf, size_t count, u64 *ppos); extern ssize_t elfcorehdr_read_notes(char *buf, size_t count, u64 *ppos); +void elfcorehdr_fill_device_ram_ptload_elf64(Elf64_Phdr *phdr, + unsigned long long paddr, unsigned long long size); extern int remap_oldmem_pfn_range(struct vm_area_struct *vma, unsigned long from, unsigned long pfn, unsigned long size, pgprot_t prot); @@ -99,6 +101,12 @@ static inline void vmcore_unusable(void) * indicated in the vmcore instead. For example, a ballooned page * contains no data and reading from such a page will cause high * load in the hypervisor. + * @get_device_ram: query RAM ranges that can only be detected by device + * drivers, such as the virtio-mem driver, so they can be included in + * the crash dump on architectures that allocate the elfcore hdr in the dump + * ("2nd") kernel. Indicated RAM ranges may contain holes to reduce the + * total number of ranges; such holes can be detected using the pfn_is_ram + * callback just like for other RAM. * @next: List head to manage registered callbacks internally; initialized by * register_vmcore_cb(). * @@ -109,6 +117,7 @@ static inline void vmcore_unusable(void) */ struct vmcore_cb { bool (*pfn_is_ram)(struct vmcore_cb *cb, unsigned long pfn); + int (*get_device_ram)(struct vmcore_cb *cb, struct list_head *list); struct list_head next; }; extern void register_vmcore_cb(struct vmcore_cb *cb); From patchwork Wed Dec 4 12:54:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13893714 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 3B92CE7716E for ; Wed, 4 Dec 2024 12:55:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 458546B00A0; Wed, 4 Dec 2024 07:55:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 409CD6B00A2; Wed, 4 Dec 2024 07:55:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 25D7F6B00A4; Wed, 4 Dec 2024 07:55:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 009286B00A0 for ; Wed, 4 Dec 2024 07:55:19 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D418AC0F97 for ; Wed, 4 Dec 2024 12:55:18 +0000 (UTC) X-FDA: 82857271770.25.AC8974C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf01.hostedemail.com (Postfix) with ESMTP id AD54040014 for ; Wed, 4 Dec 2024 12:55:05 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TdOovVI1; spf=pass (imf01.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733316906; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=na4vd6mThSkzeb6NVT06w3pd7mJ97fz8U44/x2n2hr0=; b=LghUOTET3iXVakWaFZg8dLxWNfnc7RQxR9klI1ZywHJoA/Jb+yTIyVrmaSzWjznNj1Mx8r WIWO/N3Z2SRz1RLKag3nmU/S7/L5KzYaAjHGZyIMC/qY4mNFLsLHpvfnw4R6JTJMLtylfA GiKnLxfdIC2XGgaVU2zgSTQHBtouEGs= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TdOovVI1; spf=pass (imf01.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733316906; a=rsa-sha256; cv=none; b=dL7ur/cey7QBafE3MtbFYJ0zUfPG+1FxHusThXdZpYaeISxKLABF93KaV6Ud1g+Uh5rTWw byHAuCYAxx6GP/d8O7qNjojGGORGM1dWuR50FHa8nlx5YpNCnAOKZTMf354q9E2u+9wmfD NQXAV1T4fPkKCBOoF7FUSfncEAP44rs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733316916; 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=na4vd6mThSkzeb6NVT06w3pd7mJ97fz8U44/x2n2hr0=; b=TdOovVI1AYXmBregFcCv3CP3VqahGsCQqDKzUanVUGbIvU0xVoRSg4Q3u7DgIzz7syvJEy SkMbJWFDUKOvyTjBXMDAT5AaW8SynmbU2HSBijcuXN9k3wS1I6+oGjMENf4y+vMutPHNMZ u0HaGWhWtKod+MCkdF2oBKsnf0JPhkk= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-353-AS9J6RofMseZO47B0Umt8Q-1; Wed, 04 Dec 2024 07:55:14 -0500 X-MC-Unique: AS9J6RofMseZO47B0Umt8Q-1 X-Mimecast-MFC-AGG-ID: AS9J6RofMseZO47B0Umt8Q Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-434a9861222so55180595e9.2 for ; Wed, 04 Dec 2024 04:55:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733316914; x=1733921714; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=na4vd6mThSkzeb6NVT06w3pd7mJ97fz8U44/x2n2hr0=; b=t1EFGsywBt4k4VT8MlKGc1qzkdNaAW9+LnYMNnrUyYGnsvhavVUbFe+FKTKfBeffyJ 0kf4LAKINx0we3vreGZbGzd+bYS4/jBKDMaWoDRRHckf6JDU+LvHk6Huz9FacRNo/cjU izfxpnVOc8YimB7tw1G7QGSJUxVlIJvL9BnedqjDYvAd0FCkS9ZEEHiFm85hOwV+oF5F vH+WPja5nOrMq32IybKATuysTXHh/XZkB4FDyrtm2HjgSwiXaWtRRxiudnqLz5Iyc668 UiymjmRY5tuKMjNz+1dgOcXIxXekahhbGEbo5RMsOvpsCxQr9e6+rmHX/NV8fFqS9pPl FCJw== X-Gm-Message-State: AOJu0YyZYgcoPfeV/G+3Vtnh24q2qLZu8SGSCoaP6SH390oEOcKu76HP JFXGAmfMahYuDy1fl/h21pvNejD0h/t2XtHqBGUMcEOpKUVMAdBASEmONXIWwyaj9CaN94Sw6AI fiGP/a2Xa6RFNBr4TQIv+ddpJXybMAAVbe7NIYac/YJBec7y1 X-Gm-Gg: ASbGncvr1dwTyxshQ6jY3IPz/ZvyttG02AboIThFLlXB5o5BbHcdA8BsG8xYv1OQAq5 6EVsqGNwBS6Fye0kDv6OTeVXPb8IQLsh10GeR1t/qX4iUEb33UN67SuLre76+22dMcVOxRTVC7J MhZL0bTNG+GyplPXpMkeLwlsQIJnfP0KgBrgMw4pT8t7cdWWjPjdzzmLXhTLuna93Uv/KpKl5bI p6QWeGNiMwyawVmUxFtMf7JioVP+JdLo7Pv6mFnMCG2TNK7uBxErzFstGmybU+UdzH4EnONTSUH SPZdRXwqjSaH47/2B/2xykXbF8/mtFcTgIA= X-Received: by 2002:a05:600c:3550:b0:434:a781:f5d5 with SMTP id 5b1f17b1804b1-434d0a15047mr62644345e9.30.1733316913742; Wed, 04 Dec 2024 04:55:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IHdVB6YFjtubaQuZKYqVl7K3swrZVKNM9mWRen9YVYSXicgBrRTJ3zdugRU4fK2CCWYQJl/Fg== X-Received: by 2002:a05:600c:3550:b0:434:a781:f5d5 with SMTP id 5b1f17b1804b1-434d0a15047mr62643915e9.30.1733316913375; Wed, 04 Dec 2024 04:55:13 -0800 (PST) Received: from localhost (p200300cbc70be10038d68aa111b0a20a.dip0.t-ipconnect.de. [2003:cb:c70b:e100:38d6:8aa1:11b0:a20a]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-385df488559sm15210226f8f.63.2024.12.04.04.55.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Dec 2024 04:55:12 -0800 (PST) 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 v2 09/12] virtio-mem: mark device ready before registering callbacks in kdump mode Date: Wed, 4 Dec 2024 13:54:40 +0100 Message-ID: <20241204125444.1734652-10-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241204125444.1734652-1-david@redhat.com> References: <20241204125444.1734652-1-david@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 5-y_oGjDjl8YJU56cGddvkGtbVyR62DUZLGIRACCjvY_1733316914 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Rspamd-Server: rspam05 X-Stat-Signature: gkmykh7az19rzjbqn1s7qgqaaq9xz5gw X-Rspamd-Queue-Id: AD54040014 X-Rspam-User: X-HE-Tag: 1733316905-431338 X-HE-Meta: U2FsdGVkX184vnDzfhGZTmLqPjZYLxy3NwmzerWjzU48KUSMeJrC4/aCJh9EswSFby44dsv2rR4JQ2yhlgTNzjYjJPNDfsAdvcLWwfscrjI+ZJ6mU+bJHNSRVQUQCvgrWIDU5mLJfzOejlGa2RZB0HNa4DbsK9iJblzXRe2/03Z9z1v8C36oVv+jb1/fBd1u4L16os/1ANcqw6zzsSFkYNTI2FHLMCJyMOrlb61AwwNkM3dq8R0JKCwbq0auQIu0DCS3GAYFKL4kgbR94pDEECPKu/d5ETlDmphNJ8fhEmKSg0gtoHJJm9PQ/q7oMwxFfGxq+6kXF7quxLfTE8+l+IDRmCM7tI7nPo4+IpnUCnzH2QhdAV/xP2fEg9IbtXSB/A0VX635jBTx1yBH9BZ9qvJMFUfMZGcp/96quUmhBai6m9toz9jty+VIvF4jurdpmhwKmiz/9xoK8npHNtDBx1WPRwvk94eC344rPszgH3cTnUDlBO6S6v0xCwSXJKmeGs+FWB91uw2pTr7XjyaJEzwjCve3gtzTNtGKm0lF3Cy0BDDX3H36MNsORR4+iy/vr0Qw2pp5R48MqFs+Qf+si9+4yh+Jju9JoNL84GFNesRDhadiQGGdYVPQHNbdyZUwQ9Z8IVfh7CCv3pdA3jwGYjJOCtCw3X7fYhm0a9poI6F6ordAZ6507ZM9fKXqRoj2mMNyCxdt9E1e1Cb8gRyKVhyTQHry9+z/2d4STOM1IasEZ8Y60ExxTKy0HfoIdHzmvXShPoOHxniQy8B+PMLQf8TfDbI9+S7pJbxIjNXzlroBYNgdIJcVR64UTGGqlc4TZhupHOi70unnJxSw598EJvYeVwiEQR/8vEFObF7WkCAv79f93CeZvb8+RQTUvgFsc5mxHkT8WzTU5jTY48cwDBuRB9fuEPPuqpE2boxowCJmQD1aKgYgoNZ9Q802PIjtyqc8hcVxbSIFNCpb4a3 9i+Q/llA V4N0TB0aI9DirE2MG73ccPcFaktMbtLxwhpC5ErA9ES4OfxgsK2JWNyHDhrKJp7HRqn7LfWF0Sn/Bh5yqpuoLQk5kNG3w+9RCAwBBEOR4qQpWTO7cF0lrPU6zdKTTkp2znVI0CZSWX4ez203aKR+jmBo4vNYGYoAgz0tngIicGLVNVSrC3qaDYZ5l+sYThizNmWPp0/GAQNyqLLy67jSqV78cmZ7xdNV9NV3EKYUI84v1V57yHPrFrHN6DdfRqfyhQnwthn1kF//dxZM4/edQCTjlHgy3zu1BaQzRhGF4lX9+udOLg0zFDSRNVLgTIwToHDzVMUZztPqKGDAJoLEurGdjnHkVOY7FrSIV3CW7r1uBkjwnxj1rq05vzrT2Tfkuvw7uy9KmaK8wEBxE3vU0uN82Hjzx6Jc2JW5/35dzgno8Nqiqsmk6cwltTQ== 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: After the callbacks are registered we may immediately get a callback. So mark the device ready before registering the callbacks. Signed-off-by: David Hildenbrand --- drivers/virtio/virtio_mem.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index b0b871441578..126f1d669bb0 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -2648,6 +2648,7 @@ static int virtio_mem_init_hotplug(struct virtio_mem *vm) if (rc) goto out_unreg_pm; + virtio_device_ready(vm->vdev); return 0; out_unreg_pm: unregister_pm_notifier(&vm->pm_notifier); @@ -2729,6 +2730,8 @@ static bool virtio_mem_vmcore_pfn_is_ram(struct vmcore_cb *cb, static int virtio_mem_init_kdump(struct virtio_mem *vm) { + /* We must be prepared to receive a callback immediately. */ + virtio_device_ready(vm->vdev); #ifdef CONFIG_PROC_VMCORE dev_info(&vm->vdev->dev, "memory hot(un)plug disabled in kdump kernel\n"); vm->vmcore_cb.pfn_is_ram = virtio_mem_vmcore_pfn_is_ram; @@ -2870,8 +2873,6 @@ static int virtio_mem_probe(struct virtio_device *vdev) if (rc) goto out_del_vq; - virtio_device_ready(vdev); - /* trigger a config update to start processing the requested_size */ if (!vm->in_kdump) { atomic_set(&vm->config_changed, 1); From patchwork Wed Dec 4 12:54:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13893715 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 93697E7716E for ; Wed, 4 Dec 2024 12:55:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2AB0E6B00A7; Wed, 4 Dec 2024 07:55:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 233C66B00A6; Wed, 4 Dec 2024 07:55:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0AF216B00A7; Wed, 4 Dec 2024 07:55:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id DA3956B00A2 for ; Wed, 4 Dec 2024 07:55:23 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 95F291C74C7 for ; Wed, 4 Dec 2024 12:55:23 +0000 (UTC) X-FDA: 82857272106.24.7DDC02C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf22.hostedemail.com (Postfix) with ESMTP id A715EC0018 for ; Wed, 4 Dec 2024 12:55:05 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Ev0msI2/"; spf=pass (imf22.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733316914; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=8qWcPvM3uPJNBlH29eIda0Org6XNMptmimUFcDc8wZo=; b=C2Kk5WBZ47pmaOC83015BjXSPjiylhSXTMaOFZaee21VDsAYjC3mFIJGI6Qhb6LFMeC5ze u6uYgx11AJcLYVq8kB+xk2ZQgpngGqzju37eCIGZfIgwjBxvHkjivweUtp/vcKdXIXgv1V Wd7aKdoNynMWWeamPhhLI7lMsWh+TBs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733316914; a=rsa-sha256; cv=none; b=dMHj0ahGvrl1PCvGMRRO770F+tdArXt6L2Po8A5foWfT+lSdijFuucZBXbgNTzgy01oOwX 2A2GbqHnS+x40HS5Obh0n4ZWxTwfGlmlL+ZhW4wrE+INt1TiyZMoH54m5GH3ILR/cpMtb8 5zL/yP5pztotkkr3mLoEp4D8g/sVq7s= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Ev0msI2/"; spf=pass (imf22.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733316920; 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=8qWcPvM3uPJNBlH29eIda0Org6XNMptmimUFcDc8wZo=; b=Ev0msI2/1xKiqR0Qvg2LLwuFn/3Da2fR1/x+quZTxdgUwaZLX7GZ0rIlrJZJzDU0PMe3j9 LsmFVZsaxLwDxru1TJu3JAgOxeQIMEN9vOIx6YPD+KcBlBq0QxZVGYJHkKC1/mORtNoEMc tfqe01et3HH5/NlOhLG6IyqvB1aq778= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-257-mDwNXtjyOsWdXcm0VsryfQ-1; Wed, 04 Dec 2024 07:55:17 -0500 X-MC-Unique: mDwNXtjyOsWdXcm0VsryfQ-1 X-Mimecast-MFC-AGG-ID: mDwNXtjyOsWdXcm0VsryfQ Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4349e97bfc4so62390425e9.3 for ; Wed, 04 Dec 2024 04:55:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733316916; x=1733921716; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8qWcPvM3uPJNBlH29eIda0Org6XNMptmimUFcDc8wZo=; b=YsyrRxJjp009zg6yWLYMkZADXebbQboR799Hi3QgpEYy2A2dfahDORDcI/6t/kUd3M OBT4fhJR/z8xOScGQiO/o6fu9jYk4A42sYPsfvpuKtiuR2aG4zIS4clwqDV/BfiIx3bH AAYl1D0Axi4LCSph9dLst1Lpz8X8djZOUhZ/tS5kyRAJxKb1ewNcAeqy+0VPXu6eQW4v 1uj93x5ms9iL2sH5iFMJ3BxNzMmKlu7TB94KHh9T+VEMmqMNc2tiAxGgleGkCjmBDfj2 t5QMQBmIQhShUK/QQWF8YYKNWybV1Pv9XU0dwhMxj6frnt3gWyXHohRvwXog31hscwkU jBYg== X-Gm-Message-State: AOJu0YxYVBldCsCCX7VgUx2xr+34/ISuNPrKhA9AaBOG6GmmK9wirU4V 8Yst6DXQYH9eidW3P9eCFQtbKsD9DUzvByAAsfIYEOF81G0PDupTb1A3kIxfszQ4x/umL5OHVsg V096Bp0ebkU7SjZ94BsYMLx18KG2G4uCeNwD1O83OJbcAtRpt X-Gm-Gg: ASbGnctaF6xJDJ3HTcEIrbi78EA+p/kFK0UcLeZ7Lh6Gh+xFkqAjTVc5+6pgk1GAElW HmMO9gYOqEnUa7NYyZN4ncEJmmHINBSsuFDlhddY0DH+NhnVlUyFPxjwoVrEeALFw7XyaIdxCj0 2f9/LRVubMbghOYfVEKybqSrTSltUK2zCKzxDw4PTXMFi6D7A4JFWFi8+K/6dxK2/tfQBMaMhtY gupq4SNr1CmijDj043kl+pGIfBMjeTMRkcL6RlE+gTuSBbrEaOe10c7So/BhVqRprjOQDhA7c5n IT4vPhigXbQhYQehTuAaMDyrO1+HBwrDmwQ= X-Received: by 2002:a05:600c:4fc9:b0:434:a986:11cf with SMTP id 5b1f17b1804b1-434d09c0faamr58499765e9.8.1733316916538; Wed, 04 Dec 2024 04:55:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IH0Ukl1ZPphCA+wOQqYI2PG+9UegKLtZCsee5cNCt9biGs2cCCF0gJFsDeKmcsipWxLJl404A== X-Received: by 2002:a05:600c:4fc9:b0:434:a986:11cf with SMTP id 5b1f17b1804b1-434d09c0faamr58499655e9.8.1733316916209; Wed, 04 Dec 2024 04:55:16 -0800 (PST) Received: from localhost (p200300cbc70be10038d68aa111b0a20a.dip0.t-ipconnect.de. [2003:cb:c70b:e100:38d6:8aa1:11b0:a20a]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-434d52a3139sm24274545e9.28.2024.12.04.04.55.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Dec 2024 04:55:14 -0800 (PST) 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 v2 10/12] virtio-mem: remember usable region size Date: Wed, 4 Dec 2024 13:54:41 +0100 Message-ID: <20241204125444.1734652-11-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241204125444.1734652-1-david@redhat.com> References: <20241204125444.1734652-1-david@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: zH38yRA1bilZKl3G4MIGhclHYypAQm9AUSynFnMQDf4_1733316916 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: A715EC0018 X-Stat-Signature: uz4f6dmsg5u39zuwyiwkmtuiy8kf711p X-Rspam-User: X-HE-Tag: 1733316905-372556 X-HE-Meta: U2FsdGVkX19ofmvHdiIM3+ZzwT7PzCLVzEStS56lrfmuRp6n8yKA6IljIL62iKRwDQmPAGBC8csmX1KdP3oFUiWcV3YOQcEhMI3Pu/GzquN3SeltmhzbjAOjrJNDEWiwOWlZClqZvxfHDWvYisSyRaFMDl+t5ACDfb4F2AD1QiTOV8cW2HStJS1KFu19VFQYHK3SITEJqemY6B/w7HfWVdFde7cvRWrQtyVgVolX6k5iKMkfeBRf+sViV2uVZp14Ks9AXCBbf5jzshIOcwFhu6GAXdHIaCErFCMV+wVAUmMyEmy+do1o1HsLqNlXeIMHFqaBeWmIqCZDdeGtAVDvs0e39FOZu13Zlg5ud01YnRaaKhXTxxInvI9B7hLzQSFfR9NAA63JUot/eI0O+e31DqwoQt2nlDm6YS10njiRMSHo/kWvKh6nrccapNpQ+5cggsbgU4o/65neTglw07Z2oVap5hZ5zxp/7gHf4NG3zJZ5piMyrBzysLm2cwRmls3NE//PS6Ai17zeK7hCTwVHvcJKzKj+ldn/aogv5EL3kacWT38LHnDmKQNHhdBmcN0qzLIBnAGj5XvQxKtGuOuWax8i4RdC1TTRdf4ShXVLK8fxCP7phUwWuKzT42k/oisumSUYKfemsWG6P767PhP2+XqVrCzUAVs4z7p2MQWVnn1yFqCTaSv9rtqsh9yvLlAsCYeRwjAhLLx4sKclBXw8sXDO4igRRusZBEdIMTEjXo4mKKgpG4DVQ6UHtwsMYRS3z7vWNKQM+4+GCRNUwOWFlS8Q8VYblxsAbCcA4oHygwUqajIxgqsPUQMXddK+mxgF/mq4TcU7mwV1fArHb82T7kuUF5KbWVXWvht6QEjJXj+FfASvQi09Yz38NJ3CHv2+w4OP6FxgyOepeO4re43kwpfgJGsvuiWT7rmDH+k1Esvu/slusZNR4lVPZ/AeoTvSd7ieU9ui8ah/3rQATUw aGuP8qAH 0+ZQCGSSeKFj7McpcnfonjQpGxqig4DXmUrCEQX0J23mc8QEfJKh5I5kHMATcOjh1AsJd+mh7B0URjvF9+o55IGyroabQClY9wkf4X2I3dtuDlAg6aLgTclRFpzObM9Pb8kVP/v6/mmjWuD4za1nUa6/TRDUxQROcCsov7owmS2/3mo29mKFaLYdsd/Z6HlZCb85ITs/a9l0s427uiN2TlktOr7zK2WaFW1JEcv0FOGCNYuDinSb8ZBMQRXeNOhDeOcxlnOv7bsNXS7/OcXbGJ69gEYJ1fLa/NRHOJKhjEAXA3ThfqC4M/CISqy/FOOMx62WTbr9ErIRi8xhyMmeSBnWa32Gd9qdgh1+BloiNrSow/CP02+kNLjUOLsQSUio9NbBhpsvgShQ+Q157e1Nn4kLL3xM76LNwX9hawX9rb1UvQ5O/vOnD08gtcg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000044, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Let's remember the usable region size, which will be helpful in kdump mode next. Signed-off-by: David Hildenbrand --- drivers/virtio/virtio_mem.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index 126f1d669bb0..73477d5b79cf 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -133,6 +133,8 @@ struct virtio_mem { uint64_t addr; /* Maximum region size in bytes. */ uint64_t region_size; + /* Usable region size in bytes. */ + uint64_t usable_region_size; /* The parent resource for all memory added via this device. */ struct resource *parent_resource; @@ -2368,7 +2370,7 @@ static int virtio_mem_cleanup_pending_mb(struct virtio_mem *vm) static void virtio_mem_refresh_config(struct virtio_mem *vm) { const struct range pluggable_range = mhp_get_pluggable_range(true); - uint64_t new_plugged_size, usable_region_size, end_addr; + uint64_t new_plugged_size, end_addr; /* the plugged_size is just a reflection of what _we_ did previously */ virtio_cread_le(vm->vdev, struct virtio_mem_config, plugged_size, @@ -2378,8 +2380,8 @@ static void virtio_mem_refresh_config(struct virtio_mem *vm) /* calculate the last usable memory block id */ virtio_cread_le(vm->vdev, struct virtio_mem_config, - usable_region_size, &usable_region_size); - end_addr = min(vm->addr + usable_region_size - 1, + usable_region_size, &vm->usable_region_size); + end_addr = min(vm->addr + vm->usable_region_size - 1, pluggable_range.end); if (vm->in_sbm) { @@ -2763,6 +2765,8 @@ static int virtio_mem_init(struct virtio_mem *vm) virtio_cread_le(vm->vdev, struct virtio_mem_config, addr, &vm->addr); virtio_cread_le(vm->vdev, struct virtio_mem_config, region_size, &vm->region_size); + virtio_cread_le(vm->vdev, struct virtio_mem_config, usable_region_size, + &vm->usable_region_size); /* Determine the nid for the device based on the lowest address. */ if (vm->nid == NUMA_NO_NODE) From patchwork Wed Dec 4 12:54:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13893716 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 1E776E7716B for ; Wed, 4 Dec 2024 12:55:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 93ABC6B00A8; Wed, 4 Dec 2024 07:55:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 913A56B00A9; Wed, 4 Dec 2024 07:55:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6F1166B00AA; Wed, 4 Dec 2024 07:55:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 450276B00A8 for ; Wed, 4 Dec 2024 07:55:26 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 0BAB21A0B12 for ; Wed, 4 Dec 2024 12:55:26 +0000 (UTC) X-FDA: 82857272484.28.0A744BF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf01.hostedemail.com (Postfix) with ESMTP id CAA2B40011 for ; Wed, 4 Dec 2024 12:55:12 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Yf690vQH; spf=pass (imf01.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733316912; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GxsrWUisM+4YkdsHUV4TP4AYDbO5CJkwL1nd2GKtk5k=; b=lnFJc5YFI0CKx1fp77IbF1XeJjSZSwlye9mv0hnwC3UP+RzMryXZgE9FLGm/JAKntyBC5Y 4HvoR4WtY78tYC0v2DXoBFsi1IJ9Zke6esMz9t4RmIf0aIZ++eJyC1cGQ8se5xxw5FubFa Yxpdjf15/Y0MsFWzH1TZEUGUr8+9DZY= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Yf690vQH; spf=pass (imf01.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733316912; a=rsa-sha256; cv=none; b=GJA1XsskSGejGciO6XiQe7bVGsFahZI1z78V9xDvMNIu6vN80OPAlCyo1JotTJ7O+iRliZ deR6eRwrhSvvmcqaG6wai+Gk7nIhuIH0kSKFZMScV4xme/1GTCvTJgXA7o1rASJYIXwKh5 qzdIQG9Dsel4y2ZyCK+omgjx1bm8Qsk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733316923; 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=GxsrWUisM+4YkdsHUV4TP4AYDbO5CJkwL1nd2GKtk5k=; b=Yf690vQHXm6pwynMZHORO2K/EvbovV3uToav/ThH+3SOeuOcMFtJxVGQFza/g+dkrasawe XAwRGAPyzxcRHWhBnEWuutrNpg6e5ChPxZn06t88s8icf1GPlHvcUm+FgdPxt+WYceJv4j 0fOBcwB6IY4qisnXPuu8IDQwTz7AP3Y= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-169-rq0khAElNROA-sGmkowk5A-1; Wed, 04 Dec 2024 07:55:21 -0500 X-MC-Unique: rq0khAElNROA-sGmkowk5A-1 X-Mimecast-MFC-AGG-ID: rq0khAElNROA-sGmkowk5A Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-434a90fecfeso49797305e9.1 for ; Wed, 04 Dec 2024 04:55:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733316921; x=1733921721; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GxsrWUisM+4YkdsHUV4TP4AYDbO5CJkwL1nd2GKtk5k=; b=fily8Fn4cYMypSatmXqQGxvNeHGMNxkbDe0BZcW+TvxSdAdF55uDC6t5my1mIXXYBE luwUxE1xR3smoERCTvZXplcb3oTV5WSDd/6sXSUdRhia2DVaY+867LckMKFJXHUtU43m 4rPuVcAK7DcLeotJCSWNONkSn+r0FgvMmZujFbaiz6Zz2Q79Eo4YzSQ1XY8KGJe9jthQ X6/6nvv2qQuT2sP64zvu1QvZWcZXOZYmHUyO/6kxpcYoVb5XfVe6JLRCu0yud9UPj5Nm 3uZQRiz0UHFNpfXwvg7fErPwHg62DXv9frPgVawqo8vhF9ZVjihc84OnKgH3Y8hbMEr6 oVyA== X-Gm-Message-State: AOJu0YyQdrH1dLqU/fY9w7d/EQFlUmPiH+JPfrQvcm7NBGtYjd/j+Lb8 H3IR4Pb4DTyFAwdvtylaLmtPnuO2R9HcQWfnEeFUj9CrvDzFj69Z0GCiV807AnrchCF7dipz2sk p0TliDK1l06RhEuTxEtItgSyKtdw93rOmIMcurabjWGI6w7N7puc+sKLMFEA= X-Gm-Gg: ASbGncvHB0ug2fCOmBRbc3B8ps7dQxksT1c6Q1aMFi7G8IpsVHszAsSAcD7iRcHLyQ3 G8twmlO9ZFgqdHQnlf/iNCdl4j158utlrwxHBfAsm2X7uYf71U9olC4malbfePrwE3Rp7aqAbPt m5HDjYwDtQsE2pSIHZj9ZS/Ms0ECk2lSley0UNOFSuKLtcvBHtA6q5o0i23MZ3CqCwg44u4lnnt Ka1iXgKt8q5JNzFHdUIRycVC2AsUNRcc0GDO1NK4VVSkdXBzTcqz9xbRlV1O/0OdDoNj3CIQ4Q2 w5KrY3mJPVSUZ8b4GiVfmHwUwUqYB+FgzpI= X-Received: by 2002:a5d:5986:0:b0:382:4115:1ccb with SMTP id ffacd0b85a97d-385fd3cd078mr5363634f8f.7.1733316920737; Wed, 04 Dec 2024 04:55:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IHVrn7snw7RGTPCk/ImHOMtvIc2Zo//ldD8UcsohYWGwkye1iFqtEVkXPmZASBRCfdSRO6pnw== X-Received: by 2002:a5d:5986:0:b0:382:4115:1ccb with SMTP id ffacd0b85a97d-385fd3cd078mr5363620f8f.7.1733316920347; Wed, 04 Dec 2024 04:55:20 -0800 (PST) Received: from localhost (p200300cbc70be10038d68aa111b0a20a.dip0.t-ipconnect.de. [2003:cb:c70b:e100:38d6:8aa1:11b0:a20a]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-434d52c0bc7sm23529155e9.35.2024.12.04.04.55.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Dec 2024 04:55:19 -0800 (PST) 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 v2 11/12] virtio-mem: support CONFIG_PROC_VMCORE_DEVICE_RAM Date: Wed, 4 Dec 2024 13:54:42 +0100 Message-ID: <20241204125444.1734652-12-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241204125444.1734652-1-david@redhat.com> References: <20241204125444.1734652-1-david@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: PMiAqGQ_UYRPaTGdmNDZktKpqr0pFKsFnV1_If_SmpU_1733316921 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Rspamd-Queue-Id: CAA2B40011 X-Rspamd-Server: rspam12 X-Stat-Signature: d1zj3jfotamcq3b7zt7ib4dewq5g34re X-Rspam-User: X-HE-Tag: 1733316912-241117 X-HE-Meta: U2FsdGVkX1/xwl9g9eEisgLSjG+96dkDjhPxtZvrGu4eSU9UTHIrwq6CGyZHd0w9x2lGB2m5jlXw2j2PdSyUq67lPpMaVTnbtmSTwaBlkK9KGxESdhJVDKIHMfWO4xu42uStmEYDAkEKeQAYagmdTkMU/9gqsMat4EhbZ+ob9Y0oCFK7AQrjWjFa6cSt70gNWFaf410yzLqxgeaCg5mUg6ru8psuXwNWcB5ivS1McXicsXzcLgLg7cXxLw0oXK4DT0en7fE6rnzGV4nSHBh46Q7mTZZdYeZJmEG/LBQRRkgQ4Tu422Wzm6Q4vWPeDoBX+7564mOYwZmpnZHz2RQNRy74EMllvrx/gfgu+6fI1sL1xgvaPVIUSm8MhR2IIIcbCClpgaRtiMwoFN+3flY+TtFW9R5EvP0D4jQrjBy7TPzt5OUMNCP6ayj5UrDvU+ET3oMc/70dkXNm2Hn1BkykvBWsyz1ASHSyA+tkzMS0yEcEYvuFAGnAo3NWwqQFVcnUGWhizu+3otXWBRu+BhpFlrptaR6fmNU9tz0moBNXefzN5upgPyYwfhlJLf5blRUOPdaOAn4lKsosyil/A5HiSF9D1//EaSTWI2lPXUh+zsXbrivlfKk9AaVCi2z+Dvpoz0HiPQQqQRs+4IY4+GppSKo2Z/19NPSdZHouwg54QQ3Egy1Ias8qIg5fMQapxvXOGluJvGeTwfzINGUS91tUmMxl46SCj73BW57R2fAfsz92qDgRBsE2I8TG4dvLn88XvMp6DcbS4n9pcjvUFMxOeihv4Zc/j2AcLlGkgMF0sNrAEVwNpCpkUh2iGYHbe7kc0AFlhZpVRsNElYoAZjScWDGEabzJFmY4Cwo/T3l7yGAJigkuTNW5FPBiG+y3kA7vjC8U6BDYQ5Y+RGm7hGidqLFV5Kls/+KlwpriowWp1+MfMrpycmQlIT8bwfcQDuSrzsR3EL56OPyM1OLGJ38 IVjfn9m1 deDXPdKzw11y/Jj3dbYqMCXCpfEr1LUZQNF/GLSE7IcNIk2DWOPFg+Zn5G0QdSyQleOwhHEMSoL41kkzsAOUpRcVWxAmuftsog6wrYhpCtaTJvyt9PJoIOw48XYixOVwo9CRS6xTNb/PW2wiWyq96soPsHg9EaiUzUPWduhfBHSuvY1/1njxZpkRks4bz47pRND9k7IJBPm7F0KvJ4yfyI+iE9tjqNdzLOvSmCxqppZOBhhQ51Gut8970aGETN9k6QtIgiuv5ZDJ8XfJlaaIuGvb22HP1haQ1mzmbckAccy/f/hNOAc7vX/kFRr022MvlOTGT3mI7oBoqqMGBZvXQzSc1IRPh6NlFPsTqJFS+D3muM1j9zYFf54dMbyeEUBo66x6p7ikSDVrkFoCKR5Mz2baIcXeulALd1zm0bGfBhxDMj1rce55XN0ckYawFhk/AdAyKZCKUqPMUWyhFZcZriN55DU2kdVTePgWk 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: Let's implement the get_device_ram() vmcore callback, so architectures that select NEED_PROC_VMCORE_NEED_DEVICE_RAM, like s390 soon, can include that memory in a crash dump. Merge ranges, and process ranges that might contain a mixture of plugged and unplugged, to reduce the total number of ranges. Signed-off-by: David Hildenbrand --- drivers/virtio/virtio_mem.c | 88 +++++++++++++++++++++++++++++++++++++ fs/proc/Kconfig | 1 + 2 files changed, 89 insertions(+) diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index 73477d5b79cf..8a294b9cbcf6 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -2728,6 +2728,91 @@ static bool virtio_mem_vmcore_pfn_is_ram(struct vmcore_cb *cb, mutex_unlock(&vm->hotplug_mutex); return is_ram; } + +#ifdef CONFIG_PROC_VMCORE_DEVICE_RAM +static int virtio_mem_vmcore_add_device_ram(struct virtio_mem *vm, + struct list_head *list, uint64_t start, uint64_t end) +{ + int rc; + + rc = vmcore_alloc_add_range(list, start, end - start); + if (rc) + dev_err(&vm->vdev->dev, + "Error adding device RAM range: %d\n", rc); + return rc; +} + +static int virtio_mem_vmcore_get_device_ram(struct vmcore_cb *cb, + struct list_head *list) +{ + struct virtio_mem *vm = container_of(cb, struct virtio_mem, + vmcore_cb); + const uint64_t device_start = vm->addr; + const uint64_t device_end = vm->addr + vm->usable_region_size; + uint64_t chunk_size, cur_start, cur_end, plugged_range_start = 0; + LIST_HEAD(tmp_list); + int rc; + + if (!vm->plugged_size) + return 0; + + /* Process memory sections, unless the device block size is bigger. */ + chunk_size = max_t(uint64_t, PFN_PHYS(PAGES_PER_SECTION), + vm->device_block_size); + + mutex_lock(&vm->hotplug_mutex); + + /* + * We process larger chunks and indicate the complete chunk if any + * block in there is plugged. This reduces the number of pfn_is_ram() + * callbacks and mimic what is effectively being done when the old + * kernel would add complete memory sections/blocks to the elfcore hdr. + */ + cur_start = device_start; + for (cur_start = device_start; cur_start < device_end; cur_start = cur_end) { + cur_end = ALIGN_DOWN(cur_start + chunk_size, chunk_size); + cur_end = min_t(uint64_t, cur_end, device_end); + + rc = virtio_mem_send_state_request(vm, cur_start, + cur_end - cur_start); + + if (rc < 0) { + dev_err(&vm->vdev->dev, + "Error querying block states: %d\n", rc); + goto out; + } else if (rc != VIRTIO_MEM_STATE_UNPLUGGED) { + /* Merge ranges with plugged memory. */ + if (!plugged_range_start) + plugged_range_start = cur_start; + continue; + } + + /* Flush any plugged range. */ + if (plugged_range_start) { + rc = virtio_mem_vmcore_add_device_ram(vm, &tmp_list, + plugged_range_start, + cur_start); + if (rc) + goto out; + plugged_range_start = 0; + } + } + + /* Flush any plugged range. */ + if (plugged_range_start) + rc = virtio_mem_vmcore_add_device_ram(vm, &tmp_list, + plugged_range_start, + cur_start); +out: + mutex_unlock(&vm->hotplug_mutex); + if (rc < 0) { + vmcore_free_ranges(&tmp_list); + return rc; + } + list_splice_tail(&tmp_list, list); + return 0; +} +#endif /* CONFIG_PROC_VMCORE_DEVICE_RAM */ #endif /* CONFIG_PROC_VMCORE */ static int virtio_mem_init_kdump(struct virtio_mem *vm) @@ -2737,6 +2822,9 @@ static int virtio_mem_init_kdump(struct virtio_mem *vm) #ifdef CONFIG_PROC_VMCORE dev_info(&vm->vdev->dev, "memory hot(un)plug disabled in kdump kernel\n"); vm->vmcore_cb.pfn_is_ram = virtio_mem_vmcore_pfn_is_ram; +#ifdef CONFIG_PROC_VMCORE_DEVICE_RAM + vm->vmcore_cb.get_device_ram = virtio_mem_vmcore_get_device_ram; +#endif /* CONFIG_PROC_VMCORE_DEVICE_RAM */ register_vmcore_cb(&vm->vmcore_cb); return 0; #else /* CONFIG_PROC_VMCORE */ diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig index 5668620ab34d..6ae966c561e7 100644 --- a/fs/proc/Kconfig +++ b/fs/proc/Kconfig @@ -67,6 +67,7 @@ config NEED_PROC_VMCORE_DEVICE_RAM config PROC_VMCORE_DEVICE_RAM def_bool y depends on PROC_VMCORE && NEED_PROC_VMCORE_DEVICE_RAM + depends on VIRTIO_MEM help If the elfcore hdr is allocated and prepared by the dump kernel ("2nd kernel") instead of the crashed kernel, RAM provided by memory From patchwork Wed Dec 4 12:54:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13893717 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 A86E9E7716E for ; Wed, 4 Dec 2024 12:55:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B117B6B00AA; Wed, 4 Dec 2024 07:55:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ABF876B00AB; Wed, 4 Dec 2024 07:55:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8EACE6B00AC; Wed, 4 Dec 2024 07:55:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 6A7B56B00AA for ; Wed, 4 Dec 2024 07:55:30 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id DC2FB120513 for ; Wed, 4 Dec 2024 12:55:29 +0000 (UTC) X-FDA: 82857272106.08.D4BAE00 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 3CDE980013 for ; Wed, 4 Dec 2024 12:55:00 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HaGf3Ilb; spf=pass (imf30.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733316918; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=QMLpjiP43p31BywTFNffjh3NzCBHssnVGTYWU2BwGcs=; b=7NmWrWhLPPEg+UDjRi7NoBFMdJvcpk1T71RC0+0i80iE7RRyg4hrWIOX2+zNTJ5UKpVmv0 rlRSjmhGPXJRe7pAdhBNScGj97GYZjal6+3mOCbUjtJ+MpRn1fpKfxscYo5E8AD8uMUlSg rC+G13X6281HXSzcpr01bFlp0t78Was= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733316918; a=rsa-sha256; cv=none; b=5C9ZGf3CXgQxnFPRFqDOwDH4uG0T4d8polQWrxKmHjmKkJUoAuzxfJwj+0CEtA9ZpzWlVm /GZfpKk6fhHHxPG7Ri68MQWPIRc2Q2RdG4q+xJML8wfQQ78+GHQEX8eB9m7nkhGSSAITn/ qTTCUu9kZwYinwSdAckcVRRIxOHQ4aE= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HaGf3Ilb; spf=pass (imf30.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733316927; 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=QMLpjiP43p31BywTFNffjh3NzCBHssnVGTYWU2BwGcs=; b=HaGf3IlbJ2Adk/Tq/5c69KLVUKaWWX5T2E9knbtsjei6OUKgLBAuWQTcBtqa6bdI5N300B A9D1ciSccIg9CZKgLH1M3FsNrCNf1787TymUDqf56oYA0l1gnuj1G+jSm6xO7GeUR+q4rJ irpoA3MCINn9MzNGLQQUc+dPJqSh54Y= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-640-N635yaQPNOqweAAon7wXyA-1; Wed, 04 Dec 2024 07:55:25 -0500 X-MC-Unique: N635yaQPNOqweAAon7wXyA-1 X-Mimecast-MFC-AGG-ID: N635yaQPNOqweAAon7wXyA Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-434a37a57dfso55382435e9.0 for ; Wed, 04 Dec 2024 04:55:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733316924; x=1733921724; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QMLpjiP43p31BywTFNffjh3NzCBHssnVGTYWU2BwGcs=; b=e49EYE2t5n247wFvuDi8+Ko9mHMj2UGxMo4fZWgTHUyuGa4361Q4Yv9nStqeJTguTS 5VBQMrPwnNvbGUC+NJhqdzZsKWYYaO5VcAQAwc37DAV9h8AtL5dJaqQCb8mPjcgRDPO+ t2OsycJ6FCr16QQk7mRREMvuh1Q2YvYRDNNQKaFoxFqR9/iBwh0pXjK/leb5ONcAv/mA 2eL/MmnlEMUFiG2DtQsnTa/VcXFSYD6ZIz73NjK0uMdLB0K3UlDLKBm7wY4INMHjbHLC esrEWVPREGIC/EBWP6wq4sheZK3MRjRsPIc4pL9UGzbui4UCL+KRK1JtKaJvgXhEC7Z8 RS1A== X-Gm-Message-State: AOJu0YwRUHitZuVPAXljcDmUsPFeJx/QJtaxO6oqFwwwiBXoSXLQMD2O DSFgNBFoLiQUnzPAS6qGzQtmz603izXhqohjyd+PaxmdYcWDu0jkU8JqfmvSl/tr3P9y9nINDvS AKA6lJ48tMihrwSC2M15KuuON122z5e/n8uzsjTZJaXGvRaNX X-Gm-Gg: ASbGncvtPqJzQW6ZssJgKg36JVgl+VY7/fNDMPHtcey1/HdaKkX1bCP7OsxZTCpvAXD ejV0PyK9/RZBgRuCZcQd+0vaXZPx5MUZAUt3R82LPc+ft7UaaiH0vHJBE5Aqf+fDt/FZJkaAiX3 CkpIxJRlY7j8hJkXQQUvaC6Wg5qEH0kZixkwRcpTVM8T+IoF7Y73MGy/hzLfqDFXDklKbBFjY4R tnggU/7FGOiOsvd2aR48XruANiucCkvn5ONp5KVj9NheoMsDhaa1zsP4vxl8tYbl7XPkKremTy+ b6qAh8J//VISWTyiqOppw64SlJK/NJ9ea7I= X-Received: by 2002:a05:600c:1910:b0:434:a962:2aa2 with SMTP id 5b1f17b1804b1-434d0a178d4mr49286505e9.33.1733316924456; Wed, 04 Dec 2024 04:55:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IFFzA2SYKI5zve6AhLcTcIqYEQR+M/xeFfejA5VMHPdifDyO5ycBtXVIAK8EC4IQe7u0N0Ewg== X-Received: by 2002:a05:600c:1910:b0:434:a962:2aa2 with SMTP id 5b1f17b1804b1-434d0a178d4mr49286335e9.33.1733316924087; Wed, 04 Dec 2024 04:55:24 -0800 (PST) Received: from localhost (p200300cbc70be10038d68aa111b0a20a.dip0.t-ipconnect.de. [2003:cb:c70b:e100:38d6:8aa1:11b0:a20a]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-434d52c0bc7sm23531055e9.35.2024.12.04.04.55.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Dec 2024 04:55:22 -0800 (PST) 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 v2 12/12] s390/kdump: virtio-mem kdump support (CONFIG_PROC_VMCORE_DEVICE_RAM) Date: Wed, 4 Dec 2024 13:54:43 +0100 Message-ID: <20241204125444.1734652-13-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241204125444.1734652-1-david@redhat.com> References: <20241204125444.1734652-1-david@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: LOvuYJR59SSSxVfn8ORnLhoCqjWVvTID0FIXyi7hmT0_1733316924 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 3CDE980013 X-Stat-Signature: 4sa6qjou9r8omccjuywa6p8sa1h1qs4s X-Rspam-User: X-HE-Tag: 1733316900-871910 X-HE-Meta: U2FsdGVkX1+2NyicWz8yi3g/S0iH/8/LGM5VwydmbFQF4b6AzWdVmlB5Lqr+TFwkuYSuWGBVFJYNpMptacCBmdKjWSaRnAkfeoKVbL03FEa0mIL0kPAk56ZKCHs1ltvrA3PlohgbLsu/bKrfdX5KWzoI8Dr+gwSNvWC8lwifwlhsy7q9OvnQwHjcxgMRdCkMOuZFq5MYIAaBAruJzoXKpk0lkoC9JyU0YMh3e1IAk86b7N55tvVaH4WQ/v/eDSZiollaqVepXbm04hhzXzCXNWCFkQ3lkDs/kUwXZYOPKJB8KuChBMoGWyWoZjpCcubijZUehRfFq72K5CVJDX7wrZseuVdY+W1Xb2Sl/GoWAJ8fPDFkOzChovPpGg6nO3Ur+xRf+TQFthY9LmtPGUIfaQ2e6yw5xNY6JFdstYyC4/Pf2O90KNAVBFKl4WxA2yfb6LnNe1bbnzNpTC1vXTBPIXmEY6Mqn5EcMBZH8ZOWyvvlpC4FmvdROI4OQt/qaK8AMZLCG8Y3eG1I/nznuw79iKzDBJVUlnyyHnmuNbAv31FCPP1SiUamoUYMe1STRXU3ZDmIXRWNsXJh5JUlP272T46o6rtRJUmZnnmpg7ZgCoVrS925WxY/0VczDFotQp4kCz+gTHkCUDtUMurAUU98E36jvewXSbr+p5LwXKFpWoztaH0ptNaywrmrwIek91vlAIGdYVsm9V+DnQn8F2mPLwqg4BVEig6jUv68SOmuL1BAyi/RQESWgkjMnHamz86nQ+g+2ARuoOYTFiz1ySxoD0XdpqDqVix56+DdLAowf6K77J+38q8H2Z/fyedSyFcRp56olxQCoBeFQ5xm8JEIjs2AkAApSbBo+fpSE7QAZAn8VXKdvdS50B3dV/Z1CauJefVfQCi16e2XXG76PbYZgD4Khs3ajyQn+w2oJ7yfYHdVD/o85b7NS43As/eVSvbxEg1fAsqPCTZA/ey0a/Q NFZL9ZHM 5rsGcqjbSmkV78omlaHSIZKXytTqE+AoygwUQNrPmF4FpZ/HSnZEM7qPUiDJiIFfoMcm7I6ZII6S5QNnh+w52uHyonW03zLBSe8Cu6xmz0l2rIiJoA9itdf+E3M5rO4J+xJVzbE92iwo1KiNSVr4VnwuYZJJtKAeU9eBU99kpb4PX0FaN9c8/6yh/lfMDKYsfJiuCp+OjIKqEN9P6GfWLYJ6FI5QQv9H6Be2Vq/S/CActAVRozs2DP+SoQFYS1bLNZKptQrGAJT9ci9e4gPbgrrB0y9SI0iT0ikgKEl9C74BtjOii3ylOlvxffI5J9jFEYBO99KlHH2P/clO5cwYZXsRO1z0XECMKQhphS9198g52ZgMgKGJPSBGa2N4JEsk9BWKwzBn1XjQi6P7Kl3e5zDWZ0UR3/zoaLjiZdLOy4WLIgiJvndxuZknGt4LM8+W7jfXOgROkFt7s/7mBQZxodZy4132g51zlnVL5 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: Let's add support for including virtio-mem device RAM in the crash dump, setting NEED_PROC_VMCORE_DEVICE_RAM, and implementing elfcorehdr_fill_device_ram_ptload_elf64(). To avoid code duplication, factor out the code to fill a PT_LOAD entry. Signed-off-by: David Hildenbrand --- arch/s390/Kconfig | 1 + arch/s390/kernel/crash_dump.c | 39 ++++++++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig index 0077969170e8..c230bad7f5cc 100644 --- a/arch/s390/Kconfig +++ b/arch/s390/Kconfig @@ -240,6 +240,7 @@ config S390 select MODULES_USE_ELF_RELA select NEED_DMA_MAP_STATE if PCI select NEED_PER_CPU_EMBED_FIRST_CHUNK + select NEED_PROC_VMCORE_DEVICE_RAM if PROC_VMCORE select NEED_SG_DMA_LENGTH if PCI select OLD_SIGACTION select OLD_SIGSUSPEND3 diff --git a/arch/s390/kernel/crash_dump.c b/arch/s390/kernel/crash_dump.c index cd0c93a8fb8b..f699df2a2b11 100644 --- a/arch/s390/kernel/crash_dump.c +++ b/arch/s390/kernel/crash_dump.c @@ -508,6 +508,19 @@ static int get_mem_chunk_cnt(void) return cnt; } +static void fill_ptload(Elf64_Phdr *phdr, unsigned long paddr, + unsigned long vaddr, unsigned long size) +{ + phdr->p_type = PT_LOAD; + phdr->p_vaddr = vaddr; + phdr->p_offset = paddr; + phdr->p_paddr = paddr; + phdr->p_filesz = size; + phdr->p_memsz = size; + phdr->p_flags = PF_R | PF_W | PF_X; + phdr->p_align = PAGE_SIZE; +} + /* * Initialize ELF loads (new kernel) */ @@ -520,14 +533,8 @@ static void loads_init(Elf64_Phdr *phdr, bool os_info_has_vm) if (os_info_has_vm) old_identity_base = os_info_old_value(OS_INFO_IDENTITY_BASE); for_each_physmem_range(idx, &oldmem_type, &start, &end) { - phdr->p_type = PT_LOAD; - phdr->p_vaddr = old_identity_base + start; - phdr->p_offset = start; - phdr->p_paddr = start; - phdr->p_filesz = end - start; - phdr->p_memsz = end - start; - phdr->p_flags = PF_R | PF_W | PF_X; - phdr->p_align = PAGE_SIZE; + fill_ptload(phdr, start, old_identity_base + start, + end - start); phdr++; } } @@ -537,6 +544,22 @@ static bool os_info_has_vm(void) return os_info_old_value(OS_INFO_KASLR_OFFSET); } +#ifdef CONFIG_PROC_VMCORE_DEVICE_RAM +/* + * Fill PT_LOAD for a physical memory range owned by a device and detected by + * its device driver. + */ +void elfcorehdr_fill_device_ram_ptload_elf64(Elf64_Phdr *phdr, + unsigned long long paddr, unsigned long long size) +{ + unsigned long old_identity_base = 0; + + if (os_info_has_vm()) + old_identity_base = os_info_old_value(OS_INFO_IDENTITY_BASE); + fill_ptload(phdr, paddr, old_identity_base + paddr, size); +} +#endif + /* * Prepare PT_LOAD type program header for kernel image region */