From patchwork Tue Jan 14 08:07:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Kasireddy X-Patchwork-Id: 13938515 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 312A9E77188 for ; Tue, 14 Jan 2025 08:38:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C42E46B0089; Tue, 14 Jan 2025 03:38:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BCBC5280003; Tue, 14 Jan 2025 03:38:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9CFAC6B008C; Tue, 14 Jan 2025 03:38:18 -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 79B106B0089 for ; Tue, 14 Jan 2025 03:38:18 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id EE0B7807A5 for ; Tue, 14 Jan 2025 08:38:17 +0000 (UTC) X-FDA: 83005405434.21.A0100CC Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) by imf20.hostedemail.com (Postfix) with ESMTP id E90C91C0017 for ; Tue, 14 Jan 2025 08:38:15 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=JcBQp+PW; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf20.hostedemail.com: domain of vivek.kasireddy@intel.com designates 192.198.163.18 as permitted sender) smtp.mailfrom=vivek.kasireddy@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736843896; a=rsa-sha256; cv=none; b=VEH4QLiDMxcoTwOJVhK0KJp6ePgjk4Mg/q1BZ8N3IMIe38f6EqSNO5RoM85YbJD4cOqaOp 7XK9sLw9UcyXj+bZ7+R1L8dV3J+on/+3yzjOgoE3Q6dIdUN8E+b9wapgQbLH9Mue8rly5s wSREQYhX3b30++7njIzIMaLt3Atuwvw= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=JcBQp+PW; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf20.hostedemail.com: domain of vivek.kasireddy@intel.com designates 192.198.163.18 as permitted sender) smtp.mailfrom=vivek.kasireddy@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736843896; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=rU5kp+OcQDPFmoeb+GDRj0kBXHoi8k4FfvYUGGx4rEE=; b=mz9I2f143cEMU3GSXI2VDqoy4VcMPpIwzqQUcputi8/0SupvNqpDWGt9XscCfjYz0jn4fF XaLAAS1p3Cptc3dFKiN+jAOmwSh0ZBxHdXW2gTDi/KCvA6XSZU4mkk9D+Y9YAQ2iMPFnjD WVRB687hZ0NlO+N4HfHzdQ+sYrsVGAU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1736843896; x=1768379896; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=E6TH/lyWtE8ZlFL6RJjSGsS+m2RTQmVTbw55gtCDXtU=; b=JcBQp+PW3AUBKyGqW/sxTeMonz8DI978hGB1ZzRpw+ikfySPPHLJ4Uu4 CZalhBGkK4iAN17BClQWr8NOVEvUwJZyBjqavvjzLlndNl3nsA00h+6v1 8i7H9GV/GE0DWMvBId6ggdciQbJAYiAaLbT9y0f5FZWgt/SYJ3FwC04BY 6cDyhln1SwGWEe9TYhLp+KODB4EYHv25LCZvwLSXYMoVvgpR1UzNbyn/z LVCbDMAP/AdSmSyDK6C8BnCgtMr1RAdofK5rK4zD3BsjvNUgBXPgXpTrE zGqivgSeXQtbl07y/+VRTGdpReqAub/wHMrbRo1qOeTqXdykBxde6rE5M Q==; X-CSE-ConnectionGUID: Lh1WtpVgSSuO/2iIRqxOqw== X-CSE-MsgGUID: VNL+TpkXRJ62lkjZ4/c9hA== X-IronPort-AV: E=McAfee;i="6700,10204,11314"; a="36418218" X-IronPort-AV: E=Sophos;i="6.12,313,1728975600"; d="scan'208";a="36418218" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jan 2025 00:38:10 -0800 X-CSE-ConnectionGUID: 135edZcDSea+IBOPUJPJoQ== X-CSE-MsgGUID: SletGuQ7Q7Cajz7v6XjaUg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,313,1728975600"; d="scan'208";a="105251575" Received: from vkasired-desk2.fm.intel.com ([10.105.128.132]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jan 2025 00:38:10 -0800 From: Vivek Kasireddy To: dri-devel@lists.freedesktop.org, linux-mm@kvack.org Cc: Vivek Kasireddy , Gerd Hoffmann , Steve Sistare , Muchun Song , David Hildenbrand , Andrew Morton Subject: [PATCH v2 0/2] mm/memfd: reserve hugetlb folios before allocation Date: Tue, 14 Jan 2025 00:07:59 -0800 Message-ID: <20250114080927.2616684-1-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: E90C91C0017 X-Stat-Signature: 6eetzrhappegryuc5wx53rtui9ygzekx X-Rspam-User: X-HE-Tag: 1736843895-119608 X-HE-Meta: U2FsdGVkX18iu9Ys/V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7b7TyFy6fwbZup/dEKtFa28All6dYrDDyG8Ko52Kkbc/bCw7Ga4QD/Dy/H7e8uzFa7Pnj9brWev33CH8jjD3w0F2drFD5aJlZR2iPTByRdjBDwjyB8Mob14TnhEg+NtLHkdyftSHRCqqT X-Bogosity: Ham, tests=bogofilter, spamicity=0.001447, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: There are cases when we try to pin a folio but discover that it has not been faulted-in. So, we try to allocate it in memfd_alloc_folio() but there is a chance that we might encounter a crash/failure (VM_BUG_ON(!h->resv_huge_pages)) if there are no active reservations at that instant. This issue was reported by syzbot. Therefore, to avoid this situation and fix this issue, we just need to make a reservation (by calling hugetlb_reserve_pages()) before we try to allocate the folio. This will ensure that we are properly doing region/subpool accounting associated with our allocation. ----------------------------- Patchset overview: Patch 1: Fix for VM_BUG_ON(!h->resv_huge_pages) crash reported by syzbot Patch 2: New udmabuf selftest to invoke memfd_alloc_folio() This series is tested by running the new udmabuf selftest introduced in patch #2 along with the other selftests. Changelog: v1 -> v2: - Replace VM_BUG_ON() with WARN_ON_ONCE() in the function alloc_hugetlb_folio_reserve() (David) - Move the inline function subpool_inode() from hugetlb.c into the relevant header (hugetlb.h) - Call hugetlb_unreserve_pages() if the folio cannot be added to the page cache as well - Added a new udmabuf selftest to exercise the same path as that of syzbot Cc: Gerd Hoffmann Cc: Steve Sistare Cc: Muchun Song Cc: David Hildenbrand Cc: Andrew Morton Vivek Kasireddy (2): mm/memfd: reserve hugetlb folios before allocation selftests/udmabuf: add a test to pin first before writing to memfd include/linux/hugetlb.h | 5 +++++ mm/hugetlb.c | 14 ++++++------- mm/memfd.c | 14 ++++++++++--- .../selftests/drivers/dma-buf/udmabuf.c | 20 ++++++++++++++++++- 4 files changed, 41 insertions(+), 12 deletions(-)