Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp29284lqo; Tue, 7 May 2024 11:08:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWIQjvkwPQOtZVtrqbmChNqwAciG0fL7PjGHTpa5cAEorGhGPEyNwX1pJviAmb7VUfw2W2Xgxn2RDYC/CwiNEZU824AyftiF4Ie5hEiFg== X-Google-Smtp-Source: AGHT+IE5Ox6DuW3mTOnwIPCnV5+uCBbP5A10r6gj6tVWz9ELatgJMeolHLO95DaNME87E2dDxG3C X-Received: by 2002:a17:902:76c4:b0:1e5:5cab:3185 with SMTP id d9443c01a7336-1eeb03a2fa0mr3691395ad.25.1715105318725; Tue, 07 May 2024 11:08:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715105318; cv=pass; d=google.com; s=arc-20160816; b=sJZCJA3JikSwcGXzduzQDDcdsDhCmx6eWBqPvfSgwHFLB29lRjfVx5Afndf/e1v65V I2IhvSZUVCa2YFhyXsrpYmWEaR4RMA+ddPzuQTsz2ZQeGLjTDVpccPSjnT9oHsJB9Bqm l+AxPVxKOQEnVYzdBe/XS56PgBlQn9h0sTqS6dgkXKBss6Cvx0w+IWXH1C7woN5sGS8E cwYhK+XDlYHsPWR95tz6Hp+MLcHyeif8UH90sW1j61yk98Zk3cxE2ic/CScZ64h+6G5F 7cv4dXKR26mgxB/Zwrtj9kZTzj7Ez+q4zpmNsbyFLayhQKFIzZyvuz8VAhrd/CJk1Jiu b6mA== 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=x9rksasoN6o3C+2hIlFTffjFimcLr+rqnzsLWoL6yPo=; fh=uwOp2UVTonYvy7JjkwYgWmEzMj+LYWBj3xu2PrpNAkc=; b=XsfhztfohBWlmxnOUedKcpWsXO309OJ5bs62fqLZOV0WINAzTbkXaYWupX+lkpKc4k C3xjOlx9Di9ylELToTCIspm22XEL1qaL22oqmFx4JNlZKl5ZcvSUeRpDsW1j6HEd276D zVpX+espDlQHkWm151gh6rNjVwsO6e9LX110EcoN096Q47zT/cDe+0m1wbW1lxyiPsee txRJTx69voQ/UQnud1AJrbOBMbwWegP8fNWAmlGEOA1PvOyXCPgiaIz3ujKK8FiCJrae ChHYd/b9Fc9AyTsC+oMlANcJfEOVXcFRPzmvoNOcncnYTA/4cLudJfIsZmBZETCjxOU/ 6Bfw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YZ5ittu2; 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-171956-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171956-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. [139.178.88.99]) by mx.google.com with ESMTPS id mb14-20020a170903098e00b001eb246bf701si7999376plb.43.2024.05.07.11.08.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 11:08:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171956-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YZ5ittu2; 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-171956-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171956-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 576F32878DE for ; Tue, 7 May 2024 18:08:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 065F316DEC2; Tue, 7 May 2024 18:07:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="YZ5ittu2" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 6DEA616D329 for ; Tue, 7 May 2024 18:07:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105258; cv=none; b=rT8ELPGkqjSb3/48T/Q04/Pb0+EvhsseOBYaF0pgijj1HCOLcJRuBAE1sRU9rgFGD7eG5O7UzRbGe2Dm/TWwD7+TqUPgBReBwwUUkG8BrBo15FYn1rAbmAwWp+kWQUIQDbh5KBHfMrTJVhVA05AaaaFrrdcIQ113nd9bEBxrz84= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715105258; c=relaxed/simple; bh=uVnyZYyImXug/IJ95scTctCA5brtGWGQMQzMQw1hIi0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IFaaxmX9xo/uYqOi3nIuDJAszjeIxQv6aeqYcMuIVi0f0lCjQeXYjWuABpnk0BLadivuZ/MfWnMWXjPA5NUOx30VhndwwBl+5n5Bbk8MF3fJZ0YbbgkpbJsgq7anMLqXdK/4ijWCyJtCd09t+jLjqfHRP9/COPCtFlkcyGfouY4= 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=YZ5ittu2; arc=none smtp.client-ip=170.10.129.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=1715105255; 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=x9rksasoN6o3C+2hIlFTffjFimcLr+rqnzsLWoL6yPo=; b=YZ5ittu2ktw8KESNCPcAAUF6OtkyursBH6QSyxTrjm3MNm2cOo9EkTtqx3brvDs1ztIAdf BOOw90gjHzPp1G6ZaITaC94yvdNjCMxUeMzeJgkzeRHumoM9ZL32FzAQaCrdaVPfFQVdzn 4BKGVX3k7bvorOzU4ZFFiwF1whOX1Og= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-659-6ZNMbvA3MjuEJ08xwNW0wQ-1; Tue, 07 May 2024 14:07:32 -0400 X-MC-Unique: 6ZNMbvA3MjuEJ08xwNW0wQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 5B7401839B6C; Tue, 7 May 2024 18:07:31 +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 1ABD040C6EB7; Tue, 7 May 2024 18:07:31 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: vbabka@suse.cz, isaku.yamahata@intel.com, xiaoyao.li@intel.com, binbin.wu@linux.intel.com, seanjc@google.com, rick.p.edgecombe@intel.com, michael.roth@amd.com, yilun.xu@intel.com Subject: [PATCH 4/9] KVM: guest_memfd: limit overzealous WARN Date: Tue, 7 May 2024 14:07:24 -0400 Message-ID: <20240507180729.3975856-5-pbonzini@redhat.com> In-Reply-To: <20240507180729.3975856-1-pbonzini@redhat.com> References: <20240507180729.3975856-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.2 Because kvm_gmem_get_pfn() is called from the page fault path without any of the slots_lock, filemap lock or mmu_lock taken, it is possible for it to race with kvm_gmem_unbind(). This is not a problem, as any PTE that is installed temporarily will be zapped before the guest has the occasion to run. However, it is not possible to have a complete unbind+bind racing with the page fault, because deleting the memslot will call synchronize_srcu_expedited() and wait for the page fault to be resolved. Thus, we can still warn if the file is there and is not the one we expect. Signed-off-by: Paolo Bonzini --- virt/kvm/guest_memfd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c index c27828b0d42d..fd32288d0fbc 100644 --- a/virt/kvm/guest_memfd.c +++ b/virt/kvm/guest_memfd.c @@ -499,7 +499,8 @@ int kvm_gmem_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot, gmem = file->private_data; - if (WARN_ON_ONCE(xa_load(&gmem->bindings, index) != slot)) { + if (xa_load(&gmem->bindings, index) != slot) { + WARN_ON_ONCE(xa_load(&gmem->bindings, index)); r = -EIO; goto out_fput; } -- 2.43.0