Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp245741lqp; Thu, 4 Apr 2024 11:53:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWykWTqWWspwtxq04UtaIW1zS3TMXGPr4EO3JR9pi9PokDgsskUoWg0wfHa7w7Bip5nY/SkP1KIk0GKs8ipgmn+9vJ49XxJIuTBQLzuWg== X-Google-Smtp-Source: AGHT+IGsO7p+y8n4ojyLlkVNQcfLSAdU7Ob4TJHfHdtaBMYRYyev1pjbgSa6MYxLNwK2fucHX+u2 X-Received: by 2002:a17:902:d68b:b0:1e2:c34d:dda3 with SMTP id v11-20020a170902d68b00b001e2c34ddda3mr358049ply.13.1712256802281; Thu, 04 Apr 2024 11:53:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712256802; cv=pass; d=google.com; s=arc-20160816; b=vPxSuPwuOk2tU66e/bD1Cfne+kS8Kd/P1jmStAn88QgfO2sPW26dbm6Dwvq4gf3mKR 4nGgBmpo8QwMoHnE4eki+djYr9/3qVonATZ5h5DycQLsbmv2zUtoMcZZYNHMIfL0qYKp 8hvEvMrZ3xdbrAdbVJlW0WZuZiHpiWBrFzoj2kOLYXTYPEnbH33Txd547O9A8pKgUtoS q5y1qfFrSNyf4s38j5sETXvZ8nAaVMRgUsU/IraMvZdPeKroQAj8YBNJElhbIVMB+vVt nbjq6kG2V7eMQUrqTXq4zDdam1qQETzWqLzBx7AwaLNOsFfXAihJUNMykgZ4Zqcu8wkJ eXbQ== 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=JFajdk4fDiyh8VxZ37SkZXsZFlO1RmoQzZVvkfEWg0k=; fh=YodCu8Vte8qk6mmfvotnw4P3XuROgs3fniKbwtpv3JY=; b=MO4lCPWyDSB58SHyOUI5mxWRnAe3rou1a9rKlpgz8cV3dSga/9v8hi9v83BLLhgem9 LmFCnsn8iSjk3CVHpEBH3mn+kGbmhmngWuOEEMBXJIT51SwwArLDmNU0W72TfYT4r3vk OsO1t05/941b8d36ZRIqikpOxpDORNyPrvhUAnUq9Z9L2x4Sh51F0lebwUs9Iusv5nnz 40tCDOfBV63IDNsLovg8iKQlWOww4XEi8sdhEjL7ZeiNSq69qBjOl8qb94FxWVfE4hwG K7cTIDB2VrYAJbm/n43VjcJW8e7l3xyAfl55H/PfY64a7CZDQfjixwHQQsgd6bFNhG3y Tryw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hvPvBNkc; 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-131996-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131996-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d10-20020a170902ceca00b001dcf978c34fsi16416005plg.30.2024.04.04.11.53.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 11:53:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-131996-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hvPvBNkc; 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-131996-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131996-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id EAD0228AB21 for ; Thu, 4 Apr 2024 18:53:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 09BD413C66C; Thu, 4 Apr 2024 18:50:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hvPvBNkc" 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 27635133416 for ; Thu, 4 Apr 2024 18:50:42 +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=1712256645; cv=none; b=qKvWeHHrGOCmnqpHXrO+HwV2y4XIRY/FDMxezSw5RuJELY6S3N+a7E9qZZoZ9FvzNsVjXPYv+PsKvcIkJDLRC/Vt1+zukctWLuOFAHrPd19AYZ/7NOBRECxKkLi5mN4SrjDBJs7LmmxmYJQFoM5nLerd0U36qeSAlsJM/b6YJ+k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712256645; c=relaxed/simple; bh=jdNIfZWZvPJII98ywtATikTD6VDJZQYwABwABAMUGS8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nQ8rO6U4ThhWQrGeYWpynM6FzlJ6tjLNagYsVcT7es/r6bgTOhZt3r9I2N/bZZHKCERfhZfIR6jTLv5l3OBKDLbKpD/VQHZJqWa5dCCVaMLMx+XQXGwLHhTrkDJ4new800bZ4xVK7/47AjTjwu9Cwd6Z28WRJnWX77prjDBUVYQ= 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=hvPvBNkc; 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=1712256642; 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=JFajdk4fDiyh8VxZ37SkZXsZFlO1RmoQzZVvkfEWg0k=; b=hvPvBNkc5oZFwi8mSdmNZJsdkqYq/IBy+w6KonJPl0CF2EaBdHVVEd8Z3Ly8+L7ZqwTHVw z+OT76BoWJT6fs4aDR4Fjlr6g0X1ALnijbr3nkq/Rebqztga6PvgcRqOFJjo1pcdeFiP4O PWjZ1OE/t6+czWbnRHDW6JcFJLrzRq4= 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-64-rFD63vFJMpWHpRDgCAYm6Q-1; Thu, 04 Apr 2024 14:50:36 -0400 X-MC-Unique: rFD63vFJMpWHpRDgCAYm6Q-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 6107728B7402; Thu, 4 Apr 2024 18:50:36 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B46D1C060A4; Thu, 4 Apr 2024 18:50:36 +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 Subject: [PATCH 08/11] KVM: guest_memfd: extract __kvm_gmem_punch_hole() Date: Thu, 4 Apr 2024 14:50:30 -0400 Message-ID: <20240404185034.3184582-9-pbonzini@redhat.com> In-Reply-To: <20240404185034.3184582-1-pbonzini@redhat.com> References: <20240404185034.3184582-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.7 Extract a version of kvm_gmem_punch_hole() that expects the caller to take the filemap invalidate_lock. Signed-off-by: Paolo Bonzini --- virt/kvm/guest_memfd.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c index a537a7e63ab5..51c99667690a 100644 --- a/virt/kvm/guest_memfd.c +++ b/virt/kvm/guest_memfd.c @@ -152,19 +152,12 @@ static void kvm_gmem_invalidate_end(struct kvm_gmem *gmem, pgoff_t start, } } -static long kvm_gmem_punch_hole(struct inode *inode, loff_t offset, loff_t len) +static long __kvm_gmem_punch_hole(struct inode *inode, loff_t offset, loff_t len) { struct list_head *gmem_list = &inode->i_mapping->i_private_list; pgoff_t start = offset >> PAGE_SHIFT; pgoff_t end = (offset + len) >> PAGE_SHIFT; struct kvm_gmem *gmem; - - /* - * Bindings must be stable across invalidation to ensure the start+end - * are balanced. - */ - filemap_invalidate_lock(inode->i_mapping); - list_for_each_entry(gmem, gmem_list, entry) kvm_gmem_invalidate_begin(gmem, start, end); @@ -173,11 +166,23 @@ static long kvm_gmem_punch_hole(struct inode *inode, loff_t offset, loff_t len) list_for_each_entry(gmem, gmem_list, entry) kvm_gmem_invalidate_end(gmem, start, end); - filemap_invalidate_unlock(inode->i_mapping); - return 0; } +static long kvm_gmem_punch_hole(struct inode *inode, loff_t offset, loff_t len) +{ + int r; + + /* + * Bindings must be stable across invalidation to ensure the start+end + * are balanced. + */ + filemap_invalidate_lock(inode->i_mapping); + r = __kvm_gmem_punch_hole(inode, offset, len); + filemap_invalidate_unlock(inode->i_mapping); + return r; +} + static long kvm_gmem_allocate(struct inode *inode, loff_t offset, loff_t len) { struct address_space *mapping = inode->i_mapping; -- 2.43.0