Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2230402rbb; Tue, 27 Feb 2024 15:26:32 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUJPhQoAiqXvGwhZzkJqPL8XdHcvntCq/5gpwEfyzYXW63CJPA2G/ZOxR7IdpTfAC6G7rrLc8hHBt3RIM2fSJNKmk5w7ESTUHhhw6ibHA== X-Google-Smtp-Source: AGHT+IF6pnq1T6MTswamryF4ekuQkgtDksPeonpxu6d81whqXUOQA+No+R0zBJh8FEDbnDCKOXp7 X-Received: by 2002:a05:6214:301b:b0:68f:ecc8:bd1d with SMTP id ke27-20020a056214301b00b0068fecc8bd1dmr4169569qvb.52.1709076391989; Tue, 27 Feb 2024 15:26:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709076391; cv=pass; d=google.com; s=arc-20160816; b=ZG+C/3KSJXnsYP7IkxFIZtoddCviXAjhs+bRpRBR66grBoCdcpi82evbmBZMIJAeve y7Xk09DbA2mk8dL1+ntWGoFXKG8Z4qxMpl/dcQtAIZA7DF0rVOvDg69j5x4VF0LALeoz dTpln55ouC5KwaRH0YWVjveTA0tFc/0zmoLpxuTN172dSNd8B5Qpuh0bKyRfQw6A3UDI 8b0uTylmlemjLVPU3yTueJFtzQpcfKFgDstrF+qgwrhnqDuq+l8ZO4QeLJnufsnJHrHp tNMGmq/11fODM6LwseP7ncMqcZkHlATYOpLY+1XgUfsZ2tDmCHaTaesVn9cbYFCQalqL 7nlw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=BG4ZL+4+5uPAuYv+ozkJ6gsYKFZe75rDBIaL5MNApAs=; fh=miuXyzfw5j8qsOURKCmYrSiXirUlKyDkR37pPJ+5+/s=; b=v31V2REKUr62zfUHElFPIqydrZT7FIqMVPCh7vZicW/jyvi3ZaPqCBIpET3qkQMgZg q3Ngbf6w9283f3WGt72YniYVojXueXRxAriX54wOqzQcL4vYXD8qzukwxt47U5rQmXxN 3Ky4J/weECOCZ1rQGYyYMIVL+47712cHkE1RHqL0JSoG5mabd9ZpgV1ClF6RKtsIPDNj oLx6dAgTGCybcZlggazN5Bu9vZVMOpPt4c5/Cq8c4cfFwz5q/ZRd2gjIfp2jT35bVMpT G5+AGwzCxm3T+Py/BSxD1S9Gxly2jETVseqgbHZEa39JSx6b7uS/Gay0arneDrdYny79 NiYQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=S+inPmar; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-84201-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84201-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id a9-20020ad45c49000000b0068f6580893dsi8803659qva.134.2024.02.27.15.26.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 15:26:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84201-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=S+inPmar; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-84201-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84201-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id BAFE21C230EA for ; Tue, 27 Feb 2024 23:26:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5E90E5DF0A; Tue, 27 Feb 2024 23:21:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="S+inPmar" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C90E557867 for ; Tue, 27 Feb 2024 23:21:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709076071; cv=none; b=e+PHs/ahm53CVkd2rmF0j3z+Ohry8bLXI2U5BGf6rJfJ6EQde1kQof3oZt6mnigjGAFKcpeEXdSzfBHU1+qKAj7/ih4F8plggTPvzmmaZHtbWqQTTbbRZln36Oz3fLRG7NP78z9SL/476pOyCbLSagJOMeXO2QJCVWhe1DQ28Uo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709076071; c=relaxed/simple; bh=KY7Vtiin2PBxkQCqTTa5Z5E0FoYbvkUJVSGQWBSa3os=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=hyRTGYxRQpZXjLNHv/SuL4YUJVTA3VGUJAX1oxowqDdRWpxkekEn9aeWXOi3xbVAxJZAfVmUzf+LbEscQT6aqRwfR8bv+kE5txQGBXkQa25T7r7abO2jbr1cL6ShkR8sAwfrMbl/SgyFrScGAg7mNmetdbR1xEQF295KGaLTGvM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=S+inPmar; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709076067; 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=BG4ZL+4+5uPAuYv+ozkJ6gsYKFZe75rDBIaL5MNApAs=; b=S+inPmar82UGzsy/pzFbf2sT8rDtf7brfY0qcCjrsumUAqDkYa3+zZZ3nqxM2HTBMmwRgu l4jfoVb1hLd/jHvTRz1cmtGm/yGzhqBVdVEJ/kSzCyse/aXzkW1VDdgi9e6BWAzgs6p5qI j3pw3+drMoJamioyaDvwJHl7z5cWvmU= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-90-mamPH8I0Pzi2AWxQuplGCw-1; Tue, 27 Feb 2024 18:21:05 -0500 X-MC-Unique: mamPH8I0Pzi2AWxQuplGCw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CD66D1E441C3; Tue, 27 Feb 2024 23:21:04 +0000 (UTC) Received: from virtlab511.virt.lab.eng.bos.redhat.com (virtlab511.virt.lab.eng.bos.redhat.com [10.19.152.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1441C0348F; Tue, 27 Feb 2024 23:21:04 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: seanjc@google.com, michael.roth@amd.com, isaku.yamahata@intel.com, thomas.lendacky@amd.com Subject: [PATCH 17/21] filemap: add FGP_CREAT_ONLY Date: Tue, 27 Feb 2024 18:20:56 -0500 Message-Id: <20240227232100.478238-18-pbonzini@redhat.com> In-Reply-To: <20240227232100.478238-1-pbonzini@redhat.com> References: <20240227232100.478238-1-pbonzini@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 Signed-off-by: Paolo Bonzini --- include/linux/pagemap.h | 2 ++ mm/filemap.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 2df35e65557d..e8ac0b32f84d 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -586,6 +586,7 @@ pgoff_t page_cache_prev_miss(struct address_space *mapping, * * %FGP_CREAT - If no folio is present then a new folio is allocated, * added to the page cache and the VM's LRU list. The folio is * returned locked. + * * %FGP_CREAT_ONLY - Fail if a folio is not present * * %FGP_FOR_MMAP - The caller wants to do its own locking dance if the * folio is already in cache. If the folio was allocated, unlock it * before returning so the caller can do the same dance. @@ -606,6 +607,7 @@ typedef unsigned int __bitwise fgf_t; #define FGP_NOWAIT ((__force fgf_t)0x00000020) #define FGP_FOR_MMAP ((__force fgf_t)0x00000040) #define FGP_STABLE ((__force fgf_t)0x00000080) +#define FGP_CREAT_ONLY ((__force fgf_t)0x00000100) #define FGF_GET_ORDER(fgf) (((__force unsigned)fgf) >> 26) /* top 6 bits */ #define FGP_WRITEBEGIN (FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE) diff --git a/mm/filemap.c b/mm/filemap.c index 750e779c23db..d5107bd0cd09 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1854,6 +1854,10 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, folio = NULL; if (!folio) goto no_page; + if (fgp_flags & FGP_CREAT_ONLY) { + folio_put(folio); + return ERR_PTR(-EEXIST); + } if (fgp_flags & FGP_LOCK) { if (fgp_flags & FGP_NOWAIT) { -- 2.39.0