From patchwork Mon Aug 5 09:32:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gowans, James" X-Patchwork-Id: 13753334 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 DD7ADC3DA7F for ; Mon, 5 Aug 2024 09:35:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7A9F66B009D; Mon, 5 Aug 2024 05:35:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 759C36B009E; Mon, 5 Aug 2024 05:35:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5FA116B009F; Mon, 5 Aug 2024 05:35:36 -0400 (EDT) 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 3AEE16B009D for ; Mon, 5 Aug 2024 05:35:36 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id F14F881C18 for ; Mon, 5 Aug 2024 09:35:35 +0000 (UTC) X-FDA: 82417684230.01.79B6114 Received: from smtp-fw-80009.amazon.com (smtp-fw-80009.amazon.com [99.78.197.220]) by imf05.hostedemail.com (Postfix) with ESMTP id DF791100009 for ; Mon, 5 Aug 2024 09:35:33 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=TuR4j0nd; spf=pass (imf05.hostedemail.com: domain of "prvs=940e15008=jgowans@amazon.com" designates 99.78.197.220 as permitted sender) smtp.mailfrom="prvs=940e15008=jgowans@amazon.com"; dmarc=pass (policy=quarantine) header.from=amazon.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722850472; 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=b/ZDrMWB4VIy9ADRZF2m3pCqPq++QQhsZ6WqVk7Aipc=; b=AUkGR3npc0+pXNKY1prXi5N9CsDKYX7NYLprKkJlQDx26IU6Y3JTM5k9qgb3bV/W6Rr9h3 k2y9MxAoocHRok/9yK+VdhcJ/gjpMdRJYIEtNxYci5j29vdj6esagdJhxJlAuOZ7H0AcFR 3U3xKwBIXhA/5+QZ2JNNAMuCsVIc/1w= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722850472; a=rsa-sha256; cv=none; b=xjSsMXDdh7oFGWjWDScSLXJqVOYibyS3opVPCHY2guJ1+n+XCgqd4Dm9tIKXyCUssMH06r tpLkny6LGFDKoELw9tBLYx/K475vNTkRmdBHwysf621Aqy9UIez0Kef7Zciykjn6MCdT+B 2y4wj34Zozc+QNR8YDD54chzPNWkXy4= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=amazon.com header.s=amazon201209 header.b=TuR4j0nd; spf=pass (imf05.hostedemail.com: domain of "prvs=940e15008=jgowans@amazon.com" designates 99.78.197.220 as permitted sender) smtp.mailfrom="prvs=940e15008=jgowans@amazon.com"; dmarc=pass (policy=quarantine) header.from=amazon.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1722850533; x=1754386533; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=b/ZDrMWB4VIy9ADRZF2m3pCqPq++QQhsZ6WqVk7Aipc=; b=TuR4j0ndKzOgL0hg3WqnXT0RQqvEPwzHWPYPHcv3ntsuouNSIPkNlsLo 2hwNXAURpd9aCJIpcTnoMizJNZ4LIwD069tg5FBSoqVbFGrt/E/Koz84o gCNZmSnTfqDaftX5u8dH5BkrEVyg4Tns2jVHXN0XYYOUX3xIfijDYmSwC 8=; X-IronPort-AV: E=Sophos;i="6.09,264,1716249600"; d="scan'208";a="112169575" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.210]) by smtp-border-fw-80009.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Aug 2024 09:35:29 +0000 Received: from EX19MTAEUA001.ant.amazon.com [10.0.43.254:35726] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.45.111:2525] with esmtp (Farcaster) id ba2c37fa-2737-488d-9a39-9aa5f2392569; Mon, 5 Aug 2024 09:35:28 +0000 (UTC) X-Farcaster-Flow-ID: ba2c37fa-2737-488d-9a39-9aa5f2392569 Received: from EX19D014EUC004.ant.amazon.com (10.252.51.182) by EX19MTAEUA001.ant.amazon.com (10.252.50.192) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Mon, 5 Aug 2024 09:35:27 +0000 Received: from u5d18b891348c5b.ant.amazon.com (10.146.13.113) by EX19D014EUC004.ant.amazon.com (10.252.51.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Mon, 5 Aug 2024 09:35:18 +0000 From: James Gowans To: CC: James Gowans , Sean Christopherson , Paolo Bonzini , Alexander Viro , Steve Sistare , Christian Brauner , Jan Kara , "Anthony Yznaga" , Mike Rapoport , "Andrew Morton" , , Jason Gunthorpe , , Usama Arif , , Alexander Graf , David Woodhouse , Paul Durrant , Nicolas Saenz Julienne Subject: [PATCH 08/10] guestmemfs: Block modifications when serialised Date: Mon, 5 Aug 2024 11:32:43 +0200 Message-ID: <20240805093245.889357-9-jgowans@amazon.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240805093245.889357-1-jgowans@amazon.com> References: <20240805093245.889357-1-jgowans@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.146.13.113] X-ClientProxiedBy: EX19D046UWB002.ant.amazon.com (10.13.139.181) To EX19D014EUC004.ant.amazon.com (10.252.51.182) X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: DF791100009 X-Stat-Signature: 3dgry3z94u13dhtu17a4iqkjf7q7u7jm X-HE-Tag: 1722850533-949321 X-HE-Meta: U2FsdGVkX18zEqYg+LsP97yhjye8jXLgoXnwvSSltPqCvyk9g7+twTqFFaU57KZxPXz0rfEOkrWz7meLOHk3nyGLVDCdAeTTux+SahBFkQqepqdbevwi9XvwoiyYdyMvMAu+M2oBBZm37p87fMn8eOC5QXI0WHy1wriocR3Jw75AMY1Y0cV3YtH0r+gssCTC0rvc0JpawdbtoUtO9ilTZZ54oDjalkU8Sru2ZJLqqag882FfOie0+YJF/7EmC+Yk9B5X9wf+LTVgG0zRc+ofKs4xybLqaCIaD9RlFDs/2wqSd7NblvB7/DmKOQS8MbIjps1xMzCu8xjgfhyW2HJWKqfmKc834GDPnhJ4jhN027wdKzOdlODQ6by8XXhrpag8I37sdLxezPJ6lc7cq7x9Y1nQ2Ukfijcg/G+Q/+IJgL9HhA0/yUiM4S7FIj69acC7q4JBdCyHBhrdCo1wXp9rRoSHKzMXZHi00vL/LG9G49GU/k8jZwz5EpRz224RG5uAxG3gNpCxEwmjeUXvn9/MkztebZ/DYq6i0JOkUo66SYlCWcNM3Gk8Z96y/0mYh92UMS/x0A1bJsTQpdCpr2a/zm5OEUNxf4rtVGW2wnEVeaa/gqL9OPcEMXIJ67TIzRv8Qnnc4SQy2l5Betltqx+/s8454kXjzz6YhHnhytYBUeLedltUvjAn0X8jgppTcLoL37io6wxkWA6MQPzJA9gtdZXKgqoSi6kXlnuCFd3wlfL2KMr1J1DPGFXwgH21NPYWHj3XHLAzlgmAY5W/W966zL7/NerRujHCD6ErB4Af2/KIBImViZYqFH7gJtbtIaNSj3ybqRT7fxx4Z5mImvxIF5z0vBHAJrkquMEogGMa8MPKEkaKl1fPpdPQRvS5DWKTUX3NDzkVDq29tnBQY3QSgoA+Ur6i5FfneOWaVXjjBadMZZ7DgmEGKfJ5NvcM9kk/DU3wX/+PeI5SQ4DDGXG oHvjtM+S 9LluHkHEwDSJEPS7HPFFyH22Tp/15tLFBExEiu8/lgAVvrMaCuYa3M4L/7Pi7duACf7LcqtDOvVn1ZmHNBAnkNB9vxufr9Ykdy32JFT/LUBpuH1Yokzz/EVllliaXO2VerxxLWEoKmJpzxxohUa1/os6aE0mMgCbqKxqMwlFYs8WaQ5xa1CYE3E9NOuy9DWkGLe7jw4ojVtn5wLXlnICN5UkRRiH24Xz0dsAtJAADScgVs9RH/9wD42kiFxGWHceySFXO87KGAHXEgS/SvOjeBXgGKZBX9tC/552OEuaET7mMYGNSYr3RZVGuyfnOi6Eg7rjidg4obH0xwGR/g4xy3vBmy7NJdPgX9CBtE50I2zfKUMRSq6Elj65AYWJRIg7Z4r83rFAF+T9bsIKegxNOfmuDyuaT9Bh0JivRF87o8bg0mXeBUWOt3tIzWT+EzGb7wMIr8iI2vBX8lfStHUUc2U5yfjyvfIqQ2VFoU+PeH6ivVc9a8giHaPAEH9HS7a3VgHMRZpq6x83Qax0JrnA0sxDimav3je0Gtl1V9jL8ObdrfQTsD078ByzT5JpJBJZpddFXk2itbzbkqg0= 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: Once the memory regions for inodes, mappings and allocations have been serialised, further modifications would break the serialised data; it would no longer be valid. Return an error code if attempting to create new files or allocate data for files once serialised. Signed-off-by: James Gowans --- fs/guestmemfs/file.c | 19 ++++++++++++++++--- fs/guestmemfs/guestmemfs.c | 1 + fs/guestmemfs/guestmemfs.h | 1 + fs/guestmemfs/inode.c | 6 ++++++ fs/guestmemfs/serialise.c | 8 +++++++- 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/fs/guestmemfs/file.c b/fs/guestmemfs/file.c index b1a52abcde65..8707a9d3ad90 100644 --- a/fs/guestmemfs/file.c +++ b/fs/guestmemfs/file.c @@ -8,19 +8,32 @@ static int truncate(struct inode *inode, loff_t newsize) unsigned long free_block; struct guestmemfs_inode *guestmemfs_inode; unsigned long *mappings; + int rc = 0; + struct guestmemfs_sb *psb = GUESTMEMFS_PSB(inode->i_sb); + + spin_lock(&psb->allocation_lock); + + if (psb->serialised) { + rc = -EBUSY; + goto out; + } guestmemfs_inode = guestmemfs_get_persisted_inode(inode->i_sb, inode->i_ino); mappings = guestmemfs_inode->mappings; i_size_write(inode, newsize); for (int block_idx = 0; block_idx * PMD_SIZE < newsize; ++block_idx) { free_block = guestmemfs_alloc_block(inode->i_sb); - if (free_block < 0) + if (free_block < 0) { /* TODO: roll back allocations. */ - return -ENOMEM; + rc = -ENOMEM; + goto out; + } *(mappings + block_idx) = free_block; ++guestmemfs_inode->num_mappings; } - return 0; +out: + spin_unlock(&psb->allocation_lock); + return rc; } static int inode_setattr(struct mnt_idmap *idmap, struct dentry *dentry, struct iattr *iattr) diff --git a/fs/guestmemfs/guestmemfs.c b/fs/guestmemfs/guestmemfs.c index cf47e5100504..d854033bfb7e 100644 --- a/fs/guestmemfs/guestmemfs.c +++ b/fs/guestmemfs/guestmemfs.c @@ -42,6 +42,7 @@ static int guestmemfs_fill_super(struct super_block *sb, struct fs_context *fc) if (GUESTMEMFS_PSB(sb)) { pr_info("Restored super block from KHO\n"); + GUESTMEMFS_PSB(sb)->serialised = 0; } else { struct guestmemfs_sb *psb; diff --git a/fs/guestmemfs/guestmemfs.h b/fs/guestmemfs/guestmemfs.h index 263d995b75ed..91cc06ae45a5 100644 --- a/fs/guestmemfs/guestmemfs.h +++ b/fs/guestmemfs/guestmemfs.h @@ -21,6 +21,7 @@ struct guestmemfs_sb { struct guestmemfs_inode *inodes; void *allocator_bitmap; spinlock_t allocation_lock; + bool serialised; }; // If neither of these are set the inode is not in use. diff --git a/fs/guestmemfs/inode.c b/fs/guestmemfs/inode.c index 61f70441d82c..d521b35d4992 100644 --- a/fs/guestmemfs/inode.c +++ b/fs/guestmemfs/inode.c @@ -48,6 +48,12 @@ static unsigned long guestmemfs_allocate_inode(struct super_block *sb) struct guestmemfs_sb *psb = GUESTMEMFS_PSB(sb); spin_lock(&psb->allocation_lock); + + if (psb->serialised) { + spin_unlock(&psb->allocation_lock); + return -EBUSY; + } + next_free_ino = psb->next_free_ino; psb->allocated_inodes += 1; if (!next_free_ino) diff --git a/fs/guestmemfs/serialise.c b/fs/guestmemfs/serialise.c index eb70d496a3eb..347eb8049a71 100644 --- a/fs/guestmemfs/serialise.c +++ b/fs/guestmemfs/serialise.c @@ -111,7 +111,7 @@ int guestmemfs_serialise_to_kho(struct notifier_block *self, switch (cmd) { case KEXEC_KHO_ABORT: - /* No rollback action needed. */ + GUESTMEMFS_PSB(guestmemfs_sb)->serialised = 0; return NOTIFY_DONE; case KEXEC_KHO_DUMP: /* Handled below */ @@ -120,6 +120,7 @@ int guestmemfs_serialise_to_kho(struct notifier_block *self, return NOTIFY_BAD; } + spin_lock(&GUESTMEMFS_PSB(guestmemfs_sb)->allocation_lock); err |= fdt_begin_node(fdt, "guestmemfs"); err |= fdt_property(fdt, "compatible", compatible, sizeof(compatible)); @@ -134,6 +135,11 @@ int guestmemfs_serialise_to_kho(struct notifier_block *self, err |= fdt_end_node(fdt); + if (!err) + GUESTMEMFS_PSB(guestmemfs_sb)->serialised = 1; + + spin_unlock(&GUESTMEMFS_PSB(guestmemfs_sb)->allocation_lock); + pr_info("Serialised extends [0x%llx + 0x%llx] via KHO: %i\n", guestmemfs_base, guestmemfs_size, err);